:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #fcfcfb;
  --border: #e3e1da;
  --grid: #ebe9e3;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --temperature: #eb6834;
  --humidity: #2a78d6;
  --pressure: #1baf7a;
  --battery_pct: #4a3aa7;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --seg-on: #0b0b0b;
  --seg-on-text: #ffffff;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --border: #2d2d2a;
    --grid: #272725;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --temperature: #d95926;
    --humidity: #3987e5;
    --pressure: #199e70;
    --battery_pct: #9085e9;
    --seg-on: #ffffff;
    --seg-on-text: #0b0b0b;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110;
  --surface: #1a1a19;
  --border: #2d2d2a;
  --grid: #272725;
  --text: #ffffff;
  --text-2: #c3c2b7;
  --muted: #8f8e86;
  --temperature: #d95926;
  --humidity: #3987e5;
  --pressure: #199e70;
  --battery_pct: #9085e9;
  --seg-on: #ffffff;
  --seg-on-text: #0b0b0b;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 Inter, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 1100px; margin: 0 auto; padding: 28px 16px 48px; }
.muted { color: var(--muted); }

.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 22px; }
h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 6px; }
h2 { font-size: 17px; font-weight: 600; margin: 0; }
.sub { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: 13px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-2); font-weight: 500;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.ok .dot { background: var(--good); }
.pill.stale .dot { background: var(--warning); }
.pill.dead .dot { background: var(--critical); }
.device {
  font: inherit; padding: 6px 10px; border-radius: 8px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
}

/* ---------- cards ---------- */
.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 32px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px 14px; min-width: 0;
}
.card-head { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; color: var(--text-2); }
.swatch { width: 10px; height: 10px; border-radius: 3px; background: var(--c, var(--muted)); flex: none; }
[data-m="temperature"] { --c: var(--temperature); }
[data-m="humidity"]    { --c: var(--humidity); }
[data-m="pressure"]    { --c: var(--pressure); }
[data-m="battery_pct"] { --c: var(--battery_pct); }

.value { display: flex; align-items: baseline; gap: 4px; margin: 8px 0 4px; }
.value .num { font-size: 40px; font-weight: 600; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; line-height: 1.05; }
.value .unit { font-size: 16px; color: var(--text-2); font-weight: 500; }
.trend { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); min-height: 20px; font-variant-numeric: tabular-nums; }
.trend .arrow { width: 18px; height: 18px; flex: none; }
.trend b { color: var(--text); font-weight: 600; }
.minmax { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--grid); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-height: 27px; }
.boot { margin-top: 4px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.boot b { color: var(--text-2); font-weight: 600; }
.boot span { white-space: nowrap; }

.battery { display: flex; align-items: center; gap: 12px; }
.batt-icon {
  position: relative; width: 46px; height: 24px; border: 2px solid var(--text-2); border-radius: 5px; padding: 2px; flex: none;
}
.batt-icon::after {
  content: ""; position: absolute; right: -6px; top: 6px; width: 4px; height: 8px; border-radius: 0 2px 2px 0; background: var(--text-2);
}
.batt-fill { height: 100%; width: 0; border-radius: 2px; background: var(--good); transition: width .4s; }
.batt-fill.warn { background: var(--warning); }
.batt-fill.crit { background: var(--critical); }

/* ---------- charts ---------- */
.charts-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.seg button {
  font: inherit; font-size: 13px; font-weight: 500; border: 0; background: none; color: var(--text-2);
  padding: 5px 12px; border-radius: 7px; cursor: pointer;
}
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--seg-on); color: var(--seg-on-text); }

.charts { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 8px 4px; }
.chart { margin: 0; padding: 10px 6px 4px; position: relative; }
.chart + .chart { border-top: 1px solid var(--grid); }
.chart figcaption { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; padding: 0 8px 2px; }
.plot { position: relative; width: 100%; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; margin: 0; }

.uplot { font-family: inherit; }
.u-legend { display: none; }
.tip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 4px 8px; font-size: 12px; white-space: nowrap; color: var(--text-2);
  box-shadow: 0 2px 8px rgba(0,0,0,.08); font-variant-numeric: tabular-nums;
}
.tip b { color: var(--text); font-weight: 600; margin-left: 4px; }

/* ---------- table ---------- */
.table-view { margin-top: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.table-view summary { cursor: pointer; padding: 12px 16px; font-weight: 500; font-size: 14px; color: var(--text-2); }
.table-scroll { overflow-x: auto; padding: 0 16px 12px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 10px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 500; }

@media (max-width: 860px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 440px) {
  .value .num { font-size: 30px; }
  .value .unit { font-size: 14px; }
  .card { padding: 14px; }
  .seg button { padding: 5px 8px; }
}
