:root {
  --bg: #0b0d10; --panel: #13161b; --panel2: #1a1e25; --line: #262b34;
  --text: #e6e8eb; --muted: #8b93a1; --accent: #3b82f6;
  --ok: #22c55e; --warn: #f5a524; --bad: #ef4444;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 14px; }
button, .btn, select, input { font: inherit; color: inherit; }
button, .btn {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 10px; cursor: pointer; text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { border-color: #3a4150; }
button.on { background: var(--accent); border-color: var(--accent); }
.hidden { display: none !important; }
.spacer { flex: 1; }
.meta { color: var(--muted); font-size: 12px; }

.top { display: flex; align-items: center; gap: 12px; height: 48px; padding: 0 14px;
  background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 650; letter-spacing: .02em; display: flex; align-items: center; gap: 8px; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bad);
  box-shadow: 0 0 8px var(--bad); animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.layouts, .pager { display: flex; gap: 4px; align-items: center; }
.pager span { color: var(--muted); min-width: 36px; text-align: center; }
.clock { font-variant-numeric: tabular-nums; color: var(--muted); }
.conn { font-size: 12px; color: var(--muted); }
.conn.ok { color: var(--ok); } .conn.bad { color: var(--bad); }
.arm { font-weight: 600; }
.arm.armed { background: #3b1114; border-color: var(--bad); color: #fecaca; }
.arm.disarmed { color: var(--muted); }

.main { display: flex; height: calc(100% - 48px); }
.wall { flex: 1; display: grid; gap: 4px; padding: 4px; background: #000; min-width: 0; }
.tile { position: relative; background: #050607; border: 2px solid transparent; border-radius: 4px;
  overflow: hidden; cursor: pointer; min-height: 0; }
.tile img { width: 100%; height: 100%; object-fit: contain; display: block; }
.tile img:not([src]), .focus-body img:not([src]), .feed .thumb:not([src]) { visibility: hidden; }
.tile .bar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 8px; align-items: center;
  padding: 4px 8px; background: linear-gradient(transparent, rgba(0,0,0,.8)); font-size: 12px; }
.tile .name { font-weight: 600; }
.tile .placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.tile .badge { position: absolute; top: 6px; left: 6px; background: var(--bad); color: #fff;
  font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 4px; text-transform: uppercase; }
.tile.alarm { border-color: var(--bad); animation: alarm 1s infinite; }
@keyframes alarm { 50% { border-color: transparent; } }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.online { background: var(--ok); } .dot.connecting, .dot.reconnecting, .dot.starting { background: var(--warn); }
.dot.offline { background: var(--bad); }

.side { width: 340px; flex: none; background: var(--panel); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.side-head h2 { margin: 0; font-size: 14px; }
.side-head select { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; }
.feed { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.feed li { display: flex; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.feed li:hover { background: var(--panel2); }
.feed li.live { background: rgba(239,68,68,.08); box-shadow: inset 3px 0 var(--bad); }
.feed .thumb { width: 96px; height: 54px; flex: none; background: #000; border-radius: 4px; object-fit: cover; }
.feed .t { font-weight: 600; }
.feed .s { color: var(--muted); font-size: 12px; margin-top: 2px; }
.sys { border-top: 1px solid var(--line); padding: 8px 12px; font-size: 12px; color: var(--muted); line-height: 1.6; }
.sys button { font-size: 12px; padding: 2px 8px; }

.focus { position: fixed; inset: 0; background: #000; z-index: 10; display: flex; flex-direction: column; }
.focus-bar { display: flex; gap: 10px; align-items: center; padding: 8px 12px; background: var(--panel); }
.focus-body { flex: 1; position: relative; min-height: 0; }
.focus-body img { width: 100%; height: 100%; object-fit: contain; }
.ptz { position: absolute; right: 16px; bottom: 16px; background: rgba(19,22,27,.9); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.pad { display: grid; grid-template-columns: repeat(3, 44px); gap: 4px; }
.pad button { height: 44px; font-size: 18px; user-select: none; }
.zoom { display: flex; gap: 4px; } .zoom button { flex: 1; }
.preset { display: flex; gap: 4px; } .preset input { width: 60px; background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 20; display: grid; place-items: center; padding: 16px; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; max-width: 960px; width: 100%; overflow: hidden; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); font-weight: 600; }
#modalBody { padding: 12px; } #modalBody img, #modalBody video { width: 100%; border-radius: 6px; background: #000; }

/* NVR manager */
.top select { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; max-width: 200px; }
.modal-box.wide { max-width: 1100px; max-height: 92vh; display: flex; flex-direction: column; }
.nvr-body { padding: 14px; overflow-y: auto; }
.nvr-toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
button.primary { background: var(--accent); border-color: var(--accent); font-weight: 600; }
button.danger { color: #fecaca; border-color: #5b1d1d; }
.nvr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.nvr-card { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.nvr-card.off { border-color: #5b1d1d; }
.nvr-card .head { display: flex; justify-content: space-between; gap: 8px; align-items: start; }
.nvr-card h3 { margin: 0; font-size: 15px; }
.pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: #2a2f38; color: var(--muted); white-space: nowrap; }
.pill.on { background: rgba(34,197,94,.15); color: var(--ok); } .pill.off { background: rgba(239,68,68,.15); color: var(--bad); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.stat { background: var(--panel); border-radius: 6px; padding: 6px; text-align: center; }
.stat b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--muted); }
.stat.alarm b { color: var(--bad); }
.nvr-card .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 14px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.form-grid label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 13px; padding-top: 18px; }
.form-grid input, .form-grid select, .ch-table input[type=text] { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; color: var(--text); }
.ch-table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 13px; }
.ch-table th { text-align: left; color: var(--muted); font-weight: 500; padding: 6px; border-bottom: 1px solid var(--line); }
.ch-table td { padding: 4px 6px; border-bottom: 1px solid var(--line); }
.ch-table input[type=text] { width: 100%; padding: 5px 8px; }
.note { padding: 10px 12px; border-radius: 8px; background: var(--panel2); border: 1px solid var(--line); margin: 12px 0; font-size: 13px; }
.note.err { border-color: #5b1d1d; color: #fecaca; } .note.ok { border-color: #1d5b33; color: #bbf7d0; }
.empty { display: grid; place-content: center; justify-items: center; gap: 6px; text-align: center; color: var(--text); }
.empty h3 { margin: 0; }

.login-body { display: grid; place-items: center; }
.login { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; width: min(340px, 92vw);
  display: flex; flex-direction: column; gap: 14px; }
.login label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
.login input { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; }
.login button { background: var(--accent); border-color: var(--accent); padding: 9px; font-weight: 600; }
.err { color: var(--bad); margin: 0; min-height: 1em; }

@media (max-width: 900px) {
  .main { flex-direction: column; }
  .side { width: auto; height: 40%; border-left: 0; border-top: 1px solid var(--line); }
  .top { gap: 6px; padding: 0 8px; overflow-x: auto; }
  .clock, .conn { display: none; }
}

/* AI overlay */
canvas.ov { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.focus-body canvas.ov { position: absolute; }
.filters { display: flex; gap: 6px; }
.filters select { max-width: 140px; }
.feed li.more { justify-content: center; color: var(--muted); font-size: 13px; }

/* settings center */
.tabs { display: flex; gap: 4px; padding: 8px 12px 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { border-radius: 8px 8px 0 0; border-bottom: none; white-space: nowrap; background: transparent; }
.tab.on { background: var(--panel2); border-color: var(--line); color: var(--text); font-weight: 600; }
.scard { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 12px;
  display: flex; flex-direction: column; gap: 12px; }
.scard h3 { margin: 0; font-size: 14px; }
.frow { display: grid; grid-template-columns: 240px 1fr; gap: 4px 14px; align-items: center; }
.frow > input, .frow > select { max-width: 520px; }
.flabel { color: var(--muted); font-size: 13px; }
.fhelp { grid-column: 2; font-size: 12px; color: var(--muted); }
.frow input[type=text], .frow input[type=password], .frow input[type=url], .frow input[type=number], .frow select,
.nvr-toolbar input[type=text], .sched input[type=time] {
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; color: var(--text); }
.frow input[type=number] { width: 120px; }
.frow-check { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.frow-check .fhelp { flex-basis: 100%; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.confs { display: flex; flex-direction: column; gap: 4px; }
.conf, .inline { display: flex; align-items: center; gap: 10px; }
.conf span:first-child { width: 64px; font-size: 13px; }
.conf input[type=range], .inline input[type=range] { width: 220px; }
.sched { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.sched-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; }
.savebar { margin: 0; }
.sysline { font-size: 13px; }
pre.logs { background: #07090b; border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin: 0;
  max-height: 46vh; overflow: auto; font-size: 11.5px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.zone-wrap { position: relative; display: inline-block; max-width: 100%; }
.zone-wrap img { display: block; max-width: 100%; max-height: 62vh; border-radius: 6px; background: #000; min-width: 320px; min-height: 180px; }
.zone-wrap canvas { position: absolute; left: 0; top: 0; cursor: crosshair; }
#zoneModal, #setModal { z-index: 30; } #zoneModal { z-index: 40; }
@media (max-width: 760px) { .frow { grid-template-columns: 1fr; } .fhelp { grid-column: 1; } }

/* playback */
.pb { position: fixed; inset: 0; background: var(--bg); z-index: 15; display: flex; flex-direction: column; }
.pb .focus-bar select, .pb .focus-bar input { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; color: var(--text); }
.pb-main { flex: 1; display: flex; min-height: 0; }
.pb-video { flex: 1; background: #000; min-width: 0; display: grid; place-items: center; }
.pb-video img { max-width: 100%; max-height: 100%; object-fit: contain; }
.pb-video img:not([src]) { visibility: hidden; }
.pb-side { width: 320px; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; padding: 0 0 10px; }
.pb-side h3 { font-size: 13px; margin: 10px 12px 6px; }
.pb-side .feed { flex: 1; min-height: 120px; }
.pb-export { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 0 12px; }
.pb-export select { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 4px; color: var(--text); }
.pb-side .fhelp { padding: 0 12px; }
#pbExports { display: flex; flex-direction: column; gap: 6px; padding: 0 12px; }
.export { display: flex; gap: 8px; align-items: center; font-size: 12px; }
.export .btn { font-size: 12px; }
.pb-controls { display: flex; gap: 6px; align-items: center; padding: 8px 12px; background: var(--panel); border-top: 1px solid var(--line); flex-wrap: wrap; }
.pb-time { font-variant-numeric: tabular-nums; font-weight: 600; margin-left: 10px; }
.ok-text { color: var(--ok); }
.pb-legend { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.pb-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-left: 6px; }
.pb-bar { display: block; width: 100%; height: 34px; cursor: pointer; background: var(--panel2); }
.pb-hour { height: 42px; border-top: 1px solid var(--line); }
@media (max-width: 900px) { .pb-main { flex-direction: column; } .pb-side { width: auto; height: 38%; border-left: 0; } .pb-legend { display: none; } }

/* layout fixes: never scroll sideways */
html, body { overflow-x: hidden; }
.top { min-width: 0; overflow-x: auto; scrollbar-width: none; }
.top > * { flex-shrink: 0; }
.top .spacer { flex-shrink: 1; min-width: 0; }
.side-head { flex-wrap: wrap; gap: 6px; }
.side-head .filters { flex: 1; min-width: 0; justify-content: flex-end; }
.side-head .filters select { min-width: 0; max-width: 48%; }
@media (max-width: 1500px) { .clock { display: none; } }
@media (max-width: 1200px) { #boxesBtn, #sound { display: none; } }
.tabs { flex-shrink: 0; min-height: 42px; }
.tab { padding: 8px 12px; }
table.rules td:not(:first-child), table.rules th:not(:first-child) { text-align: center; width: 90px; }
table.rules td.custom { background: rgba(59,130,246,.12); }

/* reports — series slots validated (dataviz validator, dark surface #13161b) */
:root { --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-bottom: 12px; }
.kpi { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.kpi-label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.kpi-label i, .rlegend i, .tip-row i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.kpi-value { font-size: 28px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 4px; }
.kpi-delta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.rlegend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.rlegend span { display: inline-flex; align-items: center; gap: 6px; }
svg.rchart { width: 100%; height: auto; display: block; }
.rgrid { stroke: var(--line); stroke-width: 1; }
.raxis { fill: var(--muted); font-size: 11px; font-family: system-ui, sans-serif; }
.rhit { fill: transparent; cursor: crosshair; }
.rhit:hover { fill: rgba(255,255,255,.04); }
.rcross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.rdot { stroke: var(--panel2); stroke-width: 2; }
.rtip { position: fixed; z-index: 60; background: #0b0d10; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px; pointer-events: none; min-width: 150px; }
.tip-title { color: var(--text); font-weight: 600; margin-bottom: 4px; }
.tip-row { display: grid; grid-template-columns: 10px 1fr auto; gap: 8px; align-items: center; color: var(--muted); }
.tip-row b { color: var(--text); font-variant-numeric: tabular-nums; }
.rtable td.num, .rtable th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
#repModal .modal-head input { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; color: var(--text); }
#repModal { z-index: 30; }

/* people */
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.pcard { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 8px; cursor: pointer; text-align: center; }
.pcard:hover { border-color: #3a4150; }
.pcard.known { border-color: #1d4f8a; }
.pcard.ignored { opacity: .55; }
.pcard img, .scard img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: #000; display: block; }
.pname { font-weight: 600; margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.phead { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 12px; }
.phead > img { width: 140px; height: 140px; object-fit: cover; border-radius: 10px; background: #000; flex: none; }
.pinfo { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.pinfo input[type=text], #peoBody .nvr-toolbar input[type=text], #peoBody select { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; color: var(--text); min-width: 0; }
.shead { font-size: 14px; margin: 8px 0; }
.sgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.scard { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 6px; font-size: 12px; }
.sacts { display: flex; gap: 4px; margin-top: 4px; } .sacts button { font-size: 11px; padding: 2px 6px; }
img.fthumb { width: 32px; height: 32px; border-radius: 6px; object-fit: cover; background: #000; display: block; }
#peoModal { z-index: 30; }
@media (max-width: 700px) { .phead { flex-direction: column; } }

.nameedit { display: flex; gap: 4px; margin-top: 6px; }
.nameedit input { flex: 1; min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; color: var(--text); }
.nameedit button { padding: 2px 8px; }
.namebtn { margin-top: 6px; font-size: 12px; padding: 2px 8px; }
input.tilename { background: rgba(0,0,0,.7); border: 1px solid var(--accent); border-radius: 4px; color: var(--text); padding: 1px 4px; font-weight: 600; width: 160px; }
