/**
 * Storefront UI/UX audit fixes — layered after style.css + responsive.css.
 * Addresses overflow, mobile chrome collisions, spacing rhythm, and a11y.
 */

/* ── Global containment (prevents horizontal page scroll) ── */
html {
    overflow-x: clip;
    scroll-behavior: smooth;
}

body.storefront-body {
    overflow-x: clip;
    max-width: 100%;
    -webkit-text-size-adjust: 100%;
}

.storefront-body .container-fluid,
.storefront-body .content,
.storefront-body footer.footer,
.storefront-body .mega-menu,
.storefront-body .top-menu-parent {
    max-width: 100%;
}

.storefront-body .swiper {
    overflow: hidden;
    max-width: 100%;
}

/* ── Vertical rhythm: section spacing tokens ── */
.storefront-body .content-box {
    padding-block: clamp(1rem, 2.5vw, 1.75rem);
}

.storefront-body .section-title,
.storefront-body .title-panel {
    margin-bottom: clamp(0.75rem, 2vw, 1.25rem);
}

/* ── Mobile fixed chrome: footer + chat + float buttons ── */
@media (max-width: 991.98px) {
    body.storefront-body {
        padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
    }

    .storefront-body .mobile-footer {
        padding: 12px 20px calc(12px + env(safe-area-inset-bottom, 0px));
        border-bottom-width: 3px;
        z-index: 800;
    }

    /* Center floating cart button — RTL-safe */
    .storefront-body .mobile-footer .parent .item.item-float {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
    }

    /* Override legacy percentage positioning from responsive.css */
    .storefront-body .mobile-footer li:nth-child(3) {
        top: auto;
        right: auto;
    }

    .storefront-body .mobile-footer .item {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .storefront-body .mobile-footer .item a {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 44px;
        min-height: 44px;
    }

    /* Chat launcher above mobile nav */
    #store-chat-launcher {
        bottom: calc(92px + env(safe-area-inset-bottom, 0px)) !important;
        right: 16px !important;
        z-index: 850;
    }

    #store-chat-panel {
        bottom: calc(156px + env(safe-area-inset-bottom, 0px));
    }

    /* Collapse float button stack above mobile nav */
    div#btncollapzion {
        bottom: calc(100px + env(safe-area-inset-bottom, 0px)) !important;
        z-index: 790;
    }

    .storefront-body .btn-filter-float {
        bottom: calc(130px + env(safe-area-inset-bottom, 0px)) !important;
    }

    /* Sticky header shouldn't cause overflow */
    .storefront-body header .row {
        margin-inline: 0;
        flex-wrap: nowrap;
    }

    .storefront-body header .col-6 {
        min-width: 0;
    }

    .storefront-body .btn-action-cart {
        flex-shrink: 0;
        min-width: 44px;
        min-height: 44px;
        padding: 0.4rem 0.55rem;
    }

    .storefront-body header .dropdown.ms-3 {
        margin-inline-start: 0.5rem !important;
        flex-shrink: 0;
    }
}

@media (max-width: 575.98px) {
    #store-chat-launcher {
        bottom: calc(92px + env(safe-area-inset-bottom, 0px)) !important;
    }

    #store-chat-panel {
        right: 10px;
        left: 10px;
        width: auto;
        bottom: calc(156px + env(safe-area-inset-bottom, 0px));
        height: min(70vh, 520px);
    }
}

/* ── Header / mega menu overflow ── */
.storefront-body .top-menu-menu > ul {
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
}

.storefront-body .header-btn-group .btn {
    white-space: nowrap;
}

@media (max-width: 1199.98px) and (min-width: 992px) {
    .storefront-body .header-btn-group .btn {
        font-size: 13px;
        padding-inline: 0.65rem;
    }
}

/* ── Category archive: sort controls wrap on narrow screens ── */
.storefront-body .category-sort .form-checks {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
}

.storefront-body .category-sort .form-checks .form-check {
    margin-bottom: 0;
    white-space: nowrap;
}

.storefront-body .category-items {
    min-width: 0;
}

.storefront-body .category-items > .row {
    margin-inline: 0;
}

/* ── Product page tabs: scroll inside container, not page ── */
.storefront-body .product-desc-tab {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
}

/* ── Product cards: consistent image ratio ── */
.storefront-body .product-box .product-image a {
    display: block;
    aspect-ratio: 1 / 1;
    overflow: hidden;
}

.storefront-body .product-box .product-image img,
.storefront-body .product-box .product-img-wrap--primary {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* ── Footer: long text / social row ── */
.storefront-body .footer-socail .row {
    margin-inline: 0;
}

.storefront-body .footer .contact-item .desc,
.storefront-body .footer-copy-right {
    word-break: break-word;
    overflow-wrap: anywhere;
}

.storefront-body .footer .social a {
    min-width: 40px;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ── Tables on mobile: contained horizontal scroll ── */
.storefront-body .table-responsive,
.storefront-body .main-table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ── Accessibility: focus rings ── */
.storefront-body a:focus-visible,
.storefront-body button:focus-visible,
.storefront-body .btn:focus-visible,
.storefront-body input:focus-visible,
.storefront-body select:focus-visible,
.storefront-body textarea:focus-visible,
.storefront-body [tabindex]:focus-visible {
    outline: 2px solid var(--main-color-one);
    outline-offset: 2px;
}

.storefront-body .btn.no-highlight:focus-visible {
    box-shadow: 0 0 0 2px var(--main-color-one);
}

/* ── Interaction: respect reduced motion ── */
@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    .storefront-body *,
    .storefront-body *::before,
    .storefront-body *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ── Empty / loading states polish ── */
.storefront-body .cart-canvases .empty-cart,
.storefront-body .wishlist-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: #6b7280;
}

/* ── PDP: mobile sticky buy bar ── */
@media (max-width: 991.98px) {
    body.storefront-body.page-pdp {
        padding-bottom: calc(156px + env(safe-area-inset-bottom, 0px));
    }

    .pdp-mobile-buy-bar {
        position: fixed;
        left: 0;
        right: 0;
        bottom: calc(88px + env(safe-area-inset-bottom, 0px));
        z-index: 750;
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 10px 16px;
        background: #fff;
        border-top: 1px solid #eee;
        box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.08);
    }

    .pdp-mobile-buy-bar__price {
        flex: 1;
        min-width: 0;
    }

    .pdp-mobile-buy-bar__price .new-price {
        font-weight: 700;
        line-height: 1.3;
    }

    .pdp-mobile-buy-bar__price .old-price {
        opacity: 0.7;
        text-decoration: line-through;
    }

    .pdp-mobile-buy-bar__cta {
        flex-shrink: 0;
        min-height: 44px;
        padding-inline: 1.25rem;
        white-space: nowrap;
    }
}

/* ── Cart: icon remove button ── */
.storefront-body .btn-icon-remove {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: inherit;
    cursor: pointer;
}

.storefront-body .btn-icon-remove:focus-visible {
    outline: 2px solid var(--main-color-one);
    outline-offset: 2px;
    border-radius: 6px;
}

@media (max-width: 575.98px) {
    .storefront-body .breadcrumb {
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .storefront-body .breadcrumb-item {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}
