/* ================================================================
   BMD ERP — design tokens
   ================================================================ */
:root {
  color-scheme: light;
  --canvas: #f7f7f5;
  --surface: #ffffff;
  --surface-sunken: #f2f1ee;
  --surface-hover: #f5f4f1;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #898781;
  --line: #e8e7e2;
  --line-strong: #d6d5ce;
  --grid: #ecebe6;
  --axis: #c3c2b7;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-wash: #eaf2fd;
  --on-accent: #ffffff;
  --sales: #2a78d6;
  --purchase: #eb6834;
  --good: #006300;
  --good-wash: #e7f4e7;
  --critical: #c73232;
  --critical-wash: #fcecec;
  --warn-wash: #fdf6e4;
  --warn-line: #f0dfb0;
  --neutral-wash: #f0efec;
  --age-1: #86b6ef; --age-2: #5598e7; --age-3: #2a78d6; --age-4: #1c5cab; --age-5: #104281; --age-6: #0d366b;
  --shadow-1: 0 1px 2px rgba(16, 16, 12, 0.04);
  --shadow-pop: 0 12px 40px rgba(16, 16, 12, 0.16), 0 2px 6px rgba(16, 16, 12, 0.06);
  --scrim: rgba(18, 18, 14, 0.36);
  --skeleton: #efeee9;
  --skeleton-hi: #f7f6f2;

  --font: system-ui, "Segoe UI Variable Text", "Segoe UI", -apple-system, Roboto, "Helvetica Neue", sans-serif;
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px;
  --sidebar: 248px;
  --gutter: 32px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --canvas: #111110; --surface: #1a1a19; --surface-sunken: #151514; --surface-hover: #222220;
    --text: #f6f6f4; --text-2: #c3c2b7; --text-3: #8d8b84; --line: #2a2a28; --line-strong: #3a3a37;
    --grid: #262624; --axis: #3a3a37; --accent: #3987e5; --accent-ink: #86b6ef; --accent-wash: #16263b; --on-accent: #ffffff;
    --sales: #3987e5; --purchase: #d95926; --good: #3cc23c; --good-wash: #15291a; --critical: #ef7a7a; --critical-wash: #331b1b;
    --warn-wash: #2b2516; --warn-line: #4a3f22; --neutral-wash: #262624;
    --age-1: #184f95; --age-2: #256abf; --age-3: #3987e5; --age-4: #6da7ec; --age-5: #9ec5f4; --age-6: #cde2fb;
    --shadow-1: none; --shadow-pop: 0 16px 48px rgba(0, 0, 0, 0.5); --scrim: rgba(0, 0, 0, 0.55);
    --skeleton: #222220; --skeleton-hi: #2a2a28;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #111110; --surface: #1a1a19; --surface-sunken: #151514; --surface-hover: #222220;
  --text: #f6f6f4; --text-2: #c3c2b7; --text-3: #8d8b84; --line: #2a2a28; --line-strong: #3a3a37;
  --grid: #262624; --axis: #3a3a37; --accent: #3987e5; --accent-ink: #86b6ef; --accent-wash: #16263b; --on-accent: #ffffff;
  --sales: #3987e5; --purchase: #d95926; --good: #3cc23c; --good-wash: #15291a; --critical: #ef7a7a; --critical-wash: #331b1b;
  --warn-wash: #2b2516; --warn-line: #4a3f22; --neutral-wash: #262624;
  --age-1: #184f95; --age-2: #256abf; --age-3: #3987e5; --age-4: #6da7ec; --age-5: #9ec5f4; --age-6: #cde2fb;
  --shadow-1: none; --shadow-pop: 0 16px 48px rgba(0, 0, 0, 0.5); --scrim: rgba(0, 0, 0, 0.55);
  --skeleton: #222220; --skeleton-hi: #2a2a28;
}

/* ================================================================
   Base
   ================================================================ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--canvas); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.num { font-variant-numeric: tabular-nums; }

/* ================================================================
   Shell
   ================================================================ */
.app { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); z-index: 20;
  display: flex; flex-direction: column; gap: 18px; padding: 20px 14px 14px;
  background: var(--surface); border-right: 1px solid var(--line);
}
.main { margin-left: var(--sidebar); min-width: 0; }

