/* ============================================================
   LEYENDA (posición + estilo + transparencia + blur)
   (Versión consolidada y con botones corregidos + animaciones)
============================================================ */
#leyenda-incidencias {
  position: absolute;
  bottom: 20px;
  left: 20px;
  width: 180px;                 /* 🔹 Más ancho */
  max-height: 45vh;             /* 🔹 Un poco más alta */
  overflow-y: auto;
  background: rgba(255,255,255,0.92);
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #ccc;
  font-size: 13px;
  line-height: 1.3;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  z-index: 99999;
  backdrop-filter: blur(4px);
  transition: opacity 0.2s ease, max-height 0.25s ease;
  pointer-events: auto;
}

#leyenda-incidencias:hover {
    opacity: 1;
}

.leyenda-titulo {
    font-weight: bold;
    margin-bottom: 6px;
    color: #333;
}

.leyenda-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 4px 0;
}

.leyenda-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 0 2px rgba(0,0,0,0.4);
    margin-right: 8px;
}

/* Colores de la leyenda */
.dot-30m { background: #f44336; }   /* rojo */
.dot-1h  { background: #ff9800; }   /* naranja */
.dot-mas1h { background: #777; }    /* gris */
.dot-inactivas { background: #000; } /* negro */
.dot-total { background: #333; }

/* Texto y contador */
.leyenda-text { flex: 1; color: #333; }
.leyenda-count { font-weight: bold; color: #333; }

.leyenda-separador {
    border-top: 1px solid #ccc;
    margin: 6px 0;
}

/* ============================================================
   BOTÓN REFRESCAR (estilos legacy, mantenidos por compatibilidad)
============================================================ */
#leyenda-incidencias .map-refresh-btn {
    width: 100%;
    margin: 6px 0 10px 0;
    background: #e8680c;
    color: #fff;
    border: none;
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: opacity 0.2s ease, background 0.2s ease;
}

.map-refresh-btn {
    pointer-events: auto !important;
    z-index: 999999 !important;
    opacity: 0.80;
}

.map-refresh-btn:hover {
    opacity: 1;
}

.map-refresh-btn svg {
    width: 18px;
    height: 18px;
    vertical-align: middle;
}

/* ============================================================
   MARCADORES
============================================================ */
.incidencia-marker,
.incidencia-inactiva {
    width: 22px !important;
    height: 22px !important;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 0 3px rgba(0,0,0,0.45);
}

.incidencia-30m { background: #f44336; }   /* rojo */
.incidencia-1h  { background: #ff9800; }   /* naranja */
.incidencia-mas1h { background: #777; }    /* gris */

.incidencia-inactiva {
    background: #000;                      /* negro */
}

/* ============================================================
   FULLSCREEN MAP
============================================================ */
#map-container {
  position: fixed;
  top: 48px;

  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 9999;
  background: #000;
  display: none;
  overflow: hidden;

  /* 🔥 Sin animación vertical */
  transform: none;
  transition: opacity .285s ease; /* solo fade */
}

#map {
    width: 100%;
    height: 100%;
    position: relative;
  opacity: 0;
  transition: opacity .35s ease, transform .35s ease;
  z-index: 1 !important;
}

#map.visible {
  opacity: 1;
  transform: translateY(0);
}


#map-container.open #map {
    opacity: 1;
}



#map-container.open {
    display: block;
    opacity: 1;
}

#map-container.closing {
    opacity: 0;
}

.map-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    
    display: flex;               /* ⬅️ centra contenido */
    flex-direction: column;      /* spinner arriba, texto abajo */
    align-items: center;         /* centra horizontal */
    justify-content: center;     /* centra vertical */
    gap: 10px;                   /* separación elegante */

    padding: 18px 24px;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(4px);  /* efecto premium */
    color: #fff;
    border-radius: 10px;
    font-size: 15px;
    letter-spacing: .3px;
    z-index: 1000000;
    display: none;
}

.map-loading .spinner {
    width: 28px;
    height: 28px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

/* ============================================================
   BOTÓN CERRAR
============================================================ */
.map-close-btn,
#btn-cerrar-mapa {
    position: absolute;
    top: 9px;
    right: 15px;
    z-index: 100000;
    background: white;
    border: 1px solid #ccc;
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 15px;
    opacity: 0.85;
    transition: opacity 0.2s ease;
}

#btn-cerrar-mapa:hover {
    opacity: 1;
}

/* ============================================================
   BOTÓN MI UBICACIÓN
============================================================ */
#btn-ubicacion {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 46px;
    height: 46px;
    background: #fff;
    border-radius: 50%;
    border: 1px solid #ccc;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100000;
    opacity: 0.85;
    transition: opacity 0.2s ease;
    pointer-events: auto;
}

#btn-ubicacion:hover {
    opacity: 1;
}

#btn-ubicacion::before {
    content: "";
    width: 18px;
    height: 18px; 
    border: 3px solid #1a73e8;
    border-radius: 50%;
    background: rgba(26,115,232,0.15);
}

#btn-ubicacion::after {
    content: "";
    width: 6px;
    height: 6px;
    background: #e81a1a;
    border-radius: 50%;
    position: absolute;
}

