/* Statistics tab — tiles, tables and chart chrome */

.statistics-container {
    background: var(--white);
    border-radius: var(--border-radius-lg);
    padding: 28px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--neutral-gray-200);
    /* From 1200px up, .tab-content.active is a two-column grid built for the
       form/history tabs. Statistics is a single full-bleed card, so it has to
       span both tracks or it would sit in the narrow first column. */
    grid-column: 1 / -1;
}

.statistics-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.statistics-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--neutral-gray-800);
}

#statisticsBlurb {
    margin: 4px 0 0;
    color: var(--neutral-gray-600);
    font-size: 0.95rem;
}

.statistics-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px;
}

.statistics-control {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.statistics-control label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--neutral-gray-500);
}

.statistics-control select,
.statistics-control input[type="date"] {
    font-family: var(--font-family);
    font-size: 0.95rem;
    padding: 8px 12px;
    border: 1px solid var(--neutral-gray-300);
    border-radius: var(--border-radius);
    background: var(--white);
    color: var(--neutral-gray-800);
    min-width: 150px;
}

#statisticsRefresh,
#statisticsDownload {
    /* .auth-button is width:100% for modal footers — keep this one inline. */
    width: auto;
    flex: 0 0 auto;
    align-self: flex-end;
    font-family: var(--font-family);
    font-size: 0.95rem;
    font-weight: 500;
    padding: 9px 20px;
    border: 1px solid var(--neutral-gray-300);
    border-radius: var(--border-radius);
    background: var(--white);
    color: var(--primary-blue);
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

#statisticsRefresh:hover,
#statisticsDownload:hover {
    background: var(--neutral-gray-50);
    border-color: var(--primary-blue-light);
}

#statisticsDownload:disabled {
    opacity: 0.6;
    cursor: progress;
}

#statisticsMeta {
    font-size: 0.85rem;
    color: var(--neutral-gray-500);
    margin: 0 0 20px;
}

#statisticsError {
    display: none;
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.35);
    color: #991b1b;
    border-radius: var(--border-radius);
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 0.9rem;
}

/* Sub-tab navigation */
.stats-subtabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    border-bottom: 1px solid var(--neutral-gray-200);
    margin-bottom: 24px;
}

.stats-subtab {
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 10px 18px;
    font-family: var(--font-family);
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--neutral-gray-600);
    cursor: pointer;
    transition: color 0.2s ease, border-color 0.2s ease;
}

.stats-subtab:hover {
    color: var(--primary-blue);
}

.stats-subtab.active {
    color: var(--primary-blue);
    border-bottom-color: var(--primary-blue);
    font-weight: 600;
}

.stats-panel {
    display: none;
}

.stats-panel.active {
    display: block;
}

/*
 * On a wide window, stretching one chart across 1800px does not make it more
 * readable — it just makes the marks longer. Instead the panel becomes a
 * multi-column grid so narrow sections sit side by side, while sections that
 * are genuinely wide (day-by-day series, the hour heatmap, multi-column
 * tables) keep the full row.
 */
@media (min-width: 1280px) {
    .stats-panel.active {
        display: grid;
        grid-template-columns: 1fr 1fr;
        column-gap: 72px;
        align-items: start;
    }

    .stats-panel.active > .stats-tiles,
    .stats-panel.active > .stats-section-wide,
    .stats-panel.active > .stats-footnote {
        grid-column: 1 / -1;
    }

    .stats-section-wide .viz-svg {
        max-width: 1180px;
    }
}

/* Tiles */
.stats-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
    margin-bottom: 28px;
}

.stats-tiles-compact {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    margin-bottom: 8px;
}

.stats-tile {
    background: var(--neutral-gray-50);
    border: 1px solid var(--neutral-gray-200);
    border-radius: var(--border-radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stats-tile-hero {
    background: linear-gradient(135deg, rgba(0, 94, 184, 0.08) 0%, rgba(77, 166, 255, 0.08) 100%);
    border-color: rgba(0, 94, 184, 0.25);
}

.stats-tile-good {
    border-color: rgba(16, 185, 129, 0.4);
    background: rgba(16, 185, 129, 0.07);
}

.stats-tile-warn {
    border-color: rgba(245, 158, 11, 0.45);
    background: rgba(245, 158, 11, 0.08);
}

.stats-tile-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--neutral-gray-500);
}

