:root {
  --primary: #3468f0;
  --primary-dark: #2451c9;
  --primary-light: #eaf0ff;
  --navy: #16213e;
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1a1f36;
  --text-muted: #7c8494;
  --border: #eceef2;
  --danger: #e5484d;
  --success: #10b981;
  --warning: #f59e0b;
  --purple: #8b5cf6;
  --sidebar-w: 248px;
}

* {
  box-sizing: border-box;
}

body {
  /* Google Sans เองก็มี glyph ภาษาไทยแล้ว (Cadson Demak ออกแบบให้) ส่วน Sarabun ยังกันไว้เป็น fallback เฉยๆ
     น้ำหนัก 400 ปกติของ Google Sans ดูหนา/ทึบกว่า Roboto ที่เคยใช้มาก เลยตั้ง base เป็น 300 (Light) แทน
     ตัว element ที่ตั้ง font-weight ไว้เอง (label/หัวข้อ/ปุ่ม 500/600/700) จะไม่โดนกระทบ เพราะ override ทับอยู่แล้ว */
  font-family: 'Google Sans', 'Sarabun', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 300;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

a {
  color: inherit;
}

button {
  font-family: inherit;
  font-weight: inherit;
}

svg {
  display: block;
}

/* ---------- Login page ---------- */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: 0 4px 16px rgba(16, 24, 40, 0.06);
}

.login-logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  display: block;
  margin: 0 auto 16px;
}

.login-title {
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 4px;
  color: var(--text);
}

.login-subtitle {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 24px;
}

.form-field {
  margin-bottom: 16px;
}

.form-field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
}

.required-mark {
  color: var(--danger);
}

.label-hint {
  color: var(--text-muted);
  font-weight: 400;
}

.pin-boxes {
  display: flex;
  gap: 8px;
  width: 100%;
}

.pin-box {
  flex: 1;
  min-width: 0;
  height: 38px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text);
  cursor: not-allowed;
}

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  height: auto;
  min-height: 0;
  /* padding บน-ล่าง (9px) + font-size (13px) ตรงนี้เซ็ตให้เท่ากับ .table-search input ที่ยืนยันแล้วว่า underscore/สระอู
     แสดงผลถูกต้องปกติ ณ เครื่องผู้ใช้จริง (ก่อนหน้านี้ font-size 14px + padding 6-8px ตัดตัวอักษรที่อยู่ต่ำกว่า baseline บางส่วนไป) */
  padding: 9px 12px;
  font-size: 13px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-family: inherit;
  font-weight: inherit;
  background: #fafafa;
}

.form-field textarea {
  resize: vertical;
  min-height: 64px;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
}

/* มาตรฐาน: ช่องที่แก้ไขไม่ได้ (readonly/disabled) ต้องพื้นสีเข้มกว่าช่องที่กรอกได้ (#fafafa) เสมอ
   เพื่อไม่ให้ผู้ใช้สับสนว่ากรอกได้หรือไม่ - ใช้ var(--border) เป็นสีมาตรฐานของ "แก้ไขไม่ได้" ทั่วทั้งโปรเจกต์ */
.form-field input[readonly],
.form-field input[disabled],
.form-field select[disabled],
.form-field textarea[readonly],
.form-field textarea[disabled] {
  background: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
}

.form-field input[readonly]:focus,
.form-field input[disabled]:focus,
.form-field textarea[readonly]:focus,
.form-field textarea[disabled]:focus {
  background: var(--border);
  border-color: #ddd;
}

.input-icon {
  position: relative;
}

.input-icon svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  stroke: var(--text-muted);
  pointer-events: none;
  /* z-index: 1 กันเคส .input-icon ครอบ select2 (span.select2-container ของ select2 เองตั้ง position: relative ไว้เป็น default)
     ถ้าไม่ยกไอคอนขึ้นมาก่อน select2-container ที่มาทีหลังใน DOM จะวาดทับไอคอนจนหายไป */
  z-index: 1;
}

.input-icon input {
  padding-left: 32px;
}

.input-icon svg.input-icon-suffix {
  left: auto;
  right: 12px;
}

.input-icon input.has-suffix {
  padding-right: 28px;
}

/* ตัวไฟวิ่งรอบกรอบช่องวันที่ (เช่น วันครบกำหนด ที่คำนวณอัตโนมัติจากวันเริ่มต้น+จำนวนงวด) — เทคนิคเดียวกับ .input-group-glow
   ยกเฉพาะ <input> ขึ้น z-index (ไม่ใช่ทุก child ด้วย > * แบบ .input-group-glow) เพราะไอคอนปฏิทิน/ลูกศรใน .input-icon
   วางตำแหน่งด้วย position:absolute อยู่แล้วเพื่อลอยทับ input การไปแตะ position ของมันจะทำให้ตำแหน่งไอคอนเพี้ยน
   ไอคอน (lucide แปลง <i data-lucide> เป็น <svg> ตอน runtime) ต้อง z-index สูงกว่า input เสมอ ไม่งั้น input (z-index:1) จะวาดทับไอคอนจนหายไป
   เพราะพอ input มี z-index ชัดเจนแล้ว มันจะหลุดจากกลุ่ม "non-positioned" เดิม (ที่วาดหลังสุดใต้ทุก positioned element) ไปอยู่กลุ่มเดียวกับไอคอน */
.input-icon.input-icon-glow {
  overflow: hidden;
  border-radius: 8px;
  padding: 2px;
  background: #fff;
}

.input-icon.input-icon-glow input,
.input-icon.input-icon-glow select {
  position: relative;
  z-index: 1;
}

/* select ที่ผ่าน select2 แล้ว ตัวที่แสดงจริงคือ .select2-container (แทรกต่อท้าย select เดิมที่ถูกซ่อนไว้) ต้องยกขึ้นด้วยเหมือนกัน (ดู payment_method/payment_sender_bank_code/payment_receiver_bank_code ใน contracts.php) */
.input-icon.input-icon-glow .select2-container {
  position: relative;
  z-index: 1;
}

.input-icon.input-icon-glow svg {
  z-index: 2;
}

.input-icon.input-icon-glow.money-flash::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 220%;
  height: 220%;
  background: conic-gradient(transparent, var(--primary), transparent 30%);
  transform: translate(-50%, -50%) rotate(-45deg);
  animation: money-flash-spin 900ms linear forwards;
  pointer-events: none;
  z-index: 0;
}

/* ---------- input-group: ช่อง input ที่มีหน่วยต่อท้าย (เช่น "บาท") ยึดในกล่องเดียวกับ input ---------- */
.input-group {
  display: flex;
  align-items: stretch;
  position: relative;
}

/* ตัวไฟวิ่งรอบกรอบ input เป็น feedback ตอนค่าถูกคำนวณอัตโนมัติ (เช่น เงินต้น/เงินที่จ่ายจริงในฟอร์มสัญญา)
   เทคนิค: กล่องนอก overflow:hidden + padding 2px (ช่องว่างสำหรับให้แสงโผล่ออกมาเป็น "เส้นขอบ") ครอบ conic-gradient สี่เหลี่ยมใหญ่ที่หมุนอยู่ข้างใน (::before)
   ส่วน input/suffix ข้างในยกขึ้น z-index สูงกว่าด้วย .input-group-glow > * ให้บังกลางกล่องไว้ เหลือแสงให้เห็นแค่ตรงขอบ 2px รอบๆ เท่านั้น
   ใช้ class .input-group-glow แยกต่างหาก (ไม่แก้ .input-group ตรงๆ) กัน padding/overflow ตัวนี้ไปกระทบ input-group อื่นทั้งแอปที่ไม่เกี่ยวข้อง
   พื้นหลังกล่องนอกตั้งเป็น #fff ให้ตรงกับพื้นหลัง .drawer เป๊ะ ช่องว่าง 2px เลยกลืนมองไม่เห็นตอนไม่ได้ flash (ไม่ต้อง toggle padding ไปมา กันกล่องกระตุกตอน flash ทำงาน) */
.input-group.input-group-glow {
  overflow: hidden;
  border-radius: 8px;
  padding: 2px;
  background: #fff;
}

.input-group.input-group-glow > * {
  position: relative;
  z-index: 1;
}

.input-group.input-group-glow.money-flash::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 220%;
  height: 220%;
  background: conic-gradient(transparent, var(--primary), transparent 30%);
  transform: translate(-50%, -50%) rotate(-45deg);
  animation: money-flash-spin 900ms linear forwards;
  pointer-events: none;
  z-index: 0;
}

/* วงแสงหมุนรอบกรอบช่อง input เปล่าๆ ที่ไม่มี suffix/icon เลย (เช่น เลขที่อ้างอิง/เลขบัญชีผู้โอน-ผู้รับ ในฟอร์มจ่ายเงินเปิดสัญญา ที่เติมมาจากผลตรวจสอบสลิป)
   เทคนิคเดียวกับ .input-group-glow ด้านบน แต่แยก class ต่างหาก (ไม่ใช้ .input-group-glow ตรงๆ) เพราะ .input-group input ตัดขอบขวา/มุมขวาทิ้งเผื่อมี .input-group-suffix ต่อท้ายเสมอ
   ช่องพวกนี้ไม่มี suffix ถ้าใช้ .input-group ครอบจะทำให้ขอบขวาหายไปเปล่าๆ */
.plain-input-glow {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  padding: 2px;
  background: #fff;
}

.plain-input-glow > * {
  position: relative;
  z-index: 1;
}