/* ============================================================
   BOTÓN ABRIR MAPA
============================================================ */
.map-fullscreen-btn {
    display: block;
    margin: 20px auto;
    padding: 12px 22px;
    font-size: 16px;
    font-weight: 600;
    background: rgb(143, 63, 0);
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background .2s ease;
}

.map-fullscreen-btn:hover {
    background: #555;
}






+

/* ============================================================
   MODO COMPACTO (PLEGABLE)
============================================================ */
.leyenda-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.leyenda-toggle {
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    color: #444;
    opacity: 0.7;
    transition: opacity .2s ease, transform .2s ease;
    user-select: none;
}

.leyenda-toggle:hover {
    opacity: 1;
}

#leyenda-incidencias.compacto {
    height: auto;
    max-height: none;
    overflow: hidden;
    padding-bottom: 8px;
}

#leyenda-incidencias.compacto .leyenda-item,
#leyenda-incidencias.compacto .leyenda-separador,
#leyenda-incidencias.compacto .map-refresh-btn {
    display: none;
}

#leyenda-incidencias.compacto .leyenda-toggle {
    transform: rotate(180deg);
    opacity: 1;
}

/* ============================================================
   MODO COMPACTO AUTOMÁTICO EN MÓVIL
============================================================ */
@media (max-width: 480px) {
  #leyenda-incidencias {
    width: 180px;        /* antes 150px */
    bottom: 16px;
    left: 16px;
    padding: 10px;
    font-size: 12px;
    max-height: 35vh;
  }


    #leyenda-incidencias.auto-compacto .leyenda-item,
    #leyenda-incidencias.auto-compacto .leyenda-separador,
    #leyenda-incidencias.auto-compacto .map-refresh-btn {
        display: none;
    }

    #leyenda-incidencias.auto-compacto .leyenda-toggle {
        transform: rotate(180deg);
    }
}

/* ============================================================
   EFECTO BALIZA — naranja intenso y perfectamente centrado
============================================================ */
.baliza-pulso {
    position: relative;
}

.baliza-pulso::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(255, 120, 0, 0.55);
    transform: translate(-50%, -50%) scale(1);
    animation: balizaPulse 1.6s infinite ease-out;
    pointer-events: none;
    z-index: -1;
}

@keyframes balizaPulse {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.55;
    }
    70% {
        transform: translate(-50%, -50%) scale(2.6);
        opacity: 0;
    }
    100% {
        transform: translate(-50%, -50%) scale(2.6);
        opacity: 0;
    }
}

/* ===== Contenedor de botones: fila alineada y estable ===== */
#leyenda-incidencias .modo-marcadores {
  display: flex;
  gap: 8px;
  width: 100%;
}

#leyenda-incidencias .modo-marcadores .modo-btn {
  flex: 1 1 50%;        /* 🔥 Cada botón ocupa el 50% */
  width: 50%;           /* Refuerzo para evitar saltos */
  min-width: 0;         /* Permite que se ajusten */
  height: 32px;
  padding: 6px 8px;
  background: #f0f0f0;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #333;
  transition: background .15s ease, transform .08s ease, box-shadow .12s ease;
  box-sizing: border-box;
}

/* Icono dentro del botón */
#leyenda-incidencias .modo-btn .icon {
  font-size: 16px;
  line-height: 1;
  pointer-events: none;
  display: inline-block;
}

/* Hover ligero */
#leyenda-incidencias .modo-btn:hover {
  transform: translateY(-1px);
}

/* ===== Estado activo (color institucional) ===== */
#leyenda-incidencias button.modo-btn.modo-activo {
  background: rgb(143, 63, 0);
  color: #fff;
  box-shadow: 0 6px 14px rgba(143,63,0,0.18);
}

/* ===== Feedback verde al actualizar (flash) ===== */
#leyenda-incidencias .modo-btn.flash-ok,
#leyenda-incidencias #refresh-map.flash-ok {
  background: #2ecc71 !important;
  color: #fff !important;
  box-shadow: 0 8px 20px rgba(46,204,113,0.18);
  transform: scale(1.04);
}

/* Giro simple del icono (sobre sí mismo) */
#leyenda-incidencias .modo-btn .icon.spin {
  display: inline-block;
  transform-origin: 50% 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* Asegúrate de no aplicar la clase .orbit al botón de refresh */
#leyenda-incidencias .modo-btn.orbit .icon { animation: none !important; }


/* ===== Ajustes responsive (mantener fila en móvil, reducir tamaño) ===== */
@media (max-width: 420px) {
  #leyenda-incidencias .modo-btn {
    min-width: 40px;
    height: 34px;
    padding: 4px 6px;
    font-size: 13px;
  }
  #leyenda-incidencias .modo-marcadores { gap: 6px; }
}

/* Giro controlado: por defecto no hay animación */
#leyenda-incidencias .modo-btn .icon {
  display: inline-block;
  animation: none !important;
  transform-origin: 50% 50%;
}

/* Activar giro solo cuando exista la clase .spin y el botón tenga data-spinning="true" */
#leyenda-incidencias .modo-btn[data-spinning="true"] .icon.spin {
  animation: spin 0.9s linear infinite !important;
}

/* keyframes */
@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}


.leyenda-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.leyenda-check {
    transform: scale(1.1);
    cursor: pointer;
}


.cluster-hidden {
  display: none !important;
}

