/* Publy CRM v2.0 — horizontal workspace, tokens for dark + light themes.
   System font stack only: the app runs offline from a USB drive. */

:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1b1f1c;
  --bg-2: #202521;
  --surface: #252a26;
  --surface-2: #2c322d;
  --surface-3: #353c36;
  --line: rgba(244, 242, 237, .09);
  --line-2: rgba(244, 242, 237, .16);
  --ink: #f2f0ea;
  --ink-2: #d6d4ce;
  --muted: #9a9e97;
  --accent: #ff5a24;
  --accent-ink: #ffffff;
  --accent-soft: rgba(255, 90, 36, .14);
  --focus: rgba(255, 90, 36, .38);
  --danger: #ff7a68;
  --danger-soft: rgba(255, 92, 70, .14);
  --ok: #4fd18b;
  --s0: #9aa6b4; --s0-soft: rgba(154, 166, 180, .16);
  --s1: #ff7a5c; --s1-soft: rgba(255, 122, 92, .15);
  --s2: #ffbe3d; --s2-soft: rgba(255, 190, 61, .15);
  --s3: #c2e05a; --s3-soft: rgba(194, 224, 90, .15);
  --s4: #45d08f; --s4-soft: rgba(69, 208, 143, .15);
  --c-income: #ffc83d;
  --c-expense: #ff5a24;
  --c-debt: #a98bff;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-2: 0 18px 50px rgba(0, 0, 0, .45);
  --backdrop: rgba(8, 10, 9, .62);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #efede7;
  --bg-2: #e7e4dc;
  --surface: #ffffff;
  --surface-2: #f6f5f1;
  --surface-3: #ecebe5;
  --line: rgba(32, 37, 33, .09);
  --line-2: rgba(32, 37, 33, .17);
  --ink: #1d221e;
  --ink-2: #3a403b;
  --muted: #6b7069;
  --accent: #e5440f;
  --accent-ink: #ffffff;
  --accent-soft: rgba(229, 68, 15, .1);
  --focus: rgba(229, 68, 15, .3);
  --danger: #c8341f;
  --danger-soft: rgba(200, 52, 31, .1);
  --ok: #17895a;
  --s0: #66717f; --s0-soft: rgba(102, 113, 127, .12);
  --s1: #d6492a; --s1-soft: rgba(214, 73, 42, .11);
  --s2: #b07800; --s2-soft: rgba(204, 140, 0, .13);
  --s3: #6a8a10; --s3-soft: rgba(120, 160, 20, .14);
  --s4: #13895a; --s4-soft: rgba(19, 137, 90, .12);
  --c-income: #e0a100;
  --c-expense: #e5440f;
  --c-debt: #7357e0;
  --shadow-1: 0 1px 2px rgba(30, 35, 31, .08);
  --shadow-2: 0 18px 50px rgba(30, 35, 31, .18);
  --backdrop: rgba(30, 33, 31, .38);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink);
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
small { display: block; color: var(--muted); font-size: 12.5px; line-height: 1.35; margin-top: 2px; }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .mono { white-space: nowrap; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; } .grow { flex: 1 1 auto; min-width: 0; } .spacer { flex: 1 1 auto; }
.clamp-2, .clamp-3 { display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; }
.clamp-2 { -webkit-line-clamp: 2; } .clamp-3 { -webkit-line-clamp: 3; }
.pre { white-space: pre-wrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
.sep { margin: 22px 0; }

/* ---------- App bar & horizontal navigation ---------- */
.appbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg-2) 88%, transparent);
  backdrop-filter: saturate(1.3) blur(12px);
  border-bottom: 1px solid var(--line);
}
.appbar-row { display: flex; align-items: center; gap: 16px; padding: 10px 24px 8px; max-width: 1640px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; flex: none; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--ink); color: var(--bg); font-weight: 900; font-size: 18px; letter-spacing: -.06em; }
.brand-name { font-weight: 800; font-size: 18px; letter-spacing: -.03em; display: flex; align-items: baseline; gap: 6px; }
.brand-name small { display: inline; font-size: 10.5px; font-weight: 800; letter-spacing: .12em; color: var(--accent); margin: 0; }