.plain-input-glow.money-flash::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 220%;
  height: 220%;
  background: conic-gradient(transparent, var(--primary), transparent 30%);
  transform: translate(-50%, -50%) rotate(-45deg);
  animation: money-flash-spin 900ms linear forwards;
  pointer-events: none;
  z-index: 0;
}

@keyframes money-flash-spin {
  0% {
    transform: translate(-50%, -50%) rotate(-45deg);
    opacity: 1;
  }
  92% {
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) rotate(315deg);
    opacity: 0;
  }
}

.input-group input {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: none;
  min-width: 0;
}

.input-group-suffix {
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-size: 14px;
  color: var(--text-muted);
  background: var(--border);
  border: 1px solid #ddd;
  border-top-right-radius: 8px;
  border-bottom-right-radius: 8px;
  white-space: nowrap;
}

.input-group input:focus + .input-group-suffix {
  border-color: var(--primary);
}

/* prefix ฝั่งซ้าย (กลับด้านกับ .input-group-suffix) ใช้กับช่อง "สถานะ" ของสัญญาที่ครอบด้วย select2 */
.input-group-prefix {
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-size: 14px;
  color: var(--text-muted);
  background: var(--border);
  border: 1px solid #ddd;
  border-top-left-radius: 8px;
  border-bottom-left-radius: 8px;
  border-right: none;
  white-space: nowrap;
  flex-shrink: 0;
}

/* select2 แทรก .select2-container เป็น element ใหม่ต่อท้าย <select> เดิม (ที่ถูกซ่อนไว้) ต้องยืดให้เต็มที่เหลือในแถวเอง
   แล้วตัดขอบ/มุมโค้งฝั่งซ้ายทิ้งให้ต่อกับ .input-group-prefix แบบไร้รอยต่อ เหมือน .input-group input ตัดขอบขวาทิ้งตอนต่อกับ .input-group-suffix */
.input-group .select2-container {
  flex: 1;
  min-width: 0;
}

.input-group .select2-container .select2-selection--single {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

/* ต้องใช้ selector คู่ .input-group-btn.btn-secondary (ไม่ใช่แค่ .input-group-btn เฉยๆ) เพื่อให้ specificity สูงกว่า .btn-secondary
   ซึ่งอยู่ "หลัง" ในไฟล์นี้ — ถ้า specificity เท่ากัน (แค่ 1 class เหมือนกัน) กฎที่มาทีหลังในไฟล์จะชนะ ทำให้ padding/border-radius ของ .btn-secondary
   (11px, 10px) ทับค่าที่ตั้งไว้ตรงนี้จนช่องนี้สูงไม่เท่า input อยู่ดีแม้จะตั้งค่าถูกแล้วก็ตาม */
.input-group-btn.btn-secondary {
  padding: 8px 16px;
  font-size: 14px;
  border-radius: 0 8px 8px 0;
  border-left: none;
  flex-shrink: 0;
  white-space: nowrap;
}

/* ไม่มีปุ่มไหนในระบบ reset focus ring ของเบราว์เซอร์ไว้ (ปกติไม่เด่นเพราะปุ่มอื่นไม่ได้อยู่ติด input) แต่ปุ่มนี้อยู่ติดกับช่อง input
   วงแหวน focus สีน้ำเงินเริ่มต้นของเบราว์เซอร์เลยดูขัดกับกรอบสีเทาปกติของ input-group จึงใช้ทรีตเมนต์เดียวกับตอน input โฟกัส (เปลี่ยนสีขอบเป็น var(--primary) แทน) */
.input-group-btn.btn-secondary:focus {
  outline: none;
  border-color: var(--primary);
}

.form-field .field-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.checkbox-field input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 20px;
}

/* grid item ทุกตัวต้อง min-width: 0 (ค่า default ของ grid item คือ min-width: auto = ไม่มีวันแคบกว่า min-content ของเนื้อหาข้างใน)
   ไม่งั้นถ้าช่องไหนมีเนื้อหาที่ไม่ยอมหด (เช่น select2 ที่ตั้ง white-space: nowrap ไว้ ดู .select2-selection__rendered ด้านล่าง)
   คอลัมน์นั้นทั้งคอลัมน์จะขยายกว้างตามเนื้อหานั้นไปเลย ลามไปทุกแถวที่ใช้คอลัมน์เดียวกัน (เช่นจำนวนเงิน/ชื่อผู้โอน/ชื่อผู้รับ ที่อยู่คอลัมน์ซ้ายเดียวกับช่องทางการชำระเงิน) */
.form-grid > .form-field,
.form-grid > .form-field-split {
  min-width: 0;
}

.form-grid .form-field.span-2 {
  grid-column: 1 / -1;
}

/* บังคับให้ช่องนี้ขึ้นบรรทัดใหม่เสมอ (คอลัมน์ซ้าย) โดยไม่เต็มแถวแบบ .span-2 — ต่างจาก .span-2 ตรงที่ยังกว้างแค่ครึ่งแถว ฝั่งขวาว่างไว้เฉยๆ
   ใช้กับช่องที่ไม่อยากให้ไปแชร์แถวเดียวกับช่องเดี่ยวก่อนหน้า (เช่น "ชื่อผู้โอนเงิน" ในฟอร์มจ่ายเงินเปิดสัญญา ไม่อยากอยู่แถวเดียวกับ "เลขที่อ้างอิง") */
.form-grid .form-field.row-start {
  grid-column: 1;
}

/* เส้นคั่นกลุ่มฟิลด์ภายใน .form-grid เดียวกัน (เช่นคั่นระหว่างข้อมูลธุรกรรมกับข้อมูลผู้โอน/ผู้รับเงิน ในฟอร์มจ่ายเงินเปิดสัญญา)
   สีเส้นเดียวกับเส้นคั่น .drawer-extra-info ที่ใช้คั่นทั้งบล็อกอยู่แล้ว (var(--border)) แค่กิน grid-column เต็มแถวแทนเพราะอยู่ในกริดเดียวกัน ไม่ได้แยกบล็อกใหม่ */
.form-grid hr {
  grid-column: 1 / -1;
  width: 100%;
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

/* .type-toggle ปกติวางไว้เดี่ยวๆ เหนือ .form-grid (ดูหน้าหลักทรัพย์) ถึงต้องมี margin-bottom เว้นระยะเอง
   แต่ในหน้าสัญญาวางเป็น grid item ตัวหนึ่งในแถวเดียวกับช่อง "สถานะ" เลยต้องตัด margin ทิ้งกันแถวเตี้ยกว่าอีกฝั่ง */
.form-grid .type-toggle {
  margin-bottom: 0;
}

/* ---------- แถวที่รวม field หลายช่องไว้ในบรรทัดเดียว เฉลี่ยความกว้างเท่ากัน (เช่น เนื้อที่/ราคาประเมิน/ราคาประเมินทั้งสิ้น ของอาคารชุด) ---------- */
.form-grid .form-field-row {
  grid-column: 1 / -1;
  display: flex;
  gap: 20px;
}

.form-field-row .form-field {
  flex: 1;
  min-width: 0;
}

.form-field-row .form-field[hidden] {
  display: none;
}

/* ---------- แบ่งครึ่งของ 1 ช่อง grid ให้ 2 ฟิลด์อยู่ข้างกัน (เช่น ชำระทุกวันที่ + สัญญากำหนดระยะเวลา ในฟอร์มสัญญา)
   ต่างจาก .form-field-row ตรงที่ container นี้เป็น grid item เดียว (ไม่ grid-column: 1 / -1) เลยได้แค่ครึ่งแถว ไม่ใช่เต็มแถว ---------- */
.form-grid .form-field-split {
  display: flex;
  gap: 20px;
}

.form-field-split .form-field {
  flex: 1;
  min-width: 0;
}

/* ---------- .form-field-split ที่ต้องกินเต็มแถวเอง (เช่น แถวผู้โอนเงิน/ผู้รับเงิน ในฟอร์มจ่ายเงินเปิดสัญญา)
   ปกติ .form-field-split กินแค่ครึ่งแถว ถ้าวางสอง .form-field-split ต่อกันจะไปแอบอยู่คนละคอลัมน์แต่แถวเดียวกัน
   ต้องเติม .full-row เพื่อบังคับ grid-column: 1 / -1 ให้แต่ละอันขึ้นบรรทัดใหม่ของตัวเอง ---------- */
.form-grid .form-field-split.full-row {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 8px;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 20px;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.btn-secondary:hover {
  background: var(--bg);
}

.form-actions .btn-primary {
  width: auto;
  padding: 11px 22px;
}

@media (max-width: 640px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid .form-field-row {
    flex-direction: column;
    gap: 0;
  }

  /* .form-field-split เก็บ 2 ฟิลด์ไว้ข้างกันแม้จอมือถือ (ต่างจาก .form-field-row) เพราะทั้งคู่กว้างพอประมาณอยู่แล้ว (dropdown 1-28 ตัวเลข + toggle switch)
     แค่ลด gap ลงเพื่อประหยัดพื้นที่ ให้ input/select หด width ตาม .form-field { min-width: 0 } เอาเอง */
  .form-grid .form-field-split {
    gap: 8px;
  }
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: var(--primary);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:hover {
  background: #3a3f47;
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: default;
}

.btn-primary .btn-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-secondary svg,
.btn-primary svg {
  width: 16px;
  height: 16px;
}

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px;
  font-size: 15px;
  font-weight: 500;
  color: #3c4043;
  background: #fff;
  border: 1px solid #dadce0;
  border-radius: 10px;
  text-decoration: none;
  cursor: pointer;
}

.btn-google:active {
  background: #f8f9fa;
}

.form-error {
  display: none;
  align-items: center;
  gap: 8px;
  background: #fdecea;
  color: var(--danger);
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 8px;
  margin-top: 16px;
  margin-bottom: 16px;
}

.form-error.show {
  display: flex;
}

.login-card .form-error {
  justify-content: center;
  text-align: center;
}

/* ---------- Top progress bar (ระหว่างรอโหลดหน้าใหม่ตอนคลิกเมนู) ---------- */

.top-progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), #6d93ff);
  z-index: 9999;
  opacity: 0;
  transform: scaleX(0);
  transform-origin: center;
  transition: transform 0.7s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.15s ease;
  pointer-events: none;
}

