/* ==========================================================================
   高公局 CCTV 即時影像戰情室 (Freeway Bureau CCTV Dashboard)
   Design System & Styling
   ========================================================================== */

/* Fonts are loaded once from the document head. */

:root {
  /* Dark Command Center Palette (Default) */
  --bg-primary: #070a12;
  --bg-secondary: #0d1322;
  --bg-surface: #131b2e;
  --bg-surface-hover: #1b2640;
  --bg-glass: rgba(13, 19, 34, 0.78);
  --bg-glass-card: rgba(19, 27, 46, 0.7);

  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-medium: rgba(255, 255, 255, 0.16);
  --border-active: #00f2fe;

  --accent-cyan: #00f2fe;
  --accent-blue: #38bdf8;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  --accent-purple: #a855f7;

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-inverse: #070a12;

  --glow-cyan: 0 0 20px rgba(0, 242, 254, 0.35);
  --glow-slot-active: 0 0 0 2px #00f2fe, 0 0 25px rgba(0, 242, 254, 0.45);
  --glow-emerald: 0 0 15px rgba(16, 185, 129, 0.4);

  --shadow-card: 0 8px 32px 0 rgba(0, 0, 0, 0.45);
  --shadow-modal: 0 24px 48px -12px rgba(0, 0, 0, 0.75);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

body.theme-light {
  --bg-primary: #f1f5f9;
  --bg-secondary: #ffffff;
  --bg-surface: #f8fafc;
  --bg-surface-hover: #e2e8f0;
  --bg-glass: rgba(255, 255, 255, 0.85);
  --bg-glass-card: rgba(255, 255, 255, 0.9);

  --border-subtle: rgba(0, 0, 0, 0.08);
  --border-medium: rgba(0, 0, 0, 0.16);
  --border-active: #0284c7;

  --accent-cyan: #0284c7;
  --accent-blue: #2563eb;
  --accent-emerald: #059669;
  --accent-amber: #d97706;
  --accent-rose: #e11d48;
  --accent-purple: #7c3aed;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-inverse: #ffffff;

  --glow-cyan: 0 0 15px rgba(2, 132, 199, 0.25);
  --glow-slot-active: 0 0 0 2px #0284c7, 0 0 20px rgba(2, 132, 199, 0.35);
  --glow-emerald: 0 0 12px rgba(5, 150, 105, 0.3);

  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.08);
  --shadow-modal: 0 20px 35px -10px rgba(15, 23, 42, 0.2);
}

/* ==========================================================================
   Base & Reset
   ========================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  width: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang TC", "Microsoft JhengHei", sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  font-size: 14px;
  line-height: 1.5;
  transition: background-color var(--transition-normal), color var(--transition-normal);
}

code, .mono {
  font-family: 'JetBrains Mono', monospace;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-medium);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ==========================================================================
   App Layout
   ========================================================================== */
#app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  background: radial-gradient(circle at 10% 15%, rgba(0, 242, 254, 0.04) 0%, transparent 40%),
              radial-gradient(circle at 90% 85%, rgba(16, 185, 129, 0.03) 0%, transparent 40%);
}

/* Top Navbar */
.top-navbar {
  height: 60px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-glass);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 100;
  gap: 16px;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #00f2fe 0%, #4facfe 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #070a12;
  box-shadow: var(--glow-cyan);
  flex-shrink: 0;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-subtitle {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  font-weight: 700;
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-emerald);
  box-shadow: var(--glow-emerald);
  animation: pulse-dot 1.8s infinite;
}

@keyframes pulse-dot {
  0% { transform: scale(0.95); opacity: 0.6; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.6; }
}

/* Center Quick Controls (Grid / Mode / Preset) */
.nav-center-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.segmented-control {
  display: flex;
  align-items: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
}

.seg-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.seg-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.seg-btn.active {
  background: var(--accent-cyan);
  color: var(--text-inverse);
  box-shadow: 0 2px 8px rgba(0, 242, 254, 0.3);
}

