:root {
  --bg: #070707;
  --panel: #101010;
  --card: #151515;
  --card-2: #1c1c1c;
  --line: #262626;
  --line-2: #333;
  --text: #ececec;
  --muted: #8a8a8a;
  --faint: #868686;   /* ≥4.5:1 on the page and on cards */
  --focus: #e8e8e8;
  /* z-index scale */
  --z-chart: 5; --z-nav: 20; --z-sheet: 40; --z-confirm: 50; --z-toast: 60;
  --hi: #f5f5f5;
  --danger: #e0565b;
  --ok: #55c08a;
  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.4 var(--font); }
h1, h2, h3, .name, .title { text-wrap: balance; }
p, .empty, .banner, .daystr { text-wrap: pretty; }

/* keyboard focus: always visible, never on mouse clicks */
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 8px; }
.toggle:focus-visible { border-radius: 99px; }
input[type=range]:focus-visible { outline-offset: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 12px; top: -60px; z-index: var(--z-toast); background: var(--hi); color: #0a0a0a; padding: 8px 14px; border-radius: 8px; font-weight: 600; text-decoration: none; }
.skip:focus { top: 12px; }
[role=button] { cursor: pointer; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100dvh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 22px 14px; position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; padding: 0 10px 22px; }
.brand img { border-radius: 6px; }
.nav { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--muted); border: 0; background: none; text-align: left; width: 100%; }
.nav svg { width: 19px; height: 19px; flex: none; }
.nav:hover { color: var(--text); background: #ffffff08; }
.nav.on { color: var(--hi); background: var(--card-2); }
.side-foot { margin-top: auto; padding: 10px 12px; color: var(--faint); font-size: 12px; display: grid; gap: 6px; }
.ver { background: none; border: 0; padding: 0; color: var(--faint); font-size: 12px; text-align: left; font-variant-numeric: tabular-nums; }
.ver:hover { color: var(--text); text-decoration: underline; }
main { padding: max(26px, env(safe-area-inset-top)) 32px 120px; max-width: 1240px; width: 100%; }
main:focus { outline: none; }
.top { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }
.top h1 { font-size: 24px; margin: 0; font-weight: 650; flex: 1; }
.tabbar { display: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { display: none; }
  main { padding: max(18px, env(safe-area-inset-top)) 14px calc(110px + env(safe-area-inset-bottom)); }
  .top h1 { font-size: 22px; }
  .tabbar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: #0b0b0b; border-top: 1px solid var(--line); padding: 6px max(4px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left)); z-index: var(--z-nav); }
  .tabbar .nav { flex-direction: column; gap: 3px; font-size: 11px; padding: 6px 2px; justify-content: center; text-align: center; }
  .tabbar .nav.on { background: none; }
  .tabbar .nav svg { width: 22px; height: 22px; }
}

/* ---------- common ---------- */
.btn { border: 1px solid var(--line-2); background: var(--card-2); border-radius: 10px; padding: 8px 14px; color: var(--text); display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.btn:hover { border-color: #444; background: #222; }
.btn.primary { background: var(--hi); color: #0a0a0a; border-color: var(--hi); font-weight: 600; }
.btn.primary:hover { background: #fff; }
.btn.ghost { background: none; }
.btn.danger { color: var(--danger); border-color: #4a2224; background: #1a0f10; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn svg { width: 16px; height: 16px; }
.icon-btn { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; border: 1px solid var(--line-2); background: var(--card-2); }
.icon-btn svg { width: 18px; height: 18px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.section-title { font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); margin: 30px 0 12px; display: flex; align-items: center; gap: 10px; }
.section-title:first-child { margin-top: 0; }
.section-title .line { flex: 1; height: 1px; background: var(--line); }
.empty { border: 1px dashed var(--line-2); border-radius: var(--radius); padding: 28px; text-align: center; color: var(--muted); }
.banner { border: 1px solid var(--line-2); background: var(--card); border-radius: 12px; padding: 12px 14px; margin-bottom: 18px; color: var(--muted); font-size: 14px; }
.banner b { color: var(--text); }
.pill { font-size: 11px; padding: 2px 7px; border-radius: 99px; background: #ffffff0d; color: var(--muted); border: 1px solid var(--line); text-transform: uppercase; letter-spacing: .5px; }
.pill.live { color: #fff; border-color: #ffffff30; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; align-items: start; }

/* ---------- light cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; position: relative; overflow: hidden; transition: border-color .2s; }
.card:hover { border-color: var(--line-2); }
.light .glow { position: absolute; inset: -45% -25% auto auto; width: 240px; height: 240px; background: radial-gradient(closest-side, var(--glow, transparent), transparent); opacity: 0; transition: opacity .2s ease-out; pointer-events: none; }
.light.is-on .glow { opacity: .35; }
.light .head { display: flex; align-items: center; gap: 12px; cursor: pointer; position: relative; }
.bulb { width: 42px; height: 42px; border-radius: 13px; background: #222; display: grid; place-items: center; flex: none; border: 1px solid #ffffff12; transition: background .2s ease-out; }
.bulb svg { width: 21px; height: 21px; color: #000a; }
.light:not(.is-on) .bulb svg { color: var(--faint); }
.light .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.light .meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; margin-top: 2px; }
.light .ctrl { display: flex; align-items: center; gap: 12px; margin-top: 16px; position: relative; }
.light.offline { opacity: .55; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); display: inline-block; }
.dot.off { background: var(--faint); }

/* toggle */
.toggle { width: 48px; height: 28px; border-radius: 99px; background: #2a2a2a; border: 1px solid #4a4a4a; position: relative; flex: none; padding: 0; transition: background .15s ease-out; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #8a8a8a; transition: transform .15s ease-out; }
.toggle.on { background: #e8e8e8; border-color: #e8e8e8; }
.toggle.on::after { transform: translateX(20px); background: #0b0b0b; }

/* sliders */
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 99px; background: var(--track, linear-gradient(90deg, #2a2a2a, #d8d8d8)); }
input[type=range]::-moz-range-track { height: 6px; border-radius: 99px; background: var(--track, linear-gradient(90deg, #2a2a2a, #d8d8d8)); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%; background: #f2f2f2; margin-top: -7px; border: 3px solid #0b0b0b; box-shadow: 0 0 0 1px #555; }
input[type=range]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: #f2f2f2; border: 3px solid #0b0b0b; }
input[type=range].kelvin { --track: linear-gradient(90deg, #ff9329, #ffd6aa, #fff4ea, #d6e4ff, #a9c6ff); }
.bri-val { width: 40px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }

/* swatches */
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.sw { width: 34px; height: 34px; border-radius: 10px; border: 2px solid transparent; outline: 1px solid #ffffff18; padding: 0; }
.sw.sel { border-color: #fff; }
.sw.picker { position: relative; overflow: hidden; background: conic-gradient(#f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00); }
.sw.picker input { position: absolute; inset: -10px; opacity: 0; cursor: pointer; }

/* group & scene cards */
.gcard .title { font-weight: 600; font-size: 16px; }
.gcard .dots { display: flex; gap: 4px; margin-top: 8px; flex-wrap: wrap; }
.gcard .dots span { width: 14px; height: 14px; border-radius: 5px; border: 1px solid #ffffff1a; }
.scene { cursor: pointer; padding: 0; }
.scene { position: relative; }
.scene-hit { display: block; }
.scene-edit { position: absolute; right: 10px; bottom: 8px; width: 32px; height: 32px; }
.scene .strip { height: 56px; display: flex; }
.scene .strip span { flex: 1; }
.scene .body { padding: 12px 54px 12px 14px; display: flex; align-items: center; gap: 8px; }
.scene .body .title { font-weight: 600; flex: 1; }

/* effects */
.fx { cursor: pointer; padding: 0; }
.fx .prev { height: 70px; }
.fx .body { padding: 12px 14px; }
.fx .title { font-weight: 600; }
.fx.sel { border-color: #e8e8e8; }
.active-run { display: flex; contain: layout; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line-2); border-radius: 12px; padding: 10px 14px; margin-bottom: 10px; }
.pulse { width: 10px; height: 10px; border-radius: 50%; background: #fff; animation: pulse 1.4s infinite; flex: none; }
@keyframes pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

/* chips (target picker / days) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line-2); background: var(--card-2); border-radius: 99px; padding: 6px 12px; font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 7px; }
.chip.on { background: var(--hi); color: #0a0a0a; border-color: var(--hi); font-weight: 600; }
.chip .c { width: 10px; height: 10px; border-radius: 50%; }

/* schedules */
.sched { display: flex; align-items: center; gap: 14px; }
.sched-hit { display: flex; align-items: center; gap: 14px; flex: 1; min-width: 0; }
.plug-row { display: flex; align-items: center; gap: 12px; }
.more-link { text-align: left; width: 100%; gap: 12px; }
.empty-act { margin-top: 14px; }
.cl-h { font-size: 15px; margin: 18px 0 6px; }
.cl { margin: 0; padding-left: 18px; color: var(--text); }
.cl li { margin: 4px 0; text-wrap: pretty; }
.confirm { width: min(420px, 92vw); }
.confirm h2 { font-size: 18px; margin: 0 0 8px; }
.confirm-scrim { z-index: var(--z-confirm); }
.sched .time { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -.5px; min-width: 92px; }
.sched .time small { display: block; font-size: 12px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.sched.disabled .time, .sched.disabled .grow { opacity: .45; }
.daystr { font-size: 12px; color: var(--muted); }

/* forms */
label.f { display: block; margin-bottom: 14px; }
label.f > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .8px; }
.inp, select.inp { width: 100%; background: #0c0c0c; border: 1px solid var(--line-2); border-radius: 10px; padding: 10px 12px; outline: none; }
.inp:focus { border-color: #666; }
.seg { display: inline-flex; background: #0c0c0c; border: 1px solid var(--line-2); border-radius: 10px; padding: 3px; gap: 3px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 7px 12px; border-radius: 7px; color: var(--muted); font-size: 14px; }
.seg button.on { background: #2a2a2a; color: var(--hi); }

/* sheet (modal) */
.scrim { position: fixed; inset: 0; background: #000b; z-index: var(--z-sheet); display: flex; align-items: center; justify-content: center; animation: fade .15s; }
.sheet { background: var(--panel); border: 1px solid var(--line-2); border-radius: 20px; width: min(560px, 94vw); max-height: 90vh; overflow: auto; padding: 22px; animation: rise .2s; }
.sheet h2 { margin: 0; font-size: 19px; flex: 1; }
.sheet .sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.sheet .foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
.sheet .foot .left { margin-right: auto; }
@media (max-width: 860px) {
  .scrim { align-items: flex-end; }
  .sheet { width: 100%; border-radius: 20px 20px 0 0; max-height: 92vh; padding-bottom: calc(22px + env(safe-area-inset-bottom)); }
}
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(20px); opacity: 0; } }
.scrim { animation-timing-function: ease-out; }
.sheet { animation-timing-function: ease-out; }

.big-color { height: 120px; border-radius: 16px; margin-bottom: 16px; border: 1px solid #ffffff14; position: relative; transition: background .3s; }
.big-color .toggle { position: absolute; right: 14px; bottom: 14px; }

/* music */
.meter { display: flex; gap: 6px; align-items: flex-end; height: 90px; margin: 16px 0; }
.meter div { flex: 1; height: 100%; background: #d9d9d9; border-radius: 6px 6px 2px 2px; transform-origin: bottom; transform: scaleY(.05); opacity: .35; }

.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #eee; color: #111; padding: 10px 16px; border-radius: 10px; z-index: var(--z-toast); max-width: calc(100vw - 32px); font-size: 14px; box-shadow: 0 10px 30px #000a; animation: rise .2s; }
.logs { font: 12px/1.5 ui-monospace, Menlo, monospace; background: #0a0a0a; border: 1px solid var(--line); border-radius: 10px; padding: 10px; max-height: 260px; overflow: auto; color: var(--muted); white-space: pre-wrap; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- plugs, strips ---------- */
.plug-b { background: #1e1e1e; }
.plug-b svg { color: var(--muted) !important; }
.plug.is-on .plug-b, .strip-card .plug-b { background: #2a2a2a; }
.plug.is-on .plug-b svg { color: var(--hi) !important; }
.plug .head { align-items: center; }
.watts { font-variant-numeric: tabular-nums; color: var(--text); }
.strip-card { grid-column: span 2; }
@media (max-width: 860px) { .strip-card { grid-column: auto; } }
.socket { display: flex; align-items: center; gap: 12px; padding: 10px 2px; border-top: 1px solid var(--line); }
.sock-dot { width: 8px; height: 8px; border-radius: 50%; background: #333; flex: none; transition: background .2s, box-shadow .2s; }
.socket.is-on .sock-dot { background: #eaeaea; box-shadow: 0 0 10px #ffffff55; }
.toggle.sm { width: 40px; height: 24px; }
.toggle.sm::after { width: 16px; height: 16px; }
.toggle.sm.on::after { transform: translateX(16px); }
.plug-big { display: grid; place-items: center; height: 100px; }
.plug-ico svg { width: 40px; height: 40px; color: var(--muted); }
.is-on .plug-ico svg { color: var(--hi); }

/* ---------- stats & charts ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stats > div { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.stats b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 12px; color: var(--muted); }
.chart { display: grid; grid-template-columns: 52px 1fr; column-gap: 8px; }
.chart .plot { position: relative; }
.chart svg { width: 100%; height: 100%; display: block; }
.chart .ylab { display: flex; flex-direction: column; justify-content: space-between; text-align: right; font-size: 11px; color: #8a8a8a; font-variant-numeric: tabular-nums; margin: -6px 0; }
.chart .xlab { display: flex; justify-content: space-between; font-size: 11px; color: #8a8a8a; margin-top: 6px; font-variant-numeric: tabular-nums; }
.chart .xh { position: absolute; top: 0; bottom: 0; width: 1px; background: #777; pointer-events: none; }
.barplot { display: flex; align-items: flex-end; gap: 2px; border-bottom: 1px solid #3a3a3a; }
.barplot .gl { position: absolute; left: 0; right: 0; border-top: 1px solid #262626; pointer-events: none; }
.barplot .bar { flex: 1; height: 100%; display: flex; align-items: flex-end; cursor: default; position: relative; }
.barplot .bar b { display: block; width: 100%; background: #d9d9d9; opacity: .62; border-radius: 4px 4px 0 0; min-height: 1px; transition: opacity .15s; }
.barplot .bar.today b, .barplot .bar:hover b { opacity: 1; }
.chart .tip { position: absolute; top: -6px; transform: translateY(-100%); background: #f0f0f0; color: #111; font-size: 12px; padding: 5px 9px; border-radius: 7px; pointer-events: none; white-space: nowrap; font-variant-numeric: tabular-nums; z-index: var(--z-chart); }
.spark-wrap { margin-bottom: 8px; }
.hero-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.hero span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.hero b { display: block; font-size: 30px; font-weight: 650; letter-spacing: -.5px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.hero em { font-style: normal; color: var(--muted); font-size: 14px; }
@media (max-width: 600px) { .hero-row { grid-template-columns: 1fr 1fr; } .hero-row .hero:first-child { grid-column: span 2; } .hero b { font-size: 24px; } }
.edev { cursor: pointer; }
.edev-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.edev-num { text-align: right; }
.edev-num b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.edev-num span { font-size: 12px; color: var(--muted); }

/* ---------- automations ---------- */
.auto-ico { width: 42px; height: 42px; border-radius: 12px; background: #1e1e1e; display: grid; place-items: center; flex: none; color: var(--muted); }
.auto-ico svg { width: 20px; height: 20px; }

/* ---------- sensors & cameras ---------- */
.readings { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; margin-top: 12px; }
.readings div { background: #0e0e0e; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.readings span { display: block; font-size: 11px; color: var(--muted); }
.readings b { font-size: 17px; font-variant-numeric: tabular-nums; }
.sensor.alert { border-color: #8a8a8a; box-shadow: 0 0 0 1px #8a8a8a inset; }
.sensor.alert .readings b { color: #fff; }
.cam { padding: 10px; }
.cam-img { position: relative; aspect-ratio: 16/9; background: #0b0b0b; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.cam-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-off { position: absolute; inset: 0; display: grid; place-items: center; color: var(--faint); font-size: 13px; }
.cam-live { position: absolute; right: 8px; bottom: 8px; background: #000c; }
.live { aspect-ratio: 16/9; background: #000; border-radius: 12px; overflow: hidden; }
.live iframe { width: 100%; height: 100%; border: 0; display: block; }

/* Respect "Reduce motion" */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .pulse { opacity: 1; }
}
/* Windows high-contrast / forced colours: keep switches and focus readable */
@media (forced-colors: active) {
  .toggle { border: 1px solid ButtonText; }
  .toggle.on::after { background: Highlight; }
}
