:root {
    --primary: #7e22ce; 
    --primary-light: #a855f7;
    --primary-dark: #581c87;
    --secondary: #0f172a; /* Oscurecido para mayor elegancia */
    --bg-color: #fdfdfd; /* Blanco super limpio */
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #94a3b8; /* Gris más suave y elegante */
    --success: #10b981;
    /* Sombras minimalistas y suaves */
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.02);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.03);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.06);
    --radius-md: 1rem; /* Más redondeado y moderno */
    --radius-lg: 1.25rem;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    padding: 2rem;
    min-height: 100vh;
    overflow-x: hidden;
    max-width: 100vw;
}

.dashboard-container {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #1e1b4b 0%, var(--primary-dark) 100%);

    padding: 1.5rem 2rem;
    border-radius: var(--radius-lg);
    color: white;
    box-shadow: var(--shadow-md);
}

header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Segment Controls */
.segment-control {
    display: flex;
    background: rgba(255, 255, 255, 0.2);
    padding: 0.25rem;
    border-radius: 2rem;
    backdrop-filter: blur(10px);
}

.segment-btn {
    background: transparent;
    border: none;
    color: white;
    padding: 0.5rem 1.25rem;
    border-radius: 2rem;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
}

.segment-btn.active {
    background: white;
    color: var(--primary-dark);
    box-shadow: var(--shadow-sm);
}

/* Section Titles */
.section-title {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-main);
    letter-spacing: -0.01em;
}

/* Cards Generic */
.card {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    padding: 1.75rem;
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(0,0,0,0.03);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    min-width: 0; /* Crucial para prevenir desbordes de grid/flex con canvas */
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* Yearly Grid (Section 2) */
.yearly-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1.5rem;
}

.year-col {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
}

.year-header {
    text-align: center;
    font-size: 1.1rem;
    font-weight: 700;
    color: #ffffff;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    padding: 0.6rem 1rem;
    border-radius: var(--radius-md);
    letter-spacing: 0.05em;
    box-shadow: 0 4px 10px rgba(126, 34, 206, 0.15);
    margin-bottom: 0.25rem;
}

.metric-block {
    text-align: center;
}

.metric-label {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.metric-value {
    font-size: 1.85rem;
    font-weight: 800;
    color: var(--text-main);
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.5rem;
    letter-spacing: -0.03em;
}

.growth-badge {
    font-size: 0.875rem;
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
    padding: 0.2rem 0.5rem;
    border-radius: 1rem;
    font-weight: 600;
}

/* Charts Section (Section 3) */
.charts-section {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 1.5rem;
}

.chart-container {
    position: relative;
    height: 300px;
    width: 100%;
}

/* Provincias (Anual) - Listas por año */
.provinces-wrapper {
    display: flex;
    flex-direction: column;
}

.provinces-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1.25rem;
}

.province-year-col {
    border: 1px solid rgba(0,0,0,0.04);
    border-radius: var(--radius-md);
    padding: 1rem;
    background: rgba(15, 23, 42, 0.02);
    min-width: 0;
}

.province-year-header {
    text-align: center;
    font-size: 0.95rem;
    font-weight: 800;
    color: #ffffff;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    padding: 0.55rem 0.75rem;
    border-radius: 0.85rem;
    letter-spacing: 0.05em;
    box-shadow: 0 4px 10px rgba(126, 34, 206, 0.15);
    margin-bottom: 0.9rem;
}

.province-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.province-item {
    display: grid;
    grid-template-columns: 1.6rem 1fr auto;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.65rem;
    border-radius: 0.85rem;
    background: rgba(255,255,255,0.85);
    border: 1px solid rgba(59, 130, 246, 0.14);
    min-width: 0;
}

.province-item:hover {
    border-color: rgba(59, 130, 246, 0.28);
    box-shadow: 0 6px 18px rgba(59, 130, 246, 0.08);
}

.province-item-clickable {
    cursor: pointer;
}

.province-rank {
    width: 1.6rem;
    height: 1.6rem;
    display: grid;
    place-items: center;
    border-radius: 999px;
    font-weight: 800;
    font-size: 0.75rem;
    color: var(--primary-dark);
    background: rgba(126, 34, 206, 0.14);
}

.province-name {
    font-weight: 650;
    color: var(--text-main);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.province-metrics {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: flex-end;
    white-space: nowrap;
}

.province-count {
    font-weight: 850;
    color: #0f172a;
}

#yearlyPlayersList .province-name {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
}

#yearlyArbitrosList .province-name,
#yearlyOrganizadoresList .province-name {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
}

