/**
 * StatsNexus ad slot infrastructure (Phase 3B-A).
 * Reserved dimensions prevent CLS; slots collapse when ADS_ENABLED is off (not rendered).
 */

:root {
    --snx-ad-banner-aspect: 320 / 50;
    --snx-ad-banner-min-h: 50px;
    --snx-ad-leaderboard-aspect: 728 / 90;
    --snx-ad-leaderboard-min-h: 90px;
    --snx-ad-mpu-aspect: 300 / 250;
    --snx-ad-mpu-min-h: 250px;
    --snx-ad-mpu-tall-aspect: 300 / 600;
    --snx-ad-mpu-tall-min-h: 600px;
    --snx-ad-rail-sticky-top: 128px;
    --snx-ad-rail-width: 280px;
    --snx-ad-rail-width-wide: 300px;
    --snx-ad-gutter: var(--page-gutter, 12px);
    --snx-ad-radius: 8px;
    /* Measured .global-header height; synced on mobile/tablet via base.html */
    --snx-global-header-height: 65px;
    --snx-header-banner-sticky-top: var(--snx-global-header-height);
}

/* ── Region wrappers ── */
.snx-ad-banner-region {
    width: min(1350px, calc(100vw - 24px));
    max-width: 100%;
    margin: 0 auto;
    padding: var(--snx-ad-gutter) var(--snx-ad-gutter) 0;
    box-sizing: border-box;
}

