/* Contenedor de la Galería */
.jm-gallery-container {
    padding: 4rem 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

.jm-gallery-grid {
    display: grid;
    /* Cuadrícula responsiva automática */
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

/* 1. Optimización de renderizado */
.jm-gallery-item {
    position: relative;
    height: 250px;
    border-radius: 15px;
    overflow: hidden;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
    background-color: #f0f0f0;

    /* PROPIEDADES CLAVE PARA EL LAG */
    content-visibility: auto; /* Solo renderiza si está cerca de verse */
    contain-intrinsic-size: 250px; /* Reserva el espacio de 250px de alto */
    
    will-change: transform, opacity; /* Prepara a la tarjeta gráfica */
    backface-visibility: hidden;
    /* Para el efecto de revelado que añadiremos con JS */
    opacity: 0;
    transform: translateY(30px);
    transition: all 0.6s ease-out;
}

/* Clase que activaremos con JS al hacer scroll */
.jm-gallery-item.reveal {
    opacity: 1;
    transform: translateY(0);
}

.jm-gallery-item img, 
.jm-gallery-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    aspect-ratio: 1 / 1; /* Evita que la página "salte" al cargar */
    transition: transform 0.5s ease;
    display: block;
}

/* Efecto al pasar el ratón */
.jm-gallery-item:hover img,
.jm-gallery-item:hover video {
    transform: scale(1.1);
}

.jm-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    color: white;
    font-size: 2rem;
}

.jm-gallery-item:hover .jm-overlay {
    opacity: 1;
}

/* --- ESTILOS DEL MODAL (Lightbox) --- */
.jm-modal {
    display: none; 
    position: fixed;
    z-index: 9999;
    left: 0; top: 0;
    width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.9);
    backdrop-filter: blur(5px);
    padding: 20px;
    align-items: center;
    justify-content: center;
}

.jm-modal-content {
    max-width: 90%;
    max-height: 80vh;
    margin: auto;
    display: block;
}

.jm-modal-content img, 
.jm-modal-content video {
    width: 100%;
    height: auto;
    max-height: 80vh;
    border-radius: 10px;
}

.jm-close {
    position: absolute;
    top: 20px; right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
}

/* Responsive para móvil */
@media (max-width: 600px) {
    .jm-gallery-grid {
        grid-template-columns: 1fr; /* Una columna en móviles */
    }
}