/* ==========================================================================
   보건복지 개인정보보호센터 - 점검사례 안내서 뷰어 & 다운로드 앱 스타일
   (PC & 모바일 완벽 반응형 UI/UX)
   ========================================================================== */

:root {
  --primary: #1e3a8a;          /* 코발트 블루 */
  --primary-light: #3b82f6;    /* 액티브 블루 */
  --primary-dark: #0f172a;     /* 다크 네이비 */
  --accent: #0284c7;           /* 스카이 블루 포인트 */
  --success: #10b981;          /* 성공 그린 */
  --bg-main: #e2e8f0;          /* 뷰어 배경색 */
  --bg-sidebar: #ffffff;
  --bg-header: #ffffff;
  --border-color: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --header-height: 64px;
  --mobile-header-height: 54px;
  --mobile-bottom-height: 56px;
  --sidebar-width: 360px;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius-md: 8px;
  --radius-lg: 12px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Noto Sans KR", "Segoe UI", Roboto, "Malgun Gothic", sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  height: 100vh;
  height: 100dvh; /* 모바일 브라우저 주소창 고려 */
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   상단 헤더 툴바
   ========================================================================== */
.header-bar {
  height: var(--header-height);
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  z-index: 50;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-logo {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, #1e3a8a, #0284c7);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 20px;
  box-shadow: 0 2px 4px rgba(30, 58, 138, 0.25);
  flex-shrink: 0;
}

.brand-text h1 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary-dark);
  line-height: 1.2;
}

.brand-text .meta-tags {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 2px;
}

.badge-tag {
  font-size: 0.72rem;
  padding: 1px 6px;
  border-radius: 4px;
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 600;
}

.badge-tag.version {
  background: #f0fdf4;
  color: #15803d;
}

/* 중앙 컨트롤러 (PC) */
.controls-section {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #f8fafc;
  padding: 4px 10px;
  border-radius: 30px;
  border: 1px solid var(--border-color);
}

.ctrl-btn {
  background: transparent;
  border: none;
  outline: none;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #334155;
  transition: all 0.15s ease;
}

.ctrl-btn:hover {
  background: #e2e8f0;
  color: var(--primary);
}

.ctrl-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.page-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.page-input {
  width: 42px;
  height: 28px;
  text-align: center;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
  background: white;
}

.page-input:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.divider {
  width: 1px;
  height: 18px;
  background: #cbd5e1;
  margin: 0 4px;
}

.zoom-label {
  font-size: 0.8rem;
  font-weight: 700;
  min-width: 48px;
  text-align: center;
  color: #475569;
}

/* 우측 액션 버튼 (PC) */
.actions-section {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.btn-download {
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #1d4ed8, #0284c7);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 3px 6px rgba(2, 132, 199, 0.35);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  text-decoration: none;
  white-space: nowrap;
}

.btn-download:hover {
  background: linear-gradient(135deg, #1e40af, #0369a1);
  transform: translateY(-1px);
  box-shadow: 0 5px 12px rgba(2, 132, 199, 0.45);
}

.btn-outline {
  display: flex;
  align-items: center;
  gap: 6px;
  background: white;
  border: 1px solid #cbd5e1;
  color: #334155;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn-outline:hover {
  background: #f8fafc;
  border-color: #94a3b8;
  color: var(--primary);
}

/* ==========================================================================
   메인 레이아웃 (사이드바 + 뷰어)
   ========================================================================== */
.main-wrapper {
  display: flex;
  flex: 1;
  height: calc(100vh - var(--header-height));
  height: calc(100dvh - var(--header-height));
  position: relative;
  overflow: hidden;
}

/* 사이드바 */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: width 0.25s ease, transform 0.25s ease;
  z-index: 30;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.sidebar.collapsed {
  width: 0;
  overflow: hidden;
  border-right: none;
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  background: #f8fafc;
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  padding: 11px 0;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: white;
  font-weight: 700;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
}

/* 목차 트리 */
.toc-group {
  margin-bottom: 0.75rem;
}

.toc-group-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: #334155;
  padding: 7px 10px;
  background: #f1f5f9;
  border-radius: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  border-left: 3px solid #64748b;
  margin-bottom: 3px;
}

.toc-group-title:hover {
  background: #e2e8f0;
  color: var(--primary);
  border-left-color: var(--primary);
}

.toc-item {
  padding: 8px 10px;
  margin: 3px 0;
  border-radius: 6px;
  font-size: 0.83rem;
  color: #334155;
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  transition: all 0.15s;
  line-height: 1.35;
}

.toc-item:hover {
  background: #eff6ff;
  color: var(--primary-light);
}

.toc-item.active {
  background: #eff6ff;
  color: var(--primary);
  font-weight: 700;
  border-left: 3px solid var(--primary);
}

.toc-badge {
  font-size: 0.7rem;
  font-weight: 700;
  background: #e2e8f0;
  color: #475569;
  padding: 1px 5px;
  border-radius: 4px;
  white-space: nowrap;
}

.toc-item.active .toc-badge {
  background: #bfdbfe;
  color: #1e3a8a;
}

.toc-page {
  font-size: 0.72rem;
  color: #94a3b8;
  margin-left: auto;
  font-weight: 600;
  padding-left: 6px;
}

/* 썸네일 그리드 */
.thumbnails-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 4px;
}

