/* กติกากลาง: ตารางข้อมูล (docs/PAGE-SHELL-RULES.md ข้อ 7 และ 7.7)
     <div class="msh-table-scroll"><table>…<thead>…</thead>…</table></div>
   ข้อ 7.7 (เจ้าของระบบ 27 พ.ย. 2569): ตารางในหน้าปกติ "ไม่มีกล่องเลื่อนแนวตั้งของตัวเอง" — ยาวตามจำนวนแถว ทั้งหน้าเป็นตัวเลื่อน
   - หัวคอลัมน์ติดใต้แถบเมนู (--msh-navbar-h) และใต้แถบปุ่ม [data-msh-toolbar] ที่อยู่เหนือตาราง · ระยะ = --msh-table-top (msh-table.js วัดให้)
   - กล่องเลื่อนเฉพาะแนวนอน เมื่อตารางกว้างเกินกล่อง (msh-table-wide) · พอดีกล่อง = msh-table-fits
   - โหมดกล่อง (เลื่อนแถวในกล่อง): เฉพาะตารางใน dialog หรือกล่องที่ใส่ data-msh-table-fit="box"
   ตัวกรอง: ปุ่ม data-msh-filter-toggle="#idของกล่องตัวกรอง" ใน msh-table.js ซ่อน/แสดงให้เอง */
.msh-table-scroll {
  position: relative;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  /* แนวนอนกันไว้ (ไม่ให้ปัดแล้วย้อนหน้า) · แนวตั้งไม่มีการเลื่อนในกล่อง หน้าเลื่อนเอง */
  overscroll-behavior-x: contain;
}
/* ตารางพอดีกล่อง: ไม่เป็นกล่องเลื่อน (clip ยังตัดมุมโค้งของกรอบได้) → หัวติดกับหน้าได้ด้วย CSS ล้วน */
.msh-table-scroll.msh-table-fits {
  overflow: clip;
}
.msh-table-scroll.msh-table-fits > table > thead th {
  top: calc(var(--msh-table-top, var(--msh-navbar-h, 68px)) + var(--msh-row-top, 0px));
}
/* ตารางกว้างเกินกล่อง: กล่องเป็นกล่องเลื่อนแนวนอน หัวติดกับหน้าด้วย CSS ไม่ได้ → เลื่อนหัวตามหน้า
   เบราว์เซอร์ที่รองรับ: scroll-driven animation (ลื่น ไม่กระตุก) · ที่เหลือ: msh-table.js ตั้ง --msh-head-shift */
