:root {
    --bg: #0b1220;
    --card: rgba(255, 255, 255, .08);
    --card2: rgba(255, 255, 255, .12);
    --stroke: rgba(255, 255, 255, .14);
    --text: rgba(255, 255, 255, .92);
    --muted: rgba(255, 255, 255, .72);
    --accent: #4f8cff;
    --accent2: #22c55e;
    --danger: #ef4444;
    --shadow: 0 10px 30px rgba(0, 0, 0, .25);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    background: radial-gradient(1200px 600px at 20% -10%, rgba(79, 140, 255, .25), transparent 55%),
        radial-gradient(900px 500px at 80% 0%, rgba(34, 197, 94, .18), transparent 55%),
        var(--bg);
    color: var(--text);
}

/* ============================================================
   HEADER
   ============================================================ */
.header {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 15px 20px;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
    background: rgba(11, 18, 32, .7);
    color: white;
    border-bottom: 1px solid var(--stroke);
    box-shadow: var(--shadow);
}

.header h2 {
    margin: 0;
    font-size: 1.8em;
    font-weight: 600;
    letter-spacing: .2px;
}

.header p {
    margin: 0;
    font-size: 0.9em;
    opacity: .8;
    font-style: italic;
}

.logo {
    height: 60px;
}

.title-group {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

/* ============================================================
   CONTROLES
   ============================================================ */
.controles select option {
    color: #000;
    background: #fff;
}

.controles {
    display: grid !important;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 18px;
    margin: 14px 16px 10px;
    padding: 14px 14px;
    align-items: start;
    flex-wrap: wrap;
    border: 1px solid var(--stroke);
    border-radius: 16px;
    background: linear-gradient(180deg, var(--card2), var(--card));
    box-shadow: var(--shadow);
}

.controles h3 {
    margin: 0 0 5px 0;
    color: var(--text);
    font-size: 1.1em;
    font-weight: 650;
}

.controles strong {
    display: block;
    margin-bottom: 5px;
    font-size: 0.9em;
    color: var(--muted);
    font-weight: 600;
}

.controles select,
.controles input[type="file"],
.controles input[type="text"] {
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, .16);
    background: rgba(255, 255, 255, .08);
    color: var(--text);
    font-size: 0.9em;
    min-width: 220px;
    outline: none;
}

.controles select:focus,
.controles input[type="text"]:focus {
    border-color: rgba(79, 140, 255, .65);
    box-shadow: 0 0 0 4px rgba(79, 140, 255, .18);
}

.controles button {
    padding: 10px 14px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, .16);
    background: rgba(79, 140, 255, .18);
    color: var(--text);
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.2s, transform 0.15s ease;
    box-shadow: 0 8px 20px rgba(0, 0, 0, .18);
}

.controles button:hover {
    background: rgba(79, 140, 255, .28);
}

#totalCasos {
    font-weight: 750;
    color: #ffffff;
    font-size: 1.1em;
}

#casosNoLocalizados {
    color: rgba(255, 255, 255, .68) !important;
    font-size: 0.9em;
}

/* ============================================================
   GRID DE CONTROLES
   ============================================================ */
.grid-controles {
    display: grid;
    grid-template-columns: repeat(3, minmax(220px, 1fr));
    gap: 14px 16px;
    align-items: end;
    width: 100%;
}

.grid-controles>div {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.grid-controles strong {
    margin-bottom: 6px;
}

.fila-filtro-activo.fila-completa {
    display: flex !important;
    flex-direction: row !important;
    align-items: flex-end;
    gap: 16px;
    width: 100%;
    grid-column: 1 / -1 !important;
}

.fila-filtro-activo.fila-completa>.selector-filtro {
    flex: 0 0 260px;
    max-width: 260px;
}

.fila-filtro-activo.fila-completa>#contenedorFiltrosDinamicos {
    flex: 1 1 auto;
    display: flex !important;
    align-items: flex-end;
    min-width: 0;
    width: auto !important;
}

.fila-filtro-activo.fila-completa>#contenedorFiltrosDinamicos .bloque-filtro {
    width: 100%;
    margin: 0;
}

.fila-filtro-activo.fila-completa>#contenedorFiltrosDinamicos .bloque-filtro select {
    width: 100%;
}

/* ============================================================
   FILTROS DINÁMICOS
   ============================================================ */
