/* ==========================================================================
   Vigía - Estilos Personalizados y Animaciones para Leaflet
   ========================================================================== */

html, body {
  width: 100% !important;
  height: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
  background: #f8fafc !important;
}

#map {
  width: 100% !important;
  height: 100% !important;
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  background: #f8fafc !important;
  z-index: 1 !important;
}

header {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

/* Modal flotante de alerta SOS ergonómico para móviles */
#alertBanner {
  position: fixed !important;
  top: 12px !important;
  left: 12px !important;
  right: 12px !important;
  z-index: 99999 !important;
  max-width: 460px !important;
  margin: 0 auto !important;
}

#alertBannerContent {
  display: flex !important;
  flex-direction: column !important;
  box-sizing: border-box !important;
  width: 100% !important;
}

#alertDismissBtn {
  min-width: 38px !important;
  min-height: 38px !important;
  cursor: pointer !important;
}

/* Animación de onda de choque para estado SOS */
@keyframes sos-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.8), 0 0 15px rgba(239, 68, 68, 0.6);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 18px rgba(239, 68, 68, 0), 0 0 25px rgba(239, 68, 68, 0.8);
    transform: scale(1.08);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0), 0 0 15px rgba(239, 68, 68, 0);
    transform: scale(1);
  }
}

@keyframes sos-ring {
  0% {
    transform: scale(0.9);
    opacity: 1;
  }
  100% {
    transform: scale(2.2);
    opacity: 0;
  }
}

@keyframes banner-shake {
  0%, 100% { transform: translateY(0); }
  20%, 60% { transform: translateY(-3px); }
  40%, 80% { transform: translateY(3px); }
}

.animate-banner-shake {
  animation: banner-shake 0.5s ease-in-out;
}

.custom-leaflet-marker {
  overflow: visible !important;
  background: transparent !important;
  border: none !important;
  transition: transform 0.6s cubic-bezier(0.25, 0.1, 0.25, 1);
  will-change: transform;
}

.leaflet-zoom-anim .custom-leaflet-marker {
  transition: none !important;
}

/* Marcador personalizado de dispositivo */
.device-marker-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  overflow: visible !important;
}

.device-marker-pin {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.5);
  border-width: 3.5px;
  border-style: solid;
  transition: all 0.3s ease;
  position: relative;
  z-index: 3;
  cursor: pointer;
  overflow: hidden;
  user-select: none;
}

/* Borde según batería */
.battery-high {
  border-color: #10b981; /* Verde esmeralda >50% */
  color: #065f46;
}

.battery-mid {
  border-color: #f59e0b; /* Ámbar/Amarillo >15% y <=50% */
  color: #92400e;
}

.battery-low {
  border-color: #ef4444; /* Rojo <=15% */
  color: #991b1b;
}

/* Estado de alerta SOS en marcador */
.device-marker-sos .device-marker-pin {
  border-color: #dc2626 !important;
  background: #fef2f2 !important;
  color: #b91c1c !important;
  animation: sos-pulse 1.2s infinite ease-out;
}

.device-marker-sos::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background-color: rgba(239, 68, 68, 0.4);
  animation: sos-ring 1.5s infinite cubic-bezier(0.215, 0.61, 0.355, 1);
  z-index: 1;
}

