/* =========================================================
   SABA88 Design System — single source for all admin pages
   Spacing: 4 / 8 / 12 / 16 / 24 / 32
   ========================================================= */
:root {
  --bg: #101722;
  --surface: #161e2c;
  --surface-2: #1c2536;
  --line: rgba(148, 163, 184, 0.14);
  --line-strong: rgba(148, 163, 184, 0.22);
  --text: #e8eef7;
  --text-2: #a7b3c7;
  --muted: #7d8aa0;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-soft: rgba(59, 130, 246, 0.14);
  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, 0.14);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.14);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.14);
  --side: 244px;
  --top: 56px;
  --radius: 10px;
  --radius-sm: 8px;
  --control-h: 42px;
  --row-h: 50px;
  --shadow: 0 1px 0 rgba(255,255,255,.02);
  --font: "Noto Sans Thai", "Sora", sans-serif;
  --display: "Sora", "Noto Sans Thai", sans-serif;
  --focus: 0 0 0 3px rgba(59, 130, 246, 0.35);
}

.login-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 400px at 20% 0%, rgba(59,130,246,.18), transparent 60%),
    radial-gradient(700px 360px at 90% 100%, rgba(245,158,11,.12), transparent 55%),
    var(--bg);
}
.ops-console .login-gate {
  background:
    radial-gradient(820px 420px at 12% -10%, rgba(232, 184, 74, 0.16), transparent 58%),
    radial-gradient(700px 380px at 100% 110%, rgba(180, 120, 30, 0.12), transparent 55%),
    linear-gradient(165deg, #0a0a0a 0%, #12100c 45%, #0d1118 100%);
}
.login-gate[hidden],
.app[hidden] {
  display: none !important;
}
body.is-authed .login-gate { display: none !important; }
body:not(.is-authed) .app { display: none !important; }
/* F5: มี token แล้ว — ซ่อน login ทันทีก่อน JS โหลดเสร็จ */
html.ops-has-session .login-gate { display: none !important; }
html.ops-has-session body:not(.is-authed) .app {
  display: grid !important;
  opacity: 0.01;
  pointer-events: none;
}
html.ops-has-session body.is-authed .app {
  opacity: 1;
  pointer-events: auto;
}
.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px 24px;
  display: grid;
  gap: 12px;
  box-shadow: var(--shadow);
}
.login-card-pro {
  width: min(420px, 100%);
  gap: 14px;
  padding: 32px 28px 26px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(28, 24, 16, 0.96), rgba(16, 14, 12, 0.98));
  border: 1px solid rgba(232, 184, 74, 0.28);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
