:root {
  --bg: #0b1220; --card: #141c2e; --line: #243049; --fg: #e5ecf7; --mute: #8b9bb4;
  --accent: #38bdf8; --ok: #22c55e; --warn: #f59e0b; --bad: #ef4444;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; }
body { margin: 0; touch-action: manipulation; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; background: var(--bg); color: var(--fg); font: 16px/1.4 -apple-system, system-ui, sans-serif; padding-bottom: env(safe-area-inset-bottom); }
header { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: calc(12px + env(safe-area-inset-top)) 16px 12px; background: var(--bg); border-bottom: 1px solid var(--line); }
h1 { font-size: 18px; margin: 0; }
.right { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--mute); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--bad); display: inline-block; }
.dot.on { background: var(--ok); }
button, input[type=range] { touch-action: manipulation; }
button { font: inherit; border: 0; border-radius: 10px; padding: 10px 14px; background: var(--line); color: var(--fg); cursor: pointer; }
button:active { transform: scale(0.97); }
button:disabled { opacity: .35; }
button.primary { background: var(--accent); color: #04121c; font-weight: 600; padding: 14px 22px; font-size: 17px; }
button.ghost { background: transparent; color: var(--mute); padding: 6px 8px; }
.gate { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; min-height: 60vh; padding: 24px; text-align: center; }
.err { color: var(--bad); font-size: 14px; min-height: 1.2em; }

#floors { padding: 12px 16px 32px; }
#floor-list { display: grid; gap: 20px; }
.scenes { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.scenes:empty { display: none; }
.scene { flex: 1; background: transparent; color: var(--accent); border: 2px solid var(--accent); font-weight: 600; padding: 12px 18px; font-size: 16px; border-radius: 14px; }
.scene.on { background: var(--accent); color: #04121c; }
.floor h2 { font-size: 14px; color: var(--mute); text-transform: uppercase; letter-spacing: .06em; margin: 0 0 10px; display: flex; justify-content: space-between; }
.floor .units { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; display: grid; gap: 12px; }
.card.off .body, .card.powered-off .body { opacity: .45; }
.menu { position: relative; }
.dots { background: transparent; color: var(--mute); font-size: 22px; line-height: 1; padding: 2px 6px; margin: -4px -6px -4px 0; }
.dropdown { position: absolute; right: 0; top: 100%; margin-top: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 6px; min-width: 150px; box-shadow: 0 10px 30px rgba(0,0,0,.5); z-index: 3; }
.dropdown button { display: block; width: 100%; text-align: left; background: transparent; padding: 10px 12px; border-radius: 8px; }
.dropdown button:active { background: var(--line); }
.top { display: flex; align-items: center; gap: 8px; }
.name { font-weight: 600; flex: 1; }
.chip { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--line); color: var(--mute); text-transform: uppercase; }
.chip.online { color: var(--ok); } .chip.degraded { color: var(--warn); } .chip.offline { color: var(--bad); }
.chip.error { background: var(--bad); color: #fff; }
.body { display: grid; gap: 12px; }
.readings { display: flex; gap: 14px; font-size: 13px; color: var(--mute); }
.readings b { color: var(--fg); font-weight: 500; }
.setpoint { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.setpoint .sp { font-size: 40px; font-weight: 300; letter-spacing: -.02em; min-width: 110px; text-align: center; }
.setpoint .sp small { font-size: 13px; color: var(--mute); display: block; letter-spacing: 0; }
.step { width: 56px; height: 56px; border-radius: 50%; font-size: 26px; line-height: 1; }
.fail { color: var(--bad); font-size: 12px; }
.throb { display: inline-block; width: 11px; height: 11px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; vertical-align: -2px; margin-left: 4px; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.fan label { display: flex; justify-content: space-between; font-size: 13px; color: var(--mute); margin-bottom: 4px; }
.fan label b { color: var(--fg); font-weight: 500; }
.fan input[type=range] { width: 100%; margin: 0; accent-color: var(--accent); height: 32px; }
.fan .ticks { display: flex; justify-content: space-between; font-size: 11px; color: var(--mute); padding: 0 2px; }

.power.on { background: var(--accent); color: #04121c; font-weight: 600; }
.unreach { color: var(--bad); font-size: 14px; }
.pending { opacity: .6; pointer-events: none; }
