/* ==========================================
   AD CONTAINER STYLES - OPTIMIZED
   ========================================== */

.ad-section {
    background-color: #f8f9fa;
    border-top: 1px solid #e9ecef;
    border-bottom: 1px solid #e9ecef;
    overflow: hidden;
}

.ad-container {
    display: block;
    text-align: center;
    min-height: 90px;
    margin: 0 auto;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    position: relative;
    /* Removed contain: layout to allow proper width calculation by AdSense */
}

/* ==========================================
   RESPONSIVE AD SIZES - CLS PREVENTION
   ========================================== */

@media (min-width: 768px) {
    .ad-container {
        min-height: 120px;
    }
}

@media (min-width: 992px) {
    .ad-container {
        min-height: 150px;
    }
}

/* ==========================================
   LOADING STATES - SMOOTH UX
   ========================================== */

/* Initial state - skeleton loading */
.ad-container:not(.ad-loaded) {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

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

    100% {
        background-position: 200% 0;
    }
}

/* Loaded state - smooth transition */
.ad-container.ad-loaded {
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Error state */
.ad-container.ad-error {
    background: #fff3cd;
    border: 1px dashed #ffc107;
    min-height: 0;
    display: none;
    /* Hide failed ads */
}

/* ==========================================
   AD PLACEMENT SPECIFIC STYLES
   ========================================== */

.ad-container[data-ad="responsive-1"],
.ad-container[data-ad="responsive-2"] {
    width: 100%;
}

.ad-container[data-ad="in-article-1"],
.ad-container[data-ad="in-article-2"] {
    width: 100%;
    margin: 1rem auto;
}

.ad-container[data-ad="sidebar"] {
    width: 100%;
    margin-bottom: 1.5rem;
}

/* ==========================================
   STICKY SIDEBAR AD - OPTIMIZED
   ========================================== */

.sticky-sidebar-ad {
    position: sticky;
    top: 130px;
    z-index: 100;
    margin-bottom: 1.5rem;
    /* Better performance with will-change */
    will-change: transform;
}

/* Ensure sticky works on mobile too */
@media (max-width: 991px) {
    .sticky-sidebar-ad {
        position: relative;
        top: 0;
        will-change: auto;
    }
}

/* ==========================================
   DARK MODE SUPPORT
   ========================================== */

@media (prefers-color-scheme: dark) {
    .ad-section {
        background-color: #212529;
        border-color: #343a40;
    }

    .ad-container:not(.ad-loaded) {
        background: linear-gradient(90deg, #2c2c2c 25%, #3a3a3a 50%, #2c2c2c 75%);
        background-size: 200% 100%;
    }
}

/* ==========================================
   AD LOADING INDICATOR
   ========================================== */

.ad-container::before {
    content: "Advertisement";
    display: block;
    text-align: center;
    font-size: 0.75rem;
    color: #6c757d;
    position: absolute;
    top: 0;
    width: 100%;
    /* Hide when ad loads */
    opacity: 1;
    transition: opacity 0.3s ease;
}

.ad-container.ad-loaded::before {
    opacity: 0;
    pointer-events: none;
}

/* ==========================================
   ADSENSE OPTIMIZATION
   ========================================== */

/* Ensure ads don't break layout on mobile */
.adsbygoogle {
    max-width: 100%;
    overflow: hidden;
    display: block;
}

/* Prevent AdSense from causing layout shift */
ins.adsbygoogle[data-ad-status="unfilled"] {
    display: none !important;
}

/* ==========================================
   PERFORMANCE OPTIMIZATIONS
   ========================================== */

/* Reduce paint/layout recalculations */
.ad-placeholder,
.ad-container {
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* Smooth scrolling for sticky ads */
@media (prefers-reduced-motion: no-preference) {
    .sticky-sidebar-ad {
        transition: transform 0.1s ease-out;
    }
}

/* Disable animations if user prefers reduced motion */
@media (prefers-reduced-motion: reduce) {

    .ad-container,
    .sticky-sidebar-ad {
        animation: none !important;
        transition: none !important;
    }
}