/* houseguard-map global styles
 * Dark theme, modern, responsive. */

:root {
  --bg: #0f1115;
  --bg-elev: #161a22;
  --bg-elev-2: #1d222d;
  --border: #2a2f3a;
  --text: #e6e8ee;
  --text-dim: #9aa3b2;
  --text-faint: #6b7280;
  --accent: #4f8cff;
  --accent-2: #6ea8ff;
  --good: #22c55e;
  --bad: #ef4444;
  --warn: #f59e0b;
  --person: #ef4444;
  --vehicle: #3b82f6;
  --other: #eab308;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    Oxygen, Ubuntu, Cantarell, sans-serif;
  font-size: 14px;
  line-height: 1.4;
}

/* Mobile-base hardening: stop iOS text auto-sizing and runaway horizontal
 * scroll. Most pages will never trigger x-overflow but a single stray
 * inline-style width can on small viewports. */
body {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- Top nav ---------- */
.topnav {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.topnav .brand {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.2px;
  color: var(--text);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.topnav .brand-dot {
  width: 10px;
  height: 10px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--accent);
}

.topnav nav {
  display: flex;
  gap: 4px;
  flex: 1;
  margin-left: 18px;
}

.topnav nav a {
  color: var(--text-dim);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.topnav nav a:hover,
.topnav nav a.active {
  background: var(--bg-elev-2);
  color: var(--text);
}

.topnav nav a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.ws-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
}

.ws-status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: background 0.2s;
}

.ws-status.connected .dot {
  background: var(--good);
  box-shadow: 0 0 8px var(--good);
}

.ws-status.disconnected .dot {
  background: var(--bad);
}

/* ---------- Layout ---------- */
.main {
  flex: 1;
  display: flex;
  min-height: 0;
}

.content {
  flex: 1;
  padding: 18px;
  overflow: auto;
}

.content h1 {
  margin: 0 0 14px 0;
  font-size: 20px;
  font-weight: 600;
}

.content h2 {
  margin: 18px 0 10px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

/* ---------- Buttons, inputs ---------- */
button, .btn {
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}

button:hover, .btn:hover {
  background: #262c39;
  border-color: #3a4150;
}

button:active, .btn:active { transform: translateY(1px); }

button:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button.primary, .btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

button.primary:hover, .btn.primary:hover {
  background: var(--accent-2);
  border-color: var(--accent-2);
}

button.danger, .btn.danger {
  background: transparent;
  border-color: var(--bad);
  color: var(--bad);
}

button.danger:hover, .btn.danger:hover {
  background: var(--bad);
  color: white;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

input[type="text"],
input[type="number"],
input[type="file"],
select,
textarea {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 13px;
}

input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

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

.field {
  margin-bottom: 10px;
}

.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.row > * { flex: 0 0 auto; }

/* ---------- Toggle ---------- */
.toggle {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
}
.toggle input { display: none; }
.toggle .slider {
  position: absolute;
  inset: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s;
}
.toggle .slider::before {
  content: "";
  position: absolute;
  width: 16px; height: 16px;
  left: 2px; top: 2px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: transform 0.15s, background 0.15s;
}
.toggle input:checked + .slider {
  background: var(--accent);
  border-color: var(--accent);
}
.toggle input:checked + .slider::before {
  transform: translateX(16px);
  background: white;
}

/* ---------- Map view ---------- */
.map-wrap {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}

.map-canvas-host {
  flex: 1;
  position: relative;
  background: #0a0c10;
  overflow: hidden;
}

#map-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.map-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(15, 17, 21, 0.95);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--text);
  box-shadow: var(--shadow);
  z-index: 4;
  white-space: nowrap;
}

.map-overlay {
  position: absolute;
  top: 12px; left: 12px;
  background: rgba(15, 17, 21, 0.85);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text-dim);
  pointer-events: none;
  max-width: 280px;
}

/* ---------- Side panel ---------- */
.side-panel {
  width: 340px;
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width 0.2s ease;
  overflow: hidden;
}

.side-panel.collapsed {
  width: 32px;
}

.side-panel .panel-toggle {
  background: var(--bg-elev-2);
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 6px;
  color: var(--text-dim);
  cursor: pointer;
  text-align: center;
  border-radius: 0;
}

.side-panel .panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.side-panel.collapsed .panel-body { display: none; }

.event-feed-item {
  display: flex;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius);
  background: var(--bg-elev-2);
  margin-bottom: 8px;
  border: 1px solid var(--border);
  transition: background 0.15s;
  cursor: pointer;
}

