/**
 * Fix pour Google AdSense - Résolution de l'erreur "availableWidth=0"
 *
 * Problème : AdSense se charge avant que le conteneur ait une largeur définie
 * Solution : Donner des dimensions explicites au conteneur
 */

/* Conteneur AdSense avec largeur minimale */
#sticky-ad-placeholder .sidebar-card-content {
    min-width: 250px;  /* Largeur minimale pour AdSense */
    min-height: 250px; /* Hauteur minimale pour AdSense */
    overflow: hidden;  /* Masquer les scrollbars */
}

/* Retirer le padding qui interfère avec AdSense */
#sticky-ad-placeholder .sidebar-card-content:has(.adsbygoogle) {
    padding: 0 !important;
    overflow: visible !important; /* Permettre à l'annonce de dépasser si nécessaire */
    display: block !important; /* Retirer flex pour éviter les contraintes */
    align-items: unset !important;
    justify-content: unset !important;
}

/* Ajuster le conteneur parent pour s'adapter à la hauteur de l'annonce */
.sticky-ad-container:has(.adsbygoogle) {
    /* NE PAS forcer height: auto car sticky-sidebar-ad.css définit une hauteur fixe nécessaire */
    /* height défini par sticky-sidebar-ad.css (400px par défaut) */
    min-height: 250px; /* Hauteur minimale de sécurité */
}

/* Ajuster le placeholder - GARDER LA HAUTEUR HERITÉE */
#sticky-ad-placeholder:has(.adsbygoogle) {
    /* NE PAS forcer height: auto, laisser height: 100% hérité de sticky-sidebar-ad.css */
    /* height: 100% défini dans sticky-sidebar-ad.css ligne 58 */
    min-height: 250px;
    /* display: block supprimé - on garde le flex du parent pour centrer l'annonce */
}

/* S'assurer que l'unité AdSense prend toute la largeur disponible */
.adsbygoogle {
    width: 100%;
    min-width: 250px;
    display: block !important;
}

/* Publicités in-content (index, theme, etc.) - format 728x90 */
.ad-incontent .adsbygoogle {
    min-width: unset;
    margin-top: 10px;
    margin-bottom: 30px;
}

/* Publicités index mobile - format responsive avec limite hauteur */
.ad-incontent[data-unit-id^="index_mobile_"],
.ad-responsive-mobile {
    text-align: center !important;
    display: block !important;
    overflow: hidden !important;
}

.ad-incontent[data-unit-id^="index_mobile_"] .adsbygoogle,
.ad-responsive-mobile .adsbygoogle {
    margin: 0 auto !important;
}

/* Mobile portrait (< 480px) : 320x50 - max 90px */
@media (max-width: 479px) {
    .ad-incontent[data-unit-id^="index_mobile_"],
    .ad-responsive-mobile {
        max-height: 90px !important;
    }

    .ad-incontent[data-unit-id^="index_mobile_"] .adsbygoogle,
    .ad-incontent[data-unit-id^="index_mobile_"] iframe,
    .ad-responsive-mobile .adsbygoogle,
    .ad-responsive-mobile iframe {
        max-height: 90px !important;
    }
}

/* Mobile landscape / Petite tablette (480px - 767px) : 468x60 ou 320x100 - max 100px */
@media (min-width: 480px) and (max-width: 767px) {
    .ad-incontent[data-unit-id^="index_mobile_"],
    .ad-responsive-mobile {
        max-height: 100px !important;
    }

    .ad-incontent[data-unit-id^="index_mobile_"] .adsbygoogle,
    .ad-incontent[data-unit-id^="index_mobile_"] iframe,
    .ad-responsive-mobile .adsbygoogle,
    .ad-responsive-mobile iframe {
        max-height: 100px !important;
    }
}

/* Tablette (768px - 1023px) : 728x90 - max 120px */
@media (min-width: 768px) and (max-width: 1023px) {
    .ad-incontent[data-unit-id^="index_mobile_"],
    .ad-responsive-mobile {
        max-height: 120px !important;
    }

    .ad-incontent[data-unit-id^="index_mobile_"] .adsbygoogle,
    .ad-incontent[data-unit-id^="index_mobile_"] iframe,
    .ad-responsive-mobile .adsbygoogle,
    .ad-responsive-mobile iframe {
        max-height: 120px !important;
    }
}

/* Desktop (>= 1024px) : 728x90 - max 120px */
@media (min-width: 1024px) {
    .ad-incontent[data-unit-id^="index_mobile_"],
    .ad-responsive-mobile {
        max-height: 120px !important;
    }

    .ad-incontent[data-unit-id^="index_mobile_"] .adsbygoogle,
    .ad-incontent[data-unit-id^="index_mobile_"] iframe,
    .ad-responsive-mobile .adsbygoogle,
    .ad-responsive-mobile iframe {
        max-height: 120px !important;
    }
}

/* ============================================
 * SYSTÈME RESPONSIVE MOBILE/DESKTOP
 * Basculement selon la largeur d'écran (pas User-Agent)
 * ============================================ */

/* Par défaut : masquer les deux */
.ad-show-mobile,
.ad-show-desktop {
    display: none !important;
}

