/* Loading Optimization CSS - Elimina flash de conteúdo */

/* Previne flash de conteúdo não estilizado (FOUC) - Versão mais segura */
html {
    visibility: visible;
    opacity: 1;
}

html.loading {
    visibility: hidden;
    opacity: 0;
}

html.loaded {
    visibility: visible !important;
    opacity: 1 !important;
    transition: opacity 0.3s ease-in-out;
}

/* Loading inicial suave */
body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #fff;
    overflow-x: hidden;
}

/* Preloader elegante */
.preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #e39201 0%, #f4a635 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.5s ease-out, visibility 0.5s ease-out;
}

.preloader.hidden {
    opacity: 0;
    visibility: hidden;
}

.preloader-content {
    text-align: center;
    color: white;
}

.preloader-logo {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse 2s ease-in-out infinite;
}

.preloader-text {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 10px;
    animation: fadeInUp 0.6s ease-out;
}

.preloader-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

/* Animações do preloader */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Critical CSS inline para elementos principais */
.critical-above-fold {
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.6s ease-out;
}

.critical-above-fold.loaded {
    opacity: 1;
    transform: translateY(0);
}

/* Otimizações de fonte */
@font-face {
    font-family: 'System';
    src: local(-apple-system), local(BlinkMacSystemFont), local('Segoe UI'), local(Roboto);
    font-display: swap;
}

/* Skeleton loading para conteúdo */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 37%, #f0f0f0 63%);
    background-size: 400% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
}

.skeleton-text {
    height: 1em;
    margin: 0.5em 0;
    border-radius: 4px;
}

.skeleton-text.short {
    width: 60%;
}

.skeleton-text.medium {
    width: 80%;
}

.skeleton-text.long {
    width: 100%;
}

.skeleton-image {
    width: 100%;
    height: 200px;
    border-radius: 8px;
}

@keyframes shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

/* Otimização de scroll suave */
html {
    scroll-behavior: smooth;
}

/* Evita layout shift */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Lazy loading placeholder */
img[data-src] {
    filter: blur(5px);
    transition: filter 0.3s ease;
}

img[data-src].loaded {
    filter: blur(0);
}

/* Resource hints CSS */
.resource-optimized {
    contain: layout;
    content-visibility: auto;
}

/* Performance optimizations */
* {
    box-sizing: border-box;
}

.will-change-auto {
    will-change: auto;
}

.will-change-transform {
    will-change: transform;
}

/* Reduz paint durante scroll */
.optimized-scroll {
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* Media queries para performance */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .preloader {
        display: none;
    }
    
    html {
        visibility: visible;
        opacity: 1;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .skeleton {
        background: linear-gradient(90deg, #2a2a2a 25%, #1a1a1a 37%, #2a2a2a 63%);
    }
}

/* Print optimizations */
@media print {
    .preloader,
    .skeleton,
    .loading-animation {
        display: none !important;
    }
    
    html {
        visibility: visible;
        opacity: 1;
    }
} 