.event-feed-item:hover {
  background: #232936;
}

.event-feed-item img {
  width: 64px;
  height: 48px;
  object-fit: cover;
  border-radius: 4px;
  background: #000;
  border: 1px solid var(--border);
  flex: 0 0 auto;
}

.event-feed-item .meta {
  flex: 1;
  min-width: 0;
}

.event-feed-item .meta .top-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2px;
}

.event-feed-item .label {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: white;
}

.event-feed-item .cam {
  font-size: 12px;
  color: var(--text);
  font-weight: 500;
}

.event-feed-item .time-ago {
  font-size: 11px;
  color: var(--text-faint);
}

.event-feed-item .extras {
  font-size: 11px;
  color: var(--text-dim);
}

/* ---------- Camera cards grid ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}

.cam-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}

.cam-card:hover {
  transform: translateY(-2px);
  border-color: #3a4150;
  box-shadow: var(--shadow-lg);
}

.cam-card .thumb {
  aspect-ratio: 16 / 9;
  background: #000;
  overflow: hidden;
  position: relative;
}

.cam-card .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cam-card .thumb .badge {
  position: absolute;
  top: 8px; right: 8px;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.badge.ok { background: var(--good); color: white; }
.badge.warn { background: var(--warn); color: black; }
.badge.bad { background: var(--bad); color: white; }

.cam-card .body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cam-card .name {
  font-size: 15px;
  font-weight: 600;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  padding: 4px 6px;
  margin: -4px -6px;
  border-radius: 4px;
  width: 100%;
}

.cam-card .name:hover { border-color: var(--border); }
.cam-card .name:focus { background: var(--bg); border-color: var(--accent); outline: none; }

.cam-card .meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-dim);
}

.cam-card .actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.cam-card .actions button { flex: 1 1 auto; min-width: 100px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  max-width: 720px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.modal header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.modal .modal-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

.modal footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ---------- Calibrate page ---------- */
.calib-img-host {
  position: relative;
  background: #000;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: inline-block;
  max-width: 100%;
  cursor: crosshair;
}

.calib-img-host img {
  display: block;
  max-width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}

.calib-marker {
  position: absolute;
  width: 24px;
  height: 24px;
  margin-left: -12px;
  margin-top: -12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid white;
  color: white;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  box-shadow: 0 0 6px rgba(0,0,0,0.6);
}

table.calib-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 13px;
}

table.calib-table th, table.calib-table td {
  padding: 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

table.calib-table th {
  color: var(--text-dim);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

table.calib-table input {
  width: 80px;
  padding: 4px 6px;
}

.toast {
  position: fixed;
  bottom: 20px; right: 20px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  max-width: 360px;
  font-size: 13px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { border-color: var(--good); }
.toast.error { border-color: var(--bad); }

.mini-map {
  background: #0a0c10;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  aspect-ratio: 4 / 3;
  display: block;
  cursor: crosshair;
}

/* ---------- Utilities ---------- */
.spacer { flex: 1; }
.muted { color: var(--text-dim); }
.tiny { font-size: 11px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.center { text-align: center; }
.hidden { display: none !important; }
.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
}

/* ---------- Nav dropdown menu ---------- */
.nav-menu {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.nav-menu-trigger {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-weight: 500;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background 0.15s, color 0.15s;
}

.nav-menu-trigger:hover,
.nav-menu.active .nav-menu-trigger,
.nav-menu.open .nav-menu-trigger {
  background: var(--bg-elev-2);
  color: var(--text);
}

.nav-menu .caret {
  font-size: 10px;
  opacity: 0.8;
}

.nav-menu-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 180px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  display: none;
  z-index: 60;
}

.nav-menu.open .nav-menu-list { display: block; }

.nav-menu-list a {
  display: block;
  padding: 7px 10px;
  border-radius: 4px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13px;
}

.nav-menu-list a:hover,
.nav-menu-list a.active {
  background: var(--bg-elev-2);
  color: var(--text);
}

.nav-menu-list a.disabled {
  color: var(--text-faint);
  pointer-events: none;
  cursor: not-allowed;
  font-style: italic;
}

/* ---------- Live grid / tiles ---------- */
.live-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 14px;
}

.live-tile {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}

.live-tile:hover {
  transform: translateY(-2px);
  border-color: #3a4150;
  box-shadow: var(--shadow-lg);
}

.live-tile .frame {
  position: relative;
  background: #000;
  aspect-ratio: 16 / 9;
  width: 100%;
}

.live-tile .frame iframe,
.live-tile .frame img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  object-fit: cover;
}

.live-tile .frame .frame-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 12px;
  background: #0a0c10;
}

