:root {
  --bg: #EDF2F3;
  --surface: #F8FAFA;
  --ink: #14302A;
  --muted: #557069;
  --rule: #CCD9D7;
  --frost: #2A6CB0;
  --ember: #C0701A;
  --ok: #2F7A4C;
  --bad: #B42318;
  --wait: #6B7F7A;
  --none: #DCE5E4;
  --radius-lg: 14px;
  --radius-sm: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1816; --surface: #15221F; --ink: #E3EEEA; --muted: #92AAA3; --rule: #263835;
    --frost: #79B4F0; --ember: #E8A04E; --ok: #5DBB82; --bad: #F2675B; --wait: #7F938E; --none: #1E2D2A;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1816; --surface: #15221F; --ink: #E3EEEA; --muted: #92AAA3; --rule: #263835;
  --frost: #79B4F0; --ember: #E8A04E; --ok: #5DBB82; --bad: #F2675B; --wait: #7F938E; --none: #1E2D2A;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.45 "Atkinson Hyperlegible Next", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}
h1, h2 { margin: 0; }
h2 { font-size: 15px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--frost); outline-offset: 2px; border-radius: 4px; }

.app {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 28px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px max(24px, env(safe-area-inset-right)) 40px max(24px, env(safe-area-inset-left));
}

/* Sidebar */
.side { display: flex; flex-direction: column; gap: 22px; min-width: 0; }

.status { border-radius: var(--radius-lg); padding: 16px 18px; color: #fff; background: var(--wait); }
.status--ok { background: var(--ok); }
.status--bad { background: var(--bad); }
.status__title { font-size: 22px; font-weight: 800; line-height: 1.15; }
.status__detail { margin: 4px 0 0; font-size: 15px; opacity: .92; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .status { color: #0E1816; } }
:root[data-theme="dark"] .status { color: #0E1816; }

.room__temp { display: flex; align-items: flex-start; font-weight: 800; line-height: .9; letter-spacing: -0.03em; }
.room__temp #room-temp { font-size: 88px; }
.room__unit { font-size: 28px; margin: 8px 0 0 4px; color: var(--muted); letter-spacing: 0; }
.room--frost .room__temp #room-temp { color: var(--frost); }
.room__sub { margin: 6px 0 0; color: var(--muted); font-size: 15px; }

.readings { margin: 0; }
.readings div { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-top: 1px solid var(--rule); }
.readings div:last-child { border-bottom: 1px solid var(--rule); }
.readings dt { color: var(--muted); }
.readings dd { margin: 0; font-weight: 600; text-align: right; }

.outages__list { list-style: none; margin: 0; padding: 0; }
.outages__list li { padding: 8px 0; border-top: 1px solid var(--rule); font-size: 15px; }
.outages__list li:last-child { border-bottom: 1px solid var(--rule); }
.outages__list .when { font-weight: 600; display: block; }
.outages__list .what { color: var(--muted); }
.outages__list .empty { color: var(--muted); border: 0; }

.switch { display: flex; align-items: center; gap: 12px; background: none; border: 0; padding: 6px 0; cursor: pointer; min-height: 44px; }
.switch__track { width: 46px; height: 28px; border-radius: 14px; background: var(--rule); position: relative; transition: background .15s; flex: none; }
.switch__thumb { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch[aria-checked="true"] .switch__track { background: var(--ok); }
.switch[aria-checked="true"] .switch__thumb { transform: translateX(18px); }
.switch__label { font-weight: 600; }
.alerts__hint { margin: 0; color: var(--muted); font-size: 14px; }

/* Main */
.main { display: flex; flex-direction: column; gap: 26px; min-width: 0; }
.ranges { display: inline-flex; align-self: flex-start; background: var(--surface); border: 1px solid var(--rule); border-radius: 999px; padding: 4px; gap: 2px; }
.ranges button { border: 0; background: none; padding: 8px 16px; min-height: 40px; border-radius: 999px; cursor: pointer; color: var(--muted); font-weight: 600; }
.ranges button[aria-selected="true"] { background: var(--ink); color: var(--bg); }

.chart { background: var(--surface); border-radius: var(--radius-sm); padding: 16px 16px 10px; min-width: 0; }
.chart__plot { width: 100%; min-height: 240px; }
.chart__empty { margin: 0 0 10px; color: var(--muted); font-size: 14px; max-width: 60ch; }

.timeline { position: relative; height: 22px; border-radius: 6px; overflow: hidden; background: var(--none); }
.timeline span { position: absolute; top: 0; bottom: 0; }
.timeline .off { min-width: 3px; z-index: 1; }
.timeline .on { background: var(--ok); }
.timeline .off { background: var(--bad); }
.timeline .none { background: var(--none); }
.timeline__axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; margin-top: 6px; }

.uplot { font-family: inherit; }
.u-legend { font-size: 13px; color: var(--muted); }
.u-legend .u-marker { border-radius: 2px; }
.u-legend .u-series:first-child { display: none; }

/* iPad mini portrait */
@media (max-width: 999px) {
  .app { grid-template-columns: minmax(220px, 30%) minmax(0, 1fr); gap: 20px; padding: 20px 16px 32px; }
  .room__temp #room-temp { font-size: 72px; }
  .ranges button { padding: 8px 12px; }
}

/* Phone */
@media (max-width: 699px) {
  .app { grid-template-columns: minmax(0, 1fr); gap: 20px; padding: 14px 16px 32px; }
  .side { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 16px; row-gap: 18px; }
  .status, .readings, .outages, .alerts { grid-column: 1 / -1; }
  .room__temp #room-temp { font-size: 64px; }
  .readings { display: grid; grid-template-columns: 1fr 1fr; column-gap: 16px; }
  .readings div { flex-direction: column; gap: 0; }
  .readings div:nth-last-child(2) { border-bottom: 1px solid var(--rule); }
  .readings dd { text-align: left; }
  .main { order: 2; }
  .ranges { align-self: stretch; display: flex; }
  .ranges button { flex: 1; padding: 10px 0; min-height: 44px; }
  .chart { padding: 14px 10px 8px; }
  .chart__plot { min-height: 200px; }
  .outages, .alerts { order: 3; }
}
@media (max-width: 699px) {
  /* status + room + readings first, then charts, then outages + alert switch */
  .app { display: flex; flex-direction: column; }
  .side { display: contents; }
  .status { order: 0; } .room { order: 1; } .readings { order: 2; }
  .main { order: 3; } .outages { order: 4; } .alerts { order: 5; }
}

@media (prefers-reduced-motion: reduce) {
  .switch__track, .switch__thumb { transition: none; }
}
