/* ========================================
   Standard RTL/LTR Support
   Uses [dir="rtl"] attribute and CSS logical properties
   Automatic browser adjustments - no manual ltr:/rtl: classes needed
   ======================================== */

/* Base RTL Styles - Using dir attribute (standard approach) */
[dir="rtl"] {
    direction: rtl;
    text-align: right;
    overflow-x: hidden;
}

[dir="rtl"] body {
    font-family: 'Poppins', 'Tajawal', 'Cairo', sans-serif;
}

/* Prevent horizontal overflow */
[dir="rtl"] section {
    max-width: 100vw;
    overflow-x: hidden;
    position: relative;
}

/* ========================================
   Header - Auto-adjusts with dir attribute
   ======================================== */
[dir="rtl"] header nav {
    direction: rtl;
}

/* Language dropdown - Use CSS logical properties */
[dir="rtl"] .language-dropdown-menu {
    right: auto;
    left: 0;
}

[dir="ltr"] .language-dropdown-menu {
    left: auto;
    right: 0;
}

/* Mobile Footer Language Dropdown */
[dir="rtl"] #mobileFooterLanguageMenu {
    left: auto;
    right: 50%;
    transform: translateX(50%);
}

[dir="ltr"] #mobileFooterLanguageMenu {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
}

/* Ensure mobile footer dropdown is clickable */
#mobileFooterLanguageToggle {
    cursor: pointer;
    z-index: 1;
}

#mobileFooterLanguageMenu {
    z-index: 1000 !important;
    pointer-events: auto !important;
}

#mobileFooterLanguageMenu.active {
    display: block !important;
}

/* ========================================
   Hero Section - Centered, auto-adjusts
   ======================================== */
@media (min-width: 768px) {
    /* Hero background stays centered for both LTR and RTL */
    [dir="ltr"] section[class*="h-[600px]"] > div[class*="absolute"][class*="md:left-1/2"],
    [dir="ltr"] section[class*="h-[800px]"] > div[class*="absolute"][class*="md:left-1/2"],
    [dir="rtl"] section[class*="h-[600px]"] > div[class*="absolute"][class*="md:left-1/2"],
    [dir="rtl"] section[class*="h-[800px]"] > div[class*="absolute"][class*="md:left-1/2"] {
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%) !important;
    }
    
    /* Hero gradient overlay - also centered */
    [dir="ltr"] section[class*="h-[600px]"] > div[class*="bg-gradient"],
    [dir="ltr"] section[class*="h-[800px]"] > div[class*="bg-gradient"],
    [dir="rtl"] section[class*="h-[600px]"] > div[class*="bg-gradient"],
    [dir="rtl"] section[class*="h-[800px]"] > div[class*="bg-gradient"] {
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%) !important;
    }
    
    /* Hero content text alignment */
    [dir="rtl"] section h1,
    [dir="rtl"] section > div p {
        text-align: right;
    }
}

/* ========================================
   Popular Events Section - Auto-adjusts
   ======================================== */
/* Carousel controls - Auto-position based on dir */
[dir="rtl"] .absolute.right-0 {
    right: auto;
    left: 0;
}

[dir="ltr"] .absolute.right-0 {
    left: auto;
    right: 0;
}

/* Events carousel - Keep LTR for proper scrolling */
[dir="rtl"] #eventsCarousel {
    direction: ltr !important;
}

[dir="rtl"] .carousel-item {
    direction: ltr;
}

[dir="rtl"] .carousel-item h3,
[dir="rtl"] .carousel-item p {
    direction: rtl;
    text-align: right;
}

/* Ensure carousel container allows full scrolling in RTL */
[dir="rtl"] section:has(#eventsCarousel) .overflow-x-auto {
    overflow-x: auto !important;
    overflow-y: visible !important;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

[dir="rtl"] #eventsCarousel {
    overflow-x: visible !important;
    width: auto !important;
    min-width: fit-content !important;
    display: flex !important;
    flex-direction: row !important;
}

/* Popular Events Section - Heading and Subheading alignment */
@media (min-width: 768px) {
    /* Ensure flex container is column and aligns items at the start for both LTR and RTL */
    [dir="ltr"] section:has(p[data-i18n="events.subheading"]) .flex.flex-col,
    [dir="rtl"] section:has(p[data-i18n="events.subheading"]) .flex.flex-col {
        align-items: flex-start !important;
        flex-direction: column !important;
    }
    
    /* LTR (English) - Left aligned */
    [dir="ltr"] section:has(p[data-i18n="events.subheading"]) h2[data-i18n="events.heading"] {
        text-align: left !important;
        direction: ltr !important;
    }
    
    [dir="ltr"] section:has(p[data-i18n="events.subheading"]) p[data-i18n="events.subheading"] {
        text-align: left !important;
        direction: ltr !important;
    }
    
    /* RTL (Arabic) - Right aligned */
    [dir="rtl"] section:has(p[data-i18n="events.subheading"]) {
        direction: rtl;
    }
    
    /* Popular Events heading alignment - RTL */
    [dir="rtl"] section:has(p[data-i18n="events.subheading"]) h2[data-i18n="events.heading"] {
        text-align: right !important;
        direction: rtl !important;
    }
    
    /* Popular Events subheading alignment - RTL */
    [dir="rtl"] section:has(p[data-i18n="events.subheading"]) p[data-i18n="events.subheading"] {
        text-align: right !important;
        direction: rtl !important;
    }
    
    /* Section header container alignment - RTL */
    [dir="rtl"] section:has(p[data-i18n="events.subheading"]) .flex.flex-col[class*="gap-"] {
        align-items: flex-end;
    }
    
    [dir="rtl"] section:has(p[data-i18n="events.subheading"]) .flex.items-center.justify-between {
        flex-direction: row-reverse;
    }
}