.stats-tile-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.15;
    color: var(--neutral-gray-900);
}

.stats-tile-hero .stats-tile-value {
    font-size: 2.25rem;
    color: var(--primary-blue-dark);
}

.stats-tile-note {
    font-size: 0.8rem;
    color: var(--neutral-gray-600);
    line-height: 1.35;
}

/* Sections */
.stats-section {
    margin-bottom: 32px;
}

.stats-section-title {
    margin: 0 0 4px;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--neutral-gray-800);
}

.stats-subheading {
    margin: 18px 0 6px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--neutral-gray-700);
}

.stats-section-note,
.stats-note,
.stats-footnote {
    margin: 0 0 12px;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--neutral-gray-600);
    max-width: 78ch;
}

.stats-footnote {
    border-top: 1px solid var(--neutral-gray-200);
    padding-top: 12px;
    color: var(--neutral-gray-500);
}

.stats-empty {
    margin: 0;
    padding: 18px;
    background: var(--neutral-gray-50);
    border: 1px dashed var(--neutral-gray-300);
    border-radius: var(--border-radius);
    color: var(--neutral-gray-600);
    font-size: 0.9rem;
}

.stats-callout {
    margin-top: 12px;
    padding: 14px 16px;
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    line-height: 1.5;
}

.stats-callout-warn {
    background: rgba(245, 158, 11, 0.09);
    border: 1px solid rgba(245, 158, 11, 0.4);
    color: #7c2d12;
}

/* Charts */
.stats-section .viz-svg,
.stats-callout .viz-svg {
    display: block;
    width: 100%;
    height: auto;
    max-width: 880px;
    overflow: visible;
}

.viz-label {
    font-family: var(--font-family);
    font-size: 13px;
    fill: #1f2937;
}

.viz-value {
    font-family: var(--font-family);
    font-size: 13px;
    font-weight: 600;
    fill: #1f2937;
}

.viz-muted,
.viz-step {
    font-family: var(--font-family);
    font-size: 12px;
    fill: #5e6673;
}

.viz-drop {
    font-family: var(--font-family);
    font-size: 11px;
    fill: #5e6673;
}

.viz-tick {
    font-family: var(--font-family);
    font-size: 11px;
    fill: #5e6673;
}

.viz-cell-value {
    font-family: var(--font-family);
    font-size: 10px;
    fill: #1f2937;
}

.viz-cell-value-light {
    fill: #ffffff;
}

/* Legends */
.stats-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
    margin-bottom: 10px;
    font-size: 0.82rem;
    color: var(--neutral-gray-600);
}

.stats-legend-ramp {
    gap: 4px;
}

.stats-legend-ramp .stats-legend-item {
    margin: 0 6px;
}

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

.stats-legend-item-muted {
    color: var(--neutral-gray-500);
}

.stats-legend-swatch {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.stats-legend-swatch-empty {
    background: var(--neutral-gray-50);
    border: 1px solid var(--neutral-gray-300);
}

/* Tables */
.stats-table-wrap {
    overflow-x: auto;
    margin-bottom: 8px;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    min-width: 520px;
}

.stats-table th,
.stats-table td {
    text-align: left;
    padding: 9px 12px;
    border-bottom: 1px solid var(--neutral-gray-200);
    white-space: nowrap;
}

.stats-table th {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--neutral-gray-500);
    background: var(--neutral-gray-50);
}

.stats-table td.numeric,
.stats-table th.numeric {
    text-align: right;
}

.stats-table tbody tr:hover {
    background: var(--neutral-gray-50);
}

/* Inline meter used inside table cells */
.stats-meter {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-end;
    min-width: 120px;
}

.stats-meter-track {
    position: relative;
    display: inline-block;
    width: 70px;
    height: 8px;
    border-radius: 4px;
    background: var(--neutral-gray-200);
    overflow: hidden;
}

.stats-meter-fill {
    position: absolute;
    inset: 0 auto 0 0;
    background: var(--primary-blue);
    border-radius: 4px;
}

.stats-meter-text {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--neutral-gray-800);
}

@media (max-width: 768px) {
    .statistics-container {
        padding: 18px;
    }

    .statistics-header {
        flex-direction: column;
        align-items: stretch;
    }

    .stats-tile-hero .stats-tile-value {
        font-size: 1.9rem;
    }

    .stats-subtab {
        padding: 8px 12px;
        font-size: 0.9rem;
    }
}
