/**
 * UW Gallery Frontend Styles
 *
 * @package St-works
 * @since 2.0.0
 */

/* ==========================================================================
   1. 기본 컨테이너 및 CSS 변수 기본값
   ========================================================================== */
.uw-gallery {
  /* 컬럼 */
  --gallery-columns: 4;
  --gallery-columns-tablet: 3;
  --gallery-mobile-columns: 2;

  /* 스타일 */
  --gallery-gap: 15px;
  --gallery-border-width: 0px;
  --gallery-border-radius: 8px;
  --gallery-overlay-opacity: 0.7;
  --gallery-text-align: left;
  --gallery-ratio: 1 / 1;

  /* 레이아웃별 */
  --gallery-main-ratio: 16 / 9;
  --gallery-row-height-min: 200px;
  --gallery-row-height-max: 300px;
  --masonry-columns: 4;

  width: 100%;
  margin: 30px 0;
}

.uw-gallery-error,
.uw-gallery-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-sub);
  background: var(--bg);
  border-radius: var(--gallery-border-radius);
}

/* ==========================================================================
   2. 카테고리 필터 바 (반응형: 탭 + 드롭다운)
   ========================================================================== */
.uw-gallery-filter {
  margin-bottom: 25px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

/* 데스크탑: 탭 버튼 */
.uw-gallery-filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.uw-filter-btn {
  padding: 8px 20px;
  border: 1px solid var(--border);
  border-radius: 25px;
  background: var(--white);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.uw-filter-btn:hover {
  border-color: var(--text);
}

.uw-filter-btn.is-active {
  background: var(--text);
  border-color: var(--text);
  color: var(--white);
}

/* 모바일: 드롭다운 (기본 숨김) */
.uw-gallery-filter-select {
  display: none;
  width: 100%;
  padding: 10px 15px;
  border: 1px solid var(--border);
  border-radius: 25px;
  background: var(--white);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  appearance: none;
  background-image: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="8" viewBox="0 0 12 8"><path fill="%23333" d="M1.41 0L6 4.59L10.59 0L12 1.41L6 7.41L0 1.41L1.41 0Z"/></svg>');
  background-repeat: no-repeat;
  background-position: right 15px center;
  padding-right: 40px;
}

/* ==========================================================================
   3. 그리드 레이아웃 (Grid / Masonry / Justified 공통)
   ========================================================================== */
.uw-gallery-grid {
  display: grid;
  grid-template-columns: repeat(var(--gallery-columns), 1fr);
  gap: var(--gallery-gap);
}

.uw-gallery-item {
  position: relative;
  overflow: hidden;
  border-radius: var(--gallery-border-radius);
  border: var(--gallery-border-width) solid var(--border);
  background: var(--bg);
  transition: var(--transition);
}

.uw-gallery-item.is-hidden {
  display: none;
}

.uw-gallery-link {
  display: block;
  text-decoration: none;
  color: inherit;
}

.uw-gallery-thumb {
  position: relative;
  overflow: hidden;
  aspect-ratio: var(--gallery-ratio);
}

/* 원본 비율 유지 */
.uw-gallery[style*="--gallery-ratio: auto"] .uw-gallery-thumb {
  aspect-ratio: unset;
}

.uw-gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: var(--transition);
}

/* 기본 Grid 레이아웃: 이미지 1:1 비율 꽉 채우기 */
.uw-gallery[data-layout="grid"] .uw-gallery-thumb {
  aspect-ratio: 1 / 1;
}

.uw-gallery[data-layout="grid"] .uw-gallery-thumb img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

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

/* 호버 효과 - none */
.uw-gallery--hover-none .uw-gallery-item:hover .uw-gallery-thumb img {
  transform: none;
}

/* 호버 효과 - zoom (기본) */
.uw-gallery--hover-zoom .uw-gallery-item:hover .uw-gallery-thumb img {
  transform: scale(1.1);
}

/* 호버 효과 - fade */
.uw-gallery--hover-fade .uw-gallery-item:hover .uw-gallery-thumb img {
  opacity: 0.8;
  transform: none;
}

/* 호버 효과 - overlay */
.uw-gallery--hover-overlay .uw-gallery-item::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0);
  z-index: 1;
  transition: var(--transition);
  pointer-events: none;
}

.uw-gallery--hover-overlay .uw-gallery-item:hover::before {
  background: rgba(0, 0, 0, var(--gallery-overlay-opacity));
}

.uw-gallery--hover-overlay .uw-gallery-item:hover .uw-gallery-thumb img {
  transform: none;
}

/* 비디오 재생 아이콘 */
.uw-gallery-play-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 60px;
  height: 60px;
  background: rgba(0, 0, 0, 0.7);
  color: var(--white);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  transition: background 0.2s;
}

