/* ===================================
   RTL (Right-to-Left) Support for Arabic
   Sakinah Counseling Center
   =================================== */

/* ============ FORCE LTR FOR LOADING/ANIMATIONS ============ */
/* Keep loading elements in LTR regardless of language */
[dir="rtl"] .page-loader,
[dir="rtl"] .loader-content,
[dir="rtl"] .loader-text,
[dir="rtl"] .loader-char,
[dir="rtl"] .loader-tagline,
[dir="rtl"] .loader-circles,
[dir="rtl"] .loader-circle,
[dir="rtl"] .loading-spinner,
[dir="rtl"] .loader,
[dir="rtl"] .spinner,
[dir="rtl"] .loading-overlay,
[dir="rtl"] .loading-container,
[dir="rtl"] .fa-spinner,
[dir="rtl"] .fa-spin {
    direction: ltr !important;
    text-align: center !important;
}

/* ============ RTL BASE STYLES ============ */
/* RTL ONLY for Desktop - Disabled on mobile */
@media (min-width: 1025px) {
    [dir="rtl"],
    .rtl {
        direction: rtl;
        text-align: right;
    }

    [dir="ltr"],
    .ltr {
        direction: ltr;
        text-align: left;
    }

    /* Ensure RTL is applied to body */
    [dir="rtl"] body,
    [dir="rtl"] html {
        direction: rtl;
        text-align: right;
    }

    /* Prevent horizontal scroll in RTL */
    [dir="rtl"] body {
        overflow-x: hidden;
    }

    [dir="rtl"] * {
        /* Ensure all elements respect RTL direction */
        unicode-bidi: embed;
    }
}

/* FORCE LTR on all elements by default on mobile */
@media (max-width: 1024px) {
    [dir="rtl"],
    [dir="rtl"] *,
    [dir="rtl"] body,
    [dir="rtl"] html {
        direction: ltr !important;
        text-align: left !important;
    }
    
    /* Override: RTL text direction ONLY for content elements */
    [dir="rtl"] p,
    [dir="rtl"] h1,
    [dir="rtl"] h2,
    [dir="rtl"] h3,
    [dir="rtl"] h4,
    [dir="rtl"] h5,
    [dir="rtl"] h6,
    [dir="rtl"] li,
    [dir="rtl"] .hero-subtitle,
    [dir="rtl"] .section-description,
    [dir="rtl"] .card-text,
    [dir="rtl"] .service-description,
    [dir="rtl"] .feature-description,
    [dir="rtl"] blockquote,
    [dir="rtl"] .testimonial-text,
    [dir="rtl"] span,
    [dir="rtl"] div.content,
    [dir="rtl"] .text-content {
        direction: rtl !important;
        text-align: right !important;
    }
}

/* ============ RTL TYPOGRAPHY ============ */
/* Arabic fonts - Desktop only */
@media (min-width: 1025px) {
    [dir="rtl"] body {
        font-family: 'Cairo', 'Tajawal', 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    }

    [dir="rtl"] h1,
    [dir="rtl"] h2,
    [dir="rtl"] h3,
    [dir="rtl"] h4,
    [dir="rtl"] h5,
    [dir="rtl"] h6 {
        font-family: 'Cairo', 'Tajawal', 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
        font-weight: 700;
    }
}

/* Mobile - Use Arabic fonts but with LTR layout */
@media (max-width: 1024px) {
    [dir="rtl"] body {
        font-family: 'Cairo', 'Tajawal', 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    }

    [dir="rtl"] h1,
    [dir="rtl"] h2,
    [dir="rtl"] h3,
    [dir="rtl"] h4,
    [dir="rtl"] h5,
    [dir="rtl"] h6 {
        font-family: 'Cairo', 'Tajawal', 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
        font-weight: 700;
    }
}

/* ============ RTL LAYOUT ADJUSTMENTS ============ */

/* Container */
[dir="rtl"] .container {
    text-align: right;
}

/* Navbar - Desktop RTL ONLY (above 1024px) */
@media (min-width: 1025px) {
    [dir="rtl"] .navbar {
        text-align: right;
    }

    /* Navbar typography */
    [dir="rtl"] .nav-link,
    [dir="rtl"] .nav-menu,
    [dir="rtl"] .nav-cta,
    [dir="rtl"] .language-switcher {
        font-family: 'Cairo', 'Tajawal', 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    }
    
    /* Logo text typography */
    [dir="rtl"] .logo-text,
    [dir="rtl"] .footer-logo span {
        font-family: 'Cairo', 'Tajawal', 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    }

    /* Keep natural flex flow but reverse menu items */
    [dir="rtl"] .nav-menu {
        flex-direction: row-reverse;
    }

    [dir="rtl"] .nav-link {
        margin-left: 0;
        margin-right: var(--space-4);
    }

    [dir="rtl"] .nav-link:last-child {
        margin-right: 0;
    }

    [dir="rtl"] .nav-link:first-child {
        margin-right: var(--space-4);
    }

    /* Logo - keep in normal position for RTL desktop */
    [dir="rtl"] .logo {
        order: 0;
    }

    /* Language switcher on desktop RTL */
    [dir="rtl"] .language-switcher {
        margin-left: 0;
        margin-right: var(--space-4);
    }

    /* Ensure hamburger is visible in RTL */
    [dir="rtl"] .mobile-menu-toggle {
        z-index: 1002;
        position: relative;
    }

    [dir="rtl"] .hamburger-line {
        background: var(--color-secondary);
        display: block;
        width: 28px;
        height: 3px;
    }

    /* Hamburger animation for RTL */
    [dir="rtl"] .mobile-menu-toggle.active .hamburger-line:nth-child(1) {
        transform: rotate(45deg) translate(8px, 8px);
    }

    [dir="rtl"] .mobile-menu-toggle.active .hamburger-line:nth-child(2) {
        opacity: 0;
    }

    [dir="rtl"] .mobile-menu-toggle.active .hamburger-line:nth-child(3) {
        transform: rotate(-45deg) translate(7px, -7px);
    }
}

