/* ATLAS — data intelligence console
   Portfolio concept. Light "technical paper" theme with a dark variant.
   Every colour, size and rule is a token so the SVG charts can read them too. */

:root {
  --paper: #f1f0ea;
  --panel: #fbfaf6;
  --panel-2: #f6f4ee;
  --ink: #14161a;
  --ink-2: #565d6b;
  --ink-3: #8b91a0;
  --rule: #d9d5c9;
  --rule-strong: #bab5a5;
  --accent: #0f5f57;
  --accent-soft: #dfeae6;
  --accent-ink: #08403a;
  --signal: #b03d12;
  --signal-soft: #f6e3d8;
  --good: #16624a;
  --bad: #a63314;
  --focus: #0b4de0;

  --cat-0: #0f5f57;
  --cat-1: #26418f;
  --cat-2: #9a5a06;
  --cat-3: #7a2f5f;
  --cat-4: #4a5666;

  --ramp-0: #ecebe4;
  --ramp-1: #d3e2dc;
  --ramp-2: #a9c9c0;
  --ramp-3: #74a89e;
  --ramp-4: #3d857b;
  --ramp-5: #0f5f57;

  /* Text colour paired with each ramp step so labels always clear 4.5:1. */
  --ramp-ink-0: #14161a;
  --ramp-ink-1: #14161a;
  --ramp-ink-2: #102622;
  --ramp-ink-3: #0a1c19;
  --ramp-ink-4: #f4f7f5;
  --ramp-ink-5: #f4f7f5;

  --grid-line: rgba(20, 22, 26, .05);
  --shadow: 0 1px 0 rgba(20, 22, 26, .04), 0 12px 30px -24px rgba(20, 22, 26, .55);

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --pad: clamp(18px, 4vw, 46px);
  --radius: 10px;
}

