/* =====================================================================
 * assets/css/app.css — ระบบดีไซน์กลางของทุกหน้า (ลูกค้า + แอดมิน)
 *
 * ทุกหน้าในระบบใช้เลย์เอาต์เดียวกัน: แถบเมนูซ้าย (sidebar) ตายตัว +
 * แถบหัวเรื่องบาง ๆ ด้านบนของเนื้อหา — ไม่มี navbar เต็มความกว้างแล้ว
 * และไม่มีเมนูล่างจอของมือถือแล้ว (มือถือเปิด sidebar เป็น drawer)
 *
 * กฎการใช้งาน
 *   - สีทุกสีมาจากตัวแปรใน :root / .dark เท่านั้น ห้าม hardcode hex ในหน้า
 *   - การ์ดทุกใบใช้ .card (ของเดิม .glass-panel ถูก map มาให้เท่ากัน)
 *   - ปุ่ม .btn + .btn-primary/.btn-ghost/.btn-danger/.btn-soft (+ .btn-sm)
 *   - ตารางใช้ .table ครอบด้วย .table-wrap
 *   - toast / dialog วาดโดย app.js เท่านั้น (TG.toast / TG.dialog)
 * ===================================================================== */

:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-hover: #f1f5f9;
  --surface-active: #e2e8f0;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-faint: #94a3b8;

  --primary: #2563eb;
  --primary-soft: rgba(37, 99, 235, .10);
  --success: #16a34a;
  --success-soft: rgba(22, 163, 74, .10);
  --warning: #d97706;
  --warning-soft: rgba(217, 119, 6, .10);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, .10);

  --chart-grid: rgba(71, 85, 105, 0.14);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 4px 16px -4px rgba(15, 23, 42, .10);
  --shadow-lg: 0 24px 48px -12px rgba(15, 23, 42, .22);

  --sidebar-w: 16.5rem;
  --topbar-h: 3.75rem;
  --radius: .75rem;
  --radius-lg: 1rem;
}

.dark {
  --bg: #020617;
  --surface: #0b1120;
  --surface-2: #0f172a;
  --surface-hover: #172033;
  --surface-active: #1e293b;
  --border: #1e293b;
  --border-strong: #334155;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --text-faint: #64748b;

  --primary: #60a5fa;
  --primary-soft: rgba(96, 165, 250, .14);
  --success: #4ade80;
  --success-soft: rgba(74, 222, 128, .14);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, .14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, .14);

  --chart-grid: rgba(148, 163, 184, 0.16);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 4px 16px -4px rgba(0, 0, 0, .5);
  --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, .7);
}

* { -webkit-tap-highlight-color: transparent; }
html { scroll-behavior: smooth; }

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: '"Noto Sans Thai"', 'Noto Sans Thai', system-ui, sans-serif;
  transition: background-color .25s ease, color .25s ease;
}

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* =====================================================================
 *  เลย์เอาต์ระบบ: sidebar ซ้าย + topbar บางด้านบน
 *  จอ < lg  : sidebar ซ่อนอยู่นอกจอ เปิดเป็น drawer ด้วยปุ่ม hamburger
 *  จอ >= lg : sidebar ค้างอยู่ตลอด body เว้นที่ด้วย padding-left
 * ===================================================================== */
.tg-sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  z-index: 70;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform .24s cubic-bezier(.16, 1, .3, 1);
}
.tg-sidebar.is-open { transform: none; box-shadow: var(--shadow-lg); }

.tg-scrim {
  position: fixed; inset: 0; z-index: 65;
  background: rgba(2, 6, 23, .55);
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease;
}
.tg-scrim.is-open { opacity: 1; pointer-events: auto; }

.tg-brand {
  display: flex; align-items: center; gap: .625rem;
  height: var(--topbar-h);
  padding: 0 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tg-nav { flex: 1; overflow-y: auto; padding: .875rem .625rem 1rem; }
.tg-nav-label {
  padding: .75rem .75rem .375rem;
  font-size: .625rem; font-weight: 800; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-faint);
}
.tg-nav-item {
  position: relative;
  display: flex; align-items: center; gap: .75rem;
  padding: .5625rem .75rem;
  border-radius: var(--radius);
  font-size: .875rem; font-weight: 600;
  color: var(--text-muted);
  transition: background-color .14s, color .14s;
}
.tg-nav-item:hover { background: var(--surface-hover); color: var(--text); }
.tg-nav-item > i:first-child { width: 1.125rem; text-align: center; font-size: .9375rem; flex-shrink: 0; }
.tg-nav-item.is-active { background: var(--primary-soft); color: var(--primary); }
.tg-nav-item.is-active::before {
  content: ''; position: absolute; left: -.625rem; top: 50%;
  width: 3px; height: 1.25rem; margin-top: -.625rem;
  border-radius: 0 3px 3px 0; background: var(--primary);
}
.tg-nav-badge {
  margin-left: auto; min-width: 1.25rem; height: 1.25rem; padding: 0 .375rem;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px; background: var(--danger); color: #fff;
  font-size: .625rem; font-weight: 800;
}
.tg-sidebar-foot { padding: .75rem; border-top: 1px solid var(--border); flex-shrink: 0; }

/* โหมดแอดมิน: ใช้สีแดงเป็นสีเน้น เพื่อให้รู้ทันทีว่าอยู่หลังบ้าน */
.tg-sidebar[data-scope="admin"] .tg-nav-item.is-active { background: var(--danger-soft); color: var(--danger); }
.tg-sidebar[data-scope="admin"] .tg-nav-item.is-active::before { background: var(--danger); }

.tg-topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: .75rem;
  padding: 0 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

@media (min-width: 1024px) {
  .tg-sidebar { transform: none; box-shadow: none; }
  body.tg-app { padding-left: var(--sidebar-w); }
  .tg-scrim, .tg-burger { display: none !important; }
  .tg-topbar { padding: 0 1.5rem; }
}

/* =====================================================================
 *  การ์ด / พาเนล
 *  .glass-panel = ชื่อเดิมที่หน้าอื่นใช้อยู่ ให้ผลเหมือน .card ทุกอย่าง
 *  (เลิกใช้ backdrop-filter แล้ว เพราะมันสร้าง stacking context ใหม่
 *   จนการ์ดลอยขึ้นมาทับเมนู/กล่องโต้ตอบ)
 * ===================================================================== */
