:root {
    --primary-color: #00AEEF;
    /* Cyan PP */
    --secondary-color: #0054A6;
    /* Azul PP */
    --bg-color: #f0f4f8;
    --card-bg: #ffffff;
    --text-main: #1a202c;
    --text-muted: #718096;
    --border-color: #e2e8f0;
    --success: #10b981;
    --danger: #e11d48;
    --header-bg: linear-gradient(135deg, #0054A6 0%, #007bbd 100%);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
}

.container, .wrapper {
    width: 100%;
    margin: 2rem auto;
    padding: 0 1.5rem;
    box-sizing: border-box;
}

.container {
    max-width: 1400px;
}

.wrapper {
    max-width: 1200px;
}

.card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    border: 1px solid var(--border-color);
    margin-bottom: 2rem;
    position: relative;
    overflow: hidden;
}

.section {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 2.5rem;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--border-color);
    margin-bottom: 2rem;
    position: relative;
    overflow: hidden;
}

.card:hover {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.section-title, .card-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--secondary-color);
    border-bottom: 2px solid #eee;
    padding-bottom: 0.5rem;
    margin-top: 0;
    display: block;
}

/* Filtros */
.filters-bar {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
    border: 1px solid var(--border-color);
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.filter-group label {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--secondary-color);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.filter-group select {
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    background-color: #fff;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

.filter-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 174, 239, 0.1);
}

/* Grid de resultados */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 1.5rem;
}

.col-4 {
    grid-column: span 4;
}

.col-8 {
    grid-column: span 8;
}

.col-12 {
    grid-column: span 12;
}

/* Tabla de resultados base */
.results-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

/* Tabla ancha (con scroll forzado) */
.results-table-wide {
    min-width: 1600px;
    table-layout: fixed;
}

/* Tabla compacta (para widgets/dashboards) */
.results-table-compact th,
.results-table-compact td,
.results-table.condensed th,
.results-table.condensed td {
    padding: 8px 12px !important;
    font-size: 0.85rem !important;
}

.results-table.condensed td {
    border-bottom: 1px solid #f1f5f9;
}

.results-table th,
.results-table td {
    padding: 12px 16px;
}

.results-table th.sticky-column,
.results-table td.sticky-column {
    min-width: 120px;
}

.results-table th,
.results-table td {
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.results-table th {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    background-color: #f8fafc !important;
    /* Fondo sólido */
}

/* Columna de Sección Sticky (Horizontal) - Primera Columna */
.sticky-col-1 {
    position: sticky !important;
    left: 0 !important;
    z-index: 50;
    /* Por encima de celdas normales */
    background-color: #ffffff !important;
    border-right: 1px solid var(--border-color) !important;
}

/* Columna de Censo/Total Sticky (Horizontal) - Segunda Columna */
.sticky-col-2 {
    position: sticky !important;
    left: 50px !important;
    /* Ancho de sticky-col-1 */
    z-index: 50;
    background-color: #ffffff !important;
    border-right: 2px solid var(--secondary-color) !important;
}

/* Columna de Mapa Sticky (Horizontal) - Derecha */
.sticky-right {
    position: sticky !important;
    right: 0 !important;
    z-index: 50;
    background-color: #ffffff !important;
    border-left: 1px solid var(--border-color) !important;
    box-shadow: -2px 0 5px rgba(0, 0, 0, 0.05);
}

/* Intersecciones de Cabecera (Sticky Horizontal + Vertical) */
.results-table thead th.sticky-col-1 {
    z-index: 151 !important;
    top: 0 !important;
    left: 0 !important;
    background: #f8fafc !important;
}

.results-table thead th.sticky-col-2 {
    z-index: 151 !important;
    top: 0 !important;
    left: 50px !important;
    background: #f8fafc !important;
}

.results-table thead th.sticky-right {
    z-index: 151 !important;
    top: 0 !important;
    right: 0 !important;
    background: #f8fafc !important;
}

.results-table thead th {
    position: sticky !important;
    top: 0;
    z-index: 100;
    background-color: #f8fafc !important;
    box-shadow: inset 0 -1px 0 var(--border-color);
}

.results-table tr:hover td {
    background: #f1f5f9;
}

.party-badge {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.party-color {
    width: 14px;
    height: 14px;
    border-radius: 4px;
}

@media (max-width: 1024px) {

    .col-4,
    .col-8 {
        grid-column: span 12;
    }
}

/* Utilidades de Mapa */
#map {
    height: 500px;
    min-height: 400px;
    width: 100%;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    z-index: 1;
    background: #f1f5f9;
    /* Color de fondo por si el mapa falla */
}

/* Utilidades de Tablas */
.table-container {
    overflow: auto;
    max-height: 750px;
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: white;
    position: relative;
}

/* Personalización de barra de scroll para que sea más visible */
.table-container::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

.table-container::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 10px;
}

