/* AdSense Integration Styles */
/* Optimized for Core Web Vitals and minimal layout shift */

/* CSS Custom Properties for Ad Dimensions */
:root {
    --ad-leaderboard-height: 90px;      /* 728x90 desktop/tablet leaderboard */
    --ad-mobile-banner-height: 50px;    /* 320x50 mobile banner */
    --sticky-ad-padding: 20px;          /* Padding around sticky footer ad */
}

/* Common AdSense Container Styles */
.adsense-container {
    width: 100%;
    margin: 0 auto;
    padding: 0;
    box-sizing: border-box;
}

/* Header Banner Ad (Below Navigation) */
.adsense-header {
    max-width: 1200px;
    margin: 20px auto 32px;
    padding: 0 20px;
    text-align: center;
}

/* Ad placeholder prevents layout shift (CLS optimization) */
.ad-placeholder {
    min-height: var(--ad-leaderboard-height); /* Height for 728x90 leaderboard */
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--parking-background, #f8f9fc);
    border: 1px dashed var(--parking-border, #e1e8f0);
    border-radius: 8px;
    transition: all 0.3s ease;
    position: relative; /* Required for absolute positioning of loading spinner */
}

/* AdSense native styling */
.adsbygoogle {
    display: block;
    max-width: 100%;
    overflow: hidden;
}

/* Horizontal banner styling for sticky footer */
.adsense-horizontal-banner {
    display: block;
    width: 100%;
    max-width: 728px;
    height: var(--ad-leaderboard-height);
}

/* Sticky Footer Ad Container */
.adsense-sticky-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 999;
    background: var(--parking-card-bg, #ffffff);
    border-top: 2px solid var(--parking-border, #e1e8f0);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
    padding: 4px 8px;
    animation: slideUp 0.3s ease-out;
}

/* Slide up animation for sticky footer */
@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Sticky ad wrapper with close button */
.sticky-ad-wrapper {
    max-width: 728px;
    margin: 0 auto;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Close button for sticky ad */
.ad-close-btn {
    position: absolute;
    top: 0;
    right: 0;
    background: var(--parking-text-secondary, #4b5563);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 10;
    opacity: 0.7;
    padding: 0;
    margin: 0;
}

.ad-close-btn:hover {
    background: var(--parking-text-primary, #1f2937);
    opacity: 1;
    transform: scale(1.1);
}

.ad-close-btn:active {
    transform: scale(0.95);
}

/* Sticky footer ad placeholder */
.adsense-sticky-footer .ad-placeholder {
    min-height: var(--ad-leaderboard-height);
    width: 100%;
    max-width: 728px;
    background: transparent;
    border: none;
}

/* Accessibility note: Ads are decorative, aria-label is sufficient for screen readers */

/* Tablet optimizations */
@media (max-width: 900px) {
    .adsense-header {
        margin: 16px auto 24px;
        padding: 0 16px;
    }

    .ad-placeholder {
        min-height: var(--ad-leaderboard-height); /* Still 728x90 on tablets */
    }

    .adsense-sticky-footer {
        padding: 4px 8px;
    }
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .adsense-header {
        margin: 12px auto 20px;
        padding: 0 12px;
    }

    .ad-placeholder {
        min-height: var(--ad-mobile-banner-height); /* 320x50 mobile banner height */
        border-radius: 6px;
    }

    .adsense-sticky-footer {
        padding: 2px 4px;
    }

    .sticky-ad-wrapper {
        max-width: 100%;
    }

    .ad-close-btn {
        width: 24px;
        height: 24px;
        top: 0px;
        right: 0px;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    .adsense-header {
        margin: 8px auto 16px;
        padding: 0 8px;
    }

    .ad-placeholder {
        min-height: var(--ad-mobile-banner-height);
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .adsense-sticky-footer {
        animation: none;
    }

    .ad-close-btn {
        transition: none;
    }

    .ad-close-btn:hover {
        transform: none;
    }

    .ad-close-btn:active {
        transform: none;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .ad-placeholder {
        border-width: 2px;
        border-style: solid;
    }

    .adsense-sticky-footer {
        border-top-width: 3px;
    }

    .ad-close-btn {
        border: 2px solid white;
    }
}

/* Dark mode support (if implemented in the future) */
@media (prefers-color-scheme: dark) {
    .ad-placeholder {
        background: rgba(255, 255, 255, 0.05);
        border-color: rgba(255, 255, 255, 0.1);
    }

    .adsense-sticky-footer {
        background: #1a1a1a;
        border-top-color: rgba(255, 255, 255, 0.1);
    }
}

/* Print styles - hide ads when printing */
@media print {
    .adsense-container,
    .adsense-header,
    .adsense-sticky-footer {
        display: none !important;
    }
}

/* Loading state animation */
.ad-placeholder::before {
    content: '';
    display: block;
    width: 40px;
    height: 40px;
    border: 3px solid var(--parking-border, #e1e8f0);
    border-top-color: var(--parking-primary, #0066cc);
    border-radius: 50%;
    animation: adLoading 0.8s linear infinite;
    position: absolute;
    opacity: 0.3;
}

@keyframes adLoading {
    to {
        transform: rotate(360deg);
    }
}

/* Hide loading spinner once ad loads */
/* Note: ::before cannot be applied to ins elements (replaced elements) */
/* Use .ad-filled class controlled by JavaScript for broader browser support */
.ad-placeholder.ad-filled::before {
    display: none;
}

/* Content spacing adjustment to prevent overlap with sticky footer */
/* Only applies when sticky footer ad is present - class added by JavaScript */
body.has-sticky-footer main {
    padding-bottom: calc(var(--ad-leaderboard-height) + var(--sticky-ad-padding)); /* Desktop: leaderboard height + sticky padding */
}

/* Adjust spacing for mobile */
@media (max-width: 768px) {
    body.has-sticky-footer main {
        padding-bottom: calc(var(--ad-mobile-banner-height) + var(--sticky-ad-padding)); /* Mobile: banner height + sticky padding */
    }
}
