/* แบบสอบถามงานวิจัย — ไม่เรียกไฟล์จากเว็บภายนอก (ฟอนต์ใช้ของเครื่องผู้ตอบ) */
:root {
  --paper: #f3f0e8;
  --card: #ffffff;
  --ink: #1d2327;
  --muted: #5d6670;
  --line: #d9d3c5;
  --accent: #17573f;
  --accent-soft: #e4efe9;
  --warn-bg: #fff4d6;
  --warn-ink: #6b4e00;
  --err-bg: #fde8e6;
  --err-ink: #8f1d14;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Sarabun", "TH Sarabun New", "Noto Sans Thai", "Leelawadee UI", "Thonburi", Tahoma, sans-serif;
  font-size: 17px;
  line-height: 1.75;
}
.wrap { max-width: 780px; margin: 0 auto; padding: 20px 16px 56px; }

.doc-head { padding: 8px 0 14px; }
.doc-head h1 { font-size: 1.32rem; line-height: 1.5; margin: 0; text-align: center; text-wrap: balance; }
.version {
  width: max-content; margin: 0 0 14px auto; padding: 4px 12px;
  border: 1px solid var(--ink); font-size: .86rem; line-height: 1.5;
}

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 18px 18px 20px; margin: 0 0 16px;
}
.card h1 { font-size: 1.3rem; margin: 0 0 8px; }
.card h2 { font-size: 1.1rem; margin: 0 0 10px; padding-bottom: 8px; border-bottom: 2px solid var(--accent); }
.card h3 { font-size: 1.02rem; margin: 22px 0 6px; color: var(--accent); }
.card h4 { font-size: .98rem; margin: 14px 0 4px; }
.card p { margin: 0 0 10px; }
.intro p { text-indent: 1.6em; }
.intro .consent-note { text-indent: 0; font-weight: 600; margin-top: 14px; }
.instruction { color: var(--ink); }
.note, .muted { color: var(--muted); font-size: .94rem; }
.note { margin: 0 0 4px; }

.banner { border-radius: 8px; padding: 10px 14px; margin: 0 0 16px; font-weight: 600; }
.banner-preview { background: var(--warn-bg); color: var(--warn-ink); }
.banner-error { background: var(--err-bg); color: var(--err-ink); }

