:root {
  --bg: #1c4066;
  /* Light surfaces so the all-black writing stays readable on panels,
     inputs and buttons (these were dark blue with light text). */
  --panel: #e8f4ff;
  --panel-raised: #d2e9ff;
  --border: #4a80ab;
  /* All writing is solid black - no dimmed/grey variant anywhere. */
  --text: #000;
  --text-dim: #000;
  --accent: #f0883a;
  --accent-dim: #f7b98a;
  --rec: #d14343;
  --ok: #4caf7d;
  --radius: 3px;
  /* Stencil for all writing outside the video itself - see .tile-label
     and .tile-play-btn for the on-video exceptions. */
  --font: 'Allerta Stencil', 'Stencil Std', 'Arial Black', sans-serif;
  --video-font: -apple-system, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  /* Allerta Stencil only ships a regular weight - a browser-faked bold
     smears over the stencil gaps, so bold text renders as regular. */
  font-synthesis: none;
}

button, input, select {
  font-family: inherit;
  font-size: inherit;
}

.shell {
  position: relative;
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
  overflow: hidden;
  /* The "backing page" - ONE continuous gradient spanning the full width
     (sidebar + main together, no seam between them), exactly matching the
     source reference crop: orange at both outer edges, light blue through
     the middle. The sidebar/main are transparent below so this shows
     through both instead of each re-running its own copy. */
  background: linear-gradient(90deg,
    #ffa831 0%,
    #c4e6ff 15%,
    #acdcff 36%,
    #9ed4ff 50%,
    #acdcff 64%,
    #c4e6ff 85%,
    #ffa831 100%
  );
}

.shell::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.18;
  mix-blend-mode: soft-light;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 100px 100px;
  z-index: 0;
}

/* ---------- Sidebar ---------- */

.sidebar {
  /* Transparent - shows the .shell "backing page" gradient through it
     (see above), matching the reference exactly instead of re-running its
     own separately-scaled copy. */
  position: relative;
  z-index: 1;
  overflow-y: auto;
  background: transparent;
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Hamburger toggle and backdrop - only shown/usable below the drawer
   breakpoint (see the @media block at the end of this section). Kept in
   normal flow above 768px so they never affect the desktop two-column
   layout. */
.sidebar-toggle-btn {
  display: none;
  background: none;
  border: none;
  color: #000;
  font-size: 22px;
  line-height: 1;
  padding: 4px 8px;
  cursor: pointer;
}

/* "Pop in" button inside the open drawer - the drawer covers the hamburger
   that opened it, so it needs its own way to close. Drawer mode only. */
.sidebar-close-btn {
  display: none;
  position: relative;
  margin-left: auto;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.55);
  border: 2px solid #000;
  border-radius: 6px;
  /* The X is drawn with two thick bars rather than a text character - the
     stencil font's x is thin and hard to see at a glance. */
  font-size: 0;
  cursor: pointer;
}
.sidebar-close-btn::before,
.sidebar-close-btn::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 22px;
  height: 4px;
  background: #000;
  border-radius: 2px;
}
.sidebar-close-btn::before { transform: translate(-50%, -50%) rotate(45deg); }
.sidebar-close-btn::after { transform: translate(-50%, -50%) rotate(-45deg); }
.sidebar-close-btn:hover { background: var(--accent); }

.sidebar-backdrop {
  display: none;
}

@media (max-width: 768px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar-toggle-btn {
    display: inline-flex;
    align-items: center;
    position: relative;
    z-index: 1;
  }

  .sidebar-close-btn {
    display: inline-block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 260px;
    max-width: 82vw;
    z-index: 210;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.45);
    /* As a drawer it floats over the camera grid - kept see-through like
       the desktop sidebar, with just a light tint so the writing reads. */
    background: rgba(232, 244, 255, 0.35);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
  }

  .sidebar-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.current-user {
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  text-transform: capitalize;
}

