:root {
  color-scheme: dark;
  --page: #10161b;
  --panel: #151e25;
  --raised: #1b2730;
  --border: #2a3943;
  --text: #e6eef1;
  --muted: #9aadb8;
  --accent: #6edbc9;
  --accent-deep: #264d4a;
  --motion: #f0a773;
  --event-line: #f1d36e;
  --event-zone: #bd9cf2;
  font-family: "Segoe UI", "Inter", sans-serif;
  color: var(--text);
  background: var(--page);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 290px; }
button, input, select { font: inherit; }
button, a.plain, select, input[type="date"] {
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  background: var(--raised);
}
button, a.plain { cursor: pointer; }
button:hover, a.plain:hover { border-color: var(--accent); color: var(--accent); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, canvas:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 3px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: -2px; }
button:disabled { opacity: .48; cursor: default; }
.plain { padding: .38rem .65rem; line-height: 1.3; font-size: .875rem; text-decoration: none; }
.help-trigger {
  display: inline-grid; place-items: center; flex: none; width: 1.5rem; height: 1.5rem;
  padding: 0; border-radius: 50%; color: var(--muted); font-size: .8rem; font-weight: 650;
  align-self: center; vertical-align: middle;
}
.help-heading { display: flex; align-items: center; gap: .45rem; min-width: 0; }
.device > .help-trigger { margin-inline-start: auto; }
.device h1, .help-heading h3 { overflow-wrap: anywhere; }
.help-disclosure { position: relative; display: flow-root; }
.help-disclosure > details > summary { min-height: 1.5rem; padding-inline-end: 1.8rem; line-height: 1.5; }
.help-disclosure > .help-trigger { position: absolute; inset: 0 0 auto auto; }
.help-disclosure > .ptz-extra + .help-trigger { inset-block-start: .65rem; }
.help-disclosure > details[hidden] + .help-trigger { display: none; }
.secondary { color: var(--muted); font-size: .82rem; }
.topbar {
  min-height: 57px; display: grid; align-items: stretch;
  grid-template-columns: 276px 1fr auto; border-bottom: 1px solid var(--border);
  background: var(--panel); padding-right: 1rem;
}
.brand { display: flex; align-items: center; gap: .75rem; padding: 0 1.1rem; letter-spacing: .03em; }
.brand strong { color: var(--accent); }
.brand-mark { width: 22px; height: 22px; display: grid; place-items: center; border: 1px solid var(--accent); border-radius: 6px; transform: rotate(12deg); }
.brand-mark::after { content: ""; width: 7px; height: 7px; border: 1px solid var(--accent); border-radius: 50%; }
.tabs { display: flex; align-items: stretch; gap: .25rem; }
.tab { border: 0; border-radius: 0; padding: 0 .95rem; min-height: 46px; background: transparent; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.selected { border-bottom-color: var(--accent); color: var(--text); background: #22322f; }
.top-status { display: flex; align-items: center; gap: 1rem; color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.workspace { display: grid; grid-template-columns: 276px minmax(0, 1fr); min-height: 0; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); min-width: 0; }
.device { display: flex; align-items: center; gap: .8rem; padding: 1.05rem 1rem; border-bottom: 1px solid var(--border); }
.device h1, .section-title h2 { margin: 0; font-size: 1rem; font-weight: 650; }
.device p { margin: .2rem 0 0; font-size: .82rem; color: var(--muted); }
.camera-picker { display: grid; gap: .35rem; padding: .8rem 1rem; color: var(--muted); font-size: .85rem; border-bottom: 1px solid var(--border); }
.camera-picker select { width: 100%; }
.camera-mark { width: 33px; height: 26px; border: 1.5px solid var(--accent); border-radius: 7px; display: grid; place-items: center; flex: none; }
.camera-mark::after { content: ""; width: 10px; height: 10px; border: 1.5px solid var(--accent); border-radius: 50%; }
.ptz, .presets { padding: 1rem; }
.ptz { border-bottom: 1px solid var(--border); }
.section-title { display: flex; justify-content: space-between; align-items: center; min-height: 29px; gap: .4rem; }
#patrol-status:empty { display: none; }
#ptz-lock[aria-pressed="true"], .aim-control[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-deep); color: var(--accent); }
.direction-pad { width: min(100%, 174px); margin: .9rem auto .85rem; display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.direction-pad button { aspect-ratio: 1; font-size: 1.23rem; background: var(--raised); border-color: #34444f; touch-action: none; user-select: none; }
.direction-pad button:active, .direction-pad button.held, .ptz-icon:not(:disabled):active, .ptz-icon.held { background: var(--accent-deep); border-color: var(--accent); color: var(--accent); }
.direction-pad .stop { font-size: .8rem; color: var(--accent); background: #182b2e; }
.lens-tools { display: flex; flex-wrap: wrap; justify-content: center; gap: .35rem; }
.lens-group { display: inline-flex; gap: .15rem; }
.ptz-icon { display: inline-grid; place-items: center; flex: none; width: 2.125rem; height: 2.125rem; padding: 0; touch-action: none; user-select: none; }
.ptz-icon svg { width: 1.25rem; height: 1.25rem; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
#ptz-lock[aria-pressed="false"] .ptz-lock, #ptz-lock[aria-pressed="true"] .ptz-unlock { display: none; }
.ptz-extra { margin-top: .65rem; color: var(--muted); font-size: .85rem; }
.ptz-extra summary { cursor: pointer; }
.ptz-actions { margin: .5rem 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: .35rem; }
.ptz-actions input { min-width: 0; width: 100%; padding: .4rem; }
.ptz-actions select { min-width: 0; width: 100%; }
.ptz-buttons { display: flex; flex-wrap: wrap; gap: .35rem; }
.speed-label { display: flex; justify-content: space-between; margin: .9rem 0 .2rem; color: var(--muted); font-size: .86rem; }
#speed-value { color: var(--text); font-variant-numeric: tabular-nums; }
#speed { accent-color: var(--accent); width: 100%; margin: .2rem 0 0; }
.preset-list { display: grid; gap: .24rem; margin-top: .55rem; }
.preset-list button { display: flex; align-items: center; gap: .6rem; text-align: left; padding: .47rem .5rem; border-color: transparent; background: #19242b; font-size: .88rem; }
.preset-list button:hover, .preset-list button.active { border-color: var(--accent); background: var(--accent-deep); }
.preset-index { color: var(--muted); min-width: 1.5rem; font-variant-numeric: tabular-nums; }
.preset-empty { margin: .35rem 0; color: var(--muted); font-size: .87rem; }
.monitor { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 0 .85rem; }
.monitor-bar { display: flex; align-items: center; justify-content: space-between; gap: .45rem; min-height: 47px; }
.monitor-mode, .monitor-actions { display: flex; align-items: center; gap: .6rem; }
.monitor-mode strong { font-size: .89rem; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 3px #95a7aa18; }
.dot.on { background: var(--accent); box-shadow: 0 0 0 3px #6edbc92e; }
.viewport { --corner-control-size: 38px; --corner-control-inset: .55rem; position: relative; display: grid; place-items: center; overflow: hidden; background: #0a1014; min-height: 265px; flex: 1; height: min(67vh, 70vw); border: 1px solid #33454e; border-radius: 5px; }
.video-picture { position: absolute; inset: 0; user-select: none; }
.video-picture video, #archive-preview { position: absolute; width: 100%; height: 100%; inset: 0; object-fit: contain; }
.viewport.video-zoomed .video-picture { cursor: grab; touch-action: none; }
.viewport.video-panning, .viewport.video-panning .video-picture { cursor: grabbing; }
.zoom-reset { position: absolute; z-index: 4; right: var(--corner-control-inset); bottom: .65rem; background: #10191ee8; color: var(--accent); font-variant-numeric: tabular-nums; }
#aim-overlay { position: absolute; inset: 0; z-index: 2; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }
.aim-control, .fullscreen-control { position: absolute; z-index: 4; top: .3rem; width: var(--corner-control-size); height: var(--corner-control-size); padding: 0; display: grid; place-items: center; background: #10191edb; }
.aim-control { left: var(--corner-control-inset); }
.aim-hint { position: absolute; z-index: 3; left: .65rem; right: 3.5rem; top: 3.3rem; width: fit-content; margin: 0; padding: .32rem .5rem; border-radius: 5px; background: #10191edb; color: var(--text); font-size: .83rem; pointer-events: none; }
.live-tools { position: absolute; z-index: 3; inset: 0 0 auto; display: flex; align-items: center; gap: .55rem; min-height: 47px; padding: .3rem 3.6rem .3rem .6rem; background: #10191ee8; opacity: 0; pointer-events: none; transition: opacity .12s ease; }
.aim-control:not([hidden]) ~ .live-tools { padding-left: calc(var(--corner-control-size) + 2 * var(--corner-control-inset)); }
.viewport:hover .live-tools, .viewport:focus-within .live-tools, .live-tools.talking { opacity: 1; pointer-events: auto; }
.live-stats { font-size: .82rem; font-variant-numeric: tabular-nums; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-audio-status { color: var(--muted); font-size: .78rem; min-width: 0; overflow-wrap: anywhere; }
.live-actions { display: flex; gap: .25rem; margin-left: auto; min-width: 0; }
#live-stream { min-width: 0; padding: .2rem .35rem; font-size: .8rem; }
.live-icon { display: grid; place-items: center; flex: 0 0 2rem; width: 2rem; height: 2rem; padding: 0; background: #10191edb; }
.live-icon svg { width: 1.15rem; height: 1.15rem; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.live-icon[aria-pressed="true"] { color: var(--accent); background: var(--accent-deep); }
#live-talk[aria-pressed="true"] { color: var(--motion); }
.live-icon[aria-pressed="true"] .sound-muted, .live-icon[aria-pressed="false"] .sound-waves { display: none; }
.archive-controls { display: flex; align-items: center; justify-self: center; gap: .45rem; }
#archive-toggle, #archive-sound { width: 2rem; height: 2rem; padding: 0; font-size: .95rem; }
#archive-speed { min-height: 2rem; padding: .2rem .3rem; }
#export-form { margin: 0; }
#export-form input[aria-invalid="true"] { border-color: var(--motion); }
.export-boundary input { font-variant-numeric: tabular-nums; }
#archive-time { font-variant-numeric: tabular-nums; min-width: 4.25rem; }
.viewport:fullscreen { height: 100%; border: 0; border-radius: 0; }
.viewport.viewport-expanded { position: fixed; inset: 0; z-index: 20; width: 100vw; height: 100dvh; min-height: 0; border: 0; border-radius: 0; }
body.view-expanded { overflow: hidden; }
.monitor.live-monitor { padding: .45rem; }
.fullscreen-control { right: var(--corner-control-inset); }
.fullscreen-control span { width: 17px; height: 17px; background: linear-gradient(currentColor, currentColor) 0 0 / 6px 2px, linear-gradient(currentColor, currentColor) 0 0 / 2px 6px, linear-gradient(currentColor, currentColor) 100% 0 / 6px 2px, linear-gradient(currentColor, currentColor) 100% 0 / 2px 6px, linear-gradient(currentColor, currentColor) 0 100% / 6px 2px, linear-gradient(currentColor, currentColor) 0 100% / 2px 6px, linear-gradient(currentColor, currentColor) 100% 100% / 6px 2px, linear-gradient(currentColor, currentColor) 100% 100% / 2px 6px; background-repeat: no-repeat; }
.video-message { z-index: 1; display: grid; justify-items: center; gap: .9rem; color: var(--muted); text-align: center; padding: 1rem; pointer-events: none; }
.video-message p { margin: 0; font-size: .92rem; }
.ptz-notice { position: absolute; z-index: 4; left: .65rem; bottom: .65rem; max-width: calc(100% - 1.3rem); margin: 0; padding: .38rem .6rem; border: 1px solid var(--border); border-radius: 6px; background: #10191ee8; color: var(--text); font-size: .82rem; overflow-wrap: anywhere; pointer-events: none; }
.ptz-notice:empty { opacity: 0; }
.viewfinder { width: 54px; height: 38px; border: 1px solid #536a74; border-radius: 7px; display: grid; place-items: center; }
.viewfinder::after { content: ""; width: 16px; height: 16px; border: 1px solid #536a74; border-radius: 50%; }
.timeline { padding: .8rem 0 .45rem; }
.day-control, .timeline-tools { display: flex; align-items: center; gap: .45rem; }
.timeline-toolbar { display: grid; grid-template-columns: minmax(max-content, 1fr) max-content minmax(max-content, 1fr); align-items: center; gap: .65rem; }
.timeline-tools { justify-self: end; }
.day-control label { font-size: .85rem; color: var(--muted); }
input[type="date"], select { padding: .34rem .5rem; min-height: 34px; font-size: .88rem; }
#timeline { display: block; width: 100%; height: 70px; border-radius: 5px; border: 1px solid var(--border); margin-top: .55rem; background: var(--panel); cursor: grab; touch-action: pan-y; }
#timeline.dragging { cursor: grabbing; }
.timeline-track { position: relative; }
.timeline-preview { position: absolute; z-index: 5; bottom: calc(100% + .35rem); left: var(--preview-x, 0px); width: min(185px, 100%); aspect-ratio: 16 / 9; margin: 0; display: grid; place-items: end center; border: 1px solid #536a74; border-radius: 5px; background: #0a1014; pointer-events: none; box-shadow: 0 3px 14px #0009; }
.timeline-preview img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.timeline-preview figcaption { z-index: 1; margin: .25rem; padding: .1rem .35rem; background: #10191ee8; border-radius: 4px; font-size: .78rem; font-variant-numeric: tabular-nums; }
.timeline-caption { display: flex; align-items: center; flex-wrap: wrap; gap: .75rem; color: var(--muted); font-size: .78rem; margin-top: .5rem; min-height: 18px; }
.timeline-caption span { display: inline-flex; align-items: center; gap: .35rem; }
.legend { display: inline-block; width: .75rem; height: .42rem; border-radius: 2px; }
.legend.recording { background: #448e87; }
.legend.motion { background: var(--motion); }
.legend.line { background: var(--event-line); }
.legend.zone { background: var(--event-zone); }
.storage { display: flex; justify-content: space-between; flex-wrap: wrap; gap: .5rem; border-top: 1px solid var(--border); padding: .63rem 0; color: var(--muted); font-size: .8rem; }
.login { display: grid; place-items: center; min-height: calc(100dvh - 57px); padding: 1rem; }
.login form { width: min(100%, 360px); background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 1.4rem; display: grid; gap: .6rem; }
.login h1 { margin: 0 0 .6rem; font-size: 1.45rem; }
.login label { color: var(--muted); font-size: .9rem; }
.login input { background: var(--page); border: 1px solid var(--border); border-radius: 6px; color: var(--text); min-width: 0; padding: .55rem .65rem; }
.login button[type="submit"] { color: var(--accent); padding: .6rem; margin-top: .3rem; }
.login .help-heading h1 { margin-bottom: 0; }
#login-error { color: var(--motion); margin: 0; font-size: .87rem; }
.visually-hidden { position: absolute; height: 1px; width: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.vms-dialog { width: min(94vw, 630px); max-height: 92dvh; padding: 0; border: 1px solid var(--border); border-radius: 12px; color: var(--text); background: var(--panel); }
.vms-dialog::backdrop { background: #070d12c9; }
#export-dialog { width: min(94vw, 36rem); }
#help-dialog { width: min(92vw, 34rem); }
#help-dialog .settings-head { position: sticky; inset-block-start: 0; background: var(--panel); z-index: 1; }
.help-content { padding: .95rem 1.15rem 1.15rem; font-size: .94rem; line-height: 1.5; }
.help-content p, .help-content dl { margin: 0 0 .7rem; }
.help-content > :last-child { margin-bottom: 0; }
.help-content dt { font-weight: 650; }
.help-content dd { color: var(--muted); margin: .15rem 0 .65rem; }
.help-content dd:last-child { margin-bottom: 0; }
.settings-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .85rem 1.15rem; border-bottom: 1px solid var(--border); }
.settings-head h2 { margin: 0; font-size: 1.18rem; }
.settings-tabs { display: flex; flex-wrap: wrap; padding: 0 1.15rem; border-bottom: 1px solid var(--border); }
.settings-panel { padding: 1rem 1.15rem; }
.storage-usage { display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: .5rem; margin: 0 0 .9rem; }
.storage-usage > div { background: var(--page); border: 1px solid var(--border); border-radius: 6px; padding: .55rem .65rem; }
.storage-usage dt { color: var(--muted); font-size: .8rem; }
.storage-usage dd { margin: .2rem 0 0; font-size: 1rem; font-variant-numeric: tabular-nums; }
.user-table-wrap { overflow: auto; max-height: 36dvh; border: 1px solid var(--border); border-radius: 6px; }
.user-table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.user-table th, .user-table td { padding: .35rem .45rem; text-align: center; border-bottom: 1px solid var(--border); }
.user-table thead th { position: sticky; top: 0; background: var(--raised); color: var(--muted); font-weight: 500; }
.user-table th:first-child { text-align: left; width: 100%; overflow-wrap: anywhere; }
.user-table tbody th { font-weight: 400; }
.user-table tbody tr:last-child > * { border-bottom: 0; }
.user-table button { max-width: 100%; text-align: left; }
.user-table button[aria-pressed="true"] { background: var(--accent-deep); color: var(--accent); }
.user-table .user-granted { color: var(--accent); }
.user-table .user-denied { color: var(--muted); }
.user-table-actions { margin: .65rem 0 .9rem; }
.camera-table td { color: var(--muted); overflow-wrap: anywhere; }
.camera-table td:last-child { white-space: nowrap; }
.camera-row-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: .3rem; }
.camera-details { display: grid; gap: .65rem; }
.camera-details h3 { margin: 0; font-size: 1rem; overflow-wrap: anywhere; }
.camera-details-values { margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .5rem; }
.camera-details-values > div { background: var(--page); border: 1px solid var(--border); border-radius: 6px; padding: .55rem .65rem; overflow-wrap: anywhere; }
.camera-details-values dt { color: var(--muted); font-size: .8rem; }
.camera-details-values dd { margin: .2rem 0 0; font-size: .87rem; }
#camera-topic-list { padding-left: 1.3rem; overflow-wrap: anywhere; }
.privacy-picture { position: relative; overflow: hidden; width: min(100%, 560px); cursor: crosshair; touch-action: none; }
.privacy-picture img { width: 100%; display: block; user-select: none; }
.privacy-rectangle { position: absolute; border: 2px solid var(--accent); background: #64d4c04d; pointer-events: none; }
.settings-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem .85rem; }
.settings-form label { display: grid; gap: .3rem; color: var(--muted); font-size: .87rem; }
.settings-form input { width: 100%; min-width: 0; padding: .55rem .6rem; color: var(--text); border-radius: 6px; background: var(--page); border: 1px solid var(--border); }
.settings-form .wide { grid-column: 1 / -1; }
.settings-note, .settings-feedback { margin: 0; color: var(--muted); font-size: .83rem; line-height: 1.4; overflow-wrap: anywhere; }
.settings-feedback { color: var(--accent); min-height: 1.15em; }
.settings-feedback.error, .settings-note.error { color: var(--motion); }
.settings-actions { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem; }
.settings-actions .action { padding: .45rem .7rem; background: var(--accent-deep); border-color: #3a7870; color: var(--accent); }
.settings-actions .danger { color: #f0a773; }
.settings-fieldset { min-width: 0; margin: 0; padding: .65rem .8rem; border: 1px solid var(--border); border-radius: 6px; display: grid; gap: .55rem; }
.settings-fieldset legend { padding: 0 .3rem; font-size: .87rem; color: var(--muted); }
.settings-form .settings-check { display: flex; align-items: center; gap: .55rem; }
.settings-form .settings-check input { width: auto; margin: 0; accent-color: var(--accent); }
.settings-fieldset select { justify-self: start; max-width: 100%; }
.advanced-settings { color: var(--muted); font-size: .87rem; }
.advanced-settings summary { cursor: pointer; }
.advanced-settings .settings-form { margin-top: .65rem; }

@media (max-width: 850px) {
  .topbar { grid-template-columns: 223px 1fr auto; }
  .workspace { grid-template-columns: 223px minmax(0, 1fr); }
  .top-status time { display: none; }
}
@media (max-width: 1000px) {
  .timeline-toolbar { display: flex; justify-content: space-between; flex-wrap: wrap; }
  .archive-controls { flex: 1; justify-content: center; }
}
@media (min-width: 761px) and (min-height: 280px) {
  body { display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100dvh; overflow: hidden; }
  .workspace { grid-template-rows: minmax(0, 1fr); }
  .sidebar { overflow-y: auto; overscroll-behavior-y: contain; scrollbar-width: thin; }
  .viewport { flex: 1 1 0; min-height: 0; }
  .monitor-bar, .timeline, .storage { flex: 0 0 auto; }
  .login { min-height: 0; overflow-y: auto; }
}
@media (max-width: 760px) {
  .topbar { grid-template-columns: 1fr auto; padding: 0 .5rem; }
  .brand { padding: .65rem .15rem; }
  .top-status { grid-column: 2; grid-row: 1; }
  .tabs { grid-column: 1 / -1; }
  .tab { flex: 1; }
  .workspace { display: flex; flex-direction: column; min-height: 0; }
  .monitor { order: -1; padding: 0 .55rem; min-height: 0; }
  .viewport { flex: initial; min-height: 0; height: auto; aspect-ratio: 16 / 9; }
  .monitor-actions .secondary { display: none; }
  .sidebar { border-right: 0; border-top: 1px solid var(--border); display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .device { grid-column: 1 / -1; }
  .camera-picker { grid-column: 1 / -1; }
  .presets, .ptz { padding: .7rem; }
  .ptz { border-bottom: 0; border-right: 1px solid var(--border); }
  .direction-pad { margin: .65rem auto; }
  .lens-tools { gap: .25rem; }
  .topbar .plain, .monitor-actions .plain { font-size: .75rem; }
}
@media (max-width: 510px) {
  .archive-controls { order: 2; flex: 0 0 100%; }
  .timeline-tools { flex-wrap: wrap; }
  .export-boundary { grid-column: 1 / -1; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
}
@media (hover: none) {
  .live-tools { opacity: 1; pointer-events: auto; }
}