/* ===== Leaflet.markercluster — estilos base ===== */
.marker-cluster {
  background-clip: padding-box;
  border-radius: 25px;
  background-color: rgba(51, 136, 255, 0.8);
  color: white;
  text-align: center;
  font-weight: bold;
  border: 6px solid rgba(255,255,255,0.8);
}

.marker-cluster span {
  line-height: 40px;
  font-size: 14px;
}

.marker-cluster-small {
  width: 40px;
  height: 40px;
}

.marker-cluster-medium {
  width: 50px;
  height: 50px;
}

.marker-cluster-large {
  width: 60px;
  height: 60px;
}


#btn-ubicacion.location-pulse::after {
    animation: pulse 1.2s ease-out;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: .9; }
    70% { transform: scale(2.4); opacity: 0; }
    100% { transform: scale(2.4); opacity: 0; }
}


#leyenda-incidencias {
    transition: max-height .25s ease, opacity .25s ease;
}

#leyenda-incidencias.expanded {
    max-height: 500px;
    opacity: 1;
}

#leyenda-incidencias.compacto {
    opacity: .85;
}

.leaflet-marker-icon {
    opacity: 0;
    transition: opacity .25s ease;
}

.leaflet-marker-icon.leaflet-zoom-animated {
    opacity: 1;
}

.marker-cluster {
    transform: scale(0.85);
    transition: transform .2s ease;
}

.marker-cluster:hover {
    transform: scale(1);
}


/* ============================
   OPTIMIZACIÓN MÓVIL REAL
============================ */
@media (max-width: 480px) {

    #map-container {
        height: 100dvh;
        padding: 0;
    }

    #btn-ubicacion {
        width: 42px;
        height: 42px;
        bottom: 16px;
        right: 16px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.25);
    }

    #btn-cerrar-mapa {
        top: 58px;
        right: 12px;
        padding: 6px 12px;
        font-size: 14px;
    }

    #leyenda-incidencias {
        width: 150px;
        bottom: 16px;
        left: 16px;
        padding: 10px;
        font-size: 12px;
        max-height: 35vh;
    }

    #leyenda-incidencias .modo-btn {
        min-width: 36px;
        height: 32px;
        padding: 4px 6px;
        font-size: 12px;
    }

    .leyenda-item {
        gap: 4px;
    }

    .leyenda-check {
        transform: scale(1);
    }
}


/* Animación suave al actualizar contadores */
.leyenda-count.animate {
    animation: countFlash .35s ease-out;
}

@keyframes countFlash {
    0%   { transform: scale(1);   color: #333; }
    40%  { transform: scale(1.25); color: rgb(143, 63, 0); }
    100% { transform: scale(1);   color: #333; }
}

/* Animación del item completo */
.leyenda-item.animate {
    animation: itemPulse .35s ease-out;
}

@keyframes itemPulse {
    0%   { background: transparent; }
    40%  { background: rgba(143,63,0,0.12); }
    100% { background: transparent; }
}


.popup-incidencia {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
  line-height: 1.4;
  color: #222;
  max-width: 260px;
}

.popup-incidencia .popup-header {
  border-bottom: 1px solid #ddd;
  padding-bottom: 4px;
  margin-bottom: 6px;
}

.popup-incidencia .popup-title {
  font-size: 16px;
  font-weight: 600;
}

.popup-incidencia.popup-incidencia-inactiva .popup-title {
  color: #000; /* o morado/negro para inactivas */
}

/* Valores en rojo para "Última actualización" e "Inactiva desde" */
/* Campos en rojo */
.popup-value.valor-ultima,
.popup-value.valor-inactiva {
  color: #d32f2f !important;
  font-weight: 600;
}

/* Títulos por tipo */
.popup-title.activa {
  color: #f44336; /* rojo 30m */
}

.popup-title.una-hora {
  color: #ff9800; /* naranja 1h */
}

.popup-title.mas-una-hora {
  color: #555; /* gris */
}

.popup-title.inactiva {
  color: #000; /* negro */
}
.popup-incidencia .popup-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.popup-incidencia .popup-row {
  display: flex;
  justify-content: flex-start;
  gap: 4px;
}

.popup-incidencia .popup-label {
  font-weight: 600;
  color: #555;
  min-width: 88px; /* alinea columnas */
  white-space: nowrap;
}

.popup-incidencia .popup-value {
  flex: 1;
  color: #111;
}


/* ===== Botón cerrar popup (PC) ===== */
.leaflet-popup-close-button {
    width: 26px !important;
    height: 26px !important;
    line-height: 26px !important;

    font-size: 18px !important;
    font-weight: 600 !important;

    top: 6px !important;
    right: 6px !important;

    background: rgba(255,255,255,0.95) !important;
    border: 1px solid #bbb !important;
    border-radius: 6px !important;

    display: flex !important;
    align-items: center !important;
    justify-content: center !important;

    color: #a1a1a1 !important;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);

    cursor: pointer;
    transition: background .2s ease, transform .15s ease, box-shadow .2s ease;
}

.leaflet-popup-close-button:hover {
    background: #fff !important;
    transform: scale(1.08);
    box-shadow: 0 3px 8px rgba(0,0,0,0.25);
}

@media (max-width: 480px) {
    .leaflet-popup-close-button {
        width: 36px !important;
        height: 36px !important;
        line-height: 36px !important;
        font-size: 22px !important;
        top: 4px !important;
        right: 4px !important;
    }
}



#mapa-header {
  margin-bottom: 10px;
  font-size: 13px;
}

.leyenda-actualizacion {
  justify-content: center;
  gap: 6px;
}

#auto-refresh-btn.leyenda-boton {
  min-width: 140px;
  text-align: center;
  cursor: pointer;
}

