.woocommerce div.product { position:relative; display:flex; flex-wrap:wrap; align-items:flex-start; gap:40px; max-width:var(--container-max); margin:0 auto; padding:32px 20px; }
.woocommerce div.product > .woocommerce-product-gallery, .woocommerce div.product > .mytheme-product-gallery { flex:0 0 calc(50% - 20px); width:calc(50% - 20px); min-width:0; }
.woocommerce div.product > .summary { flex:0 0 calc(50% - 20px); width:calc(50% - 20px); min-width:0; }
.woocommerce div.product > .mytheme-product-section, .woocommerce div.product > .mytheme-product-upsells-section, .woocommerce div.product > .mytheme-product-related-section { flex:0 0 100%; width:100%; }
.woocommerce div.product span.onsale { position:absolute; top:32px; right:20px; z-index:5; margin:0; }
.mytheme-product-gallery { width:100%; min-width:0; }
.mytheme-product-gallery__main-slider { width:100%; position:relative; overflow:hidden; border-radius:var(--radius); background:#fafafa; touch-action:pan-y; user-select:none; }
.mytheme-product-gallery__track { display:flex; flex-direction:row; direction:ltr; width:100%; transform:translate3d(0,0,0); will-change:transform; }
.mytheme-product-gallery__slide { direction:rtl; flex:0 0 100%; width:100%; aspect-ratio:1/1; display:flex; align-items:center; justify-content:center; overflow:hidden; }
.mytheme-product-gallery__main-img { display:block; width:100%; height:100%; object-fit:contain; cursor:zoom-in; -webkit-user-drag:none; }
.mytheme-product-gallery__main-slider.is-dragging { cursor:grabbing; }
.mytheme-product-gallery__main-slider.is-dragging .mytheme-product-gallery__main-img { cursor:grabbing; }
.mytheme-product-gallery__prev,.mytheme-product-gallery__next { position:absolute; top:50%; transform:translateY(-50%); z-index:3; width:38px; height:38px; border:1px solid var(--color-border); border-radius:50%; background:#fff; box-shadow:0 2px 10px rgba(0,0,0,.1); cursor:pointer; font-size:24px; line-height:1; display:flex; align-items:center; justify-content:center; }
.mytheme-product-gallery__prev { right:12px; }.mytheme-product-gallery__next { left:12px; }
.mytheme-product-gallery__thumbs { margin-top:12px; width:100%; overflow:hidden; }
.mytheme-product-gallery__thumb-track { display:flex; gap:10px; width:max-content; max-width:none; overflow-x:auto; padding:2px; scrollbar-width:none; cursor:grab; }
.mytheme-product-gallery__thumb-track::-webkit-scrollbar { display:none; }
.mytheme-product-gallery__thumb { flex:0 0 78px; width:78px; height:78px; padding:0; border:2px solid var(--color-border); border-radius:var(--radius); background:#fff; overflow:hidden; cursor:pointer; }
.mytheme-product-gallery__thumb img { width:100%; height:100%; object-fit:cover; display:block; }
.mytheme-product-gallery__thumb.is-active { border-color:var(--color-primary); }
.mytheme-gallery-lightbox .mytheme-modal-box { max-width:100vw; width:100%; height:100%; max-height:100vh; padding:0; background:#111; border-radius:0; }
.mytheme-gallery-lightbox__carousel-wrap { width:100%; height:100%; overflow:hidden; }
.mytheme-gallery-lightbox__track { display:flex; flex-direction:row; direction:ltr; width:100%; height:100%; transform:translate3d(0,0,0); will-change:transform; touch-action:none; user-select:none; cursor:grab; }
.mytheme-gallery-lightbox__track.is-dragging { cursor:grabbing; }
.mytheme-gallery-lightbox__slide { direction:rtl; flex:0 0 100%; width:100%; height:100%; display:flex; align-items:center; justify-content:center; padding:50px; box-sizing:border-box; }
.mytheme-gallery-lightbox__slide img { max-width:100%; max-height:90vh; width:auto; height:auto; object-fit:contain; -webkit-user-drag:none; }
.mytheme-gallery-lightbox__prev,.mytheme-gallery-lightbox__next { position:fixed; top:50%; transform:translateY(-50%); z-index:5; width:42px; height:42px; border:0; border-radius:50%; background:rgba(255,255,255,.15); color:#fff; font-size:28px; cursor:pointer; }
.mytheme-gallery-lightbox__prev { right:20px; }.mytheme-gallery-lightbox__next { left:20px; }
@media (max-width:900px){ .woocommerce div.product{gap:24px}.woocommerce div.product>.woocommerce-product-gallery,.woocommerce div.product>.mytheme-product-gallery,.woocommerce div.product>.summary{flex:0 0 100%;width:100%} }
@media (max-width:600px){ .mytheme-product-gallery__thumb{flex-basis:64px;width:64px;height:64px}.mytheme-product-gallery__slide{aspect-ratio:1/1}.mytheme-product-gallery__prev,.mytheme-product-gallery__next{width:34px;height:34px;font-size:21px} }

/* v0.3.3: the track stays LTR internally so RTL pages never reverse its math. */
.mytheme-product-gallery__main-slider,
.mytheme-gallery-lightbox__carousel-wrap { direction:ltr; }
.mytheme-product-gallery__slide,
.mytheme-gallery-lightbox__slide { direction:rtl; }
.mytheme-product-gallery__slide { cursor:zoom-in; }
.mytheme-product-gallery__slide img { pointer-events:auto; }
.mytheme-product-gallery__track,
.mytheme-gallery-lightbox__track { -webkit-tap-highlight-color:transparent; }

/* v0.3.4: image layer never steals clicks from the gallery slide. */
.mytheme-product-gallery__main-slider { direction:ltr; }
.mytheme-product-gallery__track, .mytheme-gallery-lightbox__track { direction:ltr !important; }
.mytheme-product-gallery__slide, .mytheme-gallery-lightbox__slide { direction:rtl; }
.mytheme-product-gallery__main-img { pointer-events:none; }
.mytheme-product-gallery__main-slider.is-dragging, .mytheme-product-gallery__main-slider.is-dragging * { cursor:grabbing !important; }
.mytheme-product-gallery__thumb-track { overflow-x:auto; overflow-y:hidden; touch-action:pan-x; }
.mytheme-gallery-lightbox__track { direction:ltr !important; }
.mytheme-gallery-lightbox__slide img { pointer-events:none; user-select:none; }


/* Gallery fix: exactly four thumbnails visible at once; additional thumbnails remain horizontally scrollable. */
.mytheme-product-gallery__thumb-track {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 10px;
}
.mytheme-product-gallery__thumb {
    flex: 0 0 calc((100% - 30px) / 4);
    width: calc((100% - 30px) / 4);
    height: auto;
    aspect-ratio: 1 / 1;
}
@media (max-width: 600px) {
    .mytheme-product-gallery__thumb {
        flex-basis: calc((100% - 30px) / 4);
        width: calc((100% - 30px) / 4);
        height: auto;
    }
}


/* Final gallery stability fixes: isolated lightbox layer and one-slide drag. */
.mytheme-gallery-lightbox {
    z-index: 2147483000 !important;
    isolation: isolate;
}
.mytheme-gallery-lightbox.is-open {
    visibility: visible !important;
    pointer-events: auto !important;
    display: flex !important;
}
.mytheme-gallery-lightbox .mytheme-modal-overlay {
    z-index: 0;
    pointer-events: auto;
}
.mytheme-gallery-lightbox .mytheme-gallery-lightbox__box {
    z-index: 1;
}
.mytheme-gallery-lightbox__carousel-wrap,
.mytheme-gallery-lightbox__track {
    width: 100%;
    height: 100%;
}
.mytheme-gallery-lightbox__track {
    min-width: 100%;
}
.mytheme-gallery-lightbox__slide img {
    pointer-events: none !important;
}


/* v0.3.5: isolated desktop-safe lightbox. The generic modal transform/overflow
   must not be allowed to affect the full-screen gallery viewer. */
body.mytheme-lightbox-open { overflow: hidden !important; }
#mytheme-gallery-lightbox.mytheme-gallery-lightbox {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    margin: 0 !important;
    padding: 0 !important;
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
    z-index: 2147483647 !important;
    align-items: stretch !important;
    justify-content: stretch !important;
}
#mytheme-gallery-lightbox.mytheme-gallery-lightbox.is-open {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}
#mytheme-gallery-lightbox .mytheme-modal-overlay {
    position: fixed !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: rgba(0,0,0,.94) !important;
    opacity: 1 !important;
    z-index: 0 !important;
}
#mytheme-gallery-lightbox .mytheme-gallery-lightbox__box {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-width: none !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 0 !important;
    overflow: hidden !important;
    transform: none !important;
    opacity: 1 !important;
    background: transparent !important;
    z-index: 2 !important;
}
#mytheme-gallery-lightbox .mytheme-gallery-lightbox__carousel-wrap {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    overflow: hidden !important;
    z-index: 1 !important;
}
#mytheme-gallery-lightbox .mytheme-gallery-lightbox__track {
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    height: 100% !important;
    min-width: 100% !important;
    z-index: 1 !important;
}
#mytheme-gallery-lightbox .mytheme-gallery-lightbox__slide {
    height: 100% !important;
    min-height: 100% !important;
}
#mytheme-gallery-lightbox .mytheme-modal-close {
    position: fixed !important;
    top: 18px !important;
    left: 18px !important;
    z-index: 20 !important;
    width: 44px !important;
    height: 44px !important;
    margin: 0 !important;
    padding: 0 !important;
    color: #fff !important;
    background: rgba(0,0,0,.35) !important;
    border-radius: 50% !important;
    font-size: 32px !important;
    line-height: 42px !important;
    text-align: center !important;
    cursor: pointer !important;
}
#mytheme-gallery-lightbox .mytheme-gallery-lightbox__prev,
#mytheme-gallery-lightbox .mytheme-gallery-lightbox__next {
    z-index: 20 !important;
    pointer-events: auto !important;
}
@media (max-width: 600px) {
    #mytheme-gallery-lightbox .mytheme-modal-close { top: 12px !important; left: 12px !important; }
}

