/* GALERI LIST v11 - MOBILE DAN DESKTOP
 * Menggunakan class galeri detail yang SUDAH ADA di style.css.
 * Tambahan dibatasi ke modal galeri list dan badge pada modalQuickVarian.
 * Tidak ada selector yang mengubah kartu/grid/sidebar desktop.
 */
#algListGalleryModal[hidden], #algListGalleryModal [hidden] { display: none !important; }
#algListGalleryModal .alg-gallery-dialog,
#algListGalleryModal .alg-gallery-body,
#algListGalleryModal .alg-gallery-media,
#algListGalleryModal .alg-gallery-sidebar,
#algListGalleryModal .alg-gallery-image-viewport { display: contents; }
#algListGalleryModal .alg-gallery-desktop-only { display: none !important; }
/* Gerakan mengikuti floatHemat pada tema detail, dengan nama lokal. */
@keyframes algGalleryFloatHemat {
    0%, 100% { transform: translateY(0) rotate(2deg); }
    50% { transform: translateY(-4px) rotate(-2deg); }
}

/* Badge aktif bergerak pada MOBILE DAN DESKTOP, termasuk setelah ganti varian.
 * Selector lokal mencegah aturan umum tema menghentikan animasinya.
 * Pengecualian aksesibilitas reduced-motion tetap tersedia di bawah. */
html body #algListGalleryModal.active .label-hemat[data-gallery-saving] {
    transform-origin: center bottom;
    animation: algGalleryFloatHemat 2s infinite ease-in-out !important;
    pointer-events: none;
}
/* Jangan biarkan CSS tema mengalahkan keputusan aturan pembelian. */
html body #algListGalleryModal [data-gallery-form][hidden],
html body #algListGalleryModal [data-gallery-wa][hidden] { display: none !important; }

@media (max-width: 1024px), (max-width: 1366px) and (hover: none) and (pointer: coarse) {
    html body #algListGalleryModal {
        --list-gallery-bottom: var(--alg-bottom-space, calc(68px + env(safe-area-inset-bottom, 0px)));
        top: 0 !important;
        bottom: var(--list-gallery-bottom) !important;
        height: calc(100vh - var(--list-gallery-bottom)) !important;
        height: calc(100dvh - var(--list-gallery-bottom)) !important;
        max-height: calc(100dvh - var(--list-gallery-bottom));
        width: 100% !important;
        z-index: var(--alg-panel-layer, 2147482000) !important;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        overflow: hidden !important;
    }
    html body #algListGalleryModal.active { display: flex; }
    html body.alg-list-gallery-open #topMenu,
    html body.alg-list-gallery-open .main-header { visibility: hidden; }
    html body #algListGalleryModal .gallery-header {
        padding-top: max(12px, env(safe-area-inset-top, 0px));
    }
    html body #algListGalleryModal .close-gallery {
        appearance: none;
        background: transparent;
        border: 0;
        min-width: 44px;
        min-height: 44px;
        text-align: center;
        padding: 0;
    }
    html body #algListGalleryModal .gallery-slider-container {
        min-height: 0;
        padding-top: 64px;
        padding-bottom: 196px;
        touch-action: pan-y pinch-zoom;
    }
    html body #algListGalleryModal .gallery-slide {
        flex: 0 0 100%;
        min-width: 100%;
    }
    html body #algListGalleryModal .gallery-slide img {
        max-height: min(50dvh, calc(100dvh - var(--list-gallery-bottom) - 310px));
        margin: 0;
        opacity: 1;
        object-fit: contain;
    }
    /* Foto induk DAN varian satu lajur geser; ukuran tidak menyusut saat foto banyak. */
    html body #algListGalleryModal .gallery-thumbnails {
        position: absolute;
        bottom: 126px;
        left: 15px;
        right: 15px;
        display: flex !important;
        flex-wrap: nowrap !important;
        align-items: center;
        min-width: 0;
        justify-content: flex-start;
        gap: 10px;
        margin: 0;
        padding: 3px;
        overflow-x: auto;
        overflow-y: hidden;
        overscroll-behavior-x: contain;
        touch-action: pan-x pinch-zoom;
        -webkit-overflow-scrolling: touch;
        scroll-behavior: auto;
        scrollbar-width: thin;
    }
    html body #algListGalleryModal .gallery-thumbnails:empty { display: none !important; }
    html body #algListGalleryModal .thumb-item { flex: 0 0 55px; width: 55px; height: 55px; }
    html body #algListGalleryModal .thumb-item img { width: 100%; height: 100%; }
    /* Posisi CTA mandiri dari wrapper desktop; tetap di atas navigasi bawah. */
    html body #algListGalleryModal .gallery-actions {
        position: absolute; bottom: 30px; left: 0; right: 0;
        width: 100%; display: flex; align-items: stretch; min-height: 46px;
        padding: 0 15px; z-index: 10; overflow: visible;
    }
    html body #algListGalleryModal .gallery-actions form { min-width: 0; }
    html body #algListGalleryModal .gallery-actions .action-btn { min-height: 46px; }
    /* Warna cart-btn dan badge hemat dari tema, hanya untuk modal baru. */
    html body #algListGalleryModal .btn-buy-cart {
        background: #ff9800; color: #fff; border: 0; cursor: pointer;
        box-shadow: 0 4px 10px rgba(255, 152, 0, 0.3);
    }
    html body #algListGalleryModal .label-hemat {
        position: absolute; background: #fff3c4; color: #714d0d;
        border: 1px solid #ffc107; padding: 2px 8px; border-radius: 6px;
        font-size: 10px; font-weight: 700; line-height: 1.4; white-space: nowrap;
        pointer-events: none;
    }
    html body #algListGalleryModal .gallery-actions button:disabled { cursor: wait; }
    html body #algListGalleryModal .gallery-image-error {
        color: #fff;
        font-size: 13px;
        text-align: center;
        padding: 10px;
    }
    html body #algListGalleryModal button:focus-visible,
    html body #algListGalleryModal a:focus-visible { outline: 2px solid #ffc107; outline-offset: 2px; }
    html body #algListGalleryModal .alg-gallery-sr {
        position: absolute; width: 1px; height: 1px; padding: 0;
        overflow: hidden; clip-path: inset(50%); white-space: nowrap;
    }
}

