/* =========================================================
   BINOISE — isolated single product gallery
   ========================================================= */
body.single-product.bnoise-gallery-lock {
    overflow: hidden !important;
}

.bnoise-product-gallery {
    --bnoise-gallery-orange: #fa7921;
    --bnoise-gallery-red: #f55157;
    --bnoise-gallery-text: #23254e;
    --bnoise-gallery-muted: #7d8190;
    --bnoise-gallery-line: #e5e7eb;
    position: relative;
    width: 100%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    direction: rtl;
}

.bnoise-gallery-badges {
    position: absolute;
    z-index: 8;
    top: 16px;
    right: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

.bnoise-gallery-sale,
.bnoise-gallery-count {
    min-height: 32px;
    padding: 0 12px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
    backdrop-filter: blur(9px);
}

.bnoise-gallery-sale {
    color: #fff;
    background: rgba(245, 81, 87, .96);
}

.bnoise-gallery-count {
    color: var(--bnoise-gallery-text);
    background: rgba(255, 255, 255, .92);
    border: 1px solid rgba(223, 225, 229, .95);
}

.bnoise-gallery-main {
    order: 1;
    width: 100%;
    height: 570px;
    min-height: 570px;
    overflow: hidden;
    border: 1px solid #e9eaed;
    border-radius: 24px;
    background: #f7f7f8;
}

.bnoise-gallery-main .swiper-wrapper,
.bnoise-gallery-main-slide,
.bnoise-gallery-main-open {
    width: 100%;
    height: 100%;
}

.bnoise-gallery-main-slide {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f7f7f8;
}

.bnoise-gallery-main-open {
    appearance: none;
    border: 0;
    padding: 0;
    margin: 0;
    background: transparent;
    cursor: zoom-in;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bnoise-gallery-main-image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 26px;
    mix-blend-mode: multiply;
    user-select: none;
    -webkit-user-drag: none;
}

.bnoise-gallery-main-pagination {
    display: none;
}

.bnoise-gallery-preview {
    order: 2;
    margin-top: auto;
    display: flex;
    align-items: stretch;
    justify-content: flex-start;
    gap: 9px;
    min-width: 0;
    overflow: hidden;
    direction: rtl;
}

.bnoise-gallery-thumb,
.bnoise-gallery-more {
    position: relative;
    flex: 0 0 78px;
    width: 78px;
    height: 78px;
    padding: 5px;
    border: 1px solid #dfe2e7;
    border-radius: 13px;
    background: #fff;
    overflow: hidden;
    cursor: pointer;
    transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease;
}

.bnoise-gallery-thumb img,
.bnoise-gallery-more > img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 9px;
    background: #f7f7f8;
    mix-blend-mode: multiply;
}

.bnoise-gallery-thumb:hover,
.bnoise-gallery-thumb.is-active,
.bnoise-gallery-more:hover {
    border-color: var(--bnoise-gallery-orange);
    box-shadow: 0 0 0 2px rgba(250, 121, 33, .08);
}

.bnoise-gallery-more {
    padding: 0;
    isolation: isolate;
}

.bnoise-gallery-more > img {
    border-radius: 12px;
    filter: blur(2px) saturate(.8);
    transform: scale(1.08);
    opacity: .64;
}

.bnoise-gallery-more-shade {
    position: absolute;
    inset: 0;
    z-index: 1;
    background: rgba(35, 37, 78, .38);
    backdrop-filter: blur(1px);
}

.bnoise-gallery-more-content {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: #fff;
    text-align: center;
}

.bnoise-gallery-more-content strong {
    font-size: 18px;
    font-weight: 900;
    line-height: 1;
}

.bnoise-gallery-more-content small {
    font-size: 9px;
    font-weight: 700;
}

/* Full gallery */
.bnoise-gallery-modal {
    position: fixed;
    inset: 0;
    z-index: 100050;
    display: none;
    align-items: stretch;
    justify-content: stretch;
    direction: rtl;
}

