:root {
  --bg: #0f1114;
  --surface: #171a1f;
  --surface-2: #1e2228;
  --surface-3: #262b33;
  --border: #2c323b;
  --text: #e8eaed;
  --text-2: #a3a9b3;
  --text-3: #6f7782;
  --accent: #e8eaed;

  --fire: #ef3b2d;
  --fire-bg: #3a1311;
  --prealarm: #f5821f;
  --prealarm-bg: #3a2210;
  --fault: #f2b705;
  --fault-bg: #352b08;
  --supervisory: #4b8ff7;
  --supervisory-bg: #13243f;
  --disabled: #a07cf2;
  --disabled-bg: #261d3d;
  --test: #22b8a7;
  --test-bg: #0e2d2a;
  --info: #8d96a3;
  --info-bg: #23272e;
  --normal: #2fb463;
  --normal-bg: #10291b;
  --offline: #7b828c;
  --offline-bg: #22252a;

  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f3f4f6;
    --surface: #ffffff;
    --surface-2: #f6f7f9;
    --surface-3: #eceef1;
    --border: #dde0e5;
    --text: #15181c;
    --text-2: #4f5661;
    --text-3: #868d98;
    --fire-bg: #fde6e4;
    --prealarm-bg: #fdeedd;
    --fault-bg: #fdf3d2;
    --supervisory-bg: #e2ecfd;
    --disabled-bg: #eee8fd;
    --test-bg: #dcf5f2;
    --info-bg: #eceef1;
    --normal-bg: #dff5e8;
    --offline-bg: #eceef1;
    --fault: #c99400;
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f3f4f6; --surface: #ffffff; --surface-2: #f6f7f9; --surface-3: #eceef1; --border: #dde0e5;
  --text: #15181c; --text-2: #4f5661; --text-3: #868d98;
  --fire-bg: #fde6e4; --prealarm-bg: #fdeedd; --fault-bg: #fdf3d2; --supervisory-bg: #e2ecfd;
  --disabled-bg: #eee8fd; --test-bg: #dcf5f2; --info-bg: #eceef1; --normal-bg: #dff5e8; --offline-bg: #eceef1;
  --fault: #c99400;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--text-3); }
.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.hidden { display: none !important; }

/* ---------- severity helpers ---------- */
[data-sev="fire"]        { --sev: var(--fire);        --sev-bg: var(--fire-bg); }
[data-sev="prealarm"]    { --sev: var(--prealarm);    --sev-bg: var(--prealarm-bg); }
[data-sev="fault"]       { --sev: var(--fault);       --sev-bg: var(--fault-bg); }
[data-sev="supervisory"] { --sev: var(--supervisory); --sev-bg: var(--supervisory-bg); }
[data-sev="disabled"]    { --sev: var(--disabled);    --sev-bg: var(--disabled-bg); }
[data-sev="test"]        { --sev: var(--test);        --sev-bg: var(--test-bg); }
[data-sev="info"]        { --sev: var(--info);        --sev-bg: var(--info-bg); }
[data-sev="normal"]      { --sev: var(--normal);      --sev-bg: var(--normal-bg); }
[data-sev="offline"]     { --sev: var(--offline);     --sev-bg: var(--offline-bg); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--sev-bg, var(--surface-3)); color: var(--sev, var(--text-2));
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.plain::before { display: none; }

/* ---------- buttons / inputs ---------- */
.btn {
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); cursor: pointer; font-weight: 600; font-size: 13px; white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.danger { background: var(--fire); border-color: var(--fire); color: #fff; }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-3); }
.input, select.input {
  height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); min-width: 0;
}
.input:focus, .btn:focus-visible { outline: 2px solid var(--supervisory); outline-offset: 1px; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 20px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; text-decoration: none; }
.brand img { width: 26px; height: 26px; }
.nav { display: flex; gap: 2px; margin-left: 12px; }
.nav a {
  padding: 7px 12px; border-radius: 8px; text-decoration: none; color: var(--text-2); font-weight: 600; font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--surface-3); color: var(--text); }
