/**
 * Modern Ad System Styling
 * Mobile-first, non-intrusive ad placement
 */

/* ============================================
   AD CONTAINER BASE STYLES
   ============================================ */

.ad-container {
    position: relative;
    background: var(--bg-primary, #ffffff);
    border: 1px solid var(--border, #e2e8f0);
    border-left: 3px solid var(--primary, #6366f1);
    border-radius: var(--radius-md, 0.5rem);
    padding: var(--space-4, 1rem);
    margin: var(--space-8, 2rem) 0;
    text-align: center;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.ad-container:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* Ad Label (Required by AdSense) */
.ad-label {
    font-size: var(--text-xs, 0.75rem);
    color: var(--text-muted, #94a3b8);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-2, 0.5rem);
    text-align: center;
    font-weight: 500;
}

/* ============================================
   IN-CONTENT AD STYLES
   ============================================ */

.ad-in-content-top,
.ad-in-content-mid {
    min-height: 90px; /* Prevent layout shift */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Desktop: Leaderboard */
@media (min-width: 992px) {
    .ad-in-content-top {
        min-height: 90px;
        padding: var(--space-6, 1.5rem);
        max-width: 970px;
        margin-left: auto;
        margin-right: auto;
    }

    .ad-in-content-mid {
        min-height: 280px; /* Accommodate 336x280 */
        max-width: 336px;
        margin-left: auto;
        margin-right: 0; /* Right-align for better visibility */
    }
}

/* Tablet */
@media (min-width: 768px) and (max-width: 991px) {
    .ad-in-content-top {
        min-height: 90px;
    }

    .ad-in-content-mid {
        min-height: 250px;
        max-width: 300px;
        margin-left: auto;
        margin-right: auto;
    }
}

/* Mobile */
@media (max-width: 767px) {
    .ad-container {
        margin: var(--space-6, 1.5rem) 0;
        padding: var(--space-3, 0.75rem);
    }

    .ad-in-content-top {
        min-height: 100px;
    }

    .ad-in-content-mid {
        min-height: 250px;
        width: 100%;
        max-width: 100%;
    }
}

/* ============================================
   HERO BANNER AD (Above-the-fold, inside hero)
   ============================================ */

.ad-hero-banner {
    margin: 0;
    border: none;
    border-left: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    padding: 8px 0;
    min-height: 50px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.ad-hero-banner:hover {
    transform: none;
    box-shadow: none;
}

.ad-hero-banner .ad-label {
    font-size: 9px;
    margin-bottom: 4px;
    opacity: 0.6;
}

/* Desktop: wide leaderboard */
@media (min-width: 992px) {
    .ad-hero-banner {
        min-height: 90px;
        max-width: 970px;
        margin: 0 auto;
        padding: 10px 0;
    }
}

/* Tablet */
@media (min-width: 768px) and (max-width: 991px) {
    .ad-hero-banner {
        min-height: 90px;
        max-width: 728px;
        margin: 0 auto;
    }
}

/* Mobile */
@media (max-width: 767px) {
    .ad-hero-banner {
        min-height: 50px;
        padding: 6px 0;
    }
}

/* Collapse if empty (no ad fill) */
.ad-hero-banner:not(.ad-loaded) {
    min-height: 0;
    padding: 0;
}

/* Dark theme */
[data-theme="dark"] .ad-hero-banner {
    background: transparent;
    border-color: transparent;
}

/* ============================================
   FLOATING RIGHT AD STYLES (Desktop Only)
   ============================================ */

.ad-floating-right {
    position: fixed;
    right: 10px;  /* Moved closer to edge */
    top: 100px;
    width: 300px;  /* Slightly smaller to fit better */
    max-width: 300px;
    z-index: 100;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    transform: translateX(20px);
    margin: 0;
    border-radius: var(--radius-lg, 0.75rem);
}

.ad-floating-right.ad-visible {
    display: block;
    opacity: 1;
    transform: translateX(0);
}

/* Hide on mobile/tablet and smaller desktop screens */
@media (max-width: 1299px) {
    .ad-floating-right {
        display: none !important;
    }
}

/* Desktop - only show on screens 1300px+ */
/* Hide floating right ad when right column ads are present */
@media (min-width: 1300px) {
    body.has-right-ads .ad-floating-right {
        display: none !important;
    }
    
    .ad-floating-right {
        min-height: 250px;
        bottom: 120px; /* Above sticky footer */
        right: 15px;  /* Safe distance from edge */
    }
}

/* Large screens - more breathing room */
@media (min-width: 1440px) {
    .ad-floating-right {
        right: 25px;
        width: 336px;  /* Can show full size on larger screens */
        max-width: 336px;
    }
}

/* Extra large screens - optimal positioning */
@media (min-width: 1600px) {
    .ad-floating-right {
        right: 40px;
    }
}

/* Ultra-wide screens */
@media (min-width: 1920px) {
    .ad-floating-right {
        right: 60px;
    }
}

/* Close button for floating ad */
.ad-floating-right .ad-close {
    top: var(--space-2, 0.5rem);
    right: var(--space-2, 0.5rem);
    z-index: 2;
}

/* ============================================
   RIGHT COLUMN AD CONTAINER (Desktop Only)
   Uses empty space on the right side
   ============================================ */

.ad-right-column {
    position: fixed;
    right: 10px;
    top: 100px;
    width: 300px;
    max-width: 300px;
    z-index: 99;
    display: none;
    flex-direction: column;
    gap: 1.5rem;
}

/* Show right column ads on large desktop screens */
/* Use dedicated grid column when available, otherwise fixed positioning */
@media (min-width: 1300px) {
    .ad-right-column {
        display: flex;
        flex-direction: column;
        gap: 1.5rem;
    }
    
    /* If inside tool-main grid, use grid positioning instead of fixed */
    .tool-main > .ad-right-column {
        position: sticky;
        top: 100px; /* Sticky within grid column */
        align-self: start;
        width: 100%;
        max-width: 336px;
        height: fit-content;
    }
    
    /* Fallback: Fixed positioning when not in grid */
    .ad-right-column:not(.tool-main > *) {
        position: fixed;
        right: 10px;
        top: 100px;
        width: 300px;
        max-width: 300px;
    }
}

/* Large screens - full size */
@media (min-width: 1440px) {
    .ad-right-column {
        width: 336px;
        max-width: 336px;
        right: 15px;
    }
    
    /* In grid layout, use full width of grid column */
    .tool-main .ad-right-column {
        max-width: 100%;
    }
}

/* Extra large screens */
@media (min-width: 1600px) {
    .ad-right-column {
        right: 25px;
    }
}

/* Ultra-wide screens */
@media (min-width: 1920px) {
    .ad-right-column {
        right: 40px;
    }
}

/* Right Column Ad Slot */
.ad-right-slot {
    position: relative;
    min-height: 250px;
    display: none;
    opacity: 0;
    transform: translateX(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    margin: 0;
}

.ad-right-slot.ad-visible {
    display: block;
    opacity: 1;
    transform: translateX(0);
}

/* Content width optimization - now handled by grid layout */
/* Fallback for when grid is not used */
@media (min-width: 1300px) {
    /* Grid layout handles spacing automatically, but keep fallback for compatibility */
    .tool-main:not(:has(.ad-right-column)) .tool-container {
        max-width: calc(100vw - 3rem);
    }
    
    /* Header and breadcrumbs still use calculated widths */
    body.has-right-ads .tool-header-container {
        max-width: calc(100vw - 380px - 3rem) !important;
        margin-left: 1.5rem !important;
        margin-right: auto !important;
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }
    
    body.has-right-ads .breadcrumbs-container {
        max-width: calc(100vw - 380px - 3rem) !important;
        margin-left: 1.5rem !important;
        margin-right: auto !important;
    }
}

@media (min-width: 1440px) {
    body.has-right-ads .tool-header-container {
        max-width: calc(100vw - 420px - 3rem) !important;
    }
    
    body.has-right-ads .breadcrumbs-container {
        max-width: calc(100vw - 420px - 3rem) !important;
    }
}

@media (min-width: 1600px) {
    body.has-right-ads .tool-header-container {
        max-width: min(1400px, calc(100vw - 420px - 3rem)) !important;
    }
    
    body.has-right-ads .breadcrumbs-container {
        max-width: min(1400px, calc(100vw - 420px - 3rem)) !important;
    }
}

/* Right column ad close button */
.ad-right-slot .ad-close {
    top: var(--space-2, 0.5rem);
    right: var(--space-2, 0.5rem);
    z-index: 2;
    background: var(--bg-primary, #ffffff);
    border: 1px solid var(--border, #e2e8f0);
}

.ad-right-slot .ad-close:hover {
    background: var(--bg-secondary, #f8fafc);
    border-color: var(--primary, #6366f1);
}

/* ============================================
   STICKY FOOTER AD STYLES
   ============================================ */

.ad-sticky-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: var(--z-fixed, 1030);
    margin: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    border-top: 1px solid var(--border, #e2e8f0);
    background: var(--bg-primary, #ffffff);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    padding: var(--space-3, 0.75rem) var(--space-4, 1rem);
    min-height: auto;
    display: none; /* Hidden by default, shown via JS */
    transform: translateY(100%);
    transition: transform 0.3s ease-in-out;
}

/* Desktop: Position sticky footer ad to the right side */
@media (min-width: 992px) {
    .ad-sticky-footer {
        left: auto; /* Remove left: 0 */
        right: 20px; /* Position from right edge */
        width: 728px; /* Standard leaderboard width */
        max-width: 728px;
        border-radius: var(--radius-lg, 0.75rem) var(--radius-lg, 0.75rem) 0 0;
        border-left: 1px solid var(--border, #e2e8f0);
        border-right: 1px solid var(--border, #e2e8f0);
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    }

    /* Ensure close button is easily accessible on desktop */
    .ad-sticky-footer .ad-close {
        top: var(--space-2, 0.5rem);
        right: var(--space-2, 0.5rem);
        background: var(--bg-primary, #ffffff);
        border: 1px solid var(--border, #e2e8f0);
        z-index: 2;
    }

    .ad-sticky-footer .ad-close:hover {
        background: var(--bg-secondary, #f8fafc);
        border-color: var(--primary, #6366f1);
    }
}

.ad-sticky-footer.ad-visible {
    display: block;
    transform: translateY(0);
}

.ad-sticky-footer.ad-collapsed {
    transform: translateY(80%);
}

.ad-sticky-footer.ad-dismissed {
    transform: translateY(100%);
}

/* Close Button */
.ad-close {
    position: absolute;
    top: var(--space-2, 0.5rem);
    right: var(--space-2, 0.5rem);
    background: none;
    border: none;
    font-size: var(--text-xl, 1.25rem);
    color: var(--text-muted, #94a3b8);
    cursor: pointer;
    padding: var(--space-1, 0.25rem);
    line-height: 1;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full, 9999px);
    transition: all 0.2s ease;
    z-index: 1;
}

.ad-close:hover {
    background: var(--bg-secondary, #f8fafc);
    color: var(--text-primary, #0f172a);
}

.ad-close:focus {
    outline: 2px solid var(--primary, #6366f1);
    outline-offset: 2px;
}

/* Mobile Sticky Footer */
@media (max-width: 767px) {
    .ad-sticky-footer {
        padding: var(--space-2, 0.5rem);
    }

    .ad-close {
        width: 36px;
        height: 36px;
        font-size: var(--text-2xl, 1.5rem);
    }
}

/* ============================================
   AD CONTENT WRAPPER
   ============================================ */

.ad-content {
    position: relative;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ============================================
   RESPONSIVE AD SIZING
   ============================================ */

/* Ensure ads don't overflow */
.ad-container ins {
    display: block;
    width: 100%;
    max-width: 100%;
}

/* Desktop: Center and constrain leaderboard */
@media (min-width: 992px) {
    #site_8gwifi_org_leaderboard_responsive {
        min-height: 90px;
        max-width: 970px;
        margin: 0 auto;
    }

    #site_8gwifi_org_anchor_responsive {
        min-height: 90px;
        max-width: 970px;
        margin: 0 auto;
    }

    #site_8gwifi_org_rectangle_responsive {
        min-height: 280px;
        max-width: 336px;
    }

    #site_8gwifi_org_floating_right {
        min-height: 280px;
        max-width: 336px;
    }
}


/* Tablet */
@media (min-width: 768px) and (max-width: 991px) {
    #site_8gwifi_org_leaderboard_responsive {
        min-height: 90px;
    }
}

/* Mobile */
@media (max-width: 767px) {
    #site_8gwifi_org_leaderboard_responsive {
        min-height: 100px;
    }

    #site_8gwifi_org_rectangle_responsive {
        min-height: 250px;
    }

    #site_8gwifi_org_anchor_responsive {
        min-height: 100px;
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

/* Accessibility: aria-label ensures screen readers can identify ads */

.ad-container:focus-within {
    outline: 2px solid var(--primary, #6366f1);
    outline-offset: 2px;
}

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

@media (prefers-color-scheme: dark) {
    .ad-container {
        background: var(--bg-secondary, #1e293b);
        border-color: var(--border, #334155);
    }

    .ad-label {
        color: var(--text-muted, #94a3b8);
    }

    .ad-sticky-footer {
        background: var(--bg-primary, #0f172a);
        border-top-color: var(--border, #334155);
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
    }

    .ad-close:hover {
        background: var(--bg-secondary, #1e293b);
        color: var(--text-primary, #f1f5f9);
    }
}

[data-theme="dark"] .ad-container {
    background: var(--bg-secondary, #1e293b);
    border-color: var(--border, #334155);
}

[data-theme="dark"] .ad-sticky-footer {
    background: var(--bg-primary, #0f172a);
    border-top-color: var(--border, #334155);
}

[data-theme="dark"] .ad-floating-right {
    background: var(--bg-secondary, #1e293b);
    border-color: var(--border, #334155);
}

[data-theme="dark"] .ad-floating-right .ad-close:hover {
    background: var(--bg-tertiary, #334155);
    color: var(--text-primary, #f1f5f9);
}

/* ============================================
   EDITOR PANEL NATIVE AD
   Fits inside .me-right-panel (280px wide)
   ============================================ */
.ad-panel-native {
    margin: 0;
    padding: 8px;
    border: none;
    border-bottom: 1px solid var(--border, #e2e8f0);
    border-left: none;
    border-radius: 0;
    box-shadow: none;
    background: var(--bg-secondary, #f8fafc);
    max-width: 280px;
    min-height: 250px;
    flex-shrink: 0;
}

.ad-panel-native:hover {
    transform: none;
    box-shadow: none;
}

.ad-panel-native .ad-label {
    font-size: 9px;
    color: var(--text-muted, #94a3b8);
    margin-bottom: 4px;
}

/* Hidden when right panel is hidden (<= 1024px) */
@media (max-width: 1024px) {
    .ad-panel-native {
        display: none !important;
    }
}

/* ============================================
   DASHBOARD SIDEBAR NATIVE AD
   Fits inside .me-sidebar (240px wide)
   ============================================ */
.ad-sidebar-native {
    margin: 16px 0 0 0;
    padding: 8px;
    border: none;
    border-top: 1px solid var(--border, #e2e8f0);
    border-left: none;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
    max-width: 220px;
    min-height: 200px;
}

.ad-sidebar-native:hover {
    transform: none;
    box-shadow: none;
}

.ad-sidebar-native .ad-label {
    font-size: 9px;
    color: var(--text-muted, #94a3b8);
    margin-bottom: 4px;
}

/* Hidden when sidebar collapses */
@media (max-width: 768px) {
    .ad-sidebar-native {
        display: none !important;
    }
}

/* ============================================
   DASHBOARD BELOW-GRID LEADERBOARD
   Sits after the document grid
   ============================================ */
.ad-below-grid {
    margin: 32px auto 16px auto;
    padding: 12px;
    max-width: 728px;
    min-height: 90px;
    border-left-width: 2px;
}

@media (max-width: 991px) {
    .ad-below-grid {
        max-width: 100%;
        min-height: 100px;
    }
}

/* Dark mode */
[data-theme="dark"] .ad-panel-native {
    background: var(--bg-secondary, #1e293b);
    border-bottom-color: var(--border, #334155);
}

[data-theme="dark"] .ad-sidebar-native {
    border-top-color: var(--border, #334155);
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .ad-container {
        display: none !important;
    }
}

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

/* Prevent layout shift while ads load */
.ad-container::before {
    content: '';
    display: block;
    width: 100%;
}

.ad-in-content-top::before {
    padding-bottom: 12.4%; /* 90px / 728px ≈ 12.4% */
}

.ad-in-content-mid::before {
    padding-bottom: 83.3%; /* 250px / 300px ≈ 83.3% */
}

@media (max-width: 991px) {
    .ad-in-content-top::before {
        padding-bottom: 31.25%; /* 100px / 320px ≈ 31.25% */
    }
}