/*
 * Palette and chrome. Both modes are selected sets, not an automatic flip: the dark
 * column is the same hues re-stepped for the dark surface. Series slots are assigned
 * in fixed order and never cycled, so a filter that drops a series never repaints the
 * survivors.
 */
:root {
  color-scheme: light;

  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --hover-wash: rgba(11, 11, 11, 0.04);

  --series-1: #2a78d6; /* blue */
  --series-2: #eb6834; /* orange */
  --series-3: #1baf7a; /* aqua */
  --series-4: #eda100; /* yellow */

  /* Sequential blue steps, used for meter tracks (lighter step of the same ramp). */
  --seq-100: #cde2fb;
  --seq-450: #2a78d6;

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-critical: #d03b3b;

  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 10px;
}

@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;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --hover-wash: rgba(255, 255, 255, 0.06);

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;

    --seq-100: #184f95;
    --seq-450: #3987e5;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --hover-wash: rgba(255, 255, 255, 0.06);

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;

  --seq-100: #184f95;
  --seq-450: #3987e5;
}

* { box-sizing: border-box; }

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

/* --- Page frame ----------------------------------------------------------- */

.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

header.top {
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
  padding: 20px 0 16px;
  margin-bottom: 24px;
}

header.top h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

header.top p {
  margin: 4px 0 0;
  color: var(--text-secondary);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
}

.badge.demo {
  border-color: var(--status-warning);
  color: var(--text-primary);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.top-actions .who {
  font-size: 13px;
  color: var(--text-secondary);
}

.top-actions button[aria-expanded="true"] {
  border-color: var(--text-primary);
  font-weight: 600;
}

/* --- Sign-in and endpoint panels ------------------------------------------ */

.panel {
  padding: 16px;
  margin-bottom: 20px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.panel h2 {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 600;
}

.panel .sub {
  margin: 0 0 14px;
  color: var(--text-secondary);
  font-size: 13px;
  max-width: 80ch;
}

.panel-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.panel-fields .field.grow {
  flex: 1 1 320px;
  min-width: 260px;
}

.panel-fields .field.grow input { width: 100%; }

.panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.panel-note {
  font-size: 13px;
  color: var(--text-secondary);
}

.panel-note.bad { color: var(--status-critical); }
.panel-note.good { color: var(--status-good); }

/* Discovered endpoints: what the document declares, and which card reads it. */
.endpoints {
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.endpoints h3 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.endpoints code { font-size: 12px; }

.endpoints .unused {
  color: var(--text-muted);
  font-style: italic;
}

/* --- Filter row: one row, above everything it scopes ---------------------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding: 14px 16px;
  margin-bottom: 20px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 12px;
  color: var(--text-secondary);
}

input, select, button {
  font-family: inherit;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--axis);
  border-radius: 6px;
  padding: 6px 10px;
}

button {
  cursor: pointer;
}

button:hover {
  background: var(--hover-wash);
}

button.primary {
  background: var(--series-1);
  border-color: var(--series-1);
  color: #ffffff;
}

button.primary:hover {
  filter: brightness(1.06);
}

.presets {
  display: flex;
  gap: 6px;
}

.presets button[aria-pressed="true"] {
  border-color: var(--text-primary);
  font-weight: 600;
}

/* --- Cards ---------------------------------------------------------------- */

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

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px 20px;
  min-width: 0;
}

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

.card h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.card h2 .kpi-tag {
  color: var(--text-muted);
  font-weight: 400;
}

.card .sub {
  margin: 4px 0 16px;
  color: var(--text-secondary);
  font-size: 13px;
}

.card.loading { opacity: 0.5; }  /* refetch holds the frame — no skeleton flash */

/* --- Figures -------------------------------------------------------------- */

.hero {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.hero .value {
  font-size: 56px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.hero .unit {
  font-size: 20px;
  color: var(--text-secondary);
}

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

.tile {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.tile .label {
  font-size: 12px;
  color: var(--text-secondary);
}

.tile .value {
  font-size: 22px;
  font-weight: 600;
}

.tile .note {
  font-size: 11px;
  color: var(--text-muted);
}

.meter {
  height: 10px;
  border-radius: 999px;
  background: var(--seq-100);
  overflow: hidden;
  margin: 12px 0 6px;
}

.meter > span {
  display: block;
  height: 100%;
  background: var(--seq-450);
  border-radius: 999px;
}

/* --- Legend --------------------------------------------------------------- */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-secondary);
}

.legend .item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend .swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex: none;
}

.legend .swatch.line {
  height: 2px;
  border-radius: 2px;
}

.legend .n {
  color: var(--text-primary);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* --- Tables (the relief channel: every chart has a table twin) ------------ */

details.table-view {
  margin-top: 14px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

details.table-view summary {
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13px;
}

.scroll {
  overflow-x: auto;
  max-height: 340px;
  overflow-y: auto;
  margin-top: 10px;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}

th, td {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: var(--surface-1);
  color: var(--text-secondary);
  font-weight: 600;
}

td.num, th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* --- Chart chrome --------------------------------------------------------- */

.chart { width: 100%; }

.chart svg { display: block; width: 100%; height: auto; }

.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-line { stroke: var(--axis); stroke-width: 1; }
.chart text { fill: var(--text-muted); font-size: 11px; }
.chart text.value-label { fill: var(--text-primary); font-size: 11px; font-weight: 600; }
.chart text.cat-label { fill: var(--text-secondary); font-size: 12px; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover ~ .mark, .chart .mark.hot { filter: brightness(1.12); }

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

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

#tooltip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  min-width: 140px;
  padding: 8px 10px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.14);
  font-size: 12px;
  opacity: 0;
  transition: opacity 90ms linear;
}

#tooltip.on { opacity: 1; }

#tooltip .tt-title {
  color: var(--text-secondary);
  margin-bottom: 4px;
}

#tooltip .tt-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

#tooltip .tt-key {
  width: 12px;
  height: 2px;
  border-radius: 2px;
  flex: none;
}

/* Values lead, labels follow. */
#tooltip .tt-value {
  color: var(--text-primary);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

#tooltip .tt-name { color: var(--text-secondary); }

/* --- Errors --------------------------------------------------------------- */

.error {
  padding: 12px 16px;
  margin-bottom: 20px;
  border: 1px solid var(--status-critical);
  border-radius: var(--radius);
  background: var(--surface-1);
}

.error strong { color: var(--status-critical); }

.error pre {
  margin: 6px 0 0;
  white-space: pre-wrap;
  font-size: 12px;
  color: var(--text-secondary);
}

.caveat {
  margin-top: 16px;
  padding: 10px 12px;
  border-left: 2px solid var(--status-warning);
  background: var(--hover-wash);
  border-radius: 0 6px 6px 0;
  font-size: 13px;
  color: var(--text-secondary);
}
