/* ==========================================================================
   CUSTOM GALLERY - Página de galería con hero, filtros, grid zigzag y lightbox
   ========================================================================== */

/* ---------------------------------------------------------------------------
   0. WRAPPER GLOBAL — Fondo teal que cubre todo el contenido
   --------------------------------------------------------------------------- */

#gallerySec {
    position: relative;
    overflow: hidden;
    padding-top: 140px;
    color: #ffffff;
}

#gallerySec .gallery-wrapper__bg {
    position: absolute;
    inset: 0;
    background-color: #00A8B5;
    background-image: url("../../images/noise-bg.png");
    background-position: center center;
    background-repeat: repeat;
    background-blend-mode: multiply;
    z-index: -2;
}

/* Decoradores de palmeras */
/* mix-blend-mode y opacity ya están incluidos dentro de los SVGs */
#gallerySec .gallery-wrapper__decorator {
    position: absolute;
    z-index: -1;
    pointer-events: none;
    object-fit: cover;
}

#gallerySec .gallery-wrapper__decorator--left {
    top: 0;
    left: 0;
    width: 710px;
    height: 474px;
}

#gallerySec .gallery-wrapper__decorator--right {
    top: 0;
    right: 0;
    width: 607px;
    height: 696px;
}

/* Breadcrumb dentro del fondo teal */
#gallerySec #breadCrumb {
    padding-top: 48px;
}

#gallerySec #breadCrumb ol li,
#gallerySec #breadCrumb ol li a,
#gallerySec #breadCrumb ol li::after {
    color: #ffffff;
}

/* ---------------------------------------------------------------------------
   1. HERO
   --------------------------------------------------------------------------- */

.gallery-hero {
    position: relative;
    padding: 56px 64px 56px;
    text-align: center;
    color: #ffffff;
}

.gallery-hero__inner {
    max-width: 900px;
    margin: 0 auto;
}

.gallery-hero__title {
    margin: 0 0 24px 0;
    font-family: "Playfair Display";
    font-size: 5.625rem;
    font-weight: 300;
    line-height: 6.75rem;
    letter-spacing: 0;
    text-transform: uppercase;
    color: #ffffff;
}

.gallery-hero__subtitle {
    margin: 0 0 48px 0;
    font-family: "Inter";
    font-size: 1.1875rem;
    font-weight: 700;
    line-height: 1.5;
    color: #ffffff;
}

.gallery-hero__description {
    max-width: 652px;
    margin: 0 auto;
    font-family: "Inter";
    font-size: 1.0625rem;
    font-weight: 400;
    line-height: 1.5;
    color: #ffffff;
}

.gallery-hero__description p {
    margin: 0;
}

/* ---------------------------------------------------------------------------
   2. FILTROS / TABS
   --------------------------------------------------------------------------- */

.gallery-filters {
    display: flex;
    justify-content: center;
    width: fit-content;
    /* Sin max-width: el ancho real lo fija gallery.js (JS) a partir del
       contenido ya repartido en filas, con margen para la flecha del tab
       activo. Un max-width en CSS (basado en % del viewport) puede quedar
       por debajo de ese calculo segun el contenido y encoger el contenedor,
       rompiendo el reparto al hacer clic en un tab. */
    margin: 0 auto;
    /* Sin margin-top: el espacio hero->filtros debe igualar el espacio breadcrumb->hero */
    position: relative;
    z-index: 10;
    background: rgba(42, 42, 42, 0.16);
    border: 1px solid rgba(42, 42, 42, 0.24);
    border-radius: 4px;
}

.gallery-filters__inner {
    display: inline-flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    padding: 16px;
}

/* Salto de linea forzado (insertado por gallery.js) para repartir los tabs
   en el mismo numero por fila cuando no caben en una sola linea.
   margin-bottom negativo cancela el gap extra que añadiria esta fila de altura 0. */
.gallery-filters__break {
    flex-basis: 100%;
    width: 0;
    height: 0;
    margin-bottom: -10px;
}

