/* =========================================================
   Gallery + Lightbox + Video Player — Pinterest style
   تکمیل‌کنندهٔ Tailwind. بدون وابستگی خارجی.
   ========================================================= */

:root {
    --g-gap: 10px;
    --g-radius: 14px;
    --g-card-bg: #ece6da;
    --g-shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 14px rgba(0,0,0,.06);
    --g-shadow-hover: 0 4px 10px rgba(0,0,0,.06), 0 14px 30px rgba(0,0,0,.10);
    --g-gold: #c9a96e;
    --g-gold-dark: #a07c47;
    --g-overlay: rgba(15, 12, 8, .82);
    --vp-accent: #c9a96e;
}

@media (min-width: 640px) {
    :root { --g-gap: 12px; }
}

/* ---------- Sticky offsets پویا برای موبایل ---------- */
.filter-bar { top: 58px; }
@media (min-width: 640px) {
    .filter-bar { top: 65px; }
}

/* ========================== MASONRY ========================== */
/* container با absolute positioning — JS مختصات هر کارت را تعیین می‌کند */
.masonry {
    position: relative;
    width: 100%;
    transition: height 0.25s ease;
}

.m-card {
    position: absolute;
    top: 0;
    right: 0; /* RTL */
    width: var(--card-w, 200px);
    cursor: pointer;
    border-radius: var(--g-radius);
    overflow: hidden;
    background: var(--g-card-bg);
    box-shadow: var(--g-shadow);
    transform: translate3d(var(--tx, 0), var(--ty, 0), 0);
    transition:
        transform 0.45s cubic-bezier(.2,.7,.2,1),
        box-shadow 0.25s ease,
        opacity 0.4s ease;
    will-change: transform;
    -webkit-tap-highlight-color: transparent;
}

.m-card.is-entering {
    opacity: 0;
    transform: translate3d(var(--tx, 0), calc(var(--ty, 0) + 12px), 0);
}
.m-card.is-ready {
    opacity: 1;
}

@media (hover: hover) {
    .m-card:hover {
        box-shadow: var(--g-shadow-hover);
    }
    .m-card:hover .m-img { transform: scale(1.04); }
    .m-card:hover .m-overlay { opacity: 1; transform: translateY(0); }
}

.m-card:focus-visible {
    outline: 3px solid var(--g-gold);
    outline-offset: 2px;
}

.m-media {
    position: relative;
    width: 100%;
    background: var(--g-card-bg);
    overflow: hidden;
}
/* Aspect-ratio از inline style می‌آید تا قبل از لود تصویر هم ارتفاع درست باشد */

.m-img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s cubic-bezier(.2,.7,.2,1), opacity 0.3s ease;
    opacity: 0;
}
.m-img.is-loaded { opacity: 1; }

.m-video-badge {
    position: absolute;
    bottom: 8px;
    left: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 999px;
    background: rgba(0,0,0,.55);
    color: #fff;
    backdrop-filter: blur(4px);
    pointer-events: none;
}

.m-overlay {
    position: absolute;
    inset: auto 0 0 0;
    background: linear-gradient(to top, rgba(15,12,8,.85) 0%, rgba(15,12,8,.4) 50%, transparent 100%);
    padding: 28px 12px 10px;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    color: #fff;
    pointer-events: none;
}
.m-svc {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    background: var(--g-gold);
    font-size: 10.5px;
    font-weight: 500;
    color: #fff;
    margin-bottom: 4px;
}
.m-title {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.4;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,.4);
}

/* روی موبایل overlay دائم نیمه‌فعال (بدون hover) */
@media (hover: none) {
    .m-overlay {
        opacity: 1;
        transform: translateY(0);
        background: linear-gradient(to top, rgba(15,12,8,.72) 0%, transparent 70%);
    }
}

