/* app.css | 화면 구조: 위 도구 막대, 왼쪽 썸네일, 가운데 지면. 색과 크기는 전부 토큰에서 가져옴. */
:root {
  --bg: #e8e9ec;          /* 지면 뒤 바탕 */
  --chrome: rgba(250,250,251,.86);
  --side: #f4f4f6;
  --panel: #ffffff;
  --fg: #1c2129;
  --mute: #737985;
  --line: rgba(20,28,40,.10);
  --hover: rgba(20,28,40,.06);
  --press: rgba(20,28,40,.10);
  --accent: #2f5d8a;
  --accent-fg: #ffffff;
  --accent-soft: rgba(47,93,138,.13);
  --sel: rgba(47,93,138,.14);
  --danger: #c4402f;
  --shadow: 0 1px 2px rgba(0,0,0,.08), 0 8px 28px -10px rgba(10,20,40,.28);
  --page-shadow: 0 0 0 1px rgba(0,0,0,.05), 0 2px 10px -2px rgba(0,0,0,.18);
  --r: 8px;
  --tb: 62px;
  --sb: 168px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --num: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1d21; --chrome: rgba(40,42,47,.86); --side: #24262b; --panel: #2c2f35;
    --fg: #e9ebef; --mute: #9ba1ab; --line: rgba(255,255,255,.09); --hover: rgba(255,255,255,.06); --press: rgba(255,255,255,.11);
    --accent: #7fa8d4; --accent-fg: #0f1a26; --accent-soft: rgba(127,168,212,.18); --sel: rgba(127,168,212,.2);
    --danger: #ef7a68; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px -10px rgba(0,0,0,.6);
    --page-shadow: 0 0 0 1px rgba(255,255,255,.04), 0 2px 12px -2px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #1b1d21; --chrome: rgba(40,42,47,.86); --side: #24262b; --panel: #2c2f35;
    --fg: #e9ebef; --mute: #9ba1ab; --line: rgba(255,255,255,.09); --hover: rgba(255,255,255,.06); --press: rgba(255,255,255,.11);
    --accent: #7fa8d4; --accent-fg: #0f1a26; --accent-soft: rgba(127,168,212,.18); --sel: rgba(127,168,212,.2);
    --danger: #ef7a68; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px -10px rgba(0,0,0,.6);
    --page-shadow: 0 0 0 1px rgba(255,255,255,.04), 0 2px 12px -2px rgba(0,0,0,.6);
    color-scheme: dark;
  }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font: 13px/1.4 var(--font); overflow: hidden; -webkit-font-smoothing: antialiased; user-select: none; -webkit-user-select: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: default; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 6px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- 도구 막대 ---------- */
.toolbar {
  position: fixed; inset: 0 0 auto 0; height: var(--tb); z-index: 20;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: 0 12px; background: var(--chrome); backdrop-filter: saturate(1.6) blur(18px); -webkit-backdrop-filter: saturate(1.6) blur(18px);
  border-bottom: 1px solid var(--line);
}
.mac .toolbar { padding-left: 84px; }
.tb-left, .tb-right { display: flex; align-items: center; gap: 4px; min-width: 0; }
.tb-right { justify-content: flex-end; gap: 10px; }
.grp { display: flex; gap: 2px; }
.ib { width: 32px; height: 30px; border-radius: 7px; display: grid; place-items: center; color: var(--fg); transition: background .12s; }
.ib:hover { background: var(--hover); }
.ib:active { background: var(--press); }
.ib:disabled { opacity: .32; background: none; }
.ib.accent { color: var(--accent); }
.ib.danger:hover { color: var(--danger); }
.docname { display: flex; align-items: center; gap: 6px; margin-left: 6px; min-width: 0; font-weight: 600; }
.docname span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dirty { width: 6px; height: 6px; border-radius: 50%; background: var(--mute); flex: none; }
.lockchip { width: 24px; height: 24px; border-radius: 6px; display: grid; place-items: center; color: var(--accent); background: var(--accent-soft); flex: none; }
.lockchip svg { width: 15px; height: 15px; }

.seg { display: flex; padding: 2px; gap: 2px; border-radius: 9px; background: var(--hover); }
.seg button { height: 28px; min-width: 34px; padding: 0 8px; border-radius: 7px; display: grid; place-items: center; color: var(--mute); transition: background .12s, color .12s; }
.seg button:hover { color: var(--fg); }
.seg button.on { background: var(--panel); color: var(--fg); box-shadow: 0 1px 2px rgba(0,0,0,.12), 0 0 0 .5px rgba(0,0,0,.04); }
.tools button.on { color: var(--accent); }
.seg.full { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; }
.seg.full button { font-size: 12.5px; }

