@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');

/* Reset e Configurações Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Poppins', sans-serif;
    background-color: #f8f8f8;
    color: #222;
}

/* Cabeçalho da Galeria */
.gallery-header {
    text-align: center;
    padding: 50px 20px;
    border-bottom: 1px solid #e7e7e7;
    margin-bottom: 50px;
}

.gallery-header h1 {
    font-size: 3.5rem;
    font-weight: 600;
    letter-spacing: 8px;
    margin-bottom: 15px;
    color: #2c3e50;
    text-transform: uppercase;
}

.gallery-header p {
    font-size: 1.1rem;
    font-weight: 300;
    color: #7f8c8d;
    max-width: 600px;
    margin: 0 auto;
    letter-spacing: 1px;
}

/* Container Principal da Galeria */
.gallery-container {
    padding: 0 40px 80px;
    max-width: 1600px;
    margin: 0 auto;
}

/* Layout Masonry */
.gallery {
    column-count: 3;
    column-gap: 30px;
}

.gallery-item {
    display: inline-block;
    width: 100%;
    margin-bottom: 30px;
    break-inside: avoid;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    transition: transform 0.3s ease, box-shadow 0.3s ease, opacity 0.3s ease;
    cursor: pointer;
    overflow: hidden;
    /* Performance optimizations */
    will-change: transform;
    transform: translateZ(0);
    contain: layout style paint;
}

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

.gallery-item img {
    width: 100%;
    height: auto;
    display: block;
    transition: opacity 0.3s ease, transform 0.2s ease;
    /* Performance optimizations */
    will-change: opacity;
    backface-visibility: hidden;
}

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

.gallery-item .details {
    padding: 18px 22px;
    border-top: 1px solid #f0f0f0;
}

.gallery-item h3 {
    font-size: 1.1rem;
    font-weight: 500;
    color: #34495e;
}

.gallery-item p {
    font-size: 0.9rem;
    color: #95a5a6;
    font-style: italic;
    margin-top: 5px;
}

/* === OTIMIZAÇÕES DE LOADING === */

/* Loading Placeholder Inicial */
.loading-placeholder {
    text-align: center;
    padding: 3rem 2rem;
    color: #666;
    font-size: 1.1rem;
    grid-column: 1 / -1;
}

.skeleton-loader {
    width: 100%;
    height: 200px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton 1.5s infinite;
    border-radius: 8px;
    margin-bottom: 1rem;
}

@keyframes skeleton {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Estados de Loading das Gallery Items */
.gallery-item.loading {
    opacity: 0.7;
    transform: translateY(20px);
}

.gallery-item.loaded {
    opacity: 1;
    transform: translateY(0);
}

/* Lazy Loading de Imagens */
.gallery-item img[data-src] {
    opacity: 0;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton 1.5s infinite;
}

.gallery-item img.lazy-image {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.gallery-item img.loaded {
    opacity: 1;
    animation: none;
}

.gallery-item img.loading {
    opacity: 0.6;
}

/* Load Trigger (invisível) */
.load-trigger {
    height: 1px;
    width: 100%;
    background: transparent;
    grid-column: 1 / -1;
}

/* Error State para Imagens */
.gallery-item img.error {
    background: #f5f5f5;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 0.9rem;
    min-height: 200px;
    position: relative;
}

.gallery-item img.error::after {
    content: "Imagem não disponível";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* Error Placeholder */
.error-placeholder {
    text-align: center;
    padding: 3rem 2rem;
    color: #666;
    grid-column: 1 / -1;
}

.error-placeholder h3 {
    color: #e74c3c;
    margin-bottom: 1rem;
}

.error-placeholder button {
    background: #333; 
    color: white; 
    border: none; 
    padding: 10px 20px; 
    border-radius: 5px; 
    cursor: pointer;
    margin-top: 10px;
    font-family: inherit;
    transition: background 0.3s ease;
}

.error-placeholder button:hover {
    background: #555;
}

/* === ESTILOS DO MODAL CORRIGIDOS === */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(25, 25, 25, 0.94);
    backdrop-filter: blur(8px);
    animation: fadeIn 0.3s ease;
    
    /* CENTRALIZAÇÃO CORRIGIDA */
    align-items: center;
    justify-content: center;
    padding: 40px;
}

/* Estado ativo do modal */
.modal.show {
    display: flex !important;
}

.modal-container {
    display: flex;
    flex-direction: row;
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.4);
    width: 100%;
    max-width: 1200px;
    height: 85vh;
    max-height: 700px;
    overflow: hidden;
    animation: zoomIn 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    
    /* GARANTIA DE CENTRALIZAÇÃO */
    position: relative;
    margin: auto;
}

.modal-image-wrapper {
    flex: 0 0 65%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f0f0f0;
    padding: 20px;
}

.modal-content {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
}

.modal-info-wrapper {
    flex: 0 0 35%;
    padding: 35px 30px;
    overflow-y: auto;
    border-left: 1px solid #e9ecef;
    background-color: #f8f9fa;
}

/* Estilos do texto dentro do popup */
#modalDescription h4 {
    font-size: 1.7rem;
    font-weight: 600;
    color: #2c3e50;
    line-height: 1.2;
    margin-bottom: 8px;
}

