/*
 * 사이트 레이어 팝업 (views/inc/site_popup.php + inc/js/site-popup.js)
 * - PC: 콘텐츠 영역 좌측 상단(헤더 아래)에 position:absolute, 배경 딤 없음(본문 클릭 가능), 그림자로 구분
 *       z-index 는 고정 헤더(1030)보다 낮게 → 스크롤하면 헤더 아래로 지나간다
 * - 모바일(.is-sheet, 767.98px 이하): 화면 하단 시트, 화면 일부만 차지
 * - 구조: [grab 바(시트만)] 헤더(뱃지·제목·X, 뱃지는 관리자에서 팝업별 선택 — 표시 안 함이면 제목만) / 본문(긴 내용만 내부 스크롤) / 버튼 영역 — 헤더·버튼은 고정
 * - 다크 모드: 사이트 테마 토글(html[data-bs-theme="dark"])
 * - .mr-popup--static: 관리자 미리보기용 (제자리 배치)
 */
.mr-popup {
  --mrp-bg: #fff;
  --mrp-fg: #1f2937;
  --mrp-title: #111827;
  --mrp-muted: #6b7280;
  --mrp-line: rgba(15, 23, 42, .08);
  --mrp-hover: rgba(15, 23, 42, .05);
  --mrp-badge-bg: #fff1eb;
  --mrp-badge-fg: #e8622c;
  --mrp-cta: #ff7f50;
  --mrp-cta-fg: #fff;
  --mrp-grab: #d1d5db;
  --mrp-radius: 14px;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1025;
  display: flex;
  flex-direction: column;
  width: min(400px, calc(100vw - 32px));
  max-height: min(640px, calc(100vh - 120px));
  overflow: hidden;
  background: var(--mrp-bg);
  color: var(--mrp-fg);
  border-radius: var(--mrp-radius);
  box-shadow: 0 16px 40px rgba(15, 23, 42, .22), 0 2px 6px rgba(15, 23, 42, .08), 0 0 0 1px var(--mrp-line);
  font-family: 'NEXON Lv2 Gothic', 'Pretendard Variable', Pretendard, -apple-system, sans-serif;
  text-align: left;
  outline: none;
  animation: mrp-in .16s ease-out;
}
.mr-popup--image { width: min(440px, calc(100vw - 32px)); }
.mr-popup[hidden] { display: none; }

[data-bs-theme="dark"] .mr-popup {
  --mrp-bg: #2a2d33;
  --mrp-fg: #d6d9de;
  --mrp-title: #f3f4f6;
  --mrp-muted: #9aa0a8;
  --mrp-line: rgba(255, 255, 255, .09);
  --mrp-hover: rgba(255, 255, 255, .06);
  --mrp-badge-bg: rgba(255, 127, 80, .16);
  --mrp-badge-fg: #ff9a73;
  --mrp-grab: #4b5058;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .5), 0 0 0 1px var(--mrp-line);
}

