/* Exaba Analytics — browser app.
   Palette and mark specs match the library's SVG renderer, so a chart looks the
   same here, in a served SVG and on a PDF page. Dark mode is a selected set of
   steps for the dark surface, not an automatic inversion. */

:root {
  color-scheme: light;
  --surface:        #fcfcfb;
  --surface-raised: #ffffff;
  --surface-sunken: #f3f2ee;
  --ink:            #0b0b0b;
  --ink-secondary:  #52514e;
  --ink-muted:      #6b6a66;
  --grid:           #e8e7e3;
  --axis:           #c9c8c3;
  --accent:         #2a78d6;
  --exaba:          #ffff00;  /* the Exaba yellow: the selected tab and the generate buttons */
  --good:           #008300;
  --warn:           #eda100;
  --bad:            #e34948;
  --radius: 10px;
  --pad: 16px;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface:        #1a1a19;
    --surface-raised: #232322;
    --surface-sunken: #141413;
    --ink:            #ffffff;
    --ink-secondary:  #c3c2b7;
    --ink-muted:      #9b9a92;
    --grid:           #2e2e2b;
    --axis:           #464642;
    --accent:         #3987e5;
    --good:           #2fa32f;
    --warn:           #c98500;
    --bad:            #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface:        #1a1a19;
  --surface-raised: #232322;
  --surface-sunken: #141413;
  --ink:            #ffffff;
  --ink-secondary:  #c3c2b7;
  --ink-muted:      #9b9a92;
  --grid:           #2e2e2b;
  --axis:           #464642;
  --accent:         #3987e5;
  --good:           #2fa32f;
  --warn:           #c98500;
  --bad:            #e66767;
}

* { box-sizing: border-box; }
img { max-width: 100%; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1120px; margin: 0 auto; padding: 24px 16px 64px; }

header.top { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
header.top h1 { font-size: 20px; margin: 0; letter-spacing: -0.01em; }
header.top .tag {
  font-size: 11px; color: var(--good); border: 1px solid currentColor;
  border-radius: 999px; padding: 2px 8px; font-weight: 600;
}
.lede { color: var(--ink-muted); margin: 0 0 20px; max-width: 70ch; }

/* ---- Drop zone + paste box ---- */
.intake { display: grid; gap: 12px; }
.drop {
  border: 2px dashed var(--axis);
  border-radius: var(--radius);
  padding: 22px;
  text-align: center;
  background: var(--surface-sunken);
  transition: border-color .15s, background .15s;
}
.drop.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface-sunken)); }
.drop p { margin: 0 0 10px; color: var(--ink-secondary); }
.drop .hint { font-size: 12px; color: var(--ink-muted); }

