/* Nest Control — calm UI, dark by default. Orange = heat, blue = cool. */
/* Theme tokens. Dark is the default; <html data-theme="light"> switches to light. */
:root, [data-theme="dark"] {
  color-scheme: dark;
  --bg: #0B0F17;
  --surface: #151B26;
  --surface-2: #1B2230;
  --fill: #222A38;
  --line: #263041;
  --line-soft: #1E2633;
  --line-strong: #364154;
  --ink: #E8EDF5;
  --ink-2: #A3AEC2;
  --ink-3: #8591A7;
  --faint: #5B6780;
  --body-2: #C5CEDC;
  --accent: #60A5FA;
  --on-accent: #0B0F17;
  --seg-active: #323C50;
  --danger: #F87171;
  --danger-line: #5B2323;
  --primary-bg: #E8EDF5;
  --primary-ink: #0B0F17;
  --chip-heat-bg: #3B1F0E; --chip-heat-ink: #FDBA74;
  --chip-cool-bg: #10233F; --chip-cool-ink: #93C5FD;
  --chip-idle-bg: #0F2E1C; --chip-idle-ink: #86EFAC;
  --toast-ok-bg: #0F2E1C; --toast-ok-ink: #86EFAC;
  --toast-alert-bg: #3A1414; --toast-alert-ink: #FCA5A5;
  --ring-idle: #1F6F43; --ring-heat: #FB923C; --ring-cool: #3B82F6; --ring-off: #364154;
  --tile-heat-bg: #24170D; --tile-heat-line: #7C2D12; --tile-heat-ink: #FDBA74;
  --tile-cool-bg: #0E2233; --tile-cool-line: #0C4A6E;
  --hot: #FB923C;   --hot-ink: #1C0A02;
  --warm: #F59E0B;  --warm-ink: #1C0A02;
  --mild: #92400E;  --mild-ink: #FED7AA;
  --cool: #0C4A6E;  --cool-ink: #BAE6FD;
  --shadow: 0 12px 32px rgba(0, 0, 0, .5);
  --radius: 16px;
  --tap: 44px;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #F5F6F8;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --fill: #F1F5F9;
  --line: #E5E7EB;
  --line-soft: #F1F5F9;
  --line-strong: #CBD5E1;
  --ink: #0F172A;
  --ink-2: #475569;
  --ink-3: #64748B;
  --faint: #94A3B8;
  --body-2: #334155;
  --accent: #2563EB;
  --on-accent: #FFFFFF;
  --seg-active: #FFFFFF;
  --danger: #B91C1C;
  --danger-line: #FECACA;
  --primary-bg: #0F172A;
  --primary-ink: #FFFFFF;
  --chip-heat-bg: #FFEDD5; --chip-heat-ink: #9A3412;
  --chip-cool-bg: #DBEAFE; --chip-cool-ink: #1E40AF;
  --chip-idle-bg: #DCFCE7; --chip-idle-ink: #166534;
  --toast-ok-bg: #DCFCE7; --toast-ok-ink: #166534;
  --toast-alert-bg: #FEE2E2; --toast-alert-ink: #991B1B;
  --ring-idle: #BBF7D0; --ring-heat: #FB923C; --ring-cool: #60A5FA; --ring-off: #E2E8F0;
  --tile-heat-bg: #FFF7ED; --tile-heat-line: #FED7AA; --tile-heat-ink: #9A3412;
  --tile-cool-bg: #F0F9FF; --tile-cool-line: #BAE6FD;
  --hot: #FB923C;   --hot-ink: #431407;
  --warm: #FDBA74;  --warm-ink: #431407;
  --mild: #FED7AA;  --mild-ink: #7C2D12;
  --cool: #E0F2FE;  --cool-ink: #0C4A6E;
  --shadow: 0 12px 32px rgba(15, 23, 42, .14);
}

html {
  font-family: Inter, system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100dvh; background: var(--bg); -webkit-tap-highlight-color: transparent; }
