/* ============================================================
   Referral Admin — Polished Dark Theme
   ============================================================ */

:root {
  --bg: #09090b;
  --surface: #18181b;
  --surface-2: #1f1f23;
  --surface-3: #27272a;
  --surface-hover: #2c2c31;
  --border: #2e2e33;
  --border-hover: #3f3f46;
  --text: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --text-dim: #52525b;

  --orange: #F15822;
  --orange-light: #ff7a47;
  --orange-bg: rgba(241,88,34,0.10);
  --orange-bg-hover: rgba(241,88,34,0.18);

  --blue: #3b82f6;
  --blue-bg: rgba(59,130,246,0.10);
  --green: #22c55e;
  --green-bg: rgba(34,197,94,0.10);
  --purple: #a78bfa;
  --purple-bg: rgba(167,139,250,0.10);
  --amber: #f59e0b;
  --amber-bg: rgba(245,158,11,0.10);
  --red: #ef4444;
  --red-bg: rgba(239,68,68,0.10);
  --red-hover: #f87171;

  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
}

*, *::before, *::after { box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, sans-serif;
  margin: 0;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--orange); text-decoration: none; }
a:hover { color: var(--orange-light); }
code { font-family: "SF Mono", "Fira Code", monospace; }

/* ── Topbar ── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: 56px;
  background: rgba(24,24,27,0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 100;
}

.topbar__left { display: flex; align-items: center; gap: 28px; }

.topbar__brand {
  display: flex; align-items: center; gap: 12px;
  white-space: nowrap;
}

/* ZG text wordmark */
.zg-logo {
  display: inline-flex; flex-direction: column;
  align-items: flex-start; line-height: 1;
}
.zg-logo--inline {
  flex-direction: row; align-items: baseline; gap: 0.2em;
}
.zg-logo-word {
  font-family: 'Satoshi', system-ui, sans-serif;
  font-weight: 900; font-size: 1.05rem;
  letter-spacing: -0.03em; line-height: 1.1;
  display: block; color: var(--text);
}
.zg-logo-dot { color: var(--orange); }

.topbar__divider {
  width: 1px; height: 18px;
  background: var(--border-hover); opacity: 0.6;
}
.topbar__label {
  font-size: 13px; font-weight: 500;
  color: var(--text-muted); letter-spacing: -0.01em;
}

.topbar__tabs { display: flex; gap: 2px; }

.tab-btn {
  background: none; border: none; color: var(--text-muted);
  font-size: 13px; font-weight: 500;
  padding: 7px 12px; border-radius: 6px;
  cursor: pointer; transition: all 150ms ease;
  display: flex; align-items: center; gap: 6px;
}
.tab-btn svg { opacity: 0.6; }
.tab-btn:hover { color: var(--text-secondary); background: var(--surface-2); }
.tab-btn:hover svg { opacity: 0.8; }
.tab-btn.active { color: var(--text); background: var(--surface-3); }
.tab-btn.active svg { opacity: 1; stroke: var(--orange); }

.topbar__right { display: flex; align-items: center; gap: 12px; }

.topbar__env {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 8px; border-radius: 4px;
  background: var(--green-bg); color: var(--green);
}

/* ── Layout ── */
.main { padding: 80px 32px 48px; max-width: 1200px; margin: 0 auto; }
.container { width: 100%; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.page-title {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 28px;
}
.page-title h2 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.page-subtitle { margin: 4px 0 0; font-size: 14px; color: var(--text-muted); }

/* ── Stats ── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex; align-items: flex-start; gap: 14px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.stat-card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-sm);
}
.stat-card--clickable { cursor: pointer; }
.stat-card--clickable:hover { border-color: var(--orange); }

.stat-card__icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-card__icon--blue { background: var(--blue-bg); color: var(--blue); }
.stat-card__icon--green { background: var(--green-bg); color: var(--green); }
.stat-card__icon--purple { background: var(--purple-bg); color: var(--purple); }
.stat-card__icon--orange { background: var(--orange-bg); color: var(--orange); }

.stat-card__body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat-card__value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.stat-card__label { font-size: 12px; font-weight: 500; color: var(--text-muted); }

/* ── Panels ── */
#payout-queue-panel { margin-bottom: 2rem; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.panel__header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.panel__title { margin: 0; font-size: 14px; font-weight: 600; }
.panel__body { padding: 4px 0; }
.panel__body--empty { padding: 32px 20px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ── Card Grid ── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: border-color 200ms ease, box-shadow 200ms ease;
}
.card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-sm);
}

