:root {
  --bg: #f4f6fa; --card: #ffffff; --text: #111827; --muted: #6b7280; --line: #e5e7eb;
  --accent: #ea580c; --accent-text: #ffffff; --ok: #16a34a; --warn: #d97706; --bad: #dc2626;
  --chip: #eef1f6; --chip-on: #111827; --chip-on-text: #ffffff; --cold: #2563eb;
  --radius: 18px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1624; --card: #182234; --text: #f3f4f6; --muted: #9aa4b5; --line: #263248;
    --accent: #fb923c; --accent-text: #1a1206; --chip: #223049; --chip-on: #f3f4f6; --chip-on-text: #0f1624;
    --cold: #60a5fa;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.center { text-align: center; }
.pad { padding: 20px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wrap { max-width: 640px; margin: 0 auto; padding: 12px 14px 40px; }

/* header */
.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 2px 12px; }
.topbar h1 { font-size: 22px; flex: 1; }
.topbar .sub { font-size: 13px; color: var(--muted); font-weight: 400; display: block; }
.icon-btn {
  min-width: 48px; min-height: 48px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-size: 20px; cursor: pointer; display: inline-flex;
  align-items: center; justify-content: center; text-decoration: none;
}
.icon-btn:active { transform: scale(.96); }
.icon-btn.spin { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* cards & controls */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 10px; font-weight: 600; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.chip, .btn {
  min-height: 48px; border-radius: 14px; border: 1px solid var(--line); background: var(--chip); color: var(--text);
  font: inherit; font-weight: 600; padding: 8px 12px; cursor: pointer;
}
.chip[aria-pressed="true"], .btn.primary { background: var(--chip-on); color: var(--chip-on-text); border-color: transparent; }
.btn.primary.accent { background: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--bad); }
.btn.big { min-height: 54px; width: 100%; font-size: 17px; }
.btn:disabled, .chip:disabled { opacity: .5; cursor: default; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips .chip { flex: 1 1 auto; min-height: 44px; }
select {
  width: 100%; min-height: 48px; border-radius: 14px; border: 1px solid var(--line); background: var(--chip);
  color: var(--text); font: inherit; padding: 0 12px;
}
.hold { margin-top: 12px; }
.hold label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 6px; }

/* room */
.room-head { display: flex; align-items: flex-start; gap: 8px; }
.room-head h3 { font-size: 20px; flex: 1; word-break: break-word; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.badge { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--chip); color: var(--muted); font-weight: 600; white-space: nowrap; }
.badge.heat { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent); }
.badge.warn { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--warn); }
.badge.bad { background: color-mix(in srgb, var(--bad) 20%, transparent); color: var(--bad); }
.measured { font-size: 15px; color: var(--muted); margin: 4px 0 8px; }
.measured b { color: var(--text); font-size: 17px; }
.setter { display: grid; grid-template-columns: 76px 1fr 76px; align-items: center; gap: 10px; margin: 6px 0 12px; }
.setter .step { min-height: 76px; border-radius: 22px; font-size: 38px; font-weight: 500; line-height: 1; }
.target { text-align: center; }
.target .val { font-size: 46px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.target .val small { font-size: 22px; font-weight: 600; color: var(--muted); }
.target .lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.target.pending .val { color: var(--accent); }
.meta { font-size: 13px; color: var(--muted); margin-top: 10px; }
.row-actions { display: flex; gap: 8px; margin-top: 10px; }
.row-actions .btn { flex: 1; }
details.devices { margin-top: 10px; font-size: 14px; }
details.devices summary { cursor: pointer; color: var(--muted); min-height: 32px; display: flex; align-items: center; }
.dev { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.dev:first-of-type { margin-top: 6px; }

/* notices */
.notice { border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; border: 1px solid var(--line); background: var(--card); }
.notice.warn { border-color: var(--warn); }
.notice.bad { border-color: var(--bad); }
.notice h2 { font-size: 17px; margin-bottom: 4px; }
.notice p { margin: 4px 0 10px; }
.notice .btn { width: 100%; text-decoration: none; display: flex; align-items: center; justify-content: center; }
.updated { text-align: center; font-size: 13px; color: var(--muted); margin: 6px 0 0; }
#toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--chip-on); color: var(--chip-on-text); padding: 12px 18px; border-radius: 14px; opacity: 0;
  pointer-events: none; transition: .2s; max-width: 90vw; font-weight: 600; z-index: 10; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--bad); color: #fff; }

/* settings */
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.kv:first-of-type { border-top: 0; }
.stack > * + * { margin-top: 10px; }

/* login */
body.login { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line); border-radius: 24px; padding: 28px 22px; text-align: center; }
.login-card h1 { font-size: 26px; margin: 10px 0 4px; }
.login-logo { border-radius: 18px; }
.login-card form { margin-top: 18px; display: grid; gap: 12px; }
.login-card input {
  width: 100%; min-height: 54px; border-radius: 14px; border: 1px solid var(--line); background: var(--chip);
  color: var(--text); font: inherit; font-size: 17px; padding: 0 14px;
}
.form-error { color: var(--bad); font-weight: 600; margin: 14px 0 0; }