.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.logo { display: block; width: 34px; height: 34px; flex: none; border-radius: 7px; background: #fff; box-shadow: 0 0 0 1px var(--line); }
.logo-lg { width: 96px; height: 96px; border-radius: 14px; box-shadow: var(--shadow-pop); }
.mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; font-weight: 700; font-size: 15px; letter-spacing: -.02em; flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-weight: 650; font-size: 15px; letter-spacing: -.01em; }
.brand-sub { color: var(--text-3); font-size: 12px; }

.company-picker { position: relative; display: block; margin: 0 2px; }
.company-picker select {
  appearance: none; width: 100%; border: 1px solid var(--line); background: var(--surface-sunken);
  border-radius: var(--r-sm); padding: 7px 30px 7px 10px; font-size: 12.5px; color: var(--text-2);
  text-overflow: ellipsis; white-space: nowrap; overflow: hidden;
}
.company-picker .i { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-3); pointer-events: none; }

.side-nav { display: flex; flex-direction: column; gap: 1px; flex: 1; }
.nav-heading { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); padding: 14px 10px 6px; }
.side-nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--r-sm); color: var(--text-2); font-weight: 500; transition: background .15s, color .15s; }
.side-nav a:hover { background: var(--surface-hover); color: var(--text); }
.side-nav a[aria-current="page"] { background: var(--accent-wash); color: var(--accent-ink); }
.side-nav a[aria-current="page"] .i { color: var(--accent); }

.side-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 6px 0; border-top: 1px solid var(--line); }
.conn { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-3); min-width: 0; }
.conn-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; box-shadow: 0 0 0 3px var(--neutral-wash); }
.conn.ok .dot { background: #0ca30c; box-shadow: 0 0 0 3px var(--good-wash); }
.conn.err .dot { background: #d03b3b; box-shadow: 0 0 0 3px var(--critical-wash); }
.conn.busy .dot { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.side-actions { display: flex; gap: 2px; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: var(--r-sm); border: 0; background: transparent; color: var(--text-2); transition: background .15s, color .15s; }
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }

/* Mobile app bar & tab bar (hidden on desktop) */
.appbar, .tabbar { display: none; }

/* ================================================================
   Page header & period control
   ================================================================ */
.page-head {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px 24px; flex-wrap: wrap;
  padding: 26px var(--gutter) 18px; background: color-mix(in srgb, var(--canvas) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid transparent; transition: border-color .2s;
}
.page-head.scrolled { border-bottom-color: var(--line); }
.titles h1 { font-size: 24px; font-weight: 650; letter-spacing: -.02em; line-height: 1.2; }
.page-sub { color: var(--text-3); font-size: 13px; margin-top: 4px; }
.period { display: flex; gap: 8px; align-items: center; }

.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-sunken); border: 1px solid var(--line); border-radius: 9px; }
.seg button {
  display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; color: var(--text-2);
  padding: 5px 11px; border-radius: 6px; font-size: 13px; font-weight: 500; white-space: nowrap; transition: background .15s, color .15s, box-shadow .15s;
}
.seg button .i { width: 15px; height: 15px; }
.seg .short { display: none; }
.seg button:hover { color: var(--text); }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 0 0 1px var(--line); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font-weight: 550; font-size: 13px; transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: var(--surface-hover); }
.btn:active { transform: translateY(1px); }
.btn .i { width: 16px; height: 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-hover); color: var(--text); }
.spinning .i { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ================================================================
   Content layout
   ================================================================ */
.view { padding: 8px var(--gutter) 56px; max-width: 1440px; outline: none; }
.fade-in > * { animation: rise .35s var(--ease) both; }
.fade-in > *:nth-child(2) { animation-delay: .03s; }
.fade-in > *:nth-child(3) { animation-delay: .06s; }
.fade-in > *:nth-child(4) { animation-delay: .09s; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { .fade-in > * { animation: none; } .spinning .i, .conn.busy .dot { animation: none; } }

.stack { display: grid; gap: 16px; }
.row { display: grid; gap: 16px; grid-template-columns: repeat(12, minmax(0, 1fr)); }
.row > [class*="span-"] { display: flex; flex-direction: column; }
.row > [class*="span-"] > .card { flex: 1; }
.span-4 { grid-column: span 4; } .span-5 { grid-column: span 5; } .span-6 { grid-column: span 6; }
.span-7 { grid-column: span 7; } .span-8 { grid-column: span 8; } .span-12 { grid-column: span 12; }

/* KPI tiles */
.kpis { display: grid; gap: 16px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpi {
  position: relative; display: flex; flex-direction: column; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px 18px 14px; box-shadow: var(--shadow-1);
}
a.kpi { transition: border-color .15s, box-shadow .15s; }
a.kpi:hover { border-color: var(--line-strong); }
.kpi-label { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text-2); font-weight: 500; }
.kpi-label .sw { width: 8px; height: 8px; border-radius: 2px; }
.kpi-label .go { margin-left: auto; width: 16px; height: 16px; color: var(--text-3); opacity: 0; transition: opacity .15s, transform .15s; }
a.kpi:hover .go { opacity: 1; transform: translateX(2px); }
.kpi-value { font-size: 28px; font-weight: 650; letter-spacing: -.025em; line-height: 1.15; margin-top: 8px; white-space: nowrap; }
.kpi-value.crit { color: var(--critical); }
.kpi-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; font-size: 12.5px; color: var(--text-3); min-height: 20px; }
.kpi-foot b { color: var(--text-2); font-weight: 600; }
.kpi .spark { display: block; width: 100%; height: 32px; margin-top: 10px; }

.delta { display: inline-flex; align-items: center; gap: 2px; padding: 1px 7px 1px 4px; border-radius: 999px; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; background: var(--neutral-wash); color: var(--text-2); }
.delta .i { width: 14px; height: 14px; stroke-width: 2.25; }
.delta.good { background: var(--good-wash); color: var(--good); }
.delta.bad { background: var(--critical-wash); color: var(--critical); }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-1); min-width: 0; display: flex; flex-direction: column; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 18px 0; flex-wrap: wrap; }
.card-head h2 { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.card-head p { color: var(--text-3); font-size: 12.5px; margin-top: 2px; }
.card-body { padding: 14px 18px 18px; flex: 1; min-width: 0; }
.card-body.flush { padding: 8px 0 6px; }
.card-link { font-size: 12.5px; font-weight: 550; color: var(--accent-ink); display: inline-flex; align-items: center; gap: 2px; white-space: nowrap; }
.card-link .i { width: 15px; height: 15px; }
.card-link:hover { text-decoration: underline; text-underline-offset: 3px; }

.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }

/* Callout */
.callout { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-radius: var(--r-md); background: var(--warn-wash); border: 1px solid var(--warn-line); font-size: 13px; color: var(--text); }
.callout .i { color: #b07d00; margin-top: 1px; }
.callout p + p { margin-top: 4px; }

/* ================================================================
   Charts
   ================================================================ */
.chart-wrap { position: relative; width: 100%; }
svg.chart { display: block; width: 100%; overflow: visible; }
svg.chart text { fill: var(--text-3); font-size: 11.5px; font-variant-numeric: tabular-nums; font-family: var(--font); }
svg.chart .gridline { stroke: var(--grid); }
svg.chart .baseline { stroke: var(--axis); }
svg.chart .hit { fill: transparent; }
svg.chart .hover-band { fill: var(--text); opacity: 0; transition: opacity .12s; }
svg.chart .col:hover .hover-band { opacity: .04; }

/* Ageing: segmented bar + legend list */
.ageing-bar { display: flex; gap: 2px; height: 12px; margin: 4px 0 16px; }
.ageing-bar span { height: 100%; min-width: 3px; }
.ageing-bar span:first-child { border-radius: 4px 0 0 4px; }
.ageing-bar span:last-child { border-radius: 0 4px 4px 0; }
.ageing-bar span:only-child { border-radius: 4px; }
.ageing-list { display: grid; gap: 2px; }
.ageing-row { display: grid; grid-template-columns: 12px 1fr auto 48px; gap: 10px; align-items: center; padding: 6px 0; font-size: 13px; border-radius: 6px; }
.ageing-row .lab { color: var(--text-2); }
.ageing-row .amt { font-weight: 550; font-variant-numeric: tabular-nums; text-align: right; }
.ageing-row .pct { color: var(--text-3); font-variant-numeric: tabular-nums; text-align: right; font-size: 12px; }
.ageing-row .cnt { color: var(--text-3); font-size: 12px; margin-left: 6px; }
.ageing-total { display: flex; justify-content: space-between; padding-top: 10px; margin-top: 6px; border-top: 1px solid var(--line); font-size: 13px; color: var(--text-2); }
.ageing-total b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ================================================================
   Lists (ranked + parties) — one responsive component, no tables
   ================================================================ */
.list { list-style: none; margin: 0; padding: 0; }
.li { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; padding: 10px 18px; border-top: 1px solid var(--line); }
.list .li:first-child { border-top: 0; }
.li .rank { color: var(--text-3); font-size: 12px; font-variant-numeric: tabular-nums; align-self: start; padding-top: 1px; }
.li .who { min-width: 0; }
.li .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.li .meta { color: var(--text-3); font-size: 12px; margin-top: 1px; }
.li .val { text-align: right; font-weight: 550; font-variant-numeric: tabular-nums; white-space: nowrap; }
.li .val small { display: block; font-weight: 450; font-size: 12px; color: var(--text-3); }
.li .share { grid-column: 2 / 4; height: 4px; border-radius: 2px; background: var(--surface-sunken); overflow: hidden; margin-top: 4px; }
.li .share i { display: block; height: 100%; border-radius: 0 2px 2px 0; }

button.li { width: 100%; text-align: left; border: 0; border-top: 1px solid var(--line); background: transparent; color: inherit; font: inherit; grid-template-columns: minmax(0, 1fr) auto 18px; transition: background .12s; }
button.li:hover { background: var(--surface-hover); }
button.li .chev { color: var(--text-3); width: 16px; height: 16px; }
.li .val .od { color: var(--critical); font-weight: 550; }
a.li { grid-template-columns: minmax(0, 1fr) auto 18px; transition: background .12s; }
a.li:hover { background: var(--surface-hover); }
a.li .chev { color: var(--text-3); width: 16px; height: 16px; }
.li a.name:hover, .txn a.name:hover { color: var(--accent-ink); text-decoration: underline; text-underline-offset: 3px; }

/* ================================================================
   Ledgers
   ================================================================ */
.recent { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 10px 18px; border-bottom: 1px solid var(--line); font-size: 12px; color: var(--text-3); }
.recent > span { margin-right: 4px; font-weight: 550; }
.chip.link { max-width: 260px; overflow: hidden; text-overflow: ellipsis; padding: 3px 10px; font-size: 12px; transition: background .12s, color .12s; }
.chip.link:hover { background: var(--accent-wash); color: var(--accent-ink); }

.back-link { display: inline-flex; align-items: center; gap: 2px; justify-self: start; margin: -4px 0 -6px -4px; color: var(--text-2); font-size: 13px; font-weight: 550; }
.back-link:hover { color: var(--accent-ink); }
.back-link .i { width: 17px; height: 17px; }

.btn.small { height: 30px; padding: 0 11px; font-size: 12.5px; }
.btn.small .i { width: 15px; height: 15px; }

.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-1); }
.stats div { background: var(--surface); padding: 12px 18px; min-width: 0; }
.stats span { display: block; font-size: 12px; color: var(--text-3); }
.stats b { display: block; font-size: 17px; font-weight: 650; letter-spacing: -.01em; font-variant-numeric: tabular-nums; margin-top: 2px; white-space: nowrap; }

