/* AURUM Admin v2 — bright theme */
:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --line: #e3e7f0;
  --text: #0f172a;
  --muted: #5b6478;
  --blue: #2563eb;
  --green: #16a34a;
  --red: #dc2626;
  --purple: #8b5cf6;
  --amber: #f59e0b;
  --radius: 16px;
  --side: 260px;
  --mono: 'DM Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.55;
}
a { color: var(--blue); }
button, input, select, textarea { font: inherit; }
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100vh; }
.side {
  width: var(--side);
  flex: 0 0 var(--side);
  background: #fff;
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 700; font-size: 20px; letter-spacing: .5px; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, #f59e0b, #d97706); color: #fff; display: grid; place-items: center; font-family: var(--mono); font-size: 16px; }
.brand small { display: block; font-weight: 400; font-size: 13px; color: var(--muted); letter-spacing: 0; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  min-height: 48px; padding: 10px 14px; border-radius: 12px;
  color: var(--text); text-decoration: none; font-weight: 500;
}
.nav a svg { width: 22px; height: 22px; flex: 0 0 22px; stroke: currentColor; }
.nav a:hover { background: #eef2fb; }
.nav a[aria-current='page'] { background: var(--blue); color: #fff; }
.side-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--line); font-size: 14px; color: var(--muted); }
.side-foot .who { word-break: break-all; margin-bottom: 8px; }

.main { flex: 1; min-width: 0; padding: 28px 32px 48px; }
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; justify-content: space-between; margin-bottom: 22px; }
.topbar h1 { font-size: 30px; line-height: 1.25; margin: 0; }
.topbar .sub { color: var(--muted); font-size: 15px; margin-top: 2px; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.month-label { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.rate-pill { font-size: 14px; color: var(--muted); background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; }

.menu-btn { display: none; }

/* ---------- controls ---------- */
.input, select.input, input[type='month'], input[type='search'] {
  min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--text);
}
.btn {
  min-height: 44px; min-width: 44px; padding: 8px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: #fff; color: var(--text); cursor: pointer; font-weight: 500;
}
.btn:hover { background: #f3f5fa; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: #1d4fd8; }
.btn.danger { color: var(--red); }
.btn:focus-visible, .nav a:focus-visible, .input:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid #93b4ff; outline-offset: 2px; }

/* ---------- cards ---------- */
.grid { display: grid; gap: 16px; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); margin-bottom: 20px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); margin-bottom: 20px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; position: relative; overflow: hidden; min-width: 0; }
.card.bar::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 6px; background: var(--bar, var(--blue)); }
.card.bar { padding-top: 24px; }
.bar-green { --bar: var(--green); }
.bar-red { --bar: var(--red); }
.bar-blue { --bar: var(--blue); }
.bar-purple { --bar: var(--purple); }
.bar-amber { --bar: var(--amber); }
.kpi-label { color: var(--muted); font-size: 15px; }
.kpi-value { font-family: var(--mono); font-size: 32px; font-weight: 500; line-height: 1.2; margin-top: 4px; word-break: break-word; }
.kpi-sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
.card h2 { font-size: 20px; margin: 0 0 12px; }
.card h3 { font-size: 17px; margin: 16px 0 8px; }
.section { margin-bottom: 20px; }

