.header-gallery {
     background: url(../img/headers/conduct-header.webp) center / cover no-repeat;
    height: 65vh;
    width: 100%;
    display: flex;
    align-items: center;
    flex-direction: column;
    justify-content: center;
}

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(250px, 100%), 1fr));
    grid-auto-rows: minmax(150px, auto);
    gap: 15px;
    padding: 20px;
    margin: 0 auto;
    max-width: 1200px;
    width: 100%;
    box-sizing: border-box;
    grid-auto-flow: dense;
    overflow: hidden; /* Prevenir overflow */
}

.gallery-item {
    position: relative;
    overflow: hidden;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    cursor: pointer;
}

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

.gallery-item img {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    min-width: 0;
    min-height: 0;
    object-fit: cover;
    transition: transform 0.3s ease;
    display: block; /* Eliminar espacios extra */
}

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

/* Diferentes tamaños - optimizados para menos espacios vacíos */
.gallery-item.large {
    grid-column: span 2;
    grid-row: span 2;
}

.gallery-item.wide {
    grid-column: span 2;
    grid-row: span 1;
}

.gallery-item.tall {
    grid-column: span 1;
    grid-row: span 2;
}

/* Elementos normales con altura mínima */
.gallery-item {
    min-height: 150px;
}

/* Breakpoint para pantallas medianas (tablets grandes) */
@media (max-width: 1024px) {
    .gallery {
        grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr));
        gap: 12px;
        padding: 18px;
    }
}

/* Breakpoint para tablets */
@media (max-width: 768px) {
    .gallery {
        grid-template-columns: repeat(auto-fill, minmax(min(200px, calc(50% - 10px)), 1fr));
        grid-auto-rows: minmax(120px, auto);
        gap: 10px;
        padding: 15px;
        margin: 0 auto;
    }
    
    .gallery-item {
        min-height: 120px;
    }
    
    .gallery-item.large {
        grid-column: span 2;
        grid-row: span 1;
    }
    
    .gallery-item.wide {
        grid-column: span 2;
    }
    
    .gallery-item.tall {
        grid-row: span 1;
    }
}

/* Breakpoint para móviles grandes */
@media (max-width: 480px) {
    .gallery {
        grid-template-columns: repeat(auto-fill, minmax(min(180px, calc(50% - 8px)), 1fr));
        grid-auto-rows: minmax(100px, auto);
        gap: 8px;
        padding: 12px;
        margin: 0;
    }
    
    .gallery-item {
        min-height: 100px;
    }
    
    .gallery-item.large,
    .gallery-item.wide {
        grid-column: span 2;
        grid-row: span 1;
    }
    
    .gallery-item.tall {
        grid-column: span 1;
        grid-row: span 1;
    }
}

/* Breakpoint para móviles muy pequeños */
@media (max-width: 360px) {
    .gallery {
        grid-template-columns: repeat(auto-fill, minmax(min(150px, calc(50% - 6px)), 1fr));
        grid-auto-rows: minmax(80px, auto);
        gap: 6px;
        padding: 10px;
        margin: 0;
    }
    
    .gallery-item {
        min-height: 80px;
    }
    
    .gallery-item.large,
    .gallery-item.wide,
    .gallery-item.tall {
        grid-column: span 1;
        grid-row: span 1;
    }
}

/* Prevención global de scroll horizontal */
* {
    box-sizing: border-box;
}

.gallery-container {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

/* Asegurar que el body no tenga overflow horizontal */
body {
    overflow-x: hidden;
}

@media (max-width: 480px) {
    .gallery {
        grid-template-columns: 1fr;
        grid-auto-rows: 200px;
        padding: 10px;
    }
    
    .gallery-item.large,
    .gallery-item.wide,
    .gallery-item.tall {
        grid-column: span 1;
        grid-row: span 1;
    }
}

/* Lightbox Styles */
.lightbox {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(5px);
}

.lightbox.active {
    display: flex !important;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.lightbox-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    animation: scaleIn 0.3s ease;
}

.close-btn {
    position: absolute;
    top: -40px;
    right: 0;
    color: white;
    font-size: 35px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1001;
    transition: color 0.3s ease;
    user-select: none;
}

.close-btn:hover {
    color: #ff6b6b;
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: calc(100% + 120px);
    display: flex;
    justify-content: space-between;
    pointer-events: none;
}

.nav-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 30px;
    padding: 15px 20px;
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.3s ease;
    pointer-events: auto;
    user-select: none;
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.nav-btn:active {
    transform: scale(0.95);
}

.lightbox-counter {
    position: absolute;
    bottom: -40px;
    left: 50%;
    transform: translateX(-50%);
    color: white;
    font-size: 16px;
    background: rgba(0, 0, 0, 0.5);
    padding: 8px 16px;
    border-radius: 20px;
    backdrop-filter: blur(10px);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes scaleIn {
    from { 
        transform: scale(0.8);
        opacity: 0;
    }
    to { 
        transform: scale(1);
        opacity: 1;
    }
}

@media (max-width: 768px) {
    .close-btn {
        top: -50px;
        font-size: 30px;
    }
    
    .nav-btn {
        font-size: 25px;
        padding: 12px 16px;
    }
    
    .lightbox-counter {
        bottom: -50px;
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .lightbox-content {
        max-width: 95%;
        max-height: 85%;
    }
    
    .lightbox-nav {
        width: calc(100% + 80px);
    }
    
    .nav-btn {
        font-size: 20px;
        padding: 10px 12px;
    }
}

/* Tamaños uniformes por orientación en el lightbox */
/* Horizontales: mismo ancho relativo, altura ajustada */
.lightbox.landscape .lightbox-image {
    width: 85vw;
    max-width: 1200px;
    height: auto;
    max-height: 80vh;
}

/* Verticales: misma altura relativa, ancho ajustado */
.lightbox.portrait .lightbox-image {
    height: 85vh;
    max-height: 1000px;
    width: auto;
    max-width: 70vw;
}

/* Cuadradas: tamaño intermedio consistente */
.lightbox.square .lightbox-image {
    width: 75vw;
    max-width: 900px;
    height: auto;
    max-height: 75vh;
}
