/* Configuración básica */
body, html {
    margin: 0; padding: 0; width: 100%; height: 100%;
    font-family: Arial, sans-serif; overflow: hidden;
}
.container { display: flex; width: 100%; height: 100%; }

/* Sidebar */
.sidebar {
    width: 600px; min-width: 400px; height: 100vh;
    background: #f4f4f4; padding: 20px;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1);
    overflow-y: auto; z-index: 1000; box-sizing: border-box;
}

/* Info Distrito */
#district-info {
    padding: 10px; background: #ffffff; border-radius: 5px; margin-bottom: 20px;
    text-align: center; border: 1px solid #ddd; box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
#district-info h3 { margin: 0 0 5px 0; color: #333; }


/* Esta regla ahora SOLO se aplica al <p> del sub-distrito */
#district-parent { 
    margin: 0; 
    font-size: 0.9em; 
    color: #777; 
}

/* Botón Deseleccionar */
#deselect-btn {
    display: none; width: 100%; padding: 8px; margin-top: 15px;
    background-color: #555; color: white; border: none; border-radius: 4px;
    cursor: pointer; font-size: 0.9em;
}
#deselect-btn:hover { background-color: #333; }

/* Grupo Filtros y Gráficos */
.filter-group { margin-bottom: 20px; }

/* Estilo "AI Policy Insight" */
#ai-insight-box {
    margin-top: 25px;
    padding: 15px;
    background: #ffffff; /* Fondo blanco */
    border-radius: 8px;
    border: 1px solid #ddd; /* Borde estándar */
    box-shadow: 0 1px 3px rgba(0,0,0,0.05); /* Sombra sutil */
}
#ai-insight-box h4 {
    margin-top: 0;
    margin-bottom: 10px;
    color: #6a1b9a; /* Color púrpura "AI" */
    display: flex; /* Para alinear el icono */
    align-items: center;
    gap: 8px; /* Espacio entre icono y texto */
    justify-content: center; /* Centra el título y el icono */
}
#ai-insight-box h4 svg {
    flex-shrink: 0; /* Evita que el icono se encoja */
}
#ai-insight-text {
    font-style: normal; /* Texto normal */
    color: #333; /* Texto más oscuro */
    padding-top: 10px;
    border-top: 1px solid #eee; /* Separador limpio */
    margin-top: 10px;
    margin-bottom: 0; /* Reseteo */
}

/* Mapa */
#map { flex: 1; height: 100vh; background: #e0e0e0; }
.leaflet-interactive { cursor: pointer; }

/* Leyenda Mapa */
.info.legend {
    padding: 8px; background: rgba(255,255,255,0.8); box-shadow: 0 0 15px rgba(0,0,0,0.2);
    border-radius: 5px; line-height: 1.5; color: #555;
}
.info.legend i { width: 18px; height: 18px; float: left; margin-right: 8px; opacity: 0.7; }
.info.legend small { display: block; color: #777; margin-top: 5px;}


/* --- BUSCADOR PERSONALIZADO CON 'X' --- */
#search-wrapper { position: relative; width: 100%; }
#district-search {
    width: 100%; padding: 10px 30px 10px 10px; /* Espacio para 'x' */
    font-size: 1.1em; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box;
}
#search-clear-btn {
    position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
    font-size: 1.5em; line-height: 1; color: #aaa; cursor: pointer; display: none;
}
#search-clear-btn:hover { color: #333; }

