/* ── Reset & Variables ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-base:        #080c14;
  --bg-surface:     #0d1117;
  --bg-card:        #111827;
  --bg-card-hover:  #161f30;
  --bg-input:       #1a2235;
  --border:         rgba(255,255,255,0.07);
  --border-focus:   rgba(99,102,241,0.5);

  /* Brand */
  --accent:         #6366f1;
  --accent-dim:     rgba(99,102,241,0.12);
  --accent-glow:    rgba(99,102,241,0.3);

  /* Colors */
  --green:          #10b981;
  --green-dim:      rgba(16,185,129,0.12);
  --green-glow:     rgba(16,185,129,0.3);
  --blue:           #3b82f6;
  --blue-dim:       rgba(59,130,246,0.12);
  --yellow:         #f59e0b;
  --yellow-dim:     rgba(245,158,11,0.12);
  --red:            #ef4444;
  --red-dim:        rgba(239,68,68,0.12);
  --purple:         #8b5cf6;
  --purple-dim:     rgba(139,92,246,0.12);

  /* Text */
  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:     #475569;

  /* Layout */
  --sidebar-w:      250px;
  --radius:         12px;
  --radius-sm:      8px;
  --transition:     0.2s ease;
  --shadow:         0 4px 24px rgba(0,0,0,0.5);
}

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  overflow: hidden;
}

body { display: flex; }

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  transition: width 0.25s ease, transform 0.25s ease;
}

.sidebar.collapsed { width: 0; overflow: hidden; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand-icon-wrap {
  width: 36px; height: 36px;
  background: var(--accent-dim);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  border: 1px solid var(--accent-glow);
}

.brand-name {
  font-size: 14px;
  font-weight: 800;
  color: var(--text-primary);
  display: block;
  white-space: nowrap;
  background: linear-gradient(135deg, #f1f5f9, #94a3b8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.brand-sub {
  font-size: 10px;
  color: var(--text-muted);
  display: block;
  margin-top: -2px;
  white-space: nowrap;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 12px 10px 6px;
  white-space: nowrap;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  font-size: 13px;
  transition: all var(--transition);
  margin-bottom: 1px;
  cursor: pointer;
  white-space: nowrap;
}
.nav-item:hover { background: rgba(255,255,255,0.05); color: var(--text-primary); }
.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(99,102,241,0.2);
}
.nav-item svg { flex-shrink: 0; }

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.api-key-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
.api-key-value { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--text-secondary); word-break: break-all; }

/* ── Main ────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  min-width: 0;
}

/* ── Topbar ──────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
  gap: 16px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.sidebar-toggle {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}
.sidebar-toggle:hover { color: var(--text-primary); border-color: var(--text-muted); }

.page-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}
.page-breadcrumb { font-size: 11px; color: var(--text-muted); }

.topbar-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.api-key-input-group { display: flex; gap: 6px; }
.api-key-input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  width: 200px;
  outline: none;
  transition: border-color var(--transition);
}
.api-key-input:focus { border-color: var(--border-focus); }

.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-card);
  border-radius: 20px;
  border: 1px solid var(--border);
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background var(--transition);
}
.status-dot.connected { background: var(--green); box-shadow: 0 0 8px var(--green-glow); animation: pulse 2s infinite; }
.status-text { font-size: 12px; font-weight: 500; color: var(--text-secondary); white-space: nowrap; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes shimmer {
  0% { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}

/* ── Content Sections ────────────────────────────────────────── */
.content-section {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}
.content-section.active {
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: fadeInUp 0.25s ease;
}

/* ── Stats Grid ──────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-2px); border-color: rgba(255,255,255,0.12); box-shadow: 0 8px 32px rgba(0,0,0,0.3); }

.stat-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.icon-blue   { background: var(--blue-dim); color: var(--blue); }
.icon-green  { background: var(--green-dim); color: var(--green); }
.icon-yellow { background: var(--yellow-dim); color: var(--yellow); }
.icon-red    { background: var(--red-dim); color: var(--red); }
.icon-purple { background: var(--purple-dim); color: var(--purple); }

.stat-value { font-size: 26px; font-weight: 800; color: var(--text-primary); line-height: 1; }
.stat-label { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.stat-trend { font-size: 11px; margin-top: 3px; }

/* ── Two-column Grid ─────────────────────────────────────────── */
.two-col-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 14px; font-weight: 700; }

