/* Tokens: the dataviz reference palette (chart chrome, categorical slots 1-4,
   status). Dark values are their own validated steps, not an inversion. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s4: #eda100;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --critical: #d03b3b;
  --track: #e1e0d9;
  --accent: #2a78d6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --ring: rgba(255, 255, 255, 0.10);
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --s4: #c98500;
    --good-text: #0ca30c;
    --track: #2c2c2a;
    --accent: #3987e5;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --ring: rgba(255, 255, 255, 0.10);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --good-text: #0ca30c; --track: #2c2c2a; --accent: #3987e5;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1 { font-size: 20px; margin: 0; font-weight: 650; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
.muted { color: var(--muted); margin: 2px 0 0; font-size: 13px; }
.error { color: var(--critical); min-height: 1.4em; margin: 8px 0 0; font-size: 14px; }
[hidden] { display: none !important; }

.card {
  background: var(--surface);
  border: 1px solid var(--ring);
  border-radius: 12px;
  padding: 16px;
  margin: 0;
}

button, input {
  font: inherit;
  color: inherit;
}
button {
  border: 1px solid var(--ring);
  background: var(--surface);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
}
button:hover { background: var(--grid); }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.ghost { background: transparent; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: grid; gap: 8px; }
.login-card label { font-size: 13px; color: var(--ink-2); margin-top: 8px; }
.login-card input {
  border: 1px solid var(--axis);
  background: var(--page);
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
}
.login-card button[type="submit"] {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  padding: 10px 12px;
  margin-top: 4px;
}

/* ---------- dashboard ---------- */
.dash { max-width: 1200px; margin: 0 auto; padding: 20px 16px 40px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
/* Grid items default to min-width: auto, so a wide (nowrap) table would widen the whole page; let the table scroll instead. */
.dash > *, .charts > * { min-width: 0; }
.top { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; }
.controls { display: flex; gap: 8px; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--ring); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: var(--surface); }
.seg button + button { border-left: 1px solid var(--ring); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--page); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile .label { font-size: 13px; color: var(--ink-2); }
.tile .value { font-size: 28px; font-weight: 600; margin: 2px 0; }
.tile .sub { font-size: 12px; color: var(--muted); }
.meter { height: 6px; border-radius: 3px; background: var(--track); margin-top: 8px; overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.meter.warning > span { background: var(--warning); }
.meter.critical > span { background: var(--critical); }

.status { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.status svg { width: 14px; height: 14px; flex: none; }
.status.good svg { color: var(--good); }
.status.warning svg { color: var(--warning); }
.status.critical svg { color: var(--critical); }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 6px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 520px), 1fr)); gap: 16px; }
.chart figcaption { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.chart figcaption .t { font-weight: 600; }
.chart figcaption .now { font-size: 13px; color: var(--ink-2); }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .endlabel { fill: var(--ink-2); font-size: 11px; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { opacity: 0.10; }
/* Series slots: one class per palette slot, used by lines, areas, dots and keys. */
.line.s1 { stroke: var(--s1); } .area.s1, .dot.s1 { fill: var(--s1); } .k.s1 { background: var(--s1); }
.line.s2 { stroke: var(--s2); } .area.s2, .dot.s2 { fill: var(--s2); } .k.s2 { background: var(--s2); }
.line.s3 { stroke: var(--s3); } .area.s3, .dot.s3 { fill: var(--s3); } .k.s3 { background: var(--s3); }
.line.s4 { stroke: var(--s4); } .area.s4, .dot.s4 { fill: var(--s4); } .k.s4 { background: var(--s4); }
.chart .cross { stroke: var(--axis); stroke-width: 1; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .empty { fill: var(--muted); font-size: 13px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--ink-2); margin-top: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 2px; border-radius: 1px; display: inline-block; }
.chart details { margin-top: 8px; font-size: 12px; color: var(--ink-2); }
.chart details table { font-size: 12px; margin-top: 6px; }
.chart details .table-wrap { max-height: 220px; overflow: auto; }

.tip {
  position: fixed;
  pointer-events: none;
  z-index: 10;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--ring);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  min-width: 140px;
}
.tip .h { color: var(--muted); margin-bottom: 4px; }
.tip .r { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.tip .r span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.tip .r i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.tip .r b { font-weight: 600; font-variant-numeric: tabular-nums; }
.foot { text-align: center; }

@media (max-width: 520px) {
  .tile .value { font-size: 24px; }
  .top { align-items: flex-start; }
}
@media (forced-colors: active) {
  .chart .line { stroke: CanvasText; }
}