.nav .count { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; font-size: 11px; display: inline-grid; place-items: center; background: var(--sev, var(--surface-3)); color: #fff; }
.topbar .spacer { flex: 1; }
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-3); }
.conn i { width: 8px; height: 8px; border-radius: 50%; background: var(--offline); }
.conn.live i { background: var(--normal); box-shadow: 0 0 0 3px color-mix(in srgb, var(--normal) 25%, transparent); }
.conn.down i { background: var(--fire); }
.clock { font-family: var(--mono); font-size: 13px; color: var(--text-2); }

main { padding: 20px; max-width: 1500px; margin: 0 auto; padding-bottom: 90px; }
h1 { font-size: 20px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 0 0 10px; color: var(--text-2); text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .spacer { flex: 1; }
.section { margin-top: 26px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card.pad { padding: 16px; }

/* ---------- alarm banner ---------- */
.alarm-banner {
  display: flex; align-items: center; gap: 16px; padding: 14px 20px;
  background: var(--fire); color: #fff; position: sticky; top: 55px; z-index: 19;
}
.alarm-banner.flash { animation: flash 1s steps(2, start) infinite; }
@keyframes flash { 50% { background: #9e1a10; } }
.alarm-banner .big { font-size: 18px; font-weight: 800; letter-spacing: .02em; }
.alarm-banner .where { opacity: .92; }
.alarm-banner .btn { background: #fff; color: var(--fire); border-color: #fff; }
.alarm-banner.fault { background: var(--fault); color: #1a1400; animation: none; }
.alarm-banner.fault .btn { color: #1a1400; }

/* ---------- overview ---------- */
.summary-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 22px; }
.stat { padding: 14px 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); }
.stat .n { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat .l { font-size: 12px; color: var(--text-2); font-weight: 600; }
.stat.on { background: var(--sev-bg); border-color: color-mix(in srgb, var(--sev) 40%, transparent); }
.stat.on .n { color: var(--sev); }

.site-title { display: flex; align-items: baseline; gap: 8px; margin: 22px 0 10px; }
.site-title h3 { margin: 0; }
.panel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.panel-card {
  display: block; text-decoration: none; position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px;
  transition: border-color .15s, transform .15s;
}
.panel-card:hover { border-color: var(--text-3); }
.panel-card:not([data-sev="normal"]) { border-color: color-mix(in srgb, var(--sev) 45%, var(--border)); }
.panel-card[data-sev="fire"] { background: var(--fire-bg); border-color: var(--fire); }
.panel-card .row { display: flex; align-items: center; gap: 10px; }
.panel-card .name { font-weight: 700; font-size: 15px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-card .status-word { font-size: 22px; font-weight: 800; color: var(--sev); margin: 10px 0 8px; letter-spacing: .01em; }
.panel-card .chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 22px; }
.panel-card .foot { display: flex; justify-content: space-between; margin-top: 12px; font-size: 12px; color: var(--text-3); }

/* ---------- panel detail ---------- */
.leds { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.led {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border); font-weight: 600; font-size: 13px; color: var(--text-3);
}
.led i { width: 12px; height: 12px; border-radius: 50%; background: var(--surface-3); flex: none; }
.led.on { color: var(--text); background: var(--sev-bg); border-color: color-mix(in srgb, var(--sev) 45%, transparent); }
.led.on i { background: var(--sev); box-shadow: 0 0 10px var(--sev); }
.led.on[data-sev="fire"] i { animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs button { background: none; border: 0; padding: 8px 12px; cursor: pointer; color: var(--text-2); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--text); border-bottom-color: var(--text); }

.zone-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.zone {
  padding: 10px 12px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border);
  cursor: default; min-height: 64px; display: flex; flex-direction: column; gap: 3px;
}
button.zone { font: inherit; color: inherit; text-align: left; cursor: pointer; }
button.zone:hover { border-color: var(--text-3); }
.cmd-bar { margin-bottom: 18px; }
.zone .num { font-family: var(--mono); font-size: 11px; color: var(--text-3); }
.zone .lbl { font-weight: 600; font-size: 13px; line-height: 1.25; }
.zone .st { font-size: 11px; font-weight: 700; color: var(--sev); text-transform: uppercase; letter-spacing: .04em; }
.zone:not([data-sev="normal"]) { background: var(--sev-bg); border-color: color-mix(in srgb, var(--sev) 50%, transparent); }
.zone[data-sev="fire"] { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { border-color: var(--fire); box-shadow: 0 0 0 3px color-mix(in srgb, var(--fire) 30%, transparent); } }

.loop { margin-bottom: 18px; }
.loop-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.dev-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(26px, 1fr)); gap: 3px; }
.dev {
  aspect-ratio: 1; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border);
  font-family: var(--mono); font-size: 9px; display: grid; place-items: center; color: var(--text-3); cursor: pointer;
  padding: 0;
}
.dev:hover { border-color: var(--text-2); color: var(--text); }
.dev:not([data-sev="normal"]) { background: var(--sev); border-color: var(--sev); color: #fff; font-weight: 700; }
.legend { display: flex; flex-wrap: wrap; gap: 6px; }

.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); cursor: pointer; user-select: none; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.list td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.unacked td:first-child { box-shadow: inset 3px 0 0 var(--sev); }
table.list tr.restored { color: var(--text-2); }
table.list .when { white-space: nowrap; font-variant-numeric: tabular-nums; }
table.list a { text-decoration: none; font-weight: 600; }
table.list a:hover { text-decoration: underline; }
.empty { padding: 40px; text-align: center; color: var(--text-3); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.filters .input { flex: 0 1 180px; }
.filters .grow { flex: 1 1 200px; }

/* ---------- forms / settings ---------- */
.form-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 14px; }
.notice {
  padding: 12px 14px; border-radius: 8px; background: var(--fault-bg); color: var(--text);
  border: 1px solid color-mix(in srgb, var(--fault) 40%, transparent); font-size: 13px; margin-bottom: 16px;
}
.notice b { color: var(--fault); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login form { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; padding: 28px; }
.login .brand { justify-content: center; font-size: 18px; margin-bottom: 8px; }
.login .input { height: 40px; }
.login .btn { height: 40px; }
.error { color: var(--fire); font-size: 13px; min-height: 18px; }

/* ---------- toast ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: min(380px, calc(100vw - 32px)); }
.toast {
  padding: 12px 14px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgb(0 0 0 / .3); font-size: 13px;
  animation: slidein .2s ease-out;
}
.toast b { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.toast b::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--sev, var(--text-3)); flex: none; }
@keyframes slidein { from { transform: translateY(10px); opacity: 0; } }

dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); padding: 20px; max-width: 420px; width: calc(100% - 32px); }
dialog::backdrop { background: rgb(0 0 0 / .5); }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  /* backdrop-filter would make the topbar the containing block of the fixed bottom nav */
  .topbar { padding: 10px 16px; backdrop-filter: none; background: var(--bg); }
  .nav {
    position: fixed; bottom: 0; left: 0; right: 0; margin: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 6px max(6px, env(safe-area-inset-bottom)); justify-content: space-around;
  }
  .nav a { flex: 1; justify-content: center; flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 4px; }
  .clock, .hide-sm { display: none; }
  main { padding: 16px; padding-bottom: 100px; }
  .panel-grid { grid-template-columns: 1fr; }
  .alarm-banner { top: 51px; flex-wrap: wrap; padding: 12px 16px; gap: 10px; }
  .alarm-banner .big { font-size: 15px; }
  .alarm-banner .where { font-size: 13px; }
  .zone-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  table.list .hide-sm { display: none; }

  /* active conditions: stacked cards instead of a wide table */
  table.stack thead { display: none; }
  table.stack, table.stack tbody { display: block; }
  table.stack tr {
    display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    grid-template-areas: "cond when" "loc loc" "panel panel" "ack ack";
  }
  table.stack tr.unacked { box-shadow: inset 4px 0 0 var(--sev); }
  table.stack tr.unacked td:first-child { box-shadow: none; }
  table.stack td { padding: 0; border: 0; }
  table.stack .c-when { grid-area: when; color: var(--text-3); font-size: 12px; }
  table.stack .c-cond { grid-area: cond; }
  table.stack .c-loc { grid-area: loc; font-weight: 600; }
  table.stack .c-panel { grid-area: panel; font-size: 12px; }
  table.stack .c-panel div { display: inline; }
  table.stack .c-panel div::before { content: " · "; }
  table.stack .c-ack { grid-area: ack; margin-top: 6px; }
  table.stack .c-ack .btn { width: 100%; height: 36px; }
}

/* ---------- admin forms ---------- */
.admin-form { display: flex; flex-direction: column; gap: 10px; }
.fld { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; min-width: 0; }
.fld small { font-weight: 400; font-size: 11px; }
.fld-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 14px; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 6px 14px; }
dialog:has(.fld-grid) { max-width: 640px; }

/* ---------- floor plans ---------- */
.plan-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.plan-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.plan-tabs .chip { cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); padding: 5px 12px; }
.plan-tabs .chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.zoom-btns { display: flex; gap: 2px; }
.plan-wrap { display: grid; grid-template-columns: 1fr; gap: 12px; }
.plan-wrap.editing { grid-template-columns: 1fr 300px; }
.plan-view {
  position: relative; height: min(72vh, 820px); overflow: hidden; border-radius: var(--radius);
  border: 1px solid var(--border); background: #fff; cursor: grab; touch-action: none; user-select: none;
}
.plan-view:active { cursor: grabbing; }
.plan-wrap.editing .plan-view { cursor: crosshair; outline: 2px dashed var(--fault); outline-offset: -2px; }
.plan-canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; --inv: 1; }
.plan-canvas img { display: block; max-width: none; pointer-events: none; }
.mk {
  position: absolute; width: 30px; height: 30px; padding: 4px; border-radius: 50%;
  transform: translate(-50%, -50%) scale(var(--inv)); transform-origin: center;
  background: #fff; color: var(--sev, var(--text-3)); border: 2px solid var(--sev, var(--text-3));
  box-shadow: 0 1px 4px rgb(0 0 0 / .35); cursor: pointer; display: grid; place-items: center; z-index: 1;
}
.mk svg { width: 100%; height: 100%; }
.mk[data-sev="normal"] { color: #2a7a4a; border-color: #2fb463; }
.mk:not([data-sev="normal"]):not([data-sev="offline"]) { background: var(--sev); color: #fff; z-index: 2; }
.mk[data-sev="fire"], .mk[data-sev="prealarm"] { animation: mk-pulse 1s infinite; z-index: 3; }
@keyframes mk-pulse { 50% { box-shadow: 0 0 0 10px color-mix(in srgb, var(--sev) 35%, transparent); } }
.mk.focus { outline: 4px solid var(--supervisory); outline-offset: 4px; z-index: 4; }
.mk-zone { width: auto; min-width: 34px; height: 24px; border-radius: 6px; padding: 0 6px; }
.mk-zone-text { font: 800 12px/1 var(--sans); }
.plan-wrap.editing .mk { cursor: move; }
.plan-hint {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); z-index: 5;
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-size: 13px; pointer-events: none;
}
.plan-side { padding: 12px; display: flex; flex-direction: column; gap: 8px; max-height: min(72vh, 820px); }
.ps-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; min-height: 120px; }
.ps-item {
  display: flex; align-items: center; gap: 8px; text-align: left; padding: 6px 8px; border-radius: 6px;
  border: 1px solid transparent; background: none; cursor: grab; font: inherit; font-size: 13px; color: inherit;
}
.ps-item:hover { background: var(--surface-2); }
.ps-item.armed { border-color: var(--supervisory); background: var(--supervisory-bg); }
.ps-sym { width: 22px; height: 22px; flex: none; display: inline-grid; place-items: center; color: var(--sev, var(--text-2)); }
.ps-sym[data-sev="normal"] { color: var(--text-2); }
.ps-sym svg { width: 100%; height: 100%; }
.ps-sym .mk-zone-text { font-size: 10px; }
.plan-legend { margin-top: 10px; }
.plan-legend .chip { gap: 4px; }
@media (max-width: 900px) {
  .plan-wrap.editing { grid-template-columns: 1fr; }
  .plan-view { height: 60vh; }
}

