/**
 * PDF 뷰어 — v2.0.0-dev2 (3-column 패러다임)
 *
 * 레이아웃:
 *   메인 toolbar (위 전체 가로)
 *   ┌──────┬───────────────┬──────┐
 *   │ 좌썸 │ 중앙 lazy+TXT │ 우도 │
 *   │ 220  │ 1fr           │ 320  │
 *   └──────┴───────────────┴──────┘
 * 작은 화면 (≤1300px): 좌측 썸네일 축소 / 우측 도구창 일반 진행.
 * 매우 작은 화면 (≤900px): 세로 스택.
 *
 * dev.md §14 참조.
 */

/* viewer-stage 는 .tool-stage 의 max-width 를 풀어서 화면 가로 활용 */
.viewer-stage {
  max-width: none !important;
}
.viewer-body {
  padding: 0;
}

.viewer-3col {
  display: flex;
  flex-direction: column;
  gap: 14px;
  /* 화면 가로 활용 (.tool-stage 좌우 padding 외 모두) */
}

/* ───── 메인 toolbar (가로 전체) ───── */

.viewer-main-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(20, 22, 28, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  position: sticky;
  /* topbar (.topbar) 바로 아래에 0 간격 붙음 — sticky 시 topbar 와 한 덩어리 */
  top: var(--tph);
  z-index: 50;
  backdrop-filter: blur(8px);
}
.vmt-info {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #ddd;
  min-width: 0;
  overflow: hidden;
}
.vmt-info strong {
  color: #fff;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  max-width: 360px;
}
.dot-sep { color: #666; }

.vmt-controls {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
}
.vmt-sep {
  width: 1px;
  height: 18px;
  background: rgba(255, 255, 255, 0.12);
  margin: 0 4px;
}

.vbtn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  color: #ddd;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.vbtn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  color: #fff;
}
.vbtn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.vbtn-history svg { stroke: #aaa; }
.vbtn-history:hover:not(:disabled) svg { stroke: #fff; }

.vbtn-active {
  background: rgba(74, 158, 255, 0.18);
  border-color: rgba(74, 158, 255, 0.5);
  color: #fff;
}

.vbtn-primary {
  background: #4a9eff;
  border-color: #4a9eff;
  color: #fff;
  font-weight: 600;
}
.vbtn-primary:hover:not(:disabled) {
  background: #5fb0ff;
  border-color: #5fb0ff;
}
.vbtn-primary:disabled {
  background: rgba(74, 158, 255, 0.3);
  border-color: rgba(74, 158, 255, 0.3);
}

.zoom-label {
  min-width: 48px;
  text-align: center;
  font-size: 12px;
  color: #aaa;
  font-variant-numeric: tabular-nums;
}

/* ───── 3-column body ───── */

.viewer-3col-body {
  display: grid;
  grid-template-columns: 220px 1fr 320px;
  gap: 14px;
  align-items: start;
}

@media (max-width: 1300px) {
  .viewer-3col-body {
    grid-template-columns: 180px 1fr 300px;
  }
}
@media (max-width: 900px) {
  .viewer-3col-body {
    grid-template-columns: 1fr;
  }
}

/* ─── 좌측: 썸네일 ─── */

.viewer-col-left {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 10px;
  position: sticky;
  /* topbar (44) + 메인 toolbar 높이 (~50) + gap → 메인 toolbar 아래에서 멈춤 */
  /* 메인 toolbar (var(--tph) 위치, 높이 ~50px) 바로 아래에서 멈춤 */
  top: calc(var(--tph) + 64px);
  max-height: calc(100vh - var(--tph) - 78px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.col-left-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.col-left-title {
  font-size: 12px;
  font-weight: 600;
  color: #ccc;
}
.col-left-allcheck {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: #aaa;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.col-left-allcheck input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}

.viewer-thumbs-left {
  display: flex;
  flex-direction: column;
  /* thumbnail.js 가 .thumb-grid + --thumb-w CSS var 사용 */
}
/* 좌측에서는 한 컬럼만 (CSS var 무시 + flex 세로) */
.viewer-thumbs-left.thumb-grid {
  grid-template-columns: 1fr !important;
  gap: 8px;
}

/* ─── 중앙: lazy 페이지 ─── */

.viewer-col-center {
  min-width: 0;
}
.viewer-pages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  padding: 14px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  min-height: 200px;
}
.viewer-page-wrap {
  position: relative;
  display: inline-block;
  /* TextLayer 가 absolute → wrapper 가 reference */
}
.viewer-page {
  background: #fff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  border-radius: 2px;
  max-width: 100%;
  height: auto;
  display: block;
}
.viewer-page-num {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 3px;
  font-variant-numeric: tabular-nums;
  z-index: 5;
}
.viewer-page-loading {
  width: 100%;
  height: 600px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 4px;
  color: #888;
  font-size: 13px;
}

/* ─── 우측: 도구창 (도구 리스트 + 패널 swap) ─── */

.viewer-col-right {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 16px;
  position: sticky;
  /* 메인 toolbar (var(--tph) 위치, 높이 ~50px) 바로 아래에서 멈춤 */
  top: calc(var(--tph) + 64px);
  max-height: calc(100vh - var(--tph) - 78px);
  overflow-y: auto;
}

.sidebar-header {
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.sidebar-header h2 {
  margin: 0 0 6px 0;
  font-size: 14px;
  color: #fff;
  font-weight: 600;
}
.sidebar-hint {
  margin: 0;
  font-size: 11px;
  color: #888;
  line-height: 1.5;
}
.sidebar-section { margin-bottom: 16px; }
.sidebar-section:last-of-type { margin-bottom: 8px; }
.section-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #999;
  margin-bottom: 6px;
}
.section-label .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #888;
}
.section-label[data-cat="page"] .dot { background: #4a9eff; }
.section-label[data-cat="content"] .dot { background: #00d4aa; }
.section-label[data-cat="extract"] .dot { background: #ffaa00; }
.section-label[data-cat="misc"] .dot { background: #ff6b9d; }

.tool-list { display: flex; flex-direction: column; gap: 2px; }
.tool-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 6px;
  color: #ddd;
  text-decoration: none;
  font-size: 13px;
  transition: background 0.12s, color 0.12s;
  flex-wrap: wrap;
}
.tool-link:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.tool-link small { color: #777; font-size: 11px; margin-left: auto; }
.tool-link:hover small { color: #aaa; }

/* inline 작동 도구 (v2.0) — 미세 강조 */
.tool-link-inline {
  background: rgba(74, 158, 255, 0.06);
  border-left: 2px solid rgba(74, 158, 255, 0.4);
  padding-left: 8px;
}
.tool-link-inline small {
  color: #4a9eff;
  background: rgba(74, 158, 255, 0.12);
  padding: 1px 6px;
  border-radius: 3px;
  font-weight: 600;
}
.tool-link-active {
  background: rgba(74, 158, 255, 0.18) !important;
  color: #fff !important;
  border-left-color: rgba(74, 158, 255, 0.9) !important;
}

/* ─── 패널 (도구 활성 시 swap) ─── */

.sidebar-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.panel-back-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #ddd;
  font-size: 11px;
  font-weight: 500;
  padding: 5px 9px;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  flex-shrink: 0;
}
.panel-back-btn:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.panel-title {
  display: flex; align-items: center; gap: 6px;
  font-size: 14px; font-weight: 600; color: #fff;
  min-width: 0; overflow: hidden;
}
.panel-title .panel-icon { font-size: 16px; line-height: 1; }
.panel-content { display: flex; flex-direction: column; gap: 12px; }

.panel-content .sidebar-group {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  padding: 10px 12px;
}
.panel-content .sidebar-group h3 {
  margin: 0 0 8px 0;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #aaa;
}

.panel-option-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.panel-option-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 4px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 5px;
  color: #ccc;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.05s;
  min-height: 56px;
}
.panel-option-btn:hover:not(:disabled) {
  background: rgba(74, 158, 255, 0.12);
  border-color: rgba(74, 158, 255, 0.5);
  color: #fff;
}
.panel-option-btn:active:not(:disabled) {
  transform: scale(0.96);
}
.panel-option-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.panel-option-btn.active {
  background: rgba(74, 158, 255, 0.28);
  border-color: rgba(74, 158, 255, 0.95);
  border-width: 1.5px;
  color: #fff;
  box-shadow: 0 0 0 1px rgba(74, 158, 255, 0.35) inset;
}
.panel-option-icon { font-size: 20px; line-height: 1; }
.panel-option-label { font-size: 11px; text-align: center; word-break: keep-all; }

/* 9방향 anchor 격자 (위치 선택용) */
.panel-anchor-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  background: rgba(0, 0, 0, 0.2);
  padding: 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.panel-anchor-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 48px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 5px;
  color: #999;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.panel-anchor-btn:hover {
  background: rgba(74, 158, 255, 0.12);
  border-color: rgba(74, 158, 255, 0.5);
  color: #fff;
}
.panel-anchor-btn.active {
  background: rgba(74, 158, 255, 0.28);
  border-color: rgba(74, 158, 255, 0.95);
  border-width: 1.5px;
  color: #fff;
}
.panel-anchor-btn.active .anchor-dot {
  fill: #4a9eff;
}
.panel-anchor-hint {
  text-align: center;
  font-size: 11px;
  color: #888;
  margin-top: 8px;
}

/* 단일 액션 버튼 (즉시 적용/삭제/다운로드 등) — full-width, 크게 */
.panel-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 14px;
  background: #4a9eff;
  border: 1px solid #4a9eff;
  border-radius: 6px;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.05s;
}
.panel-action-btn:hover:not(:disabled) {
  background: #5fb0ff;
  border-color: #5fb0ff;
}
.panel-action-btn:active:not(:disabled) {
  transform: scale(0.98);
}
.panel-action-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.panel-action-icon { font-size: 16px; line-height: 1; }
.panel-action-danger {
  background: #e85a5a;
  border-color: #e85a5a;
}
.panel-action-danger:hover:not(:disabled) {
  background: #ff7070;
  border-color: #ff7070;
}

.panel-notice {
  padding: 8px 10px;
  border-radius: 5px;
  font-size: 12px;
  line-height: 1.45;
  word-break: keep-all;
}
.panel-notice-info {
  background: rgba(74, 158, 255, 0.1);
  border: 1px solid rgba(74, 158, 255, 0.3);
  color: #cfe6ff;
}
.panel-notice-warn {
  background: rgba(255, 170, 0, 0.08);
  border: 1px solid rgba(255, 170, 0, 0.3);
  color: #ffd88a;
}
.panel-notice-success {
  background: rgba(0, 212, 170, 0.1);
  border: 1px solid rgba(0, 212, 170, 0.3);
  color: #9ff0d8;
}

/* ═════════════════════════════════════ */
/* TextLayer (pdf.js 4.x — 텍스트 드래그 선택)  */
/* ═════════════════════════════════════ */

.pdf-text-layer {
  position: absolute;
  text-align: initial;
  inset: 0;
  overflow: clip;
  opacity: 1;
  line-height: 1.0;
  text-size-adjust: none;
  forced-color-adjust: none;
  transform-origin: 0% 0%;
  caret-color: CanvasText;
  z-index: 2;
}
.pdf-text-layer :is(span, br) {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
}
.pdf-text-layer ::selection {
  background: rgba(74, 158, 255, 0.35);
  color: transparent;
}
/* 정렬 클래스 (pdf.js 가 자동 부여) */
.pdf-text-layer .markedContent { position: relative; }
.pdf-text-layer .endOfContent {
  display: block;
  position: absolute;
  inset: 100% 0 0 0;
  z-index: -1;
  cursor: default;
  user-select: none;
}
