* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Nanum Gothic", sans-serif;
  background: #f4f6fb;
  color: #1f2937;
}

body {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 350px;
  grid-template-rows: 64px minmax(0, 1fr);
  grid-template-areas:
    "topbar topbar topbar"
    "leftbar main rightbar";
  height: 100vh;
  overflow: hidden;
}

/* =========================
   상단바
========================= */
#topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: #ffffff;
  border-bottom: 1px solid #dbe2ea;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  z-index: 20;
}

#topbar::-webkit-scrollbar {
  height: 8px;
}

#topbar::-webkit-scrollbar-thumb {
  background: #c9d3df;
  border-radius: 999px;
}

#topbar input[type="file"],
#topbar select,
#topbar input[type="number"],
#topbar button {
  height: 38px;
  border: 1px solid #d6deea;
  border-radius: 10px;
  background: #fff;
  padding: 0 12px;
  font-size: 14px;
  color: #1f2937;
}

#topbar input[type="file"] {
  padding: 6px 10px;
}

#topbar button {
  cursor: pointer;
  transition: 0.15s ease;
}

#topbar button:hover {
  background: #f3f7fc;
}

#topbar .tool.active {
  background: #2b6cff;
  color: #fff;
  border-color: #2b6cff;
}

.color-pair {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  height: 38px;
  border: 1px solid #d6deea;
  border-radius: 10px;
  background: #fff;
}

.color-pair span {
  font-size: 13px;
  color: #4b5563;
}

.color-pair input[type="color"] {
  width: 28px;
  height: 28px;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

.icon-btn {
  width: 40px;
  padding: 0 !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn img {
  width: 18px;
  height: 18px;
  object-fit: contain;
}

/* =========================
   왼쪽 썸네일 바
========================= */
#leftbar {
  grid-area: leftbar;
  width: 280px;
  min-width: 280px;
  max-width: 280px;
  background: #eef3f8;
  border-right: 1px solid #dbe2ea;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#thumbnails {
  flex: 1;
  width: 100%;
  height: 100%;
  overflow-x: auto;
  overflow-y: auto;
  padding: 12px;
  box-sizing: border-box;
  scroll-behavior: smooth;

  display: flex;
  flex-direction: column;
  align-items: center;   /* 썸네일 가운데 정렬 */
}

#thumbnails::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

#thumbnails::-webkit-scrollbar-thumb {
  background: #c7d2df;
  border-radius: 999px;
}

#thumbnails::-webkit-scrollbar-corner {
  background: transparent;
}

#thumbnails {
  flex: 1;
  width: 100%;
  height: 100%;
  overflow-x: auto;
  overflow-y: auto;
  padding: 12px;
  box-sizing: border-box;
  scroll-behavior: smooth;

  display: flex;
  flex-direction: column;
  align-items: center;   /* 썸네일 가운데 정렬 */
}

.thumb-item:hover {
  background: #f7faff;
}

.thumb-item.thumb-selected {
  border-color: #2b6cff;
  box-shadow: 0 0 0 3px rgba(43, 108, 255, 0.14);
}

.thumb-item.dragging {
  opacity: 0.5;
}

.thumb-item.drag-over-top::before,
.thumb-item.drag-over-bottom::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  height: 3px;
  background: #2b6cff;
  border-radius: 999px;
  z-index: 3;
}

.thumb-item.drag-over-top::before {
  top: -3px;
}

.thumb-item.drag-over-bottom::after {
  bottom: -3px;
}

.thumb-item canvas {
  display: block;
  max-width: none;   /* 가로 페이지 축소 강제 금지 */
  height: auto;
  border-radius: 8px;
  background: #fff;
  margin: 0 auto;
}

.thumb-label {
  display: block;
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.4;
  color: #4b5563;
  white-space: normal;
  word-break: break-word;
  text-align: center;
}

/* =========================
   메인 뷰어
========================= */
#main {
  grid-area: main;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  background: #e9eef5;
  position: relative;
}

#main::-webkit-scrollbar {
  width: 11px;
  height: 11px;
}

#main::-webkit-scrollbar-thumb {
  background: #c2ccd8;
  border-radius: 999px;
}

#viewer {
  padding: 24px 20px 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.page-wrap {
  position: relative;
  background: #fff;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.10);
  border-radius: 12px;
  padding: 0;
  overflow: visible;
}

.pdf-canvas {
  display: block;
  border-radius: 12px;
  background: #fff;
}

.overlay-layer {
  position: absolute;
  top: 0;
  left: 0;
}

/* =========================
   오브젝트 공통
========================= */
.ov-elt {
  box-sizing: border-box;
}

.ov-selected {
  outline: 2px solid #2b6cff;
  outline-offset: 1px;
}

.ov-text {
  min-width: 80px;
  min-height: 24px;
  line-height: 1.35;
  border-radius: 4px;
}

.ov-text:focus {
  outline: 2px solid rgba(43, 108, 255, 0.35);
}

.ov-rect {
  min-width: 10px;
  min-height: 10px;
}

/* 리사이즈 핸들 */
.ov-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #2b6cff;
  border: 2px solid #fff;
  border-radius: 50%;
  z-index: 5;
}

.ov-handle.tl { top: -6px; left: -6px; cursor: nwse-resize; }
.ov-handle.tr { top: -6px; right: -6px; cursor: nesw-resize; }
.ov-handle.bl { bottom: -6px; left: -6px; cursor: nesw-resize; }
.ov-handle.br { bottom: -6px; right: -6px; cursor: nwse-resize; }

/* =========================
   오른쪽 광고 바
========================= */
#rightbar {
  grid-area: rightbar;
  background: #f8fafc;
  border-left: 1px solid #dbe2ea;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px;
}

