/* =========================================
   1. CONFIGURACIÓN GENERAL
   ========================================= */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    font-family: 'Inter', sans-serif;
    background-color: #f6f7f9; /* Fondo gris muy suave */
    overflow: hidden;
    color: #333;
}

/* =========================================
   2. LAYOUT PRINCIPAL
   ========================================= */
.app-container {
    position: relative;
    height: 100vh;
    width: 100vw;
    display: flex;
}

/* El mapa ocupa todo el fondo */
#map-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    background-color: #f6f7f9; /* Color mar/fondo por defecto */
}

/* =========================================
   3. SIDEBAR (Barra Izquierda Flotante)
   ========================================= */
.sidebar {
    position: absolute;
    top: 90px;
    left: 20px;
    width: 48px;
    background: #ffffff;
    border-radius: 8px; /* Bordes redondeados */
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 0;
    z-index: 1000;
    box-shadow: 0 2px 12px rgba(0,0,0,0.1); /* Sombra suave */
}

.sidebar-item {
    width: 32px;
    height: 32px;
    margin-bottom: 8px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #5f6368;
    transition: all 0.2s ease;
}

.sidebar-item:hover {
    background-color: #f1f3f4;
    color: #000;
}

.sidebar-item.active {
    background-color: #e8f0fe;
    color: #1a73e8;
}

.sidebar-item i {
    font-size: 1rem;
}

/* =========================================
   4. PANEL DE INFORMACIÓN (Derecha Flotante)
   ========================================= */
.info-panel {
    position: absolute;
    top: 20px;
    right: 20px;
    bottom: 20px; /* Deja espacio abajo también */
    width: 460px;
    background: #ffffff;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12); /* Sombra más profunda */
    border-radius: 16px; /* Curva característica de Electricity Maps */
    z-index: 999;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    transform: translateX(0);
    overflow: hidden; /* Para respetar los bordes redondeados */
}

.info-panel.hidden {
    transform: translateX(120%); /* Se esconde completamente */
}

/* Cabecera del Panel */
/* --- ACTUALIZACIÓN DE CABECERA --- */
.panel-header {
    padding: 20px 24px;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: space-between; /* Separa Titulo/Flecha de la X */
    background-color: #fff;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Estilo genérico para botones de navegación (Flecha y X) */
.nav-btn {
    background: #f5f5f5;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    color: #555;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 1rem;
}

.nav-btn:hover {
    background-color: #e0e0e0;
    color: #000;
}

/* Estilo específico para la X (rojo suave al hover opcional) */
.close-btn:hover {
    background-color: #ffebee;
    color: #c62828;
}

/* Clase utilitaria para ocultar elementos (la usaremos en la flecha) */
.hidden-element {
    display: none !important;
}

/* =========================================
   5. MÉTRICAS (Estilo Tarjetas Limpias)
   ========================================= */
.metrics-container {
    padding: 24px;
    background-color: #fff;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

/* Cuadros de métricas minimalistas */
.metric-card {
    background: #ffffff;
    border: 1px solid #e0e0e0; /* Borde muy sutil */
    border-radius: 12px;
    padding: 12px 4px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.metric-card:hover {
    border-color: #ccc;
    transform: translateY(-2px);
}

.metric-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: #202124;
    display: block;
}

.metric-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
    display: block;
}

.metric-icon {
    margin-top: 8px;
    font-size: 1rem;
    color: #5f6368;
    opacity: 0.7;
}

/* =========================================
   6. LISTA DE PROYECTOS (Estilo iOS/Moderno)
   ========================================= */
.projects-section {
    flex-grow: 1;
    padding: 0 24px 24px 24px;
    background-color: #fff;
    
    /* NUEVO: Crea un scroll interno solo para la lista */
    overflow-y: auto; 
    min-height: 0; /* Vital para que el scroll funcione en Flexbox */
}

.projects-section h3 {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    color: #9aa0a6;
    margin-top: 10px;
    margin-bottom: 15px;
    letter-spacing: 0.8px;
}

#projects-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.project-item {
    padding: 16px 0;
    border-bottom: 1px solid #f1f3f4;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.project-item:last-child {
    border-bottom: none;
}

.project-info strong {
    display: block;
    font-size: 0.95rem;
    color: #202124;
    margin-bottom: 4px;
}

/* Badges (Etiquetas de colores pastel) */
.badge {
    font-size: 0.7rem;
    padding: 4px 10px;
    border-radius: 20px; /* Pill shape */
    font-weight: 600;
    letter-spacing: 0.3px;
}

