/*****************************
M3yar — Mobile-First + RTL Compatibility Layer
Load last. Fixes RTL bugs and optimizes for mobile (95% traffic).
*****************************/

/* ── Prevent horizontal overflow ── */
html {
  overflow-x: clip;
}

body {
  overflow-x: clip;
  max-width: 100vw;
}

img,
video,
iframe,
.table-responsive,
.container-fluid {
  max-width: 100%;
}

/* ── Mobile-first base (default = mobile) ── */
.container {
  padding-left: 16px;
  padding-right: 16px;
}

.main-container {
  overflow-x: clip;
}

/* Touch-friendly minimum targets */
a,
button,
.btn,
.offcanvas-toggle,
.header__user-action-icon li a,
.product__action--link li a,
.sort-box__tab-list li a,
.page-pagination li a {
  -webkit-tap-highlight-color: rgba(196, 165, 116, 0.2);
}

@media (max-width: 991px) {
  /* ── Core layout safety ── */
  .container,
  .container-fluid {
    padding-left: 16px;
    padding-right: 16px;
    max-width: 100%;
  }

  .row {
    margin-left: -8px;
    margin-right: -8px;
  }

  .row > [class*="col-"] {
    padding-left: 8px;
    padding-right: 8px;
  }

  /* Primary CTAs only — don't break icon/small buttons */
  .btn.btn--green,
  .btn.btn--black,
  .btn.btn--large,
  .btn.btn--medium,
  .btn.btn--long,
  .btn.btn--block,
  .cart-table-button .btn,
  .hero-btn-primary,
  .hero-btn-outline {
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Product actions always visible, compact on small screens */
  .product__action--link {
    visibility: visible !important;
    opacity: 1 !important;
    bottom: 6px !important;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 4px;
    padding: 0 4px;
  }

  .product__action--link li {
    margin: 0 !important;
  }

  .product__action--link li a {
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    font-size: 14px !important;
    min-height: 36px !important;
  }

  .product__box:hover .product__counter-box {
    opacity: 1 !important;
    visibility: visible !important;
    right: 4px !important;
    left: auto !important;
  }

  [dir="rtl"] .product__box:hover .product__counter-box {
    right: auto !important;
    left: 4px !important;
  }

  /* Section headers */
  .section-content {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px;
  }

  .section-content--border {
    margin-bottom: 20px;
    padding-bottom: 16px;
  }

  .section-content__title {
    font-size: 1.25rem;
    line-height: 1.35;
  }

  .section-content .tablist,
  .tablist.tablist--style-gap-20,
  .tablist.nav {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    width: 100%;
    gap: 8px;
    padding-bottom: 4px;
  }

  .section-content .tablist::-webkit-scrollbar,
  .tablist.tablist--style-gap-20::-webkit-scrollbar {
    display: none;
  }

  .tablist li {
    flex-shrink: 0;
  }

  .tablist .nav-link {
    white-space: nowrap;
    font-size: 13px;
    padding: 8px 14px;
  }

  /* Shop grid — full width on phones, 2-col on larger phones */
  .shop-grid .row > [class*="col-"] {
    flex: 0 0 100%;
    max-width: 100%;
  }

  .shop-grid .product__box {
    margin-bottom: 12px;
  }

  .product__link {
    font-size: 14px;
    line-height: 1.4;
  }

  /* Category cards — horizontal scroll on mobile */
  .product__catagory {
    border: none !important;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
  }

  .product__catagory--single {
    width: min(260px, 78vw) !important;
    flex: 0 0 auto;
    float: none !important;
    min-height: 90px;
    margin: 0 !important;
    padding: 12px 14px !important;
  }

  .product__content--catagory {
    width: 55%;
    padding: 8px;
  }

  .product__img-box--catagory {
    width: 45%;
  }

  /* Slick sliders — fix overflow from negative margins */
  .gap__col--30 .slick-list {
    margin-left: -8px !important;
    margin-right: -8px !important;
    overflow: hidden;
  }

  .gap__col--30 .slick-slide {
    margin-left: 8px !important;
    margin-right: 8px !important;
  }

  .product-default-slider .slick-slide {
    transform: scale(1) !important;
  }

  .default-slider {
    padding-bottom: 8px;
  }

  .default-slider__arrow {
    visibility: visible !important;
    opacity: 0.85 !important;
    width: 36px;
    height: 36px;
    line-height: 36px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    z-index: 10;
  }

  .default-slider:hover .default-slider__arrow--left,
  .default-slider__arrow--left {
    left: 0 !important;
  }

  .default-slider:hover .default-slider__arrow--right,
  .default-slider__arrow--right {
    right: 0 !important;
  }

  [dir="rtl"] .default-slider:hover .default-slider__arrow--left,
  [dir="rtl"] .default-slider__arrow--left {
    left: auto !important;
    right: 0 !important;
  }

  [dir="rtl"] .default-slider:hover .default-slider__arrow--right,
  [dir="rtl"] .default-slider__arrow--right {
    right: auto !important;
    left: 0 !important;
  }

  /* Sort box */
  .sort-box {
    flex-direction: column;
    align-items: stretch !important;
    gap: 12px;
    padding: 14px;
  }

  .sort-box > div {
    margin-bottom: 0 !important;
    width: 100%;
  }

  .sort-box__tab-list li a {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Sidebar */
  .sidebar__widget {
    margin-bottom: 12px;
    padding: 14px;
  }

  /* Banners */
  .banner.m-t-30 .col-md-6 {
    margin-bottom: 12px;
  }

  .banner__title--large {
    font-size: 1.5rem !important;
  }

  /* Newsletter */
  .newsletter__content {
    position: relative !important;
    padding: 40px 16px !important;
  }

  .newsletter__form-content input {
    padding: 14px 90px 14px 36px !important;
    font-size: 14px !important;
  }

  .newsletter__form-content button {
    font-size: 12px !important;
    padding: 8px 12px !important;
  }

  [dir="rtl"] .newsletter__form-content input {
    padding: 14px 36px 14px 90px !important;
  }

  /* Checkout order */
  .main-container .row:has(.your-order-section) > .col-lg-7 {
    order: 2;
  }

  .main-container .row:has(.your-order-section) > .col-lg-5 {
    order: 1;
    margin-bottom: 20px;
  }

  .your-order-box {
    position: static !important;
    padding: 20px !important;
  }

  /* Cart */
  .cart-table-button,
  .cart-table-button--left,
  .cart-table-button--right {
    width: 100%;
  }

  .cart-table-button--right {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .cart-table-button .btn {
    width: 100%;
    margin: 0 !important;
  }

  /* Product single */
  .product-var__item .btn--long {
    width: 100%;
  }

  .quantity-scale.m-l-20,
  .quantity-scale.m-r-20 {
    margin-left: 0 !important;
    margin-right: 0 !important;
    margin-top: 10px;
  }

  /* Footer */
  .footer__top {
    padding-top: 32px;
    padding-bottom: 32px;
  }

  .footer__form-box input {
    padding: 14px 100px 14px 14px !important;
    font-size: 14px !important;
  }

  [dir="rtl"] .footer__form-box input {
    padding: 14px 14px 14px 100px !important;
  }

  /* Spacing — moderate reduction, not global nuke */
  .product.m-t-100,
  .cms.m-t-100,
  .testimonial.m-t-100,
  .company-logo.m-t-100 {
    margin-top: 40px !important;
  }

  .footer.m-t-100 {
    margin-top: 48px !important;
  }

  .page-breadcrumb {
    padding: 28px 0;
    margin-bottom: 24px;
  }

  [dir="rtl"] .product__catagory--single {
    float: none !important;
    width: min(260px, 78vw) !important;
    border-left: none !important;
    border-right: none !important;
  }

  [dir="rtl"] .product__catagory {
    border: none !important;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
  }

  /* Banners — contain edge bleed */
  .banner .container-fluid {
    padding-left: 16px;
    padding-right: 16px;
  }

  .banner__box--single {
    border-radius: 12px;
    overflow: hidden;
  }

  /* Hero slick — stacked slides need auto height */
  .hero-espresso .slick-slide,
  .hero-espresso .slick-list,
  .hero-espresso .slick-track {
    height: auto !important;
  }

  .hero-espresso .hero-slider {
    display: flex !important;
    flex-direction: column;
  }

  /* Product page gallery */
  .product-gallery-box {
    padding: 0 !important;
  }

  .product-gallery-box__vertical {
    flex-direction: column;
    gap: 12px;
  }

  .product-gallery-box--gallery,
  .product-gallery-box--gallery img,
  .gallery--right,
  .gallery--left {
    width: 100% !important;
    float: none !important;
  }

  .product-gallery-box--gallery img {
    max-width: 100%;
  }

  .product-image--gallery .img-responsive {
    margin: 4px;
  }

  .product-details-content .product__title,
  .product-details-content h1 {
    font-size: 1.35rem;
    line-height: 1.35;
  }

  .product-details-tab-box .tablist {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .product-details-tab-box .tablist::-webkit-scrollbar {
    display: none;
  }

  .product-details-tab-box .tablist li {
    flex-shrink: 0;
  }

  /* Checkout — stack order summary */
  .your-order-section {
    margin-top: 24px;
  }

  .your-order-box {
    position: static !important;
  }

  .checkout-box .form-box__single-group {
    margin-bottom: 12px;
  }

  /* Compare table scroll */
  .compare-table-content {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* CMS trust badges */
  .cms__content {
    margin-bottom: 12px;
    padding: 20px 16px;
  }

  /* Page inner breadcrumb */
  .page-breadcrumb__inner {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 8px;
  }

  /* Modals */
  .modal-dialog {
    margin: 12px;
    max-width: calc(100% - 24px);
  }
}

/* Larger phones — 2-column shop grid */
@media (min-width: 576px) and (max-width: 991px) {
  .shop-grid .row > [class*="col-"] {
    flex: 0 0 50%;
    max-width: 50%;
  }

  .hero-espresso .hero-slide__media {
    height: 240px;
  }
}

/* Very small phones */
@media (max-width: 374px) {
  .header-brand-mobile .header__mobile-logo-img {
    max-height: 34px;
    max-width: 120px;
  }

  .product__action--link li a {
    width: 32px !important;
    height: 32px !important;
    line-height: 32px !important;
    font-size: 12px !important;
  }
}

/* Desktop restores section-content row layout */
@media (min-width: 992px) {
  [dir="rtl"] .section-content {
    flex-direction: row-reverse;
  }

  [dir="ltr"] .section-content,
  .section-content {
    flex-direction: row;
  }
}

/* ═══════════════════════════════════════
   RTL FIXES — comprehensive
   ═══════════════════════════════════════ */

[dir="rtl"] {
  direction: rtl;
  text-align: right;
}

/* Icon direction fixes */
[dir="rtl"] .fa-arrow-left,
[dir="rtl"] .fal.fa-arrow-left,
[dir="rtl"] .fas.fa-arrow-left {
  transform: scaleX(-1);
}

[dir="rtl"] .btn--icon-left i.fa-angle-right,
[dir="rtl"] .btn--icon-left i.fal.fa-angle-right,
[dir="rtl"] .link--icon-left i.fa-angle-right {
  transform: scaleX(-1);
}

[dir="rtl"] .page-breadcrumb__nav::after {
  content: "\f053";
}

[dir="rtl"] .fa-chevron-right,
[dir="rtl"] .fal.fa-chevron-right,
[dir="rtl"] .fas.fa-chevron-right {
  transform: scaleX(-1);
}

/* Bootstrap logical alignment — ensure RTL end/start */
[dir="rtl"] .text-start {
  text-align: right !important;
}

[dir="rtl"] .text-end {
  text-align: left !important;
}

[dir="rtl"] .ms-auto {
  margin-left: 0 !important;
  margin-right: auto !important;
}

[dir="rtl"] .me-auto {
  margin-right: 0 !important;
  margin-left: auto !important;
}

/* Header phone — end alignment in RTL */
[dir="rtl"] .header-phone.text-end,
[dir="rtl"] .header-phone {
  text-align: left;
}

[dir="rtl"] .header-brand .header-search__content input {
  padding: 13px 24px 13px 56px;
}

[dir="rtl"] .header-brand .header-search__content button {
  right: auto;
  left: 4px;
}

/* Product category strip RTL */
[dir="rtl"] .product__catagory {
  border-left: none;
  border-right: none;
}

[dir="rtl"] .product__catagory--single {
  float: none;
  border-right: none;
  border-left: 1px solid var(--lux-border, #ebebeb);
}

@media (max-width: 991px) {
  [dir="rtl"] .product__catagory--single {
    float: none;
    border-left: none;
  }
}

[dir="rtl"] .product__box:hover .product__counter-box {
  right: auto;
  left: -30px;
}

/* Product labels & counters */
[dir="rtl"] .product__label {
  left: auto;
  right: 10px;
}

[dir="rtl"] .product__counter-box {
  right: auto;
  left: 7px;
}

/* Dropdown hover nudge direction */
[dir="rtl"] .header-brand .dropdown__link:hover,
[dir="rtl"] .header-brand .dropdown__submenu-link:hover {
  padding-inline-start: 0;
  padding-inline-end: 4px;
}

[dir="rtl"] .dropdown__link:hover,
[dir="rtl"] .dropdown__submenu-link:hover {
  transform: translateX(-4px);
}

/* Forms */
[dir="rtl"] .form-box__single-group label,
[dir="rtl"] .sidebar__menu-filter label {
  text-align: right;
}

[dir="rtl"] .form-box__single-group input,
[dir="rtl"] .form-box__single-group textarea,
[dir="rtl"] .form-box__single-group select {
  text-align: right;
}

[dir="rtl"] .footer__form-box input {
  padding: 12px 120px 12px 10px;
}

[dir="rtl"] .footer__form-box button {
  right: 0;
  left: auto;
}

[dir="rtl"] .footer__logo-img,
[dir="rtl"] .footer__logo {
  text-align: right;
}

/* Footer link hover — use logical property only */
[dir="rtl"] .footer__link:hover {
  padding-left: 0;
  padding-right: 0;
  padding-inline-start: 6px;
}

/* Block quote — single clean rule */
[dir="rtl"] .block-quote {
  margin-left: 0;
  margin-right: 40px;
  border-left: none;
  border-right: 5px solid #C4A574;
  border-radius: 12px 0 0 12px;
}

@media (max-width: 767px) {
  [dir="rtl"] .block-quote {
    margin-right: 0;
    margin-left: 0;
  }
}

/* Offcanvas RTL — menu from start (right), cart from end (left) */
[dir="rtl"] .offcanvas:not(.offcanvas-mobile-menu) {
  right: auto;
  left: 0;
  transform: translateX(-100%);
}

[dir="rtl"] .offcanvas:not(.offcanvas-mobile-menu).offcanvas-open {
  transform: translateX(0);
}

[dir="rtl"] .offcanvas.offcanvas-mobile-menu {
  left: auto;
  right: 0;
  transform: translateX(100%);
}

[dir="rtl"] .offcanvas.offcanvas-mobile-menu.offcanvas-open {
  transform: translateX(0);
}

[dir="rtl"] .offcanvas__menu-expand::after {
  right: auto;
  left: 0;
}

[dir="rtl"] .offcanvas-add-cart__content {
  margin-right: 0 !important;
  margin-left: 10px;
}

/* Slider arrows — swap positions in RTL */
[dir="rtl"] .hero-espresso .hero-slider__arrow--left,
[dir="rtl"] .hero-slider__arrow--left {
  left: auto !important;
  right: 16px !important;
}

[dir="rtl"] .hero-espresso .hero-slider__arrow--right,
[dir="rtl"] .hero-slider__arrow--right {
  right: auto !important;
  left: 16px !important;
}

[dir="rtl"] .slick-prev {
  left: auto;
  right: 16px;
}

[dir="rtl"] .slick-next {
  right: auto;
  left: 16px;
}

/* Tab separator position */
[dir="rtl"] .tablist--style-seperator li::after {
  right: auto;
  left: 0;
}

/* Product list view text alignment */
[dir="rtl"] .product__box--list .product__content {
  text-align: right;
}

/* Compare / wishlist tables */
[dir="rtl"] .table-content {
  direction: rtl;
}

/* Premium layer RTL cart mobile labels */
@media (max-width: 767px) {
  [dir="rtl"] .cart-table-content table tbody td {
    text-align: left;
    flex-direction: row-reverse;
  }

  [dir="rtl"] .cart-table-content table tbody td::before {
    margin-inline-end: 0;
    margin-inline-start: 12px;
  }
}

/* ═══════════════════════════════════════
   MOBILE HEADER — optimized navigation
   ═══════════════════════════════════════ */

@media (max-width: 991px) {
  .header-brand-mobile .m3-mobile-categories-hidden {
    display: none !important;
  }

  .header-brand-mobile {
    padding-top: 10px;
    padding-bottom: 0;
    position: fixed;
    top: 0;
    inset-inline: 0;
    z-index: 1001;
    box-shadow: 0 2px 12px rgba(44, 24, 16, 0.08);
    background: #fff;
    transition: box-shadow 0.25s ease;
  }

  .header-brand-mobile.is-scrolled {
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: 0 6px 24px rgba(44, 24, 16, 0.14);
  }

  /* Keep the fixed header below the offcanvas overlay while it is open */
  body.offcanvas-open .header-brand-mobile {
    z-index: 998;
  }

  /* Spacer equal to the fixed header height, measured in JS */
  body.m3-has-fixed-mobile-header {
    padding-top: var(--m3-mobile-header-h, 108px);
  }

  html:has(body.m3-has-fixed-mobile-header) {
    scroll-padding-top: calc(var(--m3-mobile-header-h, 108px) + 12px);
  }

  .header-brand-mobile .header__mobile--leftside,
  .header-brand-mobile .header__mobile--rightside {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .header-brand-mobile .header__mobile--rightside {
    gap: 6px;
    flex-shrink: 0;
  }

  .header-brand-mobile .header__user-action-icon li {
    margin: 0 !important;
  }

  .header-brand-mobile .header__user-action-icon li a {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
  }

  .header-brand-mobile .wishlist-item-count,
  .header-brand-mobile .item-count {
    top: -2px;
    right: -2px;
    left: auto;
    min-width: 16px;
    height: 16px;
    line-height: 16px;
    font-size: 9px;
  }

  [dir="rtl"] .header-brand-mobile .wishlist-item-count,
  [dir="rtl"] .header-brand-mobile .item-count {
    right: auto;
    left: -2px;
  }

  .m3-mobile-search-row {
    padding: 10px 0 12px;
  }

  .m3-mobile-search-row .header-search__content input {
    width: 100%;
    padding: 12px 44px 12px 16px;
    font-size: 15px;
    border-radius: 999px;
    border: 1px solid rgba(74, 44, 42, 0.12);
    background: #F5F0EB;
  }

  .m3-mobile-search-row .header-search__content button {
    width: 34px;
    height: 34px;
    top: 50%;
    transform: translateY(-50%);
    right: 4px;
    border-radius: 50%;
    background: #4A2C2A;
    color: #C4A574;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  [dir="rtl"] .m3-mobile-search-row .header-search__content input {
    padding: 12px 16px 12px 44px;
  }

  [dir="rtl"] .m3-mobile-search-row .header-search__content button {
    right: auto;
    left: 4px;
  }

  /* Offcanvas */
  .offcanvas {
    width: min(100vw - 32px, 340px);
    max-width: 100%;
    padding: 20px 16px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }

  .offcanvas-mobile-menu .user-set-role {
    flex-direction: column;
    gap: 8px;
    align-items: stretch !important;
  }

  .offcanvas-mobile-menu .user-set-role li {
    margin: 0 !important;
    width: 100%;
  }

  .offcanvas-brand .offcanvas-menu li a {
    min-height: 48px;
    display: flex;
    align-items: center;
    font-size: 15px;
    font-weight: 500;
  }

  .offcanvas-brand .offcanvas-menu .sub-menu li a {
    min-height: 44px;
    padding-inline-start: 16px;
    font-size: 14px;
    color: #6B6560;
  }

  .offcanvas-brand .header__user-action-icon {
    justify-content: center;
    gap: 12px;
    display: flex;
  }

  .offcanvas-brand .header__user-action-icon li a {
    width: 48px;
    height: 48px;
  }

  body.offcanvas-open {
    overflow: hidden;
    touch-action: none;
  }
}

/* Safe area for notched phones */
@supports (padding: max(0px)) {
  .header-brand-mobile {
    padding-top: max(12px, env(safe-area-inset-top));
  }

  .footer__bottom {
    padding-bottom: max(40px, env(safe-area-inset-bottom));
  }
}

/* Slick — let JS rtl:true handle direction; avoid double-RTL bugs */
.slick-list {
  overflow: hidden;
}

[dir="rtl"] .slick-prev i,
[dir="rtl"] .slick-next i,
[dir="rtl"] .default-slider__arrow i,
[dir="rtl"] .hero-slider__arrow i {
  transform: scaleX(-1);
}

/* Fix expand dropdown in RTL header top */
[dir="rtl"] .expand-dropdown-menu {
  text-align: right;
}

[dir="rtl"] .expand-dropdown-menu.dropdown-menu {
  right: 0;
  left: auto;
}

/* Navbar brand badge — centered above link (matches navbar-brand.css) */
[dir="rtl"] .header-brand .menu-label {
  left: 50%;
  right: auto;
  transform: translateX(-50%);
}

[dir="rtl"] .header-brand .menu-label::after {
  left: 50%;
  right: auto;
  margin-left: -2.5px;
}

/* Material scrolltop safe position */
[dir="rtl"] .material-scrolltop {
  right: auto;
  left: max(16px, env(safe-area-inset-left));
}

@media (max-width: 991px) {
  [dir="rtl"] .material-scrolltop {
    bottom: max(16px, env(safe-area-inset-bottom));
  }

  .hero-promo {
    overflow-x: clip;
  }

  .hero-promo__categories {
    padding-inline: 8px;
  }
}
