/* CFO's Office — design system. GOJIBERRY register (adopted 4 Jul 2026, Ketan's reference): a flat
   WHITE canvas where cards are drawn purely by 1px cool-gray hairlines — no card shadows. Friendly
   rounded type (Plus Jakarta Sans) with chunky extrabold metric numerals. The single accent is a warm
   coral (two-tone: raw coral for fills, a deeper coral for text/focus so it stays AA-readable), used
   only where a human acts. Segmented controls flip to dark slate when active. Charts are teal.
   Token-driven: re-skin = edit :root. */

:root {
  /* Surfaces — flat white; hairlines alone define the cards (Gojiberry is border-drawn, not shadowed) */
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f9fafb;            /* hover / zebra / subtle fills / table header band */
  --surface-muted: #f9fafb;        /* faint panels (totals, narration, read-only) */
  --sidebar-bg: #ffffff;

  /* Ink & cool greys (Tailwind-style cool ramp, per the reference) */
  --ink: #111827;
  --ink-2: #374151;
  --ink-muted: #6b7280;            /* 4.83:1 on white — muted text must still pass AA at 11-12px */
  --graphite: #9ca3af;             /* pencil→ink provenance: AI-drafted, unconfirmed values */
  --line: #e5e7eb;                 /* hairline — carries ALL card depth now */
  --line-strong: #d1d5db;

  /* Accent — Gojiberry coral, two-tone: --accent fills surfaces (buttons, edge bars, ticks),
     --accent-text is the deep coral for text/links/focus on white (4.63:1 — AA; raw coral is 2.3:1) */
  --accent: #fd8a6b;
  --accent-2: #f0764f;
  --accent-text: #c84d1f;
  --accent-soft: rgba(253,138,107,.12);
  --accent-tint-border: rgba(253,138,107,.35);  /* borders on coral-tinted surfaces */
  --focus-ring: rgba(200,77,31,.18);            /* input focus glow (accent-text @ 18%) */
  --accent-ink: #ffffff;
  --highlight: #374151;            /* dark slate — the "active segment" fill (was navy) */

  /* Status — Gojiberry pastel tints; fg stays calm/semantic (posted = slate, never green) */
  --ok: #2f7d5d;     --ok-bg: #ecfdf3;
  --warn: #9a6512;   --warn-bg: #fef9e7;
  --danger: #b4453a; --danger-bg: #fef2f2; --danger-on-ink: #ff9d90; /* negative on the dark grand-total row */
  --warn-border: #f0dca6;
  --info: #5b6472;   --info-bg: #eff4fb;
  --neutral: #667085;--neutral-bg: #f3f4f6;   /* 4.52:1 on its tint — pill text must stay AA */

  /* Data viz + deltas: Gojiberry teal for chart lines/series; green up / red down chips
     (delta text measured AA on its own tint: up 4.76, down 4.98) */
  --chart: #35b597;  --chart-soft: #c7e8df;
  --up: #15803d;     --up-bg: #ecfdf3;
  --down: #b4453a;   --down-bg: #fef2f2;

  /* Depth — cards are FLAT (border-only); shadow-md survives for true overlays; the primary
     button gets its own coral-tinted lift (the one Gojiberry shadow) */
  --radius: 8px;
  --radius-lg: 12px;
  --radius-pill: 999px;
  --shadow-sm: none;
  --shadow-md: 0 12px 32px rgba(16,24,40,.10);
  --shadow-btn: inset 0 .5px 0 rgba(255,255,255,.35), 0 3px 6px -2px rgba(253,138,107,.5);

  --font: "Plus Jakarta Sans", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --sidebar-w: 238px;
  --assistant-w: 384px;
  --topbar-h: 60px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 13.5px;
  line-height: 1.58;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 22px; font-weight: 600; letter-spacing: -.021em; margin: 0 0 4px; color: var(--ink); }
h2 { font-size: 14px; font-weight: 600; letter-spacing: -.012em; margin: 0 0 13px; color: var(--ink); }
h3 { font-size: 12.5px; font-weight: 600; margin: 0 0 6px; }
a { color: var(--ink-2); text-decoration: none; }
a:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 2px; }
p { margin: 8px 0; }