/* Icons - Desktop only */
@media (min-width: 1025px) {
    [dir="rtl"] .icon-left {
        margin-right: 0;
        margin-left: var(--space-2);
    }

    [dir="rtl"] .icon-right {
        margin-left: 0;
        margin-right: var(--space-2);
    }
}

/* Buttons - Desktop only */
@media (min-width: 1025px) {
    [dir="rtl"] .btn i,
    [dir="rtl"] .btn svg {
        margin-left: var(--space-2);
        margin-right: 0;
    }
}

/* Cards & Service Items - Desktop only */
@media (min-width: 1025px) {
    [dir="rtl"] .service-card,
    [dir="rtl"] .feature-box {
        text-align: right;
    }

    [dir="rtl"] .service-icon,
    [dir="rtl"] .feature-icon {
        margin-left: 0;
        margin-right: 0;
    }
}

/* Lists - Desktop only */
@media (min-width: 1025px) {
    [dir="rtl"] ul,
    [dir="rtl"] ol {
        padding-right: var(--space-6);
        padding-left: 0;
    }

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

/* Flex Layouts - Desktop only */
@media (min-width: 1025px) {
    [dir="rtl"] .flex-row {
        flex-direction: row-reverse;
    }

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

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

/* Grid Layouts - Desktop only */
@media (min-width: 1025px) {
    [dir="rtl"] .grid {
        direction: rtl;
    }
}

/* Forms - Desktop only */
@media (min-width: 1025px) {
    [dir="rtl"] .form-group label {
        text-align: right;
    }

    [dir="rtl"] input,
    [dir="rtl"] textarea,
    [dir="rtl"] select {
        text-align: right;
        direction: rtl;
    }

    [dir="rtl"] .form-control {
        padding-right: var(--space-4);
        padding-left: var(--space-4);
    }
}

/* Footer - Desktop only */
@media (min-width: 1025px) {
    [dir="rtl"] .footer {
        text-align: right;
    }

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

    [dir="rtl"] .footer-links {
        padding-right: 0;
    }
}

/* Contact Info - Desktop only */
@media (min-width: 1025px) {
    [dir="rtl"] .contact-info {
        text-align: right;
    }

    [dir="rtl"] .contact-item {
        flex-direction: row-reverse;
    }
}

[dir="rtl"] .contact-icon {
    margin-left: var(--space-3);
    margin-right: 0;
}

/* Breadcrumbs */
[dir="rtl"] .breadcrumb {
    flex-direction: row-reverse;
}

[dir="rtl"] .breadcrumb-separator {
    transform: scaleX(-1);
}

/* Animations - Adjust for RTL */
[dir="rtl"] .slide-in-left {
    animation-name: slideInRight;
}

[dir="rtl"] .slide-in-right {
    animation-name: slideInLeft;
}

/* Back to Top Button */
[dir="rtl"] .back-to-top {
    right: auto;
    left: var(--space-10);
}

/* Floating Book Button */
[dir="rtl"] .floating-book-btn {
    right: auto;
    left: 40px;
}

/* ============ LANGUAGE SWITCHER ============ */
.language-switcher {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-left: var(--space-4);
    order: 2;
}

.lang-btn {
    background: none;
    border: none;
    color: var(--color-gray-dark);
    cursor: pointer;
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
    font-weight: 500;
    transition: var(--transition-fast);
    border-radius: var(--radius-sm);
    white-space: nowrap;
}

.lang-btn:hover {
    color: var(--color-primary);
    background-color: rgba(108, 157, 190, 0.1);
}

.lang-btn.active {
    color: var(--color-primary);
    font-weight: 700;
    background-color: rgba(108, 157, 190, 0.15);
}

.lang-divider {
    color: var(--color-gray);
    opacity: 0.5;
}

/* Mobile Language Switcher - NO RTL changes on mobile */
@media (max-width: 1024px) {
    .language-switcher {
        margin: 0;
        order: 1;
        margin-right: 0;
        margin-left: auto;
        flex-shrink: 0;
        flex-grow: 0;
    }

    /* NO RTL override for language switcher on mobile */
}

@media (max-width: 768px) {
    .language-switcher {
        margin: 0;
        order: 1;
        flex-shrink: 0;
        flex-grow: 0;
    }

    /* NO RTL override for language switcher on mobile */
}

/* ============ ARABIC FONT SUPPORT ============ */
/* Load Arabic fonts */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700&family=Tajawal:wght@400;500;700&display=swap');

/* Arabic number formatting */
[dir="rtl"] .number {
    font-family: 'Cairo', sans-serif;
}

/* ============ RTL UTILITIES ============ */
.rtl-flip {
    transform: scaleX(-1);
}

[dir="rtl"] .rtl-flip {
    transform: scaleX(1);
}

.ltr-only {
    display: inline;
}

[dir="rtl"] .ltr-only {
    display: none;
}

.rtl-only {
    display: none;
}

[dir="rtl"] .rtl-only {
    display: inline;
}

/* ============ SPECIFIC COMPONENT ADJUSTMENTS ============ */

/* Page Header */
[dir="rtl"] .page-header {
    text-align: center;
}

[dir="rtl"] .page-header-content {
    text-align: center;
}

/* Hero Section */
[dir="rtl"] .hero {
    text-align: right;
}

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

/* Service Cards */
[dir="rtl"] .service-card h2,
[dir="rtl"] .service-card h3,
[dir="rtl"] .service-card p {
    text-align: right;
}

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

[dir="rtl"] .service-info h2,
[dir="rtl"] .service-info h3,
[dir="rtl"] .service-info p,
[dir="rtl"] .service-info li {
    text-align: right;
}

/* Stats Section */
[dir="rtl"] .stat-number::after {
    margin-left: 0;
    margin-right: var(--space-2);
}

/* Timeline */
[dir="rtl"] .timeline::before {
    right: 0;
    left: auto;
}

[dir="rtl"] .timeline-item {
    padding-right: var(--space-8);
    padding-left: 0;
}

/* Testimonials */
[dir="rtl"] .testimonial {
    text-align: right;
}

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

/* FAQ Accordion */
[dir="rtl"] .faq-question {
    text-align: right;
    padding-right: var(--space-6);
    padding-left: var(--space-12);
}

[dir="rtl"] .faq-icon {
    left: var(--space-6);
    right: auto;
}

/* Social Media Icons */
[dir="rtl"] .social-links {
    flex-direction: row-reverse;
}

/* ============ PRINT STYLES ============ */
@media print {
    [dir="rtl"] {
        direction: rtl;
    }
}

/* ============ ACCESSIBILITY ============ */
[dir="rtl"]:focus-visible {
    outline-offset: -2px;
}

/* Ensure proper text selection direction */
[dir="rtl"]::selection {
    direction: rtl;
}

/* ============ RESPONSIVE RTL ADJUSTMENTS ============ */

/* Large screens - Desktop RTL only */
@media (min-width: 1025px) {
    /* Desktop RTL layout */
    [dir="rtl"] .nav-wrapper {
        /* Don't reverse on desktop - keep natural flow */
        flex-direction: row;
    }
    
    [dir="rtl"] .nav-menu {
        flex-direction: row-reverse;
    }
}

/* Mobile - Keep navbar LTR, content RTL */
@media (max-width: 1024px) {
    /* FORCE LTR on navbar only */
    [dir="rtl"] .nav-menu,
    [dir="rtl"] .nav-link,
    [dir="rtl"] .nav-wrapper,
    [dir="rtl"] .logo,
    [dir="rtl"] .mobile-menu-toggle,
    [dir="rtl"] .language-switcher {
        direction: ltr !important;
        text-align: left !important;
    }
    
    /* Navbar typography on mobile */
    [dir="rtl"] .nav-link,
    [dir="rtl"] .nav-menu,
    [dir="rtl"] .nav-cta,
    [dir="rtl"] .language-switcher {
        font-family: 'Cairo', 'Tajawal', 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    }
    
    /* Logo text typography on mobile */
    [dir="rtl"] .logo-text,
    [dir="rtl"] .footer-logo span {
        font-family: 'Cairo', 'Tajawal', 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    }
}

@media (max-width: 768px) {
    /* Mobile - Keep LTR layout, minimal styling */

    [dir="rtl"] .back-to-top {
        left: 25px;
        right: auto;
    }

    [dir="rtl"] .floating-book-btn {
        left: 25px;
        right: auto;
    }

    /* Container padding only */
    [dir="rtl"] .container {
        padding-right: var(--space-3);
        padding-left: var(--space-3);
        max-width: 100%;
        width: 100%;
    }
}

@media (max-width: 480px) {
    /* Mobile - Keep LTR layout, minimal styling */

    [dir="rtl"] .lang-btn {
        padding: var(--space-1) var(--space-2);
        font-size: 0.75rem;
    }

    [dir="rtl"] .back-to-top {
        left: 20px;
        right: auto;
    }

    [dir="rtl"] .floating-book-btn {
        left: 20px;
        right: auto;
    }

    /* Container padding only */
    [dir="rtl"] .container {
        padding-right: var(--space-2);
        padding-left: var(--space-2);
        max-width: 100%;
        width: 100%;
    }
}
