/* ================================================================
   گالری ویدیوی محصول — اسلاید ویدیو داخل کادر اصلی + پلیر کاستوم
   (هماهنگ با رنگ‌های فعلی سایت: بنفش-نیلی #6366f1 و خاکستری‌های slate)
   ================================================================ */

/* ---------- حالت ویدیو روی کادر اصلی ---------- */
.main-image.is-video {
    cursor: default;
}

.main-image.is-video:hover {
    border-color: #e2e8f0;
    box-shadow: none;
}

/* کادر تطبیقی: اندازه را JS از نسبت واقعی ویدیو می‌دهد (inline width/height) */
.main-image.is-video.is-adaptive {
    max-width: 100%;
    background: #000;
    transition: width 0.25s ease, height 0.25s ease;
}

.main-image.is-video #main-product-image {
    visibility: hidden;
}

.main-image.is-video .main-image__zoom-icon {
    display: none;
}

/* ---------- اسلاید ویدیو (روکش کادر اصلی) ---------- */
.video-slide {
    position: absolute;
    inset: 0;
    z-index: 2;
    background: #0f172a;
    overflow: hidden;
    display: flex;
    align-items: stretch;
    justify-content: stretch;
}

.video-slide[hidden] { display: none !important; }

/* حالت پوستر — absolute تا کل کادر را بپوشاند و با [hidden] درست مخفی شود */
.video-slide__poster {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
}

/* مهم: display:flex روی پوستر، attribute [hidden] را override می‌کند — باید !important باشد */
.video-slide__poster[hidden] {
    display: none !important;
}

.video-slide__poster img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.video-slide__poster img[hidden] {
    display: none !important;
}

/* fallback فریم اول (preload=metadata + #t=0.1) — فقط وقتی پوستر نیست */
.video-slide__fallback {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
}

/* placeholder تمیز برای embed بدون پوستر (آپارات/نامشخص) */
.video-slide__placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: #94a3b8;
    font-size: 0.95rem;
    font-weight: 600;
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
}

.video-slide__placeholder[hidden] {
    display: none !important;
}

/* دکمه پلی بزرگ روی پوستر */
.video-slide__play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 76px;
    height: 76px;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.55);
    border: 2.5px solid rgba(255, 255, 255, 0.85);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    z-index: 3;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), background 0.25s, box-shadow 0.25s,
                opacity 0.22s ease;
}

/* محوشدن نرم بعد از کلیک — سپس با اتریبیوت hidden کاملاً حذف می‌شود */
.video-slide__play.is-fading {
    opacity: 0;
    pointer-events: none;
}

/* مهم: display:flex اتریبیوت [hidden] را خنثی می‌کند — باید !important باشد */
.video-slide__play[hidden] {
    display: none !important;
}

.video-slide__play svg {
    width: 32px;
    height: 32px;
    margin-right: 4px; /* مرکز بصری مثلث پلی */
    pointer-events: none;
}

.video-slide__play:hover {
    transform: translate(-50%, -50%) scale(1.1);
    background: rgba(99, 102, 241, 0.75);
    box-shadow: 0 12px 34px rgba(99, 102, 241, 0.45);
}

.video-slide__play:focus-visible {
    outline: 3px solid rgba(99, 102, 241, 0.7);
    outline-offset: 4px;
}

/* برچسب «ویدیو» روی کادر اصلی */
.video-slide__badge {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(15, 23, 42, 0.72);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 3px 12px;
    border-radius: 999px;
    z-index: 3;
    pointer-events: none;
    letter-spacing: 0.3px;
}

/* ---------- embed (یوتیوب/آپارات) — فقط بعد از کلیک ---------- */
.video-embed {
    position: absolute;
    inset: 0;
    z-index: 4;
    background: #000;
}

.video-embed[hidden] { display: none !important; }

.video-embed iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

/* ================================================================
   بندانگشتی ویدیو در ردیف thumbnails
   ================================================================ */
.thumb--video {
    /* همان استایل پایه .thumb + نشان‌های ویدیو */
}

.thumb__video-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #334155 0%, #1e293b 100%);
    color: #cbd5e1;
}