/* Mini píldora redondeada con relieve 3D sobre la cabeza del pin */
.battery-badge {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
  color: #ffffff;
  font-size: 10px;
  font-weight: 800;
  padding: 1.5px 7px;
  border-radius: 9999px;
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.4);
  z-index: 5;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.battery-badge.badge-high {
  background: linear-gradient(180deg, #10b981 0%, #047857 100%);
  border-color: #6ee7b7;
  box-shadow: 0 3px 8px rgba(16, 185, 129, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.battery-badge.badge-mid {
  background: linear-gradient(180deg, #f59e0b 0%, #b45309 100%);
  border-color: #fde68a;
  box-shadow: 0 3px 8px rgba(245, 158, 11, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.battery-badge.badge-low {
  background: linear-gradient(180deg, #ef4444 0%, #b91c1c 100%);
  border-color: #fca5a5;
  box-shadow: 0 3px 8px rgba(239, 68, 68, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.battery-badge.badge-charging {
  background: linear-gradient(180deg, #f59e0b 0%, #d97706 100%);
  border-color: #fef08a;
  box-shadow: 0 3px 10px rgba(251, 191, 36, 0.75), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  color: #ffffff;
}

/* Nombre del menor flotante bajo el pin */
.device-marker-name {
  position: absolute;
  bottom: -15px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: #f8fafc;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 9999px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
  z-index: 4;
  pointer-events: none;
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Marcadores de inicio y fin de ruta */
.route-start-marker {
  width: 16px;
  height: 16px;
  background: #10b981;
  border: 3px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.route-end-marker {
  width: 16px;
  height: 16px;
  background: #3b82f6;
  border: 3px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* Personalización de Tooltips y Popups de Leaflet */
.leaflet-popup-content-wrapper {
  border-radius: 12px;
  padding: 0;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.2), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.leaflet-popup-content {
  margin: 0;
  line-height: 1.4;
}

.leaflet-tooltip {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 8px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  border: 1px solid #e2e8f0;
}

/* Barra de desplazamiento estética */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: #f1f5f9;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Modales garantizados por encima del mapa Leaflet (Leaflet popups usan z-index 700-1000) */
#qrModal, #audioModal, #legalGatekeeperModal, #renameModal, #deleteModal, #geofencesModal, #geofenceEditModal, #usersModal, #newFamilyModal, #changePasswordModal, #familyManagerModal {
  z-index: 10000 !important;
}

#openFamilyManagerBtn, #familySelectorContainer {
  flex-shrink: 0 !important;
  min-width: max-content !important;
}

.no-scrollbar::-webkit-scrollbar {
  display: none;
}
.no-scrollbar {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

/* ==========================================================================
   OPTIMIZACIONES ESPECÍFICAS PARA MÓVILES (VIGÍA PADRES)
   ========================================================================== */

/* Bloqueo global de desbordamiento horizontal */
html, body {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  box-sizing: border-box;
}

*, *::before, *::after {
  box-sizing: border-box;
}

@media (max-width: 768px) {
  /* Altura y anchura fija exacta en navegadores y WebViews móviles */
  html, body {
    width: 100% !important;
    max-width: 100vw !important;
    height: 100% !important;
    height: 100dvh !important;
    overflow: hidden !important;
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
  }

  header {
    width: 100% !important;
    max-width: 100vw !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }

  /* Cabecera móvil (< 640px) ultra-limpia y sin solapamientos */
  @media (max-width: 639px) {
    #headerUserBtn {
      display: none !important;
    }
    #headerFamilySubBadge {
      display: none !important;
    }
    #connectionText {
      display: none !important;
    }
    .header-logo-text {
      display: none !important;
    }
    #openFamilyManagerBtn {
      max-width: 170px !important;
    }
    #headerFamilyName {
      max-width: 100px !important;
      display: inline-block !important;
      overflow: hidden !important;
      text-overflow: ellipsis !important;
      white-space: nowrap !important;
    }
  }

  /* Mapa en pantalla completa: sin padding inferior (la barra de navegación está oculta) */
  main {
    width: 100% !important;
    max-width: 100vw !important;
    overflow: hidden !important;
    padding-bottom: 0 !important;
    margin-bottom: 0 !important;
    box-sizing: border-box !important;
  }

  #mobileBottomNav {
    width: 100% !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }

  /* Controles de Leaflet pegados al fondo real del mapa */
  .leaflet-bottom {
    bottom: 4px !important;
    max-width: 100vw !important;
    overflow: hidden !important;
  }

  .leaflet-control-zoom {
    margin-bottom: 66px !important;
  }

  .leaflet-control-zoom a {
    width: 38px !important;
    height: 38px !important;
    line-height: 38px !important;
    font-size: 20px !important;
    border-radius: 12px !important;
  }

  .leaflet-control-attribution {
    font-size: 8px !important;
    background: rgba(15, 23, 42, 0.75) !important;
    color: #94a3b8 !important;
    padding: 2px 6px !important;
    border-top-left-radius: 6px !important;
    max-width: calc(100vw - 80px) !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  /* Popups de Leaflet optimizados para tocar con el dedo */
  .leaflet-popup-content-wrapper {
    border-radius: 16px !important;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45) !important;
    max-width: calc(100vw - 2rem) !important;
  }

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

  /* Modales móviles ajustados exactamente a la pantalla con scroll interno */
  #qrModal > div,
  #geofencesModal > div,
  #geofenceEditModal > div,
  #audioModal > div,
  #usersModal > div,
  #renameModal > div,
  #deleteModal > div,
  #newFamilyModal > div,
  #changePasswordModal > div,
  #familyManagerModal > div {
    width: calc(100vw - 1rem) !important;
    max-width: calc(100vw - 1rem) !important;
    max-height: 88vh !important;
    margin: auto !important;
    padding: 1rem !important;
    border-radius: 1.25rem !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
  }

  /* Evitar desbordamiento en inputs móviles */
  #qrModal input, #geofencesModal input, #geofenceEditModal input,
  #usersModal input, #newFamilyModal input, #changePasswordModal input,
  #familyManagerModal input {
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  /* Banners flotantes compactos para pantalla móvil */
  #geofenceAlertBanner {
    top: 8px !important;
    width: calc(100vw - 1rem) !important;
    max-width: calc(100vw - 1rem) !important;
    border-radius: 16px !important;
    padding: 10px 12px !important;
    box-sizing: border-box !important;
  }

  #activeRouteBadge {
    top: 56px !important;
    right: 8px !important;
    font-size: 11px !important;
    padding: 6px 10px !important;
    max-width: calc(100vw - 1rem) !important;
    box-sizing: border-box !important;
    z-index: 995 !important;
  }

  /* Bottom sheet ergonómico en móvil: situado abajo, nunca tapa el selector de mapas ni los controles superiores */
  #tripsControlPanel {
    top: auto !important;
    bottom: 66px !important;
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
    width: calc(100vw - 1rem) !important;
    max-width: 440px !important;
    font-size: 11px !important;
    padding: 8px 12px 12px 12px !important;
    border-radius: 20px !important;
    box-sizing: border-box !important;
    box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.75), 0 0 0 1px rgba(59, 130, 246, 0.4) !important;
    z-index: 1000 !important;
  }

  #tripsMobilePill {
    bottom: 66px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    z-index: 1000 !important;
  }

  /* Banners de acción flotantes en móvil: elevados por encima de la barra inferior */
  #geofencePickerBanner,
  #geofenceDrawBanner,
  #routeWizardBanner,
  #routePickerBanner,
  #refugePickerBanner {
    bottom: 68px !important;
    top: auto !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    width: calc(100vw - 1rem) !important;
    max-width: 480px !important;
    box-sizing: border-box !important;
    border-radius: 20px !important;
    z-index: 1001 !important;
  }

  #routeWizardBanner,
  #geofenceDrawBanner {
    flex-direction: column !important;
    align-items: stretch !important;
  }
}

