/* Referral dashboard — purple dark theme */

.referral-page-main {
  padding: 0 24px 72px;
  max-width: 1280px;
  margin: 0 auto;
}

.referral-hero {
  text-align: center;
  padding: 36px 0 28px;
}

.referral-hero h1 {
  font-size: clamp(28px, 4vw, 42px);
  font-weight: 800;
  margin: 8px 0 10px;
  letter-spacing: -0.02em;
}

.referral-hero-sub {
  font-size: 15px;
  color: var(--apex-muted);
  line-height: 1.6;
  max-width: 620px;
  margin: 0 auto;
}

/* ── Guest promo ── */
.ref-guest-promo {
  margin-top: 8px;
}

.ref-guest-card {
  position: relative;
  overflow: hidden;
  border-radius: var(--apex-radius-lg);
  border: 1px solid var(--apex-accent-border);
  background: linear-gradient(145deg, rgba(192, 132, 252, 0.14) 0%, var(--apex-bg-2) 42%, var(--apex-bg) 100%);
  padding: clamp(32px, 5vw, 56px);
  text-align: center;
  box-shadow: var(--apex-shadow-glow);
}

.ref-guest-card::before {
  content: '';
  position: absolute;
  inset: -40% auto auto -20%;
  width: 320px;
  height: 320px;
  background: radial-gradient(circle, var(--apex-glow-1), transparent 70%);
  pointer-events: none;
}

.ref-guest-icon {
  font-size: 48px;
  margin-bottom: 16px;
  filter: drop-shadow(0 0 24px var(--apex-accent-glow));
}

.ref-guest-card h2 {
  font-size: clamp(22px, 3vw, 30px);
  font-weight: 800;
  margin: 0 0 12px;
}

.ref-guest-card p {
  color: var(--apex-muted);
  font-size: 15px;
  line-height: 1.65;
  max-width: 520px;
  margin: 0 auto 24px;
}

.ref-guest-perks {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-bottom: 28px;
}

.ref-guest-perk {
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--apex-accent-light);
  background: var(--apex-accent-soft);
  border: 1px solid var(--apex-accent-border);
}

/* ── Dashboard grid ── */
.ref-dashboard {
  margin-top: 4px;
  position: relative;
}

.ref-dashboard-loading,
.ref-dashboard-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 48px 24px;
  text-align: center;
  border-radius: var(--apex-radius-lg);
  border: 1px solid var(--apex-border);
  background: var(--apex-bg-2);
  margin-bottom: 20px;
}

.ref-dashboard-loading[hidden],
.ref-dashboard-error[hidden] {
  display: none !important;
}

.ref-dashboard-spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid var(--apex-border);
  border-top-color: var(--apex-accent);
  animation: ref-spin 0.8s linear infinite;
}

@keyframes ref-spin {
  to { transform: rotate(360deg); }
}

.ref-dashboard-error p {
  margin: 0;
  color: var(--apex-muted);
  font-size: 14px;
  max-width: 420px;
}

.ref-dashboard-grid.is-loading {
  opacity: 0.45;
  pointer-events: none;
}

.ref-dashboard-grid.is-hidden {
  display: none;
}

.ref-dashboard-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

@media (min-width: 1024px) {
  .ref-dashboard-grid {
    grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
    gap: 24px;
    align-items: start;
  }
}