.live-tile .strip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
}

.live-tile .strip .name {
  flex: 1;
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.live-tile .strip .maximize {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}

.live-tile .strip .maximize:hover {
  background: var(--bg-elev-2);
  color: var(--text);
}

/* ---------- REC indicator (pulsing red dot) ---------- */
.rec-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: var(--bad);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

.rec-indicator .rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bad);
  box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
  animation: rec-pulse 1.4s infinite;
}

.rec-indicator.large {
  font-size: 13px;
  padding: 4px 12px;
}
.rec-indicator.large .rec-dot { width: 10px; height: 10px; }

@keyframes rec-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); transform: scale(1); }
  70%  { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); transform: scale(1.05); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); transform: scale(1); }
}

/* ---------- Live detail layout ---------- */
.live-detail {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  align-items: start;
}

.live-detail .player {
  background: #000;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
  aspect-ratio: 16 / 9;
  width: 100%;
  max-width: 1200px;
}

.live-detail .player iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.live-detail .control-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.live-detail .control-bar .elapsed {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 13px;
}

.live-detail .side {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.live-detail .side-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px;
}

.live-detail .side-card h2 {
  margin: 0 0 8px 0;
  font-size: 14px;
}

/* ---------- Filter row ---------- */
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 14px;
  padding: 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.filter-row .field { margin-bottom: 0; }

.filter-row .quick-range {
  display: inline-flex;
  gap: 4px;
}

.filter-row .quick-range button {
  padding: 5px 10px;
  font-size: 12px;
}

.filter-row .quick-range button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.filter-row .spacer { flex: 1; }

/* ---------- Event grid (Frigate events) ---------- */
.event-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.event-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
  position: relative;
}

.event-card:hover {
  transform: translateY(-2px);
  border-color: #3a4150;
  box-shadow: var(--shadow-lg);
}

.event-card .thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  overflow: hidden;
}

.event-card .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.event-card .thumb .label-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 3px 8px;
  border-radius: 4px;
  color: white;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.event-card .thumb .snapshot-only {
  position: absolute;
  bottom: 8px;
  right: 8px;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(15, 17, 21, 0.85);
  border: 1px solid var(--border);
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.event-card .body {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.event-card .body .top {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
}

.event-card .body .cam-name {
  font-weight: 600;
  color: var(--text);
  font-size: 13px;
}

.event-card .body .stats {
  display: flex;
  gap: 8px;
  font-size: 11px;
  color: var(--text-dim);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ---------- Recordings list ---------- */
.recordings-table {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.recording-row {
  display: grid;
  grid-template-columns: 140px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.recording-row .thumb {
  width: 140px;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.recording-row .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.recording-row .info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.recording-row .info .cam-name {
  font-weight: 600;
  font-size: 14px;
}

.recording-row .info .meta {
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.recording-row .actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.recording-row .actions button,
.recording-row .actions a {
  padding: 5px 10px;
  font-size: 12px;
}

.status-badge {
  display: inline-block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 7px;
  border-radius: 4px;
  font-weight: 700;
}

.status-badge.completed { background: rgba(34, 197, 94, 0.15); color: var(--good); border: 1px solid rgba(34,197,94,0.3); }
.status-badge.recording { background: rgba(239, 68, 68, 0.15); color: var(--bad); border: 1px solid rgba(239,68,68,0.3); }
.status-badge.failed    { background: rgba(245, 158, 11, 0.15); color: var(--warn); border: 1px solid rgba(245,158,11,0.3); }

.global-rec-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin-bottom: 12px;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius);
  font-size: 13px;
}

/* ---------- <dialog> video modal ---------- */
dialog.video-modal {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elev);
  color: var(--text);
  padding: 0;
  max-width: 90vw;
  width: 960px;
  box-shadow: var(--shadow-lg);
}

dialog.video-modal::backdrop {
  background: rgba(0, 0, 0, 0.8);
}

dialog.video-modal header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

dialog.video-modal header .title {
  flex: 1;
  font-weight: 600;
  font-size: 14px;
}

dialog.video-modal header button.close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  padding: 0 6px;
  cursor: pointer;
  line-height: 1;
}

dialog.video-modal video {
  width: 100%;
  height: auto;
  max-height: 75vh;
  display: block;
  background: #000;
}

dialog.video-modal footer {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  justify-content: flex-end;
  border-top: 1px solid var(--border);
}

/* ---------- Empty state ---------- */
.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-faint);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
}

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .topnav { padding: 8px 12px; gap: 8px; }
  .topnav nav { margin-left: 4px; gap: 0; flex-wrap: wrap; }
  .topnav nav a, .nav-menu-trigger { padding: 4px 8px; font-size: 13px; }
  .side-panel { width: 100%; border-left: none; border-top: 1px solid var(--border); }
  .main { flex-direction: column; }
  .map-canvas-host { min-height: 50vh; }

  .live-grid { grid-template-columns: 1fr; }
  .live-detail { grid-template-columns: 1fr; }
  .recording-row { grid-template-columns: 1fr; }
  .recording-row .thumb { width: 100%; max-width: 240px; }
  .recording-row .actions { justify-content: flex-start; }
  dialog.video-modal { width: 96vw; }
}

