/* รูปเล่มรายงาน A5 (148 × 210 mm) — โทนสีจากโลโก้ Medical Trend
   ขนาดรูป/ตัวอักษรมี 4 ระดับ (lvl-0 ใหญ่สุด → lvl-3 กระชับสุด)
   report.js จะเลือกระดับใหญ่ที่สุดที่ทำให้ทั้งเล่มไม่เกิน 16 หน้า */
.book {
  --navy: #1d3461;
  --blue: #1f78c1;
  --sky: #e8f2fb;
  --ink: #1c2533;
  --muted: #5f6c80;
  --line: #d9e1ec;
  /* ระดับ 0 (ค่าเริ่มต้น) */
  --res-img: 26mm;
  --res-name: 10pt;
  --res-en: 8pt;
  --res-val: 11pt;
  --pos-img: 22mm;
  --pos-name: 12pt;
  --pos-val: 15pt;
  --body-fs: 10.5pt;
  --adv-fs: 10pt;
  --adv-en-fs: 9pt;
  font-family: 'Sarabun', 'Thonburi', 'Leelawadee UI', sans-serif;
  color: var(--ink);
  font-size: var(--body-fs);
  line-height: 1.35;
}
.book.lvl-1 { --res-img: 22mm; --res-name: 9.5pt; --res-en: 7.5pt; --res-val: 10.5pt; --pos-img: 20mm; --pos-name: 11.5pt; --pos-val: 14pt; }
.book.lvl-2 { --res-img: 20mm; --res-name: 9pt; --res-en: 7.5pt; --res-val: 10pt; --pos-img: 18mm; --pos-name: 11pt; --pos-val: 13pt; --body-fs: 10pt; --adv-fs: 9.5pt; --adv-en-fs: 8.5pt; }
.book.lvl-3 { --res-img: 17mm; --res-name: 8.5pt; --res-en: 6.8pt; --res-val: 9.5pt; --pos-img: 16mm; --pos-name: 10.5pt; --pos-val: 12pt; --body-fs: 9.5pt; --adv-fs: 9pt; --adv-en-fs: 8pt; }
.book.lvl-4 { --res-img: 15mm; --res-name: 8pt; --res-en: 6.5pt; --res-val: 9pt; --pos-img: 13mm; --pos-name: 9.5pt; --pos-val: 11pt; --body-fs: 9pt; --adv-fs: 8.5pt; --adv-en-fs: 7.5pt; }
.book.lvl-4 .pos-name .en, .book.lvl-4 .pos-cls .desc { display: none; }
.book i { font-style: normal; color: var(--muted); }

.page {
  width: 148mm;
  height: 210mm;
  background: #fff;
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 7mm 8mm 6mm;
  box-sizing: border-box;
  overflow: hidden;
  break-after: page;
}

/* ---------- header / footer ---------- */
.pg-head {
  display: flex; align-items: center; gap: 2.5mm;
  padding-bottom: 2mm; border-bottom: 0.5mm solid var(--navy);
}
.pg-logo { height: 10mm; }
.pg-lab { flex: 1; min-width: 0; }
.pg-lab .th { font-family: 'Prompt', sans-serif; font-weight: 600; color: var(--navy); font-size: 8.5pt; line-height: 1.2; }
.pg-lab .en { color: var(--blue); font-size: 7pt; }
.pg-patient { text-align: right; font-size: 7.5pt; color: var(--muted); line-height: 1.25; }
.pg-patient b { color: var(--ink); font-size: 9pt; }
.pg-body { flex: 1; overflow: hidden; padding-top: 3mm; }
.pg-foot {
  display: flex; justify-content: space-between; gap: 3mm; font-size: 6.5pt; color: var(--muted);
  border-top: 0.3mm solid var(--line); padding-top: 1.5mm;
}
.pg-num { white-space: nowrap; font-weight: 600; }

.sec-title { margin-bottom: 3mm; }
.sec-title.sec-mid { margin-top: 4mm; padding-top: 3mm; border-top: 0.5mm solid var(--navy); }
.sec-title h2 { font-family: 'Prompt', sans-serif; font-weight: 600; font-size: 14pt; color: var(--navy); margin: 0; line-height: 1.2; }
.sec-title h2 small { font-size: 9pt; color: var(--muted); font-weight: 400; }
.sec-title .en { color: var(--blue); font-size: 9pt; }

