/* ── 폰트 (Cedarville + NanumSquareNeo 자체 호스팅) ───────── */
@font-face {
  font-family: 'Cedarville Cursive';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/CedarvilleCursive-Regular.ttf') format('truetype');
}
@font-face {
  font-family: 'NanumSquareNeo';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/NanumSquareNeo-bRg.ttf') format('truetype');
}

/* ── PDF 서명 페이지 자체 변수 (tools 배색과 통합) ───────── */
.pdfsign-shell {
  --c-black:        #111111;
  --c-white:        #ffffff;
  --c-bg:           #f7f7f7;
  --c-surface:      #ffffff;
  --c-text:         #111111;
  --c-text-lt:      #333333;
  --c-text-muted:   #888888;
  --c-border:       #dddddd;
  --c-border-dk:    #bbbbbb;
  --c-primary:      #00A651;
  --c-primary-dk:   #008C45;
  --c-primary-lt:   #33b973;
  --c-primary-bg:   #e8f5ee;
  --c-success:      #00A651;
  --c-danger:       #dc3545;
  --c-text:         #111;
}

/* 메인 레이아웃 (tools-layout 안에서) */
.pdfsign-shell {
  margin-bottom: 0;
  height: calc(100vh - 200px);
  min-height: 540px;
  overflow: hidden;
  border: 1px solid var(--c-border);
  background: var(--c-white);
  border-radius: var(--radius-md, 8px);
}
.pdfsign-shell .card-body {
  padding: 0;
  display: flex;
  height: 100%;
}

