/* 견적서 만들기 — 공통 스타일. 외부 글꼴 없이 시스템 글꼴만 씁니다. */
:root {
  --ink: #1b2230;
  --muted: #5a6475;
  --line: #d5dbe3;
  --bg: #f4f6f9;
  --card: #fff;
  --accent: #1f5eff;
  --accent-ink: #fff;
  --danger: #c62828;
  --warn-bg: #fff4d6;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "맑은 고딕", "Noto Sans KR", "Noto Sans CJK KR", "Segoe UI", sans-serif;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg); line-height: 1.6; word-break: keep-all; overflow-wrap: anywhere; }
a { color: var(--accent); }
img { max-width: 100%; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.skip { position: absolute; left: -9999px; top: 0; background: var(--ink); color: #fff; padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; top: 8px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }

/* 머리말·꼬리말 */
.site-header { background: var(--card); border-bottom: 1px solid var(--line); }
.site-header .in { max-width: 1280px; margin: 0 auto; padding: 10px 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; }
.brand { font-weight: 700; color: var(--ink); text-decoration: none; font-size: 1.05rem; }
.site-header nav { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .92rem; }
.site-header nav a { color: var(--muted); text-decoration: none; }
.site-header nav a:hover, .site-header nav a[aria-current] { color: var(--ink); text-decoration: underline; }
.site-footer { border-top: 1px solid var(--line); margin-top: 48px; padding: 20px 16px 32px; color: var(--muted); font-size: .88rem; }
.site-footer .in { max-width: 1280px; margin: 0 auto; display: flex; flex-wrap: wrap; gap: 6px 16px; }
.site-footer a { color: var(--muted); }

main { max-width: 1280px; margin: 0 auto; padding: 16px; }
.page { max-width: 760px; }
h1 { font-size: 1.5rem; line-height: 1.35; margin: 8px 0 6px; }
.lede { margin: 0 0 14px; color: var(--muted); }
.privacy-note { display: inline-block; background: #e9f7ee; color: #17592f; border-radius: var(--radius); padding: 4px 10px; font-size: .9rem; margin: 0 0 12px; }
.guide { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; margin-bottom: 16px; max-width: 900px; }
.guide h2 { font-size: 1.05rem; margin: 0 0 6px; }
.guide p { margin: 6px 0; }
.industries { display: flex; flex-wrap: wrap; gap: 6px 12px; margin: 0 0 14px; padding: 0; list-style: none; font-size: .92rem; }

/* 버튼·입력 */
button, .button, select { font: inherit; font-size: .92rem; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: var(--radius); padding: 7px 12px; cursor: pointer; min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: 4px; text-decoration: none; }
button:hover, .button:hover { border-color: var(--muted); }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.danger { color: var(--danger); border-color: #f0b4b4; }
button.icon { width: 38px; padding: 0; }
.visually-hidden:focus-visible + .button, input[type=file]:focus-visible + .button { outline: 3px solid var(--accent); }
label.button:focus-within { outline: 3px solid var(--accent); }
input, textarea { font: inherit; font-size: 16px; color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; width: 100%; background: #fff; }
textarea { resize: vertical; min-height: 70px; }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
input[type=number] { text-align: right; }

/* 편집기 */
.toolbar { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 0; background: var(--bg); }
.save-state { color: var(--muted); font-size: .85rem; margin-left: 4px; }
.status { min-height: 1.4em; margin: 0 0 6px; font-size: .92rem; color: #17592f; }
.status.error, .warn { color: var(--danger); }
.warn:empty { display: none; }
.warn { background: var(--warn-bg); padding: 6px 10px; border-radius: 6px; font-size: .9rem; }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.preview { scroll-margin-top: 60px; }
@media (min-width: 1100px) {
  .workspace { grid-template-columns: minmax(420px, 1fr) minmax(0, 1.15fr); align-items: start; }
  .preview { position: sticky; top: 60px; max-height: calc(100vh - 70px); overflow: auto; }
  .to-preview { display: none; }
}
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.card h2 { font-size: 1rem; margin: 0 0 10px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px 12px; }
.field { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field label { font-size: .85rem; color: var(--muted); }
.field small, .hint, .stamp-row small { color: var(--muted); font-size: .82rem; }
.hint { margin: 6px 0; }
.check, .radio { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.stamp-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.stamp-thumb { width: 52px; height: 52px; object-fit: contain; border: 1px dashed var(--line); border-radius: 6px; }

.items-edit, .pays-edit { list-style: none; margin: 0 0 8px; padding: 0; }
.item-row { display: flex; gap: 8px; align-items: flex-end; padding: 8px 0; border-bottom: 1px dashed var(--line); }
/* 품목 이름과 비고는 한 줄 전체, 수량·단위·단가는 그 사이 한 줄. 편집 칸이 좁아 네 칸을 한 줄에 두면 단가가 잘립니다. */
.item-fields { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, .8fr) minmax(0, 1.6fr); gap: 6px 8px; min-width: 0; }
.item-fields .field:first-child, .item-fields .field:last-child { grid-column: 1 / -1; }
.row-actions { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.pays-edit li { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto; gap: 6px 8px; align-items: end; padding: 6px 0; }
.pays-edit .row-actions { grid-column: 1 / -1; justify-content: flex-end; }
@media (min-width: 700px) { .pays-edit li { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) 120px auto; } .pays-edit .row-actions { grid-column: auto; } }
.pay-amt { text-align: right; padding-bottom: 8px; font-variant-numeric: tabular-nums; }
.vat { border: 0; padding: 0; margin: 12px 0 0; display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; }
.vat legend { float: left; font-weight: 600; margin-right: 8px; padding: 0; }
.vat select { width: auto; }
.vat-round { color: var(--muted); margin-left: 8px; }
.totals { margin-top: 10px; background: var(--bg); border-radius: 6px; padding: 8px 12px; }
.totals dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0; }
.totals dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.totals p { margin: 4px 0 0; text-align: right; font-weight: 600; }
.clause { border-top: 1px dashed var(--line); padding: 10px 0; display: grid; gap: 6px; }
.disclaimer { color: var(--muted); font-size: .85rem; }

dialog.list { width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 64px); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
dialog.list::backdrop { background: rgb(0 0 0 / .4); }
.list-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.list-head h2 { margin: 0; font-size: 1.1rem; }
dialog.list ul { list-style: none; padding: 0; margin: 0; }
dialog.list li { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
dialog.list li.current { background: #f0f5ff; }
dialog.list li > div:first-child { display: flex; flex-direction: column; min-width: 0; }
dialog.list small { color: var(--muted); }

/* 미리보기: 실제 A4 크기로 그리고 화면 폭에 맞춰 줄임 */
.preview-wrap { overflow: hidden; }
.sheet-scale { transform-origin: top left; width: 210mm; }
.sheet {
  width: 210mm; min-height: 297mm; padding: 14mm; background: #fff; color: #111;
  font-size: 10pt; line-height: 1.5; box-shadow: 0 1px 4px rgb(0 0 0 / .15);
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.sheet h2, .sheet h3, .sheet p { margin: 0; }
.sheet dl { display: grid; grid-template-columns: max-content 1fr; gap: 1px 10px; margin: 0; }
.sheet dt { color: #555; }
.sheet dd { margin: 0; }
.sheet-top { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; border-bottom: 2px solid #111; padding-bottom: 8px; margin-bottom: 12px; }
.sheet-title { font-size: 22pt; font-weight: 700; letter-spacing: .15em; }
.sheet-meta { font-size: 9pt; }
.parties { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.party { border: 1px solid #bbb; padding: 8px 10px; position: relative; font-size: 9pt; }
.party h3 { font-size: 8.5pt; color: #555; font-weight: 600; margin-bottom: 2px; }
.party-name { font-size: 12pt; font-weight: 700; margin-bottom: 4px !important; }
.supplier { padding-right: 26mm; min-height: 30mm; }
.stamp { position: absolute; top: 6mm; right: 4mm; width: 20mm; height: 20mm; object-fit: contain; }
.lead { margin: 4px 0 6px !important; }
.grand { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 12px; background: #eef2f7; border: 1px solid #bbb; padding: 8px 10px; margin-bottom: 10px; }
.grand strong { font-size: 12pt; }
.won { font-weight: 600; font-size: 10pt; }
.sheet table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.items { table-layout: fixed; margin-bottom: 4px; }
.items th, .items td, .pays th, .pays td { border: 1px solid #bbb; padding: 4px 5px; vertical-align: top; text-align: left; }
.items th, .pays th { background: #eef2f7; font-weight: 600; font-size: 9pt; }
.items td.note { font-size: 8.5pt; color: #333; }
.items .c-no { width: 8mm; } .items .c-qty { width: 15mm; } .items .c-unit { width: 13mm; }
.items .c-price { width: 25mm; } .items .c-amt { width: 27mm; } .items .c-note { width: 32mm; }
.sheet .r { text-align: right; white-space: nowrap; }
.sheet .c { text-align: center; }
.items .empty { text-align: center; color: #888; padding: 14px; }
.sum { width: 75mm !important; margin: 0 0 10px auto; }
.sum th, .sum td { padding: 3px 6px; border-bottom: 1px solid #ddd; text-align: right; }
.sum th { font-weight: 400; color: #555; }
.sum .total th, .sum .total td { font-weight: 700; color: #111; border-bottom: 2px solid #111; }
.block { margin-top: 10px; }
.block h3 { font-size: 10pt; margin-bottom: 4px; }
.pays { width: 110mm !important; }
.clauses { margin: 0; padding-left: 1.4em; font-size: 9pt; }
.clauses li { margin-bottom: 3px; white-space: pre-line; }
.terms { white-space: pre-wrap; }

/* 안내 페이지 */
.page h2 { font-size: 1.15rem; margin: 28px 0 8px; }
.page h3 { font-size: 1rem; margin: 18px 0 6px; }
.page table { border-collapse: collapse; width: 100%; font-size: .92rem; }
.page th, .page td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.placeholder { background: #fff0b3; padding: 0 3px; border-radius: 3px; font-family: ui-monospace, monospace; font-size: .92em; }
.signup { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 20px 0; display: grid; gap: 12px; }
.signup fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 6px; }
.signup legend { font-weight: 600; margin-bottom: 4px; padding: 0; }
.signup .opts { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.signup .hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.signup button[type=submit] { justify-self: start; }
.result { margin: 0; font-weight: 600; }
.result.ok { color: #17592f; }
.result.err { color: var(--danger); }

/* 인쇄: 문서만 A4에 맞춰 출력 */
@page { size: A4; margin: 14mm 12mm; }
@media print {
  body { background: #fff; }
  .site-header, .site-footer, .no-print, .skip { display: none !important; }
  .editor-page :is(h1, .lede, .privacy-note, .industries, .guide, noscript, .toolbar, .status, .editor, .warn, dialog) { display: none !important; }
  main { padding: 0; max-width: none; }
  .workspace { display: block; }
  .preview { position: static; max-height: none; overflow: visible; }
  .preview-wrap { height: auto !important; overflow: visible; }
  .sheet-scale { transform: none !important; width: auto; }
  /* @page 여백이 종이 여백이 되므로 시트 자체 여백과 높이는 없앱니다. */
  /* 좌우 0.3mm는 표와 상자의 바깥 테두리가 인쇄 영역 끝에서 잘리지 않게 두는 여유입니다. */
  .sheet { width: auto; min-height: 0; padding: 0 .3mm; box-shadow: none; }
  .items thead { display: table-header-group; }   /* 쪽이 넘어가면 머리줄 반복 */
  .items tr, .pays tr, .clauses li, .party, .grand { break-inside: avoid; page-break-inside: avoid; }
  .sum { break-before: avoid; page-break-before: avoid; break-inside: avoid; }  /* 합계는 마지막 품목과 같은 쪽에 */
  .block h3, .sheet-top { break-after: avoid; page-break-after: avoid; }
  .block { break-inside: auto; }
  .pays, .parties { break-inside: avoid; }
}
