/* styles.css — ระบบออกแบบตระกูล SRDI (IIM-D44 · D46 · D47)
   พื้นกระดาษอุ่น + เขียว SRDI เหมือน STAR / Service Mind / FISCAL / External Fund · ฟอนต์ Prompt (หัวข้อ) + Anuphan (เนื้อหา)
   ฟอนต์เก็บในระบบเอง (app/fonts/ — CSP font-src 'self') · ไม่มี inline style (CSP style-src 'self')
   หลัก: ป้ายสถานะต้องดูต่างจากปุ่ม (GOV.UK task list) · ตัวอักษรบนจอขั้นต่ำ 14px · ทุกปุ่ม/ลิงก์มี hover + focus
   ข้อความ/ข้อเสนอของ AI = โทนฟ้า + เส้นประ (ยังไม่ใช่ค่าที่อนุมัติ) · ไม่ใช้ม่วงไล่เฉด/อีโมจิ */

@font-face { font-family: "Anuphan"; font-style: normal; font-weight: 400; font-display: swap; src: url("/fonts/anuphan-thai-400-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Anuphan"; font-style: normal; font-weight: 400; font-display: swap; src: url("/fonts/anuphan-latin-400-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Anuphan"; font-style: normal; font-weight: 600; font-display: swap; src: url("/fonts/anuphan-thai-600-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Anuphan"; font-style: normal; font-weight: 600; font-display: swap; src: url("/fonts/anuphan-latin-600-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Prompt"; font-style: normal; font-weight: 500; font-display: swap; src: url("/fonts/prompt-thai-500-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Prompt"; font-style: normal; font-weight: 500; font-display: swap; src: url("/fonts/prompt-latin-500-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Prompt"; font-style: normal; font-weight: 600; font-display: swap; src: url("/fonts/prompt-thai-600-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Prompt"; font-style: normal; font-weight: 600; font-display: swap; src: url("/fonts/prompt-latin-600-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

/* ชุดสีสว่าง (ค่าเริ่มต้น) — .doc ใช้ชุดนี้เสมอ: เอกสาร Step-1 Pack เป็น "กระดาษ" สว่างแม้เปิดโหมดมืด */
:root, .doc {
  /* พื้นผิว */
  --paper: #faf8f3; --surface: #ffffff; --surface-2: #f6f4ee; --surface-3: #efece3;
  --line: #e6e3d8; --line-strong: #d4cfc0;
  --hover: #fcfbf7; --topbar-bg: rgba(253, 252, 248, .94); --proposal-bg: #f7fafc; --mark: #fbe7a6; --skel-hi: #f7f5ee;
  /* ตัวอักษร */
  --ink: #222831; --ink-2: #5d6673; --ink-3: #8b95a3;
  /* สีหลัก (เขียว SRDI) */
  --green: #1d7a4f; --green-hover: #17663f; --green-2: #2e9e6b; --green-ink: #155c3b; --green-soft: #e4f4ec; --green-line: #cbe7d8;
  --deep: #31473f; --accent: #1d7a4f;
  /* สถานะ */
  --amber-ink: #8a5a00; --amber-soft: #fcf1de; --amber-line: #f0d9a8;
  --red: #b3382f; --red-ink: #a3302a; --red-soft: #fbe9e5; --red-line: #f1c9c1;
  --blue-ink: #1c5f8c; --blue-soft: #e8f2f9; --blue-line: #c6dcec; --ai-mark: #1c5f8c;
  --gray-ink: #4a525c; --gray-soft: #efede6;
  /* ป้ายลอย/แท็บที่เลือก (พื้นเข้ม ตัวอักษรสว่าง) */
  --float-bg: #222831; --float-ink: #ffffff; --tab-track: rgba(34, 40, 49, .06);
  /* รูปทรง */
  --r: 14px; --r-sm: 10px; --r-xs: 6px;
  --sh: 0 1px 2px rgba(60, 54, 40, .04), 0 2px 10px rgba(60, 54, 40, .05);
  --sh-2: 0 8px 26px rgba(60, 54, 40, .12);
  --ring: 0 0 0 3px rgba(29, 122, 79, .28);
  --font: "Anuphan", "Leelawadee UI", "Tahoma", "Noto Sans Thai", sans-serif;
  --font-head: "Prompt", "Anuphan", "Leelawadee UI", "Tahoma", sans-serif;
  --mono: "Cascadia Mono", Consolas, "Courier New", monospace;
  --maxw: 1240px;
  color-scheme: light;
}
:root { font-family: var(--font); color: var(--ink); background: var(--paper); }

/* ชุดสีมืด (S18 · IIM-D49) — ui/theme-init.js ตั้ง data-theme จากปุ่มสลับที่หัว (จำในเครื่อง) หรือค่าระบบของเครื่อง · เฉพาะบนจอ: ตอนพิมพ์สว่างเสมอ */
@media screen {
  :root[data-theme="dark"] {
    --paper: #121614; --surface: #1a201d; --surface-2: #212824; --surface-3: #2a322d;
    --line: #2e3833; --line-strong: #43504a;
    --hover: #222a26; --topbar-bg: rgba(22, 27, 24, .94); --proposal-bg: #17222b; --mark: #6b5414; --skel-hi: #333c37;
    --ink: #e6ebe7; --ink-2: #aab5ae; --ink-3: #7f8c84;
    --green: #1d7a4f; --green-hover: #23905d; --green-2: #3fb57f; --green-ink: #86d6ab; --green-soft: #173326; --green-line: #2a5b41;
    --deep: #a9cfbd; --accent: #3fb57f;
    --amber-ink: #f0c470; --amber-soft: #3a2e14; --amber-line: #5c4a22;
    --red: #c24a40; --red-ink: #f3a197; --red-soft: #3d201d; --red-line: #66332d;
    --blue-ink: #93c8ec; --blue-soft: #15283a; --blue-line: #284a66; --ai-mark: #2b6ea0;
    --gray-ink: #c6cec9; --gray-soft: #29312d;
    --float-bg: #e6ebe7; --float-ink: #121614; --tab-track: rgba(230, 235, 231, .08);
    --sh: 0 1px 2px rgba(0, 0, 0, .3), 0 2px 10px rgba(0, 0, 0, .25);
    --sh-2: 0 8px 26px rgba(0, 0, 0, .45);
    --ring: 0 0 0 3px rgba(63, 181, 127, .4);
    color-scheme: dark;
  }
}
.doc { color: var(--ink); color-scheme: light; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; display: flex; flex-direction: column; font-size: 16px; line-height: 1.65; background: var(--paper); color: var(--ink); }
h1, h2, h3 { font-family: var(--font-head); font-weight: 600; line-height: 1.35; color: var(--ink); }
h3 { font-size: 1.02rem; margin: 18px 0 6px; }
a { color: var(--green-ink); text-underline-offset: 3px; }
a:hover { color: var(--green); }
p { margin: 6px 0; }
ul, ol { padding-left: 1.4em; }
li { margin: 2px 0; }
.muted { color: var(--ink-2); }
.small { font-size: .875rem; }
.err { color: var(--red-ink); }
.okc { color: var(--green-ink); }
.warnc { color: var(--amber-ink); }
.mono { font-family: var(--mono); font-size: .875rem; word-break: break-all; }
.grow { flex: 1 1 auto; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* โฟกัสด้วยแป้นพิมพ์ — ทุกองค์ประกอบที่กดได้ */
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
button:focus-visible, .btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; box-shadow: var(--ring); }

/* ---------------- แถบบน ---------------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--topbar-bg); backdrop-filter: saturate(1.4) blur(8px); border-bottom: 1px solid var(--line); }
.topbar-in { max-width: var(--maxw); margin: 0 auto; padding: 10px 24px; display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); }
.brand:hover { color: var(--ink); }
.brandmark { width: 38px; height: 38px; border-radius: 11px; background: var(--green); color: #fff; display: grid; place-items: center; font-family: var(--font-head); font-weight: 600; font-size: .95rem; letter-spacing: .02em; flex: none; }
.brandtext { display: flex; flex-direction: column; line-height: 1.25; }
.brandtext strong { font-family: var(--font-head); font-weight: 600; font-size: 1.12rem; }
.brandtext strong .accent { color: var(--accent); }
.brandtext > span { font-size: .875rem; color: var(--ink-2); }
.topright { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.user { font-size: .875rem; color: var(--ink-2); padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.user b { color: var(--ink); font-weight: 600; }

/* ตัวเลือกพื้นที่ข้อมูล */
.badge { display: inline-flex; align-items: center; border-radius: 999px; font-size: .875rem; background: var(--gray-soft); color: var(--ink); border: 1px solid transparent; }
.badge.test { background: var(--amber-soft); color: var(--amber-ink); border-color: var(--amber-line); }
.badge.research { background: var(--green-soft); color: var(--green-ink); border-color: var(--green-line); }
.badge select { background: transparent; border: 0; font: inherit; font-weight: 600; color: inherit; padding: 5px 10px; min-height: 0; width: auto; cursor: pointer; border-radius: 999px; }
.badge select:focus-visible { box-shadow: var(--ring); }

.spacestrip { font-size: .875rem; }
.spacestrip-in { max-width: var(--maxw); margin: 0 auto; padding: 5px 24px; display: flex; align-items: center; gap: 8px; }
.spacestrip.test { background: var(--amber-soft); color: var(--amber-ink); border-bottom: 1px solid var(--amber-line); }
.spacestrip.research { background: var(--green-soft); color: var(--green-ink); border-bottom: 1px solid var(--green-line); }
.spacestrip .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.spacestrip.demo .spacestrip-in { flex-wrap: wrap; row-gap: 2px; }
.spacestrip.demo a { color: inherit; font-weight: 600; }

/* แถบความคืบหน้าบนสุด (S5) — ขึ้นเมื่อมีคำขอค้างเกิน ~0.15 วินาที */
.progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 50; pointer-events: none; opacity: 0; transition: opacity .2s; overflow: hidden; }
.progress::before { content: ""; position: absolute; top: 0; bottom: 0; left: -40%; width: 40%; background: var(--green-2); border-radius: 2px; animation: progress-slide 1.1s ease-in-out infinite; }
body.is-loading .progress { opacity: 1; }
@keyframes progress-slide { 0% { left: -40%; } 100% { left: 100%; } }

/* ---------------- แถบขั้นตอน ①–④ + เครื่องมือ (S6) ---------------- */
.navwrap { background: var(--surface); border-bottom: 1px solid var(--line); }
.conveyor { max-width: var(--maxw); margin: 0 auto; padding: 12px 24px; display: flex; gap: 16px; align-items: stretch; overflow-x: auto; }
.steps { display: flex; flex: 1 1 auto; gap: 0; min-width: 640px; counter-reset: step; }
.step { flex: 1 1 0; position: relative; display: flex; gap: 10px; align-items: flex-start; padding: 8px 12px 10px; text-decoration: none; color: var(--ink); border-radius: var(--r-sm); min-width: 0; }
.step::after { content: ""; position: absolute; top: 22px; right: -2px; width: 4px; height: 4px; border-radius: 50%; background: var(--line-strong); }
.step:last-child::after { display: none; }
.step:hover { background: var(--surface-2); color: var(--ink); }
.step .num { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-family: var(--font-head); font-weight: 600; font-size: .9rem; border: 1.5px solid var(--line-strong); color: var(--ink-2); background: var(--surface); margin-top: 1px; }
.step .txt { display: flex; flex-direction: column; min-width: 0; }
.step .t { font-family: var(--font-head); font-weight: 500; font-size: .98rem; line-height: 1.35; }
.step .s { font-size: .875rem; color: var(--ink-2); line-height: 1.4; }
.step .count { margin-top: 4px; align-self: flex-start; }
.step.active { background: var(--green-soft); box-shadow: inset 0 -3px 0 var(--green); }
.step.active .num { background: var(--green); border-color: var(--green); color: #fff; }
.step.active .t { color: var(--green-ink); font-weight: 600; }
.tools { display: flex; flex-direction: column; justify-content: center; gap: 2px; padding-left: 16px; border-left: 1px solid var(--line); flex: none; }
.tool { display: inline-flex; align-items: center; gap: 8px; padding: 5px 10px; border-radius: var(--r-xs); color: var(--ink-2); text-decoration: none; font-size: .9rem; white-space: nowrap; }
.tool:hover { background: var(--surface-2); color: var(--ink); }
.tool.active { color: var(--green-ink); background: var(--green-soft); font-weight: 600; }

/* ไอคอนเส้น (SVG สร้างด้วย DOM — ไม่ใช้อีโมจิ) */
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }

/* ---------------- โครงหน้า ---------------- */
main { flex: 1; padding: 24px; max-width: var(--maxw); width: 100%; margin: 0 auto; }
main:focus { outline: none; }
.pagehead { margin: 0 0 18px; display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.pagehead h1 { font-size: 1.5rem; margin: 0; }
.pagehead p { margin: 2px 0 0; color: var(--ink-2); max-width: 70ch; }
.pagehead .eyebrow { font-size: .875rem; color: var(--green-ink); font-weight: 600; margin: 0 0 2px; }
.foot { border-top: 1px solid var(--line); background: var(--surface); }
.foot-in { max-width: var(--maxw); margin: 0 auto; padding: 10px 24px; display: flex; justify-content: space-between; gap: 12px; font-size: .875rem; color: var(--ink-2); flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 20px; margin-bottom: 16px; box-shadow: var(--sh); }
.card h2 { margin: 0 0 6px; font-size: 1.15rem; }
.card > h2 + p { margin-top: 0; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-between > h2 { margin-bottom: 0; }
.btnrow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.btnrow > input, .btnrow > select { width: auto; flex: 1 1 220px; min-width: 0; max-width: 100%; }
.s1grid { display: grid; grid-template-columns: minmax(280px, 1fr) 2.3fr; gap: 18px; align-items: start; }
/* แถบซ้ายติดจอขณะเลื่อน + เลื่อนในตัวเองเมื่อรายการยาวกว่าจอ (กันส่วนล่างของรายการมองไม่เห็น) */
.col-left { position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow-y: auto; overscroll-behavior: contain; border-radius: var(--r); }
.col-left > .card:last-child { margin-bottom: 0; }
@media (max-width: 960px) { .s1grid { grid-template-columns: 1fr; } .col-left { position: static; max-height: none; overflow: visible; } }
/* เครื่องมือวิจัย: ตารางกว้าง (คอลัมน์ผู้ประเมิน/ข้อ SUS) เลื่อนในกรอบตาราง — ไม่ดันคอลัมน์ขวาจนหน้าเลื่อนด้านข้าง */
.rtgrid > * { min-width: 0; }
.rtgrid td.rtname { min-width: 12em; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 12px; }
@media (max-width: 720px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.twrap { overflow-x: auto; }
.usertbl td { white-space: nowrap; } /* ตารางผู้ใช้ (S32): จอแคบให้เลื่อนข้างแทนการหักรหัส/ปุ่มเป็นหลายบรรทัด */

/* ---------------- ปุ่ม ---------------- */
button, .btn { font: inherit; font-weight: 600; font-size: .95rem; line-height: 1.3; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px; border-radius: var(--r-sm); border: 1px solid var(--green); background: var(--green); color: #fff; cursor: pointer; text-decoration: none;
  transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s; }
button:hover, .btn:hover { background: var(--green-hover); border-color: var(--green-hover); color: #fff; }
button:active, .btn:active { transform: translateY(1px); }
button.secondary, .btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
button.secondary:hover, .btn.secondary:hover { background: var(--surface-2); border-color: var(--ink-3); color: var(--ink); }
button.danger:not(.secondary) { background: var(--red); border-color: var(--red); }
button.danger:not(.secondary):hover { background: #962e27; border-color: #962e27; }
button.secondary.danger { color: var(--red-ink); border-color: var(--red-line); }
button.secondary.danger:hover { background: var(--red-soft); border-color: var(--red); color: var(--red-ink); }
button.ghost { background: transparent; border-color: transparent; color: var(--green-ink); padding: 6px 10px; min-height: 34px; }
button.ghost:hover { background: var(--green-soft); color: var(--green-ink); }
button:disabled, button:disabled:hover { opacity: .5; cursor: not-allowed; transform: none; }
/* กำลังทำงาน (S10) — ปุ่มกดซ้ำไม่ได้จนกว่าระบบตอบ */
button.is-busy, button.is-busy:disabled { opacity: .75; cursor: progress; }
button.is-busy::after { content: ""; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- ช่องกรอก ---------------- */
input, select, textarea { font: inherit; font-size: 1rem; color: var(--ink); border: 1px solid var(--line-strong); border-radius: var(--r-sm); padding: 8px 12px; width: 100%; background: var(--surface); min-height: 40px; transition: border-color .15s, box-shadow .15s; }
textarea { line-height: 1.6; resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: var(--ink-3); }
input:focus, select:focus, textarea:focus { border-color: var(--green); }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; accent-color: var(--green); }
input[type="file"] { padding: 6px; font-size: .9rem; }
input.pick { width: 18px; height: 18px; margin: 0 10px 0 0; flex: none; cursor: pointer; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.flabel { font-size: .9rem; font-weight: 600; color: var(--ink); }
.fhint { font-size: .875rem; color: var(--ink-2); line-height: 1.5; }
::placeholder { color: var(--ink-3); }

/* ---------------- ตาราง ---------------- */
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { border-bottom: 1px solid var(--line); padding: 9px 12px; text-align: left; vertical-align: top; }
th { background: var(--surface-2); font-weight: 600; font-size: .875rem; color: var(--ink-2); }
table:not(.heat) tbody tr:hover td { background: var(--hover); } /* ตาราง heatmap ใช้สีบอกความหมาย — ห้ามทับตอนชี้เมาส์ */
table.kv th { width: 34%; background: transparent; color: var(--ink-2); font-weight: 600; }
table.kv td, table.kv th { padding: 6px 10px; }

/* ---------------- ป้ายสถานะ (ไม่ใช่ปุ่ม: ไม่มีเส้นขอบ ไม่มี hover) ---------------- */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 999px; font-size: .875rem; font-weight: 600; line-height: 1.6; background: var(--gray-soft); color: var(--gray-ink); white-space: nowrap; }
.st-rev, .st-ai { background: var(--amber-soft); color: var(--amber-ink); }
.st-ok { background: var(--green-soft); color: var(--green-ink); }
.st-bad { background: var(--red-soft); color: var(--red-ink); }
.st-info { background: var(--blue-soft); color: var(--blue-ink); }
.pill .tag-ai { font-family: var(--font-head); font-size: .75rem; letter-spacing: .03em; padding: 0 5px; border-radius: 4px; background: var(--ai-mark); color: #fff; line-height: 1.5; }
.badges { display: inline-flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.count { display: inline-flex; align-items: center; gap: 4px; padding: 1px 9px; border-radius: 999px; font-size: .875rem; font-weight: 600; background: var(--amber-soft); color: var(--amber-ink); white-space: nowrap; line-height: 1.6; }
.swot-S { background: var(--green-soft); color: var(--green-ink); } .swot-W { background: var(--red-soft); color: var(--red-ink); }
.swot-O { background: var(--blue-soft); color: var(--blue-ink); } .swot-T { background: var(--amber-soft); color: var(--amber-ink); }

/* ---------------- ข้อความแจ้ง ---------------- */
.notice { padding: 10px 14px; border-radius: var(--r-sm); margin: 10px 0; border: 1px solid; border-left-width: 4px; }
.notice-ok { background: var(--green-soft); border-color: var(--green-line); border-left-color: var(--green); color: var(--green-ink); }
.notice-err { background: var(--red-soft); border-color: var(--red-line); border-left-color: var(--red); color: var(--red-ink); }
.notice-warn { background: var(--amber-soft); border-color: var(--amber-line); border-left-color: #c98a12; color: var(--amber-ink); }
.notice ul { margin: 6px 0 0; }

/* ---------------- รายการเลือก (แหล่ง/ปัจจัย/Pack) ---------------- */
.srclist { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; padding: 2px; }
button.srcitem { text-align: left; align-items: stretch; justify-content: flex-start; flex-direction: column; gap: 3px; width: 100%; font-weight: 400; font-size: 1rem;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px 12px; min-height: 0; margin: 0 0 8px; }
.srclist > button.srcitem { margin: 0; }
button.srcitem:hover { background: var(--hover); border-color: var(--green-line); color: var(--ink); }
button.srcitem.active { background: var(--green-soft); border-color: var(--green); box-shadow: inset 3px 0 0 var(--green); color: var(--ink); }
.srctitle { font-weight: 600; line-height: 1.45; }
.evitem, .card { scroll-margin-top: 84px; } /* ปุ่มรายการถัดไปเลื่อนมาแล้วไม่ถูกหัวจอบัง */
.pickrow { display: flex; align-items: flex-start; gap: 0; }
.pickrow > input.pick { margin-top: 14px; }
.pickrow > button.srcitem { flex: 1 1 0; min-width: 0; width: auto; }
.listhead { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.tabs { display: inline-flex; gap: 4px; padding: 4px; background: var(--tab-track); border-radius: 12px; flex-wrap: wrap; margin: 8px 0; }
.tabs button { background: transparent; border-color: transparent; color: var(--ink-2); font-weight: 500; min-height: 34px; padding: 4px 12px; border-radius: 9px; }
.tabs button:hover { background: var(--tab-track); color: var(--ink); }
.tabs button.on { background: var(--float-bg); color: var(--float-ink); }

/* ---------------- หลักฐาน / ข้อเสนอ ---------------- */
.evitem { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px 14px; margin: 10px 0; background: var(--surface); }
.evitem.pending { border-color: var(--amber-line); box-shadow: inset 3px 0 0 #d9a21b; }
.evitem.muted { background: var(--surface-2); }
.evitem .stmt { font-weight: 600; }
.evitem .meta { display: flex; gap: 6px 12px; flex-wrap: wrap; align-items: center; font-size: .875rem; color: var(--ink-2); margin-top: 4px; }
blockquote { margin: 8px 0; padding: 8px 12px; border-left: 3px solid var(--green-line); background: var(--surface-2); border-radius: 0 var(--r-xs) var(--r-xs) 0; white-space: pre-wrap; color: var(--ink); }
blockquote.ungrounded { border-left-color: var(--red); background: var(--red-soft); }
.pagetext { white-space: pre-wrap; background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--r-xs); padding: 10px 12px; max-height: 320px; overflow-y: auto; font-size: .95rem; }
mark { background: var(--mark); color: inherit; padding: 0 2px; border-radius: 3px; }
.editor { border-top: 1px dashed var(--line-strong); margin-top: 10px; padding-top: 8px; }
.aipanel { border: 1px solid var(--blue-line); background: var(--blue-soft); border-radius: var(--r-sm); padding: 12px 14px; margin: 10px 0 14px; }
.aipanel strong { color: var(--blue-ink); display: inline-flex; align-items: center; gap: 8px; }
.aimark { font-family: var(--font-head); font-weight: 600; font-size: .8125rem; letter-spacing: .04em; padding: 1px 6px; border-radius: 5px; background: var(--ai-mark); color: #fff; }
.proposal { background: var(--proposal-bg); border: 1px dashed var(--blue-line); border-radius: var(--r-xs); padding: 8px 10px; margin-top: 8px; }
.batchbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); margin: 8px 0; }
.batchbar input { width: auto; flex: 1 1 200px; }
.subrow { border-top: 1px solid var(--line); padding: 12px 0; }
.subrow:first-of-type { border-top: 0; }
.anchors { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
button.anchor { text-align: left; justify-content: flex-start; background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong); font-weight: 400; min-height: 0; padding: 7px 12px; }
button.anchor b { display: inline-grid; place-items: center; min-width: 36px; padding: 0 6px; border-radius: 6px; background: var(--surface-2); font-variant-numeric: tabular-nums; }
button.anchor:hover { background: var(--hover); border-color: var(--green-line); color: var(--ink); }
button.anchor.on { background: var(--green-soft); border-color: var(--green); box-shadow: inset 0 0 0 1px var(--green); color: var(--ink); }
button.anchor.on b { background: var(--green); color: #fff; }
.calc { position: sticky; bottom: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px 14px; margin: 12px 0; box-shadow: 0 -6px 18px rgba(60, 54, 40, .08); z-index: 2; }
.barrow { display: grid; grid-template-columns: 160px 1fr; gap: 10px; align-items: center; margin: 3px 0; }
.bar { display: block; height: 10px; background: var(--surface-3); border-radius: 5px; overflow: hidden; }
.bar .fill { display: block; height: 100%; border-radius: 5px; }
.fill.ok { background: var(--green-2); } .fill.mid { background: #d9a21b; } .fill.low { background: #d0574d; }
.evpick { max-height: 360px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 4px 10px; background: var(--surface); }
.evrow { display: flex; gap: 8px; align-items: flex-start; padding: 8px 0; border-bottom: 1px dashed var(--line); cursor: pointer; }
.evrow:last-child { border-bottom: 0; }
.evrow > span { display: flex; flex-direction: column; gap: 2px; }

/* รายละเอียดทางเทคนิค (S7 — metadata อยู่ใน inspector · PRD แถว UX) */
details { margin: 8px 0; }
details > summary { cursor: pointer; font-weight: 600; color: var(--ink); padding: 4px 0; list-style: none; display: inline-flex; align-items: center; gap: 6px; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: ""; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform .15s; margin-right: 2px; }
details[open] > summary::before { transform: rotate(45deg); }
details > summary:hover { color: var(--green-ink); }
details.tech > summary { font-weight: 500; font-size: .875rem; color: var(--ink-2); }
details.tech[open] { background: var(--surface-2); border-radius: var(--r-xs); padding: 4px 10px 8px; }
details.tech .techrow { font-size: .875rem; color: var(--ink-2); }
details.manual { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.facts { display: flex; flex-wrap: wrap; gap: 4px 18px; font-size: .9rem; color: var(--ink-2); margin: 4px 0 2px; }
.facts b { color: var(--ink); font-weight: 600; }

/* ---------------- ตรวจย้อน ---------------- */
.qa { display: grid; grid-template-columns: 2.2em 1fr; gap: 4px 10px; padding: 12px 0; border-top: 1px solid var(--line); }
.qa .qn { font-family: var(--font-head); font-weight: 600; color: var(--green-ink); }
.qa .qq { font-weight: 600; }
.qa .qans { white-space: pre-wrap; grid-column: 2; }
.qa.na .qq, .qa.na .qans { color: var(--ink-2); }
.refs { grid-column: 2; display: flex; gap: 6px; flex-wrap: wrap; }
.refs a.pill { text-decoration: none; }
.tracelink { display: inline-flex; align-items: center; gap: 4px; font-size: .875rem; text-decoration: none; color: var(--green-ink); white-space: nowrap; }
.tracelink:hover { text-decoration: underline; }

/* ---------------- สถิติ + heatmap ---------------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin: 10px 0; }
.tile { border: 1px solid var(--line); border-top: 3px solid var(--green-2); border-radius: var(--r-sm); padding: 10px 12px; background: var(--surface); }
.tile .tv { font-family: var(--font-head); font-size: 1.35rem; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; line-height: 1.3; }
.tile .tl { font-size: .875rem; color: var(--ink-2); }
.tile .chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 2px; }
.tile .chips .pill { font-variant-numeric: tabular-nums; }
table.heat { width: auto; margin: 10px 0; }
table.heat caption { caption-side: top; text-align: left; font-size: .875rem; color: var(--ink-2); padding-bottom: 6px; }
table.heat th, table.heat td { text-align: center; min-width: 2.6em; border: 1px solid var(--line); padding: 6px 8px; }
table.heat th.axis { font-weight: 600; color: var(--ink-2); background: var(--surface-2); }
table.heat th.corner { font-size: .875rem; line-height: 1.35; text-align: left; vertical-align: bottom; }
.hh { background: #f8d9d3; } .hm { background: #fbecc8; } .hl { background: #ddf0e5; }
table.swot td { width: 50%; border: 1px solid var(--line); }

/* ---------------- เอกสาร Step-1 Pack (A4 — รูปแบบทางการ) ---------------- */
.doc { max-width: 210mm; margin: 0 auto; background: #fff; }
.dochead { text-align: center; border-bottom: 2px solid var(--deep); padding-bottom: 10px; margin-bottom: 14px; }
.dochead h1 { font-size: 1.35rem; margin: 4px 0; color: var(--deep); }
.doc section { margin: 16px 0; }
.doc h2 { font-size: 1.1rem; color: var(--deep); border-left: 4px solid var(--deep); padding-left: 10px; }
.doc .lead { font-size: 1rem; line-height: 1.75; }
.insight { border-top: 1px solid var(--line); padding: 10px 0; }
.watermark { text-align: center; color: var(--red-ink); border: 2px dashed var(--red); border-radius: var(--r-xs); padding: 4px; font-weight: 600; }

/* ---------------- กำลังโหลด (S5) — โครงร่างแทนหน้าว่าง ---------------- */
.skel-wrap { display: grid; grid-template-columns: minmax(280px, 1fr) 2.3fr; gap: 18px; }
.skel-wrap.single { grid-template-columns: 1fr; }
@media (max-width: 960px) { .skel-wrap { grid-template-columns: 1fr; } }
.skel-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 20px; box-shadow: var(--sh); }
.skel { display: block; height: 14px; border-radius: 7px; margin: 10px 0; background: linear-gradient(90deg, var(--surface-3) 0%, var(--skel-hi) 50%, var(--surface-3) 100%); background-size: 200% 100%; animation: skel 1.2s ease-in-out infinite; }
.skel.h { height: 20px; width: 45%; margin-bottom: 16px; }
.skel.w60 { width: 60%; } .skel.w80 { width: 80%; } .skel.w40 { width: 40%; }
.skel.block { height: 64px; border-radius: var(--r-sm); }
@keyframes skel { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ---------------- ไปรายการรอตรวจถัดไป (S9) ---------------- */
.nextnav { position: fixed; right: 24px; bottom: 24px; z-index: 30; display: flex; align-items: center; gap: 4px; padding: 6px 6px 6px 14px; background: var(--float-bg); color: var(--float-ink); border-radius: 999px; box-shadow: var(--sh-2); font-size: .9rem; }
.nextnav button { min-height: 34px; padding: 4px 14px; border-radius: 999px; background: var(--green); border-color: var(--green); }
.nextnav button:hover { background: var(--green-2); border-color: var(--green-2); }
.nextnav.inline { position: static; box-shadow: none; background: var(--amber-soft); color: var(--amber-ink); margin: 8px 0 0; justify-content: space-between; }
.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0%, 30% { box-shadow: 0 0 0 4px rgba(217, 162, 27, .55); } 100% { box-shadow: 0 0 0 4px rgba(217, 162, 27, 0); } }

/* จอมือถือ (S17 · IIM-D49) — ตรวจด้วยการจำลอง 375 px: ไม่ล้นขอบ · หัวไม่กินจอ · ปุ่มกดด้วยนิ้วได้ */
@media screen and (max-width: 720px) { /* screen เท่านั้น — กระดาษ A4 กว้าง ~680 px ห้ามโดนกฎจอมือถือ (IIM-D46) */
  main { padding: 16px; }
  .topbar { position: static; } /* หัวสูงเมื่อขึ้นหลายบรรทัด — ไม่ให้ติดจอบังเนื้อหา */
  .topbar-in { padding-top: 8px; padding-bottom: 8px; gap: 8px; }
  .brandtext > span { display: none; }
  .topbar-in, .conveyor, .spacestrip-in, .foot-in { padding-left: 16px; padding-right: 16px; }
  .badge select { padding: 8px 12px; }
  .user { padding: 6px 10px; }
  .steps { min-width: 600px; }
  .pagehead h1 { font-size: 1.3rem; }
  .card { padding: 14px 16px; }
  .barrow { grid-template-columns: 120px 1fr; }
  .nextnav { right: 12px; bottom: 12px; }
  .nextnav.inline { flex-wrap: wrap; gap: 6px; }
  .tiles { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
}
@media screen and (max-width: 720px) {
  .doc table:not(.heat) { display: block; overflow-x: auto; } /* ตารางเอกสาร Pack เลื่อนแนวนอนในตัว (ตอนพิมพ์ไม่กระทบ) */
}

/* ---------------- ระบบสาธิต (docs/DEMO_MODE.md) — ใช้เฉพาะเมื่อ Worker ตั้ง APP_ENV=demo ---------------- */
.badge-text { padding: 5px 12px; font-weight: 600; }
.spacestrip.demo { font-weight: 600; }
button.linklike { background: transparent; border: 0; color: var(--green-ink); padding: 0; min-height: 0; font-size: inherit; text-decoration: underline; }
button.linklike:hover { background: transparent; border: 0; color: var(--green-ink); }
.quota { white-space: nowrap; }
label.check { display: flex; align-items: flex-start; gap: 8px; margin: 10px 0; font-weight: 600; cursor: pointer; }
label.check input[type="checkbox"] { width: auto; min-height: 0; margin-top: 6px; flex: none; }
.demo-notice ul { margin: 6px 0 0; padding-left: 20px; }
.pinform { max-width: 760px; margin: 0 auto; }
.pinform h1 { margin-top: 0; }
.samplelist { display: grid; gap: 8px; margin-top: 8px; }
button.sampleitem { text-align: left; align-items: stretch; justify-content: flex-start; flex-direction: column; gap: 3px; width: 100%; font-weight: 400; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}

@media print {
  .spacestrip, .progress, .nextnav { display: none !important; }
  .doc { box-shadow: none; border: 0; max-width: none; }
  .doc section.appendix { break-before: page; }
  .doc table { font-size: 10pt; }
  .card { box-shadow: none; }
  @page { size: A4; margin: 15mm; }
}
@media print { .topbar, .navwrap, .foot, .noprint, .pagehead { display: none !important; } :root, body { background: #fff; } main { padding: 0; } } /* :root ด้วย — ไม่งั้นพื้นครีมของหน้าเว็บติดไปทั้งแผ่นกระดาษ */