/* Efecto háptico visual en barra inferior */
#mobileBottomNav button:active {
  transform: scale(0.92);
}

/* ==========================================================================
   Menú Lateral Desplegable (Drawer) - Estilos con alta prioridad
   ========================================================================== */
#sidebarDrawer {
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1) !important;
  will-change: transform;
}

#sidebarDrawer.drawer-open {
  transform: translateX(0) !important;
}

#sidebarDrawer.drawer-closed {
  transform: translateX(-100%) !important;
}

#sidebarDrawerBackdrop {
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1) !important;
  will-change: opacity;
}

#sidebarDrawerBackdrop.backdrop-open {
  opacity: 1 !important;
  pointer-events: auto !important;
  display: block !important;
}

#sidebarDrawerBackdrop.backdrop-closed {
  opacity: 0 !important;
  pointer-events: none !important;
}

/* ==========================================================================
   DISEÑO MODERNO DE MAPA Y CONTROLES GLASSMORPHISM (ESTILO APPLE / LIFE360)
   ========================================================================== */

/* Controles Leaflet con diseño Glassmorphism y bordes ultra redondeados */
.leaflet-bar {
  border: none !important;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.45), 0 8px 10px -6px rgba(0, 0, 0, 0.3) !important;
  border-radius: 16px !important;
  overflow: hidden;
  backdrop-filter: blur(12px) !important;
  -webkit-backdrop-filter: blur(12px) !important;
  background: rgba(15, 23, 42, 0.88) !important;
  border: 1px solid rgba(148, 163, 184, 0.2) !important;
}

.leaflet-bar a {
  background: transparent !important;
  color: #f1f5f9 !important;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15) !important;
  width: 36px !important;
  height: 36px !important;
  line-height: 36px !important;
  font-size: 17px !important;
  font-weight: 700 !important;
  transition: all 0.2s ease !important;
}

