/* ==========================================
   CABECERA PRINCIPAL (HEADER)
   ========================================== */
.main-header {
    background-color: #1a5276; /* Azul Corporativo */
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    height: 60px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    box-sizing: border-box;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.nav-logo {
    height: 38px;
    width: auto;
    object-fit: contain;
}

.header-divider {
    width: 2px;
    height: 25px;
    background-color: rgba(255, 255, 255, 0.3);
}

.header-subtitle {
    font-size: 0.85rem;
    font-weight: 500;
    letter-spacing: 0.5px;
    color: #e0f2fe;
}

#mainTitle {
    font-size: 1.3rem;
    margin: 0;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.btn-header {
    background: rgba(255, 255, 255, 0.12);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 6px;
    padding: 8px 14px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s;
}

.btn-header:hover {
    background: rgba(255, 255, 255, 0.22);
}

/* Selector de fuente: SENAMHI actual / senamhiR histórico */
.selector-fuente {
    display: flex;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 6px;
    overflow: hidden;
}

.selector-fuente button {
    background: transparent;
    color: #e0f2fe;
    border: none;
    padding: 8px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
}

.selector-fuente button + button { border-left: 1px solid rgba(255, 255, 255, 0.35); }
.selector-fuente button:hover { background: rgba(255, 255, 255, 0.12); }

.selector-fuente button.activa {
    background: white;
    color: #1a5276;
}

.fuente-modal {
    font-size: 0.8rem;
    font-weight: 500;
    opacity: 0.85;
    margin-left: 6px;
}

/* ==========================================
   MODAL: ESTACIONES DESCARGADAS
   ========================================== */
.modal-fondo {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    z-index: 100000;
    justify-content: center;
    align-items: center;
    padding: 16px;
    box-sizing: border-box;
}

.modal-caja {
    background: #ffffff;
    border-radius: 10px;
    width: 760px;
    max-width: 100%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}

.modal-cabecera {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: #1a5276;
    color: white;
}

.modal-cabecera h3 {
    margin: 0;
    font-size: 1.05rem;
}

.modal-cerrar {
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    opacity: 0.8;
}

.modal-cerrar:hover { opacity: 1; }

.modal-buscador {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 16px 20px 8px;
    padding: 0 12px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #f8fafc;
    color: #64748b;
}

.modal-buscador input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px 0;
    font-size: 0.9rem;
    color: #334155;
    outline: none;
}

.familias-descargadas {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0 20px 10px;
}

.pestana-familia {
    border: 1px solid #cbd5e1;
    background: white;
    color: #334155;
    border-radius: 999px;
    padding: 5px 11px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
}

.pestana-familia span {
    display: inline-block;
    min-width: 18px;
    margin-left: 4px;
    padding: 0 5px;
    border-radius: 999px;
    background: #e2e8f0;
    color: #334155;
    text-align: center;
}

