/**
 * Google AdSense Styling & Placement Control
 * Prevents ads from appearing at awkward positions
 */

/* ============================================
   Ad Container Styling
   ============================================ */

.ad-container {
    margin: 0.5rem 0;
    padding: 0.25rem;
    text-align: center;
    clear: both;
    overflow: hidden;
    min-height: 0;
}

/* Row with ads - reduced spacing */
.row:has(> .ad-container),
.row:has(ins.adsbygoogle) {
    margin-top: 0.5rem !important;
    margin-bottom: 0.5rem !important;
}

/* Header Ad Container - Removes large spacing */
.header-ad-container {
    margin: 0 auto;
    max-width: 100%;
    padding: 0;
}

.header-ad {
    margin: 0;
    padding: 0;
    min-height: 50px;
    max-height: 150px;
    overflow: hidden;
}

/* Ensure ads don't create large spacing */
.header-ad ins.adsbygoogle {
    margin: 0 !important;
    padding: 0 !important;
    max-height: 150px !important;
}

.ad-container-top {
    margin-top: 1rem;
    margin-bottom: 1.5rem;
}

.ad-container-bottom {
    margin-top: 1.5rem;
    margin-bottom: 1rem;
}

.ad-container-sidebar {
    margin: 1rem 0;
    padding: 0.5rem;
}

/* Ad wrapper for responsive control */
.ad-wrapper {
    max-width: 100%;
    margin: 0 auto;
    position: relative;
}

/* ============================================
   AdSense Specific Styling
   ============================================ */

ins.adsbygoogle {
    display: block;
    text-align: center;
    overflow: hidden;
}

/* Prevent ads from breaking layout */
.adsbygoogle {
    max-width: 100%;
    overflow: hidden;
}

/* ============================================
   Responsive Ad Behavior
   ============================================ */

/* Mobile - Stack ads vertically */
@media (max-width: 767px) {
    .ad-container {
        margin: 1rem 0;
        padding: 0.5rem 0;
    }

    .ad-container-top {
        margin-top: 0.5rem;
        margin-bottom: 1rem;
    }

    .ad-container-bottom {
        margin-top: 1rem;
        margin-bottom: 0.5rem;
    }

    /* Hide sidebar ads on mobile */
    .ad-container-sidebar,
    .ad-sidebar-only {
        display: none !important;
    }

    /* Limit ad height on mobile */
    ins.adsbygoogle[data-ad-format="auto"] {
        max-height: 250px;
    }

    /* Mobile-specific ad styling */
    .ad-mobile-only {
        display: block !important;
    }
}

/* Tablet adjustments */
@media (min-width: 768px) and (max-width: 991px) {
    .ad-container {
        margin: 1.25rem 0;
    }

    .ad-container-sidebar {
        margin: 1rem 0;
    }

    /* Hide mobile-only ads */
    .ad-mobile-only {
        display: none !important;
    }
}

/* Desktop - Full ad support */
@media (min-width: 992px) {
    .ad-container {
        margin: 1.5rem 0;
    }

    .ad-container-sidebar {
        position: sticky;
        top: 10px;
        margin: 1rem 0;
    }

    /* Hide mobile-only ads */
    .ad-mobile-only {
        display: none !important;
    }

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

/* ============================================
   Ad Spacing & Separation
   ============================================ */

/* Prevent ads from sticking to content */
.content-before-ad {
    margin-bottom: 1.5rem;
}

.content-after-ad {
    margin-top: 1.5rem;
}

/* Separator line before/after ads (optional) */
.ad-separator-before::before,
.ad-separator-after::after {
    content: '';
    display: block;
    height: 1px;
    background: rgba(0, 0, 0, 0.1);
    margin: 1rem 0;
}

/* ============================================
   Ad Visibility Control
   ============================================ */

/* Hide ads in certain contexts */
.no-ads .ad-container,
.no-ads .adsbygoogle,
body.print .ad-container,
body.print .adsbygoogle {
    display: none !important;
}

/* Hide ads for premium users (if implemented) */
body.premium-user .ad-container,
body.premium-user .adsbygoogle {
    display: none !important;
}

/* Hide specific ad types */
.hide-top-ads .ad-container-top,
.hide-bottom-ads .ad-container-bottom,
.hide-sidebar-ads .ad-container-sidebar {
    display: none !important;
}

/* ============================================
   Ad Placeholder (for blocked ads)
   ============================================ */

.ad-placeholder {
    display: none;
    padding: 2rem;
    text-align: center;
    background: #f5f5f5;
    border: 1px dashed #ccc;
    color: #999;
    font-size: 0.875rem;
    margin: 1rem 0;
}

/* Show placeholder when ads are blocked */
.ad-container:empty + .ad-placeholder {
    display: block;
}

/* ============================================
   Specific Ad Format Styling
   ============================================ */

/* Full-width banner ads */
.ad-format-fullwidth {
    width: 100%;
    max-width: 970px;
    margin: 1.5rem auto;
}

/* Skyscraper ads (sidebar) */
.ad-format-skyscraper {
    width: 120px;
    max-width: 100%;
    margin: 0 auto;
}

@media (min-width: 992px) {
    .ad-format-skyscraper {
        width: 160px;
    }
}

/* Square ads */
.ad-format-square {
    width: 250px;
    max-width: 100%;
    margin: 0 auto;
}

@media (min-width: 768px) {
    .ad-format-square {
        width: 300px;
    }
}

/* ============================================
   Layer/Popup Ad Control
   ============================================ */

.ad-layer-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9999;
    background: #fff;
    padding: 1rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    max-width: 90vw;
    max-height: 90vh;
    overflow: auto;
}

.ad-layer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9998;
}

.ad-layer-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 30px;
    height: 30px;
    background: #000;
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    text-align: center;
    z-index: 10000;
}

.ad-layer-close:hover {
    background: #333;
}

/* Hide layer ads on mobile by default */
@media (max-width: 767px) {
    .ad-layer-popup {
        max-width: 95vw;
        padding: 0.5rem;
    }
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
    .ad-container,
    .adsbygoogle,
    .ad-wrapper,
    .ad-layer-popup,
    .ad-layer-overlay {
        display: none !important;
    }
}

/* ============================================
   Ad Loading State
   ============================================ */

.ad-loading {
    min-height: 50px;
    background: #f5f5f5;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 0.875rem;
}

.ad-loading::after {
    content: 'Werbung wird geladen...';
}

/* Remove loading state when ad is loaded */
.adsbygoogle[data-ad-status="filled"] + .ad-loading {
    display: none;
}

/* ============================================
   Accessibility
   ============================================ */

.ad-label {
    display: block;
    font-size: 0.75rem;
    color: #999;
    text-transform: uppercase;
    text-align: center;
    margin-bottom: 0.5rem;
}

/* Skip ad link for screen readers */
.skip-ad {
    position: absolute;
    left: -9999px;
    top: 0;
}

.skip-ad:focus {
    position: relative;
    left: 0;
    background: #000;
    color: #fff;
    padding: 0.5rem;
    z-index: 10000;
}

/* ============================================
   Animation Control
   ============================================ */

/* Smooth fade-in for loaded ads */
.adsbygoogle[data-ad-status="filled"] {
    animation: adFadeIn 0.3s ease-in;
}

@keyframes adFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Disable animations if user prefers reduced motion */
@media (prefers-reduced-motion: reduce) {
    .adsbygoogle[data-ad-status="filled"] {
        animation: none;
    }
}