.tabs-nav { display: flex; gap: 2px; padding: 0 18px; max-width: 1640px; margin: 0 auto; overflow-x: auto; scrollbar-width: none; }
.tabs-nav::-webkit-scrollbar { display: none; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: 8px; padding: 9px 12px 11px;
  color: var(--muted); font-weight: 600; white-space: nowrap; border-radius: 8px 8px 0 0; transition: color .15s, background .15s;
}
.tab:hover { color: var(--ink); background: var(--surface-2); }
.tab.active { color: var(--ink); }
.tab.active::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: 0; height: 2px; border-radius: 2px; background: var(--accent); }
.tab-end { margin-left: auto; }
.count {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--surface-3); color: var(--ink-2); font-size: 11.5px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.tab.active .count { background: var(--accent-soft); color: var(--accent); }

/* ---------- Global search ---------- */
.gsearch { position: relative; flex: 1 1 520px; max-width: 680px; margin: 0 auto; }
.gsearch input {
  width: 100%; height: 40px; padding: 0 76px 0 40px; border-radius: 10px;
  border: 1px solid var(--line-2); background: var(--surface); transition: border-color .15s, box-shadow .15s;
}
.gsearch input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.gsearch input::-webkit-search-cancel-button { display: none; }
.gsearch-icon { position: absolute; left: 12px; top: 11px; color: var(--muted); pointer-events: none; }
.gsearch-kbd { position: absolute; right: 10px; top: 9px; padding: 2px 6px; border-radius: 6px; border: 1px solid var(--line-2); color: var(--muted); font: 600 11px/18px ui-sans-serif, system-ui, sans-serif; pointer-events: none; }
.gsearch-panel {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; min-width: min(640px, 92vw); z-index: 60;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 12px; box-shadow: var(--shadow-2);
  max-height: min(70vh, 620px); overflow: auto; padding: 6px;
}
.gs-group { padding: 8px 10px 4px; font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.gs-item { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 10px; align-items: start; width: 100%; padding: 9px 10px; border: 0; border-radius: 9px; background: none; text-align: left; }
.gs-item.active, .gs-item:hover { background: var(--surface-2); }
.gs-item b { font-weight: 650; } .gs-item mark { background: var(--accent-soft); color: inherit; border-radius: 3px; padding: 0 1px; }
.gs-item .gs-meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gs-item .gs-where { margin-top: 5px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12.5px; color: var(--ink-2); }
.gs-item .gs-where span.t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 360px; }
.gs-right { text-align: right; font-size: 12.5px; color: var(--muted); white-space: nowrap; padding-top: 2px; }
.gs-foot { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 8px 10px 4px; border-top: 1px solid var(--line); margin-top: 6px; color: var(--muted); font-size: 12.5px; }
.gs-foot a { color: var(--accent); font-weight: 650; }
.gs-empty { padding: 18px 12px; color: var(--muted); }
.gs-empty b { color: var(--ink); display: block; margin-bottom: 4px; }

.appbar-actions { display: flex; align-items: center; gap: 8px; flex: none; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: 9px; border: 1px solid var(--line-2); background: var(--surface-2); color: var(--ink);
  font-weight: 600; white-space: nowrap; transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 22%, transparent); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.icon-btn { width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: 9px; border: 1px solid transparent; background: transparent; color: var(--muted); font-size: 20px; line-height: 1; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn-sm { width: 28px; height: 28px; font-size: 17px; }
.avatar-btn { border: 0; background: none; padding: 0; border-radius: 50%; }
:root[data-theme="dark"] .i-moon, :root[data-theme="light"] .i-sun { display: none; }

/* ---------- Dropdowns ---------- */
.dropdown { position: relative; }
.dropdown-menu {
  display: none; position: absolute; top: calc(100% + 6px); right: 0; min-width: 240px; z-index: 70; padding: 6px;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 12px; box-shadow: var(--shadow-2);
}
.dropdown.open .dropdown-menu { display: grid; gap: 2px; animation: pop .14s ease both; }
.dropdown-menu a, .dropdown-menu button { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; border-radius: 8px; background: none; color: var(--ink); }
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--surface-2); }
.dropdown-menu b { font-weight: 600; } .dropdown-menu small { margin: 0; }
.dropdown-head { padding: 8px 10px; } .dropdown-head small { margin: 0; }

