/* =======================================================
   1. VARIABLES Y DISEÑO DEL SISTEMA (Design Tokens)
======================================================= */
:root {
    --color-primario: #1e293b;    
    --color-secundario: #3b82f6;  
    --color-acento: #10b981;      
    
    --bg-body: #f8fafc;           
    --bg-superficie: #ffffff;     
    
    --texto-principal: #334155;   
    --texto-claro: #f1f5f9;       
    --texto-gris: #64748b;
    
    --sombra-suave: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --sombra-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --transicion: all 0.3s ease;
    --radius-card: 12px;
    
    --fuente-base: 'Inter', system-ui, -apple-system, sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--fuente-base);
    background-color: var(--bg-body);
    color: var(--texto-principal);
    line-height: 1.6;
}

a {
    text-decoration: none;
    color: inherit;
}
/* =======================================================
   PANTALLA DE CARGA (PRELOADER)
======================================================= */
#preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background-color: var(--color-primario); /* Fondo institucional oscuro */
    z-index: 9999; /* Asegura que esté por encima de TODO (mapas, modales, menús) */
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.preloader-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 25px; /* Separación entre el logo y el círculo de carga */
}

.preloader-logo {
    height: 80px; /* Un poco más grande que en la barra de navegación */
    width: auto;
    /* Animación de latido (crece y se encoge suavemente) */
    animation: latido 1.5s infinite alternate ease-in-out;
}

/* El círculo que gira */
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1); /* Borde transparente */
    border-top-color: var(--color-secundario); /* Borde azul brillante que gira */
    border-radius: 50%;
    animation: girar 1s linear infinite;
}

/* Clase que aplicará JavaScript para ocultarlo con un desvanecimiento (Fade-out) */
.preloader-oculto {
    opacity: 0;
    visibility: hidden;
}

/* Keyframes de las animaciones */
@keyframes latido {
    0% { transform: scale(0.95); opacity: 0.8; }
    100% { transform: scale(1.05); opacity: 1; }
}

@keyframes girar {
    to { transform: rotate(360deg); }
}
/* =======================================================
   2. HEADER Y NAVEGACIÓN
======================================================= */
/* Agrega esto para controlar el tamaño de tu nuevo logo */
.navbar .logo {
    display: flex;
    align-items: center;
}

.logo-img {
    height: 45px; /* Ajusta este número si lo quieres más grande o más pequeño */
    width: auto;  /* Esto mantiene las proporciones correctas */
    transition: transform 0.3s ease;
}

/* Opcional: Un pequeño efecto cuando pasen el mouse sobre el logo */
.logo-img:hover {
    transform: scale(1.05);
}

.header-global { display: flex; flex-direction: column; }

.navbar {
    background-color: var(--color-primario);
    padding: 1rem 5%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: var(--sombra-suave);
}

.navbar-brand .logo {
    color: var(--texto-claro);
    font-size: 1.5rem;
    font-weight: 700;
}

.navbar-brand .logo span { color: var(--color-secundario); }

.nav-links { display: flex; gap: 2rem; list-style: none; }

.nav-item {
    color: var(--texto-claro);
    font-weight: 500;
    font-size: 0.95rem;
    padding: 0.5rem 0;
    position: relative;
    transition: var(--transicion);
}

.nav-item::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0;
    width: 0%; height: 2px;
    background-color: var(--color-secundario);
    transition: var(--transicion);
}

.nav-item:hover::after { width: 100%; }
.nav-item:hover { color: var(--bg-superficie); }

.menu-toggle {
    display: none; background: none; border: none; cursor: pointer; flex-direction: column; gap: 5px;
}
.menu-toggle .bar { width: 25px; height: 3px; background-color: var(--texto-claro); border-radius: 3px; }

/* BANNER */
.banner-hero {
    position: relative; height: 180px; display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.banner-bg { position: absolute; width: 100%; height: 100%; object-fit: cover; z-index: 1; }
.banner-overlay {
    position: absolute; width: 100%; height: 100%;
    background: linear-gradient(to right, rgba(30, 41, 59, 0.85), rgba(30, 41, 59, 0.4)); z-index: 2;
}
.banner-content { position: relative; z-index: 3; text-align: center; color: var(--texto-claro); }
.banner-content h1 { font-size: 2rem; font-weight: 800; margin-bottom: 0.2rem; }
.banner-content p { font-size: 1rem; opacity: 0.9; }

/* =======================================================
   3. DASHBOARD MAIN CONTAINER
======================================================= */
.dashboard-container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 20px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* =======================================================
   4. SECCIÓN DE FILTROS Y NAVEGACIÓN (Tarjetas top)
======================================================= */
/* Filtro */
.filtro-dashboard-card {
    background-color: var(--bg-superficie);
    padding: 1.5rem;
    border-radius: var(--radius-card);
    box-shadow: var(--sombra-suave);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid #e2e8f0;
}
.filtro-dashboard-text h2 { font-size: 1.2rem; color: var(--color-primario); margin-bottom: 5px; }
.filtro-dashboard-text p { color: var(--texto-gris); font-size: 0.9rem; }
.filtro-dashboard-select {
    padding: 0.6rem 1rem;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    font-size: 1rem;
    outline: none;
    cursor: pointer;
    background-color: var(--bg-body);
}

/* Tarjetas de Navegación */
.nav-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}
.nav-card {
    background: var(--bg-superficie);
    border-radius: var(--radius-card);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    box-shadow: var(--sombra-suave);
    border: 1px solid #e2e8f0;
    transition: var(--transicion);
}
.nav-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--sombra-hover);
    border-color: var(--color-secundario);
}
.nav-card-text { flex-grow: 1; }
.nav-card-text h3 { font-size: 1.1rem; color: var(--color-primario); }
.nav-card-text p { font-size: 0.85rem; color: var(--texto-gris); margin-top: 3px; }
.nav-card .arrow { color: #cbd5e1; font-size: 1.2rem; }

/* Cajas de Iconos */
.icon-box {
    width: 50px; height: 50px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.4rem; color: white;
    margin-right: 1rem;
}

/* =======================================================
   5. TARJETAS KPI (Métricas numéricas)
======================================================= */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
}
.kpi-card {
    background-color: var(--bg-superficie);
    padding: 1.5rem;
    border-radius: var(--radius-card);
    box-shadow: var(--sombra-suave);
    border: 1px solid #e2e8f0;
}
.kpi-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--texto-gris);
    margin-bottom: 0.8rem;
}
.kpi-card h2 { font-size: 2.5rem; font-weight: 800; color: var(--color-primario); line-height: 1; margin-bottom: 0.5rem; }

