/* =========================
   LEAD WORKSPACE
========================= */

.lead-workspace-container,
.lead-workspace,
.lead-workspace-mode {
  width: 100%;
  max-width: none;
  margin: 0;
}

.lead-workspace-container,
.lead-workspace {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.lead-workspace-mode {
  padding: 0 24px 120px;
}

/* =========================
   BACK / HEADER
========================= */

.lead-back-button,
.lead-workspace-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 16px;
}

.lead-workspace-header {
  margin-bottom: 8px;
}

.lead-workspace-header .btn {
  padding: 14px 20px;
  border-radius: 18px;
  font-size: 0.95rem;
}

.lead-header {
  background: rgba(15, 23, 42, 0.64);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 22px;
  backdrop-filter: blur(14px);
  padding: 24px;
}

.lead-header-container {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 28px;
}

.lead-header-info {
  flex: 1;
  min-width: 0;
}

.lead-company-name {
  margin: 0;
  color: #ffffff;
  font-size: 34px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.5px;
}

.lead-header-meta,
.lead-contact-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 12px;
  color: #cbd5e1;
}

.lead-meta-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #cbd5e1;
  font-size: 13px;
}

.lead-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* =========================
   KPI STRIP
========================= */

.lead-kpi-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
  width: 100%;
}

.lead-kpi-item {
  position: relative;
  overflow: hidden;
  padding: 18px;
  text-align: center;
  background: rgba(20, 30, 48, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 16px;
  backdrop-filter: blur(12px);
}

.lead-kpi-item::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.14),
    transparent
  );
}

.lead-kpi-label {
  margin-bottom: 8px;
  color: #94a3b8;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.lead-kpi-value {
  color: #f8fafc;
  font-size: 24px;
  font-weight: 800;
  line-height: 1.1;
}

/* =========================
   MAIN LAYOUT
========================= */

.lead-main-layout,
.lead-main-left,
.lead-main-right {
  display: none;
}

.lead-workspace-main,
.lead-top-grid {
  display: grid;
  grid-template-columns:
    minmax(0, 1fr)
    minmax(520px, 1.15fr);
  gap: 18px;
  align-items: stretch;
}

/* =========================
   SHARED PANELS
========================= */

.lead-conversation-panel,
.lead-activity-panel,
.lead-ai-workspace,
.lead-context-panel {
  min-width: 0;
  background: rgba(15, 23, 42, 0.64);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 18px;
  backdrop-filter: blur(14px);
  padding: 20px;
}

.lead-conversation-panel {
  min-height: 520px;
}

.lead-activity-panel {
  min-height: 520px;
  max-height: 520px;
}

.lead-conversation-panel {
  display: flex;
  flex-direction: column;
}

.lead-activity-panel {
  display: flex;
  flex-direction: column;
}

.lead-ai-workspace {
  min-height: 260px;
  width: 100%;
}

.lead-context-panel {
  min-height: 220px;
}

.lead-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.lead-panel-header h3,
.lead-conversation-panel .detail-section-header h3,
.lead-activity-panel .detail-section-header h3 {
  margin: 0;
  color: #f8fafc;
  font-size: 18px;
  font-weight: 700;
}

/* =========================
   CONVERSATION
========================= */

.lead-conversation-list,
.conversation-wrapper,
.messages-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  padding-right: 6px;
}

.lead-conversation-list,
.conversation-wrapper {
  max-height: 420px;
}

.lead-conversation-list::-webkit-scrollbar,
.conversation-wrapper::-webkit-scrollbar {
  width: 7px;
}

.lead-conversation-list::-webkit-scrollbar-thumb,
.conversation-wrapper::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
}

.lead-conversation-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.lead-conversation-item.outbound {
  flex-direction: row-reverse;
  justify-content: flex-end;
}

.lead-conversation-avatar {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: rgba(59, 130, 246, 0.20);
  color: #93c5fd;
  font-size: 13px;
  font-weight: 800;
}

.lead-conversation-item.inbound .lead-conversation-avatar {
  background: rgba(168, 85, 247, 0.20);
  color: #d8b4fe;
}

.lead-conversation-content {
  flex: 1;
  max-width: 86%;
}

.lead-conversation-header,
.conversation-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.lead-conversation-sender,
.conversation-subject {
  color: #e2e8f0;
  font-size: 12px;
  font-weight: 700;
}

.lead-conversation-time {
  color: #64748b;
  font-size: 11px;
}

.lead-conversation-subject {
  margin-bottom: 5px;
  color: #e2e8f0;
  font-size: 12px;
  font-weight: 700;
}

.lead-conversation-body,
.conversation-body {
  color: #dbeafe;
  font-size: 13px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}

.conversation-message,
.message-item {
  display: grid;
  gap: 10px;
  width: 100%;
  padding: 16px 18px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.10);
}

