/* ==========================================================================
   TRAFIPULSE — ESTILOS DE TRÁFICO Y MOVILIDAD (MATERIAL DESIGN 3)
   ========================================================================== */

/* Layout Principal de Tráfico */
.traffic-main-container {
  max-width: 1560px;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Header & Barra de Búsqueda de Tráfico */
.traffic-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.traffic-active-location-badge {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--shape-xl);
  padding: 0.45rem 1.15rem;
  box-shadow: var(--md-elevation-1);
}

.location-pulse-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #0284c7;
  position: relative;
  box-shadow: 0 0 0 0 rgba(2, 132, 199, 0.7);
  animation: locationPulse 2s infinite;
  flex-shrink: 0;
}

@keyframes locationPulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(2, 132, 199, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(2, 132, 199, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(2, 132, 199, 0); }
}

.traffic-search-box {
  display: flex;
  align-items: center;
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--shape-full);
  padding: 0.45rem 1rem;
  gap: 0.5rem;
  min-width: 280px;
  transition: all var(--duration-short) ease;
}

.traffic-search-box:focus-within {
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 0 0 2px rgba(0, 100, 149, 0.2);
}

.traffic-search-box input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--md-sys-color-on-surface);
  font-family: inherit;
  font-size: 0.9rem;
  width: 100%;
}

/* KPI Cards de Tráfico */
.traffic-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1.25rem;
}

.traffic-kpi-card {
  background: var(--md-sys-color-card-bg);
  border: 1px solid var(--md-sys-color-card-border);
  border-radius: var(--shape-xl);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: var(--md-elevation-1);
  transition: transform var(--duration-short) ease, box-shadow var(--duration-short) ease;
}

.traffic-kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--md-elevation-2);
}

.traffic-kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.88rem;
  font-weight: 600;
}

.traffic-kpi-value-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.traffic-kpi-value {
  font-family: var(--font-family-brand);
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1;
  color: var(--md-sys-color-on-surface);
}

.traffic-kpi-unit {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--md-sys-color-on-surface-variant);
}

/* Barra de Fluidez */
.flow-bar-container {
  width: 100%;
  height: 8px;
  background: var(--md-sys-color-surface-container-highest);
  border-radius: var(--shape-full);
  overflow: hidden;
  position: relative;
}

.flow-bar-fill {
  height: 100%;
  border-radius: var(--shape-full);
  background: linear-gradient(90deg, #ef4444 0%, #f59e0b 45%, #10b981 80%);
  transition: width 0.6s ease;
}

/* Grid Principal de Tráfico (Mapa + Panel Lateral) */
.traffic-content-grid {
  display: grid;
  grid-template-columns: 1.75fr 1.25fr;
  gap: 1.5rem;
  align-items: start;
}

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

/* Tarjeta del Mapa */
.traffic-map-card {
  background: var(--md-sys-color-card-bg);
  border: 1px solid var(--md-sys-color-card-border);
  border-radius: var(--shape-xxl);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: var(--md-elevation-1);
}

.map-card-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.85rem;
}

.map-brand-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.map-provider-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--duration-short) ease;
}

.map-provider-avatar.waze {
  background: #33ccff;
  color: #0b1526;
  box-shadow: 0 2px 8px rgba(51, 204, 255, 0.45);
}

.map-provider-avatar.googlemaps {
  background: #ea4335;
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(234, 67, 53, 0.45);
}

.map-provider-avatar.osm {
  background: #10b981;
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.45);
}

/* Selector Segmentado de Proveedor: OSM / Google Maps / Waze */
.map-provider-selector {
  display: inline-flex;
  align-items: center;
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--shape-full);
  padding: 0.25rem;
  gap: 0.25rem;
  box-shadow: var(--md-elevation-1);
}

.provider-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.85rem;
  border-radius: var(--shape-full);
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--duration-short) ease;
  user-select: none;
}

.provider-pill-btn:hover {
  color: var(--md-sys-color-on-surface);
  background: rgba(0, 100, 149, 0.08);
}

.provider-pill-btn.active {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  box-shadow: var(--md-elevation-1);
}

.map-actions-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.map-badge-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(0, 100, 149, 0.12);
  color: var(--md-sys-color-primary);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--shape-full);
  padding: 0.35rem 0.85rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-decoration: none;
  transition: all var(--duration-short) ease;
}

.map-badge-pill:hover {
  background: rgba(0, 100, 149, 0.22);
  transform: translateY(-1px);
}

