/* ═══════════════════════════════════════════════════════════════════
   Lead Finder — Chat UI Design System
   Dark mode, conversational layout, company cards with contacts
   ═══════════════════════════════════════════════════════════════════ */

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

:root {
  /* Gemini-inspired Dark Theme */
  --bg-deep:     #131314;
  --bg-surface:  #1e1f20;
  --bg-elevated: #282a2c;
  --bg-hover:    #333537;
  --border:      #444746;
  --border-light:#333537;

  --text-primary:   #e3e3e3;
  --text-secondary: #c4c7c5;
  --text-muted:     #8e918f;

  /* Accent: Gemini-style soft blue/purple */
  --accent:      #a8c7fa;
  --accent-dim:  rgba(168, 199, 250, 0.12);
  
  /* Chat bubbles */
  --user-bubble: #1e1f20;
  --ai-bubble:   transparent;

  --score-perfect: #22c55e;
  --score-good:    #eab308;
  --score-possible:#f97316;
  --score-poor:    #ef4444;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Consolas', monospace;

  --topbar-h: 56px;
  --input-h:  72px;
}

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg-deep);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── Layout & Sidebar ────────────────────────────────────────────── */
.app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

.sidebar {
  width: 280px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 100;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.btn-new-search {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  background: var(--bg-hover);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-new-search:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.session-item {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.session-item:hover {
  background: var(--bg-hover);
}

.session-item.active {
  background: var(--bg-hover);
  border-left: 3px solid var(--accent);
}

.session-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.chat-content {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ── Top Bar ───────────────────────────────────────────────────── */
.top-bar {
  position: absolute; top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
}
.top-bar-left { display: flex; align-items: center; gap: 12px; }
.top-bar-right { display: flex; align-items: center; gap: 12px; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon {
  width: 28px; height: 28px; color: var(--accent);
  display: flex; align-items: center; justify-content: center;
}
.brand-icon svg { width: 24px; height: 24px; }
.brand-name {
  font-size: 15px; font-weight: 600;
  letter-spacing: -0.02em;
}

.status-chip {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-size: 12px; font-weight: 500;
  color: var(--text-secondary);
}
.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.idle { background: var(--text-muted); }
.status-dot.active {
  background: var(--score-perfect);
  animation: pulse-dot 1.5s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
  50% { opacity: 0.7; box-shadow: 0 0 0 4px rgba(34, 197, 94, 0); }
}

.btn-icon {
  width: 36px; height: 36px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s ease;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ── Chat Thread ───────────────────────────────────────────────── */
.chat-thread {
  position: fixed;
  top: var(--topbar-h);
  bottom: var(--input-h);
  left: 0; right: 0;
  overflow-y: auto;
  padding: 24px 0;
  scroll-behavior: smooth;
}
.chat-thread::-webkit-scrollbar { width: 6px; }
.chat-thread::-webkit-scrollbar-track { background: transparent; }
.chat-thread::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Message Bubbles ───────────────────────────────────────────── */
.msg {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  animation: msg-in 0.25s ease-out;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-user {
  flex-direction: row-reverse;
}
.msg-user .bubble {
  background: var(--user-bubble);
  color: var(--text-primary);
  border-radius: 20px 20px 4px 20px;
  border: none;
  padding: 12px 20px;
}

.msg-ai .avatar {
  width: 32px; height: 32px; flex-shrink: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  margin-top: 6px;
}

.bubble {
  padding: 12px 0; /* No side padding for AI */
  border-radius: 0;
  background: transparent;
  border: none;
  font-size: 15px;
  line-height: 1.6;
  max-width: 100%;
  word-wrap: break-word;
}

/* ── ICP Card ──────────────────────────────────────────────────── */
.icp-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-top: 8px;
}
.icp-card-title {
  font-size: 13px; font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
}
.icp-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; font-size: 13px;
}
.icp-field-label {
  font-size: 11px; font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 3px;
}
.icp-field-value {
  color: var(--text-primary);
  line-height: 1.4;
}
.icp-actions {
  display: flex; gap: 8px; margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.btn {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 13px; font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { background: var(--bg-hover); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: #5b4bd6; }
.btn:disabled {
  opacity: 0.5; cursor: not-allowed;
}

/* ── Status Message ────────────────────────────────────────────── */
.status-msg {
  max-width: 680px;
  margin: 0 auto 8px;
  padding: 0 20px 0 64px;
  animation: msg-in 0.2s ease-out;
}
.status-bubble {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}
.status-bubble .spinner {
  width: 12px; height: 12px;
  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); }
}
.status-bubble.done { color: var(--score-perfect); border-color: rgba(34,197,94,0.2); }
.status-bubble.error { color: var(--score-poor); border-color: rgba(239,68,68,0.2); }

/* ── Company Card ──────────────────────────────────────────────── */
.results-container {
  display: flex; flex-direction: column; gap: 10px;
  margin-top: 10px;
}

.company-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  cursor: pointer;
  transition: all 0.15s ease;
  margin-bottom: 10px;
}
.company-card:last-child { margin-bottom: 0; }
.company-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}

/* ── View Toggle ───────────────────────────────────────────────── */
.view-toggle {
  display: flex; gap: 6px; margin-bottom: 16px;
}
.btn-toggle {
  background: transparent; color: var(--text-secondary);
  border: 1px solid var(--border);
  box-shadow: none;
}
.btn-toggle.active {
  background: var(--bg-surface); color: var(--text-primary);
  border-color: var(--border-light);
  font-weight: 600;
}

/* ── Kanban Board ──────────────────────────────────────────────── */
.kanban-board {
  display: flex; gap: 16px; overflow-x: auto;
  padding-bottom: 8px; align-items: flex-start;
  /* hide scrollbar visually but allow scroll */
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.kanban-board::-webkit-scrollbar { height: 6px; }
.kanban-board::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.kanban-column {
  flex: 0 0 320px; /* fixed width columns */
  background: rgba(0,0,0, 0.15); /* slightly inset background */
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex; flex-direction: column;
  max-height: 75vh;
}
.kanban-column-header {
  padding: 12px 16px;
  font-size: 13px; font-weight: 600;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.kanban-column-count {
  background: var(--bg-surface);
  color: var(--text-secondary);
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 11px;
}
.kanban-column-body {
  padding: 12px; overflow-y: auto;
  display: flex; flex-direction: column;
}


.company-card-header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
}
.company-card-name {
  font-size: 14px; font-weight: 600;
  color: var(--text-primary);
}
.company-card-meta {
  font-size: 12px; color: var(--text-secondary);
  margin-top: 2px;
}

.score-badge {
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 13px; font-weight: 700;
  flex-shrink: 0;
  min-width: 36px; text-align: center;
}
.score-perfect { background: rgba(34,197,94,0.15); color: var(--score-perfect); }
.score-good    { background: rgba(234,179,8,0.15); color: var(--score-good); }
.score-possible{ background: rgba(249,115,22,0.15); color: var(--score-possible); }
.score-poor    { background: rgba(239,68,68,0.15); color: var(--score-poor); }

.company-card-reason {
  font-size: 12px; color: var(--text-muted);
  margin-top: 6px; font-style: italic;
}

/* ── Contact Chips ─────────────────────────────────────────────── */
.contacts-list {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-light);
  display: flex; flex-direction: column; gap: 6px;
}

.contact-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  font-size: 12px;
}
.contact-chip-icon {
  width: 24px; height: 24px;
  background: var(--accent-dim);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; flex-shrink: 0;
  color: var(--accent);
  font-weight: 600;
}
.contact-chip-info {
  display: flex; flex-direction: column; gap: 1px;
  min-width: 0;
}
.contact-chip-name {
  font-weight: 500; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.contact-chip-title {
  color: var(--text-muted); font-size: 11px;
}
.contact-chip-details {
  display: flex; gap: 10px;
  margin-left: auto; flex-shrink: 0;
}
.contact-chip-email, .contact-chip-phone {
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 11px;
}

/* ── Summary Card ──────────────────────────────────────────────── */
.summary-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-top: 8px;
}
.summary-stats {
  display: flex; gap: 20px; margin-bottom: 14px;
}
.summary-stat {
  display: flex; flex-direction: column; align-items: center;
}
.summary-stat-num {
  font-size: 20px; font-weight: 700; color: var(--text-primary);
}
.summary-stat-label {
  font-size: 11px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.03em;
}
.summary-actions {
  display: flex; gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* ── Input Bar ─────────────────────────────────────────────────── */
.input-bar {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 24px;
  background: linear-gradient(to top, var(--bg-deep) 80%, transparent);
  z-index: 100;
  display: flex;
  justify-content: center;
}
.input-wrapper {
  max-width: 800px; width: 100%;
  margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-elevated);
  border: 1px solid transparent; /* No border initially, like Gemini */
  border-radius: 30px; /* Pill shape */
  padding: 8px 16px;
  transition: border-color 0.15s ease;
}
.input-wrapper:focus-within { border-color: var(--accent); }

.chat-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  outline: none;
  min-height: 24px;
  max-height: 120px;
}
.chat-input::placeholder { color: var(--text-muted); }

.send-btn {
  width: 36px; height: 36px;
  background: var(--accent);
  border: none; border-radius: var(--radius-sm);
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
}
.send-btn:hover { background: #5b4bd6; }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Modal ─────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }

.modal-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 90%; max-width: 560px;
  max-height: 80vh;
  overflow-y: auto;
  transform: scale(0.95); transition: transform 0.2s ease;
}
.modal-overlay.open .modal-box { transform: scale(1); }

.modal-score-strip {
  height: 4px; border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.modal-score-strip.perfect { background: var(--score-perfect); }
.modal-score-strip.good    { background: var(--score-good); }
.modal-score-strip.possible{ background: var(--score-possible); }
.modal-score-strip.poor    { background: var(--score-poor); }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 8px;
}
.modal-title { font-size: 18px; font-weight: 600; }
.modal-close {
  width: 32px; height: 32px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary); cursor: pointer;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }

.modal-body { padding: 8px 20px 20px; }
.modal-field {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 6px 0;
  font-size: 13px;
}
.modal-field-icon { font-size: 14px; flex-shrink: 0; margin-top: 1px; }
.modal-field-value { color: var(--text-secondary); line-height: 1.4; }
.modal-field-value a { color: var(--accent); text-decoration: none; }
.modal-field-value a:hover { text-decoration: underline; }

.modal-description {
  font-size: 13px; color: var(--text-muted);
  line-height: 1.5; margin-top: 8px;
  padding: 10px; background: var(--bg-elevated);
  border-radius: var(--radius-sm);
}

.modal-contacts-title {
  font-size: 13px; font-weight: 600; color: var(--accent);
  margin: 14px 0 8px;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.modal-contact-item {
  padding: 8px 10px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  font-size: 12px;
}
.modal-contact-name { font-weight: 500; color: var(--text-primary); }
.modal-contact-title { color: var(--text-muted); margin-left: 6px; }
.modal-contact-detail {
  color: var(--text-secondary); margin-top: 3px;
  font-family: var(--font-mono); font-size: 11px;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex; gap: 8px;
}
.modal-footer .btn {
  font-size: 12px; padding: 6px 14px;
  text-decoration: none;
}

/* ── Company Selection Card (Apify Contact Discovery) ────────── */
.company-selection-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  margin-top: 12px;
}

.selection-list::-webkit-scrollbar { width: 6px; }
.selection-list::-webkit-scrollbar-track { background: transparent; }
.selection-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.selection-row:last-child { border-bottom: none; }

.selection-row input[type="checkbox"]:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.btn-sm {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-sm:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .msg { padding: 0 12px; }
  .status-msg { padding: 0 12px 0 48px; }
  .icp-grid { grid-template-columns: 1fr; }
  .summary-stats { flex-wrap: wrap; gap: 12px; }
  .contact-chip { flex-wrap: wrap; }
  .contact-chip-details { margin-left: 0; margin-top: 2px; }
  .brand-name { display: none; }
  .company-selection-card { padding: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