.conversation-message.inbound {
  align-self: flex-start;
}

.conversation-message.outbound {
  align-self: flex-end;
}

.lead-conversation-input {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.lead-input-field {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.10);
  color: #e2e8f0;
  font-size: 13px;
}

/* =========================
   ACTIVITY
========================= */

.lead-timeline,
.activity-timeline,
.activity-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  max-height: 620px;
}

.lead-timeline {
  margin-top: 4px;
}

.lead-timeline-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lead-timeline-label {
  padding-left: 2px;
  color: #64748b;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.lead-timeline-item,
.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.activity-item {
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.10);
}

.lead-timeline-dot {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  margin-top: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.16);
  border: 2px solid rgba(59, 130, 246, 0.34);
  font-size: 12px;
}

.lead-timeline-content {
  flex: 1;
  min-width: 0;
}

.lead-timeline-title,
.activity-type {
  color: #e2e8f0;
  font-size: 12px;
  font-weight: 700;
}

.lead-timeline-text,
.activity-text,
.activity-item p {
  margin: 0;
  color: #cbd5e1;
  font-size: 12px;
  line-height: 1.45;
  word-break: break-word;
}

.activity-header,
.activity-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 6px;
}

.activity-date,
.activity-top small {
  color: #94a3b8;
  font-size: 12px;
}

/* =========================
   AI WORKSPACE
========================= */

.lead-ai-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 12px 0 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.lead-ai-tab {
  margin-bottom: -10px;
  padding: 8px 12px;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: #94a3b8;
  border-radius: 8px 8px 0 0;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.lead-ai-tab:hover,
.lead-ai-tab.active {
  color: #93c5fd;
  border-bottom-color: #3b82f6;
}

.lead-ai-content,
.lead-ai-composer {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lead-ai-status {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  color: #94a3b8;
  font-size: 11px;
}

.lead-ai-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 7px;
  background: rgba(34, 197, 94, 0.15);
  color: #86efac;
  font-size: 11px;
  font-weight: 700;
}

.lead-ai-input,
.lead-ai-body {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.10);
  color: #e2e8f0;
  font-size: 12px;
}

.lead-ai-body {
  min-height: 110px;
  max-height: 180px;
  resize: vertical;
  font-family: inherit;
  line-height: 1.5;
}

.lead-ai-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#leadAiTabContent {
  margin-top: 16px;
}

/* =========================
   AI AUTOMATION CONTROL
========================= */

.lead-ai-automation-control {
  display: grid;
  gap: 12px;
  margin: 0 0 16px;
  padding: 14px;
  border-radius: 14px;
  background: rgba(30, 41, 59, 0.62);
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.lead-ai-automation-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.lead-ai-automation-copy {
  flex: 1;
  min-width: 0;
}

.lead-ai-automation-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 5px;
}

.lead-ai-automation-title strong {
  color: #f8fafc;
  font-size: 13px;
  font-weight: 800;
}

.lead-ai-automation-control .lead-analysis-subtitle {
  max-width: 720px;
  color: #94a3b8;
  font-size: 11px;
  line-height: 1.5;
}

.lead-ai-automation-actions {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: 8px;
}

.lead-ai-automation-actions .lead-stage-select {
  min-width: 138px;
  padding: 8px 10px;
  border-radius: 9px;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #e2e8f0;
  font-size: 12px;
}

.lead-ai-automation-actions .btn {
  min-height: 34px;
  padding: 8px 12px;
  border-radius: 9px;
  font-size: 12px;
}

.lead-ai-automation-control .lead-analysis-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.lead-ai-automation-control .lead-analysis-meta span {
  padding: 5px 8px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.04);
  color: #94a3b8;
  font-size: 10px;
  font-weight: 700;
}

.lead-ai-automation-control.is-active {
  background: rgba(22, 101, 52, 0.12);
  border-color: rgba(34, 197, 94, 0.30);
}

.lead-ai-automation-control.is-active .lead-ai-badge {
  background: rgba(34, 197, 94, 0.18);
  color: #86efac;
}

.lead-ai-automation-control.is-manual {
  background: rgba(146, 64, 14, 0.10);
  border-color: rgba(245, 158, 11, 0.26);
}

.lead-ai-automation-control.is-manual .lead-ai-badge {
  background: rgba(245, 158, 11, 0.16);
  color: #fcd34d;
}

.lead-ai-automation-control.is-blocked {
  background: rgba(127, 29, 29, 0.10);
  border-color: rgba(248, 113, 113, 0.24);
}

.lead-ai-automation-control.is-blocked .lead-ai-badge {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
}

.lead-ai-automation-control.is-error {
  background: rgba(127, 29, 29, 0.14);
  border-color: rgba(244, 63, 94, 0.30);
}

.lead-ai-automation-control.is-error .lead-ai-badge {
  background: rgba(244, 63, 94, 0.17);
  color: #fda4af;
}