/* Autocompletar */
#autocomplete-results {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    background-color: #fff; border: 1px solid #ddd; border-top: none;
    border-radius: 0 0 4px 4px; box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    max-height: 250px; overflow-y: auto; z-index: 2000;
}
.autocomplete-item { padding: 10px; cursor: pointer; text-align: left; }
.autocomplete-item:hover { background-color: #f4f4f4; }
.autocomplete-item strong { color: #6a1b9a; }
/* --- FIN BUSCADOR --- */


/* Asa Redimensionar */
.sidebar-resizer {
    width: 5px; height: 100vh; background: #ddd; cursor: ew-resize;
    transition: background 0.2s; z-index: 999;
}
.sidebar-resizer:hover { background: #6a1b9a; }

/* Tasa Dependencia */
#dependency-ratio-wrapper { margin-top: 15px; padding-top: 10px; border-top: 1px solid #eee; }
#dependency-ratio-wrapper h3 { margin: 0; font-size: 2em; transition: color 0.3s; }
#dependency-ratio-wrapper > .label-with-tooltip > p { margin: 0 8px 0 0; font-size: 0.9em; color: #666; text-transform: uppercase; }


/* --- INICIO: SECCIÓN DE TOOLTIPS UNIFICADA (LIMPIA) --- */

/* Contenedor principal para el icono y el texto (para alinear) */
.label-with-tooltip { 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    margin-bottom: 5px; 
    gap: 8px;
}

/* El 'trigger' del tooltip (el icono de información) */
.info-tooltip {
    position: relative;
    display: flex;
    align-items: center;
    cursor: default; 
}

/* Estilo del icono SVG */
.info-tooltip svg {
    width: 18px;
    height: 18px;
    color: #007bff; 
    transition: all 0.2s ease-in-out;
}
.info-tooltip:hover svg {
    color: #0056b3; 
    transform: scale(1.1);
}

/* La caja de texto del tooltip (oculta por defecto) */
.info-tooltip .tooltip-text {
    visibility: hidden;
    opacity: 0;
    position: absolute;
    width: 280px;
    background-color: #ffffff;
    color: #333; /* Color de texto base */
    text-align: left;
    border-radius: 10px;
    padding: 16px; 
    
    /* Fuente y tamaño base aplicados al contenedor */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 0.95rem; /* 15.2px */
    
    box-shadow: 0 4px 6px rgba(0,0,0,0.04), 0 8px 24px rgba(0,0,0,0.1);
    border: 1px solid #e0e0e0;
    z-index: 3000;
    transition: opacity 0.3s ease, transform 0.3s ease;
    
    /* Posición por defecto: a la izquierda y centrada */
    top: 50%;
    right: 105%;
    transform: translateY(-50%) scale(0.95);
}

/* --- INICIO: LA SOLUCIÓN DEL NODO FANTASMA --- */

/* 1. MATA la altura de línea de los nodos de texto fantasma */
.info-tooltip .tooltip-text {
    /* ... (todos los estilos que ya tiene) ... */
    line-height: 0; /* ¡AQUÍ ESTÁ LA MAGIA! */
}

/* 2. DEVUELVE la altura de línea a los elementos HTML REALES */
.info-tooltip .tooltip-text > * {
    line-height: 1.5; /* El valor original que queríamos */
}

/* --- ESTILOS DE CONTENIDO INTERNO (AHORA FUNCIONARÁN) --- */

/* Título (strong) principal */
.info-tooltip .tooltip-text > strong {
    font-size: 1.1em; /* 110% del tamaño base */
    color: #6a1b9a;
    margin-bottom: 12px; /* Espacio después del título */
    display: block;
    font-weight: 600;
}

/* Párrafos (p) dentro del tooltip */
.info-tooltip .tooltip-text p {
    /* Hereda font-size y color del padre (.tooltip-text) */
    font-weight: normal; 
    text-transform: none; 
    margin-top: 0;
    margin-bottom: 12px; /* Espacio estándar entre párrafos */
}

/* Negrita (strong) DENTRO de un párrafo */
.info-tooltip .tooltip-text p strong,
.info-tooltip .tooltip-text p b {
    color: #000; 
    font-weight: bold;
    display: inline;
}

/* Separador HR */
.info-tooltip .tooltip-text hr {
    border: 0; 
    border-top: 1px solid #eee; 
    
    /* Solución al margen doble: */
    margin-top: 0; /* El párrafo de arriba ya tiene 12px */
    margin-bottom: 12px; /* Espacio antes del siguiente párrafo */
}

/* El último elemento (párrafo O hr) no tiene margen inferior */
.info-tooltip .tooltip-text p:last-child,
.info-tooltip .tooltip-text hr:last-child {
    margin-bottom: 0;
}

/* --- FIN DE ESTILOS DE CONTENIDO --- */


/* --- MODIFICADOR DE POSICIÓN TOOLTIP (REVISADO) --- */

/* Clase 'tooltip-top' para forzar la apertura hacia arriba (para AI Policy Insight) */
.info-tooltip .tooltip-text.tooltip-top {
    /* Sobrescribe la posición vertical y lateral */
    top: auto;
    bottom: 100%; /* 1. Alinea la base del tooltip con la cima del icono */
    margin-bottom: 8px; /* 2. Añade un espacio */
    
    right: 50%;
    left: auto;
    
    /* Centra horizontalmente y resetea la transformación Y */
    transform: translateX(50%) scale(0.95);
}

/* Ajuste del hover para la nueva transformación */
.info-tooltip:hover .tooltip-text.tooltip-top {
    transform: translateX(50%) scale(1);
}

/* (Pega esto en style.css, justo después del bloque .tooltip-top) */

/* --- MODIFICADOR DE POSICIÓN TOOLTIP (HACIA ABAJO) --- */
.info-tooltip .tooltip-text.tooltip-bottom {
    top: 100%; /* 1. Se alinea CON LA PARTE SUPERIOR del icono */
    bottom: auto; /* Resetea el 'bottom' */
    margin-top: 8px; /* 2. Añade un espacio */
    
    right: 50%;
    left: auto;
    
    /* Centra horizontalmente y resetea la transformación Y */
    transform: translateX(50%) scale(0.95);
}

/* Ajuste del hover para la nueva transformación */
.info-tooltip:hover .tooltip-text.tooltip-bottom {
    transform: translateX(50%) scale(1);
}

/* Leyenda Ratio */
.dependency-ratio-legend { display: flex; justify-content: center; gap: 15px; margin-top: 10px; font-size: 0.8em; color: #666; }
.dependency-ratio-legend div { display: flex; align-items: center; }
.dependency-ratio-legend .color-box { width: 12px; height: 12px; margin-right: 5px; border-radius: 2px; }
.color-box.ratio-low { background-color: #28a745; } /* Verde */
.color-box.ratio-medium { background-color: #ffc107; } /* Naranja */
.color-box.ratio-high { background-color: #dc3545; } /* Rojo */

/* Botones Año */
#year-button-group { display: flex; justify-content: space-between; margin-top: 10px; }
.year-btn {
    flex: 1; padding: 10px 5px; font-size: 1em; font-weight: bold;
    background-color: #ddd; color: #333; border: none; border-radius: 4px;
    cursor: pointer; transition: background-color 0.2s, color 0.2s; margin: 0 3px;
}
.year-btn:first-child { margin-left: 0; }
.year-btn:last-child { margin-right: 0; }
.year-btn:hover { background-color: #ccc; }
.year-btn.active { background-color: #6a1b9a; color: white; }

/* Botones Filtro IA */
#ai-filter-box { margin-top: 25px; padding: 15px; background: #fff; border-radius: 8px; border: 1px solid #ddd; }
#ai-filter-box h4 { margin-top: 0; }


/* Esta regla ahora SOLO se aplica al <p> de descripción */
#ai-filter-box > p { 
    font-size: 0.9em; 
    color: #777; 
    margin: -5px 0 10px 0; 
text-align: center;
}

#ai-filter-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ai-filter-btn {
    padding: 10px; font-size: 0.9em; font-weight: bold; background-color: #eee;
    color: #555; border: 1px solid #ddd; border-radius: 4px; cursor: pointer; transition: all 0.2s;
}
.ai-filter-btn:hover { background-color: #ddd; border-color: #ccc; }
.ai-filter-btn.clear { background-color: #f8f8f8; color: #777; }
.ai-filter-btn.active { background-color: #6a1b9a; color: white; border-color: #6a1b9a; }


/* === ESTILOS PARA FILTROS AI (MODIFICADOS) === */

/* Regla general para los wrappers que contienen H4 + Icono */
.ai-filter-header, 
.ai-chat-title-wrapper, 
#ai-insight-box > .h4-with-tooltip /* <-- Sé más específico aquí */ {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

/* Los H4 dentro de estos wrappers NO necesitan ser flex */
.ai-filter-header h4,
.ai-chat-title-wrapper h4,
#ai-insight-box h4 {
    margin: 0; /* Asegura que no haya márgenes extraños */
    /* Quitamos el display: flex de aquí */
}

/* Color específico para Ask AI que pediste */
.ai-chat-title-wrapper h4 {
    color: #6a1b9a; 
}

/* Color específico para AI Policy Insight */
#ai-insight-box h4 {
     color: #6a1b9a; /* Ya estaba, pero lo ponemos aquí por claridad */
     margin-bottom: 10px; /* Restauramos su margen inferior específico */
}

/* El título del Filtro (AI Trend Filter) no necesita color especial */
.ai-filter-header h4 {
    color: #6a1b9a;
}

.ai-filter-header {
    display: flex;
    flex-direction: row; /* <-- Asegura que h4 e icono estén en línea */
    justify-content: center; /* <-- Centra el h4 y el icono */
    align-items: center;
    gap: 8px; /* Espacio entre título e icono */
    position: relative; /* Para los tooltips */
    z-index: 11; 
}


/* 1. Estilo para el contenedor del botón + tooltip */
.ai-filter-btn-wrapper {
    position: relative; /* Contenedor para el tooltip absoluto */
    display: flex; /* Asegura que el botón se expanda */
    z-index: 1; /* z-index base para el solapamiento */
}

/* Eleva el wrapper entero al pasar el ratón para que el tooltip
   se muestre por encima de los botones hermanos */
.ai-filter-btn-wrapper:hover {
    z-index: 10;
}

/* 2. Haz que el botón principal crezca */
.ai-filter-btn-wrapper .ai-filter-btn {
    flex-grow: 1; /* El botón ocupa todo el espacio */
    padding-right: 30px;
    text-align: center;
}

/* 3. Posiciona el icono del tooltip */
.ai-filter-btn-wrapper .info-tooltip {
    position: absolute;
    top: 50%;
    right: 10px; /* 10px desde el borde derecho */
    transform: translateY(-50%); /* Centrado vertical */
}

/* 4. Centra tooltips para botones de COLUMNA DERECHA */
/* (El primer botón es el 'clear-wrapper', por eso empezamos en 3) */
.ai-filter-btn-wrapper:nth-child(3) .tooltip-text,
.ai-filter-btn-wrapper:nth-child(5) .tooltip-text {
    top: 50%; /* Centra verticalmente */
    transform: translateY(-50%); /* Centra verticalmente */
    right: 105%; /* Mantiene la dirección a la izquierda */
}

/* 5. Centra tooltips para botones de COLUMNA IZQUIERDA */
.ai-filter-btn-wrapper:nth-child(even) .tooltip-text {
    right: auto;
    left: 105%;
    margin-right: 0;
    top: 50%; /* Centra verticalmente */
    transform: translateY(-50%); /* Centra verticalmente */
}


/* 6. Haz que el botón "Clear" ocupe las dos columnas */
.ai-filter-btn-wrapper.clear-wrapper {
    grid-column: 1 / -1; /* Ocupa todo el ancho del grid */
}

/* --- ESTILOS PARA EL CHATBOT DE IA --- */
#ai-chat-wrapper {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #eee;
}

#ai-chat-wrapper label {
    display: block;
    font-size: 0.9em;
    font-weight: bold;
    color: #666;
    margin-bottom: 8px;
    text-align: left;
}

#ai-chat-input {
    width: 100%;
    box-sizing: border-box; /* Para que el padding no rompa el ancho */
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-family: Arial, sans-serif;
    font-size: 0.95rem;
    line-height: 1.4;
    resize: vertical; /* Permite redimensionar verticalmente */
    margin-bottom: 10px;
}

#ai-chat-submit {
    width: 100%;
    padding: 10px;
    font-size: 1em;
    font-weight: bold;
    background-color: #6a1b9a; /* Púrpura "AI" */
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 40px; /* Altura fija */
}

#ai-chat-submit:hover {
    background-color: #4a148c;
}

#ai-chat-submit:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

#ai-chat-response {
    margin-top: 15px;
    padding: 12px;
    background: #fdfdfd;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    font-size: 0.95rem;
    line-height: 1.5;
    color: #333;
    display: none; /* Oculto por defecto */
}

/* --- ESTILO DEL SPINNER DE CARGA --- */
.button-spinner {
    width: 18px;
    height: 18px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
/* --- ESTILOS DE ROBUSTEZ (v4.0) --- */

/* 1. Estilo para la respuesta de error */
#ai-chat-response.error {
    background-color: #fff5f5; /* Rojo pálido */
    border-color: #e53e3e;     /* Borde rojo */
    color: #c53030;            /* Texto rojo oscuro */
}

/* 2. Contenedor para las preguntas sugeridas */
#ai-suggested-questions {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
margin-bottom: 12px;
}

/* 3. Estilo de los botones de sugerencia */
.suggested-q-btn {
    padding: 6px 10px;
    font-size: 0.85em;
    font-weight: bold;
    background-color: #f0e6f6; /* Púrpura muy pálido */
    color: #6a1b9a;            /* Púrpura "AI" */
    border: 1px solid #d1b3e6;
    border-radius: 20px;       /* Píldoras */
    cursor: pointer;
    transition: all 0.2s;
}

.suggested-q-btn:hover {
    background-color: #e0c2f0;
    border-color: #6a1b9a;
}


/* ===== ESTILOS PANELES PLEGABLES (v4.5 - v3.0) ===== */

/* 1. El Contenedor Principal (la caja blanca) */
.collapsible-container {
    background: #ffffff;
    border-radius: 8px;
    border: 1px solid #ddd;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    margin-bottom: 20px;
    overflow: hidden; /* ¡Clave para la animación! */
}

/* 2. La Cabecera Clicable */
.collapsible-header {
    display: flex;
    justify-content: space-between; /* <-- Esto empuja el título a la izq y la flecha a la der */
    align-items: center;
    cursor: pointer;
    padding: 12px 15px;
    background: #f9f9f9;
    border-bottom: 1px solid #eee;
    transition: border-color 0.3s ease;
}
.collapsible-header:hover {
    background: #f1f1f1;
}
.collapsible-header h3 {
    margin: 0;
    font-size: 1.1em;
    color: #444;
}

/* 3. El Icono de Flecha (SVG) */
.toggle-icon {
    width: 18px;
    height: 18px;
    transition: transform 0.3s ease;
    color: #555;
    transform: rotate(0deg); /* Estado por defecto: abierto */
}

/* 4. El Contenido (que se oculta) */
.collapsible-content {
    /* Animación de altura */
    max-height: 2000px; /* Un valor alto para el estado abierto */
    transition: max-height 0.4s ease-out, padding 0.4s ease-out;
    
    /* El padding que antes definimos en los paneles (AI, Metrics) */
    padding: 15px;
    box-sizing: border-box;
}

/* 5. EL ESTADO COLAPSADO */
.collapsible-container.collapsed .collapsible-content {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    border-top: none;
}
.collapsible-container.collapsed .collapsible-header {
     /* Mantiene el borde inferior cuando está cerrado */
     border-bottom-color: #ddd;
}
.collapsible-container.collapsed .toggle-icon {
    transform: rotate(-90deg); /* Gira la flecha */
}
#ai-analysis-panel > .collapsible-header {
    /* Quitamos justify-content, position, align y gap */
    /* Dejamos que herede el 'space-between' de .collapsible-header */
}


