/**
 * Global Loading Overlay System
 * Provides consistent loading indicators across the platform
 */

/* Global Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(3px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.loading-overlay.show {
    opacity: 1;
    visibility: visible;
}

/* Loading Container */
.loading-container {
    background: white;
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    text-align: center;
    max-width: 300px;
    width: 90%;
    position: relative;
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.loading-overlay.show .loading-container {
    transform: translateY(0);
}

/* Spinner */
.loading-spinner {
    width: 60px;
    height: 60px;
    margin: 0 auto 1.5rem;
    position: relative;
}

.loading-spinner::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #007bff;
    border-radius: 50%;
    animation: loadingSpin 1s linear infinite;
}

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

/* Alternative Pulse Spinner */
.loading-spinner.pulse::before {
    border: none;
    background: #007bff;
    border-radius: 50%;
    animation: loadingPulse 1.5s ease-in-out infinite;
}

@keyframes loadingPulse {
    0% {
        transform: scale(0.8);
        opacity: 1;
    }
    50% {
        transform: scale(1.2);
        opacity: 0.5;
    }
    100% {
        transform: scale(0.8);
        opacity: 1;
    }
}

/* Dots Spinner */
.loading-dots {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
    margin: 0 auto 1.5rem;
}

.loading-dots .dot {
    width: 12px;
    height: 12px;
    background: #007bff;
    border-radius: 50%;
    animation: loadingDots 1.4s ease-in-out infinite both;
}

.loading-dots .dot:nth-child(1) { animation-delay: -0.32s; }
.loading-dots .dot:nth-child(2) { animation-delay: -0.16s; }
.loading-dots .dot:nth-child(3) { animation-delay: 0s; }

@keyframes loadingDots {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1.2);
        opacity: 1;
    }
}

/* Loading Text */
.loading-text {
    color: #333;
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.loading-subtext {
    color: #666;
    font-size: 0.9rem;
    opacity: 0.8;
}

/* Progress Bar */
.loading-progress {
    width: 100%;
    height: 6px;
    background: #f0f0f0;
    border-radius: 3px;
    margin-top: 1rem;
    overflow: hidden;
    position: relative;
}

.loading-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #0056b3);
    border-radius: 3px;
    width: 0%;
    transition: width 0.3s ease;
    position: relative;
}

.loading-progress-bar.indeterminate {
    width: 30%;
    animation: loadingProgress 2s linear infinite;
}

@keyframes loadingProgress {
    0% { left: -30%; }
    100% { left: 100%; }
}

/* Button Loading States */
.btn.loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: loadingSpin 0.8s linear infinite;
}

.btn.loading:disabled {
    opacity: 0.7;
}

/* Card Loading State */
.card.loading {
    position: relative;
    overflow: hidden;
}

.card.loading::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    animation: cardShimmer 1.5s infinite;
    z-index: 1;
}

@keyframes cardShimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* Page Loading Indicator */
.page-loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: #f0f0f0;
    z-index: 99998;
    overflow: hidden;
}

.page-loading-bar {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #0056b3, #007bff);
    background-size: 200% 100%;
    width: 100%;
    animation: pageLoadingBar 1.5s linear infinite;
}

@keyframes pageLoadingBar {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .loading-overlay {
        background: rgba(0, 0, 0, 0.8);
    }
    
    .loading-container {
        background: #2a2a2a;
        color: #fff;
    }
    
    .loading-text {
        color: #fff;
    }
    
    .loading-subtext {
        color: #ccc;
    }
    
    .loading-progress {
        background: #444;
    }
}

/* Mobile Responsive */
@media (max-width: 576px) {
    .loading-container {
        padding: 1.5rem;
        border-radius: 12px;
    }
    
    .loading-spinner {
        width: 50px;
        height: 50px;
        margin-bottom: 1rem;
    }
    
    .loading-text {
        font-size: 1rem;
    }
    
    .loading-subtext {
        font-size: 0.8rem;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    .loading-spinner::before,
    .loading-dots .dot,
    .loading-progress-bar.indeterminate,
    .page-loading-bar {
        animation: none;
    }
    
    .loading-spinner.pulse::before {
        animation: none;
        opacity: 0.7;
    }
}

/* Toast Notification System */
.toast-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: linear-gradient(135deg, #007bff, #0056b3);
    color: white;
    padding: 16px 24px;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 123, 255, 0.4);
    z-index: 100000;
    opacity: 0;
    transform: translateX(400px);
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 250px;
    max-width: 400px;
}

.toast-notification.show {
    opacity: 1;
    transform: translateX(0);
}

.toast-notification.flash {
    animation: toastFlash 0.8s ease-in-out infinite;
}

@keyframes toastFlash {
    0%, 100% {
        box-shadow: 0 10px 40px rgba(0, 123, 255, 0.4);
        transform: translateX(0) scale(1);
    }
    50% {
        box-shadow: 0 15px 60px rgba(0, 123, 255, 0.8);
        transform: translateX(0) scale(1.02);
    }
}

.toast-notification-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.toast-notification-icon .spinner {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: toastSpin 0.8s linear infinite;
}

@keyframes toastSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.toast-notification-content {
    flex: 1;
}

.toast-notification-title {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 2px;
}

.toast-notification-message {
    font-size: 13px;
    opacity: 0.9;
}

.toast-notification.success {
    background: linear-gradient(135deg, #28a745, #1e7e34);
    box-shadow: 0 10px 40px rgba(40, 167, 69, 0.4);
}

.toast-notification.error {
    background: linear-gradient(135deg, #dc3545, #c82333);
    box-shadow: 0 10px 40px rgba(220, 53, 69, 0.4);
}

.toast-notification.warning {
    background: linear-gradient(135deg, #ffc107, #e0a800);
    color: #333;
    box-shadow: 0 10px 40px rgba(255, 193, 7, 0.4);
}

@media (max-width: 576px) {
    .toast-notification {
        top: 10px;
        right: 10px;
        left: 10px;
        min-width: auto;
        transform: translateY(-100px);
    }
    
    .toast-notification.show {
        transform: translateY(0);
    }
}