:root {
  --bg: #0b0e14; --panel: #11161f; --panel2: #161c27; --line: #232b3a; --line2: #2e3849;
  --text: #e6eaf2; --muted: #8b95a8; --dim: #5d6779;
  --accent: #5b8cff; --accent2: #3d6ef0; --rec: #ff4d5e; --ok: #2fd08a; --warn: #ffb020; --motion: #ff9f1c;
  --radius: 12px; --sidebar: 220px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 12px; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 4px 10px 18px; letter-spacing: .2px; }
.brand img { width: 28px; height: 28px; }
.brand small { display: block; font-weight: 500; font-size: 11px; color: var(--muted); letter-spacing: 0; }
.bname { white-space: nowrap; }
.bname .nvr { background: linear-gradient(135deg, #22d3ee, #6366f1); -webkit-background-clip: text; background-clip: text; color: transparent; font-weight: 800; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 9px; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--panel2); color: var(--text); }
.nav a.active { background: rgba(91,140,255,.12); color: var(--text); }
.nav a.active svg { color: var(--accent); }
.nav svg { width: 19px; height: 19px; flex: none; }
.sidebar .spacer { flex: 1; }
.side-stats { border-top: 1px solid var(--line); padding: 14px 10px 0; color: var(--muted); font-size: 12px; display: grid; gap: 8px; }
.meter { height: 5px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.meter.warn > i { background: var(--warn); } .meter.bad > i { background: var(--rec); }
main { overflow: auto; position: relative; }
.page { padding: 22px 26px 40px; max-width: 1700px; margin: 0 auto; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 21px; margin: 0; font-weight: 650; flex: 1; letter-spacing: -.2px; }
.muted { color: var(--muted); } .dim { color: var(--dim); } .small { font-size: 12px; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 7px; background: var(--panel2); border: 1px solid var(--line2); color: var(--text); padding: 8px 14px; border-radius: 9px; cursor: pointer; font-weight: 550; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover { background: #1d2533; border-color: #3a465c; }
.btn.primary { background: var(--accent2); border-color: var(--accent2); }
.btn.primary:hover { background: var(--accent); }
.btn.danger { color: #ff8a95; } .btn.danger:hover { background: rgba(255,77,94,.12); border-color: var(--rec); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 16px; height: 16px; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line2); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { background: none; border: 0; padding: 5px 11px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 12.5px; }
.seg button.on { background: var(--panel2); color: var(--text); box-shadow: 0 0 0 1px var(--line2); }
input[type=text], input[type=password], input[type=number], input[type=url], input[type=date], select, textarea {
  background: var(--bg); border: 1px solid var(--line2); border-radius: 8px; padding: 9px 11px; width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,140,255,.15); }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }
label.field { display: grid; gap: 6px; font-weight: 550; font-size: 13px; }
label.field > span.hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { min-width: 0; }
.grow { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.check { display: flex; gap: 9px; align-items: center; cursor: pointer; font-weight: 500; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card h2 { font-size: 15px; margin: 0 0 14px; font-weight: 650; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 20px; background: var(--panel2); color: var(--muted); letter-spacing: .3px; text-transform: uppercase; }
.badge.rec { background: rgba(255,77,94,.15); color: #ff7a87; }
.badge.ok { background: rgba(47,208,138,.13); color: var(--ok); }
.badge.off { background: rgba(139,149,168,.12); }
.badge.warn { background: rgba(255,176,32,.14); color: var(--warn); }
.badge.motion { background: rgba(255,159,28,.18); color: var(--motion); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }
.badge.rec .dot { animation: blink 1.4s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.empty { text-align: center; padding: 70px 20px; color: var(--muted); }
.empty h3 { color: var(--text); font-size: 17px; margin: 14px 0 6px; }
.empty > svg { width: 46px; height: 46px; color: var(--dim); }
.err { color: #ff8a95; font-size: 13px; }

/* ---------- live grid ---------- */
.live-grid { display: grid; gap: 8px; grid-template-columns: repeat(var(--cols, 2), 1fr); }
.tile { position: relative; background: #000; border-radius: 10px; overflow: hidden; aspect-ratio: 16/9; cursor: pointer; border: 2px solid transparent; transition: border-color .25s; }
.tile.motion { border-color: var(--motion); box-shadow: 0 0 0 1px var(--motion), 0 0 24px rgba(255,159,28,.25); }
.tile img, .tile video { width: 100%; height: 100%; object-fit: contain; display: block; }
.tile video.hd { position: absolute; inset: 0; background: #000; }
.tile video.hd.hidden { display: none; }
.tile .overlay { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none;
  background: linear-gradient(180deg, rgba(0,0,0,.55) 0, transparent 22%, transparent 78%, rgba(0,0,0,.5) 100%); }
.tile .top, .tile .bottom { display: flex; align-items: center; gap: 8px; padding: 9px 11px; font-size: 12.5px; }
.tile .name { font-weight: 650; flex: 1; text-shadow: 0 1px 2px #000; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tile .clock { font-variant-numeric: tabular-nums; color: #d5dae4; text-shadow: 0 1px 2px #000; font-size: 12px; }
.tile .offline { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); text-align: center; font-size: 13px; padding: 20px; }
.live-grid.fill { height: calc(100vh - 110px); grid-auto-rows: 1fr; }
.live-grid.fill .tile { aspect-ratio: auto; }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(4,6,10,.72); backdrop-filter: blur(4px); z-index: 50; display: grid; place-items: center; padding: 20px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--panel); border: 1px solid var(--line2); border-radius: 16px; width: min(860px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column; box-shadow: 0 30px 80px rgba(0,0,0,.5); }
.modal header { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal header h2 { margin: 0; font-size: 17px; flex: 1; }
.modal .body { padding: 20px; overflow: auto; display: grid; gap: 18px; }
.modal footer { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--line); }
.modal.wide { width: min(1400px, 100%); }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); font-weight: 700; margin: 4px 0 -6px; display: flex; align-items: center; gap: 8px; }
.section-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.viewer .ptz { position: absolute; right: 14px; bottom: 14px; display: grid; grid-template-columns: repeat(3, 38px); grid-template-rows: repeat(3, 38px); gap: 4px; }
.ptz button { background: rgba(10,14,20,.72); border: 1px solid rgba(255,255,255,.12); border-radius: 9px; color: #fff; cursor: pointer; display: grid; place-items: center; font-size: 15px; user-select: none; }
.ptz button:hover { background: rgba(91,140,255,.55); }
.zoom-btns { position: absolute; left: 14px; bottom: 14px; display: flex; gap: 4px; }
.zoom-btns button { width: 38px; height: 38px; }

/* ---------- timeline ---------- */
.tl-layout { display: grid; grid-template-columns: 1fr 330px; gap: 16px; }
.player { background: #000; border-radius: 12px; overflow: hidden; position: relative; aspect-ratio: 16/9; }
.player video { width: 100%; height: 100%; display: block; background: #000; }
.player .nofootage { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; text-align: center; }
.player .ts { position: absolute; top: 10px; left: 12px; background: rgba(0,0,0,.6); padding: 4px 9px; border-radius: 6px; font-variant-numeric: tabular-nums; font-size: 13px; }
.tl-controls { display: flex; align-items: center; gap: 10px; margin: 12px 0 8px; flex-wrap: wrap; }
.timeline { position: relative; height: 66px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; cursor: crosshair; user-select: none; }
.timeline .track { position: absolute; left: 0; right: 0; top: 10px; height: 22px; }
.timeline .rec { position: absolute; top: 0; height: 100%; background: linear-gradient(180deg, #4a7cf3, #3561d6); border-radius: 2px; opacity: .85; }
.timeline .ev { position: absolute; top: 25px; height: 8px; background: var(--motion); border-radius: 2px; min-width: 3px; }
.timeline .ticks { position: absolute; left: 0; right: 0; bottom: 0; height: 22px; }
.timeline .tick { position: absolute; bottom: 0; font-size: 10.5px; color: var(--dim); transform: translateX(-50%); padding-bottom: 4px; font-variant-numeric: tabular-nums; }
.timeline .tick::before { content: ""; position: absolute; left: 50%; bottom: 18px; width: 1px; height: 6px; background: var(--line2); }
.timeline .head { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; box-shadow: 0 0 8px rgba(255,255,255,.6); pointer-events: none; }
.timeline .head::before { content: ""; position: absolute; top: -1px; left: -5px; border: 6px solid transparent; border-top-color: #fff; }
.timeline .hover { position: absolute; top: 0; bottom: 0; width: 1px; background: rgba(255,255,255,.3); pointer-events: none; }
.timeline .hover span { position: absolute; top: 2px; left: 6px; font-size: 11px; background: #000; padding: 1px 5px; border-radius: 4px; white-space: nowrap; }
.timeline .now { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--rec); opacity: .7; }
.ev-list { display: grid; gap: 8px; align-content: start; max-height: calc(100vh - 140px); overflow: auto; padding-right: 4px; }
.ev-item { display: grid; grid-template-columns: 112px 1fr; gap: 10px; padding: 7px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); cursor: pointer; }
.ev-item:hover, .ev-item.on { border-color: var(--accent); }
.ev-item img, .ev-item .noimg { width: 112px; aspect-ratio: 16/9; object-fit: cover; border-radius: 6px; background: #000; }
.ev-item .t { font-weight: 650; font-variant-numeric: tabular-nums; }

/* ---------- events grid ---------- */
.ev-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.ev-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; cursor: pointer; transition: transform .12s, border-color .12s; }
.ev-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.ev-card img, .ev-card .noimg { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; background: #000; }
.ev-card .meta { padding: 10px 12px; display: grid; gap: 3px; }
.day-sep { grid-column: 1 / -1; font-weight: 650; color: var(--muted); margin-top: 8px; font-size: 13px; }

/* ---------- cameras ---------- */
.cam-list { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); }
.cam-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.cam-card .thumb { aspect-ratio: 16/9; background: #000; position: relative; }
.cam-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.cam-card .info { padding: 13px 14px; display: grid; gap: 8px; }
.cam-card .title { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 15px; }
.cam-card .url { font-family: ui-monospace, Consolas, monospace; font-size: 11.5px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cam-card .actions { display: flex; gap: 6px; }
.found { display: grid; gap: 8px; }
.found .item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.profiles { display: grid; gap: 6px; }
.profiles .p { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.test-out { display: grid; grid-template-columns: 240px 1fr; gap: 12px; align-items: start; font-size: 12px; }
.test-out img { width: 100%; border-radius: 8px; }
.mask-editor { position: relative; aspect-ratio: 16/9; background: #000; border-radius: 10px; overflow: hidden; user-select: none; }
.mask-editor img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; }
.mask-editor .cells { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(16, 1fr); grid-template-rows: repeat(9, 1fr); }
.mask-editor .cells div { border: 1px solid rgba(255,255,255,.07); cursor: pointer; }
.mask-editor .cells div:hover { background: rgba(91,140,255,.2); }
.mask-editor .cells div.x { background: rgba(255,77,94,.42); border-color: rgba(255,77,94,.5); }
.motion-meter { height: 8px; background: var(--line); border-radius: 6px; overflow: hidden; position: relative; }
.motion-meter i { position: absolute; inset: 0 auto 0 0; background: var(--motion); transition: width .3s; }
.motion-meter b { position: absolute; top: -3px; bottom: -3px; width: 2px; background: #fff; }

/* ---------- settings ---------- */
.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; align-items: start; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; font-size: 13px; }
.kv > :nth-child(odd) { color: var(--muted); }
.stat-big { font-size: 26px; font-weight: 700; letter-spacing: -.5px; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1000px 500px at 50% -10%, rgba(91,140,255,.18), transparent), var(--bg); }
.auth .box { width: min(400px, 100%); background: var(--panel); border: 1px solid var(--line2); border-radius: 18px; padding: 30px; display: grid; gap: 16px; box-shadow: 0 30px 80px rgba(0,0,0,.4); }
.auth .logo { display: flex; align-items: center; gap: 12px; font-size: 22px; font-weight: 750; }
.auth .logo img { width: 40px; }

/* ---------- toasts ---------- */
#toasts { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 100; }
.toast { background: var(--panel2); border: 1px solid var(--line2); border-left: 3px solid var(--accent); padding: 11px 14px; border-radius: 10px; min-width: 240px; max-width: 380px; box-shadow: 0 10px 30px rgba(0,0,0,.4); animation: slide .2s; font-size: 13px; }
.toast.err { border-left-color: var(--rec); color: var(--text); }
.toast.motion { border-left-color: var(--motion); cursor: pointer; }
@keyframes slide { from { transform: translateY(10px); opacity: 0; } }

/* ---------- responsive ---------- */
.menu-btn { display: none; }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; inset: 0 auto 0 0; width: 250px; transform: translateX(-100%); transition: transform .2s; }
  .shell.nav-open .sidebar { transform: none; box-shadow: 0 0 60px rgba(0,0,0,.6); }
  .menu-btn { display: inline-flex; }
  .page { padding: 14px 12px 30px; }
  .tl-layout { grid-template-columns: 1fr; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .live-grid { --cols: 1 !important; }
  .live-grid.fill { height: auto; }
  .live-grid.fill .tile { aspect-ratio: 16/9; }
  .test-out { grid-template-columns: 1fr; }
  .settings { grid-template-columns: 1fr; }
}

/* ---------- installed app (PWA) on phones: respect notches / home bar ---------- */
.sidebar { padding-top: calc(18px + env(safe-area-inset-top)); padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
main { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
#toasts { bottom: calc(18px + env(safe-area-inset-bottom)); }
@media (max-width: 900px) {
  .page-head h1 { font-size: 18px; }
  .page-head { gap: 8px; }
  .modal-bg { padding: 0; place-items: end center; }
  .modal { border-radius: 16px 16px 0 0; max-height: calc(100vh - env(safe-area-inset-top) - 10px); }
  .modal footer { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .tl-controls { gap: 6px; }
  .tl-controls .grow { display: none; }
  .timeline { height: 74px; }
  .cam-list, .ev-grid { grid-template-columns: 1fr; }
  #toasts { left: 12px; right: 12px; }
  .toast { max-width: none; }
}

/* brand website link under the app name */
.side-foot { padding: 12px 10px 2px; font-size: 11px; color: var(--muted); line-height: 1.5; }
.side-foot a { display: block; color: var(--accent); }
.side-foot a:hover { text-decoration: underline; }
.auth .side-foot { text-align: center; padding: 4px 0 0; }
.site-link { display: block; font-size: 11px; font-weight: 500; color: var(--accent); letter-spacing: 0; margin-top: 2px; }
.site-link:hover { text-decoration: underline; }
.auth .logo .site-link { font-size: 12px; margin-top: 3px; }

/* Arrange mode (drag cameras into order) */
.live-grid.arranging .tile { cursor: grab; touch-action: none; user-select: none; border: 2px dashed var(--accent); }
.live-grid.arranging .tile.dragging { opacity: .45; pointer-events: none; cursor: grabbing; }

/* ---------- collapsible sidebar ---------- */
.nav a, .nav-btn { white-space: nowrap; overflow: hidden; }
.nav-btn { display: flex; align-items: center; gap: 12px; padding: 10px 12px; margin-bottom: 8px; border-radius: 9px; border: 0; background: none;
  color: var(--muted); font-weight: 500; cursor: pointer; width: 100%; text-align: left; }
.nav-btn:hover { background: var(--panel2); color: var(--text); }
.nav-btn svg { width: 19px; height: 19px; flex: none; }
@media (max-width: 900px) { .nav-btn { display: none; } }
@media (min-width: 901px) {
  .shell.collapsed { grid-template-columns: 64px 1fr; }
  .shell.collapsed .sidebar { width: 64px; padding-left: 8px; padding-right: 8px; overflow: hidden; z-index: 30;
    transition: width .15s ease, box-shadow .15s ease; }
  .shell.collapsed .sidebar .lbl, .shell.collapsed .brand > div, .shell.collapsed .side-stats, .shell.collapsed .side-foot { display: none; }
  .shell.collapsed .brand { padding-left: 10px; padding-right: 0; }
  .shell.collapsed #install-app { margin: 0 0 12px !important; padding: 8px; }
  /* hovering the icon strip opens it over the page (without pinning) */
  .shell.collapsed .sidebar:hover { width: var(--sidebar); box-shadow: 0 0 50px rgba(0,0,0,.55); padding-left: 12px; padding-right: 12px; }
  .shell.collapsed .sidebar:hover .lbl { display: inline; }
  .shell.collapsed .sidebar:hover .brand > div { display: block; }
  .shell.collapsed .sidebar:hover .side-stats { display: grid; }
  .shell.collapsed .sidebar:hover .side-foot { display: block; }
}

/* ---------- camera viewer ---------- */
.viewer { position: relative; background: #000; aspect-ratio: 16/9; border-radius: 10px; overflow: hidden; touch-action: manipulation; }
.viewer .v-media, .viewer .v-media > * { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.v-bar { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; z-index: 3; }
.v-btn { display: inline-flex; align-items: center; gap: 6px; height: 36px; min-width: 36px; padding: 0 9px; justify-content: center;
  background: rgba(10,14,20,.66); border: 1px solid rgba(255,255,255,.14); border-radius: 9px; color: #fff; cursor: pointer;
  font-size: 13px; font-weight: 600; backdrop-filter: blur(6px); }
.v-btn:hover { background: rgba(91,140,255,.55); }
.v-btn.on { background: var(--accent2); border-color: var(--accent); }
.v-btn svg { width: 18px; height: 18px; }
.v-close { display: none; }
.v-ptz { position: absolute; right: 10px; bottom: 10px; z-index: 3; display: grid; grid-template-columns: auto auto; gap: 8px; align-items: center;
  background: rgba(10,14,20,.55); border: 1px solid rgba(255,255,255,.1); border-radius: 14px; padding: 10px; backdrop-filter: blur(6px); }
.ptz-pad { display: grid; grid-template-columns: repeat(3, 44px); grid-template-rows: repeat(3, 44px); gap: 5px; }
.ptz-side { display: grid; gap: 5px; }
.ptz-side button { width: 44px; height: 44px; }
.v-ptz button { background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.15); border-radius: 10px; color: #fff; cursor: pointer;
  display: grid; place-items: center; font-size: 16px; user-select: none; -webkit-user-select: none; touch-action: none; }
.v-ptz button:hover, .v-ptz button.held { background: rgba(91,140,255,.6); }
.v-ptz select { grid-column: 1 / -1; width: 100%; padding: 6px 8px; font-size: 13px; }
.v-controls { flex-wrap: wrap; }
/* HD / Fast switch on the video itself - only when the video fills the screen (the normal buttons are below it) */
/* High / Low stream choice: in the viewer's title bar; on the video itself only when the video fills the screen */
.v-stream { margin-left: 12px; vertical-align: middle; font-size: 13px; }
.v-stream button { padding: 4px 12px; }
.v-q { display: none; font-weight: 700; font-size: 12px; min-width: 44px; }
.viewer:fullscreen .v-q, .viewer.pseudo-fs .v-q { display: inline-flex; }
/* fill the window (iPhone has no element full screen) */
.viewer.pseudo-fs { position: fixed; inset: 0; z-index: 200; border-radius: 0; aspect-ratio: auto; }
.viewer:fullscreen { border-radius: 0; aspect-ratio: auto; }
.viewer:fullscreen .v-close, .viewer.pseudo-fs .v-close { display: inline-flex; }
.viewer:fullscreen .v-bar, .viewer.pseudo-fs .v-bar { top: calc(10px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right)); }
.viewer:fullscreen .v-ptz, .viewer.pseudo-fs .v-ptz { bottom: calc(10px + env(safe-area-inset-bottom)); right: calc(10px + env(safe-area-inset-right)); }

@media (max-width: 900px) {
  /* the viewer opens as a full-height sheet on phones */
  .viewer-modal .modal { border-radius: 0; width: 100%; height: 100%; max-height: none; }
  .viewer-modal .modal .body { padding: 0 0 calc(12px + env(safe-area-inset-bottom)); gap: 12px; align-content: start; flex: 1; }
  .viewer-modal .viewer { border-radius: 0; }
  .viewer-modal .v-controls { padding: 0 12px; }
  .viewer-modal .v-note { display: none; }
  .viewer-modal .v-controls .grow { flex: 1; }
  .viewer-modal .modal header { padding: calc(12px + env(safe-area-inset-top)) 14px 12px; }
  .ptz-pad { grid-template-columns: repeat(3, 40px); grid-template-rows: repeat(3, 40px); }
  .ptz-side button { width: 40px; height: 40px; }
}
@media (max-width: 480px) { .v-controls .lbl { display: none; } }
/* phone turned sideways: video fills the screen */
@media (orientation: landscape) and (max-height: 500px) {
  .viewer-modal .viewer { position: fixed; inset: 0; z-index: 200; border-radius: 0; aspect-ratio: auto; }
  .viewer-modal .v-close { display: inline-flex; }
  .viewer-modal .v-q { display: inline-flex; }
  .viewer-modal .v-bar { top: calc(8px + env(safe-area-inset-top)); right: calc(8px + env(safe-area-inset-right)); }
  .viewer-modal .v-ptz { bottom: calc(8px + env(safe-area-inset-bottom)); right: calc(8px + env(safe-area-inset-right)); padding: 8px; }
  .ptz-pad { grid-template-columns: repeat(3, 38px); grid-template-rows: repeat(3, 38px); }
  .ptz-side button { width: 38px; height: 38px; }
}

/* phone held upright: PTZ controls sit below the video instead of covering it */
@media (max-width: 900px) and (orientation: portrait) {
  .viewer-modal .viewer:not(.pseudo-fs):not(:fullscreen) { overflow: visible; }
  .viewer-modal .viewer:not(.pseudo-fs):not(:fullscreen) .v-ptz { top: calc(100% + 66px); bottom: auto; right: auto; left: 50%; transform: translateX(-50%);
    background: var(--panel2); border-color: var(--line2); padding: 14px; gap: 12px; }
  .viewer-modal .viewer:not(.pseudo-fs):not(:fullscreen) .ptz-pad { grid-template-columns: repeat(3, 56px); grid-template-rows: repeat(3, 56px); gap: 7px; }
  .viewer-modal .viewer:not(.pseudo-fs):not(:fullscreen) .ptz-side button { width: 56px; height: 56px; }
}

/* ---- clip selection on the timeline, zoom, event menus ---- */
.timeline { height: 80px; touch-action: pan-y; }
.timeline .track { height: 28px; }
.timeline .ev { top: 31px; }
.timeline.selecting { cursor: col-resize; box-shadow: 0 0 0 1px #ffc83d inset; }
.timeline .sel { position: absolute; top: 0; bottom: 22px; background: rgba(255,200,61,.18); border: 1px solid #ffc83d; border-radius: 4px; pointer-events: none; z-index: 2; }
.timeline .sel .h { position: absolute; top: -1px; bottom: -1px; width: 18px; pointer-events: auto; cursor: ew-resize; touch-action: none; }
.timeline .sel .h::after { content: ""; position: absolute; top: 50%; left: 50%; width: 5px; height: 70%; transform: translate(-50%, -50%); background: #ffc83d; border-radius: 3px; }
.timeline .sel .h[data-h="start"] { left: -10px; }
.timeline .sel .h[data-h="end"] { right: -10px; }
.tl-sel { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.tl-sel .btn.on { border-color: #ffc83d; color: #ffc83d; }
#s-info a { color: #ffc83d; cursor: pointer; font-variant-numeric: tabular-nums; font-weight: 600; }
#zoom #z-in, #zoom #z-out { font-weight: 700; min-width: 32px; }
.ev-item, .ev-card { position: relative; }
.ev-menu-btn { position: absolute; top: 6px; right: 6px; z-index: 2; padding: 4px 6px; background: rgba(0,0,0,.55); backdrop-filter: blur(4px); }
.ev-menu-btn svg { width: 18px; height: 18px; }
.pop-menu { position: fixed; z-index: 1000; min-width: 200px; background: var(--panel); border: 1px solid var(--line2); border-radius: 10px; padding: 4px; box-shadow: 0 12px 32px rgba(0,0,0,.5); }
.pop-menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; background: none; border: 0; color: inherit; font: inherit; text-align: left; border-radius: 7px; cursor: pointer; }
.pop-menu button:hover { background: rgba(255,255,255,.07); }
.pop-menu svg { width: 17px; height: 17px; }
@media (max-width: 700px) { .tl-sel .btn { padding: 8px 10px; } .timeline { height: 88px; } }

/* ---------- AI detection ---------- */
svg.ai-boxes { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
svg.ai-boxes text { font-family: system-ui, sans-serif; }
.ai-chips { display: flex; gap: 4px; flex-wrap: wrap; margin: 3px 0; }
.ai-chip { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; color: #111; background: #999; }
.ai-chip.person { background: #ef4444; color: #fff; } .ai-chip.vehicle { background: #f59e0b; } .ai-chip.animal { background: #22c55e; }
.ai-dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 2px; vertical-align: -1px; }
.ai-sec { display: grid; gap: 12px; }
#ai-opts.disabled, #ai-alert-row.disabled { opacity: .45; pointer-events: none; }

/* ---------- licence plates ---------- */
.plate-text { display: inline-block; font-family: "DejaVu Sans Mono", Consolas, monospace; font-weight: 800; letter-spacing: 1px; color: #111; background: #f4f4f4;
  border: 2px solid #111; border-left: 7px solid #1d4ed8; border-radius: 4px; padding: 1px 8px; font-size: 15px; line-height: 1.3; }
.plate-text.sm { font-size: 11px; padding: 0 5px; border-width: 1px; border-left-width: 4px; letter-spacing: .5px; }
.pl-layout { display: grid; grid-template-columns: 1fr 340px; gap: 18px; align-items: start; }
.pl-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.pl-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; cursor: pointer; transition: border-color .12s; }
.pl-card:hover { border-color: var(--accent); }
.pl-card img, .pl-card .noimg { width: 100%; height: 110px; object-fit: contain; background: #000; display: block; }
.pl-card .meta { padding: 9px 11px; display: grid; gap: 4px; }
@media (max-width: 900px) { .pl-layout { grid-template-columns: 1fr; } }

.pw-note { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line2); background: var(--panel2); border-radius: 9px; padding: 8px 10px; color: var(--muted); }
.pw-note svg { width: 16px; height: 16px; }

/* live grid pages: arrows on the sides, dots at the bottom (swipe / sideways scroll also work) */
.live-grid { position: relative; }
.pg-arrow { position: absolute; top: 50%; transform: translateY(-50%); z-index: 5; width: 44px; height: 64px; border: 0; border-radius: 12px;
  background: rgba(20,26,40,.75); border: 1px solid rgba(255,255,255,.25); color: #fff; display: grid; place-items: center; cursor: pointer; opacity: .85; transition: opacity .2s, background .2s; box-shadow: 0 2px 10px rgba(0,0,0,.5); }
.pg-arrow:hover { opacity: 1; background: rgba(0,0,0,.7); }
.pg-arrow.left { left: 6px; } .pg-arrow.right { right: 6px; }
.pg-arrow svg { width: 26px; height: 26px; }
.pg-dots { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); z-index: 5; display: flex; gap: 6px; padding: 5px 8px; border-radius: 99px; background: rgba(0,0,0,.45); pointer-events: none; }
.pg-dots span { width: 7px; height: 7px; border-radius: 50%; background: rgba(255,255,255,.4); }
.pg-dots span.on { background: #fff; }
@media (max-width: 900px) { .pg-arrow { position: fixed; top: auto; bottom: calc(16px + env(safe-area-inset-bottom)); transform: none; width: 52px; height: 52px; border-radius: 50%; opacity: .8; }
  .pg-dots { position: fixed; bottom: calc(34px + env(safe-area-inset-bottom)); } }
