/* งานวิจัย · bia.or.th/research — ใช้ร่วมกันทุกบทความ
   สีแบรนด์ตรงกับ sso/public/css/bia-shared.css (ไม่ได้เรียกไฟล์นั้นตรง ๆ เพื่อให้หน้านี้ไม่ผูกกับ SSO) */
:root {
  --bia-red: #7d1925;
  --bia-red-soft: #f6eaeb;
  --bia-gold: #c9a227;
  --ink: #1f1f1f;
  --muted: #5f5f5f;
  --line: #ddd6cf;
  --paper: #fffdf9;
  --panel: #f7f3ee;
  --todo: #fff3b0;
  --measure: 46rem;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 1rem; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Sarabun", "Leelawadee UI", "Tahoma", sans-serif;
  font-size: 1.125rem;
  line-height: 1.85;
  overflow-wrap: break-word;
}
.wrap { max-width: var(--measure); margin: 0 auto; padding: 0 16px; }
a { color: var(--bia-red); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
/* คำอ้างถึงข้อ/บท/ตาราง/รูปในบทความ: ขีดเส้นประ แยกจากลิงก์ออกนอกหน้า · กดแล้วกระโดดไปทันที (ไม่เลื่อนนุ่ม เพราะบทความยาว ไฮไลต์จะจางก่อนถึง) และไฮไลต์ปลายทางชั่วครู่ · ปุ่มย้อนกลับของเบราว์เซอร์พากลับจุดเดิม */
main a[href^="#"] { text-decoration-style: dotted; }
:target { animation: target-flash 2.4s ease-out; border-radius: 4px; }
@keyframes target-flash { 0%, 35% { background: #f6e7b4; } 100% { background: transparent; } }

/* แถบร่าง */
.draft-banner {
  background: var(--bia-red); color: #fff; text-align: center;
  font-weight: 600; font-size: .95rem; line-height: 1.5; padding: .55rem 16px;
}

/* หัว/ท้ายเว็บ */
.site-header { border-bottom: 3px solid var(--bia-gold); background: #fff; }
.site-header .wrap { display: flex; flex-wrap: wrap; gap: .25rem 1rem; align-items: baseline; justify-content: space-between; padding-top: .7rem; padding-bottom: .7rem; }
.brand { font-weight: 700; color: var(--bia-red); text-decoration: none; font-size: 1.05rem; }
.crumb { color: var(--muted); font-size: .95rem; }
.site-footer { margin-top: 4rem; border-top: 1px solid var(--line); background: var(--panel); color: var(--muted); font-size: .9rem; line-height: 1.6; }
.site-footer .wrap { padding-top: 1.25rem; padding-bottom: 2rem; }
.site-footer p { margin: .25rem 0; overflow-wrap: anywhere; }

/* หัวบทความ */
.article-header { padding-top: 2rem; }
.kind { margin: 0; color: var(--bia-red); font-weight: 600; font-size: .95rem; letter-spacing: .02em; }
h1 { font-size: 1.75rem; line-height: 1.45; margin: .4rem 0 .6rem; color: #111; }
.subtitle { margin: 0 0 .75rem; color: var(--muted); font-style: italic; line-height: 1.6; }
.author { margin: 0 0 1rem; }
.meta { display: flex; flex-wrap: wrap; gap: .25rem 1.5rem; margin: 0 0 1.25rem; padding: .7rem 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); font-size: .95rem; line-height: 1.6; }
.meta div { display: flex; gap: .4rem; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; font-weight: 600; }
.draft-note, .article-note { background: var(--panel); border-left: 4px solid var(--bia-gold); padding: .6rem 1rem; font-size: .95rem; line-height: 1.7; }
.draft-note p, .article-note p { margin: 0; }

/* สารบัญ */
.toc { margin: 1.5rem 0 1rem; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.toc summary { cursor: pointer; padding: .55rem 1rem; font-weight: 700; }
.toc ol { list-style: none; margin: 0; padding: 0 1rem .75rem; columns: 2 18rem; column-gap: 2rem; font-size: .95rem; line-height: 1.6; }
.toc li { break-inside: avoid; padding: .15rem 0; }
.toc a { text-decoration: none; }
.toc a:hover { text-decoration: underline; }

/* เนื้อความ */
article h2 { font-size: 1.4rem; line-height: 1.5; margin: 2.5rem 0 .75rem; color: var(--bia-red); }
article h3 { font-size: 1.15rem; line-height: 1.5; margin: 1.75rem 0 .5rem; }
article p { margin: 0 0 1rem; }
article ul, article ol { padding-left: 1.5rem; margin: 0 0 1rem; }
article li { margin-bottom: .3rem; }
hr { border: 0; border-top: 1px solid var(--line); margin: 2.5rem 0 0; }
code { font-family: "Consolas", "Menlo", monospace; font-size: .88em; background: var(--panel); padding: .05em .3em; border-radius: 3px; overflow-wrap: anywhere; }

/* ตาราง — เลื่อนซ้ายขวาในกรอบของตัวเอง ไม่ดันหน้า */
.table-caption { margin: 1.5rem 0 .4rem; font-size: 1rem; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 0 1.25rem; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
table { border-collapse: collapse; width: 100%; font-size: .95rem; line-height: 1.6; }
th, td { padding: .5rem .7rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; min-width: 7rem; }
th { background: var(--panel); font-weight: 700; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; min-width: 0; }
td code { overflow-wrap: normal; white-space: nowrap; }

/* รูป */
figure { margin: 1.5rem 0; }
figure img { display: block; max-width: 100%; height: auto; margin: 0 auto; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
figcaption { margin-top: .6rem; font-size: .95rem; line-height: 1.7; color: #333; }
figure > a { display: block; cursor: zoom-in; }

/* popup ภาพขยาย (research.js) */
.lightbox { border: 0; padding: 0; margin: auto; max-width: 96vw; max-height: 96vh; width: auto; background: #fff; border-radius: 8px; overflow: auto; }
.lightbox::backdrop { background: rgba(20, 12, 12, .82); }
.lightbox img { display: block; max-width: 96vw; max-height: calc(96vh - 5rem); width: auto; height: auto; margin: 0 auto; }
.lightbox-caption { margin: 0; padding: .6rem 3.25rem .8rem 1rem; font-size: .9rem; line-height: 1.6; color: #333; max-width: 60rem; }
.lightbox-caption:empty { display: none; }
.lightbox-close { position: absolute; top: .4rem; right: .4rem; width: 2.5rem; height: 2.5rem; border: 0; border-radius: 50%; background: var(--bia-red); color: #fff; font-size: 1.6rem; line-height: 1; cursor: pointer; }
.lightbox-close:hover, .lightbox-close:focus-visible { background: #5c121b; outline: 2px solid var(--bia-gold); }
body.lightbox-open { overflow: hidden; }
/* ปุ่มลูกศรกลับไปสารบัญ (research.js สร้างให้ · โผล่เมื่อเลื่อนพ้นสารบัญแล้ว) */
.to-toc { position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); z-index: 50;
  display: flex; align-items: center; gap: .3rem; padding: .5rem .85rem; border-radius: 999px; background: var(--bia-red); color: #fff;
  font-size: .95rem; font-weight: 600; line-height: 1.2; text-decoration: none; box-shadow: 0 2px 8px rgba(0,0,0,.25);
  opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity .2s, transform .2s; }
.to-toc.show { opacity: 1; transform: none; pointer-events: auto; }
.to-toc:hover, .to-toc:focus-visible { background: #5c121b; color: #fff; outline: 2px solid var(--bia-gold); outline-offset: 2px; }
.to-toc .arrow { font-size: 1.15rem; }
@media (max-width: 480px) { .to-toc .label { display: none; } .to-toc { padding: .6rem .8rem; } }

/* โค้ด Turtle */
pre { overflow-x: auto; background: #f4f1ec; border: 1px solid var(--line); border-radius: 6px; padding: .9rem 1rem; font-size: .85rem; line-height: 1.55; margin: 0 0 1.25rem; }
pre code { background: none; padding: 0; overflow-wrap: normal; font-size: inherit; }

/* เอกสารอ้างอิง — ย่อหน้าแขวน */
.references p { padding-left: 2rem; text-indent: -2rem; overflow-wrap: anywhere; }

/* ช่องที่ผู้เขียนยังต้องกรอก/ตรวจ */
.todo { background: var(--todo); padding: 0 .2em; border-radius: 3px; }
.todo-block { border: 1px dashed #c9a227; background: #fffbe0; padding: .5rem .8rem; border-radius: 6px; }

/* ท้ายบทความ */
.cite-box, .versions { margin-top: 2.5rem; padding: 1rem 1.25rem; background: var(--panel); border-radius: 6px; }
.cite-box h2, .versions h2 { font-size: 1.1rem; margin: 0 0 .5rem; color: var(--ink); }
.cite-box p { margin: 0 0 .75rem; font-size: 1rem; overflow-wrap: anywhere; }
.versions ul { margin: 0; padding-left: 1.2rem; font-size: 1rem; }
button.copy { font: inherit; font-size: .9rem; padding: .3rem .9rem; border: 1px solid var(--bia-red); color: var(--bia-red); background: #fff; border-radius: 4px; cursor: pointer; }
button.copy:hover { background: var(--bia-red-soft); }

/* หน้าดัชนีงานวิจัย */
.index-list { list-style: none; padding: 0; margin: 1.5rem 0; }
.index-list li { padding: 1.1rem 0; border-bottom: 1px solid var(--line); }
.index-list .t { font-size: 1.2rem; font-weight: 700; line-height: 1.5; }
.index-list .m { color: var(--muted); font-size: .95rem; line-height: 1.6; margin-top: .3rem; }
.badge { display: inline-block; font-size: .8rem; font-weight: 600; padding: 0 .5em; border-radius: 3px; background: var(--bia-red); color: #fff; vertical-align: middle; }

@media (max-width: 600px) {
  body { font-size: 1.0625rem; }
  h1 { font-size: 1.45rem; }
  article h2 { font-size: 1.25rem; }
  .references p { padding-left: 1.25rem; text-indent: -1.25rem; }
}

/* พิมพ์ / PDF */
@page { size: A4; margin: 18mm 17mm 20mm; }
@media print {
  body { background: #fff; font-size: 11pt; line-height: 1.7; }
  .no-print, .site-header, .toc, .to-toc, button.copy, .lightbox { display: none !important; }
  .wrap { max-width: none; padding: 0; }
  .draft-banner { background: none; color: var(--bia-red); border: 2px solid var(--bia-red); margin-bottom: 6mm; }
  a { color: inherit; text-decoration: none; }
  .references a, .site-footer a, article p a, article li a { color: var(--bia-red); }
  .table-wrap { overflow: visible; border: 0; }
  table { font-size: 9.5pt; }
  th, td { min-width: 0; }
  td code { white-space: normal; overflow-wrap: anywhere; }
  pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 8pt; }
  h2, h3, .table-caption { break-after: avoid; }
  figure, tr, .cite-box { break-inside: avoid; }
  .site-footer { margin-top: 8mm; background: none; }
  .todo, .todo-block { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
