/* ================================================================
   RESPONSIVE FRAMEWORK — wnhchurch.org
   ----------------------------------------------------------------
   PC (Desktop) : 1025px+       → 기본 스타일 (style.css)
   Tablet       : 768px–1024px  → @media (max-width: 1024px)
   Mobile       : ≤ 767px       → @media (max-width: 767px)
   ================================================================ */

/* ================================================================
   반응형 비디오 래퍼 — 16:9 고정 비율 (전역 적용)
   사용법: <div class="video-wrap"><iframe ...></iframe></div>
   ================================================================ */
.video-wrap {
  position: relative;
  width: 100%;
  padding-top: 56.25%;   /* 9 / 16 = 56.25% → 16:9 비율 유지 */
  overflow: hidden;
  border-radius: 8px;
  background: #000;
}
.video-wrap iframe,
.video-wrap video,
.video-wrap embed,
.video-wrap object {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  border: none;
}

/* ── 전역: 이미지·비디오 화면 넘침 방지 ── */
img,
video,
embed,
object {
  max-width: 100%;
  height: auto;
}

/* ================================================================
   터치 영역 최적화 — 전역 (모든 화면 크기)
   WCAG 2.5.5 기준: 최소 44×44px
   ================================================================ */

/* 네비게이션 링크 */
.nav-item > a {
  min-height: 44px;
  display: flex;
  align-items: center;
}