/* v0.3.6: explicit zoom control; only the gallery control is added. */
.mytheme-product-gallery__zoom{position:absolute;top:12px;left:12px;z-index:4;width:40px;height:40px;display:flex;align-items:center;justify-content:center;padding:0;border:1px solid var(--color-border);border-radius:50%;background:#fff;box-shadow:0 2px 10px rgba(0,0,0,.10);color:var(--color-text);cursor:pointer;font-size:25px;line-height:1}
.mytheme-product-gallery__zoom span{display:block;transform:translateY(-1px)}
.mytheme-product-gallery__zoom:hover{transform:scale(1.04)}
.mytheme-product-gallery__thumb-track.is-dragging{cursor:grabbing;user-select:none}
.mytheme-product-gallery__thumb-track.is-dragging .mytheme-product-gallery__thumb{cursor:grabbing}
@media (max-width:600px){.mytheme-product-gallery__zoom{top:10px;left:10px;width:36px;height:36px;font-size:22px}}


/* v0.3.7: precise pointer dragging; never let gallery gestures scroll the document. */
.mytheme-product-gallery__main-slider { touch-action:pan-y !important; overscroll-behavior:auto; }
.mytheme-product-gallery__thumb-track { direction:ltr !important; touch-action:pan-y !important; overscroll-behavior:auto; cursor:grab; user-select:none; -webkit-user-select:none; }
.mytheme-product-gallery__thumb { direction:rtl; }
.mytheme-product-gallery__thumb-track.is-dragging { cursor:grabbing; }
.mytheme-product-gallery__main-img, .mytheme-product-gallery__thumb img { -webkit-user-drag:none; user-select:none; }
.mytheme-gallery-lightbox__track { touch-action:none !important; overscroll-behavior:none; }

/* Thumbnail carousel: four visible items, transform-driven and RTL-safe. */
.mytheme-product-gallery__thumbs {
    width:100%;
    overflow:hidden !important;
    position:relative;
}
.mytheme-product-gallery__thumb-track {
    display:flex;
    flex-direction:row;
    direction:ltr !important;
    gap:10px;
    width:max-content !important;
    max-width:none !important;
    overflow:visible !important;
    padding:2px;
    margin:0;
    transform:translate3d(0,0,0);
    will-change:transform;
    touch-action:none !important;
    cursor:grab;
    user-select:none;
    -webkit-user-select:none;
}
.mytheme-product-gallery__thumb-track .mytheme-product-gallery__thumb {
    flex:0 0 auto !important;
    width:auto;
    height:auto;
    aspect-ratio:1 / 1;
    padding:0;
    box-sizing:border-box;
    pointer-events:auto;
    cursor:pointer;
}
.mytheme-product-gallery__thumb-track .mytheme-product-gallery__thumb img {
    display:block;
    width:100% !important;
    height:100% !important;
    max-width:none !important;
    max-height:none !important;
    object-fit:cover;
    pointer-events:none;
    user-select:none;
    -webkit-user-drag:none;
}
.mytheme-product-gallery__thumb-track.is-dragging {
    cursor:grabbing !important;
}
.mytheme-product-gallery__thumb-track.is-dragging .mytheme-product-gallery__thumb {
    cursor:grabbing !important;
}
@media (max-width:600px) {
    .mytheme-product-gallery__thumb-track { gap:8px; }
}

/* v0.3.8: keep the thumbnail viewport locked directly beneath the main image.
   Pointer dragging remains horizontal, while mouse-wheel input is allowed to
   bubble to the page instead of being trapped by the gallery. */
.mytheme-product-gallery__thumbs {
    position:relative;
    display:block;
    width:100%;
    min-width:0;
    overflow:hidden !important;
    direction:ltr;
}
.mytheme-product-gallery__thumb-track {
    position:relative;
    display:flex !important;
    flex-direction:row !important;
    direction:ltr !important;
    align-items:stretch;
    gap:10px;
    margin:0;
    padding:2px;
    min-width:0;
    overflow:visible !important;
    will-change:transform;
    touch-action:pan-y !important;
    overscroll-behavior:auto !important;
}
.mytheme-product-gallery__thumb-track .mytheme-product-gallery__thumb {
    flex:0 0 auto !important;
    width:auto;
    aspect-ratio:1 / 1;
    box-sizing:border-box;
}
.mytheme-product-gallery__thumb-track .mytheme-product-gallery__thumb img {
    display:block;
    width:100% !important;
    height:100% !important;
    max-width:none !important;
    object-fit:cover !important;
}
@media (max-width:600px) {
    .mytheme-product-gallery__thumb-track { gap:8px; }
}


/* Product page visual refinement - scoped only to the gallery. */
.single-product .mytheme-product-gallery__main-slider {
	border:1px solid #ececec;
	border-radius:18px;
}

.single-product .mytheme-product-gallery__prev,
.single-product .mytheme-product-gallery__next,
.single-product .mytheme-product-gallery__zoom {
	box-shadow:none;
	border-color:#e5e5e5;
}

.single-product .mytheme-product-gallery__thumb {
	border-color:#e5e5e5;
	border-radius:12px;
	
}

.single-product .mytheme-product-gallery__zoom {
	width:42px;
	height:42px;
	background:rgba(255,255,255,.94);
	backdrop-filter:blur(4px);
}

/* ==========================================
   SINGLE PRODUCT - TRUE FULL WIDTH
   ========================================== */

body.single-product .woocommerce-content {
    width: 100% !important;
    max-width: none !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
}
.woocommerce div.product {
    position:relative;
    display:flex;
    flex-wrap:wrap;
    align-items:flex-start;
    gap:40px;
    width:100%;
    max-width:none;
    margin:0;
    padding:32px 20px;
}
/* =========================================================
   Product Gallery - Prevent Initial Layout Shift
   ========================================================= */

/* فقط اصلاح تصاویر بندانگشتی گالری */
.mytheme-product-gallery__thumbs {
    display: flex;
    gap: 10px;
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px 2px;
    box-sizing: border-box;
}

.mytheme-product-gallery__thumb {
    flex: 0 0 78px;
    width: 78px;
    height: 78px;
    min-width: 78px;
    border-radius: 10px;
    overflow: hidden;
    box-sizing: border-box;
}

.mytheme-product-gallery__thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* تصویر بندانگشتی فعال */
.mytheme-product-gallery__thumb.is-active {
    border: 2px solid #93a254;
}

/* اسکرول بار بندانگشتی‌ها */
.mytheme-product-gallery__thumbs::-webkit-scrollbar {
    height: 5px;
}

.mytheme-product-gallery__thumbs::-webkit-scrollbar-thumb {
    border-radius: 10px;
}

/* موبایل */
@media (max-width: 600px) {
    .mytheme-product-gallery__thumb {
        flex-basis: 64px;
        width: 64px;
        height: 64px;
        min-width: 64px;
    }
	.woocommerce div.product {
    gap: 24px !important;
    padding: 12px 12px !important;
}
}
/* فقط برای محصولی که تماماً ناموجود است */
.single-product .mytheme-product-gallery--out-of-stock .mytheme-product-gallery__main-img,
.single-product .mytheme-product-gallery--out-of-stock .mytheme-product-gallery__thumb img {
	filter: grayscale(1);
}
