/* === Vista Estadisticas === */

.stats-page {
    padding: 1.5rem clamp(1rem, 3vw, 2rem);
    max-width: 1600px;
    margin: 0 auto;
}

.stats-page__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.stats-page__title {
    font-size: clamp(1.4rem, 2.2vw, 1.9rem);
    font-weight: 700;
    color: var(--app-heading, #0f172a);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.stats-page__subtitle {
    color: var(--app-muted, #64748b);
    font-size: 0.95rem;
    margin-top: 0.15rem;
}

/* Toolbar */
.stats-toolbar {
    background: var(--app-surface, #fff);
    border: 1px solid var(--app-border, #dbe4f0);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
    display: grid;
    gap: 0.75rem;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    align-items: end;
}

.stats-toolbar__actions {
    grid-column: 1 / -1;
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.stats-field label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--app-muted, #64748b);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.3rem;
}

.stats-field input,
.stats-field select {
    width: 100%;
    border: 1px solid var(--app-border, #dbe4f0);
    border-radius: 8px;
    padding: 0.45rem 0.65rem;
    font-size: 0.9rem;
    background: var(--app-surface, #fff);
    color: var(--app-text, #0f172a);
}

.stats-margin {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

.stats-margin input[type="range"] { flex: 1; accent-color: #6366f1; }
.stats-margin__value {
    font-weight: 700;
    color: #6366f1;
    min-width: 3.2ch;
    text-align: right;
}

/* KPIs */
.stats-kpis {
    display: grid;
    gap: 0.85rem;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    margin-bottom: 1.25rem;
}

.stats-kpi {
    background: var(--app-surface, #fff);
    border: 1px solid var(--app-border, #dbe4f0);
    border-radius: 14px;
    padding: 1rem 1.15rem;
    position: relative;
    overflow: hidden;
}

.stats-kpi::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: var(--kpi-color, #6366f1);
}

.stats-kpi__label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--app-muted, #64748b);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.stats-kpi__value {
    font-size: clamp(1.4rem, 2.6vw, 1.9rem);
    font-weight: 700;
    line-height: 1.1;
    margin-top: 0.2rem;
    color: var(--app-heading, #0f172a);
}

.stats-kpi__hint {
    color: var(--app-muted, #64748b);
    font-size: 0.8rem;
    margin-top: 0.2rem;
}

.stats-kpi--won { --kpi-color: #16a34a; }
.stats-kpi--money { --kpi-color: #f59e0b; }
.stats-kpi--success { --kpi-color: #6366f1; }
.stats-kpi--ticket { --kpi-color: #0ea5e9; }
.stats-kpi--parts { --kpi-color: #8b5cf6; }
.stats-kpi--theoretical { --kpi-color: #ec4899; }

/* Grid charts */
.stats-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(12, 1fr);
}

.stats-card {
    background: var(--app-surface, #fff);
    border: 1px solid var(--app-border, #dbe4f0);
    border-radius: 14px;
    padding: 1rem 1.15rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 320px;
}

.stats-card--span-6 { grid-column: span 6; }
.stats-card--span-4 { grid-column: span 4; }
.stats-card--span-8 { grid-column: span 8; }
.stats-card--span-12 { grid-column: span 12; }

@media (max-width: 1100px) {
    .stats-card--span-6,
    .stats-card--span-4,
    .stats-card--span-8 { grid-column: span 12; }
}

.stats-card__header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.stats-card__title {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: var(--app-heading, #0f172a);
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.stats-card__tools { display: flex; gap: 0.4rem; align-items: center; }

.stats-card__tools .btn {
    font-size: 0.75rem;
    padding: 0.2rem 0.55rem;
}

.stats-card__body {
    flex: 1;
    position: relative;
    min-height: 240px;
}

.stats-card__body canvas { max-height: 320px; }

.stats-card__empty {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    color: var(--app-muted, #94a3b8); font-size: 0.9rem;
    pointer-events: none;
}

.stats-table {
    width: 100%;
    font-size: 0.85rem;
}

.stats-table th {
    text-align: left;
    color: var(--app-muted, #64748b);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
    padding: 0.35rem 0.5rem;
    border-bottom: 1px solid var(--app-border, #dbe4f0);
}

.stats-table td {
    padding: 0.45rem 0.5rem;
    border-bottom: 1px solid var(--app-border-soft, #e5edf7);
}

.stats-table tr:last-child td { border-bottom: none; }

.stats-table__num,
.stats-table th.stats-table__num,
.stats-table td.stats-table__num { text-align: right; font-variant-numeric: tabular-nums; }

.stats-table th.stats-table__num { white-space: nowrap; }

.stats-table thead th:first-child,
.stats-table tbody td:first-child { padding-left: 0.75rem; }
.stats-table thead th:last-child,
.stats-table tbody td:last-child { padding-right: 0.75rem; }

.stats-help-box {
    border-radius: 10px;
    background: linear-gradient(180deg, rgba(99,102,241,0.06), rgba(99,102,241,0.02));
    border: 1px solid rgba(99,102,241,0.18);
}
.stats-help-box__inner {
    padding: 0.85rem 1rem;
}
.stats-help-box__title {
    font-weight: 600;
    color: var(--app-text, #0f172a);
    margin-bottom: 0.4rem;
}
.stats-help-box__subtitle {
    font-weight: 600;
    font-size: 0.82rem;
    margin: 0.6rem 0 0.3rem;
    color: var(--app-text, #0f172a);
}
.stats-help-list {
    margin: 0;
    padding-left: 1.1rem;
    font-size: 0.85rem;
    color: var(--app-muted, #475569);
}
.stats-help-list li { margin-bottom: 0.25rem; }
.stats-help-list code {
    background: rgba(99,102,241,0.12);
    color: #4338ca;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.78rem;
}
.stats-help-list--compact { font-size: 0.82rem; }

[data-theme="dark"] .stats-help-box {
    background: linear-gradient(180deg, rgba(99,102,241,0.12), rgba(99,102,241,0.04));
    border-color: rgba(129,140,248,0.3);
}
[data-theme="dark"] .stats-help-box__title,
[data-theme="dark"] .stats-help-box__subtitle { color: #e2e8f0; }
[data-theme="dark"] .stats-help-list { color: #cbd5e1; }
[data-theme="dark"] .stats-help-list code {
    background: rgba(129,140,248,0.2);
    color: #c7d2fe;
}

.stats-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    background: rgba(99, 102, 241, 0.12);
    color: #4f46e5;
}

.stats-pill--good { background: rgba(22, 163, 74, 0.12); color: #16a34a; }
.stats-pill--warn { background: rgba(245, 158, 11, 0.15); color: #b45309; }
.stats-pill--bad { background: rgba(220, 38, 38, 0.12); color: #b91c1c; }

/* Insights */
.stats-insights {
    display: grid;
    gap: 0.75rem;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.stats-insight {
    border: 1px solid var(--app-border, #dbe4f0);
    border-radius: 12px;
    padding: 0.9rem 1rem;
    background: var(--app-surface-alt, #f8fafc);
    display: flex;
    gap: 0.7rem;
    align-items: flex-start;
}

.stats-insight__icon {
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 10px; flex: 0 0 auto;
    background: rgba(99, 102, 241, 0.1);
    color: #4f46e5;
}

.stats-insight--success .stats-insight__icon { background: rgba(22, 163, 74, 0.12); color: #16a34a; }
.stats-insight--warning .stats-insight__icon { background: rgba(245, 158, 11, 0.14); color: #b45309; }
.stats-insight--info .stats-insight__icon { background: rgba(14, 165, 233, 0.14); color: #0284c7; }

.stats-insight__title { font-weight: 700; margin: 0 0 0.2rem; color: var(--app-heading, #0f172a); }
.stats-insight__text { font-size: 0.85rem; color: var(--app-muted, #475569); margin: 0; }

/* Dark mode */
[data-theme="dark"] .stats-toolbar,
[data-theme="dark"] .stats-kpi,
[data-theme="dark"] .stats-card {
    background: var(--app-surface, #1e293b);
    border-color: var(--app-border, #334155);
}
[data-theme="dark"] .stats-field input,
[data-theme="dark"] .stats-field select {
    background: var(--app-surface, #0f172a);
    color: var(--app-text, #e2e8f0);
    border-color: var(--app-border, #334155);
}
[data-theme="dark"] .stats-insight {
    background: rgba(255,255,255,0.03);
    border-color: #334155;
}
[data-theme="dark"] .stats-table td { border-color: rgba(255,255,255,0.05); }
[data-theme="dark"] .stats-table th { border-color: rgba(255,255,255,0.1); }
