/* ==========================================================================
   AZhai NAV · 统一加载态 UI 组件
   --------------------------------------------------------------------------
   包含：Page-Loader / Skeleton / Shimmer / Spinner / Progress-Bar /
        Circular-Progress / Button-Loading
   设计原则：
   - 纯 CSS，无依赖；配色用中性灰，自动适配 body.dark 暗色模式
   - 组件类名统一加 ui- 前缀，避免与现有样式冲突
   - 尊重 prefers-reduced-motion，动效敏感用户自动降级
   ========================================================================== */

/* --------------------------------------------------------------------------
   公共动效令牌
   -------------------------------------------------------------------------- */
:root {
    --ui-sk-base:   #ececeb;   /* 骨架底色 */
    --ui-sk-shine:  #f7f7f6;   /* 骨架流光高光 */
    --ui-line:      #3b82f6;   /* 进度条主色 */
    --ui-spin:      #9a9a97;   /* 转圈描边 */
}

body.dark {
    --ui-sk-base:   #232323;
    --ui-sk-shine:  #2e2e2e;
    --ui-line:      #60a5fa;
    --ui-spin:      #6b6b68;
}

/* ==========================================================================
   1. Skeleton（骨架屏）+ 3. Shimmer（流光扫过）
   --------------------------------------------------------------------------
   用法：
     <div class="ui-skeleton ui-skeleton--text"></div>
     <div class="ui-skeleton ui-skeleton--icon"></div>
     <div class="ui-skeleton ui-skeleton--rect" style="height:80px"></div>
   流光：默认开启（.ui-skeleton 已带），可用 .ui-skeleton--static 关闭
   ========================================================================== */
.ui-skeleton {
    position: relative;
    display: block;
    overflow: hidden;
    background: var(--ui-sk-base);
    border-radius: 6px;
    /* 防止骨架本身撑出 0 高度 */
    min-height: 1em;
}

/* 流光：一条比容器更宽的高光横向扫过 */
.ui-skeleton::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(
        90deg,
        transparent 0%,
        var(--ui-sk-shine) 50%,
        transparent 100%
    );
    animation: ui-shimmer 1.4s ease-in-out infinite;
}

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

/* 关闭流光（静态骨架） */
.ui-skeleton--static::after { display: none; }

/* 形状变体 */
.ui-skeleton--text {
    height: 0.85em;
    border-radius: 4px;
    margin: 0.28em 0;
}
.ui-skeleton--text:last-child { width: 60%; }

.ui-skeleton--icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    flex: 0 0 auto;
}

.ui-skeleton--rect {
    width: 100%;
    border-radius: 10px;
}

.ui-skeleton--circle {
    border-radius: 50%;
}

/* 常用尺寸微调 */
.ui-skeleton--w40 { width: 40%; }
.ui-skeleton--w60 { width: 60%; }
.ui-skeleton--w80 { width: 80%; }

/* ==========================================================================
   4. Spinner（转圈菊花）
   --------------------------------------------------------------------------
   用法：<span class="ui-spinner"></span>
        尺寸：.ui-spinner--sm / 默认 / .ui-spinner--lg
   ========================================================================== */
.ui-spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    vertical-align: -3px;
    border: 2px solid var(--ui-spin);
    border-top-color: transparent;
    border-radius: 50%;
    animation: ui-spin 0.7s linear infinite;
}

.ui-spinner--sm { width: 13px; height: 13px; border-width: 2px; }
.ui-spinner--lg { width: 28px; height: 28px; border-width: 3px; }

/* 居中大号加载块（用于空态 / 区域加载） */
.ui-loading-block {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 28px 16px;
    color: #8a8a87;
    font-size: 13px;
}
body.dark .ui-loading-block { color: #8a8a88; }

@keyframes ui-spin {
    100% { transform: rotate(360deg); }
}

/* ==========================================================================
   7. Button-Loading（按钮内部加载态）
   --------------------------------------------------------------------------
   由 ui-loading.js 自动添加 .is-loading 类，无需手写。
   也可手动：<button class="is-loading">提交</button>
   ========================================================================== */
button.is-loading,
.btn.is-loading,
.ui-btn.is-loading,
.save-button.is-loading,
input[type="submit"].is-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.75;
    cursor: progress;
    color: transparent !important;
}

/* 按钮内转圈：用 ::after 覆盖在正中，文字用 transparent 隐藏 */
button.is-loading::after,
.btn.is-loading::after,
.ui-btn.is-loading::after,
.save-button.is-loading::after,
input[type="submit"].is-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: ui-spin 0.7s linear infinite;
    /* currentColor 被 transparent 影响，这里固定一个可读色 */
    color: #fff;
    border-color: rgba(255, 255, 255, 0.9);
    border-top-color: transparent;
}

