/* =====================================================
   Image Optimization Styles
   ===================================================== */

/* Lazy Loading 스타일 */
img[data-src],
img[data-srcset] {
  display: block;
  min-height: 100px;
  background: #f0f0f0;
  background-image: linear-gradient(90deg, #f0f0f0 0%, #f8f8f8 50%, #f0f0f0 100%);
  background-size: 200% 100%;
  animation: loading-skeleton 1.5s ease-in-out infinite;
}

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

/* 로드된 이미지 */
img.loaded {
  animation: none;
  background: none;
}

/* 에러 상태 */
img.error {
  background: #ffebee;
  position: relative;
}

img.error::after {
  content: '⚠';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2em;
  color: #c62828;
}

/* Progressive 이미지 */
img[data-progressive] {
  transition: filter 0.3s ease-out;
}

img.progressive-loaded {
  filter: none !important;
}

/* 반응형 이미지 컨테이너 */
.responsive-image-container {
  position: relative;
  width: 100%;
  max-width: 100%;
  height: auto;
}

.responsive-image-container img {
  width: 100%;
  height: auto;
  display: block;
}

/* Aspect Ratio 유지 */
.aspect-ratio-16-9 {
  position: relative;
  padding-bottom: 56.25%; /* 16:9 */
  height: 0;
  overflow: hidden;
}

.aspect-ratio-4-3 {
  position: relative;
  padding-bottom: 75%; /* 4:3 */
  height: 0;
  overflow: hidden;
}

.aspect-ratio-1-1 {
  position: relative;
  padding-bottom: 100%; /* 1:1 */
  height: 0;
  overflow: hidden;
}

.aspect-ratio-16-9 img,
.aspect-ratio-4-3 img,
.aspect-ratio-1-1 img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* WebP 지원 감지 */
.webp .webp-image {
  display: block;
}

.no-webp .webp-image {
  display: none;
}

.webp .fallback-image {
  display: none;
}

.no-webp .fallback-image {
  display: block;
}

/* Picture 요소 스타일 */
picture {
  display: block;
  width: 100%;
}

picture img {
  width: 100%;
  height: auto;
  display: block;
}

/* 이미지 갤러리 최적화 */
.image-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1rem;
  padding: 1rem;
}

.image-gallery-item {
  position: relative;
  overflow: hidden;
  background: #f5f5f5;
  border-radius: 3px;
}

.image-gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.image-gallery-item:hover img {
  transform: scale(1.05);
}

/* 이미지 로딩 표시 */
.image-loading {
  position: relative;
  overflow: hidden;
}

.image-loading::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
  animation: shimmer 2s infinite;
}

@keyframes shimmer {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

/* 이미지 품질 선택기 */
.image-quality-selector {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 10;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 3px;
  padding: 5px;
}

.image-quality-selector button {
  background: transparent;
  border: 1px solid #fff;
  color: #fff;
  padding: 5px 10px;
  margin: 0 2px;
  cursor: pointer;
  font-size: 12px;
  border-radius: 3px;
  transition: background 0.3s;
}

.image-quality-selector button:hover,
.image-quality-selector button.active {
  background: rgba(255, 255, 255, 0.2);
}

/* 모바일 최적화 */
@media (max-width: 768px) {
  .image-gallery {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.5rem;
    padding: 0.5rem;
  }

  /* 모바일에서 저화질 이미지 우선 */
  img[data-mobile-src] {
    content: attr(data-mobile-src);
  }
}

/* 다크모드 지원 */
@media (prefers-color-scheme: dark) {
  img[data-src],
  img[data-srcset] {
    background: #2a2a2a;
    background-image: linear-gradient(90deg, #2a2a2a 0%, #3a3a3a 50%, #2a2a2a 100%);
  }

  .image-gallery-item {
    background: #1a1a1a;
  }

  img.error {
    background: #4a1c1c;
  }
}

/* 프린트 최적화 */
@media print {
  img[data-src],
  img[data-srcset] {
    display: none !important;
  }

  img.loaded {
    display: block !important;
  }

  .image-loading::before {
    display: none;
  }

  .image-quality-selector {
    display: none;
  }
}

/* 접근성 개선 - Alt 속성이 없는 이미지 테두리 표시 - 주석 처리 */
/* img:not([alt]) {
    border: 2px solid red;
} */

/* Alt 속성이 비어있는 이미지에 테두리 표시 - 주석 처리 */
/* img[alt=""] {
    border: 2px solid orange;
} */

/* 포커스 스타일 */
img:focus {
  outline: 3px solid #4caf50;
  outline-offset: 2px;
}

/* 고해상도 디스플레이 지원 */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  /* Retina 디스플레이용 스타일 */
  img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
  }
}