/* Mobile/tablet: sticky top banner below sticky global header (Matches excluded) */
@media (max-width: 1133px) {
    body:not(.page-matches) .snx-ad-banner-region {
        position: sticky;
        top: var(--snx-header-banner-sticky-top);
        z-index: 1500;
        background: var(--match-dark-bg, #000);
    }

    [data-theme="light"] body:not(.page-matches) .snx-ad-banner-region {
        background: var(--match-dark-bg, #f5f5f0);
    }
}

@media (min-width: 1134px) {
    body:not(.page-matches) .snx-ad-banner-region {
        position: relative;
        top: auto;
        z-index: auto;
    }
}

/* ── Base slot ── */
.snx-ad-slot {
    position: relative;
    box-sizing: border-box;
    width: 100%;
    margin: 0 auto var(--space-sm, 12px);
    border-radius: var(--snx-ad-radius);
    border: 1px dashed rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.02);
    overflow: hidden;
    contain: layout style;
}

[data-theme="light"] .snx-ad-slot {
    border-color: rgba(15, 23, 42, 0.12);
    background: rgba(15, 23, 42, 0.03);
}

.snx-ad-slot__label {
    position: absolute;
    top: 4px;
    left: 8px;
    z-index: 1;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted, #6b6b68);
    pointer-events: none;
    line-height: 1;
}

.snx-ad-slot__frame {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: inherit;
    box-sizing: border-box;
}

/* ── Header / site banner (320×50 mobile → 728×90 desktop) ── */
.snx-ad-slot--banner {
    width: 100%;
    max-width: min(728px, 100%);
    min-height: var(--snx-ad-banner-min-h);
    aspect-ratio: var(--snx-ad-banner-aspect);
}

@media (min-width: 768px) {
    .snx-ad-slot--banner {
        max-width: min(728px, 100%);
        min-height: 72px;
        aspect-ratio: var(--snx-ad-leaderboard-aspect);
    }
}

@media (min-width: 1024px) {
    .snx-ad-slot--banner {
        min-height: var(--snx-ad-leaderboard-min-h);
    }
}

/* ── Market pages (below filters, above fixture table) ── */
.snx-ad-slot--market-banner,
.market-ad-slot.snx-ad-slot.is-enabled {
    display: flex;
    flex-direction: column;
    max-width: min(728px, 100%);
    min-height: var(--snx-ad-banner-min-h);
    aspect-ratio: var(--snx-ad-banner-aspect);
    margin-bottom: 12px;
}

@media (min-width: 768px) {
    .snx-ad-slot--market-banner,
    .market-ad-slot.snx-ad-slot.is-enabled {
        min-height: 72px;
        aspect-ratio: var(--snx-ad-leaderboard-aspect);
    }
}

@media (min-width: 1024px) {
    .snx-ad-slot--market-banner,
    .market-ad-slot.snx-ad-slot.is-enabled {
        min-height: var(--snx-ad-leaderboard-min-h);
    }
}

/* Legacy hidden market slot when ads disabled */
.market-ad-slot:not(.is-enabled) {
    display: none;
    min-height: 0;
    margin: 0;
    border: 0;
    padding: 0;
}

/* ── MPU sidebar (~300×250) ── */
.snx-ad-slot--mpu {
    max-width: 300px;
    min-height: var(--snx-ad-mpu-min-h);
    aspect-ratio: var(--snx-ad-mpu-aspect);
}

.sidebar--ad-rail {
    align-self: flex-start;
}

/* Sticky MPU below functional sidebar content (matches, stats) */
.sidebar-ad-mpu-wrap {
    width: 100%;
    margin-top: 12px;
}

@media (min-width: 1134px) {
    .sidebar--ad-rail {
        position: sticky;
        top: var(--snx-ad-rail-sticky-top);
    }

    .sidebar--ad-rail .snx-ad-slot--mpu {
        width: 100%;
        max-width: 260px;
    }

    .sidebar--ad-rail .snx-ad-slot--mpu-tall {
        width: 100%;
        max-width: 300px;
    }

    .sidebar-ad-mpu-wrap {
        position: sticky;
        top: var(--snx-ad-rail-sticky-top);
        align-self: flex-start;
    }

    .sidebar-ad-mpu-wrap .snx-ad-slot--mpu {
        width: 100%;
        max-width: 260px;
    }
}

@media (max-width: 1133px) {
    .sidebar--ad-rail,
    .sidebar-ad-mpu-wrap {
        display: none !important;
    }
}

/* Tall MPU for dedicated wide rails (match detail, H2H) */
.snx-ad-slot--mpu-tall {
    max-width: 300px;
    min-height: var(--snx-ad-mpu-tall-min-h);
    aspect-ratio: var(--snx-ad-mpu-tall-aspect);
}

/* Two-column layout for centered pages with desktop ad rail */
@media (min-width: 1134px) {
    body.layout-with-ad-rail.layout-centered .container {
        max-width: min(100%, 1280px) !important;
        justify-content: flex-start !important;
        gap: 20px;
    }

    body.layout-with-ad-rail.layout-centered .sidebar--ad-rail {
        display: block !important;
        flex: 0 0 var(--snx-ad-rail-width-wide);
        min-width: var(--snx-ad-rail-width-wide);
    }

    body.layout-with-ad-rail.layout-centered .content {
        flex: 1 1 auto !important;
        min-width: 0;
        max-width: min(920px, calc(100% - var(--snx-ad-rail-width-wide) - 20px)) !important;
    }
}

/* Competitions: full-width content when ad rail hidden */
body.page-competitions .container {
    justify-content: flex-start !important;
}

body.page-competitions .content {
    flex: 1 1 auto;
    max-width: 100%;
}

/* Prevent ad slots from stealing focus order from primary nav */
.snx-ad-slot[role="complementary"] {
    outline: none;
}

.snx-ad-slot a,
.snx-ad-slot iframe {
    max-width: 100%;
}

/* ── In-feed native slot (/matches between league groups) ── */
.snx-ad-slot--infeed {
    width: 100%;
    max-width: 100%;
    min-height: 50px;
    aspect-ratio: 320 / 50;
    margin: 8px auto 12px;
    border-style: solid;
    border-color: rgba(255, 255, 255, 0.06);
}

@media (min-width: 768px) {
    .snx-ad-slot--infeed {
        min-height: 72px;
        aspect-ratio: 728 / 90;
        max-width: min(728px, 100%);
    }
}

@media (min-width: 1024px) {
    .snx-ad-slot--infeed {
        min-height: 90px;
    }
}

[data-theme="light"] .snx-ad-slot--infeed {
    border-color: rgba(15, 23, 42, 0.1);
}

/* ── Phase C page-level banner wraps (below hero / below filters) ── */
.snx-ad-page-banner-wrap {
    width: 100%;
    max-width: 100%;
    margin: 0 auto 12px;
    box-sizing: border-box;
}

body.layout-centered .snx-ad-page-banner-wrap {
    max-width: min(920px, 100%);
}

body.page-top-insights .snx-ad-page-banner-wrap--ti {
    max-width: min(852px, 100%);
    margin-bottom: 16px;
}

body.page-players .snx-ad-page-banner-wrap--pi {
    margin: 8px 0 12px;
}

.snx-ad-infeed-wrap {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    box-sizing: border-box;
}