.top-progress-bar.is-active {
  opacity: 1;
  transform: scaleX(1);
}

/* ---------- Admin shell ---------- */

.admin-shell {
  min-height: 100vh;
}

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--text);
  padding: 8px;
  cursor: pointer;
  border-radius: 8px;
  display: none;
  flex-shrink: 0;
}

.sidebar-toggle:active {
  background: var(--bg);
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: #fff;
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  overflow-y: auto;
  z-index: 25;
  display: flex;
  flex-direction: column;
  transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px;
  margin-bottom: 16px;
}

.sidebar-brand img {
  width: 30px;
  height: 30px;
  border-radius: 8px;
}

.sidebar-brand-name {
  font-weight: 700;
  font-size: 14px;
  line-height: 1.2;
}

.sidebar-brand-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-clock {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  margin: 0 0 12px;
  border-radius: 8px;
  background: var(--surface-muted, rgba(127, 127, 127, 0.08));
  color: var(--text-muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.sidebar-clock i {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.sidebar-section-label {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0 10px;
  margin: 0 0 4px;
}

.sidebar-nav-groups {
  margin: 0 0 auto;
}

.sidebar-nav {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-nav + .sidebar-section-label {
  margin-top: 14px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 400;
  margin-bottom: 1px;
}

.sidebar-nav a svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  flex-shrink: 0;
}

.sidebar-nav a:hover {
  background: #f6f8fb;
  color: var(--text);
}

.sidebar-nav a.active {
  background: var(--primary-light);
  color: var(--primary);
}

.sidebar-badge {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-footer {
  position: relative;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.account-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px;
  border: none;
  background: none;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
}

.account-row:hover {
  background: #f6f8fb;
}

.account-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.account-name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.6;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-sub {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  margin-top: -5px;
}

.account-sub-text {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.6;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.role-icon {
  width: 12px;
  height: 12px;
  stroke: var(--primary);
  flex-shrink: 0;
}

.account-row svg.chevron {
  width: 16px;
  height: 16px;
  stroke: var(--text-muted);
  flex-shrink: 0;
  transition: transform 0.15s;
}

.sidebar-footer.open .chevron {
  transform: rotate(180deg);
}

.account-menu {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: calc(100% + 6px);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
  padding: 6px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(6px) scale(0.98);
  transform-origin: bottom;
  transition: opacity 0.18s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.18s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.18s;
  pointer-events: none;
}

.sidebar-footer.open .account-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.account-menu button,
.account-menu a {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  background: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  box-sizing: border-box;
}

.account-menu button:hover,
.account-menu a:hover {
  background: var(--bg);
}

.account-menu button#logout-btn {
  color: var(--danger);
}

.account-menu button#logout-btn:hover {
  background: #fdecea;
}

.account-menu svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.12);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 20;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s;
  pointer-events: none;
}

.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
}

.content-inner {
  padding: 28px 32px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 24px;
}

.page-header-toggle {
  margin-right: -4px;
}

.page-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  flex: 1 1 auto;
}

.page-header-titles {
  min-width: 0;
}

.page-icon-box {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.page-icon-box svg {
  width: 22px;
  height: 22px;
  stroke: var(--primary);
}

.page-title {
  font-size: 19px;
  font-weight: 700;
  line-height: 1.6;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
  margin: 2px 0 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-header-right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.breadcrumb {
  font-size: 13px;
  color: var(--text-muted);
}

.breadcrumb .current {
  color: var(--text);
  font-weight: 500;
}

.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.btn-action:hover {
  background: #3a3f47;
}

.btn-action svg {
  width: 16px;
  height: 16px;
  stroke: #fff;
  flex-shrink: 0;
}

/* ---------- Stat tiles ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-tile-blink {
  animation: stat-tile-blink 1.2s ease-in-out infinite;
}

@keyframes stat-tile-blink {
  0%, 100% { background-color: var(--card); }
  50% { background-color: #fbdcdd; }
}

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 6px;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  margin: 0;
}

.stat-icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon svg {
  width: 19px;
  height: 19px;
  stroke: #fff;
}

.stat-icon.tone-navy { background: var(--navy); }
.stat-icon.tone-primary { background: var(--primary); }
.stat-icon.tone-success { background: var(--success); }
.stat-icon.tone-danger { background: var(--danger); }
.stat-icon.tone-warning { background: var(--warning); }
.stat-icon.tone-gray { background: var(--text-muted); }

.stat-icon-blink {
  animation: stat-icon-blink 1.2s ease-in-out infinite;
}

@keyframes stat-icon-blink {
  0%, 100% { background-color: var(--danger); }
  50% { background-color: #a3181c; }
}

.row-disburse-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 6px;
  padding: 4px 10px;
  border: 1px solid var(--danger);
  border-radius: 999px;
  background: #fff;
  color: var(--danger);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  vertical-align: middle;
  position: relative;
  top: -1px;
  white-space: nowrap;
}

.row-disburse-btn:hover {
  background: var(--danger);
  color: #fff;
}

.row-disburse-btn svg {
  width: 13px;
  height: 13px;
  stroke: currentColor;
  flex-shrink: 0;
}

/* ---------- Panel / table ---------- */

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

.panel-body {
  padding: 24px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  white-space: nowrap;
}

.data-table tr:last-child td {
  border-bottom: none;
}

/* ลิงก์ในตาราง (เช่นเลขที่สัญญา -> loan_ledger) ไม่ใช้ขีดเส้นใต้เลย ทำสีฟ้า var(--primary) อย่างเดียวให้รู้ว่ากดได้ */
.table-link {
  color: var(--primary);
  font-weight: 500;
  text-decoration: none;
}

.table-scroll {
  overflow-x: auto;
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 16px 0;
}

.table-toolbar .btn-action {
  padding: 9px 18px;
  font-size: 13px;
  border: 1px solid transparent;
}

.table-search {
  position: relative;
  width: 100%;
  max-width: 280px;
}

.table-search svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  stroke: var(--text-muted);
  pointer-events: none;
}

.table-search input {
  width: 100%;
  padding: 9px 12px 9px 36px;
  font-size: 13px;
  border: 1px solid #ddd;
  border-radius: 10px;
  font-family: inherit;
  font-weight: inherit;
  background: #fafafa;
}

.table-search input:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text-muted);
  cursor: pointer;
}

.btn-icon:hover {
  background: var(--bg);
  color: var(--text);
}

.btn-icon svg {
  width: 15px;
  height: 15px;
}

.date-empty-icon {
  width: 15px;
  height: 15px;
  stroke: var(--text-muted);
}

.contract-period-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.date-arrow-icon {
  width: 13px;
  height: 13px;
  stroke: var(--text-muted);
  flex-shrink: 0;
}

.table-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
}

.pagination-left {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

.page-size-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

.page-size-select {
  padding: 5px 8px;
  font-size: 13px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-family: inherit;
  font-weight: inherit;
  background: #fafafa;
}

.page-size-select:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
}

.pagination-info {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

.pagination {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
  gap: 4px;
  flex-wrap: wrap;
}

.pagination li a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  cursor: pointer;
}

.pagination li a svg {
  width: 15px;
  height: 15px;
}

.pagination li a:hover {
  background: var(--bg);
}

.pagination li.active a {
  background: var(--primary);
  color: #fff;
}

.pagination li.disabled a {
  opacity: 0.4;
  pointer-events: none;
  cursor: default;
}

.detail-label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.detail-value {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: pre-wrap;
}

.detail-value.status-badge {
  font-weight: 500;
}

.line-logo-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.status-badge.line-badge::before {
  display: none;
}

.line-status-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* .status-badge ตั้ง display:inline-flex ไว้ ซึ่งชนะ default ของ attribute [hidden] เพราะ author CSS มาทีหลัง UA stylesheet เสมอ
   ต้องประกาศ [hidden] ทับอีกทีไม่งั้นตั้ง el.hidden = true ทาง JS แล้วจะยังโชว์อยู่ */
#extra-line-block-status[hidden] {
  display: none;
}

/* ---------- Alert modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.12);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 60;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.22s ease, visibility 0.22s;
  pointer-events: none;
}

.modal-backdrop.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  background: #fff;
  border-radius: 16px;
  padding: 28px 24px;
  width: 90%;
  max-width: 340px;
  z-index: 61;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, -50%) scale(0.92);
  transition: opacity 0.22s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.22s;
  pointer-events: none;
}

.modal.open {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%) scale(1);
  pointer-events: auto;
}

.modal-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #fdecea;
  color: var(--danger);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}

.modal-icon svg {
  width: 24px;
  height: 24px;
}

.modal-icon.success {
  background: #e3f7e9;
  color: #1f9254;
}

.modal-icon.info {
  background: var(--primary-light);
  color: var(--primary-dark);
}

/* modal ดูรายละเอียดเบื้องต้นของหลักทรัพย์ (contracts.php) แบ่ง 2 คอลัมน์ ซ้าย = หัวข้อ (.label-hint) ขวา = ค่า
   กว้างคอลัมน์ซ้ายอิงตามหัวข้อที่ยาวที่สุด (max-content) คอลัมน์ขวากินพื้นที่ที่เหลือทั้งหมด (1fr)
   .collateral-info-fullrow ใช้กับข้อความเดี่ยวที่ไม่ใช่คู่หัวข้อ/ค่า (เช่น "กำลังโหลด..." หรือข้อความ error) ให้กินเต็มทั้ง 2 คอลัมน์ */
