/* Smart Home control panel. Light and dark, graphite neutrals, deep teal accent. System fonts only. */
:root {
  --bg: #f3f5f6; --surface: #ffffff; --surface-2: #eceff1; --line: #dde2e5; --line-strong: #c7cfd4;
  --text: #13181b; --muted: #5f6b73; --faint: #8a959c;
  --accent: #0f766e; --accent-hover: #0b5f58; --accent-ink: #ffffff; --accent-soft: #d8efeb;
  --warm: #e8920a; --warm-soft: #fff1d3; --warm-ink: #6b4300;
  --cool: #2563eb; --cool-soft: #dde8fd; --hot: #e2570f; --hot-soft: #fde4d4;
  --danger: #c0262d; --danger-soft: #fbe0e1; --ok: #14804a; --ok-soft: #d9f1e3;
  --shadow: 0 1px 2px rgba(15, 25, 30, .06), 0 4px 14px rgba(15, 25, 30, .06);
  --radius: 16px; --radius-sm: 10px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0d1113; --surface: #151b1e; --surface-2: #1d2428; --line: #273036; --line-strong: #37434b;
  --text: #e7ecee; --muted: #9aa7ae; --faint: #6f7c84;
  --accent: #2fb5a5; --accent-hover: #4bc6b7; --accent-ink: #04211d; --accent-soft: #123631;
  --warm: #f5b53d; --warm-soft: #3a2c0c; --warm-ink: #ffd88a;
  --cool: #6b9bff; --cool-soft: #17274a; --hot: #ff8a4c; --hot-soft: #3b1f10;
  --danger: #ff6b70; --danger-soft: #3d1618; --ok: #46c985; --ok-soft: #12301f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 18px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1113; --surface: #151b1e; --surface-2: #1d2428; --line: #273036; --line-strong: #37434b;
    --text: #e7ecee; --muted: #9aa7ae; --faint: #6f7c84;
    --accent: #2fb5a5; --accent-hover: #4bc6b7; --accent-ink: #04211d; --accent-soft: #123631;
    --warm: #f5b53d; --warm-soft: #3a2c0c; --warm-ink: #ffd88a;
    --cool: #6b9bff; --cool-soft: #17274a; --hot: #ff8a4c; --hot-soft: #3b1f10;
    --danger: #ff6b70; --danger-soft: #3d1618; --ok: #46c985; --ok-soft: #12301f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 18px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
h2 { font-size: 18px; font-weight: 650; letter-spacing: -.01em; }
h3 { font-size: 15px; font-weight: 650; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.boot { padding: 40px; text-align: center; color: var(--muted); }
.mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack.tight { gap: 8px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.hide { display: none !important; }

/* ---- shell ---- */
.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.side { position: sticky; top: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column; gap: 4px; padding: 18px 12px; background: var(--surface); border-right: 1px solid var(--line); overflow: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; font-weight: 700; font-size: 16px; }
.brand .logo { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.nav { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 11px; color: var(--muted); text-decoration: none; font-weight: 550; border: 0; background: none; text-align: left; width: 100%; }
.nav:hover { background: var(--surface-2); color: var(--text); }
.nav[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav .badge { margin-left: auto; }
.side .spacer { flex: 1; }
.main { min-width: 0; padding: 22px clamp(14px, 3vw, 36px) 60px; max-width: 1240px; width: 100%; margin: 0 auto; }
.top { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.top h1 { margin-right: auto; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.pill.ok .dot { background: var(--ok); } .pill.ok { color: var(--ok); }
.pill.bad .dot { background: var(--danger); } .pill.bad { color: var(--danger); }
.pill.warn .dot { background: var(--warm); } .pill.warn { color: var(--warm); }
.tabbar { display: none; }
.badge { display: inline-block; min-width: 20px; padding: 1px 7px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700; text-align: center; }
.badge.soft { background: var(--surface-2); color: var(--muted); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .main { padding: 16px 16px calc(92px + env(safe-area-inset-bottom)); }
  h1 { font-size: 21px; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(14px); border-top: 1px solid var(--line); }
  .tab { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 7px 2px; border: 0; background: none; color: var(--muted); font-size: 11.5px; font-weight: 600; text-decoration: none; border-radius: 10px; }
  .tab[aria-current="page"] { color: var(--accent); }
}

/* ---- surfaces ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card.flat { box-shadow: none; }
.card.pad0 { padding: 0; overflow: hidden; }
.section { margin-top: 26px; }
.section > .head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.section > .head h2 { margin-right: auto; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.grid.wide { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.list > * + * { border-top: 1px solid var(--line); }
.item { display: flex; align-items: center; gap: 12px; padding: 13px 16px; min-height: 56px; }
button.item, a.item { width: 100%; background: none; border: 0; text-align: left; color: inherit; text-decoration: none; }
button.item:hover, a.item:hover { background: var(--surface-2); }
.item .ico { width: 38px; height: 38px; border-radius: 11px; background: var(--surface-2); color: var(--muted); display: grid; place-items: center; flex: none; }
.item .title { font-weight: 600; }
.item .sub { color: var(--muted); font-size: 13px; }

/* ---- tiles ---- */
.tile { position: relative; display: flex; flex-direction: column; justify-content: space-between; gap: 18px; min-height: 108px; padding: 14px; text-align: left; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); transition: background .15s, border-color .15s, transform .08s; user-select: none; }
.tile:active { transform: scale(.98); }
.tile .ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); transition: inherit; }
.tile .name { font-weight: 650; line-height: 1.2; overflow-wrap: anywhere; }
.tile .state { color: var(--muted); font-size: 13px; margin-top: 2px; }
.tile .top-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.tile .more { border: 0; background: none; color: var(--faint); padding: 4px; border-radius: 8px; }
.tile .more:hover { background: var(--surface-2); color: var(--text); }
.tile.on { background: var(--accent-soft); border-color: transparent; }
.tile.on .ico { background: var(--accent); color: var(--accent-ink); }
.tile.t-light.on { background: var(--warm-soft); } .tile.t-light.on .ico { background: var(--warm); color: #2b1a00; } .tile.t-light.on .state { color: var(--warm-ink); }
.tile.cool.on { background: var(--cool-soft); } .tile.cool.on .ico { background: var(--cool); color: #fff; }
.tile.heat.on { background: var(--hot-soft); } .tile.heat.on .ico { background: var(--hot); color: #fff; }
.tile.unsafe .ico { background: var(--danger-soft); color: var(--danger); }
.tile.off-line { opacity: .55; }
.tile.busy { opacity: .7; pointer-events: none; }
.tile .level { position: absolute; left: 14px; right: 14px; bottom: 8px; height: 3px; border-radius: 3px; background: color-mix(in srgb, var(--warm) 25%, transparent); overflow: hidden; }
.tile .level > i { display: block; height: 100%; background: var(--warm); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 7px; padding: 8px 13px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-weight: 600; font-size: 13.5px; color: var(--text); }
button.chip:hover { border-color: var(--line-strong); background: var(--surface-2); }
.chip.on { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.chip .muted { font-weight: 500; }

/* ---- controls ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 8px 16px; border-radius: 11px; border: 1px solid var(--line-strong); background: var(--surface); font-weight: 600; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
a.btn, a.tab, a.nav, a.item, a.chip { text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: none; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { min-height: 34px; padding: 5px 12px; font-size: 13.5px; border-radius: 9px; }
.btn[disabled], button[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; border: 0; background: none; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.input, textarea.input, select.input { width: 100%; min-height: 42px; padding: 9px 12px; border-radius: 11px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); }
textarea.input { min-height: 84px; resize: vertical; }
.input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field .label { font-size: 13px; font-weight: 650; color: var(--muted); }
.field .hint { font-size: 12.5px; color: var(--faint); }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.switch { position: relative; width: 46px; height: 28px; border-radius: 999px; border: 0; background: var(--line-strong); flex: none; transition: background .15s; padding: 0; }
.switch .knob { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s; }
.switch.on { background: var(--accent); }
.switch.on .knob { transform: translateX(18px); }
.seg { display: inline-flex; padding: 3px; border-radius: 12px; background: var(--surface-2); gap: 2px; flex-wrap: wrap; }
.seg button { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; padding: 7px 13px; border-radius: 9px; font-weight: 600; font-size: 13.5px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper .step-val { min-width: 64px; text-align: center; font-size: 28px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--accent); height: 32px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--surface); font-weight: 550; font-size: 13.5px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.check:has(input:checked) { background: var(--accent-soft); border-color: transparent; color: var(--accent); }

/* ---- dialogs ---- */
.backdrop { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: rgba(8, 12, 14, .55); backdrop-filter: blur(3px); animation: fade .15s; }
.sheet { width: min(480px, 100%); max-height: min(88vh, 900px); display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.35); animation: pop .18s; }
.sheet.wide { width: min(760px, 100%); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 12px 8px 20px; }
.sheet-body { padding: 8px 20px 20px; overflow: auto; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 20px 18px; border-top: 1px solid var(--line); }
@media (max-width: 640px) {
  .backdrop { align-items: end; padding: 0; }
  .sheet, .sheet.wide { width: 100%; max-height: 92dvh; border-radius: 22px 22px 0 0; animation: rise .22s; padding-bottom: env(safe-area-inset-bottom); }
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.97); } }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.toasts { position: fixed; z-index: 80; left: 50%; transform: translateX(-50%); bottom: calc(90px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; align-items: center; width: min(92vw, 460px); pointer-events: none; }
@media (min-width: 861px) { .toasts { bottom: 24px; } }
.toast { pointer-events: auto; padding: 11px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-weight: 550; font-size: 14px; box-shadow: var(--shadow); animation: rise .2s; max-width: 100%; }
.toast.ok { background: var(--ok); color: #fff; } .toast.bad { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; transition: opacity .25s; }

/* ---- misc ---- */
.empty { text-align: center; padding: 38px 20px; color: var(--muted); display: flex; flex-direction: column; gap: 8px; align-items: center; }
.empty h3 { color: var(--text); } .empty p { max-width: 380px; }
.empty-ico { width: 56px; height: 56px; border-radius: 18px; background: var(--surface-2); display: grid; place-items: center; color: var(--faint); }
.spin { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--line-strong); border-top-color: var(--accent); animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.banner { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; background: var(--warm-soft); color: var(--warm-ink); font-size: 14px; }
.banner.bad { background: var(--danger-soft); color: var(--danger); }
.banner.ok { background: var(--ok-soft); color: var(--ok); }
.banner.info { background: var(--cool-soft); color: var(--cool); }
.banner svg { flex: none; margin-top: 1px; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 650; background: var(--surface-2); color: var(--muted); }
.tag.ok { background: var(--ok-soft); color: var(--ok); } .tag.bad { background: var(--danger-soft); color: var(--danger); } .tag.warn { background: var(--warm-soft); color: var(--warm-ink); }
.sentence { color: var(--text); line-height: 1.6; } .sentence b { font-weight: 650; color: var(--accent); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 14px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--accent); border-color: var(--accent); }
.countdown { font-size: 54px; font-weight: 750; letter-spacing: -.03em; font-variant-numeric: tabular-nums; text-align: center; }
.pulse { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 0 var(--accent); animation: pulse 1.6s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 14px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.qr { background: #fff; padding: 12px; border-radius: 14px; width: 232px; height: 232px; margin: 0 auto; display: grid; place-items: center; }
.qr svg { width: 100%; height: 100%; }
.pin { font-family: var(--mono); font-size: 26px; font-weight: 700; letter-spacing: .08em; text-align: center; }
.builder-block { border: 1px solid var(--line); border-radius: 14px; padding: 14px; background: var(--surface-2); }
.builder-block + .builder-block { margin-top: 10px; }
.timeline { display: flex; flex-direction: column; gap: 0; }
.timeline .ev { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.timeline .ev time { color: var(--faint); min-width: 112px; font-size: 13px; }
.signin { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.signin .card { width: min(440px, 100%); padding: 28px; }
.room-title { display: flex; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.room-title h2 { margin-right: auto; }
.reading { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 13.5px; font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media print { .side, .tabbar { display: none; } }

@media (max-width: 560px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .grid.wide { grid-template-columns: 1fr; }
  .tile { min-height: 100px; padding: 12px; gap: 12px; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; } .kv dd { margin-bottom: 8px; }
  .item { padding: 12px; }
  .top { gap: 8px; }
}
