/* EPSON LQ-630K 针式打印机 医疗器械发货单（委托配送）样式
 * 默认纸张：普通三联二等分连续纸 241mm × 140mm（两侧含撕裂孔边，LQ-630K 80列硬件最大打印宽 203.2mm）
 * @page margin: 0 自动抑制浏览器注入的网址/页码/时间页眉页脚，物理边距由 @media print 下 .dn-sheet padding 承担
 * 纯黑无灰底，适配 24 针三联无碳复写纸清晰穿透打印
 */

@page {
  size: 241mm 140mm;
  margin: 0;
}

@page dn-241x140 {
  size: 241mm 140mm;
  margin: 0;
}

@page dn-210x140 {
  size: 210mm 140mm;
  margin: 0;
}

@page dn-a4-landscape {
  size: 297mm 210mm;
  margin: 0;
}

/* 屏幕隐藏打印专用容器 */
#print-root {
  display: none;
}

/* ==================== 发货单本体（屏幕预览与实际打印共用） ==================== */

.dn-pages {
  display: block;
}

.dn-sheet {
  box-sizing: border-box;
  width: 199mm;
  background: #fff;
  color: #000;
  font-family: "SimSun", "NSimSun", "Songti SC", "STSong", "Microsoft YaHei", serif;
  font-size: 8pt;
  line-height: 1.32;
  -webkit-font-smoothing: none;
  transform: translate(var(--dn-offset-x, 0mm), var(--dn-offset-y, 0mm));
  transform-origin: top left;
}

.dn-sheet + .dn-sheet {
  page-break-before: always;
  break-before: page;
}

.dn-sheet * {
  box-sizing: border-box;
}

.dn-header {
  margin-bottom: 1.5mm;
}

.dn-title-row {
  display: grid;
  grid-template-columns: 20mm 1fr 20mm;
  align-items: baseline;
  margin-bottom: 1.5mm;
}

.dn-title {
  margin: 0;
  text-align: center;
  font-size: 13pt;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: 0.3px;
  color: #000;
}

.dn-page-no {
  text-align: right;
  font-size: 8pt;
  white-space: nowrap;
  color: #000;
}

.dn-meta {
  display: grid;
  grid-template-columns: 35% 37% 28%;
  row-gap: 0.8mm;
  column-gap: 1.8mm;
  font-size: 8pt;
  line-height: 1.32;
}

.dn-meta-cell {
  display: flex;
  align-items: baseline;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-all;
}

.dn-meta-cell .dn-lbl {
  flex: none;
  white-space: nowrap;
}

.dn-meta-cell .dn-val {
  min-width: 0;
  flex: 1;
}

/* 12 列明细表：纯黑 1px 网格，无灰底 */
.dn-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  border: 1px solid #000;
  background: #fff;
  color: #000;
}

.dn-table col.dn-col-name { width: 13.5%; }
.dn-table col.dn-col-spec { width: 12%; }
.dn-table col.dn-col-unit { width: 3.5%; }
.dn-table col.dn-col-qty { width: 4.8%; }
.dn-table col.dn-col-price { width: 6.2%; }
.dn-table col.dn-col-amount { width: 7.2%; }
.dn-table col.dn-col-batch { width: 8.3%; }
.dn-table col.dn-col-expiry { width: 9.8%; }
.dn-table col.dn-col-reg { width: 9.5%; }
.dn-table col.dn-col-registrant { width: 10%; }
.dn-table col.dn-col-mfr { width: 10%; }
.dn-table col.dn-col-storage { width: 5.2%; }

.dn-table th,
.dn-table td {
  border: 1px solid #000;
  padding: 0.9mm 0.7mm;
  vertical-align: middle;
  background: transparent;
  color: #000;
  overflow-wrap: anywhere;
  word-break: break-all;
}

.dn-table thead th {
  font-size: 7.5pt;
  font-weight: 700;
  text-align: center;
  line-height: 1.2;
  height: 8.5mm;
  padding: 0.7mm 0.5mm;
}

