/* =============================================================================
   STATS PAGE
   ============================================================================= */

.stats-page h1 {
    margin-bottom: 0.25em;
}

.stats-summary {
    color: var(--text-secondary);
    margin-bottom: 2em;
}

.stats-section {
    margin-bottom: 2.5em;
}

.stats-section h2 {
    margin-bottom: 0.75em;
    font-size: 1.2em;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3em;
    position: relative;
}

.stats-section h2:hover .heading-anchor {
    opacity: 1;
}

/* ---  Histogram  ---------------------------------------------------------- */

.stats-chart {
    margin: 0;
    padding: 0;
    overflow-x: auto;
}

.stats-bars {
    display: flex;
    align-items: stretch; /* all bar groups same total height */
    gap: 4px;
    width: 100%;
    box-sizing: border-box;
}

.stats-bar-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1 1 0;
    min-width: 18px;
}

/* Fixed-height area above the bar — holds the count label */
.stats-bar-value-area {
    height: 1.6em;
    display: flex;
    align-items: flex-end; /* value sits right at the bottom of this area, flush against bar */
    justify-content: center;
    width: 100%;
    flex-shrink: 0;
    padding-bottom: 4px; /* breathing room between value and the top of the bar */
    box-sizing: border-box;
}

.stats-bar-value {
    font-size: 0.7em;
    font-weight: 600;
    color: var(--text-secondary);
    line-height: 1;
    white-space: nowrap;
    pointer-events: none;
}

/* Fixed-height area where the bar lives */
.stats-bar-wrap {
    height: 120px;
    flex-shrink: 0;
    display: flex;
    align-items: flex-end; /* bars grow from the bottom */
    width: 100%;
}

.stats-bar {
    width: 100%;
    background: var(--link-color);
    border-radius: 3px 3px 0 0;
    min-height: 2px;
    transition: background 0.15s;
}

.stats-bar:hover {
    background: var(--link-hover-color);
}

/* Fixed-height area below the bar — holds the axis label */
.stats-bar-label {
    height: 1.5em;
    flex-shrink: 0;
    margin-top: 4px;
    font-size: 0.68em;
    color: var(--text-secondary);
    white-space: nowrap;
    line-height: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    width: 100%;
}

.stats-bar-label-hidden {
    opacity: 0;
    pointer-events: none;
}

/* ---  Detail list  -------------------------------------------------------- */

.stats-details {
    margin: 0;
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0;
}

.stats-detail-row {
    display: contents;
}

.stats-detail-row dt,
.stats-detail-row dd {
    padding: 0.45em 0.6em;
    border-bottom: 1px solid var(--border-color-light);
    margin: 0;
}

.stats-detail-row:last-child dt,
.stats-detail-row:last-child dd {
    border-bottom: none;
}

.stats-focus-empty {
    color: var(--text-secondary);
}

.stats-detail-row dt {
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    padding-right: 1.5em;
}

.stats-detail-row dd {
    color: var(--text-color);
}

/* ---  Domains table  ------------------------------------------------------- */

.stats-table-wrap {
    overflow-x: auto;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92em;
}

.stats-table th,
.stats-table td {
    padding: 0.45em 0.75em;
    border: 1px solid var(--table-border);
    text-align: left;
}

.stats-table thead th {
    background: var(--table-header-bg);
    font-weight: 600;
}

.stats-table tbody tr:nth-child(odd) {
    background: var(--table-stripe-bg);
}

.stats-table-rank {
    width: 2.5em;
    text-align: right;
    color: var(--text-secondary);
}

