:root {
  /* Echelon Light — adapted from the AUSIEX identity: deep royal-navy ink on a cool paper canvas,
     with the brand royal-blue used sparingly as the accent (links, buttons, mark, focus). */
  --bg: #f4f6fb;
  --card: #ffffff;
  --fg: #0e1330;
  --muted: #5b6478;
  --line: #dce1ec;
  --accent: #2536cc;
  --ok: #067647;
  --ok-bg: #ecfdf3;
  --warn: #b54708;
  --warn-bg: #fffaeb;
  --error: #b42318;
  --error-bg: #fef3f2;
  --row: 10px;
  /* Typefaces. Themes may override — a serif for Executive, Inter/Space Grotesk for Swiss. */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-head: inherit;
  /* Text that sits ON a solid --accent button. Default white; a light-accent theme flips it dark. */
  --on-accent: #fff;
  /* Swiss background grid — off (transparent) unless a Swiss theme lights it up. */
  --grid: transparent;
  /* Glass tints for the brand mark — derived from the accent, so they adapt to every theme. */
  --glass: color-mix(in srgb, var(--accent) 10%, transparent);
  --glass-2: color-mix(in srgb, var(--accent) 24%, transparent);
}

/* The brand IS the theme: {brand}-{mode}. Echelon is the incumbent blue look — its Light is the base
   :root above (any value with no block falls through to it), its Dark overrides here. GlassBox is the
   Swiss mono skin further down. The chosen data-theme also drives the wordmark + tagline (see views). */
:root[data-theme="echelon-dark"] {
  /* Echelon Dark — the AUSIEX deep navy as a calm dark canvas (desaturated so tables don't glare),
     lifted navy cards, and a periwinkle-royal accent bright enough to read on the navy. */
  color-scheme: dark;
  --bg: #0b1030; --card: #151c40; --fg: #e8eaf4; --muted: #99a1c6; --line: #262e57;
  --accent: #6172f5; --ok: #6ce9a6; --ok-bg: #0d2a1d; --warn: #fdb022; --warn-bg: #2b1d05;
  --error: #f97066; --error-bg: #2a1614;
}

/* GlassBox Executive — the white-label brand skin (see GLASS_BOX.md style guide). Parchment canvas,
   deep-aged-gold accent, midnight ink, serif display headings. Colours are the guide's AAA tokens. */
:root[data-theme="executive"] {
  color-scheme: light;
  --bg: #f8f9fa; --card: #ffffff; --fg: #0a1118; --muted: #3b4754; --line: #d1d5db;
  --accent: #7d5d18;
  --ok: #1e4d36; --ok-bg: #eef3f0; --warn: #7a5410; --warn-bg: #f6efdf;
  --error: #8a1c13; --error-bg: #f7eae8;
  --font-head: "GT Super", "Baskerville", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
}
/* Optometric nudge: a touch more body size and heading heft for the 60–80+ reader. */
:root[data-theme="executive"] body { font-size: 16px; }
:root[data-theme="executive"] .page-head h1,
:root[data-theme="executive"] .card-head h1,
:root[data-theme="executive"] .login-brand { letter-spacing: -0.01em; }

/* Serif display headings, when a theme sets --font-head. */
.page-head h1, .card-head h1, .brand-name, .login-brand, h2 { font-family: var(--font-head); }

/* GlassBox — the Swiss i2xp look, ported. Warm-alabaster canvas, ink monochrome (the accent IS the
   ink, so buttons and links go black-on-canvas / white-on-charcoal), Inter + Space Grotesk, a 40px
   grid. Light and dark are separate choices so either can be forced regardless of the OS. */
