:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --border: #e4e3df;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #8a8985;
  --grid: #ecebe7;
  --accent: #2a78d6;
  --pool: #2a78d6;        /* categorical slot 1: pool sensor */
  --indoor: #eb6834;      /* slot 2: indoor / gateway */
  --pool-band: rgba(42, 120, 214, 0.14);
  --good: #008300;
  --warn: #b45309;
  --live: #1baf7a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1216;
    --surface: #171b21;
    --border: #262b33;
    --text: #f4f4f2;
    --text-2: #b8b9b3;
    --text-3: #7d7f7a;
    --grid: #232830;
    --accent: #3987e5;
    --pool: #3987e5;
    --indoor: #d95926;
    --pool-band: rgba(57, 135, 229, 0.18);
    --good: #4ade80;
    --warn: #fbbf24;
    --live: #34d399;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.page { max-width: 1080px; margin: 0 auto; padding: 24px 16px 48px; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; margin: 0; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 8px; }
p { margin: 0; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.92em; }
a { color: var(--accent); }

.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.status { display: inline-flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 14px; margin-top: 2px; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.status.live .dot { background: var(--live); box-shadow: 0 0 0 3px color-mix(in srgb, var(--live) 25%, transparent); }
.status.stale .dot { background: var(--warn); }
.meta { text-align: right; display: grid; gap: 4px; justify-items: end; }
.gateway { color: var(--text-3); font-size: 13px; }
.battery { display: inline-flex; align-items: center; gap: 6px; color: var(--text-3); font-size: 12px; }
.battery .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); }
.battery.low { color: var(--warn); }
.battery.low .dot { background: var(--warn); }

.hero { display: grid; grid-template-columns: minmax(220px, 1.4fr) 1fr; gap: 16px; margin-bottom: 20px; }
.hero-main, .tile, .chart-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
}
.hero-main { padding: 20px 22px; display: flex; flex-direction: column; justify-content: center; }
.label { font-size: 13px; color: var(--text-2); }
.hero-value { font-size: 64px; font-weight: 600; line-height: 1.05; letter-spacing: -0.02em; margin: 6px 0 4px; }
.hero-value .unit, .value .unit { font-size: 0.42em; font-weight: 500; color: var(--text-2); margin-left: 4px; }
.hero-sub { color: var(--text-2); font-size: 13px; }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.tile { padding: 14px 16px; }
.tile .value { font-size: 26px; font-weight: 600; line-height: 1.2; margin-top: 4px; letter-spacing: -0.01em; }

.controls { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin: 4px 0 12px; }
.ranges { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.ranges button {
  font: inherit; font-size: 13px; font-weight: 500; color: var(--text-2); background: none; border: 0;
  border-radius: 8px; padding: 6px 12px; cursor: pointer;
}
.ranges button:hover { color: var(--text); }
.ranges button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.export { font-size: 13px; color: var(--text-2); text-decoration: none; }
.export:hover { color: var(--accent); }

.chart-card { padding: 16px 16px 8px; margin-bottom: 12px; }
.unit-hint { color: var(--text-3); font-weight: 400; font-size: 12px; margin-left: 4px; }
.chart { min-height: 240px; }
.chart.empty::after { content: "No data in this range yet."; display: block; color: var(--text-3); font-size: 13px; padding: 24px 0; }

.foot { color: var(--text-3); font-size: 13px; margin-top: 24px; display: grid; gap: 4px; }

/* uPlot theming: recessive grid/axes, legend as the readout row. */
.uplot, .u-legend { font: inherit; color: var(--text-2); }
.u-legend { text-align: left; padding: 4px 0 0; font-size: 13px; }
.u-legend .u-series { padding: 2px 14px 2px 0; }
.u-legend .u-series.band { display: none; }
.u-legend .u-marker { width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; border-width: 0 !important; }
.u-legend .u-label { font-weight: 500; }
.u-legend .u-value { color: var(--text); font-variant-numeric: tabular-nums; min-width: 6ch; display: inline-block; }
.u-legend .u-series > * { padding: 0 2px 0 0; }
.u-legend th::after { content: none; }
.u-select { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.u-cursor-x { border-right: 1px solid var(--text-3); }
.u-cursor-y { display: none; }

@media (max-width: 720px) {
  .hero { grid-template-columns: 1fr; }
  .hero-value { font-size: 52px; }
  .meta { text-align: left; justify-items: start; }
  .u-legend .u-series { padding-right: 10px; }
}
