/* พิมพ์ A4 — เนื้อหาใบให้อยู่ในครึ่งหน้าบน */
@page {
  size: A4;
  margin: 10mm 12mm;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: #e8e8e8;
  font-family: "Sarabun", "TH Sarabun New", "Tahoma", sans-serif;
  color: #000;
}

.toolbar {
  max-width: 210mm;
  margin: 12px auto;
  display: flex;
  gap: 8px;
}

.toolbar a,
.toolbar button {
  font: inherit;
  padding: 8px 14px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  color: #fff;
  background: #1a5f2a;
}

.toolbar .btn-gray { background: #555; }

/* ความสูงเต็ม A4 — ใบอยู่ครึ่งบน มีเส้นฉีกกึ่งกลาง */
.page {
  width: 210mm;
  height: 297mm;
  margin: 0 auto 24px;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,.15);
  position: relative;
  overflow: hidden;
}

.sheet {
  width: 100%;
  height: 148.5mm;
  max-height: 148.5mm;
  padding: 8mm 12mm 6mm;
  overflow: hidden;
}

/* เส้นประบอกจุดฉีกตรงกึ่งกลาง A4 */
.cut-line {
  position: absolute;
  left: 8mm;
  right: 8mm;
  top: 148.5mm;
  transform: translateY(-50%);
  border-top: 2px dashed #666;
  text-align: center;
  line-height: 0;
}

.cut-label {
  display: inline-block;
  background: #fff;
  padding: 0 10px;
  font-size: 9pt;
  color: #666;
  line-height: 1.2;
  white-space: nowrap;
}

.header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: start;
}

.brand {
  display: flex;
  gap: 8px;
  align-items: center;
}

.logo {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  object-fit: contain;
  object-position: center;
  display: block;
  align-self: center;
}

.company-name {
  font-size: 13pt;
  font-weight: 700;
  line-height: 1.2;
  margin: 0;
}

.company-addr {
  font-size: 9.5pt;
  line-height: 1.25;
  margin: 1px 0 0;
}

.brand > div {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.meta {
  text-align: left;
  justify-self: end;
  font-size: 10pt;
  line-height: 1.35;
  white-space: nowrap;
}

.title {
  text-align: center;
  font-size: 15pt;
  font-weight: 700;
  margin: 8px 0 4px;
  letter-spacing: 0.5px;
}

.doc-date {
  text-align: right;
  font-size: 11pt;
  margin: 0 0 6px;
}

.dot {
  display: inline-block;
  border-bottom: 1px dotted #333;
  min-width: 120px;
  padding: 0 4px 1px;
  text-align: center;
}

.dot.wide { min-width: 160px; }
.dot.full {
  display: block;
  width: 100%;
  min-height: 1.15em;
  margin-top: 2px;
  text-align: left;
}

.section-label {
  font-size: 11pt;
  font-weight: 700;
  margin: 0 0 4px;
}

.names {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px 24px;
  margin-bottom: 8px;
  font-size: 11pt;
}

.name-line {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.name-line .num { flex-shrink: 0; }
.name-line .dot {
  flex: 1;
  min-width: 0;
  text-align: left;
}

.purpose-block {
  font-size: 11pt;
  margin-bottom: 6px;
}

.purpose-block .lead {
  font-weight: 700;
  display: inline;
}

.time-line {
  font-size: 11pt;
  margin: 6px 0 10px;
  display: flex;
  flex-wrap: nowrap;
  gap: 6px 8px;
  align-items: baseline;
  white-space: nowrap;
}

.time-line .dot,
.time-line .dot.wide {
  display: inline-block;
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
  max-width: none;
}

.approvals {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 4px;
}

/* ส่วน QR ครึ่งล่างของ A4 — แยกจากใบด้านบนที่ฉีกออก */
.qr-sheet {
  position: absolute;
  left: 0;
  right: 0;
  top: 148.5mm;
  bottom: 0;
  padding: 10mm 12mm 8mm;
  overflow: hidden;
}

.qr-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6mm;
  align-content: flex-start;
}

.qr-card {
  position: relative;
  flex: 0 0 auto;
  width: 40mm;
  border: 1px solid #222;
  border-radius: 2px;
  padding: 8mm 2mm 3mm;
  text-align: center;
  overflow: hidden;
}

.qr-no {
  position: absolute;
  top: 0;
  left: 0;
  min-width: 6mm;
  padding: 0 1.5mm;
  font-size: 9pt;
  font-weight: 700;
  line-height: 1.5;
  color: #fff;
  background: #222;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.qr-img {
  display: block;
  width: 30mm;
  height: 30mm;
  margin: 0 auto 2mm;
}

.qr-info {
  display: block;
  line-height: 1.3;
}

.qr-empid,
.qr-name,
.qr-dept {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.qr-empid {
  font-size: 11pt;
  font-weight: 700;
}

.qr-name {
  font-size: 10pt;
}

.qr-dept {
  font-size: 8.5pt;
  color: #444;
}

.box {
  border: none;
  padding: 4px 8px 6px;
  min-height: 0;
}

.box h3 {
  margin: 0 0 6px;
  text-align: center;
  font-size: 11pt;
  font-weight: 700;
}

.checks {
  display: flex;
  justify-content: center;
  gap: 22px;
  margin-bottom: 8px;
  font-size: 11pt;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.square {
  width: 12px;
  height: 12px;
  border: 1.5px solid #222;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  line-height: 1;
  flex-shrink: 0;
}

.sig-line {
  font-size: 11pt;
  margin-top: 6px;
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.sig-label {
  flex-shrink: 0;
  line-height: 1.2;
  padding-bottom: 1px;
}

.sig-line .dot {
  flex: 1;
  min-width: 0;
  text-align: center;
}

/* เว้นที่เฉพาะเหนือบรรทัดลงชื่อ สำหรับลายเซ็น — ไม่ดันห่างจากบรรทัดถัดไป */
.sig-line-sign {
  margin-top: 44px;
}

.sig-line-sign + .sig-line {
  margin-top: 14px;
}

/* ลงชื่อ .................. อยู่แถวเดียวกัน ลายเซ็นกลางเส้น */
.sig-slot {
  position: relative;
  display: block;
  min-height: 0;
  height: 1.15em;
  line-height: 1.15em;
  padding: 0;
  border-bottom: 1px dotted #333;
}

.sig-img {
  position: absolute;
  left: 50%;
  bottom: 2px;
  transform: translateX(-50%);
  height: 56px;
  max-width: 95%;
  object-fit: contain;
  pointer-events: none;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

@media print {
  body { background: #fff; }
  .toolbar { display: none !important; }
  .page {
    width: auto;
    height: 277mm; /* A4 ลบ margin @page ประมาณ */
    margin: 0;
    box-shadow: none;
    overflow: hidden;
  }
  .sheet {
    height: 138.5mm;
    max-height: 138.5mm;
    padding: 0;
  }
  .cut-line {
    top: 50%;
    left: 0;
    right: 0;
  }
  .qr-sheet {
    top: 138.5mm;
    padding: 8mm 0 0;
  }
  .logo,
  .page {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