@media (max-width: 1100px) {
  .live-detail { grid-template-columns: 1fr; }
}

/* ---------- Zones page ---------- */
.zones-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
}

.zone-canvas-wrap {
  position: relative;
  background: #000;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  width: 100%;
  aspect-ratio: 16 / 9;
  cursor: crosshair;
}

.zone-canvas-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.zone-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.zone-side {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.zone-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.zone-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.zone-row .swatch {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.2);
  flex: 0 0 auto;
}

.zone-row .name {
  flex: 1;
  font-weight: 500;
  font-size: 13px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.zone-row .actions { display: flex; gap: 4px; flex: 0 0 auto; }
.zone-row .actions button { padding: 3px 8px; font-size: 12px; }
.zone-row.disabled { opacity: 0.55; }

.zone-mode-banner {
  background: rgba(79, 140, 255, 0.12);
  border: 1px solid rgba(79, 140, 255, 0.4);
  color: var(--accent-2);
  padding: 8px 10px;
  border-radius: var(--radius);
  font-size: 12px;
}

@media (max-width: 1100px) {
  .zones-layout { grid-template-columns: 1fr; }
}

/* ---------- Rules page ---------- */
.rule-table {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rule-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.4fr) 70px 1fr 1fr 1fr 90px auto 130px auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.rule-row .rule-name {
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rule-row .rule-meta {
  font-size: 12px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rule-row .rule-actions-col {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
}

.rule-row .row-buttons {
  display: flex;
  gap: 4px;
}

.rule-row .row-buttons button { padding: 4px 9px; font-size: 12px; }

.rule-row.disabled { opacity: 0.55; }

.rule-header-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.4fr) 70px 1fr 1fr 1fr 90px auto 130px auto;
  gap: 10px;
  padding: 6px 12px;
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.action-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
}

.action-chip.ok { color: var(--good); border-color: rgba(34,197,94,0.4); }
.action-chip.err { color: var(--bad); border-color: rgba(239,68,68,0.4); }
.action-chip.pending { color: var(--warn); border-color: rgba(245,158,11,0.4); }

.action-chip .ic { font-weight: 700; }

dialog.rule-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elev);
  color: var(--text);
  padding: 0;
  max-width: 90vw;
  width: 720px;
  box-shadow: var(--shadow-lg);
}
dialog.rule-dialog::backdrop { background: rgba(0,0,0,0.7); }
dialog.rule-dialog header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
dialog.rule-dialog header h3 { margin: 0; font-size: 15px; }
dialog.rule-dialog .rd-body {
  padding: 16px;
  max-height: 70vh;
  overflow-y: auto;
}
dialog.rule-dialog footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
dialog.rule-dialog .grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
dialog.rule-dialog select[multiple] {
  width: 100%;
  min-height: 90px;
  font-size: 12px;
}