.login-brand-pro {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(232, 184, 74, 0.16);
  margin-bottom: 2px;
}
.login-brand-pro strong {
  display: block;
  font-family: var(--display);
  font-size: 18px;
  letter-spacing: 0.04em;
  color: #f3d27a;
}
.login-brand-pro span {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  letter-spacing: 0.16em;
  color: rgba(243, 210, 122, 0.65);
}
.login-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-weight: 700;
  font-size: 20px;
  color: #1a1205;
  background: linear-gradient(145deg, #f6e2a0, #d4a43a);
  box-shadow: 0 8px 20px rgba(212, 164, 58, 0.28);
}
.login-head h1 {
  margin: 8px 0 0;
  font-size: 24px;
  font-family: var(--display);
  letter-spacing: -0.02em;
}
.login-head p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}
.login-submit {
  width: 100%;
  margin-top: 4px;
  min-height: 46px;
  border: 0;
  background: linear-gradient(135deg, #e8c15a, #c9962a) !important;
  color: #1a1205 !important;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.login-submit:hover { filter: brightness(1.05); }
.login-card h1 { margin: 0; font-size: 22px; font-family: var(--display); }
.login-card > p { margin: 0; color: var(--muted); font-size: 13px; }
.login-hint { margin: 4px 0 0; color: var(--muted); font-size: 12px; text-align: center; }
.login-card .field { display: grid; gap: 6px; }
.login-card .field span { font-size: 12px; color: var(--text-2); }
.login-step { display: grid; gap: 12px; }
.login-step[hidden] { display: none !important; }
.login-step-user {
  margin: 0;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(232, 184, 74, 0.22);
  background: rgba(232, 184, 74, 0.08);
  color: #f0d78c;
  font-size: 0.86rem;
  font-weight: 600;
  text-align: center;
}
.login-captcha-row {
  display: flex;
  justify-content: flex-start;
}
.login-captcha {
  min-width: 118px;
  min-height: 40px;
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: #f4f4f4;
  color: #111;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  cursor: pointer;
  user-select: none;
}
.login-captcha:hover { filter: brightness(0.97); }
.login-back {
  width: 100%;
  min-height: 40px;
}
.login-card-pro .control {
  background: rgba(8, 8, 8, 0.55);
  border-color: rgba(232, 184, 74, 0.2);
}
.login-card-pro .control:focus {
  border-color: rgba(232, 184, 74, 0.55);
  box-shadow: 0 0 0 3px rgba(232, 184, 74, 0.18);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  font-size: 13.5px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; max-width: 100%; }
svg { display: block; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: none; box-shadow: var(--focus); }
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #2b3548; border-radius: 99px; }

/* —— AppLayout —— */
.app { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.main { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
.content { padding: 16px 20px 28px; flex: 1; }
.view { display: none; }
.view.active { display: block; }

/* —— Sidebar —— */
.sidebar {
  position: sticky; top: 0; height: 100vh;
  background: #0e1420;
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 12px 8px;
  z-index: 40;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 8px;
}
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px; flex: 0 0 auto;
  display: grid; place-items: center;
  font-family: var(--display); font-size: 13px; font-weight: 700; letter-spacing: .04em;
  color: #e8eef8;
  background: linear-gradient(160deg, #3b82f6, #1d4ed8);
  border: 1px solid rgba(147, 197, 253, 0.35);
}
.brand strong {
  display: block; font-family: var(--display); font-size: 15px; letter-spacing: .03em;
}
.brand span {
  color: var(--muted); font-size: 10px; letter-spacing: .08em; text-transform: uppercase;
}
.login-brand {
  display: grid; gap: 4px; justify-items: center; margin-bottom: 4px;
}
.login-brand strong {
  font-family: var(--display); font-size: 28px; letter-spacing: .06em;
  color: #f3f7ff;
}
.login-brand span {
  font-size: 11px; letter-spacing: .16em; color: var(--muted); font-weight: 700;
}
.nav { overflow: auto; flex: 1; padding-bottom: 8px; }
.nav-group { margin: 4px 0; }
.nav-group + .nav-group { margin-top: 2px; }
.nav-sec {
  list-style: none;
  margin: 6px 6px 2px;
  padding: 8px 10px;
  color: #8b9bb3;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-radius: 8px;
  transition: background .15s ease, color .15s ease;
}
.nav-sec::-webkit-details-marker { display: none; }
.nav-sec::marker { content: ""; }
.nav-sec::after {
  content: "";
  width: 7px; height: 7px;
  border-right: 1.75px solid currentColor;
  border-bottom: 1.75px solid currentColor;
  transform: rotate(45deg);
  transition: transform .18s ease;
  opacity: .75;
  flex: 0 0 auto;
  margin-top: -3px;
}
.nav-group:not([open]) > .nav-sec::after {
  transform: rotate(-45deg);
  margin-top: 1px;
}
.nav-sec:hover { background: rgba(255,255,255,.04); color: #c7d2e3; }
.nav-group-body { display: grid; gap: 1px; padding: 0 4px 4px; }
.nav-item {
  width: 100%; border: 0; background: transparent; color: #a9b4c6;
  text-align: left; border-radius: var(--radius-sm);
  padding: 8px 10px; display: flex; align-items: center; gap: 10px;
  font-size: 13px; transition: background .15s ease, color .15s ease;
}
.nav-item .ico {
  width: 20px; height: 20px; display: grid; place-items: center; color: #7c8aa1; flex: 0 0 auto;
}
.nav-item .ico svg {
  width: 15px; height: 15px; stroke: currentColor; fill: none;
  stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
}
.nav-item:hover { background: rgba(255,255,255,.035); color: #fff; }
.nav-item.active {
  background: var(--primary-soft); color: #fff;
  box-shadow: inset 2px 0 0 var(--primary);
}
.nav-item.active .ico { color: #93c5fd; }
.nav-item .badge-mini {
  margin-left: auto; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--warning-soft); color: var(--warning);
  font-size: 10px; font-weight: 700; display: grid; place-items: center;
}
.side-foot { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 8px; }
.side-profile {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px 10px;
}
.side-profile img { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; }
.side-profile b { display: block; font-size: 12.5px; }
.side-profile small { color: var(--muted); font-size: 11px; }
.side-foot .btn { width: 100%; }

/* —— Topbar —— */
.topbar {
  height: var(--top);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 16px;
  background: rgba(16, 23, 34, 0.92);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
  backdrop-filter: blur(12px);
}
.top-left, .top-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.top-title h2 {
  margin: 0; font-size: 15px; font-family: var(--display); font-weight: 650; letter-spacing: -.01em;
}
.top-search {
  width: min(280px, 32vw);
  height: 36px;
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--radius-sm); padding: 0 12px; color: var(--muted);
}
.top-search input {
  border: 0; outline: 0; background: transparent; width: 100%; color: var(--text);
}
.top-search svg {
  width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 1.8; flex: 0 0 auto;
}
.menu-btn {
  display: none; width: 36px; height: 36px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); place-items: center;
}
.menu-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.icon-btn {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center; position: relative; padding: 0; color: var(--text);
}
.icon-btn svg {
  width: 15px; height: 15px; stroke: currentColor; fill: none;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn .dot {
  position: absolute; top: -4px; right: -4px; min-width: 16px; height: 16px;
  border-radius: 999px; background: var(--danger); color: #fff;
  font-size: 10px; display: grid; place-items: center; padding: 0 4px; font-weight: 700;
}
.user-chip {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 3px 10px 3px 3px;
}
.user-chip img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.user-chip b { display: block; font-size: 12.5px; font-family: var(--display); }
.user-chip small { display: block; color: var(--muted); font-size: 10.5px; }

/* —— Buttons —— */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid transparent; font-weight: 650; font-size: 13px;
  transition: background .15s ease, border-color .15s ease;
}
.btn svg {
  width: 14px; height: 14px; stroke: currentColor; fill: none;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); border-color: var(--line-strong); color: var(--text); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger-soft); border-color: rgba(239,68,68,.3); color: #fca5a5; }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: rgba(255,255,255,.04); color: var(--text); }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* —— PageHeader —— */
.page-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; margin-bottom: 16px; flex-wrap: wrap;
}
.breadcrumb {
  color: var(--muted); font-size: 11px; letter-spacing: .04em;
  text-transform: uppercase; margin-bottom: 6px;
}
.breadcrumb span { opacity: .55; margin: 0 6px; }
.page-header h1 {
  margin: 0; font-size: 22px; font-family: var(--display);
  font-weight: 700; letter-spacing: -.02em;
}
.page-header p {
  margin: 6px 0 0; color: var(--text-2); font-size: 13px; max-width: 62ch;
}
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* —— Cards / Panels —— */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 16px; }
.card-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; margin-bottom: 12px;
}
.card-head h3 {
  margin: 0; font-size: 14px; font-family: var(--display); font-weight: 650;
}
.card-head .sub { margin: 4px 0 0; color: var(--muted); font-size: 12px; }