.drawer-link { display: flex; align-items: center; gap: 10px; padding: 12px 20px; border-bottom: 1px solid var(--line); color: var(--accent-ink); font-weight: 550; transition: background .12s; }
.drawer-link:hover { background: var(--surface-hover); }
.drawer-link span { flex: 1; }
.drawer-link .chev { width: 16px; height: 16px; color: var(--text-3); }

/* Statement: a grid that reads like a ledger on desktop and stacks on phones */
.txns { font-variant-numeric: tabular-nums; }
.txn { display: grid; grid-template-columns: 86px minmax(0, 1fr) 108px 108px 128px; gap: 2px 12px; align-items: start; padding: 10px 18px; border-top: 1px solid var(--line); font-size: 13px; }
.txns .txn:first-child { border-top: 0; }
.txn .dr, .txn .cr, .txn .bal { text-align: right; white-space: nowrap; }
.txn .dr { color: var(--text); font-weight: 550; }
.txn .cr { color: var(--text); font-weight: 550; }
.txn .bal { color: var(--text-2); }
.txn .date { color: var(--text-2); white-space: nowrap; }
.txn .part { min-width: 0; }
.txn .name { font-weight: 550; }
.txn .more { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 999px; background: var(--neutral-wash); color: var(--text-3); font-size: 11px; font-weight: 600; vertical-align: 1px; }
.txn .meta { display: block; color: var(--text-3); font-size: 12px; }
.txn .m-date { display: none; }
.txn .narr { display: block; color: var(--text-3); font-size: 12px; font-style: italic; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.txn.open .narr { white-space: normal; }
.txn[tabindex] { cursor: default; transition: background .12s; }
.txn[tabindex]:hover { background: var(--surface-hover); }
.txn[tabindex]:has(.narr) { cursor: pointer; }
.txn.head { padding-top: 10px; padding-bottom: 8px; font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-3); background: var(--surface-sunken); }
.txn.head span { color: var(--text-3); font-weight: 600; }
.txn.edge { background: var(--surface-sunken); }
.txn.edge .bal { color: var(--text); font-weight: 650; }
.txn.total { border-top: 1px solid var(--line-strong); font-weight: 650; }
.txn.total .dr, .txn.total .cr { font-weight: 650; }

