/* 서류 자동 작성 시연 — 입력 → A4 견적서·거래명세서·발주서 실시간 미리보기.
   앞부분은 4개 시연이 같이 쓰는 바탕(색·입력 칸·단추·안내)이고, 강조색만 시연마다 다르다. 클래스에 ce- 접두사는 쓰지 않는다. */

:root {
  --canvas: #eef1f5;
  --surface: #ffffff;
  --sunken: #f6f8fa;
  --ink: #172033;
  --ink-2: #3a4457;
  --muted: #5e6878;
  --line: #dce1e8;
  --line-2: #ebeef3;
  --accent: #0e7a5a;
  --accent-deep: #0a5c44;
  --accent-soft: #e3f3ec;
  --accent-edge: #b9e0cf;
  --accent-text: #0b4a37;
  --accent-ring: rgba(14,122,90,.5);
  --bad: #c8281c;
  --bad-bg: #fde8e6;
  --warn: #9a5706;
  --warn-bg: #fef1d6;
  --ok: #0b7a47;
  --ok-bg: #ddf5e7;
  --kakao: #fee500;
  --chat: #bacbdc;
  --r-lg: 14px;
  --r-md: 10px;
  --r-sm: 7px;
  --font: "Pretendard Variable", Pretendard, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 400 14px/1.5 var(--font);
  letter-spacing: -0.01em;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ── 앱 머리 ───────────────────────────── */
.app-head {
  display: flex; align-items: center; gap: 14px;
  padding: 12px clamp(14px, 2.4vw, 28px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  display: grid; place-items: center; flex: none;
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--ink); color: #fff; font-weight: 800; font-size: 15px;
}
.brand-mark i { display: block; width: 14px; height: 14px; border: 3px solid #fff; border-radius: 3px; transform: rotate(45deg); }
.brand strong { display: block; font-size: 15px; font-weight: 750; line-height: 1.2; }
.brand span { display: block; font-size: 12px; color: var(--muted); }
.app-title { font-size: 15px; font-weight: 650; color: var(--ink-2); padding-left: 14px; border-left: 1px solid var(--line); }
.app-date { margin-left: auto; font-size: 13px; color: var(--muted); white-space: nowrap; }

/* 처음 보는 사람을 위한 한 줄 안내 */
.guide {
  display: flex; align-items: flex-start; gap: 10px;
  margin: 14px clamp(14px, 2.4vw, 28px) 0;
  padding: 10px 14px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-edge);
  border-radius: var(--r-md);
  color: var(--accent-text);
  font-size: 13.5px;
}
.guide b { flex: none; padding: 1px 8px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; line-height: 20px; }
.guide button { margin-left: auto; flex: none; border: 0; background: none; color: var(--accent-text); font-size: 12.5px; text-decoration: underline; padding: 2px 4px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); min-width: 0; }
.panel-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; padding: 14px 16px 10px; }
.panel-head h2 { font-size: 16px; font-weight: 750; }
.panel-head p { font-size: 12.5px; color: var(--muted); }

/* ── 입력 칸 ───────────────────────────── */
.field { display: grid; gap: 4px; min-width: 0; }
.field > span, .field legend { font-size: 12px; font-weight: 600; color: var(--muted); padding: 0; }
.field select, .field input, .field textarea {
  height: 40px; padding: 0 10px; min-width: 0; width: 100%;
  border: 1px solid #cbd2dc; border-radius: var(--r-sm); background: #fff;
}
.field textarea { height: auto; padding: 8px 10px; resize: vertical; line-height: 1.5; }
.field input[type="number"] { font-variant-numeric: tabular-nums; }
.field select:focus-visible, .field input:focus-visible, .field textarea:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.field [aria-invalid="true"] { border-color: var(--bad); background: #fff8f7; }
.form-msg { font-size: 12.5px; }
.form-msg:empty { display: none; }
.form-msg.is-error { color: var(--bad); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 18px; border-radius: var(--r-sm); border: 1px solid transparent;
  font-weight: 700; font-size: 14px; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-deep); }
