/*
  Tokens. The chart colors, ink and surfaces are the reference palette from the
  dataviz method: eight categorical slots in a fixed order (only the first three
  are used here, for the three platforms), a sequential blue for magnitude, and
  the same hues re-stepped for the dark surface rather than flipped.
*/
:root {
  color-scheme: light;
  --bg: #f9f9f7;
  --surface: #fcfcfb;
  --text: #0b0b0b;
  --muted: #52514e;
  --faint: #898781;
  --line: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --accent-text: #ffffff;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-other: #898781;
  --wash: rgba(42, 120, 214, 0.1);
  --hover: rgba(11, 11, 11, 0.05);
  --good: #006300;
  --error-bg: #fdecec;
  --error-text: #8a1c1c;
  --info-bg: #eaf2fc;
  --info-text: #184f95;
  --shadow: 0 4px 16px rgba(11, 11, 11, 0.14);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0d0d;
    --surface: #1a1a19;
    --text: #ffffff;
    --muted: #c3c2b7;
    --faint: #898781;
    --line: #2c2c2a;
    --axis: #383835;
    --ring: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --accent-text: #0d0d0d;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --wash: rgba(57, 135, 229, 0.14);
    --hover: rgba(255, 255, 255, 0.07);
    --good: #0ca30c;
    --error-bg: #3a1c1c;
    --error-text: #ffb4b4;
    --info-bg: #1d2a3d;
    --info-text: #b7d3f6;
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

/* A rule that sets display would otherwise beat the hidden attribute. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ---- Frame ------------------------------------------------------------- */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.bar h1 { margin: 0; font-size: 1.1rem; }
.who { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 0.9rem; }

main { max-width: 1120px; margin: 0 auto; padding: 16px; }

h2 { margin: 0; font-size: 1.25rem; }
h3 { margin: 0; font-size: 0.95rem; font-weight: 600; }

input[type="text"] {
  font: inherit;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  min-width: 14em;
}

input[type="text"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.badge { font-size: 0.75rem; border: 1px solid var(--line); border-radius: 999px; padding: 0 8px; color: var(--muted); }

select, button {
  font: inherit;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

button {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}

button.quiet { background: transparent; border-color: var(--line); color: var(--text); }
button.quiet:hover { background: var(--hover); }
button:disabled { opacity: 0.6; cursor: default; }
button:focus-visible, select:focus-visible, summary:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.message { padding: 12px 16px; border-radius: 8px; background: var(--info-bg); color: var(--info-text); }
.message.error { background: var(--error-bg); color: var(--error-text); }

.panel {
  background: var(--surface);
  border: 1px solid var(--ring);
  border-radius: 10px;
  padding: 16px;
}

.center { text-align: center; padding: 32px 16px; }
.note { color: var(--muted); font-size: 0.8rem; }

/* ---- Tabs and the filter row ------------------------------------------- */

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.tabs button {
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--muted);
  padding: 8px 14px;
  white-space: nowrap;
}

.tabs button:hover { color: var(--text); background: var(--hover); }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.filters .spacer { flex: 1; }
.filters label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.9rem; }

/* Refetching keeps the frame: the old render stays, dimmed. */
.view { transition: opacity 0.15s; }
.view.loading { opacity: 0.55; }

/* ---- Stat tiles -------------------------------------------------------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--ring);
  border-radius: 10px;
  padding: 12px 16px;
}

.tile.clickable { cursor: pointer; }
.tile.clickable:hover { background: var(--hover); }
.tile.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

.tile .label { color: var(--muted); font-size: 0.85rem; }
/* Proportional figures: a big standalone number set tabular looks loose. */
.tile .value { font-size: 2rem; font-weight: 600; line-height: 1.2; overflow-wrap: anywhere; }
.tile .value.long { font-size: 1.45rem; line-height: 1.6; }
.tile .sub { color: var(--muted); font-size: 0.8rem; min-height: 1.2em; }
.tile svg.spark { display: block; margin-top: 4px; width: 100%; height: 28px; }

/* ---- Chart cards ------------------------------------------------------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.grid > .wide { grid-column: 1 / -1; }

.card { min-width: 0; }
.card header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card header .titles { min-width: 0; }
.card header .note { margin-top: 2px; }
.card header button {
  flex: none;
  font-size: 0.8rem;
  padding: 2px 8px;
}

.empty { color: var(--muted); padding: 24px 0; text-align: center; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0 0 8px; padding: 0; list-style: none; font-size: 0.85rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 6px; }
.legend .key { width: 12px; height: 3px; border-radius: 2px; }
.legend .key.block { height: 10px; width: 10px; border-radius: 2px; }

/* Series colors, by slot. Marks carry the color; text never does. */
.f1 { fill: var(--series-1); } .f2 { fill: var(--series-2); } .f3 { fill: var(--series-3); } .f0 { fill: var(--series-other); }
.s1 { stroke: var(--series-1); } .s2 { stroke: var(--series-2); } .s3 { stroke: var(--series-3); } .s0 { stroke: var(--series-other); }
.k1 { background: var(--series-1); } .k2 { background: var(--series-2); } .k3 { background: var(--series-3); } .k0 { background: var(--series-other); }

/* ---- SVG chart chrome -------------------------------------------------- */

svg.chart { display: block; width: 100%; height: auto; overflow: visible; }
svg.chart text { fill: var(--faint); font: 11px system-ui, -apple-system, "Segoe UI", sans-serif; }
svg.chart text.value-label { fill: var(--muted); }
svg.chart .grid-line { stroke: var(--line); stroke-width: 1; }
svg.chart .axis-line { stroke: var(--axis); stroke-width: 1; }
svg.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg.chart .area { stroke: none; opacity: 0.1; }
svg.chart .dot { stroke: var(--surface); stroke-width: 2; }
svg.chart .crosshair { stroke: var(--axis); stroke-width: 1; }
svg.chart .mark { transition: opacity 0.1s; }
svg.chart .hit { fill: transparent; }
svg.chart .hit:hover ~ .mark, svg.chart g.col:hover .mark, svg.chart g.col:focus .mark { opacity: 0.75; }
svg.chart g.col:focus { outline: none; }
svg.chart g.col:focus-visible .focus-ring { stroke: var(--accent); }
svg.chart .focus-ring { fill: none; stroke: transparent; stroke-width: 2; }

/* ---- Bar lists (horizontal bars as HTML, so long names wrap sensibly) -- */

ul.bars { list-style: none; margin: 0; padding: 0; }

ul.bars li {
  display: grid;
  grid-template-columns: minmax(0, 11em) minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 3px 4px;
  border-radius: 6px;
}

ul.bars li:hover, ul.bars li:focus { background: var(--hover); outline: none; }
ul.bars li:focus-visible { outline: 2px solid var(--accent); }
ul.bars .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.9rem; }
ul.bars .track { height: 10px; }
ul.bars .fill { display: block; height: 10px; min-width: 2px; border-radius: 0 4px 4px 0; }
ul.bars .num { font-variant-numeric: tabular-nums; font-size: 0.9rem; color: var(--muted); text-align: right; min-width: 3ch; }

