/**
 * Phase 3B-B — information density, responsive filters, matches layout.
 * Scoped to page-matches, page-stats, page-players. Does not touch competition detail.
 */

/* ── B1: /matches fixture row density ─────────────────────────────── */
body.page-matches .enhanced-table tbody tr {
    padding: 7px 10px 7px 8px;
    gap: 6px;
    min-height: 40px;
}

body.page-matches .enhanced-table .team-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: normal;
    overflow-wrap: normal;
    line-height: 1.25;
    display: block;
    min-width: 0;
    max-width: 100%;
    font-size: 13px;
}

/* ── B1: desktop match-time compaction (single-day view) ──────────── */
@media (min-width: 1134px) {
    body.page-matches .match-year,
    body.page-matches .match-date {
        display: none;
    }

    body.page-matches .enhanced-table td.match-time {
        flex: 0 0 36px;
        gap: 0;
        justify-content: center;
    }

    body.page-matches .match-time-val {
        font-size: 12px;
        line-height: 1.2;
        font-weight: 600;
    }

    body.page-matches .enhanced-table tbody tr {
        padding: 6px 10px 6px 8px;
        min-height: 36px;
    }

    /* Live rows: keep minute lane readable */
    body.page-matches .match-row.match-live td.match-time .match-date,
    body.page-matches .match-row[data-status="ongoing"] td.match-time .match-date {
        display: block;
        font-size: 10px;
    }
}

body.page-matches .match-card.compact {
    padding: 14px 12px !important;
}

body.page-matches .league-header-row {
    margin: -12px -6px 0 -6px;
    padding: 6px 10px;
}

body.page-matches .league-header {
    padding: 12px 16px;
    font-size: 15px;
    gap: 10px;
}

body.page-matches .league-logo-wrapper {
    width: 28px;
    height: 28px;
}

body.page-matches .league-logo-wrapper img {
    width: 20px;
    height: 20px;
}

@media (max-width: 480px) {
    body.page-matches .enhanced-table tbody tr {
        padding: 8px 8px 10px;
        gap: 5px;
        min-height: 44px;
    }
}

/* ── B2: /matches filter row — zero horizontal overflow ───────────── */
@media (max-width: 767px) {
    body.page-matches .league-filter-row {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding-right: 0;
    }

    body.page-matches .status-pills {
        flex-wrap: wrap;
        width: 100%;
        gap: 6px;
    }

    body.page-matches .status-pill {
        min-height: 36px;
        padding: 6px 12px;
        flex: 0 1 auto;
    }

    body.page-matches .league-filter-row > div:last-child {
        width: 100%;
        position: relative;
    }

    body.page-matches .league-dropdown-trigger {
        width: 100%;
        justify-content: space-between;
        min-height: 44px;
        padding: 10px 12px;
        border: 1px solid rgba(255, 255, 255, 0.14);
        border-radius: 10px;
        box-sizing: border-box;
    }

    [data-theme="light"] body.page-matches .league-dropdown-trigger {
        border-color: #cbd5e1;
    }

    body.page-matches #leagueDropdown {
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100%;
        box-sizing: border-box;
    }
}

@media (min-width: 768px) and (max-width: 900px) {
    body.page-matches .league-filter-row {
        flex-wrap: wrap;
        gap: 8px;
    }

    body.page-matches .status-pills {
        flex-wrap: wrap;
        flex: 1 1 auto;
        min-width: 0;
    }

    body.page-matches .league-filter-row > div:last-child {
        flex: 0 0 auto;
    }
}

/* ── B7: in-feed ad spacing between league groups ─────────────────── */
body.page-matches .snx-ad-slot--infeed {
    margin: 8px 0 12px;
}