.ref-dashboard-main,
.ref-dashboard-side {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

.ref-paywall {
  margin-bottom: 4px;
  padding: 16px 20px;
  border-radius: var(--apex-radius);
  border: 1px solid var(--apex-accent-border);
  background: var(--apex-bg-2);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.ref-paywall p {
  margin: 0;
  font-size: 14px;
  color: var(--apex-muted);
  flex: 1;
  min-width: 200px;
}

.ref-dashboard.ref-grace-blocked .ref-dashboard-grid {
  opacity: 0.42;
  pointer-events: none;
  user-select: none;
}

/* ── Metric cards ── */
.ref-metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

@media (min-width: 1024px) {
  .ref-metrics-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.ref-metric-card {
  background: var(--apex-bg-2);
  border: 1px solid var(--apex-border);
  border-radius: var(--apex-radius);
  padding: 16px 16px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-width: 0;
}

.ref-metric-card:hover {
  border-color: var(--apex-accent-border);
  box-shadow: 0 0 0 1px var(--apex-accent-border);
}

.ref-metric-card--primary {
  border-color: var(--apex-accent-border);
  background: linear-gradient(160deg, rgba(192, 132, 252, 0.1), var(--apex-bg-2));
}

.ref-metric-label {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  min-height: 34px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--apex-muted);
  margin-bottom: 8px;
  line-height: 1.35;
}

.ref-metric-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  margin-top: 1px;
  opacity: 0.85;
  color: var(--apex-accent);
}

.ref-metric-value {
  font-size: clamp(20px, 2.5vw, 26px);
  font-weight: 800;
  color: var(--apex-text);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  min-height: 1.2em;
}

.ref-metric-card--primary .ref-metric-value,
.ref-metric-value--balance {
  font-size: clamp(18px, 1.75vw, 24px);
  color: var(--apex-accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.ref-metric-foot {
  margin-top: 10px;
  font-size: 12px;
  color: var(--apex-muted);
}

.ref-metric-actions {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ref-btn-withdraw {
  font-size: 12px;
  padding: 8px 14px;
}

/* ── Chart ── */
.ref-chart-card,
.ref-history-card,
.ref-side-card {
  background: var(--apex-bg-2);
  border: 1px solid var(--apex-border);
  border-radius: var(--apex-radius-lg);
  padding: 20px;
}

.ref-card-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--apex-muted);
  margin: 0 0 16px;
}

.ref-chart-wrap {
  position: relative;
  height: 200px;
  border-radius: var(--apex-radius-sm);
  overflow: hidden;
  background: linear-gradient(180deg, var(--apex-surface-inset) 0%, transparent 100%);
}

.ref-chart-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  margin: 0;
  font-size: 13px;
  color: var(--apex-muted);
}

.ref-chart-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.ref-chart-legend {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  font-size: 11px;
  color: var(--apex-muted);
}

.ref-chart-legend span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ref-chart-legend i {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

.ref-chart-legend .ref-legend-earn { background: var(--apex-accent); }
.ref-chart-legend .ref-legend-click { background: rgba(139, 130, 160, 0.5); }

/* ── History table ── */
.ref-history-table-wrap {
  overflow-x: auto;
}

.ref-history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.ref-history-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--apex-muted);
  border-bottom: 1px solid var(--apex-border);
}

.ref-history-table td {
  padding: 12px;
  border-bottom: 1px solid rgba(46, 38, 64, 0.6);
  vertical-align: middle;
}

.ref-history-table tr:last-child td {
  border-bottom: none;
}

.ref-history-table tr:hover td {
  background: var(--apex-surface-subtle);
}

.ref-h-amount-cell {
  font-weight: 700;
  color: var(--apex-success);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ref-status-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.ref-status-badge--paid {
  color: #6ee7b7;
  background: rgba(52, 211, 153, 0.12);
  border: 1px solid rgba(52, 211, 153, 0.35);
}

.ref-status-badge--pending {
  color: #fcd34d;
  background: rgba(252, 211, 77, 0.1);
  border: 1px solid rgba(252, 211, 77, 0.35);
}

.ref-history-empty {
  text-align: center;
  padding: 28px 16px;
  color: var(--apex-muted);
  font-size: 13px;
}

/* ── Sidebar ── */
.ref-side-card h3 {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 6px;
}

.ref-side-desc {
  font-size: 13px;
  color: var(--apex-muted);
  margin: 0 0 16px;
  line-height: 1.5;
}

.ref-wallet-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--apex-muted);
  margin-bottom: 8px;
}

.ref-wallet-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--apex-radius-sm);
  border: 1px solid var(--apex-border);
  background: var(--apex-bg);
  color: var(--apex-text);
  font-family: ui-monospace, monospace;
  font-size: 13px;
  margin-bottom: 10px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.ref-wallet-input:focus {
  outline: none;
  border-color: var(--apex-accent);
  box-shadow: 0 0 0 3px var(--apex-accent-soft);
}

.ref-wallet-input.ref-wallet-input--invalid,
.ref-wallet-input.ref-wallet-input--invalid:focus {
  border-color: #f87171;
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.18);
}

.ref-wallet-error {
  margin: -4px 0 10px;
  font-size: 12px;
  line-height: 1.4;
  color: #f87171;
}

.ref-wallet-bound {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: var(--apex-radius-sm);
  border: 1px solid rgba(34, 197, 94, 0.35);
  background: rgba(34, 197, 94, 0.1);
  color: #4ade80;
  font-size: 13px;
  font-weight: 600;
}

.ref-wallet-bound[hidden] {
  display: none !important;
}

.ref-wallet-bound svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.ref-wallet-input.ref-wallet-input--readonly {
  opacity: 0.85;
  cursor: default;
  background: var(--apex-surface-inset);
}

