/* The dashboard's design system.
 *
 * Shares the extension's vocabulary on purpose — a shop sees the confirmation overlay on Mitchell's
 * page and this an hour later, and they have to read as one product. The navy is the same #12325e.
 *
 * SERIES COLOURS ARE NOT THE BRAND COLOURS, and that is deliberate. The brand navy is L 0.32 and
 * nearly achromatic: as a chart fill it fails the lightness band and reads as grey next to the teal.
 * So navy stays UI chrome — header, nav, hero — and the three audit layers get validated steps of
 * the same hue families. The set below passes every check in `dataviz` (lightness band, chroma
 * floor, CVD separation, normal-vision floor, contrast) under --pairs all, in BOTH modes. Do not
 * hand-tune these; re-run the validator.
 */

:root {
  color-scheme: light;

  --page:        #fcfcfb;
  --card:        #ffffff;
  --sunken:      #f6f6f4;
  --line:        #e6e6e1;
  --line-strong: #d3d3cc;

  --ink:         #16161a;
  --ink-2:       #52514e;
  --ink-3:       #86857e;

  --navy:        #12325e;   /* chrome only */
  --navy-ink:    #0d2547;

  /* The three audit layers. Order is LAYER_ORDER in extension/src/audit.ts. */
  --carrier:     #2a78d6;
  --shop:        #0d9488;
  --vehicle:     #eb6834;

  --good:        #12894a;
  --warn:        #b26a00;
  --bad:         #b42318;

  --radius:      10px;
  --shadow:      0 1px 2px rgb(16 24 40 / .05);
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --page: #131315; --card: #1c1c1f; --sunken: #232326;
    --line: #2e2e33; --line-strong: #3d3d44;
    --ink: #f5f5f2; --ink-2: #c3c2b7; --ink-3: #8a897f;
    --navy: #7ba3dd; --navy-ink: #a8c4ea;
    --carrier: #3987e5; --shop: #10a396; --vehicle: #d95926;
    --good: #3dbb78; --warn: #d99a2b; --bad: #e66767;
    --shadow: none;
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --page: #131315; --card: #1c1c1f; --sunken: #232326;
  --line: #2e2e33; --line-strong: #3d3d44;
  --ink: #f5f5f2; --ink-2: #c3c2b7; --ink-3: #8a897f;
  --navy: #7ba3dd; --navy-ink: #a8c4ea;
  --carrier: #3987e5; --shop: #10a396; --vehicle: #d95926;
  --good: #3dbb78; --warn: #d99a2b; --bad: #e66767;
  --shadow: none;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--sans);
  background: var(--page);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}
a { color: inherit; }

/* ── shell ─────────────────────────────────────────────────────────────────────────────────── */

.topbar {
  background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar-in {
  max-width: 1240px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 20px; min-height: 56px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: -.01em; }
.brand .mark {
  width: 24px; height: 24px; border-radius: 6px; background: var(--navy);
  display: grid; place-items: center; color: #fff; font-size: 11px; font-weight: 800;
}
.brand small { display: block; font-weight: 500; font-size: 11px; color: var(--ink-3); line-height: 1; }

/* The signed-in shop, far right of the header. Written by `shell.header()`. */
.who { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-2); }
.who b { font-weight: 700; color: var(--ink); }

/* Straight past the sticky header. Visible only on focus, which is the only time it is wanted. */
.skip {
  position: absolute; left: 12px; top: -60px; z-index: 40;
  background: var(--card); color: var(--ink); border: 1px solid var(--line-strong);
  border-radius: 8px; padding: 8px 13px; font-size: 13px; font-weight: 600; text-decoration: none;
  transition: top .12s ease;
}
.skip:focus { top: 10px; }

/* A label only a screen reader reads, for controls whose purpose is obvious by sight.
 *
 * NOT `position: absolute`, the usual recipe: an abspos element whose containing block is outside a
 * scroll container is not clipped by it, so one inside a wide table escapes `.tablewrap` and pushes
 * the page sideways on a phone. Clipped by its own box, which cannot escape anything. */
