/* Mobile Layout Fixes - Force Stack & Direction */

/* The overlay is always in the DOM and shown/hidden via JS — no blanket display:none here */
/* It is hidden by default via opacity:0 / visibility:hidden inside the max-width:1200px block */

@media (max-width: 1200px) {
    #site-navigation .nav-menu {
        display: none !important;
    }

    /* Ensure the overlay doesn't block clicks when not active */
    .mobile-nav-wrapper:not(.active) {
        pointer-events: none !important;
    }
}

/* Fix horizontal overflow in Empower Grid */
@media (max-width: 992px) {
    .empower-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

@media (max-width: 768px) {
    .empower-grid {
        grid-template-columns: 1fr !important;
        gap: 1.5rem !important;
    }

    .empower-card {
        padding: 2rem 1.5rem !important;
    }

    /* Global Reset for punctuation bleed */
    html, body {
        overflow-x: hidden !important;
        width: 100% !important;
        position: relative;
    }
    body {
        direction: ltr !important;
        unicode-bidi: embed !important;
    }

    html[dir="rtl"] body {
        direction: rtl !important;
    }
}

/* Desktop: completely hide the mobile overlay — it should never show above 1200px */
@media (min-width: 1201px) {
    .mobile-nav-wrapper {
        display: none !important;
    }
}


@media (max-width: 1200px) {
    .mobile-nav-wrapper {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        background: rgba(15, 23, 42, 0.4);
        /* Dark backdrop tint */
        opacity: 0;
        visibility: hidden;
        z-index: 999999;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
    }

    .mobile-nav-wrapper.active {
        opacity: 1;
        visibility: visible;
    }

    .main-nav-container {
        background-color: #FFFFFF;
        width: 80%;
        /* Slide-in panel — not full width */
        max-width: 320px;
        height: 100%;
        position: absolute;
        top: 0;
        right: 0;
        transform: translateX(100%);
        /* Hidden off-screen right for RTL */
        transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        display: flex;
        flex-direction: column;
        padding: 20px;
        box-shadow: -10px 0 30px rgba(0, 0, 0, 0.2);
        z-index: 1000000;
        overflow-y: auto;
    }

    html[dir="ltr"] .main-nav-container {
        right: auto;
        left: 0;
        transform: translateX(-100%);
    }

    .mobile-nav-wrapper.active .main-nav-container {
        transform: translateX(0) !important;
    }

    .mobile-menu-header {
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 20px;
        margin-bottom: 20px;
        border-bottom: 1px solid #F1F5F9;
        flex: 0 0 auto !important;
    }

    .mobile-logo a {
        font-size: 1.2rem;
        font-weight: 800;
        color: #4F46E5;
        text-transform: uppercase;
    }

    .menu-close {
        background: #F1F5F9;
        border: none;
        width: 40px;
        height: 40px;
        border-radius: 10px;
        display: flex !important;
        align-items: center;
        justify-content: center;
        color: #475569;
        cursor: pointer;
    }

    .main-nav {
        display: block;
        flex: 1 1 auto;
        min-height: 100px;
        overflow-y: auto;
    }

    #mobile-primary-menu,
    .main-nav .nav-menu {
        list-style: none;
        padding: 0;
        margin: 0;
        width: 100%;
        display: block;
        height: auto;
    }

    .main-nav .nav-menu li {
        margin-bottom: 5px;
        width: 100%;
        display: block;
    }

    .main-nav .nav-menu li a {
        display: block;
        padding: 12px 0;
        font-size: 1.1rem;
        font-weight: 700;
        color: #1E293B;
        border-bottom: 1px solid rgba(241, 245, 249, 0.5);
        width: 100% !important;
    }

    .mobile-menu-footer {
        margin-top: auto;
        padding-top: 20px;
    }

    .mobile-menu-footer .btn {
        width: 100% !important;
        margin-bottom: 10px;
        padding: 14px !important;
        font-size: 1rem !important;
        border-radius: 12px !important;
        text-align: center !important;
        display: flex !important;
        justify-content: center !important;
    }

    .lang-toggle-mobile {
        display: flex !important;
        justify-content: center;
        align-items: center;
        background: #F1F5F9 !important;
        padding: 14px !important;
        border-radius: 12px !important;
        color: #4F46E5 !important;
        font-weight: 700 !important;
        text-decoration: none;
        gap: 8px;
    }

    /* Mobile Z-Index Audit & Overlap Fix */
    #gateofai-cookie-banner,
    .cookie-banner,
    .cookie-notice {
        z-index: 999999 !important;
    }

    #gai-newsletter-popup,
    .newsletter-footer,
    .newsletter-popup {
        z-index: 99999 !important;
    }

    /* Prevent overlap by creating margin space so newsletter is higher than cookie banner */
    #gai-newsletter-popup .gai-modal-content {
        margin-bottom: 80px !important;
    }

    /* Fix Header Overflow & Extreme Mobile Responsiveness (v3.8.1) */
    .site-branding {
        padding: 0 5px !important;
        flex: 1 1 auto !important;
        min-width: 0 !important;
        overflow: hidden;
    }

    .site-title a {
        font-size: 0.9rem !important;
        letter-spacing: -0.5px !important;
        display: block;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .header-container {
        gap: 2px !important;
        padding: 0 5px !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
    }

    .header-auth,
    .main-navigation {
        flex: 0 0 auto !important;
        z-index: 2000 !important;
        /* Above any potential overlays */
    }

    .site-branding {
        flex: 1 1 auto !important;
        min-width: 0 !important;
        text-align: center !important;
        padding: 0 5px !important;
    }

    /* Force all ads and iframes to be responsive */
    .gai-ad-container,
    .adsbygoogle,
    ins,
    iframe {
        max-width: 100% !important;
        width: 100% !important;
        overflow: hidden !important;
    }

    /* AI Tools Landing Page (archive-ai_tool.php) Responsive Fixes (v3.8.2) */
    .archive-hero-title {
        font-size: 2.22rem !important;
        /* Scaled for mobile */
        padding: 0 15px !important;
        line-height: 1.2 !important;
        margin-top: 0 !important;
    }

    .archive-hero {
        padding: 4.5rem 0 3.5rem !important;
    }

    .compare-overlay-btn {
        bottom: 25px !important;
        right: 20px !important;
        left: auto !important;
        padding: 12px 20px !important;
        font-size: 0.9rem !important;
        z-index: 1001 !important;
        box-shadow: 0 10px 20px rgba(16, 185, 129, 0.3) !important;
    }

    .hero-search-form {
        max-width: 92% !important;
        margin: 1.5rem auto 0 !important;
    }

    .hero-search-form input[type="search"] {
        padding: 18px 50px 18px 100px !important;
        font-size: 1rem !important;
    }

    .hero-search-form button[type="submit"] {
        padding: 0 20px !important;
        font-size: 0.95rem !important;
    }
}