@font-face { font-family: 'Pretendard'; font-weight: 400; font-display: swap; src: url(fonts/Pretendard-Regular.woff2) format('woff2'); }
@font-face { font-family: 'Pretendard'; font-weight: 600; font-display: swap; src: url(fonts/Pretendard-SemiBold.woff2) format('woff2'); }
@font-face { font-family: 'Pretendard'; font-weight: 700; font-display: swap; src: url(fonts/Pretendard-Bold.woff2) format('woff2'); }

:root {
  --ink: #14285A;        /* 짙은 잉크 파랑 — 화면의 유일한 색 */
  --ink-2: #1E3A7B;
  --ink-soft: #E9EDF6;
  --text: #0F1623;
  --sub: #4A5466;
  --mute: #7A8394;
  --line: #D5DAE3;
  --line-2: #E7EAF0;
  --stage: #ECEEF2;
  --bad: #B42318;
  --bad-soft: #FDECEA;
  --ok: #1F6B3A;
  --bg: #FFFFFF;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: 'Pretendard', system-ui, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif; font-size: 15px; line-height: 1.5; }
.num, input.num, output.num { font-variant-numeric: tabular-nums; }
.r { text-align: right; }
button, input, select, textarea { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

/* ── 머리 */
.strip { background: var(--text); color: #fff; font-size: 12.5px; padding: 6px 16px; text-align: center; letter-spacing: -0.01em; }
.top { display: flex; align-items: center; justify-content: space-between; padding: 0 24px; height: 56px; border-bottom: 1px solid var(--line); background: #fff; position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; }
.brand b { font-weight: 700; letter-spacing: -0.02em; }
.brand-sub { color: var(--sub); }
.brand-mark { width: 22px; height: 22px; background: var(--ink); border-radius: 4px; position: relative; }
.brand-mark::after { content: ''; position: absolute; left: 6px; top: 5px; width: 10px; height: 12px; background: #fff; clip-path: polygon(0 0, 65% 0, 100% 30%, 100% 100%, 0 100%); }
.top-tools { display: flex; gap: 4px; }
.tool { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 7px 12px; font-size: 14px; cursor: pointer; }
.tool:hover { border-color: var(--ink); color: var(--ink); }
.tool.danger { color: var(--bad); border-color: #EBC3BF; }
.tool.file { position: relative; overflow: hidden; display: inline-block; }
.tool.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ── 배치: 왼쪽 입력, 오른쪽 미리보기 */
.layout { display: grid; grid-template-columns: minmax(440px, 600px) 1fr; min-height: calc(100vh - 56px - 31px); }
.mtabs { display: none; }
.form-pane { padding: 28px 28px 140px; border-right: 1px solid var(--line); }
.preview-pane { background: var(--stage); padding: 16px 24px 110px; position: sticky; top: 56px; height: calc(100vh - 56px); overflow: auto; min-width: 0; }
.layout { align-items: start; }

.form-head h1 { font-size: 26px; line-height: 1.32; font-weight: 700; letter-spacing: -0.035em; margin: 0 0 10px; }
.form-head-tools { display: flex; gap: 14px; margin-bottom: 18px; }
.link { background: none; border: 0; padding: 4px 0; color: var(--ink); font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }

/* ── 입력 묶음 */
.blk { border: 0; border-top: 2px solid var(--text); margin: 0 0 26px; padding: 14px 0 0; min-width: 0; }
.blk legend { padding: 0 10px 0 0; font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 8px; letter-spacing: -0.02em; }
.blk .no { width: 24px; height: 24px; border-radius: 50%; background: var(--ink); color: #fff; font-size: 13px; display: inline-grid; place-items: center; font-variant-numeric: tabular-nums; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.f { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.f-wide { grid-column: 1 / -1; }
.f > span:first-child { font-size: 13.5px; font-weight: 600; color: var(--sub); }
.f em { font-style: normal; color: var(--ink); font-size: 12px; font-weight: 600; margin-left: 2px; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 9px 11px; background: #fff; font-size: 15px; min-height: 42px; }
textarea { resize: vertical; min-height: 76px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--ink); outline-offset: -1px; border-color: var(--ink); }
input[aria-invalid=true], select[aria-invalid=true] { border-color: var(--bad); background: var(--bad-soft); }
.hint { color: var(--mute); font-size: 12.5px; }
.hint.ok { color: var(--ok); }
.err { color: var(--bad); font-size: 12.5px; font-weight: 600; }
.err:empty { display: none; }
.combo { display: grid; grid-template-columns: 130px 1fr; gap: 6px; }
.combo3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }

/* ── 품목 줄 */
.items-head, .item { display: grid; grid-template-columns: 22px 0.8fr 1.1fr 0.8fr 1fr 82px; grid-template-areas: 'no name name name spec spec' 'no qty price tax amt tools' 'no err err err err err'; gap: 6px; align-items: center; }
.items-head { font-size: 12px; color: var(--mute); font-weight: 600; padding: 0 0 6px; row-gap: 0; border-bottom: 1px solid var(--line); }
.items-head .h-name { grid-area: name; } .items-head .h-spec { grid-area: spec; } .items-head .h-qty { grid-area: qty; } .items-head .h-price { grid-area: price; }
.items-head .h-tax { grid-area: tax; } .items-head .h-amt { grid-area: amt; }
.item-no { grid-area: no; align-self: start; margin-top: 9px; }
.i-name { grid-area: name; } .i-spec { grid-area: spec; } .i-tax { grid-area: tax; }
.i-qty { grid-area: qty; } .i-price { grid-area: price; } .i-amt { grid-area: amt; }
.i-tools { grid-area: tools; } .i-err { grid-area: err; }
.items { list-style: none; margin: 0; padding: 0; }
.item { padding: 6px 0; border-bottom: 1px solid var(--line-2); }
.item input, .item select { padding: 7px 8px; font-size: 14px; min-height: 38px; }
.item-no { font-size: 12px; color: var(--mute); text-align: center; font-variant-numeric: tabular-nums; }
.i-amt { font-weight: 600; font-size: 14px; padding-right: 2px; }
.i-tools { display: flex; gap: 2px; justify-content: flex-end; }
.i-tools button { width: 25px; height: 30px; border: 1px solid var(--line); background: #fff; border-radius: 5px; cursor: pointer; font-size: 12px; padding: 0; color: var(--sub); }
.i-tools button:hover:not(:disabled) { border-color: var(--ink); color: var(--ink); }
.i-tools button:disabled { opacity: .35; cursor: default; }
.items-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
.add { border: 1px dashed var(--ink); color: var(--ink); background: #fff; border-radius: 6px; padding: 8px 14px; font-weight: 600; cursor: pointer; }
.items-sum { color: var(--sub); font-size: 14px; }
.items-sum b { color: var(--text); font-size: 16px; }

/* ── 합계 카드 */
.sum-card { border: 2px solid var(--ink); border-radius: 10px; padding: 18px 20px; }
.sum-card dl { margin: 0; display: grid; grid-template-columns: 1fr 1fr 1.5fr; gap: 10px; }
.sum-card dt { font-size: 13px; color: var(--sub); font-weight: 600; }
.sum-card dd { margin: 0; font-size: 18px; font-weight: 600; }
.sum-card .sum dd { font-size: 28px; font-weight: 700; color: var(--ink); letter-spacing: -0.02em; }
.sum-card .sum small { font-size: 15px; margin-left: 2px; }
.sum-card .kor { margin: 10px 0 0; font-weight: 600; }
.sum-card .rule { margin: 4px 0 0; color: var(--mute); font-size: 12.5px; }
.sum-wait { margin: 0; color: var(--sub); }

/* ── 미리보기 */
.pv-tabs { display: inline-flex; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 3px; gap: 2px; }
.pv-tabs button { border: 0; background: none; padding: 8px 14px; border-radius: 6px; font-weight: 600; cursor: pointer; display: flex; flex-direction: column; align-items: center; line-height: 1.25; color: var(--sub); min-width: 112px; }
.pv-tabs button i { font-style: normal; font-size: 11.5px; font-weight: 500; font-variant-numeric: tabular-nums; color: var(--mute); }
.pv-tabs button i.changed { color: var(--bad); }
.pv-tabs button[aria-selected=true] { background: var(--ink); color: #fff; }
.pv-tabs button[aria-selected=true] i { color: #C9D3EA; }
.pv-status { margin: 10px 0 12px; font-size: 13.5px; color: var(--sub); }
.pv-status b { color: var(--text); font-variant-numeric: tabular-nums; }
.pv-status.changed { color: var(--bad); }
.pv-status.changed b { color: var(--bad); }
.pv-stage { display: flex; justify-content: center; }
.pv-zoom { transform-origin: top center; }
.sheet { width: 210mm; min-height: 297mm; background: #fff; padding: 14mm 15mm; box-shadow: 0 1px 2px rgba(15,22,35,.08), 0 8px 28px rgba(15,22,35,.10); }

/* ── 아래 바: 주 버튼 하나 */
.actionbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; align-items: center; gap: 18px; padding: 12px 24px calc(12px + env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -4px 18px rgba(15,22,35,.06); }
.ab-total { margin-right: auto; display: flex; align-items: baseline; gap: 10px; }
.ab-total span { color: var(--sub); font-size: 14px; font-weight: 600; }
.ab-total b { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.primary { background: var(--ink); color: #fff; border: 0; border-radius: 8px; padding: 13px 22px; font-weight: 700; font-size: 16px; cursor: pointer; letter-spacing: -0.01em; }
.primary:hover { background: var(--ink-2); }
.primary:focus-visible, .link:focus-visible, .tool:focus-visible, button:focus-visible { outline: 3px solid #8FA6D8; outline-offset: 2px; }
.actionbar .link { order: -1; }
.actionbar .ab-total { order: -2; }

.errbox { position: fixed; right: 24px; bottom: 84px; z-index: 40; width: min(420px, calc(100vw - 32px)); background: #fff; border: 2px solid var(--bad); border-radius: 10px; padding: 14px 16px; box-shadow: 0 10px 30px rgba(15,22,35,.18); }
.errbox b { color: var(--bad); }
.errbox ul { margin: 6px 0 4px; padding-left: 18px; font-size: 14px; }

/* ── 창 */
.dlg { border: 0; border-radius: 12px; padding: 0; width: min(680px, calc(100vw - 24px)); max-height: calc(100vh - 32px); box-shadow: 0 20px 60px rgba(15,22,35,.3); }
.dlg-wide { width: min(900px, calc(100vw - 24px)); }
.dlg-small { width: min(440px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(15,22,35,.45); }
.dlg form { padding: 22px 24px; }
.dlg h2 { margin: 0 0 8px; font-size: 20px; letter-spacing: -0.02em; }
.dlg h2 small { font-size: 13px; color: var(--mute); font-weight: 500; margin-left: 6px; }
.note { margin: 0 0 14px; color: var(--sub); font-size: 13.5px; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 16px; align-items: center; margin-top: 18px; }
.danger-bg { background: var(--bad); }
.danger-bg:hover { background: #8F1C13; }
.hist-wrap { max-height: 46vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.hist { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.hist th { position: sticky; top: 0; background: #F6F7F9; text-align: left; font-weight: 600; color: var(--sub); padding: 8px 10px; border-bottom: 1px solid var(--line); }
.hist td { padding: 8px 10px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
.hist tr.old td { color: var(--mute); text-decoration: line-through; text-decoration-color: rgba(122,131,148,.5); }
.hist tr.old .tag { text-decoration: none; display: inline-block; color: var(--bad); }
.hist .empty { text-align: center; color: var(--mute); padding: 24px; }
.hist-tools { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.msg { min-height: 1.4em; font-size: 13.5px; color: var(--ink); margin: 10px 0 0; }

/* ── 휴대폰: 입력 → 미리보기 탭 */
@media (max-width: 899px) {
  .top { padding: 0 16px; height: 52px; }
  .brand-sub { display: none; }
  .mtabs { display: grid; grid-template-columns: 1fr 1fr; position: sticky; top: 52px; z-index: 19; background: #fff; border-bottom: 1px solid var(--line); }
  .mtabs button { border: 0; background: none; padding: 12px 0; font-weight: 700; color: var(--mute); border-bottom: 3px solid transparent; cursor: pointer; }
  .mtabs button[aria-selected=true] { color: var(--ink); border-bottom-color: var(--ink); }
  .layout { display: block; min-height: 0; }
  .layout[data-pane=form] .preview-pane { display: none; }
  .layout[data-pane=preview] .form-pane { display: none; }
  .form-pane { padding: 20px 16px 130px; border-right: 0; }
  .form-head h1 { font-size: 22px; }
  .preview-pane { padding: 14px 8px 150px; min-height: calc(100vh - 140px); position: static; height: auto; overflow: visible; }
  .pv-tabs { display: flex; width: 100%; }
  .pv-tabs button { flex: 1; min-width: 0; padding: 7px 4px; }
  .pv-status { padding: 0 8px; }
  .grid2 { grid-template-columns: 1fr; }
  .items-head { display: none; }
  .item { grid-template-columns: 1fr 1fr 1fr; grid-template-areas: 'name name name' 'spec spec tax' 'qty price price' 'amt amt tools' 'err err err'; gap: 6px; padding: 12px 0 12px 30px; position: relative; }
  .item-no { position: absolute; left: 0; top: 18px; width: 22px; height: 22px; border-radius: 50%; background: var(--ink-soft); color: var(--ink); font-weight: 700; display: grid; place-items: center; }
  .i-name { grid-area: name; } .i-spec { grid-area: spec; } .i-tax { grid-area: tax; }
  .i-qty { grid-area: qty; } .i-price { grid-area: price; } .i-amt { grid-area: amt; text-align: left; font-size: 15px; }
  .i-amt::before { content: attr(data-formula); color: var(--mute); font-weight: 500; font-size: 12.5px; }
  .i-tools { grid-area: tools; } .i-tools button { width: 36px; height: 34px; }
  .i-err { grid-area: err; }
  .sum-card dl { grid-template-columns: 1fr 1fr; }
  .sum-card .sum { grid-column: 1 / -1; }
  .actionbar { padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); gap: 10px; flex-wrap: wrap; }
  .ab-total b { font-size: 20px; }
  .actionbar .primary { flex: 1 1 100%; order: 2; padding: 14px; }
  .actionbar .link { order: 1; margin-left: auto; }
  .errbox { right: 16px; bottom: 140px; }
  .dlg form { padding: 18px 16px; }
}
@media (max-width: 380px) {
  .form-head h1 { font-size: 20px; }
  .combo { grid-template-columns: 112px 1fr; }
}

/* 백업 알림 · 인쇄 안내 · 기록 찾기 */
.backup-warn { display: flex; gap: 14px; align-items: center; justify-content: center; flex-wrap: wrap; background: #FFF4E5; color: #7A3E00; border-bottom: 1px solid #F3D3A8; padding: 8px 16px; font-size: 13.5px; font-weight: 600; }
.backup-warn .link { color: #7A3E00; }
.pv-hint { margin: -6px 0 12px; font-size: 12.5px; color: var(--mute); }
.pv-hint b { color: var(--sub); }
.where { margin: 0 0 8px; font-size: 13px; color: var(--ink); font-weight: 600; }
.hist-q { margin-bottom: 8px; }
.note-strong { margin: 0 0 10px; font-size: 13px; font-weight: 600; color: var(--text); background: #F3F5F9; border-left: 3px solid var(--ink); padding: 6px 10px; }
.msg.bad { color: var(--bad); font-weight: 600; }
#confirm-yes:disabled { opacity: .4; cursor: default; }
@media (max-width: 899px) { .pv-hint { padding: 0 8px; } }
