/* =============================================
   STATS.CSS — Página de estadísticas públicas
   ============================================= */

/* ── Página ──────────────────────────────────── */

.stats-page {
    min-height: 100svh;
    background: var(--color-bg-subtle);
}

.stats-wrapper {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem 1.25rem 4rem;
}

/* ── Cabecera ────────────────────────────────── */

.stats-hero {
    text-align: center;
    padding: 2rem 0 2.5rem;
}

.stats-eyebrow {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--color-accent);
    margin-bottom: 0.75rem;
}

.stats-title {
    font-size: clamp(1.5rem, 4vw, 2.25rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--color-text);
    margin-bottom: 0.5rem;
}

.stats-subtitle {
    font-size: 1rem;
    color: var(--color-text-muted);
    max-width: 540px;
    margin: 0 auto;
    line-height: 1.6;
}

/* ── KPIs ────────────────────────────────────── */

.stats-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.75rem;
}

.kpi-card {
    background: #ffffff;
    border: 1px solid var(--color-border);
    border-radius: 1rem;
    padding: 1.375rem 1.25rem;
    text-align: center;
    border-top: 3px solid var(--color-primary);
}

.kpi-card--green  { border-top-color: #16a34a; }
.kpi-card--orange { border-top-color: #F97316; }
.kpi-card--blue   { border-top-color: #2563eb; }

.kpi-num {
    font-size: clamp(1.75rem, 4vw, 2.5rem);
    font-weight: 800;
    letter-spacing: -0.04em;
    color: var(--color-text);
    line-height: 1;
    margin-bottom: 0.4rem;
}

.kpi-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-muted);
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

/* ── Grid de tarjetas ────────────────────────── */

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}

.stats-card {
    background: #ffffff;
    border: 1px solid var(--color-border);
    border-radius: 1rem;
    padding: 1.375rem 1.5rem;
}

.stats-card--wide {
    grid-column: 1 / -1;
}

.stats-card-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 1.25rem;
    padding-bottom: 0.875rem;
    border-bottom: 1px solid var(--color-border);
}

/* ── Gráfico Chart.js ────────────────────────── */

.chart-container {
    position: relative;
    height: 240px;
}

/* ── Barras horizontales (categorías) ────────── */

