/* =====================================================================
   Sales & Cash Tracker — "Ledger" design system
   Swiss / minimal: one typeface (IBM Plex Sans), one accent, quiet
   surfaces, tabular numbers. Three themes: Light · Dark · Navy.
   ===================================================================== */

@font-face { font-family: "Plex"; font-weight: 400; font-display: swap; src: url("fonts/plex-400.woff2") format("woff2"); }
@font-face { font-family: "Plex"; font-weight: 500; font-display: swap; src: url("fonts/plex-500.woff2") format("woff2"); }
@font-face { font-family: "Plex"; font-weight: 600; font-display: swap; src: url("fonts/plex-600.woff2") format("woff2"); }
@font-face { font-family: "Plex"; font-weight: 700; font-display: swap; src: url("fonts/plex-700.woff2") format("woff2"); }

/* ---------- Tokens ---------- */
:root, html[data-theme="light"] {
  --bg: #f4f4f1;
  --surface: #ffffff;
  --surface-2: #f3f3ef;          /* table heads, tiles, hover */
  --surface-3: #eaeae5;          /* tracks, pressed */
  --line: #e3e3dd;
  --line-strong: #cfcfc7;
  --text: #16181d;
  --muted: #5d6169;              /* 6.1:1 on white */
  --faint: #8a8e96;
  --brand: #2343d6;              /* cobalt — the only accent */
  --brand-hover: #1b36b4;
  --on-brand: #ffffff;
  --brand-soft: #e9edfc;
  --brand-text: #1f3cc0;
  --pos: #0b7a47;  --pos-soft: #e2f3ea;
  --warn: #9a5800; --warn-soft: #fbefd9;
  --neg: #c22b2b;  --neg-soft: #fbe6e6;
  --ring: rgba(35, 67, 214, .28);
  --scrim: rgba(16, 18, 24, .42);
  --shadow-sm: 0 1px 2px rgba(16, 18, 24, .05);
  --shadow-md: 0 1px 2px rgba(16, 18, 24, .04), 0 8px 24px rgba(16, 18, 24, .07);
  --shadow-lg: 0 24px 64px rgba(16, 18, 24, .22);
  color-scheme: light;
}
html[data-theme="dark"] {
  --bg: #0d0e11;
  --surface: #16181d;
  --surface-2: #1d2026;
  --surface-3: #262a32;
  --line: #262a31;
  --line-strong: #363b45;
  --text: #ecedf0;
  --muted: #a0a5ae;
  --faint: #737883;
  --brand: #7d93ff;
  --brand-hover: #95a7ff;
  --on-brand: #0d0e11;
  --brand-soft: rgba(125, 147, 255, .15);
  --brand-text: #a6b4ff;
  --pos: #4ad295;  --pos-soft: rgba(74, 210, 149, .13);
  --warn: #f1b45a; --warn-soft: rgba(241, 180, 90, .13);
  --neg: #f57a7a;  --neg-soft: rgba(245, 122, 122, .13);
  --ring: rgba(125, 147, 255, .35);
  --scrim: rgba(0, 0, 0, .6);
  --shadow-sm: none;
  --shadow-md: 0 0 0 1px rgba(255, 255, 255, .02);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, .6);
  color-scheme: dark;
}
html[data-theme="navy"] {
  --bg: #0a1322;
  --surface: #101c31;
  --surface-2: #15243d;
  --surface-3: #1d2f4d;
  --line: #1e2e4a;
  --line-strong: #2c3f60;
  --text: #eef2f8;
  --muted: #9eabc2;
  --faint: #6f7d96;
  --brand: #f2b33d;              /* gold on navy */
  --brand-hover: #f6c25e;
  --on-brand: #0a1322;
  --brand-soft: rgba(242, 179, 61, .14);
  --brand-text: #f5c463;
  --pos: #4fd39a;  --pos-soft: rgba(79, 211, 154, .13);
  --warn: #f5a35b; --warn-soft: rgba(245, 163, 91, .14);
  --neg: #ff8080;  --neg-soft: rgba(255, 128, 128, .13);
  --ring: rgba(242, 179, 61, .35);
  --scrim: rgba(2, 6, 14, .62);
  --shadow-sm: none;
  --shadow-md: 0 0 0 1px rgba(255, 255, 255, .02);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, .6);
  color-scheme: dark;
}
:root {
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px;
  --side-w: 248px;
  --tabbar-h: 64px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Plex", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 14px; line-height: 1.45; color: var(--text); background: var(--bg);
  display: flex; overflow: hidden;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand-text); text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; display: block; }
