:root{
  --bg:#f5f4f0; --surface:#fbfbf9; --panel:#ffffff; --panel-soft:#f7f6f2;
  --ink:#1c1c1a; --ink-hover:#3a3935; --ink-2:#55534d; --sub:#7a776f; --muted:#8a877f;
  --line:#e3e1db; --line-2:#dcdad3; --line-3:#efeee9; --hover:#efeee9; --soft:#f3f2ee; --track:#ebe9e3;
  --accent:#1d6b52; /* 장부 그린 */
  --accent-soft:#e3efe9;
  --font:"IBM Plex Sans KR",sans-serif; --mono:"JetBrains Mono",monospace;
}
*{box-sizing:border-box}
[hidden]{display:none !important}
body{margin:0;background:var(--bg);color:var(--ink);font-family:var(--font);-webkit-font-smoothing:antialiased}
button{font:inherit;color:inherit}
.mono-label{font-family:var(--mono);font-size:11px;letter-spacing:.12em;color:var(--muted)}
.mono{font-family:var(--mono);font-variant-numeric:tabular-nums}
.app{min-height:100vh;display:flex;flex-direction:column}
.topbar{display:flex;align-items:center;justify-content:space-between;gap:16px;padding:16px 28px;border-bottom:1px solid var(--line);background:var(--surface);flex-wrap:wrap}
.brand{display:flex;align-items:baseline;gap:14px;min-width:0;flex-wrap:wrap}
.brand-title{font-size:17px;font-weight:700;letter-spacing:-.01em}
.actions{display:flex;gap:8px}
.btn{height:36px;padding:0 14px;background:transparent;border:1px solid var(--line-2);border-radius:999px;font-size:13px;cursor:pointer;white-space:nowrap}
.btn:hover{background:var(--hover)}
.btn--solid{background:var(--ink);color:#fff;border:none;font-weight:500}
.btn--solid:hover{background:var(--ink-hover)}
.btn.sm{height:30px;font-size:12.5px;padding:0 12px}
.text-input,.in{height:38px;padding:0 10px;background:var(--surface);border:1px solid var(--line-2);border-radius:8px;font:inherit;font-size:14px;color:var(--ink);width:100%;min-width:0}
.in:focus{outline:none;border-color:var(--accent);background:#fff;box-shadow:0 0 0 3px var(--accent-soft)}
.in.num{font-family:var(--mono);text-align:right;font-size:13.5px}
textarea.in{height:auto;padding:9px 10px;line-height:1.55;resize:vertical}

/* ---------- 레이아웃 ---------- */
.mtabs{display:none}
.desk{flex:1;display:grid;grid-template-columns:minmax(380px,500px) minmax(0,1fr);align-items:start}
.form{padding:22px 22px 40px;display:flex;flex-direction:column;gap:14px;min-width:0;border-right:1px solid var(--line)}
.stage{position:sticky;top:0;height:100vh;display:flex;flex-direction:column;min-width:0;background:#e4e8e3;
  background-image:linear-gradient(rgba(29,107,82,.07) 1px,transparent 1px),linear-gradient(90deg,rgba(29,107,82,.07) 1px,transparent 1px);background-size:24px 24px}
.stage-bar{display:flex;align-items:center;justify-content:space-between;padding:12px 20px;background:rgba(251,251,249,.8);border-bottom:1px solid rgba(0,0,0,.06)}
.pages{font-size:12.5px;color:var(--ink-2)}
.stage-scroll{flex:1;overflow:auto;padding:28px 20px 60px}
.paper-wrap{position:relative;margin:0 auto}
.paper-scale{position:absolute;left:0;top:0;width:210mm;transform-origin:0 0}
.doc{display:flex;flex-direction:column;gap:24px}

/* 문서 종류 스위치 */
.doc-switch{display:grid;grid-template-columns:1fr 1fr;gap:0;padding:4px;background:var(--panel);border:1px solid var(--line);border-radius:14px}
.ds{display:flex;flex-direction:column;align-items:flex-start;gap:2px;padding:12px 16px;border:none;background:transparent;border-radius:10px;cursor:pointer;text-align:left;transition:background .15s}
.ds-k{font-size:16px;font-weight:700;letter-spacing:-.01em}
.ds-e{font-family:var(--mono);font-size:10px;letter-spacing:.16em;color:var(--muted)}
.ds:hover{background:var(--soft)}
.ds.is-on{background:var(--accent);color:#fff}
.ds.is-on .ds-e{color:rgba(255,255,255,.7)}
.desk[data-doc="quote"] .only-statement,.desk[data-doc="statement"] .only-quote{display:none !important}

/* 블록 */
.blk{margin:0;padding:16px;border:1px solid var(--line);border-radius:14px;background:var(--panel);min-width:0}
.blk legend{float:left;width:100%;display:flex;align-items:baseline;gap:8px;padding:0;margin-bottom:12px;font-size:14.5px;font-weight:700}
.blk legend+*{clear:both}
.blk legend small{font-size:11.5px;font-weight:400;color:var(--muted)}
.no{font-family:var(--mono);font-size:11px;font-weight:500;color:var(--accent);letter-spacing:.08em}
.grid{display:grid;gap:10px}
.g2{grid-template-columns:1fr 1fr}
.g3{grid-template-columns:repeat(3,1fr)}
.g3 .f:first-child{grid-column:span 2}
.mt{margin-top:12px}
.f{display:flex;flex-direction:column;gap:5px;min-width:0}
.f>span:first-child{font-size:12px;color:var(--ink-2);font-weight:500}
.f.wide{grid-column:1 / -1}
.f b{font-family:var(--mono);font-weight:500;color:var(--muted);font-size:11px}
.with-btn{display:flex;gap:4px}
.tiny{flex:none;width:38px;height:38px;border:1px solid var(--line-2);border-radius:8px;background:transparent;cursor:pointer;font-size:15px}
.tiny:hover{background:var(--hover)}
.chk{display:flex;align-items:center;gap:7px;font-size:12.5px;color:var(--ink-2);cursor:pointer;margin-top:10px}
.chk input{accent-color:var(--accent);margin:0}
input[type=range]{accent-color:var(--accent);width:100%}
.tip{margin:4px 0 0;font-size:11.5px;color:var(--muted);line-height:1.5}

/* 도장 */
.stamp-row{display:grid;grid-template-columns:96px 1fr;gap:14px;margin-top:14px;padding-top:14px;border-top:1px dashed var(--line-2)}
.stamp-prev{width:96px;height:96px;border-radius:12px;display:grid;place-items:center;background:#fff;border:1px solid var(--line);
  background-image:linear-gradient(45deg,#f1f0ec 25%,transparent 25%,transparent 75%,#f1f0ec 75%),linear-gradient(45deg,#f1f0ec 25%,transparent 25%,transparent 75%,#f1f0ec 75%);background-size:12px 12px;background-position:0 0,6px 6px}
.stamp-prev span{font-size:11px;color:var(--muted);background:#fff;padding:2px 6px;border-radius:4px}
.stamp-prev img{max-width:80px;max-height:80px}
.stamp-ctl{display:flex;flex-direction:column;gap:2px;min-width:0}
.stamp-btns{display:flex;gap:6px;flex-wrap:wrap}
.stamp-ctl .chk{margin-top:8px}
.f.inline{margin-top:6px}

/* 부가세 */
.vat{display:grid;grid-template-columns:repeat(3,1fr);gap:6px;margin-bottom:12px}
.vt{display:flex;flex-direction:column;gap:1px;padding:8px 10px;border:1px solid var(--line-2);border-radius:10px;background:transparent;font-size:13px;font-weight:600;cursor:pointer;text-align:left}
.vt small{font-size:11px;font-weight:400;color:var(--muted)}
.vt:hover{background:var(--soft)}
.vt.is-on{border-color:var(--accent);background:var(--accent-soft);color:var(--accent)}
.vt.is-on small{color:var(--accent)}

/* 품목 */
.items{display:flex;flex-direction:column;gap:8px}
.row{border:1px solid var(--line-3);border-radius:10px;padding:8px 10px 10px;background:var(--panel-soft)}
.row-top{display:flex;align-items:center;gap:10px;margin-bottom:6px}
.row-no{font-size:11px;color:var(--accent);font-weight:500}
.row-calc{flex:1;font-size:11.5px;color:var(--sub);min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.row-calc b{font-family:var(--mono);font-weight:500;color:var(--ink)}
.row-tools{display:flex;gap:2px}
.ib{width:26px;height:26px;display:grid;place-items:center;border:none;background:transparent;border-radius:7px;cursor:pointer;color:var(--ink-2);padding:0}
.ib svg{width:14px;height:14px}
.ib:hover:not(:disabled){background:var(--hover)}
.ib:disabled{opacity:.25}
.row-grid{display:grid;grid-template-columns:2fr 1.4fr .8fr 1.4fr;gap:8px}
.row-grid .r-name{grid-column:1}
.row-grid .r-note{grid-column:1 / -1}
.row-grid.st{grid-template-columns:1.2fr 2fr 1.4fr}
.row-grid.st .r-qty{grid-column:1}
.row-grid.st .r-price{grid-column:2}
.row-grid.st .r-note{grid-column:3}
.add{margin-top:8px;width:100%;height:38px;border:1.5px dashed var(--line-2);border-radius:10px;background:transparent;font-size:13px;color:var(--ink-2);cursor:pointer}
.add:hover{border-color:var(--accent);color:var(--accent);background:#fff}
.sum-card{margin-top:12px;display:grid;grid-template-columns:1fr 1fr;gap:1px;background:var(--line);border-radius:12px;overflow:hidden;border:1px solid var(--line)}
.sum-card>div{background:var(--surface);padding:10px 12px;display:flex;flex-direction:column;gap:2px}
.sum-card span{font-size:11.5px;color:var(--sub)}
.sum-card b{font-size:16px;font-weight:500}
.sum-card .tot{grid-column:1 / -1;background:var(--ink);color:#fff}
.sum-card .tot span{color:rgba(255,255,255,.6)}
.sum-card .tot b{font-size:24px;font-weight:700;letter-spacing:-.01em}
.sum-card .tot em{font-style:normal;font-size:13px;color:#cfe8dd}

.tones{display:flex;gap:6px;align-items:center;height:38px}
.tone{width:26px;height:26px;border-radius:50%;border:none;background:var(--c);cursor:pointer}
.tone.is-on{box-shadow:0 0 0 2px #fff,0 0 0 4px var(--c)}
.legal{margin:0;padding:12px 14px;border-radius:12px;background:#fff6e5;border:1px solid #f1dcae;font-size:12.5px;line-height:1.6;color:#6b5420}
.legal b{color:#4d3b12}
.privacy{margin:0;font-size:12px;color:var(--sub);line-height:1.6}
.saved{font-family:var(--mono);font-size:11px;color:var(--muted)}
.toast{position:fixed;left:50%;bottom:28px;transform:translate(-50%,20px);opacity:0;pointer-events:none;background:var(--ink);color:#fff;padding:10px 16px;border-radius:999px;font-size:13px;transition:.25s;z-index:120;max-width:calc(100% - 32px);text-align:center}
.toast.is-on{opacity:1;transform:translate(-50%,0)}

@media (max-width:960px){
  .mtabs{display:flex;position:sticky;top:0;z-index:20;gap:4px;padding:8px 16px;background:var(--surface);border-bottom:1px solid var(--line)}
  .mtab{flex:1;height:36px;border:1px solid var(--line-2);background:transparent;border-radius:999px;font-size:13.5px;cursor:pointer}
  .mtab.is-on{background:var(--ink);color:#fff;border-color:var(--ink)}
  .desk{grid-template-columns:minmax(0,1fr)}
  .desk[data-view="edit"] .stage{display:none}
  .desk[data-view="preview"] .form{display:none}
  .form{border-right:none;padding:16px 16px 32px}
  .stage{position:static;height:auto}
  .stage-scroll{overflow:visible;padding:20px 16px 40px}
}
@media (max-width:640px){
  .topbar{padding:14px 16px}
  .g3,.g2{grid-template-columns:minmax(0,1fr) minmax(0,1fr)}
  .g3 .f:first-child{grid-column:1 / -1}
  .row-grid,.row-grid.st{grid-template-columns:minmax(0,1fr) minmax(0,1fr)}
  .row-grid .r-name,.row-grid.st .r-name{grid-column:1 / -1}
  .row-grid.st .r-qty,.row-grid.st .r-price,.row-grid.st .r-note{grid-column:auto}
  .vat{grid-template-columns:1fr}
  .vt{flex-direction:row;align-items:baseline;gap:8px}
  .stamp-row{grid-template-columns:72px 1fr}
  .stamp-prev{width:72px;height:72px}
  .stamp-prev img{max-width:60px;max-height:60px}
}
@media (prefers-reduced-motion:reduce){*{transition:none !important}}

/* =====================================================================
   문서 (A4)
   ===================================================================== */
.sheet{--tone:#1d6b52;--tint:color-mix(in srgb,var(--tone) 7%,#fff);--tline:color-mix(in srgb,var(--tone) 35%,#fff);
  position:relative;width:210mm;min-height:297mm;padding:16mm 15mm 16mm;background:#fff;color:#222;
  font-family:"Noto Sans KR","IBM Plex Sans KR","Apple SD Gothic Neo","Malgun Gothic",sans-serif;font-size:9pt;line-height:1.5;
  box-shadow:0 1px 2px rgba(0,0,0,.06),0 22px 50px rgba(20,40,30,.16);word-break:keep-all;overflow-wrap:anywhere;
  -webkit-print-color-adjust:exact;print-color-adjust:exact;-webkit-box-decoration-break:clone;box-decoration-break:clone}
.doc{--tone:#1d6b52}
.doc .sheet{--tone:inherit}
.sheet .mono{font-family:inherit;font-variant-numeric:tabular-nums;letter-spacing:0}
.sheet h1,.sheet h2,.sheet p,.sheet dl,.sheet dd{margin:0}
.sheet table{border-collapse:collapse;width:100%}
.sheet .strong{font-weight:700}
.sheet small{font-size:.85em;color:#777;font-weight:400}
.brk{position:absolute;left:-12px;right:-12px;height:0;border-top:1.5px dashed rgba(220,70,40,.75);pointer-events:none}
.brk span{position:absolute;right:0;top:-20px;font-family:var(--mono);font-size:11px;color:#c43d1f;background:#e4e8e3;padding:1px 6px;border-radius:4px}

.d-top{display:flex;justify-content:space-between;align-items:flex-end;gap:10mm;padding-bottom:4mm;border-bottom:1mm solid var(--tone)}
.d-title{font-size:26pt;font-weight:900;letter-spacing:.32em;line-height:1;color:#111}
.d-en{display:block;margin-top:2.4mm;font-size:7pt;letter-spacing:.34em;color:var(--tone);font-weight:700}
.d-en b{color:#111;letter-spacing:.1em}
.d-meta{display:flex;flex-direction:column;gap:1.2mm;text-align:right}
.d-meta div{display:flex;justify-content:flex-end;gap:3mm;align-items:baseline}
.d-meta dt{font-size:7.5pt;color:#888;letter-spacing:.05em}
.d-meta dd{font-weight:600}

.d-parties{display:grid;grid-template-columns:1fr 1.25fr;gap:6mm;margin-top:6mm;align-items:stretch}
.st-parties{grid-template-columns:1fr 1fr;gap:4mm}
.to{display:flex;flex-direction:column;padding-top:1mm}
.to-k{font-size:7.5pt;letter-spacing:.2em;color:var(--tone);font-weight:700}
.to-name{font-size:15pt;font-weight:700;margin-top:1.5mm !important;padding-bottom:2mm;border-bottom:.35mm solid #222;letter-spacing:-.01em}
.to-name small{font-size:.62em;color:#444;margin-left:1mm}
.to-meta{margin-top:2.5mm !important;display:flex;flex-direction:column;gap:.8mm;font-size:8.6pt}
.to-meta div{display:flex;gap:3mm}
.to-meta dt{width:12mm;color:#888}
.to-lead{margin-top:auto !important;padding-top:4mm;font-size:9.5pt;font-weight:500}

.party{border-top:.5mm solid #222;border-bottom:.35mm solid #222;font-size:8.4pt}
.party th,.party td{border-bottom:.2mm solid #d4d4d4;padding:1.5mm 2mm;text-align:left;vertical-align:middle;height:7.6mm}
.party tr:last-child th,.party tr:last-child td{border-bottom:none}
.party th{background:var(--tint);font-weight:500;color:#444;white-space:nowrap;width:1%}
.party th.vlabel{width:7mm;padding:0;background:var(--tone);color:#fff;text-align:center;border-bottom:none}
.party th.vlabel span{writing-mode:vertical-rl;letter-spacing:.5em;font-weight:700;font-size:8.6pt;display:inline-block;margin:auto}
.party td{border-left:.2mm solid #e6e6e6}
.party th+td,.party th+th{border-left:.2mm solid #e6e6e6}
.ceo{position:relative;white-space:nowrap}
.ceo-name{margin-right:2mm}
.in-mark{position:relative;display:inline-block;color:#999}
.stamp{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%) rotate(-4deg);object-fit:contain;pointer-events:none;opacity:.94}

.hero{display:grid;grid-template-columns:auto 1fr auto;align-items:center;gap:1mm 5mm;margin-top:6mm;padding:3.6mm 5mm;background:var(--tint);border-left:1.6mm solid var(--tone)}
.hero-k{font-size:8pt;letter-spacing:.2em;color:var(--tone);font-weight:700;grid-row:span 2}
.hero-ko{font-size:13pt;font-weight:700;letter-spacing:.02em;color:#111}
.hero-num{font-variant-numeric:tabular-nums;font-size:12.5pt;font-weight:700;color:#111;text-align:right}
.hero-note{grid-column:2 / 4;font-size:7.6pt;color:#777}
.vat-tag{margin-top:5mm;font-size:7.6pt;color:#888;text-align:right}

.items-t{margin-top:1.2mm;font-size:8.6pt;table-layout:fixed;border-top:.5mm solid #222}
.items-t col.c-no{width:11mm}.items-t col.c-name{width:auto}.items-t col.c-spec{width:27mm}.items-t col.c-qty{width:13mm}
.items-t col.c-price{width:22mm}.items-t col.c-sup{width:24mm}.items-t col.c-tax{width:19mm}.items-t col.c-note{width:21mm}
.items-t th{background:#f2f2f0;font-weight:600;color:#444;padding:1.8mm 1.6mm;border-bottom:.3mm solid #999;font-size:8pt;text-align:center}
.items-t td{padding:1.8mm 1.6mm;border-bottom:.2mm solid #e2e2e2;vertical-align:top;height:7.4mm}
.items-t td+td{border-left:.2mm solid #eee}
.items-t .c{text-align:center;color:#777}
.items-t .r{text-align:right}
.items-t .name{font-weight:500}
.items-t .spec,.items-t .note{color:#555;font-size:.95em}
.items-t tr{break-inside:avoid}
.items-t tfoot th{background:#f7f7f5;text-align:center;letter-spacing:.3em;color:#555;font-weight:600;border-top:.4mm solid #222;padding:2mm 1.6mm}
.items-t tfoot td{border-top:.4mm solid #222;background:#f7f7f5;font-weight:600;padding:2mm 1.6mm}
.items-t tfoot .grand th,.items-t tfoot .grand td{border-top:none;border-bottom:.5mm solid #222;background:var(--tint);color:var(--tone)}
.items-t tfoot .grand th small{letter-spacing:0;margin-left:1mm;color:#888}
.items-t tfoot .grand td{font-size:11pt;font-weight:700}

.cond{display:grid;grid-template-columns:1fr 1fr;gap:0 6mm;margin-top:6mm;border-top:.3mm solid #222}
.cond div{display:flex;gap:3mm;padding:1.8mm 0;border-bottom:.2mm solid #e2e2e2}
.cond dt{flex:none;width:17mm;color:var(--tone);font-weight:600;font-size:8pt}
.remark{margin-top:6mm;padding:3.5mm 4mm;border:.3mm solid #d9d9d9;border-radius:1.5mm;break-inside:avoid}
.remark h2{font-size:8pt;letter-spacing:.2em;color:var(--tone);margin-bottom:1.5mm !important}
.remark p{color:#333;line-height:1.65}
.sign{display:flex;justify-content:space-between;align-items:flex-end;margin-top:9mm;font-size:9pt;color:#333;break-inside:avoid}
.sign-line{display:flex;align-items:flex-end;gap:2mm}
.sign-line i{display:inline-block;width:32mm;border-bottom:.3mm solid #333;height:6mm}

/* ---------- 인쇄 ---------- */
@page{size:A4;margin:0}
@media print{
  html,body{background:#fff !important;margin:0 !important}
  body>:not(.app){display:none !important}
  .app{display:block;min-height:0 !important}
  .topbar,.mtabs,.form,.stage-bar,.brk,.toast{display:none !important}
  .desk{display:block !important}
  .desk .stage{display:block !important;position:static !important;height:auto !important;background:none !important}
  .stage-scroll{padding:0 !important;overflow:visible !important}
  .paper-wrap{width:auto !important;height:auto !important}
  .paper-scale{position:static !important;transform:none !important}
  .doc{gap:0;display:block}
  .sheet{box-shadow:none !important;min-height:297mm !important;break-after:page}
  .sheet:last-child{break-after:auto}
}

/* 도장 크기 직접 입력칸 */
.f-head{display:flex;justify-content:space-between;align-items:center;gap:8px}
.f-head .tb-num{height:26px;font-size:12px}
.f .tb-presets{margin-top:2px}
.tb-num-wrap .tb-num{color:var(--ink)}

/* 다크 모드 (인쇄는 라이트 그대로): A4 문서 미리보기 · 도장 미리보기는 종이라서 흰색 유지 */
@media screen{
  :root[data-theme="dark"]{
    color-scheme:dark;
    --bg:#121615; --surface:#171c1a; --panel:#1b211f; --panel-soft:#202725;
    --ink:#e8eeec; --ink-hover:#ffffff; --ink-2:#c4cdca; --sub:#9aa5a1; --muted:#85908c;
    --line:#29312e; --line-2:#333c39; --line-3:#222a27; --hover:#242c29; --soft:#222a27; --track:#2f3835;
    --accent:#5cc49e; --accent-soft:rgba(92,196,158,.14);
  }
  :root[data-theme="dark"] .btn--solid,:root[data-theme="dark"] .mtab.is-on,:root[data-theme="dark"] .toast{color:var(--bg)}
  :root[data-theme="dark"] .in:focus{background:var(--panel)}
  :root[data-theme="dark"] .stage{background-color:#161b19;background-image:linear-gradient(rgba(92,196,158,.06) 1px,transparent 1px),linear-gradient(90deg,rgba(92,196,158,.06) 1px,transparent 1px)}
  :root[data-theme="dark"] .stage-bar{background:rgba(23,28,26,.85);border-bottom-color:var(--line)}
  :root[data-theme="dark"] .sheet{box-shadow:0 1px 2px rgba(0,0,0,.3),0 22px 50px rgba(0,0,0,.5)}
  :root[data-theme="dark"] .brk{border-top-color:rgba(255,122,92,.8)}
  :root[data-theme="dark"] .brk span{color:#ff8a6e;background:#161b19}
  :root[data-theme="dark"] .ds.is-on{background:#1d6b52}
  :root[data-theme="dark"] .add:hover{background:var(--hover)}
  :root[data-theme="dark"] .sum-card .tot{background:#1a4a3b}
  :root[data-theme="dark"] .sum-card .tot em{color:#a8e6cc}
  :root[data-theme="dark"] .tone.is-on{box-shadow:0 0 0 2px var(--panel),0 0 0 4px var(--c)}
  :root[data-theme="dark"] .legal{background:rgba(240,190,90,.1);border-color:rgba(240,190,90,.28);color:#e8cf95}
  :root[data-theme="dark"] .legal b{color:#f5e0b0}
  :root[data-theme="dark"] .tb-presets button[aria-pressed="true"]{color:var(--bg)}
}