/* Nav Actions Right */
.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-icon:hover {
  color: var(--text-primary);
  border-color: var(--border-medium);
  background: var(--bg-surface-hover);
}

.btn-primary {
  background: linear-gradient(135deg, #00f2fe 0%, #4facfe 100%);
  color: #070a12;
  border: none;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 7px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: var(--glow-cyan);
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}

.btn-primary:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

/* ==========================================================================
   Main Workspace Layout
   ========================================================================== */
.main-workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* Left Sidebar (Cameras Catalog) */
.sidebar-panel {
  width: 360px;
  min-width: 360px;
  max-width: 360px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  z-index: 50;
  transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
}

.sidebar-panel.collapsed {
  margin-left: -360px;
}

/* Floating Edge Toggle when Sidebar is Collapsed */
.sidebar-edge-toggle {
  position: absolute;
  top: 60px;
  left: 12px;
  z-index: 45;
  display: none;
  align-items: center;
  gap: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  transition: all var(--transition-fast);
}

.sidebar-edge-toggle:hover {
  background: var(--bg-surface-hover);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
  transform: translateX(2px);
}

.sidebar-panel.collapsed ~ .sidebar-edge-toggle {
  display: inline-flex;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Search Box */
.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 38px;
  padding: 0 34px 0 36px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.85rem;
  transition: all var(--transition-fast);
}

.search-input:focus {
  outline: none;
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 3px rgba(0, 242, 254, 0.15);
  background: var(--bg-surface-hover);
}

.search-clear-btn {
  position: absolute;
  right: 10px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: none;
  font-size: 1rem;
}

.search-input:not(:placeholder-shown) + .search-clear-btn {
  display: block;
}

/* Highway Quick Filters Pills */
.filter-pills-container {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.pill-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
}

.pill-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.pill-btn.active {
  background: var(--accent-cyan);
  border-color: var(--accent-cyan);
  color: var(--text-inverse);
}

/* Sidebar Sub Info Row (Title & Count) */
.sidebar-info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.cam-count-title {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.dir-tags {
  display: flex;
  gap: 4px;
}

.dir-tag {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 600;
  transition: all var(--transition-fast);
}

.dir-tag:hover {
  color: var(--text-primary);
  border-color: var(--border-medium);
}

.dir-tag.active {
  background: rgba(0, 242, 254, 0.15);
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
}

/* Cameras List Area */
.cameras-list-container {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cam-catalog-card {
  display: flex;
  gap: 10px;
  padding: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
}

.cam-catalog-card:hover {
  border-color: var(--border-medium);
  background: var(--bg-surface-hover);
  transform: translateY(-1px);
}

.cam-thumb-wrapper {
  width: 88px;
  height: 52px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
  position: relative;
  flex-shrink: 0;
}

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

.cam-catalog-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
}

.cam-catalog-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cam-catalog-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.badge-tag {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 4px;
}

.badge-freeway {
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent-blue);
}

.badge-direction {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
}

/* Compact Tree Mode (縮小樹狀模式) */
.cameras-list-container.compact-tree {
  gap: 4px;
  padding: 6px;
}

.cameras-list-container.compact-tree .cam-catalog-card {
  padding: 4px 8px;
  gap: 8px;
  min-height: 38px;
}

.cameras-list-container.compact-tree .cam-thumb-wrapper {
  width: 42px;
  height: 28px;
  border-radius: 3px;
  flex-shrink: 0;
}

.cameras-list-container.compact-tree .cam-catalog-title {
  font-size: 0.78rem;
  line-height: 1.2;
}

.cameras-list-container.compact-tree .cam-catalog-meta {
  font-size: 0.68rem;
  gap: 4px;
}

/* ==========================================================================
   Center Viewport: Multi-Grid Wall & Map View
   ========================================================================== */
.content-viewport {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background: var(--bg-primary);
}

/* Viewport Header Bar (Preset & Quick Settings) */
.viewport-topbar {
  height: 48px;
  padding: 0 16px;
  background: var(--bg-glass);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 40;
}

.preset-scroll-track {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  max-width: 75%;
}

.preset-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
}