#contenedorFiltrosDinamicos {
    display: block !important;
    width: 100%;
    min-width: 0;
    grid-column: auto !important;
}

.bloque-filtro {
    width: 100%;
    margin-bottom: 12px;
}

.bloque-filtro select {
    width: 100%;
    box-sizing: border-box;
}

/* ============================================================
   BOTÓN TOGGLE
   ============================================================ */
.barra-toggle {
    margin: 14px 16px 10px;
    display: flex;
    justify-content: flex-start;
}

.barra-toggle button {
    padding: 10px 14px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, .16);
    background: rgba(79, 140, 255, .18);
    color: #fff;
    cursor: pointer;
    font-weight: bold;
    box-shadow: 0 8px 20px rgba(0, 0, 0, .18);
}

.barra-toggle button:hover {
    background: rgba(79, 140, 255, .28);
}

/* ============================================================
   MAPA
   ============================================================ */
#map {
    height: 80vh;
    width: calc(100% - 32px);
    margin: 0 16px 14px;
    border: 1px solid rgba(255, 255, 255, .10);
    border-radius: 18px;
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: height 0.3s ease;
}

/* Mapa más grande cuando el panel está oculto */
.panel-oculto {
    display: none !important;
}

body:has(.panel-oculto) #map {
    height: 90vh !important;
}

/* ============================================================
   GRÁFICAS
   ============================================================ */
.graficas-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    padding: 0 16px 16px;
    background: transparent;
}

.grafica-wrapper {
    width: 30%;
    min-width: 280px;
    height: 340px;
    border: 1px solid var(--stroke);
    border-radius: 16px;
    padding: 10px;
    margin-top: 10px;
    box-shadow: var(--shadow);
    background: linear-gradient(180deg, var(--card2), var(--card));
}

/* ============================================================
   LEYENDA DE PROGRAMAS - JERÁRQUICA
   ============================================================ */
.leyenda-programas-box {
    margin: 0 16px 14px;
    padding: 14px 16px;
    border-radius: 16px;
    background: #ffffff !important;
    border: 1px solid rgba(0, 0, 0, .14);
    box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
    color: #1a1a1a !important;
    max-height: 400px;
    overflow-y: auto;
}

.leyenda-programas-box h4 {
    margin: 0 0 10px 0;
    color: #000000 !important;
    font-size: 15px;
    font-weight: 700 !important;
    border-bottom: 2px solid #4f8cff !important;
    padding-bottom: 6px;
}

.leyenda-item-programa {
    font-weight: bold;
    color: #1a1a1a !important;
    margin-top: 8px;
    font-size: 14px;
}

.leyenda-item-evento {
    font-weight: 600;
    color: #333 !important;
    margin-left: 20px;
    font-size: 13px;
    padding: 2px 0;
}

.leyenda-item-estado {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 40px;
    padding: 3px 0;
    font-size: 12px;
    color: #333 !important;
}

.leyenda-color {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, .2);
    flex-shrink: 0;
    display: inline-block;
}

/* Forzar que TODO en la leyenda sea visible */
.leyenda-programas-box * {
    color: #1a1a1a !important;
}

/* ============================================================
   ETIQUETAS DEL MAPA - LETRAS BLANCAS CON FONDO
   ============================================================ */
.label-comuna {
    background: rgba(31, 119, 180, 0.85);
    color: white !important;
    font-size: 11px;
    font-weight: bold;
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    text-shadow: 0 0 8px rgba(0, 0, 0, 0.8);
}

.label-corregimiento {
    background: rgba(44, 160, 44, 0.85);
    color: white !important;
    font-size: 11px;
    font-weight: bold;
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    text-shadow: 0 0 8px rgba(0, 0, 0, 0.8);
}

.label-barrio {
    font-size: 10px;
    font-weight: bold;
    color: #FF6B35;
    text-shadow: 1px 1px 0px white;
}

/* ============================================================
   POPUP GRANDE - ESTILOS MEJORADOS
   ============================================================ */
.popup-grande .leaflet-popup-content-wrapper {
    border-radius: 14px !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35) !important;
    padding: 0 !important;
    background: white !important;
}

.popup-grande .leaflet-popup-content {
    font-size: 14px;
    line-height: 1.6;
    max-height: 450px;
    overflow-y: auto;
    padding: 12px 16px !important;
    margin: 0 !important;
    color: #222 !important;
}

