/* ============================================================
   ThaiLAW.net — Design System "หอกฎหมาย" (Legal Archive)
   หมึกน้ำเงินเข้ม × ทองราชการ บนพื้นกระดาษอุ่น
   ฟอนต์: Noto Serif Thai (หัวเรื่อง) + Sarabun (ตัวบท/UI)
   ============================================================ */

:root {
  /* พื้นผิว */
  --paper: #faf7f1;
  --surface: #ffffff;
  --surface-2: #f3efe7;
  --line: #e5dfd2;
  --line-strong: #d3cab7;

  /* หมึก */
  --ink: #1c2637;
  --ink-2: #4a5568;
  --ink-3: #8b93a3;

  /* แบรนด์ */
  --navy: #12305e;
  --navy-2: #1d4380;
  --navy-deep: #0b1f3f;
  --gold: #b8892e;
  --gold-2: #d4a94a;
  --gold-soft: #f6edd8;

  /* ความหมาย */
  --amber-bg: #fdf3dd;
  --amber-line: #e6c471;
  --amber-ink: #7a5a10;
  --teal: #0e6e62;
  --teal-soft: #e2f1ee;
  --blue-soft: #e8eef8;
  --red: #a83232;

  /* ลิงก์อ้างอิงในตัวบท — ต้องแยกจากตัวบทปกติได้ด้วยสายตาทันที */
  --link-ink: #0f4fa8;
  --link-bg: #e4ecfa;
  --link-line: #7ba3e0;
  --link-cross-ink: #0a6357;
  --link-cross-bg: #dcefeb;
  --link-cross-line: #63b5a8;

  --font-serif: 'Noto Serif Thai', 'Sarabun', serif;
  --font-sans: 'Sarabun', -apple-system, sans-serif;

  --shadow-sm: 0 1px 3px rgba(18, 33, 61, .07);
  --shadow-md: 0 4px 16px rgba(18, 33, 61, .09);
  --shadow-lg: 0 12px 40px rgba(18, 33, 61, .14);
  --radius: 12px;
  --radius-sm: 8px;

  --header-h: 60px;
}

html[data-theme="dark"] {
  --paper: #10151f;
  --surface: #1a2130;
  --surface-2: #212a3c;
  --line: #2c3547;
  --line-strong: #3b4557;
  --ink: #e8e6e0;
  --ink-2: #b0b6c2;
  --ink-3: #7c8494;
  --navy: #7ea4dd;
  --navy-2: #9dbcec;
  --navy-deep: #0b1f3f;
  --gold: #d4a94a;
  --gold-2: #e2bd66;
  --gold-soft: #2c2717;
  --amber-bg: #2b2312;
  --amber-line: #6b541f;
  --amber-ink: #e2bd66;
  --teal: #5cc0b2;
  --teal-soft: #14302c;
  --blue-soft: #1c2a42;
  --link-ink: #8ec2ff;
  --link-bg: #1b2e4d;
  --link-line: #4d7cbd;
  --link-cross-ink: #6ddcc9;
  --link-cross-bg: #14332e;
  --link-cross-line: #3f9184;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, .35);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

/* ⚠️ ต้องมาก่อนทุกกฎ display ในไฟล์นี้
   แอตทริบิวต์ hidden ของ HTML ถูกกำหนด display:none จาก UA stylesheet
   แต่ CSS ที่เราเขียนเอง (เช่น .peek-overlay { display:flex }) จะชนะ UA เสมอ
   → องค์ประกอบที่สั่ง hidden ไว้จะโผล่ขึ้นมาเอง (เคยทำให้หน้าต่างดูมาตราเด้งทันทีที่เข้าเว็บ)
   บรรทัดนี้บังคับให้ hidden มีผลจริงเสมอ */
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.75;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--navy-2); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--navy); color: #fff; padding: 8px 16px; z-index: 200;
}
.skip-link:focus { left: 8px; top: 8px; }

/* ============================================================
   Header
   ============================================================ */
.site-header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-h);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

/* ⚠️ iPad/มือถือ: backdrop-filter บนแถบ sticky บังคับให้ Safari เบลอพื้นหลังใหม่ "ทุกเฟรม" ที่เลื่อนหน้า
   เป็นสาเหตุอันดับหนึ่งที่ทำให้เลื่อนหน้าไม่ลื่นบน iOS (คุณช่างถึกเจอบน iPad 7 ก.ย. 2569)
   บนอุปกรณ์สัมผัสจึงใช้พื้นทึบแทน — หน้าตาใกล้เคียงเดิมมากแต่ไม่มีต้นทุนเบลอต่อเฟรม
   (เดสก์ท็อปที่มีเมาส์ยังได้เอฟเฟกต์ frosted glass เหมือนเดิม) */
@media (hover: none), (pointer: coarse) {
  .site-header {
    background: var(--surface);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

.header-inner {
  max-width: 1400px; margin: 0 auto; height: 100%;
  display: flex; align-items: center; gap: 20px;
  padding: 0 20px;
}

.site-logo {
  display: flex; align-items: center; gap: 9px;
  color: var(--ink); flex-shrink: 0;
}
.logo-mark { width: 28px; height: 28px; color: var(--gold); }
.logo-text {
  font-family: var(--font-serif); font-weight: 700; font-size: 1.25rem;
  letter-spacing: .01em;
}
.logo-text em { font-style: normal; color: var(--gold); }
.logo-tld { font-size: .85rem; font-weight: 400; color: var(--ink-3); }

/* ค้นหา */
.header-search { position: relative; flex: 1; max-width: 620px; margin: 0 auto; }
.search-box { position: relative; display: flex; align-items: center; }
.search-icon {
  position: absolute; left: 14px; width: 18px; height: 18px;
  color: var(--gold); pointer-events: none;
}
.search-input {
  width: 100%; height: 44px;
  padding: 0 46px 0 42px;
  font-family: var(--font-sans); font-size: .95rem;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--gold);
  border-radius: 10px;
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 12%, transparent), var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s;
}
.search-input:focus {
  border-color: var(--gold-2);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--gold) 22%, transparent), var(--shadow-md);
}
.search-input::placeholder { color: var(--ink-2); }
.search-kbd {
  position: absolute; right: 12px;
  font-family: var(--font-sans); font-size: .72rem;
  color: var(--ink-3);
  border: 1px solid var(--line-strong); border-radius: 5px;
  padding: 0 6px; line-height: 1.5;
  background: var(--surface);
}

.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: min(480px, 70vh); overflow-y: auto;
  display: none;
}
.search-results.visible { display: block; }
.sr-group-label {
  padding: 10px 16px 4px; font-size: .72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3);
}
.sr-item {
  display: block; padding: 10px 16px;
  border-top: 1px solid var(--line);
  cursor: pointer;
}
.sr-item:hover, .sr-item.active { background: var(--surface-2); }
.sr-item-title { font-weight: 600; font-size: .92rem; color: var(--ink); }
.sr-item-title mark, .sr-item-snippet mark {
  background: var(--gold-soft); color: var(--amber-ink);
  border-radius: 3px; padding: 0 2px;
}
.sr-item-snippet { font-size: .82rem; color: var(--ink-2); line-height: 1.55; margin-top: 2px; }
.sr-item-title .sr-item-law {
  display: inline-block; font-size: .68rem; color: var(--gold); font-weight: 700;
  background: var(--gold-soft); border-radius: 5px; padding: 1px 7px; margin-left: 6px;
  vertical-align: middle;
}
.sr-empty { padding: 20px; text-align: center; color: var(--ink-3); font-size: .9rem; }
.sr-loading {
  padding: 20px; display: flex; align-items: center; justify-content: center;
  gap: 10px; color: var(--ink-2); font-size: .9rem;
}
.sr-spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2.5px solid var(--gold-soft);
  border-top-color: var(--gold);
  animation: sr-spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes sr-spin { to { transform: rotate(360deg); } }