.dn-table tbody td {
  font-size: 8pt;
  line-height: 1.25;
  height: 16mm;
}

.dn-table.dn-rows-4 tbody td {
  height: 12.5mm;
}

.dn-table.dn-compact tbody td {
  height: 9.2mm;
  padding: 0.6mm 0.6mm;
  font-size: 7.5pt;
}

.dn-cell-center {
  text-align: center;
}

.dn-cell-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  word-break: normal;
}

/* 合计行 */
.dn-summary-row td {
  height: 7.2mm;
  padding: 0.8mm 1mm;
  font-size: 8pt;
}

.dn-summary-label {
  text-align: center;
  white-space: nowrap;
}

.dn-rmb-wrap {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 2.5mm;
}

.dn-rmb-text {
  font-size: 8.5pt;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.dn-small-wrap {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.dn-summary-mode {
  white-space: nowrap;
}

/* 签收与声明行 */
.dn-sign-row td {
  vertical-align: top;
  padding: 1mm 1.2mm;
}

.dn-sign-left {
  vertical-align: middle;
}

.dn-sign-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1.15fr;
  gap: 1.5mm;
  align-items: center;
  min-height: 11.5mm;
  font-size: 8pt;
}

.dn-sign-right {
  font-size: 7.5pt;
  line-height: 1.28;
}

.dn-disclaimer {
  margin-bottom: 1.4mm;
}

.dn-phone-val {
  display: inline-block;
  min-width: 11mm;
}

.dn-receiver-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5mm;
  font-size: 8pt;
}

/* 备注行 */
.dn-table td.dn-note-cell {
  padding: 0;
  height: 7mm;
}

.dn-note-wrap {
  display: flex;
  align-items: stretch;
  min-height: 7mm;
}

.dn-note-label {
  flex: none;
  width: 10.5mm;
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1px solid #000;
  font-size: 8pt;
  white-space: nowrap;
}

.dn-note-val {
  flex: 1;
  min-width: 0;
  padding: 0.9mm 1.4mm;
  display: flex;
  align-items: center;
  font-size: 8pt;
}

/* 套打模式：隐藏预印文字与全部表格边框，保持坐标完全一致 */
.dn-sheet.dn-mode-preprinted .dn-lbl {
  visibility: hidden !important;
}

.dn-sheet.dn-mode-preprinted .dn-table,
.dn-sheet.dn-mode-preprinted .dn-table th,
.dn-sheet.dn-mode-preprinted .dn-table td,
.dn-sheet.dn-mode-preprinted .dn-note-label {
  border-color: transparent !important;
}

/* 纸张预设宽度与命名 @page 绑定（纯外部样式，兼容严格 CSP default-src 'self'） */
.dn-paper-241x140 .dn-sheet {
  page: dn-241x140;
  width: 199mm;
}

.dn-paper-210x140 .dn-sheet {
  page: dn-210x140;
  width: 194mm;
}

.dn-paper-a4-landscape .dn-sheet {
  page: dn-a4-landscape;
  width: 269mm;
}

/* ==================== 打印预览弹窗（仅屏幕可见） ==================== */

#print-dialog {
  width: min(1160px, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 20px);
  padding: 0;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  background: #f8fafc;
  color: #151e2f;
  overflow: hidden;
}

#print-dialog[open] {
  display: flex;
  flex-direction: column;
}

#print-dialog::backdrop {
  background: rgba(17, 33, 62, 0.52);
}

.dn-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  background: #fff;
  border-bottom: 1px solid #dce2ec;
  flex: none;
}

.dn-modal-title-group {
  min-width: 0;
}

.dn-modal-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: #151e2f;
}

.dn-modal-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: #52627a;
}

.dn-modal-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

.dn-print-btn {
  background: #244baa;
  color: #fff;
  border: 1px solid #1e3f91;
  border-radius: 8px;
  padding: 8px 16px;
  min-height: 36px;
  font-weight: 650;
  font-size: 14px;
  cursor: pointer;
}

