/* ============================================
   GALERIA PROFISSIONAL — Lightbox + Swipe
   ============================================ */

/* ---- Galeria Principal ---- */
.listing-gallery {
    position: relative;
    overflow: hidden;
}

.gallery-main {
    position: relative;
    aspect-ratio: 4/3;
    background: var(--surface-3);
    cursor: zoom-in;
}

.gallery-main img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: opacity 180ms ease;
}

.gallery-main img.is-loading {
    opacity: .5;
}

/* Botão ampliar */
.gallery-zoom-btn {
    position: absolute;
    bottom: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: background 150ms ease, transform 150ms ease;
    z-index: 2;
    padding: 0;
}
.gallery-zoom-btn:hover {
    background: rgba(0, 0, 0, 0.72);
    transform: scale(1.06);
}
.gallery-zoom-btn svg {
    width: 20px;
    height: 20px;
}

/* Contador de fotos */
.gallery-counter {
    position: absolute;
    bottom: 12px;
    left: 12px;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: 8px;
    letter-spacing: 0.02em;
    z-index: 2;
    pointer-events: none;
    user-select: none;
}

/* Setas prev/next na galeria */
.gallery-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    z-index: 3;
    padding: 0;
    transition: background 150ms ease, transform 150ms ease, opacity 150ms ease;
    opacity: 0;
}
.listing-gallery:hover .gallery-nav,
.listing-gallery:focus-within .gallery-nav {
    opacity: 1;
}
.gallery-nav:hover {
    background: rgba(0, 0, 0, 0.7);
    transform: translateY(-50%) scale(1.1);
}
.gallery-nav svg {
    width: 18px;
    height: 18px;
}
.gallery-nav--prev { left: 10px; }
.gallery-nav--next { right: 10px; }

/* Thumbnails refinados */
.gallery-thumbs {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    overflow-x: auto;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(107,92,231,0.25) transparent;
}
.gallery-thumbs::-webkit-scrollbar { height: 4px; }
.gallery-thumbs::-webkit-scrollbar-track { background: transparent; }
.gallery-thumbs::-webkit-scrollbar-thumb { background: rgba(107,92,231,0.25); border-radius: 4px; }

.gallery-thumb {
    flex-shrink: 0;
    width: 72px;
    height: 56px;
    border: 2px solid transparent;
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    background: none;
    padding: 0;
    transition: border-color 180ms ease, box-shadow 180ms ease, opacity 180ms ease;
    opacity: 0.65;
}
.gallery-thumb:hover {
    opacity: 0.9;
    border-color: rgba(107, 92, 231, 0.3);
}
.gallery-thumb.active {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(107, 92, 231, 0.18);
    opacity: 1;
}
.gallery-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Fallback: 1 imagem (sem thumbs) */
.gallery-thumbs:empty { display: none; }
.listing-gallery--single .gallery-nav,
.listing-gallery--single .gallery-counter { display: none; }
.listing-gallery--single .gallery-zoom-btn { display: grid; }

/* Fallback: sem imagem */
.gallery-no-image {
    aspect-ratio: 4/3;
    background: var(--surface-3);
    display: grid;
    place-items: center;
    color: var(--color-gray-400);
}
.gallery-no-image svg { width: 48px; height: 48px; opacity: 0.5; }

/* ---- LIGHTBOX ---- */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 250ms ease, visibility 250ms ease;
    touch-action: none;
}
.lightbox-overlay.is-open {
    opacity: 1;
    visibility: visible;
}

/* Header do lightbox */
.lightbox-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    z-index: 10;
}
.lightbox-counter {
    color: rgba(255, 255, 255, 0.8);
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.03em;
    min-width: 60px;
}
/* Controles de Zoom do Lightbox */
.lightbox-zoom-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    padding: 4px 8px;
    border-radius: 99px;
    border: 1px solid rgba(255, 255, 255, 0.15);
}
.lightbox-zoom-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    padding: 0;
    transition: background 150ms ease, transform 150ms ease;
    opacity: 0.85;
}
.lightbox-zoom-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    opacity: 1;
    transform: scale(1.06);
}
.lightbox-zoom-btn svg {
    width: 16px;
    height: 16px;
}
.lightbox-close {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    padding: 0;
    transition: background 150ms ease, transform 150ms ease;
}
.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.08);
}
.lightbox-close svg { width: 20px; height: 20px; }

/* Imagem do lightbox */
.lightbox-image-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 60px 60px 20px;
    overflow: hidden;
}
.lightbox-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
    user-select: none;
    -webkit-user-drag: none;
    transition: opacity 200ms ease;
}
.lightbox-image.is-loading { opacity: 0.4; }

/* Setas do lightbox */
.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    padding: 0;
    z-index: 5;
    transition: background 150ms ease, transform 150ms ease;
}
.lightbox-nav:hover {
    background: rgba(255, 255, 255, 0.22);
    transform: translateY(-50%) scale(1.08);
}
.lightbox-nav svg { width: 22px; height: 22px; }
.lightbox-nav--prev { left: 16px; }
.lightbox-nav--next { right: 16px; }

/* Thumbs strip no lightbox */
.lightbox-thumbs {
    display: flex;
    gap: 8px;
    padding: 12px 20px 20px;
    overflow-x: auto;
    max-width: 100%;
    scrollbar-width: none;
}
.lightbox-thumbs::-webkit-scrollbar { display: none; }

.lightbox-thumb {
    flex-shrink: 0;
    width: 56px;
    height: 42px;
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    opacity: 0.5;
    transition: opacity 180ms ease, border-color 180ms ease;
    background: none;
    padding: 0;
}
.lightbox-thumb:hover { opacity: 0.8; }
.lightbox-thumb.active {
    opacity: 1;
    border-color: rgba(255, 255, 255, 0.7);
}
.lightbox-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* ---- Responsivo ---- */
@media (max-width: 768px) {
    .gallery-main { aspect-ratio: 16/10; }
    .gallery-nav {
        opacity: 1;
        width: 32px;
        height: 32px;
    }
    .gallery-nav--prev { left: 6px; }
    .gallery-nav--next { right: 6px; }
    .gallery-nav svg { width: 16px; height: 16px; }

    .gallery-thumbs {
        gap: 6px;
        padding: 8px 10px;
    }
    .gallery-thumb {
        width: 60px;
        height: 46px;
        border-radius: 8px;
    }

    /* Lightbox mobile */
    .lightbox-image-wrapper {
        padding: 50px 8px 8px;
    }
    .lightbox-nav {
        width: 36px;
        height: 36px;
    }
    .lightbox-nav--prev { left: 6px; }
    .lightbox-nav--next { right: 6px; }
    .lightbox-nav svg { width: 18px; height: 18px; }
    .lightbox-thumbs {
        padding: 8px 12px 14px;
    }
    .lightbox-thumb {
        width: 48px;
        height: 36px;
    }
}

@media (max-width: 480px) {
    .gallery-counter { font-size: 12px; padding: 4px 10px; }
    .gallery-zoom-btn { width: 34px; height: 34px; }
    .gallery-zoom-btn svg { width: 17px; height: 17px; }
}

/* Prefers reduced motion */
@media (prefers-reduced-motion: reduce) {
    .lightbox-overlay,
    .gallery-main img,
    .lightbox-image,
    .gallery-thumb,
    .gallery-nav,
    .gallery-zoom-btn,
    .lightbox-nav,
    .lightbox-close {
        transition-duration: 0.01ms !important;
    }
}