.leaflet-bar a:hover {
  background: rgba(59, 130, 246, 0.35) !important;
  color: #60a5fa !important;
}

.leaflet-bar a:last-child {
  border-bottom: none !important;
}

/* Popups de Leaflet con diseño Glassmorphism y bordes redondeados */
.leaflet-popup-content-wrapper {
  background: rgba(15, 23, 42, 0.95) !important;
  color: #ffffff !important;
  border-radius: 20px !important;
  border: 1px solid rgba(59, 130, 246, 0.4) !important;
  box-shadow: 0 20px 35px -5px rgba(0, 0, 0, 0.6) !important;
  backdrop-filter: blur(16px) !important;
  -webkit-backdrop-filter: blur(16px) !important;
  padding: 0 !important;
  overflow: hidden;
}

.leaflet-popup-content {
  margin: 0 !important;
  line-height: 1.4 !important;
}

.leaflet-popup-tip {
  background: rgba(15, 23, 42, 0.95) !important;
  border: 1px solid rgba(59, 130, 246, 0.4) !important;
}

/* Radar pulsante continuo en tiempo real para marcadores de menores */
.device-radar-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(59, 130, 246, 0.45) 0%, rgba(59, 130, 246, 0.15) 55%, transparent 100%);
  border: 2px solid rgba(59, 130, 246, 0.95);
  box-shadow: 0 0 16px rgba(59, 130, 246, 0.75), inset 0 0 8px rgba(59, 130, 246, 0.35);
  pointer-events: none;
  z-index: 1;
  transform: translate(-50%, -50%) scale(1.02);
  animation: radar-pulse-wave 2.6s infinite cubic-bezier(0.1, 0.65, 0.3, 1);
  will-change: transform, opacity;
}

.device-radar-ring.ring-2 {
  animation-delay: 1.3s;
}

.device-radar-ring.radar-charging {
  background: radial-gradient(circle, rgba(245, 158, 11, 0.5) 0%, rgba(245, 158, 11, 0.18) 55%, transparent 100%);
  border-color: rgba(251, 191, 36, 0.95);
  box-shadow: 0 0 18px rgba(251, 191, 36, 0.8), inset 0 0 8px rgba(245, 158, 11, 0.4);
}

.device-marker-sos .device-radar-ring {
  border-color: rgba(239, 68, 68, 0.95) !important;
  background: radial-gradient(circle, rgba(239, 68, 68, 0.55) 0%, rgba(239, 68, 68, 0.2) 55%, transparent 100%) !important;
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.85) !important;
  animation-duration: 1.3s !important;
}

@keyframes radar-pulse-wave {
  0% {
    transform: translate(-50%, -50%) scale(1.02);
    opacity: 0.95;
  }
  60% {
    transform: translate(-50%, -50%) scale(2.3);
    opacity: 0.42;
  }
  100% {
    transform: translate(-50%, -50%) scale(3.3);
    opacity: 0;
  }
}

/* Efecto de brillo / resplandor en trazado de rutas */
.leaflet-interactive.route-glow-underlay {
  filter: drop-shadow(0 0 6px currentColor);
}

/* Modo Noche para capas de mapa: inversión de contraste elegante sin marcas de agua */
.map-tiles-dark {
  filter: invert(100%) hue-rotate(180deg) brightness(95%) contrast(92%);
}

/* Modo Callejero nítido y suave */
.map-tiles-street {
  filter: contrast(1.02) saturate(1.05);
}

/* ==========================================================================
   Trazado de Ruta 3D Tubular Hiperrealista (Efecto Tubería / Hyperloop)
   ========================================================================== */

/* 1. Sombra de contacto al suelo (efecto de suspensión en el aire) */
path.route-3d-shadow {
  filter: blur(4px) drop-shadow(2px 8px 6px rgba(2, 6, 23, 0.85)) !important;
  opacity: 0.65 !important;
}

/* 2. Halo ambiental difuso de iluminación */
path.route-3d-glow {
  filter: blur(3px) !important;
  opacity: 0.35 !important;
}

/* 3. Carcasa/borde perimetral oscuro (define el contorno exterior del tubo cilíndrico) */
path.route-3d-casing {
  stroke-linecap: round !important;
  stroke-linejoin: round !important;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6)) !important;
}

/* 4. Base sombreada en penumbra (la mitad inferior del cilindro en sombra) */
path.route-3d-base {
  stroke-linecap: round !important;
  stroke-linejoin: round !important;
}

