/* =============================================
   公共组件样式 - 抽取自各页面重复定义
   统一 image-placeholder / spinner / image-error / focus 状态

   === CSS 加载顺序约定 ===
   为避免优先级混乱,所有页面 CSS 按以下顺序加载:
   1. minireseter.css    - 浏览器默认样式重置
   2. theme_vars.css     - 设计 token(颜色/间距/圆角/阴影/字体)
   3. base_common.css    - 公共组件(本文件)
   4. button.css         - 按钮基类
   5. base_header.css    - 全局布局(导航/底栏/弹窗/用户菜单)
   6. base_index.css     - 首页布局(或在 detail.html 中为 base_detail.css)
   7. 页面专属内联 <style> - 仅放页面独有样式

   禁止在内联样式中重复定义 base_common 已抽出的组件
   (image-placeholder / spinner / image-error / hidden / :focus-visible)。
   ============================================= */

/* =============================================
   1. 图片占位符 - shimmer 加载效果
   ============================================= */
.image-placeholder {
    background-color: var(--bg-secondary) !important;
    background-image: none !important;
    position: relative;
    overflow: hidden;
}

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

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

/* =============================================
   2. 图片加载失败样式
   ============================================= */
.image-error {
    background-color: var(--bg-secondary) !important;
    background-image: none !important;
    position: relative;
    overflow: hidden;
}

.image-error::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 44px;
    height: 44px;
    transform: translate(-50%, -50%);
    background: url('/image/img-load-failed.svg') no-repeat center;
    background-size: contain;
    opacity: 0.55;
    z-index: 3;
    pointer-events: none;
}

.image-error::before {
    display: none !important;
}

/* =============================================
   3. 加载动画 spinner
   ============================================= */
.loading-spinner {
    display: none;
    text-align: center;
    padding: 40px 0;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--bg-secondary);
    border-top: 4px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

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

/* =============================================
   4. 全局焦点状态 - 键盘可访问性 (WCAG AA)
   ============================================= */
:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* =============================================
   5. 隐藏工具类
   ============================================= */
.hidden {
    display: none !important;
}

.clearfix::after {
    content: "";
    display: table;
    clear: both;
}

/* =============================================
   6. 图片渐入动画 + 页面标题基类
   ============================================= */
.image-transition-loaded {
    animation: imageFadeIn 0.6s ease-out;
}

@keyframes imageFadeIn {
    from {
        opacity: 0;
        transform: scale(1.05);
        filter: blur(8px);
    }
    to {
        opacity: 1;
        transform: scale(1);
        filter: blur(0);
    }
}

/* 页面标题基类 - 供 index/avatar/live/m 等列表页复用 */
.page-title {
    text-align: center;
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-semibold);
    color: var(--text-main);
    margin: 30px 0 40px;
    position: relative;
}

.page-title::after {
    content: '';
    position: absolute;
    bottom: -15px;
    left: 50%;
    transform: translateX(-50%);
    width: 80px;
    height: 4px;
    background: var(--gradient-accent);
    border-radius: 2px;
}

.page-title h1 {
    font-size: inherit;
    font-weight: inherit;
    color: inherit;
    margin: 0;
}

/* =============================================
   7. 悬停效果仅在支持 hover 的设备生效
   ============================================= */
@media (hover: none) {
    /* 触屏设备禁用 transform 类悬停效果,减少不必要的渲染 */
    .nav-link:hover,
    .search-container:hover,
    .login-btn:hover,
    .feature-entry:hover,
    .feedback-entry:hover,
    .tools-entry:hover,
    .download-main-btn:hover,
    #recommend>ul>li:hover,
    .stat-item:hover,
    #footer a:hover,
    .favorite-btn:hover {
        transform: none !important;
    }
}

/* =============================================
   8. 骨架屏(skeleton) - 用于详情页信息卡片加载占位
   ============================================= */
.skeleton-line {
    height: 14px;
    background: linear-gradient(
        90deg,
        var(--bg-secondary) 25%,
        var(--bg-secondary-hover) 50%,
        var(--bg-secondary) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
}

.skeleton-line:last-child {
    margin-bottom: 0;
}

.skeleton-line--sm {
    height: 10px;
    width: 60%;
}

.skeleton-line--lg {
    height: 18px;
    width: 80%;
}

.skeleton-block {
    width: 100%;
    height: 80px;
    background: linear-gradient(
        90deg,
        var(--bg-secondary) 25%,
        var(--bg-secondary-hover) 50%,
        var(--bg-secondary) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
}

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

/* =============================================
   9. 尊重用户的「减少动效」系统偏好
   ============================================= */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* =============================================
   10. 打印样式 - 详情页打印优化
   ============================================= */
@media print {
    /* 隐藏导航、底栏、下载区、收藏、推荐 */
    #nav-bar,
    #nav-category,
    #footer,
    .download-area,
    .favorite-action,
    #recommend,
    .feedback-modal,
    .seo-breadcrumb,
    .loading-spinner,
    #shadow,
    #warning-modal {
        display: none !important;
    }

    /* 详情页改为单列,全宽显示 */
    #detail {
        width: 100% !important;
        max-width: 100% !important;
        flex-direction: column !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    #detail-left,
    #detail-right {
        width: 100% !important;
        margin: 0 !important;
    }

    /* 移除阴影、背景色,节约墨水 */
    * {
        box-shadow: none !important;
        background: white !important;
        color: black !important;
    }

    .image-container,
    .info-card,
    #pic-dec,
    .qr-code-card {
        border: 1px solid #ccc !important;
        page-break-inside: avoid;
    }

    .main-image {
        max-height: 70vh;
        object-fit: contain;
    }

    a {
        text-decoration: underline;
    }

    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 10px;
        color: #666;
    }
}

/* =============================================
   11. 搜索框原生样式重置 - type=search
   ============================================= */
input[type="search"] {
    -webkit-appearance: textfield;
    appearance: textfield;
    box-sizing: border-box;
}

/* 隐藏 Webkit/Blink 浏览器的清除按钮,避免与自定义样式冲突 */
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration {
    -webkit-appearance: none;
    appearance: none;
}

/* 隐藏 IE/Edge 的清除按钮 */
input[type="search"]::-ms-clear {
    display: none;
    width: 0;
    height: 0;
}