:root[data-theme="glassbox-light"] {
  color-scheme: light;
  --bg: #faf9f6; --card: #ffffff; --fg: #111111; --muted: #666666; --line: #e5e4df;
  --accent: #111111; --on-accent: #faf9f6;
  --ok: #3f6b3f; --ok-bg: #eef2ec; --warn: #8a6d1f; --warn-bg: #f6f0e2; --error: #b23b3b; --error-bg: #f7eded;
  --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-head: 'Inter', system-ui, sans-serif;
  --grid: rgba(229, 228, 223, 0.5);
}
:root[data-theme="glassbox-dark"] {
  color-scheme: dark;
  --bg: #131316; --card: #1c1c20; --fg: #ececea; --muted: #9b9a95; --line: #2b2b30;
  --accent: #ececea; --on-accent: #131316;
  --ok: #8bbf8b; --ok-bg: #172419; --warn: #d4b063; --warn-bg: #29230f; --error: #e58a8a; --error-bg: #2a1717;
  --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-head: 'Inter', system-ui, sans-serif;
  --grid: rgba(120, 120, 128, 0.14);
}
/* Airy Swiss display weight + tight tracking on the big headings. */
:root[data-theme^="glassbox"] .page-head h1,
:root[data-theme^="glassbox"] .card-head h1,
:root[data-theme^="glassbox"] .login-brand { font-weight: 300; letter-spacing: -0.03em; }
/* The signature 40px background grid, showing only in the canvas gutters (cards are solid). */
:root[data-theme^="glassbox"] body {
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 40px 40px;
}

:root[data-density="compact"] { --row: 5px; }

/* Swiss theme fonts — latin-subset variable woff2 (from the i2xp look). Only fetched when a Swiss
   theme references them, so the other themes pay nothing. */
@font-face {
  font-family: 'Inter'; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url('fonts/inter.woff2') format('woff2');
}
@font-face {
  font-family: 'Space Grotesk'; font-style: normal; font-weight: 300 700; font-display: swap;
  src: url('fonts/space-grotesk.woff2') format('woff2');
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.5 var(--font-sans);
  background: var(--bg);
  color: var(--fg);
}

/* --- login ------------------------------------------------------------------ */

.centered { min-height: 100vh; display: grid; place-items: center; padding: 24px; }

.card {
  width: 100%; max-width: 360px; background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 28px;
}
.card-head { text-align: center; margin-bottom: 22px; }
.card-head h1 { margin: 0; font-size: 24px; letter-spacing: 0.02em; }

/* Appearance picker on the sign-in card — a little air above it separates it from the credentials. */
.theme-select { margin-top: 4px; }
.login-card label[for="theme"] { margin-top: 16px; }

/* Login hero: brand mark + wordmark + friendly tagline + the Glass Box descriptor. */
.login-card { max-width: 380px; }
.login-head { margin-bottom: 26px; }
.login-lockup { display: flex; align-items: center; justify-content: center; gap: 11px; }
.login-lockup .brand-mark { color: var(--accent); }
.login-brand { font-size: 32px; font-weight: 700; letter-spacing: 0.02em; }
.login-tag { margin: 10px 0 4px; font-size: 15px; line-height: 1.45; color: var(--fg); }
.login-sub { margin: 0; font-size: 12.5px; letter-spacing: 0.01em; color: var(--muted); }

/* --- chrome ----------------------------------------------------------------- */

.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 0 20px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; padding: 8px 0; text-decoration: none; color: var(--fg); }
.brand-mark { flex: none; color: var(--accent); }
/* Two marks are rendered; show the one for the active brand. Layered panes = Echelon (default),
   wireframe glass cube = GlassBox. Driven by <html data-theme>, so it swaps live with the picker. */
.mark-cube { display: none; }
:root[data-theme^="glassbox"] .mark-panes { display: none; }
:root[data-theme^="glassbox"] .mark-cube { display: inline-block; }
.brand-name { font-size: 21px; font-weight: 700; letter-spacing: 0.02em; }
.menu-empty { padding: 8px 10px; font-size: 12px; color: var(--muted); }