:root[data-theme="dark"] {
  --paper: #0b0d11;
  --panel: #12161c;
  --panel-2: #171c24;
  --ink: #eef1f5;
  --ink-2: #a3abba;
  --ink-3: #6d7686;
  --rule: #242c37;
  --rule-strong: #3a4553;
  --accent: #3fd0b8;
  --accent-soft: #14312e;
  --accent-ink: #a6efe1;
  --signal: #ff8a4c;
  --signal-soft: #35211a;
  --good: #4fd6a8;
  --bad: #ff7a63;
  --focus: #7aa2ff;

  --cat-0: #3fd0b8;
  --cat-1: #7aa2ff;
  --cat-2: #e8b04b;
  --cat-3: #e58ac4;
  --cat-4: #97a4b6;

  --ramp-0: #161b22;
  --ramp-1: #17332f;
  --ramp-2: #1d4f47;
  --ramp-3: #256d61;
  --ramp-4: #2f9e8b;
  --ramp-5: #3fd0b8;

  --ramp-ink-0: #c3cbd8;
  --ramp-ink-1: #cfe6e0;
  --ramp-ink-2: #dbf1eb;
  --ramp-ink-3: #eafaf6;
  --ramp-ink-4: #07211d;
  --ramp-ink-5: #062018;

  --grid-line: rgba(238, 241, 245, .05);
  --shadow: 0 1px 0 rgba(0, 0, 0, .4), 0 18px 40px -30px #000;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 28px 28px, 28px 28px;
  color: var(--ink);
  font: 400 16px/1.55 var(--sans);
  font-synthesis-weight: none;
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
p { margin: 0; }
ul, ol, dl, dd { margin: 0; padding: 0; }
li { list-style: none; }
code, kbd { font-family: var(--mono); font-size: .88em; }
kbd {
  border: 1px solid var(--rule-strong); border-bottom-width: 2px; border-radius: 4px;
  padding: 1px 5px; background: var(--panel-2); font-size: .78em;
}

a { color: inherit; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  padding: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

.skip {
  position: absolute; left: 12px; top: -60px; z-index: 30;
  background: var(--ink); color: var(--paper); padding: 12px 18px; border-radius: 8px;
  text-decoration: none; font-weight: 600; transition: top .16s;
}
.skip:focus { top: 12px; }

.muted { color: var(--ink-2); font-size: 13px; }

/* ------------------------------------------------------------------ top bar */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 10px var(--pad);
  background: var(--paper);   /* fallback first: color-mix is the enhancement */
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
}

.brand { display: flex; align-items: center; gap: 9px; text-decoration: none; }
.mark-bg { fill: var(--accent); }
.mark-bars rect { fill: var(--panel); }
:root[data-theme="dark"] .mark-bars rect { fill: #0b0d11; }
.brand-word { font-weight: 800; letter-spacing: .16em; font-size: 15px; }
.brand-sub {
  font-size: 10px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--ink-3); border-left: 1px solid var(--rule-strong); padding-left: 9px;
}

.topnav { display: flex; gap: 4px; margin-right: auto; }
.topnav a {
  font-size: 12px; letter-spacing: .07em; text-transform: uppercase;
  color: var(--ink-2); text-decoration: none; padding: 7px 10px; border-radius: 6px;
}
.topnav a:hover { color: var(--ink); background: var(--panel-2); }

.topbar-right { display: flex; align-items: center; gap: 10px; }

.badge {
  font-family: var(--mono); font-size: 10px; letter-spacing: .12em; text-transform: uppercase;
  border: 1px solid var(--rule-strong); border-radius: 100px; padding: 4px 10px; color: var(--ink-2);
}

.icon-button {
  display: inline-flex; align-items: center; gap: 7px;
  font: inherit; font-size: 12px; color: var(--ink-2); cursor: pointer;
  background: none; border: 1px solid var(--rule); border-radius: 100px; padding: 5px 12px 5px 9px;
}
.icon-button:hover { color: var(--ink); border-color: var(--rule-strong); }
.theme-icon {
  width: 12px; height: 12px; border-radius: 50%;
  background: linear-gradient(105deg, var(--ink) 0 50%, transparent 50% 100%);
  border: 1.5px solid var(--ink); flex: none;
}

.topbar-back { font-size: 12px; text-decoration: none; color: var(--ink-2); }
.topbar-back:hover { color: var(--accent); text-decoration: underline; }

/* ---------------------------------------------------------------- masthead */

main { max-width: 1500px; margin: 0 auto; }

.masthead { padding: clamp(46px, 8vw, 96px) var(--pad) clamp(30px, 5vw, 60px); }

.kicker {
  font-family: var(--mono); font-size: 11px; letter-spacing: .16em; text-transform: uppercase;
  color: var(--ink-3); margin-bottom: 22px;
}

.masthead h1 {
  font-size: clamp(38px, 6.4vw, 88px);
  letter-spacing: -.045em; line-height: .98; font-weight: 800; margin-bottom: 26px;
}
.masthead h1 em { font-style: normal; color: var(--accent); }

.lede { max-width: 62ch; color: var(--ink-2); font-size: clamp(15px, 1.35vw, 18px); }
.lede.narrow { max-width: 56ch; }

.masthead-actions { display: flex; flex-wrap: wrap; gap: 12px; margin: 32px 0 40px; }

.button {
  display: inline-flex; align-items: center; gap: 8px;
  font: 600 14px/1 var(--sans); letter-spacing: .01em;
  background: var(--ink); color: var(--paper); border: 1px solid var(--ink);
  padding: 12px 18px; border-radius: 8px; text-decoration: none; cursor: pointer;
  transition: transform .14s ease, background .14s ease, color .14s ease;
}
.button:hover { transform: translateY(-1px); }
.button.ghost { background: none; color: var(--ink); border-color: var(--rule-strong); }
.button.ghost:hover { border-color: var(--ink); background: var(--panel-2); }
.button.small { padding: 9px 13px; font-size: 13px; }
.button.tiny { padding: 6px 10px; font-size: 12px; border-radius: 6px; }
.button:disabled { opacity: .4; cursor: not-allowed; transform: none; }

.readout {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  border-top: 1px solid var(--rule); border-left: 1px solid var(--rule);
}
.readout > div { border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); padding: 14px 16px; }
.readout dt {
  font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 6px;
}
.readout dd { font-family: var(--mono); font-size: 14px; font-variant-numeric: tabular-nums; }

.noscript {
  margin: 0 var(--pad) 40px; padding: 18px 20px;
  border: 1px solid var(--signal); border-left-width: 4px; border-radius: var(--radius);
  background: var(--signal-soft); font-size: 15px; max-width: 70ch;
}