#collateral-info-modal .modal-message,
/* สรุปผลตรวจสอบสลิป (SlipOK) ใน qr-detected-modal ตอนตรวจสอบสำเร็จ — โครงเดียวกับด้านบน (ดู renderQrDetectedModalSummary ใน admin.js) */
#qr-detected-modal-summary {
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: 16px;
  row-gap: 6px;
  text-align: left;
}

/* display: grid ด้านบนมาทีหลัง UA stylesheet เสมอ เลยชนะ default ของ attribute [hidden] ต้องกำหนดทับตรงๆ อีกที (เหมือน .btn-primary .btn-label[hidden] ด้านล่าง) */
#qr-detected-modal-summary[hidden] {
  display: none;
}

/* เส้นคั่นกลุ่มข้อมูลผู้โอน/ผู้รับเงินใน #qr-detected-modal-summary (ดู renderQrDetectedModalSummary ใน admin.js) ต้องกิน grid-column เต็มทั้ง 2 คอลัมน์ ไม่งั้นจะโดน grid จัดให้อยู่แค่คอลัมน์ซ้าย (เหมือน .form-grid hr ด้านบน) */
#qr-detected-modal-summary hr {
  grid-column: 1 / -1;
  width: 100%;
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

/* ตัวเลขจำนวนเงินในกล่องสรุปผลตรวจสอบสลิป เน้นสีเขียว+ตัวหนา แยกจากค่าอื่นในตารางเดียวกัน */
.slip-amount-value {
  color: var(--success);
  font-weight: 700;
}

.collateral-info-fullrow {
  grid-column: 1 / -1;
}

/* สถานะ "กำลังโหลด..." ระหว่างรอ fetch รายละเอียดหลักทรัพย์ กึ่งกลางเสมอ (กิน grid-column เต็มแถวผ่าน .collateral-info-fullrow) */
.modal-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-muted);
}

/* preview เอกสารแนบของหลักทรัพย์ใน modal ดูรายละเอียดเบื้องต้น (ไม่มีชื่อไฟล์ แค่ thumbnail/ไอคอน) ใช้ .attachment-row-thumb/.attachment-row-icon-wrap ชุดเดียวกับหน้าแก้ไขหลักทรัพย์
   ไม่มีเอกสารแนบก็ไม่เหลือช่องว่างอ้างว้าง เพราะ innerHTML ว่างแล้ว margin จะไม่ถูกใช้ (:empty ตัด margin ทิ้ง) */
.collateral-info-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -8px 0 20px;
}

.collateral-info-attachments:empty {
  display: none;
  margin: 0;
}

/* wrapper คลิกได้ (คลิกดูพรีวิวถ้าเป็นรูป/PDF หรือโชว์ข้อความเตือนถ้าเป็น word/excel ที่พรีวิวในเบราว์เซอร์ไม่ได้ — ดู admin.js) */
.collateral-info-attachment {
  display: inline-flex;
  cursor: pointer;
}

/* ข้อความเตือนก่อนปุ่ม "ตกลง" ตอนคลิกไฟล์ word/excel ในแถบ preview ด้านบน (พรีวิวในเบราว์เซอร์ไม่ได้ ต้องไปเปิดที่หน้าข้อมูลหลักทรัพย์แทน) */
.collateral-info-open-hint {
  color: var(--warning);
  font-size: 12px;
  margin: -10px 0 16px;
}

.countdown-ring {
  position: relative;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.countdown-ring svg {
  width: 20px;
  height: 20px;
  transform: rotate(-90deg);
}

.countdown-ring-bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.3);
  stroke-width: 2;
}

.countdown-ring-progress {
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-dasharray: 50.27;
  stroke-dashoffset: 0;
}

.countdown-ring.counting .countdown-ring-progress {
  animation: countdown-ring-shrink 3s linear forwards;
}

@keyframes countdown-ring-shrink {
  from {
    stroke-dashoffset: 0;
  }
  to {
    stroke-dashoffset: 50.27;
  }
}

