/**
 * ===================================================
 * GALLERY PERFORMANCE CSS - Otimizações Visuais
 * 
 * Estilos para:
 * - Skeleton loading (placeholders)
 * - Barra de progresso
 * - Animações de carregamento
 * - Loading lazy de imagens
 * 
 * Criado: 23/12/2025
 * ===================================================
 */

/* ==========================================
   SKELETON LOADING - Placeholder animado
   ========================================== */

.skeleton-loading {
    background: linear-gradient(
        90deg,
        #f0f0f0 25%,
        #e0e0e0 50%,
        #f0f0f0 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
}

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

/* Imagem carregando */
.gallery-photo-card img.loading {
    opacity: 0.5;
    filter: blur(5px);
    transition: opacity 0.3s, filter 0.3s;
}

/* Imagem carregada */
.gallery-photo-card img.loaded {
    opacity: 1;
    filter: blur(0);
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.98);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Imagem com erro */
.gallery-photo-card img.error {
    opacity: 0.3;
    filter: grayscale(100%);
}

/* ==========================================
   BARRA DE PROGRESSO
   ========================================== */

.gallery-progress-container {
    width: 100%;
    max-width: 400px;
    height: 6px;
    background: #e0e0e0;
    overflow: hidden;
    border-radius: 3px;
    margin: 15px auto 5px;
}

.gallery-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #fd0000, #ff6b6b);
    transition: width 0.3s ease-out;
    border-radius: 3px;
}

.gallery-progress-text {
    text-align: center;
    font-size: 13px;
    color: #666;
    padding: 5px 0 10px;
    font-weight: 500;
}

/* ==========================================
   INDICADOR DE LOADING (fim da galeria)
   ========================================== */

.gallery-load-more {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px 20px;
    text-align: center;
}

/* Dots animation */
.loading-dots {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.loading-dots span {
    width: 10px;
    height: 10px;
    background: #fd0000;
    border-radius: 50%;
    animation: dots-bounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes dots-bounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.loading-text {
    color: #666;
    font-size: 14px;
}

/* ==========================================
   ERRO DE CARREGAMENTO
   ========================================== */

.load-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 20px;
    background: #fff3f3;
    border-radius: 8px;
    border: 1px solid #ffcdd2;
}

.error-icon {
    font-size: 24px;
}

.error-text {
    color: #c62828;
    font-size: 14px;
}

.retry-btn {
    background: #fd0000;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s;
}

.retry-btn:hover {
    background: #d50000;
}

/* ==========================================
   PLACEHOLDER DE FOTO (antes de carregar)
   ========================================== */

.gallery-photo-card {
    position: relative;
    overflow: hidden;
    background: #f5f5f5;
    min-height: 150px;
}

.gallery-photo-card::before {
    content: '';
    display: block;
    padding-top: 66.67%; /* Proporção 3:2 (480/720) */
}

.gallery-photo-card img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ==========================================
   OTIMIZAÇÕES MOBILE
   ========================================== */

@media (max-width: 768px) {
    .gallery-progress-container {
        position: fixed;
        top: 0;
        border-radius: 0;
        height: 3px;
    }
    
    .gallery-progress-text {
        font-size: 12px;
        padding: 8px 10px 12px;
        margin-top: 3px;
    }
    
    .gallery-load-more {
        padding: 20px 15px;
    }
    
    .loading-dots span {
        width: 8px;
        height: 8px;
    }
    
    /* Cards menores no mobile */
    .gallery-photo-card {
        min-height: 120px;
    }
}

/* ==========================================
   SENTINELA DO INFINITE SCROLL
   ========================================== */

#scroll-sentinel {
    height: 1px;
    width: 100%;
    visibility: hidden;
}

/* ==========================================
   CONTADOR DE FOTOS CARREGADAS (opcional)
   ========================================== */

.photo-counter {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 12px;
    z-index: 1000;
    transition: opacity 0.3s;
}

.photo-counter.hidden {
    opacity: 0;
    pointer-events: none;
}

/* ==========================================
   ANIMAÇÃO DE ENTRADA DOS CARDS
   ========================================== */

.gallery-photo-card.new-item {
    animation: cardAppear 0.4s ease-out;
}

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

/* ==========================================
   LOADING OVERLAY OTIMIZADO
   ========================================== */

#page-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.98);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease-out, visibility 0.3s;
}

#page-loading-overlay.fade-out {
    opacity: 0;
    visibility: hidden;
}

/* Spinner mais moderno */
.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #fd0000;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    margin-top: 15px;
    color: #333;
    font-size: 14px;
    font-weight: 500;
}

/* ==========================================
   WILL-CHANGE para performance
   ========================================== */

.gallery-photo-card img {
    will-change: opacity, transform;
}

.gallery-progress-bar {
    will-change: width;
}

/* ==========================================
   REDUCE MOTION para acessibilidade
   ========================================== */

@media (prefers-reduced-motion: reduce) {
    .skeleton-loading {
        animation: none;
        background: #e8e8e8;
    }
    
    .loading-dots span {
        animation: none;
    }
    
    .gallery-photo-card.new-item {
        animation: none;
    }
    
    .gallery-photo-card img.loaded {
        animation: none;
    }
}