/* ---------- Page ---------- */
.page { max-width: 1640px; margin: 0 auto; padding: 22px 24px 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { margin: 0; font-size: 26px; line-height: 1.15; letter-spacing: -.025em; font-weight: 750; }
.page-sub { margin: 4px 0 0; color: var(--muted); max-width: 760px; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.back { color: var(--muted); font-weight: 600; } .back:hover { color: var(--ink); }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 18px; }
.kpi {
  display: flex; flex-direction: column; gap: 4px; min-width: 0; padding: 14px 16px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-1); transition: border-color .15s, transform .15s;
}
a.kpi:hover { border-color: var(--line-2); transform: translateY(-1px); }
.kpi-label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.kpi-value { font-size: 24px; line-height: 1.15; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi-value.neg { color: var(--danger); }
.kpi-sub { color: var(--muted); font-size: 12px; }
.kpi-accent { background: linear-gradient(135deg, var(--accent-soft), transparent 70%), var(--surface); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.kpi-form .inline { display: flex; flex-wrap: nowrap; gap: 6px; margin: 2px 0; } .kpi-form .inline input { flex: 1 1 auto; } .kpi-form input { height: 32px; padding: 0 10px; font-weight: 700; }

/* ---------- Status colors ---------- */
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--s0); }
.dot.s0 { background: var(--s0); } .dot.s1 { background: var(--s1); } .dot.s2 { background: var(--s2); } .dot.s3 { background: var(--s3); } .dot.s4 { background: var(--s4); }
.dot.c-income { background: var(--c-income); } .dot.c-expense { background: var(--c-expense); } .dot.c-debt { background: var(--c-debt); }
.line { display: inline-block; width: 16px; height: 0; border-top: 2px dashed var(--c-debt); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 650; white-space: nowrap; background: var(--s0-soft); color: var(--s0); }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.s1 { background: var(--s1-soft); color: var(--s1); } .pill.s2 { background: var(--s2-soft); color: var(--s2); }
.pill.s3 { background: var(--s3-soft); color: var(--s3); } .pill.s4 { background: var(--s4-soft); color: var(--s4); }
td .pill + small, td .pill + .pill { margin-top: 4px; }