/* Colores inspirados en Electricity Maps */
.badge.local { background-color: #e8f5e9; color: #2e7d32; }      /* Verde */
.badge.provincial { background-color: #e3f2fd; color: #1565c0; } /* Azul */
.badge.regional { background-color: #fff3e0; color: #ef6c00; }   /* Naranja */
.badge.nacional { background-color: #f3e5f5; color: #7b1fa2; }   /* Morado */


/* =========================================
   7. TOOLTIP FLOTANTE (Estilo Electricity Maps)
   ========================================= */

/* Limpieza del estilo por defecto de Leaflet */
.leaflet-tooltip.custom-tooltip {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
}

.leaflet-tooltip-top:before {
    display: none; /* Quitar la flechita de abajo */
}

/* La tarjeta que sigue al mouse */
.tooltip-card {
    background-color: rgba(255, 255, 255, 0.95); /* Ligeramente translúcido */
    backdrop-filter: blur(5px); /* Efecto blur de fondo (Glassmorphism) */
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    padding: 16px;
    font-family: 'Inter', sans-serif;
    min-width: 200px;
    text-align: center;
    border: 1px solid rgba(0,0,0,0.05);
}

.tooltip-header {
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 12px;
    color: #202124;
    padding-bottom: 8px;
    border-bottom: 1px solid #eee;
}

.tooltip-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.tooltip-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #f8f9fa;
    border-radius: 8px;
    padding: 6px;
}

.tooltip-val { 
    font-weight: 700; 
    font-size: 0.95rem; 
    color: #333; 
}

.tooltip-lbl { 
    font-size: 0.6rem; 
    color: #888; 
    text-transform: uppercase; 
    margin-top: 2px;
    font-weight: 600;
}

/* --- FIX: Quitar borde de selección (Caja Negra) --- */
path.leaflet-interactive:focus {
    outline: none;
}

/* Opcional: Transición suave para los cambios de color */
path.leaflet-interactive {
    transition: fill-opacity 0.2s, stroke-width 0.2s;
}

/* --- ESTILO DE BANDERA --- */
.country-flag {
    width: 28px;        /* Tamaño equilibrado con el texto */
    height: auto;       /* Mantiene proporción */
    border-radius: 4px; /* Bordes suaves estilo Electricity Maps */
    box-shadow: 0 1px 3px rgba(0,0,0,0.2); /* Sombrita sutil para profundidad */
    display: block;     /* Evita comportamientos extraños de línea */
}

.brand-logo-floating {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 1000;
    /* Eliminamos background, padding, border-radius y box-shadow */
    background: transparent;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    
    display: flex;
    align-items: center;
    justify-content: center;
    height: auto; /* Dejamos que la imagen defina la altura */
    box-sizing: border-box;
}

/* 2. La imagen del logo: ajustamos el tamaño para que sea sutil */
.brand-logo-floating img {
    /* Hacemos el logo un poco más pequeño para que no invada */
    max-height: 60px; 
    width: auto;
    display: block;
    /* Opcional: añadir una sombra muy sutil solo al texto/logo 
       si se pierde con el fondo del mapa */
    filter: drop-shadow(0px 1px 2px rgba(0,0,0,0.5)); 
}

/* --- GRÁFICO DE TORTA/DONA (Ajustado) --- */
.chart-section {
    padding: 15px 0;
    background-color: #fff;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 160px;
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;

    /* NUEVO: Evita que la lista inferior lo aplaste */
    flex-shrink: 0; 
}

/* El contenedor del canvas controlará el ancho máximo visual */
.chart-container-inner {
    position: relative;
    height: 100%;
    width: 100%;             /* Usa todo el ancho disponible */
    max-width: 400px;        /* ANTES: 320px -> AHORA: 400px (Más espacio para la leyenda) */
    display: flex;
    justify-content: center;
}

canvas#myChart {
    max-height: 100%;
    max-width: 100%;
}

/* =========================================
   LEYENDA DE COLORES (Bottom Left)
   ========================================= */
.map-legend {
    position: absolute;
    bottom: 20px;
    left: 20px;
    z-index: 1000; /* Para que flote sobre el mapa */
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
    padding: 12px 16px;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.1);
    font-family: 'Inter', sans-serif;
    width: 140px;
}

.map-legend h4 {
    margin: 0 0 10px 0;
    font-size: 0.75rem;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 6px;
    font-size: 0.75rem;
    color: #333;
    font-weight: 500;
}

.legend-item:last-child {
    margin-bottom: 0;
}

.color-box {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    margin-right: 10px;
    display: inline-block;
}

#details-view-container {
    position: absolute;
    top: 0; 
    left: 68px; /* Salva la barra lateral oscura */
    width: calc(100% - 68px);
    height: 100vh;
    background-color: #f6f7f9;
    z-index: 500;
    
    /* LA MAGIA ESTÁ AQUÍ EN EL PADDING:
       Arriba: 110px (Deja espacio libre para tu logo CircularTec)
       Derecha: 510px (Deja espacio para el panel derecho de 460px + margen)
       Abajo: 40px, Izquierda: 40px
    */
    padding: 110px 510px 40px 40px; 
    
    box-sizing: border-box;
    overflow-y: auto;
}