.table-container::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 10px;
    border: 3px solid #f1f5f9;
}

.table-container::-webkit-scrollbar-thumb:hover {
    background-color: #94a3b8;
}

.sticky-header th {
    position: sticky;
    top: 0;
    z-index: 120;
    background: #f8fafc;
    border-bottom: 2px solid var(--border-color);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* Ajuste para cuando hay nav-bar sticky */
.nav-bar+.container .sticky-header th,
.nav-bar~.container .sticky-header th {
    top: 0;
    /* Si usamos scroll interno en el div, el top es 0 respecto al div */
}

/* Diferenciales (Sincrizado con pareto2.php legacy) */
.diff-plus {
    color: #10b981;
    font-weight: 600;
}

.diff-minus {
    color: #ef4444;
    font-weight: 600;
}

/* Estilos para informes de Brecha */
.isla-section {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 0;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.isla-header {
    background: #f8fafc;
    padding: 1rem 1.5rem;
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--secondary-color);
    border-bottom: 1px solid var(--border-color);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge-pp {
    background-color: var(--primary-color);
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 700;
    font-size: 0.75rem;
}

.votos-needed {
    color: var(--danger);
    font-weight: 700;
}

.votos-target {
    color: var(--success);
    font-weight: 700;
}

.total-row {
    background-color: #f1f5f9;
    font-weight: 800;
}

.total-label {
    color: var(--secondary-color);
}

/* Métricas de Resumen (Resumen superior) */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.metric-card {
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 120px;
}

.card-val {
    display: block;
    font-size: 2.25rem;
    font-weight: 800;
    color: var(--secondary-color);
    line-height: 1.1;
    margin-bottom: 0.5rem;
}

.card-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
}

/* Botón Mapa */
.map-btn {
    background: var(--secondary-color);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.map-btn:hover {
    background: var(--primary-color);
    transform: translateY(-1px);
}

/* Utilidades de alineación y espaciado */
.text-right {
    text-align: right !important;
    padding-right: 12px !important;
}

.text-center {
    text-align: center !important;
}

.text-left {
    text-align: left !important;
}

/* Nuevas Utilidades de Formularios y Layout (Basadas en Admin) */
.form-row {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.form-group {
    flex: 1;
    min-width: 240px;
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.6rem;
    font-weight: 600;
    color: var(--secondary-color);
    font-size: 1rem;
    letter-spacing: -0.01em;
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #edf2f7;
    border-radius: 10px;
    font-size: 1rem;
    transition: all 0.2s ease-in-out;
    background: #fff;
    box-sizing: border-box;
    color: var(--text-main);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(0, 174, 239, 0.15);
    background: #fcfdfe;
}

.btn-save, .btn-primary {
    background: var(--primary-color);
    color: white !important;
    border: none;
    padding: 10px 24px;
    border-radius: 10px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 12px rgba(0, 174, 239, 0.2);
    font-size: 1rem;
    display: inline-block;
    text-align: center;
    text-decoration: none;
}

.btn-save:hover, .btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0, 174, 239, 0.3);
    background: var(--secondary-color);
}

.alert {
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.alert-success {
    background: #ecfdf5;
    color: #065f46;
    border-left: 4px solid #10b981;
}

.alert-error {
    background: #fff1f2;
    color: #9f1239;
    border-left: 4px solid #e11d48;
}

hr {
    border: 0;
    border-top: 1px solid var(--border-color);
    margin: 1.5rem 0;
}