.thumb-card {
  background: white;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.thumb-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: #93c5fd;
}

.thumb-card.active {
  border: 2px solid var(--primary);
  box-shadow: 0 0 0 2px rgba(30, 58, 138, 0.2);
}

.thumb-card img {
  width: 100%;
  height: auto;
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  display: block;
}

.thumb-info {
  margin-top: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #64748b;
}

/* ==========================================================================
   핵심 요약 탭 (법령 및 키워드)
   ========================================================================== */
.summary-card {
  background: white;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  border-left: 4px solid #cbd5e1;
}

.summary-card:hover {
  border-color: #93c5fd;
  border-left-color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.summary-card.active {
  border-left-color: var(--primary);
  background: #f8fafc;
}

.summary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.summary-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--primary-dark);
  line-height: 1.3;
}

.summary-sub {
  font-size: 0.77rem;
  color: #475569;
  line-height: 1.4;
  margin-bottom: 8px;
}

/* (1) 관련 법 또는 규정 블록 */
.law-block {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 6px;
  padding: 7px 9px;
  margin-bottom: 8px;
}

.law-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  color: #166534;
  margin-bottom: 3px;
}

.law-content {
  font-size: 0.74rem;
  color: #14532d;
  line-height: 1.35;
  font-weight: 600;
}

/* (2) 키워드 태그 블록 */
.keyword-block {
  margin-bottom: 8px;
}

.keyword-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  color: #475569;
  margin-bottom: 4px;
}

.keyword-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.kw-chip {
  font-size: 0.68rem;
  font-weight: 600;
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background 0.15s;
}

.kw-chip:hover {
  background: #dbeafe;
}

.summary-footer {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
  display: flex;
  justify-content: space-between;
  padding-top: 4px;
  border-top: 1px dashed var(--border-color);
}

/* ==========================================================================
   뷰어 영역 (중앙)
   ========================================================================== */
.viewer-container {
  flex: 1;
  background: var(--bg-main);
  position: relative;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 0;
  -webkit-overflow-scrolling: touch;
}

.view-sub-bar {
  position: sticky;
  top: 8px;
  z-index: 10;
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(8px);
  color: white;
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  margin-bottom: 14px;
  pointer-events: none;
  text-align: center;
  max-width: 90%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pages-stream {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
}

.page-wrapper {
  background: white;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.12), 0 1px 3px rgba(0, 0, 0, 0.08);
  border-radius: 4px;
  position: relative;
  transition: width 0.15s ease;
  overflow: hidden;
}

.page-wrapper img {
  width: 100%;
  height: auto;
  display: block;
}

.page-number-tag {
  position: absolute;
  bottom: 8px;
  right: 12px;
  background: rgba(15, 23, 42, 0.6);
  color: white;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.page-wrapper:hover .page-number-tag {
  opacity: 1;
}

/* ==========================================================================
   문서 3페이지 목차 인터랙티브 핫스팟 링크
   ========================================================================== */
.p3-hotspot-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.p3-hotspot-link {
  position: absolute;
  pointer-events: auto;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 8px;
  -webkit-tap-highlight-color: rgba(37, 99, 235, 0.2);
}

.p3-hotspot-link:hover,
.p3-hotspot-link:active {
  background: rgba(30, 58, 138, 0.12);
  box-shadow: inset 0 0 0 1.5px rgba(37, 99, 235, 0.7);
}

.p3-hotspot-tooltip {
  display: none;
  background: rgba(15, 23, 42, 0.9);
  color: white;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
}

.p3-hotspot-link:hover .p3-hotspot-tooltip {
  display: block;
}

/* ==========================================================================
   모바일 오버레이 및 하단 내비게이션 바
   ========================================================================== */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
  z-index: 150;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.sidebar-overlay.active {
  display: block;
  opacity: 1;
}

.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: var(--mobile-bottom-height);
  background: #ffffff;
  border-top: 1px solid var(--border-color);
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08);
  z-index: 100;
  justify-content: space-around;
  align-items: center;
  padding: 0 4px;
}

