/* =========================================================================
   xingAPI 도움말(/xinghelp) — PDF viewer page
   left TOC tree (25%, 카테고리를 최상위로 둔 계층 트리) · right PDF viewer (75%)
   ========================================================================= */

/* dvh 를 뒤에 둔다 — 모바일 브라우저의 100vh 는 주소창이 펼쳐진 높이를 세지 않아
   컨트롤바·PDF 바닥이 툴바 뒤로 잘린다. dvh 를 모르는 브라우저는 앞줄(vh)을 쓴다. */
.pkg-shell { margin-top: 72px; height: calc(100vh - 72px); height: calc(100dvh - 72px); display: flex; flex-direction: column; background: var(--bg); }

/* ---------- main split ---------- */
.pkg-main { flex: 1; display: grid; grid-template-columns: minmax(220px, 24%) 1fr; min-height: 0; }

/* ---------- left TOC ---------- */
.pkg-toc { border-right: 1px solid var(--border); overflow-y: auto; background: var(--bg-2); display: flex; flex-direction: column; }
.pkg-toc__head { padding: 18px 20px 12px; font-size: var(--fs-badge); line-height: var(--lh-badge); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-dim); position: sticky; top: 0; background: var(--bg-2); z-index: 2; border-bottom: 1px solid var(--border); }
.toc-tree { padding: 10px 12px 30px; }
.toc-node__row { display: flex; align-items: center; gap: 6px; padding: 9px 10px; border-radius: var(--r-sm); cursor: pointer; font-size: var(--fs-text-sm); color: var(--text-2); transition: color 0.16s, background-color 0.16s; line-height: var(--lh-text-sm); }
.toc-node__row:hover { background: var(--surface-2); color: var(--text); }
.toc-node__row.active { background: var(--accent-grad-soft); color: var(--text); font-weight: 600; box-shadow: inset 2px 0 0 var(--accent-cyan); }
.toc-node__toggle { width: 18px; height: 18px; display: grid; place-items: center; flex-shrink: 0; color: var(--text-muted); transition: transform 0.25s var(--ease); }
.toc-node__toggle svg { width: 13px; height: 13px; }
.toc-node.collapsed > .toc-node__row .toc-node__toggle { transform: rotate(-90deg); }
.toc-node__dot { width: 5px; height: 5px; border-radius: 50%; background: var(--text-dim); flex-shrink: 0; margin: 0 3px; }
.toc-node__row.active .toc-node__dot { background: var(--accent-cyan); box-shadow: 0 0 7px var(--glow-cyan); }
.toc-node__label { flex: 1; min-width: 0; }
.toc-node__pg { font-family: var(--font-mono); font-size: var(--fs-code-chip); line-height: var(--lh-code-chip); color: var(--text-dim); flex-shrink: 0; }
/* 접힘 애니메이션 — max-height 로는 내용이 그 높이를 넘으면 조용히 잘린다(계층이 깊어지면 확실히 터진다).
   grid 0fr↔1fr 은 내용 높이를 그대로 따라간다. 대신 자식이 하나여야 해서 __inner 래퍼가 필요하다. */
.toc-children { display: grid; grid-template-rows: 1fr; transition: grid-template-rows 0.3s var(--ease); }
.toc-children__inner { overflow: hidden; min-height: 0; }
.toc-node.collapsed > .toc-children { grid-template-rows: 0fr; }
/* 깊이별 들여쓰기 — 후손 선택자(.toc-children .toc-node__row)로는 L3 이하가 전부 L2 와 같아진다. */
.toc-node__row[data-depth="1"] { padding-left: 28px; }
.toc-node__row[data-depth="2"] { padding-left: 46px; }
.toc-node__row[data-depth="3"] { padding-left: 64px; }
.toc-node__row[data-depth="4"] { padding-left: 82px; }
/* 카테고리(L1) 행 — 문서를 가리키지 않고 접기/펴기만 한다(API 가이드의 cat__head 역할). */
.toc-node__row--group { font-weight: 700; color: var(--text); font-size: 0.92rem; padding: 11px 10px; }
.toc-node__row--group:hover { background: var(--surface-2); }
.toc-node__count { font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-dim); background: var(--surface-2); border-radius: 999px; padding: 2px 7px; flex-shrink: 0; }
/* 목차 없음 */
.toc-empty { padding: 40px 16px; text-align: center; color: var(--text-dim); font-size: 0.85rem; }
.toc-empty--inline { padding: 12px 10px 12px 28px; text-align: left; }

/* ---------- right viewer ---------- */
.pkg-viewer { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }

/* control bar */
.pkg-controls { display: flex; align-items: center; gap: 10px; padding: 11px 18px; border-bottom: 1px solid var(--border); background: var(--bg-2); flex-shrink: 0; flex-wrap: wrap; }
.pkg-ctrl-group { display: flex; align-items: center; gap: 4px; }
.pkg-ctrl-group.right { margin-left: auto; }
.ctrl-btn { width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center; color: var(--text-2); border: 1px solid var(--border); background: var(--surface); transition: color 0.16s, border-color 0.16s, background-color 0.16s; }
.ctrl-btn:hover:not(:disabled) { color: var(--text); border-color: var(--border-glow); background: var(--surface-hover); }
.ctrl-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.ctrl-btn svg { width: 18px; height: 18px; }
.ctrl-btn--primary { background: var(--accent-grad); color: var(--on-accent); border-color: transparent; }
.ctrl-btn--primary:hover { filter: brightness(1.08); color: var(--on-accent); }
.ctrl-btn--primary svg { color: var(--on-accent); }
.page-ind { display: inline-flex; align-items: center; gap: 7px; font-family: var(--font-mono); font-size: var(--fs-code-chip); line-height: var(--lh-code-chip); color: var(--text-2); padding: 0 6px; white-space: nowrap; }
.page-ind input { width: 42px; text-align: center; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 7px; color: var(--text); font-family: var(--font-mono); font-size: var(--fs-code-chip); line-height: var(--lh-code-chip); padding: 7px 4px; outline: none; }
.page-ind input:focus { border-color: var(--border-glow); }
.page-ind .sep { color: var(--text-dim); }
.zoom-ind { min-width: 50px; text-align: center; font-family: var(--font-mono); font-size: var(--fs-code-chip); line-height: var(--lh-code-chip); color: var(--text-2); }
.ctrl-divider { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }

/* pages scroll area */
.pkg-pages { flex: 1; overflow: hidden; background: #525659; min-height: 0; }
.pdf-frame { width: 100%; height: 100%; border: 0; display: block; background: #525659; }

/* loading / states */
.pkg-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; color: var(--text-muted); text-align: center; padding: 40px; }
.pkg-state__ic { width: 64px; height: 64px; border-radius: 18px; display: grid; place-items: center; background: var(--accent-grad-soft); border: 1px solid var(--chip-border); color: var(--accent-cyan); }
.pkg-state__ic svg { width: 30px; height: 30px; }
.pkg-state h3 { font-size: var(--fs-h3); line-height: var(--lh-h3); font-weight: 700; color: var(--text); }
.pkg-state p { font-size: var(--fs-text-md); max-width: 380px; line-height: var(--lh-text-md); }
.pkg-state.hidden { display: none; }
.pkg-pages.hidden { display: none; }

/* ---------- mobile TOC dropdown ---------- */
.pkg-toc-mobile { display: none; padding: 12px var(--gutter); border-bottom: 1px solid var(--border); background: var(--bg-2); }
.pkg-toc-mobile select { width: 100%; appearance: none; -webkit-appearance: none; background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--r-pill); color: var(--text-2); font-family: var(--font-sans); font-size: var(--fs-text-sm); line-height: var(--lh-text-sm); font-weight: 500; padding: 12px 38px 12px 14px; outline: none; cursor: pointer; }
.pkg-toc-mobile { position: relative; }
.pkg-toc-mobile::after { content: ""; position: absolute; right: calc(var(--gutter) + 16px); top: 50%; width: 8px; height: 8px; border-right: 2px solid var(--text-dim); border-bottom: 2px solid var(--text-dim); transform: translateY(-65%) rotate(45deg); pointer-events: none; }

/* 새 창에서 보기 — 모바일 전용 대체 수단이라 PC에서는 감춘다. */
.pkg-ctrl-newtab { display: none; }

@media (max-width: 860px) {
  .pkg-main { grid-template-columns: 1fr; }
  .pkg-toc { display: none; }
  .pkg-toc-mobile { display: block; }
  .pkg-pages { padding: 16px; }
  .ctrl-btn { width: 42px; height: 42px; }
  .pkg-controls { gap: 6px; padding: 10px 12px; overflow-x: auto; scrollbar-width: none; -ms-overflow-style: none; flex-wrap: nowrap; }
  .pkg-controls::-webkit-scrollbar { display: none; }
  /* 줌·원본크기·전체화면은 모바일 PDF 뷰어의 핀치줌과 충돌하고, iOS에는 Fullscreen API가 없다.
     → 이 셋을 내리고 '새 창에서 보기'로 대체한다(이전/다음·페이지·다운로드는 유지). */
  .pkg-ctrl-zoomgroup { display: none; }
  .pkg-ctrl-newtab { display: grid; }
  .pkg-ctrl-group.right { margin-left: 0; }
  .page-ind { flex-shrink: 0; }
}
@media (max-width: 560px) {
  /* 폭 402px 에서 좌우 16px 여백은 문서 폭을 8% 깎는다 — 폰에서는 최소로 둔다. */
  .pkg-pages { padding: 8px; }
  .pkg-toc-mobile { padding-block: 10px; }
  .ctrl-btn { width: 40px; height: 40px; }
}
