/* 12V dashboard.
   Colour roles come from the validated reference palette: series slots are used
   by role (--series-1 …) so light/dark swap in one place. Dark mode is a
   selected set of steps for the dark surface, not an inverted light palette. */

.viz-root {
  color-scheme: light;
  --surface-0: #f4f3f0;
  --surface-1: #fcfcfb;
  --surface-2: #eceae5;
  --hairline: #dedcd5;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #77756e;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --good: #008300;
  --warn: #eda100;
  --crit: #e34948;
  --grid: #e7e5df;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])).viz-root {
    color-scheme: dark;
    --surface-0: #111110;
    --surface-1: #1a1a19;
    --surface-2: #24241f;
    --hairline: #383835;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #96958c;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --good: #008300;
    --warn: #c98500;
    --crit: #e66767;
    --grid: #2e2e2a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.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;
}

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

.topbar {
  display: flex; flex-wrap: wrap; gap: 16px;
  align-items: center; justify-content: space-between;
  padding: 16px 24px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--hairline);
}
.topbar-main { display: flex; align-items: center; gap: 14px; }
.product-mark { color: var(--series-1); display: inline-flex; flex: none; }
.topbar h1 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.topbar .sub { margin: 3px 0 0; color: var(--text-secondary); font-size: 13px; }
.topbar-side { display: flex; align-items: center; gap: 18px; }
.brand-logo { display: inline-flex; }
/* The supplied logo is light grey — fine on the dark surface, but it would be
   nearly invisible on the light surface, so darken it just in light mode. */
.brand-logo img { display: block; height: 30px; width: auto; filter: brightness(0.5) saturate(0); }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .brand-logo img { filter: none; }
}
:root[data-theme="dark"] .brand-logo img { filter: none; }

.live {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text-secondary);
}
.live .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted);
}
.live.is-live .dot { background: var(--good); }
.live.is-down .dot { background: var(--crit); }

main { max-width: 1180px; margin: 0 auto; padding: 24px; }

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

.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px;
  margin-bottom: 24px;
}
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-secondary); }
.field.checkbox { flex-direction: row; align-items: center; gap: 7px; }

/* Device selector: icon buttons, one per device, instead of a dropdown. */
.device-tabs { display: flex; flex-wrap: wrap; gap: 8px; }
.device-tab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 12px 7px 9px;
  background: var(--surface-1);
  border: 1px solid var(--hairline); border-radius: 8px;
  color: var(--text-secondary); font: inherit; font-size: 14px;
  cursor: pointer; line-height: 1;
}
.device-tab:hover { background: var(--surface-2); }
.device-tab .tab-icon { width: 20px; height: 20px; flex: none; color: var(--text-muted); }
.device-tab .tab-label { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-tab.is-active {
  color: var(--text-primary); font-weight: 600;
  border-color: var(--series-1);
  box-shadow: inset 0 0 0 1px var(--series-1);
}
.device-tab.is-active .tab-icon { color: var(--series-1); }
/* A device with a problem (no key / wrong key) gets a warning dot. */
.device-tab .tab-warn { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); flex: none; }

.range { display: flex; gap: 0; margin: 0; padding: 0; border: 0; }
.range button {
  padding: 7px 13px;
  font: inherit; font-size: 13px;
  color: var(--text-secondary); background: var(--surface-1);
  border: 1px solid var(--hairline); border-right-width: 0;
  cursor: pointer;
}
.range button:first-of-type { border-radius: 6px 0 0 6px; }
.range button:last-of-type { border-radius: 0 6px 6px 0; border-right-width: 1px; }
.range button:hover { background: var(--surface-2); }
.range button.is-active {
  color: var(--text-primary); background: var(--surface-2);
  font-weight: 600; box-shadow: inset 0 -2px 0 var(--series-1);
}

.empty {
  padding: 28px; margin: 0 0 24px;
  text-align: center; color: var(--text-secondary);
  background: var(--surface-1);
  border: 1px solid var(--hairline); border-radius: 10px;
}

.notif-btn {
  margin-left: auto; align-self: flex-end;
  padding: 7px 14px; font: inherit; font-size: 13px;
  color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--hairline); border-radius: 8px; cursor: pointer;
}
.notif-btn:hover { background: var(--surface-2); }
.notif-btn.is-on { border-color: var(--good); box-shadow: inset 0 0 0 1px var(--good); }
.notif-btn:disabled { opacity: 0.6; cursor: default; }

/* --- phone status strip --------------------------------------------------- */