/* آیکن پلی دایره‌ای نیمه‌شفاف روی بندانگشتی */
.thumb__play-badge {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.thumb__play-badge::before {
    content: '';
    position: absolute;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.55);
    border: 1.5px solid rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.thumb__play-badge svg {
    position: relative;
    z-index: 1;
    width: 14px;
    height: 14px;
    color: #fff;
    margin-right: 2px; /* مرکز بصری مثلث */
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
}

/* برچسب کوچک «ویدیو» پایین بندانگشتی */
.thumb__video-label {
    position: absolute;
    bottom: 4px;
    left: 4px;
    right: 4px;
    text-align: center;
    background: rgba(15, 23, 42, 0.75);
    color: #fff;
    font-size: 0.62rem;
    font-weight: 700;
    line-height: 1;
    padding: 3px 4px;
    border-radius: 6px;
    pointer-events: none;
}

.thumb--video.active .thumb__play-badge::before,
.thumb--video:hover .thumb__play-badge::before {
    background: rgba(99, 102, 241, 0.8);
    border-color: #fff;
}

/* ================================================================
   پلیر کاستوم MP4
   ================================================================ */
.video-player {
    position: absolute;
    inset: 0;
    z-index: 4;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    direction: ltr; /* پلیر رسانه‌ای با چیدمان LTR — دکمه‌ها داخل RTL چیده می‌شوند */
    outline: none;
}

.video-player[hidden] { display: none !important; }

.video-player video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
    display: block;
}

/* حالت تمام‌صفحه */
.video-player:fullscreen,
.video-player:-webkit-full-screen {
    background: #000;
    /* تمام‌صفحه: کل صفحه را پر کن؛ ویدیوی طولی/عرضی با object-fit:contain درست جا می‌شود */
    width: 100%;
    height: 100%;
}

/* ---------- دکمه پلی بزرگ مرکزی داخل پلیر ----------
   با رویدادهای واقعی ویدیو کنترل می‌شود:
   پخش → محو (opacity + pointer-events:none سپس hidden)
   توقف/پایان → دوباره ظاهر می‌شود */
.vp-overlay-play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.55);
    border: 2.5px solid rgba(255, 255, 255, 0.85);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    z-index: 5;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), background 0.25s,
                box-shadow 0.25s, opacity 0.22s ease;
    opacity: 1;
}

.vp-overlay-play svg {
    width: 30px;
    height: 30px;
    margin-right: 4px; /* مرکز بصری مثلث پلی */
    pointer-events: none;
}

.vp-overlay-play:hover {
    transform: translate(-50%, -50%) scale(1.1);
    background: rgba(99, 102, 241, 0.75);
    box-shadow: 0 12px 34px rgba(99, 102, 241, 0.45);
}

.vp-overlay-play:focus-visible {
    outline: 3px solid rgba(99, 102, 241, 0.7);
    outline-offset: 4px;
}

.vp-overlay-play.is-hidden {
    opacity: 0;
    pointer-events: none;
}

.vp-overlay-play[hidden] {
    display: none !important;
}

/* ---------- اسپینر بافر ---------- */
.video-player__spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 6;
    pointer-events: none;
}

.video-player__spinner[hidden] { display: none !important; }

.vp-spinner {
    display: block;
    width: 54px;
    height: 54px;
    border: 5px solid rgba(255, 255, 255, 0.25);
    border-top-color: #fff;
    border-radius: 50%;
    animation: vp-spin 0.9s linear infinite;
}

@keyframes vp-spin {
    to { transform: rotate(360deg); }
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ---------- حالت خطا ---------- */
.video-player__error {
    position: absolute;
    inset: 0;
    z-index: 7;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    background: rgba(15, 23, 42, 0.92);
    color: #e2e8f0;
    text-align: center;
    padding: 20px;
}

.video-player__error[hidden] { display: none !important; }

.video-player__error p {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.9;
    font-family: 'Vazir', sans-serif;
}

.video-player__error svg {
    color: #f59e0b;
}

.vp-btn--retry {
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 10px 26px;
    font-family: 'Vazir', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.vp-btn--retry:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 18px rgba(99, 102, 241, 0.4);
}

/* ---------- بازخورد جلو/عقب ۱۰ ثانیه ---------- */
.vp-flash {
    position: absolute;
    top: 18%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.75);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 700;
    font-family: 'Vazir', sans-serif;
    padding: 8px 18px;
    border-radius: 999px;
    opacity: 0;
    transition: opacity 0.25s;
    pointer-events: none;
    z-index: 6;
}