/* HP landscape: pertahankan semua kontrol, bukan menyembunyikan foto/CTA. */
@media (max-height: 520px) and (max-width: 1024px), (max-height: 520px) and (max-width: 1366px) and (hover: none) and (pointer: coarse) {
    html body #algListGalleryModal .gallery-slider-container { padding-top: 45px; padding-bottom: 135px; }
    html body #algListGalleryModal .gallery-slide img {
        max-height: max(50px, calc(100dvh - var(--list-gallery-bottom) - 230px));
    }
    html body #algListGalleryModal .slide-content-wrapper { gap: 4px; }
    html body #algListGalleryModal .gallery-var-badge { padding: 2px 16px; font-size: 12px; }
    html body #algListGalleryModal .gallery-thumbnails { bottom: 78px; }
    html body #algListGalleryModal .gallery-progress-bar { bottom: 70px; }
    html body #algListGalleryModal .gallery-actions { bottom: 10px; }
    html body #algListGalleryModal .gallery-header { padding-bottom: 0; }
}
@media (prefers-reduced-motion: reduce) {
    #algListGalleryModal .gallery-slides,
    #algListGalleryModal .gallery-progress-fill { transition: none !important; }
    html body #algListGalleryModal.active .label-hemat[data-gallery-saving] {
        animation: none !important; transform: none !important;
    }
}