/* ---------- App shell ---------- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas: "sidebar topbar" "sidebar main";
  min-height: 100vh;
  transition: grid-template-columns .22s ease;
}
.app-topbar {
  grid-area: topbar;
  display: flex; align-items: center; gap: 14px;
  padding: 0 26px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.app-sidebar {
  grid-area: sidebar;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  display: flex; flex-direction: column; gap: 2px;
  overflow-y: auto;
}
.app-main { grid-area: main; padding: 34px 44px; max-width: 1320px; width: 100%; }
/* Assistant is now a right-hand POPOVER overlay (not a column) — toggled by the topbar Ask button. */
.app-assistant {
  position: fixed; top: 0; right: 0; z-index: 60;
  width: min(var(--assistant-w), 92vw); height: 100vh;
  background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: var(--shadow-md);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .2s ease;
}
.app-assistant.open { transform: translateX(0); }
/* Dim backdrop behind the open popover (click to close — wired in app.js). */
.assistant-backdrop {
  position: fixed; inset: 0; z-index: 55; background: rgba(16,24,40,.28);
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.assistant-backdrop.open { opacity: 1; pointer-events: auto; }

/* ---------- Topbar ---------- */
.brand-mark { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 15px; letter-spacing: -.01em; color: var(--ink); }
.brand-mark img { height: 22px; width: auto; display: block; }
.topbar-title { font-weight: 400; color: var(--ink-muted); font-size: 13.5px; }
.topbar-spacer { flex: 1; }
.topbar-user { display: flex; align-items: center; gap: 14px; font-size: 12.5px; color: var(--ink-muted); }
.topbar-user a { color: var(--ink-muted); }
.topbar-user a:hover { color: var(--ink); }

/* ---------- Sidebar nav ---------- */
.nav-group { margin-top: 18px; }
.nav-group:first-child { margin-top: 2px; }
.nav-label {
  font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
  color: var(--ink-muted); padding: 6px 11px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 11px; border-radius: var(--radius);
  color: var(--ink-2); font-size: 13px; font-weight: 500;
  cursor: pointer; transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
/* Active nav = Gojiberry pattern: coral-tint pill + a small coral bar on the left edge; text stays ink. */
.nav-item.active { background: var(--accent-soft); color: var(--ink); font-weight: 600;
  box-shadow: inset 3px 0 0 var(--accent); }
.nav-item.active .nav-icon { color: var(--ink); opacity: 1; }
.nav-item.disabled { color: var(--ink-muted); cursor: default; opacity: .6; }
.nav-item.disabled:hover { background: transparent; }
.nav-icon { width: 17px; height: 17px; flex: none; opacity: .7; }
.nav-soon {
  margin-left: auto; font-size: 9px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
  color: var(--ink-muted); background: var(--neutral-bg); padding: 1px 6px; border-radius: var(--radius-pill);
}
.sidebar-foot { margin-top: auto; padding: 16px 12px 4px; font-size: 11px; color: var(--ink-muted); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px 26px;
  margin: 20px 0;
  box-shadow: var(--shadow-sm);
}

/* Metric cards */
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin: 20px 0; }
.metric-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 18px 20px; box-shadow: var(--shadow-sm);
}
.metric-value { font-size: 32px; font-weight: 800; letter-spacing: -.02em; color: var(--ink); line-height: 1.1; font-variant-numeric: tabular-nums; }
.metric-label { font-size: 11px; color: var(--ink-muted); margin-top: 6px; text-transform: uppercase; letter-spacing: .05em; }
/* Status-tinted metric cards (AP counters + the bank balance check). Calm: the VALUE carries
   the status color; only is-error also washes the card — a failed check must be visible
   without opening anything (the post_failed lesson). */
.metric-card.is-pending .metric-value { color: var(--ok); }
.metric-card.is-held .metric-value    { color: var(--warn); }
.metric-card.is-posted .metric-value  { color: var(--info); }
.metric-card.is-error .metric-value   { color: var(--danger); }
.metric-card.is-error { background: var(--danger-bg); border-color: var(--danger); }