.preset-chip:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: var(--border-medium);
}

.preset-chip.active {
  background: rgba(0, 242, 254, 0.15);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.preset-delete-btn {
  color: var(--text-muted);
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 2px 4px;
  font-size: 0.75rem;
  border-radius: 4px;
}

.preset-delete-btn:hover {
  color: var(--accent-rose);
  background: rgba(244, 63, 94, 0.15);
}

.viewport-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Grid Matrix Container */
.grid-container {
  flex: 1;
  padding: 12px;
  display: grid;
  gap: 12px;
  overflow: auto;
  position: relative;
}

/* Grid Layouts */
.grid-container.layout-1x1 {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}

.grid-container.layout-2x2 {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
}

.grid-container.layout-3x3 {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
}

.grid-container.layout-4x4 {
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
}

/* CCTV Slot Box */
.cctv-slot {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  transition: box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.cctv-slot.active-slot {
  border-color: var(--accent-cyan);
  box-shadow: var(--glow-slot-active);
}

.cctv-slot.drag-over {
  border-color: var(--accent-emerald);
  box-shadow: 0 0 0 2px var(--accent-emerald), 0 0 20px rgba(16, 185, 129, 0.4);
  transform: scale(1.01);
}

/* Slot Title & Actions (Integrated in bottom bar) */
.slot-title-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #ffffff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.95), 0 0 6px rgba(0,0,0,0.85);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
}

.slot-title-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slot-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.slot-btn {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.72rem;
  transition: all var(--transition-fast);
}

.slot-btn:hover {
  background: rgba(0, 242, 254, 0.45);
  border-color: var(--accent-cyan);
}

/* Slot Media Area with Seamless Double Buffering */
.slot-media-area {
  flex: 1;
  background: #050811;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stream-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
  transition: opacity 0.25s ease-in-out;
}

.stream-layer.layer-visible {
  opacity: 1;
  z-index: 2;
}

.stream-layer.layer-hidden {
  opacity: 0;
  z-index: 1;
  pointer-events: none;
}

.slot-reconnect-badge {
  position: absolute;
  bottom: 44px;
  right: 10px;
  background: rgba(7, 10, 18, 0.85);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(0, 242, 254, 0.3);
  color: var(--accent-cyan);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.68rem;
  font-weight: 600;
  z-index: 15;
  display: none;
  align-items: center;
  gap: 5px;
  pointer-events: none;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Slot Footer Overlay (Single Compact Bottom Bar) */
.slot-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 36px;
  padding: 0 10px;
  background: linear-gradient(0deg, rgba(7, 10, 18, 0.55) 0%, rgba(7, 10, 18, 0.20) 70%, rgba(7, 10, 18, 0) 100%);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  z-index: 10;
  pointer-events: auto;
  user-select: none;
}

.slot-info-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.slot-status-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.7rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.95);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Empty Slot Placeholder */
.empty-slot-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-muted);
  cursor: pointer;
  width: 100%;
  height: 100%;
  transition: all var(--transition-fast);
}

.empty-slot-placeholder:hover {
  color: var(--accent-cyan);
  background: rgba(0, 242, 254, 0.03);
}

.empty-slot-icon {
  font-size: 1.8rem;
}

.empty-slot-text {
  font-size: 0.82rem;
  font-weight: 600;
}

.empty-slot-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ==========================================================================
   Map View (Leaflet Integration)
   ========================================================================== */
#map-viewport {
  position: absolute;
  top: 48px;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: calc(100% - 48px);
  z-index: 30;
  display: none;
}

#map-viewport.active {
  display: block;
}

#leaflet-map {
  width: 100%;
  height: 100%;
  min-height: 400px;
  background: #0b1120;
}

/* Custom Map Marker & Popup */
.custom-cam-pin {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 0 10px rgba(0,0,0,0.5);
  cursor: pointer;
  transition: transform 0.2s;
}

