/**
 * 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;
    }
}

/* ── PDP: badges, trust, gallery, lightbox ── */
.pdp-badges .badge {
    font-size: 12px;
    font-weight: 600;
    padding: 0.35em 0.65em;
}

.pdp-badge--new {
    background: var(--main-color-one, #0d6efd);
    color: #fff;
}

.pdp-badge--hot {
    background: #f59e0b;
    color: #1f2937;
}

.pdp-badge--urgent {
    background: #dc3545;
    color: #fff;
}

.pdp-trust-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 0.75rem;
    background: #f8fafc;
    border-radius: 8px;
    font-size: 13px;
    height: 100%;
}

.pdp-shipping-estimate {
    padding: 0.65rem 0.75rem;
    background: #f8fafc;
    border-radius: 8px;
}

.pdp-gallery-video-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 280px;
    background: #111;
    border-radius: 8px;
    overflow: hidden;
}

.pdp-gallery-video {
    width: 100%;
    max-height: 420px;
}

.pdp-thumb-video {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 72px;
    background: #111;
    color: #fff;
    border-radius: 6px;
    font-size: 1.5rem;
}

.pdp-discount-timer .countdown {
    display: inline-flex;
    gap: 4px;
}

.pdp-lightbox {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.pdp-lightbox[hidden] {
    display: none !important;
}

.pdp-lightbox__close {
    position: absolute;
    top: 1rem;
    left: 1rem;
    border: 0;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.pdp-lightbox__stage {
    max-width: min(96vw, 1100px);
    max-height: 90vh;
}

.pdp-lightbox__img {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
}

    body.pdp-lightbox-open {
    overflow: hidden;
}

/* ── Blog ── */
.blog-reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 0;
    z-index: 1200;
    background: var(--main-color-one, #0d6efd);
    transition: width 0.1s linear;
}

.blog-toc {
    top: 1rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
}

.blog-post-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
}

.blog-share-bar .btn {
    min-height: 36px;
}

/* ── Archive listing ── */
.archive-filters-sticky {
    position: sticky;
    top: 12px;
    z-index: 20;
    max-height: calc(100vh - 24px);
    overflow-y: auto;
}

.archive-header__banner {
    max-height: 140px;
    object-fit: cover;
    width: 100%;
    max-width: 320px;
}

.archive-filter-chip {
    border: 1px solid #dee2e6;
    background: #fff;
    border-radius: 999px;
    padding: 0.25rem 0.75rem;
    font-size: 12px;
    color: #374151;
    cursor: pointer;
}

.archive-filter-chip:hover {
    border-color: var(--main-color-one, #0d6efd);
    color: var(--main-color-one, #0d6efd);
}

.archive-view--list .archive-product-col {
    flex: 0 0 100%;
    max-width: 100%;
}

.archive-view--list .product-box {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 1rem;
}

.archive-view--list .product-image {
    flex: 0 0 180px;
    max-width: 180px;
}

.archive-view--list .product-title,
.archive-view--list .product-action {
    flex: 1 1 200px;
}

.archive-view--compact .archive-product-col {
    flex: 0 0 50%;
    max-width: 50%;
}

@media (min-width: 768px) {
    .archive-view--compact .archive-product-col {
        flex: 0 0 25%;
        max-width: 25%;
    }
}

@media (min-width: 1200px) {
    .archive-view--compact .archive-product-col {
        flex: 0 0 20%;
        max-width: 20%;
    }
}

.archive-empty-state {
    background: #f8fafc;
    border-radius: 12px;
}

.archive-brand-list {
    max-height: 220px;
    overflow-y: auto;
}

@media (min-width: 992px) {
    .page-pdp .product-float {
        top: 1rem;
    }
}

/* ── 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;
    }
}

/* Navigation badges */
.nav-badge {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    margin-right: 4px;
    background: #ef4444;
    color: #fff;
    vertical-align: middle;
}
.nav-badge-new { background: #22c55e; }
.nav-badge-hot { background: #f59e0b; }
.nav-badge-sale { background: #ef4444; }

/* Page builder blocks */
.page-landing .pb-block { margin-bottom: 1.5rem; }
.page-preview .alert { position: sticky; top: 0; z-index: 100; }
.mega-submenu { min-width: 200px; }

/* Customer Hub */
.page-customer-hub .hub-nav-group {
    font-size: 11px;
    font-weight: 600;
    color: #94a3b8;
    text-transform: uppercase;
    padding: 12px 16px 4px;
    list-style: none;
}
.page-customer-hub .hub-stat-card h4 { font-weight: 700; }
.order-timeline {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    padding: 12px 0;
}
.order-timeline-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 72px;
    opacity: 0.45;
}
.order-timeline-step.is-done { opacity: 1; }
.order-timeline-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #cbd5e1;
    margin-bottom: 6px;
}
.order-timeline-step.is-done .order-timeline-dot { background: var(--main-color-one, #2563eb); }
.order-timeline-label { font-size: 11px; text-align: center; color: #64748b; }
.order-timeline-line {
    flex: 1;
    min-width: 20px;
    height: 2px;
    background: #e2e8f0;
    margin-bottom: 22px;
}

/* Support Center — customer */
.support-chat-thread {
    max-height: 420px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f8fafc;
}
.support-chat-bubble {
    max-width: 88%;
    padding: 10px 12px;
    border-radius: 12px;
    font-size: 14px;
}
.support-chat-bubble.is-mine { align-self: flex-end; background: #dbeafe; }
.support-chat-bubble.is-agent { align-self: flex-start; background: #fff; border: 1px solid #e2e8f0; }
.support-chat-meta { font-size: 11px; color: #64748b; margin-bottom: 4px; }
.support-kb-item summary { cursor: pointer; font-weight: 500; }
.support-ticket-row:hover { background: #f8fafc; }