/* --- Ajustes a los paneles que AHORA están DENTRO --- */

/* PANEL 2: AI ANALYSIS */
#ai-analysis-panel {
    padding: 0; /* El padding lo maneja el .collapsible-content */
}
#ai-analysis-panel > .collapsible-header > h3 {
    color: #6a1b9a; /* Mantiene el título púrpura */
}
#ai-insight-box {
    margin-top: 0;
    padding: 0;
    border: none;
    box-shadow: none;
}
/* Mueve el filtro AI (que está dentro del panel) */
#ai-filter-box {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #eee; /* Separador */
}


/* PANEL 3: KEY METRICS */
#key-metrics-panel {
    padding: 0; /* El padding lo maneja el .collapsible-content */
    text-align: center;
}
#dependency-ratio-wrapper { 
    margin-top: 0; 
    padding-top: 0; 
    border-top: none; 
}


/* PANEL 4: DATA VISUALS */
#data-visuals-panel {
    margin-top: 25px;
    display: flex;
    flex-direction: column;
    gap: 15px; /* Espacio entre gráficos */
}
.chart-container {
    padding: 0; /* El padding lo maneja el .collapsible-content */
}
.chart-container .collapsible-content {
    padding: 15px; /* Restaura el padding para los canvas */
}

/* --- ESTILOS PARA EL CHATBOT DE IA (v4.5) --- */