.bnoise-gallery-modal.is-open {
    display: flex;
}

.bnoise-gallery-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(10, 11, 15, .92);
    backdrop-filter: blur(4px);
}

.bnoise-gallery-modal-dialog {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    min-width: 0;
    padding: 18px 24px 16px;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) 94px;
    gap: 14px;
    color: #fff;
}

.bnoise-gallery-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    direction: rtl;
}

.bnoise-gallery-modal-title {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 14px;
}

.bnoise-gallery-modal-title strong {
    max-width: min(620px, 62vw);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
    font-weight: 800;
}

.bnoise-gallery-modal-counter {
    min-width: 66px;
    height: 34px;
    padding-inline: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255,255,255,.18);
    border-radius: 10px;
    background: rgba(255,255,255,.08);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    direction: ltr;
}

.bnoise-gallery-modal-close {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255,255,255,.18);
    border-radius: 12px;
    background: rgba(255,255,255,.08);
    color: #fff;
    cursor: pointer;
    transition: background .2s ease, border-color .2s ease;
}

.bnoise-gallery-modal-close:hover {
    background: rgba(250,121,33,.18);
    border-color: rgba(250,121,33,.58);
}

.bnoise-gallery-modal-close svg,
.bnoise-gallery-nav svg {
    width: 22px;
    height: 22px;
}

.bnoise-gallery-modal-stage {
    position: relative;
    min-width: 0;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bnoise-gallery-modal-swiper {
    width: min(100%, 1180px);
    height: 100%;
    min-height: 0;
}

.bnoise-gallery-modal-slide {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
}

.bnoise-gallery-modal-slide img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 6px;
    user-select: none;
    -webkit-user-drag: none;
}

.bnoise-gallery-nav {
    position: absolute;
    z-index: 4;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255,255,255,.18);
    border-radius: 50%;
    background: rgba(255,255,255,.10);
    color: #fff;
    cursor: pointer;
    transition: background .2s ease, border-color .2s ease;
}

.bnoise-gallery-nav:hover {
    background: rgba(250,121,33,.84);
    border-color: var(--bnoise-gallery-orange);
}

.bnoise-gallery-nav-prev {
    right: 12px;
}

.bnoise-gallery-nav-next {
    left: 12px;
}

.bnoise-gallery-modal-thumbs {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 7px 2px;
    scrollbar-width: thin;
    direction: rtl;
}

.bnoise-gallery-modal-thumb {
    flex: 0 0 72px;
    width: 72px;
    height: 72px;
    padding: 4px;
    border: 1px solid rgba(255,255,255,.2);
    border-radius: 11px;
    background: #fff;
    overflow: hidden;
    cursor: pointer;
    opacity: .72;
    transition: opacity .2s ease, border-color .2s ease, transform .2s ease;
}

.bnoise-gallery-modal-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 8px;
    background: #f7f7f8;
}

.bnoise-gallery-modal-thumb:hover,
.bnoise-gallery-modal-thumb.is-active {
    opacity: 1;
    border-color: var(--bnoise-gallery-orange);
    transform: translateY(-2px);
}

.bnoise-gallery-placeholder {
    display: block;
    width: 100%;
    height: auto;
}

@media (max-width: 1180px) {
    .bnoise-product-gallery {
        width: min(100%, 760px);
        margin-inline: auto;
    }

    .bnoise-gallery-main {
        height: 520px;
        min-height: 520px;
    }
}

