/* ============================================================================
 *  📜 หน้าเอกสารทางกฎหมาย — นโยบายความเป็นส่วนตัว ฯลฯ
 * ----------------------------------------------------------------------------
 *  ใช้คู่กับ landing.css เสมอ (โหลด landing.css ก่อน แล้วค่อยไฟล์นี้)
 *  ตัวแปรสี · ฟอนต์ · .wrap · .btn · .site-header · .site-footer มาจากไฟล์นั้น
 *  ไฟล์นี้เพิ่มเฉพาะของที่หน้าเอกสารต้องใช้ ทุกคลาสขึ้นต้นด้วย lg- เพื่อไม่ให้
 *  มีทางชนกับคลาสของหน้า landing ได้เลย
 *
 *  ⚠️ หน้าเอกสารตั้งใจให้ไม่มี JavaScript แม้แต่บรรทัดเดียว
 *     · สารบัญใช้ลิงก์ #anchor ธรรมดา
 *     · หัวเว็บใส่คลาส is-stuck ไว้ตายตัว (หน้า landing ใช้สคริปต์สลับ เราไม่ต้อง)
 *     ⇒ CSP ของหน้านั้นจึงปิดสคริปต์ได้สนิท ห้ามเพิ่มสคริปต์เข้ามาโดยไม่แก้ CSP
 * ========================================================================== */

/* --------------------------------------------------------------- หัวเอกสาร */
.lg-hero {
  padding-block: clamp(44px, 6vw, 76px) clamp(28px, 3.5vw, 44px);
  border-bottom: 1px solid var(--line);
}
.lg-hero .h1 { margin-bottom: 1rem; font-size: clamp(1.9rem, 3.8vw, 3rem); }
.lg-hero .lead { max-width: 64ch; }

/*  แถบวันที่มีผล / ฉบับที่ — ให้ดูเป็นเอกสารที่มีการควบคุมเวอร์ชันจริง */
.lg-meta {
  display: flex; flex-wrap: wrap; gap: .55rem;
  margin-top: 1.6rem;
}
.lg-meta span {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .42rem .85rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel);
  font-size: .781rem; font-weight: 700; color: var(--ink-soft);
}
.lg-meta b { color: var(--gold-dark); font-weight: 800; }

/* ------------------------------------------------------------- โครงสองคอลัมน์ */
.lg-layout {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  gap: clamp(32px, 4vw, 64px);
  align-items: start;
  padding-block: clamp(40px, 5vw, 68px);
}

/* ----------------------------------------------------------------- สารบัญ */
.lg-toc {
  position: sticky; top: 98px;
  border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--panel);
  padding: 1.15rem 1.15rem 1.25rem;
  box-shadow: 0 24px 48px -40px rgba(94,71,32,.5);

  /*  ⚠️ สารบัญมี 14 หัวข้อ ซึ่งสูงกว่าจอโน้ตบุ๊กทั่วไป (ราว 740px เทียบกับจอ 768px)
   *  ถ้าไม่จำกัดความสูง หัวข้อท้ายๆ จะถูกตัดหายไปใต้ขอบจอ และเลื่อนไปดูไม่ได้เลย
   *  เพราะตัวมันเองติดหนึบอยู่กับที่ ⇒ ให้เลื่อนในกล่องตัวเองได้
   *  118px = ระยะ top 98px + เผื่อขอบล่าง 20px */
  max-height: calc(100vh - 118px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.lg-toc-h {
  font-size: .688rem; font-weight: 800; letter-spacing: .16em;
  text-transform: uppercase; color: var(--gold-dark);
  padding-bottom: .7rem; margin-bottom: .55rem;
  border-bottom: 1px solid var(--line);
}
.lg-toc ol { list-style: none; counter-reset: toc; display: grid; gap: .1rem; }
.lg-toc li { counter-increment: toc; }
.lg-toc a {
  display: grid; grid-template-columns: 1.55rem minmax(0, 1fr); align-items: baseline;
  gap: .2rem;
  padding: .4rem .5rem; border-radius: .5rem;
  font-size: .813rem; font-weight: 600; color: var(--ink-soft);
  line-height: 1.45;
  transition: background .18s ease, color .18s ease;
}
.lg-toc a::before {
  content: counter(toc, decimal-leading-zero);
  font-family: 'Inter', 'IBM Plex Sans Thai', sans-serif;
  font-variant-numeric: tabular-nums;
  font-size: .688rem; font-weight: 800; color: var(--muted);
}
.lg-toc a:hover { background: var(--gold-soft); color: var(--gold-dark); }
.lg-toc a:hover::before { color: var(--gold); }

/* ------------------------------------------------------------- เนื้อเอกสาร */
.lg-doc { min-width: 0; }

.lg-sec { padding-bottom: clamp(30px, 3.4vw, 46px); }
.lg-sec + .lg-sec { border-top: 1px solid var(--line); padding-top: clamp(30px, 3.4vw, 46px); }

/*  หัวข้อมีเลขกำกับเอง — ไม่ต้องพิมพ์เลขใน HTML จึงแทรก/สลับข้อได้โดยเลขไม่เพี้ยน
 *  ตัวนับตั้งต้นที่ .lg-doc (ดูกฎ counter-reset ข้างล่าง) */
.lg-h2 {
  display: grid; grid-template-columns: auto minmax(0, 1fr);
  align-items: baseline; gap: .7rem;
  font-size: clamp(1.15rem, 1.9vw, 1.45rem);
  letter-spacing: -.02em; font-weight: 800; color: var(--ink);
  margin-bottom: 1.1rem;
  scroll-margin-top: 96px;
}
.lg-doc { counter-reset: sec; }
.lg-sec { counter-increment: sec; }
.lg-h2::before {
  content: counter(sec, decimal-leading-zero);
  font-family: 'Inter', 'IBM Plex Sans Thai', sans-serif;
  font-variant-numeric: tabular-nums;
  font-size: .813rem; font-weight: 800; color: var(--gold);
  padding: .3rem .55rem; border-radius: .45rem;
  background: var(--gold-soft);
  align-self: center;
}

.lg-h3 {
  font-size: .938rem; font-weight: 800; color: var(--ink);
  letter-spacing: -.01em;
  margin: 1.6rem 0 .65rem;
}
.lg-sec p { margin-bottom: .9rem; line-height: 1.85; }
.lg-sec p:last-child { margin-bottom: 0; }

.lg-ul { display: grid; gap: .5rem; margin: 0 0 .9rem; list-style: none; }
.lg-ul li { position: relative; padding-left: 1.3rem; line-height: 1.8; }
.lg-ul li::before {
  content: ''; position: absolute; left: .3rem; top: .72em;
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--gold); opacity: .7;
}
.lg-ul li:last-child { margin-bottom: 0; }