/* ISIN alongside an instrument name — quiet, monospace, tabular. */
.isin { margin-left: 8px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Client/portfolio summary — a labelled key/value panel above the report list. */
.client-summary {
  margin: 0 0 24px; padding: 18px 20px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
}
.summary-grid {
  margin: 0; display: grid; gap: 16px 24px;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}
.summary-grid > div { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.summary-grid dt {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted);
}
.summary-grid dd { margin: 0; font-size: 15px; color: var(--fg); }
.summary-grid dd.num { font-variant-numeric: tabular-nums; }

/* Tier-one client search: a real input in the top bar with a typeahead popover of clients. */
.client-search { position: relative; }
.client-search-input {
  width: 260px; padding: 7px 12px; font: inherit; font-size: 14px; color: var(--fg);
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
}
.client-search-input::placeholder { color: var(--muted); }
.client-search-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.client-results {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 60;
  width: 340px; max-height: 62vh; overflow-y: auto; padding: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}
.client-results a {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 8px 10px; border-radius: 6px; text-decoration: none; color: var(--fg); font-size: 14px;
}
.client-results a:hover { background: var(--bg); }
.client-results a.current { color: var(--accent); font-weight: 600; }
.client-results a[hidden] { display: none; }
.client-id { flex: none; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.spacer { flex: 1; }
.who { color: var(--muted); font-size: 13px; text-decoration: none; padding: 6px 8px; border-radius: 6px; }
a.who:hover { color: var(--fg); background: var(--bg); }

/* Divider between the pinned action (Add transaction) and the standard actions. */
.action-sep { height: 0; margin: 8px 2px 10px; border-top: 1px solid var(--line); list-style: none; }


/* Breadcrumb back-link above a report title → the client landing (its reports index). */
.back-link { display: inline-block; margin-bottom: 4px; font-size: 13px; font-weight: 600; color: var(--accent); text-decoration: none; }
.back-link:hover { text-decoration: underline; }

/* Danger button (sign out). */
.btn-danger { padding: 10px 18px; font: inherit; font-size: 14px; font-weight: 600; color: #fff; background: var(--error); border: 0; border-radius: 6px; cursor: pointer; }
.btn-danger:hover { filter: brightness(1.06); }

/* Read-only settings inputs read as display, not edit. */
input[readonly] { background: var(--bg); color: var(--muted); cursor: default; }
.role {
  margin-left: 4px; padding: 1px 6px; font-size: 11px; font-weight: 600;
  border: 1px solid var(--line); border-radius: 20px;
}
.topbar form { margin: 0; }

/* The insights toggle sits on the right, just before the user block. */
.insights-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; font: inherit; font-size: 13px; font-weight: 600;
  color: var(--muted); background: var(--card);
  border: 1px solid var(--line); border-radius: 20px; cursor: pointer;
}
.insights-toggle:hover { color: var(--fg); border-color: var(--accent); }
.insights-toggle[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }
.insights-toggle .ico { font-size: 14px; line-height: 1; }

/* --- workspace: left-dominant main + right insights rail -------------------- */

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--insights-w, 380px);
  align-items: start;
}
:root[data-insights="closed"] .workspace { grid-template-columns: minmax(0, 1fr); }
:root[data-insights="closed"] .insights { display: none; }

.page { min-width: 0; max-width: 1180px; padding: 28px 32px 60px; }
.page-head { margin-bottom: 22px; }
.page-head h1 { margin: 0; font-size: 22px; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
h2 { font-size: 16px; margin-top: 32px; }

/* --- forms ------------------------------------------------------------------ */

fieldset {
  margin: 0 0 18px; padding: 18px 20px 20px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
}
legend { padding: 0 8px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; }
.span-2 { grid-column: 1 / -1; }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }

label { display: block; margin-bottom: 5px; font-size: 13px; font-weight: 600; }

input, select {
  width: 100%; padding: 8px 11px; font: inherit; color: var(--fg);
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
}
input:disabled { color: var(--muted); cursor: not-allowed; }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

.checks { display: flex; flex-wrap: wrap; gap: 20px; align-items: center; padding-top: 6px; }
.check { display: flex; align-items: center; gap: 7px; margin: 0; font-weight: 500; }
.check input { width: auto; }
.check.readonly { color: var(--muted); font-size: 13px; }

/* Appearance theme picker (settings) — a simple two-option segmented choice. */
.theme-choice { display: flex; gap: 10px; padding-top: 4px; }
.theme-opt {
  display: flex; align-items: center; gap: 8px; margin: 0; cursor: pointer; font-weight: 500;
  padding: 8px 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
}
.theme-opt input { width: auto; margin: 0; accent-color: var(--accent); }
.theme-opt:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

