/**
 * Adsterra Ad Styles - Optimized for User Experience
 * Prevents Cumulative Layout Shift (CLS) with explicit container heights
 * Priority: User Experience FIRST, Revenue SECOND
 */

/* ============================================
   BASE AD CONTAINER STYLES
   ============================================ */
.ad-container {
    position: relative;
    text-align: center;
    margin: 1.5rem auto;
    background: transparent;
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    contain: layout style paint;
    will-change: opacity;
    transition: opacity 0.3s ease-in-out;
    opacity: 0; /* Hidden until loaded to prevent flash */
}

.ad-container.loading,
.ad-container.loaded {
    opacity: 1;
}

.ad-label {
    font-size: 0.7rem;
    color: var(--text-tertiary, #94a3b8);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 6px;
    font-weight: 600;
    opacity: 0.8;
}

/* Constrain internal Adsterra elements */
.adsterra-ad {
    max-width: 100%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.adsterra-ad iframe {
    max-width: 100%;
    display: block;
    border: none;
    border-radius: 8px;
}

/* ============================================
   CONTAINER HEIGHTS (CLS Prevention)
   ============================================ */

/* Leaderboard (banner-top and banner-bottom) */
/* Desktop/Tablet viewports load 728x90 ad + 16px label */
.ad-container.leaderboard {
    min-height: 106px;
    height: 106px;
    max-height: 106px;
    max-width: 728px;
    margin: 2rem auto;
}

/* Mobile viewports override to load 300x250 rectangle format */
@media (max-width: 767px) {
    .ad-container.leaderboard {
        min-height: 266px;
        height: 266px;
        max-height: 266px;
        max-width: 336px;
    }
}

/* In-Content Medium Rectangle (in-content) */
.ad-container.medium-rectangle {
    min-height: 266px;
    height: 266px;
    max-height: 266px;
    max-width: 336px;
    margin: 2.5rem auto;
}

/* Native Banner Ad (native) */
.ad-container.native {
    min-height: 250px;
    max-width: 100%;
    margin: 2rem auto;
}

/* ============================================
   MOBILE STICKY BOTTOM BANNER (320x50)
   ============================================ */
.ad-sticky-bottom {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: var(--card-bg, #ffffff);
    box-shadow: 0 -3px 12px rgba(0, 0, 0, 0.08);
    max-width: 320px;
    margin: 0 auto;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    min-height: 66px; /* 50px ad + 16px padding/label */
    height: 66px;
    max-height: 66px;
    padding: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    overflow: hidden;
    transform: translateY(0);
    transition: transform 0.3s ease;
}

.ad-sticky-bottom .ad-label {
    font-size: 0.65rem;
    margin-bottom: 2px;
    margin-top: 2px;
}

.ad-close-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(148, 163, 184, 0.2);
    color: var(--text-secondary, #475569);
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.2s, color 0.2s;
}

.ad-close-btn:hover {
    background: rgba(148, 163, 184, 0.4);
    color: var(--text-heading, #0f172a);
}

.ad-close-btn svg {
    width: 10px;
    height: 10px;
}

@media (min-width: 768px) {
    .ad-sticky-bottom {
        display: none !important;
    }
}

/* Add bottom padding to body when mobile banner is active */
@media (max-width: 767px) {
    body.has-mobile-banner {
        padding-bottom: 66px !important;
    }
}

/* ============================================
   SIDE RAIL ADS (Desktop Only, 1400px+)
   ============================================ */
.side-rail {
    display: none;
    position: fixed;
    top: 120px;
    width: 160px;
    z-index: 100;
    background: transparent;
    margin: 0;
}

/* Left Skyscraper (160x600) */
.side-rail.left {
    left: 24px;
    min-height: 616px;
    height: 616px;
    max-height: 616px;
}

/* Right Skyscraper (160x300) */
.side-rail.right {
    right: 24px;
    min-height: 316px;
    height: 316px;
    max-height: 316px;
}

@media (min-width: 1400px) {
    .side-rail {
        display: flex;
    }
    
    /* Center main layout and ensure no overlap */
    .container,
    main {
        max-width: 1000px;
        margin: 0 auto;
    }
}

/* ============================================
   SHIMMER SKELETON LOADING EFFECT
   ============================================ */
.ad-shimmer {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, 
        var(--card-bg, #f8fafc) 0%, 
        var(--light-bg, #e2e8f0) 50%, 
        var(--card-bg, #f8fafc) 100%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 8px;
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* Remove shimmer when ad loaded */
.ad-container.loaded .ad-shimmer,
.ad-sticky-bottom.loaded .ad-shimmer {
    display: none !important;
}

/* ============================================
   DARK MODE SUPPORT
   ============================================ */
[data-theme="dark"] .ad-shimmer {
    background: linear-gradient(90deg, 
        var(--card-bg, #1e293b) 0%, 
        var(--light-bg, #334155) 50%, 
        var(--card-bg, #1e293b) 100%);
}

[data-theme="dark"] .ad-sticky-bottom {
    background: var(--card-bg, #0f172a);
    box-shadow: 0 -3px 12px rgba(0, 0, 0, 0.4);
    border-top: 1px solid var(--card-border, #1e293b);
}

[data-theme="dark"] .ad-close-btn {
    background: rgba(100, 116, 139, 0.2);
    color: var(--text-secondary, #94a3b8);
}

[data-theme="dark"] .ad-close-btn:hover {
    background: rgba(100, 116, 139, 0.4);
    color: var(--text-heading, #f8fafc);
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    .ad-container,
    .side-rail,
    .ad-sticky-bottom {
        display: none !important;
    }
}