/* ---------- Tables ---------- */
table { border-collapse: collapse; width: 100%; }
th {
  text-align: left; font-size: 10.5px; font-weight: 500; letter-spacing: .05em; text-transform: uppercase;
  color: var(--ink-muted); padding: 9px 12px 9px 0; border-bottom: 1px solid var(--line-strong);
  background: var(--surface-2);   /* Gojiberry header band */
}
td { padding: 13px 12px 13px 0; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: top; }
/* The header band made the flush-left first column visible — give the first column the same
   inset the other columns get, so text doesn't sit on the band's edge. */
th:first-child, td:first-child { padding-left: 12px; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

/* ---------- Pills / status ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px; border-radius: 6px;
  font-size: 11px; font-weight: 600; text-transform: capitalize;
  background: var(--neutral-bg); color: var(--ink-2);
  font-variant-numeric: tabular-nums;   /* the recon pill carries money figures */
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.held    { background: var(--warn-bg);   color: var(--warn); }
.pending { background: var(--ok-bg);     color: var(--ok); }
.posted  { background: var(--info-bg);   color: var(--info); }
.error   { background: var(--danger-bg); color: var(--danger); }
.post_failed { background: var(--danger-bg); color: var(--danger); font-weight: 600; }
.rejected{ background: var(--neutral-bg);color: var(--neutral); }
.processing { background: var(--neutral-bg); color: var(--neutral); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius); border: 1px solid var(--accent-2);
  background: var(--accent); color: var(--accent-ink); font-size: 12.75px; font-weight: 600;
  box-shadow: var(--shadow-btn);
  font-family: inherit; cursor: pointer; text-decoration: none; transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--accent-2); border-color: var(--accent-2); text-decoration: none; }
.approve { background: var(--accent); border-color: var(--accent-2); color: var(--accent-ink); }
.approve:hover { background: var(--accent-2); border-color: var(--accent-2); }
.reject { background: var(--surface); color: var(--ink-2); border-color: var(--line-strong); box-shadow: none; }
.reject:hover { background: var(--surface-2); color: var(--danger); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line-strong); box-shadow: none; }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--ink-muted); color: var(--ink); }
.btn-sm { padding: 5px 11px; font-size: 12px; }

/* Keyboard focus: the same orange ring inputs get — an approved accent use (focus = where the
   human is). :where() keeps specificity at zero so component styles still win on other states. */
:where(a, button, select, summary, [tabindex]):focus-visible,
/* text inputs use the box-shadow ring below; these input types don't, so give them the outline */
input[type=checkbox]:focus-visible, input[type=radio]:focus-visible,
input[type=file]:focus-visible, input[type=date]:focus-visible {
  outline: 2px solid var(--accent-text); outline-offset: 2px;
}

.muted { color: var(--ink-muted); font-size: 12.25px; }

/* ---------- Forms ---------- */
.field { margin: 16px 0; max-width: 430px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.input, .select, input[type=text], input[type=email], input[type=password], textarea, select {
  width: 100%; font-family: inherit; font-size: 13px; color: var(--ink);
  padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); transition: border-color .12s, box-shadow .12s;
}
.input:focus, input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent-text); box-shadow: 0 0 0 3px var(--focus-ring);
}
input[type=file] { font-family: inherit; font-size: 13px; color: var(--ink-2); }  /* the "No file chosen" text is browser-default Arial otherwise */
/* Dress the native file-picker button as a system ghost button (it renders in the browser's
   default style otherwise — the one un-designed control on the upload cards). */
input[type=file]::file-selector-button {
  padding: 5px 11px; margin-right: 10px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  font-family: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
  transition: background .12s, border-color .12s;
}
input[type=file]::file-selector-button:hover { background: var(--surface-2); border-color: var(--ink-muted); }

