:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --emerald: #059669;
  --emerald-soft: #ecfdf5;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --purple: #7c3aed;
  --purple-soft: #f5f3ff;
  --rose: #e11d48;
  --rose-soft: #fff1f2;
  --sky: #0284c7;
  --sky-soft: #f0f9ff;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 25px -5px rgba(15, 23, 42, 0.08), 0 8px 10px -6px rgba(15, 23, 42, 0.04);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 14px;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }

/* Top Navbar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}
.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 18px;
  color: var(--text);
  text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 16px;
  font-weight: 800;
}
.brand-sub {
  font-size: 11px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 2px 7px;
  border-radius: 99px;
}
.nav-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.credit-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--emerald-soft);
  color: var(--emerald);
  border: 1px solid #a7f3d0;
  padding: 6px 12px;
  border-radius: 99px;
  font-weight: 700;
  font-size: 13px;
}
.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  padding: 6px 12px;
  border-radius: 99px;
  font-weight: 600;
  font-size: 13px;
}

/* Container */
.container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: 9px;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  font-family: inherit;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-emerald { background: var(--emerald); color: #fff; }
.btn-emerald:hover:not(:disabled) { background: #047857; }
.btn-outline { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-outline:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { background: var(--rose-soft); color: var(--rose); border-color: #fecdd3; }
.btn-danger:hover:not(:disabled) { background: #ffe4e6; }
.btn-purple { background: var(--purple); color: #fff; }
.btn-purple:hover:not(:disabled) { background: #6d28d9; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 7px; }
.btn-xs { padding: 4px 8px; font-size: 11.5px; border-radius: 6px; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.card-title { font-size: 16px; font-weight: 700; }
.muted { color: var(--muted); }

/* Auth Screen */
.auth-wrap {
  max-width: 960px;
  margin: 34px auto;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 28px;
  align-items: center;
}
.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 99px;
  margin-bottom: 14px;
}
.hero-title {
  font-size: 32px;
  line-height: 1.18;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 12px;
}
.hero-list {
  list-style: none;
  margin-top: 18px;
  display: grid;
  gap: 10px;
}
.hero-list li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
  color: #334155;
}
.hero-check {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: var(--emerald-soft);
  color: var(--emerald);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 12px;
  flex-shrink: 0;
  margin-top: 1px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 26px;
  box-shadow: var(--shadow-lg);
}
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface-2);
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 18px;
}
.auth-tab {
  border: none;
  background: transparent;
  padding: 8px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 13.5px;
  color: var(--muted);
  cursor: pointer;
}
.auth-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* Forms */
.form-group { margin-bottom: 13px; }
.form-label { display: block; font-weight: 600; font-size: 12.5px; margin-bottom: 5px; color: #334155; }
.input, .textarea, .select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
.textarea { min-height: 110px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Community Banner */
.community-banner {
  background: linear-gradient(135deg, #1e1b4b, #312e81 60%, #4f46e5);
  color: #fff;
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.community-banner h3 { font-size: 15.5px; font-weight: 700; margin-bottom: 3px; }
.community-banner p { font-size: 13px; color: #c7d2fe; }
.community-banner .btn { background: #fff; color: #312e81; font-weight: 700; }
.community-banner .btn:hover { background: #eef2ff; text-decoration: none; }

/* Main Tabs */
.mode-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}
.mode-tab {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 9px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.mode-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px 15px;
}
.kpi-label { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.kpi-val { font-size: 22px; font-weight: 800; margin-top: 3px; color: var(--text); }
.kpi-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

/* Ratio Bar */
.ratio-bar {
  height: 12px;
  border-radius: 99px;
  overflow: hidden;
  display: flex;
  background: var(--surface-2);
  margin: 10px 0 12px;
}
.ratio-seg { height: 100%; transition: width 0.3s ease; }
.seg-info { background: #0284c7; }
.seg-money { background: #059669; }
.seg-vs { background: #7c3aed; }
.seg-single { background: #d97706; }
.seg-others { background: #94a3b8; }

.legend-row { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: #334155; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 700;
}
.badge-info { background: var(--sky-soft); color: var(--sky); }
.badge-money { background: var(--emerald-soft); color: var(--emerald); }
.badge-vs { background: var(--purple-soft); color: var(--purple); }
.badge-single { background: var(--amber-soft); color: var(--amber); }
.badge-others { background: var(--surface-2); color: var(--muted); }
.badge-overlap { background: #fef3c7; color: #b45309; border: 1px solid #fcd34d; }
.badge-ad { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }

/* Category Filter Tabs */
.cat-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.cat-tab {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 700;
  color: #334155;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.cat-tab.active {
  background: var(--text);
  color: #fff;
  border-color: var(--text);
}
.cat-count {
  background: rgba(148, 163, 184, 0.22);
  padding: 1px 6px;
  border-radius: 99px;
  font-size: 11px;
}
.cat-tab.active .cat-count { background: rgba(255, 255, 255, 0.2); }

/* Cluster Chips */
.cluster-wrap { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 8px; }
.cluster-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: #334155;
}
.cluster-chip:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

/* Filter Bar */
.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 14px;
  background: var(--surface-2);
  padding: 10px 12px;
  border-radius: 10px;
}
.filter-bar .input { width: auto; flex: 1; min-width: 160px; padding: 7px 10px; font-size: 13px; }
.filter-bar .input-sm { width: 105px; flex: 0 0 auto; min-width: 90px; }

/* Table */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: 560px;
  overflow-y: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  text-align: left;
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  z-index: 2;
}
td {
  padding: 9px 12px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}
tr:hover td { background: #f8fafc; }
.kw-cell { font-weight: 600; color: var(--text); }
.url-cell { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--muted); }

/* Referral Box */
.ref-box {
  background: linear-gradient(135deg, #ecfdf5, #eef2ff);
  border: 1px solid #c7d2fe;
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.ref-link-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex: 1;
  min-width: 260px;
  max-width: 480px;
}

/* Alerts & Toast */
.alert {
  padding: 11px 14px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 14px;
}
.alert-error { background: var(--rose-soft); color: var(--rose); border: 1px solid #fecdd3; }
.alert-success { background: var(--emerald-soft); color: var(--emerald); border: 1px solid #a7f3d0; }
.alert-info { background: var(--primary-soft); color: var(--primary); border: 1px solid #c7d2fe; }

.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  background: #0f172a;
  color: #fff;
  padding: 11px 16px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  z-index: 999;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.2s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 820px) {
  .auth-wrap { grid-template-columns: 1fr; margin-top: 16px; }
  .hero-title { font-size: 25px; }
  .form-row { grid-template-columns: 1fr; }
}

.brand-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center top;
  border: 2px solid var(--primary);
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.25);
  flex-shrink: 0;
  background: var(--primary-soft);
}