.countdown-ring-number {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

.modal-message {
  font-size: 14px;
  color: var(--text);
  margin: 0 0 20px;
  line-height: 1.5;
  white-space: pre-line; /* ให้ \n ในข้อความ (เช่น error message จาก server) ขึ้นบรรทัดใหม่จริงตอนตั้งผ่าน .textContent */
}

.modal .btn-primary {
  width: auto;
  padding: 10px 28px;
}

/* แถวปุ่ม "ยกเลิก / ยืนยันลบ" ของ confirm modal (ต่างจาก error/success modal ที่มีปุ่มเดียวกึ่งกลาง) */
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.modal-actions .btn-secondary,
.modal-actions .btn-primary {
  flex: 1;
  width: auto;
  justify-content: center;
}

.btn-danger {
  background: var(--danger);
}

.btn-danger:hover {
  background: #c8393d;
}

/* ---------- ตำแหน่งที่ตั้งหลักทรัพย์บนแผนที่ (ใน location-drawer) ---------- */

.location-map-preview {
  margin-top: 16px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.location-map-preview iframe {
  width: 100%;
  height: 260px;
  border: 0;
  display: block;
}

.location-map-preview-hint {
  margin-top: 16px;
  padding: 40px 16px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  background: var(--bg);
  border-radius: 12px;
  border: 1px dashed var(--border);
}

/* ใช้ grid แบ่ง 2 คอลัมน์เท่ากัน (QR / ปุ่มลัด) แทน flex เพื่อคุมความกว้างแต่ละฝั่งนิ่งกว่า ไม่ต้องพึ่ง flex-basis คำนวณเอง
   และยุบเหลือคอลัมน์เดียว (เรียงต่อกันแนวตั้ง) บนจอมือถือผ่าน media query ด้านล่าง กัน QR/ปุ่มบีบจนล้นหรืออ่านไม่ออก */
.location-actions-row {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.location-action-btns {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
}

.location-action-btn {
  justify-content: center;
  text-align: center;
}

.location-qr-wrap {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.location-qr-code {
  display: inline-flex;
  line-height: 0;
  flex-shrink: 0;
}

.location-qr-hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  max-width: 160px;
}

/* ---------- Modal พรีวิวรูปภาพ (lightbox แนบเอกสาร) ---------- */

.modal-preview {
  max-width: min(90vw, 720px);
  width: auto;
  padding: 0;
  background: transparent;
  box-shadow: none;
}

.modal-preview-viewport {
  max-width: min(90vw, 720px);
  max-height: 82vh;
  overflow: auto;
  display: flex;
  /* ห้ามใช้ align-items/justify-content: center — ตอนรูปซูมจนล้น viewport การจัดกลางแบบ flex align/justify
     จะ "ตัด" ส่วนที่ล้นออกครึ่งหนึ่งของแต่ละด้าน (ฝั่งบน/ซ้าย) จนเลื่อนไปดูไม่ได้เลย ต้องจัดกลางด้วย margin: auto
     บน .modal-preview-image แทน ซึ่งให้ scrollWidth/scrollHeight ครอบคลุมส่วนล้นทั้งหมดจริง เลื่อนดูได้ครบทุกมุม */
  border-radius: 12px;
  background: #101114;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.35) transparent;
}

/* สกิน scrollbar เฉพาะกล่องพรีวิวรูป (พื้นหลังมืด) ให้เข้าธีม แทน scrollbar ระบบสีเทาหนาๆ ที่ตัดกับพื้นหลัง — เบราว์เซอร์ตระกูล Chromium/Edge */
.modal-preview-viewport::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.modal-preview-viewport::-webkit-scrollbar-track {
  background: transparent;
}

.modal-preview-viewport::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.modal-preview-viewport::-webkit-scrollbar-thumb:hover {
  background-color: rgba(255, 255, 255, 0.55);
}

.modal-preview-image {
  display: block;
  width: 100%;
  max-height: 82vh;
  object-fit: contain;
  margin: auto; /* จัดกลางตอนรูปเล็กกว่า viewport โดยไม่ตัดส่วนล้นตอนซูม (ต่างจาก align-items/justify-content: center) */
  transition: transform 0.2s ease;
}

/* หมุน 90/270 องศาแล้วแกนกว้าง-สูงที่มองเห็นจะสลับกัน ต้องสลับ max-width/max-height ของทั้ง viewport และรูปตาม
   ให้ viewport มี height ที่แน่นอน (ไม่ใช่แค่ max-height) เพราะ .modal-preview-image.rotated-sideways ใช้ height: 100%
   ซึ่ง CSS จะ resolve % ของ parent ได้ก็ต่อเมื่อ parent มีความสูงที่แน่นอนเท่านั้น */
.modal-preview-viewport.rotated-sideways {
  max-width: 82vh;
  max-height: min(90vw, 720px);
  height: min(90vw, 720px);
}

.modal-preview-image.rotated-sideways {
  width: auto;
  height: 100%;
  max-width: 82vh;
  max-height: none;
}

.modal-preview-image.rotated-sideways.zoomed {
  max-width: none;
}

/* [hidden] เฉยๆ แพ้ .modal-preview-image/.modal-preview-pdf ที่ตั้ง display ไว้เอง (origin ของ author style ชนะ user-agent style เสมอไม่ว่า specificity จะเท่ากันแค่ไหน)
   ต้องมีกฎนี้ชนะเจาะจงไว้ ไม่งั้นตอน JS สลับ .hidden ระหว่างรูป/PDF ทั้งสองจะโชว์พร้อมกันเป็น flex item คนละครึ่งกล่อง */
.modal-preview-image[hidden],
.modal-preview-pdf[hidden] {
  display: none;
}

.modal-preview-image.zoomed {
  max-height: none;
  cursor: grab;
}

.modal-preview-image.zoomed.dragging {
  cursor: grabbing;
}

/* ขนาดเดียวกับกล่อง .modal-preview-viewport เป๊ะ กันไม่ให้ viewport ยุบขนาดตอนแสดง iframe (ซึ่งไม่มีขนาดโดยธรรมชาติเหมือนรูป) */
.modal-preview-pdf {
  display: block;
  width: min(90vw, 720px);
  height: 82vh;
  border: 0;
}

.modal-preview-close {
  position: absolute;
  top: -14px;
  right: -14px;
  background: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.modal-preview-zoom-controls {
  position: absolute;
  bottom: -18px;
  left: 50%;
  transform: translate(-50%, 100%);
  display: flex;
  align-items: center;
  gap: 2px;
  background: #fff;
  border-radius: 999px;
  padding: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* เหตุผลเดียวกับ .modal-preview-image[hidden]/.modal-preview-pdf[hidden] ด้านบน — ต้องเจาะจงชนะ display:flex ข้างบน [hidden] เฉยๆ ถึงจะซ่อนได้จริงตอนพรีวิว PDF */
.modal-preview-zoom-controls[hidden] {
  display: none;
}

.modal-preview-zoom-controls .btn-icon {
  border: none;
  width: 28px;
  height: 28px;
}

.modal-preview-zoom-divider {
  width: 1px;
  height: 16px;
  background: rgba(0, 0, 0, 0.12);
  margin: 0 2px;
}

.modal-preview-zoom-controls .btn-icon:disabled {
  opacity: 0.4;
  cursor: default;
  background: none;
}

.modal-preview-zoom-level {
  min-width: 44px;
  border: none;
  background: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 2px;
}

.modal-preview-zoom-level:hover {
  color: var(--text);
}

/* ---------- Button spinner ---------- */

.btn-primary .spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
}

.btn-primary.loading .btn-label {
  display: none;
}

.btn-primary.loading .spinner {
  display: inline-block;
}

@keyframes btn-spin {
  to {
    transform: rotate(360deg);
  }
}

.avatar-sm {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

.cell-name {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cell-name .name-text {
  font-weight: 400;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}

.status-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.status-badge.active {
  background: #e3f7e9;
  color: #1f9254;
}

.status-badge.active::before {
  background: #1f9254;
}

.status-badge.inactive {
  background: #fdecea;
  color: var(--danger);
}

.status-badge.inactive::before {
  background: var(--danger);
}

.status-badge.ended {
  background: #fef3e0;
  color: #b45309;
}

.status-badge.ended::before {
  background: var(--warning);
}

.status-badge.neutral {
  background: var(--primary-light);
  color: #3a3f47;
}

.status-badge.neutral::before {
  background: var(--primary);
}

.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* ---------- Settings inner nav ---------- */

.settings-layout {
  display: flex;
  align-items: flex-start;
  gap: 24px;
}

.settings-nav {
  flex: 0 0 220px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 28px;
}

.settings-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 400;
}

.settings-nav-item svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  flex-shrink: 0;
}

.settings-nav-item:hover {
  background: #f6f8fb;
  color: var(--text);
}

.settings-nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
}

.settings-content {
  flex: 1;
  min-width: 0;
}

.settings-panel {
  display: none;
}

.settings-panel.active {
  display: block;
}

/* ปุ่มบันทึกของฟอร์มคอนฟิก (ดู lib/config_system_form.php) วางไว้จุดเดียวกับปุ่ม "เพิ่ม" ของหน้าตั้งค่าข้อมูลพื้นฐาน (.table-toolbar .btn-action)
   ต้อง .btn-primary ไว้ (ไม่ใช่ .btn-action) เพื่อให้ยังใช้ spinner/loading state ตอน submit ได้ (ดู .btn-primary.loading ด้านล่าง) แค่ทับขนาด/ความกว้างให้เท่ากันเฉยๆ */
.table-toolbar .btn-primary {
  width: auto;
  padding: 9px 18px;
  font-size: 13px;
  /* .table-toolbar .btn-action (ปุ่ม "เพิ่ม" ของ config_master) มี border โปร่งใส 1px บวกความสูงไว้ 2px — .btn-primary ปกติ border: none
     ต้องใส่ border แบบเดียวกันไว้ด้วย ไม่งั้นปุ่มบันทึกจะเตี้ยกว่าปุ่มเพิ่ม 2px ทั้งที่ padding/font-size เท่ากัน */
  border: 1px solid transparent;
}

/* .panel-body ปกติ padding-top 24px เต็ม ใต้ .table-toolbar (padding-bottom: 0) เลยรวมเป็นช่องว่างหนาไปหน่อยระหว่างแถวปุ่มบันทึกกับแถวการ์ดคอนฟิก ลดเฉพาะจุดนี้ */
.config-system-form .panel-body {
  padding-top: 10px;
}

/* กริดของฟอร์มคอนฟิก (ดู lib/config_system_form.php) แยกจาก .form-grid ทั่วไป (2 คอลัมน์ตายตัว) เพราะต้องการการ์ดแคบๆ
   3 ใบต่อแถวตายตัวบนจอเดสก์ท็อป (มีแค่ 1 คอนฟิกตอนนี้ก็เลยกว้างแค่ 1/3 แถว ไม่ยืดเต็ม) ลดคอลัมน์ลงตามจอผ่าน media query ด้านล่าง (ดู "Responsive: mobile") */
.config-system-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

/* แต่ละ CONFIG_KEY ครอบด้วยการ์ดของตัวเอง กัน field ลอยโล่งๆ บนพื้นขาวของ .panel เฉยๆ
   สีพื้นเดียวกับ .panel (var(--card)) เลยต้องพึ่งเส้นขอบ + shadow จางๆ แทนสีพื้นต่างกันเพื่อให้ยังแยกจากกันได้ */
.config-system-grid .form-field {
  margin-bottom: 0;
  padding: 16px 20px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

/* ---------- Responsive: mobile ---------- */

@media (max-width: 900px) {
  .page-header-toggle {
    display: flex;
  }

  .sidebar {
    transform: translateX(-100%);
    width: 78%;
    max-width: 280px;
    top: 0;
    /* 100vh นับความสูง viewport เต็ม ไม่หักพื้นที่ที่แถบ URL ของเบราว์เซอร์บังอยู่ ทำให้บล็อก user
       ที่ถูกดันไปชิดล่างสุด (.sidebar-nav-groups margin-bottom: auto) หลุดไปอยู่ใต้ขอบจอที่มองไม่เห็น
       100dvh คำนวณจากพื้นที่จอที่มองเห็นจริง แก้ปัญหานี้ตรงๆ (เก็บ 100vh ไว้ก่อนเป็น fallback ให้เบราว์เซอร์เก่าที่ไม่รู้จัก dvh) */
    height: 100vh;
    height: 100dvh;
    padding-top: 20px;
  }

  .admin-shell.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .admin-shell.sidebar-open .sidebar-backdrop {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  .main-content {
    margin-left: 0;
  }

  .content-inner {
    padding: 16px;
  }

  /* align-items: stretch ทับ align-items: flex-start ของ desktop (บรรทัด 1778) ไว้ด้วย — ตอน flex-direction เปลี่ยนเป็น column
     แกน cross จะกลายเป็นแนวนอนแทน ถ้ายังเป็น flex-start อยู่ .settings-content จะหด/ขยายตามความกว้างของ "เนื้อหาข้างใน" แทนที่จะยืดเต็มคอลัมน์
     เจอบั๊กจากตารางกว้างที่ดันความกว้างทั้งหน้าออกไปแทนที่จะ scroll แค่ในกรอบตาราง (ดู .table-scroll) เพราะจุดนี้ */
  .settings-layout {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
  }

  .settings-nav {
    position: static;
    flex-direction: row;
    flex-basis: auto;
    width: 100%;
    overflow-x: auto;
  }

  .settings-nav-item {
    white-space: nowrap;
  }

  /* หัวข้อบนมือถืออยู่บรรทัดเดียวกับปุ่มเมนู/ปุ่ม action เสมอ (ไม่ wrap ลงบรรทัดใหม่เหมือน desktop)
     ต้อง sticky ไว้ที่ขอบบนแทน .mobile-topbar เดิมที่ถูกลบไป เพื่อให้ยังกดเปิดเมนูได้ตอนเลื่อนหน้าจอ */
  .page-header {
    position: sticky;
    top: 0;
    /* เดิม z-index: 30 สูงกว่า .sidebar (25) และ .sidebar-backdrop (20) ทำให้ตอนเปิด sidebar บนมือถือ
       page-header (sticky อยู่ใน .main-content) วาดทับด้านบนของ sidebar/backdrop แทนที่จะอยู่ใต้
       ผลคือส่วนบนของเมนูโดนบัง แตะ/scroll ในโซนที่ถูกทับก็ไปโดน page-header แทน sidebar (เลื่อนเมนูไม่ได้)
       ลดลงมาให้ต่ำกว่า backdrop เสมอ ยังพอสูงกว่าเนื้อหาปกติที่ไม่มี z-index (static/auto) ก็เพียงพอต่อการ sticky อยู่แล้ว */
    z-index: 15;
    flex-wrap: nowrap;
    align-items: center;
    margin: -16px -16px 16px;
    padding: 10px 16px;
    background: #fff;
    border-bottom: 1px solid var(--border);
  }

  .page-icon-box {
    display: none;
  }

  .page-title {
    font-size: 16px;
  }

  .page-subtitle {
    display: none;
  }

  .page-header-right {
    justify-content: flex-end;
  }

  .btn-action {
    padding: 8px 14px;
  }

  .breadcrumb {
    display: none;
  }

  .data-table th:nth-child(4),
  .data-table td:nth-child(4) {
    display: none;
  }

  .stat-grid {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 12px;
    margin-bottom: 20px;
    padding-bottom: 4px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  .stat-tile {
    flex: 0 0 auto;
    min-width: 148px;
    padding: 14px 16px;
    scroll-snap-align: start;
  }

  .stat-label {
    font-size: 12px;
    margin: 0 0 4px;
    white-space: nowrap;
  }

  .stat-value {
    font-size: 20px;
  }

  .stat-icon {
    width: 34px;
    height: 34px;
  }

  .stat-icon svg {
    width: 15px;
    height: 15px;
  }

  /* จอแคบลง (settings-nav ย้ายไปอยู่แถวนอนด้านบนแล้ว) 3 คอลัมน์แคบเกินไป ลดเหลือ 2 (ดู .config-system-grid) */
  .config-system-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* มือถือ: การ์ดคอนฟิกเต็มแถวใบเดียว ต้องมาไว้ "หลัง" @media (max-width: 900px) ด้านบนในไฟล์เสมอ (ไม่ใช่รวมไว้ในบล็อก 640px บรรทัด 462
   เหมือนตอนแรก) เพราะจอมือถือ (< 640px) เข้าเงื่อนไข media query ทั้งสองพร้อมกัน แล้ว .config-system-grid specificity เท่ากันทั้งคู่
   (แค่ class เดียว) เลยตัดสินกันด้วยลำดับที่มาทีหลังในไฟล์ล้วนๆ ไม่ใช่ query ไหนแคบกว่า ถ้าอยู่ก่อนบล็อก 900px จะโดนทับกลายเป็น 2 คอลัมน์แทน */
@media (max-width: 640px) {
  .config-system-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .login-card {
    padding: 28px 20px;
  }

  .location-actions-row {
    grid-template-columns: 1fr;
  }

  /* จอแคบมาก: ซ่อนข้อความบนปุ่ม action เหลือแค่ไอคอน กันดันหัวข้อจนล้นบรรทัด */
  .btn-action-label {
    display: none;
  }

  .btn-action {
    padding: 8px 10px;
  }
}

/* ---------- Side drawer ---------- */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.12);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 50;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.28s ease, visibility 0.28s;
  pointer-events: none;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 640px;
  max-width: 100%;
  background: #fff;
  z-index: 51;
  transform: translateX(100%);
  transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.32s ease;
  display: flex;
  flex-direction: column;
}

.drawer.open {
  transform: translateX(0);
  /* box-shadow อยู่ที่ .open เท่านั้น เพราะตอนปิด drawer ถูก translateX(100%) ออกจอไปแล้วก็จริง
     แต่ box-shadow ที่ offset-x ติดลบ (เงาทอดไปทางซ้าย) จะยังเบลอทะลุเข้ามาในจอราว 30px แม้ตัว drawer จะออกจอไปแล้ว
     ถ้าประกาศไว้ตลอด จึงต้องผูกไว้กับ .open เท่านั้นไม่งั้นจะเห็นเป็นเงาจางๆ ที่ขอบขวาของทุกหน้าตลอดเวลา */
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.15);
}

.drawer-backdrop.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.drawer-title {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
}

.drawer-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin: 2px 0 0;
}

/* subtitle ของ location-drawer เติม icon ประเภทหลักทรัพย์ (เหมือน .type-badge ในตาราง) ไว้ข้างหน้าข้อความด้วย */
#location-drawer-subtitle {
  display: flex;
  align-items: center;
  gap: 4px;
}

#location-drawer-subtitle svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

.drawer-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  color: var(--text-muted);
  display: flex;
  flex-shrink: 0;
}

.drawer-close:hover {
  background: var(--bg);
}

.drawer form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.drawer-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.drawer-body .form-field {
  margin-bottom: 14px;
}

.drawer-filter-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 20px;
}

