/* === Base (shared with app.css) === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #06060a;
  --surface: #0d0d14;
  --surface-hover: #12121e;
  --border: #1a1a2e;
  --border-light: #252540;
  --text: #e8e8ed;
  --text-dim: #8888a0;
  --text-muted: #555570;
  --accent: #6c5ce7;
  --accent-hover: #7d6ff0;
  --accent-light: #a29bfe;
  --accent-dim: rgba(108, 92, 231, 0.12);
  --green: #00d2a0;
  --green-dim: rgba(0, 210, 160, 0.12);
  --yellow: #ffd166;
  --yellow-dim: rgba(255, 209, 102, 0.12);
  --red: #ff6b6b;
  --red-dim: rgba(255, 107, 107, 0.12);
  --blue: #4ecdc4;
  --blue-dim: rgba(78, 205, 196, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', -apple-system, sans-serif;
  line-height: 1.6;
  overflow-x: hidden;
  min-height: 100vh;
}

h1, h2, h3, h4 { font-family: 'Space Grotesk', sans-serif; font-weight: 600; line-height: 1.2; }
a { color: var(--accent-light); text-decoration: none; }
a:hover { color: var(--accent); }
.container { max-width: 1400px; margin: 0 auto; padding: 0 24px; }

/* === Nav === */
nav {
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(6, 6, 10, 0.95);
  backdrop-filter: blur(12px);
  z-index: 100;
}
.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.nav-left {
  display: flex;
  align-items: center;
  gap: 32px;
}
.logo {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
  text-decoration: none;
}
.logo span { color: var(--accent-light); }

.nav-tabs {
  display: flex;
  gap: 4px;
}
.nav-tab {
  padding: 6px 16px;
  border-radius: var(--radius-xs);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-dim);
  transition: all 0.2s;
}
.nav-tab:hover { color: var(--text); background: var(--surface-hover); }
.nav-tab.active {
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); transform: translateY(-1px); }
.btn-ghost { background: transparent; color: var(--text-dim); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); border-color: var(--border-light); }
.btn-green { background: var(--green); color: #06060a; }
.btn-green:hover:not(:disabled) { background: #00e6b0; transform: translateY(-1px); }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn-xs { padding: 4px 10px; font-size: 0.75rem; }
.btn-icon {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover { color: var(--text); background: var(--surface-hover); }
.btn-danger { background: var(--red-dim); color: var(--red); border: 1px solid transparent; }
.btn-danger:hover:not(:disabled) { background: var(--red); color: white; }

/* === Badges === */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 20px;
}
.badge-new { color: var(--text-dim); background: var(--surface-hover); }
.badge-researching, .badge-generating { color: var(--yellow); background: var(--yellow-dim); }
.badge-researched { color: var(--blue); background: var(--blue-dim); }
.badge-sequenced { color: var(--green); background: var(--green-dim); }
.badge-error { color: var(--red); background: var(--red-dim); }
.badge-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}
.badge-researching .badge-dot, .badge-generating .badge-dot {
  animation: pulse-dot 1.2s infinite;
}
.outreach-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 20px;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* === Main === */
main { padding: 32px 0 80px; }

/* === Pipeline Summary === */
.pipeline-stats {
  display: flex;
  align-items: stretch;
  gap: 24px;
  margin-bottom: 28px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.pipeline-stat-total {
  min-width: 100px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-right: 24px;
  border-right: 1px solid var(--border);
}
.stat-number {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}
.stat-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 4px;
}
.pipeline-stat-stages {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
}
.pipeline-stat-stage {
  text-align: center;
}
.stat-stage-count {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
}
.stat-stage-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 4px;
}
.stat-stage-bar {
  margin-top: 8px;
  height: 3px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.stat-stage-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
  min-width: 0;
}

/* === View Toggle === */
.view-toggle {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px;
  width: fit-content;
}
.view-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-xs);
  transition: all 0.2s;
}
.view-btn:hover { color: var(--text); }
.view-btn.active {
  background: var(--accent-dim);
  color: var(--accent-light);
}

/* === Pipeline Board === */
.pipeline-board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  min-height: 400px;
}
.pipeline-column {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.pipeline-column-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.pipeline-column-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.pipeline-column-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}
.pipeline-column-count {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 10px;
}
.pipeline-column-cards {
  padding: 10px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pipeline-empty {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
  padding: 24px 8px;
}

/* === Pipeline Card === */
.pipeline-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  cursor: pointer;
  transition: all 0.2s;
}
.pipeline-card:hover {
  border-color: var(--border-light);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.pipeline-card-company {
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 4px;
}
.pipeline-card-contact {
  font-size: 0.75rem;
  color: var(--text-dim);
}
.pipeline-card-industry {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
}
.pipeline-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}
.mini-badge {
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: 500;
}
.mini-badge-blue { color: var(--blue); background: var(--blue-dim); }
.mini-badge-green { color: var(--green); background: var(--green-dim); }
.mini-badge-dim { color: var(--text-dim); background: var(--surface-hover); }

