/* QueenRice MLM — Premium Dark UI v2.0 */

/* ============================================================
   CSS Variables & Design Tokens
   ============================================================ */
:root {
  /* Brand Colors */
  --brand-primary:   #f0a500;
  --brand-secondary: #e07b00;
  --brand-accent:    #ffd060;

  /* Dark Backgrounds */
  --bg-base:    #0d0f14;
  --bg-surface: #13161e;
  --bg-card:    #1a1d27;
  --bg-hover:   #22263a;
  --bg-input:   #1e2235;

  /* Text */
  --text-primary:   #e8eaf0;
  --text-secondary: #8a90a8;
  --text-muted:     #555e7a;

  /* Status Colors */
  --green:  #22c55e;
  --red:    #ef4444;
  --blue:   #3b82f6;
  --orange: #f97316;
  --teal:   #14b8a6;

  /* Borders */
  --border:       rgba(255,255,255,0.07);
  --border-light: rgba(255,255,255,0.12);

  /* Spacing */
  --radius-sm: 8px;
  --radius:    12px;
  --radius-lg: 18px;

  /* Sidebar */
  --sidebar-w: 240px;
}

/* ============================================================
   Reset & Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Sarabun', sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--brand-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; display: block; }

/* ============================================================
   Layout — App Shell
   ============================================================ */
.app-body {
  display: flex;
  min-height: 100vh;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page-content {
  padding: 24px;
  flex: 1;
}

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.admin-sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 15px;
}

.logo-img    { height: 36px; width: auto; border-radius: 8px; }
.logo-img-sm { height: 30px; width: auto; border-radius: 6px; }

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  margin: 2px 8px;
  transition: all 0.2s;
  position: relative;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); text-decoration: none; }
.nav-item.active {
  background: linear-gradient(135deg, rgba(240,165,0,.15), rgba(224,123,0,.1));
  color: var(--brand-primary);
  border: 1px solid rgba(240,165,0,.2);
}

.nav-icon { font-size: 18px; }
.nav-label { flex: 1; }
.nav-badge {
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 20px;
}

.sidebar-logout {
  padding: 16px 18px;
  font-size: 13px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  transition: color 0.2s;
}
.sidebar-logout:hover { color: var(--red); text-decoration: none; }

/* ============================================================
   Topbar
   ============================================================ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 64px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title { font-size: 18px; font-weight: 600; }
.topbar-user  { font-size: 13px; color: var(--text-secondary); }
.admin-badge  {
  background: rgba(240,165,0,.15);
  color: var(--brand-primary);
  border: 1px solid rgba(240,165,0,.3);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

/* ============================================================
   Cards — Wallet Grid
   ============================================================ */
.wallet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.wallet-card {
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  transition: transform 0.2s, box-shadow 0.2s;
}
.wallet-card:hover { transform: translateY(-2px); box-shadow: 0 8px 30px rgba(0,0,0,.3); }