/* ----------------------------------------------------------------- console */

.console, .segments, .method, .notes { padding: 0 var(--pad) clamp(40px, 6vw, 80px); }

.console-head, .segments-head {
  display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; justify-content: space-between;
  border-top: 2px solid var(--ink); padding-top: 16px; margin-bottom: 20px;
}
.console-head h2, .segments-head h2 { font-size: clamp(22px, 2.4vw, 30px); }
.console-sub { color: var(--ink-2); font-size: 14px; margin-top: 4px; }

.stamp {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3);
}
.stamp .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }

/* filters */

.filters {
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--panel); box-shadow: var(--shadow); overflow: hidden;
}

.filter-row {
  display: flex; flex-wrap: wrap; gap: 22px 30px; padding: 18px 20px;
  border-bottom: 1px solid var(--rule);
}

.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field.grow { flex: 1 1 320px; }
.field label, .field-label, .chipset legend {
  font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3);
  display: flex; gap: 8px; align-items: baseline;
}
.field label output {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0; text-transform: none; color: var(--ink);
  font-variant-numeric: tabular-nums;
}

select, input[type="search"] {
  font: 500 14px/1 var(--sans); color: var(--ink);
  background: var(--panel-2); border: 1px solid var(--rule-strong); border-radius: 7px;
  padding: 9px 10px; min-height: 38px; min-width: 150px;
}
input[type="search"] { min-width: 190px; }

input[type="range"] { accent-color: var(--accent); width: 100%; min-width: 200px; height: 24px; }

.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.presets button {
  font: 600 12px/1 var(--mono); color: var(--ink-2); cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--rule-strong); border-radius: 7px;
  padding: 10px 11px; min-height: 38px;
}
.presets button:hover { color: var(--ink); border-color: var(--ink-3); }
.presets button[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.chipset { border: 0; border-bottom: 1px solid var(--rule); margin: 0; padding: 16px 20px; }
.chipset:last-of-type { border-bottom: 0; }
.chipset legend { padding: 0; margin-bottom: 10px; float: left; width: 100%; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; clear: both; }

.chip {
  display: inline-flex; align-items: center; gap: 8px;
  font: 500 13px/1 var(--sans); color: var(--ink-2); cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--rule-strong); border-radius: 100px;
  padding: 8px 13px; min-height: 34px;
}
.chip:hover { color: var(--ink); border-color: var(--ink-3); }
.chip[aria-pressed="true"] {
  background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink);
}
.chip .swatch { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.chip .chip-val {
  font-family: var(--mono); font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums;
}
.chip[aria-pressed="true"] .chip-val { color: inherit; opacity: .8; }
.chip.all { border-style: dashed; }

.selection-summary {
  font-family: var(--mono); font-size: 12.5px; color: var(--ink-2);
  padding: 14px 2px 20px; border-bottom: 1px solid var(--rule); margin-bottom: 24px;
  font-variant-numeric: tabular-nums;
}
.selection-summary strong { color: var(--ink); font-weight: 700; }

.section-label {
  display: flex; align-items: baseline; gap: 12px;
  font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-3);
  margin-bottom: 12px; font-weight: 600;
}
.section-label span { letter-spacing: .02em; text-transform: none; font-weight: 400; font-size: 12px; }

/* KPIs */

.kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(196px, 1fr));
  gap: 10px; margin-bottom: 26px;
}

.kpi {
  display: block; text-align: left; cursor: pointer; position: relative;
  background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 14px 15px 12px; font: inherit; color: inherit; overflow: hidden;
  transition: border-color .14s ease, transform .14s ease;
}
.kpi:hover { border-color: var(--rule-strong); transform: translateY(-2px); }
.kpi[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.kpi[aria-pressed="true"]::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--accent);
}
.kpi-name {
  display: block; font-size: 10px; letter-spacing: .13em; text-transform: uppercase;
  color: var(--ink-3); margin-bottom: 9px;
}
.kpi-value {
  display: block; font-family: var(--mono); font-size: clamp(20px, 2vw, 26px); font-weight: 600;
  letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-bottom: 8px;
}
.kpi-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.kpi-delta {
  font-family: var(--mono); font-size: 11.5px; font-variant-numeric: tabular-nums;
  display: inline-flex; align-items: center; gap: 4px;
}
.kpi-delta.good { color: var(--good); }
.kpi-delta.bad { color: var(--bad); }
.kpi-delta.flat { color: var(--ink-3); }
.kpi-spark { display: block; }
.kpi-note { display: block; font-size: 10.5px; color: var(--ink-3); margin-top: 7px; }