.dn-print-btn:hover {
  background: #1b3985;
}

.dn-secondary-btn {
  background: #fff;
  color: #151e2f;
  border: 1px solid #c5cfdf;
  border-radius: 8px;
  padding: 6px 12px;
  min-height: 34px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.dn-secondary-btn:hover {
  background: #eaf0ff;
}

.dn-close-btn {
  border: 0;
  background: transparent;
  color: #52627a;
  font-size: 24px;
  line-height: 1;
  min-height: 32px;
  padding: 0 8px;
  cursor: pointer;
  border-radius: 6px;
}

.dn-close-btn:hover {
  background: #eef2f8;
  color: #151e2f;
}

.dn-controls {
  display: grid;
  gap: 10px;
  padding: 12px 18px;
  background: #fff;
  border-bottom: 1px solid #dce2ec;
  flex: none;
}

.dn-control-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
}

.dn-control-bar label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: #334159;
  min-width: 110px;
}

.dn-control-bar input,
.dn-control-bar select {
  min-height: 33px;
  padding: 5px 8px;
  font-size: 13px;
  border: 1px solid #c5cfdf;
  border-radius: 7px;
  background: #fff;
  color: #151e2f;
}

.dn-control-bar .dn-num-input {
  width: 82px;
}

.dn-quick-edits {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px 10px;
  padding-top: 8px;
  border-top: 1px dashed #dce2ec;
}

.dn-quick-edits label {
  display: grid;
  gap: 3px;
  font-size: 12px;
  font-weight: 600;
  color: #334159;
}

.dn-quick-edits input {
  min-height: 32px;
  padding: 4px 8px;
  font-size: 13px;
  border: 1px solid #c5cfdf;
  border-radius: 7px;
  background: #fff;
  color: #151e2f;
}

.dn-quick-edits .dn-span-2 {
  grid-column: span 2;
}

.dn-tip {
  font-size: 12px;
  color: #243f7d;
  background: #eaf0ff;
  border: 1px solid #cbd9fa;
  border-radius: 7px;
  padding: 6px 10px;
}

.dn-stage {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 18px;
  background: #dde4ef;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.dn-stage-paper {
  background: #fff;
  padding: 5mm 21mm;
  box-shadow: 0 6px 24px rgba(17, 33, 62, 0.18);
  border: 1px solid #b8c4d8;
  flex: none;
}

.dn-stage-paper.dn-paper-210x140 {
  padding: 5mm 8mm;
}

.dn-stage-paper.dn-paper-a4-landscape {
  padding: 10mm 14mm;
}

.dn-stage-paper .dn-sheet + .dn-sheet {
  margin-top: 8mm;
  padding-top: 8mm;
  border-top: 1px dashed #94a3b8;
}

@media (max-width: 860px) {
  .dn-quick-edits {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .dn-modal-head {
    flex-wrap: wrap;
  }
}

/* ==================== 实际打印隔离规则 ==================== */

@media print {
  html,
  body {
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    color: #000 !important;
    width: auto !important;
    height: auto !important;
    overflow: visible !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  body > :not(#print-root),
  #shell,
  #gate,
  #dialog,
  #notice,
  #print-dialog,
  #print-dialog::backdrop {
    display: none !important;
  }

  #print-root,
  #print-root .dn-pages {
    margin: 0 !important;
    padding: 0 !important;
  }

  #print-root {
    display: block !important;
    background: #fff !important;
    width: auto !important;
  }

  #print-root .dn-sheet,
  #print-root.dn-paper-241x140 .dn-sheet {
    box-sizing: border-box;
    width: 241mm;
    padding: 5mm 21mm;
    box-shadow: none !important;
    border: none !important;
    page-break-inside: avoid;
    break-inside: avoid;
  }

  #print-root.dn-paper-210x140 .dn-sheet {
    width: 210mm;
    padding: 5mm 8mm;
  }

  #print-root.dn-paper-a4-landscape .dn-sheet {
    width: 297mm;
    padding: 10mm 14mm;
  }
}
