/* === Stats === */
.stats-page {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.stats-summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
}

.stats-summary-card {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-height: 140px;
    justify-content: center;
}

.stats-summary-label,
.stats-summary-footnote {
    color: var(--text-secondary);
    font-size: 0.88rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.stats-summary-footnote {
    text-transform: none;
    letter-spacing: 0;
    font-weight: 450;
    margin-top: 0.1rem;
}

.stats-summary-value {
    font-size: clamp(1.8rem, 3vw, 2.6rem);
    font-weight: 800;
    line-height: 1.05;
    background: var(--heading-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
        "storage duration"
        "growth growth"
        "records dow"
        "heatmap heatmap"
        "tags freq"
        "catalog catalog";
    grid-auto-rows: minmax(280px, auto);
    gap: 1rem;
    align-items: stretch;
}

.stats-panel {
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.stats-panel-wide {
    grid-area: catalog;
}

.stats-panel-storage {
    grid-area: storage;
}

.stats-panel-duration {
    grid-area: duration;
}

.stats-panel-growth {
    grid-area: growth;
    display: flex;
    flex-direction: column;
}

.stats-panel-records {
    grid-area: records;
}

.stats-panel-dow {
    grid-area: dow;
}

.stats-panel-heatmap {
    grid-area: heatmap;
    grid-auto-rows: auto;
}

.stats-panel-tags {
    grid-area: tags;
}

.stats-panel-freq {
    grid-area: freq;
}

.stats-panel-header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.stats-panel-header-row .stats-panel-header {
    margin-bottom: 0;
    flex: 1;
    min-width: 0;
}

.stats-panel-header {
    margin-bottom: 1rem;
}

.stats-panel-header h2 {
    font-size: 1.15rem;
    margin-bottom: 0.2rem;
}

.stats-panel-header p {
    color: var(--text-secondary);
    font-size: 0.92rem;
}

.stats-toggle-group {
    display: inline-flex;
    gap: 0.35rem;
    padding: 0.25rem;
    margin-bottom: 1rem;
    border-radius: 999px;
    background: var(--bg-tertiary);
    border: var(--glass-border);
}

.stats-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    font-weight: 700;
    padding: 0.45rem 0.85rem;
    border-radius: 999px;
    cursor: pointer;
    transition: all var(--transition);
}

.stats-toggle:hover {
    color: var(--text-primary);
}

.stats-toggle-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    transition: opacity var(--transition);
}

.stats-toggle:not(.is-active) {
    opacity: 0.55;
}

.stats-toggle:not(.is-active):hover {
    opacity: 0.85;
}

/* Per-metric dot colors — always visible */
[data-growth-metric="count"] .stats-toggle-dot {
    background: var(--accent-purple);
}

[data-growth-metric="duration_seconds"] .stats-toggle-dot {
    background: var(--accent-gold);
}

[data-growth-metric="bytes"] .stats-toggle-dot {
    background: #0ea5e9;
}

[data-theme="dark"] [data-growth-metric="bytes"] .stats-toggle-dot {
    background: #38bdf8;
}

/* Per-metric active button backgrounds */
.stats-toggle.is-active[data-growth-metric="count"] {
    background: var(--accent-purple);
    color: #fff;
    box-shadow: 0 4px 14px rgba(124, 58, 237, 0.35);
    opacity: 1;
}

[data-theme="dark"] .stats-toggle.is-active[data-growth-metric="count"] {
    box-shadow: 0 4px 14px rgba(176, 101, 255, 0.35);
}

.stats-toggle.is-active[data-growth-metric="duration_seconds"] {
    background: var(--button-gradient);
    color: var(--button-foreground);
    box-shadow: 0 4px 14px rgba(212, 160, 23, 0.35);
    opacity: 1;
}

.stats-toggle.is-active[data-growth-metric="bytes"] {
    background: #0ea5e9;
    color: #fff;
    box-shadow: 0 4px 14px rgba(14, 165, 233, 0.35);
    opacity: 1;
}

[data-theme="dark"] .stats-toggle.is-active[data-growth-metric="bytes"] {
    background: #38bdf8;
    color: #0c1a1f;
    box-shadow: 0 4px 14px rgba(56, 189, 248, 0.35);
}

/* Dot turns white/dark inside active button except for gold */
.stats-toggle.is-active[data-growth-metric="count"] .stats-toggle-dot,
.stats-toggle.is-active[data-growth-metric="bytes"] .stats-toggle-dot {
    background: rgba(255, 255, 255, 0.6);
}

.stats-toggle.is-active[data-growth-metric="duration_seconds"] .stats-toggle-dot {
    background: rgba(0, 0, 0, 0.25);
}

/* === Duration Distribution === */
.stats-pill-chart {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.stats-pill {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.stats-pill-meter {
    position: relative;
    flex: 1;
    min-height: 14px;
    overflow: hidden;
}

.stats-meter {
    width: 100%;
    height: 14px;
    appearance: none;
    -webkit-appearance: none;
    border: none;
    border-radius: 999px;
    overflow: hidden;
    background: var(--bg-tertiary);
}

.stats-meter::-webkit-progress-bar {
    background: var(--bg-tertiary);
    border-radius: 999px;
}

.stats-meter::-webkit-progress-value {
    background: var(--button-gradient);
    border-radius: 999px;
}

.stats-meter::-moz-progress-bar {
    background: var(--button-gradient);
    border-radius: 999px;
}

.stats-pill > span:first-child,
.stats-pill > strong {
    min-width: 72px;
}

/* === Archive Growth Area Chart === */
.stats-growth-chart {
    position: relative;
    overflow: hidden;
}

.stats-area-svg {
    display: block;
    max-width: 100%;

    --series-vods: var(--accent-purple);
    --series-runtime: var(--accent-gold);
    --series-storage: #0ea5e9;
}

[data-theme="dark"] .stats-area-svg {
    --series-storage: #38bdf8;
}

.stats-area-grid line {
    stroke: var(--border);
    stroke-width: 1;
    stroke-dasharray: 3 4;
}

.stats-area-label {
    font-size: 11px;
    fill: var(--text-secondary);
    font-family:
        Inter,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
}

.stats-area-crosshair {
    stroke: var(--text-secondary);
    stroke-width: 1;
    stroke-dasharray: 3 4;
    opacity: 0.6;
}

.stats-area-tooltip {
    position: absolute;
    pointer-events: none;
    background: var(--bg-secondary);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: var(--glass-border);
    box-shadow: var(--glass-shadow);
    border-radius: var(--radius);
    padding: 0.6rem 0.85rem;
    font-size: 0.82rem;
    line-height: 1.5;
    z-index: 10;
    white-space: nowrap;
}

.stats-tooltip-label {
    display: block;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.3rem;
}

.stats-tooltip-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
}

.stats-tooltip-row em {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* === Longest Streams === */
.stats-record-row {
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
    padding: 0.65rem 0;
    border-bottom: 1px solid var(--border);
}

.stats-record-row:last-child {
    border-bottom: none;
}

.stats-record-rank {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-secondary);
    min-width: 1.8rem;
    flex-shrink: 0;
}

.stats-record-info {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.stats-record-info a {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stats-record-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* === Calendar Heatmap === */
.stats-heatmap {
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-x: auto;
}

.stats-heatmap-row {
    display: grid;
    grid-template-columns: 3rem repeat(12, minmax(0, 1fr));
    gap: 4px;
    align-items: center;
}

.stats-heatmap-year {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-align: right;
    padding-right: 0.5rem;
    white-space: nowrap;
}

.stats-heatmap-month-label {
    font-size: 0.72rem;
    color: var(--text-secondary);
    text-align: center;
}

.stats-heatmap-cell {
    aspect-ratio: 1;
    border-radius: 3px;
    background: var(--bg-tertiary);
    cursor: default;
    min-width: 0;
}

.stats-heatmap-legend {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 0.75rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.stats-heatmap-legend .stats-heatmap-cell {
    width: 14px;
    height: 14px;
    aspect-ratio: unset;
    flex-shrink: 0;
}

/* === Streaming Habits === */
.stats-freq-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem 1.5rem;
}

.stats-freq-item {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.stats-freq-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.stats-freq-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* === Tables === */
.stats-share-cell {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

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

.stats-table-wrap-large {
    max-height: 620px;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
}

.stats-table th,
.stats-table td {
    padding: 0.8rem 0.65rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.stats-table td {
    font-size: 0.9rem;
}

.stats-table tbody tr:hover td {
    background: var(--bg-tertiary);
}

.stats-sort {
    border: none;
    background: none;
    color: var(--text-secondary);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    padding: 0;
}

.stats-sort:hover {
    color: var(--accent-purple);
}

/* === Pagination === */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin-top: 2rem;
    flex-wrap: wrap;
}

.pagination-pages {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.pagination-current {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius);
    background: var(--button-gradient);
    color: var(--button-foreground);
    font-size: 0.8rem;
    font-weight: 700;
}

.pagination-ellipsis {
    padding: 0 0.5rem;
    color: var(--text-secondary);
}

/* === Theater Mode === */
body.theater-mode {
    overflow: hidden;
}

body.theater-mode .navbar,
body.theater-mode .footer,
body.theater-mode .player-page-top,
body.theater-mode .player-title,
body.theater-mode .tags-section {
    display: none;
}

body.theater-mode .player-footer {
    flex-shrink: 0;
    padding: 0.35rem 0.75rem;
    margin-top: 0;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
    justify-content: flex-end;
}

body.theater-mode .player-info-card,
body.theater-mode .up-next-panel {
    display: none;
}

body.theater-mode .player-layout {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: var(--bg-primary);
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    align-items: stretch;
}

body.theater-mode .player-layout.has-chat {
    grid-template-columns: 1fr 380px;
}

body.theater-mode .player-layout .player-column {
    display: grid;
    align-items: center;
    min-height: 0;
    overflow: hidden;
    background: #000;
}

body.theater-mode .player-layout .player-container {
    width: min(100%, calc(100vh * 16 / 9));
    height: auto;
    max-height: 100vh;
    min-height: 0;
    aspect-ratio: 16 / 9;
    align-self: center;
    border-radius: 0;
    background: #000;
    box-shadow: none;
}

body.theater-mode .player-layout .player-container .mp-wrapper.mp-video {
    width: 100%;
    height: 100%;
    max-height: 100vh;
    min-height: 0;
    aspect-ratio: 16 / 9;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
}

body.theater-mode .player-layout .player-container .mp-wrapper.mp-video video {
    width: 100%;
    height: 100%;
    max-height: none;
    object-fit: contain;
}

body.theater-mode .player-layout .player-sidebar {
    display: none;
}

body.theater-mode .player-layout.has-chat .player-sidebar {
    display: flex;
    min-height: 0;
    max-height: 100vh;
}

body.theater-mode .player-layout.has-chat .chat-panel {
    height: 100vh;
    max-height: 100vh;
    min-height: 0;
    border-radius: 0;
    border-left: 1px solid var(--border);
}
