:root {
  --bg: #0b1220;
  --card: #151f33;
  --ink: #f4f7fb;
  --muted: #9fb0c7;
  --up: #2ecc71;
  --down: #ff5b5b;
  --unknown: #6b7890;
  --accent: #4aa3ff;
  --warn-bg: #4a2a12;
  --warn-ink: #ffcf99;
  --radius: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  font-size: 18px;
  line-height: 1.4;
  padding: env(safe-area-inset-top) 16px 24px;
  max-width: 560px;
  margin: 0 auto;
}
.hidden { display: none !important; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.25rem; margin: 0 0 12px; }
h3 { font-size: 1rem; color: var(--muted); margin: 18px 0 8px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  margin: 16px 0;
  box-shadow: 0 2px 12px rgba(0,0,0,.25);
}

/* Login */
.login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); padding: 16px; z-index: 10; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-card input {
  width: 100%; font-size: 2rem; text-align: center; letter-spacing: .3em;
  padding: 14px; margin: 14px 0; border-radius: 12px; border: 2px solid #26324a;
  background: #0e1626; color: var(--ink);
}
.login-card button, .power-now, .big { width: 100%; }
button {
  font-size: 1.2rem; padding: 14px 20px; border: 0; border-radius: 12px;
  background: var(--accent); color: #04121f; font-weight: 700; cursor: pointer;
}
.error { color: var(--down); }

/* Topbar */
.topbar { display: flex; align-items: baseline; justify-content: space-between; padding: 12px 4px 0; }
.updated { color: var(--muted); font-size: .9rem; }

.banner { border-radius: 12px; padding: 12px 16px; margin: 12px 0; font-weight: 600; }
.warn { background: var(--warn-bg); color: var(--warn-ink); }

/* Power */
.power-now {
  font-size: 1.8rem; font-weight: 800; text-align: center;
  padding: 18px; border-radius: 12px; margin-bottom: 16px;
}
.power-now.up { background: rgba(46,204,113,.16); color: var(--up); }
.power-now.down { background: rgba(255,91,91,.16); color: var(--down); }
.power-now.unknown { background: rgba(107,120,144,.18); color: var(--muted); }

.timeline { display: flex; height: 34px; width: 100%; border-radius: 8px; overflow: hidden; background: var(--unknown); }
.timeline .seg { height: 100%; }
.timeline .seg.up { background: var(--up); }
.timeline .seg.down { background: var(--down); }
.timeline .seg.unknown { background: var(--unknown); }
.timeline-axis, .bars-axis { display: flex; justify-content: space-between; color: var(--muted); font-size: .8rem; margin-top: 6px; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; margin: 14px 0 0; color: var(--muted); font-size: .9rem; }
.legend .sw { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: middle; margin-right: 6px; }
.sw.up { background: var(--up); } .sw.down { background: var(--down); } .sw.unknown { background: var(--unknown); }