.drawer-filter-row .form-field {
  flex: 1;
  margin-bottom: 0;
}

.drawer-filter-row .btn-primary {
  width: auto;
  padding: 9px 18px;
  flex-shrink: 0;
}

.browser-detect-cell {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.drawer-extra-info {
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ส่วน "เข้าใช้งานล่าสุด/LINE" อยู่บนสุดของ extra info ตอนนี้ (ต่อจาก field ที่อยู่/บันทึกทั่วไปเลย) ไม่ต้องมีเส้นกั้นซ้ำ
   และไม่ต้องมี margin/padding เผื่อเส้นอีกต่อไป เอาระยะห่างให้เท่ากับช่องฟอร์มอื่นๆ (.form-field margin-bottom: 14px) จะได้ไม่ห่างเกินไป */
#customer-extra-info {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.drawer-extra-info[hidden] {
  display: none;
}

.drawer-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 10px;
}

.attachment-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-align: center;
  padding: 12px 16px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.attachment-dropzone:hover,
.attachment-dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}

/* สัญญาเริ่มเดินแล้ว ห้ามแนบเอกสารเพิ่มของรายการจ่ายเงินเปิดสัญญาอีก (ดู applyDisburseAttachmentLockState ใน admin.js) — ปิดการคลิก/ลาก-วางไปเลยที่ระดับ CSS กันเผื่อ JS หลุด */
.attachment-dropzone.disabled {
  cursor: not-allowed;
  opacity: 0.6;
  pointer-events: none;
}

.attachment-dropzone svg {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.attachment-dropzone p {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.attachment-dropzone-link {
  color: var(--primary);
  font-weight: 500;
  margin-left: 4px;
}

.attachment-dropzone-hint {
  font-size: 11px !important;
  color: var(--text-muted);
  opacity: 0.8;
}

.attachment-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.attachment-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}

/* กล่องครอบ 32x32 เท่ากับ .attachment-row-thumb เป๊ะ กันชื่อไฟล์แต่ละแถวเยื้องกันเวลาแถวหนึ่งเป็นรูป อีกแถวเป็น pdf/word/excel */
.attachment-row-icon-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.attachment-row-icon {
  width: 18px;
  height: 18px;
  color: var(--text-muted);
}

.attachment-row-icon.tone-pdf {
  color: var(--danger);
}

.attachment-row-icon.tone-word {
  color: var(--primary);
}

.attachment-row-icon.tone-excel {
  color: var(--success);
}

.attachment-row-thumb {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid var(--border);
  object-fit: cover;
  flex-shrink: 0;
  cursor: pointer;
}

/* specificity ต้องชนะ .attachment-row .btn-icon (ตั้ง width/height 28px คงที่ไว้) ถึงจะขยายกว้างพอใส่ข้อความได้ */
.attachment-row .attachment-delete-btn.confirming {
  width: auto;
  padding: 0 10px;
  gap: 6px;
  border-color: var(--danger);
  background: #fdeceb;
}

.attachment-delete-confirm-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--danger);
  white-space: nowrap;
}

.attachment-delete-btn .countdown-ring-bg {
  stroke: rgba(229, 72, 77, 0.25);
}

.attachment-delete-btn .countdown-ring-progress {
  stroke: var(--danger);
}

.attachment-delete-btn .countdown-ring-number {
  color: var(--danger);
}

/* ปุ่มลบเอกสารแนบนับถอยหลัง 5 วิ ไม่ใช่ 3 วิเหมือน success modal เดิม ต้อง override แค่ duration */
.attachment-delete-btn .countdown-ring.counting .countdown-ring-progress {
  animation-duration: 5s;
}

.attachment-row-info {
  flex: 1;
  min-width: 0;
}

.attachment-row-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.attachment-row-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.attachment-row .btn-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.attachment-row-uploading {
  background: var(--bg);
}

.attachment-row-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
}

/* แถวแจ้งไฟล์แนบมีปัญหา (แทน alert modal กันเวลาลากหลายไฟล์พร้อมกันแล้ว alert เด้งซ้อนกันไม่ได้) */
.attachment-row-error {
  border-color: var(--danger);
  background: #fdeceb;
}

.attachment-row-error .attachment-row-name {
  color: var(--danger);
}

.attachment-row-error-reason {
  color: var(--danger);
  opacity: 0.85;
}

.attachment-row-icon.tone-error {
  color: var(--danger);
}

.attachment-row-error-timer {
  font-size: 11px;
  color: var(--danger);
  opacity: 0.7;
  flex-shrink: 0;
  white-space: nowrap;
}

.drawer-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
  flex-wrap: nowrap;
}

.drawer-footer .btn-primary {
  width: auto;
  padding: 11px 22px;
}