/* Contenedor del Mapa Multi-Proveedor */
.traffic-map-container {
  width: 100%;
  height: 540px;
  border-radius: var(--shape-xl);
  overflow: hidden;
  border: 1px solid var(--md-sys-color-outline-variant);
  position: relative;
  background: var(--md-sys-color-surface-container);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

.traffic-map-frame {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

.traffic-osm-map {
  width: 100%;
  height: 100%;
  border-radius: var(--shape-xl);
  z-index: 1;
}

/* Botón de Capas con Badge */
.layers-btn {
  cursor: pointer;
  border: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
}

.layers-btn:hover {
  background: var(--md-sys-color-surface-container-high);
}

.layers-btn.active-state {
  background: rgba(0, 100, 149, 0.15);
  border-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-primary);
}

.layers-count-chip {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border-radius: var(--shape-full);
  font-size: 0.68rem;
  padding: 0 0.4rem;
  min-width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

/* Botón flotante FAB en el mapa */
.map-floating-fab {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 1005;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--duration-short) ease;
}

.map-floating-fab:hover {
  transform: scale(1.08);
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

/* Panel Flotante de Control de Capas */
.traffic-layers-panel {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 1010;
  width: 320px;
  max-width: calc(100% - 2rem);
  max-height: calc(100% - 2rem);
  overflow-y: auto;
  background: rgba(240, 244, 250, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--shape-xl);
  padding: 1rem;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  animation: slideInLayers 0.25s cubic-bezier(0.2, 0, 0, 1);
}

[data-theme="dark"] .traffic-layers-panel {
  background: rgba(26, 32, 44, 0.95);
}

@keyframes slideInLayers {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.layers-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  font-family: var(--font-family-brand);
  font-size: 0.95rem;
  color: var(--md-sys-color-on-surface);
}

.layers-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.layers-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--md-sys-color-outline);
}

/* Grid de Capas Base */
.base-layers-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.base-layer-option {
  cursor: pointer;
}

.base-layer-option.span-full {
  grid-column: span 2;
}

.base-layer-option input[type="radio"] {
  display: none;
}

.base-layer-card {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.65rem;
  background: var(--md-sys-color-surface-container);
  border: 1.5px solid var(--md-sys-color-outline-variant);
  border-radius: var(--shape-md);
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.78rem;
  font-weight: 600;
  transition: all var(--duration-short) ease;
}

.base-layer-card .material-symbols-outlined {
  font-size: 18px;
}

.base-layer-option input[type="radio"]:checked + .base-layer-card {
  background: rgba(0, 100, 149, 0.15);
  border-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-primary);
  box-shadow: var(--md-elevation-1);
}

/* Lista de Capas de Telemetría (Overlays) */
.overlay-layers-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.overlay-toggle-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--shape-md);
  cursor: pointer;
  transition: all var(--duration-short) ease;
}

.overlay-toggle-item:hover {
  background: var(--md-sys-color-surface-container-high);
}

.overlay-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.overlay-info .material-symbols-outlined {
  font-size: 20px;
  flex-shrink: 0;
}

