/* 性能优化样式 */

/* 减少重绘和重排 */
* {
    box-sizing: border-box;
}

/* 硬件加速 */
.admin-container,
.sidebar-nav,
.main-wrapper,
.stat-card,
.dashboard-card,
.category-card {
    transform: translateZ(0);
    will-change: transform;
}

/* 优化动画性能 */
@media (prefers-reduced-motion: no-preference) {
    .stat-card,
    .dashboard-card,
    .category-card {
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                    box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    .admin-nav-item {
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    .sidebar-nav {
        transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
}

/* 减少动画的用户偏好 */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* 优化字体渲染 */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* 优化图片和图标 */
img,
svg,
i {
    max-width: 100%;
    height: auto;
}

/* 懒加载占位符 */
.lazy-placeholder {
    background: linear-gradient(90deg, var(--border-color) 25%, transparent 50%, var(--border-color) 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* 优化表格性能 */
.admin-table {
    table-layout: fixed;
}

.admin-table th,
.admin-table td {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 虚拟滚动优化 */
.virtual-scroll-container {
    height: 400px;
    overflow-y: auto;
    position: relative;
}

.virtual-scroll-item {
    position: absolute;
    width: 100%;
}

/* 减少DOM查询 */
.admin-container {
    contain: layout style paint;
}

/* 优化阴影性能 */
.shadow-optimized {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.shadow-optimized:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

/* 优化渐变性能 */
.gradient-optimized {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    background-attachment: fixed;
}

/* 减少不必要的计算 */
.performance-optimized {
    contain: layout style;
}

/* 优化滚动性能 */
.smooth-scroll {
    scroll-behavior: smooth;
}

/* 优化焦点样式 */
.focus-optimized:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* 减少重绘的hover效果 */
.hover-optimized {
    position: relative;
}

.hover-optimized::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: currentColor;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.hover-optimized:hover::before {
    opacity: 0.1;
}

/* 优化加载状态 */
.loading-optimized {
    position: relative;
    overflow: hidden;
}

.loading-optimized::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* 优化响应式图片 */
.responsive-image {
    width: 100%;
    height: auto;
    object-fit: cover;
}

/* 优化字体加载 */
.font-optimized {
    font-display: swap;
}

/* 减少布局抖动 */
.layout-stable {
    min-height: 100px;
}

/* 优化网格布局 */
.grid-optimized {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    align-items: start;
}

/* 优化弹性布局 */
.flex-optimized {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

/* 优化定位 */
.position-optimized {
    position: relative;
    z-index: 1;
}

/* 优化透明度动画 */
.opacity-optimized {
    opacity: 1;
    transition: opacity 0.2s ease;
}

.opacity-optimized.fade-out {
    opacity: 0;
}

/* 优化变换动画 */
.transform-optimized {
    transform: translateZ(0);
    transition: transform 0.2s ease;
}

.transform-optimized:hover {
    transform: translateY(-2px) translateZ(0);
}

/* 优化背景动画 */
.background-optimized {
    background-size: 200% 200%;
    animation: gradient-shift 3s ease infinite;
}

@keyframes gradient-shift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* 优化边框动画 */
.border-optimized {
    position: relative;
    border: 2px solid transparent;
    background: linear-gradient(var(--card-bg), var(--card-bg)) padding-box,
                linear-gradient(135deg, var(--primary-color), var(--secondary-color)) border-box;
}

/* 优化文本选择 */
.text-select-optimized {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.text-select-optimized.selectable {
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
}

/* 优化滚动条 */
.scrollbar-optimized {
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.scrollbar-optimized::-webkit-scrollbar {
    width: 6px;
}

.scrollbar-optimized::-webkit-scrollbar-track {
    background: transparent;
}

.scrollbar-optimized::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.scrollbar-optimized::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* 优化打印样式 */
@media print {
    .no-print {
        display: none !important;
    }
    
    .print-optimized {
        background: white !important;
        color: black !important;
        box-shadow: none !important;
    }
}

/* 优化高对比度模式 */
@media (prefers-contrast: high) {
    .contrast-optimized {
        border: 2px solid currentColor;
    }
}

/* 优化暗色模式 */
@media (prefers-color-scheme: dark) {
    .dark-optimized {
        background: var(--bg-color);
        color: var(--text-color);
    }
}

/* 优化减少动画模式 */
@media (prefers-reduced-motion: reduce) {
    .motion-optimized {
        animation: none !important;
        transition: none !important;
    }
}

/* 优化触摸设备 */
@media (hover: none) and (pointer: coarse) {
    .touch-optimized {
        min-height: 44px;
        min-width: 44px;
    }
    
    .touch-optimized:hover {
        transform: none;
    }
}

/* 优化高DPI屏幕 */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .retina-optimized {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* 优化宽屏设备 */
@media (min-aspect-ratio: 16/9) {
    .wide-optimized {
        max-width: 1400px;
        margin: 0 auto;
    }
}

/* 优化窄屏设备 */
@media (max-aspect-ratio: 4/3) {
    .narrow-optimized {
        padding: 1rem;
    }
}

/* 优化超宽屏设备 */
@media (min-width: 1920px) {
    .ultra-wide-optimized {
        max-width: 1600px;
        margin: 0 auto;
    }
}

/* 优化小屏幕设备 */
@media (max-width: 480px) {
    .mobile-optimized {
        font-size: 14px;
        line-height: 1.4;
    }
}

/* 优化中等屏幕设备 */
@media (min-width: 481px) and (max-width: 768px) {
    .tablet-optimized {
        font-size: 16px;
        line-height: 1.5;
    }
}

/* 优化大屏幕设备 */
@media (min-width: 769px) {
    .desktop-optimized {
        font-size: 18px;
        line-height: 1.6;
    }
}