/* DESKTOP: class dipasang JS sesuai breakpoint tema. Ubah variabel zoom di sini. */
html body #algListGalleryModal.alg-gallery-desktop {
    --alg-gallery-zoom-scale: 2;
    --alg-gallery-gold: #956b20;
    --alg-gallery-line: #e6dcc8;
    position: fixed; inset: 0; width: 100%; height: 100vh; height: 100dvh;
    padding: 24px; align-items: center; justify-content: center;
    background: rgba(24, 23, 20, 0.72); backdrop-filter: none; -webkit-backdrop-filter: none;
    z-index: 2147482000; color: #302b23; overflow: auto !important;
}
html body #algListGalleryModal.alg-gallery-desktop.active { display: flex; }
html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-desktop-only { display: block !important; }
html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-dialog {
    display: flex; flex-direction: column; position: relative;
    width: min(1160px, 100%); height: min(760px, calc(100vh - 48px)); height: min(760px, calc(100dvh - 48px));
    min-height: 300px; overflow: hidden; background: #fffdf8;
    border: 1px solid #e7d8b7; border-radius: 20px; box-shadow: 0 24px 80px rgba(0,0,0,0.26);
}
html body #algListGalleryModal.alg-gallery-desktop .gallery-header {
    position: relative; flex: 0 0 64px; width: 100%; padding: 10px 18px;
    color: #58472b; border-bottom: 1px solid var(--alg-gallery-line); background: #fffdf8; gap: 16px;
}
html body #algListGalleryModal.alg-gallery-desktop .gallery-counter {
    background: #f3ebdb; color: #674d22; font-size: 12px; letter-spacing: 0.5px; padding: 7px 12px;
}
html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-eyebrow {
    font-size: 10px; font-weight: 600; letter-spacing: 1.8px; color: #876a36; margin: 0 0 12px;
}
html body #algListGalleryModal.alg-gallery-desktop .gallery-header .alg-gallery-eyebrow { margin: 0 auto 0 0; }
html body #algListGalleryModal.alg-gallery-desktop .close-gallery {
    appearance: none; padding: 0; width: 38px; height: 38px; border: 1px solid var(--alg-gallery-line);
    border-radius: 50%; background: #fff; color: #53432a; font-size: 28px; line-height: 1; cursor: pointer; flex: 0 0 auto;
}
html body #algListGalleryModal.alg-gallery-desktop .close-gallery:hover { background: #f3ebdb; }
html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-body {
    display: grid; grid-template-columns: minmax(0, 1fr) 340px; min-height: 0; flex: 1;
}
html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-media {
    display: flex; flex-direction: column; gap: 14px; padding: 26px;
    min-height: 0; min-width: 0; position: relative; background: #f5f2eb;
}
html body #algListGalleryModal.alg-gallery-desktop .gallery-slider-container {
    padding: 0; min-height: 0; min-width: 0; height: auto; width: 100%; flex: 1;
    overflow: hidden; border-radius: 12px; background: #fff; touch-action: pan-y pinch-zoom;
}
html body #algListGalleryModal.alg-gallery-desktop .gallery-slides { height: 100%; }
html body #algListGalleryModal.alg-gallery-desktop .gallery-slide { flex: 0 0 100%; padding: 0; min-width: 100%; }
html body #algListGalleryModal.alg-gallery-desktop .slide-content-wrapper { height: 100%; max-height: none; min-height: 0; gap: 0; overflow: hidden; }
html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-image-viewport {
    display: flex; align-items: center; justify-content: center; position: relative;
    overflow: hidden; width: 100%; height: 100%; flex: 1; min-height: 0; cursor: zoom-in;
}
html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-image-viewport img {
    display: block; max-width: 100%; max-height: 100%; width: 100%; height: 100%;
    object-fit: contain; border-radius: 0; margin: 0; opacity: 1; box-shadow: none;
    transform: scale(1); transform-origin: var(--zoom-x, 50%) var(--zoom-y, 50%);
    transition: transform 180ms ease-out; pointer-events: none;
}
html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-image-viewport.is-zoomed img { transform: scale(var(--alg-gallery-zoom-scale)); }
html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-image-viewport.is-zoomed { cursor: zoom-out; }
html body #algListGalleryModal.alg-gallery-desktop .gallery-var-badge {
    position: absolute; bottom: 12px; padding: 6px 14px; max-width: calc(100% - 24px);
    font-size: 12px; color: #674d22; background: #fff9e7; border: 1px solid #dfc99d;
    box-shadow: 0 2px 8px rgba(90,64,20,0.09);
}
html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-navigation { display: flex !important; align-items: center; justify-content: space-between; gap: 10px; min-height: 38px; }
html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-navigation button {
    border: 1px solid #ded3bf; border-radius: 9px; padding: 7px 11px; background: #fffdf8; color: #674d22;
    min-width: 38px; min-height: 38px; font: inherit; font-size: 12px; cursor: pointer; white-space: nowrap;
}
html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-navigation button:hover,
html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-navigation button[aria-pressed="true"] { background: #ede1c9; }
html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-navigation span { flex: 1; font-size: 11px; color: #746b5c; text-align: center; }
html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-sidebar {
    display: flex; flex-direction: column; padding: 26px 24px; overflow-y: auto;
    overscroll-behavior: contain; min-width: 0; min-height: 0; border-left: 1px solid var(--alg-gallery-line);
    scrollbar-width: thin; scrollbar-color: #d6c29b transparent;
}
html body #algListGalleryModal.alg-gallery-desktop [data-gallery-name] {
    font-size: clamp(19px, 1.55vw, 24px); font-weight: 600; line-height: 1.4; letter-spacing: -0.4px;
    color: #302b23; margin: 0 0 14px; overflow-wrap: anywhere;
}
html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-selection { font-size: 12px; line-height: 1.6; color: #746853; margin: 0 0 14px; overflow-wrap: anywhere; }
html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-price-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }
html body #algListGalleryModal.alg-gallery-desktop [data-gallery-price] { color: #80571c; font-size: 24px; line-height: 1.35; font-weight: 700; overflow-wrap: anywhere; }
html body #algListGalleryModal.alg-gallery-desktop [data-gallery-original] { color: #887f71; font-size: 12px; }
html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-purchase-note { margin: 8px 0 18px; font-size: 11px; line-height: 1.6; color: #827665; }
html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-thumb-label { color: #60513a; font-size: 12px; font-weight: 600; margin: 0 0 9px; }
html body #algListGalleryModal.alg-gallery-desktop .gallery-thumbnails,
html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-variant-thumbnails {
    display: flex !important; position: static; flex-wrap: wrap; justify-content: flex-start;
    gap: 8px; margin: 0 0 18px; padding: 2px; width: auto; overflow: visible;
}
html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-variant-thumbnails:empty { display: none !important; }
html body #algListGalleryModal.alg-gallery-desktop .thumb-item {
    flex: 0 0 60px; width: 60px; height: 60px; border: 1px solid #e1d7c5; border-radius: 9px;
    padding: 3px; background: #fff; transition: border-color 150ms ease, box-shadow 150ms ease;
}
html body #algListGalleryModal.alg-gallery-desktop .thumb-item img { object-fit: contain; border-radius: 6px; }
html body #algListGalleryModal.alg-gallery-desktop .thumb-item:hover { border-color: #b58b3f; }
html body #algListGalleryModal.alg-gallery-desktop .thumb-item.active { border-color: #9c7328; box-shadow: 0 0 0 2px #efe3cd; }
html body #algListGalleryModal.alg-gallery-desktop .gallery-progress-bar { display: none !important; }
html body #algListGalleryModal.alg-gallery-desktop .gallery-actions {
    position: relative; top: auto; bottom: auto; left: auto; right: auto;
    width: 100%; margin-top: auto; padding: 22px 0 0; gap: 0;
    display: flex; flex-direction: column; flex-shrink: 0;
    overflow: visible;
}
html body #algListGalleryModal.alg-gallery-desktop .gallery-actions form { min-width: 0; order: 0; }
html body #algListGalleryModal.alg-gallery-desktop .gallery-actions [data-gallery-wa] { order: 1; }
html body #algListGalleryModal.alg-gallery-desktop .gallery-actions .action-btn {
    min-height: 46px; border-radius: 10px; font-size: 14px; font-weight: 600;
    border: 1px solid transparent; padding: 12px 16px; white-space: normal; cursor: pointer;
}
html body #algListGalleryModal.alg-gallery-desktop .btn-buy-cart { background: var(--alg-gallery-gold); color: #fff; box-shadow: 0 3px 10px rgba(112,77,21,0.12); }
html body #algListGalleryModal.alg-gallery-desktop .btn-buy-cart:hover { background: #7b5618; }
html body #algListGalleryModal.alg-gallery-desktop .wa-btn { background: #29724b; color: #fff; box-shadow: none; }
html body #algListGalleryModal.alg-gallery-desktop .label-hemat {
    position: absolute; top: -14px; right: 12px; padding: 4px 8px; border: 1px solid #deca99;
    border-radius: 6px; background: #fcf0cf; color: #714d0d; font-size: 11px;
    font-weight: 600; white-space: nowrap; line-height: 1.4; pointer-events: none;
}
html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-detail-link { color: #795e2d; font-size: 12px; font-weight: 500; text-align: center; padding: 12px 0 0; text-decoration: underline; text-underline-offset: 3px; }
html body #algListGalleryModal.alg-gallery-desktop .gallery-image-error { position: absolute; padding: 18px; color: #776d5f; font-size: 13px; text-align: center; }
html body #algListGalleryModal.alg-gallery-desktop :focus-visible { outline: 2px solid #9d7428; outline-offset: 3px; }
html body #algListGalleryModal.alg-gallery-desktop button:disabled { opacity: 0.6; cursor: wait; }
@media (max-height: 620px) {
    html body #algListGalleryModal.alg-gallery-desktop { padding: 12px; }
    html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-dialog { height: calc(100dvh - 24px); }
    html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-media { padding: 14px; }
    html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-sidebar { padding: 16px 20px; }
}
@media (prefers-reduced-motion: reduce) {
    html body #algListGalleryModal.alg-gallery-desktop * { transition: none !important; }
}

html body #algListGalleryModal.alg-gallery-desktop [hidden] { display: none !important; }

/* =====================================================================
   QUICK SELECT: badge pada Beli Sekarang, nominal varian aktif per item.
   Hanya muncul saat JS memasang data-quick-saving dan kelas status modal.
   ===================================================================== */
html body #modalQuickVarian #quickVarBtnBeli {
    position: relative;
    overflow: visible;
}
html body #modalQuickVarian.alg-quick-has-saving .quick-var-actions {
    padding-top: 10px;
}
html body #modalQuickVarian.alg-quick-has-saving .quick-var-footer {
    position: relative;
    overflow: visible;
    flex-shrink: 0;
}
html body #modalQuickVarian #quickVarBtnBeli .label-hemat[data-quick-saving] {
    position: absolute;
    top: -15px;
    right: 14px;
    z-index: 1;
    display: inline-block;
    max-width: calc(100% - 28px);
    padding: 3px 8px;
    border: 1px solid #deca99;
    border-radius: 6px;
    background: #fcf0cf;
    color: #714d0d;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
    pointer-events: none;
    transform-origin: center bottom;
}
html body #modalQuickVarian.show #quickVarBtnBeli .label-hemat[data-quick-saving] {
    animation: algGalleryFloatHemat 2s infinite ease-in-out !important;
}
/* Saat AJAX sedang memproses, jangan tampilkan badge pada tombol status. */
html body #modalQuickVarian #quickVarBtnBeli:disabled [data-quick-saving],
html body #modalQuickVarian #quickVarForm[data-submitting="true"] [data-quick-saving] {
    display: none !important;
}
@media (max-width: 1024px), (max-width: 1366px) and (hover: none) and (pointer: coarse) {
    html body #modalQuickVarian #quickVarBtnBeli .label-hemat[data-quick-saving] { font-size: 10px; }
}
@media (prefers-reduced-motion: reduce) {
    html body #modalQuickVarian.show #quickVarBtnBeli .label-hemat[data-quick-saving] {
        animation: none !important;
        transform: none !important;
    }
}

