/* ===== MAP.CSS - Leaflet map, popups, tooltips, legend ===== */

#map {
  height: 500px;
  border-radius: 8px;
  margin-bottom: 15px;
  z-index: 1;
  background: #e9e9e9;
}

/* Force Leaflet divIcon SVG visibility and prevent global CSS height/width collapse */
.leaflet-marker-icon svg {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* District labels */
.district-label {
  font-weight: 700;
  font-size: 13px;
  color: var(--primary);
  text-shadow: 1px 1px 0 #fff, -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff;
  background: 0 0 !important;
  border: 0 !important;
  box-shadow: none !important;
  pointer-events: none !important;
}

.district-label-hover {
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  background: #1a5276 !important;
  border: 0 !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
  padding: 4px 10px !important;
  border-radius: 4px !important;
}

.district-label-hover .leaflet-tooltip-content {
  color: #fff !important;
}

.district-label-hover::before {
  display: none !important;
}

/* Circuito labels */
.circuito-label {
  font-weight: 700;
  font-size: 12px;
  color: #6a1b9a;
  text-shadow: 1px 1px 0 #fff, -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff;
  background: 0 0 !important;
  border: 0 !important;
  box-shadow: none !important;
  pointer-events: none !important;
}

.circuito-label-hover {
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  background: #6a1b9a !important;
  border: 0 !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
  padding: 4px 10px !important;
  border-radius: 4px !important;
}

.circuito-label-hover .leaflet-tooltip-content {
  color: #fff !important;
}

.circuito-label-hover::before {
  display: none !important;
}

/* Barrio hover tooltip */
.barrio-label-hover {
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  background: #c0392b !important;
  border: 0 !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
  padding: 4px 10px !important;
  border-radius: 4px !important;
}

.barrio-label-hover .leaflet-tooltip-content {
  color: #fff !important;
}

.barrio-label-hover::before {
  display: none !important;
}

/* Point/shape labels */
.point-id-label {
  background: #2c3e50 !important;
  border: none !important;
  border-radius: 4px !important;
  color: #fff !important;
  font-weight: 600 !important;
  font-size: 11px !important;
  padding: 2px 8px !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4) !important;
}

.shape-label {
  background: #2c3e50 !important;
  color: #fff !important;
  font-weight: 700 !important;
  font-size: 11px !important;
  padding: 2px 6px !important;
  border-radius: 3px !important;
  border: 0 !important;
}

.leaflet-tooltip-top:before,
.leaflet-tooltip-bottom:before,
.leaflet-tooltip-left:before,
.leaflet-tooltip-right:before {
  display: none !important;
}

/* Legend */
.legend-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 500;
  color: #334155;
  background: #f8fafc;
  padding: 4px 10px;
  border-radius: 16px;
  border: 1px solid #e2e8f0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  transition: background 0.2s, border-color 0.2s;
}

.legend-item:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.legend-item svg {
  flex-shrink: 0;
}

.legend-label {
  white-space: nowrap;
}

.legend-count {
  font-size: 10px;
  font-weight: 600;
  color: #475569;
  background: #e2e8f0;
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: 2px;
}

/* Popups */
.popup-data {
  font-family: var(--font);
  font-size: 12px;
  width: 100%;
  max-width: 320px;
  min-width: 200px;
  box-sizing: border-box;
}

.popup-header {
  font-weight: 700;
  color: var(--primary);
  font-size: 14px;
  padding: 0 0 6px;
  border-bottom: 2px solid var(--primary);
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.popup-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0;
  border-bottom: 1px solid #eee;
  gap: 8px;
}

.popup-row:last-child {
  border-bottom: none;
}

.popup-label {
  font-weight: 600;
  color: #555;
  min-width: 85px;
  flex-shrink: 0;
  font-size: 11px;
}

.popup-value {
  color: var(--text);
  word-break: break-word;
  overflow-wrap: break-word;
  font-size: 12px;
  flex: 1;
  text-align: right;
}

.popup-select {
  font-size: 11px !important;
  padding: 3px 6px !important;
  border-radius: 4px !important;
  border: 1px solid var(--accent) !important;
  background: #f4f8ff !important;
  color: var(--primary) !important;
  font-weight: 600 !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
  cursor: pointer;
}

.leaflet-popup-content-wrapper {
  border-radius: 12px !important;
  padding: 0 !important;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2) !important;
}

.leaflet-popup-content {
  margin: 10px 14px !important;
  max-height: 55vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  min-width: 180px;
}

/* Overlay badges */
.overlay-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--success);
  color: #fff;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 12px;
}

.overlay-badge .remove {
  cursor: pointer;
  font-weight: 700;
  margin-left: 2px;
}

/* ===== Map Icon Markers (Animaciones desactivadas para máxima velocidad y rendimiento) ===== */
.map-icon-static,
.map-icon-animated,
.icon-semaphore,
.icon-semaphore *,
.icon-semaphore .light-active,
.icon-bus,
.icon-tree,
.icon-recycle,
.icon-pulse,
.icon-glow,
.icon-road-line,
.icon-scale-pulse,
.icon-art,
.leaflet-marker-icon svg,
.leaflet-marker-icon svg * {
  animation: none !important;
  -webkit-animation: none !important;
  transition: none !important;
  -webkit-transition: none !important;
}

/* Indicador visual para botón de Cargar Datos cuando se modifican filtros primarios */
.btn-needs-click {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.45) !important;
  border-color: #2563eb !important;
  font-weight: 700 !important;
}

