/*
 * AffiliateHub — Main Stylesheet
 * Kredit: lautandigital.id
 * Versi: 1.0.0
 */

/* =====================================================
   CSS CUSTOM PROPERTIES
===================================================== */
:root {
  --color-primary:    #6366f1;
  --color-primary-dk: #4f46e5;
  --color-primary-lt: #e0e7ff;
  --color-success:    #22c55e;
  --color-warning:    #f59e0b;
  --color-danger:     #ef4444;
  --color-info:       #3b82f6;
  --color-purple:     #a855f7;

  --bg-body:       #f1f5f9;
  --bg-sidebar:    #0f172a;
  --bg-card:       #ffffff;
  --bg-topbar:     #ffffff;

  --text-primary:   #0f172a;
  --text-secondary: #64748b;
  --text-muted:     #94a3b8;
  --text-inverse:   #f8fafc;

  --border-color:   #e2e8f0;
  --border-radius:  0.5rem;
  --border-radius-lg: 0.75rem;
  --border-radius-xl: 1rem;

  --shadow-sm:  0 1px 2px rgba(0,0,0,.05);
  --shadow-md:  0 4px 6px -1px rgba(0,0,0,.08), 0 2px 4px -2px rgba(0,0,0,.05);
  --shadow-lg:  0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -4px rgba(0,0,0,.05);
  --shadow-xl:  0 20px 25px -5px rgba(0,0,0,.1), 0 8px 10px -6px rgba(0,0,0,.05);

  --sidebar-width:        260px;
  --sidebar-width-mobile: 280px;
  --topbar-height:        64px;

  --font-sans: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --transition: 0.2s ease;
}

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

html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

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

button { cursor: pointer; font-family: inherit; }

input, select, textarea { font-family: inherit; }

img { max-width: 100%; }

/* =====================================================
   LAYOUT
===================================================== */
.app-body { display: flex; min-height: 100vh; }

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

/* =====================================================
   SIDEBAR
===================================================== */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform var(--transition);
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.brand-icon {
  font-size: 1.5rem;
  color: var(--color-primary);
}

.brand-name {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-inverse);
  letter-spacing: -0.02em;
}

.sidebar-close {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  line-height: 1;
  padding: 0.25rem;
}

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

.nav-list { list-style: none; }

.nav-item { margin: 0.125rem 0.75rem; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.875rem;
  border-radius: var(--border-radius);
  color: rgba(255,255,255,.6);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
}

.nav-link:hover {
  background: rgba(255,255,255,.07);
  color: rgba(255,255,255,.9);
  text-decoration: none;
}

.nav-item.active .nav-link {
  background: var(--color-primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(99,102,241,.4);
}

.nav-icon { font-size: 1rem; flex-shrink: 0; }

.nav-divider {
  height: 1px;
  background: rgba(255,255,255,.08);
  margin: 0.75rem 1.5rem;
}

.sidebar-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid rgba(255,255,255,.08);
}

.sidebar-credit {
  font-size: 0.75rem;
  color: rgba(255,255,255,.35);
  text-align: center;
}

.sidebar-credit a { color: rgba(255,255,255,.5); }
.sidebar-credit a:hover { color: var(--color-primary); }

/* =====================================================
   TOPBAR
===================================================== */
.topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-height);
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.topbar-menu-btn {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  padding: 0.25rem;
}

.topbar-menu-btn span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 2px;
  transition: var(--transition);
}

.topbar-search {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-body);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 0 0.875rem;
  transition: border-color var(--transition);
}

.topbar-search:focus-within { border-color: var(--color-primary); }

.search-icon { color: var(--text-muted); font-size: 0.875rem; }

.search-input {
  border: none;
  background: none;
  outline: none;
  width: 240px;
  padding: 0.5rem 0;
  font-size: 0.875rem;
  color: var(--text-primary);
}

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

.topbar-btn {
  position: relative;
  background: none;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 0.5rem 0.625rem;
  display: flex;
  align-items: center;
  color: var(--text-secondary);
  transition: background var(--transition), border-color var(--transition);
}

.topbar-btn:hover { background: var(--bg-body); border-color: var(--color-primary); }

.notif-icon { font-size: 1rem; }

.notif-badge {
  position: absolute;
  top: -5px; right: -5px;
  background: var(--color-danger);
  color: #fff;
  font-size: 0.625rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

/* User Menu */
.user-menu {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  padding: 0.375rem 0.625rem;
  border-radius: var(--border-radius);
  border: 1px solid transparent;
  transition: background var(--transition), border-color var(--transition);
}

.user-menu:hover { background: var(--bg-body); border-color: var(--border-color); }

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-info { display: flex; flex-direction: column; }

.user-name { font-size: 0.8125rem; font-weight: 600; color: var(--text-primary); }

.user-role { font-size: 0.6875rem; color: var(--text-muted); }

.user-chevron { font-size: 0.625rem; color: var(--text-muted); }

.user-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 180px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  overflow: hidden;
}