body.has-tabs { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
h1, h2 { margin: 0; }
h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.3px; }
h2 { font-size: 16px; font-weight: 600; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
form { margin: 0; }
[hidden] { display: none !important; }

.screen { max-width: 480px; margin: 0 auto; padding: calc(24px + env(safe-area-inset-top)) 20px 28px; display: flex; flex-direction: column; gap: 16px; }
/* page wrappers (e.g. the auto-refresh container) keep the same vertical rhythm */
.screen > [data-controller~="refresh"] { display: flex; flex-direction: column; gap: 16px; }

/* text helpers */
.muted { color: var(--ink-2); }
.faint { color: var(--faint); flex-shrink: 0; }
.small { font-size: 13px; }
.strong { font-weight: 500; }
.center { text-align: center; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.link { color: var(--accent); font-size: 14px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.eyebrow { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 2px; }
.footnote { font-size: 13px; color: var(--ink-3); line-height: 1.5; margin: 0 4px; }
.empty { margin: 0; padding: 14px; text-align: center; color: var(--ink-2); font-size: 14px; line-height: 1.5; }

.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 0 4px 4px; }

/* toasts */
.toast { margin: 0; padding: 10px 14px; border-radius: 12px; font-size: 14px; }
.toast--ok { background: var(--toast-ok-bg); color: var(--toast-ok-ink); }
.toast--alert { background: var(--toast-alert-bg); color: var(--toast-alert-ink); }

/* status chips */
.chip { font-size: 13px; font-weight: 500; padding: 6px 12px; border-radius: 999px; white-space: nowrap; }
.chip--heating { background: var(--chip-heat-bg); color: var(--chip-heat-ink); }
.chip--cooling { background: var(--chip-cool-bg); color: var(--chip-cool-ink); }
.chip--idle { background: var(--chip-idle-bg); color: var(--chip-idle-ink); }
.chip--off { background: var(--fill); color: var(--ink-2); }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.card__head { display: flex; justify-content: space-between; align-items: baseline; }
.section { display: flex; flex-direction: column; gap: 10px; }
.section__title { font-size: 13px; font-weight: 500; color: var(--ink-2); margin: 8px 4px 0; }
.section > .section__title { margin-top: 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

/* dial */
.dial-card { border-radius: 24px; padding: 32px 20px 20px; align-items: center; gap: 22px; }
.dial { width: 236px; height: 236px; border-radius: 50%; border: 10px solid var(--ring-idle); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; transition: border-color .3s; }
.dial--heating { border-color: var(--ring-heat); }
.dial--cooling { border-color: var(--ring-cool); }
.dial--off { border-color: var(--ring-off); }
.dial__caption, .dial__meta { font-size: 13px; color: var(--ink-2); }
.dial__value { font-size: 72px; font-weight: 500; letter-spacing: -2px; line-height: 1; font-variant-numeric: tabular-nums; }
.stepper { display: flex; gap: 20px; }
.round-btn { width: 64px; height: 64px; border-radius: 50%; border: 1px solid var(--line-strong); background: var(--surface); font-size: 28px; line-height: 1; }
.round-btn:active { background: var(--fill); transform: scale(.97); }
.hint { margin: -10px 0 0; font-size: 13px; color: var(--ink-3); }

/* segmented control */
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; padding: 4px; border-radius: 14px; background: var(--fill); width: 100%; }
.segmented__form { display: contents; }
.segmented__btn, .segmented__choice span { display: block; width: 100%; min-height: 40px; border: none; border-radius: 10px; background: transparent; color: var(--ink-2); font-size: 14px; font-weight: 500; text-align: center; padding: 10px 0; }
.segmented__btn.is-active, .segmented__choice input:checked + span { background: var(--seg-active); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .25); }
.segmented__choice input { position: absolute; opacity: 0; pointer-events: none; }
.segmented__choice input:focus-visible + span { outline: 2px solid var(--accent); }

/* presets on home */
.preset-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.preset-tile__form { display: contents; }
.preset-tile { width: 100%; height: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; text-align: left; display: flex; flex-direction: column; gap: 2px; }
.preset-tile:active { background: var(--surface-2); }
.preset-tile__name { font-size: 14px; font-weight: 500; }
.preset-tile__temp { font-size: 13px; color: var(--ink-2); }

.row-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px; display: flex; justify-content: space-between; align-items: center; text-decoration: none; color: var(--ink); }
.row-card__body { display: flex; flex-direction: column; gap: 2px; }