.remote-address {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.remote-address .field-hint {
  margin: 0;
  font-size: 11px;
}

.remote-address-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.remote-address-row code {
  flex: 1;
  font-size: 11px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-small {
  padding: 4px 10px;
  font-size: 11px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding-bottom: 6px;
}

.brand-mark {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

.brand-name {
  font-weight: 600;
  letter-spacing: 0.2px;
}

.btn {
  border: 1px solid var(--border);
  background: var(--panel-raised);
  color: var(--text);
  padding: 9px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.btn:hover { border-color: var(--accent-dim); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
  font-weight: 600;
}
.btn-primary:hover { background: #f5a15f; }

.btn-ghost { background: transparent; }

.btn-block { width: 100%; }

.camera-list {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.camera-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
}
.camera-list-item:hover { border-color: var(--border); background: var(--panel-raised); }

.camera-list-item .status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  margin-right: 8px;
  flex-shrink: 0;
}
.camera-list-item.offline .status-dot { background: var(--text-dim); }

.camera-list-item .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.camera-list-item .mode-tag {
  color: #000;
  font-size: 10px;
  font-weight: 600;
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  width: 15px;
  height: 15px;
  line-height: 13px;
  text-align: center;
  flex-shrink: 0;
}

.camera-list-item .remove,
.camera-list-item .recordings-btn,
.camera-list-item .edit-btn,
.camera-list-item .zones-btn {
  color: var(--text-dim);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 6px;
}
.camera-list-item .recordings-btn { font-size: 10px; }
.camera-list-item .remove:hover,
.camera-list-item .recordings-btn:hover,
.camera-list-item .edit-btn:hover,
.camera-list-item .zones-btn:hover { background: var(--accent); border-radius: var(--radius); }

/* ---------- Users modal ---------- */

.users-list {
  max-height: 260px;
  overflow-y: auto;
  margin-bottom: 4px;
}

.user-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.user-item .user-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-item select { font-size: 12px; padding: 3px 6px; }
.user-item .remove {
  color: var(--text-dim);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 6px;
}
.user-item .remove:hover { background: var(--accent); border-radius: var(--radius); }
.user-item .reset-devices {
  font-size: 11px;
  padding: 3px 7px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.user-item .reset-devices:hover:not(:disabled) { background: var(--accent); }
.user-item .reset-devices:disabled { opacity: 0.4; cursor: default; }

/* ---------- Devices & security ---------- */

.devices-list { max-height: 240px; overflow-y: auto; }
.device-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
}
.device-item .device-info { flex: 1; min-width: 0; }
.device-item .device-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-item .device-current { text-decoration: underline; }
.device-item .field-hint { margin: 2px 0 0; font-size: 11px; }

/* ---------- Main ---------- */

.main {
  /* Transparent - shows the .shell "backing page" gradient through it
     (see .shell above), continuing seamlessly from the sidebar with no
     seam between them, matching the reference exactly. */
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: transparent;
}

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  overflow: hidden;
  /* The header's own colour scheme - kept separate from the backing page/
     sidebar gradient (see .shell). Same confirmed stops as before
     (orange-outer / blue-centre), just running top-to-bottom instead of
     left-to-right. */
  background: linear-gradient(180deg,
    #ffa831 0%,
    #c4e6ff 15%,
    #acdcff 36%,
    #9ed4ff 50%,
    #acdcff 64%,
    #c4e6ff 85%,
    #ffa831 100%
  );
  border-bottom: 2px solid #0d1b2a;
}

/* Grainy/noise texture over the gradients, matching the source design's
   per-stop "Noise" slider - an SVG feTurbulence filter tiled as a
   background-image, blended over whichever gradient sits underneath it
   (the header's own, or the shell's backing-page one). */
.topbar::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.18;
  mix-blend-mode: soft-light;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 100px 100px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
  z-index: 1;
}
.topbar-brand { display: flex; flex-direction: column; }
.topbar-wordmark {
  font-family: 'Allerta Stencil', 'Stencil Std', 'Arial Black', sans-serif;
  font-size: 22px;
  font-weight: 400;
  letter-spacing: 1px;
  text-decoration: underline;
  color: #000;
}
.topbar-tagline {
  display: block;
  font-family: 'Allerta Stencil', 'Stencil Std', 'Arial Black', sans-serif;
  font-size: 9.5px;
  letter-spacing: 0.7px;
  color: #000;
  margin-top: 1px;
}

.topbar-meta-group {
  display: flex;
  align-items: baseline;
  gap: 14px;
  position: relative;
  z-index: 1;
}

.grid-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.grid-size-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.size-chip {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel-raised);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.size-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
}

.topbar-meta {
  color: var(--text-dim);
  font-size: 12.5px;
}
.topbar-meta.clickable { cursor: pointer; }
.topbar-meta.clickable:hover { text-decoration: underline; }

.sessions-list { max-height: 320px; overflow-y: auto; }
.session-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}
.session-item:last-child { border-bottom: none; }
.session-item .session-user { color: var(--text); font-weight: 600; }
.session-item .session-user .role-tag {
  font-weight: 400;
  color: var(--text-dim);
  text-transform: capitalize;
}
.session-item .session-meta { color: var(--text-dim); }

