:root {
  --bg: #eef1f2; --panel: #fbfcfc; --ink: #17232b; --muted: #5d6e78; --line: #cfd8dc;
  --heat: #a8321f; --cool: #1f5f8b; --ok: #2f6b4f; --warn: #8a5a00; --focus: #1f5f8b;
  --font: "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11181d; --panel: #19232a; --ink: #e4eaed; --muted: #92a4ae; --line: #2b3943;
    --heat: #ff8a73; --cool: #7fc0ea; --ok: #7fd0a4; --warn: #e8b84a; --focus: #7fc0ea;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 var(--font); }
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }

/* top bar */
.bar { display: flex; align-items: center; gap: 1.25rem; padding: .6rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.bar h1 { font-size: 1.1rem; font-weight: 700; letter-spacing: .02em; }
.bar nav { display: flex; gap: .25rem; }
.bar nav a { padding: .35rem .8rem; border-radius: 6px; color: var(--muted); text-decoration: none; }
.bar nav a[aria-current="page"] { background: var(--bg); color: var(--ink); font-weight: 600; }
.bar-actions { margin-left: auto; display: flex; gap: .5rem; align-items: center; }
.bar-actions form { margin: 0; }
button { padding: .4rem .9rem; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--cool); border-color: var(--cool); color: #fff; font-weight: 600; }
@media (prefers-color-scheme: dark) { button.primary { color: #0b1620; } }

/* progress */
.progress { padding: .6rem 1rem .5rem; background: var(--panel); border-bottom: 1px solid var(--line); }
.progress[hidden] { display: none; }
.progress-track { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
#progress-fill { height: 100%; width: 0; background: var(--cool); transition: width .25s ease; }
#progress-label { margin-top: .3rem; font-size: .85rem; color: var(--muted); }
.progress.failed #progress-fill { background: var(--heat); }

main#view { max-width: 62rem; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.meta { color: var(--muted); font-size: .9rem; margin-bottom: 1rem; }
.notice { padding: .8rem 1rem; border: 1px solid var(--line); border-left: 4px solid var(--heat); background: var(--panel); border-radius: 6px; margin-bottom: 1rem; }
.notice.good { border-left-color: var(--ok); }
.notice.warn { border-left-color: var(--warn); }

/* status */
.zones { display: grid; grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr)); gap: 1rem; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 1.1rem 1.2rem; }
.panel h2 { font-size: .95rem; font-weight: 600; color: var(--muted); }
.reading { font-size: 3.6rem; font-weight: 300; line-height: 1.1; margin: .2rem 0 .9rem; }
.band { position: relative; height: 10px; margin: 0 0 .35rem; border-radius: 5px; background: var(--line); }
.band .range { position: absolute; top: 0; bottom: 0; border-radius: 5px; background: linear-gradient(90deg, var(--heat), var(--cool)); opacity: .55; }
.band .mark { position: absolute; top: -4px; width: 4px; height: 18px; margin-left: -2px; border-radius: 2px; background: var(--ink); }
.band-legend { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); margin-bottom: 1rem; }
.heat { color: var(--heat); } .cool { color: var(--cool); }
dl { display: grid; grid-template-columns: 1fr auto; gap: .35rem 1rem; margin: 0; }
dt { color: var(--muted); } dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* status: top strip, humidity, lower panels */
.top { display: grid; grid-template-columns: 3fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.zones { margin-bottom: 1rem; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr)); gap: .6rem 1.5rem; margin-top: .5rem; }
.fact { display: flex; flex-direction: column; }
.fact .k { color: var(--muted); font-size: .85rem; }
.fact .v { font-size: 1.6rem; font-weight: 400; line-height: 1.25; }
.humidity { margin-bottom: 1rem; }
.band .fill { position: absolute; top: 0; bottom: 0; left: 0; border-radius: 5px; background: var(--cool); opacity: .4; }
.band .mark.target { width: 12px; margin-left: -6px; background: transparent; border: 2px solid var(--cool); box-sizing: border-box; }
.band-scale { display: flex; justify-content: space-between; font-size: .75rem; color: var(--muted); margin-top: .35rem; }
.band-legend span { display: inline-flex; align-items: center; gap: .4rem; }
.sw { display: inline-block; width: 10px; height: 14px; border-radius: 2px; }
.sw.now { background: var(--ink); width: 4px; }
.sw.tgt { border: 2px solid var(--cool); box-sizing: border-box; }
.state { display: inline-flex; align-items: center; gap: .55rem; margin-top: .9rem; padding: .35rem .8rem; border: 1px solid var(--line); border-radius: 999px; font-weight: 600; }
.state .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.state.on { border-color: var(--ok); color: var(--ok); }
.state.on .dot { background: var(--ok); }
@media (max-width: 40rem) { .top { grid-template-columns: 1fr; } }

/* program */
.savebar { position: sticky; top: 0; z-index: 2; display: flex; gap: .75rem; align-items: center; padding: .6rem 0; background: var(--bg); }
.savebar .count { color: var(--muted); }
.day { margin-bottom: 1.1rem; }
.day h3 { font-size: 1rem; margin-bottom: .4rem; }
.table-wrap { overflow-x: auto; }
table.prog { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
table.prog th, table.prog td { padding: .35rem .5rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.prog thead th { font-size: .85rem; font-weight: 600; color: var(--muted); }
table.prog th.zh { text-align: center; }
table.prog td.temp { text-align: center; }
table.prog td.t-heat input { color: var(--heat); } table.prog td.t-cool input { color: var(--cool); }
table.prog input[type=number] { width: 4.2rem; padding: .25rem; text-align: center; background: transparent; border: 1px solid var(--line); border-radius: 5px; }
table.prog select { padding: .25rem; background: var(--panel); border: 1px solid var(--line); border-radius: 5px; }
.changed { background: color-mix(in srgb, var(--warn) 18%, transparent); }
.differs { display: block; font-size: .75rem; color: var(--warn); }

/* login */
body.login { display: grid; place-items: center; min-height: 100vh; }
.login-box { width: min(21rem, 92vw); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 1.5rem; }
.login-box h1 { font-size: 1.3rem; margin-bottom: 1rem; }
.login-box label { display: block; margin-bottom: .8rem; color: var(--muted); font-size: .9rem; }
.login-box input { display: block; width: 100%; margin-top: .25rem; padding: .5rem; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; color: var(--ink); }
.login-box button { width: 100%; padding: .55rem; }
.form-error { color: var(--heat); margin-bottom: .8rem; }

@media (prefers-reduced-motion: reduce) { #progress-fill { transition: none; } }
