/* RTL Layout Adjustments for Arabic */
[dir="rtl"] {
    direction: rtl;
    text-align: right;
}

[dir="rtl"] body {
    font-family: 'Cairo', 'Outfit', sans-serif; /* Add Arabic font */
}

[dir="rtl"] .nav {
    gap: 30px;
}

[dir="rtl"] .logo {
    margin-left: 20px;
}



[dir="rtl"] .custom-lang-selector {
    margin-right: 0;
    margin-left: 15px;
}

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

[dir="rtl"] .lang-option span.lang-abbr {
    margin-right: 0;
    margin-left: 12px;
}

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

[dir="rtl"] .search-bar {
    padding-left: 0;
    padding-right: 20px;
}

[dir="rtl"] .search-btn {
    border-radius: 50px 0 0 50px;
}

[dir="rtl"] .search-input {
    padding-left: 20px;
    padding-right: 15px;
}

[dir="rtl"] .search-icon {
    margin-right: 0 !important;
    margin-left: 10px !important;
}

[dir="rtl"] .stat-divider {
    margin-left: 30px;
    margin-right: 0;
}

[dir="rtl"] .chef-meta, [dir="rtl"] .dish-meta {
    flex-direction: row-reverse;
}

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

[dir="rtl"] .footer-section h4::after {
    left: auto;
    right: 0;
}

/* Adjust margins and paddings for inputs/icons */
[dir="rtl"] .input-group i,
[dir="rtl"] .password-toggle {
    right: auto;
    left: 15px;
}

[dir="rtl"] .form-input {
    padding-left: 45px;
    padding-right: 20px;
}

[dir="rtl"] .input-group i.left-icon {
    left: auto;
    right: 15px;
}

[dir="rtl"] .form-input.with-icon {
    padding-right: 45px;
    padding-left: 20px;
}

/* Hot deals layout RTL */
[dir="rtl"] .deal-img-wrapper {
    margin-right: 0;
    margin-left: 20px;
}

[dir="rtl"] .deal-badge {
    left: auto;
    right: -10px;
}

[dir="rtl"] .deal-action-col {
    margin-left: 0;
    margin-right: 10px;
}

[dir="rtl"] .banner-bottom-img {
    right: auto;
    left: -15px;
}

/* Fix margin issues in deal list items if necessary */
[dir="rtl"] .deal-prices {
    flex-direction: row-reverse;
    justify-content: flex-end;
}

/* Fix text bidi issues for rating and distance */
[dir="rtl"] .rating,
[dir="rtl"] .distance {
    direction: ltr;
    display: inline-flex;
}

[dir="rtl"] .chef-footer {
    justify-content: flex-start;
    flex-direction: row-reverse;
}

[dir="rtl"] .cat-pill img {
    margin-right: 0 !important;
    margin-left: 8px !important;
}


/* Header and Cart RTL Fixes */
[dir="rtl"] .cart-badge {
    right: auto;
    left: -8px;
}

[dir="rtl"] .custom-lang-selector .fa-globe {
    margin-left: 5px;
}

[dir="rtl"] .custom-lang-selector .fa-chevron-down {
    margin-right: 5px;
}

/* Cart Sidebar RTL */
[dir="rtl"] .cart-sidebar {
    right: auto;
    left: -400px;
    /* Adjust border if it had one */
}

[dir="rtl"] .cart-sidebar.active {
    left: 0 !important;
    right: auto !important;
}

[dir="rtl"] .cart-header h3 {
    flex-direction: row-reverse;
    justify-content: flex-end;
}
[dir="rtl"] .cart-item-actions {
    align-items: flex-start !important;
}
/* ========================================= */
/*       MOBILE RESPONSIVENESS OVERHAUL      */
/* ========================================= */
@media (max-width: 992px) {
    .profile-icon { display: none !important; }
    .products-slider { grid-template-columns: repeat(2, 1fr); gap: 15px; }
    .mobile-sidebar {
        left: auto;
        right: -300px;
        transition: right 0.3s ease;
    }
    .mobile-sidebar.active {
        left: auto;
        right: 0;
    }
    .mobile-cart-badge {
        right: auto;
        left: -8px;
    }
}