.vp-flash.is-visible { opacity: 1; }

.vp-flash.is-backward { left: 22%; }
.vp-flash.is-forward { left: 78%; }

/* ---------- نوار کنترل‌ها ---------- */
.video-player__controls {
    position: absolute;
    right: 0;
    left: 0;
    bottom: 0;
    z-index: 5;
    padding: 26px 14px 10px;
    background: linear-gradient(to top, rgba(15, 23, 42, 0.88) 0%, rgba(15, 23, 42, 0.45) 60%, transparent 100%);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

/* مخفی‌شدن خودکار هنگام پخش */
.video-player.is-idle { cursor: none; }

.video-player.is-idle .video-player__controls {
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
}

/* ---------- نوار پیشرفت (LTR — قرارداد رسانه‌ای) ---------- */
.vp-progress {
    position: relative;
    height: 18px;
    display: flex;
    align-items: center;
    margin-bottom: 4px;
    cursor: pointer;
    touch-action: none; /* drag روی موبایل بدون اسکرول صفحه */
}

.vp-progress__track {
    position: relative;
    width: 100%;
    height: 5px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.25);
    overflow: visible;
    transition: height 0.15s;
}

.vp-progress:hover .vp-progress__track {
    height: 7px;
}

.vp-progress__buffered,
.vp-progress__played {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    border-radius: 999px;
    pointer-events: none;
}

.vp-progress__buffered {
    background: rgba(255, 255, 255, 0.35);
    width: 0;
}

.vp-progress__played {
    background: linear-gradient(90deg, #6366f1 0%, #8b5cf6 100%);
    width: 0;
}

/* دسته (handle) کوچک روی نوار */
.vp-progress__played::after {
    content: '';
    position: absolute;
    right: -7px;
    top: 50%;
    transform: translateY(-50%) scale(0);
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.45);
    transition: transform 0.15s;
}

.vp-progress:hover .vp-progress__played::after,
.vp-progress:has(.vp-progress__input:focus-visible) .vp-progress__played::after {
    transform: translateY(-50%) scale(1);
}

/* input محدوده شفاف روی کل نوار: drag و tap و کیبورد و ARIA */
.vp-progress__input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
}

.vp-progress__input:focus-visible {
    outline: 2px solid rgba(139, 92, 246, 0.8);
    outline-offset: 3px;
    border-radius: 6px;
}

/* ---------- ردیف دکمه‌ها (RTL) ---------- */
.vp-buttons {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: nowrap;
}

.vp-btn {
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: background 0.2s, transform 0.15s;
}

.vp-btn svg {
    width: 22px;
    height: 22px;
    pointer-events: none;
}

.vp-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-1px);
}

.vp-btn:focus-visible {
    outline: 2.5px solid rgba(139, 92, 246, 0.9);
    outline-offset: 1px;
}

.vp-btn--seek svg { width: 26px; height: 26px; }

/* آیکن پلی/پاز (سوییچ با کلاس) */
#vp-play .vp-icon-pause { display: none; }
#vp-play.is-playing .vp-icon-play { display: none; }
#vp-play.is-playing .vp-icon-pause { display: block; }

/* آیکن صدا — سه حالت: بلند / کم / بی‌صدا (همگام با مقدار اسلایدر) */
#vp-mute .vp-icon-vol,
#vp-mute .vp-icon-vol-low,
#vp-mute .vp-icon-muted { display: none; }

#vp-mute:not(.is-muted):not(.is-low) .vp-icon-vol { display: block; }
#vp-mute.is-low:not(.is-muted) .vp-icon-vol-low { display: block; }
#vp-mute.is-muted .vp-icon-muted { display: block; }

/* ---------- زمان ---------- */
.vp-time {
    color: #fff;
    font-size: 0.82rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    padding: 0 6px;
    min-width: 96px;
    text-align: center;
}

.vp-time-sep { flex: 1 1 auto; }

/* ---------- صدا ---------- */
.vp-volume {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 0 0 auto;
}

/* اسلایدر صدا ذاتاً LTR است: مقدار ۰ سمت چپ و ۱۰۰ سمت راست
   (ارث‌بری dir=rtl از نوار کنترل جهت مقدار و پرشدن را برعکس می‌کرد) */
