/* =========================================
   MODAL.CSS — 팝업 / 라이트박스 / 오버레이
   ========================================= */

/* ── 오버레이 배경 ───────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-5);
  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--transition-base),
    visibility var(--transition-base);
}

.modal-overlay.is-open {
  opacity: 1;
  visibility: visible;
}

/* ── 모달 박스 ───────────────────────────── */
.modal {
  position: relative;
  background: var(--color-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(20px) scale(0.97);
  transition: transform var(--transition-base);
}

.modal-overlay.is-open .modal {
  transform: translateY(0) scale(1);
}

/* 크기 변형 */
.modal--sm {
  max-width: 400px;
}
.modal--lg {
  max-width: 860px;
}
.modal--full {
  max-width: 95vw;
  max-height: 95vh;
}

/* ── 모달 헤더 ───────────────────────────── */
.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-5) var(--sp-6);
  border-bottom: 1px solid var(--color-border);
}

.modal__title {
  font-family: var(--font-serif);
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  color: var(--color-primary);
}

.modal__close {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-size: 20px;
  line-height: 1;
  transition:
    background var(--transition-fast),
    color var(--transition-fast);
  flex-shrink: 0;
}

.modal__close:hover {
  background: var(--color-bg-soft);
  color: var(--color-text);
}

/* ── 모달 본문 ───────────────────────────── */
.modal__body {
  padding: var(--sp-6);
}

/* ── 모달 푸터 ───────────────────────────── */
.modal__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--color-border);
  background: var(--color-bg-soft);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ── 라이트박스 (이미지 팝업) ────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--transition-base),
    visibility var(--transition-base);
}

.lightbox.is-open {
  opacity: 1;
  visibility: visible;
}

.lightbox__inner {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox__img {
  max-width: 100%;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: block;
}

.lightbox__caption {
  position: absolute;
  bottom: -36px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: var(--fs-sm);
  color: rgba(255, 255, 255, 0.75);
}

.lightbox__close {
  position: fixed;
  top: 20px;
  right: 24px;
  width: 40px;
  height: 40px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  background: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast);
}

.lightbox__close:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.8);
}

/* 이전 / 다음 버튼 */
.lightbox__prev,
.lightbox__next {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  background: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast);
}

.lightbox__prev {
  left: 20px;
}
.lightbox__next {
  right: 20px;
}

.lightbox__prev:hover,
.lightbox__next:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* ── 레거시 라이트박스 (#lightbox / .lb-*) ── */
#lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2000;
}

#lightbox.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.lb-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
}

.lb-content {
  position: relative;
  z-index: 1;
  max-width: 90vw;
  max-height: 90vh;
}

.lb-img {
  max-width: 90vw;
  max-height: 85vh;
  border-radius: 4px;
  display: block;
}

.lb-close {
  position: absolute;
  top: -36px;
  right: 0;
  background: none;
  border: none;
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
}

.lb-prev,
.lb-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  font-size: 2rem;
  padding: 10px 16px;
  cursor: pointer;
  border-radius: 3px;
  transition: background 0.2s;
}

.lb-prev {
  left: -64px;
}

.lb-next {
  right: -64px;
}

.lb-prev:hover,
.lb-next:hover {
  background: rgba(255, 255, 255, 0.3);
}

@media (max-width: 600px) {
  .lb-prev {
    left: -40px;
  }

  .lb-next {
    right: -40px;
  }
}

/* ── body 스크롤 잠금 ────────────────────── */
body.modal-open {
  overflow: hidden;
}

/* ── 반응형 ──────────────────────────────── */
@media screen and (max-width: 768px) {
  .modal {
    max-width: 100%;
    margin: 0 3px;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 85vh;
    transform: translateY(100%);
  }

  .modal-overlay.is-open .modal {
    transform: translateY(0);
  }

  .modal__body {
    padding: var(--sp-4);
  }
  .modal__header,
  .modal__footer {
    padding: var(--sp-3) var(--sp-4);
  }

  .lightbox__prev {
    left: 8px;
  }
  .lightbox__next {
    right: 8px;
  }
}