.leyenda-boton.leyenda-activo {
  background: #007bff;
  color: #fff;
  border-color: #007bff;
}


/* Botón superior: mismo estilo que los de la leyenda */
#mapa-actualizacion .modo-btn {
  position: relative;
  flex: 0 0 auto;
  min-width: 34px;
  height: 28px;
  padding: 6px 8px;
  background: #f0f0f0;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #333;
  transition: background .15s ease, transform .08s ease, box-shadow .12s ease;
  box-sizing: border-box;
}

#mapa-actualizacion .modo-btn:hover {
  transform: translateY(-1px);
}

/* Estado activo (color institucional) */
#mapa-actualizacion .modo-btn.modo-activo {
  background: rgb(143, 63, 0);
  color: #fff;
  box-shadow: 0 6px 14px rgba(143,63,0,0.18);
}

/* Icono dentro del botón */
#mapa-actualizacion .modo-btn .icon {
  font-size: 16px;
  line-height: 1;
  pointer-events: none;
}

/* Flash verde al refrescar */
#mapa-actualizacion .modo-btn.flash-ok {
  background: #2ecc71 !important;
  color: #fff !important;
  box-shadow: 0 8px 20px rgba(46,204,113,0.18);
  transform: scale(1.04);
}

#update-label {
  font-weight: 700;
}

@media (max-width: 480px) {

  #update-fecha {
    display: none !important;
  }



  /* Fila de botones: izquierda y derecha */
  #mapa-actualizacion .buttons-row {
    width: 100%;
    display: flex;
    justify-content: space-between; /* 🔥 Botones a los extremos */
    align-items: center;
  }

  /* Texto centrado debajo */
  #mapa-actualizacion .update-text {
    width: 100%;
    text-align: center;
    font-size: 12px;
    line-height: 1.2;
  }

  /* Ocultar fecha en móvil */
  #update-fecha {
    display: none !important;
  }

    #update-label {
    font-weight: 800;
    font-size: 12px;
  }

}


#mapa-actualizacion,
#leyenda-mapa {
  background: rgba(255, 255, 255, 0.85); /* 🔥 opacidad real */
  backdrop-filter: blur(4px);            /* 🔥 efecto cristal */
  border: 1px solid rgba(0,0,0,0.15);
}


.map-sidebar {
  position: absolute;
  top: 0;
  left: 0;
  width: 300px;
  height: 100%;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(6px);
  border-right: 1px solid #ddd;
  box-shadow: 2px 0 6px rgba(0,0,0,0.15);
  overflow-y: auto;
  z-index: 200000 !important; /* 🔥 MÁS ALTO QUE EL MAPA */
  pointer-events: auto;
}

.sidebar-header {
  padding: 12px;
  border-bottom: 1px solid #ccc;
}

.sidebar-header h3 {
  margin: 0 0 8px 0;
  font-size: 1.1rem;
  font-weight: 600;
}

#search-incidencias {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
}

.sidebar-filters {
  padding: 10px;
  font-size: 0.9rem;
}

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

/* ============================
   SIDEBAR — Tarjetas modernas
============================ */
.sidebar-item {
  background: #ffffff;
  border: 1px solid #e2e2e2;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
  font-size: 14px;
  line-height: 1.35;
  cursor: pointer;
  transition: background .15s ease, transform .12s ease, box-shadow .15s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.sidebar-item:hover {
  background: #f7f7f7;
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(0,0,0,0.12);
}

/* ============================
   INACTIVAS — Estilo apagado
============================ */
.sidebar-item.inactiva {
  background: #f2f2f2;
  border-left: 4px solid #000;
  color: #555;
}

.sidebar-item.inactiva strong {
  color: #222;
}

/* ============================
   Texto pequeño
============================ */
.sidebar-item small {
  color: #777;
  font-size: 12px;
}

/* Sidebar visible y por encima del mapa */
.map-sidebar {
  position: absolute;
  top: 0;
  left: 0;
  width: 300px;
  height: 100%;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(6px);
  border-right: 1px solid #ccc;
box-shadow: 2px 0 6px rgba(0,0,0,0.25); /* sombra lateral */
clip-path: inset(0 -10px -10px 0);      /* recorta la sombra superior */
  overflow-y: auto;
  z-index: 200000 !important; /* 🔥 por encima del mapa */
  pointer-events: auto;
}

/* El mapa debe quedar por debajo del sidebar */
#map {
  z-index: 1 !important;
}


#map-container.open {
    position: fixed !important;
    top: 0;
    left: 0;
}

#map-container {
    position: fixed !important;
}

.sidebar-filters {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-filters label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}

.sidebar-select {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  margin-top: 10px;
  font-size: 14px;
}


