/* ===== DESIGN SYSTEM ===== */
:root {
  --bg: #0a0b0f;
  --bg-card: #12131a;
  --bg-card-hover: #181a24;
  --bg-sidebar: #0e0f15;
  --bg-panel: #14151e;
  --bg-input: #1a1c26;
  --border: #1f2233;
  --border-hover: #2d3050;
  --text: #e4e6f0;
  --text-dim: #787ea0;
  --text-muted: #505372;
  --accent: #6366f1;
  --accent-glow: rgba(99,102,241,0.15);
  --accent-hover: #818cf8;
  --hot: #f43f5e;
  --hot-bg: rgba(244,63,94,0.12);
  --warm: #f59e0b;
  --warm-bg: rgba(245,158,11,0.12);
  --nurture: #06b6d4;
  --nurture-bg: rgba(6,182,212,0.12);
  --green: #10b981;
  --green-bg: rgba(16,185,129,0.12);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --shadow-lg: 0 12px 48px rgba(0,0,0,0.5);
  --transition: 0.2s cubic-bezier(0.4,0,0.2,1);
  --font: 'Inter', -apple-system, sans-serif;
}

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

html { font-size: 14px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100vh;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== TOPBAR ===== */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 24px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
}

.topbar-left { display: flex; align-items: center; gap: 16px; }
.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 16px; color: #fff;
}
.logo-text { font-weight: 700; font-size: 16px; letter-spacing: -0.02em; }
.logo-dim { font-weight: 400; color: var(--text-dim); }

.topbar-center { flex: 1; max-width: 480px; margin: 0 32px; }
.search-wrap {
  position: relative;
  display: flex; align-items: center;
}
.search-icon {
  position: absolute; left: 12px;
  color: var(--text-muted);
  pointer-events: none;
}
#globalSearch {
  width: 100%;
  padding: 8px 40px 8px 38px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  outline: none;
  transition: var(--transition);
}
#globalSearch:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
#globalSearch::placeholder { color: var(--text-muted); }
.search-kbd {
  position: absolute; right: 10px;
  padding: 2px 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font);
}

.topbar-right { display: flex; align-items: center; gap: 12px; }
.tagitm-badge {
  padding: 4px 10px;
  background: var(--accent-glow);
  border: 1px solid rgba(99,102,241,0.3);
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-hover);
  letter-spacing: 0.05em;
}
.status-count { font-size: 12px; color: var(--text-dim); }

/* ===== LAYOUT ===== */
#app {
  display: flex;
  margin-top: 56px;
  height: calc(100vh - 56px);
}

/* ===== SIDEBAR ===== */
#sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  overflow-y: auto;
  height: 100%;
}

.sidebar-section { margin-bottom: 24px; }
.sidebar-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.filter-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  padding: 5px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  transition: var(--transition);
  user-select: none;
  white-space: nowrap;
}
.chip:hover { border-color: var(--border-hover); color: var(--text); }
.chip.active {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent-hover);
}
.chip .chip-count {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 5px;
  background: rgba(255,255,255,0.06);
  border-radius: 10px;
  font-size: 10px;
}

.sidebar-stats { border-top: 1px solid var(--border); padding-top: 16px; }
#statCards { display: flex; flex-direction: column; gap: 8px; }
.stat-mini {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
}
.stat-mini-label { font-size: 12px; color: var(--text-dim); }
.stat-mini-val { font-size: 14px; font-weight: 700; }

/* ===== MAIN ===== */
#mainContent {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

