/* ============================================================
   ui.css — ระบบดีไซน์กลางของ LMS Report
   รวม CSS ที่เดิมก๊อปซ้ำกันอยู่ใน 5 หน้า (index/loans/writeoff/deposit/comment)
   มาไว้ที่เดียว + ปรับหน้าตาให้มินิมอลและมีอนิเมชัน

   ลำดับการโหลด:  theme.css -> nav.css -> ui.css   (ui.css ต้องมาท้ายสุด)
   ทุกหน้าที่ใช้ไฟล์นี้ ไม่ต้องมี <style> ของตัวเองอีกแล้ว
   ยกเว้นสิ่งที่เป็นของหน้านั้นจริง ๆ ให้ใส่ไว้ท้ายไฟล์ของหน้านั้น
   ============================================================ */

/* ---------- 1. โทเคนสี ---------- */
:root {
  /* แบรนด์ CMI — แดงใช้เป็นสีเน้นเท่านั้น ไม่เอามาถมพื้นที่กว้าง */
  --brand:        #c81e1e;
  --brand-hover:  #ab1818;
  --brand-dark:   #8f1414;
  --brand-tint:   #fdf2f2;
  --brand-line:   #f3d2d2;

  --green:        #15803d;
  --green-hover:  #136a34;
  --green-alt:    #0f766e;
  --amber:        #b45309;
  --amber-tint:   #fffbeb;
  --amber-line:   #fde68a;
  --red:          #dc2626;
  --blue:         #1d4ed8;

  /* กลาง — โทนเทาอมฟ้าเล็กน้อย อ่านสบายกว่าเทาล้วน */
  --bg:           #f6f7f9;
  --surface:      #ffffff;
  --surface-2:    #fafbfc;
  --surface-3:    #f1f3f6;
  --line:         #e6e9ee;
  --line-soft:    #eff1f5;
  --line-2:       #d4dae3;
  --text:         #16202c;
  --text-2:       #5b6673;
  --text-3:       #98a1ad;

  --r-sm: 7px;
  --r:    10px;
  --r-lg: 14px;
  --r-pill: 999px;

  --sh-xs: 0 1px 2px rgba(16,24,40,.05);
  --sh-sm: 0 2px 6px rgba(16,24,40,.07);
  --sh-md: 0 8px 22px rgba(16,24,40,.11);
  --sh-lg: 0 18px 44px rgba(16,24,40,.17);

  --ring: 0 0 0 3px rgba(200,30,30,.13);
  --ease: cubic-bezier(.22,.68,.36,1);

  /* ชื่อเดิมที่โค้ดหน้าอื่นยังอ้างถึงอยู่ — คงไว้ไม่ให้พัง */
  --bd:     var(--line);
  --hd:     var(--brand-dark);
  --accent: var(--brand);
  --lbl:    var(--text-2);
}

/* ---------- 2. อนิเมชัน ---------- */
@keyframes ui-fade-up   { from { opacity:0; transform:translateY(8px);  } to { opacity:1; transform:none; } }
@keyframes ui-fade-in   { from { opacity:0; } to { opacity:1; } }
@keyframes ui-pop       { from { opacity:0; transform:scale(.9);        } to { opacity:1; transform:none; } }
@keyframes ui-drop      { from { opacity:0; transform:translateY(-6px) scale(.985); } to { opacity:1; transform:none; } }
@keyframes ui-row       { from { opacity:0; transform:translateY(5px);  } to { opacity:1; transform:none; } }
@keyframes ui-shimmer   { from { background-position:-420px 0; } to { background-position:420px 0; } }
@keyframes ui-modal     { from { opacity:0; transform:translateY(14px) scale(.96); } to { opacity:1; transform:none; } }

/* ---------- 3. พื้นฐาน ---------- */
* { box-sizing: border-box; }

body {
  font-family: "Noto Sans Lao", "Segoe UI", "Leelawadee UI", Tahoma, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(200,30,30,.16); }