/* ── 좌측 서명 패널 ─────────────────────── */
.pdfsign-shell .signature-panel {
  width: 240px;
  border-right: 1px solid var(--c-border);
  background: var(--c-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.signature-panel-header {
  padding: 12px;
  border-bottom: 1px solid var(--c-border);
  background: var(--c-white);
}
.signature-panel-header .panel-title {
  font-weight: 700;
  font-size: 12px;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #000;
}
.signature-panel-header .btn-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

#signature-list {
  overflow-y: auto;
  flex: 1;
  padding: 8px;
}

/* 서명 카드 */
.sig-card {
  border: 1px solid var(--c-border);
  background: var(--c-white);
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
}
.sig-card.is-default {
  border-color: var(--c-primary);
  border-width: 2px;
}
.sig-thumb {
  background: #fff;
  background-image:
    linear-gradient(45deg, #f0f0f0 25%, transparent 25%),
    linear-gradient(-45deg, #f0f0f0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f0f0f0 75%),
    linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0px;
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  border-bottom: 1px solid var(--c-border);
  user-select: none;
}
.sig-thumb:active { cursor: grabbing; }
.sig-thumb img {
  max-height: 60px;
  max-width: 90%;
  pointer-events: none;
  display: block;
}
.sig-meta {
  padding: 5px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}
.sig-name {
  font-size: 12px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
.sig-source {
  font-size: 10px;
  color: var(--c-text-muted);
  margin-left: 4px;
  font-weight: 400;
}
.sig-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}
.btn-icon {
  background: transparent;
  border: 1px solid var(--c-border);
  color: var(--c-text-lt);
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 11px;
  padding: 0;
  border-radius: 0;
}
.btn-icon:hover {
  background: var(--c-bg);
  color: var(--c-text);
}
.btn-icon-danger:hover {
  background: var(--c-danger);
  border-color: var(--c-danger);
  color: #fff;
}

/* ── 우측 PDF 영역 ───────────────────────── */
.pdfsign-shell .pdf-area {
  flex: 1;
  background: var(--c-bg);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* 드롭존 */
.pdf-dropzone {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin: 14px;
  border: 2px dashed var(--c-border);
  transition: background 0.15s, border-color 0.15s;
  user-select: none;
}
.pdf-dropzone:hover, .pdf-dropzone.dragover {
  background: var(--c-primary-bg);
  border-color: var(--c-primary);
}
.dropzone-inner { text-align: center; padding: 30px; }
.dropzone-inner i {
  font-size: 56px;
  color: var(--c-text-muted);
  display: block;
  opacity: 0.6;
}
.pdf-dropzone:hover .dropzone-inner i,
.pdf-dropzone.dragover .dropzone-inner i { color: var(--c-primary); opacity: 1; }
.dropzone-title {
  font-size: 16px;
  font-weight: 700;
  margin: 12px 0 6px;
  color: var(--c-text);
}
.dropzone-hint {
  font-size: 12px;
  color: var(--c-text-muted);
}

/* PDF 뷰어 */
.pdf-viewer {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--c-bg);
  min-height: 0;
}
.pdf-toolbar {
  padding: 6px 10px;
  background: var(--c-white);
  border-bottom: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.pdf-toolbar .pdf-info {
  font-size: 12px;
  font-weight: 600;
  padding: 0 6px;
  min-width: 50px;
  text-align: center;
  color: var(--c-text);
}
.pdf-toolbar .pdf-filename {
  font-size: 11px;
  color: var(--c-text-muted);
  margin-left: auto;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pdf-toolbar .separator {
  width: 1px;
  height: 18px;
  background: var(--c-border);
  margin: 0 3px;
}
.pdf-toolbar .btn-sm {
  font-size: 12px;
  padding: 3px 8px;
  min-height: 28px;
}

.pdf-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

.pdf-thumbs {
  width: 110px;
  background: #1a1a1a;
  overflow-y: auto;
  padding: 6px;
  flex-shrink: 0;
  scrollbar-width: thin;
  scrollbar-color: #444 #1a1a1a;
}
.pdf-thumbs::-webkit-scrollbar { width: 6px; }
.pdf-thumbs::-webkit-scrollbar-track { background: #1a1a1a; }
.pdf-thumbs::-webkit-scrollbar-thumb { background: #444; }

.thumb {
  margin-bottom: 6px;
  cursor: pointer;
  border: 2px solid transparent;
  background: #fff;
  position: relative;
  display: block;
  transition: border-color 0.12s;
}
.thumb canvas {
  display: block;
  max-width: 100%;
  height: auto;
}
.thumb:hover { border-color: var(--c-primary-lt); }
.thumb.active { border-color: var(--c-primary); }
.thumb-label {
  position: absolute;
  bottom: 2px; right: 4px;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  background: rgba(0,0,0,0.65);
  padding: 1px 5px;
  letter-spacing: 0.05em;
}
.thumb-count {
  position: absolute;
  top: 2px; left: 2px;
  background: var(--c-primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 0;
  z-index: 1;
}

.pdf-main {
  flex: 1;
  overflow: auto;
  background: #2a2a2a;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
  scrollbar-width: thin;
  scrollbar-color: #555 #2a2a2a;
}
.pdf-main::-webkit-scrollbar { width: 10px; height: 10px; }
.pdf-main::-webkit-scrollbar-track { background: #2a2a2a; }
.pdf-main::-webkit-scrollbar-thumb { background: #555; }

.pdf-page-wrapper {
  position: relative;
  display: inline-block;
  flex-shrink: 0;
}
.pdf-page-wrapper.dragover {
  outline: 3px dashed var(--c-primary);
  outline-offset: -3px;
}

#pdf-canvas {
  background: #fff;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  display: block;
  max-width: none;
}

/* placement layer + 박스 */
.placements-layer {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}
.sig-placement {
  position: absolute;
  pointer-events: auto;
  cursor: move;
  user-select: none;
  border: 1px dashed transparent;
  background: transparent;
  box-sizing: border-box;
  transition: border-color 0.1s, box-shadow 0.1s;
}
.sig-placement img {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  object-fit: contain;
}
.sig-placement:hover {
  border-color: rgba(0, 166, 81, 0.5);
}
.sig-placement.selected {
  border-color: var(--c-primary);
  border-style: solid;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.6), 0 0 8px rgba(0,166,81,0.5);
}
.sig-placement .handles { display: none; }
.sig-placement.selected .handles { display: block; }

.handle {
  position: absolute;
  width: 11px; height: 11px;
  background: #fff;
  border: 2px solid var(--c-primary);
  pointer-events: auto;
  z-index: 2;
  box-sizing: border-box;
}
.handle.nw { top: -6px; left: -6px;  cursor: nwse-resize; }
.handle.ne { top: -6px; right: -6px; cursor: nesw-resize; }
.handle.sw { bottom: -6px; left: -6px;  cursor: nesw-resize; }
.handle.se { bottom: -6px; right: -6px; cursor: nwse-resize; }

.placement-del {
  position: absolute;
  top: -11px; right: -11px;
  width: 20px; height: 20px;
  background: var(--c-danger);
  color: #fff;
  border: 2px solid #fff;
  font-size: 13px;
  line-height: 1;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: auto;
  z-index: 3;
  font-weight: 700;
}
.sig-placement.selected .placement-del { display: flex; }
.placement-del:hover { background: #b02a37; }

/* 툴바 카운트 */
.pdf-count {
  font-size: 10px;
  font-weight: 700;
  color: var(--c-primary-dk);
  background: var(--c-primary-bg);
  padding: 3px 7px;
  border: 1px solid var(--c-primary);
  letter-spacing: 0.04em;
}

/* ── 그리기 캔버스 ─────────────── */
.sig-canvas {
  width: 100%;
  height: 300px;
  border: 1px solid var(--c-border);
  background: #fff;
  touch-action: none;
  cursor: crosshair;
  display: block;
}

/* ── 풀스크린 그리기 ──────────────── */
.draw-fullscreen {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100vw;
  height: 100vh;
  background: #fff;
  z-index: 9999;
  flex-direction: column;
}
.draw-fullscreen.open { display: flex; }
.draw-fullscreen .toolbar {
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--c-border);
  background: var(--c-bg);
  flex-shrink: 0;
}
.draw-fullscreen .toolbar input[type="text"] {
  flex: 1;
  min-width: 0;
}
.draw-fullscreen canvas {
  flex: 1;
  width: 100%;
  touch-action: none;
  cursor: crosshair;
  background: #fff;
  display: block;
}
.draw-fullscreen .hint {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: #fff;
  background: rgba(0,0,0,0.55);
  padding: 5px 12px;
  pointer-events: none;
}

/* hint-text 작은 안내 */
.hint-text {
  font-size: 11px;
  color: var(--c-text-muted);
  margin-top: 4px;
  font-weight: 500;
}

/* ── 모바일/태블릿 ─────────────── */
@media (max-width: 991px) {
  .pdfsign-shell { height: calc(100vh - 200px); }
  .pdfsign-shell .card-body { flex-direction: column; }
  .pdfsign-shell .signature-panel {
    width: 100%;
    height: 200px;
    border-right: none;
    border-bottom: 1px solid var(--c-border);
  }
  #signature-list {
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 8px;
  }
  .sig-card {
    min-width: 130px;
    margin-bottom: 0;
    flex-shrink: 0;
  }
}

/* tools-layout 안에서는 tools max-width 풀어서 더 넓게 */
@media (min-width: 1200px) {
  body .tools-layout:has(.pdfsign-shell) {
    max-width: 1500px;
  }
}
