/**
 * Loading Animations - Hybrid Loading System
 *
 * CSS animations for skeleton loaders, toast notifications, and progress indicators.
 * Part of the Hybrid Loading System implementation.
 */

/* ===================================================================
   SKELETON LOADER ANIMATIONS
   =================================================================== */

@keyframes skeleton-shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

.skeleton-line {
    background: linear-gradient(
        90deg,
        #e0f7fa 0%,
        #e0f7fa 40%,
        #b2ebf2 50%,
        #e0f7fa 60%,
        #e0f7fa 100%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 2.5s ease-in-out infinite;
    border-radius: 4px;
    display: inline-block;
}

.skeleton-circle {
    background: linear-gradient(
        90deg,
        #e0f7fa 0%,
        #e0f7fa 40%,
        #b2ebf2 50%,
        #e0f7fa 60%,
        #e0f7fa 100%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 2.5s ease-in-out infinite;
    border-radius: 50%;
    display: inline-block;
}

.skeleton-card {
    opacity: 1;
    transition: opacity 0.3s ease-out;
}

.skeleton-card:hover {
    opacity: 1;
}

/* Skeleton container */
.skeleton-container {
    animation: fade-in 0.3s ease-in;
}

/* Dark mode skeleton (optional) */
@media (prefers-color-scheme: dark) {
    .skeleton-line,
    .skeleton-circle {
        background: linear-gradient(
            90deg,
            #374151 0%,
            #374151 40%,
            #4B5563 50%,
            #374151 60%,
            #374151 100%
        );
        background-size: 200% 100%;
    }
}

/* ===================================================================
   FADE ANIMATIONS
   =================================================================== */

@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fade-out {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(10px);
    }
}

.fade-in {
    animation: fade-in 0.3s ease-out forwards;
}

.fade-out {
    animation: fade-out 0.3s ease-in forwards;
}

/* Content fade in (for skeleton → content transition) */
.content-fade-in {
    animation: fade-in 0.4s ease-out forwards;
}

/* ===================================================================
   TOAST NOTIFICATION ANIMATIONS
   =================================================================== */

@keyframes toast-slide-in {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes toast-slide-in-mobile {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes toast-slide-out {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

@keyframes toast-slide-out-mobile {
    from {
        transform: translateY(0);
        opacity: 1;
    }
    to {
        transform: translateY(-100%);
        opacity: 0;
    }
}

/* Toast Container */
.toast-container {
    position: fixed;
    z-index: 9999;
    padding: 1rem;
    pointer-events: none; /* Allow clicking through container */
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Desktop positioning: Top-Right */
@media (min-width: 769px) {
    .toast-container {
        top: 70px; /* Below topbar */
        right: 20px;
        width: 400px;
        align-items: flex-end;
    }
}

/* Mobile positioning: Top-Center */
@media (max-width: 768px) {
    .toast-container {
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100vw;
        align-items: center;
        padding: 0.75rem;
    }
    
    .toast-notification {
        width: 100% !important;
        max-width: calc(100vw - 1.5rem) !important;
        animation: toast-slide-in-mobile 0.3s ease-out forwards !important;
    }
    
    .toast-notification.closing {
        animation: toast-slide-out-mobile 0.3s ease-in forwards !important;
    }
}

.toast-notification {
    animation: toast-slide-in 0.3s ease-out forwards;
    min-width: 300px;
    max-width: 400px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    pointer-events: auto; /* Allow interaction with toast */
    border: none !important;
    border-radius: 12px !important;
    overflow: hidden;
}

.toast-notification .toast-header {
    border-bottom: none;
    background-color: transparent;
    padding: 0.75rem 1rem 0.25rem;
    font-weight: 600;
}

.toast-notification .toast-body {
    padding: 0.25rem 1rem 1rem;
}

.toast-notification.closing {
    animation: toast-slide-out 0.3s ease-in forwards;
}

/* Toast from left (if needed) */
@keyframes toast-slide-in-left {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast-notification.from-left {
    animation: toast-slide-in-left 0.3s ease-out forwards;
}

/* ===================================================================
   PROGRESS INDICATOR ANIMATIONS
   =================================================================== */

.progress-indicator-container {
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
    margin: 1rem 0;
    animation: fade-in 0.3s ease-out;
}

.progress-indicator-bar {
    transition: width 0.3s ease-out;
}

/* Multi-stage progress indicators */
.multi-stage-progress-container {
    animation: fade-in 0.3s ease-out;
}

.stage-indicators-container {
    gap: 1rem;
}

.stage-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    position: relative;
}

.stage-indicator::after {
    content: '';
    position: absolute;
    top: 12px;
    left: 50%;
    width: 100%;
    height: 2px;
    background: #dee2e6;
    z-index: -1;
}

.stage-indicator:last-child::after {
    display: none;
}

.stage-indicator.completed::after {
    background: var(--success);
}

.stage-indicator.active::after {
    background: linear-gradient(90deg, var(--success) 0%, var(--gray-200) 100%);
}

.stage-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    background: white;
    border-radius: 50%;
}

.stage-name {
    font-size: 0.75rem;
    text-align: center;
    max-width: 100px;
}

.stage-indicator.completed .stage-name {
    color: var(--success);
    font-weight: 500;
}

.stage-indicator.active .stage-name {
    color: var(--secondary);
    font-weight: 600;
}

.stage-indicator.pending .stage-name {
    color: var(--text-secondary);
}

/* ===================================================================
   SPINNER ENHANCEMENTS
   =================================================================== */

/* Inline spinner in buttons */
.btn .spinner-border,
.btn .spinner-grow {
    margin-right: 0.5rem;
}

/* ===================================================================
   LOADING OVERLAY (for critical operations)
   =================================================================== */

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    backdrop-filter: blur(2px);
    animation: fade-in 0.2s ease-out;
}

.loading-overlay-dark {
    background-color: rgba(0, 0, 0, 0.7);
}

/* ===================================================================
   PULSE ANIMATION (for emphasis)
   =================================================================== */

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.05);
        opacity: 0.8;
    }
}