/* ---------- Panels, layout ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; box-shadow: var(--shadow-1); min-width: 0; margin-bottom: 16px; }
.panel-flush { padding: 0; overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.panel-head.pad { padding: 14px 18px 0; }
.panel-head h2 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
.panel-sub { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }
.panel > .table-wrap, .panel-flush > .empty { margin: 0; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.split-even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stack { display: grid; gap: 0; min-width: 0; }
.h-sm { margin: 14px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 800; }
.stack-sm > .h-sm:first-child { margin-top: 0; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums; }
.table th { position: sticky; top: 0; z-index: 1; text-align: left; font-size: 12px; font-weight: 700; color: var(--muted); padding: 10px 12px; background: var(--surface); border-bottom: 1px solid var(--line-2); white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th:first-child, .table td:first-child { padding-left: 18px; }
.table th:last-child, .table td:last-child { padding-right: 18px; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tfoot td { font-weight: 700; border-bottom: 0; background: var(--surface-2); }
.table td b { font-weight: 650; }
.num { text-align: right !important; white-space: nowrap; }
.actions { text-align: right; white-space: nowrap; width: 1%; }
.actions form { display: inline; }
.actions > * + * { margin-left: 4px; }
.row-click { cursor: pointer; }
.cell-link { display: block; padding: 0; border: 0; background: none; text-align: left; color: inherit; }
.cell-link:hover b { color: var(--accent); }
.empty-filter { padding: 16px 18px; color: var(--muted); margin: 0; }

/* ---------- Toolbars & filters ---------- */
.toolbar-search { display: flex; gap: 6px; align-items: center; }
.toolbar-search input { width: 260px; height: 34px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input.grow { flex: 1 1 280px; }
.filters select { width: auto; min-width: 160px; }
.w-sm { max-width: 280px; height: 34px; }

.seg { display: flex; gap: 4px; flex-wrap: wrap; padding: 4px; margin-bottom: 14px; border-radius: 11px; background: var(--surface); border: 1px solid var(--line); width: fit-content; max-width: 100%; }
.seg-item { display: inline-flex; align-items: center; gap: 7px; padding: 6px 11px; border-radius: 8px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.seg-item:hover { color: var(--ink); background: var(--surface-2); }
.seg-item.active { background: var(--surface-3); color: var(--ink); box-shadow: var(--shadow-1); }

/* pipeline (work stages) */
.stage-bar { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 16px; }
.pipeline { display: flex; gap: 0; flex-wrap: wrap; }
.pipe-step {
  --c: var(--s1); --soft: var(--s1-soft);
  position: relative; display: inline-flex; align-items: center; gap: 10px; height: 40px; padding: 0 22px 0 18px; margin-right: 4px;
  background: var(--surface); border: 1px solid var(--line); color: var(--muted); font-weight: 650;
  clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 50%, calc(100% - 12px) 100%, 0 100%, 12px 50%);
}
.pipe-step:first-child { clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 50%, calc(100% - 12px) 100%, 0 100%); border-radius: 10px 0 0 10px; }
.pipe-step.s2 { --c: var(--s2); --soft: var(--s2-soft); } .pipe-step.s3 { --c: var(--s3); --soft: var(--s3-soft); } .pipe-step.s4 { --c: var(--s4); --soft: var(--s4-soft); }
.pipe-step:hover { color: var(--ink); background: var(--surface-2); }
.pipe-step.active { background: var(--soft); color: var(--ink); border-color: transparent; box-shadow: inset 0 -2px 0 var(--c); }
.pipe-count { min-width: 22px; height: 22px; padding: 0 6px; display: inline-grid; place-items: center; border-radius: 999px; background: var(--surface-3); color: var(--ink); font-size: 12px; font-weight: 750; }
.pipe-step.active .pipe-count { background: var(--c); color: #111; }

/* ---------- Cards grid (articles, loans, agents) ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 12px; align-items: start; margin-bottom: 16px; }
.span-all { grid-column: 1 / -1; }
.acard-item { --c: var(--s0); background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--c); border-radius: 12px; box-shadow: var(--shadow-1); min-width: 0; transition: border-color .15s, box-shadow .15s; scroll-margin-top: 130px; }
.acard-item.s1 { --c: var(--s1); } .acard-item.s2 { --c: var(--s2); } .acard-item.s3 { --c: var(--s3); } .acard-item.s4 { --c: var(--s4); }
.acard-item:hover { border-color: var(--line-2); border-left-color: var(--c); }
.acard-item[data-focus] { box-shadow: 0 0 0 3px var(--focus); }
.acard-item summary { list-style: none; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: start; padding: 14px 14px 14px 12px; cursor: pointer; }
.acard-item summary::-webkit-details-marker { display: none; }
.acard-item summary .dot { margin-top: 6px; }
.sum-main b { font-weight: 650; line-height: 1.3; }
.chev { color: var(--muted); transition: transform .2s; margin-top: 2px; }
.acard-item[open] .chev { transform: rotate(180deg); }
.acard-body { padding: 0 14px 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.lock { color: var(--s2); font-weight: 650; }
.authors-list { display: grid; gap: 2px; margin-bottom: 10px; max-height: 340px; overflow: auto; }
.author-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px; border-radius: 8px; }
.author-row:hover { background: var(--surface-2); }
.author-row form { display: contents; }
.card-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.card-actions form { display: inline-flex; }
.card-actions.workflow { padding-top: 10px; border-top: 1px dashed var(--line-2); margin-top: 12px; }
.mini-row { display: flex; gap: 12px; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.inline { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.inline input { flex: 1 1 160px; }

/* agents */
.agent-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; box-shadow: var(--shadow-1); }
.agent-card.is-off { opacity: .7; }
.agent-card header { display: flex; gap: 10px; align-items: center; }
.agent-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.agent-stats div { padding: 8px 10px; border-radius: 9px; background: var(--surface-2); }
.agent-stats strong { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; height: 74px; align-items: end; }
.bar { display: flex; flex-direction: column; align-items: stretch; justify-content: flex-end; height: 100%; }
.bar i { display: block; height: calc(var(--v) / var(--max) * 52px); min-height: 2px; border-radius: 3px 3px 1px 1px; background: var(--surface-3); }
.bar.cur i { background: var(--accent); }
.bar em { font-style: normal; font-size: 10px; text-align: center; color: var(--muted); margin-top: 4px; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; display: grid; }
.list li { border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list li > a, .list li > span { display: block; padding: 9px 4px; border-radius: 8px; }
.list li > a:hover { background: var(--surface-2); }
.list .pill { margin-bottom: 4px; }
.list b { font-weight: 600; }

/* ---------- Forms ---------- */
input, select, textarea {
  width: 100%; min-width: 0; height: 38px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--line-2);
  background: var(--bg-2); color: var(--ink); transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; min-height: 64px; padding: 9px 12px; resize: vertical; line-height: 1.4; }