/* ปุ่มสลับเลขไทย/อารบิก */
.numerals-toggle {
  height: 38px; min-width: 44px; flex-shrink: 0;
  padding: 0 10px;
  font-family: var(--font-serif); font-size: .92rem; font-weight: 600;
  color: var(--ink-2);
  background: none; border: 1px solid var(--line); border-radius: 9px;
  transition: background .15s, color .15s, border-color .15s;
}
.numerals-toggle:hover { background: var(--surface-2); color: var(--gold); border-color: var(--gold); }

/* ปุ่มธีม */
.theme-toggle {
  width: 38px; height: 38px; flex-shrink: 0;
  display: grid; place-items: center;
  background: none; border: 1px solid var(--line); border-radius: 9px;
  color: var(--ink-2);
  transition: background .15s;
}
.theme-toggle:hover { background: var(--surface-2); }
.theme-toggle svg { width: 18px; height: 18px; }
html:not([data-theme="dark"]) .icon-sun { display: none; }
html[data-theme="dark"] .icon-moon { display: none; }

/* ============================================================
   Hero
   ============================================================ */
.hero {
  background:
    radial-gradient(1100px 420px at 85% -10%, rgba(212, 169, 74, .16), transparent 60%),
    radial-gradient(900px 500px at 10% 110%, rgba(29, 67, 128, .35), transparent 55%),
    linear-gradient(160deg, var(--navy-deep) 0%, #14345f 70%, #1a3f6f 100%);
  color: #eef2f8;
  padding: 64px 20px 56px;
  position: relative;
  overflow: hidden;
}
.hero::after {
  /* ลายเส้นตราชั่งจางๆ */
  content: '';
  position: absolute; right: -40px; bottom: -60px;
  width: 380px; height: 380px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cg stroke='%23d4a94a' stroke-width='.6' fill='none' opacity='.5'%3E%3Cpath d='M16 3v26M8 29h16'/%3E%3Cpath d='M16 6L5 10h22L16 6z'/%3E%3Cpath d='M5 10l-3 8a5 5 0 0 0 10 0l-3-8M27 10l-3 8a5 5 0 0 0 10 0l-3-8'/%3E%3C/g%3E%3C/svg%3E") no-repeat center / contain;
  opacity: .18;
  pointer-events: none;
}
.hero-inner { max-width: 880px; margin: 0 auto; text-align: center; position: relative; }
.hero-eyebrow {
  display: inline-block;
  font-size: .85rem; font-weight: 600; letter-spacing: .04em;
  color: var(--gold-2);
  border: 1px solid rgba(212, 169, 74, .4); border-radius: 99px;
  padding: 3px 16px; margin-bottom: 18px;
  background: rgba(212, 169, 74, .08);
}
.hero h1 {
  font-family: var(--font-serif);
  font-size: clamp(1.7rem, 4.5vw, 2.7rem);
  font-weight: 700; line-height: 1.35;
}
.hero h1 span { color: var(--gold-2); }
.hero-sub {
  max-width: 620px; margin: 16px auto 0;
  font-size: 1.02rem; font-weight: 300; line-height: 1.8;
  color: #c4cedd;
}

.hero-stats {
  display: flex; justify-content: center; gap: 12px;
  margin-top: 34px; flex-wrap: wrap;
}
.stat {
  min-width: 118px;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: var(--radius);
  padding: 12px 20px 10px;
  backdrop-filter: blur(4px);
}
.stat strong {
  display: block;
  font-family: var(--font-serif); font-size: 1.65rem; font-weight: 700;
  color: var(--gold-2); line-height: 1.2;
}
.stat span { font-size: .8rem; color: #b6c2d4; }

/* ============================================================
   Home — ผังกฎหมาย (law tree)
   ============================================================ */
.law-directory { max-width: 980px; margin: 0 auto; padding: 48px 20px 8px; }

@media (min-width: 700px) { .law-directory { max-width: 1360px; } }

.section-heading {
  font-family: var(--font-serif); font-size: 1.4rem; font-weight: 700;
  margin-bottom: 22px;
  display: flex; align-items: baseline; gap: 12px;
}
.heading-note { font-family: var(--font-sans); font-size: .82rem; font-weight: 400; color: var(--ink-3); }

.law-tree-loading { color: var(--ink-3); padding: 30px 0; }

/* ── แถบเครื่องมือหาฉบับ (กรองชื่อ + นับจำนวน) ──
   จำเป็นตั้งแต่คลังโตเกินร้อยฉบับ — เลื่อนหาทีละใบไม่ใช่ทางที่ใช้งานได้อีกต่อไป */
.dir-toolbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.dir-filter {
  position: relative; display: flex; align-items: center;
  flex: 1 1 340px; max-width: 520px;
}
.dir-filter-icon {
  position: absolute; left: 14px; font-size: 1.05rem; color: var(--ink-3); pointer-events: none;
}
.dir-filter-input {
  width: 100%;
  padding: 11px 38px 11px 38px;
  font-family: var(--font-sans); font-size: .93rem; color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line); border-radius: 99px;
  transition: border-color .15s, box-shadow .15s;
}
.dir-filter-input::placeholder { color: var(--ink-3); }
.dir-filter-input:focus {
  outline: none; border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}
.dir-filter-input::-webkit-search-cancel-button { display: none; } /* ใช้ปุ่ม ✕ ของเราเองแทน */
.dir-filter-clear {
  position: absolute; right: 10px;
  width: 24px; height: 24px; border-radius: 50%;
  font-size: .78rem; color: var(--ink-3);
  background: var(--surface-2); border: none;
  display: flex; align-items: center; justify-content: center;
}
.dir-filter-clear:hover { color: var(--ink); background: var(--line); }
.dir-count { font-size: .85rem; color: var(--ink-3); white-space: nowrap; }

/* ── ป้ายหมวด: เห็นภาพรวมทั้งคลังในหน้าจอเดียว + กดข้ามไปหมวดได้ ──
   บนมือถือเรียงเป็นแถวเลื่อนแนวนอนแถวเดียว — ถ้าปล่อยให้ตัดบรรทัด 10 ป้ายจะกินพื้นที่
   เต็มหน้าจอแรกทั้งจอ ดันเนื้อหาจริงหายไปใต้ fold (ยืนยันจากการทดสอบจอ 375px) */
.dir-chips {
  display: flex; gap: 8px; margin-bottom: 28px;
  overflow-x: auto; padding-bottom: 4px;
  scrollbar-width: thin; -webkit-overflow-scrolling: touch;
}
@media (min-width: 700px) { .dir-chips { flex-wrap: wrap; overflow-x: visible; } }
.dir-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 14px; flex: 0 0 auto;
  font-size: .83rem; font-weight: 600; color: var(--navy-2);
  background: var(--blue-soft);
  border: 1px solid transparent; border-radius: 99px;
  white-space: nowrap;
  transition: border-color .15s, background .15s;
}
.dir-chip:hover { border-color: var(--gold); background: var(--gold-soft); }
.dir-chip-n {
  font-size: .76rem; font-weight: 700; color: var(--ink-3);
  background: var(--paper); border-radius: 99px; padding: 1px 7px;
}

.category-group { margin-bottom: 38px; scroll-margin-top: 80px; }
.category-group:last-child { margin-bottom: 0; }
.category-heading {
  font-family: var(--font-serif); font-size: 1.05rem; font-weight: 700;
  color: var(--navy); margin: 0 0 16px; padding-bottom: 8px;
  border-bottom: 2px solid var(--line-strong);
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
}
.cat-count {
  font-family: var(--font-sans); font-size: .78rem; font-weight: 400; color: var(--ink-3);
  white-space: nowrap;
}