[data-icon] { display: inline-grid; place-items: center; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.due { color: var(--neg); font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 36px 12px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--side-w); flex: none; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--line);
  padding: 18px 14px 14px; position: relative; z-index: 3;
}
.brand { display: flex; gap: 11px; align-items: center; padding: 2px 6px 18px; }
.logo {
  width: 36px; height: 36px; border-radius: 10px; flex: none; display: grid; place-items: center;
  background: var(--text); color: var(--bg); font-weight: 700; font-size: 16px;
}
.brand-txt { min-width: 0; }
.brand-name { font-weight: 700; font-size: 13.5px; letter-spacing: .2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.side-actions { display: grid; gap: 8px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.side-actions .btn { justify-content: flex-start; height: 40px; }

nav { display: flex; flex-direction: column; gap: 2px; margin-top: 14px; }
nav button {
  all: unset; cursor: pointer; position: relative; display: flex; align-items: center; gap: 11px;
  min-height: 40px; padding: 0 10px; border-radius: var(--r-sm); color: var(--muted); font-weight: 500;
  transition: background .15s var(--ease), color .15s var(--ease);
}
nav button:hover { background: var(--surface-2); color: var(--text); }
nav button:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
nav button.active { background: var(--brand-soft); color: var(--brand-text); font-weight: 600; }
nav button.active::before { content: ""; position: absolute; left: -14px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--brand); }
nav .ic { width: 20px; }
nav .lb-s { display: none; }
.badge {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; display: inline-grid; place-items: center;
  background: var(--neg); color: #fff; font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums;
}

.account-box { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 12px 6px 4px; border-top: 1px solid var(--line); }
.account-box .avatar { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-text); font-weight: 700; font-size: 12.5px; }
.acc-txt { flex: 1; min-width: 0; }
.acc-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc-email { color: var(--muted); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc-out { all: unset; cursor: pointer; flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); }
.acc-out:hover, .acc-out:focus-visible { background: var(--surface-2); color: var(--text); }
#accSignIn { justify-content: center; }
.side-foot { margin-top: auto; color: var(--faint); font-size: 11.5px; line-height: 1.6; padding: 10px 6px 0; }
.account-box:not([hidden]) + .side-foot { margin-top: 0; }
.side-foot kbd { font-family: inherit; font-size: 10.5px; border: 1px solid var(--line-strong); border-radius: 4px; padding: 0 4px; }

/* ---------- Main + top bar ---------- */
main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; z-index: 1; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 20px 28px 14px; min-height: 76px; }
.title-block { min-width: 0; margin-right: auto; }
.topbar h1 { margin: 0; font-size: 24px; font-weight: 600; letter-spacing: -.3px; line-height: 1.2; }
.view-sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.view-sub:empty { display: none; }
.top-controls, .tb-tools { display: flex; align-items: center; gap: 10px; }
.month-pick { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.month-pick.disabled { opacity: .5; cursor: not-allowed; }
.month-pick.disabled select { cursor: not-allowed; }
.search-box { position: relative; display: flex; align-items: center; }
.search-box > [data-icon] { position: absolute; left: 11px; color: var(--faint); pointer-events: none; }
.search-box svg.i { width: 16px; height: 16px; }
.search-box input { width: 280px; padding-left: 34px !important; }
.icon-btn {
  all: unset; cursor: pointer; width: 40px; height: 40px; border-radius: var(--r-sm); display: none; place-items: center;
  color: var(--muted); border: 1px solid var(--line); background: var(--surface);
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); }
.icon-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
#view { flex: 1; overflow: auto; padding: 4px 28px 48px; }