.card__header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 14px;
}
.card__name { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
.card__badges { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.card__referral-count {
  font-size: 12px; color: var(--text-muted); font-weight: 500;
  background: var(--surface-3); padding: 2px 8px; border-radius: 4px;
  white-space: nowrap;
}

.card__contact {
  display: flex; flex-wrap: wrap; gap: 14px;
  font-size: 13px; color: var(--text-secondary);
  margin-bottom: 6px;
}
.card__contact-item { display: flex; align-items: center; gap: 5px; }
.card__contact-item svg { opacity: 0.5; flex-shrink: 0; }

.card__link-row {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 14px;
}
.card__link {
  font-size: 12px; color: var(--orange);
  font-family: "SF Mono", "Fira Code", monospace;
  background: var(--orange-bg); padding: 3px 10px;
  border-radius: 5px; letter-spacing: -0.01em;
}
.card__copy-btn {
  background: none; border: 1px solid var(--border);
  border-radius: 5px; padding: 3px 7px;
  color: var(--text-muted); cursor: pointer;
  display: flex; align-items: center;
  transition: all 150ms ease;
}
.card__copy-btn:hover { color: var(--text); border-color: var(--border-hover); }

.card__money-row {
  display: flex; gap: 20px;
  font-size: 13px; color: var(--text-muted);
  padding: 12px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}
.card__money-item strong { font-weight: 600; }
.card__money-item .earned { color: var(--text); }
.card__money-item .paid { color: var(--green); }
.card__money-item .owed { color: var(--amber); }

.card__footer {
  display: flex; justify-content: space-between; align-items: center;
}
.card__joined { font-size: 12px; color: var(--text-dim); }
.card__actions { display: flex; gap: 6px; }

/* ── Buttons ── */
.btn {
  border: none; border-radius: 7px;
  font-size: 13px; font-weight: 600;
  padding: 8px 16px; cursor: pointer;
  transition: all 150ms ease;
  display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn--primary {
  background: var(--orange); color: #fff;
  box-shadow: 0 1px 3px rgba(241,88,34,0.3);
}
.btn--primary:hover:not(:disabled) { background: var(--orange-light); box-shadow: 0 2px 8px rgba(241,88,34,0.35); }

.btn--secondary { background: var(--surface-2); color: var(--text-secondary); border: 1px solid var(--border); }
.btn--secondary:hover:not(:disabled) { color: var(--text); border-color: var(--border-hover); background: var(--surface-3); }

.btn--ghost { background: none; color: var(--text-muted); padding: 8px 12px; }
.btn--ghost:hover:not(:disabled) { color: var(--text); background: var(--surface-2); }

.btn--danger { background: var(--red-bg); color: var(--red); }
.btn--danger:hover:not(:disabled) { background: var(--red); color: #fff; }

.btn--sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn--has-icon svg { flex-shrink: 0; }

/* ── Badges ── */
.badge {
  display: inline-flex; align-items: center;
  font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 5px;
  line-height: 1.5; letter-spacing: 0.01em;
}
.badge--active { background: var(--green-bg); color: var(--green); }
.badge--inactive { background: var(--surface-3); color: var(--text-dim); }
.badge--self-signup { background: var(--blue-bg); color: var(--blue); }
.badge--form { background: var(--amber-bg); color: var(--amber); }
.badge--admin-invite { background: var(--purple-bg); color: var(--purple); }

.badge--submitted { background: var(--blue-bg); color: var(--blue); }
.badge--contacted { background: var(--amber-bg); color: var(--amber); }
.badge--payout_owed { background: var(--orange-bg); color: var(--orange); }
.badge--paid { background: rgba(34,197,94,0.15); color: #4ade80; }
.badge--expired { background: var(--surface-3); color: var(--text-dim); }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  padding: 20px;
  animation: overlay-in 150ms ease;
}

@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-height: 85vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modal-in 200ms ease;
}
.modal--xs { max-width: 400px; }
.modal--sm { max-width: 460px; }
.modal--wide { max-width: 680px; }

.modal__header { padding: 24px 24px 0; }
.modal__title { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.modal__desc { font-size: 13px; color: var(--text-muted); margin: 6px 0 0; }
.modal__body { padding: 20px 24px 0; }
.modal__actions {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 20px 24px 24px;
}
.modal__confirm-msg { padding: 0 24px; margin: 8px 0 0; color: var(--text-secondary); font-size: 14px; line-height: 1.5; }

/* ── Form ── */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; font-size: 13px; font-weight: 600;
  margin-bottom: 6px; color: var(--text-secondary);
}
.required { color: var(--orange); }

.input {
  width: 100%; padding: 10px 14px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text);
  font-size: 14px; outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.input::placeholder { color: var(--text-dim); }
.input:focus { border-color: var(--orange); box-shadow: 0 0 0 3px var(--orange-bg); }

/* ── Toast ── */
#toast-container {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column-reverse; gap: 8px;
  z-index: 300;
  pointer-events: none;
}

.toast {
  padding: 12px 18px; border-radius: 10px;
  font-size: 13px; font-weight: 500;
  display: flex; align-items: center; gap: 8px;
  box-shadow: var(--shadow-md);
  animation: toast-in 250ms ease;
  pointer-events: auto;
  max-width: 360px;
}
.toast--success { background: #065f46; color: #d1fae5; border: 1px solid #047857; }
.toast--error { background: #7f1d1d; color: #fecaca; border: 1px solid #991b1b; }
.toast--info { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }

.toast__icon { flex-shrink: 0; }
.toast--success .toast__icon::before { content: "\2713"; }
.toast--error .toast__icon::before { content: "\2717"; }
.toast--info .toast__icon::before { content: "\2139"; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: none; }
}
@keyframes toast-out {
  from { opacity: 1; transform: none; }
  to { opacity: 0; transform: translateX(20px); }
}

/* ── Loading / Empty ── */
.loading { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.loading p { margin: 12px 0 0; font-size: 13px; }

.spinner {
  width: 28px; height: 28px;
  border: 2.5px solid var(--surface-3);
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin: 0 auto;
}
.spinner--sm { width: 16px; height: 16px; border-width: 2px; display: inline-block; margin: 0; vertical-align: middle; }

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

.loading-inline {
  display: flex; align-items: center; gap: 10px;
  padding: 24px 20px; color: var(--text-muted); font-size: 13px;
}

.empty-state {
  text-align: center; padding: 64px 20px;
}
.empty-state__icon {
  width: 64px; height: 64px;
  border-radius: 16px; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px; color: var(--text-dim);
}
.empty-state__title { font-size: 15px; font-weight: 600; margin: 0 0 4px; }
.empty-state__desc { font-size: 13px; color: var(--text-muted); margin: 0; }

.muted { color: var(--text-muted); }

/* ── Recent Referrals List ── */
/* ── Payout Queue ── */
.panel__header--queue .panel__title {
  display: flex; align-items: center; gap: 8px;
}
.panel__header--queue .panel__title svg { color: var(--orange); }
.panel__count {
  font-size: 11px; font-weight: 700;
  background: var(--orange-bg); color: var(--orange);
  padding: 1px 8px; border-radius: 10px;
  min-width: 22px; text-align: center;
}
.panel__count--zero { background: var(--surface-3); color: var(--text-dim); }

.queue-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; gap: 12px;
  border-bottom: 1px solid var(--border);
  transition: background 100ms ease;
}
.queue-item:last-child { border-bottom: none; }
.queue-item:hover { background: var(--surface-hover); }

.queue-item__info { flex: 1; min-width: 0; }
.queue-item__biz { font-size: 14px; font-weight: 600; }
.queue-item__meta {
  display: flex; align-items: center; gap: 10px;
  font-size: 12px; color: var(--text-muted); margin-top: 2px;
}
.queue-item__dot { color: var(--text-dim); }
.queue-item__action { flex-shrink: 0; }

/* ── Recent Referrals List ── */
.recent-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  transition: background 100ms ease;
  cursor: pointer;
}
.recent-item:last-child { border-bottom: none; }
.recent-item:hover { background: var(--surface-hover); }

.recent-item__left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.recent-item__biz { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-item__referrer { color: var(--text-muted); white-space: nowrap; }
.recent-item__right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.recent-item__date { font-size: 12px; color: var(--text-dim); white-space: nowrap; }

/* ── Detail Modal Sections ── */
.detail-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 24px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.detail-header__close {
  background: none; border: none; color: var(--text-muted);
  font-size: 20px; cursor: pointer; padding: 4px 8px; border-radius: 6px;
  transition: all 100ms ease; line-height: 1;
}
.detail-header__close:hover { color: var(--text); background: var(--surface-3); }

.detail-profile {
  padding: 20px 24px;
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px 24px;
  font-size: 13px;
}
.detail-field { display: flex; flex-direction: column; gap: 2px; }
.detail-field__label { font-size: 11px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.detail-field__value { color: var(--text-secondary); }

.detail-stats-row {
  display: flex; gap: 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.detail-stat {
  flex: 1; padding: 14px 24px; text-align: center;
  border-right: 1px solid var(--border);
}
.detail-stat:last-child { border-right: none; }
.detail-stat__value { font-size: 20px; font-weight: 700; display: block; line-height: 1.2; }
.detail-stat__label { font-size: 11px; color: var(--text-muted); }

.detail-section {
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
}
.detail-section__title {
  font-size: 13px; font-weight: 700; margin-bottom: 12px;
  display: flex; align-items: center; gap: 8px;
}
.detail-section__count {
  font-size: 11px; font-weight: 600;
  background: var(--surface-3); padding: 1px 7px;
  border-radius: 4px; color: var(--text-muted);
}

.referral-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.referral-row:last-child { border-bottom: none; }

.payout-table {
  width: 100%; font-size: 13px; border-collapse: collapse;
}
.payout-table th {
  text-align: left; padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 11px; color: var(--text-dim); text-transform: uppercase;
  letter-spacing: 0.04em; font-weight: 600;
}
.payout-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.payout-table tr:last-child td { border-bottom: none; }

/* ── Payout Modal ── */
.payout-amount {
  font-size: 32px; font-weight: 800; letter-spacing: -0.02em;
  color: var(--green); text-align: center;
  padding: 8px 0 20px;
}

.method-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.method-btn {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 8px;
  font-size: 12px; font-weight: 600; color: var(--text-secondary);
  cursor: pointer; transition: all 150ms ease;
  text-align: center; white-space: nowrap;
}
.method-btn:hover {
  border-color: var(--border-hover); color: var(--text);
  background: var(--surface-2);
}
.method-btn.selected {
  border-color: var(--orange); color: var(--orange);
  background: var(--orange-bg);
  box-shadow: 0 0 0 1px var(--orange);
}

@media (max-width: 480px) {
  .method-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 3px; }

/* ── Responsive ── */
@media (max-width: 900px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .stats-row { grid-template-columns: 1fr; }
  .card-grid { grid-template-columns: 1fr; }
  .topbar { padding: 0 12px; }
  .topbar__tabs { display: none; }
  .topbar__divider, .topbar__label { display: none; }
  .main { padding: 72px 16px 24px; }
  .page-title { flex-direction: column; gap: 12px; }
  .detail-profile { grid-template-columns: 1fr; }
  .detail-stats-row { flex-wrap: wrap; }
  .detail-stat { min-width: 50%; }
}

/* ── Reports Tab ── */
.report-filters {
  display: flex; flex-wrap: wrap; gap: 12px;
  align-items: flex-end;
  margin-bottom: 16px;
}
.report-filter-group { display: flex; flex-direction: column; gap: 4px; }
.report-filter-group label {
  font-size: 11px; font-weight: 600; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.report-filter-group--grow { flex: 1; min-width: 160px; }
.report-filter-group--action { align-self: flex-end; }

.input--sm { padding: 7px 10px; font-size: 13px; }
select.input--sm { appearance: auto; }

.report-summary {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; color: var(--text-secondary);
  margin-bottom: 16px;
}
.report-summary__dot { color: var(--text-dim); }

.report-export-btn svg { flex-shrink: 0; }

.report-table-wrap { overflow-x: auto; }

.report-table { min-width: 640px; }
.report-table th { white-space: nowrap; }
.report-table td { vertical-align: middle; }
.report-table__empty { text-align: center; padding: 32px 20px; color: var(--text-muted); }
.report-table__no-data { text-align: center; padding: 32px 20px; color: var(--text-muted); font-size: 13px; }