@media (max-width: 480px) {
  .map-sidebar {
    width: 100vw;
    height: 100vh;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 300000 !important;
  }

  .map-sidebar.open {
    transform: translateX(0);
  }

  #btn-open-filtros {
    position: absolute;
    top: 15px;
    left: 15px;
    z-index: 120000;
    background: white;
    border: 1px solid #ccc;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    opacity: 0.85;
  }

  #btn-close-filtros {
    position: absolute;
    top: 15px;
    right: 15px;
    z-index: 120000;
    background: white;
    border: 1px solid #ccc;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
  }

  
  .map-btn-alertas {
position: absolute;
    top: 100px;
    left: 10px;
    z-index: 120000;
    background: white;
    border: 1px solid #ccc;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    opacity: 0.85;
  }
}


.sidebar-provincia-header {
    margin: 12px 0 6px;
    font-size: 15px;
    font-weight: 700;
    color: #333;
    border-bottom: 1px solid #ddd;
    padding-bottom: 4px;
}


/* ================================
   SIDEBAR BASE
================================ */
.map-sidebar {
    position: absolute;
    top: 0;
    left: 0;
    width: 320px;
    height: 100%;
    background: #fff;
    border-right: 1px solid #ddd;
    overflow-y: auto;
    padding: 15px;
    z-index: 200000;
    transform: translateX(-100%);
    transition: transform .25s ease;
}

.map-sidebar.open {
    transform: translateX(0);
}

/* ================================
   LISTA DE INCIDENCIAS
================================ */
.sidebar-list {
    margin-top: 15px;
}

.sidebar-provincia-header {
    margin: 18px 0 8px;
    font-size: 15px;
    font-weight: 700;
    color: #333;
    border-bottom: 1px solid #ddd;
    padding-bottom: 4px;
}

.sidebar-item {
    padding: 10px 8px;
    border-radius: 6px;
    background: #f7f7f7;
    margin-bottom: 6px;
    cursor: pointer;
    transition: background .15s;
}

.sidebar-item:hover {
    background: #ececec;
}

.sidebar-item.inactiva {
    opacity: 0.6;
}

/* ================================
   FILTROS
================================ */
.sidebar-filters {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 15px;
}

.sidebar-filters label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
}

/* Select de provincias */
.sidebar-select,
#filtro-provincia {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    margin-top: 10px;
    font-size: 14px;
    background: #fff;
}

/* ================================
   BOTÓN FLOTANTE (abrir filtros)
================================ */
#btn-open-filtros {
    position: absolute;
    top: 15px;
    left: 15px;
    z-index: 120000;
    background: white;
    border: 1px solid #ccc;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
}

/* ================================
   BOTÓN CERRAR (dentro del sidebar)
================================ */
#btn-close-filtros {
    position: absolute;
    top: 15px;
    right: 15px;
    z-index: 300001;
    background: white;
    border: 1px solid #ccc;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
}

/* ================================
   MÓVIL — SIDEBAR A PANTALLA COMPLETA
================================ */
@media (max-width: 480px) {
    .map-sidebar {
        width: 100vw;
        height: 100vh;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        z-index: 300000 !important;
    }

    .map-sidebar.open {
        transform: translateX(0);
    }

    #btn-open-filtros {
        top: 58px;
        left: 12px;
        padding: 8px 12px;
        font-size: 13px;
    }

    #btn-close-filtros {
        top: 12px;
        right: 12px;
        padding: 8px 12px;
        font-size: 13px;
    }
}


.sidebar-reset-btn {
    margin-top: 10px;
    width: 100%;
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid #ccc;
    background: #f5f5f5;
    cursor: pointer;
    font-size: 14px;
}

.sidebar-reset-btn:hover {
    background: #e9e9e9;
}

.leyenda-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.leyenda-toggle {
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  color: #444;
  opacity: 0.7;
  transition: opacity .2s ease, transform .2s ease;
  user-select: none;
}

.leyenda-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.leyenda-titulo {
  font-weight: 600;
  font-size: 13px;
  color: #333;
}

.leyenda-titulo .leyenda-count {
  font-weight: 700;
}

.leyenda-toggle {
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  color: #444;
  opacity: 0.75;
  transition: opacity .2s ease, transform .2s ease;
  user-select: none;
}

.leyenda-toggle:hover {
  opacity: 1;
}


/* ============================
   ESTADO CERRADO EN MÓVIL
   ============================ */
#leyenda-incidencias.auto-compacto .leyenda-item,
#leyenda-incidencias.auto-compacto .leyenda-separador,
#leyenda-incidencias.auto-compacto .leyenda-inactivas,
#leyenda-incidencias.auto-compacto .map-refresh-btn {
    display: none;
}

/* Cabecera SIEMPRE visible */
#leyenda-incidencias.auto-compacto .leyenda-header {
    display: flex !important;
}

/* ============================
   ESTADO CERRADO POR TOGGLE
   ============================ */
#leyenda-incidencias.compacto .leyenda-item,
#leyenda-incidencias.compacto .leyenda-separador,
#leyenda-incidencias.compacto .leyenda-inactivas,
#leyenda-incidencias.compacto .map-refresh-btn {
    display: none;
}

/* Cabecera SIEMPRE visible */
#leyenda-incidencias.compacto .leyenda-header {
    display: flex !important;
}

/* Rotación del toggle */
#leyenda-incidencias.compacto .leyenda-toggle {
    transform: rotate(180deg);
}