/* —— StatCard / KPI —— */
.stat-row {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px; margin-bottom: 16px;
}
.stat-row.five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.stat-row.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 14px 12px;
  min-height: 88px; cursor: pointer; transition: border-color .15s ease;
}
.stat-card:hover { border-color: rgba(59,130,246,.4); }
.stat-card.static { cursor: default; }
.stat-card.static:hover { border-color: var(--line); }
.stat-card .label { color: var(--muted); font-size: 12px; }
.stat-card .value {
  margin-top: 8px; font-size: 20px; font-family: var(--display);
  font-weight: 700; letter-spacing: -.02em;
}
.stat-card .meta { margin-top: 4px; font-size: 11px; font-weight: 650; }
.stat-card .meta.up { color: var(--success); }
.stat-card .meta.down { color: var(--danger); }
.stat-card .meta.warn { color: var(--warning); }
.stat-card.warn { border-color: rgba(245,158,11,.35); }
.stat-card.danger { border-color: rgba(239,68,68,.35); }

/* —— FilterBar —— */
.filter-bar {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between;
  align-items: center; margin-bottom: 12px;
  padding: 12px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius);
}
.filter-group { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.control {
  height: var(--control-h); border: 1px solid var(--line); background: #121a28;
  border-radius: var(--radius-sm); padding: 0 12px; outline: none; min-width: 140px;
  color: var(--text);
}
.control:focus { border-color: rgba(59,130,246,.5); box-shadow: var(--focus); }
.control.search { min-width: min(240px, 100%); }
textarea.control {
  height: auto; min-height: 88px; padding: 10px 12px; resize: vertical;
}

/* —— DataTable —— */
.table-card { overflow: hidden; }
.table-wrap { overflow: auto; max-height: min(66vh, 680px); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
  text-align: left; padding: 0 14px; height: var(--row-h);
  border-bottom: 1px solid var(--line); white-space: nowrap; font-size: 12.5px;
  vertical-align: middle;
}
.data-table th {
  position: sticky; top: 0; z-index: 1;
  background: #1a2333; color: var(--muted);
  font-size: 11px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
  height: 42px;
}
.data-table tbody tr { cursor: pointer; transition: background .12s ease; }
.data-table tbody tr:hover { background: rgba(59,130,246,.05); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table .actions { display: flex; gap: 4px; justify-content: flex-end; }
.table-foot {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; padding: 10px 14px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 12px;
}
.amt-pos { color: var(--success); font-weight: 700; font-family: var(--display); }
.amt-neg { color: var(--danger); font-weight: 700; font-family: var(--display); }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.member-cell { display: flex; align-items: center; gap: 8px; }
.avatar-sm {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--primary-soft); color: #93c5fd; font-size: 10px; font-weight: 800;
}

/* —— StatusBadge —— */
.badge {
  display: inline-flex; align-items: center; border-radius: 999px;
  padding: 3px 8px; font-size: 11px; font-weight: 700;
}
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--primary-soft); color: #93c5fd; }

