/* Stats view (dashboard) — third view mode alongside list and map.
   Everything is themed via the CSS variables in theme.css (dark + light). */

#stats-container {
    display: none;
}

#stats-container.visible {
    display: block;
    max-width: 1400px;
    margin: 0 auto;
    /* Nav is fixed at the bottom on mobile */
    padding: 1rem 1rem calc(70px + 1.5rem);
}

@media (min-width: 800px) {
    /* Nav is fixed at the top on desktop (see nav.css) */
    #stats-container.visible {
        padding: calc(60px + 1.5rem) 1.5rem 1.5rem;
    }
}

/* Reset button in the zero-results empty state */
.stats-banner-reset {
    background: var(--secondary-accent);
    color: var(--secondary-accent-text, #fff);
    border: none;
    border-radius: 8px;
    padding: 0.4rem 0.9rem;
    font-size: 0.9rem;
    cursor: pointer;
    white-space: nowrap;
}

.stats-banner-reset:hover {
    filter: brightness(1.1);
}

/* Scope line: n of total incidents under the current filters + filter shortcut */
.stats-scope {
    font-size: 0.82rem;
    color: var(--text-secondary, #9aa0a6);
    margin: 0 0.15rem 0.75rem;
}

.stats-scope a {
    color: var(--primary-accent);
    text-decoration: none;
}

.stats-scope a:hover {
    text-decoration: underline;
}

/* Low-sample caution note */
.stats-low-n {
    color: var(--text-secondary, #9aa0a6);
    font-size: 0.85rem;
    margin-bottom: 1rem;
    padding: 0 0.25rem;
}

/* Empty state */
.stats-empty {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 2.5rem 1rem;
    text-align: center;
    color: var(--text-color);
}

.stats-empty p {
    margin: 0 0 1rem;
}

/* Decision-pattern and mitigation charts (plus their section heading) belong to
   the Analysis (interpretation) layer — hidden when the "Show analysis" setting
   is off, same CSS gating as the tag chips and filter sections (see main.css
   body.hide-interpretation rules). */
body.hide-interpretation .stats-analysis-only {
    display: none;
}

/* Section headings inside the chart grid */
.stats-section-title {
    grid-column: 1 / -1;
    margin: 1.1rem 0 0;
    padding-bottom: 0.35rem;
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-secondary, #9aa0a6);
    border-bottom: 1px solid var(--border-color);
}

/* Chart grid */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

.stats-chart-card {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem;
    min-width: 0; /* allow canvas to shrink inside grid */
}

.stats-chart-title {
    margin: 0 0 0.75rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-color);
}

/* Plain-language explanation — the simple tier, always visible above the chart. */
.stats-chart-plain {
    font-size: 0.85rem;
    color: var(--text-color);
    line-height: 1.45;
    margin: -0.45rem 0 0.7rem;
}

/* Collapsible expert note, below the chart. */
.stats-chart-details {
    margin: 0.7rem 0 0;
}
.stats-chart-details > summary {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-color);
    cursor: pointer;
    user-select: none;
    list-style-position: inside;
}
.stats-chart-details[open] > summary {
    margin-bottom: 0.35rem;
}

.stats-chart-subtitle {
    font-size: 0.78rem;
    color: var(--text-color);
    line-height: 1.45;
    margin: 0;
}

.stats-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem 1rem;
    margin: -0.4rem 0 0.6rem;
    font-size: 0.8rem;
    color: var(--text-secondary, #9aa0a6);
}

.stats-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.stats-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.stats-no-data {
    color: var(--text-secondary, #9aa0a6);
    font-size: 0.9rem;
    padding: 1.5rem 0;
    text-align: center;
}

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

/* Co-occurrence matrices need room for their category rows */
.stats-tall .chart-wrapper {
    height: 400px;
}

.stats-error {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-color);
}

@media (min-width: 900px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .stats-full {
        grid-column: 1 / -1;
    }

    .chart-wrapper {
        height: 340px;
    }

    .stats-tall .chart-wrapper {
        height: 500px;
    }
}