.province-growth {
    font-size: 0.78rem;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    font-weight: 700;
    border: 1px solid rgba(0,0,0,0.06);
}
.province-growth-pos { color: var(--success); background: rgba(16,185,129,0.10); }
.province-growth-neg { color: #ef4444; background: rgba(239,68,68,0.10); }
.province-growth-neutral { color: var(--text-muted); background: rgba(148,163,184,0.12); }
.province-growth-base { color: var(--text-muted); background: rgba(100,116,139,0.10); }
.province-growth-new { color: #0ea5e9; background: rgba(14,165,233,0.10); }

.province-list-full {
    margin-top: 0.6rem;
}

.province-rest.is-collapsed {
    display: none;
}

.province-toggle-btn {
    margin-top: 1rem;
    width: 100%;
    border: 1px solid rgba(0,0,0,0.08);
    background: rgba(255,255,255,0.75);
    color: var(--text-main);
    padding: 0.75rem 0.9rem;
    border-radius: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.province-toggle-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.province-empty {
    color: var(--text-muted);
    font-weight: 600;
    padding: 0.75rem 0.25rem;
    text-align: center;
}

.fide-search-form {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 0.65rem;
}

.fide-search-input {
    flex: 1 1 240px;
    min-width: 180px;
    border: 1px solid rgba(148, 163, 184, 0.5);
    border-radius: 0.7rem;
    padding: 0.55rem 0.75rem;
    font-size: 0.9rem;
    outline: none;
}

.fide-search-input:focus {
    border-color: rgba(126, 34, 206, 0.7);
    box-shadow: 0 0 0 3px rgba(126, 34, 206, 0.12);
}

.fide-search-btn {
    border: none;
    border-radius: 0.7rem;
    padding: 0.55rem 0.8rem;
    font-size: 0.86rem;
    font-weight: 700;
    cursor: pointer;
    background: var(--primary);
    color: #fff;
}

.fide-search-btn:hover {
    filter: brightness(0.97);
}

.fide-search-btn-secondary {
    background: #64748b;
}

.fide-search-status {
    min-height: 1.1rem;
    margin-bottom: 0.65rem;
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 600;
}

/* Modal de detalle de jugador */
.player-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
}

.player-modal.hidden {
    display: none;
}

.player-modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
}

.player-modal-dialog {
    position: relative;
    width: min(760px, 92vw);
    max-height: 82vh;
    overflow: auto;
    background: #fff;
    border-radius: 1rem;
    border: 1px solid rgba(0,0,0,0.06);
    box-shadow: 0 30px 80px rgba(2, 6, 23, 0.25);
    padding: 1rem;
}

.player-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.player-modal-header h3 {
    font-size: 1.05rem;
    color: var(--text-main);
}

.player-modal-close {
    border: 1px solid rgba(0,0,0,0.10);
    background: #fff;
    width: 2rem;
    height: 2rem;
    border-radius: 0.65rem;
    cursor: pointer;
    color: var(--text-main);
    font-size: 1.25rem;
    line-height: 1;
}

.player-modal-meta {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.85rem;
}

.player-tournament-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.player-tournament-item {
    display: grid;
    grid-template-columns: 1.6rem 1fr;
    gap: 0.6rem;
    align-items: start;
    border: 1px solid rgba(59, 130, 246, 0.16);
    border-radius: 0.85rem;
    padding: 0.6rem 0.7rem;
    background: rgba(255,255,255,0.85);
}

.player-tournament-name {
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.2rem;
}

.player-tournament-sub {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Monthly Comparison (Section 4) */
.monthly-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.month-select {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid #cbd5e1;
    background: white;
    font-size: 1rem;
    color: var(--text-main);
    outline: none;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}

.monthly-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1.5rem;
}

.monthly-card {
    border-top: 4px solid var(--primary-light);
}

.monthly-card-title {
    text-align: center;
    font-size: 1.1rem;
    font-weight: 700;
    color: #ffffff;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    padding: 0.6rem 1rem;
    border-radius: var(--radius-md);
    letter-spacing: 0.05em;
    box-shadow: 0 4px 10px rgba(126, 34, 206, 0.15);
    margin-bottom: 1.25rem;
}

.mini-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.85rem 0;
    border-bottom: 1px dashed #f1f5f9;
}

.mini-stat:last-child {
    border-bottom: none;
}

.mini-stat-label {
    font-size: 0.875rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.mini-stat-value {
    font-weight: 600;
    color: var(--text-main);
}

/* Donut Center Text */
.donut-inner-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    pointer-events: none;
}
.donut-inner-text .total {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
}
.donut-inner-text .label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* --- Responsive Design Consolidation --- */

@media (max-width: 1200px) {
    .yearly-grid, .monthly-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .provinces-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 1024px) {
    /* Tablets / Pantallas medianas */
    body {
        padding: 1.5rem;
    }
    .dashboard-container {
        gap: 1.5rem;
    }
    .yearly-grid, .monthly-grid {
        gap: 1rem;
    }
    /* Apilar los gráficos de líneas para que tengan buen ancho en tablets */
    #yearly-charts-grid, #monthly-charts-grid {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 768px) {
    /* Teléfonos y tablets pequeñas */
    .yearly-grid, .monthly-grid {
        grid-template-columns: minmax(0, 1fr);
    }
    .provinces-grid {
        grid-template-columns: minmax(0, 1fr);
    }
    body {
        padding: 1rem;
    }
    header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
        padding: 1.25rem 1rem;
    }
    header h1 {
        font-size: 1.25rem;
        justify-content: center;
    }
    .segment-control {
        width: 100%;
        justify-content: space-between;
        padding: 0.4rem;
    }
    .segment-btn {
        flex: 1;
        font-size: 0.9rem;
        padding: 0.5rem;
    }
    .monthly-header {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    .section-title {
        text-align: center;
        justify-content: center;
        font-size: 1.1rem;
    }
    .card {
        padding: 1.25rem;
    }
    .metric-value {
        font-size: 1.4rem; /* Reducir levemente el tamaño de los números gigantes */
    }
}

@media (max-width: 480px) {
    /* Teléfonos pequeños */
    body {
        padding: 0.5rem;
    }
    .card {
        padding: 1rem;
    }
    header h1 {
        font-size: 1.1rem;
    }
    /* Achicar fuente de etiquetas si falta espacio */
    .metric-label {
        font-size: 0.75rem;
    }
    .donut-inner-text .total {
        font-size: 1rem;
    }
}