.slip-thumb {
  display: inline-block;
  width: 52px;
  height: 52px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.12);
  vertical-align: middle;
}
.slip-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.badge.neutral { background: rgba(125,138,160,.14); color: var(--muted); }

/* —— Empty / Loading / Error —— */
.state-box {
  display: grid; place-items: center; text-align: center; gap: 6px;
  padding: 48px 20px; color: var(--muted);
}
.state-box b { color: var(--text); font-size: 14px; font-family: var(--display); }
.state-box span { font-size: 12.5px; max-width: 36ch; line-height: 1.45; }
.state-box .ico {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--line); color: #93c5fd; margin-bottom: 4px;
}
.state-box .ico svg {
  width: 20px; height: 20px; stroke: currentColor; fill: none;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}
.loading-bar {
  height: 3px; width: 120px; border-radius: 99px; overflow: hidden;
  background: rgba(255,255,255,.06); margin-bottom: 8px;
}
.loading-bar i {
  display: block; height: 100%; width: 40%; background: var(--primary);
  animation: load 1s ease-in-out infinite;
}
@keyframes load {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(300%); }
}

/* —— Dashboard grids —— */
.dash-2 { display: grid; grid-template-columns: 1.35fr 1fr; gap: 12px; margin-bottom: 12px; }
.dash-3 { display: grid; grid-template-columns: 1.15fr 1.15fr .9fr; gap: 12px; }
.chart-box {
  height: 200px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #121a28; padding: 6px;
}
.chart-box canvas { width: 100% !important; height: 100% !important; }
.dense-list { display: grid; gap: 8px; }
.dense-item {
  display: grid; grid-template-columns: 8px 1fr auto; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #121a28;
}
.dense-item i { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; background: var(--warning); }
.dense-item.success i { background: var(--success); }
.dense-item.danger i { background: var(--danger); }
.dense-item b { display: block; font-size: 12.5px; font-weight: 600; }
.dense-item small { color: var(--muted); font-size: 11px; }
.dense-item .right { color: var(--muted); font-size: 11px; text-align: right; }
.pending-item {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.pending-item:last-child { border-bottom: 0; }

/* —— Form fields —— */
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field > span { color: var(--muted); font-size: 12px; font-weight: 600; }
.field .hint { color: var(--muted); font-size: 11.5px; line-height: 1.4; }
.member-preview {
  display: none; padding: 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: #121a28; margin-bottom: 12px;
}
.member-preview.show { display: block; }
.member-preview b { display: block; font-size: 14px; }
.member-preview small { color: var(--muted); }

/* —— FormDrawer (compact floating panel) —— */
.overlay {
  display: none; position: fixed; inset: 0; background: rgba(2, 6, 16, .62);
  backdrop-filter: blur(2px); z-index: 60;
}
.overlay.show { display: block; }
.drawer {
  position: fixed; top: 50%; right: max(16px, calc((100vw - 1200px) / 2));
  width: min(400px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  background: linear-gradient(180deg, #172033 0%, #121a28 100%);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  z-index: 70;
  transform: translate(120%, -50%);
  transition: transform .22s ease, opacity .22s ease;
  display: flex; flex-direction: column;
  box-shadow: 0 28px 70px rgba(0,0,0,.55);
  opacity: 0; pointer-events: none;
}
.drawer.open {
  transform: translate(0, -50%);
  opacity: 1; pointer-events: auto;
}
.drawer-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.drawer-head h3 {
  margin: 0; font-size: 16px; font-family: var(--display); font-weight: 700; line-height: 1.3;
}
.drawer-head .drawer-sub {
  margin: 4px 0 0; color: var(--muted); font-size: 12px; font-weight: 500;
}
.drawer-body {
  padding: 14px 16px 4px;
  overflow: auto;
  flex: 0 1 auto;
  max-height: min(58vh, 480px);
}
.drawer-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 16px 16px;
  background: transparent;
}
.drawer-foot .btn { min-width: 92px; }
.drawer .field { margin-bottom: 12px; }
.drawer .field > span { font-size: 12px; color: var(--text-2); font-weight: 600; }
.drawer .control {
  width: 100%; min-width: 0; background: #0b1220;
  border-radius: 10px; padding: 11px 12px; border-color: rgba(148,163,184,.18);
}
.drawer .control:disabled,
.drawer .control[readonly] {
  opacity: .8; color: var(--muted); cursor: default;
}
.drawer-note {
  margin: 0 0 12px; padding: 10px 12px; border-radius: 10px;
  background: rgba(59,130,246,.08); border: 1px solid rgba(59,130,246,.18);
  color: var(--text-2); font-size: 12.5px; line-height: 1.45;
}
.drawer-metrics {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px;
}
.drawer-metrics .m {
  padding: 10px 12px; border-radius: 10px; background: #0b1220; border: 1px solid var(--line);
}
.drawer-metrics .m span { display: block; color: var(--muted); font-size: 11px; margin-bottom: 2px; }
.drawer-metrics .m b { font-size: 14px; font-weight: 700; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 720px) {
  .drawer {
    right: 50%; top: 50%;
    transform: translate(50%, 30%) scale(.98);
  }
  .drawer.open { transform: translate(50%, -50%) scale(1); }
  .field-row { grid-template-columns: 1fr; }
}

/* —— ConfirmModal —— */
.modal {
  display: none; position: fixed; inset: 0; z-index: 80;
  place-items: center; padding: 16px;
}
.modal.show { display: grid; }
.modal-card {
  width: min(440px, 100%); background: #161e2c; border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 20px 50px rgba(0,0,0,.4); overflow: hidden;
}
.modal-card .mh { padding: 16px 16px 0; }
.modal-card .mh h3 { margin: 0; font-size: 16px; font-family: var(--display); }
.modal-card .mb { padding: 12px 16px 16px; color: var(--text-2); font-size: 13px; }
.modal-card .mf {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 16px; border-top: 1px solid var(--line);
}
.summary-list { display: grid; gap: 8px; margin-top: 8px; }
.summary-list .row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px;
}
.summary-list .row span { color: var(--muted); }
.summary-list .row b { font-weight: 650; text-align: right; }

/* —— Misc —— */
.toast {
  position: fixed; left: 50%; bottom: 16px; translate: -50% 140%; z-index: 100;
  background: var(--surface-2); border: 1px solid rgba(59,130,246,.35);
  color: var(--text); padding: 10px 16px; border-radius: 999px;
  transition: translate .22s ease; max-width: min(92vw, 420px);
  text-align: center; font-weight: 650; font-size: 13px;
}
.toast.show { translate: -50% 0; }
.statusbar {
  border-top: 1px solid var(--line); background: #0e1420;
  padding: 8px 16px; display: flex; flex-wrap: wrap; gap: 16px;
  color: var(--muted); font-size: 11.5px;
}
.statusbar .ok::before {
  content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--success); margin-right: 5px;
}
.provider-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 12px;
}
.provider-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.provider-card .thumb { height: 90px; background: #121a28; position: relative; }
.provider-card .thumb img { width: 100%; height: 100%; object-fit: contain; padding: 8px; }
.provider-card .thumb .tag {
  position: absolute; left: 8px; top: 8px; background: rgba(0,0,0,.7);
  border: 1px solid var(--line); border-radius: 999px; padding: 2px 7px; font-size: 10px;
}
.provider-card .body { padding: 10px 12px 12px; display: grid; gap: 8px; }
.provider-card h4 { margin: 0; font-size: 13px; font-family: var(--display); }
.provider-card .meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }
.provider-card .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

