:root {
  /* graphite, hairlines, one light accent; colour is kept for status */
  --bg: #0f1012; --panel: #16171a; --panel2: #1c1d21; --line: #25262b; --line2: #303238;
  --text: #e9e7e3; --muted: #9a9ca3; --faint: #64666d;
  --blue: #9db8d6; --blue-d: #e9e7e3; --green: #4cc38a; --red: #ef5b5b; --amber: #e9b040;
  --accent-ink: #0f1012;
  --r: 4px; --nav: 208px; --top: 46px;
  font-family: "Segoe UI Variable Text", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  font-size: 13.5px; color-scheme: dark; font-variant-numeric: tabular-nums;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
a { color: var(--text); text-decoration: underline; text-decoration-color: var(--line2); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--muted); }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 17px; font-weight: 600; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 14px; font-weight: 600; margin: 0 0 12px; }
h3 { font-size: 13px; font-weight: 600; margin: 0 0 8px; color: var(--text); }
p { margin: 0 0 10px; line-height: 1.5; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.hide { display: none !important; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* shell */
.shell { display: grid; grid-template-columns: var(--nav) 1fr; grid-template-rows: var(--top) 1fr; height: 100vh; height: 100dvh; }
.top { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 0 12px 0 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; min-width: calc(var(--nav) - 26px); letter-spacing: -.01em; }
.brand img { width: 20px; height: 20px; }
.top .spacer { flex: 1; }
.nav { background: var(--panel); border-right: 1px solid var(--line); padding: 10px 0; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 16px; color: var(--muted); text-decoration: none; border-left: 2px solid transparent; }
.nav a svg.i { width: 16px; height: 16px; }
.nav a:hover { color: var(--text); }
.nav a.on { color: var(--text); border-left-color: var(--text); background: var(--panel2); }
.nav .sep { height: 1px; background: var(--line); margin: 8px 16px; }
.nav .badge { margin-left: auto; }
main { overflow: auto; min-width: 0; position: relative; }
.page { padding: 16px; max-width: 1280px; }
.page.full { max-width: none; padding: 0; height: 100%; display: flex; flex-direction: column; }
.page-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head .spacer { flex: 1; }

/* controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: var(--r); border: 1px solid var(--line2); background: var(--panel2); color: var(--text); cursor: pointer; white-space: nowrap; text-decoration: none !important; }
.btn:hover { background: #24262b; border-color: #3a3c43; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--text); border-color: var(--text); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { background: #fff; border-color: #fff; }
.btn.danger { color: #f08a8a; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--panel2); }
.btn.sm { height: 26px; padding: 0 8px; font-size: 12px; }
.btn.icon { width: 32px; padding: 0; }
.btn.icon.sm { width: 26px; }
.btn.on { background: #2a2c31; border-color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--line2); border-radius: var(--r); overflow: hidden; }
.seg button { height: 30px; padding: 0 10px; background: var(--panel2); border: 0; border-right: 1px solid var(--line2); cursor: pointer; color: var(--muted); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: #2a2c31; color: var(--text); }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=search], input[type=datetime-local], input[type=date], input[type=url], input[type=tel], select, textarea {
  height: 32px; padding: 0 10px; border-radius: var(--r); border: 1px solid var(--line2); background: var(--bg); outline: none; width: 100%; min-width: 0;
}
textarea { height: auto; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--muted); box-shadow: 0 0 0 3px rgba(233, 231, 227, .06); }
input[type=range] { width: 100%; accent-color: var(--blue); }
input[type=checkbox] { accent-color: var(--blue); width: 16px; height: 16px; margin: 0; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
label.field > small { display: block; font-size: 12px; color: var(--faint); margin-top: 4px; }
label.check { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; cursor: pointer; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 12px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin-bottom: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; }
.stat b { display: block; font-size: 22px; font-weight: 600; margin-top: 4px; }
.stat span { color: var(--muted); font-size: 12px; }

table.list { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
table.list th { text-align: left; font-weight: 500; font-size: 12px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); background: #1a1e23; white-space: nowrap; }
table.list td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: #22272d; }
.table-wrap { overflow-x: auto; }

/* status labels: a dot and a word, not a coloured pill */
.badge { display: inline-flex; align-items: center; gap: 5px; height: 18px; padding: 0 6px; border-radius: 3px; font-size: 11.5px; font-weight: 500; background: var(--panel2); border: 1px solid var(--line2); color: var(--muted); white-space: nowrap; }
.badge.red, .badge.green, .badge.amber { background: transparent; border-color: transparent; padding: 0; color: var(--text); }
.badge.red::before, .badge.green::before, .badge.amber::before { content: ''; width: 7px; height: 7px; border-radius: 50%; flex: none; }
.badge.red::before { background: var(--red); box-shadow: 0 0 0 3px rgba(239, 91, 91, .15); }
.badge.green::before { background: var(--green); }
.badge.amber::before { background: var(--amber); }
.badge.blue { color: var(--text); }
.alerts-btn .badge.red, .mobile-nav .badge.red, .nav .badge.red { background: var(--red); color: #fff; padding: 0 5px; border-radius: 8px; font-weight: 600; }
.alerts-btn .badge.red::before, .mobile-nav .badge.red::before, .nav .badge.red::before { display: none; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.green { background: var(--green); }
.dot.red { background: var(--red); }
.dot.amber { background: var(--amber); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

.arm { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border-radius: var(--r); border: 1px solid var(--line2); background: var(--panel2); cursor: pointer; font-size: 13px; }
.arm.armed { border-color: #6e2422; background: #2b1716; color: #ffb3ae; }
.alerts-btn { position: relative; }
.alerts-btn .badge { position: absolute; top: -4px; right: -6px; }

/* menus / modals / toasts */
.menu { position: fixed; z-index: 60; min-width: 180px; background: var(--panel2); border: 1px solid var(--line2); border-radius: var(--r); padding: 4px; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.menu button, .menu a { display: flex; width: 100%; align-items: center; gap: 8px; padding: 7px 10px; border: 0; background: none; border-radius: 4px; cursor: pointer; text-align: left; color: var(--text); text-decoration: none; }
.menu button:hover, .menu a:hover { background: #343b44; }
.menu .sep { height: 1px; background: var(--line2); margin: 4px 0; }
.modal-bg { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.55); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 12px 12px; overflow-y: auto; }
.modal { width: 100%; max-width: 560px; background: var(--panel); border: 1px solid var(--line2); border-radius: 8px; box-shadow: 0 12px 40px rgba(0,0,0,.5); }
.modal.wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; flex: 1; }
.modal-body { padding: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line); }
.modal-foot .left { margin-right: auto; }
#toasts { position: fixed; z-index: 70; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 8px; max-width: min(360px, calc(100vw - 24px)); }
.toast { background: var(--panel2); border: 1px solid var(--line2); border-left: 3px solid var(--blue); border-radius: var(--r); padding: 10px 12px; box-shadow: 0 6px 20px rgba(0,0,0,.4); display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.toast.error { border-left-color: var(--red); }
.toast.motion { border-left-color: var(--amber); }
.toast img { width: 72px; height: 40px; object-fit: cover; border-radius: 3px; background: #000; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.tabs button.on { color: var(--text); border-bottom-color: var(--text); }

/* auth */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth .card { width: 100%; max-width: 380px; padding: 22px; }
.auth .brand { margin-bottom: 18px; font-size: 16px; }
.err { color: #ff7b72; font-size: 13px; min-height: 18px; margin-bottom: 8px; }

/* live view */
.live-bar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.live-bar .spacer { flex: 1; }
.wall { position: relative; flex: 1; display: grid; gap: 2px; padding: 2px; background: #000; min-height: 0; grid-auto-rows: 1fr; justify-content: center; align-content: center; }
.tile { position: relative; background: #0b0d0f; overflow: hidden; min-height: 0; min-width: 0; outline: 2px solid transparent; outline-offset: -2px; }
.tile.motion { outline-color: var(--amber); }
.tile.sel { outline-color: var(--blue); }
.tile video, .tile img.still { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.tile .cap { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: center; gap: 6px; padding: 5px 8px; font-size: 12px; background: linear-gradient(rgba(0,0,0,.65), rgba(0,0,0,0)); pointer-events: none; }
.tile .cap .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .cap .tag { font-size: 10px; padding: 1px 5px; border-radius: 3px; background: rgba(0,0,0,.5); color: #ddd; }
.tile .cap .tag.rec { color: #ff8a85; }
.tile .cap .tag.mot { color: #f2cc60; }
.tile .tools { position: absolute; right: 6px; bottom: 6px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.tile:hover .tools, .tile.sel .tools { opacity: 1; }
.tile .tools .btn { background: rgba(20,22,26,.8); border-color: rgba(255,255,255,.15); }
.tile .msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; text-align: center; padding: 10px; }
.tile.empty-slot { display: flex; align-items: center; justify-content: center; color: var(--faint); cursor: pointer; }
.tile.empty-slot:hover { color: var(--muted); background: #111418; }
.ptz { position: absolute; left: 8px; bottom: 8px; display: grid; grid-template-columns: repeat(3, 34px); grid-template-rows: repeat(3, 34px); gap: 3px; }
.ptz button { background: rgba(20,22,26,.85); border: 1px solid rgba(255,255,255,.15); border-radius: 4px; cursor: pointer; display: flex; align-items: center; justify-content: center; color: #fff; touch-action: none; }
.ptz button:active { background: var(--blue-d); }
.ptz-zoom { position: absolute; left: 124px; bottom: 8px; display: flex; flex-direction: column; gap: 3px; }
.ptz-zoom button { width: 34px; height: 34px; background: rgba(20,22,26,.85); border: 1px solid rgba(255,255,255,.15); border-radius: 4px; color: #fff; cursor: pointer; font-size: 18px; touch-action: none; }

/* playback */
.pb { display: grid; grid-template-columns: 240px 1fr; height: 100%; min-height: 0; }
.pb-side { border-right: 1px solid var(--line); background: var(--panel); overflow-y: auto; padding: 10px; }
.pb-side .cam { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: var(--r); cursor: pointer; }
.pb-side .cam:hover { background: var(--panel2); }
.pb-side .cam.on { background: #2a3240; }
.pb-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.pb-video { flex: 1; position: relative; background: #000; min-height: 200px; }
.pb-video video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.pb-video .clock { position: absolute; left: 10px; top: 8px; font: 600 13px ui-monospace, Menlo, monospace; background: rgba(0,0,0,.6); padding: 3px 7px; border-radius: 4px; }
.pb-controls { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--panel); border-top: 1px solid var(--line); flex-wrap: wrap; }
.pb-controls .spacer { flex: 1; }
.timeline { position: relative; height: 64px; background: #101317; border-top: 1px solid var(--line); cursor: crosshair; user-select: none; touch-action: none; }
.timeline canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.tl-hover { position: absolute; top: -26px; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line2); padding: 2px 6px; border-radius: 4px; font: 12px ui-monospace, Menlo, monospace; pointer-events: none; white-space: nowrap; }
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); align-items: center; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

/* events */
.ev-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.ev { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; cursor: pointer; }
.ev:hover { border-color: var(--line2); }
.ev .thumb { aspect-ratio: 16/9; background: #0b0d0f; display: flex; align-items: center; justify-content: center; color: var(--faint); position: relative; }
.ev .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ev .thumb .badge { position: absolute; left: 6px; top: 6px; }
.ev .meta { padding: 8px 10px; display: flex; align-items: center; gap: 8px; }
.ev .meta .t { flex: 1; min-width: 0; }
.ev .meta .t div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev.acked { opacity: .6; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.filters select, .filters input { width: auto; }

/* cameras */
.cam-thumb { width: 96px; aspect-ratio: 16/9; background: #0b0d0f; border-radius: 4px; object-fit: cover; display: block; }
.zones { position: relative; aspect-ratio: 16/9; background: #000; border-radius: 4px; overflow: hidden; user-select: none; touch-action: none; }
.zones img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.zones .grid { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(16, 1fr); grid-template-rows: repeat(9, 1fr); }
.zones .grid div { border: 1px solid rgba(255,255,255,.08); cursor: pointer; }
.zones .grid div.on { background: rgba(61,139,253,.35); border-color: rgba(61,139,253,.5); }
.probe-img { width: 100%; border-radius: 4px; display: block; margin-top: 8px; }
.sched { display: grid; grid-template-columns: 42px repeat(24, 1fr); gap: 2px; user-select: none; touch-action: none; font-size: 11px; }
.sched .h { color: var(--faint); text-align: center; }
.sched .d { color: var(--muted); display: flex; align-items: center; }
.sched .c { height: 22px; background: #111418; border: 1px solid var(--line); border-radius: 2px; cursor: pointer; }
.sched .c.on { background: #6e2422; border-color: #8b2f2c; }
.bar { height: 8px; background: #111418; border-radius: 4px; overflow: hidden; border: 1px solid var(--line); }
.bar i { display: block; height: 100%; background: var(--blue); }
.bar i.warn { background: var(--amber); }
.bar i.bad { background: var(--red); }

/* mobile */
.mobile-nav { display: none; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: var(--top) 1fr auto; }
  .nav { display: none; }
  .brand { min-width: 0; }
  .brand span { display: none; }
  .mobile-nav { display: flex; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .mobile-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 0 6px; font-size: 11px; color: var(--muted); text-decoration: none; position: relative; }
  .mobile-nav a.on { color: var(--text); }
  .mobile-nav a .badge { position: absolute; top: 2px; left: calc(50% + 6px); }
  .page { padding: 12px; }
  .row, .row3 { grid-template-columns: 1fr; }
  .pb { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .pb-side { border-right: 0; border-bottom: 1px solid var(--line); display: flex; gap: 6px; overflow-x: auto; padding: 8px; }
  .pb-side h3, .pb-side .side-extra { display: none; }
  .pb-side .cam { white-space: nowrap; border: 1px solid var(--line2); }
  .pb-video { min-height: 0; aspect-ratio: 16/9; flex: none; }
  .tile .tools { opacity: 1; }
  .hide-m { display: none !important; }
  .modal-bg { padding: 0; }
  .modal { border-radius: 0; min-height: 100%; border: 0; }
  .sched { grid-template-columns: 30px repeat(24, 1fr); }
  .sched .h { font-size: 8px; }
  table.list .hide-m { display: none; }
}
@media (min-width: 861px) { .only-m { display: none !important; } }

/* shared extras */
.card.flush { padding: 0; overflow: hidden; }
.table-wrap table { width: 100%; border-collapse: collapse; }
.table-wrap th { text-align: left; font-weight: 500; font-size: 12px; color: var(--faint); padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: transparent; }
.table-wrap td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table-wrap tr.click:hover td { background: #1a1b1f; }
.table-wrap tr:last-child td { border-bottom: 0; }
.table-wrap td.empty { text-align: center; color: var(--muted); padding: 28px 10px; }
tr.dim td { opacity: .55; }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn + .btn { margin-left: 4px; }
.nowrap { white-space: nowrap; }
.wrap { white-space: normal; word-break: break-word; max-width: 360px; }
div.field { margin-bottom: 12px; }
div.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.row.tight { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.row.tight input { flex: 1; min-width: 0; }
.page.narrow { max-width: 820px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat .big { font-size: 22px; font-weight: 600; margin: 4px 0 2px; }
.stat.bad .big { color: var(--red); }
.stat.good .big { color: var(--green); }
.banner { display: flex; gap: 10px; align-items: flex-start; padding: 9px 12px; border-radius: var(--r); margin-bottom: 14px; border: 1px solid var(--line); border-left: 2px solid var(--muted); background: var(--panel); color: var(--muted); }
.banner b { color: var(--text); font-weight: 600; }
.banner .i { flex: none; margin-top: 1px; width: 16px; height: 16px; }
.banner.red { border-left-color: var(--red); color: var(--text); }
.banner.green { border-left-color: var(--green); }
.storage-bar { position: relative; height: 14px; border-radius: 4px; background: var(--bg); border: 1px solid var(--line); overflow: hidden; margin-bottom: 8px; }
.storage-bar i { position: absolute; left: 0; top: 0; bottom: 0; }
.storage-bar i.other { background: #4b535d; }
.storage-bar i.vms { background: var(--blue); }
.legend i { border: 1px solid var(--line2); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; }
.kv span { color: var(--muted); }
.kv b { font-weight: 500; }
.cam-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 2px 12px; margin-top: 6px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--r); max-height: 220px; overflow: auto; }
.cam-checks label.check { margin-bottom: 4px; }
.sched-wrap { overflow-x: auto; }
.sched-wrap .sched { min-width: 520px; }
.settings .card h3 { margin-bottom: 10px; }
.sticky-save { position: sticky; bottom: 0; display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 30%); }
.cam-name { display: flex; align-items: center; gap: 10px; }
.disc-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.disc-list .d-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--r); }
.disc-list .d-item > div { flex: 1; min-width: 0; }
.profiles { display: grid; gap: 6px; margin: 8px 0 12px; }
.profiles label { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--r); }
.test-out { margin-top: -4px; margin-bottom: 12px; font-size: 12px; }
.test-out.ok { color: var(--green); }
.test-out.bad { color: var(--red); }
@media (max-width: 860px) {
  .wrap { max-width: 220px; }
  .sticky-save { padding-bottom: 12px; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv b { margin-bottom: 6px; }
}
.pb-controls, .timeline { flex: none; }
.pb-video { min-height: 120px; }
@media (max-width: 860px) {
  .wall:not(.one) { grid-template-columns: repeat(2, 1fr) !important; grid-template-rows: none !important; grid-auto-rows: auto; align-content: start; overflow-y: auto; }
  .wall:not(.one) .tile { aspect-ratio: 16/9; }
  .tile .tools { opacity: 0; pointer-events: none; }
  .tile.sel .tools { opacity: 1; pointer-events: auto; }
  .wall:not(.one) .tile .cap .tag:not(.rec):not(.mot) { display: none; }
  .cam-list { display: flex; gap: 6px; }
  tr.click { cursor: pointer; }
}
.test-row { margin: -4px 0 6px; }
.test-out:empty { display: none; }
@media (max-width: 860px) {
  #toasts { bottom: calc(62px + env(safe-area-inset-bottom)) !important; right: 8px !important; left: 8px !important; align-items: flex-end; }
  .timeline { height: 72px; }
}

/* customers, sites & towers */
.top select.scope { width: auto; max-width: 240px; height: 30px; padding: 0 8px; background: var(--panel2); }
.top .scope-name { color: var(--muted); font-weight: 600; }
pre.code { margin: 10px 0 0; padding: 10px 12px; max-height: 320px; overflow: auto; background: var(--bg); border: 1px solid var(--line); border-radius: var(--r); font: 12px/1.55 ui-monospace, "Cascadia Mono", SFMono-Regular, Menlo, Consolas, monospace; white-space: pre; color: #cfcdc8; }
.kv b.mono { word-break: break-all; font-weight: 500; }
.mono { font-family: ui-monospace, "Cascadia Mono", SFMono-Regular, Menlo, Consolas, monospace; }
.card { border-color: var(--line); }
.page-head h1 + .sub { color: var(--faint); margin-left: 4px; }
.lede { color: var(--muted); max-width: 70ch; margin-bottom: 16px; }

.site { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 12px; }
.site-head { display: flex; align-items: baseline; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.site-head h3 { margin: 0; font-size: 14px; }
.site-head .spacer { flex: 1; }
.tower { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.3fr) minmax(0, .7fr) auto; gap: 12px; align-items: start; padding: 10px 14px; border-bottom: 1px solid var(--line); min-width: 0; }
.tower > * { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 1100px) {
  .tower { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.2fr); }
  .tower .traffic { grid-column: 1; }
  .tower .acts { grid-column: 2 / -1; }
}
.tower:last-child { border-bottom: 0; }
.tower .name b { font-weight: 600; }
.tower .meta { color: var(--faint); font-size: 12px; margin-top: 2px; line-height: 1.5; }
.tower .warn { color: var(--amber); font-size: 12px; margin-top: 3px; }
.tower .acts { display: flex; gap: 4px; justify-content: flex-end; }
.site-empty { padding: 14px; color: var(--faint); }

.devices { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r); margin: 8px 0 12px; max-height: 230px; overflow: auto; }
.devices .d { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.devices .d:last-child { border-bottom: 0; }
.devices .d > div { flex: 1; min-width: 0; }
.devices .none { padding: 14px 12px; color: var(--faint); }
.pulse { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--amber); margin-right: 6px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }

.steps { display: flex; gap: 0; margin: -2px 0 16px; border-bottom: 1px solid var(--line); }
.steps span { padding: 0 12px 10px 0; margin-right: 14px; color: var(--faint); font-size: 12.5px; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.steps span.on { color: var(--text); border-bottom-color: var(--text); }
.steps span.done { color: var(--muted); }
.checks { list-style: none; margin: 0; padding: 0; }
.checks li { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.checks li:last-child { border-bottom: 0; }
.checks .fix { color: var(--faint); font-size: 12px; margin-top: 2px; }
.checks .s { width: 14px; flex: none; padding-top: 1px; }
.checks .s.ok { color: var(--green); } .checks .s.bad { color: var(--red); }
@media (max-width: 860px) {
  .top select.scope { max-width: 130px; }
  .tower { grid-template-columns: 1fr 1fr; }
  .tower .acts { grid-column: 1 / -1; justify-content: flex-start; }
}

/* alarm console */
.alarm-btn { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border: 1px solid var(--line2); border-radius: var(--r); color: var(--muted); text-decoration: none; font-size: 12.5px; }
.alarm-btn svg.i { width: 16px; height: 16px; }
.alarm-btn.waiting { color: var(--text); border-color: var(--amber); }
.alarm-btn.overdue { color: #fff; background: #5a1d1d; border-color: var(--red); animation: pulse 1.2s ease-in-out infinite; }
.console { display: grid; grid-template-columns: 320px 1fr; height: 100%; min-height: 0; }
.aq-side { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.aq-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.aq-head .spacer { flex: 1; }
.aq { overflow-y: auto; flex: 1; }
.aq-empty, .ald-empty { padding: 30px 16px; color: var(--faint); text-align: center; }
.ald-empty { margin: auto; }
.aq-item { display: block; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); border-left: 3px solid transparent; padding: 10px 12px 10px 11px; cursor: pointer; color: var(--text); }
.aq-item:hover { background: #1a1b1f; }
.aq-item.on { background: var(--panel2); }
.aq-item.p1 { border-left-color: var(--red); }
.aq-item.p2 { border-left-color: var(--amber); }
.aq-item.esc { background: #2a1616; }
.aq-top { display: flex; justify-content: space-between; gap: 8px; }
.aq-t { color: var(--muted); }
.aq-item.esc .aq-t, .aq-item.esc .aq-state { color: #ff9b9b; }
.aq-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.aq-state { font-size: 12px; margin-top: 4px; color: var(--faint); }
.ald { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow-y: auto; }
.ald-head { display: flex; align-items: flex-start; gap: 16px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.ald-head .spacer { flex: 1; }
.ald-title { display: flex; gap: 10px; align-items: baseline; font-size: 15px; }
.ald-what { margin-top: 4px; color: var(--muted); }
.ald-times { text-align: right; color: var(--muted); }
.ald-age { font-size: 20px; color: var(--text); margin-top: 2px; }
.ald-acts { display: flex; gap: 6px; align-items: center; }
.ald-body { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(280px, 1fr); gap: 16px; padding: 16px; align-items: start; }
.ald-video { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: var(--r); overflow: hidden; }
.ald-video video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.ald-video .msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }
.ald-cams { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.ald-imgs { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.ald-img { position: relative; padding: 0; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: #000; cursor: zoom-in; aspect-ratio: 16 / 9; }
.ald-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ald-img span { position: absolute; left: 4px; bottom: 3px; font: 11px ui-monospace, monospace; background: rgba(0,0,0,.6); padding: 1px 4px; border-radius: 2px; color: #ddd; }
.ald-block { border: 1px solid var(--line); border-radius: var(--r); padding: 12px; margin-bottom: 12px; background: var(--panel); }
.ald-plan { white-space: pre-wrap; line-height: 1.5; margin-bottom: 10px; }
.kh { display: grid; grid-template-columns: 18px 1fr auto auto; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.kh:last-of-type { border-bottom: 0; }
.alog { list-style: none; margin: 0; padding: 0; max-height: 340px; overflow-y: auto; }
.alog li { display: grid; grid-template-columns: 62px 1fr; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.alog li:last-child { border-bottom: 0; }
.ald textarea { min-height: 34px; }
@media (max-width: 1100px) { .ald-body { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .console { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .aq-side { max-height: 40vh; border-right: 0; border-bottom: 1px solid var(--line); }
}
.kh a { text-decoration: none; }

/* PTZ over video */
.ptz-wrap { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.ptz-wrap > * { pointer-events: auto; }
.ptz button, .ptz-zoom button { user-select: none; -webkit-user-select: none; }
.ptz-bar { position: absolute; right: 8px; top: 8px; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; align-items: center; max-width: calc(100% - 16px); }
.ptz-bar .btn { background: rgba(15, 16, 18, .85); border-color: rgba(255, 255, 255, .15); color: #fff; }
.ptz-speed button { height: 26px; font-size: 12px; background: rgba(15, 16, 18, .85); color: #ccc; }
.ptz-speed button.on { color: #fff; background: rgba(60, 62, 68, .95); }
.ptz-lock { font-size: 12px; padding: 3px 8px; border-radius: 3px; background: rgba(120, 30, 30, .9); color: #fff; }
@media (max-width: 860px) { .ptz-bar .ptz-speed { display: none; } }

/* SD-card playback */
.sd { display: flex; flex-direction: column; min-height: 0; }
.sd-video { position: relative; aspect-ratio: 16 / 9; flex: none; }
.sd-video .msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; text-align: center; padding: 10px; }
.sd-tag { position: absolute; right: 8px; top: 8px; font: 600 11px ui-monospace, monospace; background: rgba(0,0,0,.6); color: #ddd; padding: 2px 6px; border-radius: 3px; }
.sd-main { overflow-y: auto; }
.sd-bottom { display: flex; gap: 20px; padding: 12px 14px; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; }
.sd-events { display: flex; flex-direction: column; gap: 2px; max-height: 260px; overflow-y: auto; min-width: 280px; }
.sd-ev { text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 6px 2px; color: var(--text); cursor: pointer; }
.sd-ev:hover { background: var(--panel2); }
.modal .sd .pb-controls { padding: 8px 0 0; border: 0; background: none; }

/* ---------- site health ---------- */
.flt-group { margin-bottom: 12px; }
.flt-head { display: flex; gap: 10px; align-items: baseline; padding: 9px 14px; border-bottom: 1px solid var(--line); background: var(--panel2); }
.flt { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; gap: 3px 12px; padding: 10px 14px; border-top: 1px solid var(--line); align-items: start; }
.flt-head + .flt { border-top: 0; }
.flt .dot { margin-top: 6px; }
.flt .what b { font-weight: 600; }
.flt .what > div + div { margin-top: 2px; }
.flt .acts { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.flt.cleared .what { opacity: .7; }
.flt-title { font-size: 13px; font-weight: 600; color: var(--muted); margin: 20px 0 8px; }
.test-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.test-grid figure { margin: 0; }
.test-grid img, .test-grid .noimg { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: #000; border-radius: var(--r); display: block; }
.test-grid .noimg { display: grid; place-items: center; color: var(--red); font-size: 12px; border: 1px dashed var(--line2); background: var(--panel2); }
.test-grid figcaption { margin-top: 5px; }
.nav a .badge { margin-left: auto; }
@media (max-width: 700px) {
  .flt { grid-template-columns: 10px minmax(0, 1fr); }
  .flt .acts { grid-column: 2; justify-content: flex-start; }
}
.last-test { min-width: 220px; }
.last-test a { color: inherit; text-decoration: none; display: block; }
.last-test a:hover .badge { text-decoration: underline; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 360px; }
.stats:has(.stat.compact) { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
/* ---------- talk-down ---------- */
.talk { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); }
.talk-btn { user-select: none; -webkit-user-select: none; touch-action: none; }
.talk-btn.on { background: var(--red); border-color: var(--red); color: #fff; }
.talk-level { width: 60px; height: 6px; background: var(--panel2); border-radius: 3px; overflow: hidden; }
.talk-level i { display: block; height: 100%; width: 0; background: var(--green); transition: width .1s; }
.talk-clip { width: auto; max-width: 220px; }
.talk-status { color: var(--muted); }
.clips { margin-bottom: 10px; }
.clip { display: flex; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.clip-add input[type=text] { flex: 1; min-width: 160px; }
/* ---------- shifts ---------- */
.shift-btn { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border-radius: var(--r); color: var(--muted); text-decoration: none; font-size: 12.5px; }
.shift-btn:hover { color: var(--text); background: var(--panel2); }
.shift-btn.off { color: var(--amber); border: 1px solid var(--amber); }
.shift-btn .i { width: 15px; height: 15px; }
.shift-start, .shift-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.shift-start > div { flex: 1; }
.shift-on .stats { margin: 12px 0 0; }
.handover { border-left: 2px solid var(--amber); }
.note, .pre { white-space: pre-wrap; }
.handover .note { margin: 6px 0; }
.shift-add { display: grid; gap: 8px; margin-bottom: 12px; }
.shift-add textarea { width: 100%; }
.shift-site { width: auto; max-width: 280px; }
/* ---------- reports ---------- */
.report-range { margin: -4px 0 14px; }
.chart-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; }
.chart h3 { margin-bottom: 10px; }
.bars { position: relative; display: flex; align-items: flex-end; gap: 2px; height: 130px; border-bottom: 1px solid var(--line2); padding-top: 16px; }
.bars .b { flex: 1; height: 100%; display: flex; align-items: flex-end; position: relative; cursor: default; }
.bars .b i { display: block; width: 100%; max-width: 28px; margin: 0 auto; background: var(--blue); border-radius: 4px 4px 0 0; }
.bars .b:hover i { filter: brightness(1.25); }
.bars .peak { position: absolute; top: -16px; left: 50%; transform: translateX(-50%); font-size: 11px; color: var(--muted); }
.bar-tip { position: absolute; top: -6px; transform: translate(-50%, -100%); background: var(--panel2); border: 1px solid var(--line2); border-radius: var(--r); padding: 3px 8px; font-size: 12px; white-space: nowrap; pointer-events: none; z-index: 2; }
.bars-axis { display: flex; justify-content: space-between; margin-top: 4px; }
td.bad-num { color: var(--red); }
@media print {
  .top, .nav, .mobile-nav, .no-print, .toast { display: none !important; }
  .shell { display: block !important; }
  body, .card, .stat { background: #fff !important; color: #000 !important; }
  .card, .stat, table td, table th { border-color: #ccc !important; }
  .muted, .faint { color: #555 !important; }
  .bars .b i { background: #555 !important; }
  .chart, .card { break-inside: avoid; }
}

/* Squeezed sub streams (marked in app.js): drawn at 16:9, as large as fits the box. */
.tile, .pb-video, .ald-video { container-type: size; }
video.squeezed { inset: auto; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(100cqw, 100cqh * 16 / 9); height: min(100cqh, 100cqw * 9 / 16); object-fit: fill; }
.wall-paused { position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: rgba(0,0,0,.82); color: var(--muted); font-size: 14px; cursor: pointer; text-align: center; padding: 16px; }
.wall-paused b { color: var(--text, #e6e6e6); font-size: 18px; }