/* ========================================
   Services Section - Auto-adjusts with dir
   ======================================== */
@media (min-width: 768px) {
    /* Services section - Centered and constrained like Partners section */
    [dir="rtl"] section[class*="md:h-[895px]"] {
        overflow-x: hidden;
        max-width: 100vw;
    }
    
    [dir="rtl"] section[class*="md:h-[895px]"] > div[class*="max-w-"] {
        margin-left: auto !important;
        margin-right: auto !important;
    }
    
    /* Services images - Flip to right side in RTL (mirror: images on right, content on left) */
    [dir="rtl"] section[class*="md:h-[895px]"] > div > div[class*="md:w-[60%]"][class*="md:left-0"],
    [dir="rtl"] section[class*="md:h-[895px]"] > div > div[class*="lg:w-[1014px]"][class*="md:left-0"] {
        left: auto !important;
        right: 0 !important;
        width: 60% !important;
        z-index: 1 !important;
    }

    @media (min-width: 1024px) {
        [dir="rtl"] section[class*="md:h-[895px]"] > div > div[class*="lg:w-[1014px]"] {
            width: 1014px !important;
        }
    }

    /* Services images track - Ensure visibility */
    [dir="rtl"] .services-images-track {
        z-index: 1 !important;
        width: 100% !important;
    }

    /* Services blue box - Flip to left side in RTL (mirror: content on left, images on right) */
    [dir="rtl"] section[class*="md:h-[895px]"] > div > div[class*="bg-"][class*="md:left-[60%]"],
    [dir="rtl"] section[class*="md:h-[895px]"] > div > div[class*="bg-"][class*="lg:left-[716px]"] {
        left: 0 !important;
        right: auto !important;
        width: 40% !important;
        z-index: 10 !important;
    }

    @media (min-width: 1024px) {
        [dir="rtl"] section[class*="md:h-[895px]"] > div > div[class*="bg-"][class*="lg:w-[724px]"] {
            width: 724px !important;
        }
    }
    
    /* Services content containers - Position from left in RTL */
    [dir="rtl"] section[class*="md:h-[895px]"] .relative[class*="md:absolute"][class*="md:left-"] {
        /* left: 62px !important; */
        right: auto !important;
    }
    
    /* Services text alignment */
    [dir="rtl"] section[class*="md:h-[895px]"] h2,
    [dir="rtl"] section[class*="md:h-[895px]"] p,
    [dir="rtl"] section[class*="md:h-[895px]"] .bg-white span {
        text-align: right;
        direction: rtl;
    }
    
    /* Services badge alignment */
    [dir="rtl"] section[class*="md:h-[895px]"] .bg-white {
        /* justify-content: flex-end; */
    }
    
    [dir="rtl"] section[class*="md:h-[895px]"] .bg-white span {
        text-align: right;
    }
    
    /* Services carousel text */
    [dir="rtl"] .services-carousel-content {
        direction: rtl;
    }
    
    [dir="rtl"] .service-item {
        direction: rtl;
        text-align: right;
    }
    
    /* Services images carousel - Keep LTR for proper image display */
    [dir="rtl"] .services-images-track {
        direction: ltr !important;
    }
    
    [dir="rtl"] .service-image {
        direction: ltr !important;
    }
    
    /* Services carousel controls - Reverse order in RTL */
    /* [dir="rtl"] section[class*="md:h-[895px]"] .flex.items-center[class*="gap-"] {
        flex-direction: row-reverse;
    } */
}

/* ========================================
   Gallery Section - Centered, auto-adjusts
   ======================================== */
/* Gallery Carousel - Keep LTR direction for proper scrolling */
[dir="rtl"] #galleryCarousel {
    flex-direction: row !important;
    direction: ltr !important;
}

[dir="ltr"] #galleryCarousel {
    flex-direction: row;
}

/* Gallery carousel container - Ensure scrolling works in RTL */
[dir="rtl"] #galleryCarouselContainer {
    direction: ltr !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
}

/* ========================================
   Vendor Form Section - Auto-adjusts
   ======================================== */