.pulse-animation {
    animation: pulse 2s ease-in-out infinite;
}

/* ===================================================================
   MOBILE RESPONSIVE ADJUSTMENTS
   =================================================================== */

@media (max-width: 768px) {
    .progress-indicator-container {
        padding: 0.75rem;
    }

    .skeleton-line,
    .skeleton-circle {
        animation-duration: 1.2s; /* Slightly faster on mobile */
    }

    .stage-indicators-container {
        gap: 0.5rem;
    }

    .stage-name {
        font-size: 0.65rem;
        max-width: 60px;
    }

    .multi-stage-progress-container {
        padding: 0.75rem !important;
    }
}

/* ===================================================================
   ACCESSIBILITY
   =================================================================== */

/* Respect user's motion preferences */
@media (prefers-reduced-motion: reduce) {
    .skeleton-line,
    .skeleton-circle,
    .toast-notification,
    .fade-in,
    .fade-out,
    .content-fade-in,
    .loading-overlay,
    .pulse-animation,
    .progress-indicator-bar {
        animation: none !important;
        transition: none !important;
    }

    .stage-indicator::after {
        transition: none !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .skeleton-line,
    .skeleton-circle {
        border: 1px solid currentColor;
        background: transparent;
    }

    .toast-notification {
        border: 2px solid currentColor;
    }
}

/* ===================================================================
   PERFORMANCE OPTIMIZATIONS
   =================================================================== */

/* Use GPU acceleration for animations */
.skeleton-line,
.skeleton-circle,
.toast-notification,
.fade-in,
.fade-out,
.content-fade-in {
    will-change: transform, opacity;
}

/* Prevent layout shift during animations */
.skeleton-container,
.progress-indicator-container {
    contain: layout style paint;
}