/* .btn-icon ตั้ง width/height 30px ตายตัวไว้ ต้อง override เป็น auto ทั้งคู่ก่อน ถึงจะให้ align-items: stretch
   ของ .drawer-footer (พ่อ) ดันความสูงให้เท่าปุ่ม "ยกเลิก"/"บันทึก" ข้างๆ ได้จริง แล้วใช้ aspect-ratio บังคับให้กว้าง = สูงเสมอ (สี่เหลี่ยมจัตุรัส)
   ใช้ class ร่วมกันทุกปุ่มลบมุมล่างซ้ายของ drawer footer (ลูกค้า/หลักทรัพย์/ฯลฯ) ไม่ผูกกับ id เดียว */
.drawer-delete-btn {
  width: auto;
  height: auto;
  aspect-ratio: 1 / 1;
}

.pin-display {
  width: 100%;
}

.drawer-footer-actions {
  display: flex;
  gap: 12px;
  margin-left: auto;
}

/* .btn-icon ตั้ง display:inline-flex ไว้ ชนะ default ของ attribute [hidden] เพราะ author CSS มาทีหลัง UA stylesheet เสมอ
   ต้องประกาศ [hidden] ทับอีกที (เหมือนที่อื่นในไฟล์นี้) ไม่งั้นตั้ง el.hidden = true ทาง JS แล้วปุ่มลบจะยังโชว์อยู่ตอนเปิด drawer โหมดเพิ่มข้อมูลใหม่ */
.drawer-delete-btn[hidden] {
  display: none;
}

/* เหตุผลเดียวกับ .drawer-delete-btn[hidden] ด้านบน — ปุ่มลบเอกสารแนบก็มี .btn-icon ด้วย ต้องประกาศทับอีกที
   ไม่งั้นตั้ง el.hidden = true ตอนล็อกฟอร์ม (applyDisburseAttachmentLockState ใน admin.js) แล้วปุ่มลบจะยังโชว์อยู่ */
.attachment-delete-btn[hidden] {
  display: none;
}

/* .btn-primary .btn-label ตั้ง display:inline-flex ไว้ ซึ่งชนะ default ของ attribute [hidden] เพราะ author CSS มาทีหลัง UA stylesheet เสมอ
   ต้องประกาศ [hidden] ทับอีกที (เหมือน .drawer-extra-info[hidden] ด้านบน) ไม่งั้นตั้ง el.hidden = true ทาง JS แล้วจะยังโชว์อยู่
   ปุ่ม "บันทึก" มี label 2 แบบสลับกัน (ปกติ / บันทึกอัตโนมัติ ตอนแนบ-ลบเอกสารแนบ) */
.btn-primary .btn-label[hidden] {
  display: none;
}

.spinner-inline {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
  flex-shrink: 0;
}

/* ตัวแปรสีเข้มไว้ใช้บนปุ่มพื้นขาว (เช่น .btn-icon) ต่างจาก .spinner-inline ที่ออกแบบไว้ให้ตัดกับปุ่มพื้นสีเข้ม */
.spinner-inline-muted {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--text-muted);
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
  flex-shrink: 0;
}

/* ---------- Bootstrap Datepicker (วันเกิด) theme override ---------- */
/* คลาสทั้งหมดใน bootstrap-datepicker ขึ้นต้นด้วย .datepicker เท่านั้น จึงไม่กระทบสไตล์อื่นในโปรเจกต์ */
.datepicker.dropdown-menu {
  /* bootstrap-datepicker3.min.css คาดว่ามี .dropdown-menu ของ Bootstrap core มาให้ position: absolute อยู่แล้ว
     แต่โปรเจกต์นี้ไม่ได้โหลด Bootstrap เต็มตัว จึงต้องกำหนดเองไม่งั้นปฏิทินจะไม่ถูก position และ z-index ก็จะไม่มีผล (เพราะ z-index ใช้ไม่ได้กับ position: static) */
  position: absolute;
  float: left;
  min-width: 240px;
  margin-top: 2px;
  background-color: #fff;
  background-clip: padding-box;
  font-family: 'Google Sans', 'Sarabun', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(22, 33, 62, 0.16);
  padding: 10px;
  /* .drawer อยู่ที่ z-index: 51 ต้องสูงกว่านั้นไม่งั้นปฏิทินจะเด้งมาแต่โผล่ไม่พ้น drawer */
  z-index: 9999 !important;
}

.datepicker table tr td,
.datepicker table tr th {
  font-size: 13px;
  border-radius: 8px;
}

.datepicker table tr th.datepicker-switch,
.datepicker table tr th.prev,
.datepicker table tr th.next {
  color: var(--primary);
  font-weight: 600;
}

.datepicker table tr th.prev:hover,
.datepicker table tr th.next:hover,
.datepicker table tr th.datepicker-switch:hover {
  background: var(--primary-light);
}

.datepicker table tr td.day:hover,
.datepicker table tr td.focused {
  background: var(--primary-light);
}

.datepicker table tr td.today,
.datepicker table tr td.today:hover {
  background: var(--primary-light);
  color: #3a3f47;
}

.datepicker table tr td.active.day,
.datepicker table tr td.active.day:hover,
.datepicker table tr td.active.day.focused {
  background: var(--primary);
  background-image: none;
  color: #fff;
  text-shadow: none;
}

.datepicker table tr td.new,
.datepicker table tr td.old {
  color: var(--text-muted);
}

/* ---------- Select2 (สถานะ) theme override ---------- */
.select2-container--default .select2-selection--single {
  height: 38px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fafafa;
  overflow: hidden; /* กันข้อความตัวเลือกที่ยาว (เช่น "เช็ค / แคชเชียร์เช็ค • Cheque / Cashier's Cheque") ล้นออกนอกกรอบสูง 38px ด้านบน/ล่างจนทับ field ข้างๆ */
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
  line-height: 36px;
  padding-left: 12px;
  padding-right: 30px;
  font-size: 14px;
  color: var(--text);
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis; /* ข้อความยาวเกินให้ตัดจบด้วย ... แถวเดียวเสมอ ไม่ขึ้นบรรทัดใหม่จนกล่องสูงเกิน 38px */
}

/* .input-icon ครอบ select2 (เช่น ช่องทางการชำระเงิน/ธนาคารในฟอร์มจ่ายเงินเปิดสัญญา) — select2 แทนที่ <select> เดิมด้วย span.select2-container ของมันเอง
   (ตัว <select> จริงถูกซ่อนไว้) เลยต้องเผื่อระยะเยื้องซ้ายให้ข้อความที่ select2-selection__rendered แทน ไอคอนยังวางตำแหน่งด้วย .input-icon svg ตามปกติ
   ต้องอยู่หลัง rule padding-left: 12px ด้านบน (specificity เท่ากัน ชนะกันด้วย source order) ถึงจะ override ได้ */
.input-icon .select2-container--default .select2-selection--single .select2-selection__rendered {
  padding-left: 32px;
}

/* สีกรอบ/พื้นของช่อง "สถานะ" ให้ตรงกับ .status-badge ในตารางลูกค้า (ใช้งาน=success, สิ้นสุดสัญญา=warning, ระงับการใช้งาน=danger) */
.select2-selection--single.status-select-active {
  border-color: #1f9254;
  background: #e3f7e9;
}

.select2-selection--single.status-select-ended {
  border-color: var(--warning);
  background: #fef3e0;
}

.select2-selection--single.status-select-inactive {
  border-color: var(--danger);
  background: #fdecea;
}

.select2-selection--single.status-select-neutral {
  border-color: var(--primary);
  background: var(--primary-light);
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
  height: 36px;
  width: 30px;
}

.select2-container--default .select2-selection--single .select2-selection__arrow b {
  border-color: var(--text-muted) transparent transparent transparent;
}

.select2-container--default.select2-container--open .select2-selection--single {
  border-color: var(--primary);
  background: #fff;
}

.select2-container--open .select2-dropdown {
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(22, 33, 62, 0.16);
  overflow: hidden;
  font-family: 'Google Sans', 'Sarabun', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  z-index: 9999;
}

.select2-container--default .select2-search--dropdown {
  padding: 8px;
}

.select2-container--default .select2-search--dropdown .select2-search__field {
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fafafa;
  font-family: 'Google Sans', 'Sarabun', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  outline: none;
}

.select2-container--default .select2-search--dropdown .select2-search__field:focus {
  border-color: var(--primary);
  background: #fff;
}

.select2-container--default .select2-results__option {
  padding: 8px 12px;
  font-size: 13px;
}

.select2-container--default .select2-results__option--highlighted[aria-selected] {
  background: var(--primary-light);
  color: #3a3f47;
}

.select2-container--default .select2-results__option[aria-selected="true"] {
  background: var(--primary);
  color: #fff;
}

/* ตัวเลือกจำนวนรายการต่อหน้า (compact กว่าฟอร์มปกติ) */
.select2-selection--single.select2-pagesize {
  height: 30px;
  border-radius: 8px;
  background: #fafafa;
}

.select2-selection--single.select2-pagesize .select2-selection__rendered {
  line-height: 28px;
  padding-left: 8px;
  padding-right: 24px;
  font-size: 13px;
}

.select2-selection--single.select2-pagesize .select2-selection__arrow {
  height: 28px;
  width: 24px;
}

.select2-pagesize-dropdown .select2-results__option {
  padding: 6px 10px;
  font-size: 13px;
}