/* ============================
   ESTADO ABIERTO (SIN NINGUNA CLASE)
   ============================ */

#leyenda-incidencias:not(.auto-compacto):not(.compacto) .leyenda-separador {
    display: block;
}

#leyenda-incidencias:not(.auto-compacto):not(.compacto) .leyenda-header {
    display: flex;
}

#leyenda-incidencias > .leyenda-header {
    display: flex;
}



/* El bloque completo de inactivas debe ser vertical */
.leyenda-inactivas {
    display: block;
    width: 100%;
}

/* El separador ocupa toda la línea */
.leyenda-inactivas .leyenda-separador {
    display: block;
    width: 100%;
    margin: 6px 0;
}

/* El título de inactivas debe ir arriba, no mezclado */
.leyenda-inactivas .leyenda-header {
    display: block;
    width: 100%;
    margin: 4px 0 2px 0;
}

/* El item debe ir debajo del título */
.leyenda-inactivas .leyenda-item {
    display: flex;
    align-items: center;
    width: 100%;
}

.sb-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sb-icon {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Colores coherentes con la leyenda */
.sb-30m { background: #f44336; }     /* rojo */
.sb-1h { background: #ff9800; }      /* naranja */
.sb-mas1h { background: #777; }      /* gris */
.sb-inactiva { background: #000; }   /* negro */

@media (min-width: 768px) {

  #leyenda-incidencias {
    display: none !important;
  }

  #sidebar {
    transform: translateX(0) !important;
    top: 48px !important;
    height: calc(100vh - 48px) !important;
    border-right: 1px solid #ccc; /* ← borde vertical limpio */
    background: #fff; /* por si acaso */
  }

  #btn-open-filtros,
  #btn-close-filtros {
    display: none !important;
  }
}

.sidebar-modo,
.sidebar-modo-incidencias {
  display: flex;
  gap: 8px;
  margin: 10px 0 15px;
}

.sb-btn,
.sb-btn-inc {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid #ccc;
  background: #f2f2f2;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  text-align: center;
  transition: background 0.2s, border-color 0.2s;
}

.sb-btn:hover {
  background: #e6e6e6;
}

.sb-btn.activo,
.sb-btn-inc.activo {
  background: #dcdcdc;
  border-color: #999;
  font-weight: bold;
}

#sb-count-30m {
  font-weight: bold;
  color: #f44336; /* rojo */
}

#sb-count-1h {
  font-weight: bold;
  color: #ff9800; /* naranja */
}

#sb-count-mas1h {
  font-weight: bold;
  color: #777; /* gris */
}

#sb-count-inactivas {
  font-weight: bold;
  color: #000; /* negro */
}


#topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 48px;
  background: #fff;
  border-bottom: 1px solid #ccc;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 0 16px;
  z-index: 100000;
  font-size: 14px;
  color: #333;
}

.topbar-btn {
  background: #f2f2f2;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
}

.topbar-btn:hover {
  background: #e6e6e6;
}

.topbar-btn.modo-activom {
  background: rgb(143, 63, 0);
  color: #fff;
  border-color: rgb(143, 63, 0);
}



.update-block {
  display: flex;
  align-items: center;
  gap: 6px;
  
  body {
  padding-top: 48px; /* altura del topbar */

  }
}



.icon-desktop {
  display: none;
}

.icon-mobile {
  display: inline;
}


@media (min-width: 768px) {
  .icon-desktop {
    display: inline;
  }

  .icon-mobile {
    display: none;
  }
}


@media (max-width: 767px) {
  #sidebar.open ~ #btn-cerrar-mapa {
    display: none !important;
  }
}

#modo-marcadores {
  margin-bottom: 10px;
}

#leyenda-incidencias.collapsed #modo-marcadores {
  margin-bottom: 0 !important;
}

.sidebar-subtitulo {
  margin: 12px 0 6px;
  font-size: 14px;
  font-weight: 600;
  color: #333;
  
}

/* Ocultar botón cerrar mapa cuando el sidebar está abierto en móvil */
body.sidebar-open #btn-cerrar-mapa {
  display: none !important;
}



/* === MISMO ESTILO ACTIVO QUE LA LEYENDA PARA TODOS LOS BOTONES === */
#btn-agrupado.modo-activo,
#btn-desagrupado.modo-activo,
#sb-agrupado.activo,
#sb-individual.activo,
#sb-ver-activas.activo,
#sb-ver-inactivas.activo,
#auto-refresh-btn.activo {
  background: rgb(143, 63, 0) !important;
  color: #fff !important;
  box-shadow: 0 6px 14px rgba(143,63,0,0.18) !important;
  border: none !important;
}

#logo-v16info.logo-header {
  position: fixed;
  top: 5px;
  left: 16px;
  font-size: 24px;
  font-weight: 700;
  z-index: 9999999; /* 🔥 por encima de TODO */
  pointer-events: none;
  font-family: system-ui, sans-serif;
}

#logo-v16info .logo-v16 {
  color: rgb(143, 63, 0);
}

#logo-v16info .logo-info {
  color: #222;
}

@media (max-width: 480px) {
  #topbar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    padding-right: 10px;
  }

  #topbar .topbar-btn {
    font-size: 13px;
    padding: 4px 8px;
  }
}

