/* ── Stats Shell (sidebar + content, mirrors the admin console) ── */

.stats-shell {
    display: flex;
    align-items: flex-start;
    width: 100%;
    max-width: 1560px;
    margin: 0 auto;
    text-align: left;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.stats-sidebar {
    position: sticky;
    top: 140px; /* below fixed site header (70px) + action bar (70px) */
    flex: 0 0 230px;
    /* Fill the gap between the fixed top chrome (140px) and the footer
       (70px), minus the rail's own 16px margins, so a short tab needs no
       scroll to reach the footer. */
    height: calc(100vh - 242px);
    overflow-y: auto;
    background: rgba(8, 8, 8, 0.82);
    border: 1px solid rgba(255, 191, 0, 0.12);
    border-radius: 14px;
    margin: 16px 0 16px 16px;
    padding: 12px 10px 18px;
    box-sizing: border-box;
    scrollbar-width: thin;
}

/* main.css sets a global `nav { display:flex; justify-content:center }` for
   the site header — without this override the groups flow left-to-right. */
.stats-nav {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    text-align: left;
}

.stats-nav-group {
    margin-bottom: 6px;
}

.stats-nav-group-label {
    font-family: 'HwyGothic', Arial, sans-serif;
    font-size: 0.58rem;
    letter-spacing: 2.5px;
    text-transform: uppercase;
    color: rgba(240, 236, 230, 0.32);
    padding: 14px 12px 6px;
}

/* ── Content column + top bar ─────────────────────────────── */
.stats-content-col {
    flex: 1;
    min-width: 0;
}

.stats-topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 24px 0;
    max-width: 1200px;
    margin: 0 auto;
    box-sizing: border-box;
}