.user-dropdown.show { display: block; }

.dropdown-item {
  display: block;
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  color: var(--text-primary);
  transition: background var(--transition);
}

.dropdown-item:hover { background: var(--bg-body); text-decoration: none; }

.dropdown-item--danger { color: var(--color-danger); }

.dropdown-divider { height: 1px; background: var(--border-color); margin: 0.25rem 0; }

/* =====================================================
   PAGE CONTENT
===================================================== */
.page-content { flex: 1; padding: 1.75rem 1.5rem; }

.page { display: none; }
.page.active { display: block; animation: fadeIn 0.2s ease; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.page-title {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.03em;
}

.page-subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

/* =====================================================
   BUTTONS
===================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5625rem 1.125rem;
  border-radius: var(--border-radius);
  font-size: 0.875rem;
  font-weight: 600;
  border: 1.5px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
  line-height: 1.4;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.btn-primary:hover {
  background: var(--color-primary-dk);
  border-color: var(--color-primary-dk);
  box-shadow: 0 4px 12px rgba(99,102,241,.3);
}

.btn-outline {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border-color);
}

.btn-outline:hover { background: var(--bg-body); border-color: var(--text-secondary); }

.btn-outline--danger { color: var(--color-danger); border-color: var(--color-danger); }
.btn-outline--danger:hover { background: #fff1f2; }

/* =====================================================
   STAT CARDS
===================================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--border-radius-lg);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  position: relative;
  overflow: hidden;
  transition: box-shadow var(--transition), transform var(--transition);
}

.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 4px;
  height: 100%;
}

.stat-card--blue::before  { background: var(--color-info); }
.stat-card--green::before { background: var(--color-success); }
.stat-card--orange::before{ background: var(--color-warning); }
.stat-card--purple::before{ background: var(--color-purple); }

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--border-radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.375rem;
  flex-shrink: 0;
}

.stat-card--blue   .stat-icon { background: #eff6ff; }
.stat-card--green  .stat-icon { background: #f0fdf4; }
.stat-card--orange .stat-icon { background: #fffbeb; }
.stat-card--purple .stat-icon { background: #faf5ff; }

.stat-info { flex: 1; }

.stat-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.stat-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

.stat-trend {
  position: absolute;
  top: 1rem; right: 1rem;
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 0.125rem 0.375rem;
  border-radius: 999px;
}

.stat-trend--up   { background: #dcfce7; color: #15803d; }
.stat-trend--down { background: #fee2e2; color: #b91c1c; }

/* =====================================================
   CHARTS
===================================================== */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.chart-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
}

.chart-legend {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.25rem;
}

.legend-dot--blue  { background: var(--color-info); }
.legend-dot--green { background: var(--color-success); }

.chart-canvas-wrapper {
  height: 200px;
  position: relative;
}

#perfChart { width: 100% !important; height: 100% !important; }

/* Donut Chart */
.donut-wrapper {
  position: relative;
  width: 160px;
  height: 160px;
  margin: 0 auto 1rem;
}

.donut-chart { transform: rotate(-90deg); }

.donut-bg {
  fill: none;
  stroke: #f1f5f9;
  stroke-width: 16;
}

.donut-seg {
  fill: none;
  stroke-width: 16;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.8s cubic-bezier(0.4,0,0.2,1);
}

