:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #232730;
  --border: #2e3340;
  --text: #e1e4eb;
  --text-dim: #8b90a0;
  --accent: #6c8aff;
  --accent-hover: #8ba3ff;
  --green: #34d399;
  --red: #f87171;
  --yellow: #fbbf24;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* Nav */
.nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  height: 56px;
  gap: 32px;
}
.nav-brand { font-weight: 700; font-size: 16px; color: var(--accent); }
.nav a { color: var(--text-dim); text-decoration: none; font-size: 14px; padding: 16px 0; border-bottom: 2px solid transparent; }
.nav a:hover, .nav a.active { color: var(--text); border-bottom-color: var(--accent); }

/* Layout */
.container { max-width: 1200px; margin: 0 auto; padding: 24px; }

/* Stat cards */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.stat-card .label { font-size: 12px; text-transform: uppercase; color: var(--text-dim); letter-spacing: 0.5px; margin-bottom: 4px; }
.stat-card .value { font-size: 28px; font-weight: 700; }
.stat-card .value.green { color: var(--green); }
.stat-card .value.red { color: var(--red); }

/* Tables */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
  overflow: hidden;
}
.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.panel-header h2 { font-size: 16px; font-weight: 600; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: left;
  padding: 10px 16px;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-dim);
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
tbody td { padding: 10px 16px; border-bottom: 1px solid var(--border); }
tbody tr:hover { background: var(--surface2); }
tbody tr:last-child td { border-bottom: none; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-sale { background: rgba(52,211,153,0.15); color: var(--green); }
.badge-refund { background: rgba(248,113,113,0.15); color: var(--red); }
.badge-completed { background: rgba(52,211,153,0.15); color: var(--green); }
.badge-processed { background: rgba(52,211,153,0.15); color: var(--green); }
.badge-duplicate { background: rgba(251,191,36,0.15); color: var(--yellow); }
.badge-failed { background: rgba(248,113,113,0.15); color: var(--red); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}
.btn:hover { background: var(--border); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: rgba(248,113,113,0.1); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.form-group input, .form-group select {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
}
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--accent); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 480px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
}
.modal h3 { margin-bottom: 16px; font-size: 18px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* Tabs */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.tab-btn {
  padding: 12px 20px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  font-family: var(--font);
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Pagination */
.pagination { display: flex; align-items: center; gap: 8px; padding: 12px 20px; justify-content: center; }
.pagination .info { font-size: 13px; color: var(--text-dim); }

/* Bar chart */
.bar-chart { padding: 20px; }
.bar-row { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.bar-label { width: 160px; font-size: 13px; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-fill { height: 24px; background: var(--accent); border-radius: 4px; min-width: 2px; transition: width 0.3s; }
.bar-value { font-size: 13px; color: var(--text-dim); min-width: 80px; }

/* Splits expandable */
.splits-row { display: none; }
.splits-row.active { display: table-row; }
.splits-row td { padding: 0 16px 10px 40px; background: var(--surface2); }
.splits-table { width: 100%; font-size: 13px; }
.splits-table td { padding: 4px 12px; border: none; }
.expand-btn { cursor: pointer; user-select: none; }

/* Payload viewer */
.payload-viewer {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  max-height: 400px;
  overflow: auto;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-all;
}

/* Filters */
.filters {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.filters input, .filters select {
  padding: 6px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
}
.filters label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; }

/* Utility */
.text-right { text-align: right; }
.text-dim { color: var(--text-dim); }
.mt-8 { margin-top: 8px; }
.mb-16 { margin-bottom: 16px; }
.mono { font-family: 'Courier New', monospace; font-size: 13px; }
.clickable { cursor: pointer; }
.inline-actions { display: flex; gap: 4px; }
.text-warning { color: var(--yellow); }
.row-warning td { border-left: 3px solid var(--yellow); }
.text-center { text-align: center; }
.py-12 { padding-top: 12px; padding-bottom: 12px; }

/* Dashboard Hero */
.dash-hero { text-align: center; padding: 40px 0 24px; }
.dash-title { font-size: 36px; font-weight: 700; color: var(--yellow); margin-bottom: 8px; }
.dash-subtitle { font-size: 15px; color: var(--text-dim); margin-bottom: 16px; }
.dash-divider { width: 80px; height: 3px; background: var(--accent); margin: 0 auto; border-radius: 2px; }

/* Stat card centered values */
.stat-card { text-align: center; }
.stat-card .value { color: var(--yellow); }
.stat-card .value.white { color: var(--text); }

/* Panel icon */
.panel-icon { margin-right: 6px; }

/* Top Products List */
.top-product-row {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  gap: 14px;
}
.top-product-row:last-child { border-bottom: none; }
.top-rank {
  font-size: 18px;
  font-weight: 700;
  min-width: 36px;
  text-align: center;
  color: var(--text-dim);
}
.top-rank.gold { color: #ffd700; }
.top-rank.silver { color: #c0c0c0; }
.top-rank.bronze { color: #cd7f32; }
.top-product-info { flex: 1; }
.top-product-id {
  display: inline-block;
  padding: 2px 10px;
  background: rgba(251,191,36,0.15);
  color: var(--yellow);
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 12px;
}
.top-product-assigned { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.top-product-assigned strong { color: var(--text); }
.top-product-stats { text-align: right; }
.top-product-revenue { font-size: 18px; font-weight: 700; color: var(--green); }
.top-product-sales { font-size: 12px; color: var(--text-dim); }

/* Partner Cards */
.partner-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.partner-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.partner-card-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 4px;
}
.partner-name { font-size: 18px; font-weight: 700; color: var(--yellow); }
.partner-balance { font-size: 22px; font-weight: 700; color: var(--green); }
.partner-calc { font-size: 13px; color: var(--text-dim); }
.partner-email { font-size: 13px; color: var(--text-dim); margin-bottom: 12px; }
.partner-products-label { font-size: 13px; color: var(--text-dim); margin-bottom: 8px; }
.partner-product-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; }
.partner-product-tag {
  display: inline-block;
  padding: 2px 8px;
  background: rgba(251,191,36,0.15);
  color: var(--yellow);
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 11px;
}
.partner-more { font-size: 12px; color: var(--text-dim); margin-bottom: 8px; }
.partner-actions { display: flex; gap: 8px; margin-top: 12px; border-top: 1px solid var(--border); padding-top: 12px; }
.partner-actions .btn { flex: 1; justify-content: center; }
.btn-reset { background: transparent; border-color: var(--red); color: var(--red); }
.btn-reset:hover { background: rgba(248,113,113,0.1); }
.btn-split { background: rgba(251,191,36,0.15); border-color: var(--yellow); color: var(--yellow); }
.btn-split:hover { background: rgba(251,191,36,0.25); }

/* Split info badge */
.partner-split-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 8px 12px;
  background: rgba(52,211,153,0.08);
  border: 1px solid rgba(52,211,153,0.2);
  border-radius: var(--radius);
}
.partner-split-badge {
  display: inline-block;
  padding: 2px 8px;
  background: rgba(52,211,153,0.15);
  color: var(--green);
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.partner-split-detail {
  font-size: 13px;
  color: var(--text);
}

/* Split form */
.split-form {
  margin-top: 12px;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.split-form-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--yellow);
  margin-bottom: 12px;
}
.split-form-row {
  margin-bottom: 10px;
}
.split-label {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-dim);
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.split-select {
  width: 100%;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
}
.split-pct-row {
  display: flex;
  gap: 10px;
}
.split-pct-col {
  flex: 1;
}
.split-pct-input {
  width: 100%;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
  text-align: center;
}
.split-pct-input:focus { outline: none; border-color: var(--yellow); }
.split-amount {
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--green);
  margin-top: 4px;
}
.split-form-buttons {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.split-form-buttons .btn { flex: 1; justify-content: center; }
.split-hint {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 6px;
}
.partner-split-section {
  margin-top: 12px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Balance History */
.balance-filters {
  display: flex;
  gap: 12px;
  align-items: center;
}
.balance-filters select {
  padding: 6px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
}
.check-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
}
.check-label input { accent-color: var(--accent); }

.balance-entry {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.balance-entry:last-child { border-bottom: none; }
.balance-entry-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 6px;
}
.balance-user { font-weight: 600; font-size: 15px; }
.balance-date { font-size: 13px; color: var(--text-dim); }
.balance-type {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--yellow);
  margin-bottom: 6px;
}
.balance-type-icon {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: var(--border);
}
.balance-product-tag {
  display: inline-block;
  padding: 2px 8px;
  background: rgba(251,191,36,0.15);
  color: var(--yellow);
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 11px;
  margin-left: 4px;
}
.balance-breakdown {
  display: inline-block;
  padding: 6px 12px;
  background: var(--surface2);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 4px;
}
.balance-amount-pill {
  display: inline-block;
  padding: 6px 14px;
  background: rgba(52,211,153,0.12);
  border: 1px solid rgba(52,211,153,0.3);
  border-radius: var(--radius);
  font-family: 'Courier New', monospace;
  font-size: 14px;
  font-weight: 600;
  color: var(--green);
}
.balance-amount-pill.negative {
  background: rgba(248,113,113,0.12);
  border-color: rgba(248,113,113,0.3);
  color: var(--red);
}

/* Panel danger */
.panel-danger { border-color: rgba(248,113,113,0.3); }

/* Webhook Logs */
.webhook-log-entry {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.webhook-log-entry:last-child { border-bottom: none; }
.webhook-log-info { flex: 1; }
.webhook-log-title { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.webhook-log-detail { font-size: 13px; color: var(--text-dim); }
.webhook-log-date { font-size: 12px; color: var(--text-dim); }
.badge-success { background: rgba(52,211,153,0.15); color: var(--green); }
.webhook-log-scroll { max-height: 360px; overflow-y: auto; }

/* Currency Selector */
.currency-selector {
  position: fixed;
  bottom: 16px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  z-index: 50;
}
.currency-selector select {
  padding: 4px 8px;
  background: var(--green);
  border: none;
  border-radius: 4px;
  color: #000;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
}

/* ===================== ADMIN PANEL ===================== */

/* Nav user section */
.nav-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
}
.nav-user-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: 4px;
  font-weight: 700;
  font-size: 13px;
  color: #fff;
}
.nav-signout {
  margin-left: 12px;
  color: var(--text-dim) !important;
  font-size: 13px;
  border-bottom: none !important;
}
.nav-signout:hover { color: var(--text) !important; }

/* Admin cards row */
.admin-cards-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

/* Admin card */
.admin-card {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.admin-card-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 20px;
}
.admin-card .form-group { margin-bottom: 16px; }
.admin-card .form-group input,
.admin-card .form-group select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
}
.admin-card .form-group input:focus,
.admin-card .form-group select:focus {
  outline: none;
  border-color: var(--yellow);
}

/* Admin checkbox */
.admin-checkbox {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 20px;
  cursor: pointer;
  line-height: 1.4;
}
.admin-checkbox input {
  accent-color: var(--yellow);
  margin-top: 2px;
}

/* Gold button */
.btn-gold {
  width: 100%;
  padding: 12px 20px;
  background: linear-gradient(135deg, #c5952a, #d4a832);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-gold:hover {
  background: linear-gradient(135deg, #d4a832, #e0b93e);
}

/* Remove button */
.btn-remove {
  width: 100%;
  padding: 12px 20px;
  background: transparent;
  border: 1px solid var(--red);
  border-radius: var(--radius);
  color: var(--red);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-remove:hover {
  background: rgba(248,113,113,0.1);
}

/* Fee row layout */
.admin-fee-row {
  grid-template-columns: 1.2fr 1fr;
}

/* Fee summary card */
.fee-summary-card {
  border: 1px solid var(--border) !important;
  border-top: 3px solid var(--accent) !important;
  border-right: 3px solid var(--red) !important;
  padding: 24px;
}
.fee-summary-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--yellow);
  margin-bottom: 20px;
}
.fee-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
}
.fee-summary-label {
  font-size: 15px;
  font-weight: 700;
  color: var(--red);
  font-family: 'Courier New', monospace;
}
.fee-summary-value {
  font-size: 15px;
  color: var(--text);
}
.fee-summary-updated {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 16px;
}

/* Gold table headers */
.th-gold {
  color: var(--yellow) !important;
}

/* User cell in table */
.user-cell-name {
  font-weight: 600;
  font-size: 14px;
}
.user-cell-email {
  font-size: 12px;
  color: var(--text-dim);
}

/* Reset balance link button */
.btn-reset-link {
  background: transparent !important;
  border: none !important;
  color: var(--red) !important;
  font-weight: 600;
  padding: 4px 8px !important;
}
.btn-reset-link:hover {
  text-decoration: underline;
  background: transparent !important;
}

/* Admin card wide */
.admin-card-wide {
  min-width: 0;
}

/* ===================== WEBHOOK LOGS ===================== */

/* Webhook entry card */
.wh-entry {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
}

/* Entry header */
.wh-entry-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.wh-id-badge {
  display: inline-block;
  padding: 4px 12px;
  background: rgba(251,191,36,0.15);
  color: var(--yellow);
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  font-weight: 600;
}
.wh-entry-date {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 6px;
}

/* Divider */
.wh-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* Summary line */
.wh-summary {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 16px;
}

/* Stats grid */
.wh-stats-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 12px;
}
.wh-stat-cell {
  padding: 12px 16px;
  border-right: 1px solid var(--border);
}
.wh-stat-cell:last-child {
  border-right: none;
}
.wh-stat-label {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-dim);
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.wh-stat-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--yellow);
  font-family: 'Courier New', monospace;
  word-break: break-all;
}

/* Raw webhook body button */
.wh-raw-btn {
  display: inline-block;
  padding: 6px 14px;
  background: rgba(52,211,153,0.15);
  border: 1px solid rgba(52,211,153,0.3);
  border-radius: 4px;
  color: var(--green);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  font-family: var(--font);
  transition: background 0.15s;
}
.wh-raw-btn:hover {
  background: rgba(52,211,153,0.25);
}

/* Raw body content */
.wh-raw-body {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 12px;
  max-height: 400px;
  overflow: auto;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text);
}
