/* VU CMS — ส่วนประกอบหน้าบ้านที่ทุก theme ใช้ร่วม
   theme ปรับหน้าตาด้วยตัวแปร (--primary, --border, --banner-h ...) หรือ selector ของตัวเอง */
:root {
    --primary: #6b1f7c; --accent: #f2a900; --text: #1f2430; --muted: #6b7280;
    --border: #e5e2ea; --surface: #f6f5f8; --radius: 10px;
    --banner-h: clamp(220px, 32vw, min(560px, 60vh));
}
*, *::before, *::after { box-sizing: border-box; }
img { max-width: 100%; height: auto; }
.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: 1rem; top: 1rem; background: #fff; padding: .5rem 1rem; z-index: 100; }
.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; }
.cms-menu { list-style: none; margin: 0; padding: 0; }

/* แบนเนอร์: แสดงทั้งภาพ + พื้นหลังเบลอ */
.cms-banner { position: relative; overflow: hidden; background: #111; }
.cms-banner__track { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scroll-behavior: smooth; scrollbar-width: none; }
.cms-banner__track::-webkit-scrollbar { display: none; }
.cms-banner__slide { flex: 0 0 100%; margin: 0; scroll-snap-align: start; position: relative; overflow: hidden; background: #1f1726; }
.cms-banner__slide::before { content: ""; position: absolute; inset: -40px; background: var(--bn-bg) center / cover no-repeat; filter: blur(28px) brightness(.8) saturate(1.1); }
.cms-banner__slide picture, .cms-banner__link { position: relative; z-index: 1; display: block; }
.cms-banner__slide img { display: block; width: 100%; height: var(--banner-h); object-fit: contain; }
.cms-banner__caption { position: absolute; left: 0; right: 0; bottom: 0; z-index: 2; padding: .55rem 1.25rem; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.65)); }
.cms-banner__nav { position: absolute; top: 50%; translate: 0 -50%; z-index: 3; width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255,255,255,.85); font-size: 1.6rem; line-height: 1; cursor: pointer; }
.cms-banner__nav--prev { left: 1rem; } .cms-banner__nav--next { right: 1rem; }

/* โมดูล */
.cms-block { margin-bottom: 1.25rem; }
.cms-block__title { margin: 0 0 .75rem; font-size: 1.1rem; }
.cms-post-list, .cms-category-list { list-style: none; margin: 0; padding: 0; }
.cms-post-list li { padding: .5rem 0; border-bottom: 1px solid var(--border); }
.cms-post-list time { display: block; font-size: .85rem; color: var(--muted); }
.cms-category-list li { padding: .3rem 0; }
.cms-category-list ul { list-style: none; padding-left: 1rem; margin: .25rem 0 0; }
.cms-embed { position: relative; aspect-ratio: 16 / 9; }
.cms-embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.cms-contact { font-style: normal; }
.cms-contact p { margin: 0 0 .4rem; }
.cms-social { list-style: none; margin: .75rem 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: .5rem; }
.cms-social a { display: inline-block; padding: .25rem .75rem; border: 1px solid currentColor; border-radius: 99px; font-size: .9rem; text-decoration: none; }