/* ── Badges ──────────────────────────────────────────────────── */
.badge-ai {
  font-size: 10px;
  font-weight: 700;
  padding: 3px 10px;
  background: linear-gradient(135deg, var(--accent-dim), rgba(139,92,246,0.15));
  border: 1px solid rgba(99,102,241,0.3);
  border-radius: 20px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Loading Pulse ───────────────────────────────────────────── */
.loading-pulse {
  color: var(--text-muted);
  font-size: 13px;
  padding: 20px 0;
  background: linear-gradient(90deg, var(--bg-input) 25%, var(--bg-card-hover) 50%, var(--bg-input) 75%);
  background-size: 400px 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
  min-height: 40px;
}

/* ── AI Recommendations ──────────────────────────────────────── */
.ai-recs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  padding: 18px 20px;
}

.ai-rec-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex;
  gap: 12px;
  transition: border-color var(--transition);
}
.ai-rec-card.high  { border-left: 3px solid var(--red); }
.ai-rec-card.medium { border-left: 3px solid var(--yellow); }
.ai-rec-card.low   { border-left: 3px solid var(--green); }

.ai-rec-icon { font-size: 22px; flex-shrink: 0; }
.ai-rec-text { font-size: 12px; color: var(--text-secondary); line-height: 1.6; }