/* === Table View === */
.table-wrapper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.crm-table {
  width: 100%;
  border-collapse: collapse;
}
.crm-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.crm-table td {
  padding: 14px 16px;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table-row-clickable { cursor: pointer; transition: background 0.15s; }
.table-row-clickable:hover { background: var(--surface-hover); }
.table-company { font-weight: 600; }
.table-url { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }
.table-contact-name { font-weight: 500; }
.table-contact-email { font-size: 0.75rem; color: var(--text-dim); margin-top: 1px; }
.text-muted { color: var(--text-muted); }
.text-green { color: var(--green); font-weight: 500; }

/* === Drawer === */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.drawer-overlay.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 520px;
  max-width: 90vw;
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 300;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  overflow-y: auto;
}
.drawer.open { transform: translateX(0); }

.drawer-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 10;
}

.drawer-body { padding: 20px; }

.drawer-title-section {
  margin-bottom: 24px;
}
.drawer-title-section h2 {
  font-size: 1.5rem;
  margin-bottom: 4px;
}
.drawer-url {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 10px;
}
.drawer-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.drawer-section {
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}
.drawer-section:last-child { border-bottom: none; }
.drawer-section h4 {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}
.drawer-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.drawer-section-header h4 {
  margin-bottom: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* === Stage Selector === */
.stage-selector {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stage-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.stage-btn:hover {
  border-color: var(--stage-color);
  color: var(--text);
}
.stage-btn.active {
  border-color: var(--stage-color);
  background: var(--stage-bg);
  color: var(--stage-color);
}
.stage-btn-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
}
.stage-btn.active .stage-btn-num {
  background: var(--stage-color);
  color: var(--bg);
}

/* === Drawer Form === */
.drawer-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.form-row-compact {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-field label {
  display: block;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.form-field input,
.form-field textarea {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  transition: border-color 0.2s;
  resize: vertical;
}
.form-field input:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.form-field input::placeholder,
.form-field textarea::placeholder {
  color: var(--text-muted);
}

/* === Drawer Research === */
.drawer-research-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.drawer-research-item label {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  display: block;
  margin-bottom: 2px;
}
.drawer-research-item span {
  font-size: 0.85rem;
  color: var(--text);
}
.drawer-research-summary {
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.6;
  margin-bottom: 12px;
}
.drawer-contacts {
  margin-top: 12px;
}
.drawer-contacts label {
  display: block;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.drawer-contact-chip {
  display: inline-block;
  padding: 4px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  font-size: 0.8rem;
  margin-right: 6px;
  margin-bottom: 6px;
}
.drawer-tags { margin-top: 12px; }
.drawer-tags label {
  display: block;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.tag {
  font-size: 0.75rem;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--accent-dim);
  color: var(--accent-light);
}

/* === Drawer Emails === */
.drawer-email {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}
.drawer-email:last-child { margin-bottom: 0; }
.drawer-email-header {
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: background 0.15s;
}
.drawer-email-header:hover { background: var(--surface-hover); }
.drawer-email-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}
.email-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
  flex-shrink: 0;
}
.drawer-email-subject { font-weight: 500; font-size: 0.85rem; }
.drawer-email-type { font-size: 0.7rem; color: var(--text-muted); }
.drawer-email-body {
  padding: 14px;
  white-space: pre-wrap;
  font-size: 0.85rem;
  line-height: 1.7;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  display: none;
}
.drawer-email-body.open { display: block; }

/* === Drawer Actions === */
.drawer-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.drawer-danger {
  border-bottom: none;
  padding-bottom: 0;
}

/* === Loading === */
.loading-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 0.85rem;
}
.drawer-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 60px 20px;
  color: var(--text-dim);
}

/* === Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  animation: modalIn 0.2s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.1rem; }
.form-group {
  padding: 0 24px;
  margin-top: 16px;
}
.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.form-group input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  transition: border-color 0.2s;
}
.form-group input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.form-group input::placeholder { color: var(--text-muted); }
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  padding: 0;
}
.form-row .form-group { padding: 0 24px; }
.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 20px 24px;
}

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 60px 24px;
}
.empty-state h3 {
  font-size: 1.25rem;
  margin-bottom: 8px;
}
.empty-state p {
  color: var(--text-dim);
  margin-bottom: 20px;
}

/* === Toast === */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  animation: toastIn 0.3s ease;
  max-width: 360px;
}
.toast-success { border-left: 3px solid var(--green); }
.toast-error { border-left: 3px solid var(--red); }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* === Responsive === */
@media (max-width: 1100px) {
  .pipeline-board {
    grid-template-columns: repeat(3, 1fr);
  }
  .pipeline-stat-stages {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 768px) {
  .pipeline-board {
    grid-template-columns: 1fr 1fr;
  }
  .pipeline-stats {
    flex-direction: column;
    gap: 16px;
  }
  .pipeline-stat-total {
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding-right: 0;
    padding-bottom: 16px;
  }
  .pipeline-stat-stages {
    grid-template-columns: repeat(3, 1fr);
  }
  .drawer {
    width: 100%;
    max-width: 100%;
  }
  .crm-table { font-size: 0.8rem; }
  .crm-table th, .crm-table td { padding: 10px 12px; }
  .form-row { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .pipeline-board {
    grid-template-columns: 1fr;
  }
  .pipeline-stat-stages {
    grid-template-columns: repeat(2, 1fr);
  }
  .nav-tabs { display: none; }
}