/*  รายการที่มี "หัวเรื่องตัวหนา + คำอธิบาย" ในบรรทัดเดียวกัน */
.lg-ul b { color: var(--ink); font-weight: 700; }

.lg-sec a:not(.btn) {
  color: var(--gold-dark); font-weight: 600;
  text-decoration: underline; text-underline-offset: 3px;
  text-decoration-color: var(--gold-light);
}
.lg-sec a:not(.btn):hover { text-decoration-color: var(--gold-dark); }

/* -------------------------------------------------------------- ตารางข้อมูล */
.lg-table {
  width: 100%; border-collapse: collapse;
  margin: 0 0 1rem;
  border: 1px solid var(--line); border-radius: var(--r-md);
  overflow: hidden;
  font-size: .875rem;
}
.lg-table thead th {
  background: var(--head);
  padding: .7rem .9rem;
  text-align: left; vertical-align: bottom;
  font-size: .688rem; font-weight: 800; letter-spacing: .08em;
  text-transform: uppercase; color: var(--gold-dark);
  border-bottom: 1px solid var(--line);
}
.lg-table td {
  padding: .78rem .9rem;
  vertical-align: top; line-height: 1.7;
  border-bottom: 1px solid var(--line);
  color: var(--ink-soft);
}
.lg-table tbody tr:last-child td { border-bottom: 0; }
.lg-table tbody tr:nth-child(even) td { background: rgba(245,234,210,.22); }
.lg-table td b, .lg-table td strong { color: var(--ink); font-weight: 700; }

/*  คอลัมน์แรกของตารางส่วนใหญ่คือ "หัวข้อ" — ให้เด่นกว่าคำอธิบาย */
.lg-table td:first-child { color: var(--ink); font-weight: 600; }

/*  ช่องอ้างอิงมาตรา — ตัวเลขอ่านง่าย ไม่ตัดบรรทัดกลางคำ */
.lg-law {
  display: inline-block;
  font-family: 'Inter', 'IBM Plex Sans Thai', sans-serif;
  font-variant-numeric: tabular-nums;
  font-size: .75rem; font-weight: 700; color: var(--gold-dark);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- กล่องเน้น */
.lg-note {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .85rem;
  padding: 1rem 1.15rem;
  border: 1px solid var(--line); border-left: 3px solid var(--gold);
  border-radius: var(--r-sm);
  background: var(--panel);
  margin: 1.1rem 0;
}
.lg-note svg { color: var(--gold); flex: none; margin-top: .15rem; }
.lg-note p { margin: 0; font-size: .875rem; line-height: 1.75; }
.lg-note p + p { margin-top: .5rem; }
.lg-note.is-key { background: var(--gold-soft); border-left-color: var(--gold-dark); }
.lg-note.is-key svg { color: var(--gold-dark); }

/* --------------------------------------------------- รายการติดต่อ (ชื่อ→ค่า) */
.lg-kv {
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--panel);
  overflow: hidden;
  margin-bottom: 1rem;
}
.lg-kv > div {
  display: grid; grid-template-columns: 190px minmax(0, 1fr);
  gap: .5rem 1.2rem;
  padding: .8rem 1.1rem;
  border-bottom: 1px solid var(--line);
}
.lg-kv > div:last-child { border-bottom: 0; }
.lg-kv dt {
  font-size: .781rem; font-weight: 700; color: var(--muted);
  line-height: 1.7;
}
.lg-kv dd { margin: 0; color: var(--ink); line-height: 1.7; font-weight: 600; }

