:root {
  --gray-0: #ffffff;
  --gray-5: #fafafa;
  --gray-10: #f4f5f6;
  --gray-20: #e6e8ea;
  --gray-30: #cdd1d5;
  --gray-40: #b1b8be;
  --gray-50: #8a949e;
  --gray-60: #6d7882;
  --gray-70: #58616a;
  --gray-80: #464c53;
  --gray-90: #33363d;
  --gray-95: #1e2124;
  --gray-100: #131416;
  --primary-10: #ecf2fe;
  --primary-20: #d8e5fd;
  --primary-50: #256ef4;
  --primary-60: #0b50d0;
  --primary-70: #063a74;
  --ink: #131416;
  --line: #131416;
  --font: "Pretendard GOV", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--ink);
  background: var(--gray-0);
  font-family: var(--font);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: 0;
}

body::before {
  content: "";
  display: block;
  height: 4px;
  background: var(--primary-70);
  flex: none;
}

button, input, textarea, select { font-family: inherit; color: inherit; }

button { cursor: pointer; }

:focus-visible { outline: 2px solid var(--primary-50); outline-offset: 2px; }

.mast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--gray-30);
  background: var(--gray-0);
}

.mast-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.mast-title strong { font-size: 19px; font-weight: 700; line-height: 1.3; }

.mast-title span { font-size: 14px; color: var(--gray-80); }

.mast-actions { display: flex; align-items: center; gap: 8px; flex: none; }

#saveState { font-size: 14px; color: var(--gray-70); margin-right: 4px; }

.primary, .ghost, .textish {
  height: 40px;
  padding: 0 14px;
  border-radius: 6px;
  font-size: 16px;
  font-weight: 700;
}

.primary {
  background: var(--primary-50);
  color: #fff;
  border: 1px solid var(--primary-50);
}

.primary:hover { background: var(--primary-60); border-color: var(--primary-60); }

.ghost {
  background: #fff;
  color: var(--gray-95);
  border: 1px solid var(--gray-60);
}

.ghost:hover { background: var(--gray-10); }

.textish {
  height: auto;
  padding: 0;
  border: 0;
  background: none;
  color: var(--primary-60);
  font-size: 14px;
}

.textish.danger { color: #d6322f; }

.tabs {
  display: flex;
  gap: 0;
  padding: 0 12px;
  border-bottom: 1px solid var(--gray-30);
  background: #fff;
  flex: none;
}

.tabs.docs { background: var(--gray-10); }

.tabs button {
  appearance: none;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  height: 48px;
  margin-bottom: -1px;
  padding: 0 18px;
  color: var(--gray-80);
  font-size: 16px;
  font-weight: 400;
  border-radius: 0;
}

.tabs button[aria-selected="true"] {
  color: var(--primary-60);
  font-weight: 700;
  border-bottom-color: var(--primary-50);
}

.tabs.docs button[aria-selected="true"] {
  background: #fff;
  border-bottom-color: #fff;
  box-shadow: inset 0 2px 0 var(--primary-50);
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
}

.stage {
  overflow: auto;
  background: var(--gray-10);
  padding: 18px 16px 24px;
  min-width: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.editor {
  overflow: auto;
  background: #fff;
  border-left: 1px solid var(--gray-20);
  min-width: 0;
}

.editor-head { padding: 16px 16px 8px; }

.editor-head p {
  margin: 0;
  font-size: 13px;
  color: var(--gray-70);
}

.editor-head h2 {
  margin: 2px 0 0;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.4;
}

.notice {
  margin: 8px 16px 4px;
  padding: 12px 14px;
  background: var(--primary-10);
  border: 1px solid var(--primary-20);
  color: var(--gray-95);
  font-size: 14px;
  line-height: 1.55;
}

.block { padding: 14px 16px 6px; border-top: 1px solid var(--gray-20); }

.block h3 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 700;
}

.hint {
  margin: -4px 0 10px;
  color: var(--gray-70);
  font-size: 13px;
  line-height: 1.5;
}

.field { display: block; margin-bottom: 10px; }

.field span {
  display: block;
  margin-bottom: 6px;
  color: var(--gray-80);
  font-size: 14px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

input, textarea, select {
  width: 100%;
  border: 1px solid var(--gray-70);
  border-radius: 6px;
  background: #fff;
  font-size: 15px;
}

input, select { height: 40px; padding: 0 12px; }

textarea { min-height: 76px; padding: 8px 12px; line-height: 1.5; resize: vertical; }

textarea.tall { min-height: 132px; }

input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--primary-50);
  outline-offset: 1px;
  border-color: var(--primary-50);
}