.grid {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  align-content: start;
}

.empty-state {
  grid-column: 1 / -1;
  color: var(--text-dim);
  text-align: center;
  padding: 60px 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.tile {
  background: #000;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  cursor: pointer;
}

.tile video, .tile img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
  background: #000;
}

/* Sits on top of the video itself, over a dark fade - so it keeps the
   plain font and light text (black would vanish into the fade), unlike
   all the writing outside the video. */
.tile-label {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: linear-gradient(to top, rgba(0,0,0,0.75), transparent);
  font-family: var(--video-font);
  font-size: 12.5px;
  color: #fff;
}

.tile-label .ptz-tag {
  color: var(--accent);
  font-size: 11px;
  border: 1px solid var(--accent-dim);
  padding: 1px 6px;
  border-radius: var(--radius);
}

.tile-activity-stripe {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 8px;
  background: var(--accent);
  opacity: 0.85;
  cursor: pointer;
}

.tile-play-btn {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 44px; height: 44px;
  border-radius: 50%;
  background: rgba(13,27,42,0.75);
  border: 1px solid var(--border);
  color: #fff; /* on the video, over a dark circle */
  font-family: var(--video-font);
  font-size: 16px;
  cursor: pointer;
}

/* ---------- Modals ---------- */

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-backdrop.open { display: flex; }

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 420px;
  max-width: 92vw;
  max-height: 86vh;
  overflow-y: auto;
}

.modal-wide { width: 820px; }

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 15px; margin: 0; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}

.modal-body { padding: 18px; }

.field-row {
  display: flex;
  gap: 12px;
}
.field-row label { flex: 1; }

label {
  display: block;
  margin-bottom: 12px;
  color: var(--text-dim);
  font-size: 12.5px;
}

input, select {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 8px 10px;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}