.neutral {
  background: #f1f4f9; border: 1px dashed #c9d1e1; border-radius: 12px; padding: 14px 16px; color: #3b4458; font-size: 15px;
}
.neutral.big { padding: 28px; text-align: center; font-size: 17px; }
.loading { color: var(--muted); padding: 10px 0; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 14px; background: #fafbfe; position: sticky; top: 0; }
td.r, th.r { text-align: right; }
tr:hover td { background: #fafbfe; }
.empty-row td { text-align: center; color: var(--muted); padding: 20px; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; align-items: center; }
.filters label { display: flex; align-items: center; gap: 6px; font-size: 15px; }

/* ---------- chips / badges ---------- */
.chip { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 500; margin: 1px 4px 1px 0; border: 1px solid transparent; }
.chip.aurum { background: #fff7e6; color: #92400e; border-color: #fde3a7; }
.chip.trading { background: #e8f0ff; color: #1e40af; border-color: #c7d8ff; }
.chip.chatbot { background: #f2ecff; color: #5b21b6; border-color: #ddd0ff; }
.chip.partners { background: #fff3e0; color: #9a3412; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 8px; font-size: 13px; font-weight: 500; background: #eef1f6; color: #3b4458; }
.badge.ok { background: #e7f7ec; color: #166534; }
.badge.warn { background: #fff4db; color: #92400e; }
.badge.bad { background: #fde8e8; color: #991b1b; }
.badge.info { background: #e8f0ff; color: #1e40af; }

/* ---------- alerts ---------- */
.alerts { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.alerts li { padding: 10px 14px; border-radius: 10px; background: #f6f8fc; border-left: 4px solid #94a3b8; font-size: 15px; }
.alerts li.warn { background: #fff8e8; border-left-color: var(--amber); }
.alerts li.info { background: #f1f5ff; border-left-color: var(--blue); }

/* ---------- product rows ---------- */
.prod-table td:first-child { font-weight: 600; }

/* ---------- chart ---------- */
.chart { width: 100%; height: auto; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 14px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.sharebar { display: flex; height: 18px; border-radius: 999px; overflow: hidden; background: #eef1f6; margin: 8px 0; }
.sharebar span { display: block; height: 100%; }

.stat-list { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; font-size: 15px; }
.stat-list dt { color: var(--muted); }
.stat-list dd { margin: 0; text-align: right; font-family: var(--mono); }

/* ---------- costs ---------- */
tr.soon td { background: #fff7e0; }
tr.inactive td { color: #94a3b8; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
.form-grid .wide { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.msg { margin-top: 10px; font-size: 15px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 420px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 10px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; }
.mfa-steps { margin: 10px 0 0; padding-left: 22px; color: var(--muted); font-size: 15px; line-height: 1.7; }
.mfa-qr { display: grid; place-items: center; margin-top: 12px; }
.mfa-qr img { width: 200px; height: 200px; padding: 8px; background: #fff; border: 1px solid var(--line); border-radius: 12px; }
.mfa-secret { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; font-size: 14px; color: var(--muted); }
.mfa-secret code { font-family: var(--mono); font-size: 15px; color: var(--text); background: #eef1f6; padding: 8px 10px; border-radius: 8px; word-break: break-all; user-select: all; }
.mfa-tip { margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.mfa-code { font-family: var(--mono); font-size: 24px; letter-spacing: 0.3em; text-align: center; }
.login-card .msg:not(:empty) { color: #991b1b; font-weight: 500; }
.mfa-back { align-self: flex-start; color: var(--blue); font-weight: 500; padding: 6px 0; }

/* ---------- mobile ---------- */
@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .side { position: static; width: 100%; height: auto; flex: none; padding: 10px 14px; border-right: 0; border-bottom: 1px solid var(--line); }
  .side-head { display: flex; align-items: center; justify-content: space-between; }
  .brand { padding: 4px 0; }
  .menu-btn { display: inline-flex; align-items: center; gap: 8px; }
  .nav, .side-foot { display: none; }
  .side.open .nav, .side.open .side-foot { display: flex; }
  .side.open .side-foot { display: block; }
  .main { padding: 18px 14px 40px; }
  .topbar h1 { font-size: 26px; }
  .kpi-value { font-size: 28px; }
}

/* ---------- พาร์ทเนอร์: pending banner, drawer, confirm dialog ---------- */
.pending-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; padding: 14px 16px; border: 1px solid #f7d58a; background: #fff8e6; border-radius: var(--radius); }
.badge.big { font-size: 16px; padding: 6px 14px; font-weight: 600; }
.tier { display: inline-block; padding: 2px 10px; border-radius: 8px; font-size: 13px; font-weight: 600; background: #eef1f6; color: #3b4458; }
.tier-bronze { background: #f6e7da; color: #7a3f12; }
.tier-silver { background: #eceff3; color: #3b4458; }
.tier-gold { background: #fdf1cc; color: #7a5300; }
.tier-platinum { background: #e6f0f7; color: #1f4a6b; }
.tier-elite { background: #ede7fd; color: #4c2a9c; }
tr.click-row { cursor: pointer; }
tr.click-row td { vertical-align: middle; }
tr.row-pending td { background: #fffbf0; }
.linkish { background: none; border: 0; padding: 0; min-height: 44px; color: var(--blue); font: inherit; font-weight: 600; cursor: pointer; text-align: left; }
.linkish:focus-visible { outline: 3px solid #93b4ff; outline-offset: 2px; }
body.no-scroll { overflow: hidden; }
.drawer-backdrop, .modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); z-index: 40; }
.modal-backdrop { z-index: 60; display: grid; place-items: center; padding: 16px; }
.drawer-backdrop[hidden], .modal-backdrop[hidden], .drawer[hidden] { display: none; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 100vw); background: var(--card); z-index: 50; display: flex; flex-direction: column; box-shadow: -12px 0 40px rgba(15, 23, 42, 0.18); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-size: 20px; }
.drawer-body { padding: 18px 20px 40px; overflow-y: auto; }
.drawer-body h3 { margin: 22px 0 10px; font-size: 17px; }
.pd-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; align-items: flex-start; }
.pd-name { font-size: 20px; font-weight: 600; }
.action-row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.action-grid { grid-template-columns: 1fr auto; align-items: end; }
.action-grid textarea { width: 100%; resize: vertical; }
.btn.primary[disabled] { opacity: 0.6; cursor: wait; }
.modal { background: var(--card); border-radius: var(--radius); padding: 22px; width: min(520px, 100%); max-height: 90vh; overflow-y: auto; box-shadow: 0 30px 80px rgba(15, 23, 42, 0.3); }
.modal h2 { margin: 0 0 10px; font-size: 20px; }
.changes { margin: 10px 0 14px; padding-left: 20px; display: grid; gap: 6px; font-size: 15px; }
.changes .from { color: var(--muted); text-decoration: line-through; }
.changes .to { font-weight: 600; }
.warnbox { border-color: #f7d58a; background: #fff8e6; color: #7a5300; margin-bottom: 8px; }
.result-note { padding: 10px 14px; margin-bottom: 12px; border-radius: 12px; background: #e7f7ec; color: #166534; font-weight: 500; }
.inline-err { padding: 10px 14px; margin-bottom: 12px; border-radius: 12px; background: #fdecec; color: #991b1b; font-weight: 500; }
@media (max-width: 900px) {
  .drawer { width: 100vw; }
  .drawer-body { padding: 14px 14px 40px; }
  .action-grid { grid-template-columns: 1fr; }
}

/* partner plan chip + rates card */
.plan { display: inline-block; padding: 2px 10px; border-radius: 8px; font-size: 13px; font-weight: 600; }
.plan-single { background: #e8f0ff; color: #1e40af; }
.plan-group { background: #ede7fd; color: #4c2a9c; }
.muted { color: var(--muted); }
.rates-grid { margin-bottom: 10px; }
.rates-grid .input { max-width: 100%; }
.rate-hint { font-size: 15px; margin-bottom: 12px; }
.rate-hint .warnbox, .rate-hint .inline-err { margin-top: 8px; }
.changes li.same { color: var(--muted); }
.changes li.same .from { text-decoration: none; }

/* tier rates matrix: a table on desktop, one block per tier on a phone */
.tier-rates { display: grid; gap: 8px; margin-bottom: 10px; }
.tr-row { display: grid; grid-template-columns: 110px repeat(4, minmax(0, 1fr)); gap: 8px 12px; align-items: start; padding: 8px 0; border-bottom: 1px solid var(--line); }
.tr-head { font-size: 13px; color: var(--muted); padding-top: 0; }
.tr-tier { padding-top: 10px; }
.tr-cell { display: flex; flex-direction: column; gap: 4px; }
.tr-cell .input { width: 100%; max-width: 100%; }
.tr-label { display: none; font-size: 13px; color: var(--muted); }
.tr-hint { grid-column: 2 / -1; font-size: 14px; margin-bottom: 0; }
.tr-hint .warnbox { margin: 6px 0 0; }
/* point thresholds */
.th-help { font-size: 15px; margin: 0 0 12px; }
.th-grid { display: grid; gap: 8px; max-width: 420px; margin-bottom: 10px; }
.th-row { display: grid; grid-template-columns: 110px 1fr; gap: 12px; align-items: center; }
.th-row .input { width: 100%; }
.th-fixed { padding: 8px 0; }
/* drawer: point rows */
.sub-h { margin: 16px 0 8px; font-size: 15px; color: var(--muted); }
tr.void-row td { text-decoration: line-through; color: var(--muted); }
tr.void-row td .badge { text-decoration: none; }
@media (max-width: 640px) {
  .tr-head { display: none; }
  .tr-row { grid-template-columns: 1fr; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
  .tr-tier { padding-top: 0; }
  .tr-label { display: block; }
  .tr-hint { grid-column: 1; }
  .th-row { grid-template-columns: 96px 1fr; }
}
.stat-list.stat-wide { grid-template-columns: max-content 1fr; }
@media (max-width: 640px) { .stat-list.stat-wide { grid-template-columns: 1fr; gap: 2px; } .stat-list.stat-wide dd { text-align: left; margin-bottom: 8px; } }

/* ---------- menu: red "รออนุมัติ" pill on พาร์ทเนอร์ ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.nav-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px;
  background: var(--red); color: #fff; font-family: var(--mono); font-size: 13px; font-weight: 500; line-height: 1;
}
.nav-badge[hidden] { display: none; }
.nav a .nav-badge { margin-left: auto; }
.nav a[aria-current='page'] .nav-badge { box-shadow: 0 0 0 2px #fff; }
.menu-btn .nav-badge { margin-left: 2px; }

/* ---------- พาร์ทเนอร์: KYC documents inline + viewer ---------- */
.kyc-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.kyc-cell { margin: 0; min-width: 0; }
.kyc-cell figcaption { font-weight: 500; font-size: 15px; margin-bottom: 6px; }
.kyc-cell-body { min-height: 120px; }
.kyc-thumb, .kyc-tile {
  display: flex; width: 100%; padding: 0; border: 1px solid var(--line); border-radius: 12px;
  background: #eef1f6; cursor: zoom-in; overflow: hidden; font: inherit; color: var(--text);
}
.kyc-thumb img { display: block; width: 100%; height: 240px; object-fit: contain; background: #eef1f6; }
.kyc-tile { height: 240px; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 14px; cursor: pointer; text-align: center; }
.kyc-pdf-icon { color: var(--red); }
.kyc-tile-name { font-weight: 600; }
.kyc-tile-meta { font-size: 14px; color: var(--muted); font-family: var(--mono); }
.kyc-thumb:focus-visible, .kyc-tile:focus-visible, .kyc-nav:focus-visible, .kyc-close:focus-visible { outline: 3px solid #93b4ff; outline-offset: 2px; }
.kyc-skeleton { height: 240px; border-radius: 12px; background: linear-gradient(90deg, #eef1f6 25%, #f7f8fb 50%, #eef1f6 75%); background-size: 200% 100%; animation: kyc-shimmer 1.2s linear infinite; }
@keyframes kyc-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .kyc-skeleton { animation: none; } }
.kyc-error { height: 240px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; border: 1px dashed #f3b4b4; border-radius: 12px; background: #fdf3f3; color: #991b1b; font-weight: 500; text-align: center; padding: 12px; }
.kyc-viewer { position: fixed; inset: 0; z-index: 70; background: rgba(10, 14, 24, 0.97); display: flex; flex-direction: column; }
.kyc-viewer[hidden] { display: none; }
.kyc-view-bar { display: flex; align-items: center; gap: 14px; padding: 10px 14px; color: #fff; }
.kyc-view-title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 10px; }
.kyc-view-title span { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kyc-view-title small { color: #c3c9d6; font-family: var(--mono); white-space: nowrap; }
.kyc-newtab { color: #c9dbff; font-size: 14px; white-space: nowrap; }
.kyc-close, .kyc-nav { min-width: 44px; min-height: 44px; border: 0; border-radius: 999px; background: rgba(255, 255, 255, 0.14); color: #fff; font-size: 22px; line-height: 1; cursor: pointer; }
.kyc-close:hover, .kyc-nav:hover { background: rgba(255, 255, 255, 0.26); }
.kyc-view-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 8px 64px 24px; }
.kyc-view-img { max-width: 100%; max-height: 100%; object-fit: contain; background: #eef1f6; border-radius: 6px; }
.kyc-view-pdf { width: min(1000px, 100%); height: 100%; border: 0; border-radius: 6px; background: #fff; }
.kyc-view-stage .kyc-error, .kyc-view-stage .kyc-skeleton { width: min(520px, 100%); }
.kyc-nav { position: absolute; top: 50%; transform: translateY(-50%); font-size: 30px; }
.kyc-prev { left: 10px; }
.kyc-next { right: 10px; }
@media (max-width: 640px) {
  .kyc-grid { grid-template-columns: 1fr; }
  .kyc-view-bar { gap: 10px; }
  .kyc-view-title { flex-direction: column; align-items: flex-start; gap: 0; }
  .kyc-view-title span { max-width: 100%; }
  .kyc-view-stage { padding: 4px 6px 72px; }
  .kyc-nav { top: auto; bottom: 14px; transform: none; }
  .kyc-prev { left: calc(50% - 56px); }
  .kyc-next { right: calc(50% - 56px); }
}