.action-editor {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 10px;
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.action-editor .action-row {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  padding: 6px 8px;
  border-radius: var(--radius);
}

.action-editor .action-row .a-type {
  font-weight: 600;
  font-size: 12px;
  min-width: 90px;
  color: var(--text);
}

.action-editor .action-row input[type="text"] {
  flex: 1;
  min-width: 0;
}

.action-editor .add-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.action-editor .add-buttons button {
  font-size: 12px;
  padding: 4px 10px;
}

@media (max-width: 1100px) {
  .rule-row,
  .rule-header-row {
    grid-template-columns: 1fr;
  }
  .rule-header-row { display: none; }
  .rule-row { gap: 4px; }
}

/* ---------- Firings page ---------- */
.firing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}

.firing-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}

.firing-card:hover {
  transform: translateY(-2px);
  border-color: #3a4150;
  box-shadow: var(--shadow-lg);
}

.firing-card .thumb {
  aspect-ratio: 16 / 9;
  background: #000;
  position: relative;
}

.firing-card .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.firing-card .thumb .placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 11px;
  background: #0a0c10;
}

.firing-card .body {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.firing-card .top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.firing-card .rule-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

.firing-card .firing-meta {
  font-size: 12px;
  color: var(--text-dim);
}

.firing-card .action-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

dialog.firing-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elev);
  color: var(--text);
  padding: 0;
  max-width: 90vw;
  width: 720px;
  box-shadow: var(--shadow-lg);
}
dialog.firing-dialog::backdrop { background: rgba(0,0,0,0.7); }
dialog.firing-dialog header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
dialog.firing-dialog .fd-body { padding: 16px; max-height: 70vh; overflow-y: auto; }
dialog.firing-dialog footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
dialog.firing-dialog pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow: auto;
  max-height: 320px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- Alert drawer ---------- */
.alert-drawer {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 360px;
  max-width: calc(100vw - 32px);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  z-index: 150;
  pointer-events: none;
}

.alert-drawer-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  font-size: 12px;
  color: var(--text-dim);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
}

.alert-drawer:has(.alert-card) .alert-drawer-header {
  opacity: 1;
  transform: translateY(0);
}

.alert-drawer-header .title { flex: 1; font-weight: 600; color: var(--text); }
.alert-drawer-header .alert-audio {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  cursor: pointer;
  font-size: 11px;
}
.alert-drawer-header .alert-audio input { margin: 0; }
.alert-drawer-header .clear-all {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  padding: 0 4px;
  cursor: pointer;
  line-height: 1;
}
.alert-drawer-header .clear-all:hover { color: var(--text); }

.alert-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 0;
  pointer-events: auto;
}

.alert-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: alert-slide-in 0.25s ease-out;
  border-left: 4px solid var(--accent);
}

.alert-card.sev-warn { border-left-color: var(--warn); }
.alert-card.sev-critical { border-left-color: var(--bad); }
.alert-card.sev-info { border-left-color: var(--accent); }

.alert-card-body {
  display: flex;
  gap: 10px;
  padding: 10px;
  cursor: pointer;
}

.alert-thumb {
  width: 64px;
  height: 48px;
  object-fit: cover;
  border-radius: 4px;
  background: #000;
  flex: 0 0 auto;
  border: 1px solid var(--border);
}

.alert-thumb.placeholder {
  background: #0a0c10;
}

