/* =========================================================
   Report / Print stylesheet
   รูปแบบรายงานอ้างอิงแบบฟอร์ม "Traverse Loop" ของงานก่อสร้างจริง
   ========================================================= */

/* ---- Report preview (on screen) ---- */
/* กระดาษรายงานกว้าง 1180 px (A4 แนวนอน) — บนจอมือถือต้องบังคับ max-width ไว้
   ไม่งั้นกล่องจะขยายตามความกว้างกระดาษ แล้วโดนกรอบนอกตัดทิ้ง เลื่อนดูไม่ได้ */
.report-preview{
  background:#fff; border:1px solid var(--line); border-radius:10px; box-shadow:var(--sh-2);
  padding:16px; overflow-x:auto;
  max-width:100%; width:100%; -webkit-overflow-scrolling:touch;
}
.rpt{font-family:'Sarabun',sans-serif; color:#000; font-size:10.5px; width:100%; min-width:1180px}

/* คำใบ้บนจอแคบ : รายงานเป็นกระดาษ A4 แนวนอน จึงกว้างกว่าจอเสมอ */
.rpt-hint{
  display:none; margin:0 0 8px; padding:6px 8px; border-radius:6px;
  font-size:12px; color:var(--warn); background:var(--warn-bg); text-align:center;
}
@media (max-width:900px){ .rpt-hint{display:block} }
@media print{ .rpt-hint{display:none !important} }

/* ---- หัวกระดาษบริษัท (letterhead) ---- */
.rpt-brand{
  display:flex; align-items:center; gap:11px;
  border-bottom:1.4px solid #9E1B32; padding-bottom:5px; margin-bottom:8px;
}
.rpt-brand .rpt-logo{height:36px; width:auto; flex:none}
.rpt-brand-t{display:flex; flex-direction:column; line-height:1.3}
.rpt-brand-t b{font-size:12px; color:#9E1B32}
.rpt-brand-t span{font-size:8.4px; color:#333}

.rpt-title{text-align:center; font-size:14px; font-weight:700; margin-bottom:2px}
.rpt-warn{
  border:1px solid #B3261E; background:#FDECEA; color:#7A1B14;
  padding:4px 8px; border-radius:4px; font-size:9.5px; margin:5px 0 8px; text-align:center;
}
.rpt-sub{text-align:center; font-size:11px; margin-bottom:10px}
.rpt-meta{display:flex; justify-content:space-between; gap:20px; font-size:10.5px; margin-bottom:8px}
.rpt-meta table{border-collapse:collapse}
.rpt-meta td{padding:1px 4px 1px 0; vertical-align:top}
.rpt-meta td.k{white-space:nowrap; font-weight:600}
.rpt-meta td.v{border-bottom:1px dotted #999; min-width:210px; padding-left:5px}
.rpt-loop{font-weight:700; font-size:12px; text-align:right; white-space:nowrap}

table.rpt-tbl{width:100%; border-collapse:collapse; font-size:9px; table-layout:auto}
table.rpt-tbl th, table.rpt-tbl td{border:.6px solid #333; padding:1.5px 3px; text-align:center; line-height:1.25}
table.rpt-tbl th{background:#EDEFF3; font-weight:600; font-size:8.4px}
table.rpt-tbl td.num{font-family:'Roboto Mono',monospace; text-align:right; font-size:8.6px}
table.rpt-tbl td.sta{text-align:left; font-weight:600; white-space:nowrap}
table.rpt-tbl tr.ctrl td{background:#FFF6E0}
table.rpt-tbl tr.sum td{background:#EDEFF3; font-weight:700}
table.rpt-tbl td.corr{color:#00529B; font-style:italic}
table.rpt-tbl td.neg{color:#000}

.rpt-foot{display:flex; gap:26px; margin-top:9px; font-size:9.6px; align-items:flex-start}
.rpt-foot table{border-collapse:collapse; width:100%}
.rpt-foot td{padding:1.5px 5px 1.5px 0; white-space:nowrap}
.rpt-foot td.k{font-weight:600}
.rpt-foot td.eq{text-align:center; width:14px}
.rpt-foot td.v{font-family:'Roboto Mono',monospace; text-align:right; padding-right:8px}
.rpt-foot td.n{font-size:8.6px; font-style:italic; color:#333}
.rpt-chk-pass{color:#0A6B3D; font-weight:700}
.rpt-chk-fail{color:#B3261E; font-weight:700}

.rpt-sign{display:flex; justify-content:space-around; margin-top:26px; gap:30px; font-size:10px; text-align:center}
.rpt-sign div{flex:1}
.rpt-sign .line{border-bottom:1px dotted #333; height:26px; margin:0 8px}
.rpt-sign .line.has-sig{height:auto; min-height:26px; display:flex; align-items:flex-end; justify-content:center}
.rpt-sign .rpt-sig{display:block; max-height:15mm; max-width:55mm; object-fit:contain; margin:0 auto -3px}
.rpt-sign .nm{margin-top:3px}
.rpt-sign .role{font-weight:600; margin-top:2px}

.rpt-note{margin-top:10px; font-size:8.6px; color:#333; line-height:1.5; border-top:.6px solid #999; padding-top:5px}
.rpt-page{page-break-after:always}
.rpt-page:last-child{page-break-after:auto}
.rpt-h2{font-size:11.5px; font-weight:700; margin:12px 0 5px; border-bottom:1px solid #999; padding-bottom:2px}
.rpt-2col{display:flex; gap:16px; align-items:flex-start}
.rpt-2col > *{flex:1; min-width:0}
.rpt-calc{font-size:9.2px; line-height:1.6}
/* หน้าวิธีคำนวณแบบคอลัมน์เดียว — ขั้นตอนเรียงต่อเนื่อง ไม่ข้ามฝั่ง
   เนื้อหาต้องไหลเต็มแผ่นแล้วค่อยขึ้นแผ่นใหม่
   ถ้าสั่งห้ามตัดกลาง "ทั้งขั้นตอน" ขั้นที่ยาวกว่าที่ว่างจะถูกดันไปทั้งก้อน เหลือกระดาษเปล่าครึ่งแผ่น
   จึงคุมเฉพาะหน่วยย่อย : กล่องสูตรห้ามขาดกลาง และหัวข้อย่อยห้ามค้างท้ายแผ่นโดยไม่มีเนื้อหาตาม */
.rpt-calc-1col{max-width:170mm; margin:0 auto}
.rpt-calc .stp{margin-bottom:10px; page-break-inside:auto; break-inside:auto}
.rpt-calc .stp-h{font-size:10px; page-break-after:avoid; break-after:avoid}
.rpt-calc .stp-c{font-style:italic; color:#555; font-size:8.2px; page-break-before:avoid; break-before:avoid}
.rpt-calc .f{page-break-inside:avoid; break-inside:avoid}
.rpt-calc .fh{page-break-after:avoid; break-after:avoid; page-break-inside:avoid; break-inside:avoid}
.rpt-calc .tbl-wrap{page-break-inside:auto; break-inside:auto}
/* บนจอ : หน้าวิธีคำนวณพิมพ์เป็นกระดาษแนวตั้ง จึงแสดงเป็นแผ่นแนวตั้งให้ตรงกับของจริง */
.report-preview .rpt-calc-page{min-width:0 !important; max-width:196mm}
.rpt-calc .f{font-family:'Roboto Mono',monospace; background:#F6F7F9; border-left:2px solid #999; padding:3px 7px; margin:3px 0; white-space:pre-wrap; word-break:break-word}
.rpt-calc .fh{font-weight:600; font-size:8.8px; margin-top:5px; color:#333}
/* เลขหน้า และสารบัญลำดับการอ่าน */
.rpt-pg{text-align:right; font-size:9px; color:#555; margin-bottom:2px}
.rpt-toc{
  display:flex; flex-wrap:wrap; gap:4px 14px; align-items:center;
  border:.6px solid #999; border-left:3px solid #9E1B32; background:#FAFBFD;
  padding:5px 9px; margin-top:9px; font-size:9px; border-radius:0 4px 4px 0;
}
.rpt-toc b{font-size:9.6px; margin-right:4px}
.rpt-toc span{white-space:nowrap}

/* หน้าสมุดสนาม */
table.rpt-book{width:100%; border-collapse:collapse; font-size:9.2px; margin-top:6px}
table.rpt-book th,table.rpt-book td{border:.6px solid #333; padding:2px 5px; text-align:center}
table.rpt-book th{background:#EDEFF3; font-weight:600; font-size:8.6px}
table.rpt-book td.r{font-family:'Roboto Mono',monospace; text-align:right}
table.rpt-book td.sta{font-size:11px; background:#FAFBFD}
table.rpt-book td.hi{background:#FFF6E0}
table.rpt-book tr.face-r td{background:#F7F8FA}
.rpt-book-wrap{overflow:visible}

/* ---- ตารางงานระดับในรายงาน ---- */
.rpt .tbl-block,.rpt .tbl-wrap{overflow:visible; max-width:none; border:0; background:none}
table.rpt-lvl{width:100%; border-collapse:collapse; font-size:8.4px; margin-top:5px; table-layout:auto}
table.rpt-lvl thead th,table.rpt-book thead th{position:static}
table.rpt-lvl th,table.rpt-lvl td{border:.6px solid #333; padding:1.6px 4px; text-align:center; line-height:1.3}
table.rpt-lvl th{background:#EDEFF3; font-weight:600; font-size:7.8px}
table.rpt-lvl td.r{font-family:'Roboto Mono',monospace; text-align:right}
table.rpt-lvl td.sta{text-align:left; font-weight:600; white-space:nowrap}
table.rpt-lvl td.l{text-align:left}
table.rpt-lvl td.sm{font-size:7.4px; color:#333; white-space:normal}
table.rpt-lvl tr.ctrl td{background:#FFF6E0}
table.rpt-lvl tr.is td{background:#FAFAFB}
table.rpt-lvl tr.sum td{background:#EDEFF3; font-weight:700}
table.rpt-lvl td.corr{color:#00529B; font-style:italic}
table.rpt-book.lvl-book{font-size:7.8px}
table.rpt-book.lvl-book td.wire{font-size:7px; text-align:left; color:#444}
table.rpt-book.lvl-book td.i{font-family:'Roboto Mono',monospace; font-size:7px; color:#444}
table.rpt-book.lvl-book td.r{font-family:'Roboto Mono',monospace; text-align:right}
table.rpt-book.lvl-book tr.mean td{border-bottom:1px solid #333; font-weight:700}
table.rpt-book.lvl-book td.sm{font-size:7px; white-space:normal}
.rpt .tbl-foot{font-size:7.4px; line-height:1.5; padding:3px 5px; background:#F6F7F9;
  border:.5px solid #999; white-space:pre-wrap; font-family:'Sarabun',sans-serif}
.rpt-plot svg,.rpt .lvl-fig svg{width:100%; height:auto; border:.6px solid #666; border-radius:4px; background:#fff}

/* ---- แผ่นรูปตัดแบบเขียนแบบ ----
   viewBox ของ SVG มีหน่วยเป็นมิลลิเมตรบนกระดาษ
   ตอนพิมพ์จึงบังคับความกว้างเป็น มม. จริง มาตราส่วนที่ระบุจึงถูกต้องแม่นยำ */
.rpt-sheet{border:.6px solid #666; border-radius:3px; padding:2px; background:#fff; overflow:hidden}
.rpt-sheet svg.cs-sheet{display:block; width:100%; height:auto}
@media print{
  .rpt-sheet svg.cs-sheet{width:258mm; max-width:258mm}
}
.cs-info{display:flex; gap:6px; align-items:stretch}
.cs-box{
  flex:1; border:.6px solid #999; border-radius:3px; padding:4px 6px;
  font-size:7.2px; line-height:1.55; background:#FCFCFD;
}
.cs-box b{display:block; font-size:7.8px; margin-bottom:2px; color:#333}
.cs-box .sm{color:#666; font-size:6.6px; margin-top:2px}
.cs-box .mono{font-family:'Roboto Mono',monospace; font-weight:700}
.cs-box .sw{
  display:inline-block; width:14px; height:7px; vertical-align:middle;
  margin-right:4px; border:.4px solid #999;
}
/* สัญลักษณ์ที่เป็น "เส้น" ต้องบางและไม่มีกรอบ ไม่งั้นจะดูเป็นแถบสีเทา */
.cs-box .sw.ln{height:0; border:0; border-top:1.2px solid; background:none !important}
.cs-box .sw.ln.dash{border-top-style:dashed}
.cs-box .sw.ln[style*="#111"]{border-top-color:#111}
.cs-box .sw.ln[style*="1B5E20"]{border-top-color:#1B5E20}
.cs-box .sw.ln[style*="D32F2F"]{border-top-color:#D32F2F}
.cs-unit{
  flex:0 0 auto; align-self:flex-end; border:.6px solid #333; border-radius:3px;
  padding:4px 8px; font-size:8px; font-weight:600; background:#fff;
}

/* ---- รูปตัดตามขวางในรายงาน ---- */
.rpt-cs{margin-bottom:10px; break-inside:avoid; page-break-inside:avoid}
.rpt-cs-h{font-size:9.4px; font-weight:600; margin-bottom:3px; color:#333}
.rpt-cs svg.cs-svg{width:100%; height:auto; border:.6px solid #666; border-radius:4px; background:#fff}
table.rpt-lvl td.cut{color:#7A2233}
table.rpt-lvl td.fill{color:#0A6B3D}
table.rpt-lvl.cs-sum{width:100%; max-width:none}
table.rpt-lvl.cs-sum thead th{background:#FFF6E0; text-align:left}
table.rpt-lvl.cs-sum tr.hi td{background:#FFF6E0}
table.rpt-lvl.cs-sum .net-fill{color:#B3261E}
table.rpt-lvl.cs-sum .net-cut{color:#0A6B3D}

/* ตารางประกอบวิธีคำนวณ (DMD · พิกัดฉาก · แบบฟอร์ม 7.5) ในหน้ารายงาน */
.rpt-calc .tbl-wrap{overflow-x:auto; margin:3px 0}
.rpt-calc table.tbl{font-size:6.8px; width:100%}
.rpt-calc table.tbl th,.rpt-calc table.tbl td{padding:1px 2px; border:.5px solid #999; white-space:nowrap}
.rpt-calc table.tbl thead th{background:#EDEFF3; position:static; font-size:6.4px}
.rpt-calc .tbl-foot{font-size:6.8px; line-height:1.5; padding:3px 5px; background:#F6F7F9; border:.5px solid #999; white-space:pre-wrap}
.rpt-plot{
  display:block; margin:6px auto 0; background:#fff; border:.6px solid #333;
  width:auto; max-width:100%; max-height:150mm; object-fit:contain;
}
@media screen{ .rpt-plot{max-height:none; width:100%} }

/* หน้ารูปประกอบ */
.rpt-figs{display:grid; grid-template-columns:repeat(3,1fr); gap:10px; margin-top:6px}
.rpt-figs .fig{margin:0; break-inside:avoid; page-break-inside:avoid}
.rpt-figs .fig svg{border:.6px solid #666; border-radius:4px; width:100%; height:auto; background:#fff}
.rpt-figs .fig figcaption{font-size:7.8px; color:#333; text-align:center; margin-top:2px; line-height:1.35}
@media print{ .rpt-figs{grid-template-columns:repeat(4,1fr); gap:7px} }

/* =========================================================
   ใบรับรองผลการวัดสอบกล้องประมวลผลรวม — กระดาษ A4 แนวตั้ง
   (หน้าอื่นของระบบเป็น A4 แนวนอน จึงต้องบังคับความกว้างเฉพาะใบนี้)
   ========================================================= */
.rpt-cert{min-width:0 !important; max-width:196mm; margin:0 auto; font-size:10px}
.rpt-cert table.rpt-tbl{font-size:8.8px}
.rpt-cert table.rpt-tbl td.l, .rpt-cert table.rpt-tbl th.l{text-align:left}
.rpt-cert .rpt-appear td{font-size:8.2px; line-height:1.35}
.cert-verdict{
  margin:10px 0 4px; padding:7px 12px; border-radius:6px; font-size:11.5px; font-weight:700;
  border:1px solid #999; text-align:center;
}
.cert-verdict.ok{background:#EAF6EC; border-color:#7BBF92; color:#0A6B3D}
.cert-verdict.no{background:#FBECEC; border-color:#E39A9A; color:#B3261E}
.cert-verdict.wait{background:#F6F7F9; border-color:#B9BFC7; color:#3A4048}
/* ภาพถ่ายเครื่องมือ 2 รูป วางคู่กัน — ไม่ให้รูปถูกตัดข้ามหน้า */
.rpt-cert .rpt-photos{display:grid; grid-template-columns:1fr 1fr; gap:8px; margin:3px 0 8px}
.rpt-cert .rpt-photos figure{margin:0; border:.6px solid #999; padding:4px; break-inside:avoid; page-break-inside:avoid; text-align:center}
.rpt-cert .rpt-photos img{width:100%; height:62mm; object-fit:contain; background:#F6F7F9; display:block}
.rpt-cert .rpt-photos figcaption{font-size:8.6px; line-height:1.45; margin-top:3px; text-align:left}
.rpt-cert .rpt-photos figcaption span{color:#555}
/* ส่วนประกอบของใบรับรองแบบเต็ม — วิธีวัดสอบ · เกณฑ์ · สูตร · ค่าอ่านดิบ */
.rpt-cert .rpt-pg{margin-left:auto; font-size:9px; color:#333; white-space:nowrap}
.rpt-cert .rpt-method{font-size:9.2px; line-height:1.55; margin:3px 0 2px; text-align:justify}
.rpt-cert .rpt-crit{
  font-size:9.2px; line-height:1.5; margin:2px 0 4px; padding:3px 7px;
  background:#F6F7F9; border-left:2px solid #666;
}
.rpt-cert .rpt-formula{
  font-family:'Roboto Mono',monospace; font-size:8.8px; line-height:1.55; white-space:pre-wrap;
  margin:3px 0 5px; padding:4px 8px; background:#FBFBFC; border:.6px dashed #999;
}
.rpt-cert .rpt-h3{font-size:9.6px; font-weight:700; margin:7px 0 3px}
.rpt-cert .rpt-raw{
  font-family:'Roboto Mono',monospace; font-size:8px; line-height:1.5; margin-bottom:3px;
  word-break:break-word;
}
.rpt-cert .rpt-p{font-size:9.4px; margin:3px 0 6px}
/* หัวข้อระดับบนสุดของใบรับรอง — คั่นรายละเอียดของรอบก่อนปรับแก้กับรอบหลังปรับแก้ */
.rpt-cert .rpt-h1{
  margin:14px 0 6px; padding:5px 10px; font-size:12px; font-weight:700; color:#fff;
  background:#9E1B32; border-radius:4px;
}
.rpt-cert .cv-src{font-weight:400; font-size:9.6px}
/* ตารางเทียบก่อน–หลังปรับแก้ */
.rpt-cert table.rpt-cmp td{font-size:9px}
.rpt-cert table.rpt-cmp .cmp-up{color:#0A6B3D; font-weight:700}
.rpt-cert table.rpt-cmp .cmp-down{color:#B3261E; font-weight:700}
.rpt-cert table.rpt-cmp tr.cmp-fixed{background:#EAF6EC}
.rpt-cert table.rpt-cmp tr.cmp-broke{background:#FBECEC}
/* ใบรับรองพิมพ์ต่อเนื่อง ไม่บังคับขึ้นหน้าใหม่ แต่ห้ามให้หัวข้อค้างท้ายกระดาษ
   และห้ามตัดตารางกลางคัน ถ้าตารางยังพอลงหน้าเดียวได้ */
.rpt-cert .rpt-h2{page-break-after:avoid; break-after:avoid}
.rpt-cert .rpt-h1{page-break-after:avoid; break-after:avoid; page-break-inside:avoid; break-inside:avoid}
.rpt-cert .rpt-crit, .rpt-cert .rpt-formula{page-break-inside:avoid; break-inside:avoid}
.rpt-cert table.rpt-tbl{page-break-inside:avoid; break-inside:avoid}
.rpt-cert .rpt-sign, .rpt-cert .rpt-note{page-break-inside:avoid; break-inside:avoid}

/* บนจอ : รายงานที่แบ่งหน้า (งานวงรอบ) ให้เห็นเป็นแผ่นกระดาษแยกกันชัด ๆ
   จะได้รู้ว่าเวลาพิมพ์จะได้กี่แผ่น และแต่ละแผ่นมีอะไรบ้าง */
.report-preview .rpt-page{
  background:#fff; border:1px solid var(--line); border-radius:4px;
  box-shadow:0 2px 10px rgba(20,24,31,.07);
  padding:16px 18px; margin:0 auto 22px; position:relative;
}
.report-preview .rpt-page:last-child{margin-bottom:0}
.report-preview .rpt-page::after{
  content:'— จบหน้า —'; display:block; text-align:center; font-size:8.5px;
  color:#AEB4BD; letter-spacing:1px; margin-top:10px; padding-top:6px; border-top:1px dashed var(--line);
}
@media print{
  .report-preview .rpt-page{border:0; box-shadow:none; padding:0; margin:0}
  .report-preview .rpt-page::after{display:none}
}

.rpt-ok{color:#0A6B3D; font-weight:700}
.rpt-no{color:#B3261E; font-weight:700}
.rpt-wait{color:#6B7280}

/* ---- Print ---- */
@media print{
  @page{ size:A4 landscape; margin:8mm 7mm; }
  html,body{background:#fff !important; margin:0; padding:0}
  .no-print, .app-header, .sidebar, .doc-panel, .toast-wrap, .modal, .modal-backdrop{display:none !important}
  .app-body{display:none !important}
  .report-root{display:block !important}
  .report-preview{border:0 !important; box-shadow:none !important; padding:0 !important; border-radius:0 !important;
                  background:#fff !important; overflow:visible !important; max-width:none !important}
  .rpt{min-width:0; width:100%; font-size:9.6px}
  table.rpt-tbl{font-size:7.6px}
  table.rpt-tbl th{font-size:7.2px}
  table.rpt-tbl td.num{font-size:7.4px}
  .rpt-page{page-break-after:always}
  tr, td, th{page-break-inside:avoid}
  thead{display:table-header-group}
}

/* ---- หน้ากระดาษแนวตั้งเฉพาะบางหน้า ----
   หน้า "แสดงวิธีการคำนวณโดยละเอียด" เป็นคอลัมน์เดียวไล่ขั้นตอน พิมพ์แนวตั้งได้บรรทัดต่อแผ่นมากกว่า
   ใช้ CSS named page (@page ชื่อ + คุณสมบัติ page:) รองรับใน Chrome/Edge 110 ขึ้นไป
   เบราว์เซอร์รุ่นเก่าที่ไม่รองรับจะพิมพ์หน้านี้เป็นแนวนอนตามค่าเริ่มต้นเหมือนเดิม (ไม่พัง) */
@media print{
  @page rptPortrait{ size:A4 portrait; margin:10mm 9mm; }
  .rpt-portrait, .rpt-calc-page{ page:rptPortrait; page-break-before:always; break-before:page }
  /* กำหนดความกว้างเป็น มม. ตรง ๆ เพราะเมื่อมีหลายขนาดกระดาษในไฟล์เดียว
     Chromium ยังคิด width:100% จากกระดาษแผ่นแรก (แนวนอน) ทำให้เนื้อหาล้นขอบ */
  .rpt-calc-page{ width:192mm; max-width:192mm; min-width:0 !important }
  .rpt-calc-page .rpt-calc-1col{ max-width:none; margin:0 }
  /* กล่องที่ตั้ง overflow ไว้ (มีแถบเลื่อนบนจอ) จะตัดข้ามแผ่นไม่ได้ ตอนพิมพ์จึงปลดออก
     ไม่งั้นตารางยาว ๆ จะถูกดันไปทั้งก้อน */
  .rpt-calc .tbl-wrap{ overflow:visible }
  .rpt-calc table.tbl{ page-break-inside:auto; break-inside:auto }
  .rpt-calc{ orphans:3; widows:3 }
}
