/*
 * QRTap Menu bidirectional UI layer
 * Version 1.9.0
 *
 * Design rules:
 * - AR and other RTL languages: RTL text, product text on the right, image on the left.
 * - EN/TR and other LTR languages: LTR text, product text on the left, image on the right.
 * - Language switch remains in the same top-right position in every language.
 * - Flex geometry is explicit and does not depend on CSS direction inheritance.
 */

/* ---------- Document direction ---------- */
html[dir="rtl"] body,
html[dir="rtl"] #apt-main,
html[dir="rtl"] .apt-main {
    direction: rtl;
}

html[dir="ltr"] body,
html[dir="ltr"] #apt-main,
html[dir="ltr"] .apt-main {
    direction: ltr;
}

/* ---------- General text alignment ---------- */
html[dir="rtl"] .apt-main .screen_content_entry,
html[dir="rtl"] .apt-main .if_form_control,
html[dir="rtl"] .apt-main .product_widget,
html[dir="rtl"] .apt-main .widget_radio_entry {
    text-align: right;
}

html[dir="ltr"] .apt-main .screen_content_entry,
html[dir="ltr"] .apt-main .if_form_control,
html[dir="ltr"] .apt-main .product_widget,
html[dir="ltr"] .apt-main .widget_radio_entry {
    text-align: left;
}

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

html[dir="ltr"] .apt-main input,
html[dir="ltr"] .apt-main textarea,
html[dir="ltr"] .apt-main select {
    direction: ltr;
    text-align: left;
}

/* ---------- Categories ---------- */
html[dir="rtl"] .category_entry,
html[dir="rtl"] .category_entry .apt_secondary_title {
    direction: rtl;
    text-align: right;
}

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

/* ---------- Product list cards ----------
 * Base DOM: product_info, product_thumb, cart badge.
 * Keep flex container itself LTR so flex-direction has deterministic geometry.
 */
.product_list_item {
    direction: ltr !important;
    display: flex !important;
    align-items: flex-start;
    width: 100%;
    box-sizing: border-box;
    gap: 12px;
}

html[dir="ltr"] .product_list_item {
    flex-direction: row !important;
}

html[dir="rtl"] .product_list_item {
    flex-direction: row-reverse !important;
}

.product_list_item .product_info {
    flex: 1 1 auto !important;
    min-width: 0;
    width: auto;
    margin: 0 !important;
}

html[dir="ltr"] .product_list_item .product_info {
    direction: ltr;
    text-align: left !important;
}

html[dir="rtl"] .product_list_item .product_info {
    direction: rtl;
    text-align: right !important;
}

.product_list_item .product_thumb {
    flex: 0 0 100px !important;
    width: 100px !important;
    height: 100px !important;
    margin: 0 !important;
    position: relative;
}

.product_list_item .product_thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.product_list_item .product_title,
.product_list_item .product_description,
.product_list_item .product_price_display {
    max-width: 100%;
    overflow-wrap: anywhere;
}

html[dir="ltr"] .product_list_item .product_title,
html[dir="ltr"] .product_list_item .product_description,
html[dir="ltr"] .product_list_item .product_price_display {
    direction: ltr;
    text-align: left !important;
}

html[dir="rtl"] .product_list_item .product_title,
html[dir="rtl"] .product_list_item .product_description,
html[dir="rtl"] .product_list_item .product_price_display {
    direction: rtl;
    text-align: right !important;
}

/* Quantity badge follows image side without overlapping content. */
html[dir="ltr"] .product_list_item .product_list_item_cart_info {
    right: .5em !important;
    left: auto !important;
}

html[dir="rtl"] .product_list_item .product_list_item_cart_info {
    left: .5em !important;
    right: auto !important;
}

/* ---------- Language switch ----------
 * Keep control and popup top-right for predictable desktop/mobile behavior.
 */
.apt-cover-header-overlay .lang_switch {
    direction: ltr !important;
    left: auto !important;
    right: 1em !important;
}

.apt-cover-header-overlay .lang_switch_ui {
    direction: ltr !important;
    left: auto !important;
    right: 0 !important;
    overflow: visible !important;
    z-index: 50 !important;
}

.apt-cover-header-overlay .lang_switch_ui .inside {
    direction: ltr !important;
    text-align: left !important;
    min-width: 110px !important;
    width: max-content;
    max-width: min(240px, calc(100vw - 2em));
    box-sizing: border-box;
    overflow: visible !important;
}

.apt-cover-header-overlay .lang_switch_ui .inside .in-section-link,
.apt-cover-header-overlay .lang_switch_ui .inside .form-page-link,
.apt-cover-header-overlay .lang_switch_ui .inside .tertiary-lang-custom {
    display: block !important;
    direction: ltr !important;
    text-align: left !important;
    white-space: nowrap;
    min-height: 24px;
}

/* ---------- Utility mirroring ---------- */
html[dir="rtl"] .apt-main .mr_5 { margin-right: 0 !important; margin-left: 5px !important; }
html[dir="rtl"] .apt-main .ml_5 { margin-left: 0 !important; margin-right: 5px !important; }
html[dir="ltr"] .apt-main .mr_5 { margin-right: 5px !important; margin-left: 0 !important; }
html[dir="ltr"] .apt-main .ml_5 { margin-left: 5px !important; margin-right: 0 !important; }

html[dir="rtl"] .apt-main .float-right { float: left !important; }
html[dir="rtl"] .apt-main .float-left  { float: right !important; }
html[dir="ltr"] .apt-main .float-right { float: right !important; }
html[dir="ltr"] .apt-main .float-left  { float: left !important; }

html[dir="rtl"] .apt-main .icon-chevron-right,
html[dir="rtl"] .apt-main .icon-arrow-right,
html[dir="rtl"] .apt-main .icon-chevron-left,
html[dir="rtl"] .apt-main .icon-arrow-left {
    transform: scaleX(-1);
}

html[dir="ltr"] .apt-main .icon-chevron-right,
html[dir="ltr"] .apt-main .icon-arrow-right,
html[dir="ltr"] .apt-main .icon-chevron-left,
html[dir="ltr"] .apt-main .icon-arrow-left {
    transform: none !important;
}

/* ---------- Mobile safety ---------- */
@media only screen and (max-width: 600px) {
    .product_list_item {
        gap: 10px;
    }

    .product_list_item .product_thumb {
        flex-basis: 88px !important;
        width: 88px !important;
        height: 88px !important;
    }

    .apt-cover-header-overlay .lang_switch {
        right: .75em !important;
    }
}