/* outside temperature */
.outside { display: flex; align-items: baseline; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 14px; }
.outside .o-lbl { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.outside b { font-size: 26px; font-variant-numeric: tabular-nums; }
.outside .o-src { margin-left: auto; font-size: 12px; color: var(--muted); }
.linkbtn { display: flex; align-items: center; justify-content: center; text-decoration: none; margin-top: 12px; }

/* schedule editor */
.small { font-size: 13px; }
.card.schedbtn { display: block; width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer; }
.sb-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 19px; margin-bottom: 4px; }
.mini { display: grid; gap: 3px; margin-top: 10px; }
.daybar { display: flex; height: 22px; border-radius: 7px; overflow: hidden; background: var(--chip); flex: 1; }
.daybar.big { height: 34px; margin-bottom: 12px; }
.daybar.mini { height: 8px; border-radius: 4px; flex: none; }
.seg { display: block; height: 100%; }
.zc0 { background: #ea580c; } .zc1 { background: #2563eb; } .zc2 { background: #16a34a; } .zc3 { background: #9333ea; }
.zc4 { background: #0891b2; } .zc5 { background: #ca8a04; } .zc6 { background: #db2777; } .zc7 { background: #64748b; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; flex: none; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 10px; font-size: 14px; }
.lg { display: inline-flex; align-items: center; }
.weekrows { display: grid; gap: 6px; }
.dayrow { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 6px 8px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; cursor: pointer; }
.dayrow.on { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }
.dayrow .dn { width: 34px; font-weight: 700; text-align: left; }
.hours { display: flex; justify-content: space-between; margin: 4px 0 0 44px; font-size: 11px; color: var(--muted); }
.slot { border-top: 1px solid var(--line); padding: 12px 0; }
.slot:first-of-type { border-top: 0; }
.slot-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.fixedtime { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.fixedtime small { font-size: 13px; font-weight: 400; color: var(--muted); }
.timesel { display: flex; align-items: center; gap: 6px; }
.timesel select { width: 84px; min-height: 52px; font-size: 20px; font-weight: 700; text-align: center; }
.timesel .colon { font-size: 22px; font-weight: 700; }
.btn.x { min-width: 52px; color: var(--bad); }
.zchip { display: inline-flex; align-items: center; justify-content: center; min-height: 52px !important; }
.zchip[aria-pressed="true"] .dot { box-shadow: 0 0 0 2px var(--chip-on-text); }
.copybox { margin-top: 12px; display: grid; gap: 10px; padding: 12px; border-radius: 14px; background: var(--chip); }
.dayedit .btn.big { margin-top: 12px; }
.zone { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }
.zone:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.zhead { font-size: 18px; display: flex; align-items: center; margin-bottom: 6px; }
.trow { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; }
.trow.all { opacity: .9; }
.tlabel { flex: 1; min-width: 0; word-break: break-word; font-weight: 600; }
.tstep { display: grid; grid-template-columns: 56px 76px 56px; align-items: center; gap: 6px; }
.tstep .step { min-height: 56px; font-size: 28px; border-radius: 16px; padding: 0; }
.tval { text-align: center; font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tval small { font-size: 14px; color: var(--muted); }
.tval.muted { font-size: 15px; font-weight: 600; }
input.txt { width: 100%; min-height: 52px; border-radius: 14px; border: 1px solid var(--line); background: var(--chip); color: var(--text); font: inherit; font-size: 18px; padding: 0 14px; }
.versions summary { cursor: pointer; font-weight: 700; min-height: 40px; display: flex; align-items: center; }
.ver { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.barspace { height: 90px; }
.savebar { position: fixed; left: 0; right: 0; bottom: 0; display: none; gap: 10px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); z-index: 5; max-width: 640px; margin: 0 auto; }
.savebar.show { display: flex; }
.savebar .btn { margin: 0; }
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.sheet { background: var(--card); width: 100%; max-width: 640px; max-height: 90vh; overflow: auto; border-radius: 22px 22px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); }
.sheet h2 { font-size: 20px; text-transform: none; letter-spacing: 0; color: var(--text); }
.changes { margin: 8px 0; padding-left: 20px; font-size: 15px; }
.changes li { margin: 3px 0; }

/* keep focused/scrolled-to controls clear of the fixed save bar */
html { scroll-padding-bottom: 120px; }