/* แถบเลื่อนให้บางและกลืนกับธีม */
* { scrollbar-width: thin; scrollbar-color: #cfd5de transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: #cfd5de; border-radius: var(--r-pill); border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: #adb6c2; background-clip: content-box; }

/* ---------- 4. หัวหน้า ---------- */
header {
  background: rgba(255,255,255,.88);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  color: var(--text);
  padding: 13px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
  flex-wrap: wrap;
}
header h1 {
  font-size: 15.5px; margin: 0; font-weight: 700; letter-spacing: -.012em;
  display: flex; align-items: center; gap: 10px;
}
header h1::before {
  content: ''; width: 3px; height: 16px; border-radius: var(--r-pill);
  background: var(--brand); flex-shrink: 0;
}
header .badge {
  background: var(--brand-tint); color: var(--brand-dark);
  padding: 3px 10px; border-radius: var(--r-pill);
  font-size: 10.5px; font-weight: 700; letter-spacing: .03em;
  border: 1px solid var(--brand-line);
}
header a {
  color: var(--text-2); font-size: 12.5px; text-decoration: none;
  background: var(--surface); border: 1px solid var(--line);
  padding: 6px 13px; border-radius: var(--r-sm);
  transition: background .16s var(--ease), color .16s var(--ease), border-color .16s var(--ease);
}
header a:hover { background: var(--surface-3); color: var(--text); border-color: #d9dee6; }

/* ---------- 5. โครงหน้า ---------- */
/* ⚠ .wrap ต้องไม่มีอนิเมชันที่แตะ transform เด็ดขาด
   เพราะ animation-fill-mode:both จะทิ้งค่า transform:matrix(1,0,0,1,0,0) ไว้
   (identity matrix ไม่ใช่ none) ทำให้ .wrap กลายเป็น containing block
   แล้ว position:fixed ข้างใน (popup ยืนยัน export) จะยึดกับ .wrap แทนที่จะยึดกับจอ
   -> กล่องไปโผล่นอกจอ เห็นแต่ฉากหลังมัว ๆ
   ตรงนี้จึงใช้ fade แบบ opacity ล้วน ส่วนการเลื่อนขึ้นไปใส่ที่ลูกแทน */
.wrap { padding: 18px 20px 28px; animation: ui-fade-in .3s var(--ease) backwards; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px 18px;
  margin-bottom: 14px;
  box-shadow: var(--sh-xs);
  animation: ui-fade-up .34s var(--ease) backwards;
}
.wrap > .note     { animation: ui-fade-up .34s var(--ease) backwards .04s; }
.wrap > .meta     { animation: ui-fade-up .34s var(--ease) backwards .07s; }
.wrap > .tbl-wrap { animation: ui-fade-up .34s var(--ease) backwards .1s; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 12px 14px; }
@media (min-width: 1500px) { .grid { grid-template-columns: repeat(auto-fill, minmax(190px, 230px)); } }

/* ---------- 6. ฟอร์ม ---------- */
label {
  display: block; font-size: 11.5px; font-weight: 600;
  color: var(--text-2); margin-bottom: 6px; letter-spacing: .005em;
}

input, select, textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease), background .15s var(--ease);
}
input:hover:not(:focus), textarea:hover:not(:focus) { border-color: #d3d9e2; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: var(--ring);
}
input::placeholder { color: var(--text-3); }
input[type=date] { cursor: text; }
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { opacity: .45; }

/* ---------- 7. ปุ่ม ---------- */
button {
  border: none; border-radius: var(--r-sm);
  padding: 8px 16px; font-size: 13px; font-weight: 600;
  font-family: inherit; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  transition: background .16s var(--ease), box-shadow .16s var(--ease),
              transform .12s var(--ease), opacity .16s var(--ease), color .16s var(--ease);
}
button:active { transform: translateY(1px); }
button:focus-visible { outline: none; box-shadow: var(--ring); }
button:disabled { cursor: default; opacity: .45; transform: none !important; box-shadow: none !important; }

