/* ==========================================
   Ashenna Product Gallery
   ========================================== */

/* ==========================================
   متغیرهای نسبت ابعاد
   ========================================== */
.apg-wrap {
    --apg-ratio-1-1:  1/1;
    --apg-ratio-4-3:  4/3;
    --apg-ratio-3-4:  3/4;
    --apg-ratio-16-9: 16/9;
    --apg-ratio-9-16: 9/16;
    --apg-ratio-3-2:  3/2;
    --apg-ratio-2-3:  2/3;

    display: flex;
    flex-direction: column;
    width: 100%;
    position: relative;
}

.apg-wrap.pos-left,
.apg-wrap.pos-right {
    flex-direction: row;
    align-items: flex-start;
}

.apg-wrap.pos-left  { flex-direction: row-reverse; }
.apg-wrap.pos-right { flex-direction: row; }

/* ==========================================
   تصویر اصلی
   ========================================== */
.apg-main-section {
    position: relative;
    flex: 1;
    min-width: 0;
}

.apg-main-wrap {
    position: relative;
    width: 100%;

    /* ✅ aspect-ratio به جای height ثابت */
    aspect-ratio: 1 / 1;
    height: auto;

    overflow: hidden;
    border-radius: 12px;
    background-color: #f5f5f5;
    cursor: default;
    min-height: 120px;
}

.apg-main-img-wrap {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.apg-main-img-wrap.zoom-enabled {
    cursor: crosshair;
}

.apg-main-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    user-select: none;
}

/* ==========================================
   انیمیشن‌های تغییر تصویر
   ========================================== */
.apg-main-img.anim-out-fade  { animation: apgFadeOut  0.22s ease forwards; }
.apg-main-img.anim-in-fade   { animation: apgFadeIn   0.3s  ease forwards; }

.apg-main-img.anim-out-slide-left  { animation: apgSlideOutLeft  0.25s cubic-bezier(0.4,0,0.2,1) forwards; }
.apg-main-img.anim-out-slide-right { animation: apgSlideOutRight 0.25s cubic-bezier(0.4,0,0.2,1) forwards; }
.apg-main-img.anim-in-slide-left   { animation: apgSlideInLeft   0.32s cubic-bezier(0.25,0.46,0.45,0.94) forwards; }
.apg-main-img.anim-in-slide-right  { animation: apgSlideInRight  0.32s cubic-bezier(0.25,0.46,0.45,0.94) forwards; }

.apg-main-img.anim-out-zoom { animation: apgZoomOut 0.22s ease forwards; }
.apg-main-img.anim-in-zoom  { animation: apgZoomIn  0.32s cubic-bezier(0.25,0.46,0.45,0.94) forwards; }

@keyframes apgFadeOut      { to   { opacity: 0; } }
@keyframes apgFadeIn       { from { opacity: 0; } to { opacity: 1; } }
@keyframes apgZoomOut      { to   { opacity: 0; transform: scale(1.05); } }
@keyframes apgZoomIn       { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }
@keyframes apgSlideOutLeft  { to   { opacity: 0; transform: translateX(-30px); } }
@keyframes apgSlideOutRight { to   { opacity: 0; transform: translateX(30px); } }
@keyframes apgSlideInLeft   { from { opacity: 0; transform: translateX(30px); }  to { opacity: 1; transform: translateX(0); } }
@keyframes apgSlideInRight  { from { opacity: 0; transform: translateX(-30px); } to { opacity: 1; transform: translateX(0); } }

/* ==========================================
   نقطه‌ها
   ========================================== */
.apg-dots {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 6px;
    z-index: 5;
}

.apg-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: rgba(255,255,255,0.5);
    border: none;
    padding: 0;
    cursor: pointer;
    outline: none;
    transition: all 0.3s cubic-bezier(0.34,1.56,0.64,1);
}

.apg-dot:hover {
    background-color: rgba(255,255,255,0.8);
    transform: scale(1.2);
}

.apg-dot.active {
    width: 20px;
    border-radius: 4px;
    background-color: #ffffff;
}

/* ==========================================
   دکمه لایتباکس
   ========================================== */
.apg-lightbox-btn {
    position: absolute;
    z-index: 5;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(255,255,255,0.9);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    outline: none;
    padding: 0;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    transition: background-color 0.25s ease,
                transform 0.25s cubic-bezier(0.34,1.56,0.64,1),
                box-shadow 0.25s ease;
}

.apg-lightbox-btn:hover {
    background-color: #ffffff;
    transform: scale(1.1);
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.apg-lightbox-btn svg {
    width: 16px;
    height: 16px;
    fill: #333;
    display: block;
}

/* ==========================================
   تصاویر کوچک
   ========================================== */
.apg-thumbs-section {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    position: relative;
    direction: rtl;
}

/* حالت چپ/راست */
.apg-wrap.pos-left  .apg-thumbs-section,
.apg-wrap.pos-right .apg-thumbs-section {
    flex-direction: column;
    margin-top: 0;
}

.apg-wrap.pos-left  .apg-thumbs-section { margin-right: 12px; }
.apg-wrap.pos-right .apg-thumbs-section { margin-left:  12px; }

/* Viewport */
.apg-thumbs-viewport {
    overflow: hidden;
    flex: 1;
    min-width: 0;
}

.apg-wrap.pos-left  .apg-thumbs-viewport,
.apg-wrap.pos-right .apg-thumbs-viewport {
    overflow: hidden;
    /* ✅ max-height از JS به صورت داینامیک تنظیم میشه */
}

/* Track */
.apg-thumbs-track {
    display: flex;
    flex-direction: row;
    gap: 8px;
    direction: rtl;
    transition: transform 0.35s cubic-bezier(0.25,0.46,0.45,0.94);
    will-change: transform;
}

.apg-wrap.pos-left  .apg-thumbs-track,
.apg-wrap.pos-right .apg-thumbs-track {
    flex-direction: column;
}

/* Thumb item */
.apg-thumb-item {
    flex-shrink: 0;
    width: 80px;
    height: 80px;
    overflow: hidden;
    border-radius: 8px;
    cursor: pointer;
    opacity: 0.65;
    transition: all 0.25s ease;
    border: 2px solid transparent;
}

.apg-thumb-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
    border-radius: inherit;
}

