@import url('tokens.css');

.overview-page {
    min-height: calc(100vh - 82px);
    overflow-x: hidden;
    padding: 0 0 3rem;
}

.overview-container {
    max-width: 1600px;
    padding: 0 clamp(1rem, 3vw, 2.5rem);
}

.overview-hero {
    align-items: flex-end;
    display: flex;
    gap: 2rem;
    justify-content: space-between;
    padding: 2rem 0 1.5rem;
}

.overview-eyebrow {
    color: var(--funasa-red);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.09em;
    margin: 0 0 0.35rem;
    text-transform: uppercase;
}

.overview-hero h1 {
    color: #153a58;
    font-size: clamp(1.8rem, 3vw, 2.6rem);
    font-weight: 780;
    letter-spacing: -0.035em;
    line-height: 1.1;
    margin: 0;
}

.overview-lead {
    color: var(--text-secondary);
    font-size: 1rem;
    margin: 0.55rem 0 0;
    max-width: 700px;
}

.hero-badges {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    justify-content: flex-end;
}

.source-badge,
.year-badge {
    border-radius: 999px;
    display: inline-flex;
    font-size: 0.78rem;
    font-weight: 700;
    padding: 0.48rem 0.75rem;
    white-space: nowrap;
}

.source-badge { background: var(--funasa-blue-soft); color: var(--funasa-blue-dark); }
.year-badge { background: var(--surface); border: 1px solid var(--border); color: #36556d; }

.dashboard-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 1rem;
    box-shadow: var(--shadow-sm);
}

.filter-panel { padding: 1.15rem 1.25rem 1rem; }

.filter-panel-header,
.panel-header,
.panel-header-with-action {
    align-items: flex-start;
    display: flex;
    gap: 1rem;
    justify-content: space-between;
}

.filter-panel-header h2,
.panel-header h2 {
    color: #18364e;
    font-size: 1.02rem;
    font-weight: 750;
    margin: 0;
}

.filter-panel-header p,
.panel-header p {
    color: var(--text-secondary);
    font-size: 0.84rem;
    margin: 0.25rem 0 0;
}

.clear-filters-button,
.methodology-toggle {
    color: var(--funasa-blue-dark);
    font-size: 0.82rem;
    font-weight: 700;
    padding: 0.25rem 0.35rem;
    text-decoration: none;
    white-space: nowrap;
}

.clear-filters-button:hover,
.methodology-toggle:hover { color: var(--funasa-red); text-decoration: none; }

.filter-grid {
    display: grid;
    gap: 0.85rem;
    grid-template-columns: minmax(100px, 0.55fr) minmax(100px, 0.55fr) minmax(240px, 1.45fr) repeat(3, minmax(145px, 1fr));
    margin-top: 1rem;
}

.filter-grid > :nth-child(1),
.rural-filter-grid > :nth-child(1),
.mat-filter-grid > :nth-child(1),
.quil-filter-grid > :nth-child(1) { order: 4; }
.filter-grid > :nth-child(2),
.rural-filter-grid > :nth-child(2),
.mat-filter-grid > :nth-child(2),
.quil-filter-grid > :nth-child(2) { order: 1; }
.filter-grid > :nth-child(3),
.rural-filter-grid > :nth-child(3),
.mat-filter-grid > :nth-child(3),
.quil-filter-grid > :nth-child(3) { order: 2; }
.filter-grid > :nth-child(4),
.rural-filter-grid > :nth-child(4),
.mat-filter-grid > :nth-child(4),
.quil-filter-grid > :nth-child(4) { order: 3; }
.filter-grid > :nth-child(5),
.mat-filter-grid > :nth-child(5),
.quil-filter-grid > :nth-child(5) { order: 5; }
.filter-grid > :nth-child(6),
.mat-filter-grid > :nth-child(6),
.quil-filter-grid > :nth-child(6) { order: 6; }

