/* ========================================
   🚀 FACEBOOK-STYLE LOADING OVERLAY SYSTEM
   ======================================== */

/* Main Loading Overlay - Always visible first */
#globalLoadingOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 9999999999999999999999999999999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.25s ease-out, visibility 0.25s ease-out;
    font-family: 'Fahkwang', Arial, sans-serif;
    background-image: url('/assets/ld-bg.png');
    background-size: cover;
    background-repeat: no-repeat;
}

/* Hide overlay when page is loaded */
#globalLoadingOverlay.fade-out {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* Logo Animation */
.loading-logo {
    width: 120px;
    height: 120px;
    margin-bottom: 30px;
    position: relative;
    animation: logoFloat 2s ease-in-out infinite alternate;
}

.loading-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 20px; 
}

@keyframes logoFloat {
    0% {
        transform: translateY(0px);
        box-shadow: 0 10px 30px rgba(0, 194, 255, 0.3);
    }
    100% {
        transform: translateY(-10px);
        box-shadow: 0 20px 40px rgba(0, 194, 255, 0.4);
    }
}

/* Loading Text */
.loading-text {
    color: #ffffff;
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 15px;
    background: linear-gradient(45deg, #fdad01, #d40000, #fdad01);
    background-size: 200% 200%;
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: gradientText 2s ease-in-out infinite;
    text-align: center;
    letter-spacing: 1px;
}

@keyframes gradientText {
    0%, 100% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
}

/* Loading Subtitle */
.loading-subtitle {
    color: rgba(255, 190, 50, 0.7);
    font-size: 16px;
    font-weight: 400;
    margin-bottom: 40px;
    text-align: center;
    animation: fadeInOut 2s ease-in-out infinite;
}

@keyframes fadeInOut {
    0%, 100% {
        opacity: 0.7;
    }
    50% {
        opacity: 1;
    }
}

/* Modern Loading Spinner */
.loading-spinner {
    position: relative;
    width: 60px;
    height: 60px;
    margin-bottom: 30px;
}

.loading-spinner::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top: 3px solid #e20000;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-spinner::after {
    content: '';
    position: absolute;
    top: 6px;
    left: 6px;
    width: calc(100% - 12px);
    height: calc(100% - 12px);
    border: 2px solid rgba(211, 0, 0, 0.2);
    border-top: 2px solid rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    animation: spin 1.5s linear infinite reverse;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* Loading Progress Bar */
.loading-progress {
    width: 280px;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 20px;
    position: relative;
}

.loading-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #b30000, #ff790b, #cc0000);
    background-size: 200% 100%;
    border-radius: 2px;
    animation: progressMove 2s ease-in-out, progressShine 1.5s linear infinite;
    transition: width 0.3s ease;
}

@keyframes progressMove {
    0% {
        width: 0%;
    }
    100% {
        width: 100%;
    }
}

@keyframes progressShine {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* Loading Steps */
.loading-steps {
    color: rgba(255, 255, 255, 0.6);
    font-size: 14px;
    text-align: center;
    min-height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-step {
    opacity: 0.5;
    transition: opacity 0.3s ease;
}

.loading-step.active {
    opacity: 1;
    color: #d40000;
}

.loading-step.completed {
    opacity: 0.8;
    color: #28a745;
}

/* Fallback Loading (for browsers without JS) */
.fallback-loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000000;
    z-index: 999999998;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
}

/* Critical CSS Loader Indicator */
.css-loading {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid #d10000;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    .loading-logo {
        width: 80px;
        height: 80px;
        margin-bottom: 20px;
    }
    
    .loading-text {
        font-size: 22px;
        margin-bottom: 10px;
    }
    
    .loading-subtitle {
        font-size: 14px;
        margin-bottom: 30px;
        padding: 0 20px;
    }
    
    .loading-progress {
        width: 240px;
    }
    
    .loading-spinner {
        width: 50px;
        height: 50px;
        margin-bottom: 20px;
    }
}

/* Landscape Mobile */
@media (max-width: 768px) and (orientation: landscape) {
    #globalLoadingOverlay {
        flex-direction: row;
        align-items: center;
    }
    
    .loading-logo {
        width: 60px;
        height: 60px;
        margin-right: 20px;
        margin-bottom: 0;
    }
    
    .loading-content {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
    }
    
    .loading-text {
        font-size: 18px;
        text-align: left;
    }
    
    .loading-subtitle {
        font-size: 12px;
        text-align: left;
        margin-bottom: 15px;
    }
    
    .loading-progress {
        width: 200px;
    }
}

/* Lazy loading đã được xóa - images load trực tiếp */

/* Body transition */
body {
    opacity: 0;
    transition: opacity 0.5s ease;
}

body.page-loaded {
    opacity: 1;
}

/* Prevent layout shift during loading */
.container,
.card,
.navbar {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

body.page-loaded .container,
body.page-loaded .card,
body.page-loaded .navbar {
    opacity: 1;
    transform: translateY(0);
}

/* Stagger animation delays */
body.page-loaded .navbar {
    transition-delay: 0.1s;
}

body.page-loaded .container:nth-child(1) {
    transition-delay: 0.2s;
}

body.page-loaded .container:nth-child(2) {
    transition-delay: 0.3s;
}

body.page-loaded .card:nth-child(1) {
    transition-delay: 0.4s;
}

body.page-loaded .card:nth-child(2) {
    transition-delay: 0.5s;
}

/* High priority elements load first */
.navbar,
.hero-section,
.main-content {
    will-change: transform, opacity;
}