/* 5. Cuerpo tubular principal de la ruta */
path.route-3d-body {
  stroke-linecap: round !important;
  stroke-linejoin: round !important;
  cursor: pointer !important;
  transition: stroke-width 0.2s ease, filter 0.2s ease;
}
path.route-3d-body:hover {
  stroke-width: 11px !important;
  filter: brightness(1.2) drop-shadow(0 0 4px rgba(255, 255, 255, 0.4)) !important;
}

/* 6. Cúpula luminosa superior (iluminación cenital del cilindro) */
path.route-3d-light {
  pointer-events: none !important;
  stroke-linecap: round !important;
  stroke-linejoin: round !important;
}

/* 7. Arista de brillo especular blanco (el destello de luz sobre la cresta del tubo) */
path.route-3d-highlight {
  pointer-events: none !important;
  stroke-linecap: round !important;
  stroke-linejoin: round !important;
  filter: drop-shadow(0 0 1px rgba(255, 255, 255, 0.95)) !important;
}

/* 8. Anillos de junta / Abrazaderas metálicas de acople tubular cada 34px */
path.route-3d-rings {
  pointer-events: none !important;
  stroke-linecap: butt !important;
  stroke-linejoin: round !important;
  filter: drop-shadow(0 0 1.5px rgba(2, 6, 23, 0.95)) !important;
}

/* 9. Flujo de líquido/energía animado por el interior del tubo */
@keyframes pipe-fluid-flow {
  from {
    stroke-dashoffset: 0;
  }
  to {
    stroke-dashoffset: -34;
  }
}

path.route-3d-flow {
  pointer-events: none !important;
  animation: pipe-fluid-flow 1.1s linear infinite !important;
  stroke: #ffffff !important;
  stroke-linecap: round !important;
  filter: drop-shadow(0 0 2px #ffffff) drop-shadow(0 0 5px #38bdf8) drop-shadow(0 0 10px rgba(56, 189, 248, 0.75)) !important;
}

/* Resplandor pulsante para rutas activas en tiempo real */
@keyframes route-active-pulse {
  0%, 100% {
    filter: drop-shadow(0 0 6px currentColor);
    opacity: 0.35;
  }
  50% {
    filter: drop-shadow(0 0 14px currentColor);
    opacity: 0.75;
  }
}

path.route-3d-active-glow {
  animation: route-active-pulse 2s infinite ease-in-out !important;
}

/* ==========================================================================
   Marcadores 3D: Paradas / Reposo y Extremos (Salida y Llegada)
   ========================================================================== */

/* Marcador de Parada / Detención */
.route-stop-marker {
  overflow: visible !important;
  pointer-events: auto !important;
}

.route-stop-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: #0f172a;
  font-weight: 800;
  font-size: 10px;
  padding: 2.5px 7.5px;
  border-radius: 9999px;
  border: 1.5px solid #ffffff;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.45), 0 0 0 1.5px rgba(245, 158, 11, 0.5);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  transform: translate(-50%, -50%);
  user-select: none;
}

.route-stop-pill:hover {
  transform: translate(-50%, -50%) scale(1.15);
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.55), 0 0 0 2.5px rgba(251, 191, 36, 0.6);
  z-index: 1000 !important;
}

