/* SOLUCIÓN DEFINITIVA CON CSS GRID - SIN MASONRY */
/* Reemplaza TODO el CSS anterior con este */

/* Estilos base para la galería */
.acf-gallery-masonry {
    display: grid;
    margin: 20px 0;
    padding: 0;
    gap: 15px;
    width: 100%;
    box-sizing: border-box;
}

/* Clase para ancho completo de 1400px */
.acf-gallery-masonry.acf-gallery-fullwidth {
    width: 1400px !important;
    max-width: 1400px !important;
    margin-left: calc(50% - 700px) !important;
    margin-right: calc(50% - 700px) !important;
    position: relative;
}

/* Fallback para pantallas menores a 1400px */
@media (max-width: 1440px) {
    .acf-gallery-masonry.acf-gallery-fullwidth {
        width: calc(100vw - 40px) !important;
        margin-left: calc(50% - 50vw + 20px) !important;
        margin-right: calc(50% - 50vw + 20px) !important;
    }
}

/* GRID TEMPLATE COLUMNS - AQUÍ ESTÁ LA CLAVE */
/* Para pantallas grandes (1200px+) */
@media (min-width: 1200px) {
    .acf-gallery-masonry[data-columns="2"] {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .acf-gallery-masonry[data-columns="3"] {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .acf-gallery-masonry[data-columns="4"] {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .acf-gallery-masonry[data-columns="5"] {
        grid-template-columns: repeat(5, 1fr);
    }
    
    .acf-gallery-masonry[data-columns="6"] {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* Para tablets */
@media (min-width: 768px) and (max-width: 1199px) {
    .acf-gallery-masonry[data-columns="2"] {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .acf-gallery-masonry[data-columns="3"],
    .acf-gallery-masonry[data-columns="4"],
    .acf-gallery-masonry[data-columns="5"],
    .acf-gallery-masonry[data-columns="6"] {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Para móviles grandes */
@media (min-width: 481px) and (max-width: 767px) {
    .acf-gallery-masonry {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Para móviles pequeños */
@media (max-width: 480px) {
    .acf-gallery-masonry {
        grid-template-columns: 1fr;
    }
}

/* Estilos para items individuales */
.gallery-item {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    display: block;
    margin: 0; /* Importante: sin márgenes porque grid maneja el spacing */
}

.gallery-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.gallery-item a {
    display: block;
    position: relative;
    text-decoration: none;
    width: 100%;
    height: 100%;
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover; /* Mantiene proporciones y llena el contenedor */
    display: block;
    transition: transform 0.3s ease;
}

.gallery-item:hover img {
    transform: scale(1.05);
}

.gallery-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.gallery-item:hover .gallery-overlay {
    opacity: 1;
}

.gallery-icon {
    color: white;
    font-size: 24px;
    background: rgba(255, 255, 255, 0.2);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
}

/* EFECTO MASONRY CON GRID */
/* Esto simula el efecto masonry manteniendo columnas fijas */
.acf-gallery-masonry {
    grid-auto-rows: 200px; /* Altura base */
}

/* Variaciones de altura para efecto masonry */
.gallery-item:nth-child(3n+1) {
    grid-row: span 1;
}

.gallery-item:nth-child(3n+2) {
    grid-row: span 2;
}

.gallery-item:nth-child(3n+3) {
    grid-row: span 1;
}

/* Ajuste para 4 columnas */
.acf-gallery-masonry[data-columns="4"] .gallery-item:nth-child(4n+1) {
    grid-row: span 1;
}

.acf-gallery-masonry[data-columns="4"] .gallery-item:nth-child(4n+2) {
    grid-row: span 2;
}

.acf-gallery-masonry[data-columns="4"] .gallery-item:nth-child(4n+3) {
    grid-row: span 1;
}

.acf-gallery-masonry[data-columns="4"] .gallery-item:nth-child(4n+4) {
    grid-row: span 2;
}

/* Personalización del Thickbox */
#TB_window {
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

#TB_caption {
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 10px 15px;
    border-radius: 0 0 8px 8px;
    font-size: 14px;
}

#TB_closeWindowButton {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    right: 10px;
    top: 10px;
}

/* Efectos de carga */
.gallery-item {
    opacity: 0;
    animation: fadeInItem 0.5s ease forwards;
}

@keyframes fadeInItem {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Staggered animation */
.gallery-item:nth-child(1) { animation-delay: 0.1s; }
.gallery-item:nth-child(2) { animation-delay: 0.2s; }
.gallery-item:nth-child(3) { animation-delay: 0.3s; }
.gallery-item:nth-child(4) { animation-delay: 0.4s; }
.gallery-item:nth-child(5) { animation-delay: 0.5s; }
.gallery-item:nth-child(6) { animation-delay: 0.6s; }
.gallery-item:nth-child(n+7) { animation-delay: 0.7s; }

/* Debug - descomenta para ver los límites */
/*
.acf-gallery-masonry.acf-gallery-fullwidth {
    border: 2px solid red !important;
    background: rgba(255, 0, 0, 0.1) !important;
}
.gallery-item {
    border: 1px solid blue !important;
}
*/

/* OPCIÓN ALTERNATIVA: GRID SIN EFECTO MASONRY */
/* Si prefieres que todas las filas tengan la misma altura, descomenta esto: */
/*
.acf-gallery-masonry {
    grid-auto-rows: 250px;
}
.gallery-item {
    grid-row: span 1 !important;
}
*/