.sr-only {
  display: inline-block; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap; vertical-align: middle;
}

nav.main { display: flex; gap: 2px; flex-wrap: wrap; margin-left: auto; }
nav.main a {
  padding: 7px 11px; border-radius: 7px; text-decoration: none;
  font-size: 13px; font-weight: 600; color: var(--ink-2);
}
nav.main a:hover { background: var(--sunken); color: var(--ink); }
nav.main a[aria-current='page'] { background: var(--navy); color: #fff; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) nav.main a[aria-current='page'] { color: #10131a; }
}
:root[data-theme='dark'] nav.main a[aria-current='page'] { color: #10131a; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 22px 20px 64px; }

.pagehead { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.pagehead h1 { font-size: 22px; letter-spacing: -.02em; line-height: 1.2; }
.pagehead p { color: var(--ink-2); font-size: 13px; max-width: 62ch; margin-top: 3px; }

/* Filters in one row above the charts. */
.controls { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-left: auto; }
.seg { display: flex; background: var(--sunken); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.seg button {
  border: 0; background: transparent; font: inherit; font-size: 12px; font-weight: 600;
  color: var(--ink-2); padding: 5px 10px; border-radius: 6px; cursor: pointer;
}
.seg button[aria-pressed='true'] { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.btn {
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--card); color: var(--ink);
  padding: 7px 13px; border-radius: 8px;
}
.btn:hover { background: var(--sunken); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .btn.primary { color: #10131a; } }
:root[data-theme='dark'] .btn.primary { color: #10131a; }

/* ── cards & grid ──────────────────────────────────────────────────────────────────────────── */

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px;
}
.card > h2 { font-size: 14px; letter-spacing: -.005em; margin-bottom: 2px; }
/* `.sub` is used on its own all over the app and only ever had a rule as the first child after a
 * card heading, so everywhere else it inherited body size. The heading rule keeps its margin. */
.sub { color: var(--ink-3); font-size: 12px; }
.card > h2 + .sub { color: var(--ink-3); font-size: 12px; margin-bottom: 14px; }

/* A note that wants noticing without being an error — unanswered audits, a degraded second pass. */
.warnish {
  color: var(--warn); background: color-mix(in oklab, var(--warn) 9%, transparent);
  border: 1px solid color-mix(in oklab, var(--warn) 26%, transparent);
  border-radius: 8px; padding: 7px 11px; display: inline-block;
}
.card > h2:only-of-type { margin-bottom: 12px; }

.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.span2 { grid-column: span 2; }
@media (max-width: 760px) { .span2 { grid-column: auto; } }

/* ── figures ───────────────────────────────────────────────────────────────────────────────── */

/* Exactly one hero per view. Proportional figures — tabular-nums makes a big number look loose. */
.hero { display: flex; gap: 26px; align-items: flex-start; flex-wrap: wrap; }
.hero .fig { font-size: 52px; font-weight: 700; letter-spacing: -.03em; line-height: 1.05; }
.hero .lab { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.hero .since { font-size: 12.5px; color: var(--ink-3); margin-top: 6px; }

/* The tile itself. Only its children were styled, so the figures at the top of the overview and
 * the job page sat as bare text in a grid. Same treatment as `.card`, tighter padding. */
.tile {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 13px 15px;
}
.tile .lab { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.tile .val { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; }
.tile .val.sm { font-size: 20px; }
.tile .note { font-size: 12px; color: var(--ink-3); margin-top: 3px; }
a.tile { text-decoration: none; display: block; }
a.tile:hover { border-color: var(--line-strong); }

.delta { font-size: 12.5px; font-weight: 600; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.delta.flat { color: var(--ink-3); }

/* ── legend & keys ─────────────────────────────────────────────────────────────────────────── */

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

.dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; flex: 0 0 auto; }
.dot.carrier { background: var(--carrier); }
.dot.shop    { background: var(--shop); }
.dot.vehicle { background: var(--vehicle); }

/* ── tables ────────────────────────────────────────────────────────────────────────────────── */

.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--ink-3); padding: 0 10px 7px; white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
th.n, td.n { text-align: right; font-variant-numeric: tabular-nums; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--sunken); }
/* Sortable headers, wired by `shell.sortable()`. The caret is drawn from `aria-sort`, so the arrow
 * and what a screen reader announces cannot disagree — one source for both. */
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: var(--ink); }
th[aria-sort] { color: var(--ink); }
th[data-sort]:focus-visible { outline: 2px solid var(--navy); outline-offset: -2px; border-radius: 4px; }
th[data-sort]::after {
  content: '\2195'; margin-left: 5px; opacity: .28; font-size: 10px; font-weight: 700;
}
th[data-sort]:hover::after { opacity: .6; }
th[aria-sort='ascending']::after  { content: '\2191'; opacity: 1; }
th[aria-sort='descending']::after { content: '\2193'; opacity: 1; }

/* `sortable()` gives this a tabindex so a keyboard user can reach columns past the fold; this is
 * what makes that focus visible. */
.tablewrap:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; border-radius: 6px; }
td .muted, .muted { color: var(--ink-3); }
td a { color: var(--navy); font-weight: 600; text-decoration: none; }
td a:hover { text-decoration: underline; }

/* A capture-rate meter. The track is a lighter step of the fill's own ramp, so state reads
 * across the whole bar rather than only where it is filled. */
.meter { display: flex; align-items: center; gap: 8px; min-width: 128px; }
.meter .track { flex: 1; height: 7px; border-radius: 4px; background: color-mix(in oklab, var(--m) 18%, transparent); overflow: hidden; }
.meter .fill { height: 100%; border-radius: 4px; background: var(--m); }
.meter .pct { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--ink-2); min-width: 34px; text-align: right; }

.pill {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px;
  border-radius: 20px; white-space: nowrap;
}
.pill.ok    { background: color-mix(in oklab, var(--good) 14%, transparent); color: var(--good); }
.pill.warn  { background: color-mix(in oklab, var(--warn) 16%, transparent); color: var(--warn); }
.pill.bad   { background: color-mix(in oklab, var(--bad) 14%, transparent); color: var(--bad); }
.pill.flat  { background: var(--sunken); color: var(--ink-3); }
.pill.trial { background: color-mix(in oklab, var(--shop) 14%, transparent); color: var(--shop); }

/* ── funnel ────────────────────────────────────────────────────────────────────────────────── */

.funnel { display: grid; gap: 10px; }
.funnel .step { display: grid; grid-template-columns: 1fr; gap: 5px; }
.funnel .row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 13px; }
.funnel .row b { font-size: 17px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.funnel .bar { height: 12px; border-radius: 4px; background: var(--f, var(--carrier)); }
.funnel .why { font-size: 12px; color: var(--ink-3); }

/* ── notes, empty states ───────────────────────────────────────────────────────────────────── */

.empty {
  border: 1px dashed var(--line-strong); border-radius: var(--radius);
  padding: 26px 22px; text-align: center; color: var(--ink-2); background: var(--card);
}
.empty h2, .empty h3 { font-size: 15px; color: var(--ink); margin-bottom: 5px; }
.empty p { font-size: 13px; max-width: 52ch; margin: 0 auto 12px; }
.empty .how { text-align: left; max-width: 46ch; margin: 0 auto; font-size: 13px; }
.empty .how li { margin: 5px 0 5px 18px; }

details.assump { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
details.assump summary { cursor: pointer; font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
details.assump .body { margin-top: 10px; font-size: 12.5px; color: var(--ink-2); }
details.assump code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
  background: var(--sunken); padding: 1px 5px; border-radius: 4px;
}

.err { background: color-mix(in oklab, var(--bad) 9%, transparent); border: 1px solid color-mix(in oklab, var(--bad) 30%, transparent);
       color: var(--bad); border-radius: 8px; padding: 10px 13px; font-size: 13px; margin-bottom: 14px; }

.skel { background: var(--sunken); border-radius: 6px; height: 1em; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .5 } }

/* ── charts ────────────────────────────────────────────────────────────────────────────────── */

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--ink-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .lbl { fill: var(--ink-2); font-size: 11px; font-weight: 600; }
.tip {
  position: absolute; pointer-events: none; z-index: 5; opacity: 0; transition: opacity .1s;
  background: var(--card); border: 1px solid var(--line-strong); border-radius: 8px;
  box-shadow: 0 6px 20px rgb(16 24 40 / .13); padding: 8px 10px; font-size: 12px;
  min-width: 130px; white-space: nowrap;
}
.tip.on { opacity: 1; }
.tip .t { font-weight: 700; margin-bottom: 4px; }
.tip .r { display: flex; justify-content: space-between; gap: 14px; }
.tip .r b { font-variant-numeric: tabular-nums; }

/* ── print: the board pack ─────────────────────────────────────────────────────────────────── */

@media print {
  .topbar, .controls, .btn, .noprint { display: none !important; }
  body { background: #fff; }
  .wrap { max-width: none; padding: 0; }
  .card { break-inside: avoid; border-color: #ccc; box-shadow: none; }
  .grid { gap: 10px; }
}

/* ── the tier ladder ──────────────────────────────────────────────────────────────────────────
   Bands of ONE scale, not three identities, so it is one hue with marked boundaries rather than
   three categorical colours — three hues would say these are different KINDS of thing. The fill
   turns amber only as a boundary approaches, and status colour never doubles as a series colour. */
.ladder { margin-top: 4px; }
.ladder .track {
  position: relative; height: 10px; border-radius: 5px; background: var(--sunken);
  border: 1px solid var(--line); overflow: hidden;
}
.ladder .fill { height: 100%; background: var(--m, var(--shop)); border-radius: 5px 0 0 5px; }
/* Boundaries sit ON the track as hairlines — a tick that floats above it reads as decoration. */
.ladder .edge { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--line-strong); }
.ladder .marks { position: relative; height: 34px; margin-top: 6px; }
.ladder .mark { position: absolute; transform: translateX(-50%); text-align: center; white-space: nowrap; }
.ladder .mark b { display: block; font-size: 12px; font-variant-numeric: tabular-nums; }
.ladder .mark span { font-size: 11px; color: var(--ink-3); }
.ladder .mark.on b { color: var(--ink); }
.ladder .mark.on span { color: var(--ink-2); font-weight: 600; }
.ladder .mark.off b, .ladder .mark.off span { color: var(--ink-3); }

/* The allowance meter — taller than the inline `.meter`, because it is the page's subject. */
.allowance .track { height: 14px; border-radius: 7px; background: var(--sunken); border: 1px solid var(--line); overflow: hidden; }
.allowance .fill { height: 100%; background: var(--m, var(--shop)); border-radius: 7px 0 0 7px; }

/* Trial banner — the first thing a new shop sees, and the only place the end of the trial is
   explained before it arrives. */
.trialbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
            border: 1px solid color-mix(in oklab, var(--shop) 30%, var(--line));
            background: color-mix(in oklab, var(--shop) 6%, transparent);
            border-radius: 12px; padding: 14px 16px; margin-bottom: 14px; }
.trialbar.out { border-color: color-mix(in oklab, var(--warn) 40%, var(--line));
                background: color-mix(in oklab, var(--warn) 7%, transparent); }
.trialbar .n { font-size: 26px; font-weight: 650; letter-spacing: -.02em; color: var(--shop); }
.trialbar.out .n { color: var(--warn); }
.trialbar .t { font-weight: 600; color: var(--ink); }
.trialbar .s { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.trialbar .go { margin-left: auto; }