/* ── แถวรายการแบบกระชับ ──
   การ์ดเต็มใบสูง ~130 px × 259 ฉบับ = หน้าแรกยาว 23,000 px (32 หน้าจอ) เลื่อนหาไม่ไหว
   แถวนี้สูงราว 1 ใน 3 จึงเห็นได้หลายเท่าต่อหน้าจอ แต่ยังคงรหัสสีขอบซ้ายตามชนิดกฎหมาย
   เหมือนการ์ดเดิม (น้ำเงิน = พ.ร.บ./ประมวล · เขียว = ระเบียบ · ทอง = ฉบับแก้ไข) */
.category-rows { display: flex; flex-direction: column; gap: 8px; }
@media (min-width: 700px) {
  .category-rows { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 20px; align-items: start; }
}
/* ⚠️ ต้องมี: กฎ display ด้านบนมี specificity สูงกว่า [hidden] { display: none } ของเบราว์เซอร์
   ถ้าไม่เขียนทับ ส่วนที่พับไว้ (.category-rest) จะกางออกหมดทั้งที่ตั้ง hidden ไว้ */
.category-rows[hidden] { display: none; }
.law-row {
  display: flex; align-items: baseline; justify-content: space-between; gap: 14px;
  padding: 11px 16px;
  background: var(--surface);
  border: 1px solid var(--line); border-left-width: 3px; border-radius: var(--radius);
  transition: border-color .15s, background .15s, transform .15s;
}
.law-row:hover {
  border-color: var(--gold); border-left-color: var(--gold);
  transform: translateX(2px);
}
.law-row.parent { border-left-color: var(--navy); }
.law-row.child { border-left-color: var(--teal); }
.law-row.amendment { border-left-color: var(--gold); }
.lr-name {
  font-family: var(--font-serif); font-weight: 600; font-size: .97rem;
  color: var(--ink); line-height: 1.5;
}
.lr-meta { font-size: .76rem; color: var(--ink-3); white-space: nowrap; }
/* จอแคบ: ชื่อกฎหมายไทยยาว วางคู่กับตัวเลขบรรทัดเดียวแล้วบีบกันจนอ่านยาก — ซ้อนลงมาแทน */
@media (max-width: 699px) {
  .law-row { flex-direction: column; align-items: flex-start; gap: 3px; }
}

.law-family-compact { display: flex; flex-direction: column; }
.law-family-compact .law-children-toggle { margin: 8px 0 0 18px; }
.law-family-compact .law-children { margin-top: 8px; }

/* ปุ่มกางส่วนที่เหลือของหมวด — หมวดใหญ่สุดมี 94 ฉบับ ถ้ากางหมดตั้งแต่แรกก็กลับไปยาวเหมือนเดิม */
.cat-more {
  display: inline-flex; align-items: center; gap: 8px;
  margin-top: 14px; padding: 9px 18px;
  font-size: .85rem; font-weight: 600; color: var(--navy-2);
  background: var(--blue-soft);
  border: 1px solid var(--line); border-radius: 99px;
  transition: border-color .15s;
}
.cat-more:hover { border-color: var(--gold); }
.cat-more .cm-icon { font-size: .7rem; display: inline-block; transition: transform .15s ease; }
.cat-more.open .cm-icon { transform: rotate(180deg); }
.cat-more.open { margin-top: 10px; }

.law-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
  transition: transform .15s, box-shadow .15s, border-color .15s;
  position: relative;
}
.law-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--gold);
}
.law-card.parent { border-left: 4px solid var(--navy); }
.law-card.child { border-left: 4px solid var(--teal); }
.law-card.amendment { border-left: 4px solid var(--gold); padding: 14px 20px; }

.law-children { margin: 0 0 0 26px; padding-left: 22px; border-left: 2px dashed var(--line-strong); }
.law-children .law-card { margin-top: 14px; }

.law-children-toggle {
  display: flex; align-items: center; gap: 8px;
  margin: 14px 0 0 26px;
  padding: 8px 16px;
  font-size: .83rem; font-weight: 600;
  color: var(--teal);
  background: var(--teal-soft);
  border: 1px dashed var(--line-strong);
  border-radius: 99px;
}
.law-children-toggle:hover { border-color: var(--teal); }
.law-children-toggle .lct-icon { font-size: .7rem; display: inline-block; transition: transform .15s ease; }
.law-children-toggle.open .lct-icon { transform: rotate(180deg); }
.law-children-toggle.open { margin-bottom: 4px; }
.law-child-connector {
  font-size: .75rem; color: var(--ink-3); margin: 14px 0 -6px;
  display: flex; align-items: center; gap: 6px;
}

.law-card-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.law-badge {
  font-size: .72rem; font-weight: 700; letter-spacing: .02em;
  border-radius: 6px; padding: 2px 10px;
}
.badge-act { background: var(--blue-soft); color: var(--navy-2); }
.badge-reg { background: var(--teal-soft); color: var(--teal); }
.badge-amend { background: var(--gold-soft); color: var(--amber-ink); }
.law-year { font-size: .8rem; color: var(--ink-3); }

.law-card-name {
  font-family: var(--font-serif); font-weight: 600; font-size: 1.06rem;
  color: var(--ink); line-height: 1.55;
}
.law-card.amendment .law-card-name { font-size: .95rem; }
.law-card-meta {
  display: flex; gap: 16px; margin-top: 8px; flex-wrap: wrap;
  font-size: .82rem; color: var(--ink-2);
}
.law-card-meta .m { display: inline-flex; align-items: center; gap: 5px; }

/* ============================================================
   Home — features
   ============================================================ */
.features {
  max-width: 980px; margin: 0 auto;
  padding: 34px 20px 56px;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px;
}
.feature {
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px;
}
.feature-icon { font-size: 1.5rem; margin-bottom: 8px; }
.feature h3 { font-family: var(--font-serif); font-size: 1.02rem; margin-bottom: 6px; }
.feature p { font-size: .87rem; color: var(--ink-2); line-height: 1.7; }

/* ============================================================
   Reader — layout
   ============================================================ */
/* ⚠️ ใช้ transform: scaleX() ไม่ใช่ width — การเปลี่ยน width ทุกเฟรมที่เลื่อนบังคับให้เบราว์เซอร์
   คำนวณ layout + วาดใหม่ทั้งแถบ ส่วน transform ทำงานบน compositor ล้วน ไม่แตะ layout เลย */
.reading-progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 100%;
  transform: scaleX(0); transform-origin: 0 50%;
  background: linear-gradient(90deg, var(--gold), var(--gold-2));
  z-index: 110;
  transition: transform .1s linear;
}

.breadcrumb {
  max-width: 1400px; margin: 0 auto;
  padding: 14px 20px 0;
  font-size: .85rem; color: var(--ink-3);
  display: flex; align-items: center; gap: 8px;
}
.breadcrumb a { color: var(--ink-2); }
.breadcrumb a:hover { color: var(--gold); }
.breadcrumb-sep { color: var(--line-strong); }

/* ── แถบบอกกฎหมายที่กำลังดู (ลอยใต้เฮดเดอร์)
     ปัญหา: เลื่อนอ่านลึกๆ แล้วไม่รู้ว่ากำลังดูฉบับไหนอยู่ ต้องเลื่อนกลับขึ้นบนสุดถึงจะเห็นชื่อ
     วิธีแก้: ใช้ position:fixed (ไม่กิน layout ตอนซ่อน) โผล่มาแทนที่หลังเลื่อนผ่านหัวเรื่องไปแล้ว ── */