/* 공통 버튼 */
.btn-primary,
.btn-outline,
.btn-donate,
.btn-membership,
.btn-lms-shortcut {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* 페이지네이션 버튼 */
.page-btn,
[id$="Pagination"] button,
[id$="Pagination"] span {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* 게시판 링크 */
.board-table td a,
.board-table th a {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

/* 카드 내부 링크 */
.news-card a,
.sermon-card a,
.ws-card { min-height: 44px; }

/* 햄버거 버튼 */
.hamburger {
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
}

/* 드로어 아코디언 헤더 */
.mega-col-title { min-height: 44px; }

/* ── aspect-ratio 래퍼 안의 iframe은 높이를 100%로 유지 ── */
/* aspect-ratio 래퍼 안의 iframe은 높이를 100%로 유지 */
.sermon-thumb iframe,
.mt-iframe-wrap iframe {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
}

/* 독립형 embed(tongbible/bible365 카드용) */
.tg-thumb-wrap {
  position: relative;
  width: 100%;
  padding-top: 56.25%;   /* 16:9 */
  overflow: hidden;
  border-radius: 6px;
  background: #000;
}
.tg-thumb-wrap iframe {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  border: none;
}

/* ── 컨테이너 기본 fluid 보장 ── */
.container {
  width: 100%;
  box-sizing: border-box;
}

/* ================================================================
   TABLET  768px – 1024px
   ================================================================ */
@media (max-width: 1024px) {

  /* ── 타이포그래피 ── */
  body { font-size: 1rem; }                         /* 16px 기준 */
  .section-title { font-size: clamp(1.55rem, 3.5vw, 2.2rem); }
  .section-sub   { font-size: 1rem; }
  .page-hero h1  { font-size: clamp(1.7rem, 4vw, 2.4rem); }
  .page-hero .page-sub { font-size: 1rem; }
  .hero-title    { font-size: clamp(2rem, 5vw, 3rem); }

  /* 섹션 여백 */
  .section { padding: 80px 0; }
  .page-hero { padding: 100px 0 60px; }

  /* 컨테이너 좌우 여백 */
  .container { padding-left: 20px; padding-right: 20px; }

  /* ── 그리드: 2열로 ── */
  .programs-grid { grid-template-columns: 1fr 1fr; }
  .programs-grid .program-card.featured { grid-column: span 2; }

  .footer-grid { grid-template-columns: 1fr 1fr; gap: 40px; }
  .footer-brand { grid-column: span 2; }

  /* 뉴스 */
  .news-grid { grid-template-columns: 1fr 1fr; }
  .news-featured { grid-column: span 2; grid-row: span 1; }
  .news-featured .news-img { height: 200px; }

  /* 추천사 */
  .testi-grid { grid-template-columns: 1fr 1fr; }
  .testi-grid .testi-card:last-child { grid-column: span 2; }
  .testi-page { grid-template-columns: 1fr 1fr; }

  /* 설교 */
  .sermon-feature-grid { grid-template-columns: 1fr; }
  .sermon-grid { grid-template-columns: 1fr 1fr; }
  .bulletin-grid { grid-template-columns: 1fr 1fr; }

  /* tg-grid (통성경/성경읽기 카드) */
  .tg-grid-4 { grid-template-columns: repeat(2, 1fr); }
  .tg-grid-5 { grid-template-columns: repeat(3, 1fr); }
}

/* ================================================================
   MOBILE  ≤ 767px
   ================================================================ */
@media (max-width: 767px) {

  /* ── 전역 여백 축소 ── */
  .section { padding: 56px 0; }
  .container { padding-left: 16px; padding-right: 16px; }

  /* ── 모바일 타이포그래피 (본문 16px, 제목 20-24px) ── */
  body            { font-size: 1rem; line-height: 1.7; }      /* 16px */
  .section-title  { font-size: clamp(1.25rem, 5.5vw, 1.5rem); } /* ~20–24px */
  .section-sub    { font-size: 1rem; }
  .section-tag    { font-size: .72rem; letter-spacing: .06em; }

  /* ── 페이지 히어로 ── */
  .page-hero { padding: 90px 0 44px; }
  .page-hero h1 { font-size: clamp(1.3rem, 6vw, 1.75rem); }
  .page-hero .page-sub { font-size: .95rem; }

  /* ── 카드·본문 텍스트 ── */
  .sermon-card-body h3 { font-size: .95rem; }
  .news-card h3,
  .news-card-title     { font-size: 1rem; }
  .testi-text          { font-size: .95rem; }
  p                    { font-size: 1rem; }

  /* ── 메인 히어로 ── */
  .hero-content { padding-top: 100px; padding-bottom: 60px; }
  .hero-title { font-size: clamp(1.65rem, 7.5vw, 2.4rem); }
  .hero-sub { font-size: .92rem; }
  .hero-actions {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .hero-actions a,
  .hero-actions .btn-primary,
  .hero-actions .btn-outline {
    width: 100%;
    text-align: center;
    justify-content: center;
  }

  /* ── 홈 다음세대 풀너비 카드: 모바일 세로 전환 ── */
  .church-intro-card[style*="grid-column:1/-1"] {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 20px !important;
    text-align: center;
  }
  .church-intro-card[style*="grid-column:1/-1"] > a {
    align-self: center;
  }

  /* ── 통계 띠 ── */
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-item {
    border-right: none !important;
    border-bottom: 1px solid rgba(255,255,255,.12);
  }
  .stat-item:nth-child(odd) { border-right: 1px solid rgba(255,255,255,.12) !important; }
  .stat-item:nth-child(3),
  .stat-item:nth-child(4) { border-bottom: none; }

  /* ── 소개 그리드 ── */
  .about-grid { grid-template-columns: 1fr; gap: 36px; }

  /* ── 인사말 (담임목사) ── */
  .greeting-grid { grid-template-columns: 1fr; }
  .greeting-portrait { flex-direction: column; align-items: center; text-align: center; }
  .portrait-frame { width: 120px; height: 120px; margin: 0 auto 16px; }
  .greeting-questions { width: 100%; }
  .greeting-headline { margin-bottom: 36px; }

  /* ── 비전·사명 ── */
  .vm-grid { grid-template-columns: 1fr; }
  .vm-card { padding: 28px 20px; }

  /* ── 사역 프로그램 ── */
  .programs-grid { grid-template-columns: 1fr; }
  .programs-grid .program-card.featured { grid-column: span 1; }

  /* ── 선교·지원 ── */
  .outreach-programs { grid-template-columns: 1fr; }
  .outreach-grid { grid-template-columns: 1fr; }
  .support-grid { grid-template-columns: 1fr; }

  /* ── 위치·연락 ── */
  .location-grid {
    grid-template-columns: 1fr !important;  /* 인라인 스타일 override */
    gap: 24px !important;
  }
  .location-map  { order: -1; }   /* 지도를 첫 번째로 */
  .location-info { order:  1; }   /* 주소·교통을 두 번째로 */
  .contact-grid { grid-template-columns: 1fr; gap: 36px; }

  /* ── 예배 ── */
  .worship-times { grid-template-columns: 1fr 1fr; }
  .worship-time-item:nth-child(3) { border-right: 1px solid var(--border); }
  .worship-time-item:nth-child(2n) { border-right: none; }
  .worship-time-item { padding: 18px 14px; gap: 10px; }
  .church-intro-grid { grid-template-columns: 1fr; }
  .offering-grid { grid-template-columns: 1fr; }

  /* ── 뉴스·게시판 ── */
  .news-grid { grid-template-columns: 1fr; }
  .news-featured { grid-column: span 1; }
  .news-header { flex-direction: column; align-items: flex-start; gap: 10px; }

  /* ── 추천사 ── */
  .testi-grid { grid-template-columns: 1fr; }
  .testi-grid .testi-card:last-child { grid-column: span 1; }
  .testi-page { grid-template-columns: 1fr; }

  /* ── 설교·미디어 ── */
  .sermon-feature-grid { grid-template-columns: 1fr; }
  .sermon-grid { grid-template-columns: 1fr; }
  .bulletin-grid { grid-template-columns: 1fr; }
  .sermon-card { width: 100%; }
  .sermon-thumb { aspect-ratio: 16/9; }

  /* ── 통성경 길라잡이 / 365 성경읽기 카드 그리드 ── */
  .tg-grid-2 { grid-template-columns: 1fr 1fr !important; max-width: none; }
  .tg-grid-3 { grid-template-columns: 1fr 1fr !important; max-width: none; }
  .tg-grid-4 { grid-template-columns: 1fr 1fr !important; }
  .tg-grid-5 { grid-template-columns: 1fr 1fr !important; }

  /* ── 게시판 테이블 ── */
  .board-header { flex-direction: column; gap: 12px; align-items: flex-start; }
  .board-search-wrap { width: 100%; }
  .board-search-wrap input { width: 100%; box-sizing: border-box; }
  .board-table th:nth-child(n+4),
  .board-table td:nth-child(n+4) { display: none; }

  /* ── 푸터 ── */
  .footer-grid { grid-template-columns: 1fr; gap: 28px; }
  .footer-brand { grid-column: span 1; }

  /* ── 기타 UI ── */
  .back-to-top { bottom: 16px; right: 16px; width: 40px; height: 40px; }
  .pagination { flex-wrap: wrap; gap: 6px; justify-content: center; }
  .section-cta { text-align: center; }

  /* ── LMS 워크스페이스 ── */
  .ws-hero-inner { flex-direction: column; gap: 24px; }
  .ws-hero-stats {
    width: 100%;
    justify-content: center;
    padding: 18px 12px;
    flex-wrap: wrap;
  }
  .ws-stat { padding: 0 12px; }
  .ws-stat-div { height: 32px; }
  .ws-toolbar { padding: 10px 16px; }
  .ws-main { padding: 20px 16px 60px; }
  .ws-grid { grid-template-columns: 1fr; }
  .ws-form-two-col { grid-template-columns: 1fr; }
  .ws-modal-box { padding: 24px 18px 20px; }

  /* ── 마이크로 티칭 ── */
  .mt-layout { grid-template-columns: 1fr; }
  .mt-video-col { border-right: none; }
  .mt-rubric-col { max-height: none; border-top: 2px solid #e5e7eb; }
  .mt-url-row { flex-direction: column; }
  .mt-url-btn { width: 100%; }

  /* ── AI 봇 ── */
  .ai-bot-panel { width: calc(100vw - 24px); right: 12px; bottom: 78px; }
  .ai-bot-fab { right: 12px; bottom: 12px; }
}

/* ================================================================
   OFF-CANVAS 내비게이션  (≤ 1024px)
   ─ 기존 style.css의 768px 전체화면 드로어를 완전히 대체합니다.
   ================================================================ */

/* ── 반투명 백드롭 (JS가 생성·제거) ── */
.mob-nav-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.52);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 8998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.mob-nav-backdrop.visible {
  opacity: 1;
  pointer-events: all;
}

/* ── 드로어 헤더 (JS가 삽입) ── */
.mob-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--bg-dark, #2C2845);
  border-bottom: 3px solid var(--primary, #7472B2);
  flex-shrink: 0;
}
.mob-drawer-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.mob-drawer-logo img {
  width: 30px;
  height: 30px;
  object-fit: contain;
}
.mob-drawer-logo-name {
  font-size: .88rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.25;
}
.mob-drawer-logo-sub {
  display: block;
  font-size: .68rem;
  color: rgba(255,255,255,.55);
  font-weight: 400;
}
.mob-drawer-close {
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.22);
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.3rem;
  line-height: 1;
  transition: background 0.2s;
  flex-shrink: 0;
}
.mob-drawer-close:hover { background: rgba(255,255,255,.22); }

/* ── 드로어 퀵 액션 (헌금안내) ── */
.mob-drawer-quick {
  padding: 12px 20px;
  background: #f7f8fb;
  border-bottom: 1px solid var(--border, #e8e8f0);
}
.mob-drawer-quick a {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 18px;
  background: var(--accent, #F5A623);
  color: #fff;
  border-radius: 50px;
  font-size: .82rem;
  font-weight: 700;
  text-decoration: none;
  transition: background 0.2s, transform 0.15s;
}
.mob-drawer-quick a:hover {
  background: #d4880e;
  transform: translateY(-1px);
}

@media (max-width: 1024px) {
  /* ── 데스크톱 내비게이션 요소 숨김 ── */
  .nav-links,
  .btn-donate,
  .btn-membership,
  .btn-lms-shortcut { display: none !important; }
  .hamburger { display: flex !important; }

  /* ★ 중요: #header의 backdrop-filter가 자식의 position:fixed 기준을
     뷰포트가 아닌 헤더(72px)로 가둬, 오프캔버스 드로어가 72px에 갇히는
     버그를 유발함. 모바일/태블릿에서는 블러를 제거해 드로어가 전체 화면
     높이로 펼쳐지도록 함. (헤더 배경은 rgba(255,255,255,.97)로 충분히 불투명) */
  #header {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }

  /* ── 햄버거 색상: 스크롤 전에도 항상 보이도록 ── */
  .hamburger span { background: rgba(255,255,255,0.9); }
  #header.scrolled .hamburger span { background: var(--text, #1a1a2e); }

  /* ── Off-canvas 드로어 ── */
  .mega-panel {
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    left: auto !important;
    bottom: 0 !important;
    width: 300px !important;
    max-width: 88vw !important;
    background: #fff !important;
    border-top: none !important;
    border-left: 3px solid var(--primary, #7472B2) !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    transform: translateX(105%) !important;   /* 기본: 화면 오른쪽 밖 */
    opacity: 1 !important;
    visibility: visible !important;
    transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1) !important;
    z-index: 8999 !important;
    box-shadow: -8px 0 40px rgba(0, 0, 0, 0.22) !important;
    display: flex !important;
    flex-direction: column !important;
  }
  .mega-panel.mob-drawer-open {
    transform: translateX(0) !important;
  }

  /* ── 내부 레이아웃: 세로 아코디언 ── */
  .mega-inner {
    flex-direction: column;
    padding: 0;
    gap: 0;
    flex: 1;
    overflow-y: auto;
    justify-content: flex-start;   /* 위에서부터 채움 */
  }

  .mega-col {
    flex: 0 0 auto !important;      /* ★ 데스크톱의 flex:1 해제 — 내용 높이만큼만 차지
                                       (안 하면 5개 카테고리가 드로어 높이를 1/5씩
                                       나눠 차지해 항목 사이가 크게 벌어짐) */
    padding: 0;
    border-right: none;
    border-bottom: 1px solid var(--border, #e8e8f0);
  }
  .mega-col:last-child { border-bottom: none; }

  /* 카테고리 타이틀 — 아코디언 헤더 */
  .mega-col-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    margin: 0;
    font-size: .82rem;
    font-weight: 700;
    letter-spacing: .07em;
    color: var(--text, #1a1a2e);
    border-bottom: none;
    cursor: pointer;
    user-select: none;
    transition: color 0.2s, background 0.2s;
  }
  .mega-col-title:hover {
    color: var(--primary, #7472B2);
    background: rgba(116, 114, 178, 0.05);
  }
  /* 화살표 — CSS 삼각형 */
  .mega-col-title::after {
    content: '';
    display: block;
    width: 7px;
    height: 7px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform 0.25s ease;
    flex-shrink: 0;
    margin-top: -3px;
    opacity: 0.55;
  }
  .mega-col.mob-open > .mega-col-title {
    color: var(--primary, #7472B2);
    background: rgba(116, 114, 178, 0.07);
  }
  .mega-col.mob-open > .mega-col-title::after {
    transform: rotate(-135deg);
    margin-top: 3px;
    opacity: 1;
  }

  /* 하위 링크 목록 — max-height 아코디언 애니메이션 */
  .mega-col ul {
    display: block !important;    /* display:none 오버라이드 */
    max-height: 0 !important;
    overflow: hidden !important;
    background: #f7f8fb;
    padding: 0 !important;
    transition: max-height 0.32s ease, padding 0.2s ease !important;
  }
  .mega-col.mob-open ul {
    max-height: 700px !important;
    padding: 4px 0 8px !important;
  }

  .mega-col ul li a {
    display: block;
    padding: 9px 20px 9px 28px;
    font-size: .88rem;
    color: var(--text-2, #4a4a6a);
    border-bottom: 1px solid rgba(0,0,0,.05);
    transition: color 0.15s, padding-left 0.15s, background 0.15s;
  }
  .mega-col ul li a:hover {
    color: var(--primary, #7472B2);
    padding-left: 34px;
    background: rgba(116, 114, 178, 0.06);
  }
  .mega-col ul li:last-child > a { border-bottom: none; }

  /* 들여쓰기 서브아이템 (사역소개 내 찬양단 등) */
  .mega-col ul li[style*="padding-left"] a {
    padding-left: 36px;
    font-size: .83rem;
    opacity: 0.82;
  }
  .mega-col ul li[style*="padding-left"] a:hover {
    padding-left: 42px;
    opacity: 1;
  }
}

/* ================================================================
   극소형 화면  ≤ 400px
   ================================================================ */
@media (max-width: 400px) {
  .section-title { font-size: 1.25rem; }
  .page-hero h1 { font-size: 1.3rem; }
  .hero-title { font-size: 1.6rem; }
  .stats-grid { grid-template-columns: 1fr; }
  .stat-item { border-right: none !important; border-bottom: 1px solid rgba(255,255,255,.12); }
  .stat-item:last-child { border-bottom: none; }
  .tg-grid-2,
  .tg-grid-3,
  .tg-grid-4,
  .tg-grid-5 { grid-template-columns: 1fr !important; }
  .worship-times { grid-template-columns: 1fr; }
}