/* ---- Tables ------------------------------------------------------------ */

.scroll { overflow-x: auto; }

table.data { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 0.9rem; }
table.data th { text-align: left; color: var(--muted); font-weight: 600; font-size: 0.8rem; padding: 4px 8px; white-space: nowrap; }
table.data td { padding: 4px 8px; border-top: 1px solid var(--line); vertical-align: top; }
table.data th.num, table.data td.num { text-align: right; }
table.data td.wrap { white-space: normal; overflow-wrap: anywhere; }
.tablewrap { max-height: 340px; overflow: auto; }

/* ---- Messages ---------------------------------------------------------- */

.messages details { border-top: 1px solid var(--line); padding: 8px 0; }
.messages details:first-child { border-top: 0; }
.messages summary { cursor: pointer; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.messages .subject { font-weight: 600; overflow-wrap: anywhere; }
.messages .meta { color: var(--muted); font-size: 0.8rem; }
.messages .body { margin: 8px 0 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.messages pre.stack {
  margin: 8px 0 4px;
  padding: 8px 12px;
  background: var(--hover);
  border-radius: 6px;
  font: 0.8rem/1.4 ui-monospace, "Cascadia Mono", Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 20em;
  overflow: auto;
}
.messages .badge { font-size: 0.75rem; border: 1px solid var(--line); border-radius: 999px; padding: 0 8px; color: var(--muted); }
.messages .badge.warn { border-color: var(--error-text); color: var(--error-text); }

/* ---- Tooltip ----------------------------------------------------------- */

#tooltip {
  position: fixed;
  z-index: 10;
  pointer-events: none;
  max-width: 260px;
  padding: 8px 10px;
  border: 1px solid var(--ring);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 0.8rem;
}

#tooltip[hidden] { display: none; }
#tooltip .head { color: var(--muted); margin-bottom: 2px; }
#tooltip .row { display: flex; align-items: center; gap: 8px; }
#tooltip .row .key { flex: none; width: 10px; height: 3px; border-radius: 2px; }
/* Values lead: the number is the strong element, its name is secondary. */
#tooltip .row strong { font-variant-numeric: tabular-nums; }
#tooltip .row span.name { color: var(--muted); }

@media (max-width: 520px) {
  main { padding: 12px; }
  .tile .value { font-size: 1.6rem; }
  ul.bars li { grid-template-columns: minmax(0, 8em) minmax(0, 1fr) auto; }
}

@media print, (forced-colors: active) {
  .f1, .f2, .f3, .f0 { fill: CanvasText; }
  ul.bars .fill { background: CanvasText; }
}