/* ===================== Skeleton جای واقعی ===================== */
.masonry-skeleton {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--g-gap);
    margin-top: 4px;
}
@media (min-width: 640px) {
    .masonry-skeleton { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1024px) {
    .masonry-skeleton { grid-template-columns: repeat(5, 1fr); }
}

.skel-card {
    height: var(--h, 220px);
    border-radius: var(--g-radius);
    background: linear-gradient(90deg, #ece6da 0%, #f3eee4 50%, #ece6da 100%);
    background-size: 200% 100%;
    animation: skel-shimmer 1.6s linear infinite;
}
@keyframes skel-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.masonry-skeleton.is-hidden { display: none; }

/* ========================== LIGHTBOX ========================== */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.22s ease;
    /* safe-area روی notch دستگاه‌ها */
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.lightbox.is-open {
    display: flex;
    opacity: 1;
}
.lightbox.is-closing { opacity: 0; }

.lb-backdrop {
    position: absolute;
    inset: 0;
    background: var(--g-overlay);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.lb-stage {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    max-width: min(96vw, 1100px);
    width: 100%;
    max-height: 100dvh;
    padding: 56px 12px 16px;
}
@media (min-width: 640px) {
    .lb-stage { padding: 64px 64px 24px; }
}

.lb-media {
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    /* روی موبایل ارتفاع را با 100dvh مدیریت می‌کنیم تا با کیبرد/url-bar هماهنگ باشد */
    max-height: calc(100dvh - 180px);
    min-height: 0;
    width: 100%;
    transition: transform 0.4s cubic-bezier(.2,.7,.2,1), opacity 0.3s ease;
}
.lb-media img {
    display: block;
    max-width: 100%;
    max-height: calc(100dvh - 180px);
    width: auto;
    height: auto;
    border-radius: 12px;
    object-fit: contain;
    box-shadow: 0 30px 70px rgba(0,0,0,.4);
    user-select: none;
    -webkit-user-drag: none;
}

.lb-info {
    color: #fff;
    text-align: center;
    max-width: min(640px, 92vw);
    min-height: 1.5em;
}
.lb-service {
    display: inline-block;
    color: var(--g-gold);
    font-size: 11.5px;
    font-weight: 500;
}
.lb-title {
    margin: 4px 0 0;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.5;
}
.lb-desc {
    margin: 6px 0 0;
    font-size: 13px;
    line-height: 1.7;
    color: rgba(255,255,255,.78);
}
.lb-info:empty { display: none; }

/* دکمه‌های شناور */
.lb-btn {
    position: absolute;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,.16);
    background: rgba(255,255,255,.12);
    color: #fff;
    backdrop-filter: blur(8px);
    cursor: pointer;
    transition: background 0.18s ease, transform 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}
.lb-btn:hover { background: rgba(255,255,255,.22); }
.lb-btn:active { transform: scale(.94); }
.lb-btn:focus-visible {
    outline: 2px solid var(--g-gold);
    outline-offset: 2px;
}

.lb-close {
    top: max(14px, env(safe-area-inset-top));
    right: max(14px, env(safe-area-inset-right));
}
.lb-prev {
    /* RTL: prev (قبلی) سمت راست */
    right: max(14px, env(safe-area-inset-right));
    top: 50%;
    transform: translateY(-50%);
}
.lb-next {
    left: max(14px, env(safe-area-inset-left));
    top: 50%;
    transform: translateY(-50%);
}
.lb-prev:active, .lb-next:active { transform: translateY(-50%) scale(.94); }

@media (max-width: 480px) {
    /* روی موبایل دکمه‌های قبلی/بعدی به پایین می‌آیند تا فضای تصویر بیشتر شود */
    .lb-prev, .lb-next {
        top: auto;
        bottom: max(16px, env(safe-area-inset-bottom));
        transform: none;
    }
    .lb-prev:active, .lb-next:active { transform: scale(.94); }
}

.lb-btn[disabled] {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

/* انیمیشن باز شدن */
.lightbox.is-open .lb-media {
    animation: lb-in 0.32s cubic-bezier(.2,.7,.2,1);
}
@keyframes lb-in {
    from { opacity: 0; transform: scale(.96); }
    to   { opacity: 1; transform: scale(1); }
}

/* ===================== VIDEO PLAYER سفارشی ===================== */
.vplayer {
    position: relative;
    width: 100%;
    max-width: min(90vw, 960px);
    aspect-ratio: 16 / 9;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 30px 70px rgba(0,0,0,.4);
    user-select: none;
}
.vplayer.is-portrait {
    aspect-ratio: 9 / 16;
    max-width: min(60vw, 420px);
}
.vplayer-video {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}

.vplayer-bigplay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 0;
    color: #fff;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.vplayer-bigplay::before {
    content: "";
    width: 72px; height: 72px;
    border-radius: 999px;
    background: rgba(0,0,0,.55);
    border: 2px solid rgba(255,255,255,.85);
    position: absolute;
    transition: transform .2s ease, background .2s ease;
}
.vplayer-bigplay svg {
    position: relative;
    z-index: 1;
    margin-right: -4px; /* بصری: مثلث وسط دایره */
}
.vplayer-bigplay:hover::before { background: rgba(0,0,0,.7); transform: scale(1.06); }
.vplayer[data-state="playing"] .vplayer-bigplay { display: none; }

.vplayer-controls {
    position: absolute;
    inset: auto 0 0 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px 10px;
    background: linear-gradient(to top, rgba(0,0,0,.75) 0%, rgba(0,0,0,0) 100%);
    color: #fff;
    opacity: 1;
    transition: opacity 0.25s ease;
    /* پایین در سمت چپ/راست برای ltr ولی ما را در RTL هم درست نمایش می‌دهیم */
    direction: ltr;
}
.vplayer[data-state="playing"].is-idle .vplayer-controls {
    opacity: 0;
    pointer-events: none;
}

.vplayer-controls button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px; height: 32px;
    border: 0;
    background: transparent;
    color: #fff;
    cursor: pointer;
    border-radius: 6px;
    -webkit-tap-highlight-color: transparent;
}
.vplayer-controls button:hover { background: rgba(255,255,255,.14); }

.vp-time {
    font-size: 11.5px;
    font-variant-numeric: tabular-nums;
    min-width: 38px;
    text-align: center;
    color: rgba(255,255,255,.92);
}

.vp-bar {
    position: relative;
    flex: 1;
    height: 4px;
    background: rgba(255,255,255,.22);
    border-radius: 999px;
    cursor: pointer;
    overflow: visible;
    transition: height 0.15s ease;
}
.vp-bar:hover { height: 6px; }
.vp-bar-buf {
    position: absolute;
    inset: 0;
    width: 0%;
    background: rgba(255,255,255,.32);
    border-radius: inherit;
}
.vp-bar-fill {
    position: absolute;
    inset: 0;
    width: 0%;
    background: var(--vp-accent);
    border-radius: inherit;
}
.vp-bar-thumb {
    position: absolute;
    top: 50%;
    left: 0%;
    width: 12px;
    height: 12px;
    border-radius: 999px;
    background: #fff;
    transform: translate(-50%, -50%);
    box-shadow: 0 1px 4px rgba(0,0,0,.4);
    opacity: 0;
    transition: opacity 0.15s ease;
    pointer-events: none;
}
.vp-bar:hover .vp-bar-thumb,
.vp-bar.is-scrubbing .vp-bar-thumb { opacity: 1; }

.hidden { display: none !important; }

/* ===================== iOS / موبایل tweaks ===================== */
@supports (-webkit-touch-callout: none) {
    .lb-media img { -webkit-user-select: none; }
}

/* جلوگیری از scroll background وقتی lightbox باز است */
body.lb-open {
    overflow: hidden;
    /* روی iOS body fix */
    position: fixed;
    width: 100%;
}

/* reduce motion */
@media (prefers-reduced-motion: reduce) {
    .m-card, .m-img, .m-overlay, .lb-media, .lightbox, .vplayer-bigplay::before {
        transition-duration: 0.001s !important;
        animation-duration: 0.001s !important;
    }
}