/* ---------- imported layout ---------- */
.import-box { display: flex; flex-direction: column; gap: 6px; padding: 12px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); font-size: 13px; }
.zone-members { display: flex; flex-direction: column; gap: 2px; max-height: 300px; overflow-y: auto; margin-top: 8px; }
.zm { display: grid; grid-template-columns: 36px 1fr auto; gap: 4px 10px; align-items: center; font-size: 13px; padding: 4px 6px; border-radius: 6px; }
.zm .chip { grid-column: 2 / -1; justify-self: start; }
.zm:not([data-sev="normal"]) { background: var(--sev-bg); }

.qr { display: grid; place-items: center; background: #fff; border-radius: 8px; padding: 10px; margin: 8px 0; }
.qr svg { width: 200px; height: 200px; }

.timed-box { display: flex; flex-direction: column; gap: 8px; padding: 12px; margin: 10px 0; border-radius: 8px; background: var(--disabled-bg); border: 1px solid color-mix(in srgb, var(--disabled) 35%, transparent); }

.esc-level { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; background: var(--surface-2); }

/* ---------- control-room wall mode ---------- */
body.wall-mode .topbar, body.wall-mode #banner, body.wall-mode .toasts, body.wall-mode .nav { display: none !important; }
body.wall-mode main { max-width: none; padding: 0; }
body.wall-mode { background: #0b0c0e; color: #eef0f3; }
.wall-start { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 12px; text-align: center; padding: 20px; }
.wall-exit { position: fixed; right: 10px; bottom: 10px; opacity: .35; color: #fff; }
.wall-exit:hover { opacity: 1; }
.wall-normal { min-height: 100vh; display: flex; flex-direction: column; padding: 28px 32px; gap: 24px; }
.wall-top { display: flex; justify-content: space-between; align-items: center; }
.wall-top .brand { font-size: 24px; color: #eef0f3; }
.wall-clock { font: 700 44px/1 var(--mono); color: #eef0f3; }
.wall-grid { flex: 1; display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; align-content: start; }
.wall-tile { border-radius: 16px; padding: 26px; background: #16181c; border: 2px solid var(--sev); }
.wall-tile[data-sev="normal"] { border-color: #1f6f3f; }
.wall-tile-name { font-size: 26px; font-weight: 800; }
.wall-tile-site { font-size: 16px; color: #9aa1ab; margin-top: 2px; }
.wall-tile-state { font-size: 40px; font-weight: 900; color: var(--sev); margin-top: 18px; letter-spacing: .02em; }
.wall-tile:not([data-sev="normal"]):not([data-sev="offline"]) { background: color-mix(in srgb, var(--sev) 16%, #16181c); }
.wall-ticker { display: flex; flex-wrap: wrap; gap: 10px; }
.wall-ticker .chip { font-size: 16px; padding: 6px 14px; }
.wall-alarm { min-height: 100vh; display: flex; flex-direction: column; }
.wall-alarm-head { display: flex; justify-content: space-between; gap: 20px; padding: 24px 32px; background: var(--fire); color: #fff; animation: flash 1s steps(2, start) infinite; }
.wall-alarm.prealarm .wall-alarm-head { background: var(--prealarm); animation: none; }
.wall-big { font-size: 56px; font-weight: 900; letter-spacing: .03em; line-height: 1; }
.wall-where { font-size: 36px; font-weight: 800; margin-top: 10px; }
.wall-sub { font-size: 20px; opacity: .9; margin-top: 6px; }
.wall-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 14px; }
.wall-actions .wall-clock { color: #fff; }
.wall-actions .btn { background: #fff; color: var(--fire); border-color: #fff; }
.wall-plan { flex: 1; height: auto !important; min-height: 60vh; border-radius: 0; border: 0; }
.wall-plan .mk { width: 40px; height: 40px; }
.wall-noplan { flex: 1; display: grid; place-items: center; font-size: 22px; color: #9aa1ab; padding: 40px; text-align: center; }

/* ---------- logbook ---------- */
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
.notes { display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow-y: auto; }
.note { padding: 8px 10px; border-radius: 8px; background: var(--surface-2); font-size: 13px; }
.log-list { display: flex; flex-direction: column; gap: 10px; }
.log-entry.handover { border-color: color-mix(in srgb, var(--supervisory) 50%, var(--border)); }
.handover-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 16px; font-size: 13px; margin-top: 8px; }
.handover-grid ul { margin: 4px 0 0; padding-left: 18px; }
.handover-grid > div > b { display: block; }

/* ---------- floors ---------- */
.floors-wrap { display: grid; grid-template-columns: 210px 1fr; gap: 14px; align-items: start; }
.floor-main { min-width: 0; }
.floor-list { display: flex; flex-direction: column; gap: 4px; position: sticky; top: 70px; }
.floor-list-head { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); padding: 0 4px 4px; }
.floor {
  display: flex; align-items: center; gap: 10px; text-align: left; padding: 8px 10px; border-radius: 8px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); font: inherit; color: inherit;
}
.floor:hover:not(:disabled) { border-color: var(--text-3); }
.floor.on { border-color: var(--text); box-shadow: inset 0 0 0 1px var(--text); }
.floor:disabled { opacity: .45; cursor: default; }
.floor:not([data-sev="normal"]) { background: var(--sev-bg); border-color: color-mix(in srgb, var(--sev) 50%, var(--border)); }
.floor[data-sev="fire"] { animation: pulse 1.2s infinite; }
.floor-lvl {
  min-width: 30px; height: 30px; padding: 0 6px; border-radius: 6px; display: inline-grid; place-items: center; flex: none;
  background: var(--surface-3); font: 800 13px/1 var(--mono);
}
.floor-name { flex: 1; min-width: 0; font-weight: 600; font-size: 13px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; }
.floor-name small { display: block; font-weight: 400; font-size: 11px; color: var(--text-3); }
.floor-badge { font-size: 11px; font-weight: 800; color: var(--sev); white-space: nowrap; }
.plan-title { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; }
@media (max-width: 900px) {
  .floors-wrap { grid-template-columns: 1fr; }
  .floor-list { position: static; flex-direction: row; overflow-x: auto; padding-bottom: 4px; }
  .floor-list-head { display: none; }
  .floor { flex: none; }
}

/* ---------- cameras ---------- */
.cams { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin: 10px 0; }
.cam { margin: 0; background: #000; border-radius: 8px; overflow: hidden; }
.cam img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: #111; }
.cam img.cam-err { opacity: .35; }
.cam figcaption { font-size: 12px; color: #ddd; padding: 4px 8px; }
.cam-thumb { width: 120px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; background: #111; display: block; }
.wall-alarm { position: relative; }
.wall-cams { position: absolute; right: 18px; bottom: 18px; width: min(420px, 34vw); grid-template-columns: 1fr; z-index: 6; margin: 0; }
.wall-cams .cam { border: 3px solid var(--fire); box-shadow: 0 8px 30px rgb(0 0 0 / .5); }
.wall-cams figcaption { font-size: 15px; }

/* ---------- AI assistant ---------- */
.ai-fab {
  position: fixed; right: 18px; bottom: 18px; z-index: 40; height: 46px; padding: 0 18px; border-radius: 23px; border: 0;
  background: linear-gradient(135deg, #6d4cf0, #e0408a); color: #fff; font: 700 15px var(--sans); cursor: pointer;
  box-shadow: 0 8px 24px rgb(0 0 0 / .25);
}
.ai-drawer {
  position: fixed; right: 18px; bottom: 76px; z-index: 41; width: min(420px, calc(100vw - 36px)); height: min(600px, calc(100vh - 140px));
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 16px 48px rgb(0 0 0 / .3); overflow: hidden;
}
.ai-head { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.ai-log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.ai-msg { padding: 9px 12px; border-radius: 12px; font-size: 14px; line-height: 1.45; max-width: 92%; overflow-wrap: anywhere; }
.ai-msg.user { align-self: flex-end; background: var(--text); color: var(--bg); }
.ai-msg.assistant { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); }
.ai-busy { animation: blink 1s infinite; }
.ai-example { text-align: left; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; font: inherit; font-size: 13px; color: inherit; }
.ai-example:hover { border-color: var(--text-3); }
.ai-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.ai-form textarea { flex: 1; height: auto; padding: 8px; resize: none; }
body.wall-mode .ai-fab, body.wall-mode .ai-drawer { display: none; }
@media (max-width: 760px) { .ai-fab { bottom: 76px; } .ai-drawer { bottom: 130px; } }

.license-bar { padding: 8px 20px; background: var(--fault-bg); border-bottom: 1px solid color-mix(in srgb, var(--fault) 40%, transparent); font-size: 13px; font-weight: 600; }
.license-bar.grace { background: var(--fire); color: #fff; }
.license-bar a { color: inherit; margin-left: 8px; }