.hbar-list {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

.hbar-row {
    display: grid;
    grid-template-columns: 110px 1fr 2.5rem;
    align-items: center;
    gap: 0.625rem;
}

.hbar-label {
    font-size: 0.8125rem;
    color: var(--color-text);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hbar-track {
    height: 0.5rem;
    background: var(--color-bg-subtle);
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid var(--color-border);
}

.hbar-fill {
    height: 100%;
    background: var(--color-primary);
    border-radius: 999px;
    transition: width 0.4s ease;
    min-width: 4px;
}

.hbar-val {
    font-size: 0.8125rem;
    font-weight: 700;
    color: var(--color-text-muted);
    text-align: right;
}

/* ── Tabla de localidades ────────────────────── */

.locality-table {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.locality-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0;
    border-bottom: 1px solid var(--color-border);
}
.locality-row:last-child { border-bottom: none; }

.locality-rank {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.5rem;
    height: 1.5rem;
    background: var(--color-bg-subtle);
    border: 1px solid var(--color-border);
    border-radius: 0.375rem;
    font-size: 0.6875rem;
    font-weight: 700;
    color: var(--color-text-muted);
    flex-shrink: 0;
}
.locality-row:nth-child(1) .locality-rank { background: #fef9c3; border-color: #fde047; color: #854d0e; }
.locality-row:nth-child(2) .locality-rank { background: #f1f5f9; border-color: #cbd5e1; color: #475569; }
.locality-row:nth-child(3) .locality-rank { background: #fff7ed; border-color: #fdba74; color: #9a3412; }

.locality-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.locality-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.locality-province {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.locality-cnt {
    font-size: 0.875rem;
    font-weight: 800;
    color: var(--color-primary);
    flex-shrink: 0;
}

/* ── Estado vacío ────────────────────────────── */

.stats-empty {
    text-align: center;
    padding: 4rem 1.5rem;
    color: var(--color-text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
}
.stats-empty p { font-size: 1rem; }


/* ── Responsive ──────────────────────────────── */

@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    .stats-card--wide {
        grid-column: 1;
    }
    .hbar-row {
        grid-template-columns: 90px 1fr 2rem;
    }
}

@media (max-width: 480px) {
    .stats-kpis {
        grid-template-columns: 1fr 1fr;
    }
}

/* ── Nuevos KPIs ─────────────────────────────── */

.kpi-card--purple { border-top-color: #7c3aed; }
.kpi-card--teal   { border-top-color: #0d9488; }

.kpi-unit {
    font-size: 1rem;
    font-weight: 600;
    margin-left: 2px;
    opacity: 0.6;
}

/* ── Subtítulo inline en card-title ──────────── */

.stats-card-sub {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--color-text-muted);
    margin-left: 0.4rem;
}

/* ── Donut de estados ────────────────────────── */

.stats-card--donut {
    display: flex;
    flex-direction: column;
}

.donut-wrap {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex: 1;
}

.donut-wrap canvas {
    width: 140px !important;
    height: 140px !important;
    flex-shrink: 0;
}

.donut-legend {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
}

.donut-legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.donut-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.donut-legend-label {
    font-size: 0.8125rem;
    color: var(--color-text);
    font-weight: 500;
    flex: 1;
    text-transform: capitalize;
}

.donut-legend-val {
    font-size: 0.8125rem;
    font-weight: 700;
    color: var(--color-text-muted);
}

/* ── Actividad por día de semana ─────────────── */

.dow-grid {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    height: 140px;
    padding-top: 0.5rem;
}

.dow-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    height: 100%;
}

.dow-bar-wrap {
    flex: 1;
    width: 100%;
    display: flex;
    align-items: flex-end;
}

.dow-bar {
    width: 100%;
    background: var(--color-primary);
    border-radius: 3px 3px 0 0;
    min-height: 4px;
    opacity: 0.75;
    transition: opacity 0.15s;
}

.dow-bar:hover { opacity: 1; }

.dow-label {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-align: center;
}

.dow-val {
    font-size: 0.6875rem;
    font-weight: 700;
    color: var(--color-text);
    text-align: center;
}

/* ── Tabla de municipios ─────────────────────── */

.stats-muni-card {
    margin-top: 1.25rem;
    padding: 1.375rem 1.5rem 0;
    overflow: hidden;
}

.stats-muni-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 0;
}

.muni-search-wrap {
    flex-shrink: 0;
}

.muni-search {
    height: 2rem;
    padding: 0 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 0.5rem;
    font-size: 0.8125rem;
    font-family: inherit;
    color: var(--color-text);
    background: var(--color-bg-subtle);
    outline: none;
    width: 200px;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.muni-search:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.1);
}

.muni-table-wrap {
    overflow-x: auto;
    margin: 0 -1.5rem;
    padding: 0 1.5rem;
}

.muni-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
    min-width: 580px;
}

.muni-th {
    text-align: left;
    padding: 0.75rem 0.625rem;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

.muni-th--sortable {
    cursor: pointer;
    user-select: none;
}

.muni-th--sortable:hover { color: var(--color-text); }

.muni-th--num { text-align: right; }

.sort-icon {
    font-style: normal;
    opacity: 0.5;
    margin-left: 2px;
    font-size: 0.6875rem;
}

.muni-td {
    padding: 0.6875rem 0.625rem;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
    color: var(--color-text);
}

.muni-row:last-child .muni-td { border-bottom: none; }
.muni-row:hover .muni-td { background: var(--color-bg-subtle); }

.muni-td--name {
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

.muni-rank {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.375rem;
    height: 1.375rem;
    background: var(--color-bg-subtle);
    border: 1px solid var(--color-border);
    border-radius: 0.3rem;
    font-size: 0.625rem;
    font-weight: 700;
    color: var(--color-text-muted);
    flex-shrink: 0;
}

.muni-link {
    font-weight: 600;
    color: var(--color-text);
    text-decoration: none;
    display: block;
    white-space: nowrap;
}

.muni-link:hover { color: var(--color-primary); }

.muni-province {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    display: block;
}

.muni-td--num { text-align: right; }
.muni-td--bold { font-weight: 700; color: var(--color-primary); }
.muni-td--muted { color: var(--color-text-muted); }
.muni-na { color: var(--color-text-muted); opacity: 0.4; }

/* Rate badges */
.rate-badge {
    display: inline-block;
    padding: 0.1875rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
}

.rate-badge--green { background: #dcfce7; color: #15803d; }
.rate-badge--amber { background: #fff7ed; color: #c2410c; }
.rate-badge--red   { background: #fee2e2; color: #b91c1c; }

.muni-empty {
    text-align: center;
    padding: 2rem;
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

@media (max-width: 640px) {
    .donut-wrap { flex-direction: column; gap: 1rem; }
    .donut-wrap canvas { width: 120px !important; height: 120px !important; }
    .stats-muni-header { flex-direction: column; align-items: flex-start; }
    .muni-search { width: 100%; }
}
