/* =========================================================
   ใบรับรอง — หน้า HTML ขนาด A4 จริง (พิมพ์เป็น PDF จาก Chromium ได้)
   กติกาฟอนต์ไทย: ไม่ใช้ letter-spacing / text-transform กับข้อความไทย,
   line-height ≥ 1.35 เผื่อสระบน-วรรณยุกต์ (ผู้ ปู่ ย่า), โหลดน้ำหนักฟอนต์ที่ใช้จริงทุกตัว (ไม่ให้ browser สร้างตัวหนาปลอม)
   ========================================================= */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: #D9DED9; font-family: var(--f-body); color: var(--c-ink);
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
  font-synthesis: none;
}
img { display: block; }

/* ---------- แถบเครื่องมือ (เฉพาะบนจอ ไม่พิมพ์ออก) ---------- */
.cert-toolbar {
  position: sticky; top: 0; z-index: 10; background: var(--c-paper); border-bottom: 1px solid var(--c-line);
  padding: 8px 12px; display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; font-size: 14px; line-height: 1.4;
}
.cert-toolbar .tb-title { font-family: var(--f-head); font-weight: 600; color: var(--c-primary); margin-right: auto; }
.cert-toolbar .tb-group { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.cert-toolbar .tb-label { color: var(--c-muted); margin-right: 2px; }
.cert-toolbar button, .cert-toolbar select, .cert-toolbar a.tb-link {
  font: inherit; min-height: 36px; padding: 4px 10px; border-radius: 8px; border: 1px solid var(--c-line-strong);
  background: #fff; color: var(--c-ink); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center;
}
.cert-toolbar button[aria-pressed="true"] { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
.cert-toolbar .tb-print { background: var(--c-gold); border-color: var(--c-gold); color: #241B00; font-weight: 600; }
.cert-toolbar input[type=range] { width: 110px; accent-color: var(--c-primary); }
.cert-toolbar .tb-note { width: 100%; color: var(--c-muted); font-size: 12px; }

/* ---------- เวทีแสดงกระดาษบนจอ ---------- */
.stage { padding: 16px 8px 40px; }
.sheet-holder { margin: 0 auto; position: relative; }
.sheet {
  position: relative; background: #fff; overflow: hidden; transform-origin: 0 0;
  box-shadow: 0 6px 30px rgba(0,0,0,.18);
}
.sheet.portrait { width: 210mm; height: 297mm; }
.sheet.landscape { width: 297mm; height: 210mm; }

@media print {
  body { background: #fff; }
  .no-print, .cert-toolbar { display: none !important; }
  .stage { padding: 0; }
  .sheet-holder { width: auto !important; height: auto !important; }
  .sheet { transform: none !important; box-shadow: none; break-after: avoid; page-break-after: avoid; }
}

/* ---------- ชิ้นส่วนที่ใช้ร่วมกัน ---------- */
.c-head { font-family: var(--f-head); line-height: 1.35; }
.bg-layer { position: absolute; inset: 0; background-size: cover; background-position: center; z-index: 0; }
.bg-veil { position: absolute; inset: 0; background: #fff; z-index: 0; }
.sheet > .frame { position: absolute; inset: 5mm; border: 0.6mm solid var(--c-primary); border-radius: 3mm; z-index: 1; pointer-events: none; }
.sheet > .frame::after { content: ""; position: absolute; inset: 1.2mm; border: 0.25mm solid var(--c-gold); border-radius: 2mm; }
.content { position: absolute; z-index: 2; display: flex; flex-direction: column; }
.solid { background: #fff; }   /* กฎ 36: ช่องข้อความหลัก/QR/ลายเซ็นมีพื้นขาวทึบ */

.farm-logo-svg { width: 100%; height: 100%; display: block; }
.logo-img { width: 100%; height: 100%; object-fit: contain; }

.tag-badge {
  display: inline-flex; align-items: center; gap: 1.5mm; border: 0.3mm solid var(--c-line-strong); border-radius: 10mm;
  padding: 0.3mm 2.4mm 0.3mm 1.2mm; font-size: 9pt; line-height: 1.45; background: #fff; white-space: nowrap; vertical-align: middle;
}
.tag-badge i { width: 3.4mm; height: 3.4mm; border-radius: 50%; border: 0.25mm solid rgba(0,0,0,.25); display: inline-block; }
.tier { font-family: var(--f-head); font-weight: 600; color: var(--c-gold-dark); }

.legal { font-size: 7.6pt; line-height: 1.45; color: var(--c-ink-2); }
.legal b { color: var(--c-ink); font-weight: 600; }

.sign-zone { display: flex; align-items: flex-end; gap: 4mm; }
.sign-zone .sign { flex: 1; text-align: center; font-size: 8.5pt; line-height: 1.45; color: var(--c-ink-2); }
.sign-zone .sign .line { border-bottom: 0.3mm dotted var(--c-ink-2); height: 11mm; margin-bottom: 1mm; }
.sign-zone .sign .who { font-size: 9.5pt; color: var(--c-ink); font-weight: 600; }
.sign-zone .stamp {
  width: 21mm; height: 21mm; border: 0.3mm dashed var(--c-line-strong); border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center; text-align: center; font-size: 7pt; color: var(--c-muted); line-height: 1.35;
}

/* ลายน้ำ "ตัวอย่าง" (ใบด่วนก่อนจ่ายเงิน) */
.watermark { position: absolute; inset: -40mm; z-index: 8; pointer-events: none; transform: rotate(-28deg); display: flex; flex-direction: column; justify-content: space-around; }
.watermark div { white-space: nowrap; font-family: var(--f-head); font-weight: 700; font-size: 34pt; line-height: 1.6; color: var(--c-watermark); }
.wm-ribbon {
  position: absolute; top: 9mm; right: -16mm; z-index: 9; transform: rotate(35deg); background: var(--c-err); color: #fff;
  font-family: var(--f-head); font-weight: 600; font-size: 11pt; line-height: 1.5; padding: 1mm 20mm;
}
.is-preview .photo img { filter: blur(1.4px) saturate(.9); } /* ตัวอย่างใช้ภาพความละเอียดต่ำ */

/* =========================================================
   ใบด่วน — QUICK_PORTRAIT (แนวตั้งแบบเดียว · โลโก้กลางบนเท่านั้น · ไม่มีพื้นหลัง · ไม่มี QR)
   ========================================================= */
.q .content { inset: 11mm 12mm 0 12mm; align-items: center; }
.q .q-logo { width: 24mm; height: 24mm; margin-bottom: 1.5mm; }
.q .q-owner { font-size: 20pt; font-weight: 600; color: var(--c-primary); text-align: center; line-height: 1.35; }
.q .q-phone { font-size: 10pt; color: var(--c-ink-2); line-height: 1.4; }
.q .q-title { display: flex; align-items: center; gap: 4mm; margin: 2mm 0 3mm; color: var(--c-gold-dark); font-size: 15pt; font-weight: 500; }
.q .q-title::before, .q .q-title::after { content: ""; width: 22mm; height: 0.5mm; background: linear-gradient(90deg, transparent, var(--c-gold)); }
.q .q-title::after { transform: scaleX(-1); }
.q .photo { flex: 1 1 auto; min-height: 60mm; width: 118mm; border-radius: 3mm; overflow: hidden; border: 0.8mm solid var(--c-gold); background: var(--c-primary-light); }
.q .photo img { width: 100%; height: 100%; object-fit: cover; }
.q .photo .no-photo { height: 100%; display: flex; align-items: center; justify-content: center; color: var(--c-muted); font-size: 12pt; }
.q .q-name { margin-top: 3mm; font-size: 22pt; font-weight: 600; text-align: center; line-height: 1.3; }
.q .q-table { width: 100%; margin-top: 2.5mm; display: grid; grid-template-columns: 1fr 1fr; border: 0.3mm solid var(--c-line-strong); border-radius: 2mm; overflow: hidden; }
.q .q-table div { padding: 1.6mm 4mm; font-size: 11.5pt; line-height: 1.45; border-bottom: 0.25mm solid var(--c-line); display: flex; gap: 3mm; }
.q .q-table div:nth-child(odd) { border-right: 0.25mm solid var(--c-line); }
.q .q-table div:nth-last-child(-n+2) { border-bottom: 0; }
.q .q-table span { color: var(--c-muted); min-width: 17mm; }
.q .q-table b { font-weight: 600; }
.q .q-parents { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 3mm; margin-top: 3mm; }
.q .q-parent { border-radius: 2mm; padding: 2mm 4mm; line-height: 1.45; }
.q .q-parent small { display: block; font-size: 9.5pt; font-family: var(--f-head); }
.q .q-parent b { font-size: 12.5pt; font-weight: 600; }
.q .q-parent.sire { background: var(--c-sire-tint); border: 0.3mm solid var(--c-sire-edge); }
.q .q-parent.sire small { color: var(--c-sire-ink); }
.q .q-parent.dam { background: var(--c-dam-tint); border: 0.3mm solid var(--c-dam-edge); }
.q .q-parent.dam small { color: var(--c-dam-ink); }
.q .q-foot { width: 100%; display: grid; grid-template-columns: 1fr 72mm; gap: 6mm; align-items: end; margin-top: 3mm; }
.q .q-meta { font-size: 10pt; line-height: 1.55; }
.q .q-meta b { font-weight: 600; }
.q .q-band {
  width: calc(100% + 24mm); margin-top: 4mm; background: var(--c-quick-band); color: var(--c-quick-band-ink);
  padding: 2.4mm 12mm 3mm; text-align: center;
}
.q .q-band .big { font-family: var(--f-head); font-weight: 600; font-size: 12.5pt; line-height: 1.4; }
.q .q-band .legal { color: #EADFC9; }
.q .q-band .legal b { color: #fff; }

/* =========================================================
   ใบฟาร์ม — ส่วนหัว (โลโก้ 3 ตำแหน่ง)
   ========================================================= */
.f-head { display: grid; align-items: center; column-gap: 5mm; }
.farm-block { display: flex; align-items: center; gap: 3mm; min-width: 0; }
.farm-block .logo { width: 21mm; height: 21mm; flex: none; }
.farm-block .fname { font-family: var(--f-head); font-weight: 600; font-size: 15pt; line-height: 1.3; color: var(--c-primary); }
.farm-block .fsub { font-size: 8.5pt; color: var(--c-ink-2); line-height: 1.4; }
.farm-block.pos-center { flex-direction: column; text-align: center; gap: 1mm; }
.farm-block.pos-center .logo { width: 18mm; height: 18mm; }
.farm-block.pos-right { flex-direction: row-reverse; text-align: right; }
.title-block .kicker { font-family: var(--f-head); font-size: 10pt; color: var(--c-gold-dark); line-height: 1.35; }
.title-block .cname { font-family: var(--f-head); font-weight: 700; font-size: 25pt; line-height: 1.25; color: var(--c-ink); }
.title-block .ccode { margin-top: 1mm; }
.qr-block { text-align: center; padding: 1.5mm; border-radius: 1.5mm; }
.qr-block .qr { display: block; }
.qr-block .qr-cap { font-size: 6.8pt; line-height: 1.35; color: var(--c-ink-2); margin-top: 0.5mm; }
/* E53: "ตรวจที่ … เท่านั้น" ขนาดเท่าบรรทัดลิงก์ตรวจสอบ (9pt) */
.qr-only { font-size: 9pt; line-height: 1.35; font-weight: 600; color: var(--c-ink); }
.qr-block .qr-only { margin-top: 0.5mm; }

/* node ผังสายเลือด */
.nd-label { font-family: var(--f-head); font-size: 8.5pt; line-height: 1.35; }
.nd-name { font-weight: 600; font-size: 11pt; line-height: 1.4; }
.nd-sub { font-size: 8.6pt; line-height: 1.4; color: var(--c-ink-2); }
.nd-text { font-size: 10.5pt; line-height: 1.4; font-weight: 500; }
.nd-off { font-size: 7.6pt; color: var(--c-muted); line-height: 1.35; }
.nd-unknown { font-size: 10pt; color: var(--c-muted); line-height: 1.4; }

/* =========================================================
   Layout A — แนวนอน: ตาราง pedigree
   ========================================================= */
.la .content { inset: 10mm 11mm 9mm 11mm; }
.la .f-head { grid-template-columns: 1fr auto 1fr 30mm; padding-bottom: 2.5mm; border-bottom: 0.5mm solid var(--c-primary); }
.la .f-head .qr-block .qr { width: 26mm; height: 26mm; margin: 0 auto; }
.la .f-head .center-col { text-align: center; }
.la .body { flex: 1; min-height: 0; display: grid; grid-template-columns: 76mm 1fr; gap: 5mm; padding-top: 3.5mm; }
.la .photo { border-radius: 2.5mm; overflow: hidden; border: 0.7mm solid var(--c-gold); background: var(--c-primary-light); }
.la .photo img { width: 100%; height: 100%; object-fit: cover; }
.la .right { display: flex; flex-direction: column; min-width: 0; }
.la .info { display: grid; grid-template-columns: repeat(4, 1fr); border: 0.3mm solid var(--c-line-strong); border-radius: 2mm; overflow: hidden; }
.la .info > div { padding: 1.2mm 3mm; border-right: 0.25mm solid var(--c-line); border-bottom: 0.25mm solid var(--c-line); line-height: 1.4; min-width: 0; }
.la .info > div:nth-child(4n) { border-right: 0; }
.la .info > div:nth-last-child(-n+4) { border-bottom: 0; }
.la .info .k { font-size: 7.8pt; color: var(--c-muted); font-family: var(--f-head); }
.la .info .v { font-size: 10.5pt; font-weight: 600; }
.la .info .wide { grid-column: span 2; }
.la .ped { flex: 1; margin-top: 3mm; display: grid; grid-template-columns: 1fr 1.15fr; grid-template-rows: auto 1fr 1fr 1fr 1fr; border: 0.35mm solid var(--c-line-strong); border-radius: 2mm; overflow: hidden; }
.la .ped .th { background: var(--c-primary); color: #fff; font-family: var(--f-head); font-weight: 500; font-size: 9.5pt; line-height: 1.4; padding: 1mm 3mm; }
.la .ped .th + .th { border-left: 0.3mm solid rgba(255,255,255,.35); }
.la .ped .cell { padding: 1.4mm 3mm; display: flex; flex-direction: column; justify-content: center; min-width: 0; border-top: 0.25mm solid rgba(0,0,0,.08); }
.la .ped .par { grid-row: span 2; border-right: 0.3mm solid var(--c-line-strong); }
.la .ped .sire { background: var(--c-sire-tint); }
.la .ped .dam { background: var(--c-dam-tint); }
.la .ped .sire .nd-label { color: var(--c-sire-ink); }
.la .ped .dam .nd-label { color: var(--c-dam-ink); }
.la .ped .par .nd-name { font-size: 12.5pt; }
.la .ped .divider { border-top: 0.45mm solid var(--c-line-strong); }
.la .foot { display: grid; grid-template-columns: 1.25fr 1fr 80mm; gap: 5mm; align-items: end; margin-top: 3mm; padding-top: 2.5mm; border-top: 0.3mm solid var(--c-line); }
.la .foot .meta { font-size: 9pt; line-height: 1.5; }
.la .foot .meta b { font-weight: 600; }
.la .foot .meta .no { font-family: var(--f-head); font-weight: 600; font-size: 10.5pt; color: var(--c-primary); }

/* =========================================================
   Layout B — แนวตั้ง: ผังต้นไม้ 7 กล่อง เส้นโค้ง
   ========================================================= */
.lb .content { inset: 11mm 11mm 9mm 11mm; }
.lb .f-head { grid-template-columns: 1fr 1fr 1fr; min-height: 22mm; }
.lb .f-head > .slot { display: flex; }
.lb .f-head > .slot.c { justify-content: center; }
.lb .f-head > .slot.r { justify-content: flex-end; }
.lb .doc-title { text-align: center; margin: 1.5mm 0 3mm; }
.lb .doc-title .t { font-family: var(--f-head); font-weight: 500; font-size: 13pt; color: var(--c-gold-dark); line-height: 1.35; display: inline-flex; align-items: center; gap: 4mm; }
.lb .doc-title .t::before, .lb .doc-title .t::after { content: ""; width: 18mm; height: 0.45mm; background: var(--c-gold); }
.lb .hero { display: grid; grid-template-columns: 70mm 1fr; gap: 6mm; height: 86mm; }
.lb .photo { border-radius: 3mm; overflow: hidden; border: 0.7mm solid var(--c-gold); background: var(--c-primary-light); }
.lb .photo img { width: 100%; height: 100%; object-fit: cover; }
.lb .hero-info { display: flex; flex-direction: column; border-radius: 2.5mm; padding: 3mm 4mm; border: 0.3mm solid var(--c-line); }
.lb .hero-info .cname { font-family: var(--f-head); font-weight: 700; font-size: 23pt; line-height: 1.25; }
.lb .hero-info dl { margin: 2.5mm 0 0; display: grid; grid-template-columns: 22mm 1fr; row-gap: 0.6mm; font-size: 10.5pt; line-height: 1.45; }
.lb .hero-info dt { color: var(--c-muted); }
.lb .hero-info dd { margin: 0; font-weight: 600; }
.lb .tree-title { font-family: var(--f-head); font-weight: 600; font-size: 11pt; color: var(--c-primary); margin: 4mm 0 1.5mm; line-height: 1.35; display: flex; justify-content: space-between; align-items: baseline; }
.lb .tree-title span { font-weight: 400; font-size: 8.5pt; color: var(--c-muted); font-family: var(--f-body); }
.lb .tree { position: relative; flex: 1; min-height: 0; display: grid; grid-template-columns: 44mm 54mm 1fr; column-gap: 11mm; grid-template-rows: repeat(4, 1fr); row-gap: 2.2mm; }
.lb .tree svg.links { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; overflow: visible; }
.lb .box { position: relative; z-index: 1; border-radius: 2.5mm; padding: 1.6mm 3mm; display: flex; flex-direction: column; justify-content: center; min-width: 0; background: #fff; border: 0.35mm solid var(--c-line-strong); box-shadow: 0 0.4mm 1.2mm rgba(0,0,0,.06); }
.lb .box.self { grid-column: 1; grid-row: 2 / span 2; align-self: center; border: 0.6mm solid var(--c-primary); padding: 3mm; }
.lb .box.self .nd-name { font-size: 12.5pt; }
.lb .box.p { grid-column: 2; align-self: center; }
.lb .box.p.sire { grid-row: 1 / span 2; }
.lb .box.p.dam { grid-row: 3 / span 2; }
.lb .box.g { grid-column: 3; }
.lb .box.sire { background: var(--c-sire-tint); border-color: var(--c-sire-edge); }
.lb .box.dam { background: var(--c-dam-tint); border-color: var(--c-dam-edge); }
.lb .box.sire .nd-label { color: var(--c-sire-ink); }
.lb .box.dam .nd-label { color: var(--c-dam-ink); }
.lb .foot { display: grid; grid-template-columns: 27mm 1fr 66mm; gap: 4mm; align-items: end; margin-top: 3.5mm; padding-top: 2.5mm; border-top: 0.3mm solid var(--c-line); }
.lb .foot .qr-block { padding: 0; }
.lb .foot .qr-block .qr { width: 25mm; height: 25mm; }
.lb .foot .meta { font-size: 9pt; line-height: 1.5; }
.lb .foot .meta b { font-weight: 600; }
.lb .foot .meta .no { font-family: var(--f-head); font-weight: 600; font-size: 10.5pt; color: var(--c-primary); }
.lb .legal-row { margin-top: 2mm; text-align: center; }

/* หัวกระดาษใบฟาร์มมีพื้นขาวทึบเมื่อเปิดพื้นหลัง (กฎ 36) */
.la .f-head, .lb .f-head { background: #fff; border-radius: 2mm; padding: 1.5mm 2.5mm; }
.la .f-head { padding-bottom: 2.5mm; }
.q .content > * { flex-shrink: 0; }
.q .content > .photo { flex: 1 1 auto; }
.la .foot, .lb .foot { background: #fff; border-radius: 2mm; padding: 2.5mm 2.5mm 1.5mm; }
.lb .legal-row { background: #fff; border-radius: 2mm; padding: 1mm 2mm; }

/* โหมดฝังใน iframe (ภาพย่อบนหน้าแรก / ตัวอย่างในฟอร์ม) */
body.embed { background: #fff; overflow: hidden; }
body.embed .cert-toolbar { display: none; }
body.embed .stage { padding: 0; }
body.embed .sheet { box-shadow: none; }

/* =========================================================
   รอบ 2: กระดาษ + แถบ JPG · แถบเครื่องมือพับได้ · กิ๊บปีก · ใบด่วนไม่มีรูป
   ========================================================= */
.paper { width: max-content; transform-origin: 0 0; }
.sheet { transform: none; }
.jpg-strip {
  display: flex; align-items: center; justify-content: center; gap: 10px; background: var(--c-primary); color: #fff;
  font-family: var(--f-head); font-weight: 500; font-size: 15pt; line-height: 1.4; padding: 4mm 6mm;
}
.jpg-strip svg { flex: none; background: #fff; border-radius: 6px; padding: 2px; }
@media print {
  .paper { transform: none !important; }
  .jpg-strip { display: none; }
}

/* แถบเครื่องมือ: หัว (ชื่อ + พิมพ์ + ปุ่มพับ) + เนื้อหาพับได้ */
.cert-toolbar { display: block; padding: 6px 12px; }
.cert-toolbar .tb-head { display: flex; align-items: center; gap: 8px; }
.cert-toolbar .tb-title { margin-right: auto; font-size: 14px; }
.cert-toolbar .tb-body { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding: 8px 0 4px; }
.cert-toolbar.collapsed .tb-body { display: none; }
.cert-toolbar .tb-toggle { white-space: nowrap; }

/* กิ๊บปีก (E23): บรรทัดหลัก + บรรทัดเล็ก "ด้านหลังกิ๊บ" */
.tdot { display: inline-block; width: 3.2mm; height: 3.2mm; border-radius: 50%; border: 0.3mm solid rgba(0,0,0,.35); vertical-align: -0.4mm; margin-right: 1mm; }
.wing-k { color: var(--c-muted); font-weight: 400; }
.wing-main { line-height: 1.45; }
.wing-main b { font-weight: 700; }
.wing-back { font-size: 0.82em; color: var(--c-ink-2); line-height: 1.4; }
.wing.in-cell .wing-main { font-size: 10.5pt; }
.wing.in-cell .wing-k { display: none; } /* ป้าย "กิ๊บปีก" อยู่ที่หัวช่องแล้ว */
.nd-sub .wing-k { font-size: 0.95em; }
.nd-sub .tdot { width: 2.6mm; height: 2.6mm; }
.unk { color: var(--c-muted); font-weight: 400; }

/* Layout A: ตารางข้อมูลแบบเส้นตาราง (gap) รองรับ 2–3 แถว */
.la .info { gap: 0.25mm; background: var(--c-line); }
.la .info > div { background: #fff; border: 0 !important; padding: 1.1mm 3mm; }
.la .info > .wide { grid-column: span 2; }
.la .info .v { font-size: 10pt; }
.la .foot .meta { font-size: 8.4pt; }
.la .ped .cell { padding: 1.1mm 3mm; }
.la .nd-sub { font-size: 8.2pt; }

/* Layout B: การ์ดข้อมูลด้านขวาของรูป — ชื่อ → กิ๊บปีก → รายการ → เลขที่ใบ (จัดให้เต็มสมดุล) */
.lb .hero-info { justify-content: flex-start; gap: 2mm; }
.lb .hero-info .cname { margin-bottom: 0; }
.lb .hero-wing { background: var(--c-gold-light); border: 0.3mm solid var(--c-gold); border-radius: 2mm; padding: 1.6mm 3mm; font-size: 11pt; }
.lb .hero-info dl { margin: 0.5mm 0 0; row-gap: 0.4mm; font-size: 10.2pt; }
.lb .hero-no { margin-top: auto; padding-top: 1.5mm; border-top: 0.25mm dashed var(--c-line-strong); font-size: 9pt; color: var(--c-ink-2); }
.lb .hero-no b { font-family: var(--f-head); color: var(--c-primary); font-weight: 600; }
.lb .box { padding: 1.3mm 3mm; }
.lb .nd-sub { font-size: 8.2pt; }

/* ใบด่วน: กิ๊บปีกใต้ชื่อไก่ · ตาราง · โลโก้รอตรวจ */
.q .q-wing { text-align: center; font-size: 12pt; margin-top: 0.5mm; }
.q .q-wing .wing-back { font-size: 9.5pt; }
.q .q-table { gap: 0.25mm; background: var(--c-line); }
.q .q-table div { background: #fff; border: 0 !important; }
.q .q-table div.wide { grid-column: span 2; }
.logo-pending {
  font-family: var(--f-head); font-size: 9pt; line-height: 1.4; color: #5A3A00; background: var(--c-warn-bg);
  border: 0.3mm dashed var(--c-warn); border-radius: 10mm; padding: 0.4mm 3mm; margin-bottom: 1.5mm; position: relative; z-index: 9;
}
/* E19 (d): ไม่มีรูปไก่ — แผงชื่อไก่ + ตราประดับ เต็มพื้นที่แทนกรอบรูป */
.q .q-nophoto {
  flex: 1 1 auto; width: 100%; min-height: 50mm; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2mm;
  border-radius: 3mm; border: 0.6mm solid var(--c-gold); background:
    radial-gradient(circle at 50% 38%, var(--c-gold-light) 0, #fff 62%);
}
.q .q-nophoto .emblem { width: 46mm; height: 46mm; opacity: .9; }
.q .q-nophoto .q-name { font-size: 30pt; margin-top: 0; }
.q .q-nophoto .q-wing { font-size: 14pt; }
.q.no-photo .q-table div { font-size: 13pt; padding: 2.4mm 5mm; }
.q.no-photo .q-parent b { font-size: 14pt; }
.la .info { grid-template-columns: repeat(5, 1fr); }
/* ช่องปู่ย่าตายายในแบบ A: กิ๊บ + สีขนอยู่บรรทัดเดียวกัน ประหยัดความสูง */
.la .ped .cell:not(.par) .nd-sub { display: inline; }
.la .ped .cell:not(.par) .nd-sub + .nd-sub::before { content: "  |  "; color: var(--c-line-strong); white-space: pre; }
.la .ped .cell:not(.par) { display: block; padding-top: 1.6mm; }
.q .q-nophoto { position: relative; }
.q .q-nophoto::after { content: ""; position: absolute; inset: 3mm; border: 0.3mm dashed var(--c-gold); border-radius: 2mm; pointer-events: none; }
.q .q-nophoto .emblem { width: 62mm; height: 62mm; }
.q .q-nophoto .q-name { font-size: 34pt; }
.cert-toolbar .tb-print { white-space: nowrap; }

/* =========================================================
   รอบ 3: ตัวอักษรข้อมูลบนใบ ≥ 9pt · น้ำหนักใต้รูป · ประวัติการชน · กันล้นแบบตรวจจับได้
   ========================================================= */
/* แถวตารางห้ามโตเกินกรอบเงียบ ๆ — ถ้าล้นให้ตัดและรายงาน (adapt ใน cert.js) */
.la .ped { grid-template-rows: auto repeat(4, minmax(0, 1fr)); min-height: 0; }
.la .ped .cell { overflow: hidden; }
.lb .tree { grid-template-rows: repeat(4, minmax(0, 1fr)); }
.lb .box { overflow: hidden; }

/* Layout A: ขนาดตัวอักษรข้อมูลไม่ต่ำกว่า 9pt */
.la .info .k { font-size: 9pt; }
.la .info .v { font-size: 10.5pt; }
.la .info > div { padding: 1mm 2.6mm; }
.la .wing.in-cell .wing-main { font-size: 10.5pt; }
.la .wing-back { font-size: 9pt; }
.la .nd-label { font-size: 9pt; }
.la .nd-sub { font-size: 9pt; }
.la .nd-name { font-size: 11pt; }
.la .ped .par .nd-name { font-size: 12.5pt; }
.la .nd-text, .la .nd-unknown { font-size: 10.5pt; }
.la .nd-off { font-size: 8pt; }
.la .ped .th { font-size: 9.5pt; padding: 0.8mm 3mm; }
.la .ped .cell { padding: 1mm 3mm; }
.la .foot .meta { font-size: 9pt; }
.la .legal { font-size: 8pt; }

/* Layout A: แถบใต้รูป น้ำหนัก (มีเมื่อกรอก) */
.la .left-col { display: flex; flex-direction: column; gap: 1.5mm; min-height: 0; }
.la .left-col .photo { flex: 1 1 auto; min-height: 0; }
.la .photo-stats { border: 0.3mm solid var(--c-line-strong); border-radius: 2mm; padding: 1mm 2.6mm; font-size: 10pt; line-height: 1.45; text-align: center; }
.la .photo-stats .k { color: var(--c-muted); font-size: 9pt; }
.la .photo-stats .sep { color: var(--c-line-strong); margin: 0 2mm; }

/* Layout B */
.lb .nd-sub { font-size: 9pt; }
.lb .nd-label { font-size: 9pt; }

/* ประวัติการชน: ป้ายเล็กต่อจากกิ๊บ/สีขน */
.nd-fight { color: var(--c-gold-dark); font-weight: 600; }
.fight-note { color: var(--c-ink-2); font-style: normal; }
.q .q-parent .nd-fight { font-size: 10.5pt; margin-top: 0.5mm; }

/* กล่องที่ล้น: บรรทัดเล็กเรียงต่อกันบรรทัดเดียว (เหมือนช่องปู่ย่าตายายแบบ A) */
.tight .nd-subs .nd-sub { display: inline; }
.tight .nd-subs .nd-sub + .nd-sub::before { content: "  |  "; color: var(--c-line-strong); white-space: pre; }

/* ข้อความเตือนในหน้าตัวอย่าง (ไม่พิมพ์) */
.tb-warn { margin-top: 6px; background: var(--c-warn-bg); color: #5A3A00; border: 1px dashed var(--c-warn); border-radius: 8px; padding: 6px 10px; font-size: 13px; line-height: 1.5; }
.tb-warn:empty { display: none; }
/* รอบ 3 (ปรับ): ป้ายเล็กในกล่องไม่ต่ำกว่า 9pt · ใบ B ให้ผังต้นไม้สูงขึ้นเพื่อรับบรรทัดประวัติการชน */
.la .nd-sub .wing-k, .lb .nd-sub .wing-k { font-size: 1em; }
.la .farm-block .fsub { font-size: 9pt; }
.lb .hero { height: 78mm; }
.lb .box { padding: 1mm 2.8mm; }
.lb .box .nd-name { line-height: 1.3; }
.sign-zone .sign { font-size: 9pt; }
.lb .foot .meta { font-size: 9pt; }
.lb .farm-block .fsub, .lb .tree-title span { font-size: 9pt; }
.lb .farm-block .fsub { white-space: nowrap; }

/* =========================================================
   รอบ 4: ข้อความเตือนท้ายใบตัดบรรทัดเฉพาะช่องว่าง · แถบใบด่วนอยู่ในกรอบ · ระยะหัวข้อผังใบ B
   ========================================================= */
.legal .nw { white-space: nowrap; }
.legal .nw-sep { white-space: nowrap; color: var(--c-muted); }
.la .legal, .lb .legal { font-size: 8pt; line-height: 1.45; }
/* ใบด่วน: แถบน้ำตาลอยู่ภายในกรอบทอง (กรอบทองอยู่ที่ 6.2 มม. จากขอบกระดาษ) */
.q .content { inset: 11mm 12mm 7.6mm 12mm; }
.q .q-band { width: calc(100% + 9mm); margin-top: 3mm; padding: 2.2mm 6mm 2.6mm; border-radius: 1.6mm; }
.q .q-band .legal { font-size: 8pt; line-height: 1.45; }
/* ใบ B: เว้นระยะหัวข้อ "ผังสายเลือด 2 รุ่น" จากขอบล่างรูป */
.lb .tree-title { margin-top: 6mm; }
.q .q-band .legal .nw-sep { color: #CDBA98; }
/* ใบ A: ข้อความเตือนท้ายใบอยู่ใต้ข้อมูลออกใบ กว้างเต็มช่อง → ไม่เกิน 2 บรรทัด · ลายเซ็นอยู่ขวาสูงเต็มสองแถว */
.la .foot { grid-template-columns: 1fr 78mm; row-gap: 1.2mm; align-items: end; }
.la .foot > .meta { grid-column: 1; grid-row: 1; }
.la .foot > :nth-child(2) { grid-column: 1; grid-row: 2; padding-top: 1mm; border-top: 0.25mm dashed var(--c-line); }
.la .foot > .sign-zone { grid-column: 2; grid-row: 1 / span 2; }
/* ใบ B: ส่วนรูป+การ์ดสูงตามเนื้อหา (เดิมสูงตายตัว 78 มม. การ์ดยาวจึงล้นทับหัวข้อผัง) — ผังต้นไม้ใช้ที่ที่เหลือ */
.lb .hero { height: auto; min-height: 74mm; grid-template-rows: auto; }
.lb .hero-info dl { row-gap: 0.2mm; line-height: 1.4; }
.lb .hero .photo { position: relative; }
.lb .hero .photo img { position: absolute; inset: 0; }
/* บรรทัดเล็กที่เรียงต่อกัน: ตัดบรรทัดได้เฉพาะระหว่างรายการ ไม่ตัดกลางคำ ("เหลืองหาง / ขาว") */
.tight .nd-subs .nd-sub, .la .ped .cell:not(.par) .nd-sub { white-space: nowrap; }
.nd-sub { overflow-wrap: normal; }
.tight .nd-subs .nd-sub + .nd-sub::before, .la .ped .cell:not(.par) .nd-sub + .nd-sub::before { white-space: pre-wrap; }
.lb .tight .nd-subs .nd-fight { display: block; }
.lb .tight .nd-subs .nd-fight::before { content: none; }

/* =========================================================
   รอบ 7: พิมพ์ A4 ตามแนวของใบเสมอ (A = 297×210 · B/ใบด่วน = 210×297 มม.) — ไม่ใช้ความกว้างจอตอนพิมพ์
   @page อยู่ในแต่ละหน้า (cert-a / cert-b / cert-quick) · ตัวอักษรเตือนท้ายใบ 9pt · ใบ B ข้อความ "ไม่อยู่ในระบบ" 9pt
   ========================================================= */
.la .legal, .lb .legal, .q .q-band .legal, .legal .nw { font-size: 9pt; }
.la .nd-off, .lb .nd-off { font-size: 9pt; }
/* ใบ A: ประวัติชนของปู่/ตาขึ้นบรรทัดของตัวเอง (กิ๊บ | สีขน ยังอยู่บรรทัดเดียว) — ไม่ต้องตัด "ชนะสูงสุด" เพราะบรรทัดยาว */
.la .ped .cell:not(.par) .nd-sub.nd-fight { display: block; white-space: normal; }
.la .ped .cell:not(.par) .nd-sub.nd-fight::before { content: none; }
/* ใบ A: แถวผังสูงตามเนื้อหาแล้วแบ่งที่เหลือเท่ากัน · ตัวผังถูกจำกัดความสูง (ไม่ล้นลงใต้ส่วนท้ายเงียบ ๆ) → adapt ตรวจได้ */
.la .body { grid-template-rows: minmax(0, 1fr); }
.la .right { min-height: 0; }
.la .ped { grid-template-rows: auto repeat(4, auto); align-content: stretch; overflow: hidden; }
@media print {
  html, body { width: auto !important; height: auto !important; min-width: 0 !important; margin: 0 !important; padding: 0 !important; overflow: visible !important; background: #fff; }
  .stage, .sheet-holder, .paper { margin: 0 !important; padding: 0 !important; width: auto !important; height: auto !important; transform: none !important; }
  .sheet.landscape { width: 297mm !important; height: 210mm !important; }
  .sheet.portrait { width: 210mm !important; height: 297mm !important; }
  .sheet { margin: 0 !important; break-inside: avoid; page-break-inside: avoid; }
  .print-help, .tb-warn { display: none !important; }
}
/* กล่องบอกการตั้งค่าพิมพ์บนมือถือ (ไม่พิมพ์) */
.print-help { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px; font-family: var(--f-body); }
.print-help .ph-card { background: #fff; border-radius: 14px; padding: 18px 18px 14px; max-width: 360px; width: 100%; font-size: 16px; line-height: 1.55; color: var(--c-ink); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.print-help .ph-card > b { font-family: var(--f-head); font-size: 18px; color: var(--c-primary); }
.print-help p { margin: 8px 0 4px; }
.print-help ul { margin: 0 0 6px; padding-left: 20px; }
.print-help .ph-note { font-size: 14px; color: var(--c-muted); }
.print-help .ph-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }
.print-help button { font: inherit; min-height: 44px; padding: 6px 14px; border-radius: 10px; border: 1px solid var(--c-line-strong); background: #fff; cursor: pointer; }
.print-help .ph-go { background: var(--c-gold); border-color: var(--c-gold); color: #241B00; font-weight: 600; }
.nd-name .nd-farm { font-weight: 500; }

/* =========================================================
   รอบ 11 (E50): ห้ามพิมพ์ข้อความที่ถูกตัดครึ่ง
   กล่องผังสูงตามเนื้อหา (ไม่แบ่งความสูงเท่ากัน) แล้วแบ่งที่เหลือ · กล่องพ่อแม่/การ์ดข้อมูลยกที่ว่างให้
   ล้นอยู่ → ย่อตัวอักษรรายกล่องทีละ 0.5pt ไม่ต่ำกว่า 9pt (adapt ใน cert.js) → ยังล้น = บล็อกปุ่มออกใบ/พิมพ์
   ========================================================= */
.la .ped { grid-template-rows: auto repeat(4, minmax(min-content, 1fr)); }
.lb .tree { grid-template-rows: repeat(4, minmax(min-content, 1fr)); }
/* ใบ A: ยกที่ว่างให้ผัง — การ์ดข้อมูล 6 คอลัมน์ (ผู้เพาะ/เจ้าของ/เลขที่ใบ กว้าง 2 ไม่ต้องขึ้นบรรทัดใหม่) · QR 22 มม. · รูปแคบลง ผังกว้างขึ้น */
.la .info { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.la .info > .wide { grid-column: span 2; }
.la .f-head { grid-template-columns: 1fr auto 1fr 27mm; }
.la .f-head .qr-block .qr { width: 22mm; height: 22mm; }
.la .body { grid-template-columns: 66mm 1fr; }
.la .ped .cell:not(.par) { padding-top: 0.9mm; padding-bottom: 0.9mm; }
.la .info > .span3 { grid-column: span 3; }
.cert-toolbar .tb-print:disabled { opacity: .45; cursor: not-allowed; }
/* ใบ A หัวใบ: ชื่อฟาร์มได้ความกว้างเต็ม (ไม่ถูกชื่อไก่ยาวบีบจนหลายบรรทัด) · ชื่อไก่ใช้ที่เหลือแล้วย่อให้เหลือบรรทัดเดียว (adapt) */
.la .f-head.lg-left { grid-template-columns: max-content minmax(0, 1fr) 0 27mm; }
.la .f-head.lg-right { grid-template-columns: 0 minmax(0, 1fr) max-content 27mm; }
.la .f-head.lg-center { grid-template-columns: minmax(0, 1fr) max-content minmax(0, 1fr) 27mm; }
.la .f-head .center-col, .la .f-head .col-a { min-width: 0; }
.la .farm-block .fname { white-space: nowrap; }
/* ใบ A ปู่ย่าตายาย: ป้ายอยู่บรรทัดเดียวกับชื่อ (ประหยัด 1 บรรทัดต่อกล่อง) */
.la .ped .cell:not(.par) .nd-label { display: inline; margin-right: 1.6mm; }
.la .ped .cell:not(.par) .nd-name, .la .ped .cell:not(.par) .nd-text, .la .ped .cell:not(.par) .nd-unknown { display: inline; }
.la .ped .cell:not(.par) .nd-subs, .la .ped .cell:not(.par) .nd-off { display: block; }
/* บรรทัดป้าย+ชื่อแบบ inline: ใช้ฐานตัวอักษร 9pt ให้ความสูงบรรทัดตามชื่อจริง (ไม่ใช่ strut ของตัวอักษรตั้งต้น) */
.la .ped .cell:not(.par) { font-size: 9pt; line-height: 1.35; }
/* ใบ B: กล่องปู่ย่าตายายกว้างขึ้น (ตัวไก่/พ่อแม่แคบลง — สูง 2 แถวมีที่เหลือ) · ป้ายอยู่บรรทัดเดียวกับชื่อ · บรรทัดเล็กเรียงต่อกัน */
.lb .tree { grid-template-columns: 38mm 50mm minmax(0, 1fr); column-gap: 8mm; }
.lb .box.g { font-size: 9pt; line-height: 1.35; }
.lb .box.g .nd-label { display: inline; margin-right: 1.6mm; }
.lb .box.g .nd-name, .lb .box.g .nd-text, .lb .box.g .nd-unknown { display: inline; }
.lb .box.g .nd-subs, .lb .box.g .nd-off { display: block; }
.lb .box.g .nd-subs .nd-sub { display: inline; white-space: nowrap; }
.lb .box.g .nd-subs .nd-sub + .nd-sub::before { content: "  |  "; color: var(--c-line-strong); white-space: pre-wrap; }
.lb .box.g .nd-subs .nd-fight { display: block; white-space: normal; }
.lb .box.g .nd-subs .nd-fight::before { content: none; }
.lb .box.g { display: block; }   /* flex ทำให้ลูกเป็น block เสมอ — ป้าย+ชื่อจึงต้องใช้ block ปกติ */
/* ประวัติชนเป็นบรรทัดของตัวเองเสมอ ตัดบรรทัดตามคำได้ (ไม่ยื่นเกินขอบกล่อง) */
.tight .nd-subs .nd-fight, .lb .box .nd-fight, .la .ped .nd-fight { white-space: normal; }
.lb .tight .nd-subs .nd-fight::before { content: none; }
.wing-k { white-space: nowrap; }   /* ป้าย "ผู้เพาะ" "กิ๊บ" "สีขน" ห้ามตัดกลางคำ */
.nw-w { white-space: nowrap; }   /* E51: คำไทยในชื่อห้ามถูกตัดกลางคำ — ตัดได้ที่ <wbr> ระหว่างคำเท่านั้น */