/* schedule */
.day-picker { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.day-pill { height: var(--tap); border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 500; display: flex; align-items: center; justify-content: center; text-decoration: none; }
.day-pill.is-active { background: var(--primary-bg); border-color: var(--primary-bg); color: var(--primary-ink); }

.timeline { display: flex; height: 36px; border-radius: 10px; overflow: hidden; }
.timeline--empty { align-items: center; justify-content: center; background: var(--fill); color: var(--ink-3); font-size: 13px; }
.timeline__seg { display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 500; min-width: 2px; }
.timeline__ticks { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-3); }

.band--hot { background: var(--hot); color: var(--hot-ink); }
.band--warm { background: var(--warm); color: var(--warm-ink); }
.band--mild { background: var(--mild); color: var(--mild-ink); }
.band--cool { background: var(--cool); color: var(--cool-ink); }

.block-row { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); }
.block-row:active { background: var(--surface-2); }
.block-row__body { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.block-row__temp { font-size: 20px; font-weight: 500; font-variant-numeric: tabular-nums; }
.swatch { width: 10px; height: 36px; border-radius: 6px; flex-shrink: 0; }
.add-row { border: 1.5px dashed var(--line-strong); border-radius: 16px; padding: 12px; text-align: center; text-decoration: none; font-size: 15px; font-weight: 500; }

/* dropdown menus (copy / templates) */
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu[open] > summary { border-color: var(--ink-2); }
.menu__panel { position: absolute; z-index: 5; left: 0; right: 0; bottom: calc(100% + 8px); min-width: 280px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow); }
.menu:last-child .menu__panel { left: auto; }
.template-btn { width: 100%; text-align: left; background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: var(--tap); padding: 0 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 500; text-decoration: none; cursor: pointer; width: 100%; }
.btn--primary { background: var(--primary-bg); border-color: var(--primary-bg); color: var(--primary-ink); }
.btn--danger { color: var(--danger); border-color: var(--danger-line); }
.btn--small { min-height: 36px; padding: 0 14px; border-radius: 10px; border-color: var(--line-strong); width: auto; }
.btn--pill { border-radius: 999px; width: auto; min-height: 40px; }
.btn--lg { min-height: 50px; font-size: 16px; font-weight: 600; border-radius: 14px; }
.btn--block { width: 100%; }
.chip-btn { flex: 1; background: var(--fill); color: var(--ink); border: none; border-radius: 10px; padding: 9px 0; font-size: 13px; font-weight: 500; }
.quick-row { display: flex; gap: 8px; }

/* day toggles (checkbox pills) */
.day-toggles { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.day-toggle { position: relative; }
.day-toggle input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.day-toggle span[aria-hidden] { height: var(--tap); border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 14px; font-weight: 500; display: flex; align-items: center; justify-content: center; }
.day-toggle input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.day-toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.day-toggle.is-disabled span[aria-hidden] { opacity: .35; }

/* bottom-sheet editor */
.sheet { margin: -20px -20px 0; min-height: calc(100dvh - 76px); background: var(--surface); border-radius: 0 0 28px 28px; padding: 10px 20px 28px; display: flex; flex-direction: column; gap: 18px; }
.sheet__grab { align-self: center; width: 40px; height: 5px; border-radius: 3px; background: var(--line-strong); }
.sheet__bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
.sheet__title { font-size: 17px; }
.sheet__cancel { font-size: 15px; color: var(--ink-2); text-decoration: none; }
.sheet__save { justify-self: end; background: none; border: none; color: var(--accent); font-size: 15px; font-weight: 600; padding: 8px 0; }
.sheet__body { display: flex; flex-direction: column; gap: 18px; }

.field { display: flex; flex-direction: column; gap: 8px; border: none; margin: 0; padding: 0; min-width: 0; }
.field__label { font-size: 13px; color: var(--ink-2); padding: 0; }
.field__row { display: flex; justify-content: space-between; align-items: baseline; }
.input { height: 44px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--surface); padding: 0 14px; font-size: 16px; width: 100%; }
.input--lg { height: 48px; }
.input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice span { display: inline-block; border-radius: 999px; padding: 8px 14px; border: 1px solid var(--line); font-size: 14px; font-weight: 500; }
.choice input:checked + span { background: var(--primary-bg); border-color: var(--primary-bg); color: var(--primary-ink); }
.choice input:focus-visible + span { outline: 2px solid var(--accent); }