.field-hint {
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

.discover-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.discover-item:last-child { border-bottom: none; }
.discover-item .meta { color: var(--text-dim); font-size: 12px; }
.discover-item > div { flex: 1; }
.discover-item-check { flex: 0 0 auto; width: 16px; height: 16px; }

/* ---------- PTZ modal ---------- */

.ptz-body {
  display: block;
}

.ptz-video {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16/9; /* the video's space is kept while it connects - nothing below jumps */
  background: #000;
}

.ptz-video video {
  width: 100%;
  background: #000;
  aspect-ratio: 16/9;
  transition: transform 0.08s ease-out;
}

.tile video { transition: transform 0.08s ease-out; }

/* Under the video, as drawn: PTZ Controls and Zoom on the left, this
   camera's Motion Events (the blue event-log panel) beside them - stacked
   on a narrow screen. */
.ptz-dock {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  margin-top: 12px;
  align-items: stretch;
}
.ptz-dock.no-ptz { grid-template-columns: minmax(0, 1fr); }
@media (max-width: 700px) {
  .ptz-dock { grid-template-columns: minmax(0, 1fr); }
}
.ptz-dock-controls {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  flex-wrap: wrap;
  padding: 10px 14px;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.ptz-dock-controls[hidden] { display: none; }
.ptz-dock-title { font-size: 13px; margin-bottom: 8px; }
.ptz-dock-events {
  padding: 10px 14px;
  background: #acdcff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 0;
}
.ptz-dock-events .motion-events-list { max-height: 190px; }

.motion-events-list { max-height: 240px; overflow-y: auto; }

.motion-event-row {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.motion-event-row:hover { background: var(--panel-raised); }
.motion-event-row .event-time { color: var(--text-dim); font-size: 10.5px; margin-top: 2px; }

.ptz-controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(3, 44px);
  gap: 4px;
  justify-content: center;
}

.dpad-btn {
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}
.dpad-btn:active, .dpad-btn.pressed { background: var(--accent); }
.dpad-btn::before { font-size: 18px; line-height: 1; }
.dpad-ul::before { content: '\2196'; }
.dpad-u::before { content: '\25B2'; }
.dpad-ur::before { content: '\2197'; }
.dpad-l::before { content: '\25C0'; }
.dpad-r::before { content: '\25B6'; }
.dpad-dl::before { content: '\2199'; }
.dpad-d::before { content: '\25BC'; }
.dpad-dr::before { content: '\2198'; }
.dpad-btn { touch-action: none; }

.dpad-center {
  background: transparent;
  border-radius: var(--radius);
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}
.zoom-btn {
  width: 40px;
  height: 36px;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  font-size: 20px;
  cursor: pointer;
  touch-action: none;
}
.zoom-btn:active, .zoom-btn.pressed { background: var(--accent); }
.zoom-track { width: 70px; height: 2px; background: var(--accent); }

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.preset-btn {
  font-size: 12px;
  padding: 5px 9px;
}

/* ---------- Recordings modal ---------- */

.recordings-body {
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: 18px;
}

.recordings-player video {
  width: 100%;
  background: #000;
  aspect-ratio: 16/9;
}

.recordings-player-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  gap: 10px;
}
.recordings-player-nav .field-hint { flex: 1; text-align: center; margin: 0; }
.recordings-player-nav .btn { font-size: 12px; padding: 6px 10px; }
.recordings-player-nav .btn:disabled { opacity: 0.4; cursor: default; }

.recordings-scrub {
  margin-top: 12px;
}

.recordings-scrub-header {
  display: flex;
  justify-content: center;
  margin-bottom: 4px;
}

.recordings-scrub-track {
  position: relative;
  height: 28px;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  overflow: hidden;
}

.scrub-segment {
  position: absolute;
  top: 0;
  bottom: 0;
  background: var(--accent-dim);
  min-width: 2px;
}
.scrub-segment:hover { background: var(--accent); }
.scrub-segment.active { background: var(--accent); }
/* 24/7 low-quality recording - shown fainter, so the full-quality motion
   clips on top of it stand out on the timeline. */
.scrub-segment { z-index: 1; }
.scrub-segment.low { opacity: 0.45; z-index: 0; }
.scrub-segment.low.active, .scrub-segment.low:hover { opacity: 1; }

.scrub-playhead {
  z-index: 2;
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--text);
  pointer-events: none;
  display: none;
}
.scrub-playhead.visible { display: block; }

.recordings-scrub-hours {
  display: flex;
  justify-content: space-between;
  color: var(--text-dim);
  font-size: 10px;
  margin-top: 3px;
}

.recordings-side {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

/* Filter bar for the "smart timeline" events feed below - instant,
   client-side filtering of the already-fetched event list (see
   applyEventsFilters in app.js), no re-fetch per keystroke/toggle. */
.events-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: center;
}
.events-filter-bar input[type="search"] {
  flex: 1;
  min-width: 100px;
  padding: 5px 8px;
  font-size: 12px;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}
.events-filter-bar input[type="date"] {
  padding: 4px 6px;
  font-size: 12px;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}