#modalDescription strong {
    font-size: 1rem;
    color: #888;
    display: block;
    font-weight: 400;
    margin-top: 5px;
}

#modalDescription hr {
    border: 0;
    height: 1px;
    background-color: #dee2e6;
    margin: 20px 0;
}

#modalDescription p {
    font-size: 0.9rem;
    line-height: 1.65;
    color: #495057;
    margin-bottom: 15px;
}

#modalDescription em {
    font-style: italic;
    color: #6c757d;
}

.artist-signature {
    font-style: italic;
    color: #6c757d !important;
    font-weight: 500;
    margin-top: 20px;
    border-top: 1px solid #e9ecef;
    padding-top: 15px;
}

.close-button {
    position: fixed;
    top: 20px;
    right: 25px;
    color: #ffffff;
    font-size: 45px;
    font-weight: 300;
    cursor: pointer;
    transition: transform 0.2s ease, opacity 0.2s ease;
    opacity: 0.8;
    z-index: 1001;
    user-select: none;
}

.close-button:hover {
    transform: scale(1.1);
    opacity: 1;
}

/* Fix para scroll do body quando modal aberto */
body.modal-open {
    overflow: hidden;

}

/* === ANIMAÇÕES === */
@keyframes fadeIn { 
    from { 
        opacity: 0; 
    } 
    to { 
        opacity: 1; 
    } 
}

@keyframes zoomIn { 
    from { 
        opacity: 0; 
        transform: scale(0.9); 
    } 
    to { 
        opacity: 1; 
        transform: scale(1); 
    } 
}

/* Smooth scroll para âncoras */
html {
    scroll-behavior: smooth;
}

/* Preload hint para navegadores */
.gallery-item img[loading="lazy"] {
    content-visibility: auto;
}

/* === RESPONSIVIDADE CORRIGIDA === */
@media (max-width: 1024px) {
    .modal {
        padding: 20px;
    }
    
    .modal-container {
        flex-direction: column;
        height: auto;
        max-height: 90vh;
        width: 95%;
        max-width: 800px;
    }
    
    .modal-image-wrapper {
        flex: 0 1 auto;
        min-height: 300px;
        max-height: 50vh;
    }
    
    .modal-info-wrapper {
        flex: 0 1 auto;
        max-height: 40vh;
        border-left: none;
        border-top: 1px solid #e9ecef;
        padding: 25px 20px;
    }
}

@media (max-width: 768px) {
    .gallery { 
        column-count: 2; 
    }
    .gallery-container { 
        padding: 0 20px 40px; 
    }
    .loading-placeholder {
        padding: 2rem 1rem;
    }
    .skeleton-loader {
        height: 150px;
    }
    .error-placeholder {
        padding: 2rem 1rem;
    }
    
    .modal {
        padding: 15px;
    }
    
    .modal-container {
        width: 98%;
        height: auto;
        max-height: 95vh;
    }
    
    .modal-image-wrapper {
        min-height: 250px;
        max-height: 45vh;
        padding: 15px;
    }
    
    .modal-info-wrapper {
        padding: 20px 15px;
        max-height: 45vh;
    }
    
    #modalDescription h4 {
        font-size: 1.4rem;
    }
    
    #modalDescription p {
        font-size: 0.85rem;
        line-height: 1.6;
    }
    
    .close-button {
        top: 15px;
        right: 20px;
        font-size: 35px;
    }
}

@media (max-width: 500px) {
    .gallery { 
        column-count: 1; 
    }
    .gallery-header h1 {
        font-size: 2.5rem;
        letter-spacing: 4px;
    }
    
    .modal {
        padding: 10px;
    }
    
    .modal-container {
        width: 100%;
        height: auto;
        max-height: 98vh;
        border-radius: 0;
    }
    
    .modal-image-wrapper {
        min-height: 200px;
        max-height: 40vh;
        padding: 10px;
    }
    
    .modal-info-wrapper {
        padding: 15px 12px;
        max-height: 50vh;
    }
    
    #modalDescription h4 {
        font-size: 1.2rem;
    }
    
    #modalDescription p {
        font-size: 0.8rem;
    }
    
    .close-button {
        top: 10px;
        right: 15px;
        font-size: 30px;
    }
}

/* === PERFORMANCE OPTIMIZATIONS === */
@media (prefers-reduced-motion: reduce) {
    .gallery-item,
    .gallery-item img,
    .modal,
    .modal-container {
        transition: none;
        animation: none;
    }
    
    .skeleton-loader {
        animation: none;
        background: #f0f0f0;
    }
}

/* Otimização para telas de alta densidade */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .gallery-item img {
        image-rendering: -webkit-optimize-contrast;
    }
}