input[type="file"] { height: auto; padding: 8px; }
input[type="checkbox"] { width: 16px; height: 16px; padding: 0; accent-color: var(--accent); }
input[type="month"], input[type="date"] { padding-right: 8px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
::placeholder { color: var(--muted); opacity: .8; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.modal:not(.modal-lg):not(.modal-xl) .fields { grid-template-columns: 1fr; }
.field { display: grid; gap: 5px; align-content: start; min-width: 0; }
.field-wide { grid-column: 1 / -1; }
.field > label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field .req { color: var(--accent); font-style: normal; }
.field-check label { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.field .help { margin: 0; }
.field-error { color: var(--danger); font-size: 12.5px; }
.field-error:empty { display: none; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.with-add { display: flex; gap: 6px; } .with-add select { flex: 1; } .with-add .btn { height: 38px; }
.form-error { padding: 10px 12px; border-radius: 9px; background: var(--danger-soft); color: var(--danger); margin-bottom: 12px; font-weight: 600; }
.inline-assign { display: flex; flex-wrap: wrap; gap: 6px; } .inline-assign select { flex: 1 1 240px; }
.inline-assign .form-error { flex-basis: 100%; margin: 0; }

/* ---------- Modals (native <dialog>) ---------- */
.modal {
  width: min(520px, calc(100vw - 24px)); max-height: min(88vh, 900px); padding: 0; border: 1px solid var(--line-2); border-radius: 16px;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-2); overflow: hidden;
}
.modal-lg { width: min(760px, calc(100vw - 24px)); }
.modal-xl { width: min(920px, calc(100vw - 24px)); }
.modal[open] { display: flex; flex-direction: column; animation: pop .16s ease both; }
.modal::backdrop { background: var(--backdrop); backdrop-filter: blur(2px); }
.modal-form, .modal-remote-body, .acard { display: flex; flex-direction: column; min-height: 0; max-height: min(88vh, 900px); }
.modal-remote-body > form { max-height: inherit; }
.modal-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; padding: 16px 18px 12px; border-bottom: 1px solid var(--line); flex: none; }
.modal-head h2 { margin: 0; font-size: 17px; letter-spacing: -.01em; }
.modal-head p { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }
.modal-body { padding: 16px 18px; overflow: auto; flex: 1 1 auto; min-height: 0; }
.modal-foot { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--surface-2); flex: none; flex-wrap: wrap; }
.modal-foot .spacer { flex: 1; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* author card */
.acard-head { align-items: center; }
.acard-title { flex: 1; min-width: 0; }
.acard-title h2 { font-size: 20px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { display: inline-flex; align-items: center; height: 24px; padding: 0 9px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface-2); color: var(--ink-2); font-size: 12px; }
.chip:hover { border-color: var(--accent); color: var(--ink); }
.timeline { display: flex; list-style: none; margin: 0; padding: 12px 18px; gap: 0; border-bottom: 1px solid var(--line); overflow-x: auto; flex: none; }
.timeline li { flex: 1 1 0; min-width: 96px; position: relative; padding-top: 18px; font-size: 12px; color: var(--muted); text-align: center; }
.timeline li span { position: absolute; top: 4px; left: 50%; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; background: var(--surface-3); border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line-2); z-index: 1; }
.timeline li::before { content: ""; position: absolute; top: 8px; left: -50%; right: 50%; height: 2px; background: var(--line-2); }
.timeline li:first-child::before { display: none; }
.timeline li.done { color: var(--ink-2); } .timeline li.done span { background: var(--ink-2); } .timeline li.done::before { background: var(--ink-2); }
.timeline li.current { color: var(--ink); font-weight: 700; }
.timeline li.current span { width: 14px; height: 14px; margin-left: -7px; top: 2px; background: var(--s0); }
.timeline li.current.s1 span { background: var(--s1); } .timeline li.current.s2 span { background: var(--s2); } .timeline li.current.s3 span { background: var(--s3); } .timeline li.current.s4 span { background: var(--s4); }
.timeline li.current::before { background: var(--ink-2); }
.tabs-inline { display: flex; gap: 2px; padding: 0 12px; border-bottom: 1px solid var(--line); flex: none; }
.tabs-inline button { position: relative; padding: 10px 10px; border: 0; background: none; color: var(--muted); font-weight: 650; }
.tabs-inline button.active { color: var(--ink); }
.tabs-inline button.active::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; background: var(--accent); border-radius: 2px; }
.acard-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.props { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; margin: 0; align-content: start; }
.props-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 8px; }
.props div { padding: 8px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.props div.wide { grid-column: 1 / -1; }
.props dt { font-size: 12px; color: var(--muted); }
.props dd { margin: 2px 0 0; overflow-wrap: anywhere; }
.mini { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); margin-bottom: 8px; }
.mini a:hover b { color: var(--accent); }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; } .row-actions form { display: inline; }
.standalone-card .acard { max-height: none; }

