:root {
  --fg: #1f2329;
  --muted: #6b7280;
  --line: #d6d9de;
  --line-strong: #2b2f36;
  --bg: #f4f5f7;
  --panel: #ffffff;
  --primary: #2563eb;
  --primary-fg: #ffffff;
  --input-bg: #fff9e6;
  --input-line: #e8c76a;
  --calc-bg: #f1f3f5;
  --band-section: #2f3640;
  --band-section-fg: #ffffff;
  --band-group: #e6e9ee;
  --subtotal-bg: #d9dde3;
  --total-bg: #5f6670;
  --danger: #c0392b;
  --badge-bg: #e0e7ff;
  --badge-fg: #3730a3;
  font-family: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  font-size: 14px;
  color: var(--fg);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 8px 16px; }
button:hover { border-color: #9aa1ab; }
button.primary { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); font-weight: 600; }
button.danger { color: var(--danger); border-color: var(--danger); }
button:disabled { opacity: .6; cursor: wait; }
button.link { border: 0; background: none; color: var(--primary); padding: 0 6px; font-size: 13px; }

/* ---------- 상단 ---------- */
.topbar { display: flex; align-items: center; gap: 10px; padding: 12px 20px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar .logo { height: 26px; }
.topbar h1 { font-size: 20px; margin: 0 0 0 4px; }
.spacer { flex: 1; }
.header-total { margin-right: 8px; font-size: 15px; }
.header-total .sep, .muted { color: var(--muted); font-weight: normal; font-size: 12px; }
.header-total .error { color: var(--danger); font-weight: 700; }

.layout { display: flex; gap: 16px; padding: 16px 20px; align-items: flex-start; }
.sidemenu { display: flex; flex-direction: column; gap: 6px; width: 150px; flex: none; position: sticky; top: 70px; }
.sidemenu button { text-align: left; font-weight: 600; }
.sidemenu button.active { background: var(--band-section); color: #fff; border-color: var(--band-section); }
main { flex: 1; min-width: 0; }

.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line-strong); }
.tabs button { border-radius: 6px 6px 0 0; border-bottom: 0; padding: 10px 22px; }
.tabs button.active { background: var(--band-section); color: #fff; border-color: var(--band-section); }
.panel { background: var(--panel); border: 1px solid var(--line); border-top: 0; padding: 24px; }

.banner { margin: 10px 0 0; padding: 10px 14px; border-radius: 6px; font-size: 13px; line-height: 1.6; }
.banner.warn { background: #fff7e0; border: 1px solid #f0c36d; }
.banner.error { background: #fdecea; border: 1px solid #e6a39b; color: var(--danger); }
.banner .close { float: right; }

/* ---------- 입력 ---------- */
.input { font: inherit; border: 1px solid var(--input-line); background: var(--input-bg); border-radius: 4px; padding: 5px 8px; width: 100%; }
.input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.input.num { text-align: right; }
.input.wide { width: 100%; }
select.input { padding: 4px; }
.small, .small-input { font-size: 12px; }
.small-input { margin-top: 4px; }

/* ---------- 표지 ---------- */
.cover { max-width: 980px; margin: 0 auto; }
.cv-title { text-align: center; font-size: 22px; margin: 4px 0 24px; }
.cv-head { display: flex; justify-content: space-between; gap: 24px; }
.cv-fields { flex: 1; max-width: 560px; }
.cv-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; min-height: 28px; }
.cv-label { width: 90px; flex: none; text-align: right; }
.cv-amount { margin-top: 18px; }
.cv-sender { text-align: right; line-height: 1.8; }
.cv-sender-top { display: flex; justify-content: flex-end; align-items: flex-end; gap: 6px; }
.cv-logo { height: 28px; }
.cv-unit { text-align: right; font-size: 11px; color: var(--muted); margin: 18px 0 4px; }
.cv-table { width: 100%; border-collapse: collapse; }
.cv-table th, .cv-table td { border: 1px solid var(--line-strong); padding: 6px 8px; }
.cv-table th { background: #d5d8dc; }
.cv-sum td { background: #c9ccd1; font-weight: 700; }
.cv-final td { background: var(--total-bg); color: #fff; font-weight: 700; }
.cv-notes { margin-top: 20px; }
.cv-notes-head { margin-bottom: 6px; }
.cv-notes textarea { resize: vertical; line-height: 1.6; }
.cv-foot { text-align: right; margin-top: 18px; line-height: 2; }
.cv-issue { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
.cv-issue .input { width: auto; }

/* ---------- 표 공통 ---------- */
.grid { width: 100%; border-collapse: collapse; }
.grid th { background: #d5d8dc; border: 1px solid var(--line-strong); padding: 8px; }
.grid td { border-bottom: 1px solid var(--line); padding: 6px 8px; vertical-align: top; }
.c { text-align: center; }
.r { text-align: right; }
.strong { font-weight: 700; }
.calc { background: var(--calc-bg); }
.calc-inline { color: var(--muted); margin-top: 2px; }
.band-section td { background: var(--band-section); color: var(--band-section-fg); font-weight: 700; padding: 8px 10px; }
.band-section .btn-mini { float: right; background: #fff; }
.band-group td { background: var(--band-group); font-weight: 700; }
.lv-1 { padding-left: 18px !important; }
.lv-2 { padding-left: 34px !important; }
.lv-3 { padding-left: 54px !important; }
.item-name { font-weight: 700; }
.item-desc, .sol-desc { font-size: 12px; color: var(--muted); line-height: 1.5; }
.sol-desc { color: var(--fg); font-size: 13px; }
.badge { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 8px; background: var(--badge-bg); color: var(--badge-fg); font-size: 11px; font-weight: 600; vertical-align: middle; }
.btn-mini { padding: 2px 10px; font-size: 12px; }
.added-name { display: flex; gap: 6px; }
.add-row td { border-bottom: 1px dashed var(--line); }
.subtotal td { background: var(--subtotal-bg); font-weight: 700; font-size: 15px; }
.total td { background: var(--total-bg); color: #fff; font-weight: 700; font-size: 15px; }
.opt { font-size: 12px; padding: 1px 8px; border-radius: 8px; }
.opt-mandatory { background: #dcfce7; color: #166534; }
.opt-option { background: #f3f4f6; color: #374151; }

.tier-wrap td { background: #fafbfc; }
.tier-title { font-weight: 700; margin: 4px 0 8px; }
.tier { border-collapse: collapse; margin: 0 0 12px; width: 100%; }
.tier caption { text-align: left; font-size: 12px; font-weight: 700; padding: 4px 0; }
.tier th, .tier td { border: 1px solid var(--line); padding: 4px 6px; font-size: 12px; }
.tier th { background: #eef0f3; font-weight: 600; white-space: nowrap; }
.tier .input { min-width: 70px; }

/* ---------- 모달 ---------- */
dialog { border: 0; border-radius: 10px; padding: 0; box-shadow: 0 10px 40px rgba(0,0,0,.25); max-width: 760px; width: calc(100% - 32px); }
dialog::backdrop { background: rgba(0,0,0,.35); }
.modal { padding: 20px 22px; margin: 0; }
.modal h3 { margin: 0 0 12px; }
.modal-body { margin-bottom: 16px; }
.modal-buttons { display: flex; justify-content: flex-end; gap: 8px; }
.list .error { color: var(--danger); font-weight: 600; }
.reasons { margin: 0; padding-left: 20px; color: var(--danger); line-height: 1.7; }
.list-wrap { max-height: 50vh; overflow: auto; }
.list tr.pick { cursor: pointer; }
.list tr.pick:hover, .list tr.pick:focus { background: #eef4ff; outline: none; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 18px; border-radius: 6px; z-index: 20; }

/* ---------- 인쇄 (PDF) ---------- */
#print-root { display: none; }
body.print-mode { background: #fff; }
body.print-mode #app, body.print-mode dialog { display: none; }
body.print-mode #print-root { display: block; padding: 0 4px; } /* 표 외곽선 반쪽·오른쪽 정렬 글자 끝이 PDF 여백에 잘리지 않게 */
@page { size: A4; }
.page { break-after: page; font-size: 12px; }
.page:last-child { break-after: auto; }
.doc-title { text-align: center; font-size: 20px; margin: 0 0 8px; }
#print-root .cover { max-width: none; }
#print-root .cv-fields { max-width: none; }
#print-root .cv-label { width: 80px; }
#print-root .print-notes { border: 1px solid var(--line-strong); padding: 10px 12px; line-height: 1.7; min-height: 120px; }
#print-root .grid th { padding: 5px; }
#print-root .grid td { padding: 3px 6px; border-bottom: 1px dotted #9aa1ab; }
#print-root tr { break-inside: avoid; }
.pdoc .tag { font-weight: 700; }
.p-section td { border-top: 1px solid var(--line-strong); font-weight: 700; background: #eef0f3; }
.p-group td { font-weight: 700; }
.p-subtotal td { background: var(--subtotal-bg); font-weight: 700; }
.p-total td { background: var(--total-bg); color: #fff; font-weight: 700; }
#print-root .band-section td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
* { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

@media screen and (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidemenu { flex-direction: row; flex-wrap: wrap; width: auto; position: static; }
  .cv-head { flex-direction: column; }
  .cv-sender { text-align: left; }
}