body.page-matches .snx-ad-infeed-wrap {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* ── B4/B5: mobile collapsible filter panels (stats + players) ──────── */
.snx-mobile-filters {
    width: 100%;
}

.snx-mobile-filters__bar {
    display: none;
}

/* Tablet portrait: use collapsed filter shell up to 834px (layout pressure threshold) */
@media (max-width: 834px) {
    body.page-stats .snx-mobile-filters__bar,
    body.page-players .snx-mobile-filters__bar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        padding: 10px 12px;
        margin-bottom: 0;
        background: var(--match-card-bg, #1a1a1a);
        border: 1px solid var(--match-border, #2a2a2a);
        border-radius: 10px;
        box-sizing: border-box;
    }

    body.page-stats .snx-mobile-filters.is-expanded .snx-mobile-filters__bar,
    body.page-players .snx-mobile-filters.is-expanded .snx-mobile-filters__bar {
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
        border-bottom-color: transparent;
        margin-bottom: 0;
    }

    body.page-stats .snx-mobile-filters__summary,
    body.page-players .snx-mobile-filters__summary {
        flex: 1 1 auto;
        min-width: 0;
        margin: 0;
        font-size: 13px;
        font-weight: 600;
        line-height: 1.3;
        color: var(--text-primary, #fff);
        overflow: hidden;
    }

    body.page-stats .snx-mobile-filters__summary-text,
    body.page-players .snx-mobile-filters__summary-text {
        display: block;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    body.page-stats .snx-mobile-filters__summary-label,
    body.page-players .snx-mobile-filters__summary-label {
        display: block;
        font-size: 10px;
        font-weight: 600;
        letter-spacing: 0.04em;
        text-transform: uppercase;
        color: var(--text-muted, #888);
        margin-bottom: 2px;
    }

    body.page-stats .snx-mobile-filters__toggle,
    body.page-players .snx-mobile-filters__toggle {
        flex: 0 0 auto;
        min-height: 44px;
        min-width: 44px;
        padding: 8px 14px;
        border-radius: 8px;
        border: 1px solid rgba(255, 255, 255, 0.18);
        background: rgba(255, 255, 255, 0.04);
        color: var(--text-primary, #fff);
        font-size: 13px;
        font-weight: 600;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    body.page-stats .snx-mobile-filters__toggle:focus-visible,
    body.page-players .snx-mobile-filters__toggle:focus-visible {
        outline: 2px solid var(--global-palette2, #629670);
        outline-offset: 2px;
    }

    [data-theme="light"] body.page-stats .snx-mobile-filters__toggle,
    [data-theme="light"] body.page-players .snx-mobile-filters__toggle {
        border-color: #cbd5e1;
        background: #f8fafc;
        color: #1e293b;
    }

    body.page-stats .snx-mobile-filters:not(.is-expanded) .stats-filter-bar,
    body.page-players .snx-mobile-filters:not(.is-expanded) .stats-filter-bar {
        display: none;
    }

    body.page-stats .snx-mobile-filters.is-expanded .stats-filter-bar,
    body.page-players .snx-mobile-filters.is-expanded .stats-filter-bar {
        display: flex;
        flex-direction: column;
        border-top-left-radius: 0;
        border-top-right-radius: 0;
        margin-top: 0;
    }

    body.page-stats .snx-mobile-filters.is-expanded,
    body.page-players .snx-mobile-filters.is-expanded {
        margin-bottom: 10px;
    }

    /* Hide duplicate inline summary when collapsed panel shows bar summary */
    body.page-stats .snx-mobile-filters:not(.is-expanded) .stats-filter-summary,
    body.page-players .snx-mobile-filters:not(.is-expanded) .stats-filter-summary {
        display: none;
    }
}

@media (min-width: 835px) {
    body.page-stats .snx-mobile-filters__bar,
    body.page-players .snx-mobile-filters__bar {
        display: none !important;
    }
}

/* ── Post-acceptance: /matches mobile control compaction (320–374px) ─ */
@media (max-width: 374px) {
    body.page-matches .match-control-bar {
        margin-bottom: 12px;
    }

    body.page-matches .day-navigation {
        gap: 6px;
        margin-bottom: 8px;
    }

    body.page-matches .day-pill {
        min-width: 68px;
        padding: 6px 8px;
        font-size: 12px;
    }

    body.page-matches .day-pills-container {
        gap: 6px;
    }

    body.page-matches .league-filter-row {
        gap: 6px;
    }

    body.page-matches .status-pill {
        padding: 5px 10px;
        min-height: 34px;
    }
}

/* ── Post-acceptance: touch-friendly truncated team-name reveal ─────── */
@media (max-width: 834px) {
    body.page-matches .team-name.is-truncated {
        display: inline-flex;
        align-items: center;
        gap: 2px;
        max-width: 100%;
        vertical-align: middle;
    }

    body.page-matches .team-name.is-truncated .matches-entity-link,
    body.page-matches .team-name.is-truncated {
        min-width: 0;
    }

    body.page-matches .team-name-reveal-btn {
        flex: 0 0 auto;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 28px;
        height: 28px;
        min-width: 28px;
        min-height: 28px;
        margin: 0;
        padding: 0;
        border: 1px solid rgba(255, 255, 255, 0.18);
        border-radius: 6px;
        background: rgba(255, 255, 255, 0.06);
        color: var(--text-secondary, #ccc);
        font-size: 14px;
        line-height: 1;
        cursor: pointer;
    }

    body.page-matches .team-name-reveal-btn:focus-visible {
        outline: 2px solid var(--match-green, #4a7c59);
        outline-offset: 2px;
    }

    [data-theme="light"] body.page-matches .team-name-reveal-btn {
        border-color: #cbd5e1;
        background: #f8fafc;
        color: #475569;
    }
}

.team-name-popover {
    position: absolute;
    z-index: 1200;
    max-width: min(280px, calc(100vw - 16px));
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: var(--match-card-bg, #1a1a1a);
    color: var(--text-primary, #fff);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.35;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    pointer-events: none;
}

[data-theme="light"] .team-name-popover {
    border-color: #cbd5e1;
    background: #fff;
    color: #0f172a;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}

/* ── Post-acceptance: in-feed ad scroll clearance above bottom nav ── */
@media (max-width: 1133px) {
    body.page-matches .snx-ad-infeed-wrap,
    body.page-top-insights .snx-ad-infeed-wrap {
        scroll-margin-bottom: var(--bottom-nav-offset, calc(4.5rem + env(safe-area-inset-bottom, 0px)));
    }
}