.alert-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.alert-rule {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.alert-meta {
  font-size: 11px;
  color: var(--text-dim);
}

.alert-msg {
  font-size: 12px;
  color: var(--text);
}

.alert-time {
  margin-top: 2px;
}

.alert-dismiss {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  padding: 0 4px;
  cursor: pointer;
  align-self: flex-start;
  line-height: 1;
}
.alert-dismiss:hover { color: var(--text); }

.alert-card-actions {
  padding: 0 10px 10px 10px;
  display: flex;
  gap: 6px;
}
.alert-card-actions.hidden { display: none; }
.alert-card-actions .btn { font-size: 12px; padding: 4px 10px; }

.alert-card.dismissing {
  animation: alert-fade-out 0.28s ease-out forwards;
}

@keyframes alert-slide-in {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

@keyframes alert-fade-out {
  from { opacity: 1; max-height: 200px; }
  to   { opacity: 0; max-height: 0; margin: 0; padding: 0; border-width: 0; }
}

/* Severity colors for future use */
.sev-info { color: var(--accent); }
.sev-warn { color: var(--warn); }
.sev-critical { color: var(--bad); }

@media (max-width: 760px) {
  .alert-drawer { width: calc(100vw - 24px); right: 12px; bottom: 12px; }
}

/* ---------- Mode pill in topnav ---------- */
.mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: filter 0.15s, transform 0.05s;
}
.mode-pill:hover { filter: brightness(1.15); }
.mode-pill:active { transform: translateY(1px); }
.mode-pill-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  box-shadow: 0 0 6px rgba(255,255,255,0.1);
}
.mode-pill.mode-home {
  background: rgba(34, 197, 94, 0.15);
  border-color: rgba(34, 197, 94, 0.5);
  color: var(--good);
}
.mode-pill.mode-home .mode-pill-dot {
  background: var(--good);
  box-shadow: 0 0 6px var(--good);
}
.mode-pill.mode-away {
  background: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.5);
  color: var(--warn);
}
.mode-pill.mode-away .mode-pill-dot {
  background: var(--warn);
  box-shadow: 0 0 6px var(--warn);
}
.mode-pill.mode-night {
  background: rgba(79, 140, 255, 0.15);
  border-color: rgba(79, 140, 255, 0.5);
  color: var(--accent-2);
}
.mode-pill.mode-night .mode-pill-dot {
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}
.mode-pill.mode-vacation {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.5);
  color: var(--bad);
}
.mode-pill.mode-vacation .mode-pill-dot {
  background: var(--bad);
  box-shadow: 0 0 6px var(--bad);
}

.nav-logout {
  padding: 5px 12px;
  font-size: 12px;
}

/* ---------- Mode chooser (settings page) ---------- */
.mode-chooser {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.mode-chooser button {
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  cursor: pointer;
  transition: filter 0.15s, transform 0.05s;
}
.mode-chooser button[data-mode="Home"].active {
  background: var(--good); border-color: var(--good); color: white;
}
.mode-chooser button[data-mode="Away"].active {
  background: var(--warn); border-color: var(--warn); color: black;
}
.mode-chooser button[data-mode="Night"].active {
  background: var(--accent); border-color: var(--accent); color: white;
}
.mode-chooser button[data-mode="Vacation"].active {
  background: var(--bad); border-color: var(--bad); color: white;
}
.mode-chooser button:hover { filter: brightness(1.15); }
.mode-chooser button:active { transform: translateY(1px); }

/* ---------- Settings page sections ---------- */
.settings-section {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  margin-bottom: 14px;
}
.settings-section h2 {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 600;
}
.settings-section .help {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 12px;
}
.settings-section .field { margin-bottom: 12px; }
.settings-section .kv {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 8px 16px;
  font-size: 13px;
  margin-bottom: 8px;
}
.settings-section .kv .k { color: var(--text-dim); }
.settings-section .kv .v { color: var(--text); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  margin-right: 6px;
  vertical-align: middle;
}
.status-dot.ok { background: var(--good); box-shadow: 0 0 6px var(--good); }
.status-dot.bad { background: var(--bad); }
.status-dot.warn { background: var(--warn); }

/* ---------- Login page ---------- */
body.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at top, #161a22 0%, #0f1115 65%);
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 28px 26px 22px;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  font-size: 18px;
  font-weight: 700;
}
.login-brand .brand-dot {
  width: 12px; height: 12px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 12px var(--accent);
}
.login-card .field input {
  width: 100%;
  font-size: 14px;
  padding: 9px 12px;
}
.login-card label { margin-bottom: 6px; font-size: 12px; }
.login-card .btn.primary {
  width: 100%;
  padding: 10px;
  font-size: 14px;
  margin-top: 4px;
}
.login-error {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: var(--bad);
  padding: 8px 10px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 10px;
}

/* ---------- Press-to-talk button ---------- */
.btn-talk {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn-talk:hover { background: #262c39; border-color: #3a4150; }
.btn-talk.talking {
  background: var(--bad);
  border-color: var(--bad);
  color: white;
  animation: talk-pulse 1.2s infinite;
}
.btn-talk[disabled] { opacity: 0.55; cursor: not-allowed; }
@keyframes talk-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); }
  70%  { box-shadow: 0 0 0 12px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* Wider grid columns on the rules page to fit the modes column */
.rule-row-modes { font-size: 12px; color: var(--text-dim); }

/* ============================================================
   Card-corner delete button + multi-select mode
   Used by /events.html and /firings.html
   ============================================================ */

.event-card, .firing-card { position: relative; }

/* Tiny X-style delete button in the top-right corner of each card.
   Subtle by default, pops to red on hover. */
.card-del-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  background: rgba(0,0,0,0.55);
  color: #f3f4f6;
  border-radius: 50%;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity .15s, background .15s, transform .1s;
  z-index: 3;
}
.card-del-btn:hover {
  opacity: 1;
  background: #b91c1c;
  transform: scale(1.08);
}
.card-del-btn:focus-visible {
  outline: 2px solid #fbbf24;
  outline-offset: 2px;
}