.gallery-filters__tab {
    display: inline-flex;
    align-items: center;
    gap: 0;
    padding: 12px 20px;
    border: 1px solid #ffffff;
    border-radius: 2px;
    background: transparent;
    font-family: "Inter";
    font-size: 1.1875rem;
    font-weight: 700;
    line-height: 1.375rem;
    color: #ffffff;
    text-transform: none;
    cursor: pointer;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.gallery-filters__tab:hover {
    background-color: rgba(255, 255, 255, 0.15);
    border-color: #ffffff;
    color: #ffffff;
}

/* Flecha oculta por defecto */
.gallery-filters__tab-arrow {
    display: none;
    width: 16px;
    height: 16px;
    transform: rotate(180deg);
}

/* Icono del ojo en tab "Todas" */
.gallery-filters__tab-icon {
    display: inline-block;
    width: 18px;
    height: 11px;
    margin-left: 8px;
    filter: brightness(0) invert(1);
}

.gallery-filters__tab.active .gallery-filters__tab-icon {
    filter: none;
}

/* Tab activo: fondo blanco, texto oscuro, flecha visible */
.gallery-filters__tab.active {
    background-color: #ffffff;
    border-color: #ffffff;
    color: #00181a;
}

.gallery-filters__tab.active:hover {
    background-color: #ffffff;
    color: #00181a;
}

.gallery-filters__tab.active .gallery-filters__tab-arrow {
    display: inline-block;
    margin-left: 12px;
    filter: none;
}

/* ---------------------------------------------------------------------------
   3. GRID DE IMÁGENES — Patrón zigzag con CSS Grid
   --------------------------------------------------------------------------- */

/* Grid único de toda la galería: patrón zigzag en ciclos de 8 imágenes y 3 filas
   Fila 1 (pos 1-3): [grande] [pequeña] [pequeña]
   Fila 2 (pos 4-6): [pequeña] [pequeña] [grande]
   Fila 3 (pos 7-8): [grande] [grande]  ← las dos del mismo tamaño
   Se logra con 4 columnas y span de 2 columnas para el grande.
   Las imágenes de todas las categorías van en el mismo grid para que el ciclo
   no se reinicie al cambiar de categoría (gallery.js filtra ocultando imágenes). */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-auto-flow: dense;
    gap: 32px;
    padding: 72px 64px 128px;
    max-width: 1920px;
    margin: 0 auto;
}

/* Ítems pequeños ocupan 1 columna */
.gallery-item--small {
    grid-column: span 1;
}

/* Ítems grandes ocupan 2 columnas */
.gallery-item--large {
    grid-column: span 2;
}

/* Ítem de video (Tour Virtual): "cover" clicable que abre el tour grande
   en #galleryVideoLightbox. Es un <button>, se resetean estilos nativos.
   La miniatura (thumbnail publico de Matterport) va de fondo, con una capa
   oscura encima para legibilidad del icono de play y el título. */
.gallery-item--video {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    width: 100%;
    margin: 0;
    padding: 0;
    border: none;
    background-color: #007e88;
    font: inherit;
    appearance: none;
    -webkit-appearance: none;
}

.gallery-item--video:focus-visible {
    outline: 2px solid #ffffff;
    outline-offset: -4px;
}

/* Miniatura del tour (thumbnail publico de Matterport) */
.gallery-item__video-cover {
    position: absolute;
    inset: 0;
    z-index: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s ease;
}

.gallery-item--video:hover .gallery-item__video-cover {
    transform: scale(1.02);
}

/* Capa oscura entre la miniatura y el contenido (icono + título) */
.gallery-item--video::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.15) 0%, rgba(0, 0, 0, 0.45) 100%);
    transition: background-color 0.3s ease;
}

.gallery-item--video:hover::before,
.gallery-item--video:focus-visible::before {
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.05) 0%, rgba(0, 0, 0, 0.3) 100%);
}

/* Círculo de play, dibujado en CSS puro */
.gallery-item__video-play {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.95);
    transition: transform 0.3s ease;
}

.gallery-item--video:hover .gallery-item__video-play {
    transform: scale(1.08);
}