.card, .glass-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.card-title { font-size: .9375rem; font-weight: 800; color: var(--text); }
.card-body { padding: 1.25rem; }

/* ตัวเลขสรุป (stat tile) */
.stat { padding: 1.125rem; border-radius: var(--radius-lg); border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow-sm); }
.stat-label { font-size: .6875rem; font-weight: 700; color: var(--text-muted); letter-spacing: .02em; }
.stat-value { font-size: 1.5rem; font-weight: 900; line-height: 1.15; color: var(--text); margin-top: .25rem; }
.stat-hint { font-size: .6875rem; color: var(--text-faint); margin-top: .25rem; }

/* พื้นหลังลายตาราง (หน้าแรก) */
.grid-bg {
  background-image:
    linear-gradient(var(--chart-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--chart-grid) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 40%, transparent 100%);
  -webkit-mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 40%, transparent 100%);
}

/* =====================================================================
 *  ฟอร์ม
 * ===================================================================== */
.field {
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  padding: .625rem .875rem;
  font-size: .9rem;
  transition: border-color .15s, box-shadow .15s;
}
.field::placeholder { color: var(--text-faint); }
.field:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.field:disabled { opacity: .6; cursor: not-allowed; background: var(--surface-2); }
.field-error { border-color: var(--danger) !important; box-shadow: 0 0 0 3px var(--danger-soft) !important; }
.field-label { display: block; font-size: .78rem; font-weight: 700; margin-bottom: .375rem; color: var(--text); }
.field-hint { font-size: .72rem; color: var(--text-muted); margin-top: .375rem; line-height: 1.5; }
.field-msg { font-size: .74rem; color: var(--danger); margin-top: .3rem; min-height: 1rem; }
select.field {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%2364748b'%3E%3Cpath d='M4.2 6.2 8 10l3.8-3.8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .625rem center; background-size: 1.1rem;
  padding-right: 2rem;
}
textarea.field { min-height: 5.5rem; resize: vertical; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  border-radius: var(--radius); padding: .625rem 1.125rem;
  font-weight: 700; font-size: .875rem; line-height: 1.25rem;
  transition: transform .1s, background-color .15s, border-color .15s, opacity .15s, color .15s;
  cursor: pointer; border: 1px solid transparent; white-space: nowrap;
}
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-sm { padding: .375rem .75rem; font-size: .78rem; border-radius: .625rem; }
.btn-icon { padding: 0; width: 2.25rem; height: 2.25rem; border-radius: var(--radius); }
.btn-primary { background: #2563eb; color: #fff; border-color: #2563eb; }
.btn-primary:hover:not(:disabled) { background: #1d4ed8; border-color: #1d4ed8; }
.btn-ghost { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-hover); }
.btn-soft { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.btn-soft:hover:not(:disabled) { background: var(--surface-hover); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn-danger:hover:not(:disabled) { background: #dc2626; color: #fff; }
.btn-success { background: #16a34a; color: #fff; border-color: #16a34a; }
.btn-success:hover:not(:disabled) { background: #15803d; }

/* ---------- OTP ---------- */
.otp-input {
  width: 3rem; height: 3.5rem; text-align: center;
  font-size: 1.35rem; font-weight: 800; letter-spacing: .05em;
  border-radius: var(--radius); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text);
}
.otp-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

/* =====================================================================
 *  badge / ตาราง / สถานะว่าง
 * ===================================================================== */
.badge {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .6875rem; font-weight: 700; padding: .1875rem .5rem;
  border-radius: .5rem; letter-spacing: .01em; white-space: nowrap;
  border: 1px solid transparent;
}
.badge-green { background: var(--success-soft); color: var(--success); border-color: var(--success-soft); }
.badge-amber { background: var(--warning-soft); color: var(--warning); border-color: var(--warning-soft); }
.badge-red   { background: var(--danger-soft);  color: var(--danger);  border-color: var(--danger-soft); }
.badge-blue  { background: var(--primary-soft); color: var(--primary); border-color: var(--primary-soft); }
.badge-slate { background: var(--surface-hover); color: var(--text-muted); border-color: var(--border); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table thead th {
  text-align: left; white-space: nowrap;
  padding: .625rem .75rem;
  font-size: .6875rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-muted); background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.table thead th:first-child { border-top-left-radius: var(--radius); }
.table thead th:last-child { border-top-right-radius: var(--radius); }
.table tbody td { padding: .6875rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-hover); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8125rem; }

.tg-empty { padding: 2.5rem 1rem; text-align: center; color: var(--text-muted); }
.tg-empty i { font-size: 1.5rem; opacity: .45; display: block; margin-bottom: .5rem; }
.tg-empty p { font-size: .875rem; }

/* ---------- skeleton ---------- */
.skeleton { background: linear-gradient(90deg, var(--surface-hover) 25%, var(--surface-active) 37%, var(--surface-hover) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--radius); }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* =====================================================================
 *  toast — วาดโดย TG.toast() เท่านั้น
 * ===================================================================== */
#tg-toasts {
  position: fixed; z-index: 90;
  top: .875rem; right: .875rem; left: .875rem;
  display: flex; flex-direction: column; gap: .625rem;
  pointer-events: none;
}
@media (min-width: 640px) { #tg-toasts { left: auto; width: 23rem; } }

.tg-toast {
  pointer-events: auto; position: relative; overflow: hidden;
  display: flex; gap: .75rem; align-items: flex-start;
  padding: .875rem 1rem .875rem .875rem;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  animation: tgToastIn .28s cubic-bezier(.16, 1, .3, 1) both;
}
.tg-toast.is-out { animation: tgToastOut .18s ease forwards; }
.tg-toast::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--tone, var(--primary)); }
.tg-toast-icon {
  flex-shrink: 0; width: 1.75rem; height: 1.75rem; border-radius: .5rem;
  display: flex; align-items: center; justify-content: center;
  background: var(--tone-soft, var(--primary-soft)); color: var(--tone, var(--primary));
  font-size: .8125rem;
}
.tg-toast-title { font-size: .8125rem; font-weight: 800; color: var(--text); line-height: 1.35; }
.tg-toast-msg { font-size: .75rem; color: var(--text-muted); margin-top: .1875rem; line-height: 1.5; word-break: break-word; }
.tg-toast-x { flex-shrink: 0; color: var(--text-faint); font-size: .75rem; padding: .125rem; }
.tg-toast-x:hover { color: var(--text); }
.tg-toast-bar { position: absolute; left: 0; bottom: 0; height: 2px; background: var(--tone, var(--primary)); opacity: .5; }

.tg-toast.tone-success { --tone: var(--success); --tone-soft: var(--success-soft); }
.tg-toast.tone-error   { --tone: var(--danger);  --tone-soft: var(--danger-soft); }
.tg-toast.tone-warning { --tone: var(--warning); --tone-soft: var(--warning-soft); }
.tg-toast.tone-info    { --tone: var(--primary); --tone-soft: var(--primary-soft); }

@keyframes tgToastIn { from { opacity: 0; transform: translateY(-8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes tgToastOut { to { opacity: 0; transform: translateX(12px); } }
@keyframes tgbar { from { width: 100%; } to { width: 0; } }

/* =====================================================================
 *  dialog (confirm / alert / prompt) — วาดโดย TG.dialog() เท่านั้น
 * ===================================================================== */
.tg-modal { position: fixed; inset: 0; z-index: 95; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.tg-modal-scrim { position: absolute; inset: 0; background: rgba(2, 6, 23, .6); animation: tgFade .18s ease both; }
.tg-modal-box {
  position: relative; width: 100%; max-width: 27rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  padding: 1.5rem;
  animation: tgPop .24s cubic-bezier(.16, 1, .3, 1) both;
}
.tg-modal-icon {
  width: 2.75rem; height: 2.75rem; flex-shrink: 0; border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center; font-size: 1.0625rem;
  background: var(--tone-soft, var(--primary-soft)); color: var(--tone, var(--primary));
}
.tg-modal-title { font-size: 1.0625rem; font-weight: 800; color: var(--text); }
.tg-modal-text { font-size: .875rem; color: var(--text-muted); margin-top: .375rem; line-height: 1.6; }
.tg-modal-actions { display: flex; gap: .625rem; margin-top: 1.5rem; }
.tg-modal-actions .btn { flex: 1; }
.tg-modal.tone-danger .tg-modal-box { --tone: var(--danger); --tone-soft: var(--danger-soft); }
.tg-modal.tone-success .tg-modal-box { --tone: var(--success); --tone-soft: var(--success-soft); }
.tg-modal.tone-warning .tg-modal-box { --tone: var(--warning); --tone-soft: var(--warning-soft); }

@keyframes tgFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes tgPop { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }

/* =====================================================================
 *  แผงแจ้งเตือน (กระดิ่งบน topbar) + เมนูผู้ใช้
 * ===================================================================== */
.tg-pop {
  position: absolute; right: 0; top: calc(100% + .5rem);
  width: 21rem; max-width: calc(100vw - 1.5rem);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  overflow: hidden; z-index: 60;
  animation: tgPop .16s ease both;
}
.tg-pop-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .75rem 1rem; border-bottom: 1px solid var(--border); }
.tg-pop-item { display: flex; gap: .75rem; padding: .75rem 1rem; border-bottom: 1px solid var(--border); }
.tg-pop-item:last-child { border-bottom: 0; }
.tg-pop-item:hover { background: var(--surface-hover); }
.tg-pop-menu { display: flex; align-items: center; gap: .625rem; width: 100%; padding: .625rem 1rem; font-size: .875rem; color: var(--text); }
.tg-pop-menu:hover { background: var(--surface-hover); }
.tg-pop-menu > i:first-child { width: 1rem; text-align: center; color: var(--text-muted); }

/* ---------- chart ---------- */
.chart-grid-line { stroke: var(--chart-grid); stroke-width: 1; }
.chart-axis-label { fill: var(--text-muted); font-size: 10px; }
.chart-hit { fill: transparent; cursor: crosshair; }

/* ---------- scrollbar ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-active); border-radius: 999px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

/* =====================================================================
 *  ตารางข้อมูลกลาง (TG.dataTable) — ใช้ทั้งหลังบ้านและฝั่งลูกค้า
 *  โครง: .dt > .dt-tabs / .dt-toolbar / .dt-scroll > table.dt-table / .dt-foot
 * ===================================================================== */
.dt { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); overflow: hidden; }

/* แท็บสถานะ + ตัวเลข */
.dt-tabs { display: flex; gap: .25rem; padding: .625rem .75rem 0; overflow-x: auto; border-bottom: 1px solid var(--border); scrollbar-width: none; }
.dt-tabs::-webkit-scrollbar { display: none; }
.dt-tab {
  position: relative; flex-shrink: 0; display: inline-flex; align-items: center; gap: .5rem;
  padding: .5rem .75rem .75rem; font-size: .8125rem; font-weight: 700; color: var(--text-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color .14s, border-color .14s;
}
.dt-tab:hover { color: var(--text); }
.dt-tab.is-active { color: var(--primary); border-bottom-color: var(--primary); }
.dt-tab-count {
  min-width: 1.375rem; height: 1.25rem; padding: 0 .4rem; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .6875rem; font-weight: 800; background: var(--surface-hover); color: var(--text-muted);
}
.dt-tab.is-active .dt-tab-count { background: var(--primary-soft); color: var(--primary); }
.dt-tab-count.is-alert { background: var(--danger-soft); color: var(--danger); }

/* แถบค้นหา + ตัวกรอง */
.dt-toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .625rem; padding: .875rem 1rem; }
.dt-search { position: relative; flex: 1 1 15rem; max-width: 24rem; min-width: 0; }
.dt-search > i { position: absolute; left: .875rem; top: 50%; transform: translateY(-50%); font-size: .8125rem; color: var(--text-faint); pointer-events: none; }
.dt-search .field { padding-left: 2.25rem; padding-right: 2rem; }
.dt-search-x { position: absolute; right: .375rem; top: 50%; transform: translateY(-50%); width: 1.5rem; height: 1.5rem; border-radius: 999px; color: var(--text-faint); font-size: .75rem; }
.dt-search-x:hover { background: var(--surface-hover); color: var(--text); }
.dt-filter { display: flex; flex-direction: column; gap: .125rem; min-width: 0; }
.dt-filter > span { font-size: .625rem; font-weight: 800; letter-spacing: .04em; color: var(--text-faint); padding-left: .125rem; }
.dt-filter .field { padding: .4375rem .75rem; font-size: .8125rem; width: auto; min-width: 8.5rem; }
.dt-filter select.field { padding-right: 1.9rem; }
.dt-spacer { flex: 1; }
.dt-chips { display: flex; flex-wrap: wrap; gap: .375rem; padding: 0 1rem .75rem; }
.dt-chip {
  display: inline-flex; align-items: center; gap: .375rem; padding: .1875rem .375rem .1875rem .625rem;
  border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: .6875rem; font-weight: 700;
}
.dt-chip button { width: 1.125rem; height: 1.125rem; border-radius: 999px; font-size: .625rem; display: inline-flex; align-items: center; justify-content: center; }
.dt-chip button:hover { background: var(--primary); color: #fff; }

/* ตาราง */
.dt-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border-top: 1px solid var(--border); position: relative; }
.dt-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .8125rem; }
.dt-table thead th {
  text-align: left; white-space: nowrap;
  padding: .6875rem 1rem; font-size: .75rem; font-weight: 700; color: var(--text-muted);
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.dt-table thead th.is-sort { cursor: pointer; user-select: none; }
.dt-table thead th.is-sort:hover { color: var(--text); }
.dt-table thead th.is-sorted { color: var(--primary); }
.dt-sort { display: inline-block; margin-left: .3rem; font-size: .625rem; opacity: .4; }
.dt-table thead th.is-sorted .dt-sort { opacity: 1; }
.dt-table tbody td { padding: .8125rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.dt-table tbody tr:last-child td { border-bottom: 0; }
.dt-table tbody tr:hover td { background: var(--surface-2); }
.dt-table tbody tr.is-clickable { cursor: pointer; }
.dt-table .is-right { text-align: right; font-variant-numeric: tabular-nums; }
.dt-table .is-center { text-align: center; }
.dt-table .is-nowrap { white-space: nowrap; }
.dt-table td.dt-col-actions, .dt-table th.dt-col-actions { text-align: right; width: 1%; white-space: nowrap; }
.dt.is-loading .dt-scroll::after {
  content: ''; position: absolute; left: 0; right: 0; top: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--primary), transparent); background-size: 40% 100%; background-repeat: no-repeat;
  animation: dtLoad 1s linear infinite;
}
.dt.is-loading .dt-table tbody { opacity: .55; transition: opacity .15s; }
@keyframes dtLoad { from { background-position: -40% 0; } to { background-position: 140% 0; } }

/* เซลล์สำเร็จรูป */
.dt-user { display: flex; align-items: center; gap: .625rem; min-width: 0; }
.dt-avatar {
  width: 2rem; height: 2rem; border-radius: .625rem; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 800; background: var(--primary-soft); color: var(--primary);
}
.dt-title { font-weight: 700; color: var(--text); line-height: 1.3; }
.dt-sub { font-size: .6875rem; color: var(--text-muted); line-height: 1.35; }
.dt-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .75rem; }
.dt-muted { color: var(--text-muted); }
.dt-trunc { max-width: 18rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dt-money { font-weight: 800; font-variant-numeric: tabular-nums; }
.dt-actions { display: inline-flex; align-items: center; gap: .25rem; }
.dt-btn {
  display: inline-flex; align-items: center; gap: .375rem; height: 1.875rem; padding: 0 .625rem;
  border-radius: .5rem; font-size: .75rem; font-weight: 700; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); transition: background-color .14s, color .14s, border-color .14s;
}
.dt-btn:hover { background: var(--surface-hover); }
.dt-btn.is-icon { width: 1.875rem; padding: 0; justify-content: center; }
.dt-btn.tone-primary { background: var(--primary-soft); border-color: transparent; color: var(--primary); }
.dt-btn.tone-primary:hover { background: var(--primary); color: #fff; }
.dt-btn.tone-success { background: var(--success-soft); border-color: transparent; color: var(--success); }
.dt-btn.tone-success:hover { background: var(--success); color: #fff; }
.dt-btn.tone-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.dt-btn.tone-danger:hover { background: var(--danger); color: #fff; }

/* ท้ายตาราง: สรุป + จำนวนต่อหน้า + เลขหน้า */
.dt-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; padding: .75rem 1rem; border-top: 1px solid var(--border); font-size: .75rem; color: var(--text-muted); }
.dt-foot b { color: var(--text); }
.dt-foot-l { display: flex; align-items: center; gap: .875rem; flex-wrap: wrap; }
.dt-per { display: inline-flex; align-items: center; gap: .5rem; }
.dt-per .field { width: auto; padding: .25rem 1.75rem .25rem .625rem; font-size: .75rem; }
.dt-pager { display: inline-flex; align-items: center; gap: .25rem; }
.dt-page {
  min-width: 2rem; height: 2rem; padding: 0 .5rem; border-radius: .5rem; font-size: .75rem; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; color: var(--text-muted); border: 1px solid transparent;
}
.dt-page:hover:not(:disabled):not(.is-active) { background: var(--surface-hover); color: var(--text); }
.dt-page.is-active { background: var(--primary); color: #fff; }
.dt-page:disabled { opacity: .4; cursor: not-allowed; }
.dt-gap { min-width: 1.25rem; text-align: center; color: var(--text-faint); }
.dt-page.is-nav { border-color: var(--border); }
.dt-foot-r { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.dt-page-of { display: none; min-width: 3.5rem; text-align: center; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.dt-jump { display: inline-flex; align-items: center; gap: .5rem; }
.dt-jump .field { width: 4.25rem; padding: .25rem .5rem; font-size: .75rem; text-align: center; }
/* จอเล็ก: ซ่อนเลขหน้า เหลือปุ่มนำทาง + "หน้า / ทั้งหมด" */
@media (max-width: 639px) {
  .dt-foot { justify-content: center; }
  .dt-foot-l { justify-content: center; width: 100%; }
  .dt-pager .dt-num, .dt-pager .dt-gap { display: none; }
  .dt-page-of { display: inline-block; }
  .dt-page.is-nav { min-width: 2.5rem; height: 2.5rem; }
}

/* สถานะว่าง / ผิดพลาด */
.dt-empty { padding: 3.5rem 1rem; text-align: center; color: var(--text-muted); }
.dt-empty-ic { width: 3.5rem; height: 3.5rem; margin: 0 auto .875rem; border-radius: 1rem; display: flex; align-items: center; justify-content: center; font-size: 1.375rem; background: var(--surface-hover); color: var(--text-faint); }
.dt-empty b { display: block; color: var(--text); font-size: .9375rem; }
.dt-empty p { font-size: .8125rem; margin-top: .25rem; }
.dt-skel td > span { display: block; height: .75rem; border-radius: .375rem; background: linear-gradient(90deg, var(--surface-hover) 25%, var(--surface-active) 37%, var(--surface-hover) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; }

/* มือถือ: แถวกลายเป็นการ์ดซ้อน (ใช้ data-label ของแต่ละเซลล์เป็นหัวข้อ) */
@media (max-width: 767px) {
  .dt-toolbar { padding: .75rem; }
  .dt-search { max-width: none; flex-basis: 100%; }
  .dt-filter { flex: 1 1 8rem; }
  .dt-filter .field { width: 100%; min-width: 0; }
  .dt-table thead { display: none; }
  .dt-table, .dt-table tbody, .dt-table tr, .dt-table td { display: block; width: 100%; }
  .dt-table tbody tr { padding: .75rem .875rem; border-bottom: 1px solid var(--border); }
  .dt-table tbody tr:last-child { border-bottom: 0; }
  .dt-table tbody td { border: 0 !important; padding: .25rem 0; display: flex; align-items: center; justify-content: space-between; gap: 1rem; text-align: right; background: transparent !important; }
  .dt-table tbody td[data-label]::before { content: attr(data-label); flex-shrink: 0; font-size: .6875rem; font-weight: 700; color: var(--text-faint); text-align: left; }
  .dt-table tbody td.dt-col-primary { justify-content: flex-start; text-align: left; padding-bottom: .5rem; }
  .dt-table tbody td.dt-col-primary::before { display: none; }
  .dt-table td.dt-col-actions { width: 100%; justify-content: flex-end; padding-top: .5rem; }
  .dt-table td.dt-col-actions::before { display: none; }
  .dt-trunc { max-width: 12rem; }
  .dt-foot { justify-content: center; }
}

/* =====================================================================
 *  dialog แบบฟอร์ม / drawer — วาดโดย TG.dialog.form() / TG.dialog.drawer()
 * ===================================================================== */
.tg-modal-box.is-form { padding: 0; display: flex; flex-direction: column; max-height: calc(100vh - 2rem); overflow: hidden; }
.tg-modal-box.size-sm { max-width: 24rem; }
.tg-modal-box.size-lg { max-width: 40rem; }
.tg-modal-box.size-xl { max-width: 56rem; }
.tg-modal-head { display: flex; align-items: flex-start; gap: .875rem; padding: 1.25rem 1.5rem 1rem; border-bottom: 1px solid var(--border); }
.tg-modal-x { margin-left: auto; flex-shrink: 0; width: 2rem; height: 2rem; border-radius: .625rem; color: var(--text-faint); }
.tg-modal-x:hover { background: var(--surface-hover); color: var(--text); }
.tg-modal-body { padding: 1.25rem 1.5rem; overflow-y: auto; flex: 1; }
.tg-modal-foot { display: flex; justify-content: flex-end; gap: .625rem; padding: 1rem 1.5rem; border-top: 1px solid var(--border); background: var(--surface-2); }
.tg-modal-foot .btn { min-width: 6.5rem; }
.tg-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.tg-form-grid .is-wide { grid-column: 1 / -1; }
.tg-info-list { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); padding: .25rem .875rem; margin-bottom: 1rem; font-size: .8125rem; }
.tg-info-list > div { display: flex; justify-content: space-between; gap: 1rem; padding: .5rem 0; border-bottom: 1px dashed var(--border); }
.tg-info-list > div:last-child { border-bottom: 0; }
.tg-info-list dt { color: var(--text-muted); }
.tg-info-list dd { font-weight: 700; text-align: right; word-break: break-word; }

/* สวิตช์เปิด/ปิด */
.tg-switch { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .625rem .875rem; border: 1px solid var(--border-strong); border-radius: var(--radius); cursor: pointer; }
.tg-switch input { position: absolute; opacity: 0; pointer-events: none; }
.tg-switch-track { position: relative; flex-shrink: 0; width: 2.5rem; height: 1.4rem; border-radius: 999px; background: var(--surface-active); transition: background-color .15s; }
.tg-switch-track::after { content: ''; position: absolute; top: .15rem; left: .15rem; width: 1.1rem; height: 1.1rem; border-radius: 999px; background: #fff; box-shadow: var(--shadow-sm); transition: transform .15s; }
.tg-switch input:checked + .tg-switch-track { background: var(--success); }
.tg-switch input:checked + .tg-switch-track::after { transform: translateX(1.1rem); }
.tg-switch input:focus-visible + .tg-switch-track { outline: 2px solid var(--primary); outline-offset: 2px; }

/* drawer ข้างขวา (รายละเอียดผู้ใช้ ฯลฯ) */
.tg-drawer { position: fixed; inset: 0; z-index: 95; display: flex; justify-content: flex-end; }
.tg-drawer-panel { position: relative; width: 100%; max-width: 34rem; height: 100%; display: flex; flex-direction: column; background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg); animation: tgSlide .26s cubic-bezier(.16, 1, .3, 1) both; }
.tg-drawer-panel.size-lg { max-width: 46rem; }
@keyframes tgSlide { from { transform: translateX(2rem); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 639px) {
  .tg-modal { align-items: flex-end; padding: 0; }
  .tg-modal-box { max-width: none !important; border-radius: var(--radius-lg) var(--radius-lg) 0 0; animation-name: tgSheet; }
  .tg-modal-box.is-form { max-height: 92vh; }
  .tg-form-grid { grid-template-columns: 1fr; }
  .tg-modal-foot .btn { flex: 1; }
}
@keyframes tgSheet { from { transform: translateY(100%); } to { transform: none; } }

/* =====================================================================
 *  แบนเนอร์คุกกี้ + ดาวรีวิว
 * ===================================================================== */
.tg-cookie {
  position: fixed; z-index: 92; left: 1rem; right: 1rem; bottom: 1rem; max-width: 46rem; margin: 0 auto;
  display: flex; align-items: center; gap: 1rem; padding: 1rem 1.125rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  animation: tgPop .3s cubic-bezier(.16, 1, .3, 1) both;
}
.tg-cookie-ic { width: 2.5rem; height: 2.5rem; flex-shrink: 0; border-radius: var(--radius); display: flex; align-items: center; justify-content: center; background: var(--warning-soft); color: var(--warning); font-size: 1.125rem; }
.tg-cookie p { font-size: .8125rem; color: var(--text-muted); line-height: 1.55; flex: 1; }
.tg-cookie p b { color: var(--text); }
.tg-cookie p a { color: var(--primary); font-weight: 700; }
.tg-cookie-actions { display: flex; gap: .5rem; flex-shrink: 0; }
@media (max-width: 639px) { .tg-cookie { flex-direction: column; align-items: stretch; } .tg-cookie-actions .btn { flex: 1; } }

.tg-stars { display: inline-flex; gap: .125rem; color: #f59e0b; font-size: .8125rem; }
.tg-stars .off { color: var(--border-strong); }
.tg-star-input { display: inline-flex; flex-direction: row-reverse; gap: .25rem; }
.tg-star-input input { position: absolute; opacity: 0; pointer-events: none; }
.tg-star-input label { font-size: 1.75rem; line-height: 1; color: var(--border-strong); cursor: pointer; transition: color .1s, transform .1s; }
.tg-star-input label:hover, .tg-star-input label:hover ~ label, .tg-star-input input:checked ~ label { color: #f59e0b; }
.tg-star-input label:hover { transform: scale(1.12); }

/* =====================================================================
 *  Sidebar แบบย่อได้ (collapsible) สไตล์ 21st.dev dashboard
 *  body.tg-collapsed (จอ lg+) = เหลือแถบไอคอน, hover ที่ไอคอนแสดง tooltip
 *  สถานะจำไว้ที่ localStorage['tg_sidebar'] — สลับด้วย TG.sidebar.collapse()
 * ===================================================================== */
:root { --sidebar-w: 16rem; --sidebar-w-collapsed: 4rem; }

.tg-sidebar {
  padding: .5rem; box-shadow: var(--shadow-sm);
  transition: transform .3s cubic-bezier(.16, 1, .3, 1), width .3s cubic-bezier(.16, 1, .3, 1);
}
body.tg-app { transition: padding-left .3s cubic-bezier(.16, 1, .3, 1), background-color .25s ease, color .25s ease; }

/* ---- TitleSection: โลโก้ + ชื่อบัญชี + chevron ---- */
.tg-sb-brand { display: flex; align-items: center; gap: .625rem; padding: .25rem .5rem .875rem; flex-shrink: 0; }
.tg-sb-title { margin-bottom: 1rem; padding-bottom: .75rem; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.tg-sb-account { display: flex; align-items: center; gap: .75rem; padding: .5rem; border-radius: .5rem; transition: background-color .15s; }
.tg-sb-account:hover { background: var(--surface-hover); }
.tg-sb-logo {
  width: 2.5rem; height: 2.5rem; flex-shrink: 0; border-radius: .5rem;
  display: grid; place-content: center; color: #fff; font-size: 1rem;
  background: linear-gradient(135deg, #3b82f6, #2563eb); box-shadow: var(--shadow-sm);
}
.tg-sidebar[data-scope="admin"] .tg-sb-logo { background: linear-gradient(135deg, #3b82f6, #6366f1); }
.tg-sb-name { display: block; font-size: .875rem; font-weight: 700; color: var(--text); line-height: 1.25; }
.tg-sb-plan { display: block; font-size: .75rem; color: var(--text-muted); line-height: 1.3; }
.tg-sb-chev { margin-left: auto; font-size: .6875rem; color: var(--text-faint); }

/* ---- เมนู (Option) ---- */
.tg-nav { padding: 0 0 .5rem; overflow-x: hidden; display: flex; flex-direction: column; gap: .25rem; scrollbar-width: thin; }
.tg-nav-label { margin-top: .75rem; padding: .5rem .75rem .25rem; font-size: .6875rem; font-weight: 600; letter-spacing: .06em; color: var(--text-muted); }
.tg-nav-label.is-first { margin-top: 0; }
.tg-nav-item {
  flex-shrink: 0; gap: 0; padding: 0; height: 2.75rem; width: 100%;
  border-radius: .375rem; border-left: 2px solid transparent;
  font-weight: 500; transition: background-color .2s, color .2s, box-shadow .2s;
}
.tg-nav-item::before { content: none !important; }
.tg-nav-ic { width: 3rem; height: 100%; flex-shrink: 0; display: grid; place-content: center; font-size: .9375rem; }
.tg-nav-ic i { transition: transform .2s ease; }
.tg-nav-item:hover .tg-nav-ic i { transform: scale(1.1); }
.tg-nav-text { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tg-nav-item.is-active,
.tg-sidebar[data-scope="admin"] .tg-nav-item.is-active {
  background: var(--primary-soft); color: var(--primary);
  border-left-color: var(--primary); box-shadow: var(--shadow-sm); font-weight: 600;
}
.tg-nav-item.is-danger { color: var(--danger); }
.tg-nav-badge { margin: 0 .75rem 0 .25rem; flex-shrink: 0; background: #3b82f6; font-weight: 600; font-size: .6875rem; }
.tg-nav-badge.is-alert { background: var(--danger); }
.tg-sidebar-foot { padding: .75rem .25rem; }

/* ---- ToggleClose: ปุ่มซ่อนเมนูล่างสุด ---- */
.tg-sb-toggle {
  display: none; align-items: center; flex-shrink: 0;
  margin: 0 -.5rem -.5rem; height: 3.5rem; padding: 0 .5rem;
  border-top: 1px solid var(--border);
  font-size: .875rem; font-weight: 500; color: var(--text-muted);
  transition: background-color .15s, color .15s;
}
.tg-sb-toggle:hover { background: var(--surface-hover); color: var(--text); }
.tg-sb-toggle .tg-nav-ic i { transform: rotate(180deg); transition: transform .3s cubic-bezier(.16, 1, .3, 1); }

/* ---- topbar = หัวหน้าเพจแบบในตัวอย่าง ---- */
.tg-topbar { height: 4.25rem; background: var(--bg); }
.tg-top-btn {
  position: relative; width: 2.5rem; height: 2.5rem; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: .5rem; border: 1px solid var(--border); background: var(--surface);
  color: var(--text-muted); transition: background-color .15s, color .15s;
}
.tg-top-btn:hover { background: var(--surface-hover); color: var(--text); }

@media (min-width: 1024px) {
  .tg-sb-toggle { display: flex; }
  body.tg-collapsed.tg-app { padding-left: var(--sidebar-w-collapsed); }
  body.tg-collapsed .tg-sidebar { width: var(--sidebar-w-collapsed); }
  body.tg-collapsed .tg-sb-account { padding: .5rem 0; justify-content: center; }
  body.tg-collapsed .tg-sb-account > :not(.tg-sb-logo) { display: none; }
  body.tg-collapsed .tg-sb-brand { justify-content: center; padding-left: 0; padding-right: 0; }
  body.tg-collapsed .tg-sb-brand-text { display: none; }
  body.tg-collapsed .tg-nav { overflow: visible; }
  body.tg-collapsed .tg-nav-text,
  body.tg-collapsed .tg-sidebar-foot { display: none; }
  body.tg-collapsed .tg-nav-label { font-size: 0; height: 1px; padding: 0; margin: .5rem; background: var(--border); }
  body.tg-collapsed .tg-nav-badge { position: absolute; top: .25rem; right: .125rem; margin: 0; min-width: 1rem; height: 1rem; font-size: .5625rem; padding: 0 .25rem; }
  body.tg-collapsed .tg-nav-ic { width: 100%; }
  body.tg-collapsed .tg-sb-toggle .tg-nav-ic { width: 3rem; }
  body.tg-collapsed .tg-sb-toggle .tg-nav-ic i { transform: none; }
  body.tg-collapsed .tg-nav-item::after {
    content: attr(data-tip); position: absolute; left: calc(100% + .75rem); top: 50%;
    transform: translate(-.25rem, -50%); opacity: 0; pointer-events: none; white-space: nowrap;
    padding: .375rem .625rem; border-radius: .375rem; font-size: .75rem; font-weight: 600;
    background: var(--text); color: var(--surface); box-shadow: var(--shadow-lg);
    transition: opacity .14s, transform .14s; z-index: 80;
  }
  body.tg-collapsed .tg-nav-item:hover::after { opacity: 1; transform: translate(0, -50%); }
}

/* ---- การ์ดสถิติ / การ์ดเนื้อหาแบบในตัวอย่าง ---- */
.tg-kpi {
  display: block; padding: 1.5rem; border-radius: .75rem;
  border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow-sm);
  transition: box-shadow .2s, transform .2s cubic-bezier(.16, 1, .3, 1);
}
.tg-kpi:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.tg-kpi-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.tg-kpi-ic { width: 2.25rem; height: 2.25rem; border-radius: .5rem; display: grid; place-content: center; font-size: 1rem; }
.tg-kpi-label { font-size: .875rem; font-weight: 500; color: var(--text-muted); margin-bottom: .25rem; }
.tg-kpi-value { font-size: 1.5rem; font-weight: 700; color: var(--text); line-height: 1.2; font-variant-numeric: tabular-nums; }
.tg-kpi-delta { font-size: .8125rem; margin-top: .25rem; color: var(--text-muted); }
.tg-kpi-delta.is-up { color: var(--success); }
.tg-kpi-delta.is-down { color: var(--danger); }

.tg-panel { border-radius: .75rem; border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow-sm); padding: 1.5rem; }
.tg-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.tg-panel-title { font-size: 1.0625rem; font-weight: 600; color: var(--text); }
.tg-panel-link { font-size: .8125rem; font-weight: 500; color: var(--primary); }
.tg-panel-link:hover { text-decoration: underline; }

.tg-activity { display: flex; align-items: center; gap: 1rem; padding: .75rem; border-radius: .5rem; transition: background-color .15s; }
.tg-activity:hover { background: var(--surface-hover); }
.tg-activity-ic { width: 2rem; height: 2rem; flex-shrink: 0; border-radius: .5rem; display: grid; place-content: center; font-size: .8125rem; }
.tg-activity-title { font-size: .875rem; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tg-activity-desc { font-size: .75rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tg-activity-time { font-size: .75rem; color: var(--text-faint); white-space: nowrap; flex-shrink: 0; }

.tg-meter { width: 100%; height: .5rem; border-radius: 999px; background: var(--surface-active); overflow: hidden; }
.tg-meter > span { display: block; height: 100%; border-radius: 999px; width: 0; transition: width .9s cubic-bezier(.16, 1, .3, 1); }

/* โทนสีของไอคอน/แถบ */
.tone-blue   { background: rgba(59, 130, 246, .10); color: #2563eb; }
.tone-green  { background: rgba(34, 197, 94, .10);  color: #16a34a; }
.tone-purple { background: rgba(168, 85, 247, .10); color: #9333ea; }
.tone-orange { background: rgba(249, 115, 22, .10); color: #ea580c; }
.tone-red    { background: rgba(239, 68, 68, .10);  color: #dc2626; }
.tone-slate  { background: var(--surface-hover);    color: var(--text-muted); }
.dark .tone-blue   { background: rgba(59, 130, 246, .18); color: #60a5fa; }
.dark .tone-green  { background: rgba(34, 197, 94, .16);  color: #4ade80; }
.dark .tone-purple { background: rgba(168, 85, 247, .18); color: #c084fc; }
.dark .tone-orange { background: rgba(249, 115, 22, .16); color: #fb923c; }
.dark .tone-red    { background: rgba(239, 68, 68, .16);  color: #f87171; }
.bar-blue { background: #3b82f6; } .bar-green { background: #22c55e; } .bar-orange { background: #f97316; } .bar-purple { background: #a855f7; }


/* =====================================================================
 *  dialog ขนาดใหญ่ขึ้นสำหรับงานแก้ไขข้อมูล
 *  md (ค่าเริ่มต้นของ form) 44rem · lg 56rem · xl 72rem · drawer 40/56rem
 * ===================================================================== */
.tg-modal-box.is-form { max-width: 44rem; }
.tg-modal-box.is-form.size-sm { max-width: 28rem; }
.tg-modal-box.is-form.size-lg { max-width: 56rem; }
.tg-modal-box.is-form.size-xl { max-width: 72rem; }
.tg-modal-box.is-form .tg-modal-body { padding: 1.5rem 1.75rem; }
.tg-modal-box.is-form .tg-modal-head, .tg-modal-box.is-form .tg-modal-foot { padding-left: 1.75rem; padding-right: 1.75rem; }
.tg-form-grid { gap: 1.125rem 1.25rem; }
.tg-form-section { grid-column: 1 / -1; display: flex; align-items: center; gap: .625rem; margin-top: .5rem; font-size: .75rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: var(--text-muted); }
.tg-form-section::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.tg-form-section:first-child { margin-top: 0; }
.tg-drawer-panel { max-width: 40rem; }
.tg-drawer-panel.size-lg { max-width: 56rem; }
.tg-drawer-panel .tg-modal-body { padding: 1.5rem 1.75rem; }
.tg-drawer-actions { display: flex; flex-wrap: wrap; gap: .5rem; padding: .875rem; margin-bottom: 1.25rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.tg-drawer-actions .btn-danger { margin-left: auto; }
@media (min-width: 1024px) {
  .tg-form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* =====================================================================
 *  การ์ด / สถิติในหลังบ้าน — hover ยกตัวเบา ๆ แบบ 21st
 * ===================================================================== */
.tg-app .card, .tg-app .stat { transition: transform .2s cubic-bezier(.16, 1, .3, 1), box-shadow .2s ease, border-color .2s ease; }
.tg-app .stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--border-strong); }
.tg-app main > * { animation: tgRise .45s cubic-bezier(.16, 1, .3, 1) both; }
.tg-app main > *:nth-child(2) { animation-delay: .05s; }
.tg-app main > *:nth-child(3) { animation-delay: .1s; }
.tg-app main > *:nth-child(4) { animation-delay: .15s; }
.tg-app main > *:nth-child(n+5) { animation-delay: .2s; }
@keyframes tgRise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .tg-app main > *, .tg-sidebar, body.tg-app { animation: none !important; transition: none !important; }
}

/* =====================================================================
   ช่องไอคอนในฟอร์ม + ตัวเลือกไอคอน (TG.iconPicker)
   ===================================================================== */
.tg-icon-field { display: flex; align-items: stretch; gap: .5rem; }
.tg-icon-field .field { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8125rem; }
.tg-icon-prev, .tg-ip-prev {
  width: 2.75rem; flex-shrink: 0; border-radius: .625rem; display: grid; place-content: center; font-size: 1.125rem;
  background: var(--primary-soft); color: var(--primary); border: 1px solid var(--border);
}
.tg-ip-bar { display: flex; flex-wrap: wrap; gap: .625rem; align-items: center; margin-bottom: .875rem; }
.tg-ip-search { position: relative; flex: 1 1 16rem; }
.tg-ip-search i { position: absolute; left: .875rem; top: 50%; transform: translateY(-50%); color: var(--text-faint); font-size: .8125rem; pointer-events: none; }
.tg-ip-search .field { padding-left: 2.25rem; }
.tg-ip-seg { display: inline-flex; padding: .1875rem; border-radius: .625rem; background: var(--surface-2); border: 1px solid var(--border); }
.tg-ip-seg button { padding: .375rem .75rem; border-radius: .4375rem; font-size: .75rem; font-weight: 700; color: var(--text-muted); }
.tg-ip-seg button.is-active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }
.tg-ip-cat { width: auto; flex: 0 1 12rem; }
.tg-ip-label, .tg-ip-count { font-size: .6875rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin: 0 0 .5rem; }
.tg-ip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(5.75rem, 1fr)); gap: .5rem; }
.tg-ip-grid.is-recent { margin-bottom: 1rem; }
.tg-ip-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5rem; min-height: 5.25rem; padding: .625rem .375rem;
  border-radius: .625rem; border: 1px solid var(--border); background: var(--surface); color: var(--text); transition: border-color .12s, background-color .12s, transform .12s;
}
.tg-ip-tile i { font-size: 1.375rem; }
.tg-ip-tile span { font-size: .625rem; color: var(--text-muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-ip-tile:hover, .tg-ip-tile:focus-visible { border-color: var(--primary); background: var(--primary-soft); transform: translateY(-1px); }
.tg-ip-tile.is-active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.tg-ip-more { grid-column: 1 / -1; justify-self: center; margin-top: .25rem; }
.tg-ip-custom { display: flex; align-items: stretch; gap: .5rem; flex: 1; min-width: 0; margin-right: auto; }
.tg-ip-custom .field { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8125rem; }
.tg-modal-box.size-xl .tg-modal-foot { flex-wrap: wrap; }
@media (max-width: 639px) {
  .tg-ip-custom { flex-basis: 100%; }
  .tg-ip-grid { grid-template-columns: repeat(auto-fill, minmax(4.75rem, 1fr)); }
}

/* =====================================================================
   จัดลำดับแบบลากวาง (TG.sortable / TG.dialog.reorder)
   ===================================================================== */
.tg-sort { display: flex; flex-direction: column; gap: .5rem; margin: 0; padding: 0; list-style: none; }
.tg-sort-item {
  display: flex; align-items: center; gap: .75rem; padding: .625rem .75rem .625rem .375rem; border-radius: .75rem;
  background: var(--surface); border: 1px solid var(--border); transition: box-shadow .15s, border-color .15s, background-color .3s;
}
.tg-sort-handle {
  width: 2rem; height: 2.25rem; flex-shrink: 0; display: grid; place-content: center; border-radius: .5rem; color: var(--text-faint);
  cursor: grab; touch-action: none;
}
.tg-sort-handle:hover, .tg-sort-handle:focus-visible { background: var(--surface-hover); color: var(--text); }
.tg-sort-no { min-width: 1.5rem; font-size: .75rem; font-weight: 800; color: var(--text-muted); text-align: right; font-variant-numeric: tabular-nums; }
.tg-sort-body { flex: 1; min-width: 0; font-size: .875rem; }
.tg-sort-arrows { display: inline-flex; gap: .125rem; }
.tg-sort-arrows button { width: 1.875rem; height: 1.875rem; border-radius: .5rem; color: var(--text-muted); font-size: .6875rem; }
.tg-sort-arrows button:hover { background: var(--surface-hover); color: var(--text); }
.tg-sort-item:first-child [data-sort-move="-1"], .tg-sort-item:last-child [data-sort-move="1"] { visibility: hidden; }
.tg-sort.is-sorting { user-select: none; cursor: grabbing; }
.tg-sort.is-sorting .tg-sort-handle { cursor: grabbing; }
.tg-sort-item.is-dragging { border-color: var(--primary); box-shadow: 0 10px 24px -8px rgba(15, 23, 42, .35); background: var(--primary-soft); position: relative; z-index: 1; }
.tg-sort-item.is-moved { background: var(--primary-soft); }
.tg-sort-status { margin-right: auto; align-self: center; font-size: .75rem; color: var(--warning, #d97706); font-weight: 600; }