/* ========================================= */
/*       MOBILE RESPONSIVENESS OVERHAUL      */
/* ========================================= */
@media (max-width: 992px) {
    .profile-icon { display: none !important; }
    .products-slider { grid-template-columns: repeat(2, 1fr); gap: 15px; }
    .mobile-sidebar {
        left: auto;
        right: -300px;
        transition: right 0.3s ease;
    }
    .mobile-sidebar.active {
        left: auto;
        right: 0;
    }
    .mobile-cart-badge {
        right: auto;
        left: -8px;
    }
}

/* Responsive Fluid Typography */
@media (max-width: 768px) {
    /* Headings & Hero */
    .hero-title {
        font-size: clamp(1.75rem, 8vw, 2.5rem) !important;
        line-height: 1.2 !important;
    }
    .hero-subtitle {
        font-size: clamp(0.9rem, 4vw, 1.1rem) !important;
        line-height: 1.5 !important;
    }
    .section-title, .page-title, h1, h2 {
        font-size: clamp(1.3rem, 6vw, 1.8rem) !important;
        line-height: 1.3 !important;
    }
    h3, .deal-banner-card h3 {
        font-size: clamp(1.1rem, 5vw, 1.5rem) !important;
        line-height: 1.3 !important;
    }
    h4, .deal-title, .product-title {
        font-size: clamp(0.9rem, 4vw, 1.1rem) !important;
        line-height: 1.4 !important;
    }
    
    /* Paragraphs & Text */
    p, .deal-banner-card p {
        font-size: clamp(0.85rem, 3.5vw, 1rem) !important;
        line-height: 1.5 !important;
    }
    .deal-author, .product-author, .distance {
        font-size: clamp(0.75rem, 3vw, 0.9rem) !important;
    }
    
    /* Pricing */
    .deal-new-price, .product-price {
        font-size: clamp(0.95rem, 4.5vw, 1.2rem) !important;
    }
    .deal-old-price {
        font-size: clamp(0.75rem, 3vw, 0.9rem) !important;
    }
    
    /* Badges & Small Info */
    .deal-badge, .category-item span, .badge, .status-badge {
        font-size: clamp(0.7rem, 2.5vw, 0.85rem) !important;
    }
    
    /* Buttons & Interactive Elements */
    .btn, .cat-pill, button {
        font-size: clamp(0.85rem, 4vw, 1rem) !important;
        white-space: normal !important; /* Allow text wrapping */
        word-break: break-word;
        height: auto !important;
        min-height: 44px; /* Maintain touch target size */
        line-height: 1.4 !important;
        text-align: center;
    }
    .btn-sm, .pill {
        font-size: clamp(0.75rem, 3.5vw, 0.9rem) !important;
        padding: 8px 16px !important;
    }
    .mobile-nav-link {
        font-size: clamp(0.95rem, 4.5vw, 1.1rem) !important;
        white-space: normal !important;
        line-height: 1.4 !important;
    }
    
    /* Global Overflow Prevention */
    * {
        /* This prevents any long unbroken string from forcing horizontal scroll */
        overflow-wrap: break-word !important; 
    }
}

/* Aggressive Overflow X Prevention */
html, body {
    max-width: 100vw;
    overflow-x: hidden !important;
    width: 100%;
    position: relative;
}

/* Fix for Hot Deals Button Squishing */
@media (max-width: 768px) {
    .deal-action-col {
        flex-shrink: 0;
    }
    .deal-action-col .btn-order-deal {
        white-space: nowrap !important;
        word-break: normal !important;
        min-width: max-content;
    }
}

/* Fix for Hot Deals Button Squishing */
@media (max-width: 768px) {
    .deal-action-col {
        flex-shrink: 0;
    }
    .deal-action-col .btn-order-deal {
        white-space: nowrap !important;
        word-break: normal !important;
        min-width: max-content;
    }
}

/* Hot Deals Mobile Mini-Sizing */
@media (max-width: 768px) {
    .deal-list-item .deal-new-price {
        font-size: 0.85rem !important;
    }
    .deal-list-item .deal-old-price {
        font-size: 0.7rem !important;
    }
    .deal-list-item .deal-action-col .btn-order-deal {
        font-size: 0.75rem !important;
        padding: 6px 10px !important;
        min-height: 32px !important;
    }
}

