/* SkyWatch design system: dark navy, teal accents, amber alerts. Mobile-first. */
:root {
  --bg: #0a1628; --bg2: #0d1c33; --card: #10223d; --card2: #152a4a; --line: #213b61; --line2: #2b4a76;
  --text: #e8f0fd; --muted: #93a9c9; --faint: #647a9b;
  --teal: #2dd4bf; --teal-d: #119e8e; --teal-bg: rgba(45, 212, 191, .13);
  --amber: #ffb020; --amber-bg: rgba(255, 176, 32, .14);
  --red: #ff5d4d; --red-bg: rgba(255, 93, 77, .14);
  --green: #34d399; --yellow: #f2d675; --slate: #6b86a8;
  --radius: 14px; --nav-h: 64px; --side-w: 248px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif; -webkit-tap-highlight-color: transparent; min-height: 100vh; }
body.noscroll { overflow: hidden; }
[hidden] { display: none !important; }
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: 22px; letter-spacing: -.01em; }
h2 { font-size: 16px; }
h3 { font-size: 15px; }
h4 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 18px 0 8px; }
a { color: inherit; text-decoration: none; }
code { background: var(--card2); padding: 1px 6px; border-radius: 6px; font-size: 12px; }
button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.spacer { flex: 1; }
.center { text-align: center; margin: 14px 0; }
.link { color: var(--teal); background: none; border: 0; padding: 0; text-decoration: underline; text-underline-offset: 3px; }
.amber-t { color: var(--amber); }
.ic { flex: none; vertical-align: middle; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

/* ---------- Layout ---------- */
#app { display: flex; min-height: 100vh; min-height: 100dvh; }
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
main { padding: 16px 14px calc(var(--nav-h) + var(--safe-b) + 26px); width: 100%; max-width: 1180px; margin: 0 auto; outline: none; flex: 1; }
.sidebar { display: none; width: var(--side-w); flex: 0 0 var(--side-w); background: var(--bg2); border-right: 1px solid var(--line); position: sticky; top: 0; height: 100vh; flex-direction: column; padding: 18px 12px; }
.brand { display: flex; align-items: center; gap: 9px; font-size: 19px; padding: 4px 8px 16px; }
.brand-m { padding: 0; }
.brand .logo { color: var(--teal); display: inline-flex; }
.brand-name b { color: var(--teal); font-weight: 700; }
.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 10px; color: var(--muted); font-weight: 500; }
.nav-item:hover { background: var(--card); color: var(--text); }
.nav-item.active { background: var(--teal-bg); color: var(--teal); }
.nav-item .count { margin-left: auto; }
.side-foot { padding: 10px 8px 0; border-top: 1px solid var(--line); display: grid; gap: 6px; }
.org-chip { font-size: 12.5px; color: var(--muted); background: var(--card); border: 1px solid var(--line); padding: 4px 10px; border-radius: 99px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .org-chip { display: none; }
.sim-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; background: linear-gradient(90deg, rgba(255,176,32,.17), rgba(255,176,32,.05)); border-bottom: 1px solid rgba(255,176,32,.35); color: var(--amber); font-size: 12px; padding: 7px 14px; padding-top: calc(7px + env(safe-area-inset-top, 0px)); }
.demo-pill { background: var(--amber); color: #2a1a00; font-weight: 700; border-radius: 99px; padding: 2px 10px; font-size: 11px; animation: blink 1.6s infinite; }
@keyframes blink { 50% { opacity: .55; } }
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 10px; padding: 9px 14px; background: rgba(10,22,40,.94); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.icon-btn { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 12px; border: 0; background: transparent; color: var(--text); }
.icon-btn:hover { background: var(--card); }
.count { font-style: normal; font-size: 11px; font-weight: 700; background: var(--amber); color: #2a1a00; border-radius: 99px; min-width: 18px; height: 18px; padding: 0 5px; display: inline-flex; align-items: center; justify-content: center; }
.bell .count { position: absolute; top: 3px; right: 2px; }
.bottomnav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); background: rgba(13,28,51,.97); backdrop-filter: blur(10px); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); height: calc(var(--nav-h) + var(--safe-b)); }
.bn-item { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; color: var(--muted); background: none; border: 0; padding: 6px 2px; min-height: 48px; }
.bn-item.active { color: var(--teal); }
.bn-item .count { position: absolute; top: 5px; left: calc(50% + 6px); }
.page-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head p { margin-top: 4px; }
.page-head > div { min-width: 0; }
h1, h2, h3 { overflow-wrap: anywhere; }
.grid { display: grid; gap: 12px; margin-bottom: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; min-width: 0; }
.grid > .card { margin-bottom: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card > h2 { margin-bottom: 10px; }
.empty { color: var(--muted); text-align: center; padding: 18px 8px; }
.foot-note { display: flex; gap: 6px; align-items: center; justify-content: center; text-align: center; margin-top: 4px; }
.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kpi { display: flex; flex-direction: column; gap: 2px; }
.kpi-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.kpi-val { font-size: 28px; line-height: 1.15; letter-spacing: -.02em; }
.kpi-val small { font-size: 16px; color: var(--muted); font-weight: 500; }
.kpi-sub { font-size: 12px; color: var(--muted); }
.kpi.warn { border-color: rgba(255,176,32,.5); background: linear-gradient(180deg, var(--amber-bg), var(--card)); }
.kpi.warn .kpi-val { color: var(--amber); }
.cols-main, .cols-3 { grid-template-columns: minmax(0, 1fr); }

/* ---------- Controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 44px; padding: 0 16px; border-radius: 11px; border: 1px solid var(--line2); background: var(--card2); color: var(--text); font-weight: 600; }
.btn:hover { border-color: var(--teal); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--teal); border-color: var(--teal); color: #04211d; }
.btn-primary:hover { background: #5eead4; }
.btn-amber { background: var(--amber); border-color: var(--amber); color: #2a1a00; }
.btn-danger { background: var(--red-bg); border-color: rgba(255,93,77,.6); color: #ff9a8f; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-sm { min-height: 38px; padding: 0 12px; font-size: 13.5px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.seg { display: inline-flex; background: var(--bg2); border: 1px solid var(--line); border-radius: 11px; padding: 3px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 8px 13px; min-height: 40px; border-radius: 8px; font-weight: 600; }
.seg button.on { background: var(--teal); color: #04211d; }
.field > .seg { display: flex; flex-wrap: nowrap; width: 100%; }
.field > .seg button { flex: 1 1 0; min-width: 0; padding: 8px 4px; font-size: 13px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 40px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line2); background: var(--card); color: var(--muted); font-weight: 600; white-space: nowrap; }
.chip b { color: var(--text); margin-left: 4px; }
.chip.on { background: var(--teal-bg); border-color: var(--teal); color: var(--teal); }
.tabs { display: flex; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button { flex: 1; min-height: 46px; background: none; border: 0; border-bottom: 3px solid transparent; color: var(--muted); font-weight: 600; }
.tabs button.on { color: var(--teal); border-color: var(--teal); }
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field > span { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.field output { color: var(--teal); font-weight: 700; }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg2); border: 1px solid var(--line2); border-radius: 10px; padding: 0 12px; min-height: 44px; width: 100%; }
textarea { padding: 10px 12px; resize: vertical; }
input[type="range"] { padding: 0; accent-color: var(--teal); min-height: 36px; background: transparent; border: 0; }
input[type="checkbox"] { min-height: 0; width: auto; }
select { appearance: auto; }
.inline-select { min-height: 36px; width: auto; max-width: 100%; }
.inline-f { max-width: 220px; margin: 4px 0 12px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.switch-row:last-child { border-bottom: 0; }
.switch-row.small { padding: 0; border: 0; gap: 8px; font-size: 12.5px; color: var(--muted); }
.switch-row.disabled { opacity: .6; }
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex: none; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; background: var(--line2); border-radius: 99px; transition: background .15s; }
.switch i::after { content: ""; position: absolute; width: 20px; height: 20px; top: 3px; left: 3px; background: #fff; border-radius: 50%; transition: transform .15s; }
.switch input:checked + i { background: var(--teal); }
.switch input:checked + i::after { transform: translateX(20px); }
.switch input:disabled { cursor: not-allowed; }
.search { display: flex; align-items: center; gap: 8px; background: var(--bg2); border: 1px solid var(--line2); border-radius: 10px; padding: 0 12px; margin-bottom: 10px; }
.search input { border: 0; background: transparent; padding: 0; }
.search input:focus { outline: none; }
.toolbar { padding-bottom: 8px; }
.filters summary { cursor: pointer; font-weight: 600; color: var(--teal); min-height: 36px; display: flex; align-items: center; }
.filter-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 10px; margin-top: 8px; }
.result-count { margin: 0 2px 8px; }

/* ---------- Badges & tags ---------- */
.badge { display: inline-flex; align-items: center; font-size: 11.5px; font-weight: 700; text-transform: capitalize; padding: 3px 9px; border-radius: 99px; border: 1px solid transparent; white-space: nowrap; }
.badge.sev-critical { background: var(--red-bg); color: #ff8a7d; border-color: rgba(255,93,77,.5); }
.badge.sev-high { background: var(--amber-bg); color: var(--amber); border-color: rgba(255,176,32,.5); }
.badge.sev-medium { background: rgba(242,214,117,.12); color: var(--yellow); border-color: rgba(242,214,117,.4); }
.badge.sev-low { background: rgba(107,134,168,.18); color: #9fb6d4; border-color: rgba(107,134,168,.4); }
.badge.st-new, .badge.ast-new { background: var(--amber-bg); color: var(--amber); border-color: rgba(255,176,32,.45); }
.badge.st-confirmed, .badge.ast-resolved { background: rgba(52,211,153,.13); color: var(--green); border-color: rgba(52,211,153,.4); }
.badge.st-reviewed, .badge.ast-acknowledged { background: var(--teal-bg); color: var(--teal); border-color: rgba(45,212,191,.4); }
.badge.st-false_positive, .badge.ast-dismissed { background: rgba(107,134,168,.15); color: var(--muted); border-color: var(--line2); }
.badge.cs-online { background: rgba(52,211,153,.13); color: var(--green); border-color: rgba(52,211,153,.4); }
.badge.cs-degraded { background: var(--amber-bg); color: var(--amber); border-color: rgba(255,176,32,.5); }
.badge.cs-offline { background: var(--red-bg); color: #ff8a7d; border-color: rgba(255,93,77,.5); }
.badge.cs-paused { background: rgba(107,134,168,.15); color: var(--muted); border-color: var(--line2); }
.simtag { display: inline-block; font-size: 10.5px; font-weight: 800; letter-spacing: .06em; color: var(--amber); border: 1px dashed rgba(255,176,32,.7); padding: 2px 7px; border-radius: 6px; vertical-align: middle; }
.simchip { display: inline-block; font-size: 9.5px; font-weight: 800; letter-spacing: .05em; color: var(--amber); border: 1px solid rgba(255,176,32,.5); padding: 0 5px; border-radius: 5px; margin-left: 4px; vertical-align: middle; }
.conf { display: inline-flex; align-items: center; gap: 8px; }
.conf-bar { width: 54px; height: 6px; border-radius: 4px; background: var(--line); overflow: hidden; display: inline-block; }
.conf-bar i { display: block; height: 100%; background: var(--teal); }
.conf b, .conf-mini { font-size: 13px; font-variant-numeric: tabular-nums; }
.conf-mini { color: var(--muted); }
.notice { display: flex; gap: 10px; align-items: flex-start; padding: 11px 13px; border-radius: 12px; margin-bottom: 12px; border: 1px solid var(--line2); background: var(--card2); }
.notice .ic { margin-top: 2px; }
.notice.amber { background: var(--amber-bg); border-color: rgba(255,176,32,.4); color: #ffd58a; }
.notice.red { background: var(--red-bg); border-color: rgba(255,93,77,.5); color: #ffb0a8; }
.dot, .sevdot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.online { background: var(--green); }
.dot.degraded { background: var(--amber); }
.dot.offline { background: var(--red); }
.dot.paused { background: var(--slate); }
.dot.pulse { animation: pulse 1.4s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(52,211,153,.6); } 100% { box-shadow: 0 0 0 10px rgba(52,211,153,0); } }
.sevdot.sev-critical, .sevbar.sev-critical { background: var(--red); }
.sevdot.sev-high, .sevbar.sev-high { background: var(--amber); }
.sevdot.sev-medium, .sevbar.sev-medium { background: var(--yellow); }
.sevdot.sev-low, .sevbar.sev-low { background: var(--slate); }

/* ---------- Charts & lists ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart .gl { stroke: var(--line); stroke-width: 1; }
.chart .ax, .donut .ax { fill: var(--muted); font-size: 10.5px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 12px; color: var(--muted); text-transform: capitalize; }
.legend i, .legend-list i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.donut-wrap { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; justify-content: center; }
.donut { width: 140px; height: 140px; flex: none; }
.donut .d-num { fill: var(--text); font-size: 26px; font-weight: 700; }
.legend-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; min-width: 130px; text-transform: capitalize; }
.legend-list li { display: flex; align-items: center; }
.legend-list b { margin-left: auto; padding-left: 14px; }
.list { display: grid; grid-template-columns: minmax(0, 1fr); }
.list-row { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: none; border: 0; border-top: 1px solid var(--line); padding: 11px 2px; min-height: 52px; }
.list-row:first-child { border-top: 0; }
button.list-row:hover, a.list-row:hover { background: rgba(255,255,255,.03); }
.list-row.static { cursor: default; }
.lr-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.lr-main b { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; font-size: 14px; line-height: 1.3; }
.lr-main small { overflow-wrap: anywhere; }
.hbars { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.hb { display: grid; grid-template-columns: minmax(0, 130px) minmax(0, 1fr) 28px; gap: 10px; align-items: center; font-size: 13px; }
.hb-track { height: 8px; background: var(--line); border-radius: 5px; overflow: hidden; }
.hb-track i { display: block; height: 100%; background: linear-gradient(90deg, var(--teal-d), var(--teal)); border-radius: 5px; }
.hb b { text-align: right; }

/* ---------- Detection list ---------- */
.dlist { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.drow { display: grid; grid-template-columns: 5px minmax(0, 1fr) auto; grid-template-areas: "bar main time" "bar badges conf"; gap: 6px 12px; align-items: center; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px 11px 0; overflow: hidden; width: 100%; }
.drow:hover { border-color: var(--teal-d); }
.sevbar { grid-area: bar; align-self: stretch; border-radius: 0 4px 4px 0; }
.d-main { grid-area: main; display: flex; flex-direction: column; min-width: 0; }
.d-main small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d-title { display: flex; align-items: center; gap: 6px; min-width: 0; }
.d-title b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d-title .simchip { flex: none; margin: 0; }
.d-zone { display: none; }
.d-conf { grid-area: conf; justify-self: end; }
.d-badges { grid-area: badges; display: flex; gap: 6px; flex-wrap: wrap; }
.d-time { grid-area: time; display: flex; flex-direction: column; align-items: flex-end; font-size: 13px; }
.d-time small { display: none; }

/* ---------- Cameras ---------- */
.cam-grid { grid-template-columns: minmax(0, 1fr); }
.cam { padding: 0; overflow: hidden; }
.cam-feed { display: block; width: 100%; padding: 0; border: 0; background: #000; aspect-ratio: 16 / 9; }
.feed { width: 100%; height: 100%; display: block; }
.feed-t { fill: #e8f0fd; font-size: 9px; font-family: ui-monospace, Menlo, monospace; paint-order: stroke; stroke: rgba(0,0,0,.6); stroke-width: 2px; }
.feed-big { fill: #7d93b5; font-size: 18px; font-weight: 700; letter-spacing: .12em; }
.feed-det { fill: #ffb020; font-size: 9px; font-weight: 700; font-family: ui-monospace, monospace; }
.cam-body { padding: 12px 14px 14px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.cam-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.cam-head small { display: block; }
.cam-issue { display: flex; gap: 6px; align-items: center; color: var(--amber); font-size: 12.5px; }
.cam-stats { display: flex; gap: 16px; font-size: 13px; color: var(--muted); }
.cam-stats b { color: var(--text); font-variant-numeric: tabular-nums; }
.cam-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cam.offline { border-color: rgba(255,93,77,.4); }
.cam.degraded { border-color: rgba(255,176,32,.4); }
.feed-wrap { border-radius: 12px; overflow: hidden; margin-bottom: 12px; aspect-ratio: 16 / 9; background: #000; }
.test-box { margin-top: 12px; font-size: 13px; color: var(--muted); display: grid; gap: 4px; }
.test-result { padding: 8px 10px; border-radius: 8px; font-weight: 600; }
.test-result.ok { background: rgba(52,211,153,.13); color: var(--green); }
.test-result.bad { background: var(--amber-bg); color: var(--amber); }

/* ---------- Alerts ---------- */
.alist { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.alert-card { border-left: 4px solid var(--slate); margin: 0; }
.alert-card.sev-b-critical { border-left-color: var(--red); }
.alert-card.sev-b-high { border-left-color: var(--amber); }
.alert-card.sev-b-medium { border-left-color: var(--yellow); }
.a-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.a-title { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 0; font-weight: 700; font-size: 15.5px; line-height: 1.3; margin-bottom: 4px; overflow-wrap: anywhere; word-break: break-word; }
.alert-card p { overflow-wrap: anywhere; }
.a-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.rules { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.rule { margin: 0; }
.rule-head { display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; }
.rule-ctl { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 12px; margin-top: 10px; }
.note-form { display: flex; gap: 8px; align-items: flex-start; }
.m-title { margin: 6px 0 10px; font-size: 17px; overflow-wrap: anywhere; }
.timeline-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; font-size: 13px; color: var(--muted); }
.timeline-list li, .note-line { overflow-wrap: anywhere; }
.timeline-list b { color: var(--text); font-weight: 600; margin-right: 6px; }

/* ---------- Video analysis ---------- */
.drop { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; padding: 26px 14px; border: 2px dashed var(--line2); border-radius: 14px; cursor: pointer; color: var(--teal); }
.drop:hover { border-color: var(--teal); background: var(--teal-bg); }
.drop b { color: var(--text); font-size: 16px; }
.player { position: relative; background: #000; border-radius: 12px; overflow: hidden; line-height: 0; }
.player video { width: 100%; max-height: 62vh; background: #000; display: block; }
.player canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; }
.file-meta { display: flex; flex-direction: column; gap: 2px; margin: 10px 0 4px; word-break: break-all; }
.timeline { margin-top: 10px; }
.tl-head { display: flex; justify-content: space-between; margin-bottom: 4px; }
.tl-track { position: relative; height: 26px; background: var(--bg2); border: 1px solid var(--line2); border-radius: 8px; cursor: pointer; touch-action: pan-y; }
.tl-wrap { position: relative; }
.tl-marks { position: absolute; inset: 0 1px; pointer-events: none; }
.tl-mark { pointer-events: auto; position: absolute; top: 3px; bottom: 3px; min-width: 8px; border: 0; padding: 0; border-radius: 4px; background: var(--teal); }
.tl-mark.hi { background: var(--amber); }
.tl-head-pos { position: absolute; top: -2px; bottom: -2px; width: 2px; background: #fff; pointer-events: none; }
.progress { height: 10px; background: var(--line); border-radius: 6px; overflow: hidden; margin: 12px 0 8px; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--teal-d), var(--teal)); width: 0; }

/* ---------- Demo ---------- */
.demo-status { display: flex; align-items: center; gap: 12px; }
.scen-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.scen { display: flex; flex-direction: column; gap: 3px; text-align: left; padding: 12px 14px; min-height: 64px; background: var(--card2); border: 1px solid var(--line2); border-radius: 12px; }
.scen:hover { border-color: var(--amber); }

/* ---------- Modal, toasts, misc ---------- */
.modal-back { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; background: rgba(3,8,18,.72); }
.modal { width: 100%; max-width: 580px; max-height: 90vh; max-height: 90dvh; display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line2); border-radius: 18px 18px 0 0; animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: .4; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 14px 18px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal-foot { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; padding: 12px 18px calc(12px + var(--safe-b)); border-top: 1px solid var(--line); }
.kv-grid { display: grid; gap: 0; }
.kv { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv > span { color: var(--muted); flex: none; }
.kv b { font-weight: 600; text-align: right; min-width: 0; overflow-wrap: anywhere; }
.note-line { margin: 12px 0; font-size: 14px; }
.more-list { display: grid; gap: 8px; }
.more-link { display: flex; align-items: center; gap: 14px; padding: 14px; min-height: 56px; background: var(--card2); border: 1px solid var(--line2); border-radius: 12px; font-weight: 600; }
.more-link .ic { color: var(--teal); }
#toasts { position: fixed; left: 12px; right: 12px; bottom: calc(var(--nav-h) + var(--safe-b) + 12px); z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 10px; max-width: 520px; background: #1a3358; border: 1px solid var(--line2); border-radius: 12px; padding: 11px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.4); font-size: 14px; animation: up .2s ease-out; }
.toast .ic { color: var(--teal); }
.toast.alert { background: #3a2a0a; border-color: rgba(255,176,32,.7); color: #ffe0a8; }
.toast.alert .ic { color: var(--amber); }
.toast.out { opacity: 0; transition: opacity .3s; }

/* ---------- Desktop ---------- */
@media (min-width: 640px) {
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .cam-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .scen-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .rule-ctl { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .filter-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 900px) {
  .sidebar { display: flex; }
  .bottomnav, .brand-m { display: none; }
  .topbar .org-chip { display: inline-block; }
  main { padding: 24px 28px 40px; }
  h1 { font-size: 26px; }
  .cols-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
  .cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cam-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .modal-back { align-items: center; }
  .modal { border-radius: 18px; }
  #toasts { bottom: 24px; left: auto; right: 24px; align-items: flex-end; }
  .drow { grid-template-columns: 5px minmax(0, 1.5fr) minmax(0, 1fr) 150px 190px 130px; grid-template-areas: "bar main zone conf badges time"; padding: 12px 14px 12px 0; }
  .d-zone { display: block; grid-area: zone; font-size: 13px; }
  .d-time small { display: block; }
  .filter-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .topbar { justify-content: flex-end; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- Accessibility ---------- */
.sr-only { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 12px; top: -64px; z-index: 300; background: var(--teal); color: #04211d; font-weight: 700; padding: 10px 14px; border-radius: 10px; border: 0; }
.skip-link:focus { top: calc(8px + env(safe-area-inset-top, 0px)); }
.modal:focus, main:focus { outline: none; }
.modal-body { overscroll-behavior: contain; }
.switch input:focus-visible + i { outline: 2px solid var(--teal); outline-offset: 2px; }
.drop:focus-visible, .tl-track:focus-visible, .tl-mark:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.tabs button[aria-selected="true"] { color: var(--teal); border-color: var(--teal); }
.chip[aria-pressed="true"] { background: var(--teal-bg); border-color: var(--teal); color: var(--teal); }
.seg button[aria-pressed="true"] { background: var(--teal); color: #04211d; }
.backup-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.backup-row p { min-width: 0; overflow-wrap: anywhere; }

/* Phase 1: unbreakable user-supplied strings (org name, camera name, zone, file name) must wrap, never widen the page */
.page-head p, .muted, .small, .cam-head, .cam-head *, .cam-card h3, .cam-meta, .lr-main, .lr-main *, .d-main, .d-main *, .notice span, .modal-body p, .modal-body dd, .kv * { overflow-wrap: anywhere; min-width: 0; }
.cam-head { min-width: 0; }
.cam-head > div { min-width: 0; }
/* Phase 1: implicit grid columns are `auto` (min-content sized); pin single-column grids so long words cannot widen them */
.side-foot, .field, .test-box, .kv-grid, .more-list, .legend-list { grid-template-columns: minmax(0, 1fr); }

/* Capability registry (Settings > System status) */
.simchip.ok { color: var(--green); border-color: rgba(52,211,153,.5); }
.caps { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.caps li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; min-width: 0; }
.caps .simchip { margin-left: 0; }
.caps-name { font-weight: 600; }
.caps-detail { flex-basis: 100%; min-width: 0; overflow-wrap: anywhere; }

/* Inference service card (Phase 3.5) */
.notice.teal { background: rgba(45,212,191,.08); border-color: rgba(45,212,191,.4); color: #9ff0e3; }
.svc-opts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; }
.svc-status { margin: 10px 0 4px; }
@media (max-width: 420px) { .svc-opts { grid-template-columns: minmax(0, 1fr); } }
