/* css/style-v3.css — tema-aware y mobile-first */
:root {
    --navbar-height: 56px;
    --bottom-nav-height: 60px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--theme-bg, #f8f9fa);
    color: var(--theme-text, #212529);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    height: 100vh;
    height: 100dvh;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    padding-top: calc(var(--navbar-height) + var(--safe-top));
    padding-bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 18px);
}

/* ---------- Navbar ---------- */
.navbar {
    height: calc(var(--navbar-height) + var(--safe-top));
    min-height: calc(var(--navbar-height) + var(--safe-top));
    padding-top: var(--safe-top) !important;
    background-color: var(--theme-navbar, #17465C) !important;
    color: var(--theme-navbar-text, #fff);
    z-index: 1031;
    flex-wrap: nowrap !important;
    position: fixed;
}

.navbar > .container-fluid {
    flex-wrap: nowrap !important;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-left: 10px;
    padding-right: 8px;
    height: 100%;
    min-width: 0;
}

/* --- Marca --- */
.navbar-brand {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-right: 0 !important;
    padding: 0;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--theme-navbar-text, #fff) !important;
    min-width: 0;
    flex-shrink: 1;
    line-height: 1;
    height: 32px;
}
.navbar-brand-logo {
    width: 26px !important;
    height: 26px !important;
    max-width: 26px !important;
    max-height: 26px !important;
    min-width: 26px;
    min-height: 26px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
    display: block;
}
.navbar-brand-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1;
}

/* --- Acciones a la derecha --- */
.navbar-actions {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 6px;
    flex-shrink: 0;
    margin-left: auto;
    height: 32px;
    min-width: 0;
}

.navbar-actions .dropdown {
    display: inline-flex;
    align-items: center;
    height: 28px;
    flex-shrink: 0;
    position: relative;
}

.navbar-actions .btn {
    height: 28px;
    min-height: 28px;
    padding: 0 9px;
    font-size: 0.72rem;
    line-height: 1;
    gap: 4px;
    white-space: nowrap;
    border-color: rgba(255,255,255,0.55);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.navbar-actions .btn:hover,
.navbar-actions .btn:focus {
    background-color: rgba(255,255,255,0.15);
    color: #fff;
    border-color: rgba(255,255,255,0.85);
}
.navbar-actions .btn .ico {
    width: 13px;
    height: 13px;
    flex-shrink: 0;
}

/* v21: link SMN — mismo look que .btn pero como <a> */
.navbar-actions > a.btn {
    text-decoration: none;
}

#nav-username {
    height: 28px;
    min-height: 28px;
    display: inline-flex;
    align-items: center;
    padding: 0 8px;
    font-size: 0.68rem;
    line-height: 1;
    background: rgba(255,255,255,0.15) !important;
    color: #fff !important;
    border: 1px solid rgba(255,255,255,0.3);
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex-shrink: 0;
}

.theme-picker-btn {
    background: transparent;
    border: none;
    color: var(--theme-navbar-text, #fff) !important;
    width: 28px;
    height: 28px;
    min-width: 28px;
    padding: 0;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, transform 0.15s ease;
    line-height: 1;
}
.theme-picker-btn:hover,
.theme-picker-btn:focus,
.theme-picker-btn[aria-expanded="true"] {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    box-shadow: none;
    outline: none;
}
.theme-picker-btn .ico {
    width: 16px;
    height: 16px;
    display: block;
}

/* --- Indicador online/offline (línea inferior del navbar) --- */
.online-indicator {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 3px;
    width: 100%;
    background-color: #22c55e;
    transition: background-color 0.35s ease;
    pointer-events: none;
    z-index: 1032;
}
.online-indicator.offline {
    background-color: #ef4444;
}
/* "Sin conexión al servidor": hay red pero el backend no responde.
   Se muestra en naranja para diferenciarlo de online (verde) y offline (rojo). */
.online-indicator.no-server {
    background-color: #f39c12;
}

/* --- Mobile ultra-angosto: sacar textos, dejar solo iconos --- */
@media (max-width: 480px) {
    .navbar-actions .btn-label {
        display: none;
    }
    .navbar-actions .btn {
        padding: 0 7px;
    }
    .navbar-actions {
        gap: 4px;
    }
    /* v21: el link SMN también es .btn → ya hereda el hide del label,
       pero su padding está bien; aseguramos que no rompa el layout. */
    .navbar-actions > a.btn,
    .navbar-actions > button.btn {
        flex-shrink: 0;
    }
    #nav-username {
        display: none !important;
    }
    .navbar-brand-logo {
        width: 24px !important;
        height: 24px !important;
        max-width: 24px !important;
        max-height: 24px !important;
        min-width: 24px;
        min-height: 24px;
    }
    .navbar-brand {
        font-size: 1.05rem;
    }
}

/* v21: en pantallas MUY chicas (iPhone SE 320px), con 5 botones
   (SMN + Ayuda + Refresh + Engranaje + Login) el navbar se desborda.
   Achicamos aún más el gap y el padding para que entren. */
@media (max-width: 360px) {
    .navbar-actions {
        gap: 2px;
    }
    .navbar-actions .btn {
        padding: 0 5px;
    }
    .theme-picker-btn {
        width: 24px;
        min-width: 24px;
    }
    .navbar-brand {
        font-size: 0.95rem;
    }
    .navbar-brand-logo {
        width: 22px !important;
        height: 22px !important;
        max-width: 22px !important;
        max-height: 22px !important;
        min-width: 22px;
        min-height: 22px;
    }
}

/* v21: en landscape móvil (navbar comprimido a 40px), los labels
   de los botones nuevos deben ocultarse también. */
html.landscape-touch .navbar-actions .btn-label {
    display: none;
}

/* v21: modal de ayuda — estilos mínimos que no dependen de Bootstrap
   (por si el modal se abre sin que Bootstrap haya cargado del todo). */
#ayuda-modal details summary {
    padding: 4px 0;
    list-style: none;
}
#ayuda-modal details summary::before {
    content: '▸ ';
    display: inline-block;
    transition: transform 0.15s ease;
}
#ayuda-modal details[open] summary::before {
    transform: rotate(90deg);
}
#ayuda-modal details p,
#ayuda-modal details ul {
    color: var(--theme-text, #212529);
}