.popup-grande .leaflet-popup-content table {
    width: 100%;
    border-collapse: collapse;
}

.popup-grande .leaflet-popup-content td {
    padding: 6px 10px;
    border-bottom: 1px solid #e8e8e8;
    font-size: 13px;
    color: #222 !important;
}

.popup-grande .leaflet-popup-content td:first-child {
    font-weight: 600;
    color: #1a1a1a !important;
    width: 38%;
    background: #f5f7fa;
    border-radius: 4px 0 0 4px;
}

.popup-grande .leaflet-popup-content td:last-child {
    color: #1a1a1a !important;
}

.popup-grande .leaflet-popup-content tr:hover td {
    background: #eef3ff;
}

.popup-grande .leaflet-popup-content strong {
    color: #1a1a1a !important;
}

.popup-grande .leaflet-popup-content hr {
    border: none;
    border-top: 1px solid #ddd;
    margin: 8px 0;
}

/* Flecha del popup */
.popup-grande .leaflet-popup-tip {
    background: white !important;
}

/* Títulos dentro del popup */
.popup-grande .leaflet-popup-content h3 {
    color: #1a1a1a !important;
    margin: 0 0 10px 0;
    padding-bottom: 8px;
    border-bottom: 2px solid #4f8cff;
}

/* ============================================================
   FULLSCREEN
   ============================================================ */
#map:-webkit-full-screen,
#map:-moz-full-screen,
#map:-ms-fullscreen,
#map:fullscreen {
    height: 100% !important;
    width: 100% !important;
    z-index: 9999;
}

body.map-fullscreen .header,
body.map-fullscreen .controles,
body.map-fullscreen .graficas-container {
    display: none;
}


/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1100px) {
    .controles {
        grid-template-columns: 1fr;
    }

    .grid-controles {
        grid-template-columns: repeat(2, minmax(220px, 1fr));
    }

    .fila-filtro-activo.fila-completa {
        flex-direction: column !important;
        align-items: stretch;
    }

    .fila-filtro-activo.fila-completa>.selector-filtro {
        flex: 1 1 auto;
        max-width: none;
    }

    .fila-filtro-activo.fila-completa>#contenedorFiltrosDinamicos {
        width: 100% !important;
    }
}

@media (max-width: 992px) {
    .grafica-wrapper {
        width: 45%;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 12px 14px;
    }

    .header h2 {
        font-size: 1.3em;
    }

    .controles {
        margin: 10px;
        padding: 12px;
    }

    .controles select,
    .controles input[type="file"],
    .controles input[type="text"] {
        min-width: 100%;
    }

    #map {
        width: calc(100% - 20px);
        margin: 0 10px 10px;
        height: 60vh;
    }

    .graficas-container {
        padding: 0 10px 10px;
    }

    .grafica-wrapper {
        width: 100%;
        min-width: auto;
    }

    .grid-controles {
        grid-template-columns: 1fr;
    }

    .fila-filtro-activo.fila-completa {
        flex-direction: column !important;
        align-items: stretch;
    }

    .fila-filtro-activo.fila-completa>.selector-filtro {
        flex: 1 1 auto;
        max-width: none;
    }

    .fila-filtro-activo.fila-completa>#contenedorFiltrosDinamicos {
        width: 100% !important;
    }
}
/* ============================================================
   ROSA DE LOS VIENTOS - Imagen personalizada
   ============================================================ */
.rosa-vientos-control {
    background: white;
    border: 2px solid #003366;
    border-radius: 50%;
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 10px rgba(0,0,0,0.35);
    overflow: hidden;
    padding: 5px;
    box-sizing: border-box;
}

.rosa-vientos-control svg {
    width: 100%;
    height: 100%;
}

.leaflet-control-rosa-vientos {
    margin-right: 10px !important;
}

/* ============================================================
   BARRA DE ESCALA - Más grande y visible
   ============================================================ */
.leaflet-control-scale {
    background: rgba(255, 255, 255, 0.95) !important;
    border: 2px solid #003366 !important;
    border-radius: 4px !important;
    padding: 4px 8px !important;
    font-weight: bold !important;
    font-size: 12px !important;
    color: #003366 !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
}

.leaflet-control-scale-line {
    border: 2px solid #003366 !important;
    border-top: none !important;
    background: rgba(255, 255, 255, 0.8) !important;
    color: #003366 !important;
    font-weight: bold !important;
    font-size: 11px !important;
}