/* Palette values come from the validated reference palette: categorical slots
   in fixed order (never cycled), one sequential hue, reserved status colors,
   and dark steps chosen for the dark surface rather than flipped from light. */

:root {
  color-scheme: light;

  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);

  /* categorical slots, fixed order */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;

  /* sequential blue ramp (for the meter track) */
  --blue-100: #cde2fb;
  --blue-250: #86b6ef;

  /* reserved status colors — never reused as a series */
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04);
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --blue-100: #184f95;
    --blue-250: #1c5cab;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --blue-100: #184f95;
  --blue-250: #1c5cab;
  --shadow: none;
}

* { box-sizing: border-box; }

/* Class-level `display` rules outrank the UA stylesheet's [hidden] { display:none },
   which silently un-hides anything toggled via the hidden attribute. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1240px; margin: 0 auto; padding: 24px 20px 64px; }

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

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 28px;
}
.topbar h1 { font-size: 17px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.topbar .spacer { flex: 1 1 auto; }
.topbar .meta { color: var(--text-secondary); font-size: 12.5px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  background: var(--surface-1);
  white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
/* On the light surface the warning step is sub-3:1, so the mock badge uses a
   darker ink of the same hue for its text; the dark surface can take the step
   itself. Either way the badge carries a word, never color alone. */
.badge.mock { color: #8a5a00; border-color: rgba(250, 178, 25, 0.5); background: rgba(250, 178, 25, 0.12); }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .badge.mock { color: var(--status-warning); }
}
:root[data-theme="dark"] .badge.mock { color: var(--status-warning); }
.badge.live { color: var(--status-good); border-color: rgba(12, 163, 12, 0.4); background: rgba(12, 163, 12, 0.1); }
.badge.stale { color: var(--status-critical); border-color: rgba(208, 59, 59, 0.4); background: rgba(208, 59, 59, 0.1); }

button {
  font: inherit;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  min-height: 32px;
}
button:hover { background: color-mix(in srgb, var(--surface-1) 88%, var(--text-primary)); }
button:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }

/* --------------------------------------------------------------- sections -- */

section { margin-bottom: 40px; }

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
}
.section-head h2 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin: 0;
}
.section-note {
  color: var(--text-muted);
  font-size: 12.5px;
  margin: 0 0 16px;
  max-width: 76ch;
}

/* one filter row above everything it scopes — never inside a chart card */
.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.filter-row .label { color: var(--text-secondary); font-size: 12.5px; margin-right: 2px; }
.filter-row input[type="date"] {
  font: inherit;
  padding: 5px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--text-primary);
  min-height: 32px;
}
.preset { padding: 5px 10px; font-size: 13px; }
.preset[aria-pressed="true"] {
  border-color: var(--series-1);
  color: var(--series-1);
  font-weight: 600;
}

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

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.grid { display: grid; gap: 16px; }
.grid.hero-row { grid-template-columns: minmax(230px, 1fr) 2fr; align-items: stretch; }
.grid.kpi { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }

/* The four live tiles sit as a balanced 2x2 block beside the hero, rather than
   wrapping 3 + 1. */
.grid.hero-row .grid.kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); }

@media (max-width: 820px) {
  .grid.hero-row { grid-template-columns: 1fr; }
  .grid.hero-row .grid.kpi { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
}

/* refetch holds the previous render instead of flashing a skeleton */
.refreshing { opacity: 0.6; transition: opacity 120ms ease; }

/* ------------------------------------------------------ figures & tiles --- */

.tile-label {
  color: var(--text-secondary);
  font-size: 12.5px;
  margin: 0 0 6px;
}
.tile-value {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  /* proportional figures: tabular-nums makes large numbers look loose */
}
.tile-sub { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

.hero {
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.hero-value {
  font-size: 68px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.03em;
  margin: 4px 0 8px;
}
.hero-label {
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
}

.unavailable { color: var(--text-muted); font-weight: 400; font-size: 0.55em; letter-spacing: 0; }

/* ------------------------------------------------------------------ chart -- */

.chart-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}
.chart-title { font-size: 14px; font-weight: 600; margin: 0; }
.chart-sub { color: var(--text-muted); font-size: 12px; margin: 0 0 14px; }

.toggle {
  margin-left: auto;
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.toggle button {
  border: 0;
  border-radius: 0;
  padding: 4px 11px;
  font-size: 12.5px;
  min-height: 28px;
  color: var(--text-secondary);
  background: transparent;
}
.toggle button[aria-pressed="true"] {
  background: var(--page);
  color: var(--text-primary);
  font-weight: 600;
}

/* container sized to include the x-axis band, so no nested scrollbar */
.plot { position: relative; height: 260px; }
.plot.short { height: 190px; }
.plot.tall { height: 320px; }

.view[hidden] { display: none; }

/* Empty-state message that replaces a plot, so an empty card explains itself
   instead of showing a blank rectangle. */
.plot-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  margin: 0;
  padding: 12px;
  text-align: center;
  font-size: 13px;
}

/* ------------------------------------------------------------------ table -- */

.table-scroll { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}
th {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  position: sticky;
  top: 0;
  background: var(--surface-1);
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--surface-1) 94%, var(--text-primary)); }

.swatch {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  margin-right: 7px;
  vertical-align: baseline;
}

.muted { color: var(--text-muted); }
.mono { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ meter -- */

.meter {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 150px;
}
.meter-track {
  position: relative;
  flex: 1 1 auto;
  height: 7px;
  border-radius: 999px;
  background: var(--blue-100); /* lighter step of the fill's own ramp */
  overflow: hidden;
  min-width: 64px;
}
.meter-fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 999px;
  background: var(--series-1);
}
.meter-fill.warning { background: var(--status-warning); }
.meter-fill.critical { background: var(--status-critical); }
.meter-value { font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--text-secondary); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--page);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- notices -- */

.notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 11px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  font-size: 12.5px;
  margin-bottom: 16px;
  line-height: 1.5;
}
.notice .icon { flex: 0 0 auto; font-weight: 700; line-height: 1.4; }
.notice.warn { border-color: rgba(250, 178, 25, 0.45); background: rgba(250, 178, 25, 0.09); }
.notice.warn .icon { color: #8a5a00; }
:root[data-theme="dark"] .notice.warn .icon { color: var(--status-warning); }
.notice.error { border-color: rgba(208, 59, 59, 0.45); background: rgba(208, 59, 59, 0.09); }
.notice.error .icon { color: var(--status-critical); }
.notice[hidden] { display: none; }

details.raw { margin-top: 8px; }
details.raw summary {
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 6px 0;
}
details.raw summary:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }

footer {
  color: var(--text-muted);
  font-size: 12px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
  line-height: 1.6;
}

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