.events-category-filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.events-category-filters label {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 0;
  font-size: 12px;
  white-space: nowrap;
}
.events-category-filters input { margin: 0; }

.recordings-events {
  max-height: 320px;
  overflow-y: auto;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}
.recordings-events:empty { display: none; }

.event-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  padding: 5px 4px;
  font-size: 12px;
}
.event-item .event-category-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-dim);
}
.event-item .event-category-dot.people { background: var(--accent); }
.event-item .event-category-dot.vehicles { background: var(--ok); }
.event-item .event-main {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
}
.event-item .event-type {
  color: #000;
  text-transform: capitalize;
}
.event-item .event-time { color: var(--text-dim); white-space: nowrap; }
.event-item.clickable .event-main { cursor: pointer; border-radius: var(--radius); }
.event-item.clickable .event-main:hover { background: var(--panel-raised); }
.event-item .event-download {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 14px;
  padding: 2px 4px;
  flex-shrink: 0;
}
.event-item .event-download:hover { background: var(--accent); border-radius: var(--radius); }

.recordings-list {
  max-height: 280px;
  overflow-y: auto;
}

/* ---------- Motion zone editor ---------- */

.zones-canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  background: #000;
}
.zones-canvas-wrap img,
.zones-canvas-wrap canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
}
.zones-canvas-wrap { margin: 0 auto; }
.zones-canvas-wrap img { object-fit: fill; }
.zones-canvas-wrap canvas {
  /* Overhangs the picture by ZONE_MARGIN (app.js) all round. */
  top: -12px;
  left: -12px;
  width: calc(100% + 24px);
  height: calc(100% + 24px);
  cursor: crosshair;
  touch-action: none;
}
/* Top right of the picture, as drawn: the red X "Done" while drawing a zone,
   and the orange X - Cancel while drawing, Delete when a zone is picked. */
