/* ==========================================================
   딱보(Ttakbo) - 악보 이미지 규격 배치 편집기
   레이아웃: 상단 바 / 왼쪽 페이지 목록 / 가운데 캔버스 / 오른쪽 속성 패널 / 아래 대기열
   톤: 어두운 상단 바 + 옅은 회청색 패널 + 흰 카드, 인디고 포인트
   ========================================================== */
:root {
  --canvas: #dfe3eb;        /* 작업 영역 (흰 종이가 도드라지도록 한 톤 어둡게) */
  --surface: #f3f5f9;       /* 사이드 패널 */
  --card: #ffffff;
  --line: #e1e5ec;
  --line-strong: #cbd2dd;
  --text: #182031;
  --muted: #667085;
  --subtle: #98a2b3;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-weak: #eef0ff;
  --accent-ring: rgba(79, 70, 229, .22);
  --ok: #16a34a;
  --ok-weak: #dcfce7;
  --warn-weak: #fff7e0;
  --danger: #e5484d;
  --topbar: #151a26;
  --topbar-2: #222a3b;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 18px 48px rgba(16, 24, 40, .22);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Pretendard Variable", Pretendard, "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
.spacer { flex: 1; }
.i { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#i-more circle { fill: currentColor; }

/* ---------- 레이아웃 ---------- */
.app {
  display: grid;
  height: 100vh;
  grid-template-columns: 136px minmax(0, 1fr) 300px;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "top   top  top"
    "pages main insp"
    "queue queue queue";
}
.topbar { grid-area: top; }
.pagelist { grid-area: pages; }
.workspace { grid-area: main; }
.inspector { grid-area: insp; }
.queue { grid-area: queue; }

/* ---------- 버튼 ---------- */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--card);
  box-shadow: var(--shadow-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s, box-shadow .12s;
}
button:hover:not(:disabled), .btn:hover { background: #f6f7fa; border-color: #b6bfcd; }
button:active:not(:disabled) { transform: translateY(.5px); }
button:focus-visible, .btn:focus-within, input:focus-visible, select:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.block { width: 100%; margin-bottom: 6px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button.toggle[aria-pressed="true"] { background: var(--accent-weak); border-color: var(--accent); color: var(--accent); font-weight: 600; }
button.subtle-danger { color: var(--danger); }
button.subtle-danger:hover:not(:disabled) { background: #fff1f1; border-color: #f3b4b6; }
.icon-btn { width: 34px; padding: 0; }
.icon-btn.sm { width: 28px; height: 28px; }

/* ---------- 입력 ---------- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 8px; font-size: 12px; font-weight: 500; color: var(--muted); flex: 1; min-width: 0; }
.field input, .field select, select.input {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-size: 14px;
}
select.input { margin-bottom: 8px; }
.field input:focus, .field select:focus, select.input:focus { border-color: var(--accent); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.field-row { display: flex; gap: 8px; margin-bottom: 6px; }
.field-row > button { flex: 1; min-width: 0; }
.field-row.compact { gap: 6px; }
.field-row.compact .field { font-size: 11px; }
.field-row.compact input { padding: 0 6px; font-size: 13px; }
.hint { margin: 8px 0 0; font-size: 12px; line-height: 1.55; color: var(--muted); }
.sub-title { margin: 14px 0 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.checks { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 10px; font-size: 13px; }
.checks label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.checks.two-col { display: grid; grid-template-columns: 1fr 1fr; margin: 12px 0; }
input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }
.badge { display: inline-block; min-width: 22px; padding: 1px 8px; border-radius: 999px; background: var(--accent-weak); color: var(--accent); font-size: 12px; font-weight: 700; text-align: center; }

/* 스위치 (문서 표시 옵션) */
.switch-row { justify-content: space-between; padding: 2px 0; }
input.switch {
  appearance: none;
  position: relative;
  width: 34px;
  height: 20px;
  margin: 0;
  border-radius: 999px;
  background: var(--line-strong);
  cursor: pointer;
  transition: background .15s;
}
input.switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
  transition: transform .15s;
}
input.switch:checked { background: var(--accent); }
input.switch:checked::after { transform: translateX(14px); }

/* 세그먼트 */
.seg { display: flex; gap: 2px; padding: 3px; border-radius: 9px; background: #e8ebf1; }
.seg button { flex: 1; height: 28px; border: 0; border-radius: 7px; background: transparent; box-shadow: none; color: var(--muted); }
.seg button:hover:not(:disabled) { background: rgba(255, 255, 255, .6); }
.seg button.active { background: var(--card); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

/* 카드 */
.card {
  margin-bottom: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow-sm);
}
.card-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; font-size: 13px; font-weight: 700; color: var(--text); }
.card-title output { color: var(--accent); }
.fold { padding: 0; }
.fold summary { display: flex; align-items: center; gap: 8px; padding: 12px; cursor: pointer; list-style: none; }
.fold summary .card-title { margin: 0; }
.fold summary::-webkit-details-marker { display: none; }
.fold summary::after { content: ''; width: 7px; height: 7px; margin-left: auto; border-right: 2px solid var(--subtle); border-bottom: 2px solid var(--subtle); transform: rotate(-45deg); transition: transform .15s; }
.fold[open] summary::after { transform: rotate(45deg); }
.fold > :not(summary) { margin: 0 12px 12px; }
.fold-note { color: var(--muted); font-size: 12px; }

.pins { display: flex; gap: 6px; }
.pins:empty { display: none; }
.pins-col { flex-direction: column; padding: 0 10px 8px; }
.pins-col button { font-size: 12px; height: 30px; }
.pins-row { flex-wrap: wrap; margin-bottom: 10px; }
.pins-row button { flex: 1; font-size: 12px; }

/* ---------- 상단 바 (어두운 톤) ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--topbar);
  color: #e6e9f0;
}
.topbar button, .topbar .btn {
  border-color: rgba(255, 255, 255, .1);
  background: var(--topbar-2);
  box-shadow: none;
  color: #e6e9f0;
}
.topbar button:hover:not(:disabled) { background: #2d3750; border-color: rgba(255, 255, 255, .18); }
.topbar button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.topbar button.primary:hover:not(:disabled) { background: #5b53f0; }
.topbar button.toggle[aria-pressed="true"] { background: #eef0ff; border-color: #eef0ff; color: var(--accent); }
.brand { display: flex; align-items: center; gap: 7px; margin-right: 6px; font-size: 17px; font-weight: 800; letter-spacing: -0.4px; color: #fff; }
.brand-mark { display: block; width: 28px; height: 28px; }
a.brand { text-decoration: none; }
.title-input {
  flex: 0 1 340px;
  min-width: 120px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: rgba(255, 255, 255, .07);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}
.title-input::placeholder { color: #8b93a7; }
.title-input:hover { background: rgba(255, 255, 255, .1); }
.title-input:focus { outline: none; border-color: #6d65ff; background: rgba(255, 255, 255, .12); }
.save-status { font-size: 12px; color: #9aa3b5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
.save-status.dirty { color: #fbbf24; }
.save-status.error { color: #ff8a8d; }
.tb-sep { width: 1px; height: 22px; background: rgba(255, 255, 255, .14); margin: 0 2px; }
.drawer-btn { display: none !important; }

/* ---------- 왼쪽: 페이지 목록 ---------- */
.pagelist {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.pl-head { display: flex; align-items: center; gap: 4px; padding: 12px 10px 8px 14px; font-size: 13px; }
.thumbs { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px 10px 16px; }
.thumb {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 8px 4px 6px;
  border: 2px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
  touch-action: pan-y;
  transition: background .12s;
}
.thumb:hover { background: #e7eaf1; }
.thumb.current { border-color: var(--accent); background: var(--accent-weak); }
.thumb.dragging { opacity: .4; }
.thumb .page { box-shadow: 0 1px 4px rgba(16, 24, 40, .18); outline: 0 !important; pointer-events: none; }
.thumb .grid { gap: 1px; }
.thumb .cell { border: 0; background: #eef1f5; }
.thumb .cell.filled { background: #fff; }
.thumb .cell::after, .thumb .gutter { display: none; }
.thumb-num { font-size: 12px; font-weight: 600; color: var(--muted); }
.thumb.current .thumb-num { color: var(--accent); }
.thumb.drop-before::before, .thumb.drop-after::after {
  content: '';
  position: absolute;
  left: 4px;
  right: 4px;
  height: 3px;
  border-radius: 2px;
  background: var(--accent);
}
.thumb.drop-before::before { top: -7px; }
.thumb.drop-after::after { bottom: -7px; }

/* ---------- 가운데: 캔버스 ---------- */
.workspace { position: relative; min-width: 0; min-height: 0; overflow: auto; padding: 0 28px 28px; background: var(--canvas); }
.pages { display: flex; flex-direction: column; align-items: center; gap: 28px; padding-top: 20px; }
.numbering-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 -28px;
  padding: 8px 16px;
  background: var(--warn-weak);
  border-bottom: 1px solid #f5d77a;
  font-size: 13px;
}
.numbering-bar b { display: inline-block; min-width: 22px; padding: 1px 7px; border-radius: 999px; background: var(--text); color: #fff; text-align: center; }
.sel-toolbar {
  position: absolute;
  z-index: 4;
  display: flex;
  gap: 4px;
  padding: 4px;
  transform: translateX(-50%);
  border-radius: 10px;
  background: var(--topbar);
  box-shadow: var(--shadow-lg);
}
.sel-toolbar button { height: 30px; border: 0; background: transparent; box-shadow: none; color: #fff; }
.sel-toolbar button:hover:not(:disabled) { background: rgba(255, 255, 255, .14); }

/* ---------- 페이지(용지) ----------
   크기는 모두 mm 단위 값 × --mm(화면에서는 1mm에 해당하는 px, 인쇄에서는 1mm)로 계산한다 */
.page-wrap { display: flex; flex-direction: column; align-items: center; gap: 7px; }
.page-label { font-size: 12px; font-weight: 500; color: var(--muted); user-select: none; }
.page-wrap.current .page-label { color: var(--accent); font-weight: 700; }
.page {
  --mm: 1px;
  display: flex;
  flex-direction: column;
  width: calc(var(--wmm) * var(--mm));
  height: calc(var(--hmm) * var(--mm));
  padding: calc(var(--mt) * var(--mm)) calc(var(--mr) * var(--mm)) calc(var(--mb) * var(--mm)) calc(var(--ml) * var(--mm));
  background: #fff;
  box-shadow: 0 2px 6px rgba(16, 24, 40, .08), 0 12px 32px rgba(16, 24, 40, .12);
  overflow: hidden;
  outline: 2px solid transparent;
  outline-offset: 4px;
  border-radius: 2px;
}
.page-wrap.current .page { outline-color: var(--accent); }

.doc-title {
  flex: none;
  padding-bottom: calc(4 * var(--mm));
  font-size: calc(7 * var(--mm));
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  word-break: keep-all;
}
.page-header, .page-footer {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  height: calc(7 * var(--mm));
  font-size: calc(3.2 * var(--mm));
  color: #555;
  white-space: nowrap;
  overflow: hidden;
}
.page-header { margin-bottom: calc(2 * var(--mm)); }
.page-footer { margin-top: calc(2 * var(--mm)); }

.grid { position: relative; flex: 1; min-height: 0; display: grid; gap: 3px; }
.cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow: hidden;
  container-type: size;
  border: 1px dashed #b4bdcc;
  border-radius: 2px;
  background: #f6f8fb;
  user-select: none;
}
.cell[data-ha="left"] { justify-content: flex-start; }
.cell[data-ha="right"] { justify-content: flex-end; }
.cell[data-va="middle"] { align-items: center; }
.cell[data-va="bottom"] { align-items: flex-end; }

/* 기본: 자른 영역의 비율(--ar)을 유지하며 칸 안에 최대로 맞추고(가로 폭 우선), --s 배율 적용
   free: 비율과 상관없이 칸 대비 가로(--fw)·세로(--fh) 비율로 늘이고 줄임 */
.pic {
  position: relative;
  flex: none;
  width: calc(var(--s) * min(100cqw, 100cqh * var(--ar)));
  aspect-ratio: var(--ar);
  overflow: hidden;
  cursor: grab;
  touch-action: none; /* 터치로도 끌어 옮길 수 있게 */
}
.pic.free { width: calc(var(--fw) * 100cqw); height: calc(var(--fh) * 100cqh); aspect-ratio: auto; }
.pic img { position: absolute; display: block; max-width: none; pointer-events: none; }

.cell:not(.filled)::after {
  content: attr(data-label);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 20px;
  font-weight: 700;
  color: #c3cad6;
  pointer-events: none;
}
.cell.filled { background: #fff; }
.cell.selected { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--accent-weak); }
.cell.drop-target { outline: 3px solid var(--ok); outline-offset: -3px; background: var(--ok-weak); }
.cell.dragging .pic { opacity: .35; }

/* 칸 경계선 (끌어서 행·열 크기 조절) */
.gutter { position: absolute; z-index: 2; touch-action: none; }
.gutter::after { content: ''; position: absolute; background: var(--accent); border-radius: 2px; opacity: 0; transition: opacity .12s; }
.gutter.row { left: 0; right: 0; height: 10px; margin-top: -5px; cursor: row-resize; }
.gutter.row::after { left: 0; right: 0; top: 4px; height: 2px; }
.gutter.col { top: 0; bottom: 0; width: 10px; margin-left: -5px; cursor: col-resize; }
.gutter.col::after { top: 0; bottom: 0; left: 4px; width: 2px; }
.gutter:hover::after, .gutter.active::after { opacity: 1; }

/* 번호 배지 (이미지 모서리, mm 단위) */
.order-badge {
  --bs: 5.5;
  position: absolute;
  z-index: 1;
  min-width: calc(var(--bs) * var(--mm));
  height: calc(var(--bs) * var(--mm));
  padding: 0 calc(var(--bs) * .22 * var(--mm));
  border-radius: 999px;
  font-size: calc(var(--bs) * .6 * var(--mm));
  font-weight: 700;
  line-height: calc(var(--bs) * var(--mm));
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
}
.order-badge.size-s { --bs: 4.5; }
.order-badge.size-l { --bs: 7; }
.order-badge.pos-tl { top: calc(.8 * var(--mm)); left: calc(.8 * var(--mm)); }
.order-badge.pos-tr { top: calc(.8 * var(--mm)); right: calc(.8 * var(--mm)); }
.order-badge.pos-bl { bottom: calc(.8 * var(--mm)); left: calc(.8 * var(--mm)); }
.order-badge.pos-br { bottom: calc(.8 * var(--mm)); right: calc(.8 * var(--mm)); }
.order-badge.style-solid { background: #111827; color: #fff; }
.order-badge.style-outline {
  border: calc(.35 * var(--mm)) solid #111827;
  background: #fff;
  color: #111827;
  line-height: calc((var(--bs) - .7) * var(--mm));
}
.order-badge.style-plain {
  min-width: 0;
  padding: 0;
  background: transparent;
  color: #111827;
  font-size: calc(var(--bs) * .8 * var(--mm));
}
.label-sample { --mm: 3.6px; position: relative; display: inline-block; height: 22px; min-width: 30px; }
.label-sample .order-badge { top: 0; left: 0; bottom: auto; right: auto; }

/* 선택한 이미지의 크기 조절 핸들: 모서리=비율 유지, 가장자리=자유 */
.rh {
  display: none;
  position: absolute;
  z-index: 3;
  width: 12px;
  height: 12px;
  border: 2px solid var(--accent);
  border-radius: 3px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  touch-action: none;
}
.rh.edge { width: 10px; height: 10px; border-radius: 50%; }
.cell.single .pic { outline: 2px solid var(--accent); outline-offset: -2px; }
.cell.single .rh { display: block; }
.rh[data-c="nw"] { left: 0; top: 0; cursor: nwse-resize; }
.rh[data-c="ne"] { right: 0; top: 0; cursor: nesw-resize; }
.rh[data-c="sw"] { left: 0; bottom: 0; cursor: nesw-resize; }
.rh[data-c="se"] { right: 0; bottom: 0; cursor: nwse-resize; }
.rh[data-c="n"] { left: calc(50% - 5px); top: 0; cursor: ns-resize; }
.rh[data-c="s"] { left: calc(50% - 5px); bottom: 0; cursor: ns-resize; }
.rh[data-c="w"] { left: 0; top: calc(50% - 5px); cursor: ew-resize; }
.rh[data-c="e"] { right: 0; top: calc(50% - 5px); cursor: ew-resize; }
.view-mode .rh, body.numbering .rh, .view-mode .gutter, body.numbering .gutter { display: none !important; }
.view-mode .cell.single .pic, body.numbering .cell.single .pic { outline: 0; }
body.is-resizing, body.is-resizing * { user-select: none; }
.size-tip {
  position: fixed;
  z-index: 1000;
  padding: 5px 9px;
  border-radius: 7px;
  background: var(--topbar);
  color: #fff;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--shadow-lg);
}

.cell-tools { position: absolute; top: 5px; right: 5px; z-index: 4; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.cell:hover .cell-tools { opacity: 1; }
.cell.single .cell-tools { right: 22px; top: 18px; } /* 크기 핸들을 가리지 않도록 */
.cell-tools button, .q-remove {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: rgba(21, 26, 38, .82);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .2);
  color: #fff;
  font-size: 13px;
  line-height: 1;
}
.cell-tools button:hover:not(:disabled) { background: var(--accent); }
.cell-tools .cell-remove:hover:not(:disabled), .q-remove:hover { background: var(--danger) !important; }

/* 번호 매기기 중 */
body.numbering .pic { cursor: pointer; }
body.numbering .cell-tools { display: none; }
body.numbering .cell.filled:hover { outline: 2px solid #f59e0b; outline-offset: -2px; }

/* 미리보기(뷰 모드): 편집용 선과 틈새를 숨긴다 */
.view-mode .grid { gap: 0; }
.view-mode .cell { border: 0; background: transparent; outline: 0; }
.view-mode .cell::after, .view-mode .cell-tools { display: none; }
.view-mode .pic { cursor: default; }
.view-mode .page-wrap.current .page { outline-color: transparent; }

/* ---------- 오른쪽: 속성 패널 ---------- */
.inspector {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-left: 1px solid var(--line);
}
.tabs { display: flex; gap: 2px; margin: 12px 12px 4px; padding: 3px; border-radius: 10px; background: #e5e8ef; }
.tabs button {
  flex: 1;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  box-shadow: none;
  color: var(--muted);
  font-weight: 600;
}
.tabs button:hover:not(:disabled) { background: rgba(255, 255, 255, .6); }
.tabs button.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.tab-panel { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 12px 20px; }
.panel-head { display: flex; align-items: center; gap: 6px; margin: 2px 2px 10px; font-size: 14px; }
.panel-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-note { margin: 40px 10px; color: var(--muted); font-size: 13px; line-height: 1.7; text-align: center; }
.cell-preview { display: flex; justify-content: center; margin-bottom: 10px; padding: 8px; border-radius: 8px; background: #f3f5f9; }
.cell-preview img { max-width: 100%; max-height: 110px; object-fit: contain; }

/* 패널 아래 고정 광고 (버튼과 간격을 두고, 채워지지 않거나 화면이 낮으면 숨김) */
.inspector-ad {
  flex: none;
  max-height: 300px;
  margin: 0 12px 12px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  overflow: hidden;
  text-align: center;
}
.inspector-ad .ad-label { display: block; margin-bottom: 4px; color: var(--subtle); font-size: 11px; letter-spacing: .5px; }
.inspector-ad:has(ins[data-ad-status="unfilled"]) { display: none; }
@media (max-height: 819px) { .inspector-ad { display: none; } }

/* ---------- 아래: 대기열 ---------- */
.queue { background: var(--surface); border-top: 1px solid var(--line); padding: 10px 14px 12px; }
.queue header { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 8px; }
.queue header strong { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.queue-list {
  display: flex;
  gap: 10px;
  min-height: 122px;
  padding: 8px;
  overflow-x: auto;
  border: 2px dashed var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .5);
}
.queue.drag-over .queue-list, body.file-drag .queue-list { border-color: var(--accent); background: var(--accent-weak); }
.queue-empty { margin: auto; color: var(--muted); text-align: center; line-height: 1.6; }
.q-item {
  position: relative;
  flex: none;
  width: 96px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--card);
  box-shadow: var(--shadow-sm);
  cursor: grab;
  user-select: none;
  touch-action: pan-x;
}
.q-item:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.q-item.dragging { opacity: .35; }
.q-item img { display: block; width: 100%; height: 74px; object-fit: contain; border-radius: 6px; background: #f6f8fb; }
.q-index { position: absolute; top: 7px; left: 7px; padding: 1px 6px; border-radius: 999px; background: rgba(21, 26, 38, .78); color: #fff; font-size: 10px; font-weight: 600; }
.q-name { margin-top: 4px; padding: 0 2px; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-remove { position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; opacity: 0; transition: opacity .15s; }
.q-item:hover .q-remove { opacity: 1; }

/* 끌어 옮기는 중 */
.drag-ghost {
  position: fixed;
  z-index: 1000;
  width: 140px;
  max-height: 140px;
  object-fit: contain;
  transform: translate(-50%, -50%) rotate(-2deg);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow-lg);
  opacity: .92;
  pointer-events: none;
}
body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select: none; }

/* ---------- 팝업 메뉴(⋯) ---------- */
.popup-menu {
  position: fixed;
  z-index: 1500;
  min-width: 210px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  box-shadow: var(--shadow-lg);
}
.popup-menu button { display: flex; width: 100%; height: 34px; justify-content: flex-start; border: 0; background: transparent; box-shadow: none; font-weight: 500; }
.popup-menu button:hover:not(:disabled) { background: #f1f3f8; }
.popup-menu button.danger { color: var(--danger); }
.popup-menu hr { margin: 4px 0; border: 0; border-top: 1px solid var(--line); }

/* ---------- 대화상자 ---------- */
.dialog {
  width: min(620px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  color: var(--text);
}
.dialog-wide { width: min(1000px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(15, 20, 32, .5); backdrop-filter: blur(2px); }
.dialog-form { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; background: var(--card); border-bottom: 1px solid var(--line); border-radius: 14px 14px 0 0; }
.dialog-head h2 { margin: 0; font-size: 17px; }
.dialog-head h2 small { margin-left: 6px; font-size: 13px; font-weight: 400; color: var(--muted); }
.dialog-tabs { margin: 12px 18px 0; align-self: flex-start; }
.dialog-tabs button { flex: none; padding: 0 14px; }
.dialog-body { min-height: 280px; padding: 16px 18px; overflow-y: auto; }
.dialog-body h3 { margin: 4px 0 10px; font-size: 14px; }
.dialog-body h3 + .field-row { margin-bottom: 14px; }
.dialog-foot { display: flex; align-items: center; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--card); border-radius: 0 0 14px 14px; }
.paper-list, .doc-list { list-style: none; margin: 0 0 10px; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.paper-list li, .doc-list li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.paper-list li + li, .doc-list li + li { border-top: 1px solid var(--line); }
.paper-list .paper-name { flex: 1; font-weight: 600; }
.paper-list .paper-size { color: var(--muted); font-size: 13px; }
.paper-empty, .doc-empty { color: var(--muted); font-size: 13px; justify-content: center; padding: 24px 12px !important; }
.doc-list li.current { background: var(--accent-weak); }
.doc-info { flex: 1; min-width: 0; }
.doc-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-meta { margin-top: 2px; font-size: 12px; color: var(--muted); }
.link-danger { height: 28px; padding: 0 10px; font-size: 12px; color: var(--danger); }
.paper-add { align-items: flex-end; }
.paper-add .field { flex: 0 0 96px; }
.paper-add .field.grow { flex: 1; }
.paper-add button { margin-bottom: 8px; }

/* 이미지 편집기 */
.editor { display: flex; gap: 16px; }
.editor-stage-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  border-radius: var(--radius);
  background: repeating-conic-gradient(#e3e6ec 0 25%, #f1f3f7 0 50%) 0 0 / 16px 16px;
}
.editor-stage { position: relative; overflow: hidden; line-height: 0; user-select: none; touch-action: none; }
.editor-stage img { display: block; max-width: 100%; max-height: 62vh; }
.crop-box {
  position: absolute;
  border: 2px solid #fff;
  outline: 1px solid rgba(0, 0, 0, .5);
  box-shadow: 0 0 0 9999px rgba(15, 20, 32, .55);
  cursor: move;
}
.crop-box .h {
  position: absolute;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid var(--accent);
  border-radius: 4px;
  background: #fff;
}
.h[data-h="nw"] { left: 0; top: 0; cursor: nwse-resize; }
.h[data-h="n"]  { left: 50%; top: 0; cursor: ns-resize; }
.h[data-h="ne"] { left: 100%; top: 0; cursor: nesw-resize; }
.h[data-h="e"]  { left: 100%; top: 50%; cursor: ew-resize; }
.h[data-h="se"] { left: 100%; top: 100%; cursor: nwse-resize; }
.h[data-h="s"]  { left: 50%; top: 100%; cursor: ns-resize; }
.h[data-h="sw"] { left: 0; top: 100%; cursor: nesw-resize; }
.h[data-h="w"]  { left: 0; top: 50%; cursor: ew-resize; }
.editor-side { flex: 0 0 240px; }
.print-size { color: var(--text); font-weight: 500; }

/* ---------- 토스트 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 176px;
  z-index: 2000;
  transform: translate(-50%, 10px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--topbar);
  color: #fff;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 좁은 화면: 페이지 목록·속성 패널은 서랍으로 ---------- */
@media (max-width: 1100px) {
  .topbar .lbl { display: none; }
  .topbar button:not(.icon-btn) { width: 34px; padding: 0; }
}
@media (max-width: 1000px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "main" "queue"; }
  .drawer-btn { display: inline-flex !important; }
  .save-status, .brand { display: none; }
  .pagelist, .inspector {
    position: fixed;
    top: 50px;
    bottom: 0;
    z-index: 50;
    box-shadow: var(--shadow-lg);
    transition: transform .2s;
  }
  .pagelist { left: 0; width: 156px; transform: translateX(-105%); }
  .inspector { right: 0; width: min(310px, 90vw); transform: translateX(105%); }
  body.show-pages .pagelist, body.show-inspector .inspector { transform: none; }
  .editor { flex-direction: column; }
  .editor-side { flex: none; }
}

/* ---------- 인쇄 ---------- */
@media print {
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  html, body { height: auto; background: #fff; }
  .no-print, .page-label, .gutter, .rh { display: none !important; }
  .app, .workspace, .pages { display: block; height: auto; padding: 0; margin: 0; overflow: visible; background: #fff; }
  .page-wrap { display: block; break-after: page; }
  .page-wrap:last-child { break-after: auto; }
  /* 실제 용지 mm 크기로 출력 (빈 쪽 방지용으로 높이를 아주 살짝 줄임) */
  .page {
    --mm: 1mm !important;
    height: calc(var(--hmm) * 1mm - 0.5mm);
    box-shadow: none;
    outline: 0 !important;
    border-radius: 0;
    break-inside: avoid;
  }
  .grid { gap: 0 !important; }
  .cell { border: 0 !important; background: none !important; outline: 0 !important; }
  .cell.single .pic { outline: 0 !important; }
  .cell::after, .cell-tools { display: none !important; }
}
