/*--------------------------------------------------------------
# 性能优化CSS
--------------------------------------------------------------*/

/* 图片懒加载优化 */
img[loading="lazy"] {
  opacity: 0;
  transition: opacity 0.3s ease-in-out;
}

img[loading="lazy"].loaded {
  opacity: 1;
}

/* 图片占位符，防止布局跳动 */
.img-placeholder {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
}

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

/* 关键路径CSS - 首屏内容优化 */
.hero-section {
  min-height: 100vh;
  display: flex;
  align-items: center;
}

.hero-image {
  max-width: 100%;
  height: auto;
  object-fit: cover;
}

/* 预加载器优化 */
#preloader {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  overflow: hidden;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

#preloader:before {
  content: "";
  position: absolute;
  top: calc(50% - 30px);
  left: calc(50% - 30px);
  border: 6px solid #f3f3f3;
  border-top: 6px solid #f85d23;
  border-radius: 50%;
  width: 60px;
  height: 60px;
  animation: spin 1s linear infinite;
}

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

/* 图片容器优化 */
.service-card img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  object-position: center;
  border-radius: 8px;
  transition: transform 0.3s ease;
}

.service-card img:hover {
  transform: scale(1.05);
}

/* 响应式图片优化 */
@media (max-width: 768px) {
  .service-card img {
    height: 180px;
  }
  
  .hero-image {
    max-height: 300px;
    object-fit: cover;
  }
}

@media (max-width: 576px) {
  .service-card img {
    height: 160px;
  }
  
  .hero-image {
    max-height: 250px;
  }
}

/* 字体加载优化 */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: local('Roboto'), local('Roboto-Regular'), url('../fonts/google-fonts/roboto-v30-latin-regular.woff2') format('woff2');
}

/* 减少重绘和回流 */
.aos-animate {
  will-change: transform, opacity;
}

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

/* 减少不必要的阴影计算 */
.service-card {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: box-shadow 0.3s ease, transform 0.3s ease;
}

.service-card:hover {
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
  transform: translateY(-5px);
}

/* 优化动画性能 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* 关键资源优先级 */
.critical-resource {
  font-display: swap;
}

/* 图片错误处理 */
img {
  background: #f8f9fa;
  border: 1px solid #dee2e6;
}

img::before {
  content: "图片加载中...";
  display: block;
  text-align: center;
  padding: 20px;
  color: #6c757d;
  font-size: 14px;
}

/* WebP支持检测 */
.webp .hero-image {
  background-image: url('../img/about/2.webp');
}

.no-webp .hero-image {
  background-image: url('../img/about/2.png');
}

/* 快速CSS加载优化 */
.critical-css-loaded {
  visibility: visible;
}

/* 减少首屏渲染阻塞 */
.above-fold {
  display: block !important;
}

/* 优化CLS (Cumulative Layout Shift) */
.img-container {
  position: relative;
  overflow: hidden;
}

.img-container::before {
  content: '';
  display: block;
  padding-top: 56.25%; /* 16:9 宽高比 */
}

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