/* v22: índice de pantallas dentro del modal de ayuda.
   Se genera dinámicamente desde AYUDA_POR_TAB.general en app.js. */
.ayuda-lista-pantallas {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-top: 4px;
}

.ayuda-btn-pantalla {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: var(--theme-surface-soft, #f8f9fa);
    border: 1px solid var(--theme-border, #dee2e6);
    border-radius: 10px;
    color: var(--theme-text, #212529);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: left;
    line-height: 1.2;
    min-height: 44px;
}

.ayuda-btn-pantalla:hover,
.ayuda-btn-pantalla:focus {
    background: var(--theme-primary-light, #e7f1ff);
    border-color: var(--theme-primary, #167BA5);
    color: var(--theme-primary, #167BA5);
    outline: none;
}

.ayuda-btn-pantalla:active {
    transform: scale(0.97);
}

.ayuda-btn-pantalla .ico-wrap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    color: var(--theme-primary, #167BA5);
}

.ayuda-btn-pantalla .ico {
    width: 16px !important;
    height: 16px !important;
}

/* Botón del footer "Ver todas las pantallas" */
#btn-ayuda-ver-todas:hover,
#btn-ayuda-ver-todas:focus {
    background: var(--theme-primary-light, #e7f1ff);
    outline: none;
}

/* En pantallas muy chicas, el grid se vuelve 1 columna */
@media (max-width: 420px) {
    .ayuda-lista-pantallas {
        grid-template-columns: 1fr;
    }
}

/* En landscape móvil (navbar comprimido), achicar el modal */
html.landscape-touch #ayuda-modal > div {
    max-height: 92vh !important;
}

/* ---------- Contenido ---------- */
#main-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 10px 10px 10px;
    background-color: var(--theme-bg, #f8f9fa);
    color: var(--theme-text, #212529);
}

.tab { display: none; animation: fadeIn 0.25s ease; }
.tab.active { display: block; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Texto muted ---------- */
.text-muted { color: var(--theme-muted, #6c757d) !important; }

/* ---------- Cards ---------- */
.card {
    background-color: var(--theme-surface, #fff);
    border: 1px solid var(--theme-border, #dee2e6);
    color: var(--theme-text, #212529);
    border-radius: 10px;
}

#info-panel .card h6 {
    font-size: 0.7rem;
    color: var(--theme-muted, #6c757d);
    margin-bottom: 2px;
}
#info-panel .card-compact .card-body { padding: 6px 4px; }
#info-panel .card-compact h6 { font-size: 0.63rem; margin-bottom: 0; }
#info-panel .card-compact .small { font-size: 0.62rem; }
#info-panel .display-6,
#info-panel .card-compact .display-6 {
    font-size: 1.3rem;
    font-weight: 600;
    margin: 2px 0;
    line-height: 1;
    color: var(--theme-primary-dark, #17465C);
}

/* Badges de estado del dato */
.dato-principal {
    display: flex; align-items: baseline; justify-content: center;
    gap: 3px; margin: 2px 0 5px; line-height: 1;
}
.dato-valor {
    font-size: 1.5rem; font-weight: 700;
    color: var(--theme-primary-dark, #17465C);
    font-variant-numeric: tabular-nums;
}
.dato-unidad { font-size: 0.75rem; color: var(--theme-muted, #6B7B85); }

/* ✅ Asegurar que el badge y el texto se centren */
.dato-meta {
    display: flex; 
    flex-direction: column; 
    align-items: center;
    gap: 2px; line-height: 1.2;
}
.dato-badge {
    display: inline-flex; align-items: center; gap: 3px;
    padding: 1px 6px; border-radius: 8px;
    font-weight: 600; font-size: 0.58rem;
}
.dato-badge .ico { width: 10px; height: 10px; }
.dato-badge-observado  { background: var(--theme-info-soft, #DDEDF4); color: var(--theme-info-text, #17465C); }
.dato-badge-pronostico { background: var(--theme-warning-light, #FBEBD2); color: var(--theme-warning-text, #6B4A0F); }
.dato-badge-simulacion { background: rgba(126,87,194,0.15); color: #7E57C2; }
.dato-badge-estimado   { background: rgba(107,123,133,0.15); color: var(--theme-muted, #6B7B85); }
.dato-badge-umbral     { background: var(--theme-primary-light, #DDEDF4); color: var(--theme-primary-dark, #17465C); }
.dato-badge-sindatos   { background: rgba(107,123,133,0.15); color: var(--theme-muted, #6B7B85); }
.dato-fuente { color: var(--theme-muted, #6B7B85); font-size: 0.58rem; }

/* Nivel absoluto: icono + número + unidad en una fila centrada */
.dato-principal.dato-principal-con-icono {
    align-items: center;
    gap: 5px;
}
.dato-principal-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--theme-primary-dark, #17465C);
    opacity: 0.85;
    height: 100%;
    width: 100%;
}
.dato-principal-icon .ico {
    width: 100% !important;
    height: 100% !important;
    max-height: 54px;
}

/* ============================================================
   ESTADO "CALCULANDO"
   - Oculta el número y la unidad.
   - El badge cambia de color y parpadea.
   ============================================================ */
.dato-principal.calculando #nivel-absoluto,
.dato-principal.calculando .dato-unidad {
    display: none !important;
}

.dato-principal.calculando .dato-badge {
    animation: badge-calc-blink 1s ease-in-out infinite;
    background-color: var(--theme-warning-light, #FBEBD2) !important;
    color: var(--theme-warning-text, #6B4A0F) !important;
}

@keyframes badge-calc-blink {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.3; }
}

@media (prefers-reduced-motion: reduce) {
    .dato-principal.calculando .dato-badge { animation: none; }
}

/* ---------- Gráficos ---------- */
.chart-container {
    background: var(--theme-surface, #fff);
    border-radius: 10px;
    padding: 6px;
    border: 1px solid var(--theme-border, #dee2e6);
    margin-top: 6px;
}
.chart-container canvas {
    width: 100% !important;
    height: auto !important;
    max-height: 200px;
}

.chart-meta {
    display: flex; justify-content: space-between; align-items: center;
    padding: 4px 2px 6px; font-size: 0.68rem;
}

/* ---------- Botones ---------- */
.btn-primary {
    background-color: var(--theme-primary, #167BA5);
    border-color: var(--theme-primary, #167BA5);
    color: #fff;
}
.btn-primary:hover, .btn-primary:focus {
    background-color: var(--theme-primary-dark, #17465C);
    border-color: var(--theme-primary-dark, #17465C);
    color: #fff;
}
.btn-outline-primary {
    color: var(--theme-primary, #167BA5);
    border-color: var(--theme-primary, #167BA5);
}
.btn-outline-primary:hover {
    background-color: var(--theme-primary, #167BA5);
    color: #fff;
}
.btn-outline-secondary {
    color: var(--theme-muted, #6c757d);
    border-color: var(--theme-border, #dee2e6);
}
.btn-outline-secondary:hover {
    background-color: var(--theme-surface-soft, #f1f3f5);
    color: var(--theme-text, #212529);
    border-color: var(--theme-border, #dee2e6);
}

/* ---------- Formularios ---------- */
.form-control, .form-select {
    background-color: var(--theme-surface, #fff);
    border-color: var(--theme-border, #dee2e6);
    color: var(--theme-text, #212529);
}
.form-control:focus, .form-select:focus {
    background-color: var(--theme-surface, #fff);
    color: var(--theme-text, #212529);
    border-color: var(--theme-primary, #167BA5);
    box-shadow: 0 0 0 3px var(--theme-focus-ring, rgba(22,123,165,0.18));
}
.form-control::placeholder { color: var(--theme-muted, #6c757d); opacity: 1; }

#selector-metodo, #selector-puerto-30d { font-size: 0.8rem; padding: 4px 8px; }

/* ✅ Fila compacta del método de interpolación + botón Actualizar */
#info-panel .metodo-row .form-select-sm {
    font-size: 0.74rem;
    height: 32px;
    min-height: 32px;
    padding: 4px 22px 4px 8px;
    line-height: 1.1;
}
#info-panel .metodo-row .btn {
    height: 32px;
    min-height: 32px;
    padding: 0 6px;
    font-size: 0.72rem;
}
#info-panel .metodo-row .btn .ico {
    width: 13px;
    height: 13px;
}

/* ---------- Bottom nav ---------- */
#bottom-nav {
    height: calc(var(--bottom-nav-height) + var(--safe-bottom));
    min-height: calc(var(--bottom-nav-height) + var(--safe-bottom));
    padding: 4px 0 calc(4px + var(--safe-bottom)) 0;
    background-color: var(--theme-surface, #fff) !important;
    border-top: 1px solid var(--theme-border, #dee2e6) !important;
    box-shadow: 0 -2px 8px var(--theme-shadow, rgba(0,0,0,0.05));
    z-index: 1030;
}
.nav-btn {
    background: none; border: none; text-align: center;
    font-size: 1.4rem;
    color: var(--theme-muted, #6c757d);
    padding: 2px 8px; border-radius: 8px;
    transition: all 0.15s; line-height: 1.2; flex: 1;
}
.nav-btn .small { font-size: 0.55rem; display: block; margin-top: -2px; }
.nav-btn.active {
    color: var(--theme-primary, #167BA5);
    background-color: var(--theme-primary-light, rgba(22,123,165,0.08));
}
.nav-btn:active { transform: scale(0.94); }

/* ---------- Lista de lugares ---------- */
#lista-lugares, .eventos-lista {
    background: var(--theme-surface, #fff);
    border: 1px solid var(--theme-border, #dee2e6);
    border-radius: 10px;
    max-height: 260px; overflow-y: auto;
    color: var(--theme-text, #212529);
}
.lugar-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 10px;
    border-bottom: 1px solid var(--theme-border-soft, #f1f3f5);
    gap: 8px;
}
.lugar-item:last-child { border-bottom: 0; }
.lugar-item .lugar-info { flex: 1; min-width: 0; cursor: pointer; }
.lugar-item .lugar-nombre {
    font-size: 0.85rem; font-weight: 600;
    color: var(--theme-primary, #167BA5);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lugar-item .lugar-coords { font-size: 0.65rem; color: var(--theme-muted, #6c757d); }
.lugar-item .lugar-acciones { display: flex; gap: 4px; }
.lugar-vacio { padding: 12px; text-align: center; color: var(--theme-muted, #6c757d); font-size: 0.8rem; }

/* ---------- Campana por lugar: activa vs inactiva ---------- */
/* Reservamos el mismo espacio para ambas → la lista no salta al togglear */
.lugar-item .lugar-nombre .ico-wrap[data-ico="campana"],
.lugar-item .lugar-nombre .ico-wrap[data-ico="campana-off"] {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}
.lugar-item .lugar-nombre .ico-wrap[data-ico="campana"] .ico,
.lugar-item .lugar-nombre .ico-wrap[data-ico="campana-off"] .ico {
    width: 12px;
    height: 12px;
}

/* Activa: círculo sólido con campana blanca */
.lugar-item .lugar-nombre .ico-wrap[data-ico="campana"] {
    background: var(--theme-primary, #167BA5);
    color: #fff !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}
.lugar-item .lugar-nombre .ico-wrap[data-ico="campana"] .ico {
    color: #fff;
}

/* Inactiva: apagada, sin fondo */
.lugar-item .lugar-nombre .ico-wrap[data-ico="campana-off"] {
    opacity: 0.35;
}

/* ---------- Eventos ---------- */
.evento-item {
    display: flex; gap: 8px; padding: 8px 10px;
    border-bottom: 1px solid var(--theme-border-soft, #f1f3f5);
    cursor: pointer; align-items: flex-start;
}
.evento-item:last-child { border-bottom: 0; }
.evento-item:hover { background: var(--theme-surface-soft, #f8f9fa); }
.evento-item .evento-nombre {
    font-size: 0.85rem; font-weight: 600;
    color: var(--theme-text, #212529);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.evento-item .evento-meta {
    display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
    font-size: 0.68rem; color: var(--theme-muted, #6c757d);
}
.evento-item .badge-puerto {
    background: var(--theme-info-soft, #e7f1ff);
    color: var(--theme-info-text, #167BA5);
    font-weight: 600; padding: 1px 6px; border-radius: 8px; font-size: 0.65rem;
}
.eventos-loading, .eventos-vacio, .eventos-error {
    text-align: center; padding: 14px 10px;
    font-size: 0.82rem; color: var(--theme-muted, #6c757d);
}

/* ---------- Panel de guardar lugar ---------- */
#panel-guardar {
    background: var(--theme-surface, #fff);
    border: 1px solid var(--theme-border, #dee2e6);
    border-radius: 10px;
    padding: 10px;
    animation: fadeIn 0.2s ease;
}
#panel-guardar .guardar-field {
    margin-bottom: 8px;
}
#panel-guardar .guardar-field:last-of-type {
    margin-bottom: 0;
}
#panel-guardar .form-control {
    font-size: 0.85rem;
}
#input-altura-emergencia {
    text-align: center;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* ---------- Atribución de datos ---------- */
#attribution-bar {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + var(--safe-bottom));
    left: 0;
    right: 0;
    height: 18px;
    line-height: 18px;
    text-align: center;
    font-size: 0.58rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: var(--theme-muted, #6B7B85);
    background-color: var(--theme-surface, #fff);
    border-top: 1px solid var(--theme-border-soft, #EAF2F5);
    z-index: 1029;
    padding: 0 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    pointer-events: none;
}

/* ---------- Barra de nivel ---------- */
#map {
    height: 440px;
    border-radius: 12px 12px 0 0;
    border-bottom: none;
    margin-top: 4px; margin-bottom: 0;
}
.barra-nivel {
    display: flex; align-items: center; gap: 8px;
    height: 30px; padding: 0 12px;
    font-size: 0.78rem; font-weight: 500;
    border-radius: 0 0 12px 12px;
    border: 1px solid var(--theme-border, #dee2e6);
    border-top: none;
    background-color: var(--theme-surface-soft, #e5e7eb);
    color: var(--theme-text, #4b5563);
    transition: background-color 0.3s ease, color 0.3s ease;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#barra-texto { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barra-ico { display: inline-flex; align-items: center; }
.barra-meta { margin-left: auto; font-size: 0.68rem; opacity: .75; white-space: nowrap; }

.barra-normal     { background-color: var(--theme-success-soft, #DDEBE3); color: var(--theme-success-text, #1E4A2F); border-color: var(--theme-success-border, #B9D5C5); }
.barra-alerta     { background-color: var(--theme-warning-light, #FBEBD2); color: var(--theme-warning-text, #6B4A0F); border-color: var(--theme-warning-border, #F1D8AC); }
.barra-evacuacion { background-color: var(--theme-danger-light, #F5DDDD); color: var(--theme-danger-text, #6E2222); border-color: var(--theme-danger-border, #E6BCBC); }
.barra-sin-datos  { background-color: var(--theme-surface-soft, #E8F1F4); color: var(--theme-muted, #6B7B85); border-color: var(--theme-border, #D5E2E7); }

/* ---------- Botón "Mis lugares" ---------- */
#chevron-lugares { transition: transform 0.2s ease; font-size: 0.85rem; }
#btn-toggle-lugares.abierto #chevron-lugares { transform: rotate(180deg); }
#contador-lugares { color: var(--theme-muted, #6c757d); font-weight: 400; font-size: 0.75rem; }
#btn-guardar-lugar:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Push panel ---------- */
#push-panel {
    background: var(--theme-surface, #fff);
    border: 1px solid var(--theme-border, #dee2e6);
}
#push-estado { font-size: 0.72rem; color: var(--theme-muted); }

.push-umbrales {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 6px;
}
.push-umbral-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.78rem;
    color: var(--theme-text, #212529);
    cursor: pointer;
    padding: 4px 2px;
    border-radius: 6px;
    transition: background 0.15s ease;
}
.push-umbral-item:hover {
    background: var(--theme-surface-soft, #f8f9fa);
}
.push-umbral-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--theme-primary, #167BA5);
    flex-shrink: 0;
    cursor: pointer;
    margin: 0;
}
.push-umbrales + label,
#push-config > label {
    font-size: 0.72rem;
    color: var(--theme-text, #212529);
    margin-bottom: 4px;
    display: block;
}
#push-config > label .text-muted {
    font-size: 0.68rem;
    font-weight: 400;
}

/* ---------- Pronóstico ---------- */
.forecast-card {
    background: var(--theme-surface, #fff);
    border-radius: 10px; padding: 8px;
    border: 1px solid var(--theme-border, #dee2e6);
    margin-top: 10px;
    color: var(--theme-text, #212529);
}
.forecast-header {
    display: flex; justify-content: space-between; align-items: center;
    font-size: 0.85rem; font-weight: 600;
    color: var(--theme-primary, #167BA5);
    padding: 0 4px 6px;
    border-bottom: 1px solid var(--theme-border-soft, #f1f3f5);
}
.forecast-lugar {
    font-size: 0.7rem; color: var(--theme-muted, #6c757d);
    font-weight: 400; max-width: 55%;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.forecast-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; padding: 8px 0 4px; }
.forecast-grid {
    display: grid; grid-auto-flow: column;
    grid-auto-columns: minmax(66px, 1fr); gap: 6px; min-width: max-content;
}
.forecast-day {
    text-align: center; padding: 6px 2px;
    background: var(--theme-surface-soft, #f8f9fa);
    border-radius: 8px;
    border: 1px solid var(--theme-border-soft, #e9ecef);
    min-width: 66px;
}
.forecast-day .fc-day {
    font-size: 0.7rem; font-weight: 700;
    color: var(--theme-text, #495057);
    text-transform: uppercase; letter-spacing: 0.5px;
}
.forecast-day .fc-date { font-size: 0.6rem; color: var(--theme-muted, #adb5bd); margin-bottom: 2px; }
.forecast-day .fc-icon { font-size: 1.55rem; line-height: 1.2; margin: 3px 0; }
.forecast-day .fc-tmax { font-size: 0.8rem; font-weight: 700; color: #d63384; line-height: 1; }
.forecast-day .fc-tmin { font-size: 0.72rem; color: var(--theme-muted, #6c757d); line-height: 1.2; }
.forecast-day .fc-row {
    display: flex; align-items: center; justify-content: center; gap: 3px;
    font-size: 0.7rem; line-height: 1.4;
    margin-top: 3px; padding-top: 3px;
    border-top: 1px dashed var(--theme-border, #dee2e6);
}
.forecast-day .fc-rain { color: #0d6efd; font-weight: 600; }
.forecast-day .fc-wind { color: #198754; font-weight: 500; display: inline-flex; align-items: center; gap: 2px; }
.forecast-day .fc-wind-arrow { display: inline-block; font-size: 0.9rem; transition: transform 0.2s ease; }
.forecast-empty, .forecast-error { text-align: center; font-size: 0.8rem; color: var(--theme-muted, #6c757d); padding: 14px 12px; }
.forecast-error { color: var(--theme-danger, #dc3545); }
.forecast-legend {
    display: flex; justify-content: space-between; gap: 6px;
    font-size: 0.6rem; color: var(--theme-muted, #adb5bd);
    padding: 6px 4px 0;
    border-top: 1px solid var(--theme-border-soft, #f1f3f5);
    margin-top: 4px; flex-wrap: wrap;
}

/* ---------- Tablas analógicas ---------- */
#pred-analogos-box table {
    background: var(--theme-surface, #fff);
    border-radius: 6px; border-collapse: collapse;
    color: var(--theme-text, #212529);
}
#pred-analogos-box table th,
#pred-analogos-box table td {
    padding: 4px 6px;
    border-bottom: 1px solid var(--theme-border-soft, #f1f3f5);
}
#pred-analogos-box details summary {
    padding: 4px 0; list-style: none;
    color: var(--theme-muted, #6c757d);
}
#pred-analogos-box details summary::before {
    content: '▸ '; display: inline-block; transition: transform 0.15s ease;
}
#pred-analogos-box details[open] summary::before { transform: rotate(90deg); }

/* ---------- Simulador KPIs ---------- */
#sim-pwa-kpis .card-compact .card-body { padding: 8px 6px; }
#sim-pwa-kpis .card-compact h6 {
    font-size: 0.65rem; margin-bottom: 2px;
    color: var(--theme-muted, #6c757d);
    text-transform: uppercase; letter-spacing: 0.3px;
}
#sim-pwa-kpis .card-compact .text-muted { font-size: 0.6rem; }

/* ---------- Mi puerto ---------- */
#mp-header { transition: border-left-color 0.3s ease; }
#mp-estado-badge { font-size: 0.75rem; padding: 4px 10px; border-radius: 12px; font-weight: 600; }
#mp-chart { max-height: 160px; }
#mp-pred-chart { max-height: 180px; }
#mp-eventos-lista > div:last-child { border-bottom: 0 !important; }

/* Aviso de discrepancia ENSO (ventana ±6m vs serie extendida) */
#mp-enso-resumen .enso-notice {
    font-size: 0.63rem;
    opacity: 0.95;
    background: rgba(0, 0, 0, 0.04);
    border-left: 2px solid currentColor;
    padding: 4px 6px;
    border-radius: 3px;
    margin-top: 4px;
}
#mp-enso-resumen .enso-footnote {
    font-size: 0.6rem;
    opacity: 0.75;
    border-top: 1px dashed rgba(0, 0, 0, 0.12);
    padding-top: 4px;
    margin-top: 4px;
}

/* ---------- Ajustes mobile ---------- */
@media (max-width: 380px) {
    #info-panel .display-6 { font-size: 1.2rem; }
    .nav-btn { font-size: 1.1rem; }
    .nav-btn .small { font-size: 0.5rem; }
    #selector-metodo { font-size: 0.7rem; }
    .lugar-item .lugar-nombre { font-size: 0.75rem; }
}

/* ---------- Frame celular en desktop ---------- */
@media (min-width: 768px) {
    body {
        background-color: var(--theme-bg, #e9ecef);
        display: flex; justify-content: center; align-items: stretch;
        overflow: hidden;
    }
    #app {
        width: 420px; max-width: 100%;
        background-color: var(--theme-bg, #f8f9fa);
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.15);
        position: relative;
    }
    .navbar.fixed-top {
        width: 420px; left: 50%; transform: translateX(-50%);
    }
    #bottom-nav.fixed-bottom {
        width: 420px; left: 50%; transform: translateX(-50%);
    }
    #attribution-bar {
        width: 420px;
        left: 50%;
        transform: translateX(-50%);
    }
}

/* ---------- Splash ---------- */
#splash-overlay {
    position: fixed; inset: 0;
    background-color: var(--theme-surface, #fff);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    z-index: 9999;
    transition: opacity 0.4s ease;
    padding: 20px;
}
#splash-overlay.hide { opacity: 0; pointer-events: none; }
.splash-logo { width: 260px; max-width: 70vw; height: auto; animation: splash-pop 0.7s ease-out; }
.splash-spinner {
    margin-top: 32px; width: 32px; height: 32px;
    border: 3px solid var(--theme-border, #e5e7eb);
    border-top-color: var(--theme-primary, #0ea5e9);
    border-radius: 50%;
    animation: splash-spin 0.8s linear infinite;
}
@keyframes splash-spin { to { transform: rotate(360deg); } }
@keyframes splash-pop {
    from { opacity: 0; transform: scale(0.9); }
    to   { opacity: 1; transform: scale(1); }
}

/* ---------- Theme picker ---------- */
.dropdown-menu.theme-menu {
    background: var(--theme-surface, #fff);
    border: 1px solid var(--theme-border, #dee2e6);
    border-radius: 12px;
    box-shadow: 0 8px 24px var(--theme-shadow-strong, rgba(0,0,0,0.2));
    padding: 6px; min-width: 180px;
}
.dropdown-menu.theme-menu .dropdown-item.theme-item {
    padding: 8px 12px; border-radius: 8px;
    color: var(--theme-text, #212529);
    font-weight: 600; font-size: 0.9rem;
    transition: background 0.15s ease;
}
.dropdown-menu.theme-menu .dropdown-item.theme-item:hover,
.dropdown-menu.theme-menu .dropdown-item.theme-item:focus {
    background: var(--theme-surface-soft, #f8f9fa);
    color: var(--theme-primary, #167BA5);
}
.dropdown-menu.theme-menu .dropdown-item.theme-item.active {
    background: var(--theme-primary-light, #e7f1ff);
    color: var(--theme-primary, #167BA5);
    font-weight: 700;
}
.dropdown-menu.theme-menu .theme-item-label { flex: 1; }

/* ---------- Modal login ---------- */
#login-modal .active {
    background: var(--theme-primary, #167BA5) !important;
    color: #fff !important;
}
#login-modal input:focus {
    border-color: var(--theme-primary, #167BA5) !important;
    box-shadow: 0 0 0 3px var(--theme-focus-ring, rgba(22,123,165,0.18)) !important;
    outline: none;
}

/* ---------- Toast global de alertas ---------- */
#alerta-mensaje {
    position: sticky;
    top: 0;
    z-index: 1050;
    padding: 8px 12px;
    font-size: 0.82rem;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
    margin: -2px 0 8px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
#alerta-mensaje .btn-cerrar-alerta {
    background: transparent;
    border: 0;
    font-size: 1.15rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    opacity: 0.6;
    color: inherit;
    flex-shrink: 0;
}

/* ---------- Hero: mapa con overlay de bienvenida ---------- */
#hero-mapa {
    position: relative;
    margin-top: 4px;
    border-radius: 12px 12px 0 0;
    overflow: hidden;
}

#hero-mapa #map {
    /* Altura responsive: escala con el viewport (dvh) pero acotada
       para no romper layouts chicos ni desbordar en tablets.
       
       - 340px piso: en teléfonos chicos (iPhone SE 667px) deja lugar
         para el panel de info, la barra de nivel y los botones.
       - 55dvh medio: proporción del alto dinámico del viewport.
       - 560px techo: en tablets no llega a ocupar toda la pantalla.
       
       Antes era fijo 440px → en iPad (1133px) quedaba chico; en
       iPhone SE (667px) quedaba proporcionalmente grande. */
    height: 440px;                         /* fallback para navegadores viejos */
    height: clamp(340px, 55dvh, 560px);    /* moderno */

    margin: 0;
    border-radius: 0;
    border-bottom: none;
}

#welcome-screen.welcome-overlay {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(
        180deg,
        rgba(23, 70, 92, 0.10) 0%,
        rgba(23, 70, 92, 0.45) 100%
    );
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    z-index: 400;
    animation: fadeIn 0.3s ease;
}

.welcome-card-floating {
    background: var(--theme-surface, #fff);
    border-radius: 16px;
    padding: 24px 20px 20px;
    max-width: 340px;
    width: 100%;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
    text-align: center;
    animation: welcome-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes welcome-pop {
    from { opacity: 0; transform: translateY(16px) scale(0.94); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.welcome-card-floating .welcome-ico {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--theme-primary-light, #DDEDF4);
    color: var(--theme-primary, #167BA5);
    margin-bottom: 12px;
}

.welcome-card-floating h5 {
    font-weight: 700;
    font-size: 1.15rem;
    margin: 0 0 6px;
    color: var(--theme-text, #212529);
}

.welcome-card-floating p {
    font-size: 0.82rem;
    color: var(--theme-muted, #6c757d);
    line-height: 1.45;
    margin: 0 0 16px;
}

.welcome-card-floating .btn-primary {
    padding: 11px 18px;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(22, 123, 165, 0.28);
}

@media (max-height: 700px) {
    /* (mapa ahora usa clamp(340, 55dvh, 560) — se adapta solo) */
    .welcome-card-floating { padding: 18px 16px 16px; }
    .welcome-card-floating .welcome-ico { width: 52px; height: 52px; }
    .welcome-card-floating h5 { font-size: 1.05rem; }
    .welcome-card-floating p { font-size: 0.78rem; margin-bottom: 12px; }
}

/* ---------- Modo welcome: mapa a pantalla completa ---------- */
body.welcome-active #tab-ubicacion.active {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    animation: none;
}

body.welcome-active #tab-ubicacion.active #hero-mapa {
    flex: 1;
    display: flex;
    margin: 0;
    border-radius: 0;
    min-height: 0;
}

body.welcome-active #tab-ubicacion.active #hero-mapa #map {
    flex: 1;
    height: 100% !important;
    min-height: 0;
    border-radius: 0;
}

body.welcome-active #tab-ubicacion.active #barra-nivel {
    display: none;
}

body.welcome-active:has(#tab-ubicacion.active) #main-content {
    overflow: hidden;
    padding: 0;
}

@media (max-height: 700px) {
    body.welcome-active #tab-ubicacion.active #hero-mapa #map {
        height: 100% !important;
    }
}

/* ============================================================
   TAB COMPARAR — full screen con acciones al pie
   ============================================================ */

/* Cuando la tab Comparar está activa, main-content se vuelve flex column
   para que la tab pueda ocupar el 100% de la altura disponible */
body.comparing-mode #main-content {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

body.comparing-mode #tab-comparar.active {
    display: flex !important;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    animation: fadeIn 0.25s ease;
}

/* Bloque de controles: scrollea si no entra */
#comparar-controles {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding-bottom: 4px;
}

/* Gráfico: oculto hasta comparar. Ocupa todo el alto disponible */
#comparar-chart-box {
    display: none;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    margin-top: 6px;
    padding: 4px;
}

#comparar-chart-box.active {
    display: flex;
    flex-direction: column;
}

#comparar-chart-box canvas {
    width: 100% !important;
    height: 100% !important;
    max-height: none !important;
}

/* Acciones al pie: siempre visibles, botones altos */
#comparar-acciones {
    display: flex;
    gap: 6px;
    padding: 8px 0 6px;
    flex-shrink: 0;
    background: var(--theme-bg, #f8f9fa);
    border-top: 1px solid var(--theme-border-soft, #f1f3f5);
    margin-top: 6px;
}

#comparar-acciones .btn {
    height: 52px;
    padding: 0 14px;
    font-size: 0.92rem;
    font-weight: 600;
    border-radius: 10px;
}

#comparar-acciones #btn-comparar-eventos {
    flex: 2;
}

#comparar-acciones #btn-rehacer-comparacion {
    flex: 1;
    font-size: 0.82rem;
}

@media (max-height: 700px) {
    #comparar-acciones .btn { height: 46px; font-size: 0.85rem; }
    #comparar-acciones #btn-rehacer-comparacion { font-size: 0.78rem; }
}

/* ============================================================
   SIMULADOR — gráficos apilados (Camino 3)
   ============================================================ */
#sim-pwa-chart-box {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 6px;
}

.sim-chart-panel {
    background: var(--theme-surface, #fff);
    border: 1px solid var(--theme-border, #dee2e6);
    border-radius: 8px;
    padding: 4px 6px 2px;
}

.sim-chart-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--theme-text, #212529);
    padding: 2px 2px 4px;
    border-bottom: 1px solid var(--theme-border-soft, #f1f3f5);
    margin-bottom: 2px;
}

.sim-chart-title .ico {
    color: var(--theme-primary, #167BA5);
    flex-shrink: 0;
}

.sim-chart-subtitle {
    font-size: 0.62rem;
    font-weight: 400;
    color: var(--theme-muted, #6c757d);
    margin-left: auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sim-chart-canvas-wrap {
    position: relative;
    width: 100%;
}

.sim-chart-canvas-wrap canvas {
    width: 100% !important;
    height: 100% !important;
    max-height: none !important;
}

.sim-chart-contexto {
    font-size: 0.68rem;
    line-height: 1.4;
    padding: 6px 8px;
    background: var(--theme-surface-soft, #f8f9fa);
    border-radius: 6px;
    border-left: 3px solid var(--theme-primary, #167BA5);
    color: var(--theme-text, #212529);
}

.sim-chart-contexto .ctx-line {
    display: block;
    margin-bottom: 2px;
}

.sim-chart-contexto .ctx-warn {
    color: var(--theme-danger, #dc3545);
    font-weight: 600;
}

.sim-chart-contexto .ctx-ok {
    color: var(--theme-success-text, #1E4A2F);
    font-weight: 600;
}

.sim-chart-contexto .ctx-muted {
    color: var(--theme-muted, #6c757d);
    font-size: 0.62rem;
}

/* ============================================================
   MARKER DE UBICACIÓN — pin con halo pulsante
   ============================================================ */
.user-marker .user-marker-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: visible;
}

.user-marker .user-halo {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 64px;
    height: 64px;
    margin: -32px 0 0 -32px;
    border-radius: 50%;
    background: rgba(44, 115, 210, 0.30);
    animation: user-halo-pulse 2s ease-out infinite;
    pointer-events: none;
    z-index: 0;
}

.user-marker .user-marker-svg {
    position: relative;
    z-index: 1;
    display: block;
}

@keyframes user-halo-pulse {
    0%   { transform: scale(0.55); opacity: 0.75; }
    100% { transform: scale(1.5);  opacity: 0;    }
}

@media (prefers-reduced-motion: reduce) {
    .user-marker .user-halo { animation: none; opacity: 0.25; }
}