/* ============================================================
   ระบบนวัตกรรมบริการวิจัยภาคประชาชนด้วย AI — โปรโตไทป์
   ธีม: อ้างอิงเว็บหลัก tnrr.nriis.go.th (user-pinned)
   token ดึงจาก CSS จริงของเว็บหลัก:
   :root{--color-primary:#185587;--color-primary-light:#238ed1;
         --color-primary-extra-light:#6fa7ca;--color-primary-dark:#012340;
         --color-link-text:#238ed1;--color-text-grey-light:#919293;
         --font-default:"DB Heavent"}
   DB Heavent เป็นฟอนต์เชิงพาณิชย์ → ใช้ IBM Plex Sans Thai แทน (รอ license)
   ============================================================ */

:root {
  --color-primary: #185587;
  --color-primary-light: #238ed1;
  --color-primary-extra-light: #6fa7ca;
  --color-primary-dark: #012340;
  --color-link-text: #185587;         /* เข้มขึ้นจาก #238ed1 ของเว็บหลัก เพื่อ WCAG AA บนพื้นขาว (hover = light) */
  --color-text-grey-light: #6b7073;   /* คู่สี #919293 เดิม contrast ไม่ผ่าน AA */

  --text: #4d5156;
  --ink: #262626;
  --ground: #f4f5f6;
  --ground-2: #f1f2f3;
  --card: #fff;
  --line: #e4e5e6;
  --line-soft: #eaecee;
  --danger: #c50404;
  --ok: #1c7c43;
  --warn: #9a6a00;
  --ai: #0d6e6e;              /* เขียวครามใช้เฉพาะเครื่องหมาย "AI จัดให้" */
  --thairath: #1fa45b;        /* shell ทางรัฐ (mini app) */
  --thairath-deep: #0f7a3f;

  --grad-btn: linear-gradient(325deg, #012340, #185587 57%, #185587);
  --grad-hero: linear-gradient(135deg, #185587, #238ed1);
  --grad-band: linear-gradient(0deg, #fbfcff, #e0ecf3);

  --font-default: "IBM Plex Sans Thai", "DB Heavent", "Sarabun", sans-serif;
  --f-body: "IBM Plex Sans Thai", "DB Heavent", "Sarabun", sans-serif;
  --f-mono: "IBM Plex Mono", monospace;

  --shadow-sm: 0 1px 3px rgba(1, 35, 64, 0.10);
  --shadow-md: 0 4px 14px rgba(1, 35, 64, 0.12);
  --shadow-lg: 0 12px 34px rgba(1, 35, 64, 0.20);
  --r: 8px;
  --gutter: clamp(20px, 4vw, 56px);
  --maxw: 1240px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
body {
  margin: 0;
  font-family: var(--f-body);
  font-size: 16.5px;
  line-height: 1.65;
  color: var(--text);
  background: var(--ground);
}
img, svg { max-width: 100%; display: block; }
h1, h2, h3, h4 { color: var(--color-primary-dark); font-weight: 600; line-height: 1.3; margin: 0 0 .45em; text-wrap: balance; }
h2 { font-size: clamp(1.35rem, 2.2vw, 1.7rem); }
h3 { font-size: 1.12rem; }
p { margin: 0 0 1em; }
a { color: var(--color-link-text); text-underline-offset: 3px; }
a:hover { color: var(--color-primary-light); }

/* พื้นผิว browser-drawn — ออกแบบตามธีม (craft floor) */
::selection { background: rgba(35, 142, 209, .35); color: var(--color-primary-dark); }
:focus-visible { outline: 3px solid var(--color-primary-light); outline-offset: 2px; border-radius: 3px; }
* { scrollbar-color: #c3ccd2 transparent; }
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-thumb { background: #c3ccd2; border: 3px solid var(--ground); border-radius: 8px; }
input, textarea, select, button { font: inherit; color: inherit; }
u, .linklike { text-decoration-color: var(--color-primary-light); }

.skip-link {
  position: absolute; left: -999px; top: 8px; z-index: 100;
  background: var(--color-primary-dark); color: #fff;
  padding: 10px 18px; border-radius: var(--r);
}
.skip-link:focus { left: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; clip-path: inset(50%); overflow: hidden; white-space: nowrap; }

.wrap { max-width: var(--maxw); margin: 0 auto; padding-inline: var(--gutter); }

/* ---------- header (เทาขาวแบบเว็บหลัก แถบล่างเส้นน้ำเงิน) ---------- */
.site-head {
  background: #fff;
  border-bottom: 3px solid var(--color-primary);
  position: sticky; top: 0; z-index: 60;
  box-shadow: var(--shadow-sm);
}
.site-head .inner {
  max-width: var(--maxw); margin: 0 auto; padding: 12px var(--gutter);
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.brand-mark {
  width: 44px; height: 44px; flex: none; border-radius: 10px;
  background: var(--grad-hero); display: grid; place-items: center;
  box-shadow: var(--shadow-sm);
}
.brand-mark svg { width: 24px; height: 24px; stroke: #fff; }
.brand-name { font-weight: 700; font-size: 1.05rem; color: var(--color-primary-dark); line-height: 1.25; display: block; }
.brand-sub { font-size: .72rem; color: var(--color-text-grey-light); display: block; }
.site-head nav { margin-left: auto; display: flex; gap: 10px; flex-wrap: wrap; }
.nav-link-quiet {
  font-weight: 500; font-size: .92rem; color: var(--text);
  text-decoration: none; padding: 10px 12px; border-radius: 6px;
}
.nav-link-quiet:hover { color: var(--color-primary); background: var(--ground-2); }

/* ---------- ปุ่ม (pill gradient แบบเว็บหลัก) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  font-weight: 600; font-size: .95rem;
  padding: 10px 24px; border-radius: 25px;
  border: 1.5px solid transparent; cursor: pointer; text-decoration: none;
  transition: box-shadow .15s ease, transform .15s ease, background .15s ease, color .15s ease;
  background: var(--ground-2); color: var(--color-primary-dark);
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(0); }
.btn--primary { background: var(--grad-btn); color: #fff; }
.btn--primary:hover { color: #fff; box-shadow: 0 6px 18px rgba(24, 85, 135, .45); }
.btn--light { background: var(--color-primary-light); color: #fff; }
.btn--light:hover { color: #fff; background: #1a7fc0; }
.btn--outline { background: #fff; border-color: var(--color-primary-extra-light); color: var(--color-primary); }
.btn--outline:hover { background: #eef6fc; box-shadow: none; }
.btn--ghost { background: transparent; color: var(--color-primary); border-color: var(--line); }
.btn--ghost:hover { background: var(--ground-2); box-shadow: none; }
.btn--sm { padding: 6px 16px; font-size: .85rem; }
.btn[disabled], .btn[aria-disabled="true"] { background: var(--line); color: #9aa0a5; box-shadow: none; transform: none; cursor: not-allowed; }

/* ---------- การ์ด / แผง ---------- */
.board {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
  padding: 24px 26px;
  transition: box-shadow .16s ease, transform .16s ease;
}
.board:hover { box-shadow: var(--shadow-md); }
.board--accent { border-top: 3px solid var(--color-primary-light); }

/* ---------- search rail (pill ขาวเส้นน้ำเงิน) ---------- */
.rail {
  display: flex; align-items: stretch; gap: 10px;
  background: #fff;
  border: 2px solid var(--color-primary);
  border-radius: 32px;
  padding: 8px 8px 8px 24px;
  box-shadow: var(--shadow-lg);
}
.rail input[type="search"] {
  flex: 1; min-width: 0; border: 0; background: transparent;
  font-size: 1.1rem; padding: 10px 0;
}
.rail input[type="search"]:focus { outline: none; }
.rail input[type="search"]::placeholder { color: var(--color-text-grey-light); }
.rail input[type="search"] { caret-color: var(--color-primary-light); }
.btn-search-round {
  width: 56px; height: 56px; flex: none; border-radius: 50%;
  background: var(--color-primary-light);
  border: 0; display: grid; place-items: center; cursor: pointer;
  transition: background .15s ease, transform .15s ease;
}
.btn-search-round svg { width: 24px; height: 24px; stroke: #fff; }
.btn-search-round:hover { background: #1a7fc0; transform: scale(1.04); }
.btn-search-round:active { transform: scale(.97); }

.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 16px; background: #fff;
  border: 1px solid var(--line); border-radius: 20px;
  font-size: .85rem; color: var(--text); text-decoration: none; cursor: pointer;
  transition: border-color .12s ease, color .12s ease, background .12s ease;
}
.chip:hover { border-color: var(--color-primary-light); color: var(--color-primary); background: #f2f9ff; }
.chip svg { width: 14px; height: 14px; stroke: var(--color-primary-light); flex: none; }

/* แถบตีความคำถาม (TOR 4.6) */
.understand {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  font-size: .86rem; color: var(--color-text-grey-light);
  min-height: 34px;
}
.understand .u-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #eaf4fc; border: 1px solid #bfe0f6; color: var(--color-primary);
  border-radius: 16px; padding: 4px 13px;
  animation: pop-in .26s cubic-bezier(.16,1,.3,1) both;
}
.understand .u-chip b { color: var(--color-primary-dark); font-weight: 600; }
.understand .u-chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--color-primary-light); }
@keyframes pop-in { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- tabs แบบเว็บหลัก (.nav-tabs) ---------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.tab {
  font-weight: 500; font-size: .95rem; color: var(--text);
  padding: 9px 22px; margin: 0 2px;
  background: var(--ground-2);
  border: 0; border-bottom: 3px solid #e8e9ea;
  border-radius: 6px 6px 0 0; cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.tab:hover { color: var(--color-primary); background: #eef1f4; }
.tab[aria-selected="true"] {
  background: #fff; color: var(--color-primary-dark);
  font-weight: 700; border-bottom-color: var(--color-primary-light);
}

/* ---------- เครื่องหมาย AI ---------- */
.ai-tag {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: .74rem; font-weight: 600; letter-spacing: .02em;
  color: var(--ai); background: #e3f4f2;
  border: 1px solid #b9e2dd; border-radius: 14px; padding: 3px 11px;
}
.ai-tag::before {
  content: ""; width: 12px; height: 12px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M12 2l1.9 5.8L20 9.7l-5.4 3.4L16 19l-4-3.5L8 19l1.4-5.9L4 9.7l6.1-1.9z'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M12 2l1.9 5.8L20 9.7l-5.4 3.4L16 19l-4-3.5L8 19l1.4-5.9L4 9.7l6.1-1.9z'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* ---------- การ์ดผลงานวิจัย ---------- */
.proj { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 20px 24px 18px; box-shadow: var(--shadow-sm); }
.proj:hover { box-shadow: var(--shadow-md); }
.proj h3 { margin: 4px 0 8px; font-size: 1.1rem; }
.proj h3 a { color: var(--color-primary-dark); text-decoration: none; }
.proj h3 a:hover { color: var(--color-primary-light); text-decoration: underline; }
.proj .meta { display: flex; flex-wrap: wrap; gap: 5px 18px; font-size: .85rem; color: var(--text); margin-bottom: 10px; }
.proj .meta b { font-weight: 600; color: var(--color-primary-dark); }
.proj .abs { font-size: .94rem; color: var(--text); margin: 0 0 14px; }
.proj .foot { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }

.badge-trl {
  font-family: var(--f-mono); font-size: .73rem; font-weight: 600;
  padding: 3px 10px; border-radius: 4px;
  background: var(--ground-2); color: var(--color-primary-dark);
  font-variant-numeric: tabular-nums;
}
.badge-trl--hi { background: #e2f3e9; color: var(--ok); }
.badge-status {
  font-size: .73rem; font-weight: 600; padding: 3px 10px; border-radius: 4px;
  background: #eef6fc; color: var(--color-primary);
}
.api-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--f-mono); font-size: .69rem; color: var(--color-text-grey-light);
  border: 1px dashed var(--line); border-radius: 4px; padding: 2px 8px;
}
.api-chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }

/* การ์ดนักวิจัย */
.researcher {
  display: flex; gap: 16px; align-items: flex-start;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 18px 20px; box-shadow: var(--shadow-sm);
}
.avatar {
  width: 52px; height: 52px; flex: none; border-radius: 50%;
  background: var(--grad-hero); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 1.1rem;
}
.match { font-family: var(--f-mono); font-size: .78rem; font-weight: 600; color: var(--ok); }

/* ---------- layout ---------- */
.layout {
  display: grid; grid-template-columns: 272px minmax(0, 1fr);
  gap: 34px; align-items: start; padding-block: 28px 70px;
}
.rail-side { position: sticky; top: 84px; }
.panel { margin: 0 0 32px; }
.panel-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.panel-note { font-size: .84rem; color: var(--color-text-grey-light); }

/* ---------- ฟิลด์ ---------- */
.field { margin-bottom: 20px; }
.field > label, .field > .field-label { display: block; font-weight: 600; font-size: .85rem; color: var(--color-primary-dark); margin-bottom: 8px; }
select, .text-input, textarea.text-input {
  width: 100%; background: #fff;
  border: 1.5px solid var(--line); border-radius: 6px;
  padding: 9px 12px;
}
select:focus, .text-input:focus, textarea.text-input:focus { border-color: var(--color-primary-light); outline: 2px solid rgba(35,142,209,.25); }
.check { display: flex; align-items: center; gap: 9px; padding: 4px 0; font-size: .9rem; color: var(--text); cursor: pointer; }
.check input { accent-color: var(--color-primary-light); width: 17px; height: 17px; }

/* switch */
.switch-sticker { display: inline-flex; align-items: center; gap: 12px; font-weight: 600; cursor: pointer; color: var(--color-primary-dark); }
.switch-sticker input { position: absolute; opacity: 0; width: 60px; height: 30px; margin: 0; cursor: pointer; }
.switch-track {
  width: 60px; height: 30px; flex: none; border-radius: 999px;
  background: #d7dbde; position: relative; transition: background .18s ease;
}
.switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3);
  transition: left .18s cubic-bezier(.16,1,.3,1);
}
.switch-sticker input:checked + .switch-track { background: var(--color-primary-light); }
.switch-sticker input:checked + .switch-track::after { left: 33px; }
.switch-sticker input:focus-visible + .switch-track { outline: 3px solid var(--color-primary-light); outline-offset: 2px; }

/* ---------- ตาราง / กราฟ ---------- */
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line-soft); }
th { font-size: .78rem; color: var(--color-primary-dark); background: var(--ground-2); }
tr:hover td { background: #f6fafd; }
td.num { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }

/* ---------- แผนที่ ---------- */
.mapwrap { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 26px; }
.map-svg { width: 100%; height: auto; }
.map-svg .land { fill: #dbe9f4; stroke: var(--color-primary); stroke-width: 2; stroke-linejoin: round; }
.map-svg .hit { fill: transparent; cursor: pointer; }
.map-svg .hit:hover + .pin-num circle, .map-svg .region-active .pin-num circle { fill: var(--color-primary-light); }
.pin-num circle { fill: var(--color-primary-dark); stroke: #fff; stroke-width: 2; }
.pin-num text { fill: #fff; font-family: var(--f-mono); font-size: 13px; font-weight: 600; }
.legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: .82rem; color: var(--text); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }

/* ---------- sheet (gateway) ---------- */
.sheet-veil {
  position: fixed; inset: 0; z-index: 90; background: rgba(1, 35, 64, .55);
  display: grid; place-items: end center; animation: fade .2s ease both;
}
.sheet {
  width: min(620px, 100%); max-height: 92vh; overflow: auto;
  background: var(--card); border-radius: 18px 18px 0 0;
  padding: 28px 30px 36px; box-shadow: 0 -10px 40px rgba(0,0,0,.35);
  animation: rise .26s cubic-bezier(.2,1,.4,1) both;
}
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(40px); } }
.sheet textarea { min-height: 110px; resize: vertical; }

/* ---------- สถานะ ---------- */
.err { border: 1.5px solid #f0b6b6; border-radius: var(--r); background: #fdf1f1; padding: 16px 20px; color: #7a0606; }
.empty { text-align: center; padding: 42px 20px; border: 1.5px dashed var(--line); border-radius: var(--r); color: var(--color-text-grey-light); background: #fff; }

/* ---------- motion ลายเซ็น ---------- */
@keyframes card-in { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.pin-anim { animation: card-in .4s cubic-bezier(.2,1,.4,1) both; animation-delay: var(--d, 0ms); }
.skeleton { position: relative; overflow: hidden; background: #fff; border: 1px solid var(--line); border-radius: var(--r); }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(35,142,209,.12), transparent);
  transform: translateX(-100%); animation: shimmer 1.1s infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }
@keyframes stamp-in { 0% { transform: scale(1.6); opacity: 0; } 60% { transform: scale(.95); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }
.stamp--in { animation: stamp-in .35s cubic-bezier(.2,1,.4,1) both; }

/* ---------- footer (navy เว็บหลัก) ---------- */
.site-foot {
  background: var(--color-primary-dark); color: #b9c8d6;
  padding: 42px var(--gutter) 30px; font-size: .88rem; margin-top: 30px;
}
.site-foot a { color: #8ec6ee; }
.site-foot a:hover { color: #fff; }
.site-foot h4 { color: #fff; font-size: .95rem; margin-bottom: 10px; }
.site-foot .cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 30px; max-width: var(--maxw); margin: 0 auto; }

/* ---------- responsive (TOR 4.10: desktop+tablet) ---------- */
@media (max-width: 1020px) {
  .layout { grid-template-columns: 1fr; }
  .rail-side { position: static; display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
  .mapwrap { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  body { font-size: 16px; }
  .rail-side { grid-template-columns: 1fr; }
  .site-head nav { width: 100%; justify-content: flex-end; }
}