/* ---------- Reporting-tag picker (one select per dimension, on a bill line) ---------- */
.tag-cell { display: flex; flex-direction: column; gap: 6px; min-width: 150px; }
.tag-pick { display: flex; flex-direction: column; gap: 2px; }
.tag-pick .select { padding: 6px 9px; font-size: 12.5px; }
.tag-dim { font-size: 10.5px; font-weight: 600; color: var(--ink-muted);
  text-transform: uppercase; letter-spacing: .04em; }

/* ---------- Accounting narration (posts to the bill Notes) ---------- */
.narration-label { display: block; font-size: 11.5px; font-weight: 600; color: var(--ink);
  margin-bottom: 5px; }
.narration-box { font-size: 13px; line-height: 1.5; resize: vertical; min-height: 76px; }
.narration-ro { margin-top: 12px; padding: 11px 13px; background: var(--surface-muted);
  border-left: 2px solid var(--line-strong); border-radius: var(--radius);
  font-size: 12.75px; line-height: 1.55; white-space: pre-wrap; }
.narration-stale { margin: 0 0 6px; padding: 7px 10px; border-radius: var(--radius);
  background: var(--warn-bg); color: var(--warn);
  border: 1px solid var(--warn-border); font-size: 12px; font-weight: 500; }

/* ---------- GL coding table: GST breakdown columns + bill-total row ---------- */
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
tr.gl-total td { border-top: 2px solid var(--line-strong); font-weight: 600;
  background: var(--surface-muted); }

/* GL coding: single row per line, but the interactive Account + Tags columns get real width (the old
   layout pinched the dropdown into a ~10% cell) and the numeric columns stay tight. The folded
   "Treatment" column carries TDS/tax-treatment/reason. Scoped to table.gl so the dashboard's other
   plain tables are untouched. */
table.gl { table-layout: auto; }
table.gl td.num, table.gl th.num { width: 1%; }            /* amounts: only as wide as needed */
table.gl td:first-child { min-width: 200px; }              /* line description: don't starve it into a 7-line sliver */
table.gl td.gl-acct { min-width: 250px; }
table.gl td.gl-acct .select, table.gl td.gl-acct select { width: 100%; min-width: 230px; }
table.gl td.gl-tags { min-width: 170px; }
table.gl td.gl-tags .tag-cell { min-width: 0; }
/* Treatment is a full-width line BELOW its row: the main row drops its bottom border so the two read
   as one item, and the treatment sub-row carries the divider. */
table.gl tr.gl-line td { border-bottom: none; padding-bottom: 6px; }
table.gl tr.gl-treat-row td { border-top: none; padding-top: 0; padding-bottom: 14px;
  font-size: 12px; color: var(--ink-2); }
table.gl tr.gl-treat-row:hover { background: transparent; }
.gl-treat-label { font-size: 10px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-muted); font-weight: 600; margin-right: 6px; }

/* Pencil→ink provenance (DESIGN.md): an AI-drafted value renders in graphite with a dotted
   underline; once a reviewer sets/confirms it (or the bill posts), it sets in full ink with the
   orange auditor's tick. Orange appears ONLY where a human acted — never on machine output. */
.prov-draft { color: var(--graphite); border-bottom: 1px dotted var(--graphite); padding-bottom: 1px; }
.prov-ink   { color: var(--ink); font-weight: 500; }
.prov-tick  { color: var(--accent-text); font-weight: 700; margin-left: 4px; font-size: 12px; }
.prov-draft-wrap .select, .prov-draft-wrap select { color: var(--graphite); border-style: dashed; }

/* ---------- Badges (hold / TDS) ---------- */
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 6px;
  font-size: 10.5px; font-weight: 600;
}
.badge-hold-policy { background: var(--warn-bg); color: var(--warn); }
.badge-hold-info   { background: var(--neutral-bg); color: var(--ink-2); }
.badge-hold-tds    { background: var(--info-bg); color: var(--info); }
.badge-tds         { background: var(--info-bg); color: var(--info); }

/* ---------- Briefing / anomaly / flash ---------- */
/* The briefing is the AI's note — it wears neutral slate, never orange (orange marks human
   action only; see DESIGN.md "orange is the pen"). */