.zoom { align-items: center; }
.zval { font: 500 12px var(--num); min-width: 48px; height: 30px; border-radius: 7px; color: var(--mute); font-variant-numeric: tabular-nums; }
.zval:hover { background: var(--hover); color: var(--fg); }

/* ---------- 보조 막대 (색, 굵기, 프리셋) ---------- */
.subbar {
  position: fixed; top: calc(var(--tb) + 8px); left: 50%; transform: translateX(-50%); z-index: 19;
  display: flex; align-items: center; gap: 12px; padding: 5px 8px; border-radius: 11px;
  background: var(--chrome); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); box-shadow: var(--shadow);
}
.swatches, .widths, .presetbar { display: flex; gap: 6px; align-items: center; }
.swatches button { width: 20px; height: 20px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.swatches button.on { box-shadow: 0 0 0 2px var(--panel), 0 0 0 3.5px var(--accent); }
.widths button { width: 26px; height: 24px; border-radius: 6px; display: grid; place-items: center; }
.widths button i { display: block; width: 14px; background: currentColor; border-radius: 3px; }
.widths button.on { background: var(--accent-soft); color: var(--accent); }
.chip { height: 26px; padding: 0 11px; border-radius: 13px; background: var(--hover); font-size: 12.5px; display: inline-flex; align-items: center; gap: 6px; }
.chip:hover { background: var(--press); }
.chip .x { width: 14px; height: 14px; opacity: .45; }
.chip .x:hover { opacity: 1; }

/* ---------- 본문 ---------- */
.main { position: fixed; inset: var(--tb) 0 0 0; display: flex; }
.sidebar { width: var(--sb); flex: none; background: var(--side); display: flex; flex-direction: column; transition: margin-left .2s ease; }
.no-side .sidebar { margin-left: calc(-1 * var(--sb)); }
.thumbs { flex: 1; overflow-y: auto; padding: 16px 0 24px; display: grid; justify-items: center; align-content: start; gap: 14px; outline: none; }
.thumb { display: grid; justify-items: center; gap: 5px; position: relative; }
.thumb .tp { background: #fff; box-shadow: var(--page-shadow); border-radius: 2px; overflow: hidden; position: relative; }
.thumb canvas { display: block; width: 100%; height: 100%; }
.thumb .tn { font: 500 11px var(--num); color: var(--mute); padding: 1px 7px; border-radius: 8px; font-variant-numeric: tabular-nums; }
.thumb.cur .tn { color: var(--fg); }
.thumb.sel .tp { box-shadow: 0 0 0 2.5px var(--accent); }
.thumb.sel .tn { background: var(--accent); color: var(--accent-fg); }
.thumb.dragging { opacity: .35; }
.thumb.drop-before::before, .thumb.drop-after::after { content: ""; position: absolute; left: -10px; right: -10px; height: 3px; border-radius: 2px; background: var(--accent); }
.thumb.drop-before::before { top: -9px; }
.thumb.drop-after::after { bottom: -9px; }
.selbar { display: flex; align-items: center; gap: 2px; padding: 8px; border-top: 1px solid var(--line); }
.selcount { flex: 1; font: 500 12px var(--num); color: var(--mute); padding-left: 4px; }

.canvas { flex: 1; overflow: auto; position: relative; outline: none; overscroll-behavior: contain; }
.pages { display: grid; justify-content: center; gap: 18px; padding: 24px 32px 64px; min-width: min-content; }
.row { display: flex; gap: 6px; justify-content: center; }
.page { position: relative; background: #fff; box-shadow: var(--page-shadow); flex: none; }
.page canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.page .ov { position: absolute; inset: 0; overflow: visible; }
.page .ov svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }

.tool-highlight .page, .tool-highlight .ov { cursor: text; }
.tool-pen .ov, .tool-region .ov, .tool-image .ov, .tool-stamp .ov { cursor: crosshair; }
.tool-note .ov { cursor: copy; }

.rbox { position: absolute; border: 1.5px solid var(--accent); background: var(--sel); border-radius: 1px; }
.rbox .hd { position: absolute; background: var(--panel); border: 1.5px solid var(--accent); border-radius: 2px; }
.rbox .hd.n, .rbox .hd.s { left: 50%; width: 16px; height: 7px; margin-left: -8px; cursor: ns-resize; }
.rbox .hd.e, .rbox .hd.w { top: 50%; width: 7px; height: 16px; margin-top: -8px; cursor: ew-resize; }
.rbox .hd.n { top: -4px; } .rbox .hd.s { bottom: -4px; } .rbox .hd.e { right: -4px; } .rbox .hd.w { left: -4px; }
.abox { position: absolute; border: 1.5px solid var(--accent); border-radius: 2px; box-shadow: 0 0 0 3px var(--accent-soft); pointer-events: none; }
.ghost-img { position: absolute; opacity: .55; pointer-events: none; }

.pagepill { position: fixed; bottom: 20px; left: calc(50% + var(--sb) / 2); transform: translateX(-50%); z-index: 15;
  padding: 5px 12px; border-radius: 14px; background: var(--chrome); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: var(--shadow);
  font: 500 12px var(--num); font-variant-numeric: tabular-nums; color: var(--mute); transition: opacity .3s; }
.no-side .pagepill { left: 50%; }
.pagepill.fade { opacity: 0; }

/* ---------- 빈 화면, 끌어 놓기 ---------- */
.empty { position: fixed; inset: var(--tb) 0 0 0; display: grid; place-items: center; z-index: 5; background: var(--bg); }
.emptybtn { display: grid; justify-items: center; gap: 14px; padding: 40px 56px; border-radius: 18px; border: 1.5px dashed color-mix(in srgb, var(--mute) 45%, transparent); color: var(--mute); }
.emptybtn svg { width: 46px; height: 46px; stroke-width: 1.2; }
.emptybtn span { font-size: 14px; font-weight: 600; color: var(--fg); }
.emptybtn:hover { border-color: var(--accent); color: var(--accent); }
.dropveil { position: fixed; inset: 0; z-index: 50; background: var(--accent-soft); box-shadow: inset 0 0 0 3px var(--accent); pointer-events: none; }

/* ---------- 팝오버, 메뉴 ---------- */
.menu, .pop { position: fixed; z-index: 40; background: var(--panel); border-radius: 12px; box-shadow: var(--shadow), 0 0 0 .5px var(--line); animation: pop .14s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } }
.menu { padding: 5px; min-width: 210px; display: grid; }
.menu button { display: flex; align-items: center; gap: 10px; height: 30px; padding: 0 10px; border-radius: 7px; text-align: left; }
.menu button svg { width: 16px; height: 16px; color: var(--mute); }
.menu button:hover { background: var(--accent); color: var(--accent-fg); }
.menu button:hover svg { color: var(--accent-fg); }
.menu button:disabled { opacity: .35; background: none; color: inherit; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 6px; }

.pop { padding: 12px; width: 252px; display: grid; gap: 10px; }
.field { height: 30px; border-radius: 7px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); padding: 0 10px; font: 12.5px var(--num); width: 100%; outline: none; user-select: text; -webkit-user-select: text; }
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field.bad { border-color: var(--danger); }
.rp-row { display: flex; align-items: center; gap: 6px; }
.rp-row .grow { flex: 1; }
.rp-dim { flex: 1; font: 11.5px var(--num); color: var(--mute); text-align: right; font-variant-numeric: tabular-nums; }
.btn { height: 30px; padding: 0 16px; border-radius: 8px; background: var(--accent); color: var(--accent-fg); font-weight: 600; }
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: var(--hover); color: var(--fg); }
.btn:disabled { opacity: .45; }
.pop.note { width: 240px; padding: 8px; }
.pop.note textarea { width: 100%; resize: none; border: 0; outline: none; background: transparent; color: var(--fg); font: 13px/1.5 var(--font); user-select: text; -webkit-user-select: text; }
.stamplist { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stamplist .st { aspect-ratio: 1; border-radius: 9px; background: var(--hover); display: grid; place-items: center; position: relative; padding: 8px; }
.stamplist .st img { max-width: 100%; max-height: 100%; }
.stamplist .st:hover { background: var(--press); }
.stamplist .st.on { box-shadow: 0 0 0 2px var(--accent); }
.stamplist .st .x { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border-radius: 50%; display: none; place-items: center; background: var(--panel); box-shadow: var(--shadow); }
.stamplist .st .x svg { width: 11px; height: 11px; }
.stamplist .st:hover .x { display: grid; }
.stamplist .add svg { width: 22px; height: 22px; color: var(--mute); }

/* ---------- 시트 ---------- */
.veil { position: fixed; inset: 0; z-index: 60; background: rgba(10,14,20,.28); animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.sheet { position: fixed; z-index: 61; top: calc(var(--tb) + 4px); left: 50%; transform: translateX(-50%); width: 340px; max-width: calc(100vw - 32px);
  background: var(--panel); border-radius: 14px; box-shadow: var(--shadow), 0 0 0 .5px var(--line); padding: 20px; display: grid; gap: 14px; animation: drop .18s ease-out; }
.sheet.wide { width: 520px; }
@keyframes drop { from { opacity: 0; transform: translate(-50%, -10px); } }
.sh-icon { justify-self: center; width: 42px; height: 42px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.sh-icon svg { width: 22px; height: 22px; }
.sh-title { font-weight: 700; font-size: 14px; text-align: center; overflow-wrap: anywhere; }
.sh-actions { display: flex; justify-content: flex-end; gap: 8px; }
.sh-result { font: 500 13px var(--num); text-align: center; min-height: 18px; font-variant-numeric: tabular-nums; }
.sh-result b { color: var(--accent); }
.sizes { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.sizes button { height: 28px; padding: 0 13px; border-radius: 14px; border: 1px solid var(--line); font-size: 12.5px; }
.sizes button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.un-custom { display: flex; align-items: center; gap: 6px; justify-content: center; color: var(--mute); }
.un-custom .field { width: 74px; text-align: center; }
.mini { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; font: 11.5px var(--num); color: var(--mute); }
.bt-files { max-height: 220px; overflow-y: auto; display: grid; gap: 4px; }
.bt-file { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; background: var(--hover); font-size: 12.5px; }
.bt-file .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bt-file .st { font: 11.5px var(--num); color: var(--mute); }
.bt-file.done .st { color: var(--accent); }
.bt-file.fail .st { color: var(--danger); }
.bt-pick { display: flex; gap: 8px; }
.bt-ops { display: grid; gap: 8px; }
.chk { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; font-size: 13px; }
.chk input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
.chk select { height: 26px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); font: 12px var(--font); padding: 0 6px; }
.chk.fixed { opacity: .55; }
.chk .opts { display: flex; gap: 6px; }
.bt-file .pw { width: 130px; height: 26px; }
.bt-file .pwi { width: 15px; height: 15px; color: var(--accent); }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 70; padding: 9px 16px; border-radius: 10px;
  background: var(--fg); color: var(--bg); font-weight: 500; box-shadow: var(--shadow); animation: drop2 .18s ease-out; max-width: calc(100vw - 32px); }
@keyframes drop2 { from { opacity: 0; transform: translate(-50%, 8px); } }

@media (max-width: 760px) {
  .toolbar { grid-template-columns: auto 1fr auto; }
  .docname, .zoom, .views { display: none; }
  .sidebar { display: none; }
  .pagepill { left: 50%; }
}

/* ---------- 서명 ---------- */
.signsheet { padding: 16px; }
#sign-pad { width: 100%; aspect-ratio: 8 / 3; border-radius: 10px; background: #fff; box-shadow: inset 0 0 0 1px var(--line); touch-action: none; cursor: crosshair; display: block; }
.sign-row { display: flex; align-items: center; gap: 8px; }
.sign-row .grow { flex: 1; }
.pop.stamps.signs { width: 300px; }
.pop.stamps.signs .stamplist { grid-template-columns: 1fr 1fr; }
.pop.stamps.signs .st { aspect-ratio: 2.4; background: #fff; box-shadow: inset 0 0 0 1px var(--line); }

/* 도구 이름표: 아이콘 아래 작은 이름 */
.tools button { flex-direction: column; display: flex; align-items: center; justify-content: center; gap: 2px; height: 46px; min-width: 50px; padding: 0 6px; }
.tools button b { font-size: 11px; font-weight: 500; line-height: 1; letter-spacing: -.01em; }
.tools button.on b { font-weight: 650; }
/* 폭이 좁을 때: 이름표는 살리고 간격과 부수 버튼부터 줄임 */
@media (max-width: 1260px) {
  .tools button { min-width: 42px; padding: 0 3px; }
  .tb-right { gap: 6px; }
  .zoom .zval { display: none; }
}
@media (max-width: 1060px) {
  .docname { display: none; }
  .zoom { display: none; }
}