.gallery-item__video-play::before {
    content: "";
    display: block;
    margin-left: 4px;
    border-style: solid;
    border-width: 12px 0 12px 20px;
    border-color: transparent transparent transparent #00A8B5;
}

.gallery-item__video-label {
    position: relative;
    z-index: 2;
    max-width: 80%;
    font-family: "Inter";
    font-size: 1.1875rem;
    font-weight: 700;
    line-height: 1.375rem;
    color: #ffffff;
    text-align: center;
}

/* ---------------------------------------------------------------------------
   3b. GRID — Última fila incompleta
   El ciclo 3·3·2 se repite tal cual, así que la última fila se queda a medias
   siempre que el total de imágenes visibles no cierre el ciclo. gallery.js
   marca lo que sobra con estas clases para que cubra las 4 columnas y no deje
   hueco. Los videos nunca se marcan: mantienen su tamaño fijo (media fila).
   --------------------------------------------------------------------------- */

/* Sobra 1 imagen sola en la última fila */
.gallery-item--fill-row {
    grid-column: 1 / -1;
}

/* Sobran 2 imágenes de una fila de 3: media fila cada una */
.gallery-item--fill-half {
    grid-column: span 2;
}

.gallery-item {
    overflow: hidden;
    height: 600px;
    cursor: pointer;
}

/* ---------------------------------------------------------------------------
   3c. GRID — Paginación "ver más"
   gallery.js oculta las imágenes que superan el lote visible de cada categoría
   y destapa el botón que revela el siguiente lote.
   --------------------------------------------------------------------------- */

.gallery-item--hidden {
    display: none;
}

/* Bloque del botón: ocupa una fila entera del grid, centrado */
.gallery-more {
    grid-column: 1 / -1;
    display: flex;
    justify-content: center;
}

/* Necesario porque el display: flex de arriba anula el hidden nativo */
.gallery-more[hidden] {
    display: none;
}

/* Hereda el botón global de son-sant-jordi.css (tamaño, padding, uppercase,
   radio, transición) igual que .instagram-block__loadmore, el "cargar más" del
   bloque de Instagram sobre este mismo fondo teal. Solo cambia el relleno:
   va en blanco con texto oscuro (como el tab activo de los filtros) porque
   texto blanco sobre el teal #00A8B5 se queda en 2,9:1 y WCAG AA exige 4,5:1
   para texto. */
.gallery-more__btn {
    border-color: #ffffff;
    background-color: #ffffff;
    color: #00181a;
}

.gallery-more__btn:hover {
    border-color: #ffffff;
    background-color: rgba(255, 255, 255, 0.82);
    color: #00181a;
}

.gallery-more__btn:focus-visible {
    outline: 2px solid #00181a;
    outline-offset: 2px;
}

.gallery-item__img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: opacity 0.3s ease, transform 0.4s ease;
}

.gallery-item:hover .gallery-item__img {
    opacity: 0.85;
    transform: scale(1.02);
}

/* ---------------------------------------------------------------------------
   4. LIGHTBOX
   --------------------------------------------------------------------------- */

.gallery-lightbox {
    position: fixed;
    inset: 0;
    z-index: 1050;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.9);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.gallery-lightbox.active {
    opacity: 1;
    visibility: visible;
}

/* Swiper ocupa todo el espacio disponible dejando margen para botones */
.gallery-lightbox .gallery-lightbox-swiper {
    width: 100%;
    height: 100%;
}

.gallery-lightbox .swiper-wrapper {
    align-items: center;
}

.gallery-lightbox .swiper-slide {
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-lightbox .swiper-slide img {
    max-width: 90vw;
    max-height: 85vh;
    object-fit: contain;
}

/* Botón cerrar — Círculo oscuro con X en CSS puro (patrón hamburger del header) */
.gallery-lightbox__close {
    position: absolute;
    top: 24px;
    right: 24px;
    z-index: 1060;
    width: 48px;
    height: 48px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.gallery-lightbox__close:hover {
    background: rgba(0, 0, 0, 0.7);
}

/* X interior: dos líneas blancas cruzadas ±45° */
.gallery-lightbox__close-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: block;
    width: 20px;
    height: 20px;
}

.gallery-lightbox__close-icon::before,
.gallery-lightbox__close-icon::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 2px;
    background-color: #ffffff;
    border-radius: 1px;
}