/* Hot Deals Mobile Mini-Sizing */
@media (max-width: 768px) {
    .deal-list-item .deal-new-price {
        font-size: 0.85rem !important;
    }
    .deal-list-item .deal-old-price {
        font-size: 0.7rem !important;
    }
    .deal-list-item .deal-action-col .btn-order-deal {
        font-size: 0.75rem !important;
        padding: 6px 10px !important;
        min-height: 32px !important;
    }
}

/* Header Mobile Sizing & Hamburger Fix */
@media (max-width: 992px) {
    .mobile-menu-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 10px 0 !important;
    }
    .logo-img {
        height: 50px !important;
    }
    .cart-icon {
        font-size: 1.1rem !important;
    }
    .custom-lang-selector {
        padding: 4px 8px !important;
    }
    .custom-lang-selector .current-lang {
        font-size: 0.75rem !important;
        margin: 0 4px !important;
    }
    .custom-lang-selector i {
        font-size: 0.75rem !important;
    }
    .mobile-menu-btn {
        font-size: 1.3rem !important;
    }
    .header-actions {
        gap: 12px !important;
    }
}

/* Header Mobile Sizing & Hamburger Fix */
@media (max-width: 992px) {
    .mobile-menu-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 10px 0 !important;
    }
    .logo-img {
        height: 50px !important;
    }
    .cart-icon {
        font-size: 1.1rem !important;
    }
    .custom-lang-selector {
        padding: 4px 8px !important;
    }
    .custom-lang-selector .current-lang {
        font-size: 0.75rem !important;
        margin: 0 4px !important;
    }
    .custom-lang-selector i {
        font-size: 0.75rem !important;
    }
    .mobile-menu-btn {
        font-size: 1.3rem !important;
    }
    .header-actions {
        gap: 12px !important;
    }
}

/* Categories Page & Products Responsive Fixes for RTL */
@media (max-width: 768px) {
    /* Fix Search Form Layout */
    form[action="categories.php"] {
        flex-direction: column;
        width: 100%;
    }
    
    form[action="categories.php"] .search-bar {
        min-width: 100% !important;
        width: 100% !important;
    }
    
    form[action="categories.php"] .btn {
        width: 100% !important;
    }
}

/* Categories Search Bar Mobile Fix */
@media (max-width: 768px) {
    form[action="categories.php"] .search-bar {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: flex-start !important;
        min-height: 55px !important;
        padding: 5px 20px !important;
        flex-wrap: nowrap !important;
    }
    
    form[action="categories.php"] .search-bar i {
        margin-right: 15px !important;
        margin-left: 0 !important;
        display: inline-block !important;
        width: auto !important;
    }
    
    html[dir="rtl"] form[action="categories.php"] .search-bar i {
        margin-left: 15px !important;
        margin-right: 0 !important;
    }
    
    form[action="categories.php"] .search-bar select,
    form[action="categories.php"] .search-bar input {
        height: 45px !important;
        font-size: 1rem !important;
        text-align: left !important;
    }

    html[dir="rtl"] form[action="categories.php"] .search-bar select,
    html[dir="rtl"] form[action="categories.php"] .search-bar input {
        text-align: right !important;
    }
    
    form[action="categories.php"] .btn {
        min-height: 55px !important;
        font-size: 1.05rem !important;
    }
}

/* Categories Search Bar Mobile Fix */
@media (max-width: 768px) {
    form[action="categories.php"] .search-bar {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: flex-start !important;
        min-height: 55px !important;
        padding: 5px 20px !important;
        flex-wrap: nowrap !important;
    }
    
    form[action="categories.php"] .search-bar i {
        margin-right: 15px !important;
        margin-left: 0 !important;
        display: inline-block !important;
        width: auto !important;
    }
    
    html[dir="rtl"] form[action="categories.php"] .search-bar i {
        margin-left: 15px !important;
        margin-right: 0 !important;
    }
    
    form[action="categories.php"] .search-bar select,
    form[action="categories.php"] .search-bar input {
        height: 45px !important;
        font-size: 1rem !important;
        text-align: left !important;
    }

    html[dir="rtl"] form[action="categories.php"] .search-bar select,
    html[dir="rtl"] form[action="categories.php"] .search-bar input {
        text-align: right !important;
    }
    
    form[action="categories.php"] .btn {
        min-height: 55px !important;
        font-size: 1.05rem !important;
    }
}

