﻿/* =============================================== */
/* GLOBAL LOADING OVERLAY - LIGHT GRAY (MAXIMUM BACKGROUND VISIBILITY) */
/* =============================================== */

#globalLoadingOverlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(240, 240, 240, 0.45); /* 45% opaque - background clearly 55% visible */
    z-index: 999999;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(1px); /* Minimal blur for visibility */
    -webkit-backdrop-filter: blur(1px);
}

    #globalLoadingOverlay.active {
        display: flex !important;
    }

.global-loading-content {
    text-align: center;
    padding: 50px 40px;
    background: rgba(255, 255, 255, 0.98); /* Solid white box */
    border-radius: 20px;
    box-shadow: 0 10px 40px 0 rgba(0, 0, 0, 0.25);
    border: 2px solid rgba(120, 120, 120, 0.3);
    max-width: 500px;
    width: 90%;
    animation: fadeInScale 0.3s ease-out;
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.global-loading-spinner {
    width: 80px;
    height: 80px;
    border: 8px solid rgba(150, 150, 150, 0.25);
    border-top-color: #667eea;
    border-right-color: #764ba2;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 30px;
    /* ✅ ADD: Smooth transition when hiding */
    transition: opacity 0.3s ease, transform 0.3s ease;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.global-loading-title {
    color: #1f2937;
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 15px;
    text-shadow: 0 1px 3px rgba(255, 255, 255, 0.9);
}

.global-loading-message {
    color: #4b5563;
    font-size: 16px;
    margin-bottom: 25px;
    line-height: 1.6;
}

.global-loading-progress {
    width: 100%;
    height: 30px;
    background: rgba(150, 150, 150, 0.2);
    border-radius: 15px;
    overflow: hidden;
    margin-bottom: 20px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.global-loading-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 15px;
    position: relative;
    overflow: hidden;
}

    .global-loading-progress-bar::after {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.5) 50%, transparent 100%);
        animation: shimmer 2s infinite;
    }

@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }

    100% {
        transform: translateX(100%);
    }
}

.global-loading-percentage {
    color: #1f2937;
    font-size: 22px;
    font-weight: bold;
    margin-bottom: 15px;
    text-shadow: 0 1px 3px rgba(255, 255, 255, 0.9);
}

.global-loading-warning {
    color: #d97706;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 15px;
}

    .global-loading-warning i {
        font-size: 18px;
    }

/* =============================================== */
/* PAGE FREEZE STATE */
/* =============================================== */

body.global-form-submitting {
    overflow: hidden !important;
    pointer-events: none !important;
    user-select: none !important;
}

    body.global-form-submitting * {
        cursor: wait !important;
    }

/* =============================================== */
/* PULSE ANIMATION - ✅ UPDATED: Only pulse during loading, not success */
/* =============================================== */

.global-loading-content:not(.success-state) {
    animation: fadeInScale 0.3s ease-out, pulse 2s ease-in-out 0.3s infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.02);
        opacity: 0.98;
    }
}

/* =============================================== */
/* SUCCESS STATE - ✅ ENHANCED */
/* =============================================== */

.global-loading-success {
    display: none;
    width: 80px;
    height: 80px;
    margin: 0 auto 30px; /* ✅ UPDATED: Match spinner margin */
    /* ✅ ADD: Smooth entrance */
    opacity: 0;
    transform: scale(0);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

    .global-loading-success.show {
        display: block;
        opacity: 1;
        transform: scale(1);
    }

.success-circle {
    stroke-dasharray: 166;
    stroke-dashoffset: 166;
    stroke-width: 2;
    stroke: #10b981;
    fill: none;
}

/* ✅ ADD: Animate circle when shown */
.global-loading-success.show .success-circle {
    animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

.success-check {
    transform-origin: 50% 50%;
    stroke-dasharray: 48;
    stroke-dashoffset: 48;
    stroke: #10b981;
    stroke-width: 3;
}

/* ✅ ADD: Animate checkmark when shown */
.global-loading-success.show .success-check {
    animation: stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.6s forwards;
}

@keyframes stroke {
    100% {
        stroke-dashoffset: 0;
    }
}

/* ✅ NEW: Success state styling for content box */
.global-loading-content.success-state {
    animation: fadeInScale 0.3s ease-out; /* No pulse */
}

    .global-loading-content.success-state .global-loading-title {
        color: #10b981; /* Green text for success */
    }

/* =============================================== */
/* RESPONSIVE DESIGN */
/* =============================================== */

@media (max-width: 768px) {
    .global-loading-content {
        padding: 30px 20px;
        max-width: 95%;
    }

    .global-loading-spinner,
    .global-loading-success { /* ✅ ADD: Success icon responsive too */
        width: 60px;
        height: 60px;
    }

    .global-loading-spinner {
        border-width: 6px;
    }

    .global-loading-title {
        font-size: 22px;
    }

    .global-loading-message {
        font-size: 14px;
    }

    .global-loading-percentage {
        font-size: 18px;
    }

    .global-loading-warning {
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .global-loading-content {
        padding: 20px 15px;
        max-width: 90%;
    }

    .global-loading-spinner,
    .global-loading-success { /* ✅ ADD: Success icon responsive too */
        width: 50px;
        height: 50px;
        margin-bottom: 20px;
    }

    .global-loading-spinner {
        border-width: 5px;
    }

    .global-loading-title {
        font-size: 20px;
        margin-bottom: 10px;
    }

    .global-loading-message {
        font-size: 13px;
        margin-bottom: 20px;
    }

    .global-loading-progress {
        height: 25px;
        margin-bottom: 15px;
    }

    .global-loading-percentage {
        font-size: 16px;
        margin-bottom: 10px;
    }
}

/* =============================================== */
/* ACCESSIBILITY */
/* =============================================== */

@media (prefers-reduced-motion: reduce) {
    .global-loading-spinner,
    .global-loading-progress-bar::after,
    .global-loading-content,
    .global-loading-success { /* ✅ ADD */
        animation: none !important;
    }

    .global-loading-spinner {
        border-top-color: #667eea;
        border-right-color: #667eea;
    }

    /* ✅ ADD: Show success icon immediately for reduced motion */
    .global-loading-success.show {
        opacity: 1 !important;
        transform: scale(1) !important;
    }

        .global-loading-success.show .success-circle,
        .global-loading-success.show .success-check {
            stroke-dashoffset: 0 !important;
        }
}

/* =============================================== */
/* PRINT STYLES */
/* =============================================== */

@media print {
    #globalLoadingOverlay {
        display: none !important;
    }
}

/* =============================================== */
/* HIGH CONTRAST MODE */
/* =============================================== */

@media (prefers-contrast: high) {
    #globalLoadingOverlay {
        background: rgba(230, 230, 230, 0.90);
    }

    .global-loading-content {
        background: white;
        border: 2px solid #000;
    }

    .global-loading-title,
    .global-loading-percentage {
        color: #000;
    }

    .global-loading-message {
        color: #333;
    }

    .global-loading-spinner {
        border-color: #ccc;
        border-top-color: #000;
        border-right-color: #000;
    }

    /* ✅ ADD: High contrast success icon */
    .success-circle,
    .success-check {
        stroke: #000 !important;
    }
}

/* =============================================== */
/* UTILITIES */
/* =============================================== */

.no-scroll {
    overflow: hidden !important;
}

/* Prevent text selection during loading */
#globalLoadingOverlay * {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* Smooth transitions */
#globalLoadingOverlay,
.global-loading-content,
.global-loading-progress-bar {
    transition: all 0.3s ease;
}