.zones-tools {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 16px;
}
.zones-tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 0;
  background: none;
  border: 0;
  color: #fff;
  font: inherit;
  font-size: 12px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  cursor: pointer;
}
.zones-tool[hidden] { display: none; }
.zones-tool:disabled { opacity: 0.45; cursor: default; }
.zones-tool-x { font-size: 24px; line-height: 1; font-weight: 700; }
.zones-tool-done .zones-tool-x { color: #ff3b3b; }
/* The orange is only there to pick out the X. */
.zones-tool-delete .zones-tool-x {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  background: var(--accent);
  color: #000;
  font-size: 20px;
  text-shadow: none;
  border-radius: 2px;
}
.zones-bar { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
/* Room for the longest hint, so the picture doesn't jump when it changes. */
#zonesHint { min-height: 3em; }
.zones-count { font-size: 12.5px; }

.recordings-day-header {
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 10px 4px 4px;
}
.recordings-day-header:first-child { padding-top: 0; }
.recordings-day-header.clickable { cursor: pointer; }
.recordings-day-header.clickable:hover { text-decoration: underline; }
.recordings-day-header.active { background: var(--accent); border-radius: var(--radius); }

.recordings-item {
  display: flex;
  justify-content: space-between;
  padding: 7px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
}
.recordings-item:hover { background: var(--panel-raised); }
.recordings-item.active { background: var(--accent); color: var(--text); }
.recordings-item .meta { color: var(--text-dim); font-size: 11.5px; }

/* ---- Live view (full screen, see openLiveWall in app.js) ---- */
.live-wall {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: #000;
  overflow: hidden;
}
.live-wall[hidden] { display: none; }
.live-wall.idle { cursor: none; }
.live-wall-tile {
  position: absolute;
  box-sizing: border-box;
  padding: 1px;
  overflow: hidden;
  cursor: grab;
}
/* Zoomed in (digital zoom - see enableScrollZoom): drag moves the picture. */
.zoomed { cursor: move; }
.tile, .ptz-video, .live-wall-tile { touch-action: pan-x pan-y; }
.live-wall-tile video-rtc,
.live-wall-tile video {
  display: block;
  width: 100%;
  height: 100%;
  background: #0b0f14;
}
.live-wall-tile.dragging { opacity: 0.45; }
.live-wall-tile.drop-target::after {
  content: '';
  position: absolute;
  inset: 1px;
  background: rgba(240, 136, 58, 0.35);
  border: 3px solid var(--accent);
  pointer-events: none;
}
.live-wall-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px 26px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.75), transparent);
  font-family: var(--video-font);
  color: #fff;
  transition: opacity 0.3s;
}
.live-wall-bar.hidden { opacity: 0; pointer-events: none; }
.live-wall-close {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 0;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}
.live-wall-close:hover { background: var(--accent); color: #000; }
.live-wall-title { font-size: 16px; }
.live-wall-btn {
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: 12.5px;
  padding: 5px 10px;
  cursor: pointer;
}
.live-wall-btn:hover { background: var(--accent); color: #000; }
.live-wall-btn[hidden] { display: none; }
.live-wall-hint { flex: 1; text-align: right; font-size: 12px; opacity: 0.85; }
@media (max-width: 700px) {
  .live-wall-hint { display: none; }
}
.live-wall-ptz-chip {
  position: absolute;
  top: 8px;
  right: 8px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-family: var(--video-font);
  font-size: 11px;
  padding: 3px 7px;
  cursor: pointer;
  transition: opacity 0.3s;
}
.live-wall-ptz-chip:hover { background: var(--accent); color: #000; }
.live-wall.idle .live-wall-ptz-chip { opacity: 0; }
/* Always showing while there's a PTZ camera to work - never fades. */
.live-wall-ptz {
  position: absolute;
  right: 16px;
  bottom: 16px;
  padding: 10px 12px 12px;
  background: rgba(10, 16, 24, 0.78);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 10px;
  color: #fff;
  font-family: var(--video-font);
}
.live-wall-ptz[hidden] { display: none; }
.live-wall-ptz-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; font-size: 12.5px; }
.live-wall-ptz-close { background: none; border: 0; color: #fff; font-size: 20px; line-height: 1; cursor: pointer; }
.live-wall-ptz .dpad { grid-template-columns: repeat(3, 40px); grid-template-rows: repeat(3, 40px); }
.live-wall-ptz .dpad-btn, .live-wall-ptz .zoom-btn { background: rgba(255,255,255,0.12); border-color: rgba(255,255,255,0.25); color: #fff; }
.live-wall-ptz .zoom-controls { margin-top: 10px; }
.live-wall-ptz .zoom-label { font-size: 12px; }

/* ---- Camera name, day and date on every video (see makeLiveStamp) ---- */
.video-stamp {
  position: absolute;
  top: 6px;
  left: 8px;
  max-width: calc(100% - 16px);
  padding: 2px 6px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-family: var(--video-font);
  font-size: 11.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  z-index: 2;
}
.video-stamp:empty { display: none; }
.live-wall-tile .video-stamp { top: 5px; left: 6px; }

/* Own video controls (native ones would zoom with the picture). */
.recordings-video-wrap {
  position: relative;
  overflow: hidden;
  background: #000;
  aspect-ratio: 16 / 9;
  cursor: pointer;
}
.recordings-video-wrap video { width: 100%; height: 100%; display: block; object-fit: contain; }
.player-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.player-btn, .speed-btn {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-raised);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  padding: 6px 10px;
  cursor: pointer;
}
.player-btn.on, .speed-btn.active { background: var(--accent); border-color: var(--accent); }
.player-speed { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.player-speed .field-hint { margin: 0 4px 0 0; }
.video-overlay-controls { position: absolute; right: 8px; bottom: 8px; display: flex; gap: 6px; z-index: 3; }
.video-overlay-controls .player-btn { background: rgba(0, 0, 0, 0.55); border-color: rgba(255, 255, 255, 0.3); color: #fff; font-family: var(--video-font); }
.video-overlay-controls .player-btn.on { background: var(--accent); color: #000; }

/* ---- Storage ---- */
.storage-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.storage-row small { grid-column: 1 / -1; font-size: 12px; opacity: 0.85; }
.storage-bar { grid-column: 1 / -1; height: 6px; margin-top: 6px; background: var(--panel-raised); border-radius: 3px; overflow: hidden; }
.storage-bar > div { height: 100%; background: var(--accent); }

/* ---- Legal footer ---- */
.legal-footer { margin-top: 10px; font-size: 10.5px; line-height: 1.5; opacity: 0.85; }
.legal-footer a { color: inherit; }
/* The camera's name on a grid tile opens its window. */
.tile-name-link {
  background: none;
  border: 0;
  padding: 0;
  color: #fff;
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.tile-name-link:hover { color: var(--accent); }

/* ---- Health ---- */
.health-server { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.health-card { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; background: var(--panel-raised); border: 1px solid var(--border); border-radius: var(--radius); }
.health-card span { font-size: 12px; }
.health-card strong { font-size: 20px; }
.health-card small { font-size: 11.5px; opacity: 0.8; }
.sparkline { width: 100%; height: 30px; margin-top: 4px; }
.sparkline polyline { fill: none; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.health-title { font-size: 14px; font-weight: 400; margin: 18px 0 8px; }
.health-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.health-table th, .health-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.health-table th { font-weight: 400; opacity: 0.8; }
.bad { color: var(--rec); }
.log-search { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.log-search input { flex: 1; width: auto; min-width: 0; margin: 0; }
.log-search select { flex: 0 0 auto; width: auto; margin: 0; }
.log-results { max-height: 320px; overflow-y: auto; font-size: 12px; border: 1px solid var(--border); border-radius: var(--radius); }
.log-row { display: grid; grid-template-columns: 150px 90px 1fr 1.2fr; gap: 8px; padding: 5px 8px; border-bottom: 1px solid var(--border); }
.log-row .log-time, .log-row .log-kind { opacity: 0.8; }
@media (max-width: 700px) { .log-row { grid-template-columns: 1fr; } }

/* ---- Camera settings (the camera's own - see openCameraSettings) ---- */
.camera-settings { margin-top: 12px; padding: 12px 14px; background: var(--panel-raised); border: 1px solid var(--border); border-radius: var(--radius); }
.camera-settings[hidden] { display: none; }
.cs-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.cs-head small { display: block; font-size: 11.5px; opacity: 0.8; }
.cs-row { display: grid; grid-template-columns: 130px 1fr auto; align-items: center; gap: 10px; padding: 7px 0; border-top: 1px solid var(--border); font-size: 13px; }
.cs-row small { grid-column: 2 / -1; font-size: 12px; }
.cs-choices { display: flex; flex-wrap: wrap; gap: 6px; grid-column: 2 / -1; }
.cs-choice { border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); font: inherit; font-size: 12.5px; padding: 5px 10px; cursor: pointer; }
.cs-choice.active { background: var(--accent); border-color: var(--accent); }
.cs-row input[type=range] { width: 100%; accent-color: var(--accent); margin: 0; }
.cs-value { min-width: 28px; text-align: right; }
.cs-actions { display: flex; align-items: center; gap: 8px; padding-top: 10px; border-top: 1px solid var(--border); }
.cs-danger { background: var(--rec); border-color: var(--rec); color: #fff; }
.cs-status { font-size: 12.5px; }
@media (max-width: 600px) { .cs-row { grid-template-columns: 1fr; } .cs-choices, .cs-row small { grid-column: 1; } }

/* ---- Snapshot, record, save clip ---- */
.player-btn.recording, .live-wall-btn.recording { background: var(--rec); border-color: var(--rec); color: #fff; }
.save-clip { position: relative; display: inline-flex; }
.save-clip-menu { position: absolute; bottom: calc(100% + 6px); left: 0; display: flex; gap: 4px; align-items: center; padding: 6px 8px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 4px 14px rgba(0,0,0,0.25); z-index: 5; white-space: nowrap; }
.save-clip-menu[hidden] { display: none; }
.save-clip-menu .field-hint { margin: 0 4px 0 0; }