.law-context-bar {
  position: fixed; top: var(--header-h); left: 0; right: 0; z-index: 99;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  max-width: 1400px; margin: 0 auto;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-md);
  transform: translateY(-8px);
  opacity: 0;
  pointer-events: none;
  transition: transform .18s ease, opacity .18s ease;
}
.law-context-bar.show { transform: translateY(0); opacity: 1; pointer-events: auto; }
.lcb-name {
  font-size: .88rem; font-weight: 600; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lcb-top {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 6px;
  padding: 7px 16px;
  font-size: .82rem; font-weight: 600;
  color: #fff; background: var(--gold);
  border: none; border-radius: 99px;
}
.lcb-top:hover { filter: brightness(1.08); }
html[data-theme="dark"] .lcb-top { color: var(--navy-deep); }

/* ── ปุ่ม "ลงล่างสุด" มุมล่างซ้ายจอ — ทุกหน้า (ไม่ใช่แค่หน้าอ่านฉบับ)
     จุดประสงค์: พาไปท้ายหน้าที่มีเครดิต/ลิงก์เครือ Yotathai และโฆษณา ── */
.scroll-bottom-btn {
  position: fixed; left: 20px; bottom: 20px; z-index: 90;
  display: flex; align-items: center; gap: 6px;
  padding: 9px 18px;
  font-size: .82rem; font-weight: 600;
  color: #fff; background: var(--gold);
  border: none; border-radius: 99px;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  transform: translateY(12px);
  opacity: 0;
  pointer-events: none;
  transition: transform .18s ease, opacity .18s ease;
}
.scroll-bottom-btn.show { transform: translateY(0); opacity: 1; pointer-events: auto; }
.scroll-bottom-btn:hover { filter: brightness(1.08); }
html[data-theme="dark"] .scroll-bottom-btn { color: var(--navy-deep); }

.reader-layout {
  max-width: 1400px; margin: 0 auto;
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr) 320px;
  gap: 28px;
  padding: 18px 20px 60px;
  align-items: start;
}

/* ── สารบัญ (TOC) ── */
.toc-panel {
  position: sticky; top: calc(var(--header-h) + 14px);
  /* ⚠️ 100dvh (มี 100vh เป็น fallback ให้เบราว์เซอร์เก่า): บน iOS แถบเครื่องมือ Safari ยุบ/กางระหว่างเลื่อน
     ทำให้ค่า 100vh เปลี่ยนกลางคัน → แผงสารบัญถูกคำนวณความสูงใหม่ทุกครั้ง เกิดอาการกระตุกตอนเลื่อน */
  max-height: calc(100vh - var(--header-h) - 28px);
  max-height: calc(100dvh - var(--header-h) - 28px);
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden;
}
.toc-filter { padding: 12px; border-bottom: 1px solid var(--line); }
.toc-filter input {
  width: 100%; padding: 7px 12px;
  font-family: var(--font-sans); font-size: .85rem;
  color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 7px; outline: none;
}
.toc-filter input:focus { border-color: var(--gold); }
.toc-filter-count {
  margin-top: 7px;
  font-size: .74rem; color: var(--ink-3);
}
/* ⚠️ overscroll-behavior: contain — เมื่อเลื่อนสารบัญจนสุดบน/ล่าง iOS จะ "ส่งต่อ" การเลื่อนไปให้ทั้งหน้า
   (scroll chaining) ทำให้รู้สึกว่านิ้วสะดุด/เมนูค้างแล้วหน้ากระโดดแทน — ปิดการส่งต่อให้จบในกล่องสารบัญ */
.toc-list {
  overflow-y: auto; padding: 8px 0 14px; flex: 1;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.toc-chapter {
  padding: 10px 16px 4px;
  font-size: .78rem; font-weight: 700; color: var(--navy);
  letter-spacing: .01em;
}
html[data-theme="dark"] .toc-chapter { color: var(--navy-2); }
.toc-chapter small { display: block; font-weight: 500; color: var(--ink-3); font-size: .73rem; }
.toc-item {
  padding: 4px 16px 4px 22px;
  font-size: .84rem; color: var(--ink-2);
  cursor: pointer;
  border-left: 3px solid transparent;
  line-height: 1.5;
  /* ฉบับใหญ่มีรายการสารบัญนับพัน (ป.พ.พ. = 1,848 รายการ) — ให้เบราว์เซอร์ข้ามการวาดรายการที่อยู่นอกจอ
     contain-intrinsic-size: auto 30px = จำขนาดจริงหลังเคยวาดแล้ว ถ้ายังไม่เคยวาดให้ประมาณ 30px
     (ไม่กระทบการค้นหาในหน้าและการเลื่อนไปยังรายการ เพราะเบราว์เซอร์บังคับวาดให้เองเมื่อต้องใช้) */
  content-visibility: auto;
  contain-intrinsic-size: auto 30px;
}
.toc-item-head { display: flex; align-items: baseline; gap: 8px; }
.toc-item:hover { background: var(--surface-2); color: var(--ink); }
.toc-item.active {
  border-left-color: var(--gold);
  background: var(--gold-soft);
  color: var(--amber-ink); font-weight: 600;
}
.toc-item .toc-num { font-weight: 600; white-space: nowrap; }
.toc-item .toc-flag { font-size: .7rem; }
/* ⚠️ ค้นคำในฉบับนี้ — ตัวอย่างข้อความที่เจอ ใต้เลขมาตราที่ตรง (แสดงเฉพาะตอนกรอง ไม่ใช่ตอนอ่านปกติ) */
.toc-item-snippet {
  margin-top: 2px;
  font-size: .76rem; color: var(--ink-3);
  line-height: 1.5; white-space: normal;
}
.toc-item-snippet:empty { display: none; }
.toc-item-snippet mark {
  background: var(--gold-soft); color: var(--amber-ink);
  border-radius: 3px; padding: 0 2px;
}

/* ── ตัวบท ── */
.law-content { max-width: 780px; min-width: 0; }

.law-header {
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  border-top: 4px solid var(--gold);
  padding: 26px 30px;
  margin-bottom: 22px;
  box-shadow: var(--shadow-sm);
}
.law-header .law-card-top { margin-bottom: 10px; }
.law-header h1 {
  font-family: var(--font-serif); font-size: 1.45rem; font-weight: 700;
  line-height: 1.55; margin-bottom: 10px;
}
.law-source { font-size: .82rem; color: var(--ink-3); }
.law-desc { font-size: .9rem; color: var(--ink-2); margin-top: 6px; }

.law-preamble {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 18px 22px;
  font-size: .92rem; color: var(--ink-2); line-height: 1.85;
  margin-bottom: 26px;
  border-left: 3px solid var(--line-strong);
}
.law-preamble p { margin-bottom: .7em; }
.law-preamble p:last-child { margin-bottom: 0; }

.chapter-heading {
  text-align: center;
  margin: 40px 0 8px;
  font-family: var(--font-serif);
}
.chapter-heading .ch-level {
  font-size: .95rem; font-weight: 600; color: var(--gold);
  letter-spacing: .05em;
}
.chapter-heading .ch-title {
  font-size: 1.2rem; font-weight: 700; color: var(--ink);
  margin-top: 2px;
}
.chapter-heading::after {
  content: '';
  display: block; width: 70px; height: 2px;
  background: var(--gold-2); opacity: .5;
  margin: 12px auto 0;
}

.section-block {
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 26px;
  margin: 14px 0;
  scroll-margin-top: calc(var(--header-h) + 20px);
  transition: box-shadow .2s, border-color .2s, background .6s;
  position: relative;
}
.section-block:hover { border-color: var(--line-strong); }
.section-block.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 16%, transparent);
}
.section-block.flash { background: var(--gold-soft); }

.section-head {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 10px;
}
.section-num {
  font-family: var(--font-serif); font-weight: 700; font-size: 1.02rem;
  color: var(--navy);
  background: var(--blue-soft);
  border-radius: 7px; padding: 1px 12px;
  white-space: nowrap;
}
html[data-theme="dark"] .section-num { color: var(--navy-2); }
.section-tools { margin-left: auto; display: flex; gap: 6px; opacity: 0; transition: opacity .15s; }
.section-block:hover .section-tools, .section-block.selected .section-tools { opacity: 1; }
.section-tools button {
  font-size: .72rem; color: var(--ink-3);
  background: none; border: 1px solid var(--line); border-radius: 6px;
  padding: 2px 9px;
}
.section-tools button:hover { color: var(--gold); border-color: var(--gold); }

