/* ============================================================
   Ideal AI Client Database — app.css
   Dark theme: #0f0f11 bg / #6366f1 accent
   ============================================================ */

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

:root {
  --bg:          #0f0f11;
  --surface:     #17171a;
  --surface2:    #1f1f24;
  --surface3:    #28282f;
  --border:      #2a2a33;
  --text:        #e8e8f0;
  --text-dim:    #7a7a90;
  --text-muted:  #4a4a60;
  --accent:      #6366f1;
  --accent-dim:  #4547c0;
  --accent-glow: rgba(99,102,241,0.15);
  --green:       #22c55e;
  --yellow:      #f59e0b;
  --red:         #ef4444;
  --blue:        #3b82f6;
  --purple:      #a855f7;
  --radius:      10px;
  --radius-sm:   6px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Layout ──────────────────────────────────────────────── */

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────── */

#header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#header-logo {
  font-weight: 700;
  font-size: 15px;
  color: var(--accent);
  letter-spacing: -0.3px;
  white-space: nowrap;
}

#add-contact-btn {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s;
  margin-left: auto;
}
#add-contact-btn:hover { background: var(--accent-dim); }

#header-stats {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  flex: 1;
}

#header-stats span strong {
  color: var(--text);
  font-weight: 600;
}

/* ── Toolbar ──────────────────────────────────────────────── */

#toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

#search-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  padding: 6px 10px;
  width: 220px;
  outline: none;
  transition: border-color 0.2s;
}
#search-box::placeholder { color: var(--text-muted); }
#search-box:focus { border-color: var(--accent); }

#stage-filter {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  padding: 6px 10px;
  outline: none;
  cursor: pointer;
}

#stage-filter option { background: var(--surface2); }

.toolbar-spacer { flex: 1; }

#refresh-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 12px;
  padding: 6px 12px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
#refresh-btn:hover { border-color: var(--accent); color: var(--text); }
#refresh-btn:disabled { opacity: 0.5; cursor: not-allowed; }

#last-updated {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Source filter tabs ──────────────────────────────────── */

#source-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.source-tab {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  transition: all 0.15s;
  white-space: nowrap;
}
.source-tab:hover { border-color: var(--accent); color: var(--text); }
.source-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Person filter tabs ──────────────────────────────────── */

#person-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.person-tab {
  padding: 3px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  transition: all 0.15s;
  white-space: nowrap;
}
.person-tab:hover { border-color: var(--accent); color: var(--text); }
.person-tab[data-person="jeremiah"].active {
  background: rgba(99,102,241,0.2);
  border-color: #6366f1;
  color: #a5b4fc;
}
.person-tab[data-person="lauren"].active {
  background: rgba(244,114,182,0.2);
  border-color: #f472b6;
  color: #f9a8d4;
}
.person-tab[data-person="all"].active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Person badges (row indicator) ──────────────────────── */

.person-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  font-size: 9px;
  font-weight: 700;
  margin-left: 5px;
  vertical-align: middle;
  flex-shrink: 0;
}