/* Cabecera del Chat (v4.5) */
#ai-chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
#ai-chat-header label {
    /* Sobrescribe el estilo de label anterior */
    display: block;
    font-size: 0.9em;
    font-weight: bold;
    color: #666;
    margin-bottom: 0; /* El wrapper maneja el margen */
    text-align: left;
}
/* El tooltip de modo debe ser un poco más pequeño */
#ai-chat-mode-tooltip svg {
    width: 16px;
    height: 16px;
    color: #666;
}
#ai-chat-mode-tooltip:hover svg {
    color: #333;
}

/* Hack para listas <ul> en tooltips (para el nuevo tooltip de ayuda) */
.info-tooltip .tooltip-text ul {
    line-height: 1.5;
    padding-left: 20px;
    margin-bottom: 0;
    margin-top: 12px;
}
.info-tooltip .tooltip-text li {
    margin-bottom: 5px;
}

/* === ARREGLO PARA CENTRAR TÍTULOS (H4) === */
.h4-with-tooltip, .h-with-tooltip {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px; /* Espacio entre el texto y el icono */
}

/* --- INICIO: ARREGLO BUG 2 (PLAN B) --- */
/* 1. Estilo del Contenedor Global del Tooltip */

.global-tooltip-container {
    /* --- Posicionamiento --- */
    position: fixed; /* ¡Clave! Se posiciona relativo a la ventana, no al sidebar */
    top: 0;
    left: 0;
    z-index: 9999; /* Por encima de todo */
    
    /* --- Estilo Visual (copiado de .tooltip-text) --- */
    width: 280px;
    background-color: #ffffff;
    color: #333;
    text-align: left;
    border-radius: 10px;
    padding: 16px; 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 0.95rem; /* 15.2px */
    box-shadow: 0 4px 6px rgba(0,0,0,0.04), 0 8px 24px rgba(0,0,0,0.1);
    border: 1px solid #e0e0e0;
    
    /* --- Comportamiento --- */
    pointer-events: none; /* ¡Clave! El ratón pasa "a través" de él */
    transition: opacity 0.2s ease;
    opacity: 0;
}