.amendment-banner {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--amber-bg);
  border: 1px solid var(--amber-line);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: .85rem; color: var(--amber-ink); line-height: 1.6;
}
.amendment-banner .ab-icon { flex-shrink: 0; }
.amendment-banner a { color: inherit; font-weight: 700; text-decoration: underline; }

/* ── ตัวบท: แต่ละวรรคต้องแยกกันให้เห็นชัด ──
   วรรคคือหน่วยอ้างอิงทางกฎหมาย ("มาตรา 27 วรรคหก") การรวมวรรคเป็นก้อนเดียว
   ทำให้ผู้ใช้อ้างอิงผิด จึงเว้นระยะระหว่างวรรคชัดเจน + มีป้ายกำกับเลขวรรค */
.section-body { font-size: .98rem; line-height: 1.95; }
.section-body p { margin-bottom: 1.1em; text-align: justify; }
.section-body p:last-child { margin-bottom: 0; }

/* วรรคใหม่: ย่อหน้าบรรทัดแรกแบบเอกสารราชการ (2.5 ซม. ≈ 2.6em) */
.section-body p.para { text-indent: 2.6em; }
/* อนุมาตรา (๑) (๒): เยื้องเข้าทั้งย่อหน้า เพื่อให้เห็นว่าเป็นรายการย่อยของวรรค */
.section-body p.sub-clause {
  margin-left: 2.6em; margin-bottom: .45em;
  text-indent: 0; text-align: left;
}

/* ป้ายกำกับวรรค — เครื่องมือช่วยอ้างอิง ("มาตรา 27 วรรคหก") ไม่ใช่ส่วนของตัวบท
   วางเป็นบรรทัดเล็กเหนือวรรค ไม่รบกวนการอ่าน และไม่ติดไปตอนสั่งพิมพ์ */
.para-tag {
  display: block;
  font-family: var(--font-sans);
  font-size: .67rem; font-weight: 600;
  letter-spacing: .04em;
  color: var(--ink-3);
  text-indent: 0;
  margin-bottom: 2px;
  user-select: none;
  transition: color .15s;
}
.section-block:hover .para-tag, .section-block.selected .para-tag { color: var(--gold); }

/* ── ลิงก์อ้างอิงในตัวบท ──
   ออกแบบให้ "เห็นปุ๊บรู้ปั๊บว่ากดได้" โดยไม่รบกวนการอ่านตัวบท:
   สีเข้ม + พื้นอ่อน + เส้นใต้ทึบ · สีน้ำเงิน = ในฉบับเดียวกัน · สีเขียว + ↗ = ข้ามไปอีกฉบับ */
.law-link {
  color: var(--link-ink);
  font-weight: 600;
  background: var(--link-bg);
  border-bottom: 1.5px solid var(--link-line);
  border-radius: 4px;
  padding: 0 4px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.law-link:hover, .law-link:focus-visible {
  background: var(--link-ink);
  color: var(--surface);
  border-color: var(--link-ink);
}
.law-link.cross {
  color: var(--link-cross-ink);
  background: var(--link-cross-bg);
  border-bottom-color: var(--link-cross-line);
}
.law-link.cross::after { content: '↗'; font-size: .78em; margin-left: 2px; vertical-align: .1em; }
.law-link.cross:hover, .law-link.cross:focus-visible {
  background: var(--link-cross-ink);
  color: var(--surface);
  border-color: var(--link-cross-ink);
}

.law-postamble {
  margin-top: 30px;
  padding: 18px 22px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: .88rem; color: var(--ink-2); line-height: 1.8;
  border-left: 3px solid var(--line-strong);
  white-space: pre-line;
}

/* ── แผงจุดเชื่อมโยง ── */
.relations-panel {
  position: sticky; top: calc(var(--header-h) + 14px);
  /* เหตุผลเดียวกับ .toc-panel — กัน 100vh เปลี่ยนกลางคันตอนแถบ Safari ยุบ/กาง */
  max-height: calc(100vh - var(--header-h) - 28px);
  max-height: calc(100dvh - var(--header-h) - 28px);
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden;
}
.relations-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 10px;
  border-bottom: 1px solid var(--line);
}
.relations-header h2 { font-family: var(--font-serif); font-size: 1rem; }
.relations-close { display: none; background: none; border: none; font-size: 1rem; color: var(--ink-3); }
.relations-body { overflow-y: auto; padding: 12px 14px 18px; flex: 1; }
.relations-hint { font-size: .84rem; color: var(--ink-3); line-height: 1.7; }
.relations-context {
  font-size: .8rem; color: var(--ink-3); margin-bottom: 10px;
}
.relations-context strong { color: var(--gold); font-family: var(--font-serif); }

.rel-group-label {
  font-size: .72rem; font-weight: 700; letter-spacing: .05em;
  color: var(--ink-3); text-transform: uppercase;
  margin: 12px 2px 6px;
}
.rel-card {
  display: block;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color .15s, transform .15s;
}
.rel-card:hover { border-color: var(--gold); transform: translateX(2px); }
.rel-card.amendment { background: var(--amber-bg); border-color: var(--amber-line); }
.rel-card.cross { background: var(--teal-soft); }
.rel-type {
  font-size: .7rem; font-weight: 700;
  color: var(--ink-3);
  display: flex; align-items: center; gap: 5px;
}
.rel-card.amendment .rel-type { color: var(--amber-ink); }
.rel-card.cross .rel-type { color: var(--teal); }
.rel-target { font-weight: 600; font-size: .88rem; color: var(--ink); margin-top: 2px; }
.rel-desc { font-size: .78rem; color: var(--ink-2); line-height: 1.55; margin-top: 3px; }

.relations-fab {
  position: fixed; right: 18px; bottom: 20px; z-index: 90;
  display: none;
  background: var(--navy); color: #fff;
  border: none; border-radius: 99px;
  padding: 12px 20px;
  font-size: .9rem; font-weight: 600;
  box-shadow: var(--shadow-lg);
}
html[data-theme="dark"] .relations-fab { background: var(--navy-2); color: var(--navy-deep); }

/* ============================================================
   หน้ามาตราแยก (gen-section-pages.js) — เนื้อหา static ก่อน JS hydrate
   เห็นได้เฉพาะตอนที่ยังไม่ได้รัน JS (crawler/curl) หรือช่วงสั้นๆ ก่อนหน้าเต็มฉบับโหลดเสร็จ
   ============================================================ */
.related-sections { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--line); }
.related-sections h2 { font-size: .95rem; font-weight: 700; color: var(--ink-2); margin-bottom: 10px; }
.related-sections ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.related-sections li {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.related-sections .rel-meta { display: block; font-size: .78rem; color: var(--ink-3); margin-top: 2px; }

.section-pager {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line);
}
.section-pager a { font-size: .85rem; color: var(--ink-2); }
.section-pager a:hover { color: var(--gold); }
.section-pager .pager-full { font-weight: 600; color: var(--gold); }

/* ============================================================
   Footer
   ============================================================ */
.site-footer {
  border-top: 1px solid var(--line);
  background: var(--surface);
  margin-top: 20px;
}

/* ── ลิงก์เครือโยธาไทย — ประชาสัมพันธ์บริการอื่นในเครือ + ช่วย SEO ให้ yotathai.com ── */
.footer-network {
  max-width: 980px; margin: 0 auto;
  padding: 28px 20px 0;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 26px;
}
.footer-net-col { display: flex; flex-direction: column; gap: 8px; font-size: .84rem; }
.footer-net-col strong {
  font-family: var(--font-serif); font-size: .82rem; font-weight: 700;
  color: var(--gold); text-transform: uppercase; letter-spacing: .03em;
  margin-bottom: 2px;
}
.footer-net-col a { color: var(--ink-2); line-height: 1.6; }
.footer-net-col a:hover { color: var(--link-ink); }

