:root {
  --bg: #0f1117;
  --bg2: #1a1d27;
  --bg3: #222636;
  --border: #2e3250;
  --accent: #6c63ff;
  --accent2: #4ade80;
  --danger: #f87171;
  --warning: #fbbf24;
  --text: #e8eaf6;
  --text2: #8b90b8;
  --text3: #5a5f80;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --transition: 0.18s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Sidebar ────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-logo {
  padding: 0 20px 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.sidebar-logo .logo-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
}
.sidebar-logo .logo-sub {
  font-size: 11px;
  color: var(--text3);
  margin-top: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text2);
  text-decoration: none;
  border-radius: 0;
  transition: var(--transition);
  font-size: 13.5px;
  font-weight: 500;
  position: relative;
}
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active {
  color: var(--accent);
  background: rgba(108,99,255,0.12);
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}
.nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-bottom {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}
.btn-logout {
  width: 100%;
  padding: 8px 12px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  transition: var(--transition);
  text-align: left;
  display: flex; align-items: center; gap: 8px;
}
.btn-logout:hover { background: var(--bg3); color: var(--danger); border-color: var(--danger); }

/* ── Main content ───────────────────────────── */
.main {
  margin-left: 220px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  padding: 20px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.page-title { font-size: 20px; font-weight: 700; }
.page-subtitle { font-size: 13px; color: var(--text2); margin-top: 2px; }

.content { padding: 28px 32px; }

/* ── Cards ──────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: var(--transition);
}
.stat-card:hover { border-color: var(--accent); }
.stat-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 6px;
}
.stat-label { font-size: 12px; color: var(--text2); }
.stat-value.green { color: var(--accent2); }
.stat-value.red { color: var(--danger); }
.stat-value.purple { color: var(--accent); }
.stat-value.yellow { color: var(--warning); }

/* ── Table ──────────────────────────────────── */
.table-wrap {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.table-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.table-title { font-weight: 600; font-size: 15px; flex: 1; }

table {
  width: 100%;
  border-collapse: collapse;
}
th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text3);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(108,99,255,0.04); }

.table-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text2);
  font-size: 12px;
}

/* ── Badges ─────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-green { background: rgba(74,222,128,0.15); color: var(--accent2); }
.badge-red { background: rgba(248,113,113,0.15); color: var(--danger); }
.badge-purple { background: rgba(108,99,255,0.15); color: var(--accent); }
.badge-yellow { background: rgba(251,191,36,0.15); color: var(--warning); }
.badge-gray { background: rgba(139,144,184,0.15); color: var(--text2); }

/* ── Inputs ─────────────────────────────────── */
.input, .select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
  transition: var(--transition);
}
.input:focus, .select:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text3); }
.select option { background: var(--bg2); }

.search-input {
  width: 260px;
  padding-left: 32px;
  position: relative;
}
.search-wrap { position: relative; }
.search-wrap::before {
  content: '🔍';
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  pointer-events: none;
}

/* ── Buttons ─────────────────────────────────── */
.btn {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #5b52e8; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text2);
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

/* ── Link cells ─────────────────────────────── */
.link-cell {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}
.link-cell:hover { text-decoration: underline; }

/* ── Pagination ─────────────────────────────── */
.pagination { display: flex; gap: 6px; align-items: center; }
.page-btn {
  padding: 4px 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  transition: var(--transition);
}
.page-btn:hover { border-color: var(--accent); color: var(--accent); }
.page-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Bot cards (overview) ───────────────────── */
.bot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.bot-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  transition: var(--transition);
  cursor: pointer;
}
.bot-card:hover { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.bot-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.bot-name { font-weight: 600; font-size: 14px; }
.bot-username { font-size: 11px; color: var(--text3); margin-top: 2px; }
.bot-stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.bot-stat { text-align: center; }
.bot-stat-val { font-size: 18px; font-weight: 700; }
.bot-stat-lbl { font-size: 10px; color: var(--text3); margin-top: 2px; }

/* ── User detail ───────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
  align-items: start;
}
.profile-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  position: sticky;
  top: 80px;
}
.avatar {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #9c63ff);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 700;
  margin-bottom: 16px;
  color: #fff;
}
.profile-name { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.profile-username { color: var(--text2); font-size: 13px; margin-bottom: 16px; }
.profile-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.profile-row:last-child { border-bottom: none; }
.profile-key { color: var(--text2); }
.profile-val { font-weight: 500; text-align: right; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab-btn {
  padding: 8px 16px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text2);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: -1px;
  transition: var(--transition);
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-btn:hover { color: var(--text); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Dialog ─────────────────────────────────── */
.dialog-list { display: flex; flex-direction: column; gap: 8px; }
.dialog-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  position: relative;
}
.dialog-item.user-msg { border-left: 3px solid var(--accent); }
.dialog-item.bot-msg { border-left: 3px solid var(--accent2); }
.dialog-item.btn-click { border-left: 3px solid var(--warning); }
.dialog-item.error { border-left: 3px solid var(--danger); }
.dialog-meta {
  display: flex;
  gap: 10px;
  margin-bottom: 4px;
  font-size: 11px;
  color: var(--text3);
}
.dialog-text { color: var(--text); word-break: break-word; }

/* ── Funnel step bar ────────────────────────── */
.funnel-step {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.funnel-step:last-child { border-bottom: none; }
.step-num {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--bg3);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  color: var(--text2);
  flex-shrink: 0;
}
.step-info { flex: 1; min-width: 0; }
.step-name { font-weight: 500; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step-condition { font-size: 11px; color: var(--text3); }
.step-bar-wrap { width: 120px; flex-shrink: 0; }
.step-bar {
  height: 6px;
  background: var(--bg3);
  border-radius: 3px;
  overflow: hidden;
}
.step-bar-fill { height: 100%; background: var(--accent); border-radius: 3px; }
.step-count { font-size: 12px; color: var(--text2); text-align: right; margin-top: 3px; }

/* ── Loading ─────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px;
  color: var(--text3);
  font-size: 13px;
  gap: 10px;
}
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty state ─────────────────────────────── */
.empty {
  text-align: center;
  padding: 60px;
  color: var(--text3);
}
.empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-text { font-size: 14px; }

/* ── Revenue ─────────────────────────────────── */
.revenue { color: var(--accent2); font-weight: 600; }

/* ── Scrollbar ───────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ── Responsive ──────────────────────────────── */
@media (max-width: 900px) {
  .sidebar { width: 60px; }
  .sidebar-logo, .nav-item span:last-child { display: none; }
  .main { margin-left: 60px; }
  .detail-grid { grid-template-columns: 1fr; }
  .content { padding: 20px 16px; }
  .topbar { padding: 16px; }
}

/* ── Chart container ─────────────────────────── */
.chart-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
}
.chart-title { font-weight: 600; margin-bottom: 16px; font-size: 14px; }