.item {
  border: 1px solid var(--gray-30);
  background: var(--gray-5);
  padding: 10px;
  margin-bottom: 10px;
}

.item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 14px;
}

.amount {
  margin: 2px 0 0;
  text-align: right;
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.sumline {
  margin: 4px 0 12px;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.45;
}

.row-actions { display: flex; flex-wrap: wrap; gap: 12px 16px; margin: 4px 0 12px; }

.sheet-slot { position: relative; flex: none; }

.sheet-scale { transform-origin: top left; }

.paper > p { margin: 0 0 6px; }

.paper {
  width: 210mm;
  height: 297mm;
  max-width: none;
  box-sizing: border-box;
  padding: 8mm 10mm 8mm;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--gray-30);
  border-top: 4px solid var(--rule, var(--primary-70));
  box-shadow: 0 8px 24px rgba(19, 20, 22, 0.06);
  font-size: 13px;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
}

.sheet-body { transform-origin: top left; }

.edit {
  border-radius: 2px;
  cursor: text;
  outline: none;
  min-width: 1.5em;
  min-height: 1.1em;
}

.edit:hover { background: var(--primary-10); }

.edit:focus {
  background: #fff;
  box-shadow: inset 0 -1px 0 var(--primary-50);
}

.edit.is-empty:before {
  content: attr(data-placeholder);
  color: var(--gray-50);
}

.edit.block {
  display: block;
  min-height: 2.4em;
  white-space: pre-wrap;
}

td .edit { display: inline-block; min-width: 2.4em; }
td.right .edit { min-width: 3.2em; text-align: right; }
td.left .edit { min-width: 4em; }

.vat-toggle {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  font-size: 11px;
  color: var(--gray-80);
  cursor: pointer;
}

.vat-toggle:hover { color: var(--primary-60); }

.wordmark {
  margin: 0;
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: 0.22em;
  text-indent: 0.22em;
}

.letterhead {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 14mm;
  margin: 0 0 2mm;
}

.brand-logo {
  display: block;
  height: 12mm;
  width: auto;
  max-width: 150mm;
  object-fit: contain;
  object-position: center;
}

.title-block {
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--hair, var(--line));
}

.doc-title,
.spaced,
.plain-title,
.wordmark,
.clause h2,
.account h2,
.remarks h2,
.hangul,
.line > span,
.docmeta span,
.meta span,
.party .kv span {
  color: var(--accent, var(--ink));
}

.doc-title {
  margin: 8px 0 0;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
}

.docmeta {
  width: max-content;
  margin: 0 0 6px auto;
  font-size: 13px;
  line-height: 1.5;
}

.docmeta div, .meta div {
  display: grid;
  grid-template-columns: 64px auto;
  gap: 8px;
}

.docmeta span, .meta span { color: var(--gray-90); }

.letter { padding: 2px 0 8px; border-bottom: 1px solid var(--hair, var(--line)); }

.line {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 8px;
  padding: 2px 0;
}

.line > span { letter-spacing: 0.35em; }

.prose { margin: 8px 0 0; }

.prose p { margin: 0 0 6px; }

.clause h2, .account h2, .remarks h2 {
  margin: 6px 0 1px;
  font-size: 14px;
  font-weight: 700;
}

.clause p, .paren { margin: 0; }

ul.clean, .foot {
  margin: 2px 0 0;
  padding: 0;
  list-style: none;
}

ul.clean li, .foot li { padding-left: 12px; text-indent: -12px; }