.stats-table-count {
    width: 4em;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.stats-table-domain a {
    word-break: break-all;
}

/* --- Horizontal bar chart (posts per year) --------------------------------- */

.stats-hchart {
    margin: 0;
    padding: 0;
}

.stats-hbars {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    box-sizing: border-box;
}

.stats-hbar-row {
    display: grid;
    grid-template-columns: 3.5em 1fr 2.5em;
    align-items: center;
    gap: 8px;
    min-height: 1.4em;
}

.stats-hbar-label {
    font-size: 0.8em;
    color: var(--text-secondary);
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.stats-hbar-track {
    height: 1.2em;
    background: var(--border-color-light);
    border-radius: 3px;
    overflow: hidden;
}

.stats-hbar-fill {
    height: 100%;
    background: var(--link-color);
    border-radius: 3px;
    transition: background 0.15s;
}

.stats-hbar-row:hover .stats-hbar-fill {
    background: var(--link-hover-color);
}

.stats-hbar-value {
    font-size: 0.75em;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    text-align: left;
    white-space: nowrap;
}

/* --- Responsive adjustments ----------------------------------------------- */

@media (max-width: 600px) {
    .stats-bar-wrap {
        height: 90px;
    }

    .stats-bar-value-area {
        height: 1.3em;
    }

    .stats-bar-group {
        min-width: 12px;
    }

    .stats-bar-value {
        font-size: 0.6em;
    }

    .stats-bar-label {
        font-size: 0.55em;
    }
}

/* ---  Streak chart  ------------------------------------------------------- */

/*
 * Responsive variant visibility.
 * Three variants cover 5, 9, and 10 trailing calendar months.
 * Only the appropriate variant for the current viewport is shown.
 *
 *   < 450 px          → 5-month  (always fits)
 *   450 px – 999 px   → 9-month  (grid ≈ 585 px; fits once sidebar collapses)
 *   ≥ 1000 px         → 10-month (grid ≈ 650 px; fits with sidebar at 1000 px+)
 */
.streak-variant {
    display: none;
}

.streak-variant-5mo {
    display: block;
}

@media (min-width: 450px) {
    .streak-variant-5mo {
        display: none;
    }

    .streak-variant-9mo {
        display: block;
    }
}

@media (min-width: 1000px) {
    .streak-variant-9mo {
        display: none;
    }

    .streak-variant-10mo {
        display: block;
    }
}

/*
 * The streak chart figure is a flex container so that .streak-outer (which is
 * width: fit-content) can be horizontally centred via justify-content.
 * overflow: visible is required so the hover outline on edge cells is not
 * clipped by the figure boundary.
 */
.stats-streak-chart {
    display: flex;
    justify-content: center;
    overflow: visible;
}

/*
 * Outer 2-column CSS grid: col 1 = DOW labels, col 2 = month labels + cells.
 * Both rows share the same column widths so the labels align with the grid.
 * Padding provides room for the hover outline on edge cells; the symmetric
 * negative margin counteracts the padding to prevent it from affecting layout.
 */
.streak-outer {
    display: grid;
    grid-template-columns: 30px auto;
    row-gap: 2px;
    column-gap: 4px;
    width: fit-content;
    padding: 4px;
    margin: -4px;
}

/* Row 1, Col 1: invisible spacer that aligns the month-label row with the
   DOW label column below it. */
.streak-dow-spacer {
    /* Intentionally empty; width provided by the grid column definition. */
}

/* Row 1, Col 2: month name labels */
.streak-month-labels-grid {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 13px;
    gap: 2px;
    overflow: visible;
}

.streak-month-label {
    grid-row: 1;
    font-size: 0.6em;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: visible;
}

/* Row 2, Col 1: day-of-week labels */
.streak-dow-labels {
    display: grid;
    grid-template-rows: repeat(7, 13px);
    gap: 2px;
    align-self: start;
}

.streak-dow-label {
    font-size: 0.6em;
    color: var(--text-secondary);
    line-height: 13px;
    text-align: right;
    white-space: nowrap;
}

/* Row 2, Col 2: streak cells */
.streak-grid {
    display: grid;
    grid-template-rows: repeat(7, 13px);
    grid-auto-flow: column;
    grid-auto-columns: 13px;
    gap: 2px;
    overflow: visible;
}

.streak-cell {
    width: 13px;
    height: 13px;
    border-radius: 2px;
    display: block;
    box-sizing: border-box;
}

.streak-cell-out-of-range {
    background: transparent;
}

.streak-cell-level-0 {
    background: var(--streak-cell-empty);
}

.streak-cell-level-1 {
    background: var(--streak-cell-l1);
}

.streak-cell-level-2 {
    background: var(--streak-cell-l2);
}

.streak-cell-level-3 {
    background: var(--streak-cell-l3);
}

.streak-cell-level-4 {
    background: var(--streak-cell-l4);
}

a.streak-cell:hover {
    outline: 2px solid var(--link-hover-color);
    outline-offset: 1px;
    cursor: pointer;
}
