@font-face { font-family: 'JSSans'; src: url(/vendor/fonts/sans.ttf); font-weight: 400; font-display: swap; }
@font-face { font-family: 'JSSans'; src: url(/vendor/fonts/sans-bold.ttf); font-weight: 700; font-display: swap; }

:root {
  --ink: #141826; --ink-2: #1f2437; --text: #1c2030; --muted: #6b7280; --line: #e5e7eb; --line-2: #eef0f4;
  --bg: #f5f6f9; --card: #fff; --accent: #4f46e5; --accent-2: #4338ca; --accent-soft: #eef2ff;
  --ok: #059669; --ok-soft: #ecfdf5; --warn: #d97706; --warn-soft: #fffbeb; --bad: #dc2626; --bad-soft: #fef2f2;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: 'JSSans', -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif; color: var(--text); background: var(--bg); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
button { font: inherit; cursor: pointer; }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--ink); color: #c9cdd8; display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; color: #fff; font-weight: 700; font-size: 18px; letter-spacing: -.2px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #6366f1, #22d3ee); display: grid; place-items: center; font-size: 13px; color: #fff; font-weight: 700; }
.side .new-btn { margin: 0 6px 16px; }
.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-group { font-size: 11px; color: #7c8396; padding: 14px 12px 6px; letter-spacing: .4px; }
.nav a { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border-radius: 8px; color: #c9cdd8; }
.nav a:hover { background: var(--ink-2); color: #fff; }
.nav a.on { background: #2b3150; color: #fff; }
.nav .count { font-size: 11px; background: #343b5c; color: #dfe3ff; border-radius: 10px; padding: 0 7px; min-width: 20px; text-align: center; }
.nav .count.hot { background: var(--accent); color: #fff; }
.side-foot { margin-top: auto; padding: 12px; border-top: 1px solid #262b40; font-size: 12px; display: flex; justify-content: space-between; align-items: center; }
.side-foot button { background: none; border: 0; color: #9aa1b5; padding: 0; }
.side-foot button:hover { color: #fff; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 60px; display: flex; align-items: center; justify-content: space-between; padding: 0 28px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 18px; }
.content { padding: 24px 28px 48px; }

/* ---------- primitives ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--text); font-weight: 500; white-space: nowrap; }
.btn:hover { background: #f8f9fb; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-2); }
.btn-kakao { background: #fee500; border-color: #fee500; color: #191919; }
.btn-kakao:hover { background: #f5dc00; }
.btn-danger { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }
.icon-btn { border: 0; background: transparent; width: 30px; height: 30px; border-radius: 6px; color: var(--muted); }
.icon-btn:hover { background: var(--line-2); color: var(--text); }
.input, select.input, textarea.input { width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font: inherit; color: var(--text); }
textarea.input { height: auto; padding: 10px 12px; resize: vertical; }
.input:focus { outline: 2px solid #c7d2fe; border-color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 500; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.gap-s { gap: 6px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.grow { flex: 1; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-top: 10px; cursor: pointer; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; word-break: break-all; }

.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: 11px; font-size: 12px; font-weight: 500; background: var(--line-2); color: var(--muted); white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.b-draft { background: #f3f4f6; color: #4b5563; }
.b-in_progress { background: var(--accent-soft); color: var(--accent); }
.b-completed { background: var(--ok-soft); color: var(--ok); }
.b-cancelled { background: #f3f4f6; color: #6b7280; }
.b-rejected { background: var(--bad-soft); color: var(--bad); }

/* ---------- dashboard ---------- */
.hello { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 20px 0 24px; }
.stat { padding: 18px 20px; cursor: pointer; transition: transform .12s; }
.stat:hover { transform: translateY(-1px); }
.stat .n { font-size: 28px; font-weight: 700; margin-top: 4px; }
.stat .l { color: var(--muted); font-size: 13px; }
.stat.hot .n { color: var(--accent); }
.dash-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; }
.drop { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; border: 2px dashed #c7cbe0; border-radius: 12px; padding: 36px 20px; text-align: center; background: #fafbff; cursor: pointer; transition: .15s; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop .big { font-size: 16px; font-weight: 700; }
.small-drop { padding: 18px; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line-2); }
.list-plain li:last-child { border-bottom: 0; }
.section-title { font-size: 15px; font-weight: 700; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; }

/* ---------- table ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar .input { max-width: 320px; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 500; padding: 10px 16px; border-bottom: 1px solid var(--line); background: #fafbfc; }
.tbl td { padding: 13px 16px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tbody tr.clickable:hover { background: #fafbff; }
.tbl tr.sel { background: var(--accent-soft) !important; }
.doc-title { font-weight: 500; }
.sub { font-size: 12px; color: var(--muted); }

.split { display: grid; grid-template-columns: 1fr 360px; gap: 16px; align-items: start; }
.drawer { position: sticky; top: 84px; max-height: calc(100vh - 110px); overflow-y: auto; }
.drawer h3 { font-size: 16px; margin-bottom: 6px; word-break: break-all; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0; }
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline li { position: relative; padding: 0 0 14px 22px; }
.timeline li::before { content: ''; position: absolute; left: 5px; top: 7px; width: 8px; height: 8px; border-radius: 50%; background: #c7cbe0; }
.timeline li::after { content: ''; position: absolute; left: 8.5px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline li.ev-signed::before, .timeline li.ev-completed::before { background: var(--ok); }
.timeline li.ev-rejected::before, .timeline li.ev-auth_failed::before, .timeline li.ev-cancelled::before { background: var(--bad); }
.timeline li.ev-sent::before, .timeline li.ev-kakao_sent::before { background: var(--accent); }
.timeline li.ev-kakao_failed::before { background: var(--warn); }
.steps { display: flex; flex-direction: column; gap: 8px; margin: 10px 0 18px; }
.step { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; }
.step .num { width: 22px; height: 22px; border-radius: 50%; color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.step.done .num { background: var(--ok) !important; }

/* ---------- editor ---------- */
.editor { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - 60px); }
.ed-side { background: #fff; border-right: 1px solid var(--line); overflow-y: auto; padding: 18px; }
.ed-side h4 { font-size: 13px; color: var(--muted); font-weight: 700; margin: 18px 0 10px; letter-spacing: .2px; }
.ed-side h4:first-child { margin-top: 0; }
.ed-canvas { overflow: auto; padding: 24px; display: flex; flex-direction: column; align-items: center; gap: 18px; background: #e9ebf1; }
.recip { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer; position: relative; }
.recip.on { border-color: var(--rc); box-shadow: 0 0 0 2px color-mix(in srgb, var(--rc) 25%, transparent); }
.recip-head { display: flex; align-items: center; gap: 8px; }
.recip-head .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--rc); flex: none; }
.recip-head .nm { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recip-body { margin-top: 10px; display: none; }
.recip.on .recip-body { display: block; }
.recip-body .input { height: 32px; font-size: 13px; margin-bottom: 6px; }
.recip-body .two { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.palette { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tool { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-size: 13px; }
.tool:hover { border-color: #c7cbe0; }
.tool.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.tool .ico { width: 20px; text-align: center; }
.ed-hint { font-size: 12px; color: var(--muted); background: #f8f9fb; border-radius: 8px; padding: 10px; margin-top: 10px; }
.prop { border: 1px solid var(--line); border-radius: 10px; padding: 12px; }

.pdf-page { position: relative; background: #fff; box-shadow: 0 2px 10px rgba(20,24,38,.12); flex: none; }
.pdf-page canvas { display: block; }
.pdf-page .overlay { position: absolute; inset: 0; }
.pdf-page .page-no { position: absolute; right: 8px; bottom: -22px; font-size: 11px; color: var(--muted); }
.pdf-loading { padding: 60px; color: var(--muted); }
.placing .overlay { cursor: crosshair; }

.fld { position: absolute; border: 1.5px solid var(--fc); background: color-mix(in srgb, var(--fc) 12%, transparent); border-radius: 4px; font-size: 11px; color: var(--fc); display: flex; align-items: center; justify-content: center; user-select: none; touch-action: none; font-weight: 700; overflow: visible; }
.fld .lbl { pointer-events: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 4px; }
.fld.sel { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--fc); z-index: 3; }
.fld .rz { position: absolute; right: -5px; bottom: -5px; width: 10px; height: 10px; background: var(--fc); border-radius: 2px; cursor: nwse-resize; display: none; }
.fld .del { position: absolute; right: -9px; top: -9px; width: 18px; height: 18px; border-radius: 50%; border: 0; background: var(--fc); color: #fff; font-size: 10px; line-height: 18px; padding: 0; display: none; }
.fld.sel .rz, .fld.sel .del { display: block; }
.ed-mode .fld { cursor: move; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tpl-box { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-top: 10px; background: #fafbfc; }
.tpl-box pre { white-space: pre-wrap; font: inherit; font-size: 13px; margin: 8px 0; background: #fff; border: 1px solid var(--line-2); border-radius: 8px; padding: 10px; }
.tpl-box code { font-size: 12px; background: #fff; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--line-2); word-break: break-all; }

/* ---------- modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,18,30,.5); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: #fff; border-radius: 14px; width: min(480px, 100%); max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-wide { width: min(980px, 100%); }
.modal-sig { width: min(560px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line-2); }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-body > p { white-space: pre-line; margin-top: 0; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line-2); display: flex; justify-content: flex-end; gap: 8px; }
.viewer { background: #e9ebf1; display: flex; flex-direction: column; align-items: center; gap: 22px; padding: 18px; border-radius: 8px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tab { border: 0; background: none; padding: 9px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 700; }
.draw-wrap { position: relative; height: 200px; border: 1px solid var(--line); border-radius: 10px; background: repeating-linear-gradient(#fff 0 150px, #e5e7eb 150px 151px, #fff 151px 200px); margin-bottom: 10px; }
.draw-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.draw-hint { position: absolute; inset: 0; display: grid; place-items: center; color: #b0b5c3; pointer-events: none; }
.swatch { width: 20px; height: 20px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); padding: 0; }
.swatch.on { box-shadow: 0 0 0 2px var(--accent); }
.type-preview { height: 130px; border: 1px solid var(--line); border-radius: 10px; margin-top: 10px; display: grid; place-items: center; background: #fff; }
.type-preview img { max-height: 110px; max-width: 90%; }
.saved-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.saved-item { border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 10px; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.saved-item img { height: 70px; max-width: 100%; object-fit: contain; }
.saved-item.on { border-color: var(--accent); background: var(--accent-soft); }

.sig-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.sig-card .preview { height: 150px; border: 1px dashed var(--line); border-radius: 10px; display: grid; place-items: center; margin: 12px 0; background: #fff; }
.sig-card .preview img { max-height: 130px; max-width: 90%; }

.link-row { display: flex; gap: 6px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line-2); }
.link-row:last-child { border-bottom: 0; }
.link-row .who { flex: 1; min-width: 0; }

.toasts { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; align-items: center; }
.toast { background: #1f2437; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.2); transition: .3s; font-size: 13px; }
.toast-error { background: var(--bad); }
.toast-ok { background: #065f46; }
.toast.out { opacity: 0; transform: translateY(6px); }

/* ---------- auth screen ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 600px at 20% -10%, #e0e7ff, transparent), var(--bg); }
.auth-card { width: min(400px, 100%); padding: 32px; }
.auth-card .brand { color: var(--text); padding: 0 0 18px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .dash-grid, .split, .sig-cards { grid-template-columns: 1fr; }
  .editor { grid-template-columns: 1fr; height: auto; }
}
