:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #ece7dc;
  --text: #16202e;
  --muted: #5d6675;
  --line: #ddd6c7;
  --navy: #0f1b2d;
  --accent: #c8912e;
  --accent-soft: #f6e6c6;
  --on: #e9a23b;
  --hot: #d9542b;
  --ok: #2f8a5b;
  --danger: #b4372f;
  --shadow: 0 1px 2px rgba(15, 27, 45, .06), 0 8px 24px rgba(15, 27, 45, .06);
  --radius: 18px;
  --font: "Segoe UI", "Heebo", "Assistant", "Arial Hebrew", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b131f; --surface: #142133; --surface-2: #1b2b42; --text: #eef1f6; --muted: #9aa6b8;
    --line: #24364f; --accent: #e3ab4a; --accent-soft: #3a2f1c; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; -webkit-tap-highlight-color: transparent; }
body { min-height: 100dvh; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.hidden { display: none !important; }

.splash { min-height: 100dvh; display: grid; place-items: center; }
.logo-mark { width: 64px; height: 64px; border-radius: 20px; background: var(--navy) url(/icons/icon.svg) center/cover; box-shadow: var(--shadow); }

/* ---------- auth screens ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 24px; padding: 32px 24px; box-shadow: var(--shadow); text-align: center; }
.auth-card .logo-mark { margin: 0 auto 16px; }
.auth-card h1 { font-size: 26px; margin-bottom: 8px; }
.auth-card p { color: var(--muted); margin: 0 0 24px; line-height: 1.5; }
.auth-card .link { margin-top: 16px; color: var(--muted); font-size: 14px; text-decoration: underline; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 16px 0; direction: ltr; font-family: ui-monospace, Consolas, monospace; font-size: 15px; }
.codes span { background: var(--surface-2); border-radius: 10px; padding: 8px 4px; }
.field { display: block; text-align: right; margin-bottom: 16px; }
.field span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }
.check { display: flex; gap: 10px; align-items: center; justify-content: center; margin: 8px 0 16px; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px; border-radius: 14px; font-weight: 600; background: var(--surface-2); }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn.primary { background: var(--navy); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { background: var(--accent); color: #1b1407; } }
.btn.block { width: 100%; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .5; }

/* ---------- home ---------- */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; padding: 14px 16px 10px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); }
.top h1 { font-size: 24px; flex: 1; }
.top .hello { display: block; font-size: 14px; font-weight: 400; color: var(--muted); margin-top: 2px; }
.icon-btn { position: relative; width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--surface); box-shadow: var(--shadow); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn .dot { position: absolute; top: 9px; left: 10px; width: 9px; height: 9px; border-radius: 50%; background: var(--hot); }
.rooms { display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 12px; scrollbar-width: none; }
.rooms::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 8px 16px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: 15px; }
.chip[aria-pressed="true"] { background: var(--navy); color: #fff; border-color: var(--navy); }
@media (prefers-color-scheme: dark) { .chip[aria-pressed="true"] { background: var(--accent); color: #1b1407; border-color: var(--accent); } }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; padding: 0 16px 32px; }
.card { position: relative; background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; min-height: 168px; text-align: right; transition: background .25s, transform .1s; }
.card.wide { grid-column: 1 / -1; }
@media (max-width: 520px) { .grid { grid-template-columns: 1fr; } .card { min-height: 0; } }
.card:active { transform: scale(.985); }
.card.on { background: linear-gradient(160deg, var(--accent-soft), var(--surface) 70%); }
.card.offline { opacity: .6; }
.card-head { display: flex; align-items: flex-start; gap: 10px; }
.card-icon { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--surface-2); flex: none; }
.card.on .card-icon { background: var(--on); color: #fff; }
.card-icon svg { width: 24px; height: 24px; }
.card-title { flex: 1; min-width: 0; }
.card-title b { display: block; font-size: 17px; }
.card-title small { display: block; color: var(--muted); font-size: 14px; margin-top: 2px; }
.card-more { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: var(--muted); }
.card-body { display: flex; flex-direction: column; gap: 10px; margin-top: auto; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row .btn { flex: 1; min-width: 64px; }
.big-state { font-size: 28px; font-weight: 700; letter-spacing: -.5px; }
.big-state small { font-size: 15px; font-weight: 400; color: var(--muted); margin-inline-start: 6px; }

.toggle { position: relative; width: 56px; height: 32px; border-radius: 999px; background: var(--line); flex: none; transition: background .2s; }
.toggle::after { content: ""; position: absolute; top: 3px; right: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.toggle[aria-checked="true"] { background: var(--on); }
.toggle[aria-checked="true"]::after { transform: translateX(-24px); }

input[type=range] { width: 100%; accent-color: var(--accent); height: 32px; }
.range-temp { background: linear-gradient(to left, #ffb35c, #fff3e0, #cfe6ff); border-radius: 999px; height: 10px; -webkit-appearance: none; appearance: none; }
.range-temp::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; border-radius: 50%; background: #fff; border: 2px solid var(--navy); }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--line); }
.progress { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--hot); border-radius: inherit; }

.empty { text-align: center; color: var(--muted); padding: 48px 24px; line-height: 1.6; }

/* ---------- sheet ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(5, 10, 18, .45); z-index: 20; animation: fade .15s; }
.sheet { position: fixed; inset-inline: 0; bottom: 0; z-index: 21; max-height: 88dvh; overflow-y: auto; background: var(--bg); border-radius: 24px 24px 0 0; padding: 8px 16px calc(24px + env(safe-area-inset-bottom)); animation: up .2s ease-out; }
@media (min-width: 720px) { .sheet { inset-inline: auto; left: 50%; transform: translateX(-50%); width: 560px; bottom: 24px; border-radius: 24px; animation: none; } }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 6px auto 12px; }
.sheet h2 { font-size: 21px; margin-bottom: 4px; }
.sheet .sub { color: var(--muted); margin: 0 0 16px; font-size: 15px; }
.section { background: var(--surface); border-radius: 16px; padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow); }
.section h3 { font-size: 15px; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; overflow-wrap: anywhere; }
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; scrollbar-width: none; }
.days { display: flex; gap: 6px; }
.days button { width: 38px; height: 38px; border-radius: 50%; background: var(--surface-2); font-weight: 600; }
.days button[aria-pressed="true"] { background: var(--navy); color: #fff; }
@media (prefers-color-scheme: dark) { .days button[aria-pressed="true"] { background: var(--accent); color: #1b1407; } }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.bad { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.copy-box { direction: ltr; text-align: left; font-family: ui-monospace, Consolas, monospace; font-size: 13px; background: var(--surface-2); padding: 10px; border-radius: 10px; overflow-wrap: anywhere; user-select: all; }

#toast { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); inset-inline: 16px; z-index: 40; display: flex; justify-content: center; pointer-events: none; }
#toast div { background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 14px; box-shadow: var(--shadow); max-width: 420px; animation: up .2s; }
#toast div.err { background: var(--danger); }

@keyframes up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
