/* Palette: the validated data-viz reference instance. Every colour is defined
   once on :root (light), then restated for the OS dark setting and for the
   explicit toggle, so neither can strand the other. */

:root {
  color-scheme: light;

  --plane: #f9f9f7;
  --surface-1: #fcfcfb;
  --surface-2: #f2f1ed;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --focus: #2a78d6;

  /* Categorical, in the validated order. Never cycled. */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;

  /* Sequential blue, 100 -> 700, for the matrix heat. */
  --seq-0: #f2f1ed;
  --seq-1: #cde2fb;
  --seq-2: #9ec5f4;
  --seq-3: #6da7ec;
  --seq-4: #3987e5;
  --seq-5: #256abf;
  --seq-6: #184f95;
  --seq-7: #0d366b;
  /* Ink that stays legible from --seq-4 up. */
  --seq-ink-dark: #0b0b0b;
  --seq-ink-light: #ffffff;

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-critical: #d03b3b;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane: #0d0d0d;
    --surface-1: #1a1a19;
    --surface-2: #232322;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --focus: #3987e5;

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;

    --seq-0: #232322;
    --seq-1: #0d366b;
    --seq-2: #184f95;
    --seq-3: #256abf;
    --seq-4: #3987e5;
    --seq-5: #6da7ec;
    --seq-6: #9ec5f4;
    --seq-7: #cde2fb;
    --seq-ink-dark: #ffffff;
    --seq-ink-light: #0b0b0b;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #232322;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --focus: #3987e5;

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;

  --seq-0: #232322;
  --seq-1: #0d366b;
  --seq-2: #184f95;
  --seq-3: #256abf;
  --seq-4: #3987e5;
  --seq-5: #6da7ec;
  --seq-6: #9ec5f4;
  --seq-7: #cde2fb;
  --seq-ink-dark: #ffffff;
  --seq-ink-light: #0b0b0b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--text-primary);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }

.meta { margin: 2px 0 0; color: var(--text-muted); font-size: 12px; }

/* ── Chrome ───────────────────────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: color-mix(in srgb, var(--plane) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar__actions { display: flex; gap: 8px; }

.btn {
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 6px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.btn--icon { padding: 6px 9px; }
.btn[aria-busy="true"] { opacity: 0.55; cursor: progress; }

main { max-width: 1400px; margin: 0 auto; padding: 20px 24px 64px; }

.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 20px;
}
.panel__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.panel__sub { margin: 4px 0 0; color: var(--text-secondary); font-size: 12.5px; max-width: 62ch; }

.scroller { overflow-x: auto; }

/* ── Stat tiles ───────────────────────────────────────────────────────────── */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.tile__value { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; }
.tile__label { color: var(--text-secondary); font-size: 12px; margin-top: 2px; }
.tile__note { color: var(--text-muted); font-size: 11.5px; margin-top: 6px; }

/* ── Matrix ───────────────────────────────────────────────────────────────── */

table.matrix { border-collapse: separate; border-spacing: 2px; font-size: 12px; }
table.matrix th { font-weight: 500; color: var(--text-secondary); text-align: left; }
table.matrix thead th {
  vertical-align: bottom;
  padding: 0 4px 6px;
  font-size: 11.5px;
  white-space: nowrap;
}
table.matrix thead th.col { text-align: center; min-width: 74px; }
table.matrix th.row {
  padding: 0 12px 0 4px;
  white-space: nowrap;
  color: var(--text-primary);
  font-weight: 500;
}
table.matrix th.row .rule { display: block; color: var(--text-muted); font-size: 11px; font-weight: 400; }
tr.group th {
  padding: 14px 4px 4px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
tr.group:first-child th { padding-top: 0; }

.cell {
  width: 74px;
  height: 34px;
  border: 0;
  border-radius: 6px;
  font: inherit;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  padding: 0;
  display: block;
  background: var(--seq-0);
  color: var(--text-secondary);
}
.cell--empty {
  background: transparent;
  border: 1px dashed var(--axis);
  color: var(--text-muted);
}
.cell:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.cell:hover { filter: brightness(1.06); }
.cell--on { box-shadow: 0 0 0 2px var(--surface-1), 0 0 0 4px var(--focus); }
.cell--total {
  background: transparent;
  color: var(--text-primary);
  font-weight: 600;
  cursor: default;
  border-left: 1px solid var(--grid);
  border-radius: 0;
}

.scale { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 11px; }
.scale__swatches { display: flex; gap: 2px; }
.scale__swatch { width: 20px; height: 10px; border-radius: 2px; }

/* ── Stacked bars ─────────────────────────────────────────────────────────── */

.bars { display: grid; gap: 6px; min-width: 620px; }
.bar-row {
  display: grid;
  grid-template-columns: 160px 1fr 52px;
  align-items: center;
  gap: 12px;
}
.bar-row__label { font-size: 12.5px; color: var(--text-primary); text-align: right; }
.bar-row__track { display: flex; gap: 2px; height: 18px; }
.bar-seg { border-radius: 2px; min-width: 2px; }
.bar-seg:first-child { border-top-left-radius: 4px; border-bottom-left-radius: 4px; }
.bar-seg:last-child { border-top-right-radius: 4px; border-bottom-right-radius: 4px; }
.bar-row__value {
  font-size: 12px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 11.5px; color: var(--text-secondary); }
.legend__item { display: flex; align-items: center; gap: 6px; }
.legend__dot { width: 9px; height: 9px; border-radius: 2px; }

/* ── Controls, chips ──────────────────────────────────────────────────────── */

.controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.input {
  flex: 1 1 280px;
  min-width: 220px;
  padding: 7px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
  font: inherit;
  font-size: 13px;
}
.input:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
}
.chip__dot { width: 8px; height: 8px; border-radius: 2px; }
.chip:hover { color: var(--text-primary); }

/* ── File list ────────────────────────────────────────────────────────────── */

.file { border-top: 1px solid var(--grid); }
.file:last-child { border-bottom: 1px solid var(--grid); }
.file__head {
  display: grid;
  grid-template-columns: 12px 1fr auto auto auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 4px;
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.file__head:hover { background: var(--surface-2); }
.file__head:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.file__dot { width: 8px; height: 8px; border-radius: 2px; }
.file__path { font-size: 12.5px; overflow-wrap: anywhere; }
.file__path b { font-weight: 600; }
.file__path span { color: var(--text-muted); }
.file__tag {
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}
.file__count { font-size: 12px; color: var(--text-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.file__date { font-size: 11.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

.cases { margin: 0 0 10px; padding: 0 4px 0 34px; list-style: none; }
.case { display: flex; gap: 10px; padding: 3px 0; font-size: 12.5px; color: var(--text-secondary); }
.case__line { color: var(--text-muted); font-variant-numeric: tabular-nums; min-width: 42px; text-align: right; }
.case__suite { color: var(--text-muted); }
.case--skipped .case__title { text-decoration: line-through; }
.case__badge {
  font-size: 10.5px;
  border-radius: 999px;
  padding: 0 6px;
  border: 1px solid var(--status-warning);
  color: var(--text-secondary);
}
.case__title mark { background: color-mix(in srgb, var(--series-4) 40%, transparent); color: inherit; border-radius: 2px; }
.case--dynamic .case__title { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; }

.empty { padding: 24px 4px; color: var(--text-muted); font-size: 13px; }

/* ── Tooltip ──────────────────────────────────────────────────────────────── */

.tooltip {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  max-width: 280px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  font-size: 12px;
  color: var(--text-primary);
}
.tooltip b { display: block; margin-bottom: 2px; }
.tooltip span { color: var(--text-secondary); }

@media (max-width: 720px) {
  .bar-row { grid-template-columns: 108px 1fr 44px; }
  .file__head { grid-template-columns: 12px 1fr auto; }
  .file__tag, .file__date { display: none; }
}

/* ── Heat steps ───────────────────────────────────────────────────────────────
   Sequential blue, one hue, light -> dark on the light surface and dark ->
   light on the dark one (a sequential ramp is re-stepped per surface, never
   flipped automatically). Every cell also carries its number, which is what
   satisfies the relief rule for the lighter steps. */

.heat-1 { background: #cde2fb; color: #0b0b0b; }
.heat-2 { background: #9ec5f4; color: #0b0b0b; }
.heat-3 { background: #6da7ec; color: #0b0b0b; }
.heat-4 { background: #3987e5; color: #ffffff; }
.heat-5 { background: #256abf; color: #ffffff; }
.heat-6 { background: #184f95; color: #ffffff; }
.heat-7 { background: #0d366b; color: #ffffff; }

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .heat-1 { background: #0d366b; color: #ffffff; }
  :root:where(:not([data-theme="light"])) .heat-2 { background: #184f95; color: #ffffff; }
  :root:where(:not([data-theme="light"])) .heat-3 { background: #256abf; color: #ffffff; }
  :root:where(:not([data-theme="light"])) .heat-4 { background: #3987e5; color: #ffffff; }
  :root:where(:not([data-theme="light"])) .heat-5 { background: #6da7ec; color: #0b0b0b; }
  :root:where(:not([data-theme="light"])) .heat-6 { background: #9ec5f4; color: #0b0b0b; }
  :root:where(:not([data-theme="light"])) .heat-7 { background: #cde2fb; color: #0b0b0b; }
}

:root[data-theme="dark"] .heat-1 { background: #0d366b; color: #ffffff; }
:root[data-theme="dark"] .heat-2 { background: #184f95; color: #ffffff; }
:root[data-theme="dark"] .heat-3 { background: #256abf; color: #ffffff; }
:root[data-theme="dark"] .heat-4 { background: #3987e5; color: #ffffff; }
:root[data-theme="dark"] .heat-5 { background: #6da7ec; color: #0b0b0b; }
:root[data-theme="dark"] .heat-6 { background: #9ec5f4; color: #0b0b0b; }
:root[data-theme="dark"] .heat-7 { background: #cde2fb; color: #0b0b0b; }

/* The file list runs to 400-odd rows. It scrolls inside the panel rather than
   stretching the page to 19,000px. */
.filelist {
  max-height: 620px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