textarea {
  width: 100%; min-height: 140px; resize: vertical;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  padding: 12px; border-radius: var(--radius);
  border: 1px solid var(--axis); background: var(--surface-raised); color: var(--ink);
}
textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
button {
  font: inherit; font-weight: 600; cursor: pointer;
  border-radius: 8px; padding: 8px 14px;
  border: 1px solid var(--axis); background: var(--surface-raised); color: var(--ink);
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button:hover:not(:disabled) { filter: brightness(1.06); }
button:disabled { opacity: .5; cursor: not-allowed; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Messages ---- */
.note, .err {
  border-radius: var(--radius); padding: 12px 14px; margin: 14px 0; font-size: 13px;
  border-left: 3px solid;
}
.note { background: var(--surface-sunken); border-color: var(--accent); color: var(--ink-secondary); }
.err  { background: color-mix(in srgb, var(--bad) 10%, var(--surface)); border-color: var(--bad); color: var(--ink); }
.err h3 { margin: 0 0 6px; font-size: 13px; }
.err code, .note code {
  font: 12px ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--surface-sunken); padding: 1px 5px; border-radius: 4px;
}
.err ul { margin: 6px 0 0 18px; padding: 0; }

/* ---- Stat tiles ---- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin: 18px 0; }
.tile { background: var(--surface-sunken); border-radius: var(--radius); padding: 12px 14px; }
.tile .label { font-size: 11px; color: var(--ink-muted); }
.tile .value { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; margin-top: 2px; }
.tile .delta { font-size: 11px; color: var(--ink-secondary); margin-top: 2px; }
.tile .delta.up { color: var(--good); }
.tile .delta.down { color: var(--bad); }

/* ---- Cards, charts, tables ---- */
.card {
  background: var(--surface-raised); border: 1px solid var(--grid);
  border-radius: var(--radius); padding: 16px; margin: 16px 0;
}
.card > h2 { font-size: 15px; margin: 0 0 2px; }
.card > .sub { font-size: 12px; color: var(--ink-muted); margin: 0 0 12px; }
.chart { overflow-x: auto; }
/* A figure scales to its card rather than being cut off by it; below the
   minimum it scrolls instead of becoming unreadable. */
.chart svg { display: block; min-width: 520px; width: 100%; height: auto; }

table { border-collapse: collapse; width: 100%; font-size: 13px; }
.scroll { overflow-x: auto; }
th, td { padding: 6px 10px; text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th {
  font-size: 11px; color: var(--ink-secondary); font-weight: 600;
  border-bottom: 1px solid var(--axis); position: sticky; top: 0; background: var(--surface-raised);
}
tbody tr + tr td { border-top: 1px solid var(--grid); }
tbody td { font-variant-numeric: tabular-nums; }
tfoot td { border-top: 1px solid var(--axis); font-weight: 600; }
td.pos { color: var(--good); }
td.neg { color: var(--bad); }

/* Cohort heatmap: one hue, light to dark. */
.heat td.cell { color: #fff; text-align: center; border-radius: 3px; }
.heat td.cell.light { color: var(--ink); }
.heat td.empty { background: transparent; }

.controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.controls label { display: grid; gap: 3px; font-size: 11px; color: var(--ink-muted); }
select, input[type="number"] {
  font: inherit; font-size: 13px; padding: 5px 8px; border-radius: 7px;
  border: 1px solid var(--axis); background: var(--surface-raised); color: var(--ink);
}

footer.foot { margin-top: 36px; font-size: 12px; color: var(--ink-muted); border-top: 1px solid var(--grid); padding-top: 14px; }
footer.foot a { color: var(--accent); }

@media (max-width: 560px) {
  .wrap { padding: 16px 16px 48px; }
  .tile .value { font-size: 19px; }
}

/* ---- Tabs ---- */
nav.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--grid); margin: 0 0 18px; }
nav.tabs .tab {
  border: none; border-bottom: 2px solid transparent; border-radius: 0;
  background: transparent; color: var(--ink-muted); padding: 8px 14px; margin-bottom: -1px;
}
nav.tabs .tab.active { color: #0b0b0b; background: var(--exaba); border-bottom-color: var(--exaba); border-radius: 8px 8px 0 0; }
nav.tabs .tab:hover { color: var(--ink); }

/* Cohort roster: a cell per customer, coloured by whether they are still here. */
table.roster td.cell { text-align: left; white-space: nowrap; min-width: 0; padding: 3px 8px; border-radius: 6px; vertical-align: top; font-size: 12px; font-variant-numeric: tabular-nums; cursor: help; }
table.roster td.cell.active { color: var(--good); background: color-mix(in srgb, var(--good) 10%, var(--surface)); }
table.roster td.cell.left { color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, var(--surface)); text-decoration: line-through; text-decoration-thickness: 1px; }
button.generate { background: var(--exaba); border-color: var(--exaba); color: #0b0b0b; }
button.generate:focus-visible { outline-color: var(--exaba); }

/* Columns tab: prose cells. */
table.columns td { text-align: left; white-space: normal; vertical-align: top; }
table.columns td:first-child { white-space: nowrap; }
table.roster tfoot td { border-top: 2px solid var(--axis); font-weight: 600; }
table.scorecard td.total { font-weight: 600; border-left: 1px solid var(--axis); }
.tile { cursor: help; }
.tile .label .src { float: right; font-size: 9px; letter-spacing: .04em; text-transform: uppercase; padding: 1px 5px; border-radius: 6px; border: 1px solid var(--axis); color: var(--ink-muted); }
.tile .label .src.computed { border-color: var(--accent); color: var(--accent); }
.tile .label .star { color: var(--accent); font-weight: 700; }
table.ledger td svg { display: block; }
/* Retention bands: GRR green at 91%+, red at 76% or below, orange between. */
.tile .value.good, td.good { color: var(--good); }
.tile .value.warn, td.warn { color: var(--warn); }
.tile .value.bad, td.bad { color: var(--bad); }
/* Validation errors list one problem per line. */
.err .message, .err p { white-space: pre-line; }
/* Page filters */
.filters .row button { padding: 6px 10px; font-weight: 500; }
.picks { border: 1px solid var(--axis); border-radius: 8px; padding: 4px 10px 6px; margin: 0; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.picks legend { font-size: 11px; color: var(--ink-muted); padding: 0 4px; }
.picks .pick { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; }
input[type="month"] { font: inherit; padding: 6px 8px; border: 1px solid var(--axis); border-radius: 8px; background: var(--surface-raised); color: var(--ink); }

/* The example ladder on the Fake Data tab. */
ol.ladder { padding-left: 1.4em; margin: 0.4em 0 0; }
ol.ladder li { margin: 0.7em 0 0.9em; }
ol.ladder li .sub { margin: 0.15em 0; }
ol.ladder li button { margin-top: 0.35em; }

/* The as-of replay control. */
.replay input[type="range"] { width: 22em; vertical-align: middle; margin-left: 0.5em; }
.replay .hint { display: block; margin-top: 0.3em; }
/* Ledger: the date axis sits exactly over the sparkline's width, first month at the left edge, last at the right. */
table.ledger th .axis { display: inline-flex; justify-content: space-between; font-weight: 500; color: var(--ink-muted); font-size: 11px; }
.legend .key { font-weight: 700; }
.legend .key.gain { color: var(--good); }
.legend .key.loss { color: var(--bad); }
.legend .key.muted { color: var(--ink-muted); }
/* Scorecards: the metric column and the header stay put when the table scrolls sideways, and every column says what it is. */
table.scorecard th:first-child, table.scorecard td:first-child { position: sticky; left: 0; background: var(--surface-raised); z-index: 1; }
table.scorecard th.total { border-left: 1px solid var(--axis); }
table.scorecard th .dim { display: block; font-size: 9px; font-weight: 500; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-muted); }
nav.tabs { flex-wrap: wrap; }
/* Tile groups inside a card, and the section headings between groups of graphs. */
.card h3.group { font-size: 13px; margin: 14px 0 0; }
.card h3.group .sub { font-weight: 400; color: var(--ink-muted); font-size: 12px; }
.card h3.group + .tiles { margin-top: 8px; }
.section { margin: 26px 0 8px; padding: 0 2px; }
.section h2 { font-size: 17px; margin: 0; }
.section .sub { font-size: 12px; color: var(--ink-muted); margin: 2px 0 0; }
/* Where a figure was seen in public reporting. */
.card > .sub.provenance { font-size: 11px; color: var(--ink-muted); margin: -8px 0 12px; }
.card > .sub.provenance .k { font-weight: 600; letter-spacing: .02em; }
/* Reconciliation: a green card when every cross-check holds, red when any fails. */
.card.reconcile.ok { border-left: 4px solid var(--good); }
.card.reconcile.bad { border-left: 4px solid var(--bad); }
.card.reconcile.bad > h2 { color: var(--bad); }
.card.reconcile > h2 { font-size: 14px; }
button.link { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font-size: 12px; }
table.checks td { white-space: normal; }
/* Board focus: a tile the file cannot feed is dimmed and says so. */
.tile.missing { opacity: .6; border: 1px dashed var(--axis); }
.tile .value.up { color: var(--good); }
.tile .value.down { color: var(--bad); }
/* ---- Phone navigation: one button naming the section, a full list on tap ---- */
.menu-toggle { display: none; }
@media (max-width: 640px) {
  .menu-toggle {
    display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px;
    margin: 0 0 8px; padding: 10px 14px; border: 1px solid var(--grid); border-radius: var(--radius);
    background: var(--surface-raised); color: var(--ink); font-size: 15px; font-weight: 600; text-align: left;
  }
  .menu-toggle .burger { font-size: 18px; color: var(--ink-muted); }
  .menu-toggle .current { flex: 1; }
  .menu-toggle .hint { font-size: 12px; font-weight: 400; color: var(--accent); }
  nav.tabs { display: none; flex-direction: column; gap: 0; border: 1px solid var(--grid); border-radius: var(--radius); overflow: hidden; margin: 0 0 16px; }
  nav.tabs.open { display: flex; }
  nav.tabs .tab { width: 100%; min-height: 44px; text-align: left; padding: 12px 16px; margin: 0; border-bottom: 1px solid var(--grid); border-radius: 0; font-size: 15px; }
  nav.tabs .tab:last-child { border-bottom: none; }
  nav.tabs .tab.active { border-radius: 0; }
  /* Comfortable taps and no iOS zoom on focus. */
  button, select, input, textarea { font-size: 16px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile .value { font-size: 20px; }
  .wrap { padding: 12px 12px 48px; }
  .card { padding: 12px; }
  h1 { font-size: 20px; }
}
/* The book-kind card leads the Analytics tab. */
.card.kindcard { border-left: 4px solid var(--accent); }
.card.kindcard > h2 { font-size: 17px; }
/* Valuation caveats read as a list, not a wall. */
ul.caveats { margin: 6px 0 0; padding-left: 20px; font-size: 13px; color: var(--ink-secondary); }
ul.caveats li { margin: 4px 0; }
table.scorecard tr.total td { border-top: 2px solid var(--axis); font-weight: 600; }
/* The catalogue is prose in a table: long definitions and provenance notes
   must wrap rather than push the columns off the side of the page. */
#catalogue_graphs table td, #catalogue_metrics table td { white-space: normal; vertical-align: top; }
#catalogue_graphs table td:first-child, #catalogue_metrics table td:first-child { white-space: nowrap; }
#catalogue_graphs table td:nth-child(3) { max-width: 46ch; font-size: 12px; }
#catalogue_metrics table td:nth-child(3) { max-width: 52ch; }
#catalogue_metrics table td:nth-child(4) { max-width: 30ch; }
/* Generated data says so once, quietly, and stays out of the way. A banner
   shouting at every scroll stops being read after the first minute. */
.fake-note {
  margin: 0 0 12px; padding: 8px 12px; border-radius: var(--radius);
  background: var(--surface-raised); border: 1px solid var(--grid);
  color: var(--ink-secondary); font-size: 13px;
}
.fake-note strong { color: var(--ink); }
/* The example ladder, grouped by the kind of business rather than by file
   format, because a reader arrives knowing what they run. */
.group { margin: 0 0 22px; }
.group h3 { margin: 0 0 4px; font-size: 15px; }
.group > .sub { margin: 0 0 10px; max-width: 70ch; }
.sub.dim { color: var(--ink-muted); font-size: 12px; }
