:root {
  --bg: #0b1d24; --bg2: #102a33; --card: #13313b; --line: #1f4652; --text: #e9f3f5; --muted: #8fb0b8;
  --accent: #ffb86b; --accent2: #4fd1c5; --ok: #47d18c; --bad: #ff6b6b; --warn: #ffd166; --heat: #ff7a45;
  --power-off: #29505c;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root { --bg: #f2f7f8; --bg2: #e6eff1; --card: #ffffff; --line: #d3e2e6; --text: #12303a; --muted: #5b7a83;
          --accent: #e07a1f; --accent2: #13867c; --power-off: #c5d7dc; color-scheme: light; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.big { font-size: 22px; font-weight: 700; }

main { max-width: 560px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 84px); }
.top { display: flex; align-items: center; justify-content: space-between; padding: 6px 0 10px; }
.brand { font-weight: 800; letter-spacing: .3px; font-size: 18px; }
.badge { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 5px 10px; border-radius: 99px; background: var(--bg2); }
.badge i { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.badge.on i { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.badge.off i { background: var(--bad); }
.badge.stale i { background: var(--warn); }

.alert-bar { background: color-mix(in srgb, var(--bad) 18%, var(--card)); border: 1px solid color-mix(in srgb, var(--bad) 45%, transparent);
  border-radius: 14px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }
.alert-bar b { display: block; }
.alert-bar button { float: right; background: none; border: 0; font-size: 18px; color: var(--muted); }

.hero { text-align: center; padding: 6px 0 2px; }
.temp { font-size: 76px; font-weight: 800; line-height: 1; letter-spacing: -2px; }
.temp sup { font-size: 26px; font-weight: 600; vertical-align: top; position: relative; top: 10px; margin-left: 2px; letter-spacing: 0; }
.temp-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.target-line { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 10px; }
.target { font-size: 22px; font-weight: 700; min-width: 64px; }
.target.pending { color: var(--accent); }
.step { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--bg2); font-size: 22px; line-height: 1; }
.status-line { color: var(--muted); font-size: 14px; margin-top: 8px; min-height: 20px; }

.power-wrap { display: flex; flex-direction: column; align-items: center; margin: 18px 0 16px; }
.power { width: 156px; height: 156px; border-radius: 50%; border: 0; background: var(--power-off);
  display: grid; place-items: center; transition: background .25s, box-shadow .25s, transform .1s; position: relative; }
.power:active { transform: scale(.96); }
.power svg { width: 64px; height: 64px; fill: none; stroke: var(--text); stroke-width: 2.4; stroke-linecap: round; }
.power.on { background: radial-gradient(circle at 50% 40%, #ffcf8f, var(--accent) 60%, #d9681a);
  box-shadow: 0 0 0 8px color-mix(in srgb, var(--accent) 18%, transparent), 0 10px 40px color-mix(in srgb, var(--accent) 45%, transparent); }
.power.on svg { stroke: #3a1d05; }
.power.busy::after { content: ""; position: absolute; inset: -8px; border-radius: 50%; border: 3px solid transparent;
  border-top-color: var(--accent2); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.power-label { margin-top: 10px; font-weight: 600; }

.chips { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.chip { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 64px; }
.chip b { font-size: 14px; }
.chip span { font-size: 13px; color: var(--muted); }
.chip.on { border-color: var(--accent2); background: color-mix(in srgb, var(--accent2) 16%, var(--card)); }
.chip.on span { color: var(--accent2); }
.chip.heat { border-color: var(--heat); background: color-mix(in srgb, var(--heat) 16%, var(--card)); }
.chip.heat span { color: var(--heat); }
.chip.busy { opacity: .6; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 14px; margin-bottom: 12px; }
.card-h { font-weight: 700; margin-bottom: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--bg2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: none; padding: 9px 4px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.seg button.pending { color: var(--accent); }
.seg.small button { padding: 5px 10px; font-size: 13px; }

.btn { background: var(--accent2); color: #04201d; border: 0; border-radius: 12px; padding: 10px 16px; font-weight: 700; }
.btn.ghost { background: var(--bg2); color: var(--text); border: 1px solid var(--line); }
.btn:disabled { opacity: .5; }
input { font: inherit; color: var(--text); background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; min-width: 0; }
input.num { width: 74px; }
#readyAt { flex: 1 1 100%; }
#readyTarget { flex: 1 1 auto; width: auto; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; }
.kv:empty { display: none; }
.kv dt, .kv .k { color: var(--muted); }
.kv .v { text-align: right; }
.kv + p, .kv + .row { margin-top: 10px; }
#modeHelp { margin: 8px 0; }

.jobs, .list { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.jobs li, .list li { padding: 7px 0; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; }
.jobs li:first-child, .list li:first-child { border-top: 0; }
.jobs .st { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--bg2); white-space: nowrap; align-self: center; }
.st.confirmed { color: var(--ok); } .st.failed { color: var(--bad); } .st.pending { color: var(--warn); } .st.sent { color: var(--accent2); }
.list .t { color: var(--muted); white-space: nowrap; font-size: 12px; }
.log li { display: block; }
.log .t { display: block; }

canvas { width: 100%; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend span::before { content: ""; display: inline-block; width: 14px; height: 3px; margin-right: 5px; vertical-align: middle; border-radius: 2px; }
.l-water::before { background: var(--accent); } .l-est::before { background: repeating-linear-gradient(90deg, var(--accent) 0 4px, transparent 4px 7px); }
.l-tgt::before { background: var(--accent2); } .l-amb::before { background: #7aa7ff; } .l-heat::before { background: color-mix(in srgb, var(--heat) 35%, transparent); height: 10px; }

.form { display: grid; grid-template-columns: 1fr auto; gap: 8px 10px; align-items: center; font-size: 14px; margin-bottom: 12px; }
.form label { color: var(--text); }
.form label small { display: block; color: var(--muted); font-size: 12px; }
.form input[type=number] { width: 84px; text-align: right; }
.form .sep { grid-column: 1 / -1; font-weight: 700; margin-top: 8px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; }
.toggles { display: grid; gap: 6px; margin-top: 12px; font-size: 14px; }
.toggles label, .form label.chk { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent2); }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(3, 1fr);
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs button { background: none; border: 0; padding: 9px 0 10px; display: flex; flex-direction: column; align-items: center; font-size: 12px; color: var(--muted); }
.tabs button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; margin-bottom: 2px; }
.tabs button.on { color: var(--accent); }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 76px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100% - 32px); z-index: 5; }
dialog { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 16px; max-width: 340px; }
dialog::backdrop { background: rgba(0,0,0,.5); }

/* PIN gate */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.gate-box { width: 100%; max-width: 320px; text-align: center; }
.gate-icon { width: 72px; height: 72px; border-radius: 18px; }
.gate h1 { margin: 10px 0 4px; }
.pin-dots { display: flex; justify-content: center; gap: 16px; margin: 18px 0 6px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dots i.f { background: var(--accent); border-color: var(--accent); }
.pin-msg { min-height: 20px; color: var(--bad); font-size: 14px; }
.keypad { display: grid; grid-template-columns: repeat(3, 72px); gap: 14px; justify-content: center; margin-top: 8px; }
.keypad button { height: 72px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); font-size: 26px; }
.keypad button:disabled { opacity: .4; }

/* energy chart */
.seg.period { margin: 4px 0 10px; }
.pager { display: grid; grid-template-columns: 40px 1fr 40px; align-items: center; gap: 8px; margin-bottom: 8px; }
.pager-mid { text-align: center; }
.pager-label { font-weight: 700; }
.pager .step:disabled { opacity: .3; }
#energyChart { touch-action: pan-y; }
.e-detail { font-size: 13px; color: var(--muted); margin-top: 8px; min-height: 18px; }
.e-detail b { color: var(--text); }
.l-heat2::before { background: var(--heat); height: 10px; }
.l-other::before { background: var(--accent2); height: 10px; }
