/* 레이아웃: 상단 고정 바 + 주차 바 + 넓은 표. 업무용 화면, 인쇄 시 A4 가로 */
:root {
  --bg: #f3f6f4;
  --surface: #ffffff;
  --line: #dbe3df;
  --line-strong: #b9c7c0;
  --fg: #17211d;
  --muted: #5f6f68;
  --accent: #1c5b43;
  --accent-soft: #e2efe8;
  --warn: #9a5b00;
  --warn-soft: #fbf0dc;
  --danger: #a3261d;
  --danger-soft: #fbe6e3;
  --ok: #1f7a4d;
  --ok-soft: #dff3e7;
  --off: #f2f4f3;
  --font: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
.num, td.n, th.n { font-variant-numeric: tabular-nums; text-align: right; }
[hidden] { display: none !important; }
.boot { padding: 80px 16px; text-align: center; color: var(--muted); }

/* 상단 바 */
.top { position: sticky; top: 0; z-index: 20; background: var(--accent); color: #fff; }
.top-in { display: flex; align-items: center; gap: 16px; padding: 10px 20px; flex-wrap: wrap; }
.brand { font-weight: 800; font-size: 16px; letter-spacing: -0.01em; white-space: nowrap; }
.brand small { font-weight: 500; opacity: .75; margin-left: 6px; font-size: 13px; }
.who { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; }
.who b { font-weight: 700; }
.top .btn-ghost { color: #fff; border-color: rgba(255,255,255,.4); }
.top .btn-ghost:hover { background: rgba(255,255,255,.12); }
.tabs { display: flex; gap: 2px; padding: 0 12px; overflow-x: auto; }
.tab { background: none; border: 0; color: rgba(255,255,255,.75); padding: 9px 14px; cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; font-weight: 600; }
.tab:hover { color: #fff; }
.tab.on { color: #fff; border-bottom-color: #9fe0bf; }
.demo-bar { background: var(--warn-soft); color: var(--warn); padding: 6px 20px; font-size: 13px; }

main { padding: 18px 20px 60px; max-width: 1500px; margin: 0 auto; }

/* 버튼 */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); background: var(--surface); padding: 7px 13px; border-radius: 6px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn:focus-visible, .tab:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 4px 9px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; }

/* 주차 바 */
.weekbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.weekpick { display: flex; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 3px; }
.weekpick button { border: 0; background: none; padding: 5px 10px; cursor: pointer; border-radius: 5px; font-size: 15px; }
.weekpick button:hover { background: var(--accent-soft); }
.weekpick .lbl { font-weight: 700; padding: 0 8px; font-variant-numeric: tabular-nums; min-width: 190px; text-align: center; }
.spacer { flex: 1; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.chip { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.chip-ok { background: var(--ok-soft); color: var(--ok); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-none { background: var(--off); color: var(--muted); }
.chip-danger { background: var(--danger-soft); color: var(--danger); }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 0 5px; border-radius: 4px; margin-left: 4px; vertical-align: 1px; }
.tag-new { background: #e4ecfb; color: #2648a3; }
.tag-fix { background: var(--accent-soft); color: var(--accent); }
.tag-store { background: var(--warn-soft); color: var(--warn); }

.notice { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent); padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; white-space: pre-wrap; }
.hint { color: var(--muted); font-size: 13px; }

/* 필터 */
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.filters input[type=search], .filters select { border: 1px solid var(--line-strong); border-radius: 6px; padding: 6px 10px; background: var(--surface); min-width: 0; }
.filters input[type=search] { width: 200px; max-width: 100%; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 12px; cursor: pointer; font-weight: 600; }
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button.on { background: var(--accent); color: #fff; }

/* 표 */
.tbl-wrap { overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; max-height: calc(100vh - 230px); }
table.t { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
table.t th, table.t td { padding: 5px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t thead th { position: sticky; top: 0; background: #eef3f0; z-index: 2; font-weight: 700; color: var(--muted); font-size: 12px; text-align: left; border-bottom: 1px solid var(--line-strong); }
table.t thead th.n { text-align: right; }
table.t thead th.day { text-align: center; width: 58px; }
table.t tbody tr:hover td { background: #f7faf8; }
table.t tr.grp td { background: var(--accent-soft); font-weight: 800; color: var(--accent); font-size: 12px; letter-spacing: .02em; position: sticky; top: 30px; z-index: 1; }
table.t tr.sub td { color: var(--muted); font-size: 12px; }
table.t tfoot td { position: sticky; bottom: 0; background: #eef3f0; font-weight: 800; border-top: 1px solid var(--line-strong); }
td.name { font-weight: 600; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
td.muted, .muted { color: var(--muted); }
td.zero { color: #c3ccc8; }
td.tot { font-weight: 800; }
td.cell { padding: 2px 3px; text-align: center; }
input.q { width: 52px; padding: 4px 4px; border: 1px solid var(--line); border-radius: 4px; text-align: right; font-variant-numeric: tabular-nums; background: #fff; }
input.q:hover { border-color: var(--line-strong); }
input.q.off { background: var(--off); color: var(--muted); }
input.q.has { border-color: var(--accent); background: #f4faf7; font-weight: 700; }
input.q[readonly] { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 700; }
input.q::-webkit-outer-spin-button, input.q::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input.q { -moz-appearance: textfield; }

/* 편집 표(품목관리) */
input.e, select.e { width: 100%; min-width: 50px; padding: 3px 5px; border: 1px solid transparent; border-radius: 4px; background: transparent; }
input.e:hover, select.e:hover { border-color: var(--line); }
input.e:focus, select.e:focus { border-color: var(--accent); background: #fff; }
input.e.n { text-align: right; }
tr.dirty td { background: var(--warn-soft) !important; }
tr.stopped td { opacity: .55; }

/* 요약 */
.summary { display: flex; gap: 22px; flex-wrap: wrap; align-items: baseline; margin: 12px 2px 0; }
.summary .k { color: var(--muted); font-size: 12px; margin-right: 6px; }
.summary .v { font-weight: 800; font-size: 17px; font-variant-numeric: tabular-nums; }

/* 제출현황 카드 */
.grid-stores { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.scard { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px; cursor: pointer; display: grid; gap: 6px; text-align: left; }
.scard:hover { border-color: var(--accent); }
.scard .nm { font-weight: 800; font-size: 15px; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.scard .row { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.scard .row b { color: var(--fg); font-variant-numeric: tabular-nums; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 16px; display: grid; gap: 12px; max-width: 720px; }
.panel h3 { margin: 0; font-size: 15px; }
.form-row { display: grid; grid-template-columns: 110px 1fr; gap: 10px; align-items: center; }
.form-row input, .form-row textarea, .form-row select { border: 1px solid var(--line-strong); border-radius: 6px; padding: 6px 10px; background: #fff; width: 100%; }

h2.page { font-size: 18px; margin: 0 0 4px; }
.store-block { margin-bottom: 22px; }
h3.store-h { font-size: 16px; margin: 0 0 8px; }
h3.store-h .muted { font-size: 13px; font-weight: 500; }
.print-head { display: none; }

/* 로그인 */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 32px 28px; width: 100%; max-width: 360px; display: grid; gap: 14px; }
.login h1 { margin: 0; font-size: 22px; color: var(--accent); letter-spacing: -0.02em; }
.login p { margin: 0; color: var(--muted); font-size: 13px; }
.login label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; }
.login input { border: 1px solid var(--line-strong); border-radius: 6px; padding: 9px 11px; font-size: 15px; }
.login .err { color: var(--danger); font-size: 13px; min-height: 1em; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--fg); color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 100; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.18); }
.toast.err { background: var(--danger); }

@media (max-width: 700px) {
  main { padding: 12px 12px 60px; }
  .top-in { padding: 8px 12px; }
  .weekpick .lbl { min-width: 0; }
  td.name { max-width: 150px; }
  .tbl-wrap { max-height: none; }
  .form-row { grid-template-columns: 1fr; gap: 4px; }
}


/* ---------- 출력표 (조리·전처리·포장) ---------- */
.part-block, .store-block { margin-bottom: 22px; }
h3.part-h, h3.store-h { display: flex; align-items: baseline; gap: 10px; font-size: 17px; font-weight: 800; margin: 0 0 8px; padding-left: 10px; border-left: 5px solid var(--accent); }
h3.part-h span, h3.store-h span { font-size: 13px; font-weight: 500; color: var(--muted); }
table.out { font-size: 14px; }
table.out th, table.out td { padding: 6px 9px; vertical-align: middle; }
table.out thead th { font-size: 12.5px; color: var(--fg); background: #e6eeea; }
table.out tbody tr:nth-child(even) td { background: #f8faf9; }
table.out td.code { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
table.out td.name { font-weight: 700; font-size: 14.5px; max-width: 240px; white-space: normal; }
table.out td.name .sub { font-weight: 400; font-size: 12px; color: var(--muted); }
table.out td.n { text-align: right; }
table.out .amt { display: block; font-weight: 800; font-size: 15px; line-height: 1.2; }
table.out .pk { display: block; font-size: 11.5px; color: var(--muted); line-height: 1.2; white-space: nowrap; }
table.out .nil { color: #c6cfcb; }
table.out td.big { font-weight: 800; font-size: 15.5px; }
table.out td.tot { background: #eef5f1 !important; border-left: 2px solid var(--line-strong); }
table.out td.tot .amt { font-size: 16px; }
table.out td.prods { white-space: normal; color: var(--muted); font-size: 12.5px; min-width: 240px; }
table.out th.st { min-width: 64px; }
table.out td.chk, table.out th.chk { width: 56px; text-align: center; border-left: 1px solid var(--line); }
table.out tr.grp td { background: var(--accent-soft) !important; font-weight: 800; color: var(--accent); position: static; }

/* 매장별 출고표: 2단 */
.cols2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
.cols2 > * { min-width: 0; }
@media (max-width: 1000px) { .cols2 { grid-template-columns: 1fr; } }
.self-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 2px 10px; max-height: 320px; overflow: auto; border: 1px solid var(--line, #ddd); border-radius: 8px; padding: 8px; font-size: 13px; }
.self-item { display: flex; align-items: center; gap: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
table.out td.src { white-space: nowrap; text-align: center; font-size: 12px; color: var(--muted); }
table.out td.src.self { color: #b45309; font-weight: 900; background: #fff4e5; }
table.out td.box { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
table.out .pk-inline { margin-left: 6px; font-size: 11.5px; font-weight: 400; color: var(--muted); }
table.out.compact td.name { max-width: none; }
/* 생산요일이 아닌 칸: 입력 불가 */
input.q.off[disabled] { background: repeating-linear-gradient(135deg, #eef1f0 0 4px, #e2e7e5 4px 8px); border-color: transparent; cursor: not-allowed; color: transparent; }

/* ---------- 인쇄: A3 세로 (가로 281mm × 세로 404mm 사용) ----------
   장수 최소: 파트별 강제 페이지 나눔 없이 이어서 출력, 표 머리글은 매 장 반복
   가독성: 제품명·수량 크게/굵게, 줄 음영, 합계 열 강조 */
@media print {
  @page {
    size: A3 portrait; margin: 8mm 8mm 11mm;
    @bottom-center { content: counter(page) " / " counter(pages); font-size: 9pt; color: #555; }
  }
  html, body { background: #fff !important; }
  body { font-size: 11pt; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .top, .demo-bar, .weekbar, .filters, .no-print, .toast, .summary .btn, .hint, .notice { display: none !important; }
  main { padding: 0; max-width: none; zoom: 1; }
  .print-head { display: flex; justify-content: space-between; align-items: baseline; margin: 0 0 3mm; border-bottom: 3pt solid #000; padding-bottom: 2mm; }
  .print-head h1 { font-size: 20pt; font-weight: 900; margin: 0; letter-spacing: -0.02em; }
  .print-head span { font-size: 11pt; font-weight: 700; }
  .tbl-wrap { overflow: visible; max-height: none; border: 0; border-radius: 0; background: none; }

  table.t { width: 100%; font-size: 11pt; border-collapse: collapse; }
  table.t th, table.t td { padding: 0.8mm 1.8mm; border: 0.5pt solid #999; color: #000; line-height: 1.08; }
  table.t thead { display: table-header-group; }
  table.t thead th { position: static; background: #d9d9d9 !important; color: #000; font-size: 10.5pt; font-weight: 800; text-align: center; border-bottom: 1.2pt solid #000; }
  table.t tr.grp td { position: static; background: #e6e6e6 !important; color: #000; font-weight: 900; }
  table.t tfoot td { position: static; }
  tr { break-inside: avoid; page-break-inside: avoid; }

  table.out tbody tr:nth-child(even) td { background: #f2f2f2 !important; }
  table.out td.code { font-size: 9.5pt; color: #333; width: 1%; white-space: nowrap; }
  table.out td.name { font-size: 12.5pt; font-weight: 800; max-width: none; }
  table.out td.name .sub { font-size: 8.5pt; font-weight: 400; color: #333; line-height: 1; }
  table.out .amt { font-size: 13pt; font-weight: 900; line-height: 1; }
  table.out .pk { font-size: 8.5pt; color: #333; line-height: 1; }
  table.out td.big { font-size: 13.5pt; font-weight: 900; }
  table.out td.tot { background: #e2e2e2 !important; border-left: 1.8pt solid #000; }
  table.out td.tot .amt { font-size: 13.5pt; }
  table.out td.prods { font-size: 9pt; color: #222; }
  table.out .nil { color: #b3b3b3; }
  table.out td.chk { width: 12mm; }
  table.out th.st { min-width: 0; }

  /* 파트/구역 제목: 표와 떨어지지 않게, 강제 페이지 나눔 없음 */
  h3.part-h, h3.store-h { font-size: 15pt; font-weight: 900; border-left: 0; padding: 0 0 1.2mm; margin: 0 0 1.5mm; border-bottom: 2pt solid #000; break-after: avoid; page-break-after: avoid; }
  h3.part-h span, h3.store-h span { font-size: 10pt; font-weight: 600; color: #000; }
  .part-block { margin: 0 0 5mm; break-after: auto; page-break-after: auto; }

  /* 매장별 출고표: 매장당 1장(A3 세로), 2단 */
  .store-block { margin: 0; break-after: page; page-break-after: always; }
  .store-block:last-of-type { break-after: auto; page-break-after: auto; }
  .cols2 { grid-template-columns: 1fr 1fr; gap: 4mm; }
  table.out.compact { font-size: 11.5pt; }
  table.out.compact th, table.out.compact td { padding: 1mm 1.6mm; }
  table.out.compact td.name { font-size: 12.5pt; }
  table.out.compact td.big { font-size: 13.5pt; }
  table.out.compact td.code { font-size: 9pt; }
  table.out.compact .pk-inline { font-size: 8.5pt; color: #333; }
  table.out.compact td.chk { width: 8mm; }
  table.out.compact tr.grp td { font-size: 10pt; padding: 0.6mm 1.6mm; }
  table.out.compact.dense { font-size: 10pt; }
  table.out.compact.dense th, table.out.compact.dense td { padding: 0.5mm 1.4mm; line-height: 1.02; }
  table.out.compact.dense td.name { font-size: 10.5pt; }
  table.out.compact.dense td.big { font-size: 11.5pt; }
  table.out.compact.dense td.code { font-size: 8pt; }
  td.zero { color: #bbb; }
}
/* ---------- 매장 주간 물량표 (매장 배포용) ---------- */
.dist-block { margin-bottom: 28px; }
.dist-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; border-bottom: 3px solid var(--accent); padding-bottom: 6px; margin-bottom: 8px; }
.dist-head h2 { margin: 0; font-size: 20px; font-weight: 900; }
.dist-head span { color: var(--muted); font-size: 13px; }
.dist-wrap { max-height: none; }
table.dist { font-size: 13px; }
table.dist th, table.dist td { padding: 4px 7px; }
table.dist thead th { background: #e6eeea; color: var(--fg); text-align: center; position: static; }
table.dist td.code, table.dist td.cyc, table.dist td.pk2, table.dist td.pr { color: var(--muted); font-size: 12px; }
table.dist td.name { font-weight: 600; max-width: none; }
table.dist tr.on td.name { font-weight: 800; }
table.dist td.d { font-weight: 800; font-size: 14px; min-width: 54px; }
table.dist td.d.x { background: repeating-linear-gradient(135deg, #f1f3f2 0 4px, #e3e7e5 4px 8px); }
table.dist td.tot { font-weight: 900; background: #eef5f1; border-left: 2px solid var(--line-strong); }
table.dist td.amt2 { font-size: 12px; }
table.dist tr.grp td { background: var(--accent-soft); color: var(--accent); font-weight: 800; position: static; }
table.dist tfoot td { font-weight: 900; }

@media print {
  .dist-block { margin: 0; break-before: page; page-break-before: always; }
  .dist-block:first-of-type { break-before: auto; page-break-before: auto; }
  .dist-head { border-bottom: 3pt solid #000; padding-bottom: 1.5mm; margin-bottom: 2mm; }
  .dist-head h2 { font-size: 20pt; }
  .dist-head span { font-size: 10.5pt; color: #000; font-weight: 600; }
  table.dist { font-size: 10.5pt; }
  table.dist th, table.dist td { padding: 0.35mm 1.6mm; line-height: 1.03; }
  table.dist thead th { font-size: 10pt; }
  table.dist td.code, table.dist td.cyc, table.dist td.pk2, table.dist td.pr { font-size: 9pt; color: #333; }
  table.dist td.name { font-size: 11pt; }
  table.dist td.d { font-size: 12pt; font-weight: 900; }
  table.dist td.d.x { background: repeating-linear-gradient(135deg, #f0f0f0 0 3px, #d9d9d9 3px 6px) !important; }
  table.dist td.tot { font-size: 12pt; background: #e2e2e2 !important; border-left: 1.8pt solid #000; }
  table.dist td.amt2 { font-size: 9.5pt; }
  table.dist tr.grp td { background: #e0e0e0 !important; color: #000; font-size: 10pt; padding: 0.4mm 1.6mm; }
  table.dist tbody tr:nth-child(even) td:not(.x):not(.tot) { background: #f5f5f5 !important; }
  table.dist tfoot td { background: #d9d9d9 !important; font-size: 11pt; border-top: 1.5pt solid #000; }
  table.dist tfoot { display: table-row-group; }
  /* 매장 계정 주간 발주서: A4 세로 (A3용 글자를 줄여 폭에 맞춤, 품목이 많으면 다음 장으로 이어짐) */
  @page order4 { size: A4 portrait; margin: 8mm 8mm 10mm; }
  .dist-block.a4 { page: order4; }
  .dist-block.a4 .dist-head h2 { font-size: 15pt; }
  .dist-block.a4 .dist-head span { font-size: 8.5pt; }
  .dist-block.a4 table.dist { font-size: 8pt; }
  .dist-block.a4 table.dist { width: 100%; }
  .dist-block.a4 table.dist th, .dist-block.a4 table.dist td { padding: 0.3mm 0.7mm; line-height: 1.05; }
  .dist-block.a4 table.dist thead th { font-size: 7.5pt; }
  .dist-block.a4 table.dist td.code, .dist-block.a4 table.dist td.cyc, .dist-block.a4 table.dist td.pk2, .dist-block.a4 table.dist td.pr { font-size: 7pt; }
  .dist-block.a4 table.dist td.name { font-size: 8.5pt; }
  .dist-block.a4 table.dist td.d, .dist-block.a4 table.dist td.tot { font-size: 9pt; }
  .dist-block.a4 table.dist td.d { min-width: 0; }
  .dist-block.a4 table.dist td.amt2 { font-size: 7.5pt; }
  .dist-block.a4 table.dist tr.grp td { font-size: 8pt; padding: 0.4mm 1mm; }
  .dist-block.a4 table.dist tfoot td { font-size: 8.5pt; }
}
/* 조리팀·포장팀: 파트별로 새 장에서 시작 (전처리팀은 이어서 인쇄) */
@media print {
  .part-block.part-page { break-before: page; page-break-before: always; margin: 0; }
  .part-block.part-page:first-of-type { break-before: auto; page-break-before: auto; }
}
/* 인쇄 맞춤(.fit): 행 높이 --rh(mm)에 맞춰 글자 크기를 비례 조정
   조리팀 = 파트마다 1장, 포장팀(하루·주간) = 전체 2장 */
@media print {
  .fit table.out tbody td { height: var(--rh); padding-top: 0; padding-bottom: 0; line-height: 1; }
  .fit table.out td.code { font-size: min(3.4mm, calc(var(--rh) * 0.42)); }
  .fit table.out td.name { font-size: min(4.4mm, calc(var(--rh) * 0.5)); }
  table.out td.src { font-size: 9pt; color: #000; }
  table.out td.src.self { background: #ddd !important; font-weight: 900; }
  .fit table.out td.box { font-size: min(3.2mm, calc(var(--rh) * 0.4)); color: #333; }
  .fit table.out td.name .sub { font-size: min(3mm, calc(var(--rh) * 0.33)); }
  .fit table.out td.n { font-size: min(4.2mm, calc(var(--rh) * 0.52)); }
  .fit table.out td.big { font-size: min(4.6mm, calc(var(--rh) * 0.6)); }
  .fit table.out .amt { font-size: min(4.6mm, calc(var(--rh) * 0.54)); line-height: 1; }
  .fit table.out .pk { font-size: min(3mm, calc(var(--rh) * 0.33)); line-height: 1; }
  .fit table.out td.tot .amt { font-size: min(4.8mm, calc(var(--rh) * 0.56)); }
  .fit h3.part-h { margin-bottom: 1mm; }
  /* 포장팀은 파트를 이어서 인쇄 (파트 사이 간격만) */
  .part-block.fit:not(.part-page) { break-before: auto; page-break-before: auto; margin: 0 0 3mm; }
}
/* 장수 제한 보강: 행이 아주 작아져도 테두리·여백이 높이를 늘리지 않도록 */
@media print {
  .fit table.out tbody td { border-width: 0.3pt; overflow: hidden; }
  .fit table.out tbody td > * { overflow: hidden; }
}
/* ---------- 매장 송장 (거래명세서) ---------- */
.inv-block { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 22px 24px; margin: 0 auto 22px; max-width: 820px; color: #111; }
.inv-top { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 3px double #111; padding-bottom: 8px; margin-bottom: 10px; }
.inv-top h1 { margin: 0; font-size: 26px; font-weight: 900; letter-spacing: 0.15em; }
.inv-no { text-align: right; font-size: 13px; line-height: 1.6; }
.inv-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
table.inv-party { width: 100%; border-collapse: collapse; font-size: 12px; }
table.inv-party caption { text-align: left; font-weight: 800; font-size: 12px; padding: 0 0 3px; }
table.inv-party th, table.inv-party td { border: 1px solid #555; padding: 3px 6px; }
table.inv-party th { width: 74px; background: #f0f0f0; font-weight: 700; text-align: center; }
.inv-store { font-size: 15px; }
table.inv-party td.inv-small { font-size: 10px; letter-spacing: -0.3px; line-height: 1.25; }
.inv-storeno { font-weight: 400; color: #555; margin-left: 4px; }
.inv-sum { display: flex; align-items: baseline; gap: 14px; border: 2px solid #111; padding: 6px 10px; margin-bottom: 8px; font-size: 13px; }
.inv-sum b { font-size: 20px; font-weight: 900; }
.inv-sum span:last-child { margin-left: auto; color: #444; }
table.inv-items { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.inv-items th { background: #e8e8e8; border: 1px solid #555; padding: 4px 5px; font-weight: 800; }
table.inv-items td { border: 1px solid #999; padding: 3px 5px; }
table.inv-items td.n { text-align: right; font-variant-numeric: tabular-nums; }
table.inv-items td.c { text-align: center; }
table.inv-items td.code { color: #444; font-size: 11px; }
table.inv-items td.name { font-weight: 700; }
table.inv-items td.big { font-weight: 900; }
table.inv-items tbody tr:nth-child(even) td { background: #f7f7f7; }
table.inv-items tfoot td { border: 1px solid #555; border-top: 2px solid #111; font-weight: 900; background: #ececec; padding: 4px 5px; text-align: right; }
table.inv-items tfoot td:first-child { text-align: center; }
table.inv-sign { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 12px; }
table.inv-sign th { background: #f0f0f0; border: 1px solid #555; padding: 4px; width: 13%; }
table.inv-sign td { border: 1px solid #555; height: 34px; width: 20%; text-align: center; }
.inv-note { font-size: 11px; color: #444; margin: 5px 0 0; }

@media print {
  @page invoice { size: A4 portrait; margin: 8mm 8mm 9mm; }
  .inv-block { page: invoice; border: 0; border-radius: 0; padding: 0; margin: 0; max-width: none; break-after: page; page-break-after: always; }
  .inv-block:last-of-type { break-after: auto; page-break-after: auto; }
  .inv-top h1 { font-size: 22pt; }
  .inv-no { font-size: 10pt; }
  table.inv-party { font-size: 9pt; }
  table.inv-party th, table.inv-party td { padding: 0.8mm 1.5mm; }
  .inv-store { font-size: 12pt; }
  table.inv-party td.inv-small { font-size: 7.5pt; }
  .inv-sum { font-size: 10pt; padding: 1.5mm 3mm; }
  .inv-sum b { font-size: 15pt; }
  table.inv-items thead { display: table-header-group; }
  table.inv-items th { font-size: 9pt; padding: 0.8mm 1.2mm; background: #e0e0e0 !important; }
  /* 품목 행: --rh에 맞춰 높이·글자 크기 비례 (한 장에 맞춤) */
  table.inv-items tbody td { height: var(--rh); padding: 0 1.2mm; line-height: 1; font-size: min(3.9mm, calc(var(--rh) * 0.56)); border-width: 0.4pt; }
  table.inv-items tbody td.code { font-size: min(3.2mm, calc(var(--rh) * 0.46)); }
  table.inv-items tbody td.big { font-size: min(4.3mm, calc(var(--rh) * 0.62)); }
  table.inv-items tbody tr:nth-child(even) td { background: #f3f3f3 !important; }
  table.inv-items tfoot td { font-size: 10pt; padding: 1mm 1.2mm; background: #e6e6e6 !important; }
  table.inv-sign { font-size: 9pt; }
  table.inv-sign td { height: 10mm; }
  .inv-note { font-size: 8pt; }
  tr { break-inside: avoid; }
}
/* 송장 2단(품목 40개 초과) */
.inv-cols2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: start; }
.inv-cols2 > table { min-width: 0; }
table.inv-items.two td.name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 0; width: 44%; }
.inv-pk { margin-left: 4px; font-weight: 400; color: #555; font-size: 0.85em; }
table.inv-total { width: 100%; border-collapse: collapse; margin-top: 6px; font-weight: 900; font-size: 13px; }
table.inv-total td { border: 2px solid #111; padding: 4px 8px; text-align: right; background: #ececec; }
table.inv-total td:first-child { text-align: center; width: 30%; }
@media print {
  .inv-cols2 { gap: 2.5mm; }
  table.inv-items.two { table-layout: fixed; }
  table.inv-items.two th:nth-child(1) { width: 6mm; } table.inv-items.two th:nth-child(3) { width: 9mm; }
  table.inv-items.two th:nth-child(4) { width: 12mm; } table.inv-items.two th:nth-child(5) { width: 11mm; }
  table.inv-items.two th:nth-child(6) { width: 15mm; }
  table.inv-total { font-size: 10pt; margin-top: 1.5mm; }
  table.inv-total td { padding: 1mm 2mm; background: #e6e6e6 !important; }
}/* 전처리팀: 전처리 품목(A3 세로 1장) / 세트 부재료(A3 가로 1장)를 각각 따로 인쇄
   .fill = 행이 적으면 행 높이(--rh, 최대 30mm)와 글자를 키워 용지를 꽉 채움 (세로 장은 폭이 좁아 글자 상한을 낮춤) */
@media print {
  @page prepset {
    size: A3 landscape; margin: 8mm 8mm 11mm;
    @bottom-center { content: counter(page) " / " counter(pages); font-size: 9pt; color: #555; }
  }
  .part-block.prep-page { margin: 0; break-before: page; page-break-before: always; }
  .part-block.prep-page:first-of-type { break-before: auto; page-break-before: auto; }
  .part-block.prep-set { page: prepset; break-before: page; page-break-before: always; }
  .fill table.out thead th { font-size: 12pt; padding-top: 1.2mm; padding-bottom: 1.2mm; }
  .fill table.out td.name { font-size: min(7mm, calc(var(--rh) * 0.48)); }
  .fill table.out td.name .sub { font-size: min(4.6mm, calc(var(--rh) * 0.3)); }
  .fill table.out td.n { font-size: min(7mm, calc(var(--rh) * 0.5)); }
  .fill table.out td.big { font-size: min(7.5mm, calc(var(--rh) * 0.58)); }
  .fill table.out .amt { font-size: min(7mm, calc(var(--rh) * 0.52)); }
  .fill table.out .pk { font-size: min(4.6mm, calc(var(--rh) * 0.32)); }
  .fill table.out td.tot .amt { font-size: min(7.5mm, calc(var(--rh) * 0.54)); }
  .fill table.out td.src { font-size: min(5mm, calc(var(--rh) * 0.4)); }
  .fill h3.part-h { font-size: 17pt; }
  .fill table.out td.name, .fill table.out td.name .sub { white-space: nowrap; }
  .prep-page:not(.prep-set) table.out td.name { font-size: min(5.4mm, calc(var(--rh) * 0.48)); }
  .prep-page:not(.prep-set) table.out td.name .sub { font-size: min(3.6mm, calc(var(--rh) * 0.3)); }
  .prep-page:not(.prep-set) table.out td.n { font-size: min(5.4mm, calc(var(--rh) * 0.5)); }
  .prep-page:not(.prep-set) table.out td.big { font-size: min(6mm, calc(var(--rh) * 0.58)); }
  .prep-page:not(.prep-set) table.out .amt { font-size: min(5.2mm, calc(var(--rh) * 0.52)); }
  .prep-page:not(.prep-set) table.out .pk { font-size: min(3.6mm, calc(var(--rh) * 0.32)); }
  .prep-page:not(.prep-set) table.out td.tot .amt { font-size: min(5.6mm, calc(var(--rh) * 0.54)); }
}