.hint { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.field-error { margin: 4px 0 0; font-size: 12px; font-weight: 600; color: var(--error); }

.form-actions { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }

button[type="submit"] {
  padding: 9px 18px; font: inherit; font-weight: 600; color: var(--on-accent);
  background: var(--accent); border: 0; border-radius: 6px; cursor: pointer;
}
button[type="submit"]:hover { filter: brightness(1.08); }

.card button[type="submit"] { width: 100%; margin-top: 20px; }

.btn-secondary {
  padding: 9px 16px; font-size: 14px; font-weight: 600; text-decoration: none;
  color: var(--fg); background: var(--card);
  border: 1px solid var(--line); border-radius: 6px;
}
button.link { font: inherit; color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; }

.saved {
  padding: 3px 10px; font-size: 12px; font-weight: 600;
  color: var(--ok); background: var(--ok-bg); border-radius: 20px;
}
.error {
  margin: 0 0 4px; padding: 9px 11px; font-size: 13px;
  color: var(--error); background: var(--error-bg);
  border: 1px solid currentColor; border-radius: 6px;
}

/* --- tables ----------------------------------------------------------------- */

table {
  width: 100%; border-collapse: collapse; background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
}
th, td { padding: var(--row) 14px; text-align: left; border-bottom: 1px solid var(--line); }
th {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); background: var(--bg);
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--bg); }
td.num { font-variant-numeric: tabular-nums; color: var(--muted); }
td a { color: var(--accent); font-weight: 600; text-decoration: none; }

.tag {
  display: inline-block; padding: 1px 8px; font-size: 11px; font-weight: 700;
  letter-spacing: 0.04em; border: 1px solid var(--line); border-radius: 20px;
}
.tag.warn { color: var(--warn); background: var(--warn-bg); border-color: currentColor; }

/* --- dashboard -------------------------------------------------------------- */

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.card-stat {
  display: flex; flex-direction: column; gap: 2px; padding: 18px 20px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  text-decoration: none; color: var(--fg);
}
a.card-stat:hover { border-color: var(--accent); }
.card-stat.muted .stat { color: var(--muted); }
.stat { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12px; color: var(--muted); }

.empty { padding: 40px; text-align: center; color: var(--muted); background: var(--card); border: 1px dashed var(--line); border-radius: 10px; }

/* --- documentation TOC ------------------------------------------------------ */

.toc { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.toc a {
  display: block; padding: 16px 18px; text-decoration: none; color: var(--fg);
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
}
.toc a:hover { border-color: var(--accent); }
.toc-title { display: block; font-size: 15px; font-weight: 600; }
.toc-title::after { content: " →"; color: var(--muted); }
.toc-note { display: block; margin-top: 3px; font-size: 13px; color: var(--muted); }

/* report reference (/docs/reports) */
.doc-index {
  display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 24px;
  padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 8px;
}
.doc-index a { font-size: 13px; font-weight: 600; color: var(--accent); text-decoration: none; }
.doc-index a:not(:last-child)::after { content: "·"; margin-left: 8px; color: var(--muted); font-weight: 400; }
.doc-report {
  margin: 0 0 14px; padding: 20px 22px; scroll-margin-top: 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
}
.doc-report h2 { margin: 0 0 8px; font-size: 18px; display: flex; align-items: center; gap: 10px; }
.doc-desc { margin: 0; font-size: 14px; line-height: 1.55; }
.doc-h {
  margin: 16px 0 6px; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted);
}
.doc-calc { margin: 0; padding-left: 20px; }
.doc-calc li { margin-bottom: 6px; font-size: 14px; line-height: 1.5; }
.doc-trap {
  margin: 14px 0 0; padding: 10px 12px; font-size: 13px; line-height: 1.5;
  color: var(--warn); background: var(--warn-bg); border: 1px solid currentColor; border-radius: 6px;
}
.insight-link { font-size: 13px; font-weight: 600; color: var(--accent); text-decoration: none; }
.chip-frame { display: block; width: 100%; min-height: 240px; border: 0; background: var(--bg); }
/* The Upload centre hosts the same surface full-width, but capped to a comfortable measure. */
.import-frame { max-width: 560px; min-height: 420px; }

/* Glass Box — entity blocks (reuse .doc-report as the card). */
.doc-lede { margin: 0 0 22px; max-width: 72ch; font-size: 15px; line-height: 1.6; color: var(--fg); }
.doc-report h3 { margin: 0 0 8px; font-size: 16px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tag.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; text-transform: none; letter-spacing: 0; }
.entity-kv { margin: 14px 0 0; display: grid; grid-template-columns: max-content 1fr; gap: 5px 14px; }
.entity-kv dt {
  align-self: baseline; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted);
}
.entity-kv dd { margin: 0; font-size: 14px; line-height: 1.5; }
.doc-note {
  margin: 14px 0 0; padding: 10px 12px; font-size: 13px; line-height: 1.5;
  color: var(--muted); background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
}