/* picker */
.pick-list { display: grid; gap: 2px; margin-top: 10px; max-height: 52vh; overflow: auto; }
.pick-item { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 9px; cursor: pointer; }
.pick-item:hover { background: var(--surface-2); }
.pick-item:has(input:checked) { background: var(--accent-soft); }
.pick-item input { margin-top: 3px; }

/* avatar */
.avatar { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-weight: 800; flex: none; }
.avatar-lg { width: 46px; height: 46px; font-size: 18px; }

/* month switch */
.month-switch { display: flex; align-items: center; gap: 2px; padding: 2px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--surface); }
.month-switch input { height: 32px; border: 0; background: transparent; width: 150px; }
.month-switch .icon-btn { width: 32px; height: 32px; }

/* chart */
.chart-box { position: relative; }
.chart-box canvas { display: block; width: 100%; }
.chart-tip { position: absolute; pointer-events: none; padding: 8px 10px; border-radius: 9px; background: var(--surface-3); border: 1px solid var(--line-2); box-shadow: var(--shadow-2); font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums; z-index: 2; }
.chart-tip b { display: block; margin-bottom: 2px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 12.5px; }
.legend span { display: inline-flex; gap: 6px; align-items: center; }

/* empty states */
.empty { display: grid; gap: 4px; justify-items: start; padding: 26px 22px; color: var(--muted); }
.panel .empty { padding: 22px 18px; }
.cards > .empty { border: 1px dashed var(--line-2); border-radius: 12px; background: var(--surface); }
.empty strong { color: var(--ink); font-size: 15px; }
.empty-actions { margin-top: 10px; }