.msh-table-scroll.msh-table-wide {
  view-timeline: --msh-table-box block;
  view-timeline-inset: var(--msh-table-top, var(--msh-navbar-h, 68px)) 0px;
}
.msh-table-scroll.msh-table-wide > table > thead th {
  transform: translateY(var(--msh-head-shift, 0px));
}
@supports (animation-timeline: view()) and (animation-range: exit-crossing 0% exit-crossing 100%) {
  .msh-table-scroll.msh-table-wide > table > thead th {
    transform: none;
    animation: msh-table-head-follow linear both;
    animation-timeline: --msh-table-box;
    animation-range: exit-crossing 0% exit-crossing 100%;
  }
}
@keyframes msh-table-head-follow {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(var(--msh-box-h, 0px));
  }
}
/* แถบเลื่อนแนวนอนติดขอบล่างจอ (msh-table.js ใส่ให้ตารางกว้างบนเครื่องที่แถบเลื่อนกินพื้นที่) · แถบเลื่อนจริงของกล่องอยู่ท้ายตารางจึงซ่อน */
.msh-table-scroll.msh-table-hbarred {
  scrollbar-width: none;
}
.msh-table-scroll.msh-table-hbarred::-webkit-scrollbar {
  display: none;
}
.msh-table-hbar {
  position: sticky;
  bottom: 0;
  z-index: 4;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
}
.msh-table-hbar > div {
  height: 1px;
}
.msh-table-hbar[hidden] {
  display: none;
}
/* แถบปุ่มเหนือตาราง ติดใต้แถบเมนูคู่กับหัวคอลัมน์ (msh-table.js ใส่คลาสให้ [data-msh-toolbar] ที่อยู่เหนือตาราง) */
.msh-toolbar-stick {
  position: sticky;
  top: var(--msh-navbar-h, 68px);
  z-index: 20;
  margin-bottom: 0 !important;
  padding-block: 6px;
  background: var(--msh-toolbar-bg, #fff);
}
/* โหมดกล่อง: ตารางใน dialog หรือ data-msh-table-fit="box" — สูงไม่เกิน --msh-table-max แล้วเลื่อนแถวในกล่อง หัวติดบนสุดของกล่อง */
/* :where() = น้ำหนักต่ำ สไตล์ของหน้าต่างลอยแต่ละหน้ากำหนดความสูงเองทับได้ */
:where(dialog, [role='dialog'], [data-msh-table-fit='box']) .msh-table-scroll,
.msh-table-scroll:where([data-msh-table-fit='box']),
.msh-table-scroll.msh-table-boxed {
  max-height: var(
    --msh-table-max,
    calc(100dvh - var(--msh-navbar-h, 68px) - var(--msh-table-gap, 12px))
  );
  overflow: auto;
  overscroll-behavior-y: auto;
}
/* หน้าแบบ legacy ตั้ง html,body { overflow-x: hidden } (style.css, system-layout.css) → body กลายเป็นกล่องเลื่อนที่ไม่ได้เลื่อนจริง
   หัวตาราง/แถบปุ่มที่ติด (sticky) จะอ้างอิง body แทนจอ เลยไม่ติดใต้แถบเมนู · หน้าที่มีตารางตามกติกาใช้ clip แทน (ตัดเหมือนเดิม แต่ไม่เป็นกล่องเลื่อน) */
html:has(.msh-table-scroll),
html:has(.msh-table-scroll) > body {
  overflow-x: clip;
  overflow-y: visible;
}
.msh-table-scroll > table {
  border-collapse: separate;
  border-spacing: 0;
}
.msh-table-scroll > table > thead th {
  position: sticky;
  top: 0;
  z-index: 3;
}
/* ปุ่มซ่อน/แสดงตัวกรอง (msh-table.js) */
.msh-filter-toggle[aria-expanded='false'] .msh-filter-toggle-icon {
  opacity: 0.6;
}
[data-msh-filters][hidden] {
  display: none !important;
}
@media print {
  .msh-table-scroll {
    position: static;
    max-height: none !important;
    overflow: visible !important;
  }
  .msh-table-scroll > table > thead th {
    position: static;
    transform: none !important;
    animation: none !important;
  }
  .msh-table-hbar {
    display: none;
  }
  .msh-toolbar-stick {
    position: static;
  }
}
/* แถวตัวกรอง: จอคอม (≥ 1024px) ช่องกรอก/ช่องค้นหาทุกช่องอยู่บรรทัดเดียวกัน · จอเล็กกว่านั้นตัดขึ้นบรรทัดใหม่ตามเดิม
   ใช้: <section id="filters" class="msh-filter-row" data-msh-filters> · ใส่ data-grow="2" ให้ช่องที่ต้องกว้างกว่า */
@media (min-width: 1024px) {
  .msh-filter-row {
    display: flex !important;
    flex-wrap: nowrap;
    align-items: end;
  }
  .msh-filter-row > * {
    flex: 1 1 0;
    min-width: 0;
    grid-column: auto !important;
  }
  .msh-filter-row > [data-grow='2'] {
    flex-grow: 2;
  }
}
/* ช่องค้นหาอัจฉริยะ (select-search.js .msh-ss ตั้ง flex: 1 1 220px ไว้สำหรับแถวแนวนอน) ที่อยู่ในช่องตัวกรองแบบซ้อนแนวตั้ง
   (ป้ายชื่อบน · ช่องล่าง) ค่า 220px จะกลายเป็น "ความสูง" ทำให้กล่องตัวกรองสูงผิดปกติ → ให้สูงตามเนื้อหา กว้างเต็มช่อง */
[data-msh-filters] label > .msh-ss,
[data-msh-filters] .lb-field > .msh-ss {
  flex: 0 0 auto;
  width: 100%;
}
/* ---- กติกาตาราง (เจ้าของระบบ 13 ต.ค. 2569): ทุกหัวคอลัมน์กดเรียงได้ · ติ๊กซ่อน/แสดงคอลัมน์ · จำตามผู้ใช้ (msh-table.js) ---- */
.msh-col-hidden {
  display: none !important;
}
/* หัวคอลัมน์ที่กดเรียงได้ (MshTable.enhance ห่อข้อความหัวคอลัมน์ด้วยปุ่มนี้) */
.msh-th-sort {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  width: 100%;
  min-height: 28px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: inherit;
  text-align: inherit;
  cursor: pointer;
}
.msh-th-sort:hover {
  color: #185fae;
}
.msh-th-sort:focus-visible {
  outline: 2px solid #2477d4;
  outline-offset: 2px;
  border-radius: 4px;
}
.msh-th-sort .msh-sort-icon {
  flex: 0 0 auto;
  margin-left: auto;
}
/* แถบเครื่องมือเหนือตาราง + ปุ่ม "คอลัมน์" */
.msh-table-tools {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin: 0 0 6px;
}
.msh-table-columns-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid #cfe0f2;
  border-radius: 10px;
  background: #f7fbff;
  color: #52627a;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}
.msh-table-columns-button .material-symbols-outlined {
  font-size: 19px;
}
.msh-table-columns-button:hover,
.msh-table-columns-button:focus-visible,
.msh-table-columns-button[aria-expanded='true'] {
  border-color: #9fc8f4;
  background: #eaf4ff;
  color: #185fae;
}
.msh-table-columns-button:focus-visible {
  outline: 3px solid rgba(36, 119, 212, 0.22);
  outline-offset: 2px;
}
/* เมนูลอยติ๊กคอลัมน์ (วางใต้ปุ่ม ไม่เกินขอบจอ เว้น 16px) */
.msh-table-columns-menu {
  position: fixed;
  z-index: 1200;
  width: min(260px, calc(100vw - 32px));
  overflow: auto;
  padding: 12px 14px;
  border: 1px solid #d6e4f5;
  border-radius: 14px;
  background: #fff;
  color: #344054;
  font-size: 0.8rem;
  box-shadow: 0 16px 40px rgba(16, 24, 40, 0.16);
}
.msh-table-columns-menu[hidden] {
  display: none;
}
.msh-table-columns-menu:focus {
  outline: none;
}
.msh-table-columns-menu h3 {
  margin: 0 0 8px;
  color: #17243a;
  font-size: 0.86rem;
  font-weight: 800;
}
.msh-table-columns-list {
  display: grid;
  gap: 2px;
}
.msh-table-columns-item {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 34px;
  padding: 4px 6px;
  border-radius: 8px;
  cursor: pointer;
}
.msh-table-columns-item:hover {
  background: #f3f8ff;
}
.msh-table-columns-item input {
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: #2477d4;
}
.msh-table-columns-grip {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 22px;
  height: 28px;
  margin: 0 -4px 0 -4px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #98a2b3;
  cursor: grab;
  touch-action: none;
}
.msh-table-columns-grip .material-symbols-outlined {
  font-size: 18px;
}
.msh-table-columns-grip:hover,
.msh-table-columns-grip:focus-visible {
  color: #185fae;
  background: #eaf4ff;
}
.msh-table-columns-grip:focus-visible {
  outline: 2px solid #2477d4;
  outline-offset: 1px;
}
.msh-table-columns-item.is-dragging {
  background: #eaf4ff;
  opacity: 0.85;
}
.msh-table-columns-item.drop-before {
  box-shadow: inset 0 2px 0 #2477d4;
}
.msh-table-columns-list.drop-end {
  box-shadow: inset 0 -2px 0 #2477d4;
}
.msh-table-columns-item.is-locked {
  color: #98a2b3;
  cursor: default;
}
.msh-table-columns-reset {
  margin-top: 8px;
  padding: 6px 10px;
  border: 1px solid #dce7f3;
  border-radius: 9px;
  background: #f8fbff;
  color: #185fae;
  font: inherit;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
}
.msh-table-columns-reset:hover,
.msh-table-columns-reset:focus-visible {
  background: #eaf4ff;
}
/* ตัวกรองที่หัวคอลัมน์ (กฎกลาง · เจ้าของระบบ 8 พ.ย. 2569) · แบบเดียวกับตารางคัดกรองมะเร็ง (ca-screen.css .cas-col-filter) */
.msh-row-filtered {
  display: none !important;
}
.msh-th-has-filter > .msh-th-sort {
  width: calc(100% - 24px);
  vertical-align: middle;
}
.msh-th-filter {
  display: inline-grid;
  width: 20px;
  height: 20px;
  margin-left: 4px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: inherit;
  vertical-align: middle;
  opacity: 0.4;
  cursor: pointer;
}
.msh-th-filter .material-symbols-outlined {
  font-size: 15px;
}
.msh-th-filter:hover,
.msh-th-filter:focus-visible,
th:hover > .msh-th-filter,
.msh-th-filter[aria-expanded='true'] {
  opacity: 1;
  background: #eaf4ff;
}
.msh-th-filter:focus-visible {
  outline: 2px solid #2477d4;
  outline-offset: 1px;
}
/* คอลัมน์ที่กรองอยู่: ปุ่มกรองสีเด่นค้างไว้ให้รู้ว่าข้อมูลถูกซ่อนบางส่วน */
.msh-th-filter.is-active {
  opacity: 1;
  background: #2477d4;
  color: #fff;
}
.msh-filter-menu {
  display: grid;
  gap: 8px;
  width: min(300px, calc(100vw - 32px));
  font-size: 0.86rem;
}
.msh-filter-menu[hidden] {
  display: none;
}
.msh-filter-menu h3 {
  margin: 0;
}
.msh-filter-search {
  width: 100%;
  min-height: 40px;
  padding: 6px 10px;
  border: 1px solid #cfe0f2;
  border-radius: 8px;
  background: #fff;
  color: #17243a;
  font: inherit;
  font-size: 16px;
}
.msh-filter-tools {
  display: flex;
  gap: 14px;
}
.msh-filter-link {
  padding: 0;
  border: 0;
  background: none;
  color: #185fae;
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}
.msh-filter-list {
  display: grid;
  /* minmax(0,1fr): แถวไม่ขยายตามคำยาว ให้คำตัดเป็น … และเลขจำนวนยังอยู่ขวาสุด */
  grid-template-columns: minmax(0, 1fr);
  max-height: min(320px, 45vh);
  overflow-y: auto;
  border-top: 1px solid #e4edf7;
  border-bottom: 1px solid #e4edf7;
}
.msh-filter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
}
.msh-filter-item:hover {
  background: #f3f8ff;
}
.msh-filter-item input {
  flex: none;
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: #2477d4;
}
/* คำยาวตัดเป็น … บรรทัดเดียว (คำเต็มอยู่ใน title) · padding บนล่างกันสระ/วรรณยุกต์ไทยถูกตัด */
.msh-filter-text {
  flex: 1;
  min-width: 0;
  padding-block: 2px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.msh-filter-text.is-blank {
  color: #667085;
  font-style: italic;
}
.msh-filter-count {
  flex: none;
  color: #667085;
  font-size: 0.85em;
}
.msh-filter-none {
  margin: 8px 6px;
  color: #667085;
}
.msh-filter-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.msh-filter-clear,
.msh-filter-ok {
  min-height: 38px;
  padding: 5px 14px;
  border: 1px solid #cfe0f2;
  border-radius: 9px;
  background: #fff;
  color: #344054;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.msh-filter-clear:disabled {
  opacity: 0.5;
  cursor: default;
}
.msh-filter-ok {
  border-color: #2477d4;
  background: #2477d4;
  color: #fff;
}
.msh-table-clear-filters[hidden] {
  display: none;
}
@media print {
  .msh-table-tools,
  .msh-table-columns-menu,
  .msh-th-filter {
    display: none !important;
  }
}
/* ---- ข้อ 7.6 ลากขอบขวาหัวคอลัมน์ปรับความกว้าง (msh-table.js resizeColumns · เจ้าของระบบ 10 พ.ย. 2569) ----
   หัวคอลัมน์ที่ติด (sticky) เป็นกรอบอ้างอิงของขอบลากอยู่แล้ว · :where() = ไม่ทับ position: sticky ของหัวตาราง */
:where(th.msh-col-resizable) {
  position: relative;
}
.msh-col-grip {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 4;
  width: 9px;
  height: 100%;
  cursor: col-resize;
  touch-action: none;
}
.msh-col-grip::after {
  content: '';
  position: absolute;
  top: 22%;
  bottom: 22%;
  right: 3px;
  width: 1px;
  border-radius: 2px;
  background: #c9d6e4;
}
.msh-col-grip:hover::after,
.msh-col-grip:focus-visible::after,
.msh-col-grip.is-active::after {
  top: 0;
  bottom: 0;
  right: 2px;
  width: 3px;
  background: #2477d4;
}
.msh-col-grip:focus-visible {
  outline: none;
}
body.msh-col-resizing,
body.msh-col-resizing * {
  cursor: col-resize !important;
  user-select: none;
}
/* ลากแล้ว = ล็อกความกว้างตามที่จำ · ข้อความยาวเกินช่องตัดด้วย … (ดูเต็มได้เมื่อขยายคอลัมน์) */
table.msh-table-sized {
  table-layout: fixed;
}
table.msh-table-sized > thead > tr > th,
table.msh-table-sized > tbody > tr > td,
table.msh-table-sized > tfoot > tr > td {
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (max-width: 720px) {
  .msh-col-grip {
    display: none;
  }
}
@media print {
  .msh-col-grip {
    display: none;
  }
}