/* < 768px : afficher mobile uniquement */
@media (max-width: 767px) {
    .ad-show-mobile {
        display: block !important;
    }

    .ad-show-desktop {
        display: none !important;
    }
}

/* >= 768px : afficher desktop uniquement */
@media (min-width: 768px) {
    .ad-show-mobile {
        display: none !important;
    }

    .ad-show-desktop {
        display: block !important;
    }
}

/* Responsive : adapter selon la taille d'écran */
@media (max-width: 1200px) {
    #sticky-ad-placeholder .sidebar-card-content {
        min-width: 210px;
    }

    .adsbygoogle {
        min-width: 210px;
    }
}

@media (min-width: 1201px) {
    #sticky-ad-placeholder .sidebar-card-content {
        min-width: 310px;
    }

    .adsbygoogle {
        min-width: 310px;
    }
}

/* Fix pour dark mode */
.dark-mode #sticky-ad-placeholder {
    background-color: var(--color-card-bg-dark, #2c3e50);
}

/* ======================================
 * BLOQUER LES PUBLICITÉS AUTOMATIQUES
 * (Overlay/Anchor ads en bas d'écran)
 * ====================================== */

/* Masquer les publicités d'ancrage automatiques (bottom anchor ads) */
/* Ces bannières apparaissent en bas de l'écran via AdSense automatique */
div[data-anchor-status],
div[id^="google_ads_iframe"][id*="anchor"],
.google-auto-placed,
ins.adsbygoogle[data-anchor-status] {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    overflow: hidden !important;
}

/* Alternative : cibler spécifiquement les iframes d'ancrage */
iframe[id*="google_ads_iframe"][id*="anchor"],
iframe[id*="aswift"][style*="fixed"] {
    display: none !important;
}

/* Bloquer la position des publicités latérales automatiques */
/* Forcer position static pour empêcher le suivi au scroll */
div[id*="google_ads_iframe"][id*="side"],
iframe[id*="google_ads_iframe"][id*="side"],
div[data-google-query-id]:not(#sticky-ad-placeholder *),
.google-side-ad,
ins.adsbygoogle[data-ad-format="rectangle"] {
    position: static !important;
    top: auto !important;
    bottom: auto !important;
    left: auto !important;
    right: auto !important;
    transform: none !important;
}

/* Empêcher les publicités de suivre le scroll (fixed/sticky) */
div[style*="position: fixed"]:has(iframe[id*="google_ads"]):not(#sticky-ad-placeholder *),
div[style*="position: sticky"]:has(iframe[id*="google_ads"]):not(#sticky-ad-placeholder *),
div[id^="google_ads_iframe"]:not(#sticky-ad-placeholder div[id^="google_ads_iframe"]) {
    position: static !important;
    position: absolute !important; /* Fallback si static ne fonctionne pas */
    top: 0 !important;
    transform: none !important;
    will-change: auto !important;
}

/* ======================================
 * MASQUER LES PUBLICITÉS AU DESSUS DU HERO
 * ET AVANT LE SCROLL
 * ====================================== */

/* Masquer les publicités latérales par défaut (avant scroll) */
/* Exclure : sidebar (#sticky-ad-placeholder) ET publicités latérales (.side-ad-left/right) */
body:not(.scrolled-past-hero) div[data-google-query-id]:not(#sticky-ad-placeholder *):not(.side-ad-left *):not(.side-ad-right *),
body:not(.scrolled-past-hero) div[id*="google_ads_iframe"][id*="side"]:not(.side-ad-left *):not(.side-ad-right *),
body:not(.scrolled-past-hero) .google-side-ad:not(.side-ad-left *):not(.side-ad-right *),
body:not(.scrolled-past-hero) ins.adsbygoogle[data-ad-format="rectangle"]:not(#sticky-ad-placeholder *):not(.side-ad-left *):not(.side-ad-right *) {
    opacity: 0 !important;
    pointer-events: none !important;
    transition: opacity 0.3s ease;
}

/* Afficher les publicités après scroll */
/* Exclure : sidebar (#sticky-ad-placeholder) ET publicités latérales (.side-ad-left/right) */
body.scrolled-past-hero div[data-google-query-id]:not(#sticky-ad-placeholder *):not(.side-ad-left *):not(.side-ad-right *),
body.scrolled-past-hero div[id*="google_ads_iframe"][id*="side"]:not(.side-ad-left *):not(.side-ad-right *),
body.scrolled-past-hero .google-side-ad:not(.side-ad-left *):not(.side-ad-right *),
body.scrolled-past-hero ins.adsbygoogle[data-ad-format="rectangle"]:not(#sticky-ad-placeholder *):not(.side-ad-left *):not(.side-ad-right *) {
    opacity: 1 !important;
    pointer-events: auto !important;
}

/* Masquer les scrollbars sur le conteneur de la publicité */
#sticky-ad-placeholder {
    overflow: hidden;
}

/* Masquer les scrollbars Webkit (Chrome, Safari, Edge) */
#sticky-ad-placeholder .sidebar-card-content::-webkit-scrollbar,
.adsbygoogle::-webkit-scrollbar {
    display: none;
}

/* Masquer les scrollbars Firefox */
#sticky-ad-placeholder .sidebar-card-content,
.adsbygoogle {
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE et Edge */
}