.route-stop-pill.stop-major {
  background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%);
  color: #ffffff;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.45), 0 0 0 1.5px rgba(239, 68, 68, 0.5);
}
.route-stop-pill.stop-major:hover {
  background: linear-gradient(135deg, #f87171 0%, #dc2626 100%);
}

.route-stop-pill.stop-stay {
  background: linear-gradient(135deg, #6366f1 0%, #4338ca 100%);
  color: #ffffff;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.45), 0 0 0 1.5px rgba(99, 102, 241, 0.5);
}
.route-stop-pill.stop-stay:hover {
  background: linear-gradient(135deg, #818cf8 0%, #4f46e5 100%);
}

/* Marcadores 3D de Extremos de Ruta (Salida y Llegada) */
.route-endpoint-marker {
  overflow: visible !important;
}

.route-endpoint-pin {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffffff 0%, var(--endpoint-color, #2563eb) 60%, #020617 100%);
  border: 2.5px solid #ffffff;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.7), 0 0 0 2px rgba(15, 23, 42, 0.6), inset 0 2px 4px rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translate(-50%, -50%);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  cursor: pointer;
}

.route-endpoint-pin:hover {
  transform: translate(-50%, -50%) scale(1.28);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.8), 0 0 0 3px #ffffff;
}

.route-endpoint-inner {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: #ffffff;
  box-shadow: 0 0 6px #ffffff;
}

.route-endpoint-start {
  --endpoint-color: #10b981 !important;
}

/* ==========================================================================
   Marcador de Autobús con el Menor Asomado en la Ventanilla
   ========================================================================== */
.device-bus-marker-container {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 68px;
  height: 58px;
  overflow: visible !important;
  cursor: pointer;
}

.bus-badge-top {
  top: -14px !important;
  font-size: 9px !important;
  padding: 1px 7px !important;
  background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%) !important;
  border: 1.5px solid #fbbf24 !important;
  color: #fbbf24 !important;
  font-weight: 800 !important;
  letter-spacing: 0.03em;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4) !important;
}

.bus-vehicle-card {
  position: relative;
  width: 58px;
  height: 38px;
  background: linear-gradient(180deg, #f59e0b 0%, #d97706 70%, #b45309 100%);
  border-radius: 9px 12px 6px 6px;
  border: 2px solid #ffffff;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.5), 0 0 0 1.5px rgba(245, 158, 11, 0.6);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 2px 3px;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 4;
}

.device-bus-marker-container:hover .bus-vehicle-card {
  transform: scale(1.15);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.6), 0 0 0 2.5px rgba(251, 191, 36, 0.8);
}

/* Techo del autobús */
.bus-roof-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 7px;
  padding: 0 4px;
}

.bus-roof-sign {
  font-size: 7px;
  font-weight: 900;
  color: #0f172a;
  letter-spacing: 1px;
  line-height: 1;
}

.bus-flasher {
  width: 3.5px;
  height: 3.5px;
  border-radius: 50%;
  background-color: #ef4444;
  box-shadow: 0 0 4px #ef4444;
}

/* Fila de ventanillas */
.bus-windows-row {
  display: flex;
  gap: 3px;
  height: 20px;
  background: rgba(15, 23, 42, 0.88);
  border-radius: 5px;
  padding: 1px 2px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  position: relative;
  overflow: visible;
}

/* Ventanilla del menor */
.bus-window-child {
  flex: 1.2;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}

.bus-child-passenger {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid #3b82f6;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: -2px;
  left: 50%;
  transform: translateX(-50%);
  overflow: hidden;
  z-index: 5;
  animation: child-peek 3s infinite ease-in-out;
}

@keyframes child-peek {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-1.5px); }
}

.bus-window-front {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(59, 130, 246, 0.35);
  border-radius: 3px;
}

.bus-driver-wheel {
  font-size: 9px;
  opacity: 0.8;
}

/* Chasis inferior */
.bus-lower-chassis {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 5px;
  padding: 0 2px;
}

.bus-headlight {
  width: 4px;
  height: 3px;
  background: #fef08a;
  border-radius: 1px;
  box-shadow: 0 0 4px #fef08a;
}

.bus-stripe {
  height: 2px;
  flex: 1;
  margin: 0 3px;
  background: #0f172a;
  border-radius: 1px;
  opacity: 0.65;
}

/* Ruedas */
.bus-wheels-container {
  position: absolute;
  bottom: -4px;
  left: 6px;
  right: 6px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.bus-wheel {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #0f172a;
  border: 2px solid #94a3b8;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.bus-marker-name {
  margin-top: 8px !important;
  font-weight: 800 !important;
  background: rgba(15, 23, 42, 0.95) !important;
  border: 1px solid rgba(245, 158, 11, 0.6) !important;
  color: #fbbf24 !important;
}

/* ==========================================================================
   Marcador de Coche Familiar 3D con Menor Asomado en la Ventanilla
   ========================================================================== */

.car-badge-top {
  top: -14px !important;
  font-size: 10px !important;
  padding: 1px 7px !important;
  background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%) !important;
  border: 1.5px solid #38bdf8 !important;
  color: #38bdf8 !important;
  font-weight: 800 !important;
  letter-spacing: 0.03em;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4) !important;
}