.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* ---- ช่องกรอก ---- */
.field { margin: 0 0 16px; }
.field > label, .choices legend { display: block; font-weight: 600; margin-bottom: 6px; padding: 0; }
input[type=text], input[type=number], input[type=password], textarea {
  width: 100%; font: inherit; color: inherit; background: #fff;
  border: 1px solid #b9b2a2; border-radius: 8px; padding: 9px 12px;
}
input.short { max-width: 140px; }
textarea { resize: vertical; min-height: 92px; }
input:focus-visible, textarea:focus-visible, .btn:focus-visible { outline: 3px solid #7fb39d; outline-offset: 1px; }

fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.choice-list { display: flex; flex-wrap: wrap; gap: 8px; }
.choice, .consent {
  display: inline-flex; align-items: flex-start; gap: 8px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; background: #fff;
}
.choice input, .consent input { width: 20px; height: 20px; margin: 4px 0 0; accent-color: var(--accent); flex: none; }
.choice:has(input:checked), .consent:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.consent { display: flex; font-weight: 600; margin-top: 6px; }

/* ---- มาตรประมาณค่า ---- */
.legend { list-style: none; margin: 0 0 10px; padding: 10px 14px; background: var(--accent-soft); border-radius: 8px; columns: 2; column-gap: 24px; font-size: .95rem; }
.legend li { break-inside: avoid; }
.item { border-top: 1px solid var(--line); padding: 12px 0 10px; break-inside: avoid; }
.stem { margin: 0 0 8px !important; }
.stem .no { font-variant-numeric: tabular-nums; color: var(--muted); margin-right: 2px; }
.scales { display: grid; gap: 8px 28px; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.scale legend { font-size: .9rem; color: var(--muted); margin-bottom: 4px; padding: 0; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { position: relative; cursor: pointer; }
.pill input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.pill span {
  display: grid; place-items: center; min-width: 44px; height: 44px; padding: 0 8px;
  border: 1.5px solid #b9b2a2; border-radius: 999px; background: #fff;
  font-weight: 600; font-variant-numeric: tabular-nums;
}
.item-worded .pill span { border-radius: 8px; padding: 0 12px; font-weight: 500; font-size: .95rem; }
.pill input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.pill input:focus-visible + span { outline: 3px solid #7fb39d; outline-offset: 2px; }

/* ---- ท้ายแบบสอบถาม ---- */
.closing .thanks, .done .thanks { font-weight: 600; text-align: center; margin-bottom: 2px; }
.closing .sign { text-align: center; margin: 0; }
.hint { color: var(--muted); font-size: .92rem; margin-top: 14px !important; text-align: center; }
.btn {
  display: block; width: 100%; max-width: 320px; margin: 12px auto 0; cursor: pointer;
  font: inherit; font-weight: 700; color: #fff; background: var(--accent);
  border: 0; border-radius: 10px; padding: 12px 20px;
}
.btn:disabled { background: #a9b3ad; cursor: not-allowed; }
.closing .muted { text-align: center; margin-top: 6px; }
.done { text-align: center; }

/* ---- หน้าผู้วิจัย ---- */
table.grid { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.grid th, table.grid td { border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: left; vertical-align: top; }
table.grid td.num { text-align: right; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; border-radius: 999px; padding: 0 10px; font-size: .85rem; white-space: nowrap; }
table.grid th { white-space: nowrap; }
.tag-open { background: var(--accent-soft); color: var(--accent); }
.tag-closed { background: var(--warn-bg); color: var(--warn-ink); }
a { color: var(--accent); }
.btn-small { display: inline-block; width: auto; margin: 0; padding: 6px 14px; font-size: .92rem; text-decoration: none; }

/* ---- หน้าผู้วิจัย: ผลการตอบ ---- */
.admin .wrap { max-width: 1180px; }
.admin-head { margin: 4px 0 14px; }
.admin-head h1 { font-size: 1.3rem; line-height: 1.5; margin: 0 0 2px; }
.admin-head .form-code { display: inline; margin-right: 6px; color: var(--accent); }
.crumb { margin: 0 0 6px; font-size: .94rem; }
.small { font-size: .86rem; }
.btn-ghost { background: #fff; color: var(--accent); border: 1.5px solid var(--accent); }
.login { max-width: 460px; margin: 40px auto; }
.remember { font-weight: 400; margin: 0 0 4px; }
.logout .btn { max-width: 200px; }

.form-cards { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); margin-bottom: 16px; }
.form-card { margin: 0; display: flex; flex-direction: column; }
.form-card .form-title { font-size: 1rem; line-height: 1.55; border: 0; padding: 0; margin: 2px 0 6px; }
.form-code { margin: 0 !important; display: flex; gap: 8px; align-items: center; }
.big-num { font-size: 2rem; font-weight: 700; line-height: 1.2; margin: 6px 0 2px !important; color: var(--accent); font-variant-numeric: tabular-nums; }
.big-num small { font-size: .95rem; font-weight: 500; color: var(--muted); }
.actions, .downloads { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: auto; padding-top: 8px; }
.link-line { margin: 10px 0 0 !important; font-size: .82rem; word-break: break-all; }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9em; background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; }

.toolbar { display: grid; gap: 10px; }
.filter { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: end; }
.filter label { display: flex; flex-direction: column; font-size: .9rem; color: var(--muted); }
.filter input[type=date] { font: inherit; color: var(--ink); border: 1px solid #b9b2a2; border-radius: 8px; padding: 6px 10px; background: #fff; }
.toolbar .big-num { margin: 0 !important; }
.downloads { padding-top: 0; }

.tabs { display: flex; gap: 4px; margin: 0 0 12px; border-bottom: 2px solid var(--line); overflow-x: auto; }
.tabs a { padding: 8px 16px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tabs a[aria-current=page] { color: var(--accent); border-bottom-color: var(--accent); }

.freq-grid { display: grid; gap: 14px 28px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.freq h3 { margin: 0 0 4px; font-size: .98rem; color: var(--ink); }
table.compact th, table.compact td { padding: 4px 6px; }
.bar-col { width: 34%; }
meter { width: 100%; height: 12px; }
meter::-webkit-meter-bar { background: var(--accent-soft); border: 0; border-radius: 6px; }
meter::-webkit-meter-optimum-value { background: var(--accent); border-radius: 6px; }
meter::-moz-meter-bar { background: var(--accent); border-radius: 6px; }

.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.scroll.tall { max-height: 70vh; overflow: auto; }
table.stats th.c { text-align: center; }
table.stats td:first-child { min-width: 280px; }
table.stats .no { color: var(--muted); font-variant-numeric: tabular-nums; }
table.stats .interp { white-space: nowrap; color: var(--muted); font-size: .9rem; }
table.stats .freq-cell { color: var(--muted); }
table.grid th.num { text-align: right; }
tr.row-h1 td { background: var(--accent-soft); font-weight: 700; }
tr.row-h2 td { background: #f7f5ef; font-weight: 600; }
tr.row-total td { border-top: 2px solid var(--accent); font-weight: 700; }
table.raw { font-size: .85rem; }
table.raw th { position: sticky; top: 0; background: #fff; z-index: 1; }
table.raw td, table.raw th { white-space: nowrap; }
table.raw .sticky { position: sticky; left: 0; background: #fff; z-index: 2; }
.nowrap { white-space: nowrap; }
.pager { display: flex; gap: 16px; justify-content: center; margin-top: 10px; }
ol.answers { margin: 0; padding-left: 1.6em; }
ol.answers li { padding: 8px 0; border-bottom: 1px solid var(--line); }
ol.answers li p { margin: 0 !important; }

@media (max-width: 520px) {
  body { font-size: 16px; }
  .card { padding: 14px 14px 16px; }
  .legend { columns: 1; }
  .pill span { min-width: 46px; height: 46px; }
}

/* ---- พิมพ์/บันทึกเป็น PDF เพื่อเสนอคณะกรรมการ ---- */
@media print {
  body { background: #fff; font-size: 12pt; line-height: 1.5; }
  .wrap { max-width: none; padding: 0; }
  .card { border: 0; border-radius: 0; padding: 0; margin-bottom: 14pt; }
  .btn, .hint, .hp, .closing .muted { display: none !important; }
  .banner-preview { border: 1px solid #999; background: none; color: #000; }
  .pill span { min-width: 28pt; height: 22pt; border-color: #333; }
  .legend { background: none; border: 1px solid #999; }
  .item, .field { break-inside: avoid; }
  h2, h3, h4 { break-after: avoid; }
  .crumb, .filter, .downloads, .tabs, .pager, .logout { display: none !important; }
  .scroll, .scroll.tall { overflow: visible; max-height: none; }
  tr.row-h1 td, tr.row-h2 td { background: none; }
}