.briefing {
  background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--info);
  border-radius: var(--radius-lg); padding: 16px 18px; margin: 20px 0; box-shadow: var(--shadow-sm);
}
.anomaly {
  background: var(--info-bg); border: 1px solid transparent; border-radius: var(--radius-lg);
  padding: 13px 16px; margin: 20px 0;
}
.anomaly.blocking { background: var(--warn-bg); }
.flash {
  background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--info);
  border-radius: var(--radius-lg); padding: 13px 16px; margin: 16px 0; color: var(--ink-2); font-size: 13px;
}
.anomaly ul { margin: 6px 0 0; padding-left: 18px; }
.anomaly li { margin: 2px 0; }
/* Ownership-override confirm, shown next to Approve when a bill is flagged as the wrong client. */
.owner-confirm {
  display: inline-flex; align-items: center; gap: 7px; margin-right: 12px;
  font-size: 13px; color: var(--danger); font-weight: 600;
}
.owner-confirm input { accent-color: var(--danger); }
/* Inline 'set identity' form in the admin clients table. */
.ident-form { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* ---------- Assistant popover ---------- */
.assistant-head { padding: 16px 16px 14px; border-bottom: 1px solid var(--line); }
.assistant-head-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.assistant-head .title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; letter-spacing: -.005em; }
.assistant-head .sub { font-size: 11.5px; color: var(--ink-muted); margin-top: 4px; }
.assistant-close { border: 0; background: none; cursor: pointer; font-size: 22px; line-height: 1;
  color: var(--ink-muted); padding: 0 4px; border-radius: var(--radius); }
.assistant-close:hover { color: var(--ink); background: var(--surface-2); }
.assistant-thread { flex: 1; overflow-y: auto; padding: 16px 16px 8px; display: flex; flex-direction: column; gap: 10px; }
.assistant-empty { color: var(--ink-muted); font-size: 12.5px; padding: 6px 2px; }
.assistant-msg { padding: 10px 12px; border-radius: var(--radius); font-size: 12.75px; max-width: 92%; white-space: pre-wrap; }
/* The user's words wear the coral TINT (human = coral, but body text must stay AA-readable;
   white-on-raw-coral was 2.33:1). */
.assistant-msg.user { align-self: flex-end; background: var(--accent-soft); color: var(--ink);
  border: 1px solid var(--accent-tint-border); border-bottom-right-radius: 3px; }
.assistant-msg.ai { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--line); border-bottom-left-radius: 3px; }
.assistant-msg.thinking { color: var(--ink-muted); font-style: italic; background: none; border: 0; }
.suggested-qs { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 16px 12px; }
.suggested-q {
  font-size: 12px; color: var(--ink-2); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius-pill);
  padding: 5px 12px; cursor: pointer; transition: border-color .12s, color .12s;
}
.suggested-q:hover { border-color: var(--ink-muted); color: var(--ink); }
.assistant-form { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.assistant-input { flex: 1; }
.assistant-form .btn { padding: 8px 12px; }

/* ---------- Login ---------- */
.login-wrap { max-width: 390px; margin: 12vh auto; padding: 0 18px; }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 34px 32px; box-shadow: var(--shadow-md); }
.login-hero { text-align: center; margin-bottom: 26px; }
.login-hero img { height: 32px; margin-bottom: 14px; }
.login-hero h1 { margin-bottom: 6px; }
.login-hero .tag { color: var(--ink-muted); font-size: 13px; }

/* ---------- Misc ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.crumb { font-size: 12.25px; color: var(--ink-muted); margin-bottom: 14px; }
/* Panel-collapse toggles. The sidebar's own collapse button + the Ask button are always shown;
   the topbar reopen button appears only when the sidebar is collapsed (or on mobile). */
