* { box-sizing: border-box; margin: 0; }

/* Light theme (default) */
:root {
  --bg: #EBF1F8; --panel: #FFFFFF; --line: #DDE6ED; --fg: #202C3B; --dim: #5E6B7A;
  --red: #C62E2E; --red-soft: #FDECEC; --amber: #B26A00; --amber-soft: #FFF4E2;
  --green: #178A45; --green-soft: #E7F6EC; --blue: #007278; --blue-soft: #E3F5F4;
  --btn: #F6F9FB; --btn-hover: #EBF1F8; --line-strong: #C9D6E0;
  --shadow: 0 1px 2px rgba(15,23,36,.05), 0 4px 12px rgba(15,23,36,.05);
  --hdr: linear-gradient(135deg, #000C2A 0%, #06283A 100%); --hdr-fg: #FFFFFF;
}
/* Dark theme (control-room night mode) */
:root[data-theme="dark"] {
  --bg: #0A111B; --panel: #111A26; --line: #2C3A4A; --fg: #F6F9FB; --dim: #93A1B0;
  --red: #F86A60; --red-soft: #3A1416; --amber: #FFA734; --amber-soft: #33270D;
  --green: #2FC97D; --green-soft: #102917; --blue: #00CCC0; --blue-soft: #06302F;
  --btn: #1A2634; --btn-hover: #22303F; --line-strong: #34465A;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
  --hdr: linear-gradient(135deg, #000C2A 0%, #041B2C 100%); --hdr-fg: #F6F9FB;
}

html, body { height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font: 14px/1.5 "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ---------- header ---------- */
header { display: flex; align-items: center; gap: 28px; padding: 14px 22px; background: var(--hdr); color: var(--hdr-fg); }
.brand { display: flex; align-items: center; gap: 12px; }
.logo-dot { width: 14px; height: 14px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #00CCC0, #007278 70%); box-shadow: 0 0 12px rgba(0,204,192,.8); flex: none; }
.logo-dot.big { width: 22px; height: 22px; margin: 0 auto 12px; }
.brand-name { font-weight: 800; letter-spacing: 4px; font-size: 16px; line-height: 1.1; }
.brand-site { color: #93A1B0; font-size: 12px; font-weight: 500; }
.kpis { display: flex; gap: 10px; margin-left: auto; }
.kpi { display: flex; align-items: baseline; gap: 7px; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.1); border-radius: 10px; padding: 6px 14px; }
.kpi-num { font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi-lbl { font-size: 11px; color: #93A1B0; text-transform: uppercase; letter-spacing: .6px; white-space: nowrap; }
.kpi.hot { background: rgba(216,52,44,.25); border-color: rgba(255,110,90,.5); }
.kpi.hot .kpi-num { color: #FF9A8A; }
.hdr-right { display: flex; gap: 8px; align-items: center; }
.pill { height: 34px; display: inline-flex; align-items: center; gap: 7px; padding: 0 13px; border-radius: 10px; font-size: 12px; font-weight: 700; letter-spacing: .6px; background: var(--green); color: #fff; }
.pill.off { background: var(--red); }
#connState:not(.off)::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #fff; flex: none; animation: livedot 1.7s ease-out infinite; }
@keyframes livedot { 0% { box-shadow: 0 0 0 0 rgba(255,255,255,.6); } 70% { box-shadow: 0 0 0 6px rgba(255,255,255,0); } 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); } }
header button { border: 1px solid rgba(255,255,255,.22); background: transparent; color: var(--hdr-fg); }
.hdr-right button { height: 34px; display: inline-flex; align-items: center; }
header button:hover { background: rgba(255,255,255,.12); }
button.icon { padding: 6px 10px; }

/* ---------- layout ---------- */
main { flex: 1; display: grid; grid-template-columns: 340px 1fr 320px; min-height: 0; }
aside { background: var(--bg); overflow-y: auto; padding: 16px 14px; }
#alertPane { border-right: 1px solid var(--line); }
#devicePane { border-left: 1px solid var(--line); }
h2 { font-size: 11px; text-transform: uppercase; letter-spacing: 2px; color: var(--dim); margin: 20px 2px 10px; font-weight: 700; }
h2:first-child { margin-top: 2px; }
h2 .count { background: var(--btn-hover); color: var(--dim); border-radius: 999px; padding: 1px 9px; font-size: 10px; letter-spacing: 0; margin-left: 4px; }
#map { min-height: 0; }
/* OSM has no dark tile set, so darken the light tiles. Tile pane only: markers and zones keep their colours. */
[data-theme="dark"] #map .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.95) contrast(.9); }
.empty { color: var(--dim); font-size: 13px; padding: 14px; text-align: center; border: 1px dashed var(--line-strong); border-radius: 12px; }

/* ---------- alert cards ---------- */
.alert { border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin-bottom: 10px; background: var(--panel); box-shadow: var(--shadow); }
.alert.active { border-color: var(--red); animation: flash 1.1s infinite alternate; }
.alert.acked { border-color: var(--amber); }
.alert.resolved { opacity: .62; }
@keyframes flash { from { box-shadow: var(--shadow); } to { box-shadow: 0 0 0 4px var(--red-soft), var(--shadow); } }
.alert-row { display: flex; gap: 10px; align-items: flex-start; }
.type-ico { width: 38px; height: 38px; border-radius: 11px; display: flex; align-items: center; justify-content: center; font-size: 18px; flex: none; background: var(--btn); }
.t-sos, .t-man_down { background: var(--red-soft); }
.t-silent { background: var(--amber-soft); }
.t-welfare_missed, .t-comms_lost { background: var(--amber-soft); }
.t-test { background: var(--blue-soft); }
.alert-main { flex: 1; min-width: 0; }
.alert .type { font-weight: 700; font-size: 13.5px; letter-spacing: .2px; }
.alert.active .type { color: var(--red); }
.alert.acked .type { color: var(--amber); }
.alert.test .type { color: var(--blue); }
.alert .meta { color: var(--dim); font-size: 12px; margin-top: 2px; }
.alert-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.alert-id { color: var(--dim); font-size: 11px; font-variant-numeric: tabular-nums; }
.chip { font-size: 10px; font-weight: 800; letter-spacing: .8px; padding: 3px 9px; border-radius: 999px; }
.chip.red { background: var(--red); color: #fff; }
.chip.amber { background: var(--amber); color: #fff; }
.chip.grey { background: var(--btn-hover); color: var(--dim); }
.esc { background: var(--red); color: #fff; font-size: 10px; padding: 2px 8px; border-radius: 999px; margin-left: 6px; vertical-align: middle; animation: escflash .6s infinite alternate; }
@keyframes escflash { from { opacity: 1; } to { opacity: .55; } }
.note { background: var(--btn); border-radius: 10px; padding: 8px 10px; font-size: 12.5px; color: var(--fg); margin-top: 10px; }
.alert .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.alert.test .actions { margin-top: 0; }

/* ---------- buttons ---------- */
button { border: 1px solid var(--line-strong); background: var(--btn); color: var(--fg); border-radius: 9px; padding: 7px 14px; cursor: pointer; font: inherit; font-size: 13px; font-weight: 600; transition: background .12s, transform .06s; }
button:hover { background: var(--btn-hover); }
button:active { transform: translateY(1px); }
button.danger { background: var(--red); border-color: var(--red); color: #fff; }
button.warn { background: var(--amber); border-color: var(--amber); color: #fff; }
button.ok { background: var(--green); border-color: var(--green); color: #fff; }
button.ghost { background: transparent; }

/* ---------- devices ---------- */
.device { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 14px; margin-bottom: 8px; border: 1px solid var(--line); background: var(--panel); box-shadow: var(--shadow); cursor: pointer; }
.device.in-alert { border-color: var(--red); background: var(--red-soft); }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--btn-hover); color: var(--dim); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex: none; position: relative; }
.avatar.on { background: var(--green-soft); color: var(--green); }
.avatar.on::after { content: ""; position: absolute; right: -1px; bottom: -1px; width: 11px; height: 11px; border-radius: 50%; background: var(--green); border: 2px solid var(--panel); }
.dev-main { flex: 1; min-width: 0; }
.device .nm { font-weight: 600; font-size: 13.5px; line-height: 1.25; overflow-wrap: anywhere; }
.device .sub, .timer .sub { color: var(--dim); font-size: 11.5px; }
.danger-text { color: var(--red); }
.batt { font-size: 11.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.batt-ok { color: var(--green); } .batt-mid { color: var(--amber); } .batt-low { color: var(--red); }
.device .watch { font-size: 12px; padding: 5px 10px; }

/* ---------- welfare timers ---------- */
.timer { border: 1px solid var(--line); border-radius: 14px; padding: 11px 12px; margin-bottom: 8px; background: var(--panel); box-shadow: var(--shadow); }
.timer-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.timer .nm { font-weight: 600; font-size: 13.5px; }
.timer .tleft { font-weight: 800; font-variant-numeric: tabular-nums; font-size: 17px; }
.timer .bar { height: 5px; border-radius: 999px; background: var(--btn-hover); margin-top: 9px; overflow: hidden; }
.timer .bar-fill { height: 100%; border-radius: 999px; background: var(--blue); transition: width 1s linear; }
.timer.low { border-color: var(--amber); }
.timer.low .tleft { color: var(--amber); }
.timer.low .bar-fill { background: var(--amber); }

/* ---------- map pins ---------- */
.pin { width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font: 700 11px "Inter", sans-serif; color: #fff; border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.35); }
.pin-on { background: #178A45; }
.pin-off { background: #93A1B0; }
.pin-alert { background: #D8342C; animation: pulse 1.2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(216,52,44,.55); } 100% { box-shadow: 0 0 0 16px rgba(216,52,44,0); } }

/* ---------- misc ---------- */
.quiet { color: var(--dim); font-size: 12px; }
.err { color: var(--red); font-size: 12px; min-height: 16px; margin-top: 6px; }
.hidden { display: none !important; }
textarea { width: 100%; resize: vertical; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--bg); color: var(--fg); padding: 10px 12px; font: inherit; }
textarea:focus, input:focus { outline: 2px solid var(--blue); outline-offset: 0; border-color: transparent; }

/* ---------- login ---------- */
.login { position: fixed; inset: 0; background: var(--hdr); z-index: 3000; display: flex; align-items: center; justify-content: center; }
.login-box { text-align: center; width: 310px; background: var(--panel); border-radius: 18px; padding: 34px 28px; box-shadow: 0 14px 44px rgba(0,0,0,.35); }
.login-box h1 { letter-spacing: 7px; margin-bottom: 2px; color: var(--fg); font-size: 24px; }
.login-box p { color: var(--dim); margin-bottom: 20px; }
.login-box input { width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--bg); color: var(--fg); margin-bottom: 10px; text-align: center; font-size: 16px; }
.login-box button { width: 100%; padding: 12px; font-size: 14.5px; background: #007278; border-color: #007278; color: #fff; font-weight: 700; }

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; background: rgba(8,12,18,.72); z-index: 2000; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(2px); }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; width: min(720px, 94vw); box-shadow: 0 18px 60px rgba(0,0,0,.4); }
.modal-hdr { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-weight: 700; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
#liveVideo { width: 100%; aspect-ratio: 4/3; background: #000; border-radius: 12px; }

.leaflet-container { font: inherit; }

/* ---------- v0.4: team assist ---------- */
.t-assist { background: var(--amber-soft); }
.alert.assist.active { border-color: var(--amber); animation: none; box-shadow: 0 0 0 3px var(--amber-soft), var(--shadow); }
.alert.assist.active .type { color: var(--amber); }
.chip.amber-solid { background: var(--amber); color: #fff; }

/* ---------- v0.4: readiness ---------- */
.device.not-ready { border-left: 4px solid var(--amber); }
h2 button.mini { font-size: 10px; padding: 3px 9px; letter-spacing: .5px; margin-left: 6px; text-transform: none; }
pre.report { max-height: 56vh; overflow: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 14px; font: 12px/1.6 ui-monospace, "SF Mono", Menlo, monospace; white-space: pre-wrap; }
.modal-box.wide { width: min(860px, 96vw); max-height: 92vh; overflow-y: auto; }

/* ---------- reports & analytics modal ---------- */
.report-modal { width: min(1120px, 95vw); height: min(860px, 92vh); max-height: 92vh; padding: 0; display: flex; flex-direction: column; overflow: hidden; }
.report-modal.fullscreen { width: 100vw; height: 100vh; max-height: 100vh; border-radius: 0; border: none; }
.report-hdr { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 20px; background: var(--hdr); color: var(--hdr-fg); flex: none; }
.report-title { display: flex; align-items: center; gap: 12px; font-weight: 800; letter-spacing: .5px; font-size: 15px; }
.report-hdr-actions { display: flex; align-items: center; gap: 8px; }
.report-hdr-actions select, .report-hdr-actions button { border: 1px solid rgba(255,255,255,.22); background: rgba(255,255,255,.07); color: var(--hdr-fg); border-radius: 9px; padding: 7px 12px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; transition: background .12s; }
.report-hdr-actions select:hover, .report-hdr-actions button:hover { background: rgba(255,255,255,.16); }
.report-hdr-actions select option { color: var(--fg); background: var(--panel); }
.report-body { flex: 1; overflow-y: auto; padding: 20px; }
.report-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }

/* ---------- v0.4: talkback + captions ---------- */
.video-tools { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
#talkBtn.talking { background: var(--green); border-color: var(--green); animation: escflash .6s infinite alternate; }
.captions { margin-top: 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 12.5px; max-height: 140px; overflow-y: auto; color: var(--fg); }
.captions div { padding: 2px 0; border-bottom: 1px dashed var(--line); }
.captions div:last-child { border-bottom: none; }
/* two-way conversation: who said what */
.cap-hs b { color: var(--blue); font-weight: 600; }
.cap-op b { color: var(--green); font-weight: 600; }
.convo { margin: 8px 0; }
.convo:empty { display: none; }
.convo-hdr { font-weight: 600; margin-bottom: 4px; }
.convo div:not(.convo-hdr) { padding: 2px 0; font-size: 12.5px; border-bottom: 1px dashed var(--line); }
.convo div:last-child { border-bottom: none; }

/* ---------- v0.4: incident + policies ---------- */
.media-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 12.5px; }
.media-row audio { height: 32px; flex: 1; }
.media-row.media-video { flex-wrap: wrap; }
.media-row.media-video video { flex-basis: 100%; max-height: 300px; background: #000; border-radius: 10px; }
.policy-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 6px; background: var(--bg); }
.policy-add { margin-top: 14px; }
.policy-add input, .policy-ask input { width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--bg); color: var(--fg); margin-bottom: 8px; font: inherit; }
.policy-ask { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: start; }
.policy-ask div { grid-column: 1 / -1; white-space: pre-wrap; }

/* ---------- v0.5: competitive parity (setup, reports, toasts) ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 14px; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.tab { background: transparent; border: 1px solid var(--line-strong); border-radius: 8px; padding: 6px 14px; font-size: 12.5px; }
.tab.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.tab-body h3.sub-h { font-size: 11px; text-transform: uppercase; letter-spacing: 2px; color: var(--dim); margin: 18px 2px 8px; }
.esc-level { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; background: var(--bg); }
.esc-hdr { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; font-size: 13px; }
.esc-hdr input, .contact-row input:not([type="checkbox"]), .inline-form input, .inline-form select {
  padding: 6px 9px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--panel); color: var(--fg); font: inherit; font-size: 12.5px;
}
.contact-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 5px 0; font-size: 12px; }
.contact-row label { display: flex; align-items: center; gap: 3px; color: var(--dim); }
.inline-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; font-size: 12.5px; color: var(--dim); }
.team-tag { font-size: 10px; background: var(--btn-hover); color: var(--dim); border-radius: 6px; padding: 1px 7px; font-weight: 600; vertical-align: middle; }
.rtls-chip { font-size: 10.5px; font-weight: 600; border-radius: 6px; padding: 1px 6px; margin-left: 5px; white-space: nowrap; vertical-align: middle; }
.rtls-chip.ok { background: var(--green-soft); color: var(--green); }
.rtls-chip.warn { background: var(--amber-soft); color: var(--amber); }
.rtls-chip.bad { background: var(--red-soft); color: var(--red); }
.warn-text { color: var(--amber); }
.report-kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 10px; margin-bottom: 18px; }
.rkpi { position: relative; border: 1px solid var(--line); border-left: 3px solid var(--line-strong); border-radius: 14px; padding: 13px 15px; background: var(--panel); box-shadow: var(--shadow); overflow: hidden; transition: transform .12s ease, box-shadow .12s ease; }
.rkpi:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,.14); }
.rkpi-ico { position: absolute; top: 11px; right: 12px; font-size: 15px; opacity: .5; }
.rkpi-num { font-size: 27px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.05; letter-spacing: -.5px; }
.rkpi-lbl { font-size: 10px; color: var(--dim); text-transform: uppercase; letter-spacing: .7px; font-weight: 600; margin-top: 3px; }
.rkpi--red { border-left-color: var(--red); } .rkpi--red .rkpi-num { color: var(--red); }
.rkpi--amber { border-left-color: var(--amber); } .rkpi--amber .rkpi-num { color: var(--amber); }
.rkpi--green { border-left-color: var(--green); } .rkpi--green .rkpi-num { color: var(--green); }
.rkpi--blue { border-left-color: var(--blue); } .rkpi--blue .rkpi-num { color: var(--blue); }
.btn-link { text-decoration: none; display: inline-block; padding: 7px 12px; border: 1px solid var(--line-strong); border-radius: 9px; color: var(--fg); font-size: 13px; font-weight: 600; }
.btn-link:hover { background: var(--btn-hover); }
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 4000; display: flex; flex-direction: column; gap: 8px; max-width: 380px; }
.toast { background: var(--panel); border: 1px solid var(--line-strong); border-left: 4px solid var(--green); border-radius: 12px; padding: 10px 14px; font-size: 12.5px; box-shadow: 0 6px 20px rgba(0,0,0,.25); transition: opacity .5s; }
.toast.warn { border-left-color: var(--amber); }
.toast.bad { border-left-color: var(--red); }
.toast.fade { opacity: 0; }

@media (max-width: 980px) {
  main { grid-template-columns: 1fr; grid-template-rows: auto 320px auto; }
  #alertPane, #devicePane { border: none; }
  .kpis { display: none; }
}

/* ---------- live activity feed ---------- */
.feed { max-height: 340px; overflow-y: auto; }
.feed-item { border-bottom: 1px solid var(--line); padding: 6px 2px; font-size: 12px; line-height: 1.45; }
.feed-item:last-child { border-bottom: none; }
.feed-item .when { color: var(--dim); font-variant-numeric: tabular-nums; margin-right: 6px; }
.feed-item .what { font-weight: 600; }
.feed-item .who { color: var(--dim); }

/* ---------- welfare check register (reports) ---------- */
.register { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
.register table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.register th, .register td { text-align: left; padding: 9px 13px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.register th { color: var(--dim); font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; background: var(--bg); position: sticky; top: 0; z-index: 1; }
.register tr:last-child td { border-bottom: none; }
.register tbody tr:nth-child(even) td, .register tr:nth-child(even) td { background: rgba(127,140,160,.05); }
.register tr:hover td { background: var(--btn); }
.register .oc-completed { color: var(--green); font-weight: 700; }
.register .oc-active { color: var(--blue); font-weight: 700; }
.register .oc-missed, .register .oc-comms_lost { color: var(--red); font-weight: 700; }

/* ---------- users & teams tab ---------- */
.setup-card { border: 1px solid var(--line); border-radius: 14px; background: var(--bg); padding: 14px 16px; margin-bottom: 20px; }
.setup-card-hdr { font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--dim); font-weight: 700; margin-bottom: 12px; }
.stack > * + * { margin-top: 6px; }
.login-row, .staff-row { display: flex; align-items: center; gap: 10px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.lg-name, .st-name { font-weight: 600; font-size: 13.5px; }
.lg-user { color: var(--dim); font-size: 12px; }
.role-tag { font-size: 9.5px; text-transform: uppercase; letter-spacing: .5px; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--btn-hover); color: var(--dim); }
.role-admin { background: var(--red-soft); color: var(--red); }
.role-manager { background: var(--blue-soft); color: var(--blue); }
.role-operator { background: var(--green-soft); color: var(--green); }
.st-status { font-size: 11px; color: var(--dim); }
.st-status.on { color: var(--green); }
.login-row .teamselect, .staff-row .teamselect { margin-left: auto; }
.teamselect { padding: 6px 9px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--panel); color: var(--fg); font: inherit; font-size: 12.5px; cursor: pointer; }
.addrow { margin-top: 14px; }
.teams-hdr { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 4px 2px 14px; }
.teams-hdr h3.sub-h { margin: 0; }
.team-card { border: 1px solid var(--line); border-radius: 14px; margin-bottom: 12px; overflow: hidden; background: var(--panel); box-shadow: var(--shadow); }
.team-card-hdr { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 15px; background: var(--bg); border-bottom: 1px solid var(--line); }
.team-name { font-weight: 700; font-size: 14px; }
.team-meta { font-size: 11.5px; color: var(--dim); font-weight: 600; }
.team-card-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.team-logins { font-size: 12px; color: var(--dim); margin-bottom: 2px; }
.chip-soft { background: var(--btn-hover); border-radius: 6px; padding: 2px 8px; font-size: 11.5px; color: var(--fg); white-space: nowrap; }
.team-empty { color: var(--dim); font-size: 12.5px; font-style: italic; padding: 2px; }

/* ---------- zone map picker ---------- */
.zone-draw-btn { width: 100%; padding: 15px; font-size: 14.5px; margin-top: 8px; }
.zone-picker { position: fixed; inset: 0; z-index: 1500; pointer-events: none; }
.zp-banner { position: absolute; top: 80px; left: 50%; transform: translateX(-50%); background: var(--hdr); color: var(--hdr-fg); padding: 11px 20px; border-radius: 999px; font-size: 13px; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,.4); pointer-events: auto; display: flex; align-items: center; gap: 14px; max-width: 92vw; }
.zp-banner button { border: 1px solid rgba(255,255,255,.3); background: rgba(255,255,255,.1); color: #fff; border-radius: 8px; padding: 4px 10px; font-size: 12px; font-weight: 600; }
.zp-card { position: absolute; bottom: 28px; left: 50%; transform: translateX(-50%); width: min(430px, 92vw); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 18px 60px rgba(0,0,0,.45); padding: 18px; pointer-events: auto; display: flex; flex-direction: column; gap: 14px; }
.zp-card h4 { font-size: 13px; font-weight: 700; }
.zp-row { display: flex; flex-direction: column; gap: 7px; }
.zp-row.zp-timer { flex-direction: row; align-items: center; gap: 8px; font-size: 12.5px; color: var(--dim); }
.zp-card input { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--bg); color: var(--fg); font: inherit; }
.zp-card input[type=number] { width: 72px; padding: 8px 10px; }
.zp-card input[type=range] { padding: 0; border: none; background: transparent; accent-color: var(--red); width: 100%; }
.zp-slider label { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; color: var(--dim); }
.zp-slider label b { color: var(--fg); font-variant-numeric: tabular-nums; }
.zp-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 2px; }
.zone-pin { font-size: 27px; line-height: 1; filter: drop-shadow(0 2px 3px rgba(0,0,0,.45)); cursor: grab; }
.zone-pin:active { cursor: grabbing; }

/* ---- analytics dashboard (P1) ---- */
.report-charts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 18px; }
@media (max-width: 720px) { .report-charts { grid-template-columns: 1fr; } }
.chart-card { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); padding: 14px 16px; }
.chart-card.span2 { grid-column: 1 / -1; }
.chart-card h4 { margin: 0 0 12px; font-size: 12px; text-transform: uppercase; letter-spacing: .7px; color: var(--dim); font-weight: 700; }
.chart-empty { color: var(--dim); font-size: 13px; padding: 10px 0; }
.vbars { display: flex; align-items: flex-end; gap: 3px; height: 120px; }
.vbar { flex: 1 1 0; background: var(--blue); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; opacity: .85; }
.vbar:hover { opacity: 1; }
.vbars-axis { display: flex; justify-content: space-between; font-size: 10px; color: var(--dim); margin-top: 6px; }
.zbar-row { display: grid; grid-template-columns: 120px 1fr 34px; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 13px; }
.zbar-name { color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.zbar-track { background: var(--line); border-radius: 999px; height: 12px; overflow: hidden; }
.zbar-fill { height: 100%; border-radius: 999px; background: var(--red); }
.zbar-val { text-align: right; font-variant-numeric: tabular-nums; color: var(--dim); font-weight: 700; }
.resp-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.resp-table th { text-align: left; color: var(--dim); font-size: 10px; text-transform: uppercase; letter-spacing: .6px; padding: 4px 8px; border-bottom: 1px solid var(--line); }
.resp-table td { padding: 7px 8px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.resp-table tr:last-child td { border-bottom: none; }

/* ---------- coercion (duress PIN on cancel, v0.15) ---------- */
.coerced-badge { display: inline-block; background: #C62E2E; color: #fff; font-size: 10.5px; font-weight: 800; letter-spacing: 1px; padding: 2px 8px; border-radius: 6px; margin-right: 6px; vertical-align: middle; animation: escflash .6s infinite alternate; }
.alert.coerced { border: 2px solid #C62E2E; }
.coerced-note { background: var(--red-soft); color: var(--red); border: 1px solid var(--red); border-radius: 10px; padding: 8px 10px; font-size: 12.5px; font-weight: 600; margin: 8px 0; }
.toast.coerced { background: #C62E2E; color: #fff; border-color: #8F1F1A; font-weight: 700; font-size: 13.5px; }

/* ---------- incident replay (v0.15) ---------- */
.replay-map { height: 340px; border-radius: 12px; border: 1px solid var(--line); }
[data-theme="dark"] .replay-map .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.95) contrast(.9); }
.replay-indoor { min-height: 18px; margin-top: 6px; }
.replay-controls { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.replay-controls #replayScrub { flex: 1; }
.replay-speeds { display: flex; gap: 4px; }
.replay-speeds button.active { background: var(--red); border-color: var(--red); color: #fff; }
.replay-clock { font-variant-numeric: tabular-nums; margin-top: 4px; }
.replay-timeline { max-height: 30vh; overflow-y: auto; margin-top: 8px; border: 1px solid var(--line); border-radius: 12px; }
.rp-row { display: flex; gap: 10px; padding: 5px 10px; font-size: 12.5px; border-bottom: 1px dashed var(--line); cursor: pointer; opacity: .5; }
.rp-row:last-child { border-bottom: none; }
.rp-row.past { opacity: 1; }
.rp-row.now { background: var(--btn-hover); }
.rp-row.rp-coerced .rp-what { color: var(--red); font-weight: 700; }
.rp-t { font-variant-numeric: tabular-nums; color: var(--dim); flex: none; width: 56px; }
.rp-what { flex: none; font-weight: 600; }
.rp-detail { color: var(--dim); min-width: 0; overflow-wrap: anywhere; }

/* ---------- v0.16 comms: broadcast, roll call, messages ---------- */
.ctab { background: transparent; border: 1px solid var(--line-strong); border-radius: 8px; padding: 6px 14px; font-size: 12.5px; }
.ctab.active { background: var(--red); border-color: var(--red); color: #fff; }
.comms input.full, .comms .ctab-body textarea { width: 100%; margin-top: 10px; }
.comms input:not([type="checkbox"]), .comms select { padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--panel); color: var(--fg); font: inherit; font-size: 12.5px; }
.comms label.chk { display: inline-flex; align-items: center; gap: 6px; }
.team-picks { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; font-size: 12.5px; color: var(--dim); align-items: center; }
.team-picks label { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line-strong); border-radius: 8px; padding: 4px 9px; cursor: pointer; color: var(--fg); }
.bc-card, .rc-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; background: var(--panel); }
.bc-card.p-emergency { border-left: 4px solid var(--red); }
.bc-card.p-urgent { border-left: 4px solid var(--amber); }
.bc-card.p-normal { border-left: 4px solid var(--blue); }
.bc-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.bc-top .grow { flex: 1; }
.prio { font-size: 10px; font-weight: 800; letter-spacing: 1px; padding: 2px 7px; border-radius: 6px; text-transform: uppercase; }
.prio.emergency { background: var(--red); color: #fff; }
.prio.urgent { background: var(--amber); color: #fff; }
.prio.normal { background: var(--blue-soft); color: var(--blue); }
.prio.ended { background: var(--btn-hover); color: var(--dim); }
.bc-body { margin: 6px 0; white-space: pre-wrap; font-size: 13px; }
.bc-counts { font-size: 12px; color: var(--dim); }
.bc-counts b { color: var(--fg); }
.comms details summary { cursor: pointer; font-size: 12px; color: var(--dim); margin-top: 6px; }
.comms .register td.yes { color: var(--green); font-weight: 600; }
.comms .register td.no { color: var(--dim); }
.tally { display: flex; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.tally div { flex: 1; min-width: 90px; border-radius: 10px; padding: 8px 10px; text-align: center; background: var(--btn); }
.tally b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.tally span { font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; color: var(--dim); }
.tally .t-safe { background: var(--green-soft); color: var(--green); }
.tally .t-help { background: var(--red-soft); color: var(--red); }
.tally .t-none { background: var(--amber-soft); color: var(--amber); }
.rc-entry.overdue td { background: var(--amber-soft) !important; }
.rc-entry.help td { background: var(--red-soft) !important; color: var(--red); font-weight: 700; }
.rc-state { font-weight: 700; }
.rc-state.safe { color: var(--green); }
.rc-state.help { color: var(--red); }
.rc-state.no_response { color: var(--amber); }
.rc-state.offline { color: var(--dim); }
.pill.warn { background: var(--amber); }
button.pill { border: none; cursor: pointer; }
.tpl-row { display: grid; grid-template-columns: 160px 130px 1fr auto; gap: 8px; align-items: start; }
.tpl-row textarea { min-height: 38px; padding: 7px 10px; font-size: 12.5px; }
.chat-list { max-height: 50vh; min-height: 160px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 10px; background: var(--bg); border-radius: 12px; border: 1px solid var(--line); }
.chat-msg { max-width: 80%; padding: 8px 11px; border-radius: 12px; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-msg.out { align-self: flex-end; background: var(--blue); color: #fff; }
.chat-msg.in { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); }
.chat-msg small { display: block; font-size: 10.5px; opacity: .75; margin-top: 2px; }
.device .ubadge { display: inline-block; min-width: 16px; padding: 0 5px; margin-left: 3px; border-radius: 8px; background: var(--red); color: #fff; font-size: 10px; line-height: 16px; text-align: center; }
@media (max-width: 640px) { .tpl-row { grid-template-columns: 1fr; } }

/* 1.4 location hazard register + 1.5 worker's account */
.hz-chip { font-size: 10.5px; font-weight: 700; border-radius: 6px; padding: 1px 6px; margin-left: 5px; white-space: nowrap; vertical-align: middle; background: var(--blue-soft); color: var(--blue); }
.hz-chip.caution { background: var(--amber-soft); color: var(--amber); }
.hz-chip.high { background: var(--red); color: #fff; }
.zone-entry { margin-bottom: 6px; }
.zone-entry .policy-row { margin-bottom: 0; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.zone-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1 1 260px; }
.zone-notes { font-size: 12.5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.zone-acts { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; flex: 0 1 auto; }
.zone-edit, .zone-hist { border: 1px solid var(--line); border-top: none; border-radius: 0 0 10px 10px; padding: 10px; background: var(--panel); }
.zone-edit-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; font-size: 12.5px; }
.zone-edit-row label { display: flex; gap: 6px; align-items: center; }
.zone-edit textarea { width: 100%; }
.zone-hist { max-height: 240px; overflow-y: auto; }
.zone-hist tr.hz-unsafe td { color: var(--red); }
.hz-settings { margin-top: 14px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; }
.hz-settings label { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.zp-risk select, .zp-row textarea { width: 100%; }
.convo.debrief { border-left: 4px solid var(--blue); padding-left: 10px; }
.convo.debrief div:not(.convo-hdr) { border-bottom: none; padding: 0; }
.convo.debrief .debrief-row { padding: 6px 0; border-bottom: 1px dashed var(--line); display: flex; flex-direction: column; gap: 4px; }
.convo.debrief .debrief-row:last-child { border-bottom: none; }
.debrief-text { font-size: 13px; white-space: pre-wrap; }
.debrief-row audio { width: 100%; max-width: 420px; height: 32px; }

/* 1.7 SSO + MFA */
#userChip { cursor: pointer; border: 0; }
.login-box .sso-btn { display: block; margin-top: 10px; padding: 12px; border-radius: 10px; border: 1px solid var(--line-strong); color: var(--fg); background: var(--bg); font-weight: 700; font-size: 14.5px; text-decoration: none; }
.login-box .sso-btn.hidden { display: none; }
.login-box .mfa-lead { font-size: 13.5px; margin-bottom: 12px; }
.login-box .mfa-link { display: block; font-weight: 700; color: var(--red); margin-bottom: 8px; word-break: break-all; }
.login-box .mfa-secret { font-size: 12px; color: var(--dim); margin-bottom: 12px; word-break: break-all; }
.login-box .mfa-secret code { font-size: 13px; letter-spacing: 1px; color: var(--fg); }
#tab-security .setup-card { margin-bottom: 14px; }
#tab-security label { display: block; margin: 8px 0; }
.chain-ok { color: var(--green); font-weight: 700; }
.chain-bad { color: var(--red); font-weight: 700; }
.mfa-tag { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--green); color: #fff; }
.mfa-tag.off { background: var(--line-strong); color: var(--fg); }
.via-sms { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--amber); color: #fff; margin-left: 6px; }

/* 2.3 beacons, 2.4 shift login, 2.5 peer response */
.ok-text { color: var(--green); }
.wearer-chip { font-size: 10.5px; font-weight: 600; border-radius: 6px; padding: 1px 6px; margin-left: 5px; white-space: nowrap; vertical-align: middle; background: var(--blue-soft); color: var(--blue); }
.wearer-chip.none { background: var(--amber-soft); color: var(--amber); }
.loc-lead { font-size: 9.5px; font-weight: 800; letter-spacing: .5px; border-radius: 5px; padding: 1px 5px; background: var(--blue); color: #fff; vertical-align: middle; }
.meta.peers { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; }
.peer-chip { font-size: 11px; border: 1px solid var(--line); border-radius: 8px; padding: 1px 7px; background: var(--bg); white-space: nowrap; }
.peer-chip.coming { border-color: var(--green); background: var(--green-soft); }
.peer-chip.cant { opacity: .75; }

.note.noloc { color: var(--amber); }

/* live video docked in the corner: no dimmed backdrop, map stays usable */
#videoModal.docked { inset: auto 16px 16px auto; background: none; backdrop-filter: none; display: block; pointer-events: none; }
#videoModal.docked.hidden { display: none; }
#videoModal.docked .modal-box { width: 380px; max-width: calc(100vw - 32px); padding: 10px; pointer-events: auto; box-shadow: 0 12px 40px rgba(0,0,0,.45); }
#videoModal.docked .modal-hdr { font-size: 13px; margin-bottom: 8px; gap: 8px; flex-wrap: wrap; }
#videoModal.docked .modal-hdr button { padding: 4px 8px; font-size: 12px; }
#videoModal.docked .captions { max-height: 90px; }

/* ---------- smaller windows: the header tightens in stages and never pushes the page wider ---------- */
header { flex-wrap: wrap; row-gap: 10px; min-width: 0; }
.brand, .kpis, .hdr-right { min-width: 0; }
.hdr-right { flex-wrap: wrap; justify-content: flex-end; margin-left: auto; }
main { min-width: 0; }
@media (max-width: 1500px) {
  header { gap: 16px; padding: 12px 16px; }
  .brand-name { font-size: 14px; letter-spacing: 3px; }
  .kpis { gap: 8px; }
  .kpi { padding: 6px 10px; }
  .kpi-lbl { font-size: 10px; letter-spacing: .4px; }
  .hdr-right { gap: 6px; }
  .hdr-right .ghost { padding-left: 9px; padding-right: 9px; }
}
@media (max-width: 1320px) {
  .kpi { flex-direction: column; align-items: center; gap: 0; padding: 3px 10px; line-height: 1.15; }
  .kpi-num { font-size: 16px; }
  .kpi-lbl { font-size: 9px; }
  .mute-lbl { display: none; }
}
@media (max-width: 1100px) {
  .brand-site { display: none; }
  .brand img { height: 30px !important; }
  .brand-name { font-size: 12px; letter-spacing: 2px; }
}
@media (min-width: 981px) and (max-width: 1320px) { main { grid-template-columns: 290px 1fr 270px; } }
@media (min-width: 981px) and (max-width: 1100px) { main { grid-template-columns: 250px 1fr 230px; } }
/* phone/tablet: one column, the whole page scrolls instead of squashing each panel */
@media (max-width: 980px) { main { overflow-y: auto; } aside { overflow-y: visible; } }

/* map popup for a person: name, status, quick actions */
.dev-pop { min-width: 210px; font: 13px/1.4 "Inter", -apple-system, sans-serif; }
.dev-pop-name { font-weight: 800; font-size: 14px; }
.dev-pop-sub { color: #5E6B7A; font-size: 12px; margin: 2px 0 8px; }
.dev-pop-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.dev-pop-actions button { padding: 7px 8px; font-size: 12.5px; border: 1px solid #DDE6ED; border-radius: 8px; background: #F6F9FB; color: #202C3B; cursor: pointer; }
.dev-pop-actions button:hover:not(:disabled) { border-color: #007278; color: #007278; }
.dev-pop-actions button:disabled { opacity: .45; cursor: not-allowed; }

/* device rows: in a narrow column the buttons drop under the name instead of crushing it */
.device { flex-wrap: wrap; }
.device .dev-main { min-width: 110px; }
.device .nm { overflow-wrap: normal; word-break: normal; }

.cam-pin { width: 26px; height: 26px; border-radius: 50%; background: var(--panel); border: 1px solid var(--line-strong); display: flex; align-items: center; justify-content: center; font-size: 13px; box-shadow: var(--shadow); cursor: pointer; }

.note.distress { border-left: 3px solid var(--red); color: var(--fg); }

.switch-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 8px 0; font-size: 13px; }
.switch-row select, .switch-row input[type=number] { padding: 5px 8px; }

/* =====================================================================
   WillowCreek Brand and Theme Guide v1.0 (3 Nov 2026), theme k values.
   Applied 23 Nov 2026. Later rules win, so this block is the source of truth.
   - system fonts only, mono for data readouts
   - flat: 1px borders, no shadows; cards 16px, controls 10px, buttons 9px
   - labels on Action Teal are dark (#041018); on light, Deep Teal with white
   - red is reserved for duress: strong fill #DC2626 behind white text,
     #FF6E70 only for red text and borders on dark
   ===================================================================== */
:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  /* light (theme k Light) */
  --bg: #F6F9FB; --panel: #FFFFFF; --line: #DDE6ED; --line-strong: #7B8A99;
  --fg: #202C3B; --dim: #5E6B7A;
  --btn: #F6F9FB; --btn-hover: #EBF1F8;
  --blue: #007278; --blue-soft: #E3F5F4; --eyebrow: #007278;
  --action: #007278; --action-hover: #00BDB5; --on-action: #FFFFFF;
  --red: #DC2626; --red-fill: #DC2626; --red-soft: #FDECEC;
  --amber: #F59E0B; --amber-soft: #FFF4E2; --on-amber: #041018;
  --green: #047857; --green-soft: #E7F6EC;
  --info: #3FB8E8;
  --shadow: none;
  --hdr: #0A111B; --hdr-fg: #F6F9FB;
}
:root[data-theme="dark"] {
  /* dark (theme k Dark) */
  --bg: #0A111B; --panel: #111A26; --line: #2C3A4A; --line-strong: #6E7F91;
  --fg: #F6F9FB; --dim: #AEBBC9;
  --btn: #1A2634; --btn-hover: #22303F;
  --blue: #00CCC0; --blue-soft: #06302F; --eyebrow: #00CCC0;
  --action: #00BDB5; --action-hover: #00CCC0; --on-action: #041018;
  --red: #FF6E70; --red-fill: #DC2626; --red-soft: #3A1416;
  --amber: #FFA734; --amber-soft: #33270D; --on-amber: #041018;
  --green: #2FC97D; --green-soft: #102917;
  --shadow: none;
  --hdr: #0A111B; --hdr-fg: #F6F9FB;
}
body, input, select, textarea, button { font-family: var(--font-sans); }
.kpi-num, .timer, .feed-item .when, .alert-id, .countdown, [class*="mono"] { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
h1, h2, h3, .brand-name { letter-spacing: -0.015em; }
.brand-name { letter-spacing: 0.14em; }
/* eyebrow labels: short capitals in teal */
h2 { color: var(--eyebrow); font-size: 11.5px; letter-spacing: 0.14em; }
/* flat surfaces */
.alert, .device, .card, .setup-card, .modal-box, .login-box, .kpi, .policy-row { box-shadow: none; }
.alert, .device, .card, .setup-card, .modal-box, .login-box { border-radius: 16px; }
input, select, textarea, .chip, .note, .toast { border-radius: 10px; }
button { border-radius: 9px; }
button.pill, .pill { border-radius: 999px; }
/* buttons: primary is teal; danger is the duress red fill; warn is amber with a dark label */
button.ok, .login-box button { background: var(--action); border-color: var(--action); color: var(--on-action); }
button.ok:hover, .login-box button:hover { background: var(--action-hover); border-color: var(--action-hover); color: #041018; }
button.danger { background: var(--red-fill); border-color: var(--red-fill); color: #FFFFFF; }
button.warn { background: var(--amber); border-color: var(--amber); color: var(--on-amber); }
.danger-text { color: var(--red); }
.pin-alert, .coerced-badge, .toast.coerced { background: var(--red-fill); color: #FFFFFF; }
.alert.coerced { border-color: var(--red-fill); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(220,38,38,.55); } 100% { box-shadow: 0 0 0 16px rgba(220,38,38,0); } }
a { color: var(--blue); }
.pill { font-family: var(--font-sans); }

/* ---------- Site setup window: calmer layout (2026-11-24) ---------- */
#setupModal .modal-box { width: min(1100px, 96vw); max-height: 90vh; padding: 0; display: flex; flex-direction: column; overflow: hidden; }
#setupModal .modal-hdr { padding: 20px 24px 4px; margin: 0; font-size: 20px; letter-spacing: -0.015em; }
#setupModal .close-x { width: 36px; height: 36px; padding: 0; display: inline-flex; align-items: center; justify-content: center; font-size: 16px; border-color: var(--line); color: var(--dim); }
#setupModal .close-x:hover { color: var(--fg); border-color: var(--line-strong); }
/* tabs: one line of text links with a teal underline, scrolls sideways on small screens */
#setupModal .tabs { flex: none; gap: 2px; margin: 0; padding: 0 16px; border-bottom: 1px solid var(--line); overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
#setupModal .tabs::-webkit-scrollbar { display: none; }
#setupModal .tab { flex: none; white-space: nowrap; background: transparent; border: 0; border-bottom: 2px solid transparent; border-radius: 0; padding: 14px 10px 12px; margin-bottom: -1px; font-size: 14px; font-weight: 600; color: var(--dim); }
#setupModal .tab:hover { background: transparent; color: var(--fg); }
#setupModal .tab:active { transform: none; }
#setupModal .tab.active { background: transparent; color: var(--fg); border-bottom-color: var(--action); }
#setupModal .tab:focus-visible { outline: 2px solid var(--action); outline-offset: -2px; }
/* body scrolls, the header and tabs stay put */
#setupModal .tab-body { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 20px 24px 24px; }
#setupModal .tab-body > p.quiet:first-child { font-size: 14px; line-height: 1.6; max-width: 75ch; margin: 0 0 18px; color: var(--dim); }
#setupModal .tab-body p.quiet { font-size: 13.5px; line-height: 1.6; }
#setupModal .setup-card { background: var(--bg); border: 1px solid var(--line); border-radius: 16px; padding: 20px; margin: 0 0 16px; }
#setupModal .setup-card-hdr { font-size: 13px; letter-spacing: 0.14em; color: var(--eyebrow); margin-bottom: 14px; }
#setupModal .empty { padding: 22px; border: 1px dashed var(--line-strong); background: var(--bg); margin-bottom: 16px; font-size: 14px; }
#setupModal .modal-actions { margin-top: 16px; align-items: center; }
#setupModal label { font-size: 14px; }
/* every text box and dropdown the same height */
#setupModal input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), #setupModal select {
  height: 40px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--panel); color: var(--fg); font: inherit; font-size: 14px; }
#setupModal input:focus, #setupModal select:focus { outline: none; border-color: var(--action); box-shadow: 0 0 0 3px var(--blue-soft); }
#setupModal .inline-form { gap: 10px 12px; font-size: 14px; margin-top: 14px; }
#setupModal button { min-height: 40px; padding: 0 18px; font-size: 14px; }
#setupModal button.mini { min-height: 34px; padding: 0 14px; font-size: 13px; }
/* labelled field grid */
.field-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px 16px; }
.field-grid.cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
@media (max-width: 860px) { .field-grid, .field-grid.cols-6 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.wide { grid-column: span 2; }
.field > span:first-child { font-size: 12.5px; font-weight: 600; color: var(--dim); }
.field input, .field select, .field button { width: 100%; }
.field .unit { display: flex; align-items: center; position: relative; }
.field .unit input { padding-right: 46px; }
.field .unit i { position: absolute; right: 12px; font-style: normal; font-size: 13px; color: var(--dim); pointer-events: none; }
@media (max-width: 560px) {
  #setupModal .modal-box { width: 100vw; max-height: 100vh; height: 100vh; border-radius: 0; }
  #setupModal .tab-body { padding: 16px; }
  .field.wide { grid-column: 1 / -1; }
  .field-grid { grid-template-columns: 1fr 1fr; }
}

/* ---------- Site setup: shared pieces for every tab (2026-11-24, pass 2) ---------- */
.field-grid.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
@media (max-width: 860px) { .field-grid.cols-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.field.full { grid-column: 1 / -1; }
.field.hidden { display: none; }
.field-grid + .field-grid, .check + .field-grid, .field-grid + .check { margin-top: 14px; }
.field-sub { font-size: 12.5px; font-weight: 700; color: var(--fg); margin: 20px 0 10px; }
.setup-card > .field-sub:first-child, .esc-section > .field-sub:first-child { margin-top: 0; }
.hint-cell .quiet { height: 40px; display: flex; align-items: center; font-size: 13px; }
#setupModal .setup-card > p.quiet { margin: 0 0 14px; }
/* checkboxes */
#setupModal input[type="checkbox"] { width: 18px; height: 18px; margin: 0; accent-color: var(--action); flex: none; cursor: pointer; }
#setupModal label.check { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--fg); margin: 0 0 10px; cursor: pointer; line-height: 1.4; }
#setupModal .field label.check { height: 40px; margin: 0; }
.check-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.check-row label.check { margin: 0 !important; }
#setupModal label.chip-check { border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px 7px 10px; background: var(--panel); font-size: 13.5px; }
#setupModal label.chip-check:has(input:checked) { border-color: var(--action); background: var(--blue-soft); }
.field .check-row { min-height: 40px; }
/* trigger rows */
#setupModal .switch-row { gap: 10px; margin: 12px 0; font-size: 14px; }
#setupModal .switch-row .unit { width: 120px; }
.unit { display: inline-flex; align-items: center; position: relative; }
.unit input { width: 100%; padding-right: 46px !important; }
.unit i { position: absolute; right: 12px; font-style: normal; font-size: 13px; color: var(--dim); pointer-events: none; }
/* action rows */
#setupModal .modal-actions .spacer { flex: 1; }
#setupModal .modal-actions.start { justify-content: flex-start; margin: 0 0 16px; }
/* teams */
#setupModal .teams-hdr { margin: 24px 0 14px; }
.team-create { display: flex; gap: 10px; align-items: center; }
.team-create input { width: 260px; }
#setupModal .team-card { border-radius: 16px; }
#setupModal .team-card-hdr { padding: 14px 18px; }
#setupModal .team-card-body { padding: 14px 18px; }
/* escalation levels */
#setupModal .esc-level { border: 1px solid var(--line); border-radius: 16px; background: var(--bg); padding: 18px 20px; margin-bottom: 14px; }
#setupModal .esc-hdr { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin: 0 0 16px; padding-bottom: 14px; border-bottom: 1px solid var(--line); font-size: 14px; }
.esc-title { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.esc-num { width: 28px; height: 28px; border-radius: 50%; background: var(--action); color: var(--on-action); display: inline-flex; align-items: center; justify-content: center; font: 700 13px var(--font-mono); }
.esc-after { display: flex; align-items: center; gap: 10px; color: var(--dim); }
.esc-after .unit { width: 120px; }
.esc-remove { margin-left: auto; }
#setupModal .esc-remove:hover { color: var(--red); border-color: var(--red); background: transparent; }
.esc-section + .esc-section { margin-top: 18px; }
.esc-none { font-size: 13.5px; margin: 0 0 10px; }
#setupModal .contact-row { display: grid; grid-template-columns: 1.1fr 1.1fr 1.4fr auto 40px; gap: 10px; align-items: center; margin: 0 0 8px; font-size: 13px; }
#setupModal .contact-row input { width: 100%; min-width: 0; }
#setupModal .contact-head { margin-bottom: 6px; font-size: 12.5px; font-weight: 600; color: var(--dim); }
.chan-toggles { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 10px; overflow: hidden; height: 40px; }
.chan-toggles label.chan { display: flex; align-items: center; gap: 6px; padding: 0 12px; font-size: 13px; font-weight: 600; color: var(--dim); cursor: pointer; background: var(--panel); }
.chan-toggles label.chan + label.chan { border-left: 1px solid var(--line); }
.chan-toggles label.chan input { width: 15px !important; height: 15px !important; }
.chan-toggles label.chan:has(input:checked) { background: var(--blue-soft); color: var(--fg); }
#setupModal button.icon-btn { width: 40px; padding: 0; color: var(--dim); }
#setupModal button.icon-btn:hover { color: var(--red); border-color: var(--red); background: transparent; }
#setupModal button.add-contact { min-height: 36px; padding: 0 14px; font-size: 13px; border-style: dashed; }
@media (max-width: 760px) {
  #setupModal .contact-row { grid-template-columns: 1fr 1fr; }
  #setupModal .contact-head { display: none; }
  .esc-remove { margin-left: 0; }
}
#setupModal .contact-head span { text-align: left; }
#setupModal .modal-box { height: min(860px, 90vh); }
#setupModal .zone-draw-btn { width: auto; }
@media (max-width: 560px) {
  #setupModal .modal-box { height: 100vh; height: 100dvh; max-height: none; }
}
@media (max-width: 760px) {
  #setupModal .contact-row { grid-template-columns: minmax(0, 1fr) 40px; }
  #setupModal .contact-row > input { grid-column: 1 / -1; }
  #setupModal .contact-row > .chan-toggles { grid-column: 1; justify-self: start; }
  #setupModal .contact-row > .icon-btn { grid-column: 2; }
  #setupModal .contact-row { padding-bottom: 12px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
}

/* ---------- header: one calm row (2026-11-24) ---------- */
header { flex-wrap: nowrap; gap: 24px; padding: 0 20px; height: 64px; background: #0A111B; border-bottom: 1px solid #2C3A4A; }
header .brand { flex: none; gap: 11px; }
header .brand img { height: 32px !important; width: auto; }
header .brand-name { font-size: 13px; font-weight: 700; letter-spacing: 0.14em; line-height: 1.2; color: #F6F9FB; }
header .brand-site { font-size: 12px; color: #93A1B0; font-weight: 500; }
/* counts: plain figures with a label, divided by hairlines, no boxes */
header .kpis { gap: 0; margin-left: auto; align-items: center; }
header .kpi { background: transparent; border: 0; border-radius: 0; padding: 0 18px; display: flex; flex-direction: column; align-items: flex-start; gap: 1px; line-height: 1.15; position: relative; }
header .kpi + .kpi { border-left: 1px solid #2C3A4A; }
header .kpi-num { font: 700 18px/1.15 var(--font-mono); color: #F6F9FB; }
header .kpi-lbl { font-size: 11.5px; color: #93A1B0; text-transform: none; letter-spacing: 0; font-weight: 500; }
header .kpi.hot { background: transparent; border-color: #2C3A4A; }
header #kpiActiveWrap.hot .kpi-num { color: #FF6E70; }
header #kpiActiveWrap.hot .kpi-lbl { color: #FF6E70; }
header #kpiActiveWrap.hot::before { content: ""; position: absolute; left: 6px; top: 7px; width: 6px; height: 6px; border-radius: 50%; background: #FF6E70; animation: livedot 1.7s ease-out infinite; }
header #kpiReadyWrap.hot .kpi-num { color: #FFA734; }
/* right side */
header .hdr-right { flex: none; flex-wrap: nowrap; gap: 10px; margin-left: 8px; }
header .pill { height: 30px; padding: 0 12px; gap: 7px; border-radius: 999px; font-size: 12.5px; font-weight: 600; letter-spacing: 0; text-transform: none; background: transparent; border: 1px solid #2C3A4A; color: #AEBBC9; white-space: nowrap; }
header .pill svg { width: 15px; height: 15px; flex: none; }
header #connState { color: #2FC97D; border-color: rgba(47, 201, 125, .35); }
header #connState:not(.off)::before { width: 7px; height: 7px; background: #2FC97D; }
header #connState.off { color: #FF6E70; border-color: rgba(255, 110, 112, .4); background: transparent; }
header #connState.off::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #FF6E70; }
header #rcPill { cursor: pointer; color: #F6F9FB; }
header #rcPill:hover { background: #1A2634; }
header #rcPill.warn { border-color: #FFA734; color: #FFA734; background: transparent; }
header #rcPill.off { background: #DC2626; border-color: #DC2626; color: #FFFFFF; }
header #rcPill.off:hover { background: #B91C1C; }
header .hdr-tools { display: flex; align-items: center; gap: 2px; padding-left: 10px; border-left: 1px solid #2C3A4A; }
header button.hdr-icon { width: 36px; height: 36px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 9px; background: transparent; color: #AEBBC9; }
header button.hdr-icon:hover { background: #1A2634; color: #F6F9FB; border-color: #2C3A4A; }
header button.hdr-icon:focus-visible, header #userChip:focus-visible, header #rcPill:focus-visible { outline: 2px solid #00CCC0; outline-offset: 2px; }
header button.hdr-icon.is-muted { color: #FF6E70; }
header #userChip { display: inline-flex; align-items: center; gap: 9px; height: 40px; padding: 0 12px 0 4px; border: 1px solid transparent; border-radius: 999px; background: transparent; color: #F6F9FB; cursor: pointer; font-size: 13px; font-weight: 600; }
header #userChip.hidden { display: none; }
header #userChip:hover { background: #1A2634; border-color: #2C3A4A; }
header #userChip .avatar { width: 32px; height: 32px; border-radius: 50%; background: #007278; color: #FFFFFF; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; letter-spacing: .02em; flex: none; }
header #userChip .user-name { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.2; }
header #userChip small { font-size: 11px; color: #93A1B0; font-weight: 500; }
/* narrower windows: drop words before anything wraps */
@media (max-width: 1400px) { header #userChip .user-name { display: none; } header #userChip { padding: 0 4px; } }
@media (max-width: 1250px) { header .kpi { padding: 0 12px; } header #privacyPill span { display: none; } }
@media (max-width: 1120px) { header .kpi-lbl { font-size: 10.5px; } header .brand-site { display: none; } }
@media (max-width: 980px) { header .kpis { display: none; } header .hdr-right { margin-left: auto; } }
@media (max-width: 640px) {
  header { gap: 10px; padding: 0 12px; height: auto; min-height: 56px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
  header .brand-name { font-size: 11.5px; }
  header .hdr-right { flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
  header .hdr-tools { padding-left: 4px; border-left: 0; }
  header button.hdr-icon { width: 34px; height: 34px; }
}
header #kpiActiveWrap.hot::before { content: none; }
header #kpiActiveWrap.hot .kpi-num::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #FF6E70; margin: 0 6px 2px 0; vertical-align: middle; animation: livedot 1.7s ease-out infinite; }

/* ---------- device card: every action on one row (2026-11-24) ---------- */
.device .dev-actions { flex-basis: 100%; display: flex; align-items: center; gap: 6px; margin-top: 2px; padding-left: 50px; }
.device button.dev-act { width: 38px; height: 34px; padding: 0; display: inline-flex; align-items: center; justify-content: center; gap: 4px; border-radius: 9px; border: 1px solid var(--line); background: var(--panel); color: var(--dim); font-size: 12px; position: relative; }
.device button.dev-act svg { width: 17px; height: 17px; }
.device button.dev-act:hover:not(:disabled) { color: var(--fg); border-color: var(--line-strong); background: var(--btn-hover); }
.device button.dev-act:disabled { opacity: .4; cursor: not-allowed; }
.device button.dev-act .ubadge { position: absolute; top: -6px; right: -6px; margin: 0; }
.device button.dev-del { margin-left: auto; }
.device button.dev-del:hover:not(:disabled) { color: var(--red); border-color: var(--red); background: transparent; }
@media (max-width: 1100px) { .device .dev-actions { padding-left: 0; } }

/* ---------- instant hover labels on icon buttons (2026-11-24) ---------- */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 8px); transform: translateX(-50%) translateY(2px);
  background: #0A111B; color: #F6F9FB; border: 1px solid #2C3A4A; border-radius: 8px; padding: 6px 10px;
  font: 600 12px/1.3 var(--font-sans); letter-spacing: 0; text-transform: none; white-space: nowrap;
  pointer-events: none; opacity: 0; transition: opacity .08s, transform .08s; z-index: 3000;
}
[data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; transform: translateX(-50%) translateY(0); }
/* the last button on a card sits at the panel edge: anchor its label to the right */
.device .dev-del[data-tip]::after { left: auto; right: 0; transform: translateY(2px); }
.device .dev-del[data-tip]:hover::after, .device .dev-del[data-tip]:focus-visible::after { transform: translateY(0); }
/* header labels drop below the bar */
header [data-tip]::after { bottom: auto; top: calc(100% + 8px); }
header .hdr-tools button:last-child[data-tip]::after { left: auto; right: 0; transform: translateY(2px); }
header .hdr-tools button:last-child[data-tip]:hover::after { transform: translateY(0); }
/* the device list must not clip the labels */
#deviceList, .device { overflow: visible; }

/* ---------- view-only login (2026-11-24) ---------- */
header #viewOnlyPill { color: #FFA734; border-color: rgba(255, 167, 52, .45); }
body.view-only .policy-add, body.view-only #talkBtn, body.view-only #zoneDrawBtn { display: none !important; }
/* sign-out sits last in the header tools */
header #logoutBtn:hover { color: #FF6E70; }

/* ---------- device card in a narrow column (2026-11-25) ----------
   The zone label ("Eastern Avenue, Bilinga, 4225 · unacked") and the row of buttons used to keep
   their full width and spill past the card, giving the list a sideways scrollbar. Now the label
   drops to its own line and is cut short with "…" (hover shows it in full), and the buttons
   shrink to fit, so nothing ever leaves the card. */
#deviceList { container-type: inline-size; }
.device .sub { min-width: 0; }
.device .sub .hz-chip { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; box-sizing: border-box; }
.device .dev-actions { min-width: 0; }
.device button.dev-act { flex: 0 1 38px; min-width: 26px; }
@container (max-width: 300px) {
  .device .dev-actions { padding-left: 0; gap: 4px; }
}

/* live camera permission tick on the Users screen (2026-11-25) */
.cam-perm { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--dim); white-space: nowrap; cursor: pointer; }
.cam-perm input { margin: 0; accent-color: var(--teal, #007278); }

/* message sound pickers (2026-11-25) */
.snd-row { display: flex; gap: 6px; align-items: center; } .snd-row select { flex: 1; min-width: 0; }

/* app-in-background label on a device card (2026-11-27) */
.hz-chip.bg-chip { background: var(--amber-soft); color: var(--amber); }