/* ------------------------------------------------------------------ charts */

.charts { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px; }

.card {
  margin: 0; background: var(--panel); border: 1px solid var(--rule);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px 14px; min-width: 0;
}
.chart-trend { grid-column: span 12; }
.chart-cat { grid-column: span 5; }
.chart-map { grid-column: span 7; }
.chart-matrix { grid-column: span 12; }

.card figcaption {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; justify-content: space-between;
  margin-bottom: 14px;
}
.card h3 { font-size: 15px; letter-spacing: -.01em; }
.card figcaption p {
  font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); margin-top: 5px;
  font-variant-numeric: tabular-nums;
}

.chart-tools { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.switch { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--ink-2); cursor: pointer; }
.switch input { accent-color: var(--accent); width: 15px; height: 15px; }

.skip-inline { font-size: 11px; color: var(--ink-3); }

.plot { position: relative; }
.plot svg { display: block; width: 100%; }
/* Only the brushable chart claims horizontal drags; the page still scrolls vertically. */
#trend-svg { touch-action: pan-y; }
#trend-svg:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

.grid-line { stroke: var(--rule); stroke-width: 1; }
.axis-text { fill: var(--ink-3); font-family: var(--mono); font-size: 10px; }
.axis-text.strong { fill: var(--ink-2); }
.series-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.series-area { fill: url(#trend-fill); }
.compare-line {
  fill: none; stroke: var(--signal); stroke-width: 1.5; stroke-dasharray: 4 4; opacity: .85;
}
.series-dot { fill: var(--accent); }
.cursor-line { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 3 3; }
.cursor-dot { fill: var(--panel); stroke: var(--accent); stroke-width: 2.5; }
.brush-rect { fill: var(--accent); opacity: .13; }
.hit { fill: transparent; }

.tooltip {
  position: absolute; z-index: 5; pointer-events: none;
  min-width: 190px; max-width: 260px;
  background: var(--ink); color: var(--paper);
  border-radius: 8px; padding: 10px 12px; font-size: 12px; line-height: 1.45;
  box-shadow: 0 14px 30px -18px rgba(0, 0, 0, .8);
}
.tooltip h4 { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; opacity: .7; margin-bottom: 6px; }
.tooltip .tip-value { font-family: var(--mono); font-size: 16px; font-weight: 600; display: block; margin-bottom: 8px; }
.tooltip .tip-delta { font-family: var(--mono); font-size: 11px; opacity: .8; }
.tooltip ul { border-top: 1px solid rgba(255, 255, 255, .18); margin-top: 8px; padding-top: 7px; }
.tooltip li { display: flex; align-items: center; gap: 7px; font-family: var(--mono); font-size: 11px; }
.tooltip li b { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.tooltip li span { margin-left: auto; font-variant-numeric: tabular-nums; }

.chart-help { font-size: 11.5px; color: var(--ink-3); margin-top: 10px; line-height: 1.5; }
.chart-help strong { color: var(--ink-2); }

/* bars */

.bar-track { fill: var(--panel-2); }
.bar { cursor: pointer; }
.bar-label { fill: var(--ink); font-size: 12px; font-weight: 500; }
.bar-value { fill: var(--ink-2); font-family: var(--mono); font-size: 11px; }
.bar-row .bar-hit { fill: transparent; cursor: pointer; }
.bar-row:hover .bar-label { fill: var(--accent-ink); }
.bar-row.is-off .bar-label, .bar-row.is-off .bar-value { opacity: .45; }
/* Outlines on SVG <g> are unreliable, so the focus ring is drawn as a stroke too. */
.bar-row:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.bar-row:focus-visible .bar-track { stroke: var(--focus); stroke-width: 2; }
.bar-row[aria-pressed="true"] .bar-label { font-weight: 700; }
.bar-row[aria-pressed="true"] .bar-track { stroke: var(--accent); stroke-width: 1.5; }

/* map */

.tile { stroke: var(--panel); stroke-width: 2; transition: fill .35s ease, stroke .15s ease; }
.tile-group { cursor: pointer; }
.tile-group:hover .tile { stroke: var(--ink); }
.tile-group:focus-visible { outline: none; }
.tile-group:focus-visible .tile { stroke: var(--focus); stroke-width: 3; }
.tile-group.is-on .tile { stroke: var(--accent); stroke-width: 3; }
.tile-group.is-dim { opacity: .38; }
.tile-code { font-family: var(--mono); font-size: 10px; font-weight: 600; }
.tile-val { font-family: var(--mono); font-size: 9.5px; }

.legend { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-top: 12px; }
.legend .legend-label { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); margin-right: 6px; }
.legend .swatch-box { display: flex; align-items: center; gap: 3px; }
.legend i { width: 26px; height: 10px; border-radius: 2px; display: block; }
.legend small { font-family: var(--mono); font-size: 10px; color: var(--ink-3); }

/* matrix */

.matrix-scroll { overflow-x: auto; }
.matrix { border-collapse: collapse; width: 100%; min-width: 660px; }
.matrix caption {
  caption-side: top; text-align: left; font-size: 11.5px; color: var(--ink-3);
  margin-bottom: 10px; line-height: 1.5;
}
.matrix th {
  font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3);
  font-weight: 600; text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--rule);
}
.matrix th.row-head {
  text-align: left; text-transform: none; letter-spacing: 0; font-size: 12px; color: var(--ink);
  white-space: nowrap; border-bottom: 1px solid var(--rule); font-weight: 500;
}
.matrix td { padding: 2px; border-bottom: 1px solid var(--rule); }
.matrix .cell {
  display: block; width: 100%; text-align: left; cursor: pointer; font: inherit;
  border: 1px solid transparent; border-radius: 5px; padding: 8px 9px;
  transition: fill .3s ease, background-color .3s ease, border-color .12s ease;
}
.matrix .cell:hover { border-color: var(--ink); }
.matrix .cell[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.matrix .cell b {
  display: block; font-family: var(--mono); font-size: 12.5px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.matrix .cell small { display: block; font-family: var(--mono); font-size: 10px; opacity: .72; margin-top: 2px; }

/* chart fallback tables */

.fallback {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
body.show-tables .fallback {
  position: static; width: auto; height: auto; margin: 16px 0 0; overflow: auto;
  clip: auto; clip-path: none; white-space: normal;
  border-top: 1px solid var(--rule); padding-top: 12px; max-height: 320px;
}
.fallback table { border-collapse: collapse; width: 100%; font-size: 12px; }
.fallback caption {
  caption-side: top; text-align: left; font-size: 11px; color: var(--ink-3); margin-bottom: 8px;
}
.fallback th, .fallback td { padding: 4px 8px; border-bottom: 1px solid var(--rule); text-align: left; }
.fallback td.num, .fallback th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }

.perf-note {
  font-family: var(--mono); font-size: 11px; color: var(--ink-3); margin-top: 14px;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- segments */

.segments-tools { display: flex; gap: 18px; flex-wrap: wrap; }

.table-scroll {
  overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--panel); box-shadow: var(--shadow);
}
.segments-table { border-collapse: collapse; width: 100%; min-width: 900px; }
.segments-table caption {
  caption-side: top; text-align: left; font-family: var(--mono); font-size: 11.5px;
  color: var(--ink-3); padding: 12px 14px; border-bottom: 1px solid var(--rule);
}
.segments-table th {
  position: sticky; top: 0; z-index: 2; background: var(--panel-2);
  border-bottom: 1px solid var(--rule-strong); padding: 0; text-align: left;
}
.segments-table th button {
  width: 100%; text-align: inherit; font: 600 10px/1 var(--sans); letter-spacing: .11em;
  text-transform: uppercase; color: var(--ink-2); background: none; border: 0; cursor: pointer;
  padding: 11px 12px; display: block;
}
.segments-table th.num button, .segments-table th.num { text-align: right; }
.segments-table th button:hover { color: var(--ink); }
.segments-table th[aria-sort="ascending"] button::after { content: " ▲"; color: var(--accent); }
.segments-table th[aria-sort="descending"] button::after { content: " ▼"; color: var(--accent); }
.segments-table th.spark-col {
  font: 600 10px/1 var(--sans); letter-spacing: .11em; text-transform: uppercase;
  color: var(--ink-2); padding: 11px 12px;
}

.segments-table td { padding: 0; border-bottom: 1px solid var(--rule); }
.segments-table tbody tr { cursor: pointer; }
.segments-table tbody tr:hover td { background: var(--panel-2); }
.segments-table tbody tr[aria-current="true"] td { background: var(--accent-soft); }
.segments-table tbody tr[aria-current="true"] td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.segments-table .cell-inner { padding: 9px 12px; display: block; }
.segments-table td.num .cell-inner {
  text-align: right; font-family: var(--mono); font-size: 12.5px; font-variant-numeric: tabular-nums;
}
.segments-table .seg-name { display: flex; align-items: center; gap: 9px; font-size: 13.5px; }
.segments-table .seg-name i { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.segments-table .row-button {
  font: inherit; background: none; border: 0; color: inherit; text-align: left; cursor: pointer;
  padding: 9px 12px; width: 100%; display: block;
}
.segments-table .empty-row td { padding: 26px 14px; color: var(--ink-2); font-size: 14px; text-align: center; }
.row-spark { display: block; }

/* drilldown */

.drill {
  margin-top: 12px; border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--panel); box-shadow: var(--shadow); padding: 16px 18px;
}
.drill-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.drill-head h3 { font-size: 13px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.drill-title { font-size: clamp(18px, 2vw, 24px); margin-bottom: 4px; }
.drill-sub { font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); margin-bottom: 16px; }
.drill-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.drill-metrics { display: grid; gap: 1px; background: var(--rule); border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; }
.drill-metrics div { display: flex; justify-content: space-between; gap: 12px; background: var(--panel); padding: 8px 11px; }
.drill-metrics dt { font-size: 11.5px; color: var(--ink-2); }
.drill-metrics dd { font-family: var(--mono); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.drill-facts { display: grid; gap: 10px; align-content: start; }
.drill-facts p { font-size: 13px; color: var(--ink-2); }
.drill-facts b { color: var(--ink); font-family: var(--mono); font-variant-numeric: tabular-nums; }
.drill-chart { border: 1px solid var(--rule); border-radius: 8px; padding: 10px 12px; min-width: 0; }
.drill-chart h4 { font-size: 10px; letter-spacing: .13em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 8px; }
.drill-chart svg { width: 100%; height: auto; margin-bottom: 6px; }

/* export */

.export {
  margin-top: 12px; border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--panel-2); padding: 16px 18px;
  display: grid; gap: 14px;
}
.export h3 { font-size: 15px; }
.export-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.csv-preview summary { font-size: 12.5px; color: var(--ink-2); cursor: pointer; }
.csv-preview pre {
  margin: 10px 0 0; padding: 12px; overflow: auto; max-height: 220px;
  background: var(--panel); border: 1px solid var(--rule); border-radius: 8px;
  font-family: var(--mono); font-size: 11px; line-height: 1.6; color: var(--ink-2);
}
#export-fallback textarea {
  width: 100%; font-family: var(--mono); font-size: 11px; padding: 10px;
  border: 1px solid var(--rule-strong); border-radius: 8px; background: var(--panel); color: var(--ink);
}
#export-fallback label { display: block; font-size: 12.5px; margin-bottom: 6px; color: var(--ink-2); }
.status { font-family: var(--mono); font-size: 12px; color: var(--accent-ink); min-height: 1.2em; }
:root[data-theme="dark"] .status { color: var(--accent); }

.table-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 16px; }
.table-tools button {
  font: 600 12px/1 var(--sans); color: var(--ink); cursor: pointer;
  background: none; border: 1px solid var(--rule-strong); border-radius: 7px; padding: 9px 12px;
}
.table-tools button[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* ------------------------------------------------------------------ method */

.method h2, .notes h2 {
  font-size: clamp(24px, 3vw, 40px); letter-spacing: -.03em;
  border-top: 2px solid var(--ink); padding-top: 16px; margin-bottom: 16px;
}

.pipeline {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px;
  margin: 34px 0 40px; counter-reset: step;
}
.pipeline li {
  position: relative; background: var(--panel); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: 14px 15px 16px;
}
.pipeline li::after {
  content: ""; position: absolute; right: -9px; top: 50%; z-index: 2;
  width: 0; height: 0; transform: translateY(-50%);
  border-left: 7px solid var(--rule-strong);
  border-top: 5px solid transparent; border-bottom: 5px solid transparent;
}
.pipeline li:last-child::after { display: none; }
.pipe-step {
  display: inline-block; font-family: var(--mono); font-size: 10px; letter-spacing: .1em;
  color: var(--accent-ink); background: var(--accent-soft); border-radius: 4px;
  padding: 3px 6px; margin-bottom: 9px;
}
:root[data-theme="dark"] .pipe-step { color: var(--accent); }
.pipeline h3 { font-size: 14px; margin-bottom: 6px; }
.pipeline p { font-size: 12.5px; color: var(--ink-2); line-height: 1.5; }

.method-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 22px; }
.method-grid h3 { font-size: 16px; margin-bottom: 8px; }
.method-grid p { color: var(--ink-2); font-size: 14px; }

