/* ═══════════════════════════════════════════════════════════════
   LEAD MACHINE — Lead Pipeline & Conversion Tracking
   ═══════════════════════════════════════════════════════════════ */

/* ─── Lead Pipeline Cards ─── */
.lead-pipeline {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

.pipeline-stage {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  text-align: center;
  transition: all var(--duration-normal) var(--ease-default);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.pipeline-stage:hover {
  border-color: var(--border-default);
  transform: translateY(-2px);
}

.pipeline-stage::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
}

.pipeline-stage.new::before { background: var(--info); }
.pipeline-stage.contacted::before { background: var(--warning); }
.pipeline-stage.quoted::before { background: var(--purple); }
.pipeline-stage.converted::before { background: var(--success); }
.pipeline-stage.lost::before { background: var(--error); }

.pipeline-stage-icon {
  font-size: 1.5rem;
  margin-bottom: var(--space-2);
}

.pipeline-stage-name {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-1);
}

.pipeline-stage-count {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
}

.pipeline-stage-value {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-1);
}

/* ─── Lead Summary Cards ─── */
.lead-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

.lead-summary-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.lead-summary-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.lead-summary-icon.blue { background: var(--info-muted); }
.lead-summary-icon.green { background: var(--success-muted); }
.lead-summary-icon.yellow { background: var(--warning-muted); }
.lead-summary-icon.purple { background: var(--purple-muted); }

.lead-summary-content {
  flex: 1;
  min-width: 0;
}

.lead-summary-value {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
}

.lead-summary-label {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: 2px;
}

/* ─── Lead Table ─── */
.lead-table-wrap {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.lead-table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}

.lead-table-title {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.lead-table-actions {
  display: flex;
  gap: var(--space-2);
}

.lead-table-body {
  max-height: 400px;
  overflow-y: auto;
}

.lead-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 80px 80px 100px;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  align-items: center;
  transition: background var(--duration-fast);
  cursor: pointer;
}

.lead-row:hover {
  background: var(--bg-hover);
}

.lead-row:last-child {
  border-bottom: none;
}

.lead-row-header {
  background: var(--bg-elevated);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: default;
}

.lead-row-header:hover {
  background: var(--bg-elevated);
}

.lead-name {
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lead-contact {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: 2px;
}

.lead-source-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  color: var(--text-secondary);
}

.lead-source-badge.web { background: var(--info-muted); color: var(--info); }
.lead-source-badge.referral { background: var(--success-muted); color: var(--success); }
.lead-source-badge.facebook { background: var(--info-muted); color: #1877f2; }
.lead-source-badge.google { background: var(--warning-muted); color: var(--warning); }
.lead-source-badge.direct { background: var(--purple-muted); color: var(--purple); }
.lead-source-badge.partner { background: var(--accent-muted); color: var(--accent-text); }

.lead-stage-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  border-radius: var(--radius-full);
}

.lead-stage-badge.new { background: var(--info-muted); color: var(--info); }
.lead-stage-badge.contacted { background: var(--warning-muted); color: var(--warning); }
.lead-stage-badge.quoted { background: var(--purple-muted); color: var(--purple); }
.lead-stage-badge.converted { background: var(--success-muted); color: var(--success); }
.lead-stage-badge.lost { background: var(--error-muted); color: var(--error); }

/* ─── Lead Score ─── */
.lead-score {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.lead-score-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-elevated);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.lead-score-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width var(--duration-slow);
}

.lead-score-fill.high { background: var(--success); }
.lead-score-fill.medium { background: var(--warning); }
.lead-score-fill.low { background: var(--error); }

.lead-score-value {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  min-width: 28px;
  text-align: right;
}

/* ─── Source Performance Grid ─── */
.source-perf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-4);
}

.source-perf-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

.source-perf-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.source-perf-name {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  text-transform: capitalize;
}

.source-perf-rate {
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  color: var(--accent-text);
}

.source-perf-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
}

.source-perf-stat {
  text-align: center;
  padding: var(--space-2);
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
}

.source-perf-stat-value {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.source-perf-stat-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ─── Charts Section ─── */
.lead-charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.lead-chart-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

.lead-chart-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  margin-bottom: var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* ─── CSS Bar Charts ─── */
.lead-bar-chart {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  height: 140px;
  padding: var(--space-2) 0;
  gap: var(--space-2);
}

.lead-bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
}

.lead-bar {
  width: 100%;
  max-width: 40px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: var(--accent);
  transition: height var(--duration-slow);
  min-height: 4px;
}

.lead-bar-value {
  font-size: 10px;
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
}

.lead-bar-label {
  font-size: 10px;
  color: var(--text-muted);
}

/* ─── Source Pie/Donut Visual ─── */
.source-breakdown-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.source-breakdown-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.source-breakdown-dot {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

.source-breakdown-name {
  flex: 1;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  text-transform: capitalize;
}

.source-breakdown-count {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.source-breakdown-pct {
  font-size: var(--text-xs);
  color: var(--text-muted);
  min-width: 40px;
  text-align: right;
}

/* ─── Lead Detail Modal ─── */
.lead-detail-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all var(--duration-normal);
}

.lead-detail-modal.open {
  opacity: 1;
  visibility: visible;
}

.lead-detail-content {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  transform: scale(0.95);
  transition: transform var(--duration-normal);
}

.lead-detail-modal.open .lead-detail-content {
  transform: scale(1);
}

.lead-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
}

.lead-detail-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.lead-detail-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: var(--space-1);
}

.lead-detail-close:hover {
  color: var(--text-primary);
}

.lead-detail-body {
  padding: var(--space-5);
}

.lead-detail-section {
  margin-bottom: var(--space-5);
}

.lead-detail-section:last-child {
  margin-bottom: 0;
}

.lead-detail-section-title {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-3);
}

.lead-detail-field {
  display: flex;
  justify-content: space-between;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border-subtle);
}

.lead-detail-field:last-child {
  border-bottom: none;
}

.lead-detail-label {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.lead-detail-value {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
}

.lead-detail-actions {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
}

/* ─── Stage Selector ─── */
.stage-selector {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.stage-selector-btn {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--duration-fast);
}

.stage-selector-btn:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.stage-selector-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ─── Responsive ─── */
@media (max-width: 1200px) {
  .lead-pipeline {
    grid-template-columns: repeat(3, 1fr);
  }
  
  .lead-charts-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .lead-pipeline {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .lead-row {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2);
  }
  
  .lead-row-header {
    display: none;
  }
  
  .source-perf-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .lead-pipeline {
    grid-template-columns: 1fr;
  }
  
  .lead-summary-grid {
    grid-template-columns: 1fr 1fr;
  }
}