.seg-1 { stroke: #6366f1; }
.seg-2 { stroke: #22c55e; }
.seg-3 { stroke: #f59e0b; }
.seg-4 { stroke: #a855f7; }

.donut-center {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.donut-total { display: block; font-size: 1.25rem; font-weight: 700; color: var(--text-primary); }
.donut-label { display: block; font-size: 0.625rem; color: var(--text-muted); margin-top: 0.125rem; }

.donut-legend { display: flex; flex-direction: column; gap: 0.5rem; }

.donut-legend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.donut-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 0.5rem;
}

.dot-1 { background: #6366f1; }
.dot-2 { background: #22c55e; }
.dot-3 { background: #f59e0b; }
.dot-4 { background: #a855f7; }

/* =====================================================
   TABLE CARD
===================================================== */
.table-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.table-title { font-size: 0.9375rem; font-weight: 600; color: var(--text-primary); }

.table-link {
  font-size: 0.8125rem;
  color: var(--color-primary);
  font-weight: 500;
}

.table-actions { display: flex; gap: 0.5rem; }

.table-responsive { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.data-table th {
  padding: 0.75rem 1.25rem;
  text-align: left;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: #f8fafc;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table td {
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tbody tr:hover { background: #f8fafc; }

.table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1.25rem;
  border-top: 1px solid var(--border-color);
  background: #fafafa;
}

.table-count { font-size: 0.8125rem; color: var(--text-muted); }

/* =====================================================
   PAGINATION
===================================================== */
.pagination { display: flex; align-items: center; gap: 0.25rem; }

.page-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 500;
  transition: all var(--transition);
}

.page-btn:hover:not(:disabled) { background: var(--color-primary-lt); color: var(--color-primary); border-color: var(--color-primary); }
.page-btn.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.page-ellipsis { color: var(--text-muted); padding: 0 0.25rem; }

/* =====================================================
   STATUS BADGES
===================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.1875rem 0.5rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }

.badge--active  { background: #dcfce7; color: #15803d; }
.badge--inactive{ background: #f1f5f9; color: #64748b; }
.badge--pending { background: #fef9c3; color: #a16207; }
.badge--success { background: #dcfce7; color: #15803d; }
.badge--failed  { background: #fee2e2; color: #b91c1c; }
.badge--process { background: #dbeafe; color: #1d4ed8; }

/* Tier badges */
.tier-badge {
  display: inline-block;
  padding: 0.1875rem 0.625rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.tier-badge--bronze { background: #fef3c7; color: #92400e; }
.tier-badge--silver { background: #f1f5f9; color: #475569; }
.tier-badge--gold   { background: #fef9c3; color: #b45309; }

/* =====================================================
   FILTER BAR
===================================================== */
.filter-bar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.filter-input, .filter-select {
  height: 40px;
  padding: 0 0.875rem;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  background: var(--bg-card);
  font-size: 0.875rem;
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition);
}

.filter-input:focus, .filter-select:focus { border-color: var(--color-primary); }

.filter-input { min-width: 220px; }

/* =====================================================
   AFFILIATE AVATAR
===================================================== */
.affiliate-cell {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.aff-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6875rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.aff-name { font-weight: 600; color: var(--text-primary); font-size: 0.875rem; }
.aff-email { font-size: 0.75rem; color: var(--text-muted); }

/* =====================================================
   ACTION BUTTONS (Table)
===================================================== */
.action-btns { display: flex; gap: 0.375rem; }

.action-btn {
  width: 28px; height: 28px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.action-btn:hover { background: var(--color-primary-lt); color: var(--color-primary); border-color: var(--color-primary); }
.action-btn--danger:hover { background: #fee2e2; color: var(--color-danger); border-color: var(--color-danger); }

/* =====================================================
   LINKS PAGE
===================================================== */
.links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}

.link-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition), transform var(--transition);
}

.link-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

.link-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.875rem;
}

.link-name { font-size: 0.9375rem; font-weight: 600; color: var(--text-primary); }
.link-created { font-size: 0.75rem; color: var(--text-muted); }

.link-url {
  display: block;
  background: var(--bg-body);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  color: var(--color-primary);
  margin-bottom: 0.875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.link-stats {
  display: flex;
  gap: 1rem;
}

.link-stat { display: flex; flex-direction: column; }
.link-stat-value { font-size: 1.125rem; font-weight: 700; color: var(--text-primary); }
.link-stat-label { font-size: 0.6875rem; color: var(--text-muted); }

/* =====================================================
   REPORTS PAGE
===================================================== */
.report-filters {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.date-range { display: flex; align-items: center; gap: 0.5rem; font-size: 0.875rem; color: var(--text-secondary); }

/* =====================================================
   PAYOUTS PAGE
===================================================== */
.payout-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.payout-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.payout-label { font-size: 0.8125rem; color: var(--text-secondary); }

.payout-value {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.payout-value--warning { color: var(--color-warning); }
.payout-value--success { color: var(--color-success); }
.payout-value--blue    { color: var(--color-info); }

.payout-count { font-size: 0.75rem; color: var(--text-muted); }

/* =====================================================
   SETTINGS PAGE
===================================================== */
.settings-layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 1.5rem;
  align-items: start;
}

.settings-nav {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  box-shadow: var(--shadow-sm);
}

.settings-tab {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.625rem 0.875rem;
  border: none;
  border-radius: var(--border-radius);
  background: none;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
}

.settings-tab:hover { background: var(--bg-body); color: var(--text-primary); }
.settings-tab.active { background: var(--color-primary-lt); color: var(--color-primary); font-weight: 600; }

.settings-body {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

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

.settings-section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

/* =====================================================
   FORM ELEMENTS
===================================================== */
.form-group { margin-bottom: 1.125rem; }

.form-group--inline { display: flex; flex-direction: column; gap: 0.25rem; }

.form-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.375rem;
}

.required { color: var(--color-danger); }

.form-input {
  width: 100%;
  height: 40px;
  padding: 0 0.875rem;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  background: var(--bg-card);
  font-size: 0.875rem;
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}

.form-input--sm { width: 120px; }

.form-textarea {
  height: auto;
  padding: 0.625rem 0.875rem;
  resize: vertical;
  min-height: 80px;
}

/* Toggle Switch */
.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #cbd5e1;
  border-radius: 24px;
  cursor: pointer;
  transition: background var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}

.toggle input:checked + .toggle-slider { background: var(--color-primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* Checkbox */
.checkbox-group { display: flex; flex-direction: column; gap: 0.5rem; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-primary);
  cursor: pointer;
}

/* Commission Tiers */
.commission-tiers { display: flex; flex-direction: column; gap: 1rem; margin-bottom: 1.25rem; }

.tier-row {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.875rem;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  background: var(--bg-body);
}

/* API Key */
.api-key-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.api-key-row .form-input { flex: 1; font-family: monospace; font-size: 0.8125rem; }

/* Notification rows */
.notif-list { display: flex; flex-direction: column; gap: 0; }

.notif-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border-color);
}

.notif-row:last-child { border-bottom: none; }

.notif-desc { font-size: 0.8125rem; color: var(--text-muted); margin-top: 0.125rem; }

/* Webhook */
.webhook-section { margin-top: 1.25rem; }
.webhook-section h4 { font-size: 0.875rem; font-weight: 600; margin-bottom: 0.5rem; }

/* =====================================================
   MODAL
===================================================== */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 300;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}

.modal-backdrop.show { display: flex; animation: fadeIn 0.15s ease; }

.modal {
  background: var(--bg-card);
  border-radius: var(--border-radius-xl);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  margin: 1rem;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.modal-title { font-size: 1.0625rem; font-weight: 700; color: var(--text-primary); }

.modal-close {
  background: none;
  border: none;
  font-size: 1.125rem;
  color: var(--text-muted);
  padding: 0.25rem;
  line-height: 1;
  transition: color var(--transition);
}

.modal-close:hover { color: var(--text-primary); }

.modal-body { padding: 1.25rem 1.5rem; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  background: #fafafa;
  border-radius: 0 0 var(--border-radius-xl) var(--border-radius-xl);
}

/* =====================================================
   TOAST NOTIFICATIONS
===================================================== */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1.125rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  min-width: 280px;
  max-width: 360px;
  animation: slideInRight 0.3s ease;
}

.toast--success { border-left: 4px solid var(--color-success); }
.toast--error   { border-left: 4px solid var(--color-danger); }
.toast--info    { border-left: 4px solid var(--color-info); }

.toast-icon { font-size: 1.125rem; flex-shrink: 0; }
.toast-msg  { flex: 1; color: var(--text-primary); }
.toast-close { color: var(--text-muted); background: none; border: none; font-size: 0.875rem; }

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: none; }
}

@keyframes slideOutRight {
  from { opacity: 1; transform: none; }
  to   { opacity: 0; transform: translateX(40px); }
}

/* =====================================================
   SIDEBAR OVERLAY (Mobile)
===================================================== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 99;
}

/* =====================================================
   FOOTER
===================================================== */
.app-footer {
  display: flex;
  justify-content: space-between;
  padding: 0.875rem 1.5rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-card);
}

.app-footer a { color: var(--color-primary); }

/* =====================================================
   SCROLLBAR CUSTOMIZATION
===================================================== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* =====================================================
   RESPONSIVE — TABLET (max 1024px)
===================================================== */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-row { grid-template-columns: 1fr; }
  .chart-card--wide { order: 1; }
  .payout-summary { grid-template-columns: 1fr; }
}

/* =====================================================
   RESPONSIVE — MOBILE (max 768px)
===================================================== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width-mobile);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-xl);
  }

  .sidebar-close { display: flex; }

  .sidebar-overlay.show { display: block; }

  .main-wrapper { margin-left: 0; }

  .topbar-menu-btn { display: flex; }

  .search-input { width: 140px; }

  .stats-grid { grid-template-columns: 1fr; }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .settings-layout { grid-template-columns: 1fr; }

  .settings-nav { flex-direction: row; overflow-x: auto; }

  .user-info { display: none; }
  .user-chevron { display: none; }

  .filter-bar { flex-direction: column; }
  .filter-input, .filter-select { width: 100%; }

  .table-footer { flex-direction: column; gap: 0.75rem; }

  .modal { margin: 0.75rem; }

  .report-filters { flex-direction: column; align-items: flex-start; }
}