/* เนื้อหา */
.cms-content table { border-collapse: collapse; width: 100%; display: block; overflow-x: auto; }
.cms-content td, .cms-content th { border: 1px solid var(--border); padding: .5rem; }
.notice { background: #fff4d6; border: 1px solid #eed39c; padding: .5rem 1rem; border-radius: 6px; }
.empty { color: var(--muted); }
.attachments { margin-top: 2rem; padding: 1rem 1.25rem; background: var(--surface); border-radius: var(--radius); }

/* ค้นหา */
.cms-search { display: flex; gap: .5rem; }
.cms-search input { flex: 1; min-width: 0; font: inherit; padding: .55rem .8rem; border: 1px solid var(--border); border-radius: 8px; }
.cms-search button { font: inherit; padding: .55rem 1.1rem; border: 0; border-radius: 8px; background: var(--primary); color: var(--primary-on, #fff); cursor: pointer; }
.cms-search--large { max-width: 640px; margin-top: .75rem; }
.search-summary { color: var(--muted); margin: 1rem 0 1.5rem; }
.search-group { margin-bottom: 2rem; }
.search-item { padding: .9rem 0; border-bottom: 1px solid var(--border); }
.search-item h3 { margin: 0 0 .25rem; font-size: 1.1rem; }
.search-item h3 a { color: var(--primary-ink, var(--primary)); text-decoration: none; }
.search-item h3 a:hover { text-decoration: underline; }
.search-item p { margin: .2rem 0; }
.search-item__meta { font-size: .85rem; color: var(--muted); }
mark { background: #fff1c2; color: inherit; padding: 0 .1em; border-radius: 2px; }

/* แบ่งหน้า */
.pagination { display: flex; flex-wrap: wrap; gap: .35rem; list-style: none; padding: 0; margin: 1.5rem 0 0; }
.pagination li > a, .pagination li > span { display: block; min-width: 2.4rem; text-align: center; padding: .4rem .7rem; border: 1px solid var(--border); border-radius: 6px; text-decoration: none; color: var(--text); }
.pagination li.active > span { background: var(--primary); border-color: var(--primary); color: var(--primary-on, #fff); }
.pagination li.disabled > span { color: var(--muted); }

/* ปุ่ม hamburger ☰ -> ✕ (แสดงบนมือถือโดย theme) */
.nav-toggle { display: none; align-items: center; justify-content: center; gap: .55rem; min-width: 44px; min-height: 44px; padding: .5rem; background: transparent; border: 0; color: inherit; font: inherit; cursor: pointer; }
.nav-toggle__bars { position: relative; display: inline-block; width: 22px; height: 16px; flex: none; }
.nav-toggle__bars span { position: absolute; left: 0; width: 100%; height: 2px; border-radius: 2px; background: currentColor; transition: top .2s ease, transform .2s ease, opacity .15s ease; }
.nav-toggle__bars span:nth-child(1) { top: 0; }
.nav-toggle__bars span:nth-child(2) { top: 7px; }
.nav-toggle__bars span:nth-child(3) { top: 14px; }
.nav-toggle[aria-expanded="true"] .nav-toggle__bars span:nth-child(1) { top: 7px; transform: rotate(45deg); }
.nav-toggle[aria-expanded="true"] .nav-toggle__bars span:nth-child(2) { opacity: 0; }
.nav-toggle[aria-expanded="true"] .nav-toggle__bars span:nth-child(3) { top: 7px; transform: rotate(-45deg); }
/* ปุ่มกาง/พับเมนูย่อยบนมือถือ */
.submenu-toggle { display: none; align-items: center; justify-content: center; width: 44px; height: 44px; flex: none; background: transparent; border: 0; color: inherit; font-size: 1.1rem; cursor: pointer; }
.submenu-toggle span { display: inline-block; transition: transform .2s ease; }
.is-open > .submenu-toggle span { transform: rotate(180deg); }
@media (prefers-reduced-motion: reduce) {
    .nav-toggle__bars span, .submenu-toggle span { transition: none; }
}

/* เมนูในโมดูล (เช่น เมนูด้านข้าง): เมนูย่อยแบบพับ/กาง */
.cms-block--menu .cms-menu__item { display: flex; flex-wrap: wrap; align-items: center; }
.cms-block--menu .cms-menu__item > a, .cms-block--menu .cms-menu__label { flex: 1; min-width: 0; }
.cms-block--menu .cms-menu__label { cursor: pointer; }
.cms-block--menu .cms-menu__sub { display: none; width: 100%; list-style: none; margin: 0; padding: 0 0 .35rem 1rem; }
.cms-block--menu .is-open > .cms-menu__sub { display: block; }
.cms-block--menu .submenu-toggle { display: inline-flex; width: 36px; height: 36px; color: var(--muted); }
.cms-block--menu .submenu-toggle:hover { color: var(--primary-ink, var(--primary)); }

/* ไอคอนหน้าชื่อเมนู + เครื่องหมาย › ของเมนูย่อยที่ไม่มีไอคอน */
.cms-menu__icon { display: inline-block; width: 1.4em; margin-right: .3em; text-align: center; font-style: normal; }
.cms-menu__sub .cms-menu__item > a:not(:has(.cms-menu__icon))::before,
.cms-menu__sub .cms-menu__label:not(:has(.cms-menu__icon))::before {
    content: "›"; display: inline-block; width: 1em; margin-right: .35em; text-align: center; opacity: .55;
}

/* ปุ่ม "ดูข่าวทั้งหมด" และตัวกรองหมวดในหน้าข่าวทั้งหมด */
.section__more { margin: 1.25rem 0 0; text-align: right; }
.more-link { display: inline-block; padding: .5rem 1.15rem; border: 1px solid var(--primary); border-radius: 999px; color: var(--primary-ink, var(--primary)); text-decoration: none; font-size: .95rem; }
.more-link:hover { background: var(--primary); color: var(--primary-on, #fff); }
.more-link::after { content: ""; }
.news-filter { display: flex; flex-wrap: wrap; gap: .4rem .5rem; margin: .5rem 0 1.25rem; }
.news-filter a { padding: .25rem .8rem; border: 1px solid var(--border); border-radius: 999px; font-size: .9rem; text-decoration: none; color: var(--muted); }
.news-filter a:hover { border-color: var(--primary); color: var(--primary-ink, var(--primary)); }

/* โหมดแสดงตำแหน่ง (?show_positions=1 เห็นเฉพาะผู้ดูแล) */
.cms-pos { position: relative; outline: 2px dashed #8b5cf6; outline-offset: 3px; margin: 1.75rem 0 .75rem; min-height: 2.75rem; }
.cms-pos__label { position: absolute; top: -1.55rem; left: -3px; z-index: 40; background: #6d28d9; color: #fff; font: 600 12px/1.7 system-ui, sans-serif; padding: 0 .5rem; border-radius: 4px 4px 0 0; white-space: nowrap; }
.cms-pos__label code { font-size: 11px; opacity: .8; }
.cms-pos__label a { color: #fde68a; margin-left: .35rem; text-decoration: underline; }
.cms-pos--content { outline-color: #94a3b8; }
.cms-pos--content > .cms-pos__label { background: #475569; white-space: normal; }
.cms-pos__empty { margin: 0; padding: .8rem; font: 13px system-ui, sans-serif; color: #6d28d9; background: rgba(139, 92, 246, .07); }
.cms-posbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 9999; background: #1e1b4b; color: #fff; font: 14px system-ui, sans-serif; padding: .55rem 1rem; text-align: center; }
.cms-posbar a { color: #fde68a; margin-left: 1rem; }

/* แบนเนอร์: รูปแบบการแสดงภาพ (ตั้งที่กลุ่มแบนเนอร์) */
.cms-banner--cover .cms-banner__slide img { object-fit: cover; }
.cms-banner--cover .cms-banner__slide::before,
.cms-banner--natural .cms-banner__slide::before { display: none; }
.cms-banner--natural { background: transparent; }
.cms-banner--natural .cms-banner__track { align-items: flex-start; }
.cms-banner--natural .cms-banner__slide { background: transparent; }
.cms-banner--natural .cms-banner__slide img { height: auto; max-height: none; object-fit: initial; }
.cms-banner__link--zoom { cursor: zoom-in; }

/* ภาพขนาดเต็ม */
.cms-lightbox { position: fixed; inset: 0; z-index: 10000; display: grid; place-items: center; padding: 3.5rem 1rem 1rem; background: rgba(10, 12, 20, .88); cursor: zoom-out; }
.cms-lightbox img { max-width: min(100%, 1600px); max-height: calc(100vh - 5rem); width: auto; height: auto; border-radius: 4px; box-shadow: 0 12px 40px rgba(0, 0, 0, .45); cursor: default; }
.cms-lightbox__close { position: absolute; top: .75rem; right: 1rem; width: 44px; height: 44px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .15); color: #fff; font-size: 1.8rem; line-height: 1; cursor: pointer; }
.cms-lightbox__close:hover, .cms-lightbox__close:focus-visible { background: rgba(255, 255, 255, .3); }

/* ตัวเลื่อนแบนเนอร์ (เมื่อ JavaScript ทำงาน) */
.cms-banner.is-enhanced { overflow: hidden; }
.cms-banner.is-enhanced .cms-banner__track { overflow: visible; scroll-snap-type: none; scroll-behavior: auto; touch-action: pan-y; }
.cms-banner.is-slide .cms-banner__track { display: flex; will-change: transform; }
.cms-banner.is-fade .cms-banner__track { display: grid; }
.cms-banner.is-fade .cms-banner__slide {
    grid-area: 1 / 1; opacity: 0; visibility: hidden;
    transition: opacity var(--bn-speed, 600ms) ease, visibility 0s linear var(--bn-speed, 600ms);
}
.cms-banner.is-fade .cms-banner__slide.is-active { opacity: 1; visibility: visible; z-index: 1; transition: opacity var(--bn-speed, 600ms) ease, visibility 0s; }
.cms-banner__dots { position: absolute; left: 0; right: 0; bottom: .35rem; z-index: 3; display: flex; justify-content: center; }
.cms-banner__dot { width: 26px; height: 26px; padding: 0; border: 0; background: none; cursor: pointer; display: grid; place-items: center; }
.cms-banner__dot::before { content: ""; width: 9px; height: 9px; border-radius: 5px; background: rgba(255, 255, 255, .6); box-shadow: 0 0 0 1px rgba(0, 0, 0, .2); transition: width .25s ease, background .25s ease; }
.cms-banner__dot[aria-current="true"]::before { width: 22px; background: #fff; }
.cms-banner__dot:focus-visible { outline: 2px solid #fff; outline-offset: -4px; border-radius: 50%; }
.cms-banner.has-dots .cms-banner__caption { padding-bottom: 2rem; }
@media (prefers-reduced-motion: reduce) { .cms-banner__dot::before { transition: none; } }

/* หน้าเว็บที่ฝังด้วยโมดูล Embed (ความสูงปรับอัตโนมัติ) */
.cms-embed-site { display: block; width: 100%; max-width: 100%; border: 0; }

/* ---------- แถวรูปบุคลากร (ใช้ในโมดูล HTML / เนื้อหาหน้าเว็บ) ----------
   <div class="research-team">                     (หรือ class="cms-team")
     <div class="research-team-row single"> ...      single | two | three | four | five | six
       <div class="research-team-item"><img ...></div>
   แต่ละแถวจัดกลาง รูปในแถวเดียวกันกว้างเท่ากัน แถวที่มีคนน้อยรูปใหญ่กว่า (ทรงพีระมิด) */
.research-team, .cms-team { --team-gap: 14px; display: flex; flex-direction: column; align-items: center; gap: var(--team-gap); margin: 1.5rem 0; }
.research-team-row, .cms-team-row { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--team-gap); width: 100%; }
.research-team-item, .cms-team-item { flex: 0 0 auto; width: min(22%, 150px); }
.research-team-row.single > *, .cms-team-row.single > *,
.research-team-row.two > *, .cms-team-row.two > * { width: min(32%, 200px); }
.research-team-row.three > *, .cms-team-row.three > * { width: min(28%, 170px); }
.research-team-row.four > *, .cms-team-row.four > * { width: min(22.5%, 150px); }
.research-team-row.five > *, .cms-team-row.five > * { width: min(18%, 122px); }
.research-team-row.six > *, .cms-team-row.six > * { width: min(15%, 106px); }
.research-team-item img, .cms-team-item img {
    display: block; width: 100%; height: auto; margin: 0;
    border-radius: 4px; box-shadow: 0 2px 10px rgba(20, 24, 40, .14);
}
@media (max-width: 640px) {
    .research-team-row.single > *, .cms-team-row.single > *,
    .research-team-row.two > *, .cms-team-row.two > * { width: min(46%, 200px); }
    .research-team-row.three > *, .cms-team-row.three > *,
    .research-team-row.five > *, .cms-team-row.five > *,
    .research-team-row.six > *, .cms-team-row.six > * { width: calc((100% - 2 * var(--team-gap)) / 3); }
    .research-team-row.four > *, .cms-team-row.four > * { width: calc((100% - var(--team-gap)) / 2); }
}

/* เมนู "เพิ่มเติม ▾" (สร้างอัตโนมัติเมื่อเมนูหลักยาวเกิน 1 บรรทัด) */
.cms-menu__more > .cms-menu__label { cursor: pointer; white-space: nowrap; }
.cms-menu__more > .cms-menu__sub { left: auto; right: 0; }
.cms-menu__more .cms-menu__sub .cms-menu__sub { left: auto; right: 100%; }   /* เมนูย่อยชั้นถัดไปกางไปทางซ้าย ไม่ล้นจอ */
.main-nav .cms-menu__item { white-space: nowrap; }
.main-nav .cms-menu__sub .cms-menu__item { white-space: normal; }

/* สไลด์รูปในเนื้อหา (<div class="cms-slider">) */
.cms-slider-built { --banner-h: clamp(240px, 56vw, 560px); margin: 1.5rem 0; border-radius: 6px; }
.cms-slider__count { position: absolute; top: .6rem; right: .7rem; z-index: 3; padding: .1rem .6rem; border-radius: 999px; background: rgba(0, 0, 0, .55); color: #fff; font-size: .82rem; }
.cms-content .cms-slider:not(.cms-slider-built) img { max-width: 100%; height: auto; }   /* ก่อน JavaScript ทำงาน: รูปเรียงตามปกติ */

/* ---------- ส่วนของหน้า (บล็อกสำเร็จรูป) ----------
   theme ปรับได้ด้วยตัวแปร --primary / --border / --surface หรือ override view theme::sections.{type} */
.cms-sections { display: flex; flex-direction: column; gap: 2.25rem; margin-top: 1.5rem; }
.cms-sec__title { margin: 0 0 1rem; font-size: 1.35rem; color: var(--primary-ink, var(--primary)); }
/* โมดูลที่วางในหน้าเว็บ: ระยะห่างมาจาก .cms-sections แล้ว หัวข้อโมดูลใหญ่ขึ้นให้เข้ากับหัวข้อส่วนอื่น */
.cms-sec--block > .cms-block { margin-bottom: 0; }
.cms-sec--block > .cms-block > .cms-block__title { font-size: 1.35rem; color: var(--primary-ink, var(--primary)); margin-bottom: 1rem; }

/* รายการเอกสาร */
.cms-docs { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--border); }
.cms-docs__item { display: flex; gap: .9rem; align-items: flex-start; padding: .85rem .25rem; border-bottom: 1px solid var(--border); }
.cms-docs__icon {
    flex: 0 0 auto; width: 2.75rem; height: 3.1rem; display: grid; place-items: center;
    border-radius: 6px; background: var(--surface); color: var(--muted);
    font-size: .68rem; font-weight: 700; letter-spacing: .02em; border: 1px solid var(--border);
}
.cms-docs__icon--pdf { background: #fdecea; color: #b42318; border-color: #f6c7c1; }
.cms-docs__icon--doc, .cms-docs__icon--docx { background: #e8f0fd; color: #1849a9; border-color: #c4d7f7; }
.cms-docs__icon--xls, .cms-docs__icon--xlsx, .cms-docs__icon--csv { background: #e7f6ec; color: #087443; border-color: #bfe5cc; }
.cms-docs__icon--ppt, .cms-docs__icon--pptx { background: #fdf0e7; color: #b54708; border-color: #f7d4bb; }
.cms-docs__body { min-width: 0; flex: 1; }
.cms-docs__link { font-weight: 600; color: var(--primary-ink, var(--primary)); text-decoration: none; overflow-wrap: anywhere; }
.cms-docs__link:hover, .cms-docs__link:focus-visible { text-decoration: underline; }
.cms-docs__badge { display: inline-block; margin-left: .4rem; padding: .05rem .5rem; border-radius: 99px; background: var(--accent); color: var(--accent-on, #1f2430); font-size: .75rem; font-weight: 600; vertical-align: middle; }
.cms-docs__note { margin: .2rem 0 0; }
.cms-docs__meta { margin: .2rem 0 0; color: var(--muted); font-size: .85rem; }

/* บุคลากร: แถวจัดกึ่งกลาง (แถวหัวหน้าและแถวที่ไม่เต็ม) จำนวนคนต่อแถวลดตามความกว้างของพื้นที่เนื้อหาจริง */
.cms-people-group { container-type: inline-size; }
.cms-people-group + .cms-people-group { margin-top: 1.75rem; }
.cms-people-group__title { margin: 0 0 .9rem; font-size: 1.1rem; padding-bottom: .35rem; border-bottom: 2px solid var(--border); }
.cms-people {
    --cols: 4; --c: var(--cols); --gap: 1.25rem;
    list-style: none; margin: 0; padding: 0;
    display: flex; flex-wrap: wrap; justify-content: center; gap: 1.5rem var(--gap);
}
.cms-people + .cms-people { margin-top: 1.75rem; }
.cms-person { flex: 0 0 calc((100% - (var(--c) - 1) * var(--gap)) / var(--c)); max-width: 13rem; min-width: 0; text-align: center; }
.cms-people--lead .cms-person { max-width: 15rem; }
.cms-person__photo {
    display: block; width: 100%; aspect-ratio: 3 / 4; margin: 0 auto .6rem;
    object-fit: cover; border-radius: 8px; background: var(--surface); box-shadow: 0 2px 10px rgba(20, 24, 40, .12);
}
.cms-person__photo--empty { display: grid; place-items: center; font-size: 2.5rem; color: var(--muted); }
.cms-person__name { margin: 0; font-weight: 600; }
.cms-person__position { margin: .15rem 0 0; color: var(--muted); font-size: .92rem; }
.cms-person__contact { margin: .35rem 0 0; font-size: .85rem; display: flex; flex-direction: column; gap: .1rem; overflow-wrap: anywhere; }
.cms-person__contact a { color: var(--primary-ink, var(--primary)); }
@container (max-width: 640px) { .cms-people { --c: min(var(--cols), 3); --gap: 1rem; } }
@container (max-width: 420px) { .cms-people { --c: min(var(--cols), 2); --gap: .75rem; } }

/* รูปที่จัดกึ่งกลางใน Editor (margin-left/right: auto) ต้องเป็น block จึงจะกลางจริง */
.cms-content img[style*="margin-left:auto"], .cms-content img[style*="margin-left: auto"],
.cms-content img[style*="margin-right:auto"], .cms-content img[style*="margin-right: auto"] {
    display: block;
    max-width: 100%;
    height: auto;
}