/* Sync status chip */
.sync-state {
  display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 12px; border-radius: 15px; cursor: pointer; white-space: nowrap;
  font-size: 12.5px; font-weight: 500; color: var(--muted); background: var(--surface); border: 1px solid var(--line);
}
.sync-state::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.sync-state.synced::before { background: var(--pos); }
.sync-state.syncing::before { background: var(--brand); animation: pulse 1s ease-in-out infinite; }
.sync-state.error { color: var(--neg); border-color: color-mix(in srgb, var(--neg) 35%, transparent); }
.sync-state.error::before { background: var(--neg); }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px;
  border-radius: var(--r-sm); border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font-weight: 600; font-size: 13.5px; white-space: nowrap; cursor: pointer;
  transition: background .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease), transform .1s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn svg.i { width: 16px; height: 16px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn.green { background: var(--pos); border-color: var(--pos); color: var(--surface); }
.btn.green:hover { filter: brightness(1.08); }
.btn.danger { color: var(--neg); }
.btn.danger:hover { background: var(--neg-soft); border-color: color-mix(in srgb, var(--neg) 40%, transparent); }
.btn.danger.solid { background: var(--neg); border-color: var(--neg); color: #fff; }
.btn.small { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn.ico { width: 30px; padding: 0; }
.btn.block { width: 100%; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }

input[type=text], input[type=number], input[type=date], input[type=search], input[type=email], input[type=password], select, textarea {
  height: 38px; padding: 0 11px; min-width: 0; border-radius: var(--r-sm);
  background: var(--surface); color: var(--text); border: 1px solid var(--line-strong);
  transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; padding: 8px 11px; }
select { padding-right: 30px; appearance: none; -webkit-appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }
select option { background: var(--surface); color: var(--text); }
input:hover, select:hover, textarea:hover { border-color: var(--faint); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
input::placeholder { color: var(--faint); }
input[readonly] { background: var(--surface-2); color: var(--muted); }
input[type=search]::-webkit-search-cancel-button { cursor: pointer; }

/* ---------- Cards ---------- */
.grid { display: grid; gap: 16px; }
.two { grid-template-columns: 1fr 1fr; }
.three { grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); }
.stack { display: grid; gap: 16px; align-content: start; }
.mb { margin-bottom: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 18px 20px; min-width: 0; box-shadow: var(--shadow-sm); }
.card h2 { margin: 0 0 14px; font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card h2 .hint { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.card h2 .btn { margin-left: auto; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 16px 20px 0; }
@media (max-width: 1250px) {
  .two, .three { grid-template-columns: 1fr; }
  body .overview { grid-template-columns: 1fr 1fr; }
  body .overview > .ov:first-child { grid-column: 1 / -1; }
}
@media (max-width: 1100px) and (min-width: 821px) {
  :root { --side-w: 220px; }
  .topbar, #view { padding-left: 22px; padding-right: 22px; }
  .search-box input { width: 220px; }
}

/* ---------- Dashboard: overview ---------- */
.overview { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr) minmax(0, 1fr); gap: 16px; margin-bottom: 16px; }
.ov { display: flex; flex-direction: column; gap: 4px; }
.ov-label { font-size: 13px; color: var(--muted); font-weight: 500; display: flex; align-items: center; gap: 8px; }
.ov-label .tag { margin-left: auto; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 10px; background: var(--surface-2); color: var(--muted); }
.ov-value { font-size: 34px; font-weight: 600; letter-spacing: -.8px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.ov-value small { font-size: 14px; font-weight: 500; color: var(--muted); letter-spacing: 0; margin-left: 6px; }
.ov.sm .ov-value { font-size: 26px; letter-spacing: -.4px; }
.ov-value.neg { color: var(--neg); }
.ov-sub { font-size: 13px; color: var(--muted); }
.ov-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.ov-stats div { min-width: 0; }
.ov-stats span { display: block; font-size: 12px; color: var(--muted); }
.ov-stats b { display: block; font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ov-lines { display: grid; gap: 8px; margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line); }
.ov-line { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.ov-line span { color: var(--muted); }
.ov-line b { font-weight: 600; font-variant-numeric: tabular-nums; }
.ov-alert { display: inline-flex; align-items: center; gap: 6px; margin-top: auto; padding-top: 14px; font-size: 13px; font-weight: 500; color: var(--warn); }
.ov-alert.ok { color: var(--muted); }
.ov-alert button { all: unset; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* mini month chart */
.spark { display: flex; align-items: flex-end; gap: 6px; height: 56px; margin-top: 14px; }
.spark i { flex: 1; min-width: 4px; max-width: 72px; border-radius: 4px 4px 1px 1px; background: var(--surface-3); position: relative; }
.spark i.cur { background: var(--brand); }
.spark i:hover::after { content: attr(data-t); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); white-space: nowrap;
  background: var(--text); color: var(--bg); font-size: 11.5px; font-style: normal; padding: 3px 7px; border-radius: 6px; z-index: 2; }

/* legacy KPI tiles (kept for any old markup) */
.kpis { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12.5px; }
.kpi .value { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Tables ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-sm); }
.card .table-wrap { border: none; border-radius: 0; box-shadow: none; margin: 0 -20px -18px; }
.card .table-wrap th:first-child, .card .table-wrap td:first-child { padding-left: 20px; }
.card .table-wrap th:last-child, .card .table-wrap td:last-child { padding-right: 20px; }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 0 12px; height: 42px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th {
  height: 38px; background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600;
  position: sticky; top: 0; z-index: 1; user-select: none;
}
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--text); }
th .arr { color: var(--brand-text); margin-left: 3px; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
tfoot td { font-weight: 600; background: var(--surface-2); position: sticky; bottom: 0; border-top: 1px solid var(--line); border-bottom: none; }
.card table th { position: static; }
.card table.simple th { background: transparent; height: 32px; }
.card table.simple td { height: 38px; }
td.wrap { white-space: normal; min-width: 180px; }
td.idx { color: var(--faint); width: 1%; }
.clickable { cursor: pointer; color: var(--text); font-weight: 500; text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 4px; }
.clickable:hover { color: var(--brand-text); text-decoration-color: currentColor; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; opacity: .55; transition: opacity .15s; }
tr:hover .row-actions, .row-actions:focus-within { opacity: 1; }
tr.sel td { background: var(--brand-soft); }
.cust { font-weight: 500; }

.pill { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: 11px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.pill.PAID, .pill.COMPLETED, .pill.USED { background: var(--pos-soft); color: var(--pos); }
.pill.PARTIAL, .pill.HOLD, .pill.ENQUIRY { background: var(--warn-soft); color: var(--warn); }
.pill.PENDING, .pill.CANCELLED, .pill.REFUND, .pill.REFUNDED { background: var(--neg-soft); color: var(--neg); }
.pill.SUBMITTED, .pill.OPEN, .pill.ACTIVE { background: var(--brand-soft); color: var(--brand-text); }
.pill.plain::before { display: none; }

/* ---------- Toolbars & chips ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.toolbar .count { color: var(--muted); font-size: 13px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.seg-chips { display: inline-flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); }
.chip {
  all: unset; cursor: pointer; display: inline-flex; align-items: center; height: 30px; padding: 0 12px; border-radius: 8px;
  font-size: 13px; font-weight: 500; color: var(--muted); white-space: nowrap; transition: background .15s, color .15s;
}
.chip:hover { color: var(--text); }
.chip:focus-visible { outline: 2px solid var(--brand); outline-offset: 0; }
.chip.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow-sm), 0 0 0 1px var(--line); }
.subs { display: flex; flex-wrap: wrap; gap: 6px; }
.subs .chip { height: 30px; border: 1px solid var(--line-strong); border-radius: 15px; background: var(--surface); }
.subs .chip.on { background: var(--brand-soft); color: var(--brand-text); border-color: var(--brand); box-shadow: none; }

/* summary strip above lists */
.sumbar { display: flex; flex-wrap: wrap; gap: 6px 22px; margin: -4px 0 14px; font-size: 13px; color: var(--muted); }
.sumbar b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.sumbar b.due { color: var(--neg); }

/* ---------- Bars (category breakdown) ---------- */
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; align-items: baseline; margin-bottom: 12px; }
.bar-row:last-child { margin-bottom: 0; }
.bar-row .name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .name .muted { font-weight: 400; font-size: 12.5px; }
.bar-row .amt { font-weight: 600; font-variant-numeric: tabular-nums; }
.bar { grid-column: 1 / -1; height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 3px; }

/* ---------- Cash checker ---------- */
.checker { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.checker label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
.check-results { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.check-results div { background: var(--surface-2); border-radius: var(--r-md); padding: 10px 12px; min-width: 0; }
.check-results b { display: block; font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.check-results span { font-size: 12px; color: var(--muted); }
.agent-sum { font-size: 12.5px; line-height: 1.7; color: var(--muted); margin-top: 10px; }
.agent-sum b { color: var(--text); font-weight: 600; }

/* ---------- Mobile list (tables become rows of cards on phones) ---------- */
.mlist { display: none; }
.mrow {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 12px; padding: 13px 16px; border-bottom: 1px solid var(--line);
  background: var(--surface); cursor: pointer; transition: background .1s;
}
.mrow:active { background: var(--surface-2); }
.mrow:last-child { border-bottom: none; }
.mrow .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mrow .a { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.mrow .s { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mrow .r { font-size: 12.5px; text-align: right; font-variant-numeric: tabular-nums; }
.mrow .pills-row { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.mlist-wrap { border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; background: var(--surface); }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; background: var(--scrim); display: grid; place-items: center; z-index: 50; animation: fade .15s var(--ease); }
.modal {
  background: var(--surface); color: var(--text); border-radius: 18px; width: min(980px, 94vw); max-height: 92vh;
  display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow-lg); border: 1px solid var(--line);
  animation: rise .2s var(--ease);
}
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px) scale(.99); } }
.modal.narrow { width: min(480px, 94vw); }
.modal.wide { width: min(1040px, 94vw); }
.modal-head { flex: none; padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.modal-head h3 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -.2px; }
.modal-body { flex: 1 1 auto; min-height: 0; padding: 18px 20px; overflow-y: auto; }
.modal-body p { line-height: 1.55; }
.modal-foot { flex: none; padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; background: var(--surface); }
.x { all: unset; cursor: pointer; width: 36px; height: 36px; border-radius: var(--r-sm); display: grid; place-items: center; color: var(--muted); margin-right: -8px; }
.x:hover { background: var(--surface-2); color: var(--text); }
.x:focus-visible { outline: 2px solid var(--brand); }

/* forms */
.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.form-grid .span2 { grid-column: span 2; }
.form-grid .span4 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.field > input, .field > select, .field > textarea { width: 100%; }
.field.hide { display: none; }
.req { color: var(--neg); font-style: normal; font-weight: 600; }
.field .err { display: none; font-style: normal; font-size: 12px; color: var(--neg); font-weight: 500; }
.field.invalid .err { display: block; }
.field.invalid input, .field.invalid select { border-color: var(--neg) !important; box-shadow: 0 0 0 3px var(--neg-soft) !important; }
.calc {
  height: 38px; display: flex; align-items: center; padding: 0 11px; border-radius: var(--r-sm);
  background: var(--surface-2); font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text);
}
.calc.pos { color: var(--pos); } .calc.neg, .calc.due { color: var(--neg); }

/* New-sale form: 12-column grid */
.sale-form { padding: 0 24px 28px; }
.g12 { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 14px 16px; align-items: start; }
.g12 > .c2 { grid-column: span 2; } .g12 > .c3 { grid-column: span 3; } .g12 > .c4 { grid-column: span 4; }
.g12 > .c6 { grid-column: span 6; } .g12 > .c12 { grid-column: 1 / -1; }
.fsec { display: flex; align-items: baseline; justify-content: space-between; margin-top: 18px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.fsec:first-child { margin-top: 16px; }
.fsec h4 { margin: 0; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.fsec span { font-size: 12px; color: var(--muted); }
.fp-wrap { margin-top: 24px; }
.fp-wrap .btn { height: 38px; width: 100%; }
.picker { grid-column: 1 / -1; display: grid; gap: 8px; }
.picker-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.picker-label { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.popt {
  all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 13px 0 10px; border-radius: 18px;
  font-size: 13px; font-weight: 500; color: var(--text); background: var(--surface); border: 1px solid var(--line-strong); white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.popt .pi { display: grid; place-items: center; color: var(--muted); }
.popt .pi svg.i { width: 16px; height: 16px; }
.popt:hover { border-color: var(--faint); }
.popt:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.popt.on { background: var(--brand-soft); color: var(--brand-text); border-color: var(--brand); font-weight: 600; }
.popt.on .pi { color: var(--brand-text); }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; padding: 3px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--line); }
.seg button { all: unset; cursor: pointer; text-align: center; height: 36px; border-radius: 8px; font-weight: 500; color: var(--muted); font-size: 13px; display: flex; align-items: center; justify-content: center; gap: 7px; }
.seg button:hover { color: var(--text); }
.seg button:focus-visible { box-shadow: 0 0 0 3px var(--ring); }
.seg button i { width: 8px; height: 8px; border-radius: 50%; }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow-sm), 0 0 0 1px var(--line); }
.profit-pill { border-radius: 11px; height: 24px; display: inline-flex; align-items: center; padding: 0 10px; font-weight: 600; font-size: 12.5px; background: var(--pos-soft); color: var(--pos); font-variant-numeric: tabular-nums; }
.profit-pill.neg { background: var(--neg-soft); color: var(--neg); }

/* ---------- Settings ---------- */
.set-grid { display: grid; gap: 16px; max-width: 920px; }
.lists-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.list-edit ul { list-style: none; margin: 0 0 8px; padding: 0; max-height: 240px; overflow: auto; border: 1px solid var(--line); border-radius: var(--r-sm); }
.list-edit li { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; border-bottom: 1px solid var(--line); gap: 8px; }
.list-edit li:last-child { border-bottom: none; }
.list-edit li button { all: unset; cursor: pointer; color: var(--neg); font-weight: 700; padding: 0 4px; }
.list-edit .add { display: flex; gap: 6px; }
.list-edit .add input { flex: 1; }
.data-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.path { font-family: Consolas, monospace; font-size: 12px; background: var(--surface-2); padding: 2px 6px; border-radius: 4px; }
.theme-opts { display: flex; gap: 12px; flex-wrap: wrap; }
.theme-opt {
  all: unset; cursor: pointer; display: flex; flex-direction: column; gap: 10px; width: 150px; padding: 10px; border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--surface); font-weight: 500; font-size: 13px; transition: border-color .15s;
}
.theme-opt:hover { border-color: var(--faint); }
.theme-opt:focus-visible { box-shadow: 0 0 0 3px var(--ring); }
.theme-opt.on { border: 2px solid var(--brand); padding: 9px; font-weight: 600; }
.theme-opt .sw { height: 64px; border-radius: 8px; display: grid; grid-template-columns: 30% 1fr; gap: 6px; padding: 6px; border: 1px solid rgba(127,127,127,.2); }
.theme-opt .sw b { border-radius: 4px; }
.theme-opt .sw span { display: grid; gap: 5px; align-content: start; }
.theme-opt .sw i { height: 8px; border-radius: 3px; }
.theme-opt .sw i:last-child { width: 45%; }

/* ---------- Welcome (empty dashboard) ---------- */
#view.empty-canvas { display: grid; place-items: center; }
.welcome { max-width: 560px; margin: 24px auto; text-align: center; padding: 36px 32px; }
.welcome .wl-ic { width: 56px; height: 56px; margin: 0 auto 16px; border-radius: 16px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-text); }
.welcome .wl-ic svg.i { width: 26px; height: 26px; }
.welcome h2 { font-size: 22px; font-weight: 600; letter-spacing: -.3px; margin: 0 0 8px; display: block; }
.welcome p { color: var(--muted); line-height: 1.6; margin: 0 0 20px; }
.welcome .wl-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.welcome .wl-actions .btn { height: 42px; padding: 0 18px; }
.welcome .wl-foot { font-size: 12.5px; margin: 20px 0 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 60; max-width: calc(100vw - 32px);
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 10px; font-weight: 500; box-shadow: var(--shadow-lg);
  animation: rise .2s var(--ease);
}
.toast.err { background: var(--neg); color: #fff; }

/* ---------- Sign-in page ---------- */
.auth-screen { position: fixed; inset: 0; z-index: 45; display: grid; place-items: center; padding: 16px; overflow: auto; background: var(--bg); }
.auth-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 28px 28px 20px; box-shadow: var(--shadow-md); }
.auth-brand { display: flex; gap: 11px; align-items: center; margin-bottom: 22px; }
.auth-company { font-weight: 700; letter-spacing: .2px; }
.auth-card h2 { margin: 0 0 6px; font-size: 22px; font-weight: 600; letter-spacing: -.3px; }
.auth-card p { margin: 0 0 18px; line-height: 1.55; font-size: 13.5px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-card input { height: 42px; font-size: 15px; }
.auth-go { height: 44px; font-size: 15px; margin-top: 2px; }
.auth-msg { color: var(--neg); font-size: 13px; }
.auth-msg:empty { display: none; }
.auth-msg.ok { color: var(--pos); }
.auth-links { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-top: 16px; font-size: 13px; }
.auth-links a { color: var(--brand-text); text-decoration: none; font-weight: 600; }
.auth-links a:hover { text-decoration: underline; }
.auth-skip { all: unset; cursor: pointer; display: block; margin: 20px auto 0; font-size: 13px; color: var(--muted); }
.auth-skip:hover { color: var(--text); text-decoration: underline; }

/* ---------- FAB (phones) ---------- */
.fab { display: none; }

/* ---------- Windows app: custom title bar ---------- */
.titlebar { display: none; }
html.desktop .titlebar {
  display: flex; align-items: center; gap: 10px; position: fixed; top: 0; left: 0; right: 0; height: 38px; z-index: 30;
  padding: 0 150px 0 16px; background: var(--surface); border-bottom: 1px solid var(--line); color: var(--text); font-size: 12.5px; font-weight: 600;
  -webkit-app-region: drag; user-select: none;
}
html.desktop .tb-logo { width: 18px; height: 18px; border-radius: 5px; background: var(--text); color: var(--bg); display: grid; place-items: center; font-size: 10px; font-weight: 700; }
html.desktop body { padding-top: 38px; }
html.desktop .modal-back, html.desktop .auth-screen { top: 38px; }

/* =====================================================================
   Phones & small tablets
   ===================================================================== */
@media (max-width: 820px) {
  body { flex-direction: column; height: 100dvh; }
  input, select, textarea { font-size: 16px !important; }   /* stops iOS zoom */

  /* sidebar becomes a bottom tab bar */
  .sidebar {
    position: fixed; left: 0; right: 0; bottom: 0; width: auto; z-index: 40; padding: 0 4px env(safe-area-inset-bottom);
    border-right: none; border-top: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  }
  .brand, .side-actions, .account-box, .side-foot, nav .nav-settings { display: none !important; }
  nav { flex-direction: row; margin: 0; gap: 0; height: var(--tabbar-h); }
  nav button {
    flex: 1; flex-direction: column; justify-content: center; gap: 3px; min-height: 0; padding: 0 2px; border-radius: 0;
    font-size: 11px; font-weight: 500; color: var(--muted);
  }
  nav button:hover { background: transparent; }
  nav button.active { background: transparent; color: var(--brand-text); font-weight: 600; }
  nav button.active::before { display: none; }
  nav button .ic { width: 24px; }
  nav button.active .ic { background: var(--brand-soft); border-radius: 14px; width: 52px; height: 28px; }
  nav .ic svg.i { width: 21px; height: 21px; }
  nav .lb { display: none; }
  nav .lb-s { display: block; }
  nav .badge { position: absolute; top: 6px; left: calc(50% + 6px); margin: 0; min-width: 18px; height: 18px; font-size: 10.5px; }

  main { min-height: 0; flex: 1; }
  .topbar {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: calc(12px + env(safe-area-inset-top)) 16px 10px; min-height: 0;
    border-bottom: 1px solid var(--line); background: var(--surface);
  }
  .title-block { grid-column: 1; grid-row: 1; align-self: center; }
  .topbar h1 { font-size: 20px; }
  .view-sub { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .tb-tools { grid-column: 2; grid-row: 1; gap: 8px; }
  .icon-btn { display: grid; }
  .sync-state { height: 32px; padding: 0 10px; font-size: 0; gap: 0; }        /* dot only */
  .sync-state::before { width: 9px; height: 9px; }
  .top-controls { grid-column: 1 / -1; grid-row: 2; gap: 8px; }
  .top-controls:not(:has(> :not([hidden]))) { display: none; }
  .month-pick { flex: 0 0 auto; }
  .month-pick .mp-lb { display: none; }
  .month-pick select { height: 38px; max-width: 46vw; }
  .search-box { flex: 1; min-width: 0; }
  .search-box input { width: 100%; height: 38px; }

  #view { padding: 14px 14px calc(var(--tabbar-h) + 96px + env(safe-area-inset-bottom)); }
  .grid, .stack { gap: 12px; }
  .mb { margin-bottom: 12px; }
  .card { padding: 16px; border-radius: 14px; }
  .card .table-wrap { margin: 0 -16px -16px; }
  .card .table-wrap th:first-child, .card .table-wrap td:first-child { padding-left: 16px; }
  .card .table-wrap th:last-child, .card .table-wrap td:last-child { padding-right: 16px; }

  body .overview { grid-template-columns: 1fr; gap: 12px; margin-bottom: 12px; }
  .ov-value { font-size: 30px; }
  .ov.sm .ov-value { font-size: 24px; }
  .ov-alert { padding-top: 10px; }
  .ov-stats b { font-size: 15px; }
  .spark { height: 44px; }

  .checker, .check-results { grid-template-columns: 1fr; }
  .check-results { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .check-results b { font-size: 15px; }

  /* lists instead of wide tables */
  .dt { display: none !important; }
  .mlist { display: block; }

  .toolbar { gap: 8px; margin-bottom: 12px; }
  .toolbar > select { flex: 1 1 40%; }
  .toolbar .spacer, .toolbar .add-btn { display: none; }
  .scroll-x { overflow-x: auto; scrollbar-width: none; margin: 0 -14px; padding: 0 14px; max-width: calc(100% + 28px); }
  .scroll-x::-webkit-scrollbar { display: none; }
  .seg-chips { flex-wrap: nowrap; }

  .fab {
    display: grid; place-items: center; position: fixed; right: 16px; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); z-index: 41;
    width: 56px; height: 56px; border-radius: 18px; border: none; background: var(--brand); color: var(--on-brand); cursor: pointer;
    box-shadow: 0 8px 24px color-mix(in srgb, var(--brand) 40%, transparent);
  }
  .fab svg.i { width: 26px; height: 26px; stroke-width: 2.2; }
  .toast { bottom: calc(var(--tabbar-h) + 88px + env(safe-area-inset-bottom)); }

  /* sheets go full screen */
  .modal-back { place-items: end stretch; }
  .modal, .modal.narrow, .modal.wide { width: 100vw; max-height: 100dvh; border-radius: 18px 18px 0 0; border: none; }
  .modal.wide { height: 100dvh; border-radius: 0; }
  .modal-head { padding: calc(12px + env(safe-area-inset-top)) 16px 12px; }
  .modal.narrow .modal-head { padding-top: 14px; }
  .modal-body { padding: 16px; }
  .modal-foot { flex-wrap: wrap; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1; height: 44px; }
  .form-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .form-grid .span2 { grid-column: 1 / -1; }
  .sale-form { padding: 0 16px 28px; }
  .g12 { gap: 12px; }
  .g12 > .c2, .g12 > .c3, .g12 > .c4, .g12 > .c6 { grid-column: 1 / -1; }
  .g12 > .half, .g12 > .c2 { grid-column: span 6; }
  .g12 > .fp-wrap { margin-top: 0; }
  #prodTiles { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 2px 16px 4px; }
  #prodTiles::-webkit-scrollbar { display: none; }
  .seg button { font-size: 12.5px; }

  .data-actions .btn { flex: 1 1 45%; }
  .theme-opt { width: calc(50% - 6px); }
  .welcome { padding: 28px 20px; margin: 8px auto; }
  html.desktop body { padding-top: 0; }
}
@media (max-width: 380px) {
  .check-results { grid-template-columns: 1fr; }
}

/* ---------- Sahvanta logo (from the Figma logo file) ---------- */
img.logo { width: 36px; height: 36px; border-radius: 0; background: none; display: block; flex: none; }
.auth-brand { margin-bottom: 26px; }
.auth-logo { height: 34px; width: auto; display: block; }
.wm-dark { display: none; }
html[data-theme="dark"] .wm-light, html[data-theme="navy"] .wm-light { display: none; }
html[data-theme="dark"] .wm-dark, html[data-theme="navy"] .wm-dark { display: block; }
.wl-logo { width: 64px; height: 64px; display: block; margin: 0 auto 18px; }
html.desktop img.tb-logo { width: 18px; height: 18px; background: none; border-radius: 0; }
