/* ============================================================================
   BMA Traffic AI & CCTV Dashboard - Premium Design System
   ============================================================================ */

/* --- Custom Sleek Scrollbar --- */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}
::-webkit-scrollbar-track {
  background: #e2e8f0;
}
::-webkit-scrollbar-thumb {
  background: #94a3b8;
  border-radius: 9999px;
}
::-webkit-scrollbar-thumb:hover {
  background: #64748b;
}

.dark ::-webkit-scrollbar-track {
  background: #090d16;
}
.dark ::-webkit-scrollbar-thumb {
  background: #1e293b;
  border: 1px solid #0f172a;
}
.dark ::-webkit-scrollbar-thumb:hover {
  background: #334155;
}

.no-scrollbar::-webkit-scrollbar {
  display: none;
}
.no-scrollbar {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

/* --- Glassmorphism & Modern Surfaces --- */
.glass-panel {
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(51, 65, 85, 0.45);
}

.glass-nav {
  background: rgba(248, 250, 252, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(203, 213, 225, 0.9);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.dark .glass-nav {
  background: rgba(11, 15, 25, 0.88);
  border-bottom-color: rgba(30, 41, 59, 0.8);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.glass-card {
  background: linear-gradient(180deg, rgba(22, 30, 49, 0.85) 0%, rgba(15, 23, 42, 0.95) 100%);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(51, 65, 85, 0.5);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
}

/* --- Camera Card Micro-interactions --- */
.camera-card {
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), 
              box-shadow 0.28s cubic-bezier(0.16, 1, 0.3, 1), 
              border-color 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform, box-shadow;
}

.camera-card:hover {
  transform: translateY(-4px);
  border-color: rgba(244, 63, 94, 0.5);
  box-shadow: 0 20px 30px -10px rgba(0, 0, 0, 0.6), 
              0 0 25px -5px rgba(244, 63, 94, 0.15);
}

/* Subtle Shimmer for Skeleton / Loading */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.skeleton-loading {
  background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.8s infinite;
}

.dark .skeleton-loading {
  background: linear-gradient(90deg, #0f172a 25%, #1e293b 50%, #0f172a 75%);
  background-size: 200% 100%;
}

/* --- Glow Effects --- */
.glow-emerald {
  box-shadow: 0 0 16px -2px rgba(16, 185, 129, 0.45);
}
.glow-amber {
  box-shadow: 0 0 16px -2px rgba(245, 158, 11, 0.45);
}
.glow-rose {
  box-shadow: 0 0 16px -2px rgba(244, 63, 94, 0.45);
}
.glow-indigo {
  box-shadow: 0 0 16px -2px rgba(99, 102, 241, 0.45);
}

/* --- KPI Stats Interactive Card --- */
.kpi-stat-card {
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.kpi-stat-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: transparent;
  transition: background 0.22s ease;
}

.kpi-stat-card:hover {
  transform: translateY(-2px);
  border-color: rgba(148, 163, 184, 0.4);
}

.kpi-stat-card.active-flowing::after { background: #10b981; }
.kpi-stat-card.active-moderate::after { background: #f59e0b; }
.kpi-stat-card.active-congested::after { background: #f43f5e; }
.kpi-stat-card.active-all::after { background: #6366f1; }

.kpi-stat-card.active {
  border-color: rgba(244, 63, 94, 0.8) !important;
  box-shadow: 0 0 20px -5px rgba(244, 63, 94, 0.3) !important;
}

/* --- CCTV Custom Map Markers --- */
.cctv-custom-pin {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: white;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6);
  cursor: pointer;
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
}
.cctv-custom-pin:hover {
  transform: scale(1.35);
  z-index: 9999 !important;
}

.cctv-pin-flowing {
  background: linear-gradient(135deg, #10b981, #047857);
  border: 2px solid #a7f3d0;
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.7);
}

.cctv-pin-moderate {
  background: linear-gradient(135deg, #f59e0b, #b45309);
  border: 2px solid #fef08a;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.7);
}

.cctv-pin-congested {
  background: linear-gradient(135deg, #f43f5e, #be123c);
  border: 2px solid #ffe4e6;
  box-shadow: 0 0 16px rgba(244, 63, 94, 0.85);
}

.cctv-pin-congested::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid #f43f5e;
  animation: radar-pulse 1.8s infinite cubic-bezier(0, 0, 0.2, 1);
  pointer-events: none;
}

@keyframes radar-pulse {
  0% {
    transform: scale(0.85);
    opacity: 1;
  }
  100% {
    transform: scale(1.65);
    opacity: 0;
  }
}

/* --- Modern Mapbox Popup Styling --- */
.maplibregl-popup-content, .mapboxgl-popup-content {
  background: #ffffff !important;
  color: #0f172a !important;
  border: 1px solid #cbd5e1 !important;
  border-radius: 20px !important;
  box-shadow: 0 25px 40px -10px rgba(15, 23, 42, 0.25) !important;
  padding: 14px !important;
  backdrop-filter: blur(12px) !important;
}

.maplibregl-popup-tip, .mapboxgl-popup-tip {
  border-top-color: #ffffff !important;
  border-bottom-color: #ffffff !important;
}

.dark .maplibregl-popup-content, .dark .mapboxgl-popup-content {
  background: #090d16 !important;
  color: #f8fafc !important;
  border-color: #334155 !important;
  box-shadow: 0 25px 40px -10px rgba(0, 0, 0, 0.85), 0 0 15px rgba(244, 63, 94, 0.15) !important;
}

.dark .maplibregl-popup-tip, .dark .mapboxgl-popup-tip {
  border-top-color: #090d16 !important;
  border-bottom-color: #090d16 !important;
}

.maplibregl-popup-close-button, .mapboxgl-popup-close-button {
  color: #94a3b8 !important;
  font-size: 18px !important;
  padding: 6px 10px !important;
  outline: none !important;
}
.maplibregl-popup-close-button:hover, .mapboxgl-popup-close-button:hover {
  color: #ffffff !important;
}

/* Offline Map Contrast */
.map-dark-tiles .maplibregl-canvas,
.map-dark-tiles .mapboxgl-canvas {
  filter: invert(93%) hue-rotate(180deg) brightness(85%) contrast(110%);
}

/* --- Floating Scroll-To-Top Button --- */
#btn-scroll-top {
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
#btn-scroll-top:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 20px -5px rgba(244, 63, 94, 0.5);
}

/* --- Quick Preset Button Active Styles --- */
.quick-preset-btn.active {
  background-color: #e11d48 !important;
  color: #ffffff !important;
  font-weight: 700 !important;
  border-color: #f43f5e !important;
  box-shadow: 0 2px 8px rgba(244, 63, 94, 0.4) !important;
}

/* --- Hardware Acceleration & Smooth Frame Fade --- */
.smooth-stream-img {
  image-rendering: auto;
  transform: translateZ(0);
  backface-visibility: hidden;
  will-change: opacity, transform;
}

/* Pulse animation for live badges */
@keyframes live-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.9); }
}
.live-pulse-dot {
  animation: live-pulse 1.6s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* ============================================================================
   Header controls
   Written as components rather than utility strings because the same look is
   applied from both index.html and app.js, and they must agree.
   ============================================================================ */

.view-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  color: #475569;
  background: transparent;
  cursor: pointer;
  transition: color 0.18s ease, background 0.18s ease;
  white-space: nowrap;
}
.view-tab:hover {
  color: #0f172a;
  background: rgba(255, 255, 255, 0.85);
}
.view-tab.is-active {
  color: #ffffff;
  background: #e11d48;
  box-shadow: 0 2px 8px rgba(225, 29, 72, 0.35);
}
.dark .view-tab {
  color: #94a3b8;
}
.dark .view-tab:hover {
  color: #ffffff;
  background: rgba(30, 41, 59, 0.85);
}
.dark .view-tab.is-active {
  color: #ffffff;
  background: #e11d48;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  color: #475569;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #cbd5e1;
  cursor: pointer;
  transition: color 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}
.icon-btn:hover {
  color: #0f172a;
  background: #ffffff;
  border-color: #94a3b8;
}
.dark .icon-btn {
  color: #94a3b8;
  background: rgba(15, 23, 42, 0.9);
  border-color: #1e293b;
}
.dark .icon-btn:hover {
  color: #ffffff;
  background: #1e293b;
  border-color: #334155;
}

/* Selects and secondary buttons in the toolbar share one height and radius so
   the row reads as a single strip instead of a pile of odd shapes. */
.ctl,
.ctl-btn {
  height: 38px;
  padding: 0 12px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  color: #334155;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
}
.ctl:hover,
.ctl-btn:hover {
  border-color: #94a3b8;
}
.ctl:focus-visible,
.ctl-btn:focus-visible {
  outline: 2px solid rgba(244, 63, 94, 0.6);
  outline-offset: 1px;
}
.dark .ctl,
.dark .ctl-btn {
  color: #cbd5e1;
  background: rgba(15, 23, 42, 0.9);
  border-color: #1e293b;
}
.dark .ctl:hover,
.dark .ctl-btn:hover {
  border-color: #334155;
}

/* The two toggles turn rose when what they control is on */
.ctl-btn.is-on,
.dark .ctl-btn.is-on {
  color: #ffffff;
  background: #e11d48;
  border-color: #e11d48;
}

/* Card surface, light and dark. .camera-card already carried the hover lift. */
.camera-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}
.camera-card:hover {
  box-shadow: 0 20px 30px -12px rgba(15, 23, 42, 0.22),
              0 0 20px -6px rgba(244, 63, 94, 0.18);
}
.dark .camera-card {
  background: #0f172a;
  border-color: #1e293b;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4);
}
.dark .camera-card:hover {
  box-shadow: 0 20px 30px -10px rgba(0, 0, 0, 0.6),
              0 0 25px -5px rgba(244, 63, 94, 0.15);
}

/* Hide the browser's own search-field clear button; the toolbar draws its own */
#search::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

/* No camera toolbar while the map is up - none of it applies there */
body.hide-toolbar #toolbar {
  display: none;
}

/* Amber-on-amber was written for the dark page only; on the light one it
   washed out, so the two themes now carry their own text colour. */
.detector-notice {
  padding: 10px 16px;
  font-size: 12px;
  text-align: center;
  background: rgba(245, 158, 11, 0.16);
  border-bottom: 1px solid rgba(245, 158, 11, 0.45);
  color: #92400e;
}
.dark .detector-notice {
  background: rgba(245, 158, 11, 0.12);
  color: #fcd34d;
}
