:root {
  --bg: #f3f5f8; --panel: #fff; --text: #17212b; --muted: #6b7785; --line: #d5dbe3;
  --on: #f5b301; --ok: #2e9e5b; --warn: #e8830c; --alert: #d93636; --off: #9aa5b1; --accent: #2f7de1;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1720; --panel: #17212b; --text: #e6edf3; --muted: #8b98a6; --line: #2a3745; --off: #5d6b79; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}
header { display: flex; align-items: center; gap: 12px; max-width: 980px; margin: 0 auto; padding: 14px 0; }
h1 { font-size: 20px; margin: 0; flex: 1; }
main { max-width: 980px; margin: 0 auto; padding-bottom: 24px; }
button { font: inherit; cursor: pointer; }
.ghost { background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 8px; padding: 4px 10px; }

.status { font-size: 13px; padding: 3px 10px; border-radius: 999px; color: #fff; }
.status.ok { background: var(--ok); }
.status.warn { background: var(--warn); }
.status.off { background: var(--alert); }

.pills { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.pill { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 13px; }
.pill.alert { background: var(--alert); border-color: var(--alert); color: #fff; font-weight: 600; }
.pill.warn { border-color: var(--warn); color: var(--warn); }

.tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.tabs button { flex: 1; padding: 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--text); }
.tabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.floors { display: flex; gap: 8px; margin-bottom: 8px; }
.floors button { padding: 6px 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--text); }
.floors button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.floors button.flag:not(.active) { border-color: var(--warn); color: var(--warn); font-weight: 600; }
.room-bg.ghost { stroke-dasharray: 4 6; stroke-width: 1.5; opacity: .45; }
.room-title.ghost { opacity: .45; }
.room-bg.out { stroke-dasharray: 8 6; stroke-width: 2; }
.zone-label { fill: var(--muted); font-size: 12px; letter-spacing: .12em; text-transform: uppercase; }
.win-frame { stroke: var(--accent); stroke-width: 6; }
.win-glass { stroke: var(--panel); stroke-width: 2; }
.win-sash { stroke: var(--muted); stroke-width: 3; stroke-linecap: round; }
.door-gap { stroke: var(--panel); stroke-width: 6; }
.door-leaf { stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.door-arc { fill: none; stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; opacity: .7; }
/* состояние по датчику: красный — открыто, зелёный — закрыто, без цвета — датчика нет / нет связи */
.opening.open .win-frame, .opening.open .win-sash, .opening.open .door-leaf { stroke: var(--alert); }
.opening.open .door-arc { stroke: var(--alert); opacity: 1; }
.opening.open .door-leaf { stroke-width: 3.5; }
.opening.closed .win-frame, .opening.closed .door-leaf { stroke: var(--ok); }
.opening.closed .door-leaf { stroke-width: 3.5; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 8px 2px 0; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 18px; height: 4px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.legend .l-open { background: var(--alert); } .legend .l-closed { background: var(--ok); } .legend .l-none { background: var(--muted); }
.gate-body { stroke: var(--muted); stroke-width: 8; }
.gate-slats { stroke: var(--panel); stroke-width: 8; stroke-dasharray: 2 7; }
.gate-label { fill: var(--muted); font-size: 11px; }
.stairs { fill: none; stroke: var(--line); stroke-width: 1.5; }
.credit { margin: 6px 2px 0; font-size: 12px; color: var(--muted); }
.credit a { color: var(--muted); }
#plan { width: 100%; height: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.room-bg { fill: none; stroke: var(--muted); stroke-width: 3; }
.room-title { fill: var(--text); font-size: 15px; font-weight: 600; }
.room-clim { fill: var(--muted); font-size: 13px; }
.more { fill: var(--muted); font-size: 12px; }
.chip rect { fill: var(--bg); stroke: var(--off); stroke-width: 1.5; cursor: pointer; }
.chip.on rect { fill: color-mix(in srgb, var(--on) 30%, var(--panel)); stroke: var(--on); }
.chip.warn rect { fill: color-mix(in srgb, var(--warn) 25%, var(--panel)); stroke: var(--warn); }
.chip.alert rect { fill: var(--alert); stroke: var(--alert); }
.chip.offline rect { stroke-dasharray: 3 3; opacity: .5; }
.chip.static rect { fill: transparent; stroke: var(--muted); stroke-dasharray: 3 3; }
.chip.sel rect { stroke: var(--accent); stroke-width: 3; }
.chip text { pointer-events: none; text-anchor: middle; }
.chip .ico { font-size: 18px; }
.chip .val { font-size: 10px; fill: var(--text); }
.chip.alert .val { fill: #fff; }

.detail { margin-top: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; color: var(--muted); }
.detail b { color: var(--text); }

#tab-list h3 { margin: 16px 0 6px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.row { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin-bottom: 6px; }
.row .ico { font-size: 20px; width: 28px; text-align: center; }
.row .name { flex: 1; }
.row .ago { color: var(--muted); font-size: 12px; }
.row .state { font-weight: 600; }
.row .state.on { color: var(--on); }
.row .state.warn { color: var(--warn); }
.row .state.alert { color: var(--alert); }
.row .state.offline { color: var(--off); }

.login { position: fixed; inset: 0; background: var(--bg); display: grid; place-items: center; padding: 16px; }
.login form { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px; width: 100%; max-width: 320px; display: grid; gap: 12px; }
.login h2 { margin: 0; }
.login input { font: inherit; padding: 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.login button { padding: 10px; border-radius: 8px; border: 0; background: var(--accent); color: #fff; }
.err { color: var(--alert); margin: 0; min-height: 1.4em; }