code {
  padding: 1px 5px; font-size: 0.9em; background: var(--bg);
  border: 1px solid var(--line); border-radius: 4px;
}

/* --- desk ------------------------------------------------------------------- */

.warn-banner {
  padding: 12px 14px; margin: 0 0 20px;
  font-size: 14px; color: var(--warn); background: var(--warn-bg);
  border: 1px solid currentColor; border-radius: 8px;
}
.warn-text { color: var(--warn); font-weight: 600; }
.card-stat.warn .stat { color: var(--warn); }
.tag.ok { color: var(--ok); background: var(--ok-bg); border-color: currentColor; }

th.r, td.r { text-align: right; }

/* A stapled leg is NOT additional units — it is the same holding seen as a CGT asset.
   Rendered subordinate so it can never be read as another line to add up. */
tr.leg td { color: var(--muted); background: var(--bg); }
tr.leg code { font-size: 0.9em; }

.basis-switch {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 20px; padding: 10px 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
}
.basis-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.basis-switch a {
  padding: 4px 12px; font-size: 13px; font-weight: 600; text-decoration: none;
  color: var(--muted); border: 1px solid var(--line); border-radius: 20px;
}
.basis-switch a.on { color: #fff; background: var(--accent); border-color: var(--accent); }
.basis-switch .hint { margin: 0 0 0 6px; }

/* --- API viewer -------------------------------------------------------------- */

.concept {
  margin: 0 0 12px; padding: 14px 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
}
.concept h3 { margin: 0 0 8px; font-size: 14px; }
.concept h3 code { font-size: 13px; background: var(--bg); }
.concept p { margin: 0 0 6px; font-size: 14px; }
.kk {
  display: inline-block; min-width: 92px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted);
}
/* The traps. If a consumer misses these it produces a confidently wrong number. */
.concept p.consequence { color: var(--warn); }
.concept p.consequence .kk { color: var(--warn); opacity: .8; }
.seq { margin: 4px 0 0 18px; padding: 0; font-size: 14px; }
.seq li { margin-bottom: 3px; }

h3.group {
  margin: 26px 0 10px; font-size: 12px; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted);
}
.endpoint {
  margin: 0 0 10px; padding: 14px 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
}
.ep-head { margin: 0 0 6px; display: flex; align-items: center; gap: 10px; }
.verb {
  padding: 2px 8px; font-size: 11px; font-weight: 700; border-radius: 4px; letter-spacing: .04em;
}
.verb-get  { color: var(--ok);     background: var(--ok-bg);   border: 1px solid currentColor; }
.verb-post { color: var(--accent); background: transparent;    border: 1px solid currentColor; }
.ep-path { font-size: 14px; font-weight: 600; }
.ep-summary { margin: 0 0 4px; font-size: 14px; font-weight: 600; }
.ep-desc { margin: 0 0 10px; }

.ep-table { margin: 8px 0 0; border-radius: 6px; }
.ep-table th {
  font-size: 10px; letter-spacing: .08em; padding: 5px 12px;
}
.ep-table td { padding: 5px 12px; font-size: 13px; vertical-align: top; }
.kcell { white-space: nowrap; width: 1%; }

.schema {
  margin: 8px 0 0; padding: 10px 12px; overflow-x: auto;
  font-size: 12px; line-height: 1.45;
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
}
details summary { cursor: pointer; }

tr.total td { border-top: 2px solid var(--line); font-size: 15px; }

.review-form fieldset { margin-bottom: 14px; }
.source-panel { position: sticky; top: 16px; }
.source-panel .schema { white-space: pre-wrap; max-height: 520px; overflow-y: auto; }

/* --- insights rail ---------------------------------------------------------- */