.filter-field { min-width: 0; }
.filter-label { color: #36556d; display: block; font-size: 0.75rem; font-weight: 700; margin: 0 0 0.35rem; }

.filter-field .Select-control,
.filter-field .select__control {
    border-color: var(--border);
    border-radius: 0.55rem;
    box-shadow: none;
    min-height: 38px;
}

.filter-field .Select-control:hover { border-color: #9db7ca; }

.active-filters {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.8rem;
    min-height: 25px;
}

.active-filters-label { color: var(--text-secondary); font-size: 0.72rem; font-weight: 700; margin-right: 0.15rem; }
.active-filter-badge { background: #f2f6f9; border-radius: 999px; color: #36556d; font-size: 0.72rem; padding: 0.3rem 0.55rem; }

.kpi-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin: 1rem 0;
}

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 1rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    gap: 0.9rem;
    min-height: 166px;
    overflow: hidden;
    padding: 1.15rem;
    position: relative;
}

.kpi-card::before { background: var(--funasa-blue); content: ""; inset: 0 auto 0 0; position: absolute; width: 4px; }
.kpi-card.kpi-red::before { background: var(--funasa-red); }
.kpi-card.kpi-green::before { background: #2e7d5a; }

.kpi-icon {
    align-items: center;
    background: var(--funasa-blue-soft);
    border-radius: 0.75rem;
    color: var(--funasa-blue);
    display: inline-flex;
    flex: 0 0 42px;
    font-size: 1.15rem;
    height: 42px;
    justify-content: center;
}

.kpi-icon-red { background: var(--funasa-red-soft); color: var(--funasa-red); }
.kpi-icon-green { background: #eaf6f0; color: #257052; }
.kpi-content { min-width: 0; }
.kpi-label { color: #536b7d; font-size: 0.76rem; font-weight: 750; margin: 0 0 0.25rem; }
.kpi-value { color: #153a58; font-size: clamp(1.55rem, 2.2vw, 2rem); font-weight: 780; letter-spacing: -0.035em; line-height: 1.05; margin: 0; }
.kpi-detail { color: var(--text-secondary); font-size: 0.75rem; margin: 0.35rem 0 0; }

.kpi-breakdown {
    border-top: 1px solid #e8eef2;
    display: grid;
    font-size: 0.67rem;
    gap: 0.15rem;
    margin-top: 0.55rem;
    padding-top: 0.45rem;
}

.kpi-breakdown span { color: #60788a; }
.kpi-breakdown strong { color: #36556d; }

.charts-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: minmax(0, 1.65fr) minmax(340px, 0.85fr);
    margin-bottom: 1rem;
}

.chart-panel,
.map-panel,
.table-panel { min-width: 0; padding: 1.25rem; }

.overview-chart { height: 400px !important; margin-top: 0.35rem; min-width: 0; }
.chart-panel-wide:has(input[value="todos"]:checked) .overview-chart { height: 720px !important; }

.segmented-control {
    background: #f2f6f9;
    border-radius: 0.65rem;
    display: flex;
    flex: 0 0 auto;
    gap: 0.15rem;
    padding: 0.22rem;
}

.segmented-control label {
    border-radius: 0.48rem;
    color: #536b7d;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.42rem 0.62rem;
}

.segmented-control label:has(input:checked) { background: var(--surface); box-shadow: var(--shadow-sm); color: var(--funasa-blue-dark); }
.segmented-control input { margin-right: 0.28rem; accent-color: var(--funasa-blue); }

.map-panel { margin-bottom: 1rem; }
.coordinate-legend { align-items: center; display: flex; flex-wrap: wrap; gap: 0.75rem; justify-content: flex-end; }
.map-legend-item { color: #536b7d; font-size: 0.75rem; font-weight: 650; white-space: nowrap; }

.map-dot {
    border-radius: 999px;
    display: inline-block;
    height: 9px;
    margin-right: 0.2rem;
    width: 9px;
}

.map-dot-official { background: var(--funasa-blue); }
.map-dot-supplemental { background: var(--funasa-red); }
.methodology-toggle { margin: 0.6rem 0 0.5rem; }

.methodology-note {
    background: #f7fafc;
    border-left: 3px solid var(--funasa-red);
    border-radius: 0.45rem;
    color: #496477;
    font-size: 0.8rem;
    margin: 0 0 0.8rem;
    padding: 0.75rem 0.9rem;
}

.map-frame { border: 0; border-radius: 0.75rem; display: block; height: 620px; overflow: hidden; width: 100%; }

.table-panel-header { align-items: center; }
.municipality-search { flex: 0 1 320px; min-width: 250px; }
.municipality-search .input-group-text { background: #f7fafc; border-color: var(--border); color: #60788a; }
.municipality-search .form-control { border-color: var(--border); font-size: 0.84rem; }
.municipality-search .form-control:focus { border-color: var(--funasa-blue); box-shadow: 0 0 0 0.2rem rgba(12, 94, 166, 0.12); }

.municipality-tabs { border-bottom: 1px solid var(--border); margin: 1rem 0 0; overflow-x: auto; overflow-y: hidden; flex-wrap: nowrap; }
.municipality-tabs .nav-link { border: 0; color: #536b7d; font-size: 0.8rem; font-weight: 700; padding: 0.7rem 0.9rem; white-space: nowrap; }
.municipality-tabs .nav-link.active { border-bottom: 3px solid var(--funasa-red); color: var(--funasa-blue-dark); }
.table-status { color: var(--text-secondary); font-size: 0.75rem; min-height: 32px; padding: 0.75rem 0 0.5rem; }
.table-panel .dash-table-container {
    border: 1px solid var(--border);
    border-radius: 0.65rem;
    display: block;
    max-width: 100%;
    overflow: hidden;
    width: 100%;
}
.table-panel .dash-table-container .dash-spreadsheet-container {
    max-width: 100%;
    width: 100%;
}
.table-method-note {
    background: #f7fafc;
    border-left: 3px solid var(--funasa-blue);
    border-radius: 0.4rem;
    color: #536b7d;
    font-size: 0.73rem;
    margin: 0.75rem 0 0;
    padding: 0.6rem 0.7rem;
}
.table-panel .dash-spreadsheet-menu { align-items: center; display: flex; justify-content: flex-end; padding: 0 0 0.55rem; }
.table-panel .export { background: var(--funasa-blue); border: 0; border-radius: 0.45rem; color: #fff; font-size: 0.75rem; font-weight: 700; padding: 0.42rem 0.7rem; }
.table-panel .export::before { content: "Exportar aba"; }
.table-panel .export { font-size: 0; }
.table-panel .export::before { font-size: 0.75rem; }

@media (max-width: 1199.98px) {
    .filter-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
    .filter-grid .filter-field-wide,
    .filter-grid .filter-field { grid-column: span 1; }
    .kpi-card { min-height: 176px; }
}

@media (max-width: 991.98px) {
    .overview-hero { padding-top: 1.5rem; }
    .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .filter-grid .filter-field,
    .filter-grid .filter-field-wide { grid-column: auto; }
    .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kpi-card { min-height: 154px; }
    .charts-grid { grid-template-columns: minmax(0, 1fr); }
    .map-frame { height: 540px; }
}

@media (max-width: 767.98px) {
    .overview-hero { align-items: flex-start; flex-direction: column; gap: 0.85rem; }
    .hero-badges { justify-content: flex-start; }
    .filter-panel-header,
    .panel-header-with-action,
    .table-panel-header { align-items: flex-start; flex-direction: column; }
    .filter-panel-header { gap: 0.35rem; }
    .filter-grid { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: 1fr; }
    .kpi-card { min-height: 0; }
    .segmented-control { align-self: stretch; justify-content: center; }
    .coordinate-legend { justify-content: flex-start; }
    .municipality-search { flex-basis: auto; min-width: 0; width: 100%; }
    .map-frame { height: 470px; }
}

@media (max-width: 575.98px) {
    .overview-container { padding-left: 0.75rem; padding-right: 0.75rem; }
    .overview-hero { padding: 1.15rem 0 1rem; }
    .overview-lead { font-size: 0.9rem; }
    .filter-panel,
    .chart-panel,
    .map-panel,
    .table-panel { border-radius: 0.8rem; padding: 1rem; }
    .filter-grid { gap: 0.65rem; margin-top: 0.75rem; }
    .active-filters { margin-top: 0.65rem; }
    .kpi-grid { gap: 0.75rem; margin: 0.75rem 0; }
    .kpi-card { border-radius: 0.8rem; padding: 1rem; }
    .map-frame { height: 420px; }
}