.gallery-lightbox__close-icon::before {
    transform: translate(-50%, -50%) rotate(45deg);
}

.gallery-lightbox__close-icon::after {
    transform: translate(-50%, -50%) rotate(-45deg);
}

/* Botones anterior / siguiente — Iconos SVG hero sin fondo propio */
.gallery-lightbox__prev,
.gallery-lightbox__next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1060;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    transition: opacity 0.3s ease;
}

.gallery-lightbox__prev {
    left: 24px;
}

.gallery-lightbox__next {
    right: 24px;
}

.gallery-lightbox__nav-icon {
    display: block;
    width: 64px;
    height: 64px;
}

.gallery-lightbox__prev:hover,
.gallery-lightbox__next:hover {
    opacity: 0.7;
}

/* Estado disabled (Swiper añade .swiper-button-disabled al contenedor) */
.gallery-lightbox__prev.swiper-button-disabled,
.gallery-lightbox__next.swiper-button-disabled {
    opacity: 0.3;
    pointer-events: none;
}

/* ---------------------------------------------------------------------------
   4b. VIDEO LIGHTBOX — Popup grande del Tour Virtual (Matterport)
   --------------------------------------------------------------------------- */

.gallery-video-lightbox {
    position: fixed;
    inset: 0;
    z-index: 1050;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.9);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.gallery-video-lightbox.active {
    opacity: 1;
    visibility: visible;
}

.gallery-video-lightbox__content {
    position: relative;
    width: 90vw;
    max-width: 1400px;
    aspect-ratio: 16 / 9;
    max-height: 85vh;
}

.gallery-video-lightbox__frame {
    width: 100%;
    height: 100%;
}

.gallery-video-lightbox__iframe {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
}

/* Botón cerrar — mismo patrón que gallery-lightbox__close */
.gallery-video-lightbox__close {
    position: absolute;
    top: 24px;
    right: 24px;
    z-index: 1060;
    width: 48px;
    height: 48px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.gallery-video-lightbox__close:hover {
    background: rgba(0, 0, 0, 0.7);
}

.gallery-video-lightbox__close-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: block;
    width: 20px;
    height: 20px;
}

.gallery-video-lightbox__close-icon::before,
.gallery-video-lightbox__close-icon::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 2px;
    background-color: #ffffff;
    border-radius: 1px;
}

.gallery-video-lightbox__close-icon::before {
    transform: translate(-50%, -50%) rotate(45deg);
}

.gallery-video-lightbox__close-icon::after {
    transform: translate(-50%, -50%) rotate(-45deg);
}

/* ---------------------------------------------------------------------------
   5. BODY NO-SCROLL
   --------------------------------------------------------------------------- */

body.no-scroll {
    overflow: hidden;
}

/* ==========================================================================
   DESKTOP GRANDE (>1920px)
   ========================================================================== */

@media (min-width: 1921px) {

    .gallery-hero {
        padding: 72px 80px 72px;
    }

    .gallery-hero__title {
        font-size: 6.25rem;
        line-height: 7.5rem;
    }

    .gallery-hero__description {
        max-width: 720px;
    }

    .gallery-grid {
        padding: 80px 80px 160px;
    }

    .gallery-item {
        height: 700px;
    }

}

/* ==========================================================================
   RANGO INTERMEDIO (1366px - 1920px) — Ajustes tipográficos
   ========================================================================== */

@media (min-width: 1366px) and (max-width: 1920px) {

    .gallery-hero__title {
        font-size: 5rem;
        line-height: 6.125rem;
    }

}

/* ==========================================================================
   RANGO INTERMEDIO (992px - 1365px)
   ========================================================================== */