/* 浅色 / 描边按钮上的转圈改为深色 */
.btn--ghost.is-loading::after,
.theme-toggle.is-loading::after,
button.secondary.is-loading::after {
    border-color: rgba(17, 17, 17, 0.75);
    border-top-color: transparent;
}

/* ==========================================================================
   5. Progress-Bar（顶部直线进度条）
   --------------------------------------------------------------------------
   由 ui-loading.js 自动注入 #uiPageProgress，无需手写 DOM。
   ========================================================================== */
#uiPageProgress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 0;
    z-index: 9999;
    background: linear-gradient(90deg, var(--ui-line), #22d3ee);
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.5);
    border-radius: 0 2px 2px 0;
    transition: width 0.2s ease, opacity 0.3s ease;
    opacity: 0;
    pointer-events: none;
}
#uiPageProgress.is-active { opacity: 1; }
#uiPageProgress.is-done {
    width: 100% !important;
    opacity: 0;
}

/* ==========================================================================
   6. Circular-Progress（环形进度）
   --------------------------------------------------------------------------
   用法（JS 控制）：
     <div class="ui-ring" style="--ui-val:0.35">
       <svg viewBox="0 0 36 36"><circle class="ui-ring__bg" cx="18" cy="18" r="15.9"/>
       <circle class="ui-ring__fg" cx="18" cy="18" r="15.9"/></svg>
       <span class="ui-ring__text">35%</span>
     </div>
   --ui-val: 0~1
   ========================================================================== */
.ui-ring {
    position: relative;
    width: 44px;
    height: 44px;
    display: inline-grid;
    place-items: center;
}
.ui-ring svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}
.ui-ring__bg {
    fill: none;
    stroke: var(--ui-sk-base);
    stroke-width: 3.4;
}
.ui-ring__fg {
    fill: none;
    stroke: var(--ui-line);
    stroke-width: 3.4;
    stroke-linecap: round;
    stroke-dasharray: 100 100;
    /* r=15.9 → 周长≈100，直接当百分比用 */
    stroke-dashoffset: calc(100 - (var(--ui-val, 0) * 100));
    transition: stroke-dashoffset 0.25s ease;
}
.ui-ring__text {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-size: 11px;
    font-weight: 600;
    color: #555;
}
body.dark .ui-ring__text { color: #c9c9c6; }

/* ==========================================================================
   2. 图标骨架 / 图片加载占位（配合 .lazy-icon）
   ========================================================================== */
/* 未加载完成的图标容器加 .is-loading-icon → 显示骨架底色 */
.site-icon.is-loading-icon,
.ui-icon-skeleton {
    background: var(--ui-sk-base);
    overflow: hidden;
    position: relative;
}
.site-icon.is-loading-icon::after,
.ui-icon-skeleton::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(
        90deg,
        transparent,
        var(--ui-sk-shine) 50%,
        transparent
    );
    animation: ui-shimmer 1.4s ease-in-out infinite;
}
/* 图片加载完成后移除骨架（JS 打标 .is-loaded） */
.site-icon.is-loaded {
    background: transparent;
}
.site-icon.is-loaded::after { display: none; }

/* ==========================================================================
   1. Page-Loader（全屏初始化加载）——轻量版
   --------------------------------------------------------------------------
   只在首屏挂载，DOMContentLoaded 后由 JS 淡出移除。
   为避免"闪一下就没"，仅当加载确实超过 120ms 才由 JS 显示。
   ========================================================================== */
#uiPageLoader {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: none;
    place-items: center;
    background: #f7f7f5;
    transition: opacity 0.25s ease;
}
body.dark #uiPageLoader { background: #161616; }
#uiPageLoader.is-visible { display: grid; }
#uiPageLoader.is-hiding { opacity: 0; }

.ui-loader-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}
.ui-loader-brand {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: #111;
}
body.dark .ui-loader-brand { color: #f0f0ee; }
.ui-loader-bar {
    width: 120px;
    height: 3px;
    border-radius: 2px;
    overflow: hidden;
    background: var(--ui-sk-base);
}
.ui-loader-bar span {
    display: block;
    width: 40%;
    height: 100%;
    border-radius: 2px;
    background: linear-gradient(90deg, var(--ui-line), #22d3ee);
    animation: ui-loader-slide 1.1s ease-in-out infinite;
}
@keyframes ui-loader-slide {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(320%); }
}

/* ==========================================================================
   无障碍：动效敏感用户降级
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
    .ui-skeleton::after,
    .site-icon.is-loading-icon::after,
    .ui-icon-skeleton::after {
        animation: none;
    }
    .ui-spinner,
    button.is-loading::after,
    .btn.is-loading::after,
    .ui-btn.is-loading::after,
    .save-button.is-loading::after,
    .ui-loader-bar span {
        animation-duration: 1.6s;
    }
    #uiPageProgress { transition: none; }
}