@media (max-width: 820px) {
    .bnoise-product-gallery {
        width: 100%;
        max-width: none;
        gap: 9px;
    }

    /* Force the correct mobile order regardless of legacy gallery rules. */
    .bnoise-gallery-main {
        order: 1 !important;
        height: min(92vw, 390px);
        min-height: min(92vw, 390px);
        border-radius: 18px;
    }

    .bnoise-gallery-preview {
        order: 2 !important;
        width: 100%;
        gap: 7px;
        overflow-x: auto;
        overflow-y: hidden;
        padding-bottom: 2px;
        scrollbar-width: none;
    }

    .bnoise-gallery-preview::-webkit-scrollbar {
        display: none;
    }

    .bnoise-gallery-main-image {
        padding: 12px;
    }

    .bnoise-gallery-badges {
        top: 10px;
        right: 10px;
    }

    .bnoise-gallery-sale,
    .bnoise-gallery-count {
        min-height: 28px;
        padding-inline: 9px;
        border-radius: 9px;
        font-size: 9px;
    }

    .bnoise-gallery-thumb,
    .bnoise-gallery-more {
        flex-basis: 58px;
        width: 58px;
        height: 58px;
        border-radius: 11px;
    }

    /* Mobile keeps four standard previews plus the final more tile. */
    .bnoise-gallery-thumb:nth-of-type(n+5) {
        display: none;
    }

    .bnoise-gallery-main-pagination {
        display: flex;
        position: absolute;
        z-index: 5;
        bottom: 9px !important;
        left: 50% !important;
        width: auto !important;
        transform: translateX(-50%);
        gap: 4px;
    }

    .bnoise-gallery-main-pagination .swiper-pagination-bullet {
        width: 5px;
        height: 5px;
        margin: 0 !important;
        background: #bcc0c8;
        opacity: .8;
    }

    .bnoise-gallery-main-pagination .swiper-pagination-bullet-active {
        width: 16px;
        border-radius: 999px;
        background: var(--bnoise-gallery-orange);
    }

    .bnoise-gallery-modal-dialog {
        padding: 10px 10px 8px;
        grid-template-rows: auto minmax(0, 1fr) 72px;
        gap: 8px;
    }

    .bnoise-gallery-modal-title strong {
        max-width: 54vw;
        font-size: 11px;
    }

    .bnoise-gallery-modal-counter {
        min-width: 54px;
        height: 32px;
        font-size: 10px;
    }

    .bnoise-gallery-modal-close {
        width: 38px;
        height: 38px;
        flex-basis: 38px;
    }

    .bnoise-gallery-nav {
        width: 40px;
        height: 40px;
        background: rgba(20,20,24,.55);
    }

    .bnoise-gallery-nav-prev {
        right: 4px;
    }

    .bnoise-gallery-nav-next {
        left: 4px;
    }

    .bnoise-gallery-modal-thumb {
        flex-basis: 56px;
        width: 56px;
        height: 56px;
        border-radius: 9px;
    }

    .bnoise-gallery-modal-thumbs {
        justify-content: flex-start;
    }
}

@media (max-width: 480px) {
    .bnoise-gallery-main {
        height: min(94vw, 350px);
        min-height: min(94vw, 350px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .bnoise-gallery-thumb,
    .bnoise-gallery-more,
    .bnoise-gallery-modal-close,
    .bnoise-gallery-nav,
    .bnoise-gallery-modal-thumb {
        transition: none !important;
    }
}

/* =========================================================
   V16 — Mobile gallery order hardening
   Legacy theme CSS sets .imageGallery to column-reverse on mobile.
   Force the redesigned gallery to keep main image first, previews below.
   ========================================================= */
@media (max-width: 820px) {
    body.single-product .imageGallery.single-product-gallery.bnoise-product-gallery,
    body.single-product .bnoise-product-gallery {
        display: flex !important;
        flex-direction: column !important;
    }

    body.single-product .bnoise-product-gallery > .bnoise-gallery-main {
        order: 1 !important;
    }

    body.single-product .bnoise-product-gallery > .bnoise-gallery-preview {
        order: 2 !important;
    }
}

/* Desktop: pin thumbnail rail to the bottom of the stretched gallery column.
   Auto margin consumes only the real leftover height; no fixed offset is used. */
@media (max-width: 1180px) {
    body.single-product .bnoise-product-gallery > .bnoise-gallery-preview {
        margin-top: 0 !important;
    }
}