.stats-heading {
    font-family: 'DragonSlayer', serif;
    color: #ffbf00;
    font-size: 1.5rem;
    letter-spacing: 4px;
    margin: 0;
    flex: 1;
    text-align: left;
    text-shadow: 0 0 14px rgba(255, 191, 0, 0.18);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stats-page {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 18px 24px 80px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    box-sizing: border-box;
}

/* Centered top-of-page caption. Slight dark pill so it reads cleanly against
   the page bg without over-shouting. */
.stats-tagline {
    color: rgba(240, 236, 230, 0.9);
    font-family: 'HwyGothic', Arial, sans-serif;
    font-size: 0.85rem;
    letter-spacing: 1px;
    text-align: center;
    background: #1c1c1c;
    border: 1px solid rgba(255, 191, 0, 0.25);
    border-radius: 6px;
    padding: 8px 14px;
    align-self: center;
    max-width: 100%;
}

.stats-stats-start {
    color: rgba(240, 236, 230, 0.65);
    font-family: 'HwyGothic', Arial, sans-serif;
    font-size: 0.72rem;
    letter-spacing: 0.5px;
    text-align: center;
    margin-top: -8px;
    min-height: 1em;
}

/* Admin-only manual recompute control. Sits above the tabs, only revealed by
   stats.js when the signed-in user has admin=true; the endpoint also enforces
   admin server-side, so the CSS hide is purely UX. */
.stats-admin-bar {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    background: #1c1c1c;
    border: 1px solid rgba(255, 191, 0, 0.25);
    border-radius: 6px;
    padding: 10px 14px;
    align-self: center;
    max-width: 100%;
}

.stats-admin-info {
    color: rgba(240, 236, 230, 0.78);
    font-family: 'HwyGothic', Arial, sans-serif;
    font-size: 0.78rem;
    letter-spacing: 0.5px;
}

.stats-admin-btn {
    background: rgba(255, 191, 0, 0.18);
    border: 1px solid rgba(255, 191, 0, 0.45);
    color: #ffbf00;
    padding: 6px 14px;
    border-radius: 6px;
    font-family: 'HwyGothic', Arial, sans-serif;
    font-size: 0.72rem;
    letter-spacing: 1.5px;
    cursor: pointer;
    transition: background 0.2s;
}

.stats-admin-btn:hover { background: rgba(255, 191, 0, 0.3); }
.stats-admin-btn:disabled { opacity: 0.5; cursor: default; }

/* ── Sidebar nav items (the old tab strip, restyled) ──────── */
.stats-tab {
    display: flex;
    align-items: center;
    gap: 11px;
    width: 100%;
    height: auto; /* override global button height */
    background: transparent;
    border: none;
    border-radius: 9px;
    padding: 10px 12px;
    color: rgba(240, 236, 230, 0.55);
    font-family: 'HwyGothic', Arial, sans-serif;
    font-size: 0.78rem;
    letter-spacing: 1.5px;
    cursor: pointer;
    text-align: left;
    transition: background 0.2s, color 0.2s;
    box-sizing: border-box;
}

.stats-tab > i:first-child {
    width: 18px;
    text-align: center;
    font-size: 0.8rem;
    color: rgba(255, 191, 0, 0.45);
    transition: color 0.2s;
    flex-shrink: 0;
}

.stats-tab > span {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stats-tab:hover {
    color: rgba(240, 236, 230, 0.9);
    background: rgba(255, 255, 255, 0.04);
}

.stats-tab.active {
    background: rgba(255, 191, 0, 0.13);
    color: #ffbf00;
}

.stats-tab.active > i:first-child {
    color: #ffbf00;
}

.stats-lock-icon {
    font-size: 0.62rem;
    opacity: 0.55;
    flex-shrink: 0;
}

/* Subscriber lock/crown pattern, matching the play page's Spectate button:
   non-subscribers see a lock, subscribers see a crown — never both. */
.stats-crown-icon {
    display: none;
    font-size: 0.62rem;
    color: rgba(255, 191, 0, 0.85);
    flex-shrink: 0;
}

.stats-tab-premium.stats-unlocked .stats-lock-icon {
    display: none;
}

.stats-tab-premium.stats-unlocked .stats-crown-icon {
    display: inline-block;
}

/* ── Panels ──────────────────────────────────────────────── */
.stats-panel {
    display: none;
    position: relative;
}

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

.stats-content {
    transition: filter 0.2s;
}

.stats-content-locked {
    filter: blur(4px) saturate(0.5);
    pointer-events: none;
    user-select: none;
}

/* ── Lock Overlay ────────────────────────────────────────── */
/* Popup is anchored to the top of the panel (just under the tabs) instead of
   centered. Centering looked fine on average-height panels, but tall ones (Decks)
   pushed the popup hundreds of pixels off-screen and short ones (Matchup) made
   the larger popup card overflow above the panel into the tab row. */
.stats-locked-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background: rgba(14, 14, 14, 0.65);
    backdrop-filter: blur(2px);
    border-radius: 6px;
    padding: 24px 16px;
    box-sizing: border-box;
}

.stats-locked-overlay[hidden] {
    display: none;
}

/* Locked panels get a comfortable min-height so the popup card never overflows
   above the panel's top edge into the tabs (which happens when the panel's
   actual content is shorter than the popup itself). :has() lets us target only
   the panels currently showing an unhidden lock overlay. */
.stats-panel.active:has(.stats-locked-overlay:not([hidden])) {
    min-height: 340px;
}

.stats-lock-content {
    background: #1c1c1c;
    border: 1px solid rgba(255, 191, 0, 0.3);
    border-radius: 6px;
    padding: 28px 36px;
    text-align: center;
    max-width: 380px;
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
}

.stats-lock-content i.fas.fa-lock {
    font-size: 1.8rem;
    color: #ffbf00;
    margin-bottom: 10px;
}

.stats-lock-content h3 {
    font-family: 'Dragon Slayer', serif;
    color: #ffbf00;
    margin: 6px 0 10px;
    letter-spacing: 1px;
}

.stats-lock-content p {
    font-family: 'HwyGothic', Arial, sans-serif;
    color: rgba(240, 236, 230, 0.7);
    margin: 0 0 16px;
    font-size: 0.85rem;
    line-height: 1.4;
}

.stats-subscribe-btn {
    display: inline-block;
    background: rgba(255, 191, 0, 0.15);
    border: 1px solid rgba(255, 191, 0, 0.5);
    color: #ffbf00;
    padding: 10px 28px;
    border-radius: 6px;
    font-family: 'HwyGothic', Arial, sans-serif;
    letter-spacing: 2px;
    text-decoration: none;
    font-size: 0.85rem;
    transition: background 0.2s;
}

.stats-subscribe-btn:hover {
    background: rgba(255, 191, 0, 0.28);
}

/* Inline column blur (premium-only columns when locked) */
.stats-blurred {
    filter: blur(5px);
    user-select: none;
    pointer-events: none;
}

/* ── Action Bar (search, buttons) ────────────────────────── */
.stats-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.stats-search {
    flex: 1;
    min-width: 200px;
    background: #1c1c1c;
    border: 1px solid rgba(255, 191, 0, 0.25);
    border-radius: 6px;
    padding: 10px 16px;
    color: #f0ece6;
    font-family: 'HwyGothic', Arial, sans-serif;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
    outline: none;
    transition: border-color 0.2s;
}

.stats-search:focus {
    border-color: rgba(255, 191, 0, 0.5);
}

.stats-search::placeholder {
    color: rgba(240, 236, 230, 0.3);
}

.stats-btn-primary,
.stats-btn-secondary {
    background: rgba(255, 191, 0, 0.15);
    border: 1px solid rgba(255, 191, 0, 0.3);
    border-radius: 6px;
    padding: 10px 18px;
    color: #ffbf00;
    font-family: 'HwyGothic', Arial, sans-serif;
    font-size: 0.8rem;
    letter-spacing: 2px;
    cursor: pointer;
    transition: background 0.2s;
}

.stats-btn-primary:hover,
.stats-btn-secondary:hover {
    background: rgba(255, 191, 0, 0.28);
}

.stats-btn-secondary {
    background: rgba(255, 255, 255, 0.04);
    color: rgba(240, 236, 230, 0.85);
    border-color: rgba(255, 255, 255, 0.12);
}

.stats-btn-secondary:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* ── Tables ──────────────────────────────────────────────── */
.stats-table-wrap {
    background: #1c1c1c;
    border: 1px solid rgba(255, 191, 0, 0.3);
    border-radius: 6px;
    overflow: auto;
}

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

.stats-table th,
.stats-table td {
    padding: 3px 14px;
    font-family: 'HwyGothic', Arial, sans-serif;
    font-size: 0.82rem;
    letter-spacing: 0.5px;
    border-bottom: 1px solid rgba(255, 191, 0, 0.06);
    text-align: center;
    white-space: nowrap;
    line-height: 1.2;
}

.stats-table th {
    padding-top: 6px;
    padding-bottom: 6px;
}

.stats-table th {
    background: rgba(255, 191, 0, 0.1);
    color: #ffbf00;
    font-size: 0.7rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    position: sticky;
    top: 0;
    z-index: 1;
    border-bottom: 1px solid rgba(255, 191, 0, 0.25);
}

.stats-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.stats-table th.sortable:hover {
    background: rgba(255, 191, 0, 0.14);
}

/* Sort direction indicators — a faint hint on every sortable column,
   a solid arrow on the active one. */
.stats-table th.sortable::after {
    content: '\2195';
    margin-left: 5px;
    font-size: 0.85em;
    opacity: 0.3;
}

.stats-table th.sortable.sorted-asc::after {
    content: '\25B2';
    opacity: 1;
}

.stats-table th.sortable.sorted-desc::after {
    content: '\25BC';
    opacity: 1;
}

.stats-table td {
    color: rgba(240, 236, 230, 0.82);
}

.stats-table tr:hover td {
    background: rgba(255, 191, 0, 0.03);
}

.stats-table tr:last-child td {
    border-bottom: none;
}

.stats-num {
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.stats-loading {
    text-align: center;
    color: rgba(240, 236, 230, 0.6);
    font-style: italic;
    padding: 24px 16px;
}

.stats-card-link {
    color: rgba(240, 236, 230, 0.92);
    text-decoration: none;
    border-bottom: 1px dotted rgba(255, 191, 0, 0.3);
}

.stats-card-link:hover {
    color: #ffbf00;
}

/* ── Expandable deck rows (Decks tab) ───────────────────────── */
.stats-deck-row {
    cursor: pointer;
}

.stats-deck-name-cell {
    white-space: nowrap;
}

.stats-deck-chevron {
    font-size: 0.7rem;
    color: rgba(255, 191, 0, 0.55);
    margin-right: 8px;
    transition: transform 0.18s ease;
    display: inline-block;
}

.stats-deck-row.expanded .stats-deck-chevron {
    transform: rotate(90deg);
    color: #ffbf00;
}

.stats-table tr.stats-deck-row.expanded > td {
    background: rgba(255, 191, 0, 0.06);
}

.stats-deck-detail > td {
    padding: 0;
    background: #161616;
}

.stats-table tr.stats-deck-detail:hover > td {
    background: #161616;
}

.stats-deck-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 12px 14px;
    justify-content: flex-start;
}

.stats-deck-card {
    position: relative;
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
}

.stats-deck-card img {
    width: 70px;
    height: 98px;
    border-radius: 6px;
    display: block;
}

.stats-deck-card-badge {
    position: absolute;
    top: 3px;
    right: 3px;
    background: #ffbf00;
    color: #0e0e0e;
    font-family: 'HwyGothic', Arial, sans-serif;
    font-size: 0.6rem;
    font-weight: bold;
    padding: 2px 5px;
    border-radius: 8px;
    min-width: 14px;
    text-align: center;
    line-height: 1.2;
}

.stats-delta-pos { color: #6dd47e; }
.stats-delta-neg { color: #f47670; }

/* ── Section Titles & Notes ──────────────────────────────── */
.stats-section-title {
    font-family: 'Dragon Slayer', serif;
    color: #ffbf00;
    font-size: 1.1rem;
    letter-spacing: 1.5px;
    margin: 16px 0 8px;
}

/* Captions/notes that sit underneath section titles. Slight dark pill keeps
   them legible against the dark page bg, matching the .admin-result-count look. */
.stats-section-note {
    color: rgba(240, 236, 230, 0.9);
    font-family: 'HwyGothic', Arial, sans-serif;
    font-size: 0.8rem;
    margin-bottom: 10px;
    letter-spacing: 0.5px;
    background: #1c1c1c;
    border: 1px solid rgba(255, 191, 0, 0.25);
    border-radius: 6px;
    padding: 8px 12px;
    display: inline-block;
    max-width: 100%;
}

/* ── Matchup ─────────────────────────────────────────────── */
.stats-matchup-pickers {
    display: flex;
    align-items: end;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.stats-matchup-pick {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 180px;
}

.stats-matchup-pick label {
    color: rgba(240, 236, 230, 0.55);
    font-family: 'HwyGothic', Arial, sans-serif;
    font-size: 0.7rem;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.stats-matchup-pick select {
    background: #1c1c1c;
    border: 1px solid rgba(255, 191, 0, 0.25);
    border-radius: 6px;
    padding: 10px 14px;
    color: #f0ece6;
    font-family: 'HwyGothic', Arial, sans-serif;
    font-size: 0.85rem;
    outline: none;
}

.stats-matchup-vs {
    color: #ffbf00;
    font-family: 'Dragon Slayer', serif;
    font-size: 1.1rem;
    padding-bottom: 8px;
}

.stats-matchup-card {
    background: #1c1c1c;
    border: 1px solid rgba(255, 191, 0, 0.3);
    border-radius: 6px;
    padding: 22px 24px;
}

.stats-matchup-pair {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    font-family: 'Dragon Slayer', serif;
    font-size: 1.4rem;
    color: #ffbf00;
    letter-spacing: 1.5px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.stats-matchup-amp {
    color: rgba(240, 236, 230, 0.45);
    font-family: 'HwyGothic', Arial, sans-serif;
    font-size: 0.95rem;
}

.stats-matchup-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    text-align: center;
}

.stats-matchup-stats > div {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* "On their own" comparison line under the combined matchup numbers */
.stats-matchup-solo {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    text-align: center;
    font-family: 'HwyGothic', Arial, sans-serif;
    font-size: 0.78rem;
    letter-spacing: 0.5px;
    color: rgba(240, 236, 230, 0.55);
}

.stats-stat-label {
    font-family: 'HwyGothic', Arial, sans-serif;
    color: rgba(240, 236, 230, 0.5);
    font-size: 0.75rem;
    letter-spacing: 2px;
}

.stats-stat-value {
    font-family: 'HwyGothic', Arial, sans-serif;
    color: #ffbf00;
    font-size: 1.4rem;
    letter-spacing: 1px;
}

/* ── Win-conditions share bars ───────────────────────────── */
.stats-wc-cell {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    min-width: 90px;
    padding: 2px 0;
}

.stats-wc-num {
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

.stats-wc-bar {
    width: 90px;
    height: 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    overflow: hidden;
}

.stats-wc-fill {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, rgba(255, 191, 0, 0.55), #ffbf00);
    transition: width 0.5s ease;
}

/* ── Trend Chart ─────────────────────────────────────────── */
.stats-chart-wrap {
    background: #1c1c1c;
    border: 1px solid rgba(255, 191, 0, 0.3);
    border-radius: 6px;
    padding: 16px;
    height: 360px;
}

/* ── Responsive: sidebar becomes a wrapping chip bar ──────── */
@media only screen and ((max-width: 1024px) or (hover: none)) {
    .stats-shell {
        flex-direction: column;
    }

    .stats-sidebar {
        position: static;
        flex: none;
        width: auto;
        height: auto;
        max-height: none;
        overflow: visible;
        margin: 10px 10px 0;
        padding: 8px;
        border-radius: 12px;
    }

    .stats-nav {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        justify-content: center;
        gap: 6px;
    }

    /* Flatten the groups into one wrapping chip row */
    .stats-nav-group {
        display: contents;
    }

    .stats-nav-group-label {
        display: none;
    }

    .stats-tab {
        width: auto;
        flex: 0 0 auto;
        white-space: nowrap;
        padding: 8px 13px;
        gap: 7px;
        font-size: 0.68rem;
        border: 1px solid rgba(255, 191, 0, 0.14);
        border-radius: 999px;
    }

    .stats-tab.active {
        border-color: rgba(255, 191, 0, 0.55);
    }

    .stats-tab > i:first-child {
        width: auto;
    }

    .stats-topbar {
        padding: 12px 10px 0;
    }

    .stats-heading {
        font-size: 1.2rem;
        letter-spacing: 3px;
    }
}

/* ── Responsive: mobile ──────────────────────────────────── */
@media only screen and ((max-width: 767px) or (hover: none)) {
    .stats-page {
        padding: 12px 12px 60px;
    }

    .stats-table th,
    .stats-table td {
        padding: 2px 9px;
        font-size: 0.76rem;
    }
    .stats-table th {
        padding-top: 5px;
        padding-bottom: 5px;
    }

    .stats-matchup-stats {
        grid-template-columns: 1fr;
    }

    .stats-chart-wrap {
        height: 280px;
    }
}