@media (min-width: 768px) {
    /* Vendor form layout - Auto-reverse */
    [dir="rtl"] section[id="vendorForm"] > div > div.flex.flex-col.md\\:flex-row {
        flex-direction: row-reverse;
    }
    
    /* Form inputs - Auto-align */
    [dir="rtl"] #vendorForm input[type="text"],
    [dir="rtl"] #vendorForm input[type="email"],
    [dir="rtl"] #vendorForm textarea {
        text-align: right;
        direction: rtl;
        width: 100%;
    }
    
    /* Phone input stays LTR */
    [dir="rtl"] #vendorForm input[type="tel"] {
        text-align: left;
        direction: ltr;
    }
    
    /* Form labels - Auto-position */
    [dir="rtl"] #vendorForm label[class*="absolute"][class*="left-\\[12px\\]"] {
        left: auto !important;
        right: 12px !important;
        text-align: right;
    }
    
    /* Form header alignment - Auto-adjusts */
    [dir="rtl"] section[id="vendorForm"] .flex.flex-col.items-center[class*="md:items-start"] {
        align-items: flex-start; /* In RTL, flex-start = RIGHT */
    }
    
    [dir="rtl"] section[id="vendorForm"] h2,
    [dir="rtl"] section[id="vendorForm"] p {
        text-align: right;
    }
}

/* ========================================
   Download Section - Auto-adjusts
   ======================================== */
@media (min-width: 768px) {
    /* Ensure section allows overflow for mockup */
    [dir="rtl"] section[class*="backdrop-blur"] {
        direction: rtl;
        overflow: visible !important;
        position: relative !important;
        z-index: 1;
    }
    
    [dir="rtl"] section[class*="backdrop-blur"] > div[class*="max-w"] {
        direction: rtl;
        justify-content: flex-start; /* In RTL, flex-start = RIGHT */
        position: relative;
        z-index: 1;
    }
    
    /* Phone mockup - Auto-position with higher z-index to appear above everything */
    [dir="rtl"] section[class*="backdrop-blur"] .hidden.md\:block.absolute[class*="right-"] {
        right: auto !important;
        left: 80px !important;
        z-index: 999 !important;
        position: absolute !important;
    }
    
    /* Ensure mockup image itself has proper z-index */
    [dir="rtl"] section[class*="backdrop-blur"] .hidden.md\:block.absolute img {
        position: relative;
        z-index: 1;
    }
    
    /* Content alignment */
    [dir="rtl"] section[class*="backdrop-blur"] h2,
    [dir="rtl"] section[class*="backdrop-blur"] p {
        text-align: right;
        direction: rtl;
    }
    
    /* Content container alignment */
    [dir="rtl"] section[class*="backdrop-blur"] .flex.flex-col.relative.z-10 {
        align-items: flex-start; /* In RTL, flex-start = RIGHT */
        z-index: 10;
    }
}

/* ========================================
   Footer - Auto-adjusts
   ======================================== */
[dir="rtl"] footer {
    direction: rtl;
}

[dir="rtl"] footer .flex {
    direction: rtl;
}

/* ========================================
   General RTL Utilities
   ======================================== */
/* Text alignment - Auto-adjusts */
[dir="rtl"] .text-left {
    text-align: right;
}

[dir="rtl"] .text-right {
    text-align: left;
}

/* Flex alignment - Auto-adjusts */
[dir="rtl"] .items-start {
    align-items: flex-end;
}

[dir="rtl"] .items-end {
    align-items: flex-start;
}

/* Justify content - Auto-adjusts */
/* [dir="rtl"] .justify-start {
    justify-content: flex-end;
} */

[dir="rtl"] .justify-end {
    justify-content: flex-start;
}

/* Absolute positioning - Auto-adjusts */
[dir="rtl"] .absolute.left-0 {
    left: auto;
    right: 0;
}

[dir="rtl"] .absolute.right-0 {
    right: auto;
    left: 0;
}

/* Button icons - Flip for RTL */
[dir="rtl"] .btn-primary svg,
[dir="rtl"] button img[src*="arrow"],
[dir="rtl"] button img[src*="carousel"],
[dir="rtl"] button svg {
    transform: scaleX(-1);
}

/* Keep images from flipping */
[dir="rtl"] img {
    transform: none !important;
}

[dir="rtl"] img[alt="Copyright"],
[dir="rtl"] img[src*="logo"],
[dir="rtl"] img[src*="badge"] {
    transform: none !important;
}

/* Phone numbers stay LTR */
[dir="rtl"] input[type="tel"] {
    direction: ltr;
    text-align: left;
}

/* Email stays LTR */
[dir="rtl"] [data-i18n="footer.email"] {
    direction: ltr;
    text-align: right;
}

/* ========================================
   Centered Sections (like Partners)
   ======================================== */
@media (min-width: 768px) {
    [dir="rtl"] section > div[class*="max-w-"] {
        margin-left: auto !important;
        margin-right: auto !important;
    }
}

/* ========================================
   Browser Compatibility
   ======================================== */
html[dir="rtl"],
html[dir="ltr"] {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Prevent layout shift */
html[dir="rtl"] *,
html[dir="ltr"] * {
    box-sizing: border-box;
}

/* Force GPU acceleration */
html[dir="rtl"] section,
html[dir="ltr"] section {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* Prevent horizontal scrolling */
html[dir="rtl"],
html[dir="ltr"] {
    overflow-x: hidden;
    max-width: 100vw;
    width: 100vw;
}