/* Status stok dan centang hanya di dalam GALERI PRODUK. */
html body #algListGalleryModal .alg-gallery-stock {
    display: inline-flex; align-items: center; flex: 0 0 auto;
    padding: 4px 7px; border: 1px solid #f0b5b5; border-radius: 5px;
    background: #fff1f1; color: #b42323; font-size: 10px;
    font-weight: 800; line-height: 1.3; letter-spacing: .3px; white-space: nowrap;
}
html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-detail-heading {
    display: flex; align-items: center; flex-wrap: wrap; gap: 8px; letter-spacing: 1px;
}
html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-mobile-stock { display: none !important; }
html body #algListGalleryModal .thumb-item[data-gallery-kind="variant"] {
    position: relative;
    overflow: visible;
}
html body #algListGalleryModal .thumb-item[data-gallery-kind="variant"].active {
    border-color: #ff5722;
    background: #fff5e8;
    box-shadow: 0 0 0 1px #ff5722;
}
html body #algListGalleryModal .alg-gallery-check {
    display: none; position: absolute; top: -8px; right: -8px; z-index: 2;
    box-sizing: border-box; width: 24px; height: 24px;
    border-radius: 50%; border: 2px solid #fff;
    background: #ff5722; color: #fff; font: 800 14px/1 Arial, sans-serif;
    align-items: center; justify-content: center;
    box-shadow: 0 2px 5px rgba(255, 87, 34, .25);
    transform-origin: center;
    pointer-events: none;
}
html body #algListGalleryModal .thumb-item[data-gallery-kind="variant"].active .alg-gallery-check {
    display: flex;
    animation: algGalleryCheckPop 320ms cubic-bezier(.2, .8, .3, 1) both;
}
/* Ruang untuk badge dan pantulannya agar tidak terpotong saat thumbnail digeser. */
html body #algListGalleryModal:not(.alg-gallery-desktop) .gallery-thumbnails,
html body #algListGalleryModal.alg-gallery-desktop .alg-gallery-variant-thumbnails {
    padding: 14px 12px 6px;
}
@keyframes algGalleryCheckPop {
    0% { opacity: 0; transform: scale(.35); }
    65% { opacity: 1; transform: scale(1.18); }
    85% { opacity: 1; transform: scale(.94); }
    100% { opacity: 1; transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
    html body #algListGalleryModal .thumb-item[data-gallery-kind="variant"].active .alg-gallery-check {
        animation: none;
    }
}
