#newTool,
#newTool * {
  box-sizing: border-box;
}
#newTool {
  font-family: system-ui, sans-serif;
  max-width: 980px;
  margin: 40px auto;
  padding: 0 16px;
}
#newTool h1 {
  font-size: 22px;
  margin: 0 0 10px;
}
#newTool .box {
  border: 1px solid #ddd;
  padding: 16px;
  border-radius: 12px;
  background: #fff;
}
#newTool label {
  display: block;
  margin: 0 0 10px;
  font-weight: 900;
}
#newTool .hint {
  color: #666;
  font-size: 13px;
  margin-top: 8px;
  line-height: 1.4;
}
#newTool .small {
  font-size: 12px;
  color: #777;
}
#newTool .hidden {
  display: none !important;
}

/* Dropzone */
#newTool .drop {
  border: 1px dashed #ddd;
  border-radius: 12px;
  cursor: pointer;
  text-align: center;
  padding: 18px;
}
#newTool .drop.hasFiles {
  cursor: default;
  text-align: left;
  padding: 14px;
  border-style: solid;
}
#newTool .drop.isOver {
  border-color: #111;
}

/* Buttons */
#newTool button {
  width: 100%;
  padding: 10px;
  margin-top: 6px;
  cursor: pointer;
  border: 1px solid #ddd;
  border-radius: 10px;
  background: #fff;
}
#newTool button:hover {
  background: #f5f5f5;
}
#newTool button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
#newTool .btnMini {
  width: auto !important;
  padding: 8px 10px !important;
  margin: 0 !important;
  border-radius: 10px;
  white-space: nowrap;
}
#newTool .btnMini:active {
  transform: translateY(1px);
}
#newTool .btnPrimary {
  font-weight: 900;
}

/* Panel header */
#newTool .topRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
#newTool .btnRow {
  display: flex;
  gap: 10px;
}
#newTool .warn {
  color: #c00;
  font-weight: 800;
  margin-left: 8px;
}

/* Layout split */
#newTool .split {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 12px;
  margin-top: 12px;
}
#newTool .subBox {
  border: 1px solid #eee;
  border-radius: 12px;
  padding: 12px;
  background: #fff;
}
#newTool .subTitle {
  font-weight: 900;
  font-size: 13px;
  margin-bottom: 8px;
}
#newTool .subMeta {
  font-weight: 700;
  font-size: 12px;
  color: #666;
  margin-left: 8px;
}

#newTool .row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 10px;
}
#newTool .checkRow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-weight: 700;
  user-select: none;
}
#newTool .checkRow input {
  width: auto !important;
  margin: 0;
}

/* Range row */
#newTool .rangeRow {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}
#newTool .rangeInput {
  flex: 1;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 10px;
  outline: none;
  min-width: 0;
}
#newTool .rangeInput:focus {
  border-color: #111;
}

/* Shared drag handle */
#newTool .dragHandle {
  user-select: none;
  cursor: grab;
  font-weight: 900;
  color: #555;
  width: 28px;
  height: 28px;
  line-height: 26px;
  border: 1px solid #eee;
  border-radius: 10px;
  text-align: center;
  background: #fafafa;
  flex: 0 0 28px;
}

/* PDF list (left) */
#newTool .pdfList {
  display: grid;
  gap: 10px;
}
#newTool .pdfItem {
  border: 1px solid #eee;
  border-radius: 12px;
  padding: 10px;
  background: #fff;
}
#newTool .pdfItem.dropTarget {
  outline: 2px solid #111;
  outline-offset: 2px;
}

#newTool .pdfTop {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  align-items: start;
}
#newTool .pdfRight {
  min-width: 0;
}
#newTool .pdfName {
  font-weight: 900;
  font-size: 13px;
  overflow-wrap: anywhere; /* 파일명만 어디서든 줄바꿈 */
  word-break: normal;
}
#newTool .pdfMeta {
  font-size: 12px;
  color: #666;
  margin-top: 4px;
  word-break: keep-all; /* 한 글자씩 깨지는 현상 방지 */
  overflow-wrap: break-word;
}
#newTool .pdfActions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-top: 8px;
}
#newTool .btnDanger {
  border-color: #f0c1c1;
}