.sidebar-toggle, .ask-toggle { display: inline-flex; }
.topbar-toggle { display: none; }
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  height: var(--topbar-h); margin: -18px -12px 10px; padding: 0 12px 0 14px;
  border-bottom: 1px solid var(--line);
}
/* Icon-only panel toggles: deliberate borderless icon buttons (system radius, hover, pointer,
   inherited font) — NOT half-styled ghost buttons. Display is managed by the visibility rules
   above/below, so it's not set here. */
.sidebar-toggle, .topbar-toggle {
  align-items: center; justify-content: center; padding: 6px;
  background: transparent; border: 0; border-radius: var(--radius);
  color: var(--ink-muted); font-family: inherit; cursor: pointer;
  transition: background .12s, color .12s;
}
.sidebar-toggle:hover, .topbar-toggle:hover { background: var(--surface-2); color: var(--ink); }

/* Desktop: collapse the sidebar to a 64px ICON RAIL (Gojiberry pattern — never fully hidden,
   so the user always sees the rail is there; icons stay clickable and the .nav-label-text
   flyout below provides the names — deliberately NO title= attributes, a native tooltip
   would double the flyout). State persisted in localStorage and re-applied in <head>. */
@media (min-width: 1101px) {
  html.nav-collapsed .app-shell { grid-template-columns: 64px minmax(0, 1fr); }
  /* overflow visible so the hover flyouts can escape the rail (its content is short; no scroll needed) */
  html.nav-collapsed .app-sidebar { padding-left: 10px; padding-right: 10px; overflow: visible; }
  html.nav-collapsed .brand-name,
  html.nav-collapsed .nav-label,
  html.nav-collapsed .nav-soon,
  html.nav-collapsed .sidebar-foot { display: none; }
  /* Hover flyout: the item's own label becomes an instant dark pill beside the icon
     (kept in the DOM — not display:none — so screen readers still announce it). */
  html.nav-collapsed .nav-label-text {
    position: absolute; left: calc(100% + 12px); top: 50%; transform: translateY(-50%);
    background: var(--highlight); color: var(--surface);
    font-size: 12px; font-weight: 600; line-height: 1; padding: 7px 11px;
    border-radius: 6px; white-space: nowrap; box-shadow: var(--shadow-md);
    opacity: 0; visibility: hidden; pointer-events: none; z-index: 70;
    transition: opacity .12s ease;
  }
  html.nav-collapsed .nav-item:hover .nav-label-text,
  html.nav-collapsed .nav-item:focus-visible .nav-label-text { opacity: 1; visibility: visible; }
  /* Head stacks: logo mark on top, the expand chevron under it (as in the reference). */
  html.nav-collapsed .sidebar-head {
    flex-direction: column; justify-content: center; gap: 6px;
    height: auto; margin: -18px -10px 10px; padding: 12px 0 10px;
  }
  /* Keep group rhythm without labels: a hairline stands in for each group heading. */
  html.nav-collapsed .nav-group { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
  html.nav-collapsed .nav-group:first-of-type { border-top: none; padding-top: 0; margin-top: 0; }
  html.nav-collapsed .nav-item { position: relative; justify-content: center; padding: 10px 0; }
  html.nav-collapsed .app-main { max-width: 1560px; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .app-sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; z-index: 50;
    transform: translateX(-100%); transition: transform .22s ease; box-shadow: var(--shadow-md);
  }
  .app-sidebar.open { transform: translateX(0); }
  .app-shell { grid-template-columns: 1fr; grid-template-areas: "topbar" "main"; }
  .topbar-toggle { display: inline-flex; }
}
@media (max-width: 760px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); grid-template-areas: "topbar" "main"; }
  .app-sidebar {
    position: fixed; top: 0; left: 0; width: 250px; height: 100vh; z-index: 60;
    transform: translateX(-100%); transition: transform .22s ease;
  }
  .app-sidebar.open { transform: translateX(0); box-shadow: var(--shadow-md); }
  .topbar-toggle { display: inline-flex; }
  .app-main { padding: 20px 18px; }
}