/* 2. Estilos del contenido (copiados de .tooltip-text) */
/* (Re-declaramos los estilos para asegurarnos de que se aplican) */

.global-tooltip-container {
    line-height: 0; /* Arreglo del nodo fantasma */
}
.global-tooltip-container > * {
    line-height: 1.5; /* Devuelve la altura de línea */
}
.global-tooltip-container > strong {
    font-size: 1.1em;
    color: #6a1b9a;
    margin-bottom: 12px;
    display: block;
    font-weight: 600;
}
.global-tooltip-container p {
    font-weight: normal; 
    text-transform: none; 
    margin-top: 0;
    margin-bottom: 12px;
}
.global-tooltip-container p strong,
.global-tooltip-container p b {
    color: #000; 
    font-weight: bold;
    display: inline;
}
.global-tooltip-container hr {
    border: 0; 
    border-top: 1px solid #eee; 
    margin-top: 0;
    margin-bottom: 12px;
}
.global-tooltip-container p:last-child,
.global-tooltip-container hr:last-child {
    margin-bottom: 0;
}
.global-tooltip-container ul {
    line-height: 1.5;
    padding-left: 20px;
    margin-bottom: 0;
    margin-top: 12px;
}
.global-tooltip-container li {
    margin-bottom: 5px;
}
/* 1. Estilo del nuevo separador <hr> */
hr.ai-separator {
    border: 0;
    border-top: 1px solid #eee;
    margin: 25px 0 20px 0; /* Da espacio entre las dos secciones */
}