/* 헤더: 공지 뱃지 + 제목 + X */
.mr-popup-grab { display: none; }
.mr-popup-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 10px 12px 18px;
  border-bottom: 1px solid var(--mrp-line);
}
.mr-popup-badge {
  flex: 0 0 auto;
  padding: 3px 7px;
  border-radius: 6px;
  background: var(--mrp-badge-bg, #fff1eb);
  color: var(--mrp-badge-fg, #e8622c);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -.01em;
}
/* 뱃지 종류별 색 (Site_popup::BADGES). notice 는 위 기본값(사이트 주황) */
.mr-popup-badge--update { --mrp-badge-bg: #e8f0fe; --mrp-badge-fg: #1d5fd6; }
.mr-popup-badge--new    { --mrp-badge-bg: #e3f6ec; --mrp-badge-fg: #137a45; }
.mr-popup-badge--event  { --mrp-badge-bg: #f3ebff; --mrp-badge-fg: #7a3fd1; }
.mr-popup-badge--maint  { --mrp-badge-bg: #fdecec; --mrp-badge-fg: #c42b2b; }
[data-bs-theme="dark"] .mr-popup-badge--update { --mrp-badge-bg: rgba(96, 150, 255, .17); --mrp-badge-fg: #8db4ff; }
[data-bs-theme="dark"] .mr-popup-badge--new    { --mrp-badge-bg: rgba(52, 199, 120, .16); --mrp-badge-fg: #6fd9a0; }
[data-bs-theme="dark"] .mr-popup-badge--event  { --mrp-badge-bg: rgba(168, 120, 255, .18); --mrp-badge-fg: #c3a3ff; }
[data-bs-theme="dark"] .mr-popup-badge--maint  { --mrp-badge-bg: rgba(255, 99, 99, .17); --mrp-badge-fg: #ff9191; }
.mr-popup-title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  color: var(--mrp-title);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mr-popup-x {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin: -4px 0;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--mrp-muted);
  cursor: pointer;
}
.mr-popup-x svg { width: 16px; height: 16px; }
.mr-popup-x:hover { background: var(--mrp-hover); color: var(--mrp-title); }

/* 본문: 긴 내용은 여기만 스크롤 */
.mr-popup-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.mr-popup-text {
  padding: 16px 20px 18px;
  font-size: 14.5px;
  line-height: 1.75;
  letter-spacing: -.005em;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
/* 이미지형: 팝업 가장자리까지 꽉 차게 (헤더 아래, 바깥 모서리는 팝업 overflow 로 라운드 맞춤) */
.mr-popup--image .mr-popup-head { border-bottom: 0; }
.mr-popup--image .mr-popup-body picture { display: block; }
.mr-popup-img { display: block; width: 100%; height: auto; }

/* 버튼 영역 */
.mr-popup-actions {
  flex: 0 0 auto;
  background: var(--mrp-bg);
}
.mr-popup-cta {
  display: block;
  margin: 2px 16px 14px;
  padding: 11px 14px;
  border-radius: 10px;
  background: var(--mrp-cta);
  color: var(--mrp-cta-fg) !important;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.4;
  text-align: center;
  text-decoration: none !important;
  transition: filter .12s;
}
.mr-popup--image .mr-popup-cta { margin-top: 14px; }
.mr-popup-cta:hover, .mr-popup-cta:focus-visible { filter: brightness(.94); }
.mr-popup-cta .fa { margin-left: 5px; font-size: 12px; opacity: .85; }
.mr-popup-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 8px;
  border-top: 1px solid var(--mrp-line);
}
.mr-popup-foot button {
  margin: 0;
  padding: 9px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--mrp-muted);
  font: inherit;
  font-size: 12.5px;
  line-height: 1.3;
  cursor: pointer;
}
.mr-popup-foot .mr-popup-close { color: var(--mrp-fg); font-weight: 600; }
.mr-popup-foot button:hover { background: var(--mrp-hover); color: var(--mrp-title); }
.mr-popup :focus-visible { outline: 2px solid #3b82f6; outline-offset: -2px; }

.mr-popup-dim { display: none; }

/* 모바일 하단 시트 */
.mr-popup.is-sheet {
  position: fixed;
  top: auto !important;
  left: 0 !important;
  right: 0;
  bottom: 0;
  z-index: 2147483000;
  width: auto;
  max-width: 560px;
  max-height: min(66vh, 580px);
  margin: 0 auto;
  border-radius: 18px 18px 0 0;
  padding-bottom: env(safe-area-inset-bottom, 0);
  animation: mrp-up .2s cubic-bezier(.2, .8, .3, 1);
}
.mr-popup.is-sheet .mr-popup-grab {
  display: block;
  flex: 0 0 auto;
  width: 36px;
  height: 4px;
  margin: 8px auto 0;
  border-radius: 2px;
  background: var(--mrp-grab);
}
.mr-popup.is-sheet .mr-popup-head { padding-top: 8px; }
.mr-popup.is-sheet .mr-popup-text { padding: 14px 20px 16px; }
.mr-popup.is-sheet .mr-popup-foot { padding: 4px 10px; }
.mr-popup.is-sheet .mr-popup-foot button { padding: 11px 10px; font-size: 13px; }
.mr-popup-dim.is-sheet {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 2147482999;
  background: rgba(0, 0, 0, .32);
  animation: mrp-fade .2s ease-out;
}

/* 관리자 미리보기 */
.mr-popup.mr-popup--static { position: relative; z-index: auto; animation: none; max-height: 560px; }
.mr-popup.mr-popup--static.is-sheet { position: relative; max-height: 420px; width: 100%; margin: 0; }

@keyframes mrp-in { from { opacity: 0; transform: translateY(-4px) scale(.99); } to { opacity: 1; transform: none; } }
@keyframes mrp-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes mrp-fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .mr-popup, .mr-popup.is-sheet, .mr-popup-dim.is-sheet { animation: none; }
  .mr-popup-cta { transition: none; }
}
