/*
 * Bazarban storefront direction bridge.
 * Loaded after page/module styles so newer Bazaro modules follow the active
 * language instead of assuming RTL.
 */

html[dir="rtl"],
html[dir="rtl"] body {
    direction: rtl;
}

html[dir="ltr"],
html[dir="ltr"] body {
    direction: ltr;
    text-align: left;
}

html[dir="ltr"] :is(
    .bb-products-page,
    .bb-product-preview,
    .bb-single-bazaro,
    .bb-bazaro-cart,
    .bb-bazaro-checkout,
    .bb-user-panel,
    .bb-user-panel .modal,
    .bb-blog-page,
    .bb-rbb-role,
    .bb-home-product-role,
    .bbf-footer,
    .bbh-header
) {
    direction: ltr !important;
}

html[dir="rtl"] :is(
    .bb-products-page,
    .bb-product-preview,
    .bb-single-bazaro,
    .bb-bazaro-cart,
    .bb-bazaro-checkout,
    .bb-user-panel,
    .bb-user-panel .modal,
    .bb-blog-page,
    .bb-rbb-role,
    .bb-home-product-role,
    .bbf-footer,
    .bbh-header
) {
    direction: rtl !important;
}

/* Forms and UI copy should follow the page direction. Numeric/contact values
 * can opt into LTR explicitly via dir="ltr" or the .bb-ltr utility. */
html[dir="ltr"] :is(
    .bb-products-page,
    .bb-product-preview,
    .bb-single-bazaro,
    .bb-bazaro-cart,
    .bb-bazaro-checkout,
    .bb-user-panel
) :is(input:not([dir]), select:not([dir]), textarea:not([dir]), .form-control:not([dir])) {
    direction: ltr;
    text-align: left;
}

html[dir="rtl"] :is(input[type="email"], input[type="tel"], input[inputmode="numeric"], .bb-ltr) {
    direction: ltr !important;
}

/* Products page */
html[dir="ltr"] .bb-products-page :is(
    .aq-product-sidebar-widget,
    .aq-product-sidebar-widget-title,
    .bb-products-price-field,
    .bb-products-sidebar-category-list,
    .bb-products-toolbar,
    .bb-qv-info,
    .bb-qv-option-head
) {
    direction: ltr !important;
    text-align: left !important;
}

html[dir="ltr"] .bb-products-page .bb-products-price-field__control {
    direction: ltr !important;
}

html[dir="ltr"] .bb-products-page .bb-products-sidebar__close {
    margin-left: auto;
    margin-right: 0;
}

html[dir="ltr"] .bb-products-page .bb-products-filter-toggle i,
html[dir="ltr"] .bb-products-page [data-bb-filter-toggle] i {
    transform: scaleX(-1);
}

html[dir="ltr"] .bb-product-preview .bb-qv-gallery__arrow--prev {
    left: 18px !important;
    right: auto !important;
}
html[dir="ltr"] .bb-product-preview .bb-qv-gallery__arrow--next {
    right: 18px !important;
    left: auto !important;
}
html[dir="ltr"] .bb-product-preview .bb-qv-gallery__arrow--prev i,
html[dir="ltr"] .bb-product-preview .bb-qv-gallery__arrow--next i {
    transform: scaleX(-1);
}
html[dir="ltr"] .bb-product-preview .bb-qv-head__product-link i {
    transform: scaleX(-1);
}

/* Single product */
html[dir="ltr"] .bb-single-bazaro :is(
    .aq-product-details-wrap,
    .bb-single-buybox,
    .bb-single-tab-content,
    .bb-single-other-seller,
    .bb-single-related-products
) {
    direction: ltr !important;
    text-align: left !important;
}

html[dir="ltr"] .bb-single-bazaro .bb-single-gallery-prev,
html[dir="ltr"] .bb-single-gallery-modal__prev {
    left: 18px !important;
    right: auto !important;
}
html[dir="ltr"] .bb-single-bazaro .bb-single-gallery-next,
html[dir="ltr"] .bb-single-gallery-modal__next {
    right: 18px !important;
    left: auto !important;
}
html[dir="ltr"] .bb-single-bazaro .bb-single-gallery-prev i,
html[dir="ltr"] .bb-single-bazaro .bb-single-gallery-next i,
html[dir="ltr"] .bb-single-gallery-modal__prev i,
html[dir="ltr"] .bb-single-gallery-modal__next i {
    transform: scaleX(-1);
}