/* Multi-select mode: checkbox top-left, hide the corner X.
   The grid root gets .select-mode when multi-select is active. */
.card-select-cb {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 22px;
  height: 22px;
  margin: 0;
  cursor: pointer;
  display: none;
  z-index: 3;
  accent-color: #ef4444;
}
.select-mode .card-select-cb { display: block; }
.select-mode .card-del-btn { display: none; }
.event-card.selected, .firing-card.selected {
  outline: 2px solid #ef4444;
  outline-offset: -2px;
}

/* Sticky bulk-action bar at the bottom when items are selected */
.bulk-bar {
  position: sticky;
  bottom: 8px;
  margin-top: 10px;
  padding: 8px 12px;
  background: rgba(15,18,28,0.96);
  border: 1px solid var(--border, #2a2f3e);
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
.bulk-bar.hidden { display: none; }
.bulk-bar .count { color: var(--text-dim, #9ca3af); font-size: 13px; }
.bulk-bar .spacer { flex: 1; }

/* ============================================================
   Mobile responsive overrides (additive — keeps desktop layout
   untouched). Two breakpoints:
   - 720px: tablets / large phones in landscape
   - 480px: phones in portrait
   ============================================================ */

@media (max-width: 720px) {
  /* Content gutters tighter on phones */
  .content { padding: 12px; }
  .content h1 { font-size: 18px; }

  /* Top nav: wrap to multiple rows, smaller pills, smaller pill labels */
  .topnav {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
  }
  .topnav nav {
    margin-left: 0;
    flex-wrap: wrap;
    gap: 2px;
    order: 10;          /* push nav under brand + status pills */
    width: 100%;
    flex: 1 0 100%;
  }
  .topnav nav a, .nav-menu-trigger {
    padding: 5px 9px;
    font-size: 12px;
  }
  .ws-status { font-size: 11px; padding: 3px 8px; }
  .ws-status .label { display: none; }   /* dot is enough on mobile */
  .mode-pill { font-size: 11px; padding: 3px 9px; }
  .mode-pill-label { font-size: 11px; }
  .nav-logout { padding: 4px 10px; font-size: 11px; }

  /* Grids collapse to single column */
  .live-grid { grid-template-columns: 1fr !important; }
  .event-grid { grid-template-columns: 1fr; }
  .firing-grid { grid-template-columns: 1fr; }
  .card-grid { grid-template-columns: 1fr; }
  .live-detail { grid-template-columns: 1fr; }
  .zones-layout { grid-template-columns: 1fr; }

  /* Filter rows wrap. Each field gets a sane min-width so they can collapse. */
  .filter-row {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px;
  }
  .filter-row .field {
    flex: 1 1 140px;
    min-width: 0;
  }
  .filter-row .field select,
  .filter-row .field input { width: 100%; }
  .filter-row .quick-range { flex-wrap: wrap; }

  /* Recording rows already collapse — also align actions */
  .recording-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .recording-row .thumb { width: 100%; max-width: none; aspect-ratio: 16 / 9; }
  .recording-row .actions {
    justify-content: stretch;
    flex-wrap: wrap;
  }
  .recording-row .actions button,
  .recording-row .actions a {
    flex: 1 1 30%;
    min-width: 90px;
  }

  /* Rules table already collapses below 1100px — tighten the row */
  .rule-row { padding: 8px; }

  /* Dialogs / modals: go full-screen on mobile so there's no awkward
     side-scroll for content that overflows. */
  dialog.video-modal,
  dialog.rule-dialog,
  dialog.firing-dialog {
    max-width: 100vw;
    max-height: 100vh;
    width: 100vw;
    margin: 0;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }
  dialog.video-modal video { max-height: 50vh; }
  dialog.rule-dialog .rd-body,
  dialog.firing-dialog .fd-body { max-height: calc(100vh - 130px); }
  dialog.rule-dialog .grid-2 { grid-template-columns: 1fr; }

  /* Custom .modal-backdrop modals (cameras.html position modal) */
  .modal-backdrop { padding: 0; }
  .modal {
    max-width: 100vw;
    max-height: 100vh;
    width: 100vw;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  /* Alert drawer: dock to bottom full-width on mobile, cap at 3 visible.
     Override the older 760px rule for slightly different geometry. */
  .alert-drawer {
    width: 100vw;
    max-width: 100vw;
    right: 0;
    left: 0;
    bottom: 0;
    max-height: 50vh;
    border-radius: 0;
  }
  .alert-drawer-header {
    border-radius: 0;
  }
  .alert-list {
    padding: 4px 6px;
    /* show ~3 cards before scroll; each card is ~80px */
    max-height: calc(50vh - 36px);
  }

  /* Camera card name input full-width without margins eating layout */
  .cam-card .body { padding: 10px; }
  .cam-card .actions button,
  .cam-card .actions a { flex: 1 1 100%; min-width: 0; }

  /* Map page: panel and overlay tweaks */
  .map-overlay { font-size: 11px; padding: 6px 8px; max-width: 70vw; }
  .side-panel { width: 100%; border-left: 0; border-top: 1px solid var(--border); }
  .side-panel.collapsed { width: 100%; height: 36px; }
  .side-panel.collapsed .panel-body { display: none; }

  /* Live page detail player: respect portrait so the iframe doesn't push
     the whole page below the fold. */
  .live-detail .player { max-height: 80vh; }

  /* Larger tap targets per Apple HIG (44x44 minimum) — applied only on
     mobile to keep desktop compact. */
  button:not(.card-del-btn):not(.alert-dismiss):not(.clear-all):not(.panel-toggle):not(.nav-menu-trigger),
  .btn:not(.card-del-btn),
  input[type="text"],
  input[type="number"],
  input[type="password"],
  input[type="search"],
  select,
  textarea {
    min-height: 40px;
  }
  /* Slightly larger touch zones for the small corner buttons too */
  .card-del-btn { width: 32px; height: 32px; font-size: 16px; top: 6px; right: 6px; opacity: 0.75; }
  .card-select-cb { width: 28px; height: 28px; }
  .live-tile .strip .maximize { min-width: 40px; min-height: 32px; }

  /* Buttons inside .filter-row .quick-range — they had padding 5px 10px,
     bump touch zone but keep visual height moderate. */
  .filter-row .quick-range button { min-height: 36px; padding: 6px 12px; }

  /* Inputs / selects full-width inside forms on mobile (covers login etc) */
  .login-card { padding: 22px 18px 18px; }
  .login-card .field input { font-size: 16px; /* prevent iOS zoom on focus */ }

  /* Login body had centered padding — be a bit tighter */
  body.login-body { padding: 12px; }

  /* Toasts: don't run off-screen on tiny phones */
  .toast {
    right: 8px;
    bottom: 8px;
    left: 8px;
    max-width: none;
  }

  /* Tables (calibration) wrap fields nicely */
  table.calib-table input { width: 70px; }
}

/* Tightest viewport */
@media (max-width: 480px) {
  .content { padding: 10px; }
  .content h1 { font-size: 16px; }

  /* On very small screens, even the filter-row fields go full-width */
  .filter-row .field { flex: 1 1 100%; }

  /* Hide the brand text on the smallest screens to save space —
     dot alone identifies the site. */
  .topnav .brand span:not(.brand-dot) { display: none; }

  /* Cameras page: name input grows */
  .cam-card .name { font-size: 14px; }

  /* Bulk action bar: stack vertically on tiny widths */
  .bulk-bar {
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px;
  }
  .bulk-bar .spacer { display: none; }
  .bulk-bar button { flex: 1 1 40%; }

  /* Live-detail control-bar: ensure buttons stretch and the elapsed badge
     doesn't push everything off the right edge. */
  .live-detail .control-bar { gap: 6px; padding: 8px; }
  .live-detail .control-bar > * { flex: 0 0 auto; }
  .live-detail .control-bar .spacer { display: none; }
}

/* Older 760px rule for .alert-drawer is now superseded for ≤720px, but
 * we leave it intact so 720–760px tablets still get the old "narrow
 * floating" geometry. The 720px rule above takes priority below 720px. */
