: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);
  --wash: rgba(11, 11, 11, 0.05);
  --accent: #2a78d6;
  --heat: #e34948;
  --heat-band: rgba(227, 73, 72, 0.11);
  --s1: #2a78d6; --s2: #1baf7a; --s3: #4a3aa7; --s4: #e87ba4; --s5: #008300; --s6: #eda100;
}
@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);
    --wash: rgba(255, 255, 255, 0.06);
    --accent: #3987e5;
    --heat: #e66767;
    --heat-band: rgba(230, 103, 103, 0.16);
    --s1: #3987e5; --s2: #199e70; --s3: #9085e9; --s4: #d55181; --s5: #008300; --s6: #c98500;
  }
}
: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); --wash: rgba(255,255,255,0.06);
  --accent: #3987e5; --heat: #e66767; --heat-band: rgba(230,103,103,0.16);
  --s1: #3987e5; --s2: #199e70; --s3: #9085e9; --s4: #d55181; --s5: #008300; --s6: #c98500;
}

* { box-sizing: border-box; }
body {
  margin: 0 auto;
  max-width: 1400px;
  padding: 20px 16px 40px;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 10px; }
.top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.updated { color: var(--muted); font-size: 12px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--ring); border-radius: 10px; padding: 12px 14px; position: relative; }
.tile .name { color: var(--ink-2); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.tile .key { width: 12px; height: 3px; border-radius: 2px; flex: none; }
.tile .val { font-size: 28px; font-weight: 600; margin-top: 2px; }
.tile .sub { color: var(--muted); font-size: 12px; }
.tile.stale .val { color: var(--muted); }
.tile.heat { border-color: var(--ring); }
.tile.heat.on { box-shadow: inset 4px 0 0 var(--heat); }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 1px 7px; border-radius: 99px; }
.badge.on { background: var(--heat-band); color: var(--ink); }
.badge.off { background: var(--wash); color: var(--ink-2); }

.filters { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin-bottom: 10px; }
.group { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.range label { color: var(--ink-2); display: flex; gap: 4px; align-items: center; }
button, input[type="datetime-local"] {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--ring); border-radius: 7px; padding: 5px 10px; min-height: 32px;
}
button { cursor: pointer; }
button:hover { background: var(--wash); }
button[aria-pressed="true"] { background: var(--ink); color: var(--page); border-color: var(--ink); }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.rooms button { display: inline-flex; align-items: center; gap: 6px; }
.rooms button .key { width: 12px; height: 3px; border-radius: 2px; }
.rooms button[aria-pressed="false"] { color: var(--muted); }
.rooms button[aria-pressed="false"] .key { opacity: 0.3; }
.rooms button[aria-pressed="true"] { background: var(--surface); color: var(--ink); border-color: var(--ink-2); }
.check { display: flex; align-items: center; gap: 6px; color: var(--ink-2); }

#charts { display: grid; gap: 14px; margin: 8px 0 18px; transition: opacity .2s; }
#charts.loading { opacity: .55; }
#charts.each { grid-template-columns: repeat(auto-fill, minmax(min(100%, 560px), 1fr)); }
.card { background: var(--surface); border: 1px solid var(--ring); border-radius: 10px; padding: 14px 16px; min-width: 0; }
.card header { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.card header h2 { margin: 0; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--ink-2); font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend .line { width: 14px; height: 2px; border-radius: 1px; }
.legend .dash { width: 14px; height: 0; border-top: 2px dashed var(--heat); }
.legend .band { width: 14px; height: 10px; background: var(--heat-band); border-bottom: 3px solid var(--heat); }
.plot { position: relative; height: 380px; }
#charts.each .plot { height: 260px; }
.plot.small { height: 180px; }
.empty { color: var(--muted); padding: 40px 0; text-align: center; }

.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 6px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--ink-2); font-weight: 500; }

footer { color: var(--muted); font-size: 12px; margin-top: 16px; display: flex; flex-wrap: wrap; gap: 6px 18px; }
footer .err { color: var(--heat); }

#tooltip {
  position: fixed; z-index: 10; pointer-events: none; min-width: 160px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--ring); border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.15); padding: 8px 10px; font-size: 12px;
}
#tooltip .t { color: var(--ink-2); margin-bottom: 4px; }
#tooltip .row { display: flex; align-items: center; gap: 6px; }
#tooltip .row b { min-width: 44px; }
#tooltip .row .line { width: 12px; height: 2px; border-radius: 1px; }
#tooltip .row .name { color: var(--ink-2); }
#tooltip .heat { margin-top: 5px; padding-top: 5px; border-top: 1px solid var(--grid); }

.signout { color: var(--muted); font-size: 12px; margin-left: 10px; }
.signout:hover { color: var(--ink); }

/* ---------- phones ---------- */
@media (max-width: 640px) {
  body { padding: 12px 12px 32px; font-size: 15px; }
  h1 { font-size: 19px; }
  .top { margin-bottom: 10px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
  .tile { padding: 9px 11px; }
  .tile .val { font-size: 24px; }
  .tile .sub { font-size: 11px; }
  .filters { gap: 8px; margin-bottom: 8px; }
  /* single swipeable rows instead of wrapping stacks */
  #presets, .rooms { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; width: 100%;
                     -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
  #presets::-webkit-scrollbar, .rooms::-webkit-scrollbar { display: none; }
  #presets button, .rooms button { flex: none; }
  .range { display: grid; grid-template-columns: 44px 1fr 44px 1fr; gap: 6px; width: 100%; }
  .range label { grid-column: 1 / -1; display: grid; grid-template-columns: 42px 1fr; }
  .range label:nth-of-type(1) { grid-row: 1; } .range label:nth-of-type(2) { grid-row: 2; }
  .range input[type="datetime-local"] { width: 100%; min-width: 0; }
  #prev { grid-area: 3 / 1; } #apply { grid-area: 3 / 2; } #next { grid-area: 3 / 3; } #now { grid-area: 3 / 4; }
  [data-view] { flex: 1; }
  .group[aria-label="Layout"] { width: 100%; }
  button, input[type="datetime-local"] { min-height: 40px; }   /* finger-sized */
  .card { padding: 10px 10px 8px; border-radius: 8px; }
  .card header { flex-direction: column; align-items: flex-start; gap: 4px; }
  .plot { height: 290px; }
  #charts.each .plot { height: 220px; }
  .plot.small { height: 170px; }
  th, td { padding: 6px 6px; }
  #summary th:last-child, #summary td:last-child { display: none; }
  #tooltip { max-width: calc(100vw - 16px); }
}
