/* ----------------------------------------------------------------
 * TOR stylesheet — เลียนแบบเอกสาร Microsoft Word บนกระดาษ A4
 * ฟอนต์ที่ใช้: TH Sarabun New (ระบบ Thai gov ที่ติดตั้งทั่วไป)
 *   fallback: TH SarabunPSK → Sarabun (ถ้ามี) → ฟอนต์ Thai serif ของระบบ
 * ทั้งหมด offline — ไม่มีการโหลดทรัพยากรจากภายนอก
 * ---------------------------------------------------------------- */

* { box-sizing: border-box; }

html { font-size: 16pt; }

body {
  margin: 0;
  padding: 1cm 0;
  font-family: 'TH Sarabun New', 'TH SarabunPSK', 'Sarabun',
               'Noto Sans Thai', 'Leelawadee UI', 'Tahoma', serif;
  font-size: 1rem;
  line-height: 1.35;
  color: #000;
  background: #525659; /* คล้าย PDF viewer */
  min-height: 100vh;
}

.page-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1cm;
}

/* ---------- หน้ากระดาษ A4 (210mm x 297mm) ขนาดจริง ---------- */

article {
  width: 21cm;            /* A4 width */
  min-height: 29.7cm;     /* A4 height */
  padding: 2.54cm 2.54cm; /* Word default 1 inch margins */
  background: white;
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.4);
}

/* ---------- Header (หัวเอกสารหลัก เฉพาะ header ที่เป็นลูกตรงของ article) ---------- */

article > header {
  text-align: center;
  font-weight: bold;
  margin-bottom: 1.4em;
}

article > header h1 {
  font-size: 1em;
  margin: 0;
  font-weight: bold;
}

article > header .en-title {
  margin: 0.05em 0 0;
  font-weight: bold;
}

article > header .subject {
  margin: 0.35em 0 0;
  font-weight: bold;
  line-height: 1.4;
}

/* ---------- Items ---------- */

article > section { margin-bottom: 0.4em; }

.item {
  display: flex;
  gap: 0.15em;
  margin-bottom: 0.1em;
  align-items: baseline;
}

.item .num {
  flex: 0 0 auto;
  font-weight: normal;
  white-space: nowrap;
}

.item .text {
  flex: 1;
  min-width: 0;
}

.item .text .heading {
  font-weight: bold;
}

.item .text > p {
  margin: 0;
  text-indent: 1.5em;
}

.item .text > p + p {
  margin-top: 0;
}

.item .text > p.no-indent {
  text-indent: 0;
}

/* ---------- ระดับ indent (เลียนแบบ tab ของ Word) ---------- */

.lvl-1 {
  padding-left: 0;
  margin-top: 0.9em;
}
.lvl-1 .num {
  min-width: 1.3em; /* "14." */
  font-weight: bold; /* เฉพาะเลขข้อระดับบนสุดเท่านั้นที่เป็นตัวหนา */
}

.lvl-2 {
  padding-left: 1.5em;
}
.lvl-2 .num { min-width: 1.7em; } /* "4.1.", "10.5" */

.lvl-3 {
  padding-left: 3.5em;
}
.lvl-3 .num { min-width: 2.3em; } /* "4.1.10.", "12.3.3" */

.lvl-4 {
  padding-left: 5.8em;
}
.lvl-4 .num { min-width: 2.9em; } /* "4.1.13.1.", "11.2.10.3" */

/* ---------- Sub list (พารามิเตอร์สี ฯลฯ) ใช้ขีดนำหน้า ---------- */

.sub-list {
  margin: 0.2em 0;
  padding-left: 0.5em;
  list-style: none;
}

.sub-list li {
  margin: 0.02em 0;
}

.sub-list li::before {
  content: '- ';
}

/* ---------- รายการ 2 คอลัมน์ (เรียงลงในแนวตั้งก่อน แล้วค่อยข้าม) ---------- */

.twocol-list {
  margin: 0.25em 0 0.15em;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(5, auto);
  grid-auto-flow: column;
  column-gap: 1em;
  row-gap: 0.05em;
}

.twocol-list li {
  margin: 0;
}

.twocol-list li::before {
  content: '- ';
}

/* ---------- Note (** prefix ต่อท้ายรายการ) ---------- */

.note {
  margin: 0.25em 0 0;
  text-indent: 0;
}

/* ---------- เอกสารแนบท้าย ---------- */

.annex {
  margin-top: 0;
  padding-top: 0;
}

.annex > header {
  margin-bottom: 0.9em;
}

.annex-tag {
  text-align: right;
  font-weight: bold;
  margin: 0 0 0.4em;
}

.annex h2 {
  font-size: 1em;
  text-align: center;
  margin: 0;
  font-weight: bold;
}

/* ---------- เส้นลายเซ็น ---------- */

.signature-line {
  text-align: center;
  margin: 0.7em 0 0;
  letter-spacing: 0.15em;
}