/* ---------- CFO dashboard ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(208px, 1fr)); gap: 14px; margin: 20px 0; }
.kpi { margin: 0; }
/* Reserve two lines so the metric values align on one baseline whether the label wraps or not. */
.kpi-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-muted); line-height: 1.3; min-height: 29px; }
.kpi-value { font-size: 32px; font-weight: 800; letter-spacing: -.02em; margin-top: 9px; font-variant-numeric: tabular-nums; color: var(--ink); line-height: 1.1; }
.kpi-value.is-loss { color: var(--danger); }
.kpi-value.is-gain { color: var(--ok); }
.kpi-sub { font-size: 12px; color: var(--ink-muted); margin-top: 7px; }

/* Delta chips (à la Profound): green up / red down / grey flat, beside a metric or in a table cell. */
.delta { display: inline-flex; align-items: center; gap: 2px; font-size: 11.5px; font-weight: 600;
  padding: 1px 7px; border-radius: var(--radius-pill); font-variant-numeric: tabular-nums; }
.delta.up   { color: var(--up);   background: var(--up-bg); }
.delta.down { color: var(--down); background: var(--down-bg); }
.delta.flat { color: var(--ink-muted); background: var(--neutral-bg); }

/* Underline tab nav (à la Profound): grey tabs, active = ink text + ink underline. */
.tabnav { display: flex; gap: 22px; border-bottom: 1px solid var(--line); margin: 0 0 18px; flex-wrap: wrap; }
.tabnav a { padding: 9px 1px; font-size: 13px; color: var(--ink-muted); font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabnav a:hover { color: var(--ink); text-decoration: none; }
.tabnav a.active { color: var(--ink); border-bottom-color: var(--ink); font-weight: 600; }
/* align-items:start so each card keeps its natural height (no dead space stretched under the chart). */
.dash-cols { display: grid; grid-template-columns: 1.45fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .dash-cols { grid-template-columns: 1fr; } }
.chart-legend { display: flex; gap: 18px; font-size: 12px; color: var(--ink-2); margin-top: 12px; }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.attn-item { display: flex; align-items: center; gap: 11px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--ink-2); text-decoration: none; }
.attn-item:last-child { border-bottom: 0; }
.attn-item:hover { color: var(--ink); text-decoration: none; }
.attn-item .n { font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink); min-width: 34px; }

/* ===== Financial statements module ===== */
.stmt-toolbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 18px; flex-wrap: wrap; margin: 6px 0 12px; }
.range-row { display: flex; justify-content: flex-end; margin: 0 0 12px; }
.range { display: flex; gap: 10px; align-items: flex-end; margin: 0; }
.range .f { display: flex; flex-direction: column; gap: 5px; }
.range .lbl { font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-muted); }
.range input[type=date] { font: inherit; padding: 8px 11px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); color: var(--ink); font-size: 13px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.chip { padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; font-size: 12px; color: var(--ink-2); background: var(--surface); text-decoration: none; }
.chip:hover { border-color: var(--line-strong); color: var(--ink); text-decoration: none; }
.chip.on { background: var(--highlight); color: var(--surface); border-color: transparent; font-weight: 600; }
button.chip { font-family: inherit; cursor: pointer; }
.bank-filters { margin: 10px 0; }
.fin-wrap { border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-sm); overflow: hidden; }
.fin-scroll { max-height: 72vh; overflow: auto; }
table.fin { border-collapse: separate; border-spacing: 0; width: 100%; font-variant-numeric: tabular-nums; }
table.fin th, table.fin td { padding: 10px 18px; font-size: 13px; white-space: nowrap; text-align: right; border-bottom: 1px solid var(--line); }
table.fin thead th { position: sticky; top: 0; z-index: 3; background: var(--surface-2); font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-muted); font-weight: 600; border-bottom: 1px solid var(--line-strong); }
table.fin th.lab, table.fin td.lab { text-align: left; position: sticky; left: 0; z-index: 2; background: var(--surface); min-width: 280px; box-shadow: 1px 0 0 var(--line); }
table.fin thead th.lab { z-index: 5; }
table.fin th.tot, table.fin td.tot { position: sticky; right: 0; z-index: 2; background: var(--surface); box-shadow: -1px 0 0 var(--line-strong); font-weight: 600; }
table.fin thead th.tot { z-index: 5; background: var(--surface-2); }
table.fin tbody tr:hover td, table.fin tbody tr:hover td.lab, table.fin tbody tr:hover td.tot { background: var(--surface-2); }
table.fin tr.acct td, table.fin tr.acct td.lab { color: var(--ink-2); font-weight: 400; }
table.fin tr.subtotal td { font-weight: 600; color: var(--ink); }
table.fin tr.total td { font-weight: 700; color: var(--ink); border-top: 1px solid var(--line-strong); }
table.fin tr.grand td { font-weight: 700; background: var(--ink); color: var(--surface); border-top: none; }
table.fin tr.grand td.lab, table.fin tr.grand td.tot { background: var(--ink); color: var(--surface); box-shadow: none; }
table.fin tr.grand:hover td, table.fin tr.grand:hover td.lab, table.fin tr.grand:hover td.tot { background: var(--ink); }
table.fin .num.neg { color: var(--danger); }
table.fin tr.grand .num.neg { color: var(--danger-on-ink); }
table.fin .num.zero { color: var(--ink-muted); }
.fin-foot { padding: 11px 18px; font-size: 11.5px; color: var(--ink-muted); border-top: 1px solid var(--line); background: var(--surface-2); }