.btn-ghost { background: #fff; border-color: #cbd2dc; color: var(--ink-2); }
.btn-ghost:hover { border-color: var(--ink-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }

/* 처음 사용자 강조: 눌러 볼 곳에 링 */
.coach-ring { box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--accent-ring); animation: ring 1.6s ease-in-out infinite; }
@keyframes ring { 50% { box-shadow: 0 0 0 3px #fff, 0 0 0 10px transparent; } }

@media (max-width: 680px) {
  .app-title { display: none; }
  .guide { flex-wrap: wrap; }
}
@media (max-width: 420px) { .app-date { display: none; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}

/* ══ 이 시연 ═══════════════════════════════ */
.layout {
  display: grid;
  grid-template-columns: 400px minmax(0, 1fr);
  gap: 16px;
  padding: 14px clamp(14px, 2.4vw, 28px) 28px;
  align-items: start;
}

/* ── 입력 ───────────────────────────────── */
.editor form { display: grid; }
.ed-group { padding: 4px 16px 14px; display: grid; gap: 10px; border-bottom: 1px solid var(--line-2); }
.ed-group + .ed-group { padding-top: 14px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.client-info { font-size: 12.5px; color: var(--muted); margin-top: -4px; }
.lines-head { display: flex; align-items: baseline; justify-content: space-between; }
.lines-head h3 { font-size: 14px; font-weight: 750; }
.lines-head span { font-size: 12px; }
.lines { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.line {
  display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 6px 8px;
  padding: 10px; border: 1px solid var(--line-2); border-radius: var(--r-md); background: var(--sunken);
}
.line .row2 { grid-column: 1 / -1; display: grid; grid-template-columns: 76px minmax(0, 1fr) auto 36px; gap: 8px; align-items: end; }
.line .field input { height: 36px; }
.line .field > span { font-size: 11.5px; }
.line .q input, .line .p input { text-align: right; }
.line .amt { font-size: 13.5px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; padding-bottom: 8px; white-space: nowrap; min-width: 84px; }
.line .del { width: 36px; height: 36px; border-radius: var(--r-sm); border: 1px solid #cbd2dc; background: #fff; color: var(--muted); font-size: 16px; line-height: 1; }
.line .del:hover { color: var(--bad); border-color: var(--bad); }
.line.is-new { animation: lineIn .35s ease-out; }
@keyframes lineIn { from { opacity: 0; transform: translateY(-6px); } }
.add-line { width: 100%; border-style: dashed; color: var(--accent-deep); }

.check { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }

.totals { margin: 0; padding: 14px 16px 4px; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-variant-numeric: tabular-nums; }
.totals dt { color: var(--muted); font-size: 13px; }
.totals dd { margin: 0; text-align: right; font-weight: 650; }
.totals .grand { font-size: 15px; color: var(--ink); font-weight: 750; padding-top: 6px; border-top: 1px solid var(--line-2); }
.totals dd.grand { font-size: 20px; color: var(--accent-deep); }
.ed-actions { padding: 10px 16px 16px; display: grid; gap: 8px; }
.ed-actions .btn { height: 46px; font-size: 15px; }
.note { font-size: 12.5px; color: var(--muted); padding: 8px 10px; border-radius: var(--r-sm); background: var(--sunken); }
.note.is-on { color: var(--accent-text); background: var(--accent-soft); }

/* ── 미리보기 ───────────────────────────── */
.preview { min-width: 0; position: sticky; top: 12px; }
.pv-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; margin-bottom: 10px; }
.tabs { display: inline-flex; padding: 3px; gap: 2px; background: #dfe4eb; border-radius: 10px; }
.tabs button { border: 0; background: none; height: 36px; padding: 0 16px; border-radius: 8px; font-weight: 650; font-size: 14px; color: var(--ink-2); }
.tabs button[aria-selected="true"] { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(23, 32, 51, .12); }
.pv-meta { margin-left: auto; font-size: 12.5px; color: var(--muted); }
.desk {
  background: #d9dee6;
  border-radius: var(--r-lg);
  padding: 22px;
  max-height: calc(100vh - 90px);
  overflow: auto;
  overscroll-behavior: contain;
}
.desk:focus-visible { outline-offset: 3px; }
.sheet-fit { position: relative; margin: 0 auto; }
.sheet {
  width: 794px; min-height: 1123px;
  transform-origin: top left;
  position: absolute; top: 0; left: 0;
  background: #fff; color: #1b1f27;
  padding: 56px 60px 48px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .12), 0 18px 40px -20px rgba(23, 32, 51, .45);
  font-size: 13px; line-height: 1.55;
  letter-spacing: -0.015em;
}

/* 서류 안 (회사 양식) */
.doc-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; padding-bottom: 18px; border-bottom: 3px solid #1b1f27; }
.doc-logo { display: flex; align-items: center; gap: 10px; }
.doc-logo .mk { width: 40px; height: 40px; border-radius: 10px; background: #1b1f27; display: grid; place-items: center; }
.doc-logo .mk i { width: 16px; height: 16px; border: 3.5px solid #fff; border-radius: 3px; transform: rotate(45deg); }
.doc-logo b { display: block; font-size: 20px; font-weight: 800; letter-spacing: -0.03em; }
.doc-logo small { display: block; font-size: 10.5px; color: #6b7280; letter-spacing: 0.04em; }
.doc-title { text-align: right; }
.doc-title h3 { font-size: 30px; font-weight: 800; letter-spacing: 0.32em; margin-right: -0.32em; }
.doc-title p { font-size: 12px; color: #6b7280; font-variant-numeric: tabular-nums; }
.doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin: 20px 0 16px; }
.doc-to h4, .doc-from h4 { margin: 0 0 6px; font-size: 11px; font-weight: 700; color: #6b7280; }
.doc-to .to-name { font-size: 21px; font-weight: 800; border-bottom: 1px solid #1b1f27; padding-bottom: 4px; margin-bottom: 8px; }
.doc-to .to-name small { font-size: 14px; font-weight: 600; margin-left: 6px; }
.kv { display: grid; grid-template-columns: 74px 1fr; gap: 3px 10px; font-size: 12.5px; margin: 0; }
.kv dt { color: #6b7280; }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.doc-from { position: relative; border: 1px solid #c9ced6; padding: 12px 14px; }
.seal {
  position: absolute; right: 14px; top: 10px;
  width: 58px; height: 58px; border: 3px solid #d0312d; border-radius: 6px;
  display: grid; grid-template-columns: 1fr 1fr; place-items: center;
  color: #d0312d; font-size: 17px; font-weight: 800; line-height: 1; padding: 4px;
  transform: rotate(-8deg); opacity: .88; mix-blend-mode: multiply;
}
.seal span { display: block; }
.doc-amount {
  display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 6px 16px;
  padding: 12px 16px; margin-bottom: 14px; background: #f3f5f7; border-left: 4px solid var(--accent);
}
.doc-amount .words { font-size: 15px; font-weight: 750; }
.doc-amount .fig { font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; }
.doc-amount small { font-size: 11.5px; color: #6b7280; font-weight: 500; margin-left: 6px; }
.doc-table { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.doc-table th { background: #1b1f27; color: #fff; font-weight: 650; padding: 7px 8px; text-align: center; font-size: 12px; }
.doc-table td { padding: 7px 8px; border-bottom: 1px solid #dfe3e8; }
.doc-table td.c { text-align: center; color: #6b7280; }
.doc-table td.r { text-align: right; }
.doc-table tr.blank td { height: 31px; }
.doc-table tfoot td { border-bottom: 0; padding: 6px 8px; }
.doc-table tfoot tr:first-child td { border-top: 2px solid #1b1f27; }
.doc-table tfoot .lbl { text-align: right; color: #6b7280; }
.doc-table tfoot .sum td { font-weight: 800; font-size: 14px; border-top: 1px solid #1b1f27; }
.doc-memo { margin-top: 16px; display: grid; grid-template-columns: 74px 1fr; gap: 10px; font-size: 12.5px; padding: 10px 0; border-top: 1px solid #dfe3e8; }
.doc-memo dt { color: #6b7280; }
.doc-memo dd { margin: 0; white-space: pre-wrap; }
.doc-foot { margin-top: 26px; display: flex; justify-content: space-between; align-items: flex-end; font-size: 11px; color: #8a919c; }
.sign { display: flex; gap: 0; border: 1px solid #c9ced6; font-size: 11.5px; color: #1b1f27; }
.sign div { width: 74px; text-align: center; }
.sign div + div { border-left: 1px solid #c9ced6; }
.sign b { display: block; font-weight: 600; padding: 3px; border-bottom: 1px solid #c9ced6; background: #f3f5f7; }
.sign span { display: block; height: 42px; }

/* 거래명세서: 공급자 / 공급받는자 두 칸 */
.stmt-grid { display: grid; grid-template-columns: 1fr 1fr; border: 1.5px solid #1b1f27; margin: 18px 0 14px; }
.stmt-grid > div { display: grid; grid-template-columns: 24px 1fr; }
.stmt-grid > div + div { border-left: 1.5px solid #1b1f27; }
.stmt-grid .side { writing-mode: vertical-rl; text-orientation: upright; display: grid; place-items: center; font-weight: 700; font-size: 12px; background: #f3f5f7; border-right: 1px solid #c9ced6; letter-spacing: 0.2em; }
.stmt-grid dl { margin: 0; display: grid; grid-template-columns: 64px 1fr; font-size: 12px; }
.stmt-grid dt, .stmt-grid dd { padding: 5px 8px; border-bottom: 1px solid #dfe3e8; margin: 0; }
.stmt-grid dt { color: #6b7280; background: #fafbfc; border-right: 1px solid #dfe3e8; }
.stmt-grid dl > :nth-last-child(-n+2) { border-bottom: 0; }
.stmt-grid .with-seal { position: relative; }
.stmt-grid .with-seal .seal { width: 44px; height: 44px; font-size: 13px; top: 4px; right: 8px; border-width: 2.5px; }

/* 값이 바뀐 곳 깜빡임 */
.hl { animation: hl 1.2s ease-out; }
@keyframes hl { 0%, 25% { background: #fff3b0; } 100% { background: transparent; } }

.zoom { display: none; height: 36px; padding: 0 12px; font-size: 13px; }
.narrow-only { display: none; }
.desk.is-zoomed { overflow-x: auto; }
.desk.is-zoomed .sheet-fit { margin: 0; }

/* 휴대폰: 아래에 붙는 합계 단추 */
.jump { display: none; }

@media (max-width: 1080px) {
  .layout { grid-template-columns: 360px minmax(0, 1fr); }
  .desk { padding: 14px; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .preview { position: static; }
  .desk { max-height: none; overflow: visible; padding: 12px; }
  .desk.is-zoomed { overflow-x: auto; }
  .zoom { display: inline-flex; margin-left: auto; }
  .wide-only { display: none; }
  .narrow-only { display: inline; }
  .jump {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    position: sticky; bottom: 0; z-index: 5;
    margin: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: var(--ink); color: #fff; text-decoration: none; font-variant-numeric: tabular-nums;
  }
  .jump b { padding: 6px 12px; border-radius: 999px; background: var(--accent); font-size: 13px; }
}
@media (max-width: 420px) {
  .line .row2 { grid-template-columns: 64px minmax(0, 1fr) 36px; }
  .line .amt { grid-column: 1 / -1; grid-row: 2; text-align: right; padding: 0; }
  .pv-meta { display: none; }
  .tabs { width: 100%; }
  .tabs button { flex: 1; padding: 0 8px; }
}

/* 인쇄: 서류 한 장만 A4 로 */
@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; }
  body > *:not(main), .editor, .pv-bar, .guide { display: none !important; }
  main.layout { display: block; padding: 0; }
  .preview { position: static; }
  .desk { padding: 0; background: none; max-height: none; overflow: visible; border-radius: 0; }
  .sheet-fit { width: auto !important; height: auto !important; }
  .sheet { position: static; transform: none !important; box-shadow: none; width: 210mm; min-height: 297mm; }
  .hl { animation: none; }
}