.mob-nav-btn {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 0.68rem;
  font-weight: 600;
  color: #475569;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  text-decoration: none;
  flex: 1;
  height: 100%;
}

.mob-nav-btn:active {
  background: #f1f5f9;
  color: var(--primary);
}

.mob-nav-btn.primary {
  color: var(--primary-light);
  font-weight: 700;
}

/* ==========================================================================
   검색 모달
   ========================================================================== */
.search-modal {
  position: fixed;
  top: var(--header-height);
  right: 20px;
  width: 400px;
  max-height: 520px;
  background: white;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 300;
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.search-modal.active {
  display: flex;
}

.search-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
}

.search-input {
  flex: 1;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.88rem;
  outline: none;
}

.search-input:focus {
  border-color: var(--primary-light);
}

.search-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: #64748b;
  cursor: pointer;
  padding: 0 4px;
}

.search-results {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
}

.search-result-item {
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 0.82rem;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
  line-height: 1.4;
}

.search-result-item:hover,
.search-result-item:active {
  background: #eff6ff;
}

.search-result-page {
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 2px;
}

.highlight {
  background-color: #fef08a;
  color: #854d0e;
  font-weight: 700;
  padding: 0 2px;
  border-radius: 2px;
}

/* ==========================================================================
   ★ 모바일 반응형 미디어 쿼리 (@media (max-width: 768px))
   ========================================================================== */
@media (max-width: 768px) {
  /* 상단 헤더 컴팩트화 */
  .header-bar {
    height: var(--mobile-header-height);
    padding: 0 0.75rem;
  }

  .brand-logo {
    width: 32px;
    height: 32px;
  }

  .brand-logo svg {
    width: 18px;
    height: 18px;
  }

  .brand-text h1 {
    font-size: 0.88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 170px;
  }

  .brand-text .meta-tags {
    display: none; /* 모바일 헤더 공간 절약 */
  }

  /* PC 중앙 컨트롤러 숨김 (모바일 하단바로 대체) */
  .controls-section {
    display: none;
  }

  /* PC 우측 일반 버튼 숨김 (인쇄, 새창열기) */
  .actions-section .btn-outline {
    display: none;
  }

  .btn-download {
    padding: 6px 10px;
    font-size: 0.78rem;
    gap: 4px;
  }

  .btn-download span {
    display: none; /* 아이콘만 표시하거나 축약 */
  }

  .btn-download::after {
    content: "PDF";
    font-size: 0.75rem;
  }

  /* 메인 래퍼 높이 (상하 바 고려) */
  .main-wrapper {
    height: calc(100vh - var(--mobile-header-height) - var(--mobile-bottom-height));
    height: calc(100dvh - var(--mobile-header-height) - var(--mobile-bottom-height));
  }

  /* 사이드바 -> 모바일 오프캔버스 드로어 (Drawer) 전환 */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 86%;
    max-width: 320px;
    height: 100vh;
    height: 100dvh;
    z-index: 200;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.25);
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .sidebar.open {
    transform: translateX(0);
    width: 86% !important;
  }

  .sidebar.collapsed {
    transform: translateX(-100%);
    width: 86%;
  }

  /* 뷰어 영역 모바일 너비 100% 자동 맞춤 */
  .viewer-container {
    padding: 10px 0 20px 0;
  }

  .pages-stream {
    width: 100%;
    padding: 0 6px;
    gap: 12px;
  }

  .page-wrapper {
    width: 100% !important; /* 스마트폰 가로 폭에 칼같이 맞춤 */
    max-width: 100% !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }

  .view-sub-bar {
    font-size: 0.72rem;
    padding: 4px 10px;
    top: 6px;
    margin-bottom: 10px;
  }

  /* 모바일 하단 내비게이션 바 표시 */
  .mobile-bottom-nav {
    display: flex;
  }

  /* 검색 모달 모바일 전체 너비 */
  .search-modal {
    top: var(--mobile-header-height);
    left: 10px;
    right: 10px;
    width: auto;
    max-height: 70vh;
  }
}
