// Loading animations and states

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

@keyframes pulse-opacity {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes bounce-delay {
    0%, 80%, 100% { 
        transform: scale(0);
    } 
    40% { 
        transform: scale(1.0);
    }
}

// Loading spinner
.spinner {
    display: inline-block;
    width: 1em;
    height: 1em;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

// Loading dots
.loading-dots {
    display: inline-flex;
    gap: 0.25em;
    
    span {
        width: 0.5em;
        height: 0.5em;
        background-color: currentColor;
        border-radius: 50%;
        animation: bounce-delay 1.4s infinite ease-in-out both;
        
        &:nth-child(1) { animation-delay: -0.32s; }
        &:nth-child(2) { animation-delay: -0.16s; }
        &:nth-child(3) { animation-delay: 0; }
    }
}

// Loading bar
.loading-bar {
    position: relative;
    width: 100%;
    height: 4px;
    background-color: var(--gumi-bg-secondary);
    border-radius: var(--gumi-radius-full);
    overflow: hidden;
    
    &::before {
        content: '';
        position: absolute;
        top: 0;
        left: -100%;
        width: 100%;
        height: 100%;
        background: linear-gradient(90deg, 
            transparent,
            var(--gumi-primary),
            transparent
        );
        animation: loading-bar 1.5s linear infinite;
    }
}

@keyframes loading-bar {
    to { left: 100%; }
}

// Loading skeleton
.skeleton {
    position: relative;
    overflow: hidden;
    background-color: var(--gumi-bg-secondary);
    
    &::after {
        content: '';
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        transform: translateX(-100%);
        background: linear-gradient(
            90deg,
            transparent,
            rgba(255, 255, 255, 0.2),
            transparent
        );
        animation: shimmer 2s infinite;
    }
    
    &-text {
        height: 1em;
        border-radius: var(--gumi-radius-sm);
        margin-bottom: 0.5em;
        
        &:last-child {
            width: 80%;
            margin-bottom: 0;
        }
    }
    
    &-avatar {
        width: 40px;
        height: 40px;
        border-radius: var(--gumi-radius-full);
    }
    
    &-button {
        height: 36px;
        border-radius: var(--gumi-radius-base);
    }
}

@keyframes shimmer {
    to { transform: translateX(100%); }
}

// Button loading states
.btn {
    &[data-loading="true"] {
        position: relative;
        pointer-events: none;
        opacity: 0.8;
        
        // Hide original content
        > * {
            visibility: hidden;
        }
        
        // Show spinner
        &::after {
            content: '';
            position: absolute;
            top: 50%;
            left: 50%;
            width: 14px;
            height: 14px;
            margin: -7px 0 0 -7px;
            border: 2px solid transparent;
            border-top-color: currentColor;
            border-radius: 50%;
            animation: spin 0.8s linear infinite;
        }
    }
    
    // Loading dots variant
    &-loading-dots[data-loading="true"] {
        &::after {
            display: none;
        }
        
        &::before {
            content: '···';
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            font-size: 16px;
            letter-spacing: 2px;
            animation: loading-dots-pulse 1.5s ease-in-out infinite;
        }
    }
    
    // Loading progress variant
    &-loading-progress[data-loading="true"] {
        overflow: hidden;
        
        &::after {
            display: none;
        }
        
        &::before {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(
                90deg,
                transparent,
                rgba(255, 255, 255, 0.3),
                transparent
            );
            animation: loading-progress-sweep 1.5s ease-in-out infinite;
        }
    }
}

// Loading overlay
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(2px);
    
    .loading-content {
        background: var(--gumi-bg-primary);
        padding: 2rem;
        border-radius: var(--gumi-radius-lg);
        box-shadow: var(--gumi-shadow-lg);
        text-align: center;
        
        .spinner {
            width: 3rem;
            height: 3rem;
            margin: 0 auto 1rem;
        }
    }
}

// Progress loading animation
.progress-loading {
    .progress-bar {
        animation: progress-pulse 1.5s ease-in-out infinite;
    }
}

@keyframes progress-pulse {
    0% { opacity: 1; }
    50% { opacity: 0.6; }
    100% { opacity: 1; }
}

@keyframes loading-dots-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

@keyframes loading-progress-sweep {
    0% { left: -100%; }
    100% { left: 100%; }
}