:root {
  --bg: #0b0e13;
  --panel: #131821;
  --panel2: #1a2130;
  --line: #263042;
  --text: #e9edf3;
  --muted: #8a96a8;
  --accent: #f5a623;
  --accent-ink: #1b1204;
  --ok: #2ecc71;
  --warn: #f39c12;
  --bad: #e74c3c;
  --cool: #4aa3ff;
  --heat: #ff6b3d;
  --radius: 16px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #eef1f5; --panel: #ffffff; --panel2: #f3f5f8; --line: #dde2ea;
    --text: #18202b; --muted: #5d6878; color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #eef1f5; --panel: #ffffff; --panel2: #f3f5f8; --line: #dde2ea;
  --text: #18202b; --muted: #5d6878; color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
}
button { font: inherit; color: inherit; cursor: pointer; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: linear-gradient(135deg, #ffbf47, #f08a00); color: var(--accent-ink); font-weight: 800; font-size: 20px;
}
.brand-name { font-weight: 800; letter-spacing: .04em; }
.brand-name span { font-weight: 500; color: var(--accent); }
.site-name { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.mode { display: flex; background: var(--panel2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.mode button { border: 0; background: transparent; padding: 6px 16px; border-radius: 999px; font-weight: 600; color: var(--muted); }
.mode button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }

.status { display: flex; align-items: center; gap: 8px; }
.pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); font-size: 13px; white-space: nowrap; }
.pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill b { font-weight: 600; }
.pill.demo i { background: var(--accent); }
.pill.ok i { background: var(--ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 25%, transparent); }
.pill.warn i { background: var(--warn); animation: blink 1s infinite; }
.pill.bad i { background: var(--bad); }
@keyframes blink { 50% { opacity: .3; } }
.icon-btn { border: 1px solid var(--line); background: var(--panel2); padding: 6px 12px; border-radius: 999px; font-size: 13px; }

.banner { margin: 12px 20px 0; padding: 10px 14px; border-radius: 12px; background: color-mix(in srgb, var(--warn) 18%, var(--panel)); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); font-size: 14px; }
.banner.bad { background: color-mix(in srgb, var(--bad) 18%, var(--panel)); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }

/* Layout */
.layout { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(340px, 1fr); gap: 18px; padding: 18px 20px 28px; max-width: 1600px; margin: 0 auto; }
.plan-card { background: #0a0c10; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; position: sticky; top: 76px; align-self: start; }
#plan { width: 100%; height: auto; display: block; aspect-ratio: 1300 / 1080; border-radius: 10px; }
.plan-hint { text-align: center; color: #8a96a8; font-size: 12px; padding: 8px 0 2px; }
.side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.block { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }

/* Plan */
.shade polygon { transition: opacity .5s ease; pointer-events: none; }
.glow { mix-blend-mode: screen; pointer-events: none; }
.glow g { transition: opacity .45s ease; }
.blinds line { transition: x2 .2s linear; pointer-events: none; }
.blind-label { fill: #fff; font-size: 22px; font-weight: 700; paint-order: stroke; stroke: #0a0c10; stroke-width: 5px; pointer-events: none; }
.room-hit { fill: transparent; stroke: transparent; stroke-width: 6; cursor: pointer; transition: stroke .2s, fill .2s; outline: none; }
.room-hit:hover, .room-hit:focus-visible { fill: rgba(245, 166, 35, .06); }
.room-hit.sel { stroke: var(--accent); fill: rgba(245, 166, 35, .08); }
.room-label { fill: #fff; font-size: 21px; font-weight: 600; paint-order: stroke; stroke: rgba(0,0,0,.65); stroke-width: 5px; pointer-events: none; letter-spacing: .02em; }
.mark { cursor: pointer; outline: none; -webkit-tap-highlight-color: transparent; }
.mark-hit { fill: transparent; }
@media (max-width: 700px) {
  .mark-bg { transform: scale(1.35); }
}
.mark-bg { fill: rgba(16, 20, 28, .82); stroke: rgba(255,255,255,.35); stroke-width: 2; transition: fill .25s, stroke .25s; }
.mark-ic { fill: none; stroke: #cfd6e0; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: stroke .25s; }
.mark:hover .mark-bg, .mark:focus-visible .mark-bg { stroke: var(--accent); stroke-width: 3; }
.mark.on .mark-bg { fill: var(--accent); stroke: #fff; }
.mark.on .mark-ic { stroke: var(--accent-ink); }
.mark-climate.on .mark-bg { fill: var(--cool); }
.mark-climate.on.heat .mark-bg { fill: var(--heat); }
.mark-climate.on .mark-ic, .mark-tv.on .mark-ic, .mark-audio.on .mark-ic { stroke: #fff; }
.mark-tv.on .mark-bg { fill: #6c5ce7; }
.mark-audio.on .mark-bg { fill: #00b894; }
.mark-blind.on .mark-bg { fill: rgba(16, 20, 28, .82); stroke: #8fd3ff; }
.mark-blind.on .mark-ic { stroke: #8fd3ff; }
.mark.moving .mark-bg { animation: pulse 1s infinite; }
.mark.ping .mark-bg { animation: ping .5s ease-out; }
@keyframes pulse { 50% { stroke: var(--accent); stroke-width: 5; } }
@keyframes ping { 0% { stroke-width: 14; stroke: var(--accent); } 100% { stroke-width: 2; } }

/* Summary */
.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; min-width: 0; }
.stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }

/* Scenes */
.scenes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.scene { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 4px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel2); font-size: 13px; font-weight: 600; transition: transform .1s, border-color .2s; }
.scene:hover { border-color: var(--accent); }
.scene:active { transform: scale(.96); }
.scene.ran { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
.scene .ic { width: 24px; height: 24px; color: var(--accent); }

.quick { display: flex; flex-direction: column; gap: 10px; }
.quick-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.quick-row > span { font-weight: 600; }
.btns { display: flex; gap: 6px; flex-wrap: wrap; }
.btn { border: 1px solid transparent; background: var(--accent); color: var(--accent-ink); padding: 8px 14px; border-radius: 11px; font-weight: 700; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; }
.btn.ghost { background: var(--panel2); color: var(--text); border-color: var(--line); }
.btn:active { transform: scale(.97); }
.btn .ic { width: 18px; height: 18px; }
.btn.sq { width: 40px; padding: 0; }
.btn.sel { border-color: var(--accent); color: var(--accent); }

/* Rooms + cards */
.rooms { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: thin; }
.rooms button { flex: none; border: 1px solid var(--line); background: var(--panel2); padding: 7px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--muted); }
.rooms button[aria-selected="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.rooms button .dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-left: 6px; vertical-align: middle; }
.cards { display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--panel2); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; transition: border-color .3s, box-shadow .3s; }
.card.hl { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.card.pending { opacity: .7; }
.card.err { border-color: var(--bad); }
.card.offline { border-style: dashed; border-color: color-mix(in srgb, var(--bad) 60%, var(--line)); }
.card.offline .card-title small::after { content: " · offline"; color: var(--bad); }
.card-head { display: flex; align-items: center; gap: 10px; }
.card-ic { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--panel); border: 1px solid var(--line); flex: none; color: var(--muted); transition: background .25s, color .25s; }
.card-ic .ic { width: 20px; height: 20px; }
.card.on .card-ic { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.card-title { flex: 1; min-width: 0; }
.card-title b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-title small { color: var(--muted); font-size: 12px; }
.card-body { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.card-body:empty { display: none; }
.row { display: flex; align-items: center; gap: 10px; }
.row .grow { flex: 1; }
.row.wrap { flex-wrap: wrap; }
.val { font-variant-numeric: tabular-nums; min-width: 44px; text-align: right; font-weight: 700; }

.switch { position: relative; width: 50px; height: 30px; border-radius: 999px; border: 0; background: var(--line); flex: none; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }

input[type="range"] { width: 100%; accent-color: var(--accent); height: 28px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.sw { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; padding: 0; }
.sw.sel { border-color: var(--text); }
input[type="color"] { width: 32px; height: 32px; border: 0; padding: 0; background: none; }

.blindbar { position: relative; height: 10px; border-radius: 6px; background: #8fd3ff; overflow: hidden; }
.blindbar i { position: absolute; inset: 0 auto 0 0; background: #2b2f36; transition: width .2s linear; }

.clim { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.clim-temp { font-size: 40px; font-weight: 300; font-variant-numeric: tabular-nums; line-height: 1; }
.clim-temp small { font-size: 14px; color: var(--muted); display: block; margin-top: 4px; }
.target { display: flex; align-items: center; gap: 8px; }
.target b { font-size: 24px; font-variant-numeric: tabular-nums; min-width: 72px; text-align: center; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { border: 1px solid var(--line); background: var(--panel); padding: 6px 10px; border-radius: 10px; font-size: 13px; font-weight: 600; display: inline-flex; gap: 6px; align-items: center; }
.seg button .ic { width: 16px; height: 16px; }
.seg button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.lbl { font-size: 12px; color: var(--muted); }
.track { font-weight: 600; }

/* Login */
dialog { border: 1px solid var(--line); border-radius: 18px; background: var(--panel); color: var(--text); padding: 22px; width: min(380px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.6); backdrop-filter: blur(3px); }
dialog h2 { font-size: 20px; text-transform: none; letter-spacing: 0; color: var(--text); margin: 0 0 4px; }
dialog label { display: block; margin-top: 12px; font-size: 13px; color: var(--muted); }
dialog input { display: block; width: 100%; margin-top: 6px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font: inherit; }
.err { color: var(--bad); font-size: 13px; margin: 10px 0 0; }
.dlg-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* Responsive */
@media (max-width: 1020px) {
  .layout { grid-template-columns: 1fr; padding: 12px 16px 24px; }
  .plan-card { position: static; }
}
@media (max-width: 560px) {
  .top { flex-wrap: wrap; padding: 10px 16px; }
  .status { order: 3; width: 100%; justify-content: space-between; }
  .summary { grid-template-columns: repeat(2, 1fr); }
  .scenes { grid-template-columns: repeat(3, 1fr); }
  .quick-row { flex-direction: column; align-items: stretch; }
  .quick-row .btns > * { flex: 1; }
  .banner { margin: 10px 16px 0; }
}