/* 2. Estilo del nuevo título "Ask AI" y su wrapper */
.ai-chat-title-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-bottom: 15px; /* Espacio antes del chat */
}
.ai-chat-title-wrapper h4 {
    margin: 0;
    color: #6a1b9a; /* Un color de subtítulo estándar */
}

/* 3. Limpieza: ajusta el margen superior del chat-wrapper */
#ai-chat-wrapper {
    margin-top: 0; /* El wrapper del título ya tiene margen */
    padding-top: 0;
    border-top: none; /* El <hr> es el nuevo separador */
}

/* 4. Arreglo "Preguntas Rarillas" (Bug 3) */
#ai-suggested-questions {
    margin-top: 10px;
    margin-bottom: 12px;
    display: grid; /* <-- CAMBIO de flex a grid */
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); /* <-- La magia */
    gap: 8px;
}
/* --- INICIO: ARREGLO BUG 4 (Key Metrics Grid) --- */

/* 1. Estilo de la nueva cuadrícula 2x2 */
#metrics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr; /* Dos columnas de igual tamaño */
    gap: 15px; /* Espacio entre las cajas */
}

/* 2. Estilo de cada caja de métrica */
.metric-box {
    background-color: #fdfdfd;
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 10px;
    text-align: center;
}

/* 3. Estilo de la etiqueta (ej. "Total Population") */
.metric-label {
    margin: 0 0 5px 0;
    font-size: 0.9em;
    color: #666;
    text-transform: uppercase;
}

/* 4. Estilo del valor (ej. "120,450") */
.metric-value {
    margin: 0;
    font-size: 1.8em; /* Más pequeño que el 2em de antes */
    transition: color 0.3s;
}

/* 5. Asegura que el tooltip centrado funcione en la caja */
.metric-box .label-with-tooltip {
    /* (Ya tiene display:flex, justify-content:center) */
    margin-bottom: 5px; /* Sobrescribe el default */
}
.metric-box .label-with-tooltip p {
    margin: 0; /* Resetea el p dentro del label */
}