.insights {
  position: sticky; top: 0; align-self: start;
  height: 100vh; overflow-y: auto;
  background: var(--card); border-left: 1px solid var(--line);
}
.insights-head {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 12px; background: var(--card); border-bottom: 1px solid var(--line);
}
.insights-head h2 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.insights-close {
  font-size: 20px; line-height: 1; color: var(--muted);
  background: none; border: 0; cursor: pointer; padding: 0 4px;
}
.insights-close:hover { color: var(--fg); }
.insights-body { padding: 16px 18px 32px; }

/* Rail sections: Actions (do) on top, Insights (understand) below. */
.rail-section { margin: 0 0 22px; }
.rail-label {
  margin: 0 0 10px; padding-bottom: 6px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted);
  border-bottom: 1px solid var(--line);
}

/* A short, extensible list of task actions. Each row is a chip (expandable) or a link. */
.action-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.action-row {
  display: flex; align-items: center; gap: 9px; padding: 9px 11px;
  font-size: 13px; font-weight: 600; color: var(--fg); text-decoration: none;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  cursor: pointer; user-select: none;
}
.action-row:hover { border-color: var(--accent); color: var(--accent); }
.action-row.current { border-color: var(--accent); color: var(--accent); } /* the active nav chip */
.action-ico {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; font-size: 15px; line-height: 1; color: var(--accent);
  transition: transform 0.15s ease;
}
details.action > summary.action-row { list-style: none; }
details.action > summary.action-row::-webkit-details-marker { display: none; }
details.action[open] > summary.action-row {
  border-color: var(--accent); color: var(--accent);
  border-bottom-left-radius: 0; border-bottom-right-radius: 0;
}
details.action[open] > summary.action-row .action-ico { transform: rotate(45deg); } /* + becomes × */
.action-body {
  padding: 12px; background: var(--card);
  border: 1px solid var(--accent); border-top: 0; border-radius: 0 0 8px 8px;
}
@media (prefers-reduced-motion: reduce) { .action-ico { transition: none; } }

.insight-card { margin: 0 0 16px; }
.insight-card h3 {
  margin: 0 0 6px; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted);
}
.insight-card p { margin: 0 0 6px; font-size: 13px; line-height: 1.5; }
.insight-card p.insight-title { font-weight: 600; color: var(--fg); }
.insight-kv { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; }
.insight-kv dt { font-size: 12px; color: var(--muted); }
.insight-kv dd { margin: 0; font-size: 13px; text-align: right; }
.insight-list { margin: 8px 0 0; padding-left: 18px; }
.insight-list li { margin-bottom: 6px; font-size: 12.5px; line-height: 1.45; }
.insight-note {
  margin: 10px 0 0; padding: 8px 10px; font-size: 12px; line-height: 1.45;
  color: var(--warn); background: var(--warn-bg); border-radius: 6px;
}

/* Narrow screens: the rail stops being a rail and flows beneath the main column. */
@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; }
  .insights {
    position: static; height: auto;
    border-left: 0; border-top: 1px solid var(--line);
  }
  .insights-head { position: static; }
}

/* PDF/print action reads like the link rows. */
button.action-row { width: 100%; font: inherit; font-weight: 600; font-size: 13px; text-align: left; }

/* Print / Save-as-PDF: strip the chrome, force paper colours, keep the report content. */
@media print {
  :root, :root[data-theme="echelon-dark"], :root[data-theme="executive"],
  :root[data-theme="glassbox-light"], :root[data-theme="glassbox-dark"] {
    --bg: #ffffff; --card: #ffffff; --fg: #111827; --muted: #4b5563; --line: #d1d5db;
  }
  body { background: #fff !important; }
  .topbar, .insights, .back-link, button { display: none !important; }
  .workspace { display: block !important; }
  .page { max-width: none !important; padding: 0 !important; }
  a { color: inherit; text-decoration: none; }
  h2 { break-after: avoid; }
  tr { break-inside: avoid; }
  /* Stat tiles: two-up on paper with a smaller number, so big values never clip their box. */
  .cards { grid-template-columns: repeat(2, 1fr) !important; gap: 12px !important; }
  .card-stat { padding: 13px 16px !important; overflow: visible; break-inside: avoid; }
  .stat { font-size: 21px !important; }
  /* Boxes keep their content and don't split awkwardly across pages. */
  .card-stat, .client-summary, .warn-banner, .doc-report, fieldset { break-inside: avoid; }
}
