/* WaterCentral dashboard.
   Colours are the validated data-viz palette. Dark mode is a selected set of
   steps for the dark surface, not an automatic inversion, declared under both
   the media query (OS setting) and [data-theme] (explicit toggle) so the toggle
   wins either way. */

:root {
  color-scheme: light;
  --surface-0: #f4f4f2;
  --surface-1: #fcfcfb;
  --surface-2: #eeeeea;
  --border: #dcdcd6;
  --border-strong: #c2c2ba;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7d7c76;

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;

  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;

  --grid: #e6e6e1;
  --radius: 8px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --surface-2: #242422;
    --border: #383835;
    --border-strong: #4c4c48;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #97968c;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --grid: #2e2e2b;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #121211;
  --surface-1: #1a1a19;
  --surface-2: #242422;
  --border: #383835;
  --border-strong: #4c4c48;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #97968c;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --grid: #2e2e2b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

button, input, select, textarea { font: inherit; color: inherit; }

button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--border-strong); }
button.primary { background: var(--series-1); border-color: var(--series-1); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button[aria-pressed="true"] { background: var(--series-1); border-color: var(--series-1); color: #fff; }
button:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
}

/* ---- layout ---- */

header.top {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 18px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
header.top h1 { font-size: 16px; margin: 0; letter-spacing: -.01em; }
header.top h1 span { color: var(--text-muted); font-weight: 400; }
.spacer { flex: 1; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12px; color: var(--text-secondary);
}
.chip b { color: var(--text-primary); font-variant-numeric: tabular-nums; }

.layout { display: grid; grid-template-columns: 260px 1fr; min-height: calc(100vh - 49px); }
@media (max-width: 820px) { .layout { grid-template-columns: 1fr; } }

nav.sidebar {
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  padding: 12px;
}
nav.sidebar h2 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-muted); margin: 14px 4px 8px;
}
.device {
  display: flex; align-items: center; gap: 8px;
  width: 100%; text-align: left; margin-bottom: 4px;
  background: transparent; border: 1px solid transparent;
}
.device:hover { background: var(--surface-2); }
.device[aria-current="true"] { background: var(--surface-2); border-color: var(--border-strong); }
.device .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device .site { display: block; font-size: 11px; color: var(--text-muted); }

main { padding: 18px; min-width: 0; }
section { margin-bottom: 24px; }
section > h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted); margin: 0 0 10px;
}

/* ---- status ---- */

.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.online { background: var(--good); }
.dot.offline { background: var(--critical); }

.sev { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; }
.sev-good     { color: var(--good); }
.sev-warning  { color: var(--warning); }
.sev-serious  { color: var(--serious); }
.sev-critical { color: var(--critical); }
/* Status colour never carries meaning alone: the glyph and the text label
   travel with it. */
.sev .glyph { font-size: 12px; }

/* ---- tiles ---- */

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
}
.tile .label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-muted); margin-bottom: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tile .value {
  font-size: 26px; font-weight: 650; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; line-height: 1.15;
}
.tile .value .unit { font-size: 13px; font-weight: 400; color: var(--text-secondary); margin-left: 3px; }
.tile .age { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.tile.stale { border-color: var(--warning); }

/* ---- cards, tables ---- */

.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
}
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 600; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: none; }

.muted { color: var(--text-muted); }
.mono { font-family: var(--mono); font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---- charts ---- */

.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 12px; }
.chart-card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px 6px;
}
.chart-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.chart-head .title { font-weight: 600; font-size: 13px; }
.chart-head .last { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--text-secondary); }
svg.chart { display: block; width: 100%; height: 150px; overflow: visible; }
svg.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
svg.chart .axis-label { fill: var(--text-muted); font-size: 10px; }
svg.chart .series { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg.chart .band { fill: var(--series-1); opacity: .13; }
svg.chart .crosshair { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 3; }
/* 2px surface ring keeps the marker legible over the line it sits on */
svg.chart .marker { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
svg.chart .last-label { fill: var(--text-secondary); font-size: 11px; font-variant-numeric: tabular-nums; }

.tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--surface-1); border: 1px solid var(--border-strong);
  border-radius: 6px; padding: 6px 9px; font-size: 12px;
  box-shadow: 0 4px 14px rgb(0 0 0 / .18);
  opacity: 0; transition: opacity .08s;
}
.tooltip.on { opacity: 1; }
.tooltip .t-time { color: var(--text-muted); font-size: 11px; }
.tooltip .t-value { font-weight: 650; font-variant-numeric: tabular-nums; }

/* ---- login ---- */

.overlay {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: var(--surface-0); z-index: 100;
}
.overlay form {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 12px; padding: 26px; width: 320px;
  display: grid; gap: 10px;
}
.overlay h2 { margin: 0 0 6px; font-size: 18px; }
.error { color: var(--critical); font-size: 12px; min-height: 16px; }

.hidden { display: none !important; }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--surface-1); border: 1px solid var(--border-strong);
  border-radius: 8px; padding: 9px 14px; z-index: 60;
  box-shadow: 0 6px 20px rgb(0 0 0 / .2);
}

/* --- second factor / settings ------------------------------------------ */
.chip.ok    { background: var(--ok, #1f7a3f); color: #fff; }
.chip.warn  { background: var(--warn, #a86b00); color: #fff; }
label.check  { display: flex; align-items: center; gap: 8px; }
label.check input { width: auto; }
.small       { font-size: 0.85em; }
.qr          { max-width: 220px; margin: 10px 0; }
.qr svg      { width: 100%; height: auto; background: #fff; padding: 8px;
               border-radius: 6px; }
#elevate-code, #mfa-code {
  font-size: 1.4em; letter-spacing: 0.25em; text-align: center; width: 8ch;
}