.ref-wallet-input::placeholder {
  color: var(--apex-muted);
  opacity: 0.7;
}

.ref-link-box {
  margin: 12px 0;
  padding: 12px 14px;
  border-radius: var(--apex-radius-sm);
  border: 1px dashed var(--apex-accent-border);
  background: var(--apex-surface-inset);
  font-family: ui-monospace, monospace;
  font-size: 12px;
  color: var(--apex-accent-light);
  word-break: break-all;
  line-height: 1.45;
}

.ref-side-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ref-btn-save {
  width: 100%;
}

.ref-btn-copy {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.2s, border-color 0.2s, color 0.2s, opacity 0.2s;
}

.ref-btn-copy.ref-btn-copy--disabled,
.ref-btn-copy:disabled:not(.is-copied) {
  opacity: 0.5;
  cursor: not-allowed;
}

.ref-btn-copy.is-copied {
  background: #22c55e !important;
  border-color: #22c55e !important;
  color: #fff !important;
  opacity: 1 !important;
  cursor: default;
}

.ref-withdraw-wrap {
  position: relative;
  display: inline-flex;
  max-width: 100%;
}

.ref-withdraw-wrap--zero .ref-btn-withdraw {
  opacity: 0.55;
  cursor: not-allowed;
}

.ref-withdraw-tip {
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  z-index: 5;
  min-width: 220px;
  max-width: 280px;
  margin: 0;
  padding: 8px 12px;
  border-radius: var(--apex-radius-sm);
  border: 1px solid var(--apex-border);
  background: var(--apex-bg-3);
  color: var(--apex-muted);
  font-size: 12px;
  line-height: 1.45;
  box-shadow: var(--apex-shadow);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 0.2s, visibility 0.2s, transform 0.2s;
}

.ref-withdraw-wrap--zero:hover .ref-withdraw-tip,
.ref-withdraw-wrap--zero:focus-within .ref-withdraw-tip,
.ref-withdraw-wrap--wait:hover .ref-withdraw-tip,
.ref-withdraw-wrap--wait:focus-within .ref-withdraw-tip {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.ref-withdraw-wrap--wait .ref-btn-withdraw {
  opacity: 0.55;
  cursor: not-allowed;
}

.ref-faq .apex-faq-question {
  cursor: pointer;
}

.ref-faq-chevron {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  color: var(--apex-accent);
  transition: transform 0.25s ease;
}

.ref-faq-chevron svg {
  width: 18px;
  height: 18px;
}

.apex-faq-item.is-open .ref-faq-chevron {
  transform: rotate(180deg);
}

.ref-btn-copy svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* ── Leaderboard widget ── */
.ref-leaderboard-card h3,
.ref-promo-card h3 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--apex-muted);
  margin: 0 0 14px;
}

.ref-leaderboard {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ref-leaderboard-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--apex-radius-sm);
  border: 1px solid var(--apex-border);
  background: var(--apex-bg);
  font-size: 13px;
}

.ref-leaderboard-empty {
  padding: 12px;
  text-align: center;
  font-size: 13px;
  color: var(--apex-muted);
  border: 1px dashed var(--apex-border);
  border-radius: var(--apex-radius-sm);
}

.ref-leaderboard-rank {
  font-size: 16px;
  line-height: 1;
}

.ref-leaderboard-name {
  font-weight: 600;
  color: var(--apex-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ref-leaderboard-amount {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--apex-accent-light);
  white-space: nowrap;
  font-size: 12px;
}

/* ── Promo materials widget ── */
.ref-promo-card {
  position: relative;
  overflow: hidden;
  border-color: var(--apex-accent-border);
  background: linear-gradient(155deg, rgba(192, 132, 252, 0.12) 0%, var(--apex-bg-2) 48%, var(--apex-bg) 100%);
}

.ref-promo-card::before {
  content: '';
  position: absolute;
  inset: -40% -20% auto auto;
  width: 160px;
  height: 160px;
  background: radial-gradient(circle, var(--apex-glow-1), transparent 70%);
  pointer-events: none;
  opacity: 0.55;
}

.ref-promo-card h3 {
  position: relative;
  color: var(--apex-accent-light);
}

.ref-promo-desc {
  position: relative;
  margin: 0 0 14px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--apex-muted);
}

.ref-promo-soon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--apex-radius-sm);
  border: 1px dashed var(--apex-accent-border);
  background: rgba(192, 132, 252, 0.08);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--apex-accent-light);
  text-align: center;
}

/* ── How-to timeline ── */
.ref-howto-timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.ref-howto-item {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 12px;
  padding: 14px 0;
  position: relative;
}