.details-header {
    margin-bottom: 30px;
}

.details-header h2 {
    margin: 0 0 10px 0;
    font-size: 1.8rem;
    color: #202124;
}

.details-table {
    width: 100%;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    border-collapse: collapse;
}

.details-table th {
    background: #e8f0fe;
    color: #1a73e8;
    text-align: left;
    padding: 16px 20px;
    font-weight: 600;
}

.details-table td {
    padding: 16px 20px;
    border-bottom: 1px solid #f0f0f0;
    color: #444;
    line-height: 1.5;
    vertical-align: top;
}

.details-table tr:hover td {
    background-color: #fafafa;
}

/* Enlaces en la tabla y panel derecho */
.initiative-link {
    color: #1a73e8;
    text-decoration: none;
    font-weight: 500;
    word-break: break-all; /* Evita que links largos rompan el diseño */
}

.initiative-link:hover {
    text-decoration: underline;
}

/* Botón flotante para ver detalle en panel derecho */
.btn-ver-detalle {
    display: block;
    width: 100%;
    text-align: center;
    background: #e8f0fe;
    color: #1a73e8;
    padding: 10px;
    border-radius: 8px;
    margin-top: 15px;
    text-decoration: none;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
}

.btn-ver-detalle:hover {
    background: #d2e3fc;
}

/* =========================================
   COLAPSO DE PANEL Y RESALTADOS (NUEVO)
   ========================================= */

/* Transición para colapsar el panel sin cerrarlo (X) */
.info-panel.collapsed {
    transform: translateX(120%);
}

/* El botón que muestra/oculta el panel en la vista Detalles */
.floating-toggle-btn {
    background: #ffffff;
    color: #1a73e8;
    border: 1px solid #e8f0fe;
    padding: 10px 16px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.floating-toggle-btn:hover {
    background: #f8faff;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* Animación del padding cuando el panel se oculta/muestra */
#details-view-container {
    transition: padding 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* Clase que aplicamos cuando el panel está oculto para darle ancho total a la tabla */
#details-view-container.panel-collapsed {
    padding-right: 40px !important; 
}

/* Diseño de la lista de iniciativas en el panel derecho */
.initiative-list-item {
    cursor: pointer;
    padding: 10px;
    border-radius: 6px;
    transition: background 0.2s;
    color: #1a73e8;
    font-size: 0.85rem;
    font-weight: 500;
    line-height: 1.4;
}

.initiative-list-item:hover {
    background-color: #f1f3f4;
}

.ini-id-badge {
    color: #5f6368;
    font-weight: 700;
    margin-right: 5px;
}

/* Efecto de resaltado al darle click a una iniciativa */
.details-table tr.highlight-row td {
    background-color: #fff8e1 !important; /* Amarillo suave */
    transition: background-color 0.5s ease-out;
    border-top: 2px solid #ffb300;
    border-bottom: 2px solid #ffb300;
}

/* =========================================
   MODAL DE PROPUESTAS
   ========================================= */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(3px);
}

.modal-content {
    background: #fff;
    width: 90%;
    max-width: 500px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 24px;
    background: #f8f9fa;
    border-bottom: 1px solid #eee;
}

.modal-header h3 { margin: 0; color: #202124; }

.modal-body { padding: 24px; }

.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 5px; font-weight: 500; font-size: 0.85rem; color: #444; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 6px; box-sizing: border-box; font-family: 'Inter', sans-serif;
}

.btn-submit {
    width: 100%; padding: 12px; background: #1a73e8; color: white; border: none; border-radius: 6px; font-weight: 600; cursor: pointer; transition: 0.2s; margin-top: 10px;
}
.btn-submit:hover { background: #1557b0; }
