/*
 * stats.css — Stats page styles
 * Extends style.css — uses the same CSS variables, never redefines them.
 */

/* ── Layout ────────────────────────────────────────────────────────────────── */

.stats-page .stats-main {
    padding: 24px 40px 80px;
}

@media (max-width: 700px) {
    .stats-page .stats-main { padding: 16px 16px 80px; }
}

/* ── Responsive grid ────────────────────────────────────────────────────── */

.stats-grid,
.stats-detail-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    align-items: stretch;   /* all blocks in a row grow to same height */
    margin-bottom: 20px;
}

/* 2 columns on medium screens */
@media (max-width: 1100px) {
    .stats-grid,
    .stats-detail-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* 1 column on mobile */
@media (max-width: 700px) {
    .stats-grid,
    .stats-detail-grid {
        grid-template-columns: 1fr;
    }
}

/* Blocks inside grid fill their cell height */
.stats-grid > .stats-block,
.stats-detail-grid > .stats-block {
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
}

/* Person list grows to fill remaining block height */
.stats-grid > .stats-block > .stats-person-list,
.stats-detail-grid > .stats-block > .stats-person-list {
    flex: 1;
}

/* ── Search bar in page-top ────────────────────────────────────────────────── */

.stats-search-bar {
    background: var(--bg-elevated);
    border-bottom: 2px solid var(--border);
    padding: 10px 40px;
    position: relative;
    z-index: 10;
}

@media (max-width: 700px) {
    .stats-search-bar { padding: 10px 16px; }
}

.stats-search-inner {
    position: relative;
    display: flex;
    align-items: center;
    max-width: 600px;
}

.stats-search-inner .search-icon {
    position: absolute;
    left: 12px;
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    pointer-events: none;
    flex-shrink: 0;
}

.stats-search-inner .filter-input {
    padding-left: 38px;
    width: 100%;
}

.stats-search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 2px solid var(--border-light);
    border-radius: var(--radius);
    max-height: min(480px, calc(100vh - 200px));
    overflow-y: auto;
    z-index: 200;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

.stats-search-group-label {
    padding: 6px 14px 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent-bright);        /* red label */
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
}

.stats-search-result {
    display: block;
    padding: 8px 14px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.95rem;
    border-bottom: 1px solid var(--border);
    transition: background 0.12s, color 0.12s;
}

.stats-search-result:last-child { border-bottom: none; }

.stats-search-result:hover,
.stats-search-result:focus {
    background: rgba(160,0,0,0.35);     /* stronger red hover */
    color: #fff;
    outline: none;
}

/* "More results" hint at bottom of a group */
.stats-search-more {
    padding: 5px 14px 6px;
    font-size: 0.78rem;
    color: var(--text-muted);
    font-style: italic;
    border-top: 1px solid var(--border);
    background: var(--bg-elevated);
}

.stats-search-year {
    color: var(--text-muted);
    font-size: 0.88rem;
}

.stats-search-known-for {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-style: italic;
}

.stats-search-result--person::before {
    content: '👤 ';
    font-size: 0.8rem;
    opacity: 0.6;
}

/* ── Latest film callout ───────────────────────────────────────────────────── */

.stats-latest {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 28px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 0.95rem;
}

.stats-latest-label { color: var(--text-muted); white-space: nowrap; }

.stats-latest-title {
    color: var(--text-primary);
    font-weight: 600;
    text-decoration: none;
    font-family: var(--font-display);
    letter-spacing: 0.02em;
}

.stats-latest-title:hover { color: var(--accent-bright); text-decoration: underline; }

/* ── Section blocks ────────────────────────────────────────────────────────── */

.stats-block {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    margin-bottom: 24px;
}

.stats-block h2 {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 16px;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

/* ── Charts ────────────────────────────────────────────────────────────────── */

.stats-chart-wrap {
    position: relative;
    width: 100%;
    height: 280px;       /* fixed — never grows or shrinks */
    margin-bottom: 16px;
}

.stats-chart {
    position: absolute;
    top: 0; left: 0;
    width: 100% !important;
    height: 100% !important;
}



/* ── Person list ───────────────────────────────────────────────────────────── */

.stats-person-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stats-person {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 1px);
    overflow: hidden;
    transition: border-color 0.15s;
}

.stats-person:hover { border-color: var(--border-light); }

.stats-person-details > summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    list-style: none;
    color: var(--text-secondary);
    font-size: 0.95rem;
    transition: color 0.12s, background 0.12s;
    user-select: none;
}

/* Expand/collapse chevron — clearly shows the row is toggleable */
.stats-expand-icon {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-style: normal;
    transition: transform 0.18s;
}
.stats-expand-icon::before { content: "▶"; font-size: 0.6rem; }
.stats-person-details[open] > summary .stats-expand-icon { transform: rotate(90deg); }

.stats-person-details > summary::-webkit-details-marker { display: none; }
.stats-person-details > summary::marker { display: none; }

.stats-person-details > summary:hover {
    color: var(--text-primary);
    background: var(--accent-glow);
}

.stats-person-details > summary a {
    color: inherit;
    text-decoration: none;
    font-weight: 500;
    /* no flex:1 — link only covers the name text, not the whole row */
}

/* role label — sits between name and count badge, truncates if long */
.stats-person-details > summary .stats-role {
    flex: 0 1 auto;
    margin-right: 4px;
}

.stats-person-details > summary a:hover {
    color: var(--text-primary);
    text-decoration: underline;
}

.stats-person-details[open] > summary { color: var(--text-primary); }