/* ===== Map Fullscreen Control & Floating Volver Button ===== */
.leaflet-control-fullscreen a {
  background: #ffffff !important;
  color: #1e293b !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  font-size: 13px !important;
  cursor: pointer !important;
  transition: background 0.2s, color 0.2s !important;
}

.leaflet-control-fullscreen a:hover {
  background: #f1f5f9 !important;
  color: #00255c !important;
}

.night-mode .leaflet-control-fullscreen a {
  background: #1e293b !important;
  color: #f8fafc !important;
}

.night-mode .leaflet-control-fullscreen a:hover {
  background: #334155 !important;
}

/* Fallback si la API Fullscreen nativa está restringida */
.leaflet-fullscreen-active {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 99999 !important;
  margin: 0 !important;
  border-radius: 0 !important;
}

/* Botón flotante 'Volver' cuando el mapa está en pantalla completa */
.map-fullscreen-exit-btn {
  display: none;
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  background: rgba(15, 23, 42, 0.90);
  color: #ffffff;
  padding: 8px 20px;
  border-radius: 24px;
  font-size: 13px;
  font-weight: 600;
  border: 1.5px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  align-items: center;
  gap: 8px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  font-family: inherit;
}

.map-fullscreen-exit-btn:hover {
  background: #00255c;
  transform: translateX(-50%) scale(1.05);
  box-shadow: 0 6px 24px rgba(0, 37, 92, 0.55);
}

/* Responsive map */
@media (max-width: 768px) {
  #map {
    height: 420px;
  }

  .popup-data {
    max-width: 280px;
  }
}

@media (max-width: 480px) {
  #map {
    height: 380px;
  }

  .popup-data {
    max-width: calc(100vw - 60px);
    min-width: 190px;
    font-size: 11px;
  }

  .popup-row {
    padding: 3px 0;
    gap: 4px;
  }

  .popup-label {
    min-width: 75px;
    font-size: 11px;
  }

  .popup-value {
    font-size: 11px;
  }

  .leaflet-popup-content {
    margin: 8px 10px !important;
    min-width: 160px;
    max-height: 50vh;
  }
}

/* ===== Suggestions Autocomplete & Draw Mode Buttons ===== */
.suggestions-container {
  position: absolute;
  background: #fff;
  border: 1px solid #ccc;
  border-top: none;
  border-radius: 0 0 6px 6px;
  width: 100%;
  max-height: 220px;
  overflow-y: auto;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.suggestion-item {
  padding: 10px 15px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  font-size: 13px;
  text-align: left;
  transition: background 0.15s ease;
}

.suggestion-item:hover {
  background: #f1f3f5;
}

.suggestion-item strong {
  display: block;
  color: var(--primary);
  font-weight: 600;
}

.suggestion-item small {
  color: var(--text-light);
  font-size: 11px;
}

.draw-mode-btn.active {
  background-color: var(--success) !important;
  color: white !important;
  border-color: var(--success) !important;
  font-weight: 600;
  box-shadow: 0 2px 5px rgba(40, 167, 69, 0.3);
}

.draw-mode-btn:not(.active) {
  background-color: #e9ecef !important;
  color: #495057 !important;
}

.draw-mode-btn:not(.active):hover {
  background-color: #dee2e6 !important;
}

#btn-cancel-draw:hover {
  background-color: #c82333 !important;
}

#btn-finish-draw:hover {
  background-color: #218838 !important;
}

/* Beautiful custom Leaflet popup close button styling */
.leaflet-popup-close-button {
  background-color: #f8f9fa !important;
  color: #555 !important;
  border-radius: 50% !important;
  width: 24px !important;
  height: 24px !important;
  line-height: 24px !important;
  text-align: center !important;
  top: 8px !important;
  right: 8px !important;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15) !important;
  font-size: 14px !important;
  font-weight: bold !important;
  transition: all var(--transition) !important;
  border: 1px solid var(--border-dark) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 !important;
}

.leaflet-popup-close-button:hover {
  background-color: var(--danger) !important;
  color: #fff !important;
  border-color: var(--danger) !important;
  transform: scale(1.05);
}

.leaflet-popup-close-button span {
  position: relative;
  top: -1px;
}

/* Custom Leaflet Geolocation Control Button */
.leaflet-bar a.leaflet-control-locate-btn {
  background-color: #fff;
  color: #1d4ed8;
  font-size: 15px;
  line-height: 30px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.leaflet-bar a.leaflet-control-locate-btn:hover {
  background-color: #eff6ff;
  color: #2563eb;
}

body.night-mode .leaflet-bar a.leaflet-control-locate-btn {
  background-color: #1e293b;
  color: #60a5fa;
  border-color: #334155;
}

/* Radar pulse animation for user device location */
.gps-pulse-marker {
  position: relative;
  width: 24px;
  height: 24px;
}

.gps-pulse-dot {
  position: absolute;
  top: 5px;
  left: 5px;
  width: 14px;
  height: 14px;
  background-color: #2563eb;
  border: 2.5px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.4);
  z-index: 2;
}

.gps-pulse-ring {
  position: absolute;
  top: 0;
  left: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-color: rgba(37, 99, 235, 0.35);
  animation: gpsPulse 2s cubic-bezier(0.215, 0.61, 0.355, 1) infinite;
  z-index: 1;
}

@keyframes gpsPulse {
  0% {
    transform: scale(0.6);
    opacity: 0.9;
  }

  70% {
    transform: scale(2.2);
    opacity: 0;
  }

  100% {
    transform: scale(2.2);
    opacity: 0;
  }
}