/* toasts */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: grid; gap: 8px; width: min(420px, calc(100vw - 36px)); }
.toast { display: flex; gap: 10px; align-items: flex-start; padding: 11px 12px 11px 14px; border-radius: 11px; background: var(--surface); border: 1px solid var(--line-2); border-left: 3px solid var(--s0); box-shadow: var(--shadow-2); animation: pop .2s ease both; }
.toast span { flex: 1; }
.toast.success { border-left-color: var(--ok); } .toast.warning { border-left-color: var(--s2); } .toast.error { border-left-color: var(--danger); }
.toast-x { border: 0; background: none; color: var(--muted); font-size: 18px; line-height: 1; padding: 0 2px; }
.toast.hide { opacity: 0; transform: translateY(6px); transition: opacity .25s, transform .25s; }

/* login */
.login-body { display: grid; place-items: center; padding: 24px; }
.login-card { width: min(400px, 100%); padding: 28px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-2); }
.login-card .brand { margin-bottom: 18px; }
.login-card p { color: var(--muted); margin: 0 0 18px; }
.login-form { display: grid; gap: 12px; }
.login-form label { display: grid; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.login-form .btn { height: 40px; margin-top: 4px; }

@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(.985); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .split { grid-template-columns: 1fr; }
  .hide-md { display: none; }
}
@media (max-width: 900px) {
  .split-even { grid-template-columns: 1fr; }
  .acard-grid { grid-template-columns: 1fr; }
  .appbar-row { flex-wrap: wrap; padding: 10px 16px 8px; gap: 10px; }
  .gsearch { order: 3; flex-basis: 100%; max-width: none; }
  .appbar-actions { margin-left: auto; }
  .gsearch-kbd { display: none; }
  .gsearch input { padding-right: 12px; }
  .tabs-nav { padding: 0 8px; }
}
@media (max-width: 680px) {
  .page { padding: 16px 16px 56px; }
  .hide-sm { display: none; }
  .fields { grid-template-columns: 1fr; }
  .cards { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-value { font-size: 20px; }
  .toolbar-search, .toolbar-search input { width: 100%; }
  .page-head h1 { font-size: 22px; }
  .props, .props-3 { grid-template-columns: 1fr 1fr; }
  .pipe-step { padding: 0 16px 0 14px; height: 36px; font-size: 13px; }
  .modal, .modal-lg, .modal-xl { width: 100vw; max-width: 100vw; max-height: 92vh; margin: auto 0 0; border-radius: 16px 16px 0 0; }
  .table th:first-child, .table td:first-child { padding-left: 14px; }
  .table th:last-child, .table td:last-child { padding-right: 14px; }
}

/* polish */
.modal:focus, .modal:focus-visible { outline: none; }
.page-sub.mono { white-space: normal; overflow-wrap: anywhere; }

/* installments */
.kpi-danger { border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.kpi-danger .kpi-value { color: var(--danger); }
.progress { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; min-width: 90px; margin-top: 6px; }
.progress i { display: block; height: 100%; border-radius: inherit; background: var(--s4); }
.progress-lg { height: 8px; margin-top: 12px; }
.w-progress { min-width: 140px; }
.inst-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.inst-summary > div { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); min-width: 0; }
.inst-summary strong { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.table-compact th, .table-compact td { padding: 7px 8px !important; }
.table-compact th { position: static; }
.sched-paid td { color: var(--muted); }
.pay-inline { padding: 12px; border-radius: 10px; background: var(--surface-2); margin-bottom: 10px; display: grid; gap: 10px; }
.pay-inline .fields { grid-template-columns: 1fr 1fr; }
.pay-inline .btn { justify-self: start; }
.mini-row form { display: inline; }
@media (max-width: 680px) { .inst-summary { grid-template-columns: 1fr 1fr; } }
.count-danger { background: var(--danger-soft) !important; color: var(--danger) !important; }
.link { color: var(--accent); font-weight: 600; }
