/* ==========================================================================
   GRELHA INICIAL DA GALERIA
   ========================================================================== */

.property-gallery-wrapper {
    position: relative;
    margin-bottom: clamp(40px, 6vw, 64px);
}

/* --- Mobile First: Slider Horizontal --- */
.property-gallery-grid {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    height: clamp(250px, 50vh, 400px);
    gap: 8px;
}

.property-gallery-grid::-webkit-scrollbar {
    display: none;
}

.gallery-trigger {
    flex: 0 0 100%;
    min-width: 100%;
    scroll-snap-align: center;
    border: none;
    padding: 0;
    background: #f3f4f6;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    display: block;
    height: 100%;
}

.gallery-trigger img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.6s cubic-bezier(0.25, 1, 0.5, 1);
}

.gallery-trigger:hover img {
    transform: scale(1.05);
}

/* Esconde o botão "Ver todas as fotos" no telemóvel para não poluir o ecrã */
.gallery-more-button {
    display: none;
}

/* --- Contador Mobile (Pílula) --- */
.mobile-gallery-counter {
    position: absolute;
    bottom: 16px;
    right: 16px;
    background-color: rgba(0, 0, 0, 0.65);
    color: #FFFFFF;
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    padding: 6px 14px;
    border-radius: 20px;
    z-index: 10;
    pointer-events: none;
    letter-spacing: 0.5px;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* ==========================================================================
   LAYOUT DESKTOP DA GRELHA (3x3 Mapeamento Exato do Figma)
   ========================================================================== */
@media (min-width: 768px) {
    .property-gallery-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        grid-template-rows: repeat(3, 1fr);
        gap: 16px;
        overflow: hidden;
        height: 100%;
    }

    .gallery-trigger {
        min-width: auto;
        /* Reset do flex do mobile */
    }

    /* Esconde a pílula do contador mobile em ecrãs grandes */
    .mobile-gallery-counter {
        display: none;
    }

    /* Escurece ligeiramente a última imagem (6ª) para destacar o botão */
    .property-gallery-grid .gallery-trigger:nth-child(6)::after {
        content: "";
        position: absolute;
        inset: 0;
        background: rgba(0, 0, 0, 0.15);
        transition: background 0.3s ease;
    }

    .property-gallery-grid .gallery-trigger:nth-child(n+7) {
        display: none;
    }

    .property-gallery-grid .gallery-trigger:nth-child(6):hover::after {
        background: rgba(0, 0, 0, 0.25);
    }

    /* Mostra e posiciona o botão "Ver todas as fotos" no Desktop */
    .gallery-more-button {
        display: flex;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        background-color: #FFFFFF;
        color: var(--color-neutral-900);
        padding: 10px 20px;
        border-radius: 50px;
        align-items: center;
        gap: 8px;
        font-family: var(--font-heading);
        font-weight: 600;
        font-size: 16px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        z-index: 2;
        white-space: nowrap;
    }

    /* Mapeamento das imagens no grid */
    .property-gallery-grid .gallery-trigger:nth-child(1) {
        grid-column: 1 / 3;
        grid-row: 1 / 3;
        min-height: 460px;
    }

    .property-gallery-grid .gallery-trigger:nth-child(2) {
        grid-column: 3 / 4;
        grid-row: 1 / 2;
    }

    .property-gallery-grid .gallery-trigger:nth-child(3) {
        grid-column: 3 / 4;
        grid-row: 2 / 3;
    }

    .property-gallery-grid .gallery-trigger:nth-child(4) {
        grid-column: 1 / 2;
        grid-row: 3 / 4;
    }

    .property-gallery-grid .gallery-trigger:nth-child(5) {
        grid-column: 2 / 3;
        grid-row: 3 / 4;
    }

    .property-gallery-grid .gallery-trigger:nth-child(6) {
        grid-column: 3 / 4;
        grid-row: 3 / 4;
    }
}

/* ==========================================================================
   MODAL DE GALERIA (FULLSCREEN)
   ========================================================================== */
.gallery-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}

.gallery-modal.is-open {
    opacity: 1;
    visibility: visible;
}

.gallery-modal-backdrop {
    position: absolute;
    inset: 0;
    background-color: rgba(17, 24, 39, 0.95);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: -1;
}

/* --- Modal Header --- */
.gallery-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px;
    color: white;
}

.gallery-counter {
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 16px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.gallery-close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.3s ease;
    margin-left: auto;
}

.gallery-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.gallery-close-btn svg {
    width: 20px;
    height: 20px;
}

/* --- Modal Content --- */
.gallery-modal-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 0 16px;
    overflow: hidden;
}

.gallery-main-image-container {
    max-width: 90vw;
    max-height: 70vh;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.4);
    opacity: 0;
    transform: scale(0.98);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.gallery-modal.is-ready .gallery-main-image-container {
    opacity: 1;
    transform: scale(1);
}

.gallery-main-image-container img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* Garante que a foto não é cortada no modal */
    display: block;
    max-height: 70vh;
}

/* --- Controlos de Navegação --- */
.gallery-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: white;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.3s ease;
    z-index: 10;
}

.gallery-nav-btn:hover {
    transform: translateY(-50%) scale(1.1);
}

.gallery-nav-btn svg {
    width: 32px;
    height: 32px;
}

.gallery-nav-btn.prev {
    left: 24px;
}

.gallery-nav-btn.next {
    right: 24px;
}

/* --- Thumbnails Trilha --- */
.gallery-thumbnails-track {
    padding: 24px;
    display: flex;
    gap: 12px;
    overflow-x: auto;
    justify-content: center;
    scrollbar-width: none;
    /* Firefox */
}

.gallery-thumbnails-track::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari */
}

.gallery-thumb-btn {
    flex: 0 0 90px;
    height: 64px;
    border-radius: 8px;
    border: 2px solid transparent;
    padding: 0;
    cursor: pointer;
    overflow: hidden;
    opacity: 0.5;
    transition: all 0.3s ease;
    background: #000;
}

.gallery-thumb-btn img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-thumb-btn.is-active,
.gallery-thumb-btn:hover {
    opacity: 1;
}

.gallery-thumb-btn.is-active {
    border-color: white;
}