/* Cart / Checkout */
html[dir="ltr"] .bb-bazaro-cart,
html[dir="ltr"] .bb-bazaro-checkout,
html[dir="ltr"] .bb-bazaro-cart :is(.bb-cart-summary, .bb-cart-product-copy, .bb-cart-seller-head),
html[dir="ltr"] .bb-bazaro-checkout :is(.bb-checkout-card, .bb-checkout-summary, .bb-checkout-section-intro) {
    direction: ltr !important;
    text-align: left !important;
}

html[dir="ltr"] .bb-bazaro-checkout .modal-header .close,
html[dir="ltr"] .bb-bazaro-checkout [data-dismiss="modal"] {
    margin-left: auto !important;
    margin-right: 0 !important;
}

html[dir="ltr"] .bb-bazaro-cart .bb-cart-progress,
html[dir="ltr"] .bb-bazaro-checkout .bb-checkout-progress {
    direction: ltr !important;
}

/* User panel */
html[dir="ltr"] .bb-user-panel,
html[dir="ltr"] .bb-user-panel :is(
    .bb-dashboard-sidebar-wrap,
    .aq-dashboard-main,
    .bb-dashboard-profile-data,
    .bb-panel-page,
    .table-responsive
) {
    direction: ltr !important;
    text-align: left !important;
}

html[dir="ltr"] .bb-user-panel .row {
    direction: ltr;
}

html[dir="ltr"] .bb-user-panel .bb-dashboard-profile-box__toggle svg,
html[dir="ltr"] .bb-user-panel .bb-dashboard-menu a i[class*="arrow"] {
    transform: scaleX(-1);
}

/* Header / footer / home role navigation */
html[dir="ltr"] .bbh-header :is(.dropdown-menu, .bbh-search-results, .bbh-mobile-drawer),
html[dir="ltr"] .bbf-footer,
html[dir="ltr"] .bb-rbb-role {
    text-align: left;
}

html[dir="ltr"] .bb-home-product-role__head,
html[dir="ltr"] .bb-rbb-head,
html[dir="ltr"] .bb-rbb-element-head {
    direction: ltr;
}

html[dir="ltr"] .bb-rbb-taxonomy-arrow--prev {
    left: 0 !important;
    right: auto !important;
}
html[dir="ltr"] .bb-rbb-taxonomy-arrow--next {
    right: 0 !important;
    left: auto !important;
}
html[dir="ltr"] .bb-rbb-taxonomy-arrow svg,
html[dir="ltr"] .bb-home-product-role__nav svg {
    transform: scaleX(-1);
}

/* Bootstrap-era fixed right/left helpers inside the storefront are frequently
 * visual-only. These logical helpers cover common modern blocks without
 * changing intentionally LTR phone/card-number fields. */
html[dir="ltr"] .bb-products-breadcrumb,
html[dir="ltr"] .bb-single-breadcrumb,
html[dir="ltr"] .bb-cart-breadcrumb,
html[dir="ltr"] .bb-checkout-breadcrumb {
    direction: ltr;
}

html[dir="ltr"] .bb-products-page :is(.text-right, .text-end),
html[dir="ltr"] .bb-single-bazaro :is(.text-right, .text-end),
html[dir="ltr"] .bb-bazaro-cart :is(.text-right, .text-end),
html[dir="ltr"] .bb-bazaro-checkout :is(.text-right, .text-end),
html[dir="ltr"] .bb-user-panel :is(.text-right, .text-end) {
    text-align: left !important;
}

/* Preserve genuinely centered presentation elements. */
html[dir="ltr"] :is(
    .text-center,
    .bb-product-card--soft .bb-product-title,
    .bb-product-card--soft .bb-product-price,
    .bb-rbb-taxonomy-item,
    .bb-rbb-testimonial
) {
    text-align: center !important;
}