.tile { background: var(--surface-2); border: 1px solid var(--line); border-radius: 18px; padding: 14px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.tile--heat { background: var(--tile-heat-bg); border-color: var(--tile-heat-line); }
.tile--heat .field__label { color: var(--tile-heat-ink); }
.tile--cool { background: var(--tile-cool-bg); border-color: var(--tile-cool-line); }
.tile__value { font-size: 30px; font-weight: 500; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.tile__steps { display: flex; gap: 10px; }
.step-btn { width: 48px; height: var(--tap); border-radius: 12px; border: 1px solid var(--line-strong); background: var(--surface); font-size: 20px; }
.tile--heat .step-btn { border-color: var(--tile-heat-line); }
.preview { margin: 0; background: var(--surface-2); border-radius: 14px; padding: 12px 14px; font-size: 14px; color: var(--body-2); line-height: 1.5; }

/* presets list */
.preset-row { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px; display: flex; align-items: center; gap: 14px; }
.preset-row__body { flex: 1; display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: var(--ink); min-width: 0; }
.badge { width: 52px; height: 48px; border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 600; flex-shrink: 0; }
.switch-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.switch-row > span { display: flex; flex-direction: column; gap: 2px; }
.switch { appearance: none; width: 52px; height: 32px; border-radius: 999px; background: var(--line-strong); position: relative; flex-shrink: 0; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #FFFFFF; transition: transform .2s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }

/* settings */
.list-card { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 0 16px; }
.list-card > div, .list-card__row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line-soft); font-size: 15px; }
.list-card > div:last-child, .list-card > form:last-child { border-bottom: none; }
.list-card dd { margin: 0; color: var(--ink-2); text-align: right; overflow-wrap: anywhere; }
.list-card__danger { width: 100%; text-align: left; background: none; border: none; padding: 14px 0; font-size: 15px; color: var(--danger); }

/* sign in */
.signin { min-height: calc(100dvh - 44px); display: flex; flex-direction: column; gap: 24px; padding: 0 4px 20px; }
.signin__brand { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; }
.signin__brand h1 { font-size: 26px; }
.signin__brand p { margin: 0; }
.signin__mark { width: 88px; height: 88px; border-radius: 50%; border: 8px solid var(--hot); background: var(--surface); display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 600; }
.signin__form { display: flex; flex-direction: column; gap: 12px; }

/* error */
.error-state { min-height: 60dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; }
.error-state p { margin: 0; max-width: 300px; line-height: 1.5; }
.error-state .btn { width: auto; margin-top: 8px; }
.error-state__icon { width: 56px; height: 56px; border-radius: 50%; background: var(--chip-heat-bg); color: var(--chip-heat-ink); display: flex; align-items: center; justify-content: center; font-size: 26px; font-weight: 600; }

/* tab bar */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--surface); border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 8px max(0px, calc((100vw - 480px) / 2)) calc(12px + env(safe-area-inset-bottom)); }
.tab { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 0; color: var(--ink-3); font-size: 12px; text-decoration: none; }
.tab.is-active { color: var(--ink); font-weight: 600; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* theme switch in Settings */
.theme-form { display: contents; }
.segmented--compact { width: auto; display: inline-grid; padding: 3px; border-radius: 10px; }
.segmented--compact .segmented__btn { min-height: 32px; padding: 5px 14px; font-size: 13px; border-radius: 8px; }