.pestana-familia:hover { border-color: #1a5276; }

.pestana-familia.activa {
    background: #1a5276;
    border-color: #1a5276;
    color: white;
}

.pestana-familia.activa span {
    background: rgba(255, 255, 255, 0.25);
    color: white;
}

.item-retirada {
    color: #9a3412;
    background: #ffedd5;
}

.item-variables {
    flex-basis: 100%;
    color: #64748b;
}

.modal-resumen {
    margin: 0 20px 8px;
    font-size: 0.75rem;
    color: #64748b;
}

.lista-descargadas {
    overflow-y: auto;
    padding: 0 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.item-descargada {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.item-descargada:hover {
    border-color: #93c5fd;
    background: #f8fbff;
}

.item-nombre {
    font-weight: 700;
    color: #1e293b;
    font-size: 0.95rem;
}

.item-codigo {
    font-weight: 500;
    color: #64748b;
    font-size: 0.8rem;
    margin-left: 6px;
}

.item-tipo {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 700;
    color: #1e3a8a;
    background: #dbeafe;
    border-radius: 4px;
    padding: 2px 6px;
    margin-left: 6px;
    vertical-align: middle;
}

.item-datos {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 18px;
    margin-top: 6px;
    font-size: 0.78rem;
    color: #475569;
}

.item-datos b { color: #1e293b; }

.btn-usar {
    flex-shrink: 0;
    background: #1a5276;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
}

.btn-usar:hover { background: #154360; }

.item-acciones {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.btn-accion {
    background: white;
    color: #1a5276;
    border: 1px solid #1a5276;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
}

.btn-accion:hover { background: #eff6ff; }

.btn-peligro {
    color: #dc2626;
    border-color: #fca5a5;
}

.btn-peligro:hover { background: #fef2f2; border-color: #dc2626; }

/* Aviso bajo el buscador: la estación ya está en la base de datos */
.aviso-cache {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    margin-top: 8px;
    padding: 8px 10px;
    border-radius: 6px;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    color: #065f46;
    font-size: 0.75rem;
    line-height: 1.4;
}

.aviso-cache i { margin-top: 2px; }

.aviso-cache a {
    color: #047857;
    font-weight: 700;
    white-space: nowrap;
}

.lista-vacia {
    text-align: center;
    color: #64748b;
    font-size: 0.85rem;
    padding: 30px 0;
}

@media (max-width: 600px) {
    .item-descargada { flex-direction: column; align-items: stretch; }
    .item-acciones { justify-content: flex-end; }
}

/* ==========================================
   CONTENEDOR DE PRODUCCIÓN Y LAYOUT
   ========================================== */
.dashboard-container {
    padding: 15px;
    background-color: #f1f5f9;
    min-height: calc(100vh - 60px);
    display: flex;
    flex-direction: column;
    gap: 15px;
    box-sizing: border-box;
}

.top-section {
    display: flex;
    width: 100%;
    gap: 15px;
    align-items: stretch;
}

/* PANEL IZQUIERDO TRABAJADO */
.left-panel {
    flex: 0 0 340px; /* Ancho idéntico de referencia */
    background: #ffffff;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
    border: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-sizing: border-box;
}

.panel-title {
    font-size: 1rem;
    color: #1e293b;
    margin: 0 0 5px 0;
    font-weight: 600;
}

.panel-segment {
    display: flex;
    flex-direction: column;
}

.input-label {
    font-size: 0.72rem;
    font-weight: 700;
    color: #1e3a8a;
    margin-bottom: 6px;
    text-transform: uppercase;
}

.sub-label {
    font-size: 0.68rem;
    color: #64748b;
    display: block;
    margin-bottom: 3px;
}

.select-container {
    display: flex;
    gap: 8px;
    align-items: center;
}

.left-panel select, .left-panel input[type="text"], .left-panel input[type="number"], .left-panel input[type="date"] {
    width: 100%;
    padding: 9px 12px;
    border-radius: 6px;
    border: 1px solid #cbd5e1;
    background-color: #f8fafc;
    color: #334155;
    font-size: 0.85rem;
    font-weight: 500;
    box-sizing: border-box;
}

.coord-grid, .date-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.panel-divider {
    border: 0;
    height: 1px;
    background: #e2e8f0;
    margin: 5px 0;
}

/* BOTÓN DESCARGAR */
.btn-descargar {
    background: #1a5276;
    color: white;
    border: none;
    padding: 12px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 4px rgba(26, 82, 118, 0.2);
    transition: background 0.2s;
}

.btn-descargar:hover {
    background: #154360;
}

/* ZONA DE ARRASTRE JSON */
.upload-box {
    border: 2px dashed #cbd5e1;
    padding: 15px;
    border-radius: 6px;
    text-align: center;
    background: #f8fafc;
    cursor: pointer;
    transition: border-color 0.2s;
}

.upload-box:hover {
    border-color: #3b82f6;
}

.upload-icon {
    font-size: 1.5rem;
    color: #94a3b8;
    margin-bottom: 5px;
}

.upload-box p {
    margin: 0;
    font-size: 0.78rem;
    color: #64748b;
    font-weight: 500;
}

/* PANEL DERECHO (CONTENEDOR BLANCO) */
.right-panel {
    flex: 1;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
    border: 1px solid #e2e8f0;
    display: flex; /* Añadimos esto para que obligue al mapa a expandirse */
    flex-direction: column;
    overflow: hidden;
}

/* EL VISOR DEL MAPA LEAFLET */
#map {
    width: 100%;
    height: 100%;
    min-height: 600px; /* Forzamos una altura mínima visible en pantalla */
    border-radius: 8px;
    z-index: 1;
}

/* VENTANA DE CLAVE (encima de todo, incluida la lista de estaciones) */
.modal-clave { z-index: 100001; }

.caja-clave {
    background: #ffffff;
    border-radius: 10px;
    width: 420px;
    max-width: 100%;
    padding: 22px 24px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.caja-clave h3 {
    margin: 0 0 10px;
    color: #1a5276;
    font-size: 1.05rem;
}

.clave-detalle {
    margin: 0 0 14px;
    font-size: 0.82rem;
    color: #475569;
    line-height: 1.5;
}

.clave-etiqueta {
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    color: #1e3a8a;
    margin-bottom: 6px;
    text-transform: uppercase;
}

.caja-clave input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.95rem;
    box-sizing: border-box;
}

.caja-clave input:focus { outline: 2px solid #93c5fd; border-color: #1a5276; }

.clave-error {
    min-height: 1.2em;
    margin: 8px 0 0;
    font-size: 0.8rem;
    color: #dc2626;
}

.clave-botones {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
}

.clave-botones button:disabled { opacity: 0.6; cursor: wait; }

/* BOTONES DE DESCARGA BAJO EL GRÁFICO */
.botones-descarga {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 14px;
    margin-top: 20px;
}

.btn-descarga-csv {
    background: transparent;
    color: #27ae60;
    border: 2px solid #27ae60;
    padding: 12px 30px;
    font-weight: bold;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: background 0.2s ease;
}

.btn-descarga-csv:hover { background: rgba(39, 174, 96, 0.06); }

.nota-resolucion {
    margin: -10px 0 0;
    font-size: 0.78rem;
    color: #64748b;
    text-align: center;
}

/* OVERLAY DE CARGA */
.overlay-container {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background: rgba(15, 23, 42, 0.9);
    z-index: 99999;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
}

.spinner {
    border: 4px solid rgba(255,255,255,0.1);
    border-top: 4px solid #3b82f6;
    border-radius: 50%;
    width: 45px;
    height: 45px;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.overlay-text { font-weight: 600; font-size: 1.1rem; }
.overlay-subtext { font-size: 0.8rem; color: #94a3b8; margin-top: 4px; }