/* ---- Live "glass box" processing stepper ---- */
.stepper-card { padding: 16px 18px; }
details.stepper-card > summary.stepper-summary { cursor: pointer; font-weight: 600; color: var(--ink-2); font-size: 13px; list-style: none; }
details.stepper-card > summary::-webkit-details-marker { display: none; }
details.stepper-card > summary::before { content: "▸ "; color: var(--ink-muted); }
details.stepper-card[open] > summary::before { content: "▾ "; }
details.stepper-card[open] > summary { margin-bottom: 12px; }
.stepper-block + .stepper-block { margin-top: 14px; }
.stepper-title { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-muted); margin: 2px 0 10px; }
.stepper { list-style: none; margin: 0; padding: 0; }
.step { position: relative; display: flex; gap: 12px; align-items: flex-start; padding: 0 0 14px 0; }
.step:not(:last-child)::before { content: ""; position: absolute; left: 10px; top: 20px; bottom: 0; width: 1px; background: var(--line); }
.step-ic { position: relative; flex: 0 0 auto; width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--line-strong); background: var(--surface); box-sizing: border-box; }
.step-body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.step-label { font-size: 13.5px; font-weight: 600; color: var(--ink-2); line-height: 1.35; }
.step-sum { font-size: 12px; color: var(--ink-muted); line-height: 1.35; }
/* pending — not yet reached */
.step--pending .step-label { color: var(--graphite); font-weight: 500; }
.step--pending .step-ic { border-color: var(--line); }
/* active — teal spinner (the MACHINE working; coral is reserved for the human hand-off) */
.step--started .step-ic { border-color: var(--chart-soft); border-top-color: var(--chart); animation: ap-spin .7s linear infinite; }
.step--started .step-label { color: var(--ink); }
/* done — green filled check */
.step--done .step-ic { background: var(--ok); border-color: var(--ok); }
.step--done .step-ic::after { content: ""; position: absolute; left: 6px; top: 2.5px; width: 4px; height: 8px; border: solid #fff; border-width: 0 1.5px 1.5px 0; transform: rotate(45deg); }
/* hold — the moment it hands off to a HUMAN: coral (the pen) */
.step--hold .step-ic { background: var(--accent); border-color: var(--accent); }
.step--hold .step-label, .step--hold .step-sum { color: var(--accent-text); }
/* error — red cross */
.step--error .step-ic { background: var(--danger); border-color: var(--danger); }
.step--error .step-ic::after { content: "\00d7"; position: absolute; left: 0; right: 0; top: -3px; text-align: center; color: #fff; font-size: 14px; line-height: 20px; font-weight: 700; }
.step--error .step-label { color: var(--danger); }
@keyframes ap-spin { to { transform: rotate(360deg); } }