.footer-inner {
  max-width: 980px; margin: 0 auto;
  padding: 34px 20px 20px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 30px;
  font-size: .85rem; color: var(--ink-2);
}
.footer-brand strong { font-family: var(--font-serif); font-size: 1.05rem; color: var(--ink); }
.footer-brand p { margin-top: 6px; line-height: 1.7; }
.footer-note p { line-height: 1.7; }
.disclaimer { color: var(--gold); margin-top: 6px; font-weight: 500; }
.footer-links { margin-top: 12px; }
.footer-links a { color: var(--ink-2); text-decoration: underline; text-underline-offset: 3px; }
.footer-links a:hover { color: var(--gold); }

/* ── หน้าข้อมูลนิ่ง (เกี่ยวกับเรา / ติดต่อ / นโยบาย / ข้อกำหนด) ── */
.static-page { max-width: 820px; margin: 0 auto; padding: 20px 20px 60px; }
.static-doc {
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 32px 36px;
}
.static-doc h1 { font-family: var(--font-serif); font-size: 1.75rem; margin-bottom: 6px; }
.static-doc h2 {
  font-family: var(--font-serif); font-size: 1.15rem;
  margin: 28px 0 10px; color: var(--navy);
}
html[data-theme="dark"] .static-doc h2 { color: var(--navy-2); }
.static-doc p, .static-doc li { line-height: 1.85; color: var(--ink-2); }
.static-doc p { margin-bottom: 12px; }
.static-doc ul, .static-doc ol { margin: 0 0 14px 22px; }
.static-doc li { margin-bottom: 8px; }
.static-doc a { color: var(--gold-2); text-decoration: underline; text-underline-offset: 3px; }
.static-doc strong { color: var(--ink); }
.static-updated { font-size: .82rem; color: var(--ink-3); margin-bottom: 22px; }
@media (max-width: 820px) {
  .static-doc { padding: 22px 20px; }
  .static-doc h1 { font-size: 1.45rem; }
}
.footer-bottom {
  max-width: 980px; margin: 0 auto;
  padding: 14px 20px 26px;
  border-top: 1px solid var(--line);
  font-size: .8rem; color: var(--ink-3);
}
.footer-bottom a { color: var(--ink-2); }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1150px) {
  .reader-layout { grid-template-columns: 250px minmax(0, 1fr); }
  .relations-panel {
    position: fixed; right: 0; top: var(--header-h); bottom: 0;
    width: min(360px, 92vw);
    max-height: none;
    border-radius: 0;
    transform: translateX(100%);
    transition: transform .25s ease;
    box-shadow: var(--shadow-lg);
    z-index: 95;
  }
  .relations-panel.open { transform: translateX(0); }
  .relations-close { display: block; }
  .relations-fab { display: flex; align-items: center; gap: 6px; }
}

@media (max-width: 820px) {
  .header-inner { gap: 10px; }
  .logo-text { display: none; }
  .search-kbd { display: none; }
  .reader-layout { grid-template-columns: minmax(0, 1fr); padding-top: 10px; }
  .toc-panel {
    position: static; max-height: 260px;
    margin-bottom: 4px;
  }
  .section-block { padding: 16px 18px; }
  .section-body { font-size: .95rem; }
  .footer-inner { grid-template-columns: 1fr; gap: 16px; }
  .footer-network { grid-template-columns: 1fr 1fr; gap: 18px 20px; }
  .hero { padding: 44px 16px 40px; }
  .stat { min-width: 100px; padding: 10px 14px 8px; }
  .stat strong { font-size: 1.3rem; }
}

/* ============================================================
   การอ่านต่อเนื่องเมื่อกดอ้างอิงข้ามมาตรา
   ปัญหา: กด "มาตรา ๑" จากมาตรา ๕๕ แล้วหน้าเลื่อนไป ผู้ใช้หาทางกลับเองไม่ได้
   วิธีแก้ 2 ชั้น: (1) เปิดหน้าต่างดูทับ ไม่ต้องละจากที่เดิม
                  (2) ถ้าเลือกไปจริง มีปุ่มย้อนกลับแบบซ้อนชั้น
   ============================================================ */
.peek-overlay {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(12, 20, 34, .55);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: peekIn .16s ease;
}
@keyframes peekIn { from { opacity: 0 } to { opacity: 1 } }

.peek-card {
  width: min(720px, 100%);
  max-height: min(80vh, 720px);
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 4px solid var(--gold);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.peek-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 14px;
  padding: 18px 22px 12px;
  border-bottom: 1px solid var(--line);
}
.peek-eyebrow { font-size: .76rem; font-weight: 600; color: var(--gold); margin-bottom: 2px; }
.peek-head h2 { font-family: var(--font-serif); font-size: 1.2rem; }
.peek-close {
  background: none; border: 1px solid var(--line); border-radius: 8px;
  width: 32px; height: 32px; flex-shrink: 0;
  color: var(--ink-2); font-size: .95rem;
}
.peek-close:hover { background: var(--surface-2); color: var(--ink); }

.peek-body { overflow-y: auto; padding: 18px 22px; font-size: .96rem; line-height: 1.9; }
.peek-body p { margin-bottom: 1em; text-align: justify; }
.peek-body p.para { text-indent: 2.6em; }
.peek-body p.sub-clause { margin-left: 2.6em; text-indent: 0; text-align: left; margin-bottom: .45em; }
.peek-body .peek-ref { color: var(--link-ink); font-weight: 600; }
.peek-body .peek-amend {
  background: var(--amber-bg); border: 1px solid var(--amber-line);
  border-radius: var(--radius-sm); padding: 8px 12px; margin-bottom: 12px;
  font-size: .85rem; color: var(--amber-ink);
}
.peek-loading { color: var(--ink-3); text-align: center; padding: 30px 0; }

.peek-foot {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 12px 22px 16px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}
.btn-jump {
  padding: 8px 18px; font-size: .88rem; font-weight: 600;
  background: var(--navy); color: #fff;
  border: none; border-radius: 8px;
}
.btn-jump:hover { background: var(--navy-2); }
html[data-theme="dark"] .btn-jump { background: var(--navy-2); color: var(--navy-deep); }
.peek-hint { font-size: .78rem; color: var(--ink-3); }

/* ปุ่มย้อนกลับ (ลอยล่างซ้าย) */
.back-trail {
  position: fixed; left: 18px; bottom: 20px; z-index: 96;
  display: flex; align-items: center; gap: 8px;
  padding: 11px 18px;
  font-size: .88rem; font-weight: 600;
  color: #fff; background: var(--gold);
  border: none; border-radius: 99px;
  box-shadow: var(--shadow-lg);
  animation: peekIn .18s ease;
  max-width: min(320px, 70vw);
}
.back-trail:hover { filter: brightness(1.08); }
.back-trail .bt-arrow { font-size: 1rem; }
.back-trail .bt-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back-trail .bt-count {
  background: rgba(255, 255, 255, .28);
  border-radius: 99px; padding: 0 8px; font-size: .74rem;
}
html[data-theme="dark"] .back-trail { color: var(--navy-deep); }

@media (max-width: 820px) {
  .peek-card { max-height: 88vh; width: 100%; }
  .peek-overlay { padding: 0; align-items: flex-end; }
  .peek-card { border-radius: var(--radius) var(--radius) 0 0; }
  .back-trail { left: 12px; bottom: 14px; font-size: .82rem; padding: 9px 14px; }
}

@media print { .peek-overlay, .back-trail { display: none !important; } }