/* ตั้งค่าเกมส์ — แนว demowebs /setting/game */
.game-setting {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 14px;
  align-items: start;
}
.game-cats {
  display: grid;
  gap: 8px;
  position: sticky;
  top: calc(var(--top) + 12px);
}
.game-cat {
  appearance: none; border: 1px solid var(--line); background: var(--surface-2);
  color: var(--primary); border-radius: 999px; padding: 10px 12px;
  font: inherit; font-weight: 700; font-size: 12px; letter-spacing: .04em;
  cursor: pointer; text-align: center;
}
.game-cat.active {
  background: #1e3a8a; border-color: #1e3a8a; color: #fff;
}
.game-setting-main {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.game-setting-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 14px; flex-wrap: wrap;
}
.game-setting-toolbar h2 {
  margin: 0; font-size: 18px; font-family: var(--display); letter-spacing: .04em;
}
.game-setting-toolbar .search { width: min(240px, 100%); }
.game-provider-grid {
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}
.game-tile {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
}
.game-tile.is-off .game-tile-media::after {
  content: "ปิดอยู่";
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(8, 12, 20, .72);
  color: #fff; font-weight: 700; font-size: 18px;
  letter-spacing: .02em;
}
.game-tile-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 10px 12px 0;
}
.game-tile-head b {
  font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.game-tile-head .ico-btn {
  width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--line);
  background: transparent; color: var(--text-2); cursor: pointer;
  display: grid; place-items: center; flex: 0 0 auto;
}
.game-tile-media {
  position: relative; height: 160px; margin: 10px 12px 12px;
  border-radius: 10px; overflow: hidden; background: #0d1420;
}
.game-tile-media img {
  width: 100%; height: 100%; object-fit: cover; padding: 0;
}
.game-tile .tile-actions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  padding: 0 12px 12px;
}
.game-tile.sort-mode { cursor: grab; outline: 1px dashed rgba(59,130,246,.45); }
.game-tile.sort-mode .tile-actions { display: none; }
@media (max-width: 900px) {
  .game-setting { grid-template-columns: 1fr; }
  .game-cats { grid-template-columns: repeat(4, 1fr); position: static; }
}