.badge-jeremiah { background: rgba(99,102,241,0.15); color: #a5b4fc; }
.badge-lauren   { background: rgba(244,114,182,0.15); color: #f9a8d4; }

/* ── Source badges ───────────────────────────────────────── */

.source-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
  margin-left: 4px;
  vertical-align: middle;
}

.source-cold-email  { background: rgba(122,122,144,0.15); color: #a1a1c0; }
.source-demo        { background: rgba(59,130,246,0.15);  color: #93c5fd; }
.source-warm        { background: rgba(34,197,94,0.15);   color: #4ade80; }
.source-meetup      { background: rgba(168,85,247,0.15);  color: #d8b4fe; }
.source-aria        { background: rgba(168,85,247,0.12);  color: #d8b4fe; border: 1px solid rgba(168,85,247,0.3); }
.source-chloe       { background: rgba(34,197,94,0.12);   color: #86efac; border: 1px solid rgba(34,197,94,0.3); }

/* ── Meetup breakdown group headers ─────────────────────── */

.meetup-group-header-row { background: transparent; }
.meetup-group-header-row:hover { background: transparent; }

.meetup-group-header-cell {
  padding: 0 !important;
}

.meetup-group-header {
  padding: 12px 20px 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #6366f1;
  border-bottom: 1px solid rgba(99,102,241,0.15);
  border-top: 1px solid rgba(99,102,241,0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
  background: rgba(99,102,241,0.04);
}

.meetup-group-stats {
  font-size: 11px;
  font-weight: 500;
  color: #64748b;
  text-transform: none;
  letter-spacing: 0;
}

/* ── Main scroll area ────────────────────────────────────── */

#main {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

/* ── Loading / error ─────────────────────────────────────── */

#loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 20px;
  color: var(--text-dim);
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#error-msg {
  display: none;
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius);
  padding: 16px 20px;
  color: #fca5a5;
  font-size: 13px;
  margin-bottom: 16px;
}

/* ── Pipeline summary bar ────────────────────────────────── */

#pipeline-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.pipeline-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
}
.pipeline-pill:hover { opacity: 0.85; }
.pipeline-pill.active { border-color: currentColor; }
.pipeline-pill-count {
  background: rgba(0,0,0,0.25);
  border-radius: 10px;
  padding: 0 5px;
  font-size: 10px;
  font-weight: 700;
}

/* ── Table ───────────────────────────────────────────────── */

#contacts-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead tr {
  background: var(--surface2);
}

thead th {
  padding: 10px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

thead th.sortable {
  cursor: pointer;
  user-select: none;
}
thead th.sortable:hover { color: var(--text); }
thead th.sort-asc::after { content: " ↑"; color: var(--accent); }
thead th.sort-desc::after { content: " ↓"; color: var(--accent); }

tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
tbody tr.expanded { background: var(--surface2); }

td {
  padding: 10px 12px;
  vertical-align: middle;
}

.td-name {
  min-width: 140px;
  max-width: 200px;
}

.contact-name {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 190px;
}

.practice-name {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 190px;
  margin-top: 1px;
}

.td-stage { white-space: nowrap; }
.td-intent { white-space: nowrap; }
.td-activity { white-space: nowrap; color: var(--text-dim); font-size: 12px; }
.td-score { text-align: center; }
.td-actions { white-space: nowrap; text-align: right; }

/* ── Stage badges ────────────────────────────────────────── */

.stage-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.stage-won          { background: rgba(34,197,94,0.15);  color: #4ade80; }
.stage-not-a-fit    { background: rgba(239,68,68,0.12);  color: #f87171; }
.stage-proposal-sent{ background: rgba(99,102,241,0.15); color: #a5b4fc; }
.stage-booked       { background: rgba(59,130,246,0.15); color: #93c5fd; }
.stage-human-handling{ background: rgba(245,158,11,0.15); color: #fbbf24; }
.stage-call-now     { background: rgba(239,68,68,0.2);   color: #fca5a5; border: 1px solid rgba(239,68,68,0.4); }
.stage-chloe-called { background: rgba(34,197,94,0.12);   color: #86efac; }
.stage-aria-called  { background: rgba(168,85,247,0.12); color: #d8b4fe; }
.stage-outreach     { background: rgba(122,122,144,0.12); color: #a1a1c0; }
.stage-lead         { background: rgba(122,122,144,0.08); color: #7a7a90; }

/* ── Intent badges ───────────────────────────────────────── */

.intent-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.intent-booked       { background: rgba(34,197,94,0.15);  color: #4ade80; }
.intent-interested   { background: rgba(245,158,11,0.15); color: #fbbf24; }
.intent-undecided    { background: rgba(122,122,144,0.12); color: #9ca3af; }
.intent-not_interested{ background: rgba(239,68,68,0.12); color: #f87171; }

/* ── Attention dot ───────────────────────────────────────── */

.attention-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  flex-shrink: 0;
}
.attention-alert { background: var(--red); box-shadow: 0 0 6px var(--red); }
.attention-warn  { background: var(--yellow); }
.attention-ok    { background: transparent; }

/* ── Interest score ──────────────────────────────────────── */

.score-pill {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
}

/* ── Expand row ──────────────────────────────────────────── */

.expand-row td {
  padding: 0;
  background: var(--surface);
}

.expand-inner {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.detail-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.detail-card-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 4px;
}

.detail-card-value {
  font-size: 13px;
  color: var(--text);
  word-break: break-word;
}

.detail-card-value.dim { color: var(--text-dim); }
.detail-card-value.accent { color: var(--accent); }

.transcript-box {
  grid-column: 1 / -1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.6;
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
}

.expand-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-sm {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid var(--border);
  background: var(--surface3);
  color: var(--text-dim);
  transition: all 0.15s;
}
.btn-sm:hover { border-color: var(--accent); color: var(--text); }
.btn-sm.accent { border-color: var(--accent); color: var(--accent); background: var(--accent-glow); }

/* ── Tags ────────────────────────────────────────────────── */

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tag {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--surface3);
  border: 1px solid var(--border);
  color: var(--text-dim);
}

/* ── Empty state ─────────────────────────────────────────── */

#empty-state {
  display: none;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}
#empty-state p { margin-top: 8px; font-size: 13px; }

/* ── Scrollbar ───────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Responsive ──────────────────────────────────────────── */

@media (max-width: 768px) {
  #header-stats { display: none; }
  #main { padding: 12px; }
  .td-activity, .td-score, .td-actions .btn-sm:not(.mobile-show) { display: none; }
  #search-box { width: 160px; }
  #source-tabs { gap: 4px; padding: 6px 12px; }
  .source-tab { font-size: 11px; padding: 3px 9px; }
  #person-tabs { gap: 4px; padding: 4px 12px; }
  .person-tab { font-size: 10px; padding: 2px 8px; }
}