.uw-gallery-item:hover .uw-gallery-play-icon {
  background: rgba(0, 0, 0, 0.9);
}

/* ==========================================================================
   4. 텍스트 - 하단 위치
   ========================================================================== */
.uw-gallery--text-bottom .uw-gallery-caption {
  padding: 15px;
  background: var(--white);
}

.uw-gallery-item-title {
  margin: 0 0 5px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.uw-gallery-item-desc {
  margin: 0;
  font-size: 14px;
  color: var(--text-sub);
  line-height: 1.5;
}

/* ==========================================================================
   5. 텍스트 - 오버레이 위치
   ========================================================================== */
.uw-gallery--text-overlay .uw-gallery-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
  color: var(--white);
  opacity: 0;
  transition: var(--transition);
}

.uw-gallery--text-overlay .uw-gallery-item:hover .uw-gallery-overlay {
  opacity: 1;
}

.uw-gallery--text-overlay .uw-gallery-item-title {
  color: var(--white);
}

.uw-gallery--text-overlay .uw-gallery-item-desc {
  color: rgba(255, 255, 255, 0.8);
}

/* ==========================================================================
   6. Masonry 레이아웃 (CSS Columns 기반 - 원본 비율 유지)
   ========================================================================== */
.uw-gallery--masonry .uw-gallery-grid {
  /* CSS Grid 대신 CSS Columns 사용하여 원본 비율 유지 */
  display: block;
  column-count: var(--masonry-columns);
  column-gap: var(--gallery-gap);
}

.uw-gallery--masonry .uw-gallery-item {
  /* 컬럼 내 아이템이 잘리지 않도록 */
  break-inside: avoid;
  margin-bottom: var(--gallery-gap);
  /* 배경/테두리 제거 */
  background: transparent;
  border: none;
}

.uw-gallery--masonry .uw-gallery-thumb {
  /* aspect-ratio 제거하여 원본 비율 유지 */
  aspect-ratio: unset;
  height: auto;
}

.uw-gallery--masonry .uw-gallery-thumb img {
  width: 100%;
  height: auto;
  object-fit: contain;
  display: block;
}

/* Masonry 비디오 아이콘 숨김 */
.uw-gallery--masonry .uw-gallery-play-icon {
  display: none;
}

/* ==========================================================================
   7. Justified 레이아웃 (Flexbox 기반 - 원본 비율 유지)
   ========================================================================== */
.uw-gallery--justified .uw-gallery-grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gallery-gap);
  align-items: flex-start;
}

.uw-gallery--justified .uw-gallery-item {
  /* 이미지 원본 비율 기반으로 유동적으로 확장 */
  flex: 1 1 auto;
  min-width: 150px;
  max-width: 350px;
  /* 고정 높이 제거 - 원본 비율 유지 */
  height: auto;
  /* 배경/테두리 제거 */
  background: transparent;
  border: none;
}

.uw-gallery--justified .uw-gallery-thumb {
  /* aspect-ratio 제거하여 원본 비율 유지 */
  aspect-ratio: unset;
  height: auto;
}

.uw-gallery--justified .uw-gallery-thumb img {
  width: 100%;
  height: auto;
  object-fit: contain;
  display: block;
}

/* Justified 비디오 아이콘 숨김 */
.uw-gallery--justified .uw-gallery-play-icon {
  display: none;
}

/* ==========================================================================
   8. 썸네일형 레이아웃
   ========================================================================== */
.uw-gallery-thumbnail-layout {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

/* 메인 이미지 */
.uw-gallery-main-image {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  background: var(--black);
  border-radius: 8px;
  overflow: hidden;
}

.uw-gallery-main-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.uw-gallery-main-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
  color: var(--white);
}

.uw-gallery-main-title {
  margin: 0 0 5px;
  font-size: 20px;
  font-weight: 600;
}

.uw-gallery-main-desc {
  margin: 0;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.8);
}

/* 썸네일 리스트 */
.uw-gallery-thumbnails {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 5px 0;
}

.uw-gallery-thumb-btn {
  flex: 0 0 auto;
  width: 100px;
  height: 70px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  overflow: hidden;
  background: none;
  position: relative;
  transition: border-color 0.2s;
}

.uw-gallery-thumb-btn:hover {
  border-color: var(--text-sub);
}

.uw-gallery-thumb-btn.is-active {
  border-color: #2271b1;
}

.uw-gallery-thumb-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.uw-thumb-video-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 18px;
  color: var(--white);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

/* ==========================================================================
   9. 슬라이드형 레이아웃
   ========================================================================== */
.uw-gallery-slide-layout {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  background: var(--black);
  border-radius: 8px;
  overflow: hidden;
}

.uw-gallery-slides {
  position: relative;
  width: 100%;
  height: 100%;
}