.btn-primary    { background: var(--brand);     color: #fff; box-shadow: 0 1px 2px rgba(200,30,30,.26); }
.btn-primary:hover:not(:disabled)    { background: var(--brand-hover); box-shadow: 0 4px 12px rgba(200,30,30,.3); }
.btn-ghost      { background: var(--surface-3); color: var(--text-2); box-shadow: inset 0 0 0 1px var(--line); }
.btn-ghost:hover:not(:disabled)      { background: #e8ebf0; color: var(--text); }
.btn-export     { background: var(--green);     color: #fff; box-shadow: 0 1px 2px rgba(21,128,61,.24); }
.btn-export:hover:not(:disabled)     { background: var(--green-hover); box-shadow: 0 4px 12px rgba(21,128,61,.28); }
.btn-export-alt,
.btn-export-csv { background: var(--green-alt);  color: #fff; box-shadow: 0 1px 2px rgba(15,118,110,.24); }
.btn-export-alt:hover:not(:disabled),
.btn-export-csv:hover:not(:disabled) { background: #0c5f59; box-shadow: 0 4px 12px rgba(15,118,110,.28); }
.btn-green      { background: var(--green); color: #fff; }
.btn-green:hover:not(:disabled)      { background: var(--green-hover); }
.btn-red        { background: var(--red);   color: #fff; }
.btn-red:hover:not(:disabled)        { background: #bb1f1f; }

/* ---------- 8. แถบปุ่ม ---------- */
.actions {
  display: flex; gap: 9px; margin-top: 15px; padding-top: 14px;
  border-top: 1px solid var(--line-soft);
  flex-wrap: wrap; align-items: center;
}
.action-group { display: flex; align-items: center; gap: 8px; }
.action-sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 3px; }
.grouplabel { font-size: 11px; color: var(--text-3); font-weight: 600; }

.exp-scope { display: flex; align-items: center; gap: 7px; margin: 0 0 0 2px; }
.exp-scope > span { font-size: 11.5px; font-weight: 600; color: var(--text-2); white-space: nowrap; }

/* ---------- 9. ตาราง ---------- */
.tbl-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--sh-xs);
}
table { border-collapse: separate; border-spacing: 0; width: 100%; white-space: nowrap; }
th, td { padding: 9px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line-soft); }
th {
  background: var(--surface-2);
  position: sticky; top: 0; z-index: 2;
  font-size: 11px; font-weight: 700; color: var(--text-2);
  letter-spacing: .035em; text-transform: uppercase;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
tbody tr { transition: background .13s var(--ease); }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td {
  background: var(--surface-3); font-weight: 700; color: var(--text);
  border-top: 1px solid var(--line); border-bottom: none;
  position: sticky; bottom: 0; z-index: 2;
}

/* แถวค่อย ๆ ไล่ขึ้นมาตอนโหลดผลลัพธ์ใหม่ */
tbody tr { animation: ui-row .26s var(--ease) backwards; }
tbody tr:nth-child(1){animation-delay:.00s} tbody tr:nth-child(2){animation-delay:.012s}
tbody tr:nth-child(3){animation-delay:.024s} tbody tr:nth-child(4){animation-delay:.036s}
tbody tr:nth-child(5){animation-delay:.048s} tbody tr:nth-child(6){animation-delay:.06s}
tbody tr:nth-child(7){animation-delay:.072s} tbody tr:nth-child(8){animation-delay:.084s}
tbody tr:nth-child(9){animation-delay:.096s} tbody tr:nth-child(10){animation-delay:.108s}
tbody tr:nth-child(11){animation-delay:.12s} tbody tr:nth-child(12){animation-delay:.132s}
tbody tr:nth-child(13){animation-delay:.144s} tbody tr:nth-child(14){animation-delay:.156s}
tbody tr:nth-child(15){animation-delay:.168s} tbody tr:nth-child(n+16){animation-delay:.18s}

/* ---------- 10. ส่วนสรุป / เพจเจอร์ ---------- */
.meta { display: flex; justify-content: space-between; align-items: center; margin: 14px 2px 10px; flex-wrap: wrap; gap: 10px; }
.count-line { font-size: 13.5px; font-weight: 700; color: var(--text); letter-spacing: -.005em; }
.muted { color: var(--text-3); font-size: 12px; }

.totlabel { font-size: 10px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 10px; }
.totchip {
  display: inline-flex; align-items: baseline; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r-pill); padding: 5px 13px;
  margin: 0 7px 7px 0; font-size: 12.5px; color: var(--text-2);
  transition: border-color .16s var(--ease), background .16s var(--ease);
}
.totchip:hover { border-color: #d7dce4; background: var(--surface); }
.totchip b { color: var(--text); font-variant-numeric: tabular-nums; font-size: 13px; }
.totchip.alt { background: #f0fbfd; border-color: #c2e6ee; }
.totchip.alt b { color: #0e6e84; }

.pager { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }
.pager button {
  padding: 6px 11px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--line);
  color: var(--text-2); font-weight: 600; font-size: 12.5px; border-radius: var(--r-sm);
}
.pager button:hover:not(:disabled):not(.active) { background: var(--surface-3); color: var(--text); }
.pager button.active { background: var(--brand); color: #fff; box-shadow: 0 1px 2px rgba(200,30,30,.26); }
.pager-total {
  font-weight: 700; color: var(--brand-dark); background: var(--brand-tint);
  border: 1px solid var(--brand-line); border-radius: var(--r-pill);
  padding: 5px 12px; font-size: 12.5px;
}
.pager-total.muted { font-weight: 600; color: var(--text-3); background: var(--surface-3); border-color: var(--line); }

/* ---------- 11. ป้าย / ข้อความกำกับ ---------- */
.pill {
  display: inline-block; padding: 2px 9px; border-radius: var(--r-pill);
  font-size: 10.5px; font-weight: 700; letter-spacing: .015em; white-space: nowrap;
}
.pill.normal        { background:#dcfce7; color:#14532d; }
.pill.pending_close { background:#dbeafe; color:#1e3a8a; }
.pill.stopped       { background:#fef3c7; color:#854d0e; }
.pill.refused       { background:#fee2e2; color:#7f1d1d; }
.pill.applying      { background:#e8ebf0; color:#374151; }
.pill.closed        { background:#e8ebf0; color:#374151; }
.pill.on            { background:#dcfce7; color:#14532d; }
.pill.off           { background:#fee2e2; color:#7f1d1d; }
.pill.admin         { background:#ede9fe; color:#4c1d95; }
.pill.user          { background:#e8ebf0; color:#374151; }

.note {
  background: var(--amber-tint); border: 1px solid var(--amber-line); color: #8a4a09;
  border-radius: var(--r); padding: 10px 13px; font-size: 12px; line-height: 1.6;
  margin-bottom: 14px;
}
.note b { color: #713f12; }

/* กล่องคำอธิบายแบบพับเก็บ — <details class="note note-fold"> */
.note-fold { padding: 0; overflow: hidden; }
.note-fold > summary {
  padding: 9px 13px; cursor: pointer; list-style: none;
  font-size: 12.5px; font-weight: 700; color: #7c4708;
  display: flex; align-items: center; gap: 8px;
  transition: background .15s var(--ease);
}
.note-fold > summary::-webkit-details-marker { display: none; }
.note-fold > summary:hover { background: #fef6e0; }
.note-fold > summary::after {
  content: ''; width: 7px; height: 7px; margin-left: auto; flex-shrink: 0;
  border-right: 1.7px solid #b4791f; border-bottom: 1.7px solid #b4791f;
  transform: rotate(45deg) translateY(-2px);
  transition: transform .22s var(--ease);
}
.note-fold[open] > summary::after { transform: rotate(-135deg) translateY(-2px); }
.note-fold[open] > summary { border-bottom: 1px solid var(--amber-line); }
.note-fold > summary .note-tag {
  background: #fdeec4; border: 1px solid var(--amber-line); color: #8a5a10;
  border-radius: var(--r-pill); padding: 1px 9px; font-size: 10.5px; font-weight: 700;
}
.note-fold .note-body {
  padding: 11px 13px 12px; font-size: 12px; line-height: 1.65;
  animation: ui-fold .22s var(--ease) backwards;
}
.note-fold .note-body + .note-body { border-top: 1px dashed var(--amber-line); }
.note-fold code {
  background: #fdeec4; border-radius: 4px; padding: 1px 5px; font-size: 11.5px;
  font-family: ui-monospace, Consolas, monospace;
}
@keyframes ui-fold { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: none; } }
.warn { background: var(--amber-tint); border: 1px solid var(--amber-line); color: #8a4a09; padding: 10px 13px; border-radius: var(--r); margin-bottom: 12px; font-size: 12.5px; }
.msg  { background:#dcfce7; color:#14532d; padding:9px 13px; border-radius:var(--r); margin-bottom:12px; animation: ui-fade-up .3s var(--ease) backwards; }
.err  { background:#fee2e2; color:#7f1d1d; padding:9px 13px; border-radius:var(--r); margin-bottom:12px; animation: ui-fade-up .3s var(--ease) backwards; }

.dash { color: var(--text-3); }
.spin { color: var(--brand); }
.flag-suspect { color: var(--amber); font-weight: 600; }
.flag-suspect::after { content: ' ⚠'; }
.amt-neg { background: #fff5f5 !important; }
.urgent-row { background: #fff5f6 !important; }

/* ไฮไลต์แถวตามสถานะสัญญา (หน้า Loan List / Write-off) */
tr.st-pending_close { background: #f4f8ff; }
tr.st-stopped       { background: #fffbeb; }
tr.st-closed        { color: var(--text-3); }
tr.st-refused       { color: var(--text-3); text-decoration: line-through; }
tr.st-pending_close:hover { background: #eaf1fd; }
tr.st-stopped:hover       { background: #fdf6dd; }

.mark { display: inline-block; margin-left: 5px; font-size: 12px; cursor: help; transition: transform .15s var(--ease); }
.mark:hover { transform: scale(1.22); }
.mark-file { color: var(--green-alt); }
.mark-link { color: var(--blue); }
.mark-urgent { color: #b91c1c; font-weight: 700; }

/* ช่องข้อความยาว — ย่อ 3 บรรทัด คลิกกางได้ */
.txt {
  white-space: pre-wrap; max-width: 340px; min-width: 165px; cursor: pointer;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden; line-height: 1.5;
  transition: color .15s var(--ease);
}
.txt:hover { color: var(--brand-dark); }
.txt.open { -webkit-line-clamp: unset; overflow: visible; }
.txt:empty::before { content: '—'; color: var(--text-3); }

/* ---------- 12. โครงร่างตอนกำลังโหลด (skeleton) ---------- */
.sk {
  display: inline-block; height: 11px; border-radius: var(--r-pill); min-width: 60px;
  background: linear-gradient(90deg, var(--surface-3) 25%, #e7eaef 50%, var(--surface-3) 75%);
  background-size: 420px 100%;
  animation: ui-shimmer 1.15s linear infinite;
}

/* ---------- 13. ดรอปดาวน์เลือกหลายค่า (msel) ---------- */
.msel { position: relative; }
.msel-box {
  min-height: 34px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 4px 28px 4px 7px;
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center; cursor: pointer;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.msel-box::after {
  content: ''; position: absolute; right: 11px; top: 14px; pointer-events: none;
  width: 7px; height: 7px; border-right: 1.6px solid var(--text-3); border-bottom: 1.6px solid var(--text-3);
  transform: rotate(45deg) translateY(-1px); transition: transform .2s var(--ease), border-color .15s var(--ease);
}
.msel-box:hover { border-color: #d3d9e2; }
.msel-box:hover::after { border-color: var(--text-2); }
.msel.open .msel-box { border-color: var(--brand); box-shadow: var(--ring); }
.msel.open .msel-box::after { transform: rotate(-135deg) translateY(-3px); border-color: var(--brand); }
.msel-placeholder { color: var(--text-3); font-size: 13px; padding: 3px 3px; }

.msel-box .chip {
  background: var(--brand-tint); color: var(--brand-dark); border: 1px solid var(--brand-line);
  border-radius: var(--r-pill); padding: 2px 4px 2px 9px;
  font-size: 11px; font-weight: 600; display: inline-flex; align-items: center; gap: 2px;
  white-space: nowrap; max-width: 100%; animation: ui-pop .17s var(--ease) backwards;
}
.msel-box .chip-x {
  cursor: pointer; font-weight: 700; opacity: .5; padding: 0 4px;
  border-radius: 50%; line-height: 1.35;
  transition: opacity .14s var(--ease), background .14s var(--ease);
}
.msel-box .chip-x:hover { opacity: 1; background: rgba(143,20,20,.12); }

.msel-panel {
  display: none; position: absolute; z-index: 40; top: calc(100% + 5px); left: 0;
  width: max-content; min-width: 100%; max-width: 420px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  max-height: 300px; overflow-y: auto; box-shadow: var(--sh-md); padding: 5px;
}
.msel-panel.open { display: block; animation: ui-drop .17s var(--ease) backwards; }
.msel-row {
  padding: 7px 11px 7px 31px; position: relative; font-size: 12.5px;
  cursor: pointer; white-space: nowrap; border-radius: var(--r-sm);
  transition: background .12s var(--ease), color .12s var(--ease);
}
.msel-row:hover { background: var(--surface-3); }
.msel-row.all-row { border-bottom: 1px solid var(--line-soft); border-radius: var(--r-sm) var(--r-sm) 0 0; font-weight: 600; margin-bottom: 4px; padding-bottom: 8px; }
.msel-row::before {
  content: ''; position: absolute; left: 9px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; border: 1.5px solid #cdd4de; border-radius: 4px;
  transition: background .14s var(--ease), border-color .14s var(--ease);
}
.msel-row.all-row::before { border: none; }
.msel-row.selected { background: var(--brand-tint); color: var(--brand-dark); font-weight: 600; }
.msel-row.selected::before {
  content: '✓'; background: var(--brand); border-color: var(--brand); color: #fff;
  font-size: 10px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}

/* ---------- 14. ดรอปดาวน์ค้นหาได้ (combo) ---------- */
.combo { position: relative; }
.combo input[type=text] { padding-right: 28px; }
.combo::after {
  content: ''; position: absolute; right: 11px; top: 13px; pointer-events: none;
  width: 7px; height: 7px; border-right: 1.6px solid var(--text-3); border-bottom: 1.6px solid var(--text-3);
  transform: rotate(45deg) translateY(-1px);
  transition: transform .2s var(--ease), border-color .15s var(--ease);
}
.combo.open::after { transform: rotate(-135deg) translateY(-3px); border-color: var(--brand); }
.combo-panel {
  display: none; position: absolute; z-index: 40; top: calc(100% + 5px); left: 0; right: 0;
  min-width: 262px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); max-height: 286px; overflow-y: auto;
  box-shadow: var(--sh-md); padding: 5px;
}
.combo-panel.open { display: block; animation: ui-drop .17s var(--ease) backwards; }
.combo-opt {
  padding: 7px 11px; font-size: 12.5px; cursor: pointer; border-radius: var(--r-sm);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background .12s var(--ease), color .12s var(--ease);
}
.combo-opt:hover { background: var(--surface-3); }
.combo-opt.combo-all { font-weight: 600; border-bottom: 1px solid var(--line-soft); border-radius: var(--r-sm) var(--r-sm) 0 0; margin-bottom: 4px; padding-bottom: 8px; }
.combo-opt.muted { color: var(--text-3); font-size: 11.5px; cursor: default; }
.combo-opt.muted:hover { background: transparent; }

/* ---------- 15. ดรอปดาวน์ธรรมดา (แทน <select> ของเบราว์เซอร์) ----------
   ui.js จะซ่อน <select> เดิมไว้ แล้วสร้างปุ่ม+พาเนลนี้ขึ้นมาแทน
   ตัว <select> ยังอยู่ใน DOM ตามเดิม โค้ดที่อ่าน .value จึงทำงานได้เหมือนเดิม */
select.sel-native {
  position: absolute !important; width: 1px !important; height: 1px !important;
  padding: 0 !important; margin: -1px !important; border: 0 !important;
  clip: rect(0 0 0 0); clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}
.sel { position: relative; width: 100%; }
.sel-btn {
  width: 100%; min-height: 34px; padding: 7px 30px 7px 11px;
  background: var(--surface); color: var(--text);
  border-radius: var(--r-sm); box-shadow: inset 0 0 0 1px var(--line);
  font-size: 13px; font-weight: 400; text-align: left;
  display: flex; align-items: center; justify-content: flex-start; gap: 0;
  transition: box-shadow .15s var(--ease), background .15s var(--ease);
}
.sel-btn:hover:not(:disabled) { box-shadow: inset 0 0 0 1px #d3d9e2; background: var(--surface); }
.sel-btn:active { transform: none; }
.sel-val { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; width: 100%; }
.sel-val.is-placeholder { color: var(--text-3); }
.sel-caret {
  position: absolute; right: 11px; top: 50%; margin-top: -4px; pointer-events: none;
  width: 7px; height: 7px; border-right: 1.6px solid var(--text-3); border-bottom: 1.6px solid var(--text-3);
  transform: rotate(45deg); transition: transform .2s var(--ease), border-color .15s var(--ease);
}
.sel.open .sel-btn { box-shadow: inset 0 0 0 1px var(--brand), var(--ring); }
.sel.open .sel-caret { transform: rotate(-135deg) translate(-2px,-2px); border-color: var(--brand); }
.sel-btn:focus-visible { outline: none; box-shadow: inset 0 0 0 1px var(--brand), var(--ring); }

.sel-panel {
  display: none; position: absolute; z-index: 45; top: calc(100% + 5px); left: 0;
  min-width: 100%; width: max-content; max-width: 340px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--sh-md); padding: 5px; max-height: 292px; overflow-y: auto;
}
.sel-panel.open { display: block; animation: ui-drop .17s var(--ease) backwards; }
.sel-panel.drop-up { top: auto; bottom: calc(100% + 5px); }
.sel-search { padding: 2px 3px 6px; position: sticky; top: -5px; background: var(--surface); z-index: 1; }
.sel-search input { font-size: 12.5px; padding: 6px 9px; }
.sel-opt {
  padding: 7px 11px 7px 26px; position: relative; font-size: 12.5px;
  cursor: pointer; border-radius: var(--r-sm); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
  transition: background .12s var(--ease), color .12s var(--ease);
}
.sel-opt:hover, .sel-opt.cursor { background: var(--surface-3); }
.sel-opt.selected { background: var(--brand-tint); color: var(--brand-dark); font-weight: 600; }
.sel-opt.selected::before {
  content: '✓'; position: absolute; left: 9px; top: 50%; transform: translateY(-50%);
  font-size: 11px; font-weight: 700; color: var(--brand);
}
.sel-opt.muted { color: var(--text-3); cursor: default; font-size: 11.5px; }
.sel-opt.muted:hover { background: transparent; }
.sel-group { padding: 8px 11px 4px; font-size: 10.5px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; }

/* ดรอปดาวน์ตัวเล็ก (เช่น "แสดง N แถว/หน้า") */
.sel.sel-sm { width: auto; min-width: 82px; }
.sel.sel-sm .sel-btn { min-height: 30px; padding: 5px 28px 5px 10px; font-size: 12.5px; }

/* ---------- 16. ของหน้า admin ---------- */
/* กล่องโต้ตอบ (ตั้งรหัสผ่านใหม่ ฯลฯ) */
.modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 60;
  background: rgba(22,32,44,.42);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; animation: ui-fade-in .18s var(--ease) backwards; }
.modal-box {
  background: var(--surface); border-radius: 16px; padding: 20px 22px;
  width: 340px; max-width: 90vw; box-shadow: var(--sh-lg);
  animation: ui-modal .25s var(--ease) backwards;
}
.modal-box h3 { margin: 0 0 12px; font-size: 14px; font-weight: 700; letter-spacing: -.008em; }
.modal-actions { display: flex; gap: 9px; margin-top: 16px; justify-content: flex-end; }
.pwrow { display: flex; gap: 7px; }
.pwrow input { flex: 1; }

.log-detail { max-width: 300px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: help; }
.log-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; flex-wrap: wrap; gap: 10px; }
.toolbar { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input { max-width: 290px; }
.you { background:#dbeafe; color:#1e3a8a; font-size:10px; font-weight:700; padding:2px 7px; border-radius:var(--r-pill); margin-left:6px; }
form.inline { display: inline; }
.pill.ev-login_ok{background:#dcfce7;color:#14532d;} .pill.ev-login_fail{background:#fee2e2;color:#7f1d1d;}
.pill.ev-logout{background:#e8ebf0;color:#374151;}   .pill.ev-search{background:#e0e7ff;color:#312e81;}
.pill.ev-export{background:#fef3c7;color:#854d0e;}   .pill.ev-security{background:#fce7f3;color:#831843;}
.pill.ev-search_loans{background:#e0e7ff;color:#312e81;}   .pill.ev-export_loans{background:#fef3c7;color:#854d0e;}
.pill.ev-search_writeoff{background:#e0e7ff;color:#312e81;} .pill.ev-export_writeoff{background:#fef3c7;color:#854d0e;}
.pill.ev-search_deposit{background:#e0e7ff;color:#312e81;}  .pill.ev-export_deposit{background:#fef3c7;color:#854d0e;}
.pill.ev-search_comment{background:#e0e7ff;color:#312e81;}  .pill.ev-export_comment{background:#fef3c7;color:#854d0e;}

/* ---------- 16.5 เลือกคอลัมน์ + กางดูทุกช่องของแถว ---------- */
.meta-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.colpick { position: relative; }
.colpick-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-pill); padding: 6px 13px;
  font: inherit; font-size: 12.5px; font-weight: 700; color: var(--text-2);
  cursor: pointer; transition: all .15s var(--ease);
}
.colpick-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--line-2); }
.colpick-btn .icon { width: 14px; height: 14px; }
.colpick-count {
  background: var(--surface-3); color: var(--text-3);
  border-radius: var(--r-pill); padding: 1px 7px; font-size: 11px; font-weight: 700;
}

.colpick-panel {
  display: none; position: absolute; right: 0; top: calc(100% + 7px); z-index: 46;
  width: min(520px, 88vw); max-height: 60vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--line-2);
  border-radius: var(--r); box-shadow: var(--sh-md); padding: 11px;
}
.colpick-panel.open { display: block; animation: ui-fold .18s var(--ease) backwards; }
.colpick-panel.up { top: auto; bottom: calc(100% + 7px); }
.colpick-title {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-3); margin: 1px 4px 8px;
}
.colpick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 1px 6px; }
.colpick-opt {
  display: flex; align-items: center; gap: 7px; padding: 5px 7px;
  border-radius: 8px; cursor: pointer; font-size: 12.5px; color: var(--text-2);
  user-select: none; transition: background .13s var(--ease);
}
.colpick-opt:hover { background: var(--surface-2); color: var(--text); }
.colpick-opt input { width: 14px; height: 14px; accent-color: var(--brand); cursor: pointer; margin: 0; }
.colpick-opt.locked { opacity: .5; cursor: not-allowed; }
.colpick-foot {
  display: flex; gap: 7px; justify-content: flex-end;
  border-top: 1px solid var(--line); margin-top: 9px; padding-top: 9px;
}
.colpick-foot button {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-pill);
  padding: 5px 12px; font: inherit; font-size: 12px; font-weight: 700;
  color: var(--text-2); cursor: pointer; transition: all .15s var(--ease);
}
.colpick-foot button:hover { background: var(--surface-3); color: var(--text); }

/* ปุ่มลูกศรหน้าแถว — กางดูทุกช่องของแถวนั้น */
th.th-exp, td.td-exp { width: 30px; padding-left: 8px !important; padding-right: 0 !important; }
.row-exp {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; padding: 0;
  background: transparent; border: 1px solid transparent; border-radius: 7px;
  color: var(--text-3); cursor: pointer; transition: all .15s var(--ease);
}
.row-exp:hover { background: var(--surface-3); color: var(--brand); border-color: var(--line); }
.row-exp .icon { width: 14px; height: 14px; transition: transform .22s var(--ease); }
.row-exp.open .icon { transform: rotate(180deg); }

tr.detail-row > td { background: var(--surface-2); padding: 0 !important; border-top: 0; }
.detail-box {
  padding: 13px 16px 15px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 9px 20px;
  animation: ui-fold .2s var(--ease) backwards;
}
.detail-grp {
  grid-column: 1 / -1; margin: 5px 0 -2px;
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-3);
}
.detail-grp:first-child { margin-top: 0; }
.detail-f dt { font-size: 10.5px; font-weight: 600; color: var(--text-3); margin-bottom: 1px; }
.detail-f dd {
  margin: 0; font-size: 12.5px; color: var(--text); line-height: 1.5;
  word-break: break-word; white-space: pre-wrap;
}
.detail-f dd a { color: var(--brand-dark); }
.detail-f.wide { grid-column: 1 / -1; }

/* ---------- 17. จอเล็ก ---------- */
@media (max-width: 780px) {
  .wrap { padding: 14px 13px 24px; }
  .card { padding: 14px; border-radius: var(--r); }
  header { padding: 11px 14px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .actions { gap: 7px; }
  .actions button { flex: 1 1 auto; }
  .exp-scope { width: 100%; }
  .meta { flex-direction: column; align-items: flex-start; }
}

/* ---------- 18. เคารพการตั้งค่าของผู้ใช้ที่ไม่อยากเห็นอนิเมชัน ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