/* Favorites Page Search Bar Mobile Fix */
@media (max-width: 768px) {
    .fav-actions {
        flex-direction: column;
        width: 100%;
    }
    
    .fav-search, .fav-sort {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: flex-start !important;
        min-height: 55px !important;
        padding: 5px 20px !important;
        flex-wrap: nowrap !important;
        width: 100% !important;
        min-width: 100% !important;
    }
    
    .fav-search i {
        margin-right: 15px !important;
        margin-left: 0 !important;
        display: inline-block !important;
        width: auto !important;
    }
    
    html[dir="rtl"] .fav-search i {
        margin-left: 15px !important;
        margin-right: 0 !important;
    }
    
    .fav-search input {
        height: 45px !important;
        font-size: 1rem !important;
        text-align: left !important;
        margin-left: 0 !important; /* Overridden by gap or icon margin */
    }

    html[dir="rtl"] .fav-search input {
        text-align: right !important;
    }
    
    .fav-sort {
        justify-content: space-between !important;
        font-size: 1.05rem !important;
    }
}

/* Favorites Page Search Bar Mobile Fix */
@media (max-width: 768px) {
    .fav-actions {
        flex-direction: column;
        width: 100%;
    }
    
    .fav-search, .fav-sort {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: flex-start !important;
        min-height: 55px !important;
        padding: 5px 20px !important;
        flex-wrap: nowrap !important;
        width: 100% !important;
        min-width: 100% !important;
    }
    
    .fav-search i {
        margin-right: 15px !important;
        margin-left: 0 !important;
        display: inline-block !important;
        width: auto !important;
    }
    
    html[dir="rtl"] .fav-search i {
        margin-left: 15px !important;
        margin-right: 0 !important;
    }
    
    .fav-search input {
        height: 45px !important;
        font-size: 1rem !important;
        text-align: left !important;
        margin-left: 0 !important; /* Overridden by gap or icon margin */
    }

    html[dir="rtl"] .fav-search input {
        text-align: right !important;
    }
    
    .fav-sort {
        justify-content: space-between !important;
        font-size: 1.05rem !important;
    }
}

/* Container Mobile Edge Spacing Fix */
@media (max-width: 768px) {
    .container {
        padding-left: 20px !important;
        padding-right: 20px !important;
        width: 100% !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
    }
}

/* Container Mobile Edge Spacing Fix */
@media (max-width: 768px) {
    .container {
        padding-left: 20px !important;
        padding-right: 20px !important;
        width: 100% !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
    }
}

/* Fix Like Button Shape on Mobile */
@media (max-width: 768px) {
    button.btn-like {
        width: 38px !important;
        height: 38px !important;
        min-width: 38px !important;
        min-height: 38px !important;
        border-radius: 50% !important;
        padding: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
}

/* Fix Like Button Shape on Mobile */
@media (max-width: 768px) {
    button.btn-like {
        width: 38px !important;
        height: 38px !important;
        min-width: 38px !important;
        min-height: 38px !important;
        border-radius: 50% !important;
        padding: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
}

/* Fix Map Overflow on Mobile */
@media (max-width: 768px) {
    .map-container {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        /* Fix for Safari/WebKit ignoring border-radius on children with transform/z-index */
        -webkit-mask-image: -webkit-radial-gradient(white, black) !important;
        isolation: isolate !important;
        transform: translateZ(0) !important;
    }
    
    #map {
        width: 100% !important;
        max-width: 100% !important;
    }
}

/* Fix Map Overflow on Mobile */
@media (max-width: 768px) {
    .map-container {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        /* Fix for Safari/WebKit ignoring border-radius on children with transform/z-index */
        -webkit-mask-image: -webkit-radial-gradient(white, black) !important;
        isolation: isolate !important;
        transform: translateZ(0) !important;
    }
    
    #map {
        width: 100% !important;
        max-width: 100% !important;
    }
}

