:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --wash: rgba(11, 11, 11, 0.05);
  --link: #1c5cab;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;
  --series-other: #898781;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --wash: rgba(255, 255, 255, 0.06);
    --link: #86b6ef;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --wash: rgba(255, 255, 255, 0.06);
  --link: #86b6ef;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
.viz-root { max-width: 1180px; margin: 0 auto; padding: 32px 20px 64px; background: var(--page); }
a { color: var(--link); }
code { font-size: 0.9em; background: var(--wash); padding: 0 4px; border-radius: 4px; }
h1 { font-size: 28px; line-height: 1.2; margin: 0 0 6px; font-weight: 650; }
h2 { font-size: 16px; margin: 0; font-weight: 600; }
.lede { margin: 0; color: var(--text-secondary); max-width: 70ch; }
.help { margin: 8px 0 0; color: var(--text-muted); font-size: 13px; }

.page-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 24px; }
button, select, input {
  font: inherit; color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px;
}
button { cursor: pointer; }
button.ghost:hover { background: var(--wash); }
input[type="checkbox"] { padding: 0; accent-color: var(--series-1); }

/* Filter row: one row above everything it scopes */
.filters { display: flex; flex-wrap: wrap; gap: 16px 24px; align-items: flex-end; margin-bottom: 20px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 12px; color: var(--text-secondary); font-weight: 500; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-1); }
.seg button { border: 0; border-radius: 0; padding: 6px 12px; background: transparent; color: var(--text-secondary); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button:hover { background: var(--wash); }
.seg button[aria-checked="true"] { color: var(--text-primary); font-weight: 600; background: var(--wash); }
.repo-field { flex: 1 1 320px; }
.repo-picker { display: flex; gap: 6px; }
.repo-picker input { flex: 1; min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 10px; font-size: 13px; border-radius: 999px; }
.chip span { font-size: 15px; line-height: 1; padding: 0 4px; color: var(--text-muted); }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--text-secondary); padding-bottom: 7px; }

/* KPI row */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.kpi-label { font-size: 13px; color: var(--text-secondary); }
.kpi-value { font-size: 30px; font-weight: 600; line-height: 1.2; margin-top: 4px; }
.kpi-note { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.kpi.hero .kpi-value { font-size: 48px; }

.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 20px; margin-bottom: 16px; min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px; margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
.grid2 .card { margin-bottom: 0; }
.grid2 { margin-bottom: 16px; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }

.chart { position: relative; width: 100%; }
.chart:focus-visible { outline: 2px solid var(--series-1); outline-offset: 4px; border-radius: 4px; }
.chart svg { display: block; overflow: visible; }
.chart text { fill: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart text.label { fill: var(--text-secondary); font-variant-numeric: normal; }
.chart text.value { fill: var(--text-primary); font-weight: 500; }
.chart .grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .hover-band { fill: var(--wash); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .bar-row:hover .bar, .chart .bar-row:focus .bar { filter: brightness(1.12); }
.chart .bar-row:focus { outline: none; }
.chart .bar-row:focus-visible .hit { stroke: var(--series-1); stroke-width: 2; }
.empty { color: var(--text-muted); padding: 40px 0; text-align: center; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--text-secondary); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

.tooltip {
  position: fixed; z-index: 10; pointer-events: none; min-width: 160px; max-width: 300px;
  background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}
.tooltip .tt-title { color: var(--text-secondary); margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; }
.tooltip .tt-row b { font-variant-numeric: tabular-nums; min-width: 2.5em; }
.tooltip .tt-row i { width: 12px; height: 2px; border-radius: 1px; display: inline-block; }
.tooltip .tt-row .muted { color: var(--text-secondary); }
.tooltip .tt-foot { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 6px; color: var(--text-secondary); }

details { margin-top: 12px; }
summary { cursor: pointer; color: var(--text-secondary); font-size: 14px; }
.table-wrap { overflow: auto; max-height: 360px; margin-top: 8px; }
.table-wrap.tall { max-height: 560px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
th { position: sticky; top: 0; background: var(--surface-1); color: var(--text-secondary); font-weight: 500; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.nowrap { white-space: nowrap; }
td .key { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
#search { width: min(340px, 100%); }
.method ul { padding-left: 20px; margin: 12px 0 0; color: var(--text-secondary); }
.method li { margin-bottom: 8px; }
.method strong { color: var(--text-primary); font-weight: 600; }

@media (max-width: 640px) {
  .viz-root { padding: 20px 12px 48px; }
  h1 { font-size: 22px; }
  .kpi.hero .kpi-value { font-size: 40px; }
}
.evidence { margin-top: 2px; color: var(--text-secondary); }
.badge {
  display: inline-block; margin-right: 6px; padding: 0 6px; border-radius: 999px; font-size: 11px;
  border: 1px solid var(--border); background: var(--wash); color: var(--text-secondary); white-space: nowrap;
}
