/* ============================================================
   单据打印样式（v52 新增）
   应用是深色主题，单据必须白纸黑字：这里的颜色全部为绝对色值，
   不跟随 --text / --panel 等主题变量，避免打印时继承深色。
   ============================================================ */

/* 静默打印的 iframe 里只加载本文件，必须自带盒模型约定（与 app.css 一致），
   否则 sheet 用 content-box 会把 76mm 标签撑到 82mm、超出纸宽 */
* { box-sizing: border-box; }

#printRoot {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: none;
  background: rgba(3, 7, 14, .82);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
#printRoot.on { display: block; }

#printBar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  gap: 10px;
  justify-content: center;
  padding: 12px;
  background: rgba(6, 10, 18, .92);
  border-bottom: 1px solid rgba(125, 165, 220, .16);
  backdrop-filter: blur(8px);
}

/* A4 纸：210 × 297mm */
.sheet {
  width: 210mm;
  min-height: 297mm;
  margin: 20px auto 48px;
  padding: 14mm 13mm;
  background: #fff;
  color: #1b2230;
  box-shadow: 0 24px 70px -20px rgba(0, 0, 0, .75);
  font: 11.5pt/1.55 "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Segoe UI", sans-serif;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* ---------- 抬头 ---------- */
.doc-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid #1b2230;
}
.doc-co-name { font-size: 15pt; font-weight: 700; letter-spacing: .5px; }
.doc-co-sub { font-size: 8.5pt; color: #5b666f; margin-top: 2px; }
.doc-meta { text-align: right; font-size: 9pt; color: #3d4854; line-height: 1.7; }
.doc-meta b { color: #1b2230; }

.doc-title {
  margin: 12px 0 10px;
  text-align: center;
  font-size: 17pt;
  font-weight: 700;
  letter-spacing: 6px;
}

/* ---------- 往来单位信息 ---------- */
.doc-meta-grid {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 10px;
  font-size: 9.5pt;
}
.doc-meta-grid th,
.doc-meta-grid td {
  border: 1px solid #cfd6de;
  padding: 5px 8px;
  text-align: left;
  vertical-align: top;
}
.doc-meta-grid th {
  width: 15%;
  background: #f4f6f9;
  color: #46525e;
  font-weight: 600;
  white-space: nowrap;
}

/* ---------- 明细表 ---------- */
.doc-items {
  width: 100%;
  border-collapse: collapse;
  font-size: 9.5pt;
}
.doc-items th,
.doc-items td {
  border: 1px solid #cfd6de;
  padding: 5px 7px;
  vertical-align: top;
}
.doc-items thead th {
  background: #f4f6f9;
  color: #2b3542;
  font-weight: 600;
  white-space: nowrap;
}
.doc-items tbody tr:nth-child(even) td { background: #fbfcfe; }
.doc-items .c { text-align: center; }
.doc-items .r { text-align: right; white-space: nowrap; }
.doc-items .mono { font-family: "SFMono-Regular", Consolas, "Courier New", monospace; font-size: 8.5pt; }
.doc-tag {
  display: inline-block;
  margin-left: 4px;
  padding: 0 4px;
  border: 1px solid #b9c2cc;
  border-radius: 3px;
  font-size: 7.5pt;
  color: #4b5663;
  vertical-align: 1px;
}
.doc-sub { font-size: 8pt; color: #6b7684; margin-top: 1px; }

/* ---------- 合计 ---------- */
.doc-total {
  display: flex;
  justify-content: flex-end;
  gap: 26px;
  margin-top: 8px;
  font-size: 10pt;
}
.doc-total b.big { font-size: 12.5pt; }

.doc-upper {
  margin-top: 6px;
  padding: 6px 9px;
  border: 1px dashed #b9c2cc;
  font-size: 10pt;
  background: #fafbfd;
}

.doc-remark {
  margin-top: 8px;
  font-size: 9.5pt;
  color: #3d4854;
  white-space: pre-wrap;
}

/* ---------- 签字栏 ---------- */
.doc-sign {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  margin-top: 26px;
  font-size: 9.5pt;
  color: #2b3542;
}
.doc-sign > div { flex: 1; }
.doc-sign .line {
  display: inline-block;
  width: 62%;
  border-bottom: 1px solid #9aa5b1;
  margin-left: 4px;
  height: 15px;
}

.doc-foot {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 18px;
  padding-top: 6px;
  border-top: 1px solid #dfe4ea;
  font-size: 7.5pt;
  color: #7b8694;
}

/* ============================================================
   订单标签：76mm × 130mm 热敏标签纸（XP-D10pro 等）
   版式对应客户 Excel 模板：7 个标签 + 订单内容明细块。
   热敏机只有黑白两点，因此不用底色、只用实线，字号按纸宽收敛。
   ============================================================ */
.sheet-label {
  width: 76mm;
  min-height: 130mm;
  margin: 20px auto 48px;
  padding: 3mm 3.5mm;
  background: #fff;
  color: #000;
  box-shadow: 0 24px 70px -20px rgba(0, 0, 0, .75);
  font: 8.2pt/1.5 "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Segoe UI", sans-serif;
  transform: none;
}

.lb-head { display: block; }
/* v69：标签拆页时的「第 X 张 / 共 N 张」标注（右上角，只有一张时不渲染） */
.lb-part {
  text-align: right;
  font-weight: 700;
  line-height: 4.2mm;
  margin-bottom: .4mm;
}
.lb-row {
  display: flex;
  align-items: flex-start;
  gap: 1.2mm;
  line-height: 4.6mm;
  border-bottom: .2mm dotted #9aa3ad;
}
.lb-row:last-child { border-bottom: 0; }
.lb-k { flex: 0 0 15mm; color: #000; }
.lb-v { flex: 1 1 auto; min-width: 0; word-break: break-all; }

.lb-sec {
  margin-top: 1.4mm;
  padding-top: 1.2mm;
  border-top: .4mm solid #000;
  font-weight: 700;
  line-height: 4.6mm;
}

.lb-tbl {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin-top: .6mm;
}
.lb-tbl th,
.lb-tbl td {
  border: .2mm solid #000;
  padding: .5mm .6mm;
  font-size: 6.9pt;
  line-height: 1.35;
  height: 4.4mm;
  vertical-align: top;
  word-break: break-all;
  overflow-wrap: anywhere;
}
.lb-tbl th { font-weight: 700; }
.lb-tbl .r { text-align: right; }
.lb-tbl .c { text-align: center; }

/* ---------- 随箱发货单（一箱一码，扫码发货用） ---------- */
.lb-wo-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: .5mm solid #000;
  padding-bottom: 1mm;
  margin-bottom: 1.4mm;
}
.lb-wo-title { font-size: 11.5pt; font-weight: 700; letter-spacing: .5mm; }
.lb-wo-box { font-size: 8.5pt; font-weight: 700; }
.lb-wo-main {
  display: flex;
  gap: 2.6mm;
  align-items: center;
  padding: 1mm 0 1.4mm;
  border-bottom: .3mm solid #000;
}
.lb-wo-qr { flex: 0 0 26mm; width: 26mm; height: 26mm; }
.lb-wo-qr svg { width: 100%; height: 100%; display: block; }
.lb-wo-noqr { font-size: 7pt; color: #000; border: .2mm dashed #000; padding: 2mm 1mm; text-align: center; }
.lb-wo-id { flex: 1 1 auto; min-width: 0; }
.lb-wo-k { font-size: 6.6pt; color: #444; line-height: 1.3; }
.lb-wo-no {
  font-size: 12.5pt;
  font-weight: 700;
  font-family: ui-monospace, "Courier New", monospace;
  line-height: 1.25;
  word-break: break-all;
  margin-bottom: 1.2mm;
}
.lb-wo-so { font-size: 8.5pt; font-weight: 700; word-break: break-all; }
.lb-wo .lb-k.lb-wo-k2 { flex: 0 0 17mm; font-weight: 700; }
.lb-wo-foot {
  margin-top: 1.6mm;
  padding-top: 1.2mm;
  border-top: .3mm dashed #000;
  font-size: 7pt;
  line-height: 1.55;
}

/* ---------- v97 整单一张标签（一单一码） ---------- */
.bl { display: flex; flex-direction: column; height: 100%; }
.bl-top { display: flex; justify-content: space-between; align-items: baseline; line-height: 1.4; }
.bl-co { font-size: 7.4pt; letter-spacing: .3mm; }
.bl-part { font-size: 8pt; font-weight: 700; }
.bl-cust {
  display: flex; align-items: baseline; gap: 1.6mm;
  border-bottom: .5mm solid #000; padding: .6mm 0 1.4mm;
}
.bl-cust .k { font-size: 6.6pt; flex: 0 0 auto; }
.bl-cust .v { font-size: 11.5pt; font-weight: 700; line-height: 1.2; flex: 1 1 auto; min-width: 0; word-break: break-all; }
.bl-qrrow {
  display: flex; gap: 2.8mm; align-items: center;
  padding: 2.2mm 0 2mm; border-bottom: .5mm solid #000;
}
.bl-qr { flex: 0 0 29mm; width: 29mm; height: 29mm; }
.bl-qr svg { width: 100%; height: 100%; display: block; }
.bl-qi { flex: 1 1 auto; min-width: 0; }
.bl-lbl { font-size: 6.4pt; color: #333; line-height: 1.2; margin-top: .9mm; }
.bl-lbl:first-child { margin-top: 0; }
.bl-no {
  font: 700 11pt/1.15 ui-monospace, "Courier New", monospace;
  word-break: break-all;
}
.bl-mix { font-size: 8.4pt; font-weight: 700; line-height: 1.25; word-break: break-all; }
/* v173 订单情况：今日发/加急 醒目大字 */
.bl-situ { font-size: 9.5pt; font-weight: 800; line-height: 1.25; letter-spacing: .3mm; }
.bl-meta { padding-top: 1.4mm; }
.bl-vwrap { line-height: 1.3; padding: .4mm 0; }
.bl-goods { flex: 1 1 auto; min-height: 0; margin-top: 1.6mm; border-top: .4mm solid #000; padding-top: 1.2mm; }
.bl-sec { font-size: 7.8pt; font-weight: 700; line-height: 1.4; }
.bl-tbl { width: 100%; border-collapse: collapse; table-layout: fixed; margin-top: .8mm; }
.bl-tbl th,
.bl-tbl td {
  border: .2mm solid #000; padding: .5mm .6mm;
  font-size: 7.1pt; line-height: 1.3; vertical-align: top;
  word-break: break-all; overflow-wrap: anywhere;
}
.bl-tbl th { font-weight: 700; }
.bl-tbl .r { text-align: right; }
.bl-tbl .mono { font-family: ui-monospace, "Courier New", monospace; font-size: 6.6pt; }
.bl-sub { font-size: 6.2pt; }
.bl .lb-wo-foot { margin-top: auto; }

/* ---------- 手机上缩小纸面，可横向滑动查看 ---------- */
@media screen and (max-width: 900px) {
  .sheet {
    width: 210mm;
    margin: 12px 0 40px;
    transform: scale(.62);
    transform-origin: top left;
    margin-left: 4vw;
  }
  .sheet-label {
    width: 76mm;
    min-height: 130mm;
    margin: 12px auto 32px;
    transform: none;
    margin-left: auto;
  }
}

/* ---------- 真正打印时 ---------- */
@media print {
  @page { size: A4; margin: 12mm; }

  /* 只留单据层，应用界面（侧边栏、顶栏、弹窗）全部隐藏 */
  body.printing > *:not(#printRoot) { display: none !important; }
  body.printing #printRoot {
    position: static !important;
    display: block !important;
    background: #fff !important;
    overflow: visible !important;
  }
  body.printing #printBar { display: none !important; }
  body.printing .sheet {
    width: auto;
    min-height: 0;
    margin: 0;
    padding: 0;
    box-shadow: none;
    transform: none;
    font-size: 10.5pt;
  }
  /* 标签纸：纸宽 = 76mm，页面由 openPrint 注入的 @page 控制。
     v173：左右不对称 padding——热敏机可打区域右侧偏窄（内容曾整体偏右、数量列被裁），
     内容左移 + 右侧多留安全余量 */
  body.printing .sheet.sheet-label {
    width: 76mm;
    min-height: 0;
    padding: 2.6mm 5.4mm 2.6mm 2.2mm;
    font-size: 8.2pt;
  }
  body.printing .sheet.sheet-label .lb-tbl th,
  body.printing .sheet.sheet-label .lb-tbl td { font-size: 6.9pt; }
  /* 批量打印：一张标签一页，除最后一张外强制分页 → 打印机连续出纸 */
  body.printing .sheet.sheet-label.lb-page {
    page-break-after: always;
    break-after: page;
    page-break-inside: avoid;
    break-inside: avoid;
  }
  body.printing .lb-tbl tr,
  body.printing .lb-row { page-break-inside: avoid; }
  body.printing .doc-items,
  body.printing .doc-meta-grid { page-break-inside: auto; }
  body.printing .doc-items tr { page-break-inside: avoid; }
  body.printing .doc-sign,
  body.printing .doc-total { page-break-inside: avoid; }
}
