/* Layout: control-room feed — stats strip, device rail, live alert grid. */
:root {
  --bg: #f4f5f7; --panel: #ffffff; --ink: #161b22; --muted: #5d6673; --line: #dde1e7;
  --accent: #e8641b; --ok: #1f8a5a; --warn: #c98a00; --crit: #c8322b; --info: #2f6fb5;
  --chip: #eef0f3; --shadow: 0 1px 2px rgba(20,24,31,.06), 0 4px 16px rgba(20,24,31,.05);
  --font: "PingFang HK", "Microsoft JhengHei", "Noto Sans HK", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1217; --panel: #171b22; --ink: #e8ebef; --muted: #9099a6; --line: #262c36;
          --chip: #1f2530; --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); }
h1 { font-size: 17px; margin: 0; letter-spacing: .02em; }
h2 { font-size: 12px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.muted { color: var(--muted); }
button { font: inherit; cursor: pointer; }
button:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); border-radius: 6px; padding: 5px 12px; }
.ghost:hover { border-color: var(--muted); }

.top { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
  background: #14181f; color: #f1f3f5; }
.top .ghost { color: #f1f3f5; border-color: #3a414d; }
.brand, .actions { display: flex; align-items: center; gap: 10px; }
.env { font-size: 11px; padding: 1px 8px; border-radius: 99px; background: #2a313c; color: #c7ccd4; }
.clock { font-family: var(--mono); font-variant-numeric: tabular-nums; color: #c7ccd4; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #6b7280; display: inline-block; }
.dot.on { background: #34c77b; box-shadow: 0 0 0 3px rgba(52,199,123,.2); }

main { padding: 16px max(16px, env(safe-area-inset-right)) 32px max(16px, env(safe-area-inset-left)); max-width: 1500px; margin: 0 auto; }
.stats { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; min-width: 120px; }
.stat .n { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: 12px; }
.stat .open { font-size: 11px; color: var(--crit); }

.layout { display: grid; grid-template-columns: 240px 1fr; gap: 16px; align-items: start; }
@media (max-width: 820px) { .layout { grid-template-columns: 1fr; } }
.side { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px; display: grid; gap: 14px; }
.devices { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.devices li { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; }
.devices .dot { margin-top: 6px; flex: none; }
.devices .sn { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.field { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
select { font: inherit; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); }

.feed { min-width: 0; }
.feed-head { display: flex; align-items: baseline; gap: 10px; }
.events { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.empty { grid-column: 1 / -1; background: var(--panel); border: 1px dashed var(--line); border-radius: 8px; padding: 32px; text-align: center; }
.empty p { margin: 4px 0; }

.ev { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.ev.fresh { animation: flash 2.2s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 3px var(--accent); } to { box-shadow: var(--shadow); } }
@media (prefers-reduced-motion: reduce) { .ev.fresh { animation: none; } }
.ev.done { opacity: .62; }
.thumb { position: relative; aspect-ratio: 16 / 9; background: #0b0d10; cursor: zoom-in; border: 0; padding: 0; width: 100%; display: block; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.thumb .noimg { position: absolute; inset: 0; color: #6b7280; display: grid; place-items: center; font-size: 12px; }
.box { position: absolute; border: 2px solid var(--crit); border-radius: 2px; pointer-events: none; }
.ev-body { padding: 10px 12px; display: grid; gap: 6px; }
.ev-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.badge { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 4px; color: #fff; }
.t-no_helmet { background: var(--warn); } .t-smoking { background: #8a5a2b; } .t-fall { background: var(--crit); }
.t-fire, .t-smoke { background: #b4451d; } .t-intrusion { background: var(--info); } .t-crowd { background: #6a4fb0; } .t-other { background: #5d6673; }
.time { font-family: var(--mono); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.where { font-size: 13px; overflow-wrap: anywhere; }
.where .sub { color: var(--muted); font-size: 12px; }
.st { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--chip); color: var(--muted); }
.st.new { background: rgba(200,50,43,.12); color: var(--crit); }
.ev-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.ev-actions button { font-size: 12px; padding: 3px 9px; border-radius: 5px; border: 1px solid var(--line); background: transparent; color: var(--ink); }
.ev-actions button:hover { border-color: var(--muted); }
.ev-actions button.primary { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.more { margin: 16px auto 0; display: block; }

.tabs { display: flex; gap: 4px; margin-left: 12px; }
.tabs a { color: #aab2bd; text-decoration: none; padding: 4px 12px; border-radius: 6px; font-size: 14px; }
.tabs a:hover { color: #fff; }
.tabs a.on { background: #2a313c; color: #fff; }
@media (max-width: 560px) { .env, .clock { display: none; } .tabs { margin-left: 4px; } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; margin-bottom: 16px; }
.panel-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.panel-head h2 { margin: 0; }
.panel-head button { margin-left: auto; }
.small { font-size: 12px; }
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl td.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl td.ua { color: var(--muted); font-size: 11px; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tbl tr.me td:first-child::after { content: " （你）"; color: var(--accent); font-family: var(--font); }
.tbl .empty-row td { color: var(--muted); text-align: center; padding: 18px; }
.pill { font-size: 11px; padding: 1px 8px; border-radius: 99px; white-space: nowrap; }
.pill.ok { background: rgba(31,138,90,.14); color: var(--ok); }
.pill.bad { background: rgba(200,50,43,.12); color: var(--crit); }
.pill.info { background: var(--chip); color: var(--muted); }
.ghost.danger { color: var(--crit); border-color: rgba(200,50,43,.4); }
.top .ghost.danger { color: #ff8b84; }

dialog { border: 0; padding: 0; background: #0b0d10; color: #e8ebef; max-width: min(1200px, 96vw); width: 100%; border-radius: 8px; }
dialog::backdrop { background: rgba(0,0,0,.7); }
.viewer-img { position: relative; }
.viewer-img img { width: 100%; display: block; }
.viewer-meta { padding: 10px 14px; font-size: 13px; }
.close { position: absolute; top: 6px; right: 8px; z-index: 2; background: rgba(0,0,0,.5); color: #fff; border: 0; width: 32px; height: 32px; border-radius: 50%; font-size: 20px; line-height: 1; }
.tbl td.geo { min-width: 120px; }
.tbl td.geo .isp { display: block; color: var(--muted); font-size: 11px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.geo-note { margin: 10px 0 0; }
.live-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: 12px; margin-top: 8px; }
.live-tile { margin: 0; background: #0b0d10; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.live-tile video { width: 100%; aspect-ratio: 16 / 9; display: block; background: #0b0d10; cursor: zoom-in; object-fit: contain; }
.live-tile figcaption { display: flex; align-items: center; gap: 8px; padding: 8px 12px; color: #e8ebef; font-size: 13px; background: #14181f; }
.live-st { margin-left: auto; color: #9099a6; font-size: 12px; }
.usage { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin: 8px 0 4px; }
.usage .u { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; }
.usage .l { color: var(--muted); font-size: 12px; }
.usage .n { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.usage .s { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.live-bytes { color: #9099a6; font-size: 11px; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.live-st:empty { display: none; }
.live-st:empty + .live-bytes { margin-left: auto; }
.cam-pick { display: flex; flex-wrap: wrap; gap: 8px 12px; margin: 4px 0 10px; }
.cam-opt { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.cam-opt:has(input:checked) { border-color: var(--accent); background: rgba(232,100,27,.07); }
.cam-opt input { accent-color: var(--accent); width: 16px; height: 16px; }
.cam-actions { display: flex; align-items: center; gap: 10px; }
.usage .u-session { border-color: var(--accent); }