.outages { list-style: none; padding: 0; margin: 0; }
.outages li { padding: 10px 0; border-bottom: 1px solid #26324a; }
.outages li:last-child { border-bottom: 0; }
.muted { color: var(--muted); }

/* Motion */
.big { text-align: center; margin: 4px 0 18px; }
.big span { font-size: 4rem; font-weight: 800; display: block; color: var(--accent); line-height: 1; }
.big small { color: var(--muted); font-size: 1rem; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 120px; }
.bars .bar { flex: 1; background: var(--accent); border-radius: 6px 6px 0 0; min-height: 3px; position: relative; opacity: .9; }
.bars .bar { border: 0; padding: 0; cursor: pointer; font: inherit; }
.bars .bar:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.bars .bar:hover { opacity: 1; }
.hint { text-align: center; font-size: .85rem; margin: 10px 0 0; }

/* Motion day view */
#dash.day-mode > section:not(#motionDay), #dash.day-mode > #ownerBar { display: none; }
.motion-day .back { padding: 0; margin-bottom: 4px; }
.day-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.day-nav h2 { margin: 0; text-align: center; flex: 1; }
.nav-btn { width: 44px; height: 44px; border-radius: 12px; border: 0; background: #0e1626; color: var(--ink); font-size: 1.4rem; cursor: pointer; }
.nav-btn:disabled { opacity: .3; cursor: default; }
.zoom { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 0 0 26px; color: var(--muted); }
.zoom b { color: var(--ink); }
.zoom > span { min-width: 8.5em; text-align: center; }
.day-bars .bar { border-radius: 3px 3px 0 0; min-height: 2px; }
.day-bars .bar.zero { opacity: .35; }
.day-bars .bar.future { background: var(--unknown); opacity: .25; }
.day-bars .bar.picked { background: var(--ink); }
.day-pick { min-height: 3em; margin: 12px 0 0; font-size: .95rem; overflow-wrap: anywhere; }
.bars .bar span { position: absolute; top: -20px; left: 0; right: 0; text-align: center; font-size: .75rem; color: var(--muted); }

.foot { text-align: center; padding: 8px; }
.link { background: none; color: var(--muted); font-size: 1rem; font-weight: 500; }

@media (prefers-color-scheme: light) {
  :root { --bg:#eef2f8; --card:#fff; --ink:#0b1220; --muted:#5a6b82; --unknown:#aab6c8; --warn-bg:#fff2dd; --warn-ink:#8a5200; }
  .nav-btn { background: #e3e9f2; }
}

/* Owner links */
.owner-link { margin-top: 18px; font-size: .9rem; }
.owner-link a, .owner-bar a { color: var(--accent); }
.owner-bar { margin: 8px 4px 0; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.owner-bar select { font-size: 1rem; padding: 6px 10px; border-radius: 8px; background: var(--card); color: var(--ink); border: 1px solid var(--unknown); }

/* Floor plan */
:root { --open: #f5a524; --closed: #2ecc71; --off: #8593a8; --wall: #dbe4f0; }
.plan-svg { display: block; width: 100%; height: auto; touch-action: manipulation; }
.plan-grid line { stroke: #9aa3b2; stroke-opacity: .25; stroke-width: .04; }
.plan-walls .wall { fill: none; stroke: var(--wall); stroke-width: .25; stroke-linecap: round; stroke-linejoin: round; }
.dev .hit { fill: transparent; }
.dev .dot { fill: var(--card); stroke: currentColor; stroke-width: .12; }
.dev text { fill: var(--ink); text-anchor: middle; font-weight: 600; paint-order: stroke; stroke: var(--card); stroke-width: .25; }
.dev .state { fill: currentColor; }
.dev.on { color: var(--up); }
.dev.off { color: var(--off); }
.dev.open { color: var(--open); }
.dev.closed { color: var(--closed); }
.dev.tampered { color: var(--down); }
.dev.unknown { color: var(--off); }
.dev.offline { color: var(--off); opacity: .55; }
.dev.missing { color: var(--down); }
.dev.missing .dot { stroke-dasharray: .3 .2; }
.dev.selected .dot { stroke-width: .3; }
/* Switchable from the dashboard: a ring, a hand cursor, and a pulse while the command is in flight. */
.dev .ring { fill: none; stroke: currentColor; stroke-width: .08; stroke-dasharray: .25 .15; }
.dev.ctl { cursor: pointer; }
.dev.ctl:focus-visible .ring, .dev-row.ctl:focus-visible { outline: none; stroke-width: .2; }
.dev-row.ctl { cursor: pointer; border-radius: 8px; padding: 0 8px; margin: 0 -8px; }
.dev-row.ctl .st::after { content: " ⏻"; }
.dev-row.ctl:hover, .dev-row.ctl:focus-visible { background: rgba(74,163,255,.10); }
.busy { animation: busy 1s ease-in-out infinite; pointer-events: none; }
@keyframes busy { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .busy { animation: none; opacity: .5; } }
.offplan h3 { margin-top: 16px; }
#planMsg { background: rgba(255,91,91,.15); color: var(--down); }
.offplan-list { list-style: none; padding: 0; margin: 0; }
.dev-row { display: flex; align-items: center; gap: 10px; min-height: 44px; border-bottom: 1px solid #26324a; }
.dev-row:last-child { border-bottom: 0; }
.dev-row .ic { width: 24px; height: 24px; flex: none; }
.dev-row .nm { flex: 1; color: var(--ink); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dev-row .st { font-weight: 700; }
.dev-row.on { color: var(--up); } .dev-row.off, .dev-row.unknown { color: var(--off); }
.dev-row.open { color: var(--open); } .dev-row.closed { color: var(--closed); } .dev-row.tampered { color: var(--down); }
.dev-row.offline { color: var(--off); opacity: .6; } .dev-row.missing { color: var(--down); }
@media (prefers-color-scheme: light) {
  :root { --wall: #1d2a40; --open: #b86e00; --closed: #1a8f4c; }
}