@media (max-width: 480px) {
  #topbar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    padding-right: 10px;
  }


  #topbar .topbar-btn {
    font-size: 13px;
    padding: 4px 8px;
  }
}

body.sidebar-open #logo-v16info {
    display: none !important;
}

#sidebar {
  box-shadow: none !important;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

#sidebar.open {
  box-shadow: -4px 0 12px rgba(0,0,0,0.25) !important;
}



#mapa-switcher {
    position: absolute;
    bottom: 65px;
    right: 15px;
    z-index: 300000;
    pointer-events: none; /* importante */
    
}

#mapa-main-btn {
    pointer-events: auto; /* para que sí reciba clicks */
}

#mapa-switcher {
    position: absolute;
    bottom: 90px;
    right: 20px;
    z-index: 300000;
    pointer-events: none; /* importante */
    
}

/* Botón principal */
#mapa-main-btn {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: white;
    border: 1px solid #ccc;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    cursor: pointer;
    transition: transform .25s ease;
    opacity: 0.85;
    box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}

#mapa-main-btn.open {
    transform: rotate(45deg);
}

/* Contenedor radial */
#mapa-radial {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}


/* Botones radiales */
#mapa-radial .mapa-option {
    position: absolute;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: white;
    border: 1px solid #ccc;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    opacity: 0;
    transform: scale(0.5);
    transition: all .35s cubic-bezier(.2,1.4,.4,1);
    pointer-events: auto;
}

/* Arco hacia la izquierda (no se sale de pantalla) */
#mapa-switcher.open #mapa-radial .mapa-option:nth-child(1) {
    transform: translate(-40px, -10px) scale(1);
    opacity: 1;
}
#mapa-switcher.open #mapa-radial .mapa-option:nth-child(2) {
    transform: translate(-70px, -50px) scale(1);
    opacity: 1;
}
#mapa-switcher.open #mapa-radial .mapa-option:nth-child(3) {
    transform: translate(-90px, -90px) scale(1);
    opacity: 1;
}
#mapa-switcher.open #mapa-radial .mapa-option:nth-child(4) {
    transform: translate(-70px, -130px) scale(1);
    opacity: 1;
}
#mapa-switcher.open #mapa-radial .mapa-option:nth-child(5) {
    transform: translate(-40px, -160px) scale(1);
    opacity: 1;
}



/* Activo */
.mapa-option.modo-activo {
    background: rgb(143,63,0);
    color: white;
}

#mapa-radial {
    transform: translateX(-70px);
}

@media (max-width: 480px) {

  #mapa-switcher {
    position: absolute;
    bottom: 65px;
    right: 15px;
    z-index: 300000;
    pointer-events: none; /* importante */
    
}


    #mapa-radial {
        transform: translateX(-70px);
        bottom: 70px
    }


/* Botón principal */
#mapa-main-btn {
    width: 43px;
    height: 43px;
    border-radius: 50%;
    background: white;
    border: 1px solid #ccc;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    cursor: pointer;
    transition: transform .25s ease;
    opacity: 0.85;
    box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}


    #mapa-switcher.open #mapa-radial .mapa-option:nth-child(1) {
        transform: translate(-122px, 0px) scale(1);
    }
    #mapa-switcher.open #mapa-radial .mapa-option:nth-child(2) {
        transform: translate(-90px, -35px) scale(1);
    }
    #mapa-switcher.open #mapa-radial .mapa-option:nth-child(3) {
        transform: translate(-53px, -65px) scale(1);
    }
    #mapa-switcher.open #mapa-radial .mapa-option:nth-child(4) {
        transform: translate(-10px, -85px) scale(1);
    }
    #mapa-switcher.open #mapa-radial .mapa-option:nth-child(5) {
        transform: translate(35px, -100px) scale(1);
    }
}


/* Botón reset: igual estilo que el botón principal */
#btn-reset-view {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: white;
    border: 1px solid #ccc;
    box-shadow: 0 2px 6px rgba(0,0,0,0.25);
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0.85;
    pointer-events: auto; /* imprescindible porque el contenedor tiene pointer-events:none */
    margin-top: 12px; /* separación respecto al botón principal */
}

/* Versión móvil */
@media (max-width: 480px) {
    #btn-reset-view {
        width: 43px;
        height: 43px;
        font-size: 20px;
        margin-top: 10px;
    }
}

.sb-btn-inc {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}

.sb-btn-inc .sb-icono {
  font-weight: bold;
  color: #000;
  font-size: 14px;
  display: inline-block;
  width: 14px;
  text-align: center;
}

.sb-btn {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sb-btn .sb-icono {
  color: white;
  font-size: 15px;
  width: 14px;
  text-align: center;
}

/* Contenedor general */
.sidebar-filter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid #eee;
  font-size: 14px;
}

/* Checkbox */
.sidebar-filter-item input {
  margin-right: 4px;
}

/* Punto de color */
.sf-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