.phone-strip {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px;
  padding: 12px 16px; margin-bottom: 20px;
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-left: 4px solid var(--text-muted);
  border-radius: 10px;
  font-size: 13px; color: var(--text-secondary);
}
/* State carries meaning, so it also gets an icon + word, never colour alone. */
.phone-strip.state-online  { border-left-color: var(--good); }
.phone-strip.state-late    { border-left-color: var(--warn); }
.phone-strip.state-offline { border-left-color: var(--crit); }

.phone-strip .headline {
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 600; color: var(--text-primary);
}
.phone-strip .state-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-muted); }
.phone-strip.state-online  .state-dot { background: var(--good); }
.phone-strip.state-late    .state-dot { background: var(--warn); }
.phone-strip.state-offline .state-dot { background: var(--crit); }

.phone-strip .metric { display: inline-flex; align-items: baseline; gap: 5px; }
.phone-strip .metric b { color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; }
.phone-strip .metric.alert b { color: var(--crit); }

/* --- stat tiles ----------------------------------------------------------- */

.tiles {
  display: grid; gap: 12px; margin-bottom: 28px;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
}
.tile {
  padding: 14px 16px;
  background: var(--surface-1);
  border: 1px solid var(--hairline); border-radius: 10px;
}
.tile .label {
  font-size: 12px; color: var(--text-secondary);
  text-transform: none; margin-bottom: 6px;
}
.tile .value {
  font-size: 26px; font-weight: 600; letter-spacing: -0.02em;
  /* Proportional figures: tabular-nums makes a big standalone number look loose. */
}
.tile .value .unit {
  font-size: 14px; font-weight: 500; color: var(--text-secondary); margin-left: 3px;
}
.tile.is-state .value { font-size: 17px; }
.tile .meta { margin-top: 4px; font-size: 12px; color: var(--text-muted); }

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

.charts { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }

.card {
  position: relative;
  padding: 16px 18px 8px;
  background: var(--surface-1);
  border: 1px solid var(--hairline); border-radius: 10px;
}
.card.is-loading { opacity: 0.55; }
.card h3 { margin: 0; font-size: 14px; font-weight: 600; }
.card .card-sub { margin: 2px 0 10px; font-size: 12px; color: var(--text-secondary); }
.card svg { display: block; width: 100%; height: auto; overflow: visible; }

.grid-line { stroke: var(--grid); stroke-width: 1; }
.axis-text { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.series-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.series-area { stroke: none; opacity: 0.1; }
.end-dot { stroke: var(--surface-1); stroke-width: 2; }
.crosshair { stroke: var(--text-muted); stroke-width: 1; pointer-events: none; }

.tooltip {
  position: absolute; z-index: 5;
  min-width: 130px; padding: 8px 10px;
  background: var(--surface-1);
  border: 1px solid var(--hairline); border-radius: 8px;
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.13);
  pointer-events: none; opacity: 0; transition: opacity 0.1s;
  font-size: 12px;
}
.tooltip.is-visible { opacity: 1; }
.tooltip .tip-value {
  display: block;
  font-size: 17px; font-weight: 600; color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.tooltip .tip-row { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); }
/* Line key, not a filled box — the mark is a line, so the key is a line. */
.tooltip .tip-key { width: 14px; height: 2px; border-radius: 1px; flex: none; }
.tooltip .tip-time { margin-top: 4px; color: var(--text-muted); }

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

.table-view, .devices { margin-top: 28px; }
.devices h2 { font-size: 15px; font-weight: 600; margin: 0 0 10px; }

table { width: 100%; border-collapse: collapse; background: var(--surface-1); font-size: 13px; }
caption { text-align: left; padding: 12px 14px 8px; font-weight: 600; }
th, td {
  padding: 7px 12px; text-align: right;
  border-bottom: 1px solid var(--hairline);
  font-variant-numeric: tabular-nums;
}
th:first-child, td:first-child { text-align: left; font-variant-numeric: normal; }
thead th { color: var(--text-secondary); font-weight: 600; font-size: 12px; }
.table-wrap {
  max-height: 460px; overflow: auto;
  border: 1px solid var(--hairline); border-radius: 10px;
}
.dot-key { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; }

footer {
  max-width: 1180px; margin: 0 auto; padding: 8px 24px 40px;
  color: var(--text-secondary); font-size: 13px;
}
footer a { color: var(--series-1); }
footer .brand { margin-top: 6px; color: var(--text-muted); font-size: 12px; }

@media (max-width: 620px) {
  .charts { grid-template-columns: 1fr; }
  main { padding: 16px; }
}
