:root {
  color-scheme: light;
  --page: #f3f3f1;
  --surface: #fcfcfb;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #76756f;
  --grid: #e4e3df;
  --axis: #c9c8c2;
  --temp: #e34948;
  --hum: #2a78d6;
  --heat: #eda100;
  --cool: #1baf7a;
  --band-alpha: 0.16;
  --accent: #2a78d6;
  --danger: #c4312f;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #111110;
    --surface: #1a1a19;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #9b9a92;
    --grid: #2c2c2a;
    --axis: #45443f;
    --temp: #e66767;
    --hum: #3987e5;
    --heat: #eda100;
    --cool: #199e70;
    --band-alpha: 0.24;
    --accent: #3987e5;
    --danger: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #111110;
  --surface: #1a1a19;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #9b9a92;
  --grid: #2c2c2a;
  --axis: #45443f;
  --temp: #e66767;
  --hum: #3987e5;
  --heat: #eda100;
  --cool: #199e70;
  --band-alpha: 0.24;
  --accent: #3987e5;
  --danger: #e66767;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
main { max-width: 960px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 0.95rem; margin: 0 0 8px; color: var(--text-2); font-weight: 600; }
.card {
  background: var(--surface);
  border-radius: 20px;
  padding: 16px 18px;
  margin-bottom: 14px;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 6px 24px rgb(0 0 0 / 0.05);
}
.muted { color: var(--muted); }
.quiet { color: var(--text-2); font-size: 0.9rem; text-decoration: none; }
.quiet:hover { text-decoration: underline; }

.top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

.now { padding-top: 28px; }
.hero { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; }
.hero-num {
  font-size: clamp(4.5rem, 18vw, 6.5rem); font-weight: 300; line-height: 1; letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}
#now-updated { font-size: 0.85rem; min-height: 1.2em; }
.tiles { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin: 16px 0 0; }
.tiles div {
  min-width: 120px; padding: 10px 18px; border-radius: 16px; background: var(--page); text-align: center;
}
.tiles dt { color: var(--text-2); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; }
.tiles dd { margin: 4px 0 0; font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.state-heat::before, .state-cool::before {
  content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 6px; vertical-align: 1px;
}
.state-heat::before { background: var(--heat); }
.state-cool::before { background: var(--cool); }
.state-off { color: var(--danger); }

.ctl { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--grid); display: grid; gap: 14px; justify-items: center; }
.ctl > .hold, .ctl > .ctl-msg { text-align: center; }
.seg {
  display: inline-flex; gap: 2px; padding: 4px; border-radius: 999px; background: var(--page);
  width: fit-content; max-width: 100%;
}
.seg button {
  font: inherit; font-size: 0.95rem; padding: 8px 18px; border: 0; border-radius: 999px;
  background: transparent; color: var(--text-2); cursor: pointer; transition: background 0.15s, color 0.15s;
}
.seg button[aria-pressed="true"] { box-shadow: 0 1px 4px rgb(0 0 0 / 0.15); }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.seg button[data-mode="heat"][aria-pressed="true"], .seg button[data-mode="aux"][aria-pressed="true"] { background: var(--heat); color: #1a1a19; }
.seg button[data-mode="cool"][aria-pressed="true"] { background: var(--cool); }
.seg button[data-mode="off"][aria-pressed="true"] { background: var(--text-2); color: var(--surface); }
.steppers { display: flex; justify-content: center; gap: 12px 24px; flex-wrap: wrap; }
.sp { display: flex; align-items: center; gap: 10px; }
.sp .lbl { color: var(--text-2); font-size: 0.9rem; }
.sp-box {
  display: flex; align-items: center; gap: 2px; padding: 0 14px 0 4px; border-radius: 999px;
  background: var(--page); border: 1.5px solid transparent; transition: border-color 0.15s;
}
.sp-box.heat { --ring: var(--heat); }
.sp-box.cool { --ring: var(--cool); }
.sp-box:focus-within { border-color: var(--ring); }
.sp-box input {
  width: 3.6em; padding: 8px 0 8px 10px; border: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 1.4rem; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums;
  -moz-appearance: textfield; appearance: textfield;
}
.sp-box input::-webkit-outer-spin-button, .sp-box input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.sp-box input:focus { outline: none; }
.sp-box input:disabled { opacity: 0.55; }
.sp-box .unit { color: var(--text-2); font-size: 1rem; }
.sp .btn-primary { border-radius: 999px; padding: 10px 18px; }
.seg button:disabled { opacity: 0.4; cursor: default; }
.ctl-msg { margin: 0; font-size: 0.9rem; color: var(--danger); }

.controls { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
#devices { margin-bottom: 12px; }
.chips button, .chip-btn {
  border: 1px solid var(--grid);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 14px;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
.chips button[aria-pressed="true"], .chip-btn[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: #fff;
}

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.82rem; color: var(--text-2); margin-bottom: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.key-line { width: 16px; height: 0; border-top: 2px solid; }
.key-dash { width: 16px; height: 0; border-top: 2px dashed var(--text-2); }
.key-band { width: 12px; height: 12px; border-radius: 3px; }

.chart { position: relative; width: 100%; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .empty { fill: var(--muted); font-size: 13px; }

.tip {
  position: fixed; z-index: 10; pointer-events: none;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--grid); border-radius: 12px;
  padding: 8px 10px; font-size: 0.82rem; min-width: 140px;
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.15);
}
.tip .t { color: var(--text-2); margin-bottom: 4px; }
.tip .r { display: flex; align-items: center; gap: 6px; }
.tip .r b { font-variant-numeric: tabular-nums; }
.tip .r .lbl { color: var(--text-2); }

.table-wrap { max-height: 420px; overflow: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 4px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { position: sticky; top: 0; background: var(--surface); color: var(--text-2); font-weight: 600; }

.login { min-height: 100vh; display: grid; place-items: center; }
.login form { width: min(340px, 100%); display: grid; gap: 10px; }
.login h1 { margin-bottom: 6px; }
.login label { color: var(--text-2); font-size: 0.9rem; }
.login input {
  font: inherit; padding: 9px 10px; border-radius: 8px;
  border: 1px solid var(--axis); background: var(--page); color: var(--text);
}
.login button {
  font: inherit; padding: 9px; border: 0; border-radius: 8px;
  background: var(--accent); color: #fff; cursor: pointer;
}
.error { color: var(--danger); margin: 0; font-size: 0.9rem; }

/* ---------- schedule ---------- */
.hold { margin: 0; font-size: 0.9rem; }
.sched-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.sched-head h2 { margin: 0; }
.seg.small button { padding: 5px 14px; font-size: 0.85rem; }
.sched-pick { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-bottom: 12px; }
.chips button .dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: currentColor; margin-right: 6px; vertical-align: 1px;
}
.week { display: grid; }
.day-row {
  display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 10px;
  padding: 8px 0; border-top: 1px solid var(--grid);
}
.day-row:first-child { border-top: 0; }
.day-row .day { font-weight: 600; color: var(--text-2); }
.day-row .steps { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.step-chip {
  display: inline-flex; gap: 6px; align-items: baseline; padding: 3px 9px; border-radius: 999px;
  background: var(--page); font-size: 0.85rem; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.step-chip .tm { color: var(--text-2); }
.step-chip .h { color: var(--text); font-weight: 600; }
.step-chip .h.heat::before, .step-chip .h.cool::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 4px; vertical-align: 1px;
}
.step-chip .h.heat::before { background: var(--heat); }
.step-chip .h.cool::before { background: var(--cool); }
.icon-btn {
  border: 1px solid var(--axis); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 6px 14px; font: inherit; font-size: 0.85rem; cursor: pointer;
}
.icon-btn:disabled { opacity: 0.4; cursor: default; }
.editor {
  grid-column: 1 / -1; display: grid; gap: 10px; padding: 14px; margin-top: 4px;
  border: 1px solid var(--grid); border-radius: 16px; background: var(--page);
}
.ed-grid { display: grid; gap: 6px 10px; align-items: center; }
.ed-grid.cols-1 { grid-template-columns: minmax(110px, 140px) minmax(70px, 90px) 36px; }
.ed-grid.cols-2 { grid-template-columns: minmax(110px, 140px) minmax(64px, 84px) minmax(64px, 84px) 36px; }
.ed-grid .hd { font-size: 0.8rem; color: var(--text-2); }
.ed-grid input {
  font: inherit; font-variant-numeric: tabular-nums; padding: 6px 8px; border-radius: 8px;
  border: 1px solid var(--axis); background: var(--surface); color: var(--text); width: 100%; min-width: 0;
}
.ed-grid .rm { width: 32px; height: 32px; padding: 0; }
.apply { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.apply .lbl { color: var(--text-2); font-size: 0.85rem; margin-right: 4px; }
.apply button {
  width: 38px; height: 34px; border-radius: 8px; border: 1px solid var(--axis);
  background: var(--surface); color: var(--text); font: inherit; font-size: 0.85rem; cursor: pointer;
}
.apply button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.ed-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-primary {
  font: inherit; padding: 8px 18px; border: 0; border-radius: 999px; background: var(--accent); color: #fff; cursor: pointer;
}
.btn-primary:disabled { opacity: 0.35; cursor: default; }

/* ---------- hold until ---------- */
.hold-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 10px; }
.app-hold { font-weight: 600; font-size: 0.95rem; }
.app-hold.warn { color: var(--danger); }
.hold-panel { max-width: 420px; width: 100%; }
.hp-grid { display: grid; grid-template-columns: auto 1fr; gap: 8px 12px; align-items: center; }
.hp-grid label { color: var(--text-2); font-size: 0.9rem; }
.hp-when { display: flex; gap: 8px; flex-wrap: wrap; }
.hp-temp { display: flex; align-items: center; gap: 6px; }
.hp-grid input {
  font: inherit; font-variant-numeric: tabular-nums; padding: 6px 8px; border-radius: 8px;
  border: 1px solid var(--axis); background: var(--surface); color: var(--text); min-width: 0;
}
.hp-temp input { width: 84px; }
.hp-temp .unit { color: var(--text-2); }