@media (max-width: 991.98px) {
    html[dir="ltr"] .bb-product-preview .bb-qv-gallery__arrow--prev,
    html[dir="ltr"] .bb-single-gallery-modal__prev {
        left: 8px !important;
    }
    html[dir="ltr"] .bb-product-preview .bb-qv-gallery__arrow--next,
    html[dir="ltr"] .bb-single-gallery-modal__next {
        right: 8px !important;
    }
}

/* Final LTR safety net for modules that still carry legacy `direction: rtl`
 * declarations deep in their component CSS. This intentionally scopes to the
 * storefront application shells instead of user-authored rich text globally. */
html[dir="ltr"] .bb-products-page :where(*),
html[dir="ltr"] .bb-product-preview :where(*),
html[dir="ltr"] .bb-single-bazaro :where(*),
html[dir="ltr"] .bb-bazaro-cart :where(*),
html[dir="ltr"] .bb-bazaro-checkout :where(*),
html[dir="ltr"] .bb-user-panel :where(*),
html[dir="ltr"] .bb-blog-page :where(*) {
    direction: ltr !important;
}

/* Rich/user content is allowed to resolve its own bidi runs. */
html[dir="ltr"] :is(.product-description, .bb-single-description, .blog-content, .bb-blog-post-content, [data-user-content]) {
    unicode-bidi: plaintext;
}

/* Authentication pages use an RTL-first standalone stylesheet. */
html[dir="ltr"] body.bb-auth-body,
html[dir="ltr"] .bb-auth-page,
html[dir="ltr"] .bb-auth-shell,
html[dir="ltr"] .bb-auth-main,
html[dir="ltr"] .bb-auth-form,
html[dir="ltr"] .bb-auth-terms-modal,
html[dir="ltr"] .bb-auth-terms-content {
    direction: ltr !important;
    text-align: left !important;
}

html[dir="ltr"] .bb-auth-input-icon {
    left: 15px !important;
    right: auto !important;
}

html[dir="ltr"] .bb-auth-field .form-control,
html[dir="ltr"] .bb-auth-field input.form-control,
html[dir="ltr"] .bb-auth-seller-box .form-control {
    padding-left: 45px !important;
    padding-right: 14px !important;
    text-align: left;
}

html[dir="ltr"] .bb-auth-has-toggle .form-control {
    padding-left: 45px !important;
    padding-right: 47px !important;
}

html[dir="ltr"] .bb-auth-pass-toggle {
    left: auto !important;
    right: 9px !important;
}

html[dir="ltr"] .bb-auth-terms-content {
    text-align: left !important;
}

/* The hero's electronics mode used a hard-coded RTL item direction. Keep the
 * slider geometry intact, but let textual content follow the active language. */
html[dir="ltr"] .bb-role-slider-shell--style-electronics.bb-bazaro-slider-ready .carousel-inner > .carousel-item {
    direction: ltr !important;
}

/* Footer and map UI. */
html[dir="ltr"] .bbf-footer :is(.bbf-map-service-picker, .bbf-location-map, .bbf-newsletter, .bbf-footer-column) {
    direction: ltr !important;
    text-align: left !important;
}

/* Common legacy panel/checkout shells that predate the Bazaro wrappers. */
html[dir="ltr"] :is(.checkout, .dashboard-content, .dashboard-wrapper, .dashboard-main, .user-panel-content) {
    direction: ltr !important;
    text-align: left;
}

/* Logical alignment helpers for RTL-authored legacy panel markup. */
html[dir="ltr"] .bb-user-panel .float-right {
    float: left !important;
}
html[dir="ltr"] .bb-user-panel .float-left {
    float: right !important;
}

/* -------------------------------------------------------------------------
 * Legacy storefront coverage
 * -------------------------------------------------------------------------
 * A number of pre-Bazaro modules still ship RTL-first component CSS.  Keep
 * the direction bridge last in the document and normalize their structural
 * containers when an LTR storefront language is selected.  Controls that are
 * inherently LTR (phone, email, card numbers) keep their explicit direction.
 */