svg.chart .pt { stroke: var(--surface); stroke-width: 2; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 550; background: var(--neutral-wash); color: var(--text-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.chip.crit { background: var(--critical-wash); color: var(--critical); }
.chip.good { background: var(--good-wash); color: var(--good); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 14px 18px 12px; border-bottom: 1px solid var(--line); }
.search { position: relative; flex: 1 1 220px; max-width: 340px; }
.search .i { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-3); pointer-events: none; }
.search input { width: 100%; height: 34px; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: 0 10px 0 32px; font-size: 13px; }
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.filters { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.filters button { height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text-2); font-size: 12.5px; font-weight: 500; }
.filters button[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--surface); }
.sort { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; color: var(--text-3); font-size: 12.5px; }
.sort select { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; height: 30px; padding: 0 8px; font-size: 12.5px; color: var(--text); }
.list-foot { padding: 10px 18px 14px; color: var(--text-3); font-size: 12px; border-top: 1px solid var(--line); }
.empty { padding: 28px 18px; text-align: center; color: var(--text-3); }

/* ================================================================
   Dialogs: custom range (popover) + party drawer / bottom sheet
   ================================================================ */
dialog.sheet { padding: 0; border: 1px solid var(--line); background: var(--surface); color: var(--text); box-shadow: var(--shadow-pop); }
dialog.sheet::backdrop { background: var(--scrim); backdrop-filter: blur(2px); }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 14px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.eyebrow { font-size: 11.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); margin-bottom: 2px; }
.sheet-body { padding: 18px 20px; overflow: auto; }
.sheet-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--line); }