.ref-howto-item:not(:last-child)::after {
  content: '';
  position: absolute;
  left: 17px;
  top: 44px;
  bottom: -2px;
  width: 2px;
  background: linear-gradient(180deg, var(--apex-accent-border), transparent);
}

.ref-howto-marker {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--apex-accent-soft);
  border: 1px solid var(--apex-accent-border);
  color: var(--apex-accent);
  flex-shrink: 0;
}

.ref-howto-marker svg {
  width: 18px;
  height: 18px;
}

.ref-howto-item.ref-howto-done .ref-howto-marker {
  background: var(--apex-accent);
  color: var(--apex-btn-on-accent);
  border-color: transparent;
}

.ref-howto-body h4 {
  font-size: 14px;
  font-weight: 700;
  margin: 0 0 4px;
}

.ref-howto-body p {
  font-size: 12px;
  color: var(--apex-muted);
  margin: 0;
  line-height: 1.5;
}

.ref-commission-note {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: var(--apex-radius-sm);
  background: var(--apex-surface-inset);
  border: 1px solid var(--apex-border);
  font-size: 12px;
  color: var(--apex-muted);
  line-height: 1.5;
}

.ref-commission-note strong {
  color: var(--apex-accent-light);
}

/* Toast — reuse position */
.ref-toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  padding: 12px 20px;
  border-radius: 999px;
  background: var(--apex-bg-3);
  border: 1px solid var(--apex-accent-border);
  color: var(--apex-text);
  font-size: 13px;
  font-weight: 600;
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  box-shadow: var(--apex-shadow-glow);
}

.ref-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── How it works (page sections) ── */
.ref-how-section,
.ref-faq-section {
  padding: clamp(48px, 6vw, 64px) 0;
}

.ref-section-head {
  text-align: center;
  max-width: 640px;
  margin: 0 auto 36px;
}

.ref-section-head h2 {
  font-size: clamp(22px, 3vw, 30px);
  font-weight: 800;
  margin: 0 0 10px;
  letter-spacing: -0.02em;
}

.ref-section-sub {
  margin: 0;
  font-size: 15px;
  line-height: 1.65;
  color: var(--apex-muted);
}

.ref-how-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-items: stretch;
}

@media (min-width: 768px) {
  .ref-how-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
  }
}

.ref-step-card {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 28px 24px 26px;
  border-radius: var(--apex-radius-lg);
  border: 1px solid var(--apex-border);
  background: linear-gradient(160deg, rgba(192, 132, 252, 0.08) 0%, var(--apex-bg-2) 55%, var(--apex-bg) 100%);
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}

.ref-step-card-inner {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  flex: 1;
  position: relative;
  z-index: 1;
  min-height: 0;
}

.ref-step-card:hover {
  border-color: var(--apex-accent-border);
  box-shadow: 0 0 32px rgba(192, 132, 252, 0.12);
  transform: translateY(-2px);
}

.ref-step-card::before {
  content: '';
  position: absolute;
  inset: auto -30% -50% auto;
  width: 180px;
  height: 180px;
  background: radial-gradient(circle, var(--apex-glow-1), transparent 70%);
  pointer-events: none;
  opacity: 0.6;
}

.ref-step-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  margin: 0 0 14px;
  border-radius: 14px;
  color: var(--apex-accent-light);
  background: var(--apex-accent-soft);
  border: 1px solid var(--apex-accent-border);
  box-shadow: 0 0 20px rgba(192, 132, 252, 0.15);
  flex-shrink: 0;
}

.ref-step-icon svg {
  width: 24px;
  height: 24px;
}

.ref-step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin: 0 0 12px;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--apex-accent-light);
  background: var(--apex-bg-3);
  border: 2px solid var(--apex-accent-border);
  flex-shrink: 0;
}

.ref-step-card h3 {
  font-size: 17px;
  font-weight: 700;
  margin: 0 0 10px;
  line-height: 1.3;
}

.ref-step-card p {
  margin: 0;
  font-size: 14px;
  line-height: 1.65;
  color: var(--apex-muted);
  flex: 1;
}

/* ── FAQ block ── */
.ref-faq {
  max-width: 760px;
  margin: 0 auto;
}

.ref-faq .apex-faq-item {
  border-left: 3px solid transparent;
  transition: border-color 0.2s;
}

.ref-faq .apex-faq-item.is-open {
  border-left-color: var(--apex-accent);
}

@media (max-width: 639px) {
  .ref-paywall {
    flex-direction: column;
    align-items: stretch;
  }
}