/* ── Funnel Bars ─────────────────────────────────────────────── */
.funnel-item {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.funnel-label { font-size: 12px; color: var(--text-secondary); width: 100px; flex-shrink: 0; }
.funnel-bar-wrap { flex: 1; background: var(--bg-input); border-radius: 4px; height: 8px; overflow: hidden; }
.funnel-bar { height: 100%; border-radius: 4px; transition: width 0.8s ease; }
.funnel-count { font-size: 12px; font-weight: 700; color: var(--text-primary); width: 36px; text-align: right; }

/* ── Country List ────────────────────────────────────────────── */
.country-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.country-row:last-child { border-bottom: none; }

/* ── Recent Leads Table ──────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { padding: 10px 12px; text-align: left; font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 1px solid var(--border); }
.data-table td { padding: 10px 12px; border-bottom: 1px solid rgba(255,255,255,0.04); }
.data-table tr:hover td { background: rgba(255,255,255,0.02); }

/* ── Kanban Board ────────────────────────────────────────────── */
.kanban-board {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding: 20px;
  min-height: 400px;
}

.kanban-col {
  min-width: 220px;
  max-width: 220px;
  background: var(--bg-input);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.kanban-col-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.kanban-col-title { font-size: 12px; font-weight: 700; }
.kanban-col-count {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--bg-card);
}

.kanban-col-body {
  flex: 1;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  max-height: 500px;
}

.kanban-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  cursor: pointer;
  transition: all var(--transition);
}
.kanban-card:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: 0 4px 16px rgba(0,0,0,0.3); }
.kanban-card-name { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.kanban-card-meta { font-size: 11px; color: var(--text-muted); }
.kanban-card-value { font-size: 12px; color: var(--green); font-weight: 600; margin-top: 6px; }
.kanban-card-actions { display: flex; gap: 4px; margin-top: 8px; }
.kanban-btn {
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  transition: all var(--transition);
}

/* Stage colors */
.stage-new .kanban-col-header { border-top: 3px solid var(--blue); }
.stage-contacted .kanban-col-header { border-top: 3px solid var(--purple); }
.stage-proposal .kanban-col-header { border-top: 3px solid var(--yellow); }
.stage-negotiation .kanban-col-header { border-top: 3px solid var(--accent); }
.stage-won .kanban-col-header { border-top: 3px solid var(--green); }
.stage-lost .kanban-col-header { border-top: 3px solid var(--red); }

/* ── Tasks ───────────────────────────────────────────────────── */
.task-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.task-item:hover { background: rgba(255,255,255,0.02); }
.task-icon { font-size: 18px; flex-shrink: 0; margin-top: 2px; }
.task-info { flex: 1 }
.task-title { font-size: 13px; font-weight: 600; }
.task-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.task-actions { display: flex; gap: 6px; }

/* ── SEO Score Ring ──────────────────────────────────────────── */
.seo-score-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.seo-score-value { font-size: 48px; font-weight: 900; line-height: 1; }
.seo-score-label { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

.seo-issue {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--border);
  background: var(--bg-input);
}
.seo-issue.critical { border-left-color: var(--red); }
.seo-issue.warning  { border-left-color: var(--yellow); }
.seo-issue.info     { border-left-color: var(--blue); }
.seo-issue-title { font-size: 13px; font-weight: 600; }
.seo-issue-desc  { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.seo-issue-fix   { font-size: 11px; color: var(--green); margin-top: 4px; }

.seo-rec {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border-left: 3px solid var(--border);
}
.seo-rec.high   { border-left-color: var(--red); }
.seo-rec.medium { border-left-color: var(--yellow); }
.seo-rec.low    { border-left-color: var(--green); }
.seo-rec-action { font-size: 13px; font-weight: 600; }
.seo-rec-impact { font-size: 11px; color: var(--text-muted); margin-top: 3px; }

/* ── Keyword Table ───────────────────────────────────────────── */
.kw-competition { padding: 3px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.kw-competition.low    { background: var(--green-dim); color: var(--green); }
.kw-competition.medium { background: var(--yellow-dim); color: var(--yellow); }
.kw-competition.high   { background: var(--red-dim); color: var(--red); }

.kw-intent { font-size: 10px; padding: 2px 7px; border-radius: 20px; background: var(--bg-input); color: var(--text-muted); }

/* ── Rank Tracker ────────────────────────────────────────────── */
.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 800;
}
.rank-top3  { background: linear-gradient(135deg, #ffd700, #ff9500); color: #000; }
.rank-top10 { background: var(--green-dim); color: var(--green); }
.rank-top50 { background: var(--blue-dim); color: var(--blue); }
.rank-other { background: var(--bg-input); color: var(--text-muted); }

/* ── Competitor Cards ────────────────────────────────────────── */
.comp-metric {
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
}
.comp-metric-value { font-size: 22px; font-weight: 800; }
.comp-metric-label { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ── Social Posts ────────────────────────────────────────────── */
.social-posts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.social-post-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: all var(--transition);
}
.social-post-card:hover { border-color: rgba(255,255,255,0.12); transform: translateY(-2px); }

.social-post-header {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.social-platform-badge {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
}
.platform-facebook  { background: rgba(24,119,242,0.15); color: #1877f2; }
.platform-instagram { background: rgba(225,48,108,0.15); color: #e1306c; }
.platform-linkedin  { background: rgba(10,102,194,0.15); color: #0a66c2; }
.platform-twitterx  { background: rgba(255,255,255,0.08); color: #fff; }
.platform-tiktok    { background: rgba(105,201,208,0.15); color: #69c9d0; }

.social-post-body { padding: 14px; font-size: 13px; color: var(--text-secondary); line-height: 1.6; }
.social-post-footer {
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
}

.post-status { padding: 3px 8px; border-radius: 20px; font-size: 10px; font-weight: 700; }
.post-status.scheduled  { background: var(--blue-dim); color: var(--blue); }
.post-status.published  { background: var(--green-dim); color: var(--green); }
.post-status.draft      { background: var(--bg-card); color: var(--text-muted); }

/* ── AI Chat ─────────────────────────────────────────────────── */
.ai-chat-message {
  display: flex;
  gap: 12px;
  max-width: 80%;
}
.ai-chat-message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.ai-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--accent-dim);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.ai-bubble {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-secondary);
}
.ai-bubble p { margin-bottom: 6px; }
.ai-bubble p:last-child { margin-bottom: 0; }
.ai-bubble ul { padding-left: 16px; }
.ai-bubble strong { color: var(--text-primary); }
.ai-chat-message.user .ai-bubble {
  background: var(--accent-dim);
  border-color: var(--accent-glow);
  color: var(--text-primary);
}
.ai-typing {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 8px;
}
.ai-typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: bounce 1.2s infinite;
}
.ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; } 40% { transform: scale(1.1); opacity: 1; } }

/* ── Agency Features ─────────────────────────────────────────── */
.agency-features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.agency-feature-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  transition: all var(--transition);
}
.agency-feature-card:hover { border-color: var(--accent-glow); transform: translateY(-2px); }
.agency-feature-icon { font-size: 32px; margin-bottom: 12px; }
.agency-feature-card h3 { font-size: 14px; font-weight: 700; margin-bottom: 8px; }
.agency-feature-card p { font-size: 12px; color: var(--text-muted); line-height: 1.6; }

/* ── Pricing ─────────────────────────────────────────────────── */
.pricing-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  position: relative;
  transition: all var(--transition);
}
.pricing-card:hover { border-color: var(--accent-glow); transform: translateY(-2px); }
.pricing-card.featured { border-color: var(--accent); background: linear-gradient(135deg, var(--accent-dim), var(--bg-card)); }
.pricing-card.enterprise { border-color: var(--yellow); }
.plan-badge { position: absolute; top: -10px; left: 50%; transform: translateX(-50%); background: var(--accent); color: white; font-size: 10px; font-weight: 700; padding: 3px 12px; border-radius: 20px; white-space: nowrap; }
.plan-name { font-size: 14px; font-weight: 700; margin-bottom: 8px; }
.plan-price { font-size: 24px; font-weight: 900; color: var(--text-primary); margin-bottom: 12px; }
.plan-price span { font-size: 13px; font-weight: 400; color: var(--text-muted); }
.plan-features { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.plan-features li { font-size: 12px; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; }
.plan-features li::before { content: '✓'; color: var(--green); font-weight: 700; flex-shrink: 0; }

/* ── Backlink Cards ──────────────────────────────────────────── */
.backlink-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  padding: 20px;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  font-family: 'Inter', sans-serif;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: #4f52e0; transform: translateY(-1px); box-shadow: 0 4px 16px var(--accent-glow); }
.btn-secondary { background: var(--bg-input); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg-card-hover); border-color: var(--text-muted); }
.btn-outline { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-outline:hover { border-color: var(--text-muted); color: var(--text-primary); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-wide { width: 100%; justify-content: center; }

/* ── Forms ───────────────────────────────────────────────────── */
.send-form { padding: 22px; display: flex; flex-direction: column; gap: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 11px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.06em; }
.hint { font-weight: 400; color: var(--text-muted); text-transform: none; letter-spacing: 0; }
.form-input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 13px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: 'Inter', sans-serif;
  outline: none;
  transition: border-color var(--transition);
  width: 100%;
}
.form-input:focus { border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(99,102,241,0.1); }
.form-textarea { min-height: 100px; resize: vertical; }
.form-mono { font-family: 'JetBrains Mono', monospace; font-size: 12px; }
select.form-input option { background: #1a2235; }

.send-result { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; display: none; }
.send-result.success { background: var(--green-dim); border: 1px solid var(--green-glow); color: var(--green); display: block; }
.send-result.error   { background: var(--red-dim);   border: 1px solid var(--red); color: var(--red); display: block; }
.send-result.info    { background: var(--blue-dim); border: 1px solid var(--blue); color: var(--blue); display: block; }

/* ── API Docs ─────────────────────────────────────────────────── */
.api-docs { padding: 22px; display: flex; flex-direction: column; gap: 20px; }
.api-base-url { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--bg-input); border-radius: var(--radius-sm); border: 1px solid var(--border); }
.api-label { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; }
.api-base-url code { font-family: 'JetBrains Mono', monospace; color: var(--green); font-size: 13px; }
.api-auth-note { font-size: 13px; color: var(--text-muted); }
.api-auth-note code { color: var(--blue); font-family: 'JetBrains Mono', monospace; font-size: 12px; }
.endpoint-group { display: flex; flex-direction: column; gap: 6px; }
.endpoint-group-title { font-weight: 700; color: var(--text-secondary); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.endpoint { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: var(--radius-sm); background: var(--bg-input); }
.method { font-family: 'JetBrains Mono', monospace; font-size: 10px; font-weight: 700; padding: 3px 7px; border-radius: 4px; flex-shrink: 0; }
.method.post   { background: rgba(59,130,246,0.2); color: #60a5fa; }
.method.get    { background: rgba(16,185,129,0.15); color: var(--green); }
.method.delete { background: rgba(239,68,68,0.15); color: #f87171; }
.method.patch  { background: rgba(245,158,11,0.15); color: #fbbf24; }
.endpoint code { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--text-primary); flex: 1; }
.ep-desc { font-size: 12px; color: var(--text-muted); }

/* ── Modals ──────────────────────────────────────────────────── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 100; align-items: center; justify-content: center; backdrop-filter: blur(6px); }
.modal-overlay.open { display: flex; }
.modal { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); width: 92%; max-width: 480px; box-shadow: var(--shadow); animation: modalIn 0.2s ease; max-height: 90vh; overflow-y: auto; }
.modal-sm { max-width: 380px; }
@keyframes modalIn { from { opacity: 0; transform: scale(0.95) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg-card); z-index: 1; }
.modal-header h3 { font-size: 15px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 18px; cursor: pointer; transition: color var(--transition); }
.modal-close:hover { color: var(--text-primary); }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }

/* ── QR ──────────────────────────────────────────────────────── */
.qr-hint { font-size: 13px; color: var(--text-secondary); }
.qr-loading { padding: 40px; color: var(--text-muted); }
#qrImageContainer img { width: 240px; height: 240px; border-radius: 8px; border: 2px solid var(--accent); margin-top: 16px; }

/* ── Toast ───────────────────────────────────────────────────── */
.toast { position: fixed; bottom: 24px; right: 24px; padding: 12px 20px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-primary); font-size: 13px; font-weight: 500; box-shadow: var(--shadow); z-index: 200; opacity: 0; transform: translateY(10px); transition: all 0.3s ease; pointer-events: none; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { border-color: var(--green-glow); color: var(--green); }
.toast.error   { border-color: var(--red); color: var(--red); }

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

/* ── Scrollbar ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ── AI Panel ────────────────────────────────────────────────── */
.ai-notice { padding: 12px 16px; background: rgba(245,158,11,0.08); border: 1px solid rgba(245,158,11,0.25); border-radius: var(--radius-sm); font-size: 12px; color: var(--yellow); line-height: 1.7; }
.ai-notice code { background: rgba(255,255,255,0.08); padding: 1px 5px; border-radius: 3px; }
.ai-toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 16px; background: var(--bg-input); border-radius: var(--radius-sm); border: 1px solid var(--border); }
.ai-toggle-title { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.ai-toggle-desc  { font-size: 12px; color: var(--text-muted); }
.toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; inset: 0; background: var(--bg-card); border: 1px solid var(--border); border-radius: 24px; cursor: pointer; transition: all 0.3s ease; }
.toggle-slider::before { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: var(--text-muted); border-radius: 50%; transition: all 0.3s ease; }
.toggle-switch input:checked + .toggle-slider { background: var(--green-dim); border-color: var(--green-glow); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); background: var(--green); box-shadow: 0 0 8px var(--green-glow); }

/* ── Chatbot Grid ────────────────────────────────────────────── */
.ai-bots-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; padding: 16px; }
.ai-bot-card { background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; transition: all var(--transition); }
.ai-bot-card.active { border-color: rgba(16,185,129,0.2); }
.ai-bot-card-header { padding: 14px; display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 1px solid var(--border); }
.ai-bot-name { font-weight: 700; font-size: 15px; color: var(--text-primary); }
.ai-bot-phone { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.ai-bot-status-pill { padding: 4px 10px; border-radius: 20px; font-size: 10px; font-weight: 700; text-transform: uppercase; }
.ai-bot-status-pill.enabled { background: var(--green-dim); color: var(--green); }
.ai-bot-status-pill.disabled { background: var(--border); color: var(--text-muted); }
.ai-bot-body { padding: 14px; }
.ai-bot-prompt-preview { font-size: 13px; color: var(--text-secondary); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; margin-bottom: 12px; min-height: 58px; }
.ai-bot-meta { display: flex; gap: 12px; font-size: 11px; color: var(--text-muted); background: var(--bg-card); padding: 8px 12px; border-radius: 6px; }
.ai-bot-footer { padding: 12px 14px; display: flex; gap: 8px; border-top: 1px solid var(--border); }

/* ── Lead Table ──────────────────────────────────────────────── */
.header-main { display: flex; flex-direction: column; gap: 8px; }
.search-box { display: flex; align-items: center; gap: 10px; background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 14px; width: 300px; transition: all var(--transition); }
.search-box:focus-within { border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(99,102,241,0.1); }
.search-box input { background: none; border: none; color: var(--text-primary); font-size: 13px; width: 100%; outline: none; }
.lead-tr { border-bottom: 1px solid var(--border); transition: background var(--transition); }
.lead-tr:hover { background: rgba(255,255,255,0.02); }
.table-container { max-height: 70vh; overflow-y: auto; }

/* ── Tabs ────────────────────────────────────────────────────── */
.tab-btn { background: none; border: none; color: var(--text-muted); font-size: 13px; font-weight: 600; padding: 6px 12px; cursor: pointer; transition: all var(--transition); border-bottom: 2px solid transparent; }
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Status Badges ───────────────────────────────────────────── */
.inst-status-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.inst-status-dot.connected    { background: var(--green); box-shadow: 0 0 8px var(--green-glow); }
.inst-status-dot.qr_ready     { background: var(--yellow); }
.inst-status-dot.initializing { background: var(--blue); animation: pulse 1.5s infinite; }
.inst-status-dot.reconnecting { background: var(--yellow); animation: pulse 1s infinite; }
.inst-status-dot.disconnected, .inst-status-dot.logged_out { background: var(--red-dim); border: 1.5px solid var(--red); }
.inst-status-dot.error { background: var(--red); }

.inst-status-badge { padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; text-transform: capitalize; }
.badge-connected    { background: var(--green-dim);  color: var(--green); }
.badge-qr_ready     { background: var(--yellow-dim); color: var(--yellow); }
.badge-initializing { background: var(--blue-dim);   color: var(--blue); }
.badge-reconnecting { background: var(--yellow-dim); color: var(--yellow); }
.badge-disconnected, .badge-logged_out { background: var(--red-dim); color: var(--red); }
.badge-error { background: var(--red-dim); color: var(--red); }
.badge-status { padding: 4px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.instance-list { padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.instance-row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: var(--radius-sm); background: transparent; border: 1px solid transparent; transition: all var(--transition); cursor: default; }
.instance-row:hover { background: var(--bg-card-hover); border-color: var(--border); }
.inst-name  { font-weight: 600; color: var(--text-primary); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inst-phone { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--text-muted); }
.inst-actions { display: flex; gap: 6px; }
.btn-icon { width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; border-radius: 6px; border: 1px solid var(--border); background: transparent; color: var(--text-secondary); cursor: pointer; transition: all var(--transition); }
.btn-icon:hover { background: rgba(255,255,255,0.07); color: var(--text-primary); }
.btn-icon.danger:hover { background: var(--red-dim); border-color: var(--red); color: var(--red); }
.btn-icon.success:hover { background: var(--green-dim); border-color: var(--green); color: var(--green); }

/* ── Visitor Stats ───────────────────────────────────────────── */
.visitor-bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 12px; }
.visitor-bar-label { width: 80px; color: var(--text-secondary); flex-shrink: 0; }
.visitor-bar-wrap { flex: 1; background: var(--bg-input); border-radius: 4px; height: 6px; overflow: hidden; }
.visitor-bar { height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--accent), var(--purple)); }
.visitor-bar-count { width: 40px; text-align: right; color: var(--text-muted); }

/* ── Tracker Code Display ────────────────────────────────────── */
.tracker-code { background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--green); word-break: break-all; line-height: 1.6; }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .two-col-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 50; transform: translateX(0); }
  .sidebar.collapsed { transform: translateX(-100%); }
  .main-content { margin-left: 0 !important; }
}
@media (max-width: 600px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .topbar { padding: 10px 14px; }
  .content-section { padding: 14px; }
  .api-key-input { width: 140px; }
  .kanban-board { padding: 12px; }
}