.vp-volume__slider {
    -webkit-appearance: none;
    appearance: none;
    direction: ltr;
    width: 0;
    opacity: 0;
    height: 4px;
    border-radius: 999px;
    /* پرشدن track با متغیر --vol — از چپ (۰) به راست (۱۰۰) */
    background: linear-gradient(to right,
        #fff 0%,
        #fff var(--vol, 100%),
        rgba(255, 255, 255, 0.3) var(--vol, 100%),
        rgba(255, 255, 255, 0.3) 100%);
    cursor: pointer;
    transition: width 0.25s ease, opacity 0.25s ease;
    margin: 0;
}

.vp-volume:hover .vp-volume__slider,
.vp-volume__slider:focus-visible {
    width: 74px;
    opacity: 1;
}

.vp-volume__slider:focus-visible {
    outline: 2px solid rgba(139, 92, 246, 0.9);
    outline-offset: 3px;
}

/* track شفاف در هر دو موتور — گرادیان روی خود input رندر می‌شود */
.vp-volume__slider::-webkit-slider-runnable-track {
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    border-radius: 999px;
    background: transparent;
}

.vp-volume__slider::-moz-range-track {
    height: 4px;
    border-radius: 999px;
    background: transparent;
}

.vp-volume__slider::-moz-range-progress {
    height: 4px;
    border-radius: 999px;
    background: transparent;
}

/* thumb یکدست در webkit و moz — ۱۲px، سفید، با سایه */
.vp-volume__slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    margin-top: -4px; /* مرکزکردن روی track ۴px */
    border-radius: 50%;
    background: #fff;
    border: none;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

.vp-volume__slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #fff;
    border: none;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

/* در موبایل فقط دکمه mute کافی است (mute/unmute مستقل از اسلایدر کار می‌کند) */
@media (max-width: 768px) {
    .vp-volume__slider { display: none; }
}

/* ---------- سرعت پخش ---------- */
.vp-speed {
    position: relative;
    flex: 0 0 auto;
}

.vp-speed__btn {
    width: auto;
    min-width: 44px;
    padding: 0 8px;
    font-family: 'Vazir', sans-serif;
    font-size: 0.88rem;
    font-weight: 700;
}

.vp-speed__menu {
    position: absolute;
    bottom: calc(100% + 10px);
    right: 0;
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 108px;
    z-index: 10;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    direction: rtl;
}

.vp-speed__menu[hidden] { display: none !important; }

.vp-speed__menu button {
    border: none;
    background: transparent;
    color: #e2e8f0;
    font-family: 'Vazir', sans-serif;
    font-size: 0.88rem;
    font-weight: 600;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    text-align: right;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    white-space: nowrap;
}

.vp-speed__menu button:hover {
    background: rgba(99, 102, 241, 0.35);
    color: #fff;
}

.vp-speed__menu button[aria-checked="true"] {
    background: rgba(99, 102, 241, 0.5);
    color: #fff;
}

.vp-speed__menu button[aria-checked="true"]::after {
    content: '✓';
    font-size: 0.8rem;
}

.vp-speed__menu button:focus-visible {
    outline: 2px solid rgba(139, 92, 246, 0.9);
    outline-offset: 1px;
}

/* ---------- موبایل: کنترل‌های فشرده‌تر ---------- */
@media (max-width: 768px) {
    .vp-btn { width: 38px; height: 38px; }
    .vp-btn svg { width: 20px; height: 20px; }
    .vp-btn--seek svg { width: 24px; height: 24px; }
    .vp-time { min-width: 86px; font-size: 0.75rem; padding: 0 2px; }
    .video-player__controls { padding: 20px 8px 6px; }
    .video-slide__play { width: 64px; height: 64px; }
    .video-slide__play svg { width: 26px; height: 26px; }
    .vp-flash.is-backward { left: 18%; }
    .vp-flash.is-forward { left: 82%; }
}

/* موبایل باریک (≤۴۸۰px): حذف دکمه‌های جلو/عقب ۱۰ثانیه‌ای برای جا شدن نوار
   (seek همچنان از طریق نوار پیشرفت، دابل‌تپ و کیبورد در دسترس است) */
@media (max-width: 480px) {
    .vp-btn--seek { display: none; }
    .vp-buttons { gap: 2px; }
    .vp-time { min-width: 76px; }
    .vp-overlay-play { width: 60px; height: 60px; }
    .vp-overlay-play svg { width: 26px; height: 26px; }
}
