/* kit.css: shared look for ~/webdata reports. Tokens first; components below.
   Colors are the validated dataviz reference palette (light + dark). */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --good-text: #006300;
  --bad-text: #b42323;

  /* Categorical: assign in this order, never cycle past 8. */
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #4a3aa7; --series-8: #e34948;
  /* Status: only when the color means good/bad, always with a label. */
  --status-good: #0ca30c; --status-warning: #fab219; --status-serious: #ec835a; --status-critical: #d03b3b;
  /* Sequential (blue, light -> dark) and diverging (blue <-> gray <-> red). */
  --seq-low: #cde2fb; --seq-high: #0d366b;
  --div-neg: #e34948; --div-mid: #f0efec; --div-pos: #2a78d6;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 12px;
  --gap: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
    --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5; --good-text: #0ca30c; --bad-text: #e66767;
    --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-low: #184f95; --seq-high: #cde2fb;
    --div-neg: #e66767; --div-mid: #383835; --div-pos: #3987e5;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
  --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5; --good-text: #0ca30c; --bad-text: #e66767;
  --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-low: #184f95; --seq-high: #cde2fb;
  --div-neg: #e66767; --div-mid: #383835; --div-pos: #3987e5;
}

/* ---------------------------------------------------------------- base */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  padding: 0 max(16px, var(--safe-right)) calc(32px + var(--safe-bottom)) max(16px, var(--safe-left));
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 650; }
h1 { font-size: 22px; letter-spacing: -0.01em; }
h2 { font-size: 16px; }
h3 { font-size: 14px; color: var(--ink-2); }
p { margin: 0; }
main { max-width: 1120px; margin: 0 auto; display: grid; gap: var(--gap); }
.muted { color: var(--muted); }
.secondary { color: var(--ink-2); }
.num { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- header */

/* Sticky app bar; respects the notch when saved to the iOS home screen. */
.app-header {
  position: sticky; top: 0; z-index: 10;
  margin: 0 calc(-1 * max(16px, var(--safe-right))) 0 calc(-1 * max(16px, var(--safe-left)));
  padding: calc(12px + var(--safe-top)) max(16px, var(--safe-right)) 12px max(16px, var(--safe-left));
  background: color-mix(in srgb, var(--page) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.app-header .inner { max-width: 1120px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.app-header .titles { min-width: 0; flex: 1; }
.app-header h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-header .back {
  display: grid; place-items: center; width: 32px; height: 32px; flex: none;
  border-radius: 8px; color: var(--ink-2); font-size: 20px;
}
.app-header .back:hover { background: var(--surface-2); text-decoration: none; }
.kit-status { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kit-status::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--status-good); flex: none;
}
.kit-status[data-state="loading"]::before { background: var(--muted); }
.kit-status[data-state="error"]::before { background: var(--status-critical); }
main > :first-child { margin-top: var(--gap); }

/* ---------------------------------------------------------------- layout */

.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}
.card > header { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
/* A freshness note that doesn't fit beside the title drops below it instead of squeezing it. */
.card > header:has(> .freshness) { flex-wrap: wrap; row-gap: 2px; }
.card > header p { font-size: 13px; color: var(--muted); }
.wide { grid-column: 1 / -1; }

/* Stat tile: label, value (proportional figures), optional delta/note. */
.stat .label { font-size: 13px; color: var(--ink-2); }
.stat .value { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; margin-top: 2px; }
.stat .note { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat .delta { font-size: 13px; font-weight: 550; margin-top: 2px; color: var(--ink-2); }
.stat .delta.good { color: var(--good-text); }
.stat .delta.bad { color: var(--bad-text); }

/* Segmented control (one filter row above the content it scopes). */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 2px; }
.segmented button {
  font: inherit; font-size: 13px; border: 0; background: none; color: var(--ink-2);
  padding: 6px 12px; min-height: 32px; border-radius: 7px; cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
input[type="search"], select {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border); border-radius: 9px; padding: 7px 10px; min-width: 0;
}

/* ---------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; }
table.data th, table.data td { padding: 7px 10px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--grid); }
table.data th { font-weight: 600; color: var(--ink-2); position: sticky; top: 0; background: var(--surface); }
table.data th[data-sort] { cursor: pointer; user-select: none; }
table.data th[aria-sort="ascending"]::after { content: " ↑"; }
table.data th[aria-sort="descending"]::after { content: " ↓"; }
table.data td.n, table.data th.n { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: 0; }

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

.kit-chart { width: 100%; min-width: 0; color: var(--muted); } /* Plot legends inherit this */
.kit-chart svg { display: block; overflow: visible; --plot-background: var(--surface); }
.kit-chart [aria-label="tip"] { filter: drop-shadow(0 2px 6px rgba(0,0,0,.18)); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--ink-2); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend i.line { height: 2px; width: 14px; border-radius: 1px; }

/* ---------------------------------------------------------------- feeds (briefing pages) */

/* feed(): headlines, results, events. Title, a grey meta line, an optional
   two-line summary; hairlines between items. */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { padding: 10px 0; border-bottom: 1px solid var(--grid); }
.feed li:first-child { padding-top: 0; }
.feed li:last-child { border-bottom: 0; padding-bottom: 0; }
.feed .title { display: block; color: var(--ink); font-weight: 550; line-height: 1.35; }
.feed a.title { text-decoration: none; }
.feed a.title:hover { text-decoration: underline; }
.feed a.title:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
.feed .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.feed .summary {
  font-size: 13px; color: var(--ink-2); margin-top: 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* freshness(): "Updated 12 minutes ago" in a card header; a warning dot plus
   words when the section is out of date (never color alone). */
.card > header p.freshness.stale, .freshness.stale { color: var(--ink-2); }
.freshness.stale::before {
  content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--status-warning); margin-right: 6px; vertical-align: 1px;
}

/* ---------------------------------------------------------------- states */

.kit-error {
  border: 1px solid var(--status-critical); color: var(--ink); background: var(--surface);
  border-radius: var(--radius); padding: 12px 16px; font-size: 13px; white-space: pre-wrap;
}
.kit-error strong { color: var(--bad-text); }
.loading { opacity: .55; transition: opacity .2s; }
.empty { color: var(--muted); font-size: 14px; padding: 24px 0; text-align: center; }

@media (max-width: 520px) {
  body { font-size: 14px; }
  .stat .value { font-size: 24px; }
  .card { padding: 14px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
