/* Auto Masonry Gallery Styles */

.auto-masonry-gallery {
    margin: 2rem 0;
    padding: 0;
    width: 100%;
    display: grid;
    gap: 15px;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    grid-auto-rows: min-content;
}

.masonry-item {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: #1e1f23;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    break-inside: avoid;
    page-break-inside: avoid;
}

.masonry-item:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
    z-index: 10;
}

.masonry-item.loading {
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.masonry-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.9rem;
    text-align: center;
}

.masonry-placeholder.error {
    color: #ff6b35;
}

.masonry-image {
    width: 100% !important;
    height: auto !important;
    display: block !important;
    object-fit: cover;
    transition: all 0.3s ease;
    filter: brightness(0.9);
}

.masonry-item:hover .masonry-image {
    filter: brightness(1) contrast(1.05);
}

.masonry-image.fade-in {
    animation: masonryFadeIn 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes masonryFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Loading spinner */
.loading-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-top: 2px solid rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Lightbox styles (enhanced) */
.lightbox-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(10px);
}

.lightbox-modal.active {
    display: flex;
    opacity: 1;
    align-items: center;
    justify-content: center;
}

.lightbox-content {
    position: relative;
    max-width: 95vw;
    max-height: 95vh;
    text-align: center;
}

.lightbox-image {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.8);
    animation: lightboxZoomIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes lightboxZoomIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.lightbox-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    color: white;
    font-size: 1.1rem;
}

.lightbox-loading .loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top: 3px solid white;
    margin-bottom: 15px;
}

.lightbox-close, .lightbox-nav {
    position: absolute;
    color: white;
    cursor: pointer;
    z-index: 10001;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    user-select: none;
    backdrop-filter: blur(10px);
}

.lightbox-close {
    top: 20px;
    right: 30px;
    width: 50px;
    height: 50px;
    font-size: 2rem;
}

.lightbox-nav {
    top: 50%;
    transform: translateY(-50%);
    width: 60px;
    height: 60px;
    font-size: 2rem;
    font-weight: bold;
}

.lightbox-prev { left: 30px; }
.lightbox-next { right: 30px; }

.lightbox-close:hover, .lightbox-nav:hover {
    background: rgba(0, 0, 0, 0.8);
    transform: scale(1.1);
}

.lightbox-nav:hover {
    transform: translateY(-50%) scale(1.1);
}

.lightbox-info {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: white;
    background: rgba(0, 0, 0, 0.7);
    padding: 12px 24px;
    border-radius: 25px;
    font-size: 0.95rem;
    backdrop-filter: blur(10px);
    white-space: nowrap;
}

/* Responsive Design */
@media screen and (max-width: 1200px) {
    .auto-masonry-gallery {
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
        gap: 12px;
    }
}

@media screen and (max-width: 768px) {
    .auto-masonry-gallery {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
        gap: 10px;
        margin: 1.5rem 0;
    }
    
    .masonry-item {
        border-radius: 6px;
    }
    
    .masonry-item:hover {
        transform: translateY(-2px) scale(1.01);
    }
    
    .lightbox-close {
        top: 15px;
        right: 15px;
        width: 45px;
        height: 45px;
        font-size: 1.8rem;
    }
    
    .lightbox-nav {
        width: 50px;
        height: 50px;
        font-size: 1.6rem;
    }
    
    .lightbox-prev { left: 15px; }
    .lightbox-next { right: 15px; }
    
    .lightbox-info {
        bottom: 15px;
        padding: 10px 20px;
        font-size: 0.85rem;
    }
}

@media screen and (max-width: 480px) {
    .auto-masonry-gallery {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 8px;
    }
    
    .masonry-item {
        border-radius: 4px;
    }
    
    .lightbox-close {
        width: 40px;
        height: 40px;
        font-size: 1.5rem;
        top: 10px;
        right: 10px;
    }
    
    .lightbox-nav {
        width: 45px;
        height: 45px;
        font-size: 1.4rem;
    }
    
    .lightbox-prev { left: 10px; }
    .lightbox-next { right: 10px; }
    
    .lightbox-info {
        bottom: 10px;
        padding: 8px 16px;
        font-size: 0.8rem;
    }
}

/* Support for browsers without CSS Grid masonry */
@supports not (grid-auto-rows: masonry) {
    .auto-masonry-gallery {
        display: block;
        column-count: auto;
        column-width: 300px;
        column-gap: 15px;
    }
    
    .masonry-item {
        display: inline-block;
        width: 100%;
        margin-bottom: 15px;
    }
}

@media screen and (max-width: 768px) {
    @supports not (grid-auto-rows: masonry) {
        .auto-masonry-gallery {
            column-width: 250px;
            column-gap: 10px;
        }
        
        .masonry-item {
            margin-bottom: 10px;
        }
    }
}

/* Enhance image quality on hover */
.masonry-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.03), transparent);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 1;
}

.masonry-item:hover::before {
    opacity: 1;
}

/* Loading shimmer effect */
.masonry-item.loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.05),
        transparent
    );
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}