dialog.small { width: min(380px, calc(100vw - 32px)); border-radius: var(--r-lg); }
.range-fields { display: grid; gap: 14px; }
.range-fields label { display: grid; gap: 6px; font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.range-fields input { height: 38px; border: 1px solid var(--line-strong); border-radius: 8px; padding: 0 10px; background: var(--surface); }

dialog.drawer {
  margin: 0 0 0 auto; height: 100vh; max-height: 100vh; width: min(520px, 100vw); border-radius: 0; border-width: 0 0 0 1px;
  display: none; flex-direction: column;
}
dialog.drawer[open] { display: flex; animation: slide-in .28s var(--ease); }
@keyframes slide-in { from { transform: translateX(32px); } }
.drawer .sheet-body { flex: 1; padding: 0; }
.drawer-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--line); border-bottom: 1px solid var(--line); }
.drawer-stats div { background: var(--surface); padding: 14px 20px; }
.drawer-stats span { display: block; font-size: 12px; color: var(--text-3); }
.drawer-stats b { display: block; font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; letter-spacing: -.01em; }
.drawer-stats b.crit { color: var(--critical); }
.drawer h3 { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); padding: 18px 20px 6px; }
.bill { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 11px 20px; border-top: 1px solid var(--line); }
.bill .ref { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bill .amt { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.bill .dates { color: var(--text-3); font-size: 12px; }
.bill .tags { text-align: right; }
.bill.credit .amt { color: var(--good); }

/* ================================================================
   Tooltip
   ================================================================ */
.tooltip {
  position: fixed; z-index: 100; pointer-events: none; min-width: 160px;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 12.5px; box-shadow: var(--shadow-pop); font-variant-numeric: tabular-nums;
}
.tooltip .t { font-weight: 600; margin-bottom: 6px; }
.tooltip .r { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 1px 0; }
.tooltip .r span { display: inline-flex; align-items: center; gap: 7px; color: var(--text-2); }
.tooltip .r b { font-weight: 600; }

/* ================================================================
   Loading & error states
   ================================================================ */
.sk { background: linear-gradient(90deg, var(--skeleton) 0%, var(--skeleton-hi) 50%, var(--skeleton) 100%); background-size: 200% 100%; animation: shimmer 1.3s linear infinite; border-radius: 6px; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .sk { animation: none; } }
.sk-line { height: 12px; }
.sk-value { height: 28px; width: 60%; margin-top: 12px; }
.sk-block { height: 260px; }

.state { max-width: 460px; margin: 64px auto; text-align: center; padding: 0 16px; }
.state .badge { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; margin: 0 auto 18px; background: var(--critical-wash); color: var(--critical); }
.state .badge .i { width: 26px; height: 26px; }
.state h2 { font-size: 18px; font-weight: 650; letter-spacing: -.01em; }
.state p { color: var(--text-2); margin-top: 8px; }
.state ol { text-align: left; color: var(--text-2); margin: 18px auto 22px; padding-left: 20px; max-width: 360px; }
.state li + li { margin-top: 6px; }

/* ================================================================
   Sign-in page
   ================================================================ */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background:
  radial-gradient(900px 480px at 50% -10%, var(--accent-wash), transparent 70%), var(--canvas); }
.auth { width: 100%; max-width: 400px; }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 24px; }
.auth-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px 28px 24px; box-shadow: var(--shadow-pop); }
.auth-card h1 { font-size: 22px; font-weight: 650; letter-spacing: -.02em; }
.auth-lead { color: var(--text-2); margin: 8px 0 22px; }
.auth-lead b { color: var(--text); font-weight: 600; }
.btn.block { width: 100%; height: 44px; font-size: 14px; }
.btn:disabled { opacity: .6; cursor: progress; }
.otp {
  display: block; width: 100%; height: 60px; margin-bottom: 14px; text-align: center;
  font-size: 30px; font-weight: 650; letter-spacing: .5em; text-indent: .5em; font-variant-numeric: tabular-nums;
  border: 1px solid var(--line-strong); border-radius: 12px; background: var(--surface-sunken);
}
.otp::placeholder { color: var(--line-strong); }
.otp:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; background: var(--surface); }
.auth-msg { margin-top: 14px; font-size: 13px; padding: 9px 12px; border-radius: 8px; }
.auth-msg.err { background: var(--critical-wash); color: var(--critical); }
.auth-msg.ok { background: var(--good-wash); color: var(--good); }
.auth-foot { margin-top: 18px; color: var(--text-3); font-size: 13px; text-align: center; }
.linkish { border: 0; background: none; padding: 0; color: var(--accent-ink); font-weight: 550; font-size: 13px; }
.linkish:disabled { color: var(--text-3); cursor: default; }
.auth-back { display: inline-flex; align-items: center; gap: 2px; border: 0; background: none; padding: 0; margin: -4px 0 14px -4px; color: var(--text-2); font-size: 13px; font-weight: 500; }
.auth-back .i { width: 18px; height: 18px; }
.auth-note { text-align: center; color: var(--text-3); font-size: 12px; margin-top: 18px; }
@media (max-width: 420px) { .auth-card { padding: 24px 20px 20px; } }

/* ================================================================
   Responsive
   ================================================================ */