/* Member detail */
.member-detail {
  display: grid;
  grid-template-columns: minmax(260px, 300px) 1fr;
  gap: 16px;
  align-items: start;
}
.md-hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px 24px;
  padding: 18px 20px;
  margin-bottom: 16px;
  align-items: center;
  background:
    linear-gradient(120deg, rgba(59,130,246,.12), transparent 42%),
    var(--surface);
}
.md-hero-main { display: flex; align-items: center; gap: 14px; min-width: 0; }
.md-hero-text { min-width: 0; }
.md-hero-text h2 {
  margin: 4px 0 0; font-size: 20px; font-family: var(--display); font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.md-hero-text .mono { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.md-hero .md-badges { justify-content: flex-start; margin: 0; }
.md-hero-balance {
  text-align: right; padding: 10px 14px; border-radius: 12px;
  background: rgba(15, 23, 42, .45); border: 1px solid var(--line);
  min-width: 140px; cursor: pointer; transition: border-color .15s ease, background .15s ease;
}
.md-hero-balance:hover { border-color: rgba(59,130,246,.45); background: rgba(59,130,246,.08); }
.md-hero-balance .label { display: block; color: var(--muted); font-size: 11px; margin-bottom: 2px; }
.md-hero-balance strong {
  display: block; font-size: 22px; font-family: var(--display); letter-spacing: -.02em;
  color: #86efac;
}
.md-hero-balance small { color: var(--muted); font-size: 11px; }
.md-quick {
  grid-column: 1 / -1;
  padding-top: 10px; border-top: 1px solid var(--line);
}
.md-quick-label {
  margin: 0 0 8px; font-size: 11px; font-weight: 650; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
}
.md-actions-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}
.md-act {
  appearance: none; border: 1px solid var(--line); background: #0d1420; color: var(--text);
  border-radius: 12px; padding: 10px 10px 9px; cursor: pointer; text-align: left;
  transition: border-color .15s ease, background .15s ease, transform .12s ease;
  min-height: 58px;
}
.md-act:hover { border-color: rgba(59,130,246,.45); background: rgba(59,130,246,.08); }
.md-act:active { transform: translateY(1px); }
.md-act.primary {
  background: rgba(59,130,246,.16); border-color: rgba(59,130,246,.4);
}
.md-act.primary:hover { background: rgba(59,130,246,.24); }
.md-act.ghost { background: transparent; }
.md-act b { display: block; font-size: 13px; font-weight: 700; line-height: 1.2; }
.md-act small { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.md-actions { gap: 8px; }
.stat-card.is-click {
  cursor: pointer;
}
.stat-card.is-click:hover { border-color: rgba(59,130,246,.45); }
.md-profile { text-align: left; position: sticky; top: 12px; }
.md-sec-title {
  margin: 0 0 10px; font-size: 11px; font-weight: 650; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
}
.md-panel { margin-bottom: 14px; }
.md-panel .stat-row { margin-bottom: 0; }
.md-avatar {
  width: 64px; height: 64px; flex-shrink: 0; border-radius: 16px;
  display: grid; place-items: center; font-size: 22px; font-weight: 700;
  background: linear-gradient(145deg, #38bdf8, #2563eb); color: #fff;
  box-shadow: 0 8px 20px rgba(37, 99, 235, .28);
}
.md-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.md-cal { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 14px; }
.md-cal span {
  width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  font-size: 11px; border: 1px solid var(--line); color: var(--muted); background: #0d1420;
}
.md-cal span.on {
  background: rgba(59,130,246,.2); border-color: rgba(59,130,246,.55); color: #dbeafe; font-weight: 650;
}
.md-banks { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 14px; }
.md-banks h4 { margin: 0 0 8px; font-size: 11px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.md-main { display: flex; flex-direction: column; gap: 0; min-width: 0; }
.stat-row.three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat-row.five { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.md-main .stat-card .value { font-size: 18px; }
.md-main .stat-card .label { font-size: 11.5px; }
.seg {
  display: inline-flex; padding: 3px; border-radius: 10px;
  background: #0d1420; border: 1px solid var(--line); gap: 2px;
}
.seg button {
  appearance: none; border: 0; background: transparent; color: var(--muted);
  padding: 6px 12px; border-radius: 8px; cursor: pointer; font: inherit; font-size: 12px;
}
.seg button.active { background: var(--primary); color: #fff; font-weight: 600; }
.md-chart-card { margin-bottom: 14px; }
.md-chart-wrap { position: relative; min-height: 180px; }
.md-chart-empty {
  position: absolute; inset: 0; display: grid; place-content: center; gap: 6px; text-align: center;
  background: linear-gradient(180deg, transparent, rgba(13,20,32,.55));
  pointer-events: none;
}
.md-chart-empty b { font-size: 14px; }
.md-chart-empty span { color: var(--muted); font-size: 12.5px; }
.leg {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin: 0 4px 0 10px;
  vertical-align: middle;
}
.leg:first-child { margin-left: 0; }
.leg.dep { background: #22c55e; }
.leg.wit { background: #ef4444; }
.leg.bon { background: #3b82f6; }
.md-tx-head { padding-bottom: 8px; }
.md-tx-head h3 { margin: 0; font-size: 14px; font-family: var(--display); }
.md-tx-head .sub { margin: 4px 0 0; }
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 60;
  min-width: 200px; background: #121a28; border: 1px solid var(--line-strong);
  border-radius: 12px; padding: 6px; box-shadow: 0 16px 40px rgba(0,0,0,.45);
  display: grid; gap: 2px;
}
.dropdown-menu[hidden] {
  display: none !important;
}
.md-profile .dense-list { text-align: left; margin-top: 4px; }
.md-profile .dense-list > .dense-item {
  display: grid; grid-template-columns: 88px 1fr; gap: 8px; align-items: baseline;
  padding: 9px 0; border-bottom: 1px solid var(--line);
}
.md-profile .dense-list > .dense-item:last-child { border-bottom: 0; }
.md-profile .dense-list > .dense-item i { display: none; }
.md-profile .dense-list > .dense-item b {
  color: var(--muted); font-size: 11px; font-weight: 500; text-transform: none;
}
.md-profile .dense-list > .dense-item small {
  color: var(--text); font-size: 13px; font-weight: 600; word-break: break-word;
}
.md-banks .dense-item {
  display: flex; gap: 10px; text-align: left; padding: 10px 0;
  border-bottom: 1px solid var(--line); align-items: center;
}
.md-banks .dense-item:last-child { border-bottom: 0; }
.md-banks .dense-item > div { min-width: 0; }
.md-banks .dense-item b { color: var(--text); font-size: 12.5px; display: block; }
.md-banks .dense-item small { color: var(--muted); font-weight: 400; }
.dropdown-menu button {
  appearance: none; border: 0; background: transparent; color: var(--text);
  text-align: left; padding: 10px 12px; border-radius: 8px; cursor: pointer; font: inherit; font-size: 13px;
}
.dropdown-menu button:hover { background: rgba(59,130,246,.15); }
@media (max-width: 1100px) {
  .md-hero { grid-template-columns: 1fr; }
  .md-hero-balance { text-align: left; justify-self: stretch; }
  .md-actions-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
  .member-detail { grid-template-columns: 1fr; }
  .md-profile { position: static; }
  .stat-row.five { grid-template-columns: repeat(2, 1fr); }
  .md-actions-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.bank-chip {
  display: inline-flex; align-items: center; gap: 8px;
  max-width: 100%; vertical-align: middle;
}
.bank-chip img {
  width: 28px; height: 28px; border-radius: 8px; object-fit: contain;
  background: #0b1220; padding: 0; flex: 0 0 auto;
  border: 1px solid var(--line);
}
.bank-chip-text { display: grid; gap: 1px; min-width: 0; line-height: 1.2; }
.bank-chip-text b {
  font-size: 12.5px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bank-chip-text small { color: var(--muted); font-size: 10.5px; }
.bank-chip.sm img { width: 22px; height: 22px; border-radius: 6px; }
.md-banks .dense-item { align-items: center; }
.md-banks .dense-item .bank-chip { margin-bottom: 2px; }
.channel-opt {
  display: flex; align-items: center; gap: 8px;
}
.stub-card { padding: 16px; }
.stub-card h4 { margin: 0 0 6px; font-size: 14px; font-family: var(--display); }
.stub-card p { margin: 0; color: var(--muted); font-size: 12.5px; line-height: 1.45; }
.pre {
  margin: 0; max-height: 240px; overflow: auto; background: #121a28;
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px;
  font-size: 12px; color: #d1d5db;
}
.backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 35; }
.backdrop.show { display: block; }

@media (max-width: 1400px) {
  .stat-row, .stat-row.five { grid-template-columns: repeat(3, 1fr); }
  .dash-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 1100px) {
  .stat-row, .stat-row.five, .stat-row.four { grid-template-columns: repeat(2, 1fr); }
  .dash-2, .dash-3 { grid-template-columns: 1fr; }
  .top-search { display: none; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: min(86vw, var(--side));
    transform: translateX(-105%); transition: transform .22s ease;
  }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-grid; }
}
