:root {
  --bg: #f4f1ea; --card: #ffffff; --ink: #1f2a24; --muted: #5f6661; --line: #e4ded2; --soft: #efeae0;
  --accent: #2f6f4f; --accent-soft: #e6f0ea; --on: #f2b84b; --on-ink: #3b2a05;
  --danger: #b3412f; --danger-soft: #fbe3dd; --cold: #2b6cb0; --cold-soft: #eaf1f9; --warm: #c2611f; --warm-soft: #fbeadf;
  --radius: 18px;
}
:root[data-theme="dark"] { --bg: #141a17; --card: #1f2723; --ink: #eef0ec; --muted: #a3aca6; --line: #2f3833; --soft: #28302c;
          --accent: #6fbf94; --accent-soft: #1f3a2c; --danger: #ef8a78; --danger-soft: #3a2420;
          --cold: #8ab8ee; --cold-soft: #1e2a3a; --warm: #f0a06a; --warm-soft: #3a2a1e; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #141a17; --card: #1f2723; --ink: #eef0ec; --muted: #a3aca6; --line: #2f3833; --soft: #28302c;
          --accent: #6fbf94; --accent-soft: #1f3a2c; --danger: #ef8a78; --danger-soft: #3a2420;
          --cold: #8ab8ee; --cold-soft: #1e2a3a; --warm: #f0a06a; --warm-soft: #3a2a1e; }
}
:root { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { color-scheme: dark; } }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 16px/1.4 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
#app { max-width: 560px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
.screen { flex: 1; padding: calc(20px + env(safe-area-inset-top)) 20px 24px; display: flex; flex-direction: column; gap: 22px; }
.with-tabs { padding-bottom: 110px; }
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.top-sub { display: flex; align-items: center; gap: 6px; margin: 0 -8px; }
.hello { font-size: 14px; color: var(--muted); }
h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.top-sub h1 { font-size: 20px; flex: 1; }
.top-sub .sub { font-size: 13px; color: var(--muted); }
h2.label { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.section { display: flex; flex-direction: column; gap: 12px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.grid6 { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.strong { font-weight: 600; }
.note { font-size: 13px; color: var(--muted); line-height: 1.45; margin: 0; }
.error { color: var(--danger); font-size: 14px; min-height: 1.2em; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.card.tile { min-height: 124px; }
.card.is-on { background: var(--on); border-color: var(--on); color: var(--on-ink); }
.card.is-on .muted { color: var(--on-ink); opacity: .8; }
.card.offline { opacity: .5; }
.card.busy { opacity: .7; }
.card.big { padding: 16px; gap: 14px; }
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 0 14px; }
.list > * + * { border-top: 1px solid var(--soft); }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 0; min-height: 56px; }
.item .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.item .title { font-size: 15px; font-weight: 600; }

.icon-dot { width: 38px; height: 38px; border-radius: 19px; background: var(--soft); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.card.is-on .icon-dot { background: rgba(255,255,255,.55); }
.icon-dot.red { background: var(--danger-soft); color: var(--danger); }
.icon-dot.warm { background: var(--warm-soft); color: var(--warm); }
.big-temp { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }

.btn { height: 50px; border-radius: 16px; border: 1px solid var(--line); background: var(--card); padding: 0 18px; font-weight: 600; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme="dark"] .btn.primary { color: #0d1a13; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #0d1a13; } }
.btn.danger { color: var(--danger); }
.btn.dashed { border: 1.5px dashed #b9b2a4; background: transparent; color: var(--accent); }
.btn.small { height: 40px; border-radius: 12px; font-size: 14px; padding: 0 12px; }
.btn.pill { height: 44px; border-radius: 22px; }
.btn[disabled] { opacity: .5; }
.icon-btn { width: 44px; height: 44px; border-radius: 22px; border: 1px solid var(--line); background: var(--card); display: inline-flex; align-items: center; justify-content: center; position: relative; flex-shrink: 0; }
.icon-btn.plain { border: 0; background: transparent; }
.badge-dot { position: absolute; top: 6px; right: 7px; min-width: 10px; height: 10px; border-radius: 5px; background: var(--danger); border: 2px solid var(--card); }

.switch { width: 52px; height: 30px; border-radius: 15px; border: 0; padding: 3px; display: flex; background: #cfc8ba; flex-shrink: 0; transition: background .15s; }
.switch::after { content: ""; width: 24px; height: 24px; border-radius: 12px; background: #fff; transition: transform .15s; }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(22px); }
.card.is-on .switch[aria-checked="true"] { background: var(--on-ink); }

.chip { white-space: nowrap; padding: 0; height: 34px; border-radius: 10px; border: 1px solid rgba(59,42,5,.18); background: rgba(255,255,255,.6); font-weight: 600; font-size: 12px; }
.chip.sel { background: var(--on-ink); color: #fff; border-color: var(--on-ink); }
.card:not(.is-on) .chip { border-color: var(--line); background: var(--card); }
.card:not(.is-on) .chip.sel { background: var(--ink); color: var(--card); }
.filter { height: 34px; padding: 0 14px; border-radius: 17px; border: 1px solid var(--line); background: var(--card); font-size: 13px; font-weight: 500; }
.filter.sel { background: var(--ink); color: var(--card); border-color: var(--ink); font-weight: 600; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); background: var(--soft); border-radius: 14px; padding: 4px; }
.seg button { height: 38px; border: 0; border-radius: 11px; background: transparent; color: var(--muted); font-weight: 600; font-size: 14px; }
.seg button.sel { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.06); }
input[type=range] { width: 100%; margin: 0; accent-color: var(--on-ink); height: 28px; }
.card:not(.is-on) input[type=range] { accent-color: var(--accent); }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.input, select.input { height: 50px; border-radius: 14px; border: 1px solid #d6d0c4; background: var(--card); padding: 0 14px; font-size: 16px; font-weight: 400; width: 100%; }
select.input { padding: 0 10px; font-weight: 600; font-size: 15px; }
.input.compact { height: 42px; border-radius: 10px; font-size: 15px; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; min-height: 44px; font-weight: 400; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 8px 8px calc(10px + env(safe-area-inset-bottom)); z-index: 5; }
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 0; font-size: 12px; color: var(--muted); position: relative; }
.tabbar a.active { color: var(--accent); font-weight: 600; }
.tabbar-inner { max-width: 560px; margin: 0 auto; }

.panel { border-radius: 24px; padding: 24px 20px; display: flex; flex-direction: column; align-items: center; gap: 16px; background: var(--card); border: 1px solid var(--line); }
.panel.is-on { background: var(--on); color: var(--on-ink); border-color: var(--on); }
.panel .pct { font-size: 64px; font-weight: 700; letter-spacing: -0.04em; line-height: 1; }
.power { height: 48px; padding: 0 22px; border-radius: 24px; border: 0; display: flex; align-items: center; gap: 8px; font-weight: 600; background: var(--accent); color: #fff; }
.panel.is-on .power { background: var(--on-ink); }

.tag { align-self: flex-start; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: var(--soft); color: var(--muted); }
.tag.person { background: var(--accent-soft); color: var(--accent); }
.tag.auto { background: var(--warm-soft); color: var(--warm); }
.tag.external { background: var(--cold-soft); color: var(--cold); }
.tag.admin { background: var(--accent-soft); color: var(--accent); font-weight: 700; padding: 4px 8px; border-radius: 8px; }

.sheet-backdrop { position: fixed; inset: 0; background: rgba(20, 20, 18, .45); z-index: 10; display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; max-height: 88vh; overflow: auto; background: var(--card); border-radius: 24px 24px 0 0; padding: 10px 20px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; }
.grabber { align-self: center; width: 40px; height: 5px; border-radius: 3px; background: #d6d0c4; }
.pick { border: 1px solid var(--line); border-radius: 16px; padding: 12px; display: flex; flex-direction: column; gap: 10px; background: var(--card); text-align: left; }
.pick.sel { border: 1.5px solid var(--accent); background: var(--accent-soft); }
.tick { width: 30px; height: 30px; border-radius: 15px; border: 1.5px solid #b9b2a4; display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: transparent; }
.pick.sel .tick { background: var(--accent); border-color: var(--accent); color: #fff; }

.stepper { display: flex; align-items: center; justify-content: space-between; }
.stepper button { width: 36px; height: 36px; border-radius: 18px; border: 0; background: var(--card); font-weight: 700; font-size: 18px; }
.box-cold { border-radius: 14px; background: var(--cold-soft); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.box-warm { border-radius: 14px; background: var(--warm-soft); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.box-cold .lbl { color: var(--cold); font-size: 13px; font-weight: 600; }
.box-warm .lbl { color: var(--warm); font-size: 13px; font-weight: 600; }

.auth { max-width: 420px; margin: 0 auto; padding: 48px 24px 32px; display: flex; flex-direction: column; gap: 18px; min-height: 100vh; }
.logo { width: 88px; height: 88px; border-radius: 24px; background: #1f2a24; display: flex; align-items: center; justify-content: center; }
.url-pill { align-self: center; font-size: 12px; color: var(--muted); background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 6px 12px; }
.rule { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 400; }
.rule i { width: 16px; height: 16px; border-radius: 8px; border: 1.5px solid #b9b2a4; flex-shrink: 0; }
.rule.ok i { background: var(--accent); border-color: var(--accent); }

.toast { position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%); background: var(--ink); color: var(--card); padding: 12px 18px; border-radius: 14px; font-size: 14px; font-weight: 600; z-index: 20; max-width: 90vw; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.err { background: var(--danger); color: #fff; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.legend { display: flex; gap: 16px; font-size: 12px; flex-wrap: wrap; }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { width: 16px; height: 3px; border-radius: 2px; display: inline-block; }
.si { font-weight: 700; color: var(--accent); width: 54px; flex-shrink: 0; }
.alors { font-weight: 700; color: var(--warm); width: 54px; flex-shrink: 0; }
.rowline { display: flex; gap: 8px; font-size: 14px; }
.sr { position: absolute; left: -9999px; }