html[dir="ltr"] body.bb-dir-ltr :is(
    main,
    .main,
    .main-content,
    .page-content,
    .content,
    .content-wrapper,
    .container,
    .container-fluid,
    .card,
    .modal,
    .modal-content,
    .dropdown-menu,
    .table,
    .table-responsive,
    form,
    .form-group,
    .input-group,
    .checkout,
    .checkout-content,
    .seller-page,
    .seller-list,
    .single-page,
    .preorder,
    .fast-order,
    .weblog,
    .blog,
    .favorites,
    .support,
    .wallet,
    .orders,
    .addresses
) {
    direction: ltr;
}

html[dir="rtl"] body.bb-dir-rtl :is(
    main,
    .main,
    .main-content,
    .page-content,
    .content-wrapper,
    .checkout,
    .seller-page,
    .single-page,
    .preorder,
    .fast-order
) {
    direction: rtl;
}

html[dir="ltr"] body.bb-dir-ltr :is(.text-right, .text-end) {
    text-align: left !important;
}
html[dir="ltr"] body.bb-dir-ltr :is(.text-left, .text-start) {
    text-align: right;
}
html[dir="ltr"] body.bb-dir-ltr .float-right {
    float: left !important;
}
html[dir="ltr"] body.bb-dir-ltr .float-left {
    float: right !important;
}

/* Bootstrap 4-era auto-margin helpers were authored against RTL markup. */
html[dir="ltr"] body.bb-dir-ltr .mr-auto {
    margin-right: auto !important;
    margin-left: 0 !important;
}
html[dir="ltr"] body.bb-dir-ltr .ml-auto {
    margin-left: auto !important;
    margin-right: 0 !important;
}

/* Lists, table headers and common legacy form rows should read from the
 * active edge instead of retaining Persian alignment. */
html[dir="ltr"] body.bb-dir-ltr :is(
    .list-group,
    .list-group-item,
    .nav,
    .nav-tabs,
    .breadcrumb,
    .accordion,
    .accordion-item,
    .accordion-body,
    .alert,
    .form-check,
    table th,
    table td
) {
    direction: ltr;
    text-align: left;
}

html[dir="rtl"] body.bb-dir-rtl :is(table th, table td) {
    direction: rtl;
}

/* Keep numeric/contact strings readable in either UI direction. */
:is(html[dir="rtl"], html[dir="ltr"]) :is(
    [data-bb-ltr],
    .bb-ltr,
    input[type="email"],
    input[type="tel"],
    input[inputmode="numeric"],
    input[inputmode="decimal"]
) {
    direction: ltr !important;
    unicode-bidi: plaintext;
}

/* Home role/builder content follows language direction while visual tracks
 * remain controlled by their own JavaScript and therefore are not reversed
 * by a blanket RTL/LTR carousel rule. */
html[dir="ltr"] :is(.bb-home-product-role, .bb-rbb-role, .bb-rbb-element, .bb-rbb-promo, .bb-rbb-testimonial) {
    direction: ltr !important;
}
html[dir="rtl"] :is(.bb-home-product-role, .bb-rbb-role, .bb-rbb-element, .bb-rbb-promo, .bb-rbb-testimonial) {
    direction: rtl !important;
}

/* Last-resort direction normalization. Legacy component files frequently set
 * `direction: rtl` on nested divs. In an LTR locale, structural descendants
 * must inherit the page direction. Text that contains a different script is
 * still handled correctly by the Unicode bidi algorithm. */
html[dir="ltr"] body.bb-dir-ltr :where(
    div, section, article, aside, main, header, footer, nav,
    form, fieldset, label, ul, ol, li,
    table, thead, tbody, tfoot, tr, th, td,
    p, h1, h2, h3, h4, h5, h6
) {
    direction: ltr !important;
}

html[dir="ltr"] body.bb-dir-ltr :where(.rtl, .owl-rtl) {
    direction: ltr !important;
}

/* Preserve deliberate centered UI after the broad legacy normalization. */
html[dir="ltr"] body.bb-dir-ltr :where(
    .text-center,
    [style*="text-align: center"],
    .bb-product-card--soft,
    .bb-rbb-taxonomy-item,
    .bb-rbb-testimonial
) {
    text-align: center !important;
}
