/**
 * Loading Indicators - 加载指示器样式
 *
 * 包含:
 * 1. 全局顶部加载条
 * 2. 页面遮罩层
 * 3. 按钮加载态
 * 4. 加载动画
 *
 * @version 1.0.0
 */

/* ============================================
   全局加载条 (顶部进度条)
   ============================================ */

.global-loading-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.global-loading-bar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 100%;
    background: linear-gradient(
        90deg,
        var(--bs-primary) 0%,
        var(--bs-info) 50%,
        var(--bs-primary) 100%
    );
    animation: loading-progress 2s ease-in-out infinite;
}

.global-loading-bar.active {
    opacity: 1;
}

.global-loading-bar.active::before {
    animation: loading-progress 2s ease-in-out infinite;
}

@keyframes loading-progress {
    0% {
        width: 0%;
        left: 0;
    }
    50% {
        width: 50%;
        left: 25%;
    }
    100% {
        width: 0%;
        left: 100%;
    }
}

/* ============================================
   页面遮罩层
   ============================================ */

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.loading-overlay__content {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    text-align: center;
    min-width: 200px;
}

.loading-overlay__text {
    margin-top: 1rem;
    color: var(--bs-gray-700);
    font-size: 0.95rem;
    font-weight: 500;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* ============================================
   加载动画 - 三点跳动
   ============================================ */

.loading-spinner {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
    height: 40px;
}

.loading-spinner__circle {
    width: 12px;
    height: 12px;
    background: var(--bs-primary);
    border-radius: 50%;
    animation: loading-bounce 1.4s ease-in-out infinite;
}

.loading-spinner__circle:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-spinner__circle:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes loading-bounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ============================================
   按钮加载态
   ============================================ */

.btn-loading {
    position: relative;
    pointer-events: none;
    cursor: not-allowed;
}

.btn-loading .spinner-border {
    vertical-align: middle;
    margin-right: 0.5rem;
}

/* 按钮禁用态优化 */
.btn:disabled,
.btn.disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ============================================
   内联加载动画 (用于内容区域)
   ============================================ */

.inline-loading {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--bs-gray-600);
    font-size: 0.9rem;
}

.inline-loading__spinner {
    display: inline-block;
    width: 1em;
    height: 1em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

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

/* ============================================
   骨架屏加载
   ============================================ */

.skeleton {
    background: linear-gradient(
        90deg,
        #f0f0f0 0%,
        #e0e0e0 20%,
        #f0f0f0 40%,
        #f0f0f0 100%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 4px;
}

.skeleton-text {
    height: 1em;
    margin-bottom: 0.5rem;
}

.skeleton-text:last-child {
    width: 80%;
    margin-bottom: 0;
}

.skeleton-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
}

.skeleton-card {
    height: 200px;
    border-radius: 8px;
}

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

/* ============================================
   进度条组件
   ============================================ */

.progress-bar-container {
    width: 100%;
    background: var(--bs-gray-200);
    border-radius: 8px;
    overflow: hidden;
    height: 24px;
    position: relative;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(
        90deg,
        var(--bs-primary) 0%,
        var(--bs-info) 100%
    );
    transition: width 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
}

.progress-bar-text {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--bs-gray-700);
    z-index: 1;
}

/* 当进度超过50%时,文字显示在进度条上 */
.progress-bar-fill[data-progress] {
    position: relative;
}

.progress-bar-fill[data-progress]::after {
    content: attr(data-progress);
    position: absolute;
    right: 8px;
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
}

/* ============================================
   加载态卡片
   ============================================ */

.loading-card {
    padding: 2rem;
    text-align: center;
    color: var(--bs-gray-600);
}

.loading-card__spinner {
    margin-bottom: 1rem;
}

.loading-card__text {
    font-size: 0.95rem;
}

/* ============================================
   空状态 (加载后无数据)
   ============================================ */

.empty-state {
    padding: 3rem 2rem;
    text-align: center;
    color: var(--bs-gray-600);
}

.empty-state__icon {
    font-size: 4rem;
    color: var(--bs-gray-400);
    margin-bottom: 1rem;
}

.empty-state__title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--bs-gray-700);
    margin-bottom: 0.5rem;
}

.empty-state__description {
    font-size: 0.95rem;
    color: var(--bs-gray-600);
    margin-bottom: 1.5rem;
}

/* ============================================
   响应式优化
   ============================================ */

@media (max-width: 576px) {
    .loading-overlay__content {
        padding: 1.5rem;
        min-width: 160px;
    }

    .loading-overlay__text {
        font-size: 0.875rem;
    }

    .loading-spinner {
        height: 32px;
    }

    .loading-spinner__circle {
        width: 10px;
        height: 10px;
    }
}

/* ============================================
   暗色模式支持
   ============================================ */

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

    .loading-overlay__content {
        background: #2d3748;
        color: white;
    }

    .loading-overlay__text {
        color: #cbd5e0;
    }

    .skeleton {
        background: linear-gradient(
            90deg,
            #2d3748 0%,
            #4a5568 20%,
            #2d3748 40%,
            #2d3748 100%
        );
        background-size: 200% 100%;
    }

    .progress-bar-container {
        background: #4a5568;
    }

    .empty-state__icon {
        color: #4a5568;
    }

    .empty-state__title {
        color: #e2e8f0;
    }

    .empty-state__description {
        color: #cbd5e0;
    }
}

/* ============================================
   实用类
   ============================================ */

/* 隐藏元素,显示加载动画 */
.is-loading {
    position: relative;
    overflow: hidden;
}

.is-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

/* 加载时模糊内容 */
.loading-blur {
    filter: blur(2px);
    pointer-events: none;
    user-select: none;
}

/* 加载完成动画 */
.load-complete {
    animation: loadComplete 0.5s ease;
}

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