/* Colores EXACTOS de tu leyenda */
.dot-30m { background: #f44336; }     /* rojo */
.dot-1h { background: #ff9800; }      /* naranja */
.dot-mas1h { background: #777; }      /* gris */
.dot-inactivas { background: #000; }  /* negro */

/* Texto */
.sf-text {
  flex: 1;
  color: #333;
}

/* Contador */
.sf-count {
  font-weight: bold;
  opacity: 0.7;
  min-width: 24px;
  text-align: right;
}

/* Ocultamos el checkbox nativo */
.sidebar-filter-item input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid #bbb;
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  transition: all 0.2s ease;
  margin-right: 4px;
}

/* Estado activo */
.sidebar-filter-item input[type="checkbox"]:checked {
  border-color: #007bff;
  background: #007bff;
}

/* Icono de check */
.sidebar-filter-item input[type="checkbox"]:checked::after {
  content: "✔";
  position: absolute;
  top: -1px;
  left: 2px;
  font-size: 14px;
  color: white;
  font-weight: bold;
}

/* Hover suave */
.sidebar-filter-item input[type="checkbox"]:hover {
  border-color: #888;
}

.sb-btn-inc .sb-icono { color: white; }
.sb-btn .sb-icono { color: white; }


/* Iconos por defecto → NEGROS */
.sb-btn-inc .sb-icono,
.sb-btn .sb-icono {
  color: #000;
  font-weight: bold;
  font-size: 15px;
  width: 14px;
  text-align: center;
}

/* Cuando el botón está activo → icono blanco */
.sb-btn-inc.activo .sb-icono,
.sb-btn.activo .sb-icono,
.modo-activo .sb-icono {
  color: #fff;
}

.sidebar-filter-item {
  cursor: pointer;
}

.sidebar-filter-item input {
  cursor: pointer;
}

.leyenda-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.leyenda-toggle {
  transition: transform 0.25s ease;
}

.leyenda-header.abierta .leyenda-toggle {
  transform: rotate(180deg);
}



.map-btn-alertas.modo-activo {
  background: rgb(143,63,0);
  background: rgb(143,63,0);
  color: #FFF !important;
}


/* Fondo semitransparente del popup */
.popup-alertas {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: none;              /* Se muestra como flex al abrir */
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

/* Contenido del popup */
.popup-alertas .popup-content {
  background: #ffffff;
  min-width: 260px;
  max-width: 320px;
  padding: 18px 20px 16px;
  border-radius: 10px;
  box-shadow: 0 4px 18px rgba(0,0,0,0.25);
  font-family: inherit;       /* Usa la misma que el resto de la web */
}

/* Título */
.popup-alertas .popup-content h3 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 600;
  color: #222;
}

/* Label radio */
.popup-alertas .popup-content label {
  display: block;
  font-size: 13px;
  color: #555;
  margin-bottom: 4px;
}

/* Select radio */
.popup-alertas #alert-radius {
  width: 100%;
  padding: 6px 8px;
  font-size: 13px;
  border-radius: 4px;
  border: 1px solid #ccc;
  margin-bottom: 10px;
  box-sizing: border-box;
}

/* Botones dentro del popup */
.popup-alertas .popup-btn,
.popup-alertas .popup-close {
  display: block;
  width: 100%;
  padding: 7px 10px;
  font-size: 13px;
  border-radius: 4px;
  border: 1px solid transparent;
  cursor: pointer;
  box-sizing: border-box;
}

/* Botón activar/desactivar */
.popup-alertas .popup-btn {
  background: rgb(143,63,0);
  border-color:rgb(143,63,0);
  color: #3f3000;
  font-weight: 600;
  color:#FFF;
}

.popup-alertas .popup-btn:hover {
  background: rgb(143,63,0);
}

/* Botón cerrar */
.popup-alertas .popup-close {
  margin-top: 6px;
  background: #f3f3f3;
  border-color: #d0d0d0;
  color: #444;
}

.popup-alertas .popup-close:hover {
  background: #e7e7e7;
}

/* Versión móvil: ajustar un poco */
@media (max-width: 480px) {
  .popup-alertas .popup-content {
    width: 86%;
    max-width: none;
    padding: 16px 14px 14px;
  }

}

/* Mostrar solo en escritorio */
.solo-escritorio {
    display: block;
}

@media (max-width: 768px) {
    .solo-escritorio {
        display: none !important;
    }
}

/* Estilo del bloque de alertas */
#alertas-fijas {
    background: #fff;
    border: 1px solid #ddd;
    padding: 12px;
    margin-bottom: 12px;
    border-radius: 6px;
}

#alertas-fijas h3 {
    margin: 0 0 8px 0;
    font-size: 15px;
    font-weight: 600;
}


.alerta-item {
    padding: 6px 0;
    border-bottom: 1px solid #eee;
    font-size: 14px;
}

.alerta-item:last-child {
    border-bottom: none;
}

.sidebar-alertas {
  background: #fff;
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 15px;
  border: 1px solid #ddd;
}

.sidebar-alertas h3 {
  margin-top: 0;
  margin-bottom: 10px;
  font-size: 16px;
  font-weight: bold;
}

.sidebar-alertas select {
  width: 100%;
  padding: 8px;
  margin: 6px 0 12px 0;
  border-radius: 6px;
  border: 1px solid #ccc;
}

.sidebar-alert-btn {
  width: 100%;
  padding: 10px;
  background: rgb(143,63,0);
  border: none;
  border-radius: 6px;
  font-weight: bold;
  cursor: pointer;
  color: #FFF;
  margin-bottom: 8px;
}

.sidebar-alert-btn:hover {
  background: rgb(143,63,0);
}

.sidebar-alert-close:hover {
  background: #ccc;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