.apg-thumb-item:hover {
    opacity: 1;
    border-color: #999;
}

.apg-thumb-item.active {
    opacity: 1;
    border-color: #333;
}

/* ==========================================
   فلش‌های تصاویر کوچک
   ========================================== */
.apg-thumb-arrow {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(255,255,255,0.9);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    outline: none;
    padding: 0;
    z-index: 2;
    transition: background-color 0.2s ease, transform 0.2s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

.apg-thumb-arrow:hover {
    background-color: #fff;
    transform: scale(1.1);
}

.apg-thumb-arrow:disabled {
    opacity: 0.35;
    cursor: default;
    transform: none;
}

.apg-thumb-arrow svg {
    width: 12px;
    height: 12px;
    fill: #333;
    display: block;
}

.apg-thumb-arrow i {
    font-size: 12px;
    color: #333;
}

/* فلش‌ها در حالت عمودی */
.apg-wrap.pos-left  .apg-thumb-prev,
.apg-wrap.pos-right .apg-thumb-prev {
    transform: rotate(-90deg);
}

.apg-wrap.pos-left  .apg-thumb-next,
.apg-wrap.pos-right .apg-thumb-next {
    transform: rotate(-90deg);
}

.apg-wrap.pos-left  .apg-thumb-prev:hover,
.apg-wrap.pos-right .apg-thumb-prev:hover,
.apg-wrap.pos-left  .apg-thumb-next:hover,
.apg-wrap.pos-right .apg-thumb-next:hover {
    transform: rotate(-90deg) scale(1.1);
}

/* ==========================================
   لایتباکس
   ========================================== */
.apg-lightbox-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0,0,0,0.92);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.apg-lightbox-overlay.open {
    opacity: 1;
    visibility: visible;
}

.apg-lightbox-inner {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 60px 80px;
    box-sizing: border-box;
}

.apg-lb-img-wrap {
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.apg-lb-img {
    max-width: 100%;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 8px;
    display: block;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

/* دکمه بستن */
.apg-lb-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(255,255,255,0.15);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    outline: none;
    color: #fff;
    transition: background-color 0.2s ease, transform 0.2s ease;
    z-index: 10;
}

.apg-lb-close:hover {
    background-color: rgba(255,255,255,0.3);
    transform: rotate(90deg);
}

.apg-lb-close svg {
    width: 20px;
    height: 20px;
    fill: #fff;
    display: block;
}

/* فلش‌های لایتباکس */
.apg-lb-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(255,255,255,0.15);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    outline: none;
    color: #fff;
    transition: background-color 0.2s ease,
                transform 0.25s cubic-bezier(0.34,1.56,0.64,1);
    z-index: 10;
}

.apg-lb-prev { left:  16px; }
.apg-lb-next { right: 16px; }

.apg-lb-nav:hover {
    background-color: rgba(255,255,255,0.3);
    transform: translateY(-50%) scale(1.1);
}

.apg-lb-nav svg {
    width: 22px;
    height: 22px;
    fill: #fff;
    display: block;
}

/* شماره */
.apg-lb-counter {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255,255,255,0.7);
    font-size: 14px;
    font-family: sans-serif;
    letter-spacing: 1px;
}

/* ==========================================
   Responsive
   ========================================== */
@media (max-width: 768px) {
    /* حالت چپ/راست → ستونی میشه */
    .apg-wrap.pos-left,
    .apg-wrap.pos-right {
        flex-direction: column;
    }

    .apg-wrap.pos-left  .apg-thumbs-section,
    .apg-wrap.pos-right .apg-thumbs-section {
        flex-direction: row;
        margin-left:  0;
        margin-right: 0;
        margin-top:   10px;
    }

    .apg-wrap.pos-left  .apg-thumbs-track,
    .apg-wrap.pos-right .apg-thumbs-track {
        flex-direction: row;
    }

    /* ✅ روی موبایل height ثابت را override میکنیم */
    /* aspect-ratio همچنان از CSS var کنترل میشه */
    .apg-main-wrap {
        height: auto !important;
    }

    .apg-thumb-item { width: 60px; height: 60px; }

    .apg-lightbox-inner { padding: 50px 16px 40px; }
    .apg-lb-prev { left:  8px; }
    .apg-lb-next { right: 8px; }
    .apg-lb-nav  { width: 36px; height: 36px; }
}

@media (max-width: 480px) {
    .apg-thumb-item { width: 50px; height: 50px; }
}

/* ==========================================
   زوم با دنبال کردن موس
   ========================================== */
.apg-main-img-wrap.zoom-enabled .apg-main-img {
    transition: transform 0.15s ease, transform-origin 0s;
    transform-origin: center center;
    will-change: transform, transform-origin;
}

.apg-main-img-wrap.zoom-enabled:not(:hover) .apg-main-img {
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform-origin 0s;
}