.overlay-info div {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.overlay-info strong {
  font-size: 0.78rem;
  color: var(--md-sys-color-on-surface);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.overlay-info span {
  font-size: 0.68rem;
  color: var(--md-sys-color-outline);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Material 3 Switch Slider */
.m3-switch-input {
  display: none;
}

.m3-switch-slider {
  width: 38px;
  height: 22px;
  background: var(--md-sys-color-surface-container-highest);
  border: 1.5px solid var(--md-sys-color-outline);
  border-radius: var(--shape-full);
  position: relative;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.m3-switch-slider::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--md-sys-color-outline);
  transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
}

.m3-switch-input:checked + .m3-switch-slider {
  background: var(--md-sys-color-primary);
  border-color: var(--md-sys-color-primary);
}

.m3-switch-input:checked + .m3-switch-slider::after {
  transform: translateX(16px);
  background: var(--md-sys-color-on-primary);
}

/* Leyenda del Mapa */
.traffic-map-legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--md-sys-color-on-surface-variant);
  padding-top: 0.25rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.legend-line {
  width: 22px;
  height: 4px;
  border-radius: var(--shape-full);
}

.line-fluid { background: #10b981; }
.line-dense { background: #f59e0b; }
.line-slow { background: #ea580c; }
.line-congested { background: #dc2626; }

/* Columna Principal (Mapa + Cámaras debajo) */
.traffic-main-column {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-width: 0;
}

/* Panel Lateral (Cámaras) */
.traffic-side-panel {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  align-self: start;
}

.incidents-card {
  background: var(--md-sys-color-card-bg);
  border: 1px solid var(--md-sys-color-card-border);
  border-radius: var(--shape-xxl);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: var(--md-elevation-1);
}

.incidents-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 0.75rem;
  max-height: 520px;
  overflow-y: auto;
  padding-right: 0.35rem;
  scrollbar-width: thin;
}

.incident-item {
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--shape-lg);
  padding: 0.85rem 1rem;
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  cursor: pointer;
  transition: all var(--duration-short) ease;
}

.incident-item:hover {
  background: var(--md-sys-color-surface-container-high);
  border-color: var(--md-sys-color-primary);
  transform: translateX(3px);
}

.incident-icon-box {
  width: 36px;
  height: 36px;
  border-radius: var(--shape-full);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.incident-icon-box.sev-high {
  background: rgba(220, 38, 38, 0.15);
  color: #dc2626;
}

.incident-icon-box.sev-med {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}

.incident-icon-box.sev-low {
  background: rgba(2, 132, 199, 0.15);
  color: #0284c7;
}

.incident-info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
}

.incident-road {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
}

.incident-desc {
  font-size: 0.8rem;
  color: var(--md-sys-color-on-surface-variant);
  line-height: 1.3;
}

.incident-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--md-sys-color-outline);
  margin-top: 0.2rem;
}

/* Tarjeta de Cámaras de Tráfico */
.cameras-card {
  background: var(--md-sys-color-card-bg);
  border: 1px solid var(--md-sys-color-card-border);
  border-radius: var(--shape-xxl);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  height: fit-content;
  box-shadow: var(--md-elevation-1);
}

.cameras-carousel {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.85rem;
  height: auto;
  max-height: none;
  overflow: visible;
}

.camera-box {
  background: #090e17;
  border-radius: var(--shape-md);
  overflow: hidden;
  border: 1px solid var(--md-sys-color-outline-variant);
  position: relative;
  display: flex;
  flex-direction: column;
  transition: transform var(--duration-short) ease, box-shadow var(--duration-short) ease;
}

.camera-box:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  border-color: var(--md-sys-color-primary);
}

.camera-preview {
  width: 100%;
  height: 110px;
  background-size: cover;
  background-position: center;
  position: relative;
}

.camera-live-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(220, 38, 38, 0.85);
  color: #ffffff;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 0.1rem 0.4rem;
  border-radius: var(--shape-full);
  display: flex;
  align-items: center;
  gap: 0.2rem;
  letter-spacing: 0.05em;
  z-index: 2;
}

.camera-dist-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(15, 23, 42, 0.85);
  color: #38bdf8;
  font-size: 0.64rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: var(--shape-full);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(56, 189, 248, 0.3);
  z-index: 2;
}

.camera-live-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #ffffff;
  animation: pulseLiveDot 1.2s infinite;
}

@keyframes pulseLiveDot {
  0% { opacity: 0.4; }
  50% { opacity: 1; }
  100% { opacity: 0.4; }
}

.camera-footer {
  padding: 0.5rem 0.65rem;
  background: var(--md-sys-color-surface-container-high);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.camera-road-tag {
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--md-sys-color-primary);
  font-family: var(--font-family-brand);
}

.camera-pk-tag {
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
  padding: 0.08rem 0.4rem;
  border-radius: var(--shape-xs);
  border: 1px solid var(--md-sys-color-outline-variant);
}

.camera-road-name {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.camera-km-info {
  font-size: 0.68rem;
  color: var(--md-sys-color-on-surface-variant);
}

/* Chips de selección de ciudad */
.traffic-chip-btn {
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--shape-full);
  padding: 0.4rem 0.9rem;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--duration-short) ease;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.traffic-chip-btn:hover {
  background: var(--md-sys-color-surface-container-high);
  border-color: var(--md-sys-color-primary);
}

.traffic-chip-btn.active {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 2px 6px rgba(0, 100, 149, 0.3);
}

/* Modal de previsualización de cámara */
.camera-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1.5rem;
}

.camera-modal-card {
  background: var(--md-sys-color-surface-container-lowest);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--shape-xxl);
  width: 100%;
  max-width: 640px;
  overflow: hidden;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
}

.camera-modal-header {
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.camera-modal-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.camera-modal-screen {
  width: 100%;
  height: 280px;
  background: #090e17;
  border-radius: var(--shape-lg);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.camera-modal-footer {
  padding: 0.75rem 1.25rem;
  background: var(--md-sys-color-surface-container-low);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--md-sys-color-on-surface-variant);
}
