/**
 * Page Load Optimization
 * Prevents flash of unstyled content (FOUC) during page navigation
 */

/* VERY SHORT fade-in animation with guaranteed fallback */
@keyframes pageReveal {
    from { opacity: 0; }
    to { opacity: 1; }
}

body {
    /* Start invisible */
    opacity: 0;
    /* Auto-reveal after just 30ms - almost instant but prevents FOUC */
    animation: pageReveal 0.1s ease-in 0.03s forwards;
}

/* If JavaScript adds .ready class early, use instant reveal */
body.ready {
    opacity: 1 !important;
    animation: none;
}

/* Emergency fallback: Force visible after 200ms no matter what */
@keyframes emergencyReveal {
    0%, 90% { opacity: 0; }
    100% { opacity: 1; }
}

html {
    animation: emergencyReveal 0.2s linear forwards;
}

html body {
    /* This ensures body is visible even if animation breaks */
    min-height: 100vh;
}

/* Loading overlay for smooth page transitions */
.page-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #f8fafc;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    pointer-events: none;
}

.page-loading-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: all;
}

.page-loading-overlay .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(102, 126, 234, 0.2);
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Prevent layout shifts during load */
html {
    overflow-y: scroll; /* Always show scrollbar to prevent width jump */
}

/* Accessibility: Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    body,
    .page-loading-overlay,
    .page-loading-overlay .spinner {
        transition: none !important;
        animation: none !important;
    }

    body {
        opacity: 1 !important;
    }

    .page-loading-overlay.active {
        opacity: 1;
    }
}