.custom-cam-pin:hover {
  transform: scale(1.4);
}

.pin-freeway-1 { background: #38bdf8; }
.pin-freeway-2 { background: #818cf8; }
.pin-freeway-3 { background: #10b981; }
.pin-freeway-5 { background: #f59e0b; }
.pin-freeway-other { background: #a855f7; }
.pin-expressway { background: #f43f5e; }

/* OpenStreetMap 開源地圖深色主題濾鏡 (徹底消除 API Key 浮水印，呈現高科技戰情室暗色質感) */
body:not(.theme-light) .leaflet-tile-pane {
  filter: invert(100%) hue-rotate(180deg) brightness(88%) contrast(92%);
}

/* 確保攝影機標記、影像彈窗與地圖控制元件不受濾鏡影響 */
.leaflet-marker-pane,
.leaflet-popup-pane,
.leaflet-control-container {
  filter: none !important;
}

/* Leaflet 圖層切換控制選單 (深色模式風格化) */
.leaflet-control-layers {
  background: var(--bg-surface) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border-medium) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-card) !important;
  padding: 6px 10px !important;
}

.leaflet-control-layers label {
  color: var(--text-primary) !important;
  font-size: 0.78rem !important;
  font-weight: 500 !important;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.leaflet-control-layers-toggle {
  background-color: var(--bg-surface) !important;
  border-radius: var(--radius-sm);
}

/* Leaflet Popup Custom Styling */
.leaflet-popup-content-wrapper {
  background: var(--bg-surface) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-modal) !important;
  padding: 0 !important;
}

.leaflet-popup-content {
  margin: 12px !important;
}

.map-popup-card {
  width: 220px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.map-popup-card img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: #000;
}

.map-popup-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
}

.map-popup-btn {
  background: var(--accent-cyan);
  color: var(--text-inverse);
  border: none;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.75rem;
  cursor: pointer;
  text-align: center;
}

/* ==========================================================================
   Modals & Dialogs (Password 7154 Confirmation & Save Preset)
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-dialog {
  width: 400px;
  max-width: 90vw;
  background: var(--bg-secondary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-modal);
  overflow: hidden;
  transform: scale(0.95);
  transition: transform var(--transition-fast);
}

.modal-overlay.open .modal-dialog {
  transform: scale(1);
}

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

.modal-title {
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.modal-input {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.95rem;
}

.modal-input:focus {
  outline: none;
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 3px rgba(0, 242, 254, 0.15);
}

.modal-pin-input {
  letter-spacing: 0.4em;
  font-size: 1.3rem;
  text-align: center;
  font-weight: 700;
}

.modal-alert-box {
  background: rgba(244, 63, 94, 0.1);
  border: 1px solid rgba(244, 63, 94, 0.25);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: var(--accent-rose);
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-footer {
  padding: 14px 20px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-secondary:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--accent-rose);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(244, 63, 94, 0.35);
  transition: opacity var(--transition-fast);
}

.btn-danger:hover {
  opacity: 0.9;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 2000;
  pointer-events: none;
}

.toast {
  background: var(--bg-secondary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-modal);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  pointer-events: auto;
  animation: slide-in 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slide-in {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.toast.toast-success { border-left: 4px solid var(--accent-emerald); }
.toast.toast-error { border-left: 4px solid var(--accent-rose); }
.toast.toast-info { border-left: 4px solid var(--accent-cyan); }

/* Fullscreen Mode on Single Slot */
.cctv-slot.fullscreen-slot {
  position: fixed !important;
  inset: 0 !important;
  z-index: 9999 !important;
  border-radius: 0 !important;
  border: none !important;
}

/* Self-contained layer control without external PNG assets. */
.leaflet-control-layers-toggle,
.leaflet-retina .leaflet-control-layers-toggle {
  background-image: none;
  display: grid;
  place-items: center;
}
.leaflet-control-layers-toggle::before {
  content: '▱';
  color: #334155;
  font: bold 30px/1 sans-serif;
}