@media (max-width: 1280px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row > .span-4 { grid-column: span 6; }
  .row > .span-4:last-child:nth-child(3) { grid-column: span 12; }
}
@media (max-width: 1100px) {
  .row > .span-5, .row > .span-7, .row > .span-8 { grid-column: span 12; }
  .row > .span-4.solo { grid-column: span 12; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .txn { grid-template-columns: minmax(0, 1fr) auto; padding: 10px 16px; }
  .txn.head, .txn .date { display: none; }
  .txn .m-date { display: inline; }
  .txn .part { grid-column: 1; grid-row: 1 / span 3; }
  .txn .dr, .txn .cr, .txn .bal { grid-column: 2; }
  .txn .dr:empty, .txn .cr:empty, .txn .bal:empty { display: none; }
  .txn:not(.edge) .dr::after { content: " Dr"; color: var(--text-3); font-weight: 450; }
  .txn:not(.edge) .cr::after { content: " Cr"; color: var(--text-3); font-weight: 450; }
  .txn:not(.edge) .bal { font-size: 12px; color: var(--text-3); }
}

/* Tablet & phone: app bar on top, tab bar at bottom, no sidebar */
@media (max-width: 960px) {
  :root { --gutter: 20px; }
  .sidebar { display: none; }
  .main { margin-left: 0; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .appbar {
    display: flex; position: sticky; top: 0; z-index: 15; align-items: center; justify-content: space-between; gap: 12px;
    padding: calc(10px + env(safe-area-inset-top)) var(--gutter) 10px; background: color-mix(in srgb, var(--surface) 90%, transparent);
    backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px); border-bottom: 1px solid var(--line);
  }
  .appbar-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
  .appbar-titles { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
  .appbar-title { font-weight: 650; font-size: 15px; }
  .appbar-sub { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .appbar-actions { display: flex; gap: 2px; }

  .page-head { position: static; padding: 18px var(--gutter) 14px; background: none; backdrop-filter: none; -webkit-backdrop-filter: none; }
  .page-head .titles { display: none; }
  .period { width: 100%; }
  .seg { flex: 1; overflow-x: auto; scrollbar-width: none; }
  .seg::-webkit-scrollbar { display: none; }
  .seg button { flex: 1 0 auto; justify-content: center; }
  .refresh { display: none; }

  .tabbar {
    display: grid; grid-template-columns: repeat(6, 1fr); position: fixed; inset: auto 0 0 0; z-index: 20;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px); border-top: 1px solid var(--line);
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 5px 0; color: var(--text-3); font-size: 11px; font-weight: 550; border-radius: 8px; }
  .tabbar a .i { width: 22px; height: 22px; }
  .tabbar a[aria-current="page"] { color: var(--accent); }

  .row > [class*="span-"] { grid-column: span 12; }
}

@media (max-width: 600px) {
  :root { --gutter: 16px; }
  .view { padding-top: 0; }
  .stack, .row, .kpis { gap: 12px; }
  .kpi { padding: 14px 14px 12px; border-radius: 12px; }
  .kpi-value { font-size: 22px; margin-top: 6px; }
  .kpi-label { font-size: 12.5px; }
  .kpi .spark { height: 26px; }
  .card { border-radius: 12px; }
  .card-head { padding: 14px 16px 0; }
  .card-body { padding: 12px 16px 16px; }
  .li { padding: 10px 16px; }
  .toolbar { padding: 12px 16px; }
  .search { max-width: none; flex-basis: 100%; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); border-radius: 12px; }
  .stats div { padding: 10px 14px; }
  .stats div:last-child { grid-column: span 2; }
  .stats b { font-size: 15px; }
  .recent { padding: 10px 16px; }
  .drawer-link { padding: 12px 16px; }
  .sort { margin-left: 0; }
  .seg button { padding: 6px 8px; font-size: 12.5px; }
  .seg .long { display: none; }
  .seg .short { display: inline; }
  .seg button[data-preset="custom"] { flex: 0 0 auto; padding: 6px 10px; }

  dialog.drawer {
    margin: auto 0 0; width: 100vw; max-width: 100vw; height: auto; max-height: 88vh;
    border-radius: 16px 16px 0 0; border-width: 1px 0 0;
  }
  dialog.drawer[open] { animation: slide-up .3s var(--ease); }
  dialog.drawer .sheet-head::before { content: ""; position: absolute; left: 50%; top: 7px; width: 36px; height: 4px; margin-left: -18px; border-radius: 2px; background: var(--line-strong); }
  dialog.drawer .sheet-head { position: relative; padding-top: 22px; }
  .drawer-stats div { padding: 12px 16px; }
  .drawer-stats b { font-size: 15px; }
  .bill, .drawer h3 { padding-left: 16px; padding-right: 16px; }
  .bill:last-child { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  dialog.small { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 16px 16px 0 0; }
  dialog.small[open] { animation: slide-up .3s var(--ease); }
  .sheet-foot { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .sheet-foot .btn { flex: 1; height: 42px; }
}
@keyframes slide-up { from { transform: translateY(48px); } }
@media (prefers-reduced-motion: reduce) { dialog.drawer[open], dialog.small[open] { animation: none; } }
@media (max-width: 330px) {
  .kpis { grid-template-columns: minmax(0, 1fr); }
}
