/* QMES print styles.
   Print-only extension point.
   Current production rules remain in common.css to preserve the exact original cascade. */

/* Work order preview: align only the Korean title with the logo and document metadata. */
.qmes-wo-output-preview .qmes-wo-cert .qmes-iqc-centered-title {
  transform: none !important;
}

.qmes-wo-cert .qmes-iqc-centered-title .text-xl {
  position: relative !important;
  top: -8px !important;
}

/* LOT trace: current React tabs already render materials, production, inspection,
   and shipment independently. Suppress only the legacy wrappers injected by the
   older shipment/detail synchronization script. */
[data-qmes-lot-production-detail],
[data-qmes-lot-oqc-shipment],
[data-qmes-lot-quality-hold] {
  display: none !important;
}

/* Work order: keep the printed header aligned with the on-screen preview. */
@media print {
  body.print-doc #qmes-print-root > .doc-paper.qmes-iqc-doc.qmes-wo-cert,
  body.print-doc #qmes-print-root > .qmes-screen-print-copy.doc-paper.qmes-iqc-doc.qmes-wo-cert,
  body.print-doc #qmes-print-root > .qmes-screen-print-copy.qmes-wo-cert {
    top: 0 !important;
    margin: 0 auto !important;
    padding: 5mm 8mm 4mm !important;
    box-sizing: border-box !important;
  }

  body.print-doc #qmes-print-root .qmes-wo-cert .qmes-wo-header,
  body.print-doc #qmes-print-root .qmes-screen-print-copy .qmes-wo-header,
  body.print-doc #qmes-print-root .qmes-wo-cert .qmes-iqc-centered-header,
  body.print-doc #qmes-print-root .qmes-screen-print-copy .qmes-iqc-centered-header {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    padding-top: 0 !important;
    padding-bottom: 16px !important;
    align-items: center !important;
  }

  body.print-doc #qmes-print-root .qmes-wo-cert .qmes-wo-header-logo,
  body.print-doc #qmes-print-root .qmes-screen-print-copy .qmes-wo-header-logo,
  body.print-doc #qmes-print-root .qmes-wo-cert .qmes-iqc-header-logo,
  body.print-doc #qmes-print-root .qmes-screen-print-copy .qmes-iqc-header-logo,
  body.print-doc #qmes-print-root .qmes-wo-cert .qmes-iqc-centered-title,
  body.print-doc #qmes-print-root .qmes-screen-print-copy .qmes-iqc-centered-title,
  body.print-doc #qmes-print-root .qmes-wo-cert .qmes-iqc-header-meta,
  body.print-doc #qmes-print-root .qmes-screen-print-copy .qmes-iqc-header-meta {
    position: static !important;
    margin: 0 !important;
    transform: none !important;
  }

  body.print-doc #qmes-print-root .qmes-wo-cert .qmes-iqc-centered-title .text-xl,
  body.print-doc #qmes-print-root .qmes-screen-print-copy .qmes-wo-cert .qmes-iqc-centered-title .text-xl {
    top: -11px !important;
  }
}

/* Work order logo only: use the exact IQC print size and position. */
@media print {
  body.print-doc #qmes-print-root > .qmes-wo-cert .qmes-wo-header-logo-wrap,
  body.print-doc #qmes-print-root > .qmes-screen-print-copy.qmes-wo-cert .qmes-wo-header-logo-wrap {
    position: static !important;
    top: auto !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    margin: 0 !important;
    transform: none !important;
    align-self: center !important;
  }

  body.print-doc #qmes-print-root > .qmes-wo-cert .qmes-wo-header-logo,
  body.print-doc #qmes-print-root > .qmes-screen-print-copy.qmes-wo-cert .qmes-wo-header-logo {
    width: 205px !important;
    max-width: 100% !important;
    max-height: 58px !important;
    height: auto !important;
    margin: 0 !important;
    object-fit: contain !important;
    object-position: left center !important;
    transform: translateY(-8px) !important;
    transform-origin: left center !important;
  }
}

/* CoA: the injected layout removes the final row border with border-bottom:0.
   Restore the final two information cells at the source-layout level so both
   the output preview and the print clone inherit the same complete frame. */
.qmes-coa-unified-doc > div:nth-child(2) > div:nth-last-child(-n+2) {
  border-bottom: 1px solid #94a3b8 !important;
}

.qmes-coa-unified-doc > div:nth-child(2) > div:nth-last-child(-n+2) > span:first-child,
.qmes-coa-unified-doc > div:nth-child(2) > div:nth-last-child(-n+2) > span:last-child {
  border-bottom: 1px solid #94a3b8 !important;
  box-sizing: border-box !important;
}

@media print {
  body.print-doc #qmes-print-root .qmes-coa-unified-doc > div:nth-child(2) > div:nth-last-child(-n+2),
  body.print-doc #qmes-print-root .qmes-coa-unified-doc > div:nth-child(2) > div:nth-last-child(-n+2) > span:first-child,
  body.print-doc #qmes-print-root .qmes-coa-unified-doc > div:nth-child(2) > div:nth-last-child(-n+2) > span:last-child {
    border-bottom: 1px solid #000 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}

/* Global one-page print guard.
   Chrome can round an exact 297mm layout a fraction of a millimetre beyond A4,
   producing a blank second sheet. Reserve a tiny safety gap and clip only the
   page-box overflow; document layout itself is otherwise unchanged. */
@media print {
  @page {
    size: A4 portrait !important;
    margin: 0 !important;
  }

  html,
  body.print-doc,
  body.qmes-screen-exact-print {
    width: 210mm !important;
    height: 296mm !important;
    min-height: 0 !important;
    max-height: 296mm !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
  }

  body.print-doc #qmes-print-root,
  body.qmes-screen-exact-print #qmes-print-root {
    width: 210mm !important;
    height: 296mm !important;
    min-height: 0 !important;
    max-height: 296mm !important;
    margin: 0 auto !important;
    padding: 0 !important;
    overflow: hidden !important;
    break-after: avoid-page !important;
    page-break-after: avoid !important;
  }

  body.print-doc #qmes-print-root > *,
  body.qmes-screen-exact-print #qmes-print-root > * {
    break-after: avoid-page !important;
    page-break-after: avoid !important;
  }
}