/* Global Mobile Overflow Fix */
html, body {
    max-width: 100vw;
    overflow-x: hidden;
}

@media (max-width: 768px) {
    .product-container {
        width: 100% !important;
        max-width: 100vw !important;
        box-sizing: border-box !important;
        padding-left: 15px !important;
        padding-right: 15px !important;
        overflow-x: hidden;
    }
    
    .header-container {
        padding-left: 10px !important;
        padding-right: 10px !important;
        gap: 5px !important;
    }
    
    .header-actions {
        gap: 10px !important;
    }
    
    .prod-topbar {
        gap: 10px;
    }
    
    .main-image-wrap {
        width: 100%;
        max-width: 100%;
    }
}

/* Global Mobile Overflow Fix */
html, body {
    max-width: 100vw;
    overflow-x: hidden;
}

@media (max-width: 768px) {
    .product-container {
        width: 100% !important;
        max-width: 100vw !important;
        box-sizing: border-box !important;
        padding-left: 15px !important;
        padding-right: 15px !important;
        overflow-x: hidden;
    }
    
    .header-container {
        padding-left: 10px !important;
        padding-right: 10px !important;
        gap: 5px !important;
    }
    
    .header-actions {
        gap: 10px !important;
    }
    
    .prod-topbar {
        gap: 10px;
    }
    
    .main-image-wrap {
        width: 100%;
        max-width: 100%;
    }
}

/* Fix Product Info Box Paddings for Mobile */
@media (max-width: 768px) {
    .prod-info {
        padding: 15px !important;
        border-radius: 20px !important;
    }
    
    .size-option {
        padding: 12px 10px !important;
        gap: 5px;
    }
    
    .radio-circle {
        margin-right: 8px !important;
        margin-left: 8px !important;
    }
    
    .size-name {
        font-size: 0.85rem !important;
        white-space: normal !important;
        word-wrap: break-word;
        flex: 1;
        line-height: 1.2;
    }
    
    .size-price {
        font-size: 0.9rem !important;
        white-space: nowrap;
    }
    
    .feature-badges {
        gap: 10px !important;
    }
    
    .f-badge {
        width: 48%; /* fit two per row comfortably */
    }
}

/* Fix Product Info Box Paddings for Mobile */
@media (max-width: 768px) {
    .prod-info {
        padding: 15px !important;
        border-radius: 20px !important;
    }
    
    .size-option {
        padding: 12px 10px !important;
        gap: 5px;
    }
    
    .radio-circle {
        margin-right: 8px !important;
        margin-left: 8px !important;
    }
    
    .size-name {
        font-size: 0.85rem !important;
        white-space: normal !important;
        word-wrap: break-word;
        flex: 1;
        line-height: 1.2;
    }
    
    .size-price {
        font-size: 0.9rem !important;
        white-space: nowrap;
    }
    
    .feature-badges {
        gap: 10px !important;
    }
    
    .f-badge {
        width: 48%; /* fit two per row comfortably */
    }
}


/* Fix mobile header items overflowing the screen on RTL */
@media (max-width: 768px) {
    html[dir="rtl"] .logo,
    [dir="rtl"] .logo {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
    
    html[dir="rtl"] .custom-lang-selector,
    [dir="rtl"] .custom-lang-selector {
        margin-left: 5px !important;
        margin-right: 0 !important;
    }
    
    html[dir="rtl"] .header-actions,
    [dir="rtl"] .header-actions {
        gap: 8px !important;
        flex-shrink: 1;
    }
    
    html[dir="rtl"] .header-container,
    [dir="rtl"] .header-container {
        justify-content: space-between !important;
        padding-left: 15px !important;
        padding-right: 15px !important;
        overflow: visible !important;
    }
    
    html[dir="rtl"] .mobile-menu-btn,
    [dir="rtl"] .mobile-menu-btn {
        margin-left: 0 !important;
        margin-right: 5px !important;
    }
    
    html[dir="rtl"] .hero-content,
    [dir="rtl"] .hero-content {
        text-align: center !important;
    }
}

/* RTL Deals Banners */
[dir="rtl"] .banner-dynamic-content h3,
[dir="rtl"] .banner-dynamic-content p {
    font-family: 'Cairo', 'Outfit', sans-serif;
}