/* 6. Estilo de la leyenda pequeña para la ratio (MEJORADO) */
.dependency-ratio-legend-small {
    display: flex; /* <-- Usa flexbox */
    justify-content: center; /* <-- Centra los items */
    align-items: center; /* <-- Alinea verticalmente */
    gap: 10px; /* <-- Espacio entre items */
    font-size: 0.75em; /* <-- Un poco más pequeña */
    color: #888;
    margin-top: 4px;
}
.dependency-ratio-legend-small span { /* Estilo para cada grupo (caja + texto) */
    display: inline-flex; /* <-- Alinea caja y texto */
    align-items: center;
}
.dependency-ratio-legend-small .color-box {
    width: 10px;
    height: 10px;
    display: inline-block;
    border-radius: 2px;
    margin-right: 4px; /* <-- Espacio entre caja y texto */
    vertical-align: middle; /* Ya no es necesario con flex, pero no hace daño */
}
/* (Los colores .ratio-low, etc. ya están definidos) */


/* 7. Limpieza: Elimina estilos antiguos que ya no usamos */
#dependency-ratio-wrapper {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}
/* (La leyenda grande .dependency-ratio-legend ya no existe) */

/* --- INICIO: ARREGLO ESPACIO GRÁFICOS (POST-DRAG) --- */

/*
 * Le dice al contenedor de paneles móviles que use flexbox 
 * y ponga un espacio de 15px entre CADA panel.
 * Esto es mucho más limpio que lo que te dije antes.
*/
#sortable-panels-container {
    display: flex;
    flex-direction: column;
    
}

/* * El panel de AI ya tiene un <hr> encima, así que
 * no necesita el 'gap' de 15px.
*/

/* * Limpieza: elimina los estilos del ID que hemos borrado
 * para que no causen problemas en el futuro.
*/
#data-visuals-panel {
    display: block; /* Resetea el flex */
    gap: 0;
    margin-top: 0;
}

/* --- FIN: ARREGLO ESPACIO GRÁFICOS --- */

/* --- INICIO: ESTILOS DRAG-AND-DROP (SORTABLEJS) --- */

/* 1. Cursor de "mover" en las cabeceras */
#sortable-panels-container .collapsible-header {
    cursor: grab; /* Indica que se puede arrastrar */
}
#sortable-panels-container .collapsible-header:active {
    cursor: grabbing; /* Cambia el cursor mientras se arrastra */
}

/* 2. Estilo del "fantasma" (el elemento que sigues arrastrando) */
.sortable-ghost {
    opacity: 0.4;
    background: #c8ebfb; /* Un azul claro */
}

/* 3. Estilo del elemento mientras se arrastra (opcional, pero ayuda) */
.sortable-drag {
    opacity: 0.9 !important; /* Un poco transparente */
    box-shadow: 0 4px 15px rgba(0,0,0,0.1); /* Añade sombra */
}

/* --- INICIO: ARREGLO GLITCH GRÁFICOS (v2) --- */

/* 1. Oculta el canvas por defecto (si no tiene chart-ready) */
.chart-container .collapsible-content canvas {
    visibility: hidden;
}

/* 2. Muestra el canvas solo cuando JS nos de permiso */
.chart-container .collapsible-content.chart-ready canvas {
    visibility: visible;
    transition: none; /* Asegura que no haya un retraso visual */
}

/* --- MEJORA: TÍTULO DEL DASHBOARD CON SUBTÍTULO --- */

.control-header {
    /* Le damos un poco más de espacio */
    padding: 18px 20px;
}

.header-title-wrapper h2 { /* Título Principal */
    margin: 0 0 4px 0; /* Espacio pequeño debajo */
    font-size: 1.3em;
    font-weight: 700;
    color: #ffffff; /* Texto blanco (ya lo tiene) */
}

.header-title-wrapper p { /* Subtítulo */
    margin: 0;
    font-size: 0.9em;
    font-weight: 400;
    color: #ced4da; /* Un gris claro para el subtítulo */
}

/* --- INICIO: MEJORA DE ESTILOS (TÍTULO INTEGRADO + FILTROS) --- */

/* 1. Estructura de la Barra Lateral y Encabezado */
.sidebar {
    background-color: #ffffff; /* Fondo blanco (coherencia) */
    padding: 0; 
    box-shadow: 2px 0 5px rgba(0,0,0,0.1); 
    border-radius: 0;
}

/* 2. Contenedor de Filtros (Ahora contiene TODO) */
.control-container {
    padding: 0 20px; /* Padding lateral */
    margin-bottom: 20px;
}

/* 3. Nuevo Título Integrado */
.header-title-wrapper {
    padding: 20px 0 15px 0; /* Padding superior e inferior */
    text-align: left;
}
.header-title-wrapper h2 {
    margin: 0 0 4px 0;
    font-size: 1.6em; /* Más grande, es el título principal */
    font-weight: 700;
    color: #333; /* Color oscuro, no blanco */
}
.header-title-wrapper p {
    margin: 0;
    font-size: 1.0em;
    font-weight: 400;
    color: #6a1b9a; /* Color acento púrpura */
}