/* ---------- โหมดพิมพ์ (เอกสาร TOR หลัก, A4 portrait) ---------- */

@media print {
  @page {
    size: A4;
    margin: 0;
  }
  body {
    padding: 0;
    background: white;
    min-height: 0;
  }
  .page-stack {
    gap: 0;
    display: block;
  }
  article {
    width: 100%;
    min-height: 0;
    box-shadow: none;
    padding: 2.54cm;
  }
  article + article {
    page-break-before: always;
    break-before: page;
  }
  .item { page-break-inside: avoid; }
  .lvl-1 { page-break-after: avoid; }
}

/* ================================================================
 * TOR_CHECKLIST — ตารางตรวจสอบความครอบคลุมของโค้ดต่อ TOR (A4 landscape)
 * ================================================================ */

article.landscape {
  width: 29.7cm;
  min-height: 21cm;
  padding: 1.6cm 1.6cm;
}

article > header.checklist-header {
  text-align: center;
  margin-bottom: 0.9em;
}
article > header.checklist-header h1 {
  font-size: 1em;
  margin: 0;
  font-weight: bold;
}
article > header.checklist-header .subject {
  margin: 0.25em 0 0;
  font-weight: normal;
  font-size: 0.9em;
}
article > header.checklist-header .audit-meta {
  margin: 0.35em 0 0;
  font-size: 0.85em;
  font-weight: normal;
}
article > header.checklist-header .legend {
  margin: 0.55em 0 0;
  font-size: 0.85em;
  font-weight: normal;
}

.legend .pill {
  display: inline-block;
  padding: 0 0.4em;
  border-radius: 0.2em;
  margin: 0 0.25em;
  font-weight: bold;
}
.pill.full    { background: #d4edda; color: #155724; }
.pill.partial { background: #fff3cd; color: #856404; }
.pill.missing { background: #f8d7da; color: #721c24; }

/* ---------- ตาราง checklist ---------- */

table.checklist {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.78em;
  line-height: 1.25;
}

table.checklist colgroup col.c-num    { width: 4.2%; }
table.checklist colgroup col.c-req    { width: 33%;  }
table.checklist colgroup col.c-status { width: 7%;   }
table.checklist colgroup col.c-evid   { width: 55.8%; }

table.checklist th,
table.checklist td {
  border: 1px solid #888;
  padding: 0.35em 0.5em;
  vertical-align: top;
  text-align: left;
}
table.checklist thead th {
  background: #e9eaee;
  font-weight: bold;
  text-align: center;
  font-size: 0.95em;
}
table.checklist tr.group td {
  background: #f3f3f0;
  font-weight: bold;
}
table.checklist td.num     { font-weight: bold; white-space: nowrap; text-align: center; }
table.checklist td.status  { text-align: center; white-space: nowrap; font-weight: bold; }

table.checklist td.evid code {
  font-family: 'Menlo', 'Consolas', 'Courier New', monospace;
  font-size: 0.78em;
  background: #f5f5f1;
  padding: 0 0.2em;
  border-radius: 0.15em;
  white-space: nowrap;
}
table.checklist td.evid ul {
  margin: 0.15em 0 0;
  padding-left: 1.1em;
}
table.checklist td.evid li { margin: 0.05em 0; }
table.checklist td .gap {
  display: block;
  margin-top: 0.25em;
  font-style: italic;
  color: #666;
}

td.s-full    { background: #d4edda; color: #155724; }
td.s-partial { background: #fff3cd; color: #856404; }
td.s-missing { background: #f8d7da; color: #721c24; }

.checklist-summary {
  margin: 0.4em 0 0.9em;
  padding: 0.55em 0.8em;
  background: #f7f7f2;
  border-left: 3px solid #444;
  font-size: 0.85em;
  color: #222;
}
.checklist-summary p { margin: 0.2em 0; text-indent: 0; }

@media print {
  /* override @page เป็นแนวนอนเมื่อหน้า checklist ถูกพิมพ์ */
  @page { size: A4 landscape; margin: 0; }
  article.landscape {
    width: 100%;
    min-height: 0;
    box-shadow: none;
    padding: 1.4cm 1.4cm;
  }
  table.checklist tr { page-break-inside: avoid; }
}

/* ---------- ตารางทะเบียนพารามิเตอร์ (เอกสารแนบท้ายนิยาม IPL) ---------- */

table.registry { width:100%; border-collapse:collapse; font-size:0.8em; line-height:1.25; margin:0.3em 0 0.5em; }
table.registry th, table.registry td { border:1px solid #888; padding:0.12em 0.4em; vertical-align:top; text-align:left; }
table.registry thead th { background:#e9eaee; text-align:center; font-weight:bold; }
table.registry td.id { font-family:'Menlo','Consolas','Courier New',monospace; font-size:0.82em; white-space:nowrap; }
table.registry td.c { text-align:center; white-space:nowrap; }
@media print { table.registry tr { page-break-inside: avoid; } }