/* ----------------------------------------------- ช่องที่ยังไม่ได้กรอกข้อมูลจริง
 *  ข้อความในนี้มีคำว่า TODO-LEGAL ซึ่ง tools/deploy-hosting.js ตรวจอยู่
 *  ⇒ ตราบใดที่ยังเหลือแม้แต่ช่องเดียว จะ deploy ขึ้นเว็บจริงไม่ได้เลย
 *  กรอกครบแล้วให้ลบทั้งแท็ก <span class="lg-todo">…</span> ทิ้งไปเลย */
.lg-todo {
  display: inline-block;
  padding: .12rem .5rem; border-radius: .35rem;
  background: #FBE9E7; border: 1px dashed #C4453A;
  color: #8E2B22; font-size: .813rem; font-weight: 700;
}

/* ------------------------------------------------------------ ท้ายเอกสาร */
.lg-end {
  margin-top: clamp(30px, 3.4vw, 46px);
  padding-top: clamp(24px, 3vw, 36px);
  border-top: 1px solid var(--line);
  display: flex; flex-wrap: wrap; gap: 1rem;
  align-items: center; justify-content: space-between;
}
.lg-end p { margin: 0; font-size: .813rem; color: var(--muted); }

/* ================================================================== มือถือ */
@media (max-width: 960px) {
  .lg-layout { grid-template-columns: 1fr; gap: 28px; }

  /*  สารบัญเลิกติดหนึบ ไปนั่งเป็นกล่องธรรมดาบนสุดของเอกสารแทน
   *  ⚠️ ต้องปลด max-height/overflow ที่ตั้งไว้ตอนติดหนึบด้วย ไม่งั้นบนมือถือ
   *     จะกลายเป็นกล่องเตี้ยๆ ที่ต้องเลื่อนในตัวเอง แล้วหัวข้อท้ายๆ หายไปเฉยๆ */
  .lg-toc { position: static; max-height: none; overflow: visible; }
  .lg-toc ol { grid-template-columns: repeat(2, minmax(0, 1fr)); display: grid; }
}

@media (max-width: 680px) {
  .lg-toc ol { grid-template-columns: 1fr; }
  .lg-kv > div { grid-template-columns: 1fr; gap: .2rem; }

  /*  ตารางกลายเป็นการ์ดเรียงลง — ใช้ข้อความจาก data-label ของแต่ละช่อง
   *  ⚠️ ทุก <td> ในหน้านี้ต้องมี data-label เสมอ ไม่งั้นบนมือถือจะอ่านไม่รู้เรื่อง */
  .lg-table { border: 0; font-size: .875rem; }
  .lg-table thead {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
  }
  .lg-table, .lg-table tbody, .lg-table tr, .lg-table td { display: block; width: 100%; }
  .lg-table tr {
    border: 1px solid var(--line); border-radius: var(--r-sm);
    background: var(--panel);
    margin-bottom: .7rem; overflow: hidden;
  }
  .lg-table tbody tr:nth-child(even) td { background: transparent; }
  .lg-table td {
    padding: .7rem .9rem;
    border-bottom: 1px solid var(--line);
  }
  .lg-table td:last-child { border-bottom: 0; }
  .lg-table td::before {
    content: attr(data-label);
    display: block;
    font-size: .688rem; font-weight: 800; letter-spacing: .07em;
    text-transform: uppercase; color: var(--gold-dark);
    margin-bottom: .22rem;
  }
}

/* ================================================================ สั่งพิมพ์
 *  เอกสารแบบนี้ถูกสั่งพิมพ์เก็บเป็นหลักฐานบ่อย — ให้ออกมาเป็นกระดาษที่อ่านได้จริง */
@media print {
  .site-header, .site-footer, .lg-toc, .lg-end { display: none !important; }
  body { background: #fff !important; color: #000; }
  .lg-layout { display: block; padding-block: 0; }
  .lg-hero { border-bottom: 1px solid #ccc; padding-block: 0 18px; }
  .lg-sec { page-break-inside: avoid; }
  .lg-h2 { page-break-after: avoid; }
  .lg-table { font-size: .75rem; }
  .lg-note { page-break-inside: avoid; }
  a[href^="http"]::after { content: ' (' attr(href) ')'; font-size: .7rem; color: #555; }
}