.card-green  { background: linear-gradient(135deg, #0d2d1e, #0f3525); border-color: rgba(34,197,94,.2); }
.card-blue   { background: linear-gradient(135deg, #0d1a35, #0f2040); border-color: rgba(59,130,246,.2); }
.card-purple { background: linear-gradient(135deg, #1a0d35, #210f40); border-color: rgba(139,92,246,.2); }
.card-orange { background: linear-gradient(135deg, #2d1a0d, #352010); border-color: rgba(249,115,22,.2); }
.card-teal   { background: linear-gradient(135deg, #0d2d2d, #0f3535); border-color: rgba(20,184,166,.25); }

.wc-icon { font-size: 28px; }
.wc-body { flex: 1; }
.wc-label  { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 2px; }
.wc-amount { display: block; font-size: 22px; font-weight: 700; }
.card-green  .wc-amount { color: var(--green); }
.card-blue   .wc-amount { color: var(--blue); }
.card-purple .wc-amount { color: #a78bfa; }
.card-orange .wc-amount { color: var(--orange); }
.card-teal   .wc-amount { color: var(--teal); }

/* ============================================================
   KPI Cards (Admin)
   ============================================================ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  padding: 20px 24px 0;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.kpi-warn { border-color: rgba(249,115,22,.3); background: rgba(249,115,22,.05); }
.kpi-icon { font-size: 26px; }
.kpi-num  { display: block; font-size: 24px; font-weight: 700; color: var(--text-primary); }
.kpi-label{ display: block; font-size: 11px; color: var(--text-muted); }

/* ============================================================
   Section Cards
   ============================================================ */
.section-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-bottom: 20px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.section-header h2 { font-size: 17px; font-weight: 600; }

/* ============================================================
   Data Tables
   ============================================================ */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th {
  background: var(--bg-surface);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg-hover); }
.admin-table { font-size: 13px; }
.row-highlight { background: rgba(240,165,0,.04); }

/* ============================================================
   Badges
   ============================================================ */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-active  { background: rgba(34,197,94,.15);  color: var(--green); }
.badge-pending { background: rgba(249,115,22,.15); color: var(--orange); }
.badge-danger  { background: rgba(239,68,68,.15);  color: var(--red); }
.badge-closed  { background: rgba(138,144,168,.12); color: var(--text-secondary); }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-family: 'Sarabun', sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.1); transform: translateY(-1px); text-decoration: none; }

.btn-primary   { background: linear-gradient(135deg, var(--brand-primary), var(--brand-secondary)); color: #111; }
.btn-secondary { background: linear-gradient(135deg, #3b82f6, #2563eb); color: #fff; }
.btn-success   { background: linear-gradient(135deg, #22c55e, #16a34a); color: #fff; }
.btn-danger    { background: linear-gradient(135deg, #ef4444, #dc2626); color: #fff; }
.btn-ghost     { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-full      { width: 100%; justify-content: center; }
.btn-lg        { padding: 12px 24px; font-size: 16px; border-radius: var(--radius); }
.btn-sm        { padding: 6px 14px; font-size: 13px; }
.btn-xs        { padding: 4px 10px; font-size: 12px; }
.btn-outline-light { background: rgba(255,255,255,.1); color: #fff; border: 1px solid rgba(255,255,255,.2); }

.action-btns { display: flex; gap: 6px; flex-wrap: wrap; }

/* ============================================================
   Forms
   ============================================================ */
.form-group  { margin-bottom: 16px; }
.form-row    { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3  { grid-template-columns: 1fr 1fr 1fr; }
.form-section { margin-bottom: 24px; padding-bottom: 24px; border-bottom: 1px solid var(--border); }
.form-section:last-of-type { border-bottom: none; }

.section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--brand-primary);
  margin-bottom: 14px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: 'Sarabun', sans-serif;
  font-size: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(240,165,0,.12);
}

select option { background: var(--bg-card); }

/* ============================================================
   Auth Pages
   ============================================================ */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at 50% 0%, rgba(240,165,0,.08) 0%, transparent 60%), var(--bg-base);
}

.auth-container { width: 100%; max-width: 480px; padding: 20px; }
.register-container { max-width: 640px; }

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  animation: slideUp .4s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-logo .logo-img { height: 60px; margin: 0 auto 12px; }
.auth-title    { font-size: 22px; font-weight: 700; }
.auth-subtitle { font-size: 13px; color: var(--text-muted); }

.auth-switch { text-align: center; margin-top: 18px; font-size: 13px; color: var(--text-muted); }
.btn-link { color: var(--brand-primary); font-weight: 600; }

.input-pw-wrap { position: relative; }
.pw-toggle {
  position: absolute;
  right: 10px; top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
}

/* ============================================================
   Alerts
   ============================================================ */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 16px;
  border: 1px solid;
}
.alert-error   { background: rgba(239,68,68,.1);  border-color: rgba(239,68,68,.3);  color: #fca5a5; }
.alert-success { background: rgba(34,197,94,.1);  border-color: rgba(34,197,94,.3);  color: #86efac; }
.alert-info    { background: rgba(59,130,246,.1); border-color: rgba(59,130,246,.3); color: #93c5fd; }

/* ============================================================
   Matrix Position
   ============================================================ */
.position-active-card {
  background: linear-gradient(135deg, rgba(59,130,246,.08), rgba(14,184,166,.05));
  border: 1px solid rgba(59,130,246,.2);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

.pa-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 8px; }
.pa-badge  { background: rgba(34,197,94,.15); color: var(--green); padding: 4px 12px; border-radius: 20px; font-size: 13px; font-weight: 600; }
.pa-date   { font-size: 12px; color: var(--text-muted); }
.pa-note   { font-size: 12px; color: var(--text-muted); margin-top: 10px; }

.empty-position {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.ep-icon { font-size: 40px; display: block; margin-bottom: 10px; }

/* Progress Bar */
.progress-wrap {
  position: relative;
  background: var(--bg-base);
  border-radius: 20px;
  height: 18px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--brand-secondary), var(--brand-primary));
  border-radius: 20px;
  transition: width 0.5s ease;
}
.progress-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,.5);
}
.progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* ============================================================
   Referral Link
   ============================================================ */
.ref-link-box {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 10px 0;
}
.ref-link-box input {
  flex: 1;
  font-size: 12px;
  color: var(--text-muted);
  cursor: text;
}
.ref-note { font-size: 12px; color: var(--text-muted); }

/* ============================================================
   Toggle Switch (Auto Re-entry)
   ============================================================ */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 0;
}
.setting-info p { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.setting-note   { font-size: 13px; color: var(--text-muted); margin-top: 8px; }

.toggle-switch { position: relative; display: inline-block; width: 52px; height: 28px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: 30px;
  transition: .3s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  height: 20px; width: 20px;
  left: 3px; bottom: 3px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: .3s;
}
.toggle-switch input:checked + .toggle-slider {
  background: rgba(240,165,0,.2);
  border-color: var(--brand-primary);
}
.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(24px);
  background: var(--brand-primary);
}

/* ============================================================
   File Upload
   ============================================================ */
.file-upload-area {
  background: var(--bg-input);
  border: 2px dashed var(--border-light);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s;
  position: relative;
}
.file-upload-area:hover,
.file-upload-area.dragging { border-color: var(--brand-primary); }

.file-upload-area input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.file-icon { font-size: 32px; display: block; margin-bottom: 8px; }
.file-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
#fileName { font-size: 13px; color: var(--text-secondary); }

/* Slip Thumbnail */
.slip-thumb      { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.slip-thumb-link { display: block; }

/* ============================================================
   Sponsor Box
   ============================================================ */
.sponsor-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(34,197,94,.08);
  border: 1px solid rgba(34,197,94,.2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
}
.sponsor-icon { font-size: 20px; }

/* Payment Info */
.payment-info {
  background: rgba(240,165,0,.07);
  border: 1px solid rgba(240,165,0,.2);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 14px;
  font-size: 14px;
}
.bank-detail { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ============================================================
   Re-entry Page
   ============================================================ */
.reentry-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}
.reentry-tab {
  flex: 1;
  text-align: center;
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  font-weight: 600;
  font-size: 14px;
  color: var(--text-secondary);
  transition: all 0.2s;
}
.reentry-tab.active {
  background: linear-gradient(135deg, rgba(240,165,0,.2), rgba(224,123,0,.1));
  border-color: var(--brand-primary);
  color: var(--brand-primary);
}
.reentry-tab:hover { text-decoration: none; color: var(--text-primary); }

.reentry-info-box {
  background: var(--bg-surface);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}
.reentry-info-box h3 { font-size: 16px; margin-bottom: 8px; }
.reentry-info-box ul { list-style: none; margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.reentry-info-box li { font-size: 14px; color: var(--text-secondary); }

.wallet-summary {
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  font-size: 15px;
}

/* ============================================================
   Search Bar
   ============================================================ */
.search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.search-bar input  { flex: 1; min-width: 200px; }
.search-bar select { min-width: 140px; }

/* ============================================================
   Toast Notification
   ============================================================ */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
  transform: translateY(80px);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 9999;
}
.toast.show { transform: translateY(0); opacity: 1; }

/* ============================================================
   Utility
   ============================================================ */
.text-green  { color: var(--green) !important; }
.text-red    { color: var(--red) !important; }
.text-muted  { color: var(--text-muted) !important; }
.text-sm     { font-size: 12px; }
.text-center { text-align: center; }
.empty-state { text-align: center; padding: 32px; color: var(--text-muted); font-size: 14px; }
.type-badge  { background: var(--bg-hover); padding: 3px 8px; border-radius: 6px; font-size: 11px; }
.section-desc { font-size: 14px; color: var(--text-muted); margin-bottom: 16px; }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .main-content { margin-left: 0; }
  .wallet-grid  { grid-template-columns: 1fr 1fr; }
  .kpi-grid     { grid-template-columns: 1fr 1fr; }
  .form-row     { grid-template-columns: 1fr; }
  .form-row-3   { grid-template-columns: 1fr; }
  .data-table   { font-size: 12px; }
  .page-content { padding: 14px; }
}

/* ============================================================
   AJAX Loader Bar
   ============================================================ */
.ajax-loader-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--brand-primary);
  z-index: 99999;
  width: 0%;
  transition: width 0.2s ease, opacity 0.3s ease;
  opacity: 0;
  box-shadow: 0 0 10px var(--brand-primary);
}
.ajax-loader-bar.active {
  opacity: 1;
}

/* ============================================================
   NET BALANCE BANNER — ยอดเงินคงเหลือสุทธิ (admin_dashboard)
   ============================================================ */
@keyframes shimmer-nb {
  0%   { background-position: -200% center; }
  100% { background-position:  200% center; }
}

.net-balance-banner {
  border-radius: 16px;
  padding: 1.6rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1.25rem;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(16,185,129,0.3);
  background: linear-gradient(135deg, rgba(16,185,129,0.12) 0%, rgba(16,185,129,0.05) 50%, rgba(59,130,246,0.08) 100%);
}
.net-balance-banner.negative {
  border-color: rgba(239,68,68,0.35);
  background: linear-gradient(135deg, rgba(239,68,68,0.12) 0%, rgba(239,68,68,0.05) 50%, rgba(245,158,11,0.06) 100%);
}
.net-balance-banner::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.04), transparent);
  background-size: 200% auto;
  animation: shimmer-nb 3s linear infinite;
  pointer-events: none;
}

.net-balance-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.net-balance-icon {
  width: 60px; height: 60px;
  border-radius: 16px;
  background: rgba(16,185,129,0.15);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem;
  flex-shrink: 0;
}
.net-balance-banner.negative .net-balance-icon {
  background: rgba(239,68,68,0.15);
}

.net-balance-label {
  font-size: .72rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: .4rem;
}
.net-balance-amount {
  font-size: 2.4rem;
  font-weight: 800;
  line-height: 1;
  color: #10b981;
  text-shadow: 0 0 32px rgba(16,185,129,0.35);
}
.net-balance-banner.negative .net-balance-amount {
  color: #ef4444;
  text-shadow: 0 0 32px rgba(239,68,68,0.35);
}
.net-balance-sub {
  font-size: .78rem;
  color: #64748b;
  margin-top: .4rem;
}

.net-balance-right {
  display: flex;
  flex-wrap: wrap;
  gap: .65rem;
  justify-content: flex-end;
}
.nb-breakdown-item {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 10px;
  padding: .65rem 1rem;
  text-align: center;
  min-width: 130px;
}
.nb-breakdown-label {
  font-size: .65rem;
  color: #64748b;
  margin-bottom: .25rem;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.nb-breakdown-val {
  font-size: .95rem;
  font-weight: 700;
  color: #e2e8f0;
}

.nb-bar-wrap {
  margin-top: .85rem;
  width: 100%;
  background: rgba(255,255,255,0.06);
  border-radius: 99px;
  height: 6px;
  overflow: hidden;
}
.nb-bar-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #10b981, #34d399);
  transition: width .8s ease;
}

@media (max-width: 900px) {
  .net-balance-banner { flex-direction: column; align-items: flex-start; }
  .net-balance-right  { justify-content: flex-start; }
  .nb-breakdown-item  { min-width: 110px; }
}

/* ============================================================
   ADMIN DASHBOARD — KPI & LAYOUT GRID
   (ต้องอยู่ใน style.css เพื่อให้ PJAX โหลดได้)
   ============================================================ */

/* Dashboard Variables */
:root {
  --gold:        #f59e0b;
  --gold-light:  #fcd34d;
  --gold-dim:    rgba(245,158,11,0.12);
  --green:       #10b981;
  --green-dim:   rgba(16,185,129,0.12);
  --red:         #ef4444;
  --red-dim:     rgba(239,68,68,0.12);
  --blue:        #3b82f6;
  --blue-dim:    rgba(59,130,246,0.12);
  --surface:     #1e2433;
  --surface2:    #252d3d;
  --surface3:    #2d3748;
  --text:        #e2e8f0;
  --muted:       #64748b;
}

/* Dashboard Grid Layout */
.dash-grid {
  display: grid;
  gap: 1.25rem;
  padding: 0 1.5rem 2rem;
}

/* KPI Cards Row */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}
@media (max-width: 1100px) { .kpi-row { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 600px)  { .kpi-row { grid-template-columns: 1fr; } }

.dash-kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.4rem 1.5rem;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  position: relative;
  overflow: hidden;
  transition: transform .2s, box-shadow .2s;
}
.dash-kpi:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.dash-kpi::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  border-radius: 14px 14px 0 0;
}
.dash-kpi.gold::before  { background: linear-gradient(90deg, var(--gold), var(--gold-light)); }
.dash-kpi.green::before { background: linear-gradient(90deg, var(--green), #34d399); }
.dash-kpi.red::before   { background: linear-gradient(90deg, var(--red), #f87171); }
.dash-kpi.blue::before  { background: linear-gradient(90deg, var(--blue), #60a5fa); }

.kpi-icon-wrap {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}
.dash-kpi.gold  .kpi-icon-wrap { background: var(--gold-dim); }
.dash-kpi.green .kpi-icon-wrap { background: var(--green-dim); }
.dash-kpi.red   .kpi-icon-wrap { background: var(--red-dim); }
.dash-kpi.blue  .kpi-icon-wrap { background: var(--blue-dim); }

.kpi-body { flex: 1; min-width: 0; }
.kpi-subtitle { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: .3rem; }
.kpi-main {
  font-size: 1.55rem; font-weight: 700; line-height: 1.1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dash-kpi.gold  .kpi-main { color: var(--gold); }
.dash-kpi.green .kpi-main { color: var(--green); }
.dash-kpi.red   .kpi-main { color: var(--red); }
.dash-kpi.blue  .kpi-main { color: var(--blue); }
.kpi-sub { font-size: 0.75rem; color: var(--muted); margin-top: .35rem; }
.kpi-badge-wrap { font-size: .7rem; margin-top: .4rem; }
.kpi-badge-sm {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: .68rem; font-weight: 600;
}
.badge-gold  { background: var(--gold-dim);  color: var(--gold); }
.badge-green { background: var(--green-dim); color: var(--green); }
.badge-red   { background: var(--red-dim);   color: var(--red); }
.badge-blue  { background: var(--blue-dim);  color: var(--blue); }

/* Secondary KPIs */
.secondary-kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .75rem;
}
@media (max-width: 900px) { .secondary-kpi-row { grid-template-columns: repeat(2,1fr); } }

.sec-kpi {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .9rem 1.1rem;
}
.sec-kpi-label { font-size: .7rem; color: var(--muted); margin-bottom: .25rem; }
.sec-kpi-val   { font-size: 1.1rem; font-weight: 700; color: var(--text); }

/* Charts Row */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 1.25rem;
}
@media (max-width: 1000px) { .charts-row { grid-template-columns: 1fr; } }

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.5rem;
  position: relative;
  min-height: 320px;            /* ป้องกัน chart-card collapse เป็น 0 */
}
/* Canvas ต้องมี background สีเข้ม ป้องกัน white flash ขณะ Chart.js กำลัง render */
.chart-card canvas {
  display: block;
  background: var(--surface);   /* พื้นหลังเดียวกับ card */
}
.chart-card-title {
  font-size: .85rem; font-weight: 600; color: var(--text);
  margin-bottom: 1.2rem; display: flex; align-items: center; gap: .5rem;
}
.chart-card-title span { color: var(--muted); font-weight: 400; font-size: .75rem; }
.chart-legend {
  display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem;
}
.legend-item {
  display: flex; align-items: center; gap: .35rem;
  font-size: .72rem; color: var(--muted);
}
.legend-dot {
  width: 8px; height: 8px; border-radius: 50%;
}

/* Bottom Row */
.bottom-row {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1.25rem;
}
@media (max-width: 1000px) { .bottom-row { grid-template-columns: 1fr; } }

.panel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}
.panel-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.panel-title {
  font-size: .85rem; font-weight: 600; color: var(--text);
  display: flex; align-items: center; gap: .5rem;
}
.panel-body { padding: 0; }

/* Withdrawal table */
.wd-table { width: 100%; border-collapse: collapse; font-size: .8rem; }
.wd-table th {
  padding: .65rem 1rem; text-align: left;
  font-size: .68rem; color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
.wd-table td {
  padding: .8rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text); vertical-align: middle;
}
.wd-table tr:last-child td { border-bottom: none; }
.wd-table tr:hover td { background: var(--surface2); }
.wd-amount { font-weight: 700; color: var(--red); }
.wd-actions { display: flex; gap: .4rem; }

/* Activity feed */
.feed-list { padding: 0; list-style: none; margin: 0; }
.feed-item {
  padding: .8rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex; gap: .75rem; align-items: flex-start;
}
.feed-item:last-child { border-bottom: none; }
.feed-dot {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .9rem; flex-shrink: 0; margin-top: .05rem;
}
.feed-dot.in  { background: var(--green-dim); }
.feed-dot.out { background: var(--red-dim); }
.feed-dot.co  { background: var(--gold-dim); }
.feed-dot.sp  { background: var(--blue-dim); }
.feed-info { flex: 1; min-width: 0; }
.feed-name { font-size: .8rem; font-weight: 600; color: var(--text); }
.feed-desc { font-size: .7rem; color: var(--muted); margin-top: .1rem;
             white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feed-amt  { font-size: .8rem; font-weight: 700; flex-shrink: 0; text-align: right; }
.feed-amt.pos { color: var(--green); }
.feed-amt.neg { color: var(--red); }
.feed-time { font-size: .65rem; color: var(--muted); }

/* Topbar Controls */
.dash-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.25rem 1.5rem .5rem;
  flex-wrap: wrap; gap: .75rem;
}
.dash-title { font-size: 1.35rem; font-weight: 700; color: var(--text); }
.dash-title small { display: block; font-size: .75rem; color: var(--muted); font-weight: 400; }
.dash-controls { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }

.btn-export {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .5rem 1rem; border-radius: 8px; font-size: .8rem; font-weight: 600;
  cursor: pointer; text-decoration: none; border: none;
  transition: all .2s;
}
.btn-export.csv   { background: var(--green-dim);  color: var(--green); border: 1px solid rgba(16,185,129,.25); }
.btn-export.csv:hover { background: var(--green); color: #fff; }
.btn-export.csv2  { background: var(--gold-dim);   color: var(--gold);  border: 1px solid rgba(245,158,11,.25); }
.btn-export.csv2:hover { background: var(--gold); color: #000; }

.refresh-wrap {
  display: flex; align-items: center; gap: .6rem;
  padding: .45rem .9rem; border-radius: 8px;
  background: var(--surface2); border: 1px solid var(--border);
  font-size: .8rem; color: var(--muted);
}
.refresh-countdown {
  min-width: 28px; text-align: center;
  font-weight: 700; color: var(--gold); font-variant-numeric: tabular-nums;
}
.btn-refresh-now {
  background: none; border: none; cursor: pointer;
  color: var(--blue); font-size: .85rem; padding: 0; line-height: 1;
  transition: color .15s;
}
.btn-refresh-now:hover { color: #93c5fd; }

.admin-badge-dash {
  background: var(--gold-dim); color: var(--gold);
  border: 1px solid rgba(245,158,11,.3);
  padding: .3rem .8rem; border-radius: 20px; font-size: .75rem; font-weight: 600;
}

.empty-panel {
  padding: 2.5rem; text-align: center; color: var(--muted); font-size: .85rem;
}

/* Pulse dot for live */
@keyframes pulse-dot {
  0%,100% { opacity:1; transform:scale(1); }
  50%      { opacity:.5; transform:scale(.7); }
}
.live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green); display: inline-block;
  animation: pulse-dot 1.8s infinite;
}

/* Number display — ไม่ใช้ animation เพราะทำให้กระพริบทุกครั้งที่ AJAX update */
/* .kpi-main { animation: countUp .5s ease both; } */

