/**
 * 性能优化CSS
 * 提升页面加载速度和用户体验
 */

/* ============================================
   关键渲染路径优化
   ============================================ */

/* 字体加载优化 - 使用系统字体栈 */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Helvetica Neue", Arial,
                 "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol",
                 "Noto Color Emoji", "PingFang SC", "Microsoft YaHei", "SimSun";
}

/* 图片加载优化 */
img {
    content-visibility: auto;
    /* 提升图片渲染性能 */
}

img[loading="lazy"] {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s ease-in-out infinite;
}

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

/* ============================================
   动画性能优化
   ============================================ */

/* 使用 transform 和 opacity 实现动画 */
.animated-element {
    will-change: transform, opacity;
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* 禁用动画的情况 */
@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;
    }
}

/* ============================================
   布局稳定性优化
   ============================================ */

/* 为图片容器设置宽高比，防止布局偏移 */
.image-container {
    position: relative;
    overflow: hidden;
}

.image-container::before {
    content: '';
    display: block;
    padding-top: 100%; /* 1:1 默认比例 */
}

.image-container img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ============================================
   滚动性能优化
   ============================================ */

/* 优化滚动性能 */
.scroll-container {
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* 虚拟滚动容器 */
.virtual-scroll {
    contain: layout style paint;
    content-visibility: auto;
}

/* ============================================
   交互优化
   ============================================ */

/* 点击区域优化 - 增大触摸目标 */
button,
a,
.clickable {
    min-height: 44px;
    min-width: 44px;
    padding: 12px;
}

/* 禁用状态 */
button:disabled,
a[aria-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* 焦点可见性 */
:focus-visible {
    outline: 2px solid #0066CC;
    outline-offset: 2px;
}

/* 移除默认焦点样式 */
:focus:not(:focus-visible) {
    outline: none;
}

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

/* WebP 支持检测 */
@supports (background-image: -webkit-image-set(url("test.webp") 1x)) {
    .product-image {
        background-image: -webkit-image-set(
            url("../images/placeholder.webp") 1x,
            url("../images/placeholder@2x.webp") 2x
        );
    }
}

/* ============================================
   CSS Containment 优化
   ============================================ */

/* 独立组件容器 */
.component-container {
    contain: layout style paint;
}

/* 产品卡片优化 */
.product-card {
    contain: content;
    content-visibility: auto;
    contain-intrinsic-size: 300px;
}

/* 新闻卡片优化 */
.news-item {
    contain: layout style;
    content-visibility: auto;
    contain-intrinsic-size: 200px;
}

/* ============================================
   渐进式增强
   ============================================ */

/* 加载状态 */
.loading-skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s ease-in-out infinite;
    border-radius: 4px;
}

/* 错误状态 */
.error-state {
    padding: 20px;
    text-align: center;
    color: #dc3545;
    border: 1px solid #f8d7da;
    background: #f8d7da;
    border-radius: 4px;
}

/* 空状态 */
.empty-state {
    padding: 40px;
    text-align: center;
    color: #6c757d;
}

/* ============================================
   打印优化
   ============================================ */

@media print {
    /* 隐藏不必要的元素 */
    .no-print,
    .nav201,
    .right_nav,
    .footer169,
    button,
    .back-to-top {
        display: none !important;
    }

    /* 优化打印布局 */
    body {
        font-size: 12pt;
        line-height: 1.5;
        color: #000;
        background: #fff;
    }

    a {
        text-decoration: underline;
        color: #000;
    }

    /* 显示链接地址 */
    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 10pt;
        color: #666;
    }

    /* 防止分页断裂 */
    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid;
        page-break-inside: avoid;
    }

    img {
        max-width: 100% !important;
        page-break-inside: avoid;
    }

    table {
        page-break-inside: avoid;
    }

    /* 保持颜色 */
    * {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

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

@media (prefers-color-scheme: dark) {
    /* 暗色模式可选实现 */
    /* 如果需要支持暗色模式，可以在这里添加样式 */
}

/* ============================================
   高对比度模式
   ============================================ */

@media (prefers-contrast: high) {
    * {
        border-width: 2px;
    }

    button,
    a {
        outline: 2px solid currentColor;
        outline-offset: 2px;
    }
}

/* ============================================
   网络条件优化
   ============================================ */

/* 慢速网络降级 */
@media (prefers-reduced-data: reduce) {
    /* 禁用背景图片 */
    * {
        background-image: none !important;
    }

    /* 简化动画 */
    * {
        animation: none !important;
        transition: none !important;
    }
}