#rightbar::-webkit-scrollbar {
  width: 10px;
}

#rightbar::-webkit-scrollbar-thumb {
  background: #c7d2df;
  border-radius: 999px;
}

.pdf_left_ad {
  background: #fff;
  border: 1px solid #e4eaf1;
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 12px;
  overflow: hidden;
}

/* =========================
   확대/축소 버튼
========================= */
#zoomControls {
  position: fixed;
  right: 278px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 30;
}

#zoomControls button {
  width: 44px;
  height: 44px;
  border: 1px solid #d6deea;
  border-radius: 12px;
  background: #fff;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12);
}

#zoomControls button:hover {
  background: #f3f7fc;
}

/* =========================
   모달
========================= */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 1000;
}

.modal-content {
  position: relative;
  max-width: 700px;
  margin: 60px auto;
  background: #fff;
  border-radius: 16px;
  padding: 24px 24px 18px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.20);
}

.modal-content h2 {
  margin-top: 0;
  margin-bottom: 14px;
}

.modal-content ul {
  margin: 0;
  padding-left: 18px;
  line-height: 1.7;
}

#helpClose {
  position: absolute;
  right: 16px;
  top: 12px;
  font-size: 28px;
  cursor: pointer;
  color: #6b7280;
}

/* =========================
   우클릭 메뉴
========================= */
.thumb-context-menu {
  display: none;
  position: absolute;
  z-index: 9999;
  min-width: 190px;
  background: #ffffff;
  border: 1px solid #d9e1ec;
  border-radius: 12px;
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.16);
  padding: 8px;
}

.thumb-context-menu button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: #1f2937;
}

.thumb-context-menu button:hover {
  background: #f3f6fb;
}


/* =========================
   삭제 표시 상태
========================= */
.thumb-item.thumb-deleted {
  opacity: 0.42;
  filter: grayscale(100%);
  background: #e5e7eb;
}

.thumb-item.thumb-deleted::after {
  content: "삭제 예정";
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(55, 65, 81, 0.92);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 6px 8px;
  border-radius: 999px;
  z-index: 5;
  pointer-events: none;
}

.page-wrap.page-deleted {
  opacity: 0.45;
  filter: grayscale(100%);
}

.page-wrap.page-deleted::after {
  content: "삭제 예정";
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(55, 65, 81, 0.92);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  padding: 7px 10px;
  border-radius: 999px;
  z-index: 15;
  pointer-events: none;
}

#btnDeleteMark:disabled,
#btnRestore:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
/* =========================
   저장 중
========================= */
body.exporting {
  cursor: progress;
}

/* =========================
   반응형
========================= */
@media (max-width: 1400px) {
  body {
    grid-template-columns: 300px minmax(0, 1fr) 220px;
  }

  #leftbar {
    width: 300px;
    min-width: 300px;
    max-width: 300px;
  }

  #zoomControls {
    right: 235px;
  }
}

@media (max-width: 1100px) {
  body {
    grid-template-columns: 280px minmax(0, 1fr);
    grid-template-areas:
      "topbar topbar"
      "leftbar main";
  }

  #rightbar {
    display: none;
  }

  #zoomControls {
    right: 18px;
  }
}

@media (max-width: 768px) {
  body {
    grid-template-columns: 1fr;
    grid-template-rows: 64px 220px minmax(0, 1fr);
    grid-template-areas:
      "topbar"
      "leftbar"
      "main";
  }

  #leftbar {
    width: 100%;
    min-width: 0;
    max-width: none;
    border-right: 0;
    border-bottom: 1px solid #dbe2ea;
  }

  #rightbar {
    display: none;
  }

  #zoomControls {
    right: 18px;
    bottom: 18px;
  }

  .modal-content {
    margin: 20px 12px;
    max-width: none;
  }
}


.loading-overlay{
  position:fixed;
  inset:0;
  display:none;
  align-items:center;
  justify-content:center;
  background:rgba(15,23,42,.35);
  z-index:9999;
  backdrop-filter:blur(2px);
}

.loading-overlay.show{
  display:flex;
}

.loading-box{
  min-width:220px;
  max-width:320px;
  padding:20px 24px;
  border-radius:16px;
  background:#fff;
  box-shadow:0 12px 40px rgba(0,0,0,.18);
  text-align:center;
  font-size:15px;
  color:#111827;
}

.loading-spinner{
  width:36px;
  height:36px;
  margin:0 auto 12px;
  border:4px solid #e5e7eb;
  border-top-color:#2563eb;
  border-radius:50%;
  animation:spin .9s linear infinite;
}

@keyframes spin{
  to{ transform:rotate(360deg); }
}

.toast{
  position:fixed;
  left:50%;
  bottom:28px;
  transform:translateX(-50%) translateY(20px);
  opacity:0;
  pointer-events:none;
  z-index:10000;
  background:#111827;
  color:#fff;
  padding:12px 16px;
  border-radius:12px;
  font-size:14px;
  box-shadow:0 10px 28px rgba(0,0,0,.2);
  transition:.22s ease;
}

.toast.show{
  opacity:1;
  transform:translateX(-50%) translateY(0);
}

.ov-elt.ov-selected{
  outline:2px solid #2563eb;
  outline-offset:2px;
}

.ov-handle{
  width:10px;
  height:10px;
  border-radius:50%;
  background:#2563eb;
  border:2px solid #fff;
  box-shadow:0 2px 8px rgba(0,0,0,.18);
}

.ov-line .ov-handle.tr{
  right:-7px;
  top:-7px;
}

.ov-text{
  min-height:24px;
}

.ov-text:hover,
.ov-rect:hover,
.ov-line:hover{
  box-shadow:0 0 0 1px rgba(37,99,235,.18);
}