.uw-gallery-slide {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: var(--transition);
}

.uw-gallery-slide.is-active {
  opacity: 1;
  z-index: 1;
}

.uw-gallery-slide img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.uw-gallery-slide-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
  color: var(--white);
}

.uw-gallery-slide-title {
  margin: 0 0 5px;
  font-size: 18px;
  font-weight: 600;
}

.uw-gallery-slide-desc {
  margin: 0;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.8);
}

/* 네비게이션 버튼 */
.uw-slide-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  width: 50px;
  height: 50px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  font-size: 28px;
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.uw-slide-nav:hover {
  background: var(--white);
}

.uw-slide-prev {
  left: 15px;
}

.uw-slide-next {
  right: 15px;
}

/* 인디케이터 (닷) */
.uw-slide-dots {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  gap: 8px;
}

.uw-slide-dot {
  width: 10px;
  height: 10px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  transition: background 0.2s;
}

.uw-slide-dot:hover {
  background: rgba(255, 255, 255, 0.8);
}

.uw-slide-dot.is-active {
  background: var(--white);
}

/* ==========================================================================
   10. 라이트박스
   ========================================================================== */
.uw-lightbox {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 99999;
  display: none;
}

.uw-lightbox.is-open {
  display: block;
}

.uw-lightbox-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.95);
}

.uw-lightbox-content {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px;
}

.uw-lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 50px;
  height: 50px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: var(--white);
  font-size: 32px;
  cursor: pointer;
  transition: background 0.2s;
}

.uw-lightbox-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.uw-lightbox-prev,
.uw-lightbox-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 60px;
  height: 60px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: var(--white);
  font-size: 36px;
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.uw-lightbox-prev:hover,
.uw-lightbox-next:hover {
  background: rgba(255, 255, 255, 0.2);
}

.uw-lightbox-prev {
  left: 20px;
}

.uw-lightbox-next {
  right: 20px;
}

.uw-lightbox-media {
  max-width: calc(100% - 120px);
  max-height: calc(100% - 100px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.uw-lightbox-media img {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
}

.uw-lightbox-media iframe {
  width: 80vw;
  height: 45vw;
  max-height: 80vh;
  border: none;
}

.uw-lightbox-caption {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--white);
  font-size: 16px;
  text-align: center;
  max-width: 80%;
}

/* ==========================================================================
   11. 반응형
   ========================================================================== */
@media (max-width: 1280px) {
  .uw-gallery {
    --gallery-columns: 3;
  }
}

@media (max-width: 800px) {
  .uw-gallery {
    --gallery-columns: var(--gallery-mobile-columns);
    --gallery-gap: 10px;
  }

  /* 카테고리 필터: 탭 숨김, 드롭다운 표시 */
  .uw-gallery-filter-tabs {
    display: none;
  }

  .uw-gallery-filter-select {
    display: block;
  }

  /* 모바일: 썸네일형 → 슬라이드로 폴백 */
  .uw-gallery--thumbnail .uw-gallery-thumbnails {
    display: none;
  }

  .uw-gallery--thumbnail .uw-gallery-main-image {
    aspect-ratio: 4/3;
  }

  /* 슬라이드 */
  .uw-gallery-slide-layout {
    aspect-ratio: 4/3;
  }

  .uw-slide-nav {
    width: 40px;
    height: 40px;
    font-size: 22px;
  }

  .uw-slide-prev {
    left: 10px;
  }

  .uw-slide-next {
    right: 10px;
  }

  /* 라이트박스 */
  .uw-lightbox-content {
    padding: 20px;
  }

  .uw-lightbox-prev,
  .uw-lightbox-next {
    width: 40px;
    height: 40px;
    font-size: 24px;
  }

  .uw-lightbox-close {
    width: 40px;
    height: 40px;
    font-size: 24px;
    top: 10px;
    right: 10px;
  }

  /* Justified - 모바일 */
  .uw-gallery--justified .uw-gallery-item {
    min-width: 45%;
    max-width: 55%;
    height: auto;
  }

  /* Masonry 모바일 열 조정 */
  .uw-gallery--masonry .uw-gallery-grid {
    column-count: var(--gallery-mobile-columns);
  }
}

@media (max-width: 480px) {
  .uw-gallery {
    --gallery-columns: 2;
  }

  .uw-gallery-main-image {
    aspect-ratio: 1/1;
  }

  .uw-gallery-slide-layout {
    aspect-ratio: 1/1;
  }

  /* Justified - 480px 이하 */
  .uw-gallery--justified .uw-gallery-item {
    min-width: 100%;
    max-width: 100%;
    height: auto;
  }

  /* Masonry 480px 이하: 2열 */
  .uw-gallery--masonry .uw-gallery-grid {
    column-count: 2;
  }
}
