/* =========================================
   1. VARIABLES & RESET
   ========================================= */
:root {
    --bg: #0b1020;           
    --panel: #10172a;        
    --border: rgba(255, 255, 255, 0.08);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent: #38bdf8;       
    --accent-hover: #0ea5e9;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --radius: 12px;
    --header-height: 60px;
}

* { box-sizing: border-box; }

html { height: 100%; }

body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text-main);
    line-height: 1.5;
    font-size: 14px;
    padding-bottom: 40px;
    
    /* FIX: Permitir scroll si es necesario */
    overflow-x: auto; 
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    
    width: 100%;
    min-height: 100%;
}

/* =========================================
   2. HEADER
   ========================================= */
.site-header {
    background: rgba(16, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1000;
    padding: 0 12px;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.brand { 
    display: flex; flex-direction: column; justify-content: center; 
    flex: 1; min-width: 0; padding-right: 8px;
}

.brand h1 { 
    font-size: 15px; font-weight: 700; margin: 0; color: var(--text-main); 
    display: flex; align-items: center; gap: 6px; 
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.brand .subtitle { 
    font-size: 11px; color: var(--text-muted); 
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.brand h1 a { color: inherit; text-decoration: none; }

.logos-container {
    background-color: rgba(255, 255, 255, 0.9);
    padding: 4px 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.logo-img { height: 22px; width: auto; display: block; }

/* =========================================
   3. LAYOUT
   ========================================= */
.app-wrapper {
    max-width: 1600px;
    margin: 0 auto;
    padding: 12px;
    display: grid;
    gap: 16px;
    grid-template-columns: 1fr; 
    width: 100%;
}

@media (min-width: 1024px) {
    .app-wrapper {
        grid-template-columns: 320px 1fr; 
        align-items: start;
        padding: 16px;
    }
    .sidebar details { display: block; }
    .sidebar summary { pointer-events: none; }
    .sidebar summary::after { display: none; }
}

/* =========================================
   4. COMPONENTES UI
   ========================================= */
.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 16px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
}

.card-body { padding: 16px; }

h3 {
    font-size: 15px; font-weight: 600; margin: 0 0 12px 0;
    color: var(--accent); display: flex; align-items: center; gap: 8px;
}

label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; font-weight: 500; }

input, select, button {
    width: 100%; border-radius: 8px; padding: 10px 12px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: #0f172a; color: white; font-size: 14px; font-family: inherit;
    margin-bottom: 12px; appearance: none;
    box-sizing: border-box;
    max-width: 100%;
}

input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2); }

button.btn-primary {
    background: var(--accent); color: #0f172a; font-weight: 700;
    border: none; cursor: pointer; text-transform: uppercase;
    font-size: 13px; letter-spacing: 0.5px; transition: filter 0.2s; margin-bottom: 0;
}
button.btn-primary:hover { filter: brightness(1.1); }

.presets-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
button.btn-chip {
    background: rgba(255, 255, 255, 0.05); border: 1px solid var(--border);
    color: var(--text-muted); font-size: 12px; padding: 6px; margin-bottom: 0; cursor: pointer;
}
button.btn-chip:hover { background: rgba(255, 255, 255, 0.1); color: white; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* AJUSTE LISTA PROVINCIAS */
#provSelect {
    flex: 1; 
    min-width: 0; 
    width: 0; /* Truco Flex para móviles */
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23cbd5e1%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat; background-position: right 12px center; background-size: 10px; padding-right: 30px;
    text-overflow: ellipsis;
}

#btnGoProv {
    white-space: nowrap; background: rgba(255, 255, 255, 0.1); border: 1px solid var(--border); color: var(--accent);
    width: auto; flex-shrink: 0;
}
#btnGoProv:hover { background: var(--accent); color: #000; }

/* =========================================
   5. ACORDEONES
   ========================================= */