/* ---------- เจ้าของกรรมสิทธิ์หลักทรัพย์: ปุ่ม "+เพิ่ม" เปิดช่องค้นหา แล้วรายชื่อที่เพิ่มแล้วโชว์เป็น list (เลขบัตร + ชื่อ) เหมือน .attachment-row ---------- */
.form-field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.form-field-label-row label {
  margin-bottom: 0;
}

.form-field-label-row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.owner-add-btn {
  width: auto;
  flex-shrink: 0;
  padding: 4px 10px;
  font-size: 12px;
  gap: 6px;
}

.owner-add-btn svg {
  width: 13px;
  height: 13px;
}

/* .btn-secondary ตั้ง display:inline-flex ไว้ ซึ่งชนะ default ของ attribute [hidden] เพราะ author CSS มาทีหลัง UA stylesheet เสมอ
   ต้องประกาศ [hidden] ทับอีกที (เหมือนที่อื่นในไฟล์นี้) ไม่งั้นตั้ง el.hidden = true ทาง JS แล้วปุ่ม "+เพิ่ม" เจ้าของกรรมสิทธิ์จะยังโชว์/กดได้อยู่ตอนทรัพย์ผูกสัญญาแล้ว */
.owner-add-btn[hidden] {
  display: none;
}

.owner-search-wrap {
  margin-top: 8px;
}

.owner-search-wrap[hidden] {
  display: none;
}

.owner-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.owner-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}

/* หลักทรัพย์ค้ำประกันในฟอร์มสัญญาใช้ป้ายประเภทเดียวกับตารางหลักทรัพย์ (.type-badge) กันบีบเวลาชื่อ/ที่ตั้งยาว */
.owner-row .type-badge {
  flex-shrink: 0;
}

.owner-row-info {
  flex: 1;
  min-width: 0;
}

.owner-row-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.owner-row-idnumber {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.owner-row .btn-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

/* ---------- select2 ที่ถูก disable ไว้ (เช่น อำเภอ/ตำบล ก่อนเลือกจังหวัด/อำเภอ) ให้หน้าตาตรงกับ .form-field input[disabled] ทั่วโปรเจกต์ ---------- */
.select2-container--default.select2-container--disabled .select2-selection--single {
  background: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* ช่อง "สถานะ" ตอน disable (เช่นทรัพย์ผูกสัญญาแล้ว) ยังต้องโชว์สีพื้นตามสถานะเดิม (ไม่ใช่สีเทาเรียบๆ แบบ select ที่ disable ทั่วไปด้านบน)
   ต้องเจาะจงกว่า rule ด้านบนถึงจะชนะ (เพิ่ม .status-select-* เข้าไปในตัวเลือกด้วยให้ specificity สูงกว่า) */
.select2-container--default.select2-container--disabled .select2-selection--single.status-select-active {
  background: #e3f7e9;
}

.select2-container--default.select2-container--disabled .select2-selection--single.status-select-ended {
  background: #fef3e0;
}

.select2-container--default.select2-container--disabled .select2-selection--single.status-select-inactive {
  background: #fdecea;
}

.select2-container--default.select2-container--disabled .select2-selection--single.status-select-neutral {
  background: var(--primary-light);
}

/* ---------- ตัวเลือกประเภทหลักทรัพย์ (ที่ดิน / อาคารชุด) ---------- */
.type-toggle {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
}

.type-toggle-option {
  flex: 1;
  cursor: pointer;
}

.type-toggle-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.type-toggle-option span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px;
  border: 1px solid #ddd;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  background: #fafafa;
}

.type-toggle-option span svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
}

.type-toggle-option input:checked + span {
  border-color: var(--primary);
  background: var(--primary-light);
  color: #3a3f47;
}

/* ---------- Toggle switch (เปิด/ปิด) เช่น "สัญญากำหนดระยะเวลา" ในฟอร์มสัญญา ----------
   ใช้ selector "label.switch-field" (ไม่ใช่แค่ ".switch-field") เพราะตัว element เป็น <label>
   ต้อง specificity สูงกว่า ".form-field label" (บรรทัด 88) ที่ set display:block ไว้ ไม่งั้น flex ที่นี่จะโดนทับ
   กลายเป็น block แล้ว track/thumb/ข้อความไปเรียงซ้อนทับกันแทนที่จะเรียงแถวเดียวกัน */
label.switch-field {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 9px 0;
  margin-bottom: 0;
  user-select: none;
}

.switch-field input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  position: relative;
  flex: 0 0 auto;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: #cfd4dd;
  transition: background 0.18s ease;
}

.switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.18s ease;
}

.switch-field input:checked + .switch-track {
  background: var(--primary);
}

.switch-field input:checked + .switch-track .switch-thumb {
  transform: translateX(18px);
}

.switch-field input:focus-visible + .switch-track {
  box-shadow: 0 0 0 3px var(--primary-light);
}

.switch-label-text {
  font-size: 14px;
  color: var(--text-muted);
}

.switch-field input:checked ~ .switch-label-text {
  color: var(--text);
}

/* กำหนดงวด: dropdown สำเร็จรูป + ช่องกำหนดเอง อยู่ข้างกันในแถวเดียว (ไม่ตกบรรทัดใหม่แบบเดิม)
   select2 แทนที่ <select> เดิมด้วย .select2-container ที่เป็น sibling ต้องเลี้ยง flex ให้ทั้งคู่ */
.total-terms-row {
  display: flex;
  gap: 8px;
}

.total-terms-row select,
.total-terms-row .select2-container {
  flex: 1;
  min-width: 0;
}

.total-terms-row .total-terms-custom-input {
  flex: 1;
  min-width: 0;
}

.collateral-type-fields {
  margin-top: 4px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

#condo-fields {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.collateral-type-fields[hidden] {
  display: none;
}

/* ---------- กลุ่ม input หลายช่องแบ่งเท่ากันในแถวเดียว ใช้ label เดียวคุมทั้งกลุ่ม (เช่น เลขที่ดิน-หน้าสำรวจ, เนื้อที่ไร่-งาน-ตารางวา) ---------- */
.grouped-input-row {
  display: flex;
  gap: 8px;
}

.grouped-input {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.grouped-input-col {
  flex: 1;
  min-width: 0;
}

.type-status-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  white-space: nowrap;
}

/* ---------- ป้ายประเภทหลักทรัพย์ในตารางลิสต์ ---------- */
.type-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

.type-badge svg {
  width: 13px;
  height: 13px;
  stroke: currentColor;
}

.type-badge.type-land {
  background: #e3f7e9;
  color: #1f9254;
}

.type-badge.type-condo {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.type-badge.type-mortgage {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.type-badge.type-consignment {
  background: #fef3e0;
  color: #b45309;
}

/* Bootstrap Tooltip (bootstrap.bundle.min.js) — เอาเฉพาะ CSS ของ component นี้มาใช้ ไม่โหลด bootstrap.css ทั้งชุด
   เพื่อไม่ให้ reset/typography ของ Bootstrap ไปทับ style เดิมของทั้งเว็บ */
.tooltip {
  position: absolute;
  z-index: 1080;
  display: block;
  margin: 0;
  font-family: 'Google Sans', 'Sarabun', sans-serif;
  font-size: 0.8125rem;
  line-height: 1.5;
  word-wrap: break-word;
  opacity: 0;
}

.tooltip.show {
  opacity: 1;
}

.tooltip .tooltip-arrow {
  position: absolute;
  display: block;
  width: 0.8rem;
  height: 0.4rem;
}

.tooltip .tooltip-arrow::before {
  position: absolute;
  content: '';
  border-color: transparent;
  border-style: solid;
}

.bs-tooltip-top .tooltip-arrow,
.bs-tooltip-auto[data-popper-placement^='top'] .tooltip-arrow {
  bottom: 0;
}
.bs-tooltip-top .tooltip-arrow::before,
.bs-tooltip-auto[data-popper-placement^='top'] .tooltip-arrow::before {
  top: -1px;
  border-width: 0.4rem 0.4rem 0;
  border-top-color: #3a3f47;
}

.bs-tooltip-bottom .tooltip-arrow,
.bs-tooltip-auto[data-popper-placement^='bottom'] .tooltip-arrow {
  top: 0;
}
.bs-tooltip-bottom .tooltip-arrow::before,
.bs-tooltip-auto[data-popper-placement^='bottom'] .tooltip-arrow::before {
  bottom: -1px;
  border-width: 0 0.4rem 0.4rem;
  border-bottom-color: #3a3f47;
}

.bs-tooltip-start .tooltip-arrow,
.bs-tooltip-auto[data-popper-placement^='left'] .tooltip-arrow {
  right: 0;
  width: 0.4rem;
  height: 0.8rem;
}
.bs-tooltip-start .tooltip-arrow::before,
.bs-tooltip-auto[data-popper-placement^='left'] .tooltip-arrow::before {
  left: -1px;
  border-width: 0.4rem 0 0.4rem 0.4rem;
  border-left-color: #3a3f47;
}

.bs-tooltip-end .tooltip-arrow,
.bs-tooltip-auto[data-popper-placement^='right'] .tooltip-arrow {
  left: 0;
  width: 0.4rem;
  height: 0.8rem;
}
.bs-tooltip-end .tooltip-arrow::before,
.bs-tooltip-auto[data-popper-placement^='right'] .tooltip-arrow::before {
  right: -1px;
  border-width: 0.4rem 0.4rem 0.4rem 0;
  border-right-color: #3a3f47;
}

.tooltip-inner {
  max-width: 220px;
  padding: 0.35rem 0.7rem;
  color: #fff;
  text-align: center;
  background-color: #3a3f47;
  border-radius: 6px;
}