/* ── ข้อความที่ใช้บังคับใหม่จากฉบับแก้ไข ── */
.amended-text {
  margin-top: 14px;
  border-left: 3px solid var(--gold);
  background: color-mix(in srgb, var(--gold-soft) 70%, transparent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 12px 16px;
}
.amended-text .at-head {
  font-size: .74rem; font-weight: 700; letter-spacing: .02em;
  color: var(--amber-ink); margin-bottom: 5px;
}
.amended-text p { font-size: .96rem; line-height: 1.9; text-align: left; text-indent: 2.6em; }
.amended-missing {
  margin-top: 12px; padding: 9px 14px;
  border: 1px dashed var(--amber-line); border-radius: var(--radius-sm);
  font-size: .84rem; color: var(--amber-ink);
}

/* ── ประวัติการแก้ไข (ฉบับสมบูรณ์) — ข้อความเดิมทุกยุคของมาตรานี้ ── */
.badge-history { background: var(--teal-soft); color: var(--teal); }
.history-panel {
  margin-top: 14px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  overflow: hidden;
}
.history-panel summary {
  cursor: pointer; list-style: none;
  padding: 10px 16px; font-size: .84rem; font-weight: 700; color: var(--teal);
  background: var(--teal-soft);
  display: flex; align-items: center; gap: 6px;
}
.history-panel summary::-webkit-details-marker { display: none; }
.history-panel[open] summary { border-bottom: 1px solid var(--line-strong); }
.history-version {
  padding: 12px 16px; border-top: 1px dashed var(--line);
}
.history-version:first-of-type { border-top: none; }
.history-version.current { background: color-mix(in srgb, var(--teal-soft) 45%, transparent); }
.hv-head {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px;
  font-size: .76rem; font-weight: 700; color: var(--ink-2); margin-bottom: 6px;
}
.hv-label { color: var(--teal); }
.hv-date { font-weight: 400; color: var(--ink-3); }
.history-version p { font-size: .93rem; line-height: 1.85; text-align: left; text-indent: 2.6em; color: var(--ink-2); }

/* ปุ่มพิมพ์ (บนหน้าจอ) */
.print-group { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.print-btn.ghost {
  background: none; color: var(--ink-2);
  border-color: var(--line); font-weight: 500;
}
.print-btn.ghost:hover { background: var(--surface-2); color: var(--ink); border-color: var(--line-strong); }
.print-btn {
  display: inline-flex; align-items: center; gap: 7px;
  margin-top: 14px;
  padding: 8px 16px;
  font-size: .87rem; font-weight: 600;
  color: var(--navy-2);
  background: var(--surface-2);
  border: 1px solid var(--line-strong); border-radius: 8px;
  transition: background .15s, border-color .15s, color .15s;
}
.print-btn:hover { background: var(--navy); color: #fff; border-color: var(--navy); }
html[data-theme="dark"] .print-btn:hover { background: var(--navy-2); color: var(--navy-deep); }

/* ส่วนที่โผล่เฉพาะตอนพิมพ์ */
.print-only { display: none; }

/* ============================================================
   ADS — กันโฆษณา Auto Ads ทำ layout เพี้ยน
   ⚠️ ห้ามใช้ display:none / visibility:hidden กับ ins.adsbygoogle หรือ iframe
   โฆษณา — ผิดนโยบาย AdSense (ห้าม "ปิดบัง/ซ่อน" โฆษณาที่แสดงจริงแล้ว เสี่ยงระงับบัญชี)
   กฎด้านล่างนี้แค่ "กักขนาด" ไม่ให้ล้นจอ/ดันเลย์เอาต์ ไม่ได้ซ่อนโฆษณา
   ส่วน Anchor ads / Vignette ads (โฆษณาลอยทับจอ) ต้องปิดที่ AdSense Dashboard
   → Ads → By site → thailaw.net → แก้ไข → Overlay formats เท่านั้น CSS แก้ไม่ได้
   ============================================================ */
ins.adsbygoogle {
  max-width: 100%;
  overflow: hidden;
}

/* ============================================================
   PRINT — เอกสาร A4 สำหรับพิมพ์ใส่แฟ้ม/ใช้ในที่ประชุม
   ออกแบบให้หน้าตาเป็นเอกสารกฎหมายราชการ ไม่ใช่หน้าเว็บที่ถูกยัดลงกระดาษ
   ============================================================ */
/* ขอบกระดาษตามระเบียบงานสารบรรณ: บน 2.5 ซม. · ล่าง 2 ซม. · ซ้าย 3 ซม. · ขวา 2 ซม.
   (ซ้ายกว้างกว่าเพื่อเจาะรูเข้าแฟ้มได้โดยไม่โดนตัวหนังสือ) */
@page {
  size: A4 portrait;
  margin: 25mm 20mm 20mm 30mm;
}

@media print {
  /* ── รีเซ็ตชุดสีเป็นขาว-ดำเสมอ ──
     สำคัญ: ถ้าผู้ใช้เปิด dark mode อยู่ กฎ html[data-theme="dark"] มี specificity สูงกว่า
     กฎในบล็อกนี้ ทำให้พิมพ์ออกมาเป็นสีผิด → ต้องเขียนทับที่ระดับตัวแปรทั้งชุด */
  :root, html[data-theme="dark"] {
    --paper: #fff; --surface: #fff; --surface-2: #fff;
    --line: #bbb; --line-strong: #888;
    --ink: #000; --ink-2: #1a1a1a; --ink-3: #444;
    --navy: #000; --navy-2: #000; --navy-deep: #000;
    --gold: #000; --gold-2: #000; --gold-soft: #fff;
    --teal: #000; --teal-soft: #fff; --blue-soft: #fff;
    --amber-bg: #fff; --amber-line: #000; --amber-ink: #000;
    --link-ink: #000; --link-bg: transparent; --link-line: #666;
    --link-cross-ink: #000; --link-cross-bg: transparent; --link-cross-line: #666;
  }

  /* ── ซ่อนทุกอย่างที่ไม่ใช่ตัวบท ── */
  .site-header, .toc-panel, .relations-panel, .relations-fab, .site-footer,
  .breadcrumb, .law-context-bar, .reading-progress, .section-tools, .print-btn, .scroll-bottom-btn,
  .hero, .law-directory, .features, .search-results, .history-panel,
  ins.adsbygoogle, iframe { display: none !important; }

  .print-only { display: block; }

  /* ── ตัวอักษรตามมาตรฐานหนังสือราชการไทย ──
     ราชการใช้ TH SarabunPSK ขนาด 16pt · เว็บนี้ใช้ Sarabun (ตระกูลแบบอักษรเดียวกัน
     ออกแบบโดยคุณศุภกิจ เฉลิมลาภ) จึงได้หน้าตาและสัดส่วนตรงตามเอกสารราชการ */
  /* ขนาด 14pt อ่านสบายและได้เนื้อหาต่อหน้ามากกว่า 16pt ราว 30%
     (16pt เป็นมาตรฐานหนังสือราชการ แต่เอกสารกฎหมายฉบับยาวใช้ 14pt จะเปลืองกระดาษน้อยกว่ามาก)
     line-height 1.45 เทียบเท่าระยะบรรทัด "หลายบรรทัด 1.15" ของ Word ที่อ่านลื่นที่สุด */
  /* ⚠️ ห้ามใช้ text-align: justify กับภาษาไทยในงานพิมพ์
     ภาษาไทยไม่มีช่องว่างระหว่างคำ เบราว์เซอร์จึงยืด "ช่องว่างวรรคตอน" ที่มีอยู่ไม่กี่จุด
     ให้กว้างผิดปกติเพื่อดันบรรทัดให้เต็ม (Word เกลี่ยทีละตัวอักษรจึงไม่มีปัญหานี้)
     ชิดซ้ายให้ระยะห่างสม่ำเสมอและอ่านเป็นธรรมชาติกว่ามาก */
  html, body {
    background: #fff !important;
    color: #000;
    font-family: 'Sarabun', 'TH SarabunPSK', sans-serif;
    font-size: 14pt;
    line-height: 1.45;
    text-rendering: optimizeLegibility;
  }

  /* โหมด "พิมพ์ตามต้นฉบับ" — ตัดข้อความจากฉบับแก้ไขออก เหลือเฉพาะที่ประกาศในฉบับนี้ */
  body.print-original-only .amended-text,
  body.print-original-only .amended-missing { display: none !important; }

  #reader-view { display: block !important; }
  .reader-layout { display: block; padding: 0; max-width: none; }
  .law-content { max-width: none; min-width: 0; }

  /* ── หัวเอกสาร (แทน law-header บนหน้าจอ) ── */
  .law-header { display: none; }

  /* ── หัวเอกสาร: จัดกึ่งกลางแบบประกาศราชกิจจานุเบกษา ──
     ตัวบทต้นฉบับเองมักขึ้นต้นด้วยชื่อกฎหมายซ้ำอีกครั้ง (เป็นธรรมชาติของเอกสารราชการจริง)
     จึงตัดหน้าหลังปกเสมอ ให้ปกกับเนื้อหาแยกกันชัดเจน ไม่ดูเหมือนพิมพ์ชื่อซ้ำติดกัน */
  .print-cover { text-align: center; margin-bottom: 12mm; break-after: page; page-break-after: always; }
  .print-cover .pc-type {
    font-size: 15pt; font-weight: 600;
    letter-spacing: .02em; margin-bottom: 1mm;
  }
  .print-cover h1 {
    font-size: 17pt; font-weight: 700; line-height: 1.4;
    margin: 0 auto; max-width: 145mm;
  }
  .print-cover .pc-rule {
    width: 30mm; height: .8pt; background: #000;
    margin: 5mm auto 3mm;
  }
  .print-cover .pc-meta {
    font-size: 11.5pt; color: #222; line-height: 1.5;
  }

  /* ── คำปรารภ: ย่อหน้าแรก 2.5 ซม. ตามระเบียบงานสารบรรณ ── */
  .law-preamble {
    background: none; border: none; border-left: none;
    padding: 0; margin: 0 0 8mm;
    font-size: 14pt; color: #000;
    text-align: left;
  }
  .law-preamble p { margin-bottom: .2em; text-indent: 25mm; }

  /* ── หมวด / ส่วนที่: จัดกึ่งกลาง ตัวหนา ห้ามตกค้างท้ายหน้า ── */
  .chapter-heading {
    margin: 10mm 0 5mm;
    break-after: avoid; break-inside: avoid;
    page-break-after: avoid;
  }
  .chapter-heading::after { display: none; }
  .chapter-heading .ch-level { color: #000; font-size: 14pt; font-weight: 700; }
  .chapter-heading .ch-title { color: #000; font-size: 14pt; font-weight: 700; margin-top: 0; }

  /* ── ตัวบทรายมาตรา ──
     ทำให้ "มาตรา ๗" อยู่ติดกับข้อความบรรทัดแรก เหมือนเอกสารกฎหมายจริง
     (บนหน้าจอเป็นป้ายแยกเพื่อให้กดง่าย แต่บนกระดาษต้องอ่านเป็นย่อหน้าเดียว) */
  /* ── ตัวบทรายมาตรา ──
     รูปแบบราชกิจจานุเบกษา: ย่อหน้าแรก 2.5 ซม. แล้วขึ้นต้นด้วย "มาตรา ๗" ตัวหนา
     ต่อด้วยเนื้อความในย่อหน้าเดียวกัน · วรรคถัดไปย่อหน้า 2.5 ซม. เช่นกัน */
  .section-block {
    border: none; box-shadow: none; background: none;
    padding: 0; margin: 0 0 .5em;   /* ระยะห่างระหว่างมาตรา ~ "ระยะห่างหลังย่อหน้า 6pt" ของ Word */
    break-inside: auto;
    text-indent: 25mm;              /* ย่อหน้าแรกของมาตรา */
  }

  /* ข้อความจากฉบับแก้ไข: พิมพ์ติดไปด้วย แต่กำกับที่มาให้ชัดว่าไม่ใช่ตัวบทเดิม */
  .amended-text {
    background: none; border: none;
    border-left: 1pt solid #000;
    border-radius: 0;
    padding: 0 0 0 4mm;
    margin: 1.5mm 0 2.5mm 25mm;
    text-indent: 0;
    break-inside: avoid;
  }
  .amended-text .at-head {
    font-size: 11pt; font-style: italic; color: #000;
    margin-bottom: .5mm;
  }
  .amended-text p { font-size: 14pt; text-indent: 0; text-align: left; }
  .amended-missing {
    margin: 1.5mm 0 2.5mm 25mm; padding: 0 0 0 4mm;
    border: none; border-left: 1pt dashed #000;
    font-size: 11pt; font-style: italic; color: #000;
    text-indent: 0;
  }
  .section-block.selected { box-shadow: none; }
  .section-head { display: inline; margin: 0; break-after: avoid; page-break-after: avoid; }
  .section-head .law-badge { display: none; }
  .section-num {
    display: inline;
    font-family: inherit;
    font-weight: 700; font-size: 14pt;
    color: #000; background: none;
    padding: 0; margin-right: .5em;
    white-space: nowrap;
  }
  .section-body { display: inline; font-size: 14pt; }
  .section-body p {
    text-align: left;
    text-indent: 25mm;
    margin-bottom: .1em;
    orphans: 2; widows: 2;
  }
  /* วรรคแรกต่อท้าย "มาตรา ๗" ในบรรทัดเดียวกัน จึงไม่ต้องย่อหน้าซ้ำ */
  .section-body p:first-child { display: inline; text-indent: 0; }
  /* ป้ายกำกับวรรคเป็นเครื่องมือช่วยอ่านบนหน้าจอ ไม่ใช่ส่วนหนึ่งของตัวบท — ห้ามพิมพ์ */
  .para-tag { display: none !important; }
  .section-body p.para, .section-body p.sub-clause { padding-left: 0; border-left: none; }
  .section-body p.sub-clause { text-indent: 25mm; }

  /* ── ป้ายเตือนมาตราที่ถูกแก้ไข: ต้องพิมพ์ติดไปด้วย (สำคัญทางกฎหมาย) ── */
  .amendment-banner {
    display: block;
    background: none;
    border: none; border-left: 2pt solid #000;
    border-radius: 0;
    padding: 0 0 0 3mm;
    margin: 1.5mm 0 2mm 25mm;
    font-size: 11.5pt; font-style: italic; color: #000;
    text-indent: 0;
    break-inside: avoid;
  }
  /* บนกระดาษกดลิงก์ไม่ได้ — ตัดคำว่า "อ่านฉบับแก้ไข" ออก เหลือแต่สาระว่าถูกแก้โดยฉบับใด */
  .amendment-banner .ab-icon, .amendment-banner .ab-link { display: none; }
  .amendment-banner::before { content: '⚠ '; font-weight: 700; }
  .amendment-banner a { text-decoration: none; color: #000; font-weight: 700; }

  /* ── ลิงก์อ้างอิง: บนกระดาษกดไม่ได้ ให้เป็นตัวหนังสือธรรมดาแต่ยังเน้นให้เห็น ── */
  .law-link, .law-link.cross {
    color: #000; background: none;
    border: none; border-bottom: .5pt dotted #666;
    padding: 0; font-weight: 600;
  }
  .law-link.cross::after { content: ''; }

  /* ── ท้ายเอกสาร ── */
  /* ── ท้ายประกาศ: "ประกาศ ณ วันที่ / ผู้ลงนาม" จัดกึ่งกลางตามแบบราชการ ── */
  .law-postamble {
    background: none; border: none; border-left: none;
    padding: 0; margin: 10mm 0 0;
    font-size: 14pt; color: #000;
    text-align: center; line-height: 1.5;
    break-inside: avoid;
  }

  .print-endnote {
    margin-top: 12mm; padding-top: 3mm;
    border-top: .5pt solid #999;
    font-size: 11pt; color: #333;
    text-align: center; line-height: 1.5;
    text-indent: 0;
    break-inside: avoid;
  }
}