/* Role label */
.stats-role {
    color: var(--text-muted);
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Count badge */
.stats-count {
    margin-left: auto;
    background: var(--bg-card);
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: 10px;
    padding: 1px 8px;
    min-width: 28px;
    text-align: center;
    white-space: nowrap;
    flex-shrink: 0;
    border: 1px solid var(--border);
}

/* Expandable movie list inside person row */
.stats-movie-list {
    list-style: none;
    margin: 0;
    padding: 8px 12px 10px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.stats-movie-list li { font-size: 0.88rem; }

.stats-movie-list a {
    color: var(--text-muted);
    text-decoration: none;
}

.stats-movie-list a:hover {
    color: var(--accent-bright);
    text-decoration: underline;
}

/* ── "Show more" expander ──────────────────────────────────────────────────── */

.stats-more-details { margin-top: 8px; }

.stats-more-btn {
    display: inline-block;
    cursor: pointer;
    padding: 6px 14px;
    border-radius: var(--radius);
    border: 2px solid var(--border-light);
    background: transparent;
    color: var(--text-muted);
    font-size: 0.875rem;
    list-style: none;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.stats-more-btn::-webkit-details-marker { display: none; }
.stats-more-btn::marker { display: none; }

.stats-more-btn:hover {
    color: var(--text-primary);
    border-color: var(--accent);
    background: var(--accent-glow);
}

.stats-more-details[open] .stats-more-btn { color: var(--text-secondary); }

.stats-more-details > .stats-person-list,
.stats-more-details > .stats-genre-list,
.stats-more-details > .stats-year-list {
    margin-top: 8px;
}

/* ── Genre list ────────────────────────────────────────────────────────────── */

.stats-genre-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stats-genre-item { }

.stats-genre-tag {
    display: inline-block;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 10px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: border-color 0.12s, color 0.12s;
}

.stats-genre-tag:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

/* ── Year list ─────────────────────────────────────────────────────────────── */

.stats-year-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* ── Detail page ───────────────────────────────────────────────────────────── */

.stats-detail-header {
    display: flex;
    gap: 28px;
    align-items: flex-start;
    margin-bottom: 28px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
}

@media (max-width: 600px) {
    .stats-detail-header { flex-direction: column; }
}

.stats-poster-wrap { flex-shrink: 0; }

.stats-poster {
    width: 130px;
    border-radius: calc(var(--radius) - 1px);
    display: block;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}

.stats-detail-meta { flex: 1; min-width: 0; }

.stats-detail-title {
    font-family: var(--font-display);
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 8px;
    line-height: 1.2;
    letter-spacing: 0.02em;
}

.stats-detail-year {
    color: var(--text-muted);
    font-weight: 400;
    font-size: 1.3rem;
}

.stats-detail-genres {
    margin: 0 0 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.stats-detail-overview {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.6;
    margin: 0 0 14px;
}

.stats-detail-links {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 14px;
}

.stats-ep-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 0 14px;
    border: 2px solid var(--border-light);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.stats-ep-link:hover {
    border-color: var(--accent);
    color: var(--text-primary);
    background: var(--accent-glow);
}

.stats-ep-date {
    color: var(--text-muted);
    font-size: 0.82rem;
}

.stats-back-link {
    margin: 4px 0 0;
    font-size: 0.875rem;
}

.stats-back-link a {
    color: var(--text-muted);
    text-decoration: none;
}

.stats-back-link a:hover { color: var(--accent-bright); }

/* ── Compact scrolled state ────────────────────────────────────────────────── */

body.stats-page.scrolled .stats-search-bar {
    /* still visible when scrolled — search is always useful */
}

/* ── TMDb attribution ──────────────────────────────────────────────────────── */

/* Uses existing .tmdb-attribution from style.css — nothing extra needed */

/* ── Genre list toggle (hidden on load) ─────────────────────────────────── */

.stats-genres-toggle {
    margin-top: 12px;
}

.stats-genres-toggle > .stats-genre-list {
    margin-top: 12px;
}



/* ── Year label in release years list ───────────────────────────────────── */

.stats-year-label {
    font-weight: 500;
    color: inherit;
}

/* ── Person detail page ──────────────────────────────────────────────────── */

.stats-person-photo {
    width: 130px;
    border-radius: calc(var(--radius) - 1px);
    display: block;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}

.stats-block--person-movies {
    grid-column: 1 / -1; /* full width in the detail grid */
}

.stats-person-movies-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 10px;
}

.stats-person-movie-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    transition: border-color 0.15s;
}

.stats-person-movie-item:hover {
    border-color: var(--border-light);
}

.stats-person-movie-poster-link {
    flex-shrink: 0;
}

.stats-person-movie-poster {
    width: 40px;
    border-radius: 3px;
    display: block;
}

.stats-person-movie-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.stats-person-movie-title {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stats-person-movie-title:hover {
    color: var(--text-primary);
    text-decoration: underline;
}

.stats-person-movie-info .stats-role {
    font-size: 0.82rem;
}

@media (max-width: 700px) {
    .stats-person-movies-list {
        grid-template-columns: 1fr;
    }
}

/* ── Person bio data ─────────────────────────────────────────────────────── */

.stats-person-bio {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 20px;
    margin: 10px 0 14px;
}

.stats-person-bio-item {
    display: flex;
    gap: 6px;
    font-size: 0.9rem;
}

.stats-person-bio-item dt {
    color: var(--text-muted);
    white-space: nowrap;
}

.stats-person-bio-item dt::after {
    content: ':';
}

.stats-person-bio-item dd {
    color: var(--text-secondary);
    margin: 0;
}

.stats-bio-wrap {
    margin-bottom: 14px;
}

.stats-bio-text {
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-secondary);
    margin: 0 0 4px;
}

.stats-bio-text.js-bio-clamp {
    max-height: 4.8em;   /* ~3 lines */
    overflow: hidden;
}

.stats-bio-text.js-bio-clamp.expanded {
    max-height: none;
}