.car-vehicle-card {
  position: relative;
  width: 58px;
  height: 38px;
  background: linear-gradient(180deg, #2563eb 0%, #1d4ed8 70%, #1e40af 100%);
  border-radius: 12px 14px 6px 6px;
  border: 2px solid #ffffff;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.5), 0 0 0 1.5px rgba(59, 130, 246, 0.6);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 2px 3px;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 4;
}

.device-car-marker-container:hover .car-vehicle-card {
  transform: scale(1.15);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.6), 0 0 0 2.5px rgba(56, 189, 248, 0.8);
}

.car-roof-curve {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 6px;
  padding: 0 6px;
}

.car-sunroof {
  width: 22px;
  height: 3px;
  background: rgba(15, 23, 42, 0.6);
  border-radius: 2px;
}

.car-windows-row {
  display: flex;
  gap: 3px;
  height: 20px;
  background: rgba(15, 23, 42, 0.88);
  border-radius: 5px;
  padding: 1px 2px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  position: relative;
  overflow: visible;
}

.car-window-child {
  flex: 1.2;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}

.car-child-passenger {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid #38bdf8;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: -2px;
  left: 50%;
  transform: translateX(-50%);
  overflow: hidden;
  z-index: 5;
  animation: child-peek 3s infinite ease-in-out;
}

.car-window-front {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(56, 189, 248, 0.35);
  border-radius: 3px;
}

.car-driver-wheel {
  font-size: 9px;
  opacity: 0.85;
}

.car-lower-chassis {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 5px;
  padding: 0 2px;
}

.car-headlight {
  width: 4px;
  height: 3px;
  background: #fef08a;
  border-radius: 1px;
  box-shadow: 0 0 5px #fef08a;
}

.car-grille {
  height: 2px;
  flex: 1;
  margin: 0 4px;
  background: #0f172a;
  border-radius: 1px;
  opacity: 0.75;
}

.car-wheels-container {
  position: absolute;
  bottom: -4px;
  left: 6px;
  right: 6px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.car-wheel {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #0f172a;
  border: 2px solid #94a3b8;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.car-marker-name {
  margin-top: 8px !important;
  font-weight: 800 !important;
  background: rgba(15, 23, 42, 0.95) !important;
  border: 1px solid rgba(56, 189, 248, 0.6) !important;
  color: #38bdf8 !important;
}

/* ============================================================
   SELECTOR DE MAPA - Botón redondo flotante (estilo Google Maps)
   ============================================================ */

/* Ocultar botones +/- de zoom de Leaflet en móvil (se usa pinch-to-zoom)
   y moverlos a la derecha en desktop para no solapar con el botón de capas */
.leaflet-top.leaflet-left .leaflet-control-zoom {
  display: none !important;   /* oculto en móvil por defecto */
}
@media (min-width: 768px) {
  .leaflet-top.leaflet-left .leaflet-control-zoom {
    display: block !important;
  }
}
/* En desktop los ponemos a la derecha del mapa para no solapar */
@media (min-width: 768px) {
  .leaflet-top.leaflet-left {
    left: auto !important;
    right: 12px !important;
  }
}

#mapLayerToggleBtn {
  transition: box-shadow 0.2s, transform 0.15s;
}
#mapLayerToggleBtn:active {
  transform: scale(0.93);
}
#mapLayerPanel {
  animation: fadeInDown 0.15s ease-out;
}
@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
#mapLayerPanel .map-style-btn {
  transition: background 0.12s;
}
#mapLayerPanel #tileBtn3D {
  color: #334155;
}
#mapLayerPanel #tileBtn3D.bg-purple-600,
#mapLayerPanel #tileBtn3D[class*="bg-purple-600"] {
  background: #f5f3ff !important;
  color: #6b21a8 !important;
}

/* ============================================================
   BOTTOM SHEET DE MENORES
   ============================================================ */
#devicesBottomSheet {
  will-change: transform;
}
#devicesBottomSheet.sheet-open {
  transform: translateY(0) !important;
}

/* ============================================================
   BARRA INFERIOR - OCULTA POR DEFECTO, visible con .nav-visible
   ============================================================ */
#mobileBottomNav {
  will-change: transform;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}
#mobileBottomNav.nav-visible {
  transform: translateY(0) !important;
}

/* Controles Leaflet: sin margen inferior (barra está oculta) */
.leaflet-bottom {
  bottom: 4px !important;
}
/* Si la barra está visible, ajustar */
body.nav-open .leaflet-bottom {
  bottom: 68px !important;
}

/* Zona de swipe invisible en el borde inferior */
#swipeZone {
  height: 32px;
  z-index: 39;
}