/* Stats Banner */
.stats-banner {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  transition: var(--transition);
}
.stat-card:hover { border-color: var(--border-hover); transform: translateY(-1px); }
.stat-card .stat-num {
  font-size: 28px; font-weight: 800;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.stat-card .stat-label {
  font-size: 11px; color: var(--text-muted);
  margin-top: 4px; text-transform: uppercase; letter-spacing: 0.06em;
}

.stat-card.hot .stat-num { background: linear-gradient(135deg, var(--hot), #fb7185); -webkit-background-clip: text; }
.stat-card.warm .stat-num { background: linear-gradient(135deg, var(--warm), #fbbf24); -webkit-background-clip: text; }
.stat-card.nurture .stat-num { background: linear-gradient(135deg, var(--nurture), #22d3ee); -webkit-background-clip: text; }
.stat-card.green .stat-num { background: linear-gradient(135deg, var(--green), #34d399); -webkit-background-clip: text; }

/* Contacts Header */
.contacts-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
}
.contacts-count { font-size: 13px; color: var(--text-dim); }
.sort-controls { display: flex; align-items: center; gap: 8px; }
.sort-controls label { font-size: 12px; color: var(--text-muted); }
.sort-controls select {
  padding: 6px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 12px;
  outline: none;
  cursor: pointer;
}

/* Contacts List */
.contacts-list { display: flex; flex-direction: column; gap: 6px; padding-bottom: 40px; }

.contact-row {
  display: grid;
  grid-template-columns: 40px 1.5fr 2fr 1fr 1fr 120px 100px 60px;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
}
.contact-row:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
  transform: translateX(2px);
}

.contact-score {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px;
}
.score-5 { background: var(--hot-bg); color: var(--hot); }
.score-4 { background: var(--warm-bg); color: var(--warm); }
.score-3 { background: var(--nurture-bg); color: var(--nurture); }
.score-2 { background: rgba(99,102,241,0.12); color: var(--accent); }
.score-1 { background: rgba(255,255,255,0.04); color: var(--text-muted); }

.contact-name { font-weight: 600; font-size: 13px; }
.contact-title { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.contact-org { font-size: 12px; color: var(--text-dim); }
.contact-org-name { font-weight: 500; color: var(--text); font-size: 13px; }

.tier-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.tier-hot { background: var(--hot-bg); color: var(--hot); }
.tier-warm { background: var(--warm-bg); color: var(--warm); }
.tier-nurture { background: var(--nurture-bg); color: var(--nurture); }

.dept-badge {
  font-size: 11px;
  color: var(--text-dim);
  padding: 3px 8px;
  background: var(--bg-input);
  border-radius: 12px;
}

.status-badge {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: var(--transition);
}
.status-not-sent { background: rgba(255,255,255,0.04); color: var(--text-muted); }
.status-sent { background: var(--warm-bg); color: var(--warm); }
.status-replied { background: var(--green-bg); color: var(--green); }
.status-skipped { background: rgba(255,255,255,0.02); color: var(--text-muted); text-decoration: line-through; }

.contact-actions { display: flex; gap: 6px; }
.action-btn {
  width: 28px; height: 28px;
  border: none;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
  font-size: 14px;
}
.action-btn:hover { background: var(--accent-glow); color: var(--accent-hover); }

/* ===== DETAIL PANEL ===== */
.detail-overlay {
  position: fixed;
  top: 56px; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  justify-content: flex-end;
  transition: opacity 0.3s ease;
}
.detail-overlay.hidden { display: none; }

.detail-panel {
  width: 680px;
  max-width: 90vw;
  height: 100%;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 32px;
  animation: slideIn 0.3s ease;
  box-shadow: var(--shadow-lg);
}
@keyframes slideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.detail-close {
  position: absolute; top: 12px; right: 16px;
  width: 36px; height: 36px;
  border: none;
  background: var(--bg-input);
  border-radius: 50%;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
}
.detail-close:hover { background: var(--hot-bg); color: var(--hot); }

/* Detail sections */
.detail-header {
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.detail-name { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.detail-titlerole { font-size: 14px; color: var(--text-dim); margin-top: 4px; }
.detail-meta {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 12px;
}
.detail-meta .tier-badge { font-size: 12px; padding: 4px 12px; }

.detail-section {
  margin-bottom: 24px;
}
.detail-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 10px;
  display: flex; align-items: center; gap: 6px;
}
.detail-section-title svg { width: 14px; height: 14px; }

.intel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.intel-item {
  padding: 12px;
  background: var(--bg-input);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.intel-item.full { grid-column: 1 / -1; }
.intel-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.intel-value {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
}
.intel-value:empty::after { content: "—"; color: var(--text-muted); }

.services-tags {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.service-tag {
  padding: 5px 12px;
  background: var(--accent-glow);
  border: 1px solid rgba(99,102,241,0.2);
  border-radius: 20px;
  font-size: 12px;
  color: var(--accent-hover);
  font-weight: 500;
}

/* Email section */
.email-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.email-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px;
  background: var(--bg-input);
  border-bottom: 1px solid var(--border);
}
.email-toolbar-left { display: flex; align-items: center; gap: 8px; }
.email-toolbar-title { font-size: 13px; font-weight: 600; }
.email-toolbar-right { display: flex; gap: 8px; }

.email-btn {
  padding: 7px 14px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: flex; align-items: center; gap: 6px;
}
.email-btn:hover { border-color: var(--accent); color: var(--accent-hover); }
.email-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.email-btn.primary:hover { background: var(--accent-hover); }
.email-btn.copied {
  background: var(--green-bg);
  border-color: var(--green);
  color: var(--green);
}

.email-body {
  padding: 20px;
}
.email-subject {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
  outline: none;
  transition: var(--transition);
}
.email-subject:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

.email-textarea {
  width: 100%;
  min-height: 300px;
  padding: 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.65;
  outline: none;
  resize: vertical;
  transition: var(--transition);
}
.email-textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

/* Status selector inside detail */
.status-selector {
  display: flex; gap: 8px;
  margin-top: 8px;
}
.status-opt {
  padding: 6px 14px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  border-radius: 20px;
  font-size: 12px;
  font-family: var(--font);
  color: var(--text-dim);
  cursor: pointer;
  transition: var(--transition);
}
.status-opt:hover { border-color: var(--border-hover); }
.status-opt.active-not-sent { border-color: var(--text-muted); color: var(--text); }
.status-opt.active-sent { border-color: var(--warm); color: var(--warm); background: var(--warm-bg); }
.status-opt.active-replied { border-color: var(--green); color: var(--green); background: var(--green-bg); }
.status-opt.active-skipped { border-color: var(--text-muted); color: var(--text-muted); text-decoration: line-through; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 10px 20px;
  background: var(--green);
  color: #fff;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  z-index: 1000;
  transition: transform 0.3s ease;
  box-shadow: var(--shadow);
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ===== RESPONSIVE ===== */
@media (max-width: 1100px) {
  .stats-banner { grid-template-columns: repeat(3, 1fr); }
  .contact-row { grid-template-columns: 36px 1.4fr 1.6fr 1fr 100px 80px 50px; }
  .contact-row .dept-badge { display: none; }
}
@media (max-width: 800px) {
  #sidebar { display: none; }
  .stats-banner { grid-template-columns: repeat(2, 1fr); }
}