/* ------------------------------------------------------------------- notes */

.notes ul { display: grid; gap: 12px; max-width: 78ch; }
.notes li {
  font-size: 15px; color: var(--ink-2); padding-left: 18px; position: relative; line-height: 1.55;
}
.notes li::before {
  content: ""; position: absolute; left: 0; top: .62em; width: 7px; height: 7px;
  background: var(--accent); border-radius: 2px;
}
.notes strong { color: var(--ink); }

/* ------------------------------------------------------------------ footer */

.footer {
  display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between;
  max-width: 1500px; margin: 0 auto; padding: 26px var(--pad) 60px;
  border-top: 1px solid var(--rule); font-size: 13px; color: var(--ink-2);
}
.footer p { margin-top: 6px; }
.footer a { font-weight: 600; text-decoration: none; color: var(--ink); }
.footer a:hover { color: var(--accent); text-decoration: underline; }

/* ------------------------------------------------------------- responsive */

@media (max-width: 1180px) {
  .chart-cat, .chart-map { grid-column: span 12; }
  .pipeline { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .pipeline li:nth-child(3)::after { display: none; }
}

@media (max-width: 900px) {
  .topnav { order: 3; width: 100%; margin: 0; overflow-x: auto; padding-bottom: 2px; }
  .topbar { gap: 12px; }
  .brand-sub { display: none; }
  .filter-row { gap: 18px; }
  .field.grow { flex-basis: 100%; }
}

@media (max-width: 640px) {
  body { font-size: 15px; }
  .pipeline { grid-template-columns: 1fr; }
  .pipeline li::after {
    display: block; right: auto; left: 50%; top: auto; bottom: -9px;
    transform: translateX(-50%) rotate(90deg);
  }
  .pipeline li:nth-child(3)::after { display: block; }
  .pipeline li:last-child::after { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-value { font-size: 19px; }
  .masthead-actions .button { flex: 1 1 100%; justify-content: center; }
  .badge { display: none; }
  .tooltip { min-width: 150px; max-width: 200px; font-size: 11.5px; }
  .console, .segments, .method, .notes { padding-bottom: 40px; }
  .export-actions .button { flex: 1 1 100%; justify-content: center; }
  /* The tile map keeps a legible minimum size and scrolls, like the data tables. */
  .chart-map .plot { overflow-x: auto; }
  #map-svg { min-width: 430px; }
  .tile-code { font-size: 12px; }
  .tile-val { font-size: 11px; }
}

@media (max-width: 420px) {
  .kpis { grid-template-columns: 1fr; }
}

/* Touch pointers get bigger hit areas; hover-only affordances are never the only path. */
@media (hover: none) {
  .chip, .presets button { min-height: 40px; }
  .matrix .cell { padding: 10px 9px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important; scroll-behavior: auto !important;
  }
}

@media (prefers-contrast: more) {
  :root { --rule: #9a958a; --ink-2: #33383f; --ink-3: #4c525c; }
  :root[data-theme="dark"] { --rule: #566172; --ink-2: #c8cfda; --ink-3: #9aa4b3; }
  .tile { stroke-width: 2.5; }
}
