/**
 * 图片优化相关样式
 */

/* 懒加载占位符 */
.lazy-image {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: imageLoading 1.5s infinite;
}

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

/* 图片加载状态 */
.image-loading {
  opacity: 0.6;
  filter: blur(2px);
  transition: all 0.3s ease;
}

.image-loaded {
  opacity: 1;
  filter: blur(0);
  transition: all 0.3s ease;
}

.image-error {
  opacity: 0.5;
  filter: grayscale(100%);
}

/* 应用图标优化 */
.app-item img {
  transition: all 0.3s ease;
  will-change: transform;
}

.app-item img.image-loaded {
  animation: imageFadeIn 0.5s ease-out;
}

@keyframes imageFadeIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* 响应式图片容器 */
.responsive-image-container {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 0;
  padding-bottom: 56.25%; /* 16:9 宽高比 */
}

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

/* 图片加载指示器 */
.image-loading-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 24px;
  height: 24px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: #fff;
  animation: imageSpinner 1s ease-in-out infinite;
}

@keyframes imageSpinner {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* 图片错误状态 */
.image-error::before {
  content: '🖼️';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 24px;
  opacity: 0.5;
}

/* 高DPI屏幕优化 */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .app-item img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
  }
}

/* 低性能设备优化 */
@media (prefers-reduced-data: reduce) {
  .lazy-image {
    animation: none;
    background: #f0f0f0;
  }

  .image-loading {
    filter: none;
    opacity: 0.8;
  }
}

/* 深色模式适配 */
@media (prefers-color-scheme: light) {
  .lazy-image {
    background: linear-gradient(90deg, #e0e0e0 25%, #d0d0d0 50%, #e0e0e0 75%);
  }

  .image-error::before {
    content: '📷';
    color: #666;
  }
}

/* 图片占位符优化 */
.image-placeholder {
  background-color: rgba(255, 255, 255, 0.1);
  border: 1px dashed rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.6);
  font-size: 12px;
}

/* 图片预览功能 */
.image-preview {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.image-preview.show {
  opacity: 1;
  visibility: visible;
}

.image-preview img {
  max-width: 90%;
  max-height: 90%;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.image-preview-close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  color: white;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.image-preview-close:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

/* 移动端优化 */
@media (max-width: 768px) {
  .image-loading-indicator {
    width: 20px;
    height: 20px;
    border-width: 1.5px;
  }

  .image-preview img {
    max-width: 95%;
    max-height: 95%;
  }

  .image-preview-close {
    width: 36px;
    height: 36px;
    font-size: 18px;
    top: 10px;
    right: 10px;
  }
}

/* 网络状态优化 */
@media (prefers-reduced-data: reduce) {
  .app-item img {
    image-rendering: pixelated;
  }
}

/* 图片加载优先级 */
.image-high-priority {
  z-index: 10;
}

.image-low-priority {
  z-index: 1;
}

/* 图片错误重试按钮 */
.image-retry {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.7);
  color: white;
  border: none;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 10px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.image-error:hover .image-retry {
  opacity: 1;
}

/* 图片统计信息 */
.image-stats {
  position: fixed;
  bottom: 10px;
  left: 10px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 11px;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.image-stats.show {
  opacity: 1;
}