.grid {
  width: 100%;
  margin-top: 8px;
  border-collapse: collapse;
  font-size: 12.5px;
  line-height: 1.35;
}

.grid th, .grid td {
  border: 1px solid var(--hair, var(--line));
  padding: 3px 5px;
  vertical-align: middle;
}

.grid th {
  background: var(--wash, var(--gray-10));
  color: var(--accent, var(--ink));
  font-weight: 700;
  text-align: center;
}

.grid td.left { text-align: left; }
.grid td.right { text-align: right; }
.grid td.center { text-align: center; }

.unit {
  margin: 4px 0 0;
  text-align: right;
  font-size: 13px;
  color: var(--gray-80);
}

.blank { color: var(--gray-60); }

.foot {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--hair, var(--line));
  font-size: 12.5px;
}

.head-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding-bottom: 10px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--hair, var(--line));
}

.brand-name { margin: 0; font-size: 15px; font-weight: 700; }

.kicker {
  margin: 0 0 2px;
  text-align: center;
  font-size: 13px;
  color: var(--accent, var(--gray-80));
}

.spaced {
  margin: 0;
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.5em;
  text-indent: 0.5em;
}

.plain-title {
  margin: 0;
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
}

.meta { justify-self: end; font-size: 13px; line-height: 1.4; }

.meta b { font-weight: 400; }

.parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0 0 12px;
}

.party { border: 1px solid var(--hair, var(--line)); }

.party h2 {
  margin: 0;
  padding: 4px 8px;
  background: var(--wash, var(--gray-10));
  border-bottom: 1px solid var(--hair, var(--line));
  color: var(--accent, var(--ink));
  font-size: 13px;
  font-weight: 700;
}

.party .kv {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 3px 8px;
  margin: 0;
  padding: 6px 8px 7px;
  font-size: 13px;
  line-height: 1.45;
}

.party .kv span { color: var(--gray-90); }

.party .kv b { font-weight: 400; overflow-wrap: anywhere; }

.total-wrap {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-top: 8px;
}

.hangul {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

.vatnote { margin: 4px 0 0; font-size: 12px; color: var(--gray-80); }

.totals { width: 240px; border-collapse: collapse; font-size: 13px; }

.totals td {
  border: 1px solid var(--hair, var(--line));
  padding: 5px 8px;
}

.totals td:first-child {
  width: 80px;
  background: var(--wash, var(--gray-10));
  color: var(--accent, var(--ink));
  text-align: center;
  font-weight: 700;
}

.totals td:last-child { text-align: right; }

.remarks { white-space: pre-wrap; font-size: 13px; line-height: 1.4; }

.account { margin-top: 8px; max-width: 360px; }

.account h2 { margin-bottom: 4px; }

.account div {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 8px;
  min-height: 22px;
  border-bottom: 1px solid var(--hair, var(--line));
  font-size: 13px;
  align-items: center;
}

.account b { font-weight: 400; min-height: 1em; }

.pre { white-space: pre-wrap; margin: 0; }

@media (max-width: 1080px) {
  body { height: auto; overflow: auto; }
  .workspace { display: block; height: auto; }
  .stage { overflow: visible; }
  .editor { border-left: 0; border-top: 1px solid var(--gray-20); }
}

@media print {
  body { height: auto; overflow: visible; display: block; background: #fff; }
  body::before, .mast, .tabs, .editor, .no-print { display: none !important; }
  .workspace { display: block; height: auto; }
  .stage { display: block; overflow: visible; height: auto; background: #fff; padding: 0; }
  .sheet-slot { width: 210mm !important; height: 297mm !important; }
  .sheet-scale { transform: none !important; }
  .paper {
    width: 210mm !important;
    height: 297mm !important;
    border-right: 0;
    border-left: 0;
    border-bottom: 0;
    box-shadow: none;
  }
  .edit:hover, .edit:focus { background: transparent; box-shadow: none; }
  .edit.is-empty:before { content: none; }
  .paper, .paper th, .totals td:first-child, .party h2 {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  @page { size: A4; margin: 0; }
}