details { width: 100%; }
summary {
    list-style: none; padding: 14px 16px; font-weight: 600; cursor: pointer;
    display: flex; align-items: center; justify-content: space-between;
    background: rgba(255, 255, 255, 0.02); border-bottom: 1px solid transparent;
    transition: background 0.2s;
}
summary::after { content: '+'; font-size: 18px; font-weight: 400; color: var(--text-muted); }
details[open] summary { border-bottom: 1px solid var(--border); background: rgba(255, 255, 255, 0.04); color: var(--accent); }
details[open] summary::after { content: '−'; }
summary::-webkit-details-marker { display: none; }
details[open] .card-body { animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }

/* =========================================
   6. KPIS
   ========================================= */
.kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 0; }
@media (min-width: 768px) { .kpi-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1200px) { .kpi-grid { grid-template-columns: repeat(6, 1fr); } }

.kpi-card {
    background: rgba(255, 255, 255, 0.03); border: 1px solid var(--border);
    border-radius: 8px; padding: 12px; text-align: center;
}
.kpi-label { font-size: 10px; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.5px; margin-bottom: 4px; }
.kpi-value { font-size: 18px; font-weight: 700; color: var(--text-main); }

/* =========================================
   7. MAPA
   ========================================= */
#map { width: 100%; height: 400px; background: #000; z-index: 1; }
@media (min-width: 768px) { #map { height: 550px; } }
.map-credits {
    padding: 8px 12px; font-size: 11px; color: var(--text-muted);
    background: rgba(0,0,0,0.2); border-top: 1px solid var(--border); text-align: right;
}

/* =========================================
   8. GRÁFICOS Y TABLAS
   ========================================= */
.grid-2-col { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 768px) { .grid-2-col { grid-template-columns: 1fr 1fr; } }

.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; width: 100%; display: block; }
table { width: 100%; border-collapse: collapse; font-size: 13px; white-space: nowrap; }
th, td { padding: 10px; border-bottom: 1px solid var(--border); text-align: left; }
th { background: rgba(255, 255, 255, 0.03); color: var(--accent); font-weight: 600; }
td.num { font-feature-settings: "tnum"; }

/* =========================================
   9. EXTRAS
   ========================================= */
.alert-info {
    background: rgba(59, 130, 246, 0.1); border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 8px; padding: 12px; font-size: 12px; color: #bfdbfe; margin-top: 16px;
}
ul.bullets { padding-left: 20px; font-size: 13px; color: #cbd5e1; }
ul.bullets li { margin-bottom: 6px; }

/* =========================================
   10. CONTAINERS
   ========================================= */
.map-container { position: relative; height: 500px; width: 100%; overflow: hidden; border-radius: 12px; }
#windyFrame { width: 100%; height: 100%; position: absolute; top: 0; left: 0; z-index: 10; background: #0b1020; display: none; }

/* =========================================
   11. BOTONES CLIMA (FIX MULTILINEA + TAMAÑO)
   ========================================= */
.climate-tabs {
    display: flex;
    gap: 8px;
    /* Permitir que bajen a otra línea */
    flex-wrap: wrap;
    /* Centrar para que se vea ordenado */
    justify-content: center; 
    padding-bottom: 8px;
    margin-bottom: 10px;
    width: 100%;
}

.climate-btn {
    background: rgba(255,255,255,0.05); 
    border: 1px solid var(--border); 
    color: var(--text-muted);
    padding: 8px 16px; 
    border-radius: 20px; 
    white-space: nowrap;
    cursor: pointer; 
    font-size: 13px; 
    font-weight: 500;
    transition: all 0.2s; 
    display: flex; 
    align-items: center; 
    gap: 6px;
    
    /* IMPORTANTE: Anular el 100% global de los botones */
    width: auto !important; 
    max-width: none;
    flex-grow: 0;
}
.climate-btn:hover { background: rgba(255,255,255,0.1); color: white; }
.climate-btn.active { background: var(--accent); color: #001122; border-color: transparent; font-weight: 700; }