@media (min-width: 992px) and (max-width: 1365px) {

    #gallerySec {
        padding-top: 120px;
    }

    .gallery-hero {
        padding: 40px 40px 40px;
    }

    .gallery-hero__title {
        font-size: 4.375rem;
        line-height: 5rem;
        margin-bottom: 20px;
    }

    .gallery-hero__subtitle {
        font-size: 1.0625rem;
        margin-bottom: 36px;
    }

    .gallery-hero__description {
        font-size: 1rem;
        max-width: 580px;
    }

    .gallery-filters__tab {
        font-size: 1.0625rem;
        padding: 10px;
    }

    .gallery-grid {
        padding: 56px 40px 100px;
        gap: 24px;
    }

    .gallery-item {
        height: 450px;
    }

}

/* ==========================================================================
   TABLET Y MÓVIL (<992px)
   ========================================================================== */

@media (max-width: 991px) {

    #gallerySec {
        padding-top: 100px;
    }

    /* Ocultar decoradores en mobile */
    #gallerySec .gallery-wrapper__decorator {
        display: none;
    }

    .gallery-hero {
        padding: 32px 24px 32px;
    }

    .gallery-hero__title {
        font-size: 2.5rem;
        line-height: 3rem;
        margin-bottom: 16px;
    }

    .gallery-hero__subtitle {
        font-size: 1rem;
        margin-bottom: 24px;
    }

    .gallery-hero__description {
        font-size: 0.9375rem;
        max-width: 100%;
    }

    /* Filtros: wrap en filas en mobile */
    .gallery-filters {
        justify-content: center;
    }

    .gallery-filters__inner {
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
        padding: 12px;
    }

    .gallery-filters__break {
        margin-bottom: -8px;
    }

    .gallery-filters__tab {
        font-size: 0.9375rem;
        padding: 10px 12px;
        white-space: nowrap;
    }

    /* Grid: 1 columna en móvil, sin patrón zigzag */
    .gallery-grid {
        display: flex;
        flex-direction: column;
        gap: 16px;
        padding: 40px 16px 64px;
    }

    .gallery-item {
        height: auto;
        aspect-ratio: 4 / 3;
    }

    /* Botón "ver más" a todo el ancho, como el resto de tarjetas en 1 columna */
    .gallery-more__btn {
        width: 100%;
    }

    /* Lightbox: botones adaptados a pantallas pequeñas */
    .gallery-lightbox__close,
    .gallery-video-lightbox__close {
        top: 16px;
        right: 16px;
    }

    .gallery-video-lightbox__content {
        width: 100vw;
        max-height: 100vh;
        aspect-ratio: auto;
        height: 70vh;
    }

    .gallery-lightbox__nav-icon {
        width: 48px;
        height: 48px;
    }

    .gallery-lightbox__prev,
    .gallery-lightbox__next {
        top: auto;
        bottom: 32px;
        transform: none;
    }

    .gallery-lightbox__prev {
        left: calc(50% - 60px);
    }

    .gallery-lightbox__next {
        right: calc(50% - 60px);
    }

    .gallery-lightbox .swiper-slide img {
        max-width: 95vw;
        max-height: 80vh;
    }

}

/* ==========================================================================
   MÓVIL PEQUEÑO (<576px)
   ========================================================================== */

@media (max-width: 575px) {

    /* Header más pequeño en móvil: padding 10px 15px + logo 120px */
    #gallerySec {
        padding-top: 72px;
    }

    .gallery-hero {
        padding: 24px 16px 24px;
    }

    .gallery-hero__title {
        font-size: 2.1875rem;
        line-height: 2.5rem;
    }

    .gallery-hero__subtitle {
        font-size: 0.9375rem;
    }

    .gallery-item {
        aspect-ratio: 3 / 2;
    }

}

/* ==========================================================================
   ACCESIBILIDAD — Reducción de movimiento
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {

    .gallery-item__img {
        transition: none;
    }

    .gallery-lightbox {
        transition: none;
    }

    .gallery-filters__tab {
        transition: none;
    }

    .gallery-more__btn {
        transition: none;
    }

    .gallery-lightbox__close,
    .gallery-lightbox__prev,
    .gallery-lightbox__next {
        transition: none;
    }

}