/* Page list (right) */
#newTool .pageList {
  display: grid;
  gap: 10px;
}
#newTool .pageItem {
  border: 1px solid #eee;
  border-radius: 12px;
  padding: 12px;
  background: #fff;
  display: grid;
  grid-template-columns: 28px auto 1fr auto;
  gap: 10px;
  align-items: center;
  transition: all 0.2s;
}
#newTool .pageItem:hover {
  border-color: #ccc;
}
#newTool .pageItem.dragging {
  opacity: 0.55;
  cursor: grabbing;
}
#newTool .pageItem.dragging .dragHandle {
  cursor: grabbing;
}
#newTool .pageItem.dropTarget {
  outline: 2px solid #111;
  outline-offset: 2px;
}

#newTool .pageMain {
  min-width: 0;
}
#newTool .pageTitle {
  font-weight: 900;
  font-size: 13px;
  word-break: keep-all; /* 한 글자씩 깨지지 않게 */
  overflow-wrap: break-word;
}
#newTool .pageTitle .fileWrap {
  overflow-wrap: anywhere; /* 파일명만 어디서든 줄바꿈 허용 */
  word-break: normal;
}
#newTool .pageMeta {
  font-size: 12px;
  color: #666;
  margin-top: 4px;
  word-break: keep-all;
  overflow-wrap: break-word;
}

#newTool .pageActions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* actions bar */
#newTool .actionsBar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

/* Loading bar */
#newTool .bar-wrap {
  height: 10px;
  border: 1px solid #ddd;
  border-radius: 999px;
  overflow: hidden;
}
#newTool .bar {
  height: 100%;
  width: 0%;
  background: #111;
}

/* modal */
#newTool .modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
}
#newTool .modalDim {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}
#newTool .modalBox {
  position: relative;
  max-width: 820px;
  max-height: 90vh;
  margin: 40px auto;
  background: #fff;
  border-radius: 14px;
  padding: 14px;
  border: 1px solid #eee;
  overflow-y: auto;
}
#newTool .modalTop {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
#newTool .modalMeta {
  margin-top: 8px;
  font-size: 12px;
  color: #555;
  line-height: 1.35;
}
#newTool .modalBody {
  margin-top: 10px;
}
#previewCanvas {
  width: 100%;
  height: auto;
  border: 1px solid #eee;
  border-radius: 12px;
}

/* moved highlight */
#newTool .pageItem.flash {
  animation: flashMove 850ms ease-out;
}
@keyframes flashMove {
  0% {
    background: #fff7cc;
    border-color: #f2c94c;
    box-shadow: 0 0 0 3px rgba(242, 201, 76, 0.25);
  }
  100% {
    background: #fff;
    border-color: #eee;
    box-shadow: none;
  }
}

/* responsive */
@media (max-width: 860px) {
  #newTool .split {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 520px) {
  #newTool .actionsBar {
    grid-template-columns: 1fr;
  }

  /* ✅ 페이지 카드: 버튼이 왼쪽에 세로로 떨어지는 현상 방지(그리드 영역 배치) */
  #newTool .pageItem {
    grid-template-columns: 28px auto 1fr;
    grid-template-areas:
      "h c t"
      ". . a";
    align-items: start;
  }
  #newTool .pageItem .dragHandle {
    grid-area: h;
  }
  #newTool .pageItem input[type="checkbox"] {
    grid-area: c;
    margin-top: 3px;
  }
  #newTool .pageMain {
    grid-area: t;
  }
  #newTool .pageActions {
    grid-area: a;
    justify-content: flex-start;
    flex-wrap: nowrap; /* 모바일에서 버튼 줄바꿈 최소화 */
  }

  /* 범위 입력 줄바꿈 */
  #newTool .rangeRow {
    flex-direction: column;
    align-items: stretch;
  }
  #newTool .rangeRow button {
    width: 100% !important;
  }

  /* PDF 카드: 액션이 너무 좁아져 글자 깨지는 문제 방지 */
  #newTool .pdfActions {
    justify-content: flex-start;
  }
}
#newTool .spinner {
  width: 28px;
  height: 28px;
  margin: 0 auto 10px;
  border: 3px solid #ddd;
  border-top-color: #111;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