/* =========================
   CONTEXT
========================= */

.lead-context-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 12px 0;
}

.lead-context-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.lead-context-card-full {
  grid-column: 1 / -1;
}

.lead-context-label {
  color: #64748b;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.lead-context-value {
  color: #cbd5e1;
  font-size: 12px;
  line-height: 1.45;
  word-break: break-word;
}

.lead-recommendation {
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(59, 130, 246, 0.16);
}

.lead-recommendation-title {
  margin-bottom: 4px;
  color: #93c5fd;
  font-size: 12px;
  font-weight: 700;
}

.lead-recommendation-text {
  color: #cbd5e1;
  font-size: 12px;
  line-height: 1.45;
}

/* =========================
   DETAIL / LEGACY SUPPORT
========================= */

.lead-detail-header {
  margin-bottom: 24px;
}

.lead-detail-header h3 {
  margin: 0;
  font-size: 2.2rem;
  line-height: 1.15;
}

.lead-page-copy {
  max-width: 1000px;
  color: #cbd5e1;
  font-size: 1rem;
  line-height: 1.7;
}

.lead-detail-empty {
  flex: 1;
}

.lead-detail-panel {
  flex: 1;
  width: 100%;
  min-height: 0;
  padding: 24px;
  overflow-y: auto;
  overflow-x: hidden;
}

.lead-detail-content {
  width: 100%;
  max-width: none;
  margin: 0;
  display: block;
}

.lead-detail-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  flex-wrap: wrap;
}

.lead-detail-top h3 {
  margin: 0 0 10px;
  font-size: 2rem;
  line-height: 1.2;
}

.lead-stage {
  margin: 0 0 10px;
  color: #dbeafe;
}

.lead-badge,
.lead-stage-badge {
  align-self: flex-start;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.16);
  color: #dcfce7;
  font-size: 0.82rem;
  font-weight: 800;
}

.lead-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
  width: 100%;
}

.info-box,
.meta-card {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 110px;
  padding: 20px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.10);
}

.info-box span,
.meta-card span {
  color: #94a3b8;
  font-size: 0.82rem;
}

.info-box strong,
.meta-card strong {
  color: #ffffff;
  font-size: 0.94rem;
  word-break: break-word;
}

.lead-quick-actions,
.lead-actions,
.stage-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.stage-actions button {
  flex: 1 1 auto;
  min-width: 120px;
}

.danger-zone {
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.10);
}

.danger-zone .btn,
#deleteLeadBtn {
  background: rgba(244, 63, 94, 0.12);
  color: #fecdd3;
  border: 1px solid rgba(244, 63, 94, 0.24);
}

/* =========================
   EMPTY STATE
========================= */

.lead-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 48px 24px;
  text-align: center;
  color: #94a3b8;
}

.lead-empty-icon {
  font-size: 42px;
  opacity: 0.45;
}

.lead-empty-text {
  color: #cbd5e1;
  font-size: 14px;
  font-weight: 700;
}

.lead-empty-hint {
  max-width: 260px;
  color: #64748b;
  font-size: 12px;
}

/* =========================
   BUTTON OVERRIDES
========================= */

.lead-conversation-input .btn,
.lead-ai-actions .btn {
  padding: 8px 12px;
  border-radius: 9px;
  font-size: 12px;
}

/* =========================
   RESPONSIVE
========================= */

@media (max-width: 1400px) {
  .lead-kpi-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .lead-workspace-main,
  .lead-top-grid,
  .lead-bottom-grid {
    grid-template-columns: 1fr;
  }

  .lead-conversation-panel,
  .lead-activity-panel {
    min-height: 520px;
  }
}

@media (max-width: 768px) {
  .lead-workspace-container,
  .lead-workspace {
    gap: 16px;
  }

  .lead-workspace-mode {
    padding: 0 12px 80px;
  }

  .lead-header {
    padding: 18px;
  }

  .lead-header-container {
    flex-direction: column;
    gap: 16px;
  }

  .lead-company-name {
    font-size: 26px;
  }

  .lead-kpi-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .lead-conversation-panel,
  .lead-activity-panel,
  .lead-ai-workspace,
  .lead-context-panel {
    padding: 16px;
  }

  .lead-conversation-panel,
  .lead-activity-panel {
    min-height: 440px;
  }

  .lead-context-grid {
    grid-template-columns: 1fr;
  }

  .lead-conversation-content {
    max-width: 100%;
  }

  .lead-conversation-input {
    flex-direction: column;
  }

  .lead-ai-automation-header {
    flex-direction: column;
    align-items: stretch;
  }

  .lead-ai-automation-actions {
    width: 100%;
  }

  .lead-ai-automation-actions .lead-stage-select {
    flex: 1;
    min-width: 0;
  }
}