/* ---------- cover ---------- */
.cover { padding: 10mm 11mm 8mm; background:
  radial-gradient(circle at 100% 0%, #dcebf8 0, #dcebf8 34mm, transparent 34.2mm),
  radial-gradient(circle at 0% 100%, #eef4fb 0, #eef4fb 42mm, transparent 42.2mm), #fff; }
.cover-top { text-align: center; }
.cover-logo { height: 40mm; }
.cover-title { text-align: center; margin: 4mm 0 5mm; }
.cover-title .kicker { letter-spacing: 0.25em; text-transform: uppercase; color: var(--blue); font-size: 7.5pt; }
.cover-title h1 { font-family: 'Prompt', sans-serif; font-weight: 600; font-size: 18pt; color: var(--navy); margin: 1mm 0 0; line-height: 1.25; }
.cover-title .en { font-family: 'Prompt', sans-serif; font-size: 13pt; color: var(--blue); }
.cover-title .panel { display: inline-block; margin-top: 2mm; padding: 0.6mm 3.5mm; border-radius: 10mm; background: var(--navy); color: #fff; font-size: 8pt; }
.cover-card { border: 0.4mm solid var(--line); border-radius: 3mm; padding: 3.5mm 4mm; background: #fff; }
.cover-card .row { display: flex; align-items: center; gap: 4mm; padding-bottom: 2mm; border-bottom: 0.3mm dashed var(--line); }
.cover-card .row span { color: var(--muted); font-size: 8pt; line-height: 1.2; }
.cover-card .big { font-family: 'Prompt', sans-serif; font-size: 14pt; color: var(--navy); font-weight: 500; line-height: 1.2; }
.cover-card .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2mm 5mm; margin-top: 2mm; }
.cover-card .grid div { display: flex; flex-direction: column; }
.cover-card .grid span { color: var(--muted); font-size: 7.5pt; }
.cover-card .grid b { font-size: 10pt; font-weight: 600; line-height: 1.25; }
.cover-card .grid i { font-size: 7.5pt; }
.cover-stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1.5mm; margin-top: 4mm; }
.stat { border-radius: 2.5mm; background: var(--sky); padding: 2mm 1mm; text-align: center; display: flex; flex-direction: column; }
.stat span { font-size: 6.5pt; color: var(--navy); min-height: 6mm; line-height: 1.2; }
.stat b { font-family: 'Prompt', sans-serif; font-size: 15pt; color: var(--navy); line-height: 1.1; }
.stat i { font-size: 6pt; line-height: 1.2; }
.stat.accent { background: var(--navy); }
.stat.accent span, .stat.accent b, .stat.accent i { color: #fff; }
.cover-foot { margin-top: auto; text-align: center; font-size: 7.5pt; color: var(--muted); border-top: 0.3mm solid var(--line); padding-top: 2mm; line-height: 1.3; }
.cover-foot .th { font-family: 'Prompt', sans-serif; color: var(--navy); font-size: 9pt; font-weight: 500; }

/* ---------- thumbnails ---------- */
.thumb { display: grid; gap: 0.5mm; border-radius: 2mm; overflow: hidden; background: #f3f6fa; flex: none; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .ph { display: flex; align-items: center; justify-content: center; background: #f1f5fa; }
.thumb.n2 { grid-template-columns: 1fr 1fr; }
.thumb.n3, .thumb.n4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.thumb.n3 > :first-child { grid-row: span 2; }
.thumb-md { width: var(--pos-img); height: var(--pos-img); }
.thumb-md .ph { font-size: calc(var(--pos-img) * 0.5); }
.thumb-md.n2 .ph, .thumb-md.n3 .ph, .thumb-md.n4 .ph { font-size: calc(var(--pos-img) * 0.25); }
.thumb-sm { width: 100%; height: var(--res-img); }
.thumb-sm .ph { font-size: calc(var(--res-img) * 0.5); }
.thumb-sm.n2 .ph, .thumb-sm.n3 .ph, .thumb-sm.n4 .ph { font-size: calc(var(--res-img) * 0.25); }

/* ---------- summary ---------- */
.ige-box { display: grid; grid-template-columns: auto 1fr; gap: 1mm 4mm; align-items: center; border-radius: 3mm; background: var(--sky); padding: 3mm 4mm; margin-bottom: 2.5mm; }
.ige-box .lbl { font-size: 9pt; color: var(--navy); font-weight: 600; line-height: 1.2; }
.ige-box .val { font-family: 'Prompt', sans-serif; font-size: 20pt; color: var(--navy); line-height: 1.1; grid-row: span 2; grid-column: 1; }
.ige-box .val small { font-size: 9pt; }
.ige-box .ref { font-size: 8pt; color: var(--muted); }
.ige-box .flag { font-size: 9pt; color: #2d7a4b; font-weight: 600; }
.ige-box.high { background: #fff0ea; }
.ige-box.high .flag { color: #c8303c; }
.class-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 0.8mm; margin-bottom: 3mm; }
.class-strip div { border-radius: 1.5mm; padding: 1mm 0.5mm; text-align: center; line-height: 1.15; }
.class-strip b { display: block; font-size: 10pt; }
.class-strip span { display: block; font-size: 6.8pt; }
.class-strip em { display: block; font-style: normal; font-size: 5.8pt; opacity: 0.85; }
.sw { display: inline-flex; width: 5.5mm; height: 5.5mm; border-radius: 1.2mm; align-items: center; justify-content: center; font-weight: 700; font-size: 8pt; }
.sub-title { font-weight: 600; color: var(--navy); font-size: 10.5pt; margin: 1mm 0 2mm; line-height: 1.25; }
.sub-title i { display: block; font-weight: 400; font-size: 8.5pt; }
.pos-pair { display: grid; grid-template-columns: repeat(var(--pos-cols, 2), 1fr); gap: 2mm; margin-bottom: 2mm; }
.pos-row {
  display: grid; grid-template-columns: var(--pos-img) 1fr; gap: 1mm 2.5mm; align-items: center;
  padding: 1.8mm 2.2mm 1.8mm 1.8mm; border: 0.3mm solid var(--line); border-left: 1.4mm solid var(--c); border-radius: 2.5mm;
}
.pos-row .thumb { grid-row: span 2; }
.pos-name { min-width: 0; }
.pos-name .th { font-family: 'Prompt', sans-serif; font-size: var(--pos-name); font-weight: 500; color: var(--navy); line-height: 1.2; }
.pos-name .en { font-size: 8pt; line-height: 1.25; }
.code { color: var(--muted); font-size: 7pt; border: 0.25mm solid var(--line); border-radius: 1mm; padding: 0 0.8mm; }
.pos-name .cat { display: none; }
.pos-val { display: flex; align-items: baseline; gap: 1.5mm; flex-wrap: wrap; }
.pos-val b { font-family: 'Prompt', sans-serif; font-size: var(--pos-val); line-height: 1; }
.pos-val small { color: var(--muted); font-size: 7pt; }
.pos-val .badge { margin-left: auto; }
.pos-cls { grid-column: 1 / span 2; display: flex; align-items: center; gap: 2mm; }
.pos-cls .desc { font-size: 7.5pt; color: var(--muted); white-space: nowrap; }
.pos-cls .meter { flex: 1; }
.pos-main { display: flex; flex-direction: column; gap: 1mm; min-width: 0; }
.badge { display: inline-block; padding: 0.3mm 2mm; border-radius: 5mm; font-weight: 700; font-size: 8pt; white-space: nowrap; }
.badge-na { background: #eee; }
.meter { display: grid; grid-template-columns: repeat(6, 1fr); gap: 0.5mm; }
.meter span { height: 1.8mm; border-radius: 0.5mm; background: #edf1f6; }
.none-box { border-radius: 3mm; background: #eaf7ef; padding: 5mm; text-align: center; }
.none-box .big { font-family: 'Prompt', sans-serif; color: #2d7a4b; font-size: 12pt; }
.note-box { border-radius: 2.5mm; background: var(--sky); padding: 2.5mm 3mm; font-size: 9pt; margin-top: 2.5mm; }
.note-box.warn { background: #fff4e5; }
.note-box .en { color: var(--muted); margin-top: 1mm; font-size: 8.5pt; }

/* ---------- full results ---------- */
.grp-title { font-family: 'Prompt', sans-serif; font-size: 11pt; color: #fff; background: var(--navy); border-radius: 2mm; padding: 0.8mm 2.5mm; margin: 1.5mm 0; }
.grp-title i { color: #c9daf1; font-size: 8.5pt; }
.grp-title em { float: right; font-style: normal; font-size: 8.5pt; background: #fff; color: #c8303c; border-radius: 3mm; padding: 0 2mm; margin-top: 0.6mm; }
.cat-legend { display: flex; flex-wrap: wrap; gap: 0.6mm 3mm; font-size: 7.5pt; color: var(--muted); margin: 0 0 1.5mm; }
.card-img { position: relative; }
.cat-ic { position: absolute; left: 0.8mm; top: 0.8mm; font-size: 7pt; line-height: 1; background: rgba(255, 255, 255, 0.85); border-radius: 1mm; padding: 0.4mm; }
.cat-title { display: flex; gap: 2mm; align-items: baseline; flex-wrap: wrap; font-weight: 600; font-size: 10.5pt; color: var(--navy); border-bottom: 0.3mm solid var(--line); margin: 1.5mm 0; padding-bottom: 0.4mm; }
.cat-title i { font-weight: 400; font-size: 8pt; }
.cat-title em { margin-left: auto; font-style: normal; font-size: 8pt; color: #c8303c; }
.card-row { display: grid; grid-template-columns: repeat(var(--per-row, 3), 1fr); gap: 1.8mm; margin-bottom: 1.8mm; }
.card { border: 0.3mm solid var(--line); border-radius: 2mm; padding: 1.2mm; display: flex; flex-direction: column; gap: 0.4mm; min-width: 0; }
.card .nm-th { font-size: var(--res-name); font-weight: 600; line-height: 1.15; margin-top: 0.6mm;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .nm-en { font-size: var(--res-en); color: var(--muted); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .vl { display: flex; justify-content: space-between; align-items: center; margin-top: auto; padding-top: 0.6mm; font-size: var(--res-val); }
.card .cl { min-width: 5mm; text-align: center; border-radius: 1mm; background: #edf1f6; color: var(--muted); font-weight: 700; font-size: calc(var(--res-val) - 1pt); }
.card.pos { border: 0.5mm solid var(--c); background: color-mix(in srgb, var(--c) 12%, #fff); }
.card.pos .cl { background: var(--c); color: var(--ink); }
.card.pos .vl b { color: var(--navy); }
.mix-note { font-size: 7pt; color: var(--muted); margin-top: 1.5mm; line-height: 1.3; }

/* ---------- advice ---------- */
.adv-top { border-top: 0.4mm solid var(--line); padding-top: 2mm; margin-top: 1mm; }
.adv-top:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
.adv-head { display: flex; gap: 2.5mm; align-items: center; }
.adv-head .ic { font-size: 14pt; }
.adv-head .th { font-family: 'Prompt', sans-serif; font-size: 11pt; color: var(--navy); font-weight: 500; line-height: 1.2; }
.adv-head .en { color: var(--blue); font-size: 8.5pt; }
.chips { display: flex; flex-wrap: wrap; gap: 1mm; margin: 1.2mm 0 1.5mm; }
.chip { border-radius: 4mm; padding: 0.2mm 2mm; font-size: 8.5pt; background: color-mix(in srgb, var(--c) 30%, #fff); border: 0.3mm solid var(--c); }
.chip b { font-size: 7pt; }
ul.adv-th, ul.adv-en { margin: 0 0 1.5mm; padding-left: 4mm; line-height: 1.3; }
ul.adv-th { font-size: var(--adv-fs); }
ul.adv-en { font-size: var(--adv-en-fs); color: var(--muted); margin-bottom: 2.5mm; }
ul.adv-th li, ul.adv-en li { margin-bottom: 0.4mm; }

/* ---------- interpretation ---------- */
.interp { width: 100%; border-collapse: collapse; font-size: 9pt; margin-bottom: 3mm; }
.interp th { background: var(--navy); color: #fff; text-align: left; padding: 1mm 2mm; font-weight: 500; }
.interp td { padding: 0.8mm 2mm; border-bottom: 0.3mm solid var(--line); }
.explain p { margin: 0 0 2mm; font-size: 8.5pt; line-height: 1.3; }
.explain p i { font-size: 7.8pt; }
.signs { display: grid; grid-template-columns: 1fr 1fr; gap: 6mm; margin-top: 6mm; text-align: center; }
.sign .line { border-bottom: 0.3mm dotted var(--ink); height: 9mm; margin: 0 4mm; }
.sign .nm { margin-top: 1mm; font-weight: 600; font-size: 9pt; }
.sign .tt { font-size: 7.5pt; color: var(--muted); line-height: 1.25; }
.issued { margin-top: 4mm; text-align: center; font-size: 7.5pt; color: var(--muted); }
.issued .draft { color: #c8303c; }

.orig { display: flex; justify-content: center; }
.orig img { max-width: 100%; max-height: 160mm; border: 0.3mm solid var(--line); }

@media print {
  @page { size: A5; margin: 0; }
  .book .page { box-shadow: none !important; margin: 0 !important; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