/* 4. Separador Limpio */
hr.header-separator {
    border: 0;
    border-top: 1px solid #eee;
    margin: 0 0 15px 0; /* Espacio antes del panel de distrito */
}

/* 5. Panel de Información de Distrito (Ajuste ligero) */
#district-info {
    padding: 10px 0 10px 0; /* Padding vertical más ajustado */
    background: #ffffff;
    border: none;
    box-shadow: none;
    text-align: left;
    margin-bottom: 10px;
    border-bottom: 1px solid #eee;
}
#district-info h3 {
    font-size: 1.5em;
    font-weight: 700;
    color: #000;
    margin: 0 0 2px 0;
}
#district-parent {
    font-size: 0.95em;
    color: #6c757d;
    margin: 0 0 15px 0;
}
#deselect-btn {
    width: 100%;
    padding: 8px 12px;
    background-color: #6c757d;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 600;
    transition: background-color 0.2s;
}
#deselect-btn:hover {
    background-color: #5a6268;
}

/* 6. Etiquetas de Filtro */
.filter-group {
    margin-bottom: 20px;
}
.filter-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #495057;
    font-size: 0.9em;
}

/* 7. Botones de Año (Estilo Píldora) */
#year-button-group {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 5px;
    margin-top: 0;
}
.year-btn {
    flex: 0;
    padding: 8px 5px;
    font-size: 0.9em;
    font-weight: 600;
    background-color: #f8f9fa;
    color: #343a40;
    border: 1px solid #dee2e6;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s;
    margin: 0;
    text-align: center;
}
.year-btn:hover:not(.active) {
    background-color: #e9ecef;
    border-color: #ced4da;
}
.year-btn.active {
    background-color: #6a1b9a;
    color: white;
    border-color: #6a1b9a;
}

/* 8. Botones de Tema de Mapa (Estilo Píldora) */
#map-theme-group {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* 2 columnas */
    gap: 5px;
}
.map-theme-btn {
    flex: 0;
    padding: 8px 10px;
    border: 1px solid #dee2e6;
    background-color: #f8f9fa;
    color: #343a40;
    border-radius: 5px;
    font-size: 0.9em;
    font-weight: 600;
    transition: all 0.2s ease;
}
.map-theme-btn.active {
    background-color: #6a1b9a;
    color: white;
    border-color: #6a1b9a;
    box-shadow: none;
}
.map-theme-btn:hover:not(.active) {
    background-color: #e9ecef;
}

/* 9. Arreglo de Espacio (GAP) */
.control-container .filter-group:last-child {
    margin-bottom: 0; /* Quita el espacio extra antes de los paneles */
}
/* --- FIN: MEJORA DE ESTILOS (TÍTULO INTEGRADO + FILTROS) --- */
/* --- ESTILOS PARA LA GUÍA RÁPIDA (TOOLTIP) --- */

/* 1. Contenedor para el Título H2 y el icono de Ayuda */
.main-title-group {
    display: flex;
    align-items: center;
    gap: 10px; /* Espacio entre el título y el icono '?' */
}

/* 2. Estilo del icono '?' de la guía */
#guide-tooltip svg {
    color: #aaa; /* Un gris sutil */
    transition: color 0.2s;
}
#guide-tooltip:hover svg {
    color: #6a1b9a; /* Color de acento al pasar el ratón */
}

/* 3. Ajusta el ancho del tooltip de la guía */
#guide-tooltip-text {
    width: 320px; /* Un poco más ancho para la lista */
}



/* --- Foco visible ---
 *
 * El fichero no tenia ni una regla :focus. Con teclado se navegaba a ciegas:
 * el foco existia y no se veia por ninguna parte. :focus-visible solo lo pinta
 * cuando la navegacion es de teclado, asi que el raton sigue igual que antes. */
:focus-visible {
    outline: 3px solid #6a1b9a;
    outline-offset: 2px;
    border-radius: 3px;
}

.autocomplete-item:focus-visible,
.autocomplete-item:hover {
    background: #f3e5f5;
    outline-offset: -3px;
}

/* Quien navegue con teclado necesita poder saltarse la lista de 1.545 nombres. */
.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    background: #6a1b9a;
    color: #fff;
    padding: 0.6rem 1rem;
    z-index: 10000;
}
.skip-link:focus {
    left: 0;
}