/* =======================================================
   6. GRID PRINCIPAL (Mapa y Widgets Laterales)
======================================================= */
.main-grid {
    display: grid;
    grid-template-columns: 2fr 1fr; /* El mapa ocupa el doble que los widgets */
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.card {
    background-color: var(--bg-superficie);
    border-radius: var(--radius-card);
    box-shadow: var(--sombra-suave);
    border: 1px solid #e2e8f0;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}
.card-header h3 { font-size: 1.1rem; color: var(--color-primario); border-bottom: 1px solid #e2e8f0; padding-bottom: 10px; margin-bottom: 15px; }

/* Mapa */
.map-container {
    height: 450px;
    width: 100%;
    background-color: #e2e8f0; /* Color temporal mientras carga Leaflet */
    z-index: 1; /* Para evitar problemas de superposición con el navbar */
}

/* Barras de Progreso (Provincias) */
.progress-bar { margin-bottom: 1.2rem; }
.progress-label { display: flex; justify-content: space-between; font-size: 0.9rem; font-weight: 600; color: var(--texto-principal); margin-bottom: 5px; }
.track { background-color: #f1f5f9; height: 8px; border-radius: 4px; overflow: hidden; }
.fill { height: 100%; border-radius: 4px; transition: width 0.8s ease; }

/* Gráfico de dona */
.chart-container { position: relative; height: 220px; width: 100%; display: flex; justify-content: center;}

/* =======================================================
   7. MODAL (Detalle de Obra)
======================================================= */
.modal-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(15, 23, 42, 0.6); backdrop-filter: blur(4px);
    z-index: 2000; justify-content: center; align-items: center;
}
.modal-contenido {
    background-color: var(--bg-superficie);
    width: 90%; max-width: 450px;
    border-radius: var(--radius-card);
    padding: 2rem; position: relative;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}
.modal-cerrar {
    position: absolute; top: 15px; right: 20px;
    font-size: 1.8rem; cursor: pointer; color: var(--texto-gris); transition: var(--transicion);
}
.modal-cerrar:hover { color: #ef4444; }
.modal-cabecera { margin-bottom: 1.5rem; }
.etiqueta-estado { display: inline-block; padding: 4px 10px; border-radius: 20px; font-size: 0.8rem; font-weight: 600; background: #e0e7ff; color: #4338ca; margin-bottom: 10px; }
.texto-principal { font-size: 1.3rem; color: var(--color-primario); margin-bottom: 5px; line-height: 1.3; }
.texto-secundario { font-size: 0.9rem; color: var(--texto-gris); }
.modal-cuerpo { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dato-bloque { background-color: var(--bg-body); padding: 12px; border-radius: 8px; display: flex; flex-direction: column; }
.dato-etiqueta { font-size: 0.8rem; color: var(--texto-gris); margin-bottom: 4px; }
.dato-valor { font-size: 1rem; font-weight: 700; color: var(--color-primario); }
.btn-primary { display: block; text-align: center; background-color: var(--color-secundario); color: white; padding: 12px; border-radius: 8px; font-weight: 600; transition: var(--transicion); border: none; cursor: pointer; }
.btn-primary:hover { background-color: #2563eb; }

/* =======================================================
   8. CLASES UTILITARIAS DE COLORES
======================================================= */
.bg-blue { background-color: #3b82f6; }
.bg-teal { background-color: #14b8a6; }
.bg-purple { background-color: #8b5cf6; }
.bg-yellow { background-color: #f59e0b; }
.text-green { color: #10b981 !important; }

/* =======================================================
   9. DISEÑO RESPONSIVO (Tablets y Móviles)
======================================================= */
@media screen and (max-width: 992px) {
    .main-grid { grid-template-columns: 1fr; } /* El mapa y widgets se apilan */
}

@media screen and (max-width: 768px) {
    .menu-toggle { display: flex; }
    .nav-links {
        position: absolute; top: 100%; right: -100%; width: 250px; height: 100vh;
        background-color: var(--color-primario); flex-direction: column; align-items: center;
        padding-top: 2rem; transition: right 0.4s ease; box-shadow: -5px 0 15px rgba(0,0,0,0.1); gap: 1rem;
    }
    .nav-links.active { right: 0; }
    .filtro-dashboard-card { flex-direction: column; align-items: stretch; gap: 15px; text-align: center; }
    .nav-cards { grid-template-columns: 1fr; }
}