:root {
  --bg-primary: #090d14;
  --bg-secondary: #111827;
  --bg-card: #162032;
  --bg-hover: #1e293b;
  --bg-active: #24344d;
  --border-color: #1f293d;
  --border-highlight: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-cyan: #06b6d4;
  --accent-cyan-glow: rgba(6, 182, 212, 0.15);
  --accent-purple: #8b5cf6;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -2px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.6), 0 4px 6px -4px rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Header */
.app-header {
  height: 60px;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  z-index: 20;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  font-size: 1.4rem;
}

.brand-text h1 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.brand-badge {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent-cyan);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid transparent;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, #06b6d4, #3b82f6);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(6, 182, 212, 0.3);
}

.btn-primary:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border-color);
}

.btn-secondary:hover {
  background-color: var(--bg-hover);
  border-color: var(--border-highlight);
}

.btn-sm {
  padding: 4px 8px;
  font-size: 0.75rem;
}

.btn-icon-only {
  padding: 6px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
}

.btn-icon-only:hover {
  color: var(--text-primary);
  background-color: var(--bg-hover);
}

.btn-danger-hover:hover {
  background-color: rgba(244, 63, 94, 0.15);
  color: var(--accent-rose);
  border-color: var(--accent-rose);
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Main Container */
.main-container {
  display: flex;
  flex: 1;
  height: calc(100vh - 60px);
  overflow: hidden;
  position: relative;
}

/* Left Sidebar */
.sidebar {
  width: 320px;
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.25s ease;
  z-index: 15;
}

.sidebar-search {
  padding: 12px 14px 8px;
}

.sidebar-search input {
  width: 100%;
  padding: 8px 12px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.85rem;
}

.sidebar-search input:focus {
  outline: none;
  border-color: var(--accent-cyan);
}

.filter-tabs {
  display: flex;
  padding: 0 10px 8px;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.filter-tabs::-webkit-scrollbar {
  display: none;
}

.filter-tab {
  padding: 4px 8px;
  font-size: 0.72rem;
  font-weight: 600;
  background: none;
  border: 1px solid transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
}

.filter-tab.active {
  background-color: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border-color);
}

.leads-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.lead-item {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background-color: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.lead-item:hover {
  background-color: var(--bg-card);
}

.lead-item.active {
  background-color: var(--bg-card);
  border-color: var(--accent-cyan);
  box-shadow: 0 0 12px var(--accent-cyan-glow);
}

.lead-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.lead-item-handle {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text-primary);
}

.lead-item-score {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 12px;
  background-color: rgba(6, 182, 212, 0.15);
  color: var(--accent-cyan);
}

.score-hot {
  background-color: rgba(245, 158, 11, 0.2);
  color: var(--accent-amber);
}

.score-won {
  background-color: rgba(16, 185, 129, 0.2);
  color: var(--accent-emerald);
}

.lead-item-podcast {
  font-size: 0.78rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lead-item-snippet {
  font-size: 0.75rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Chat Workspace */
.chat-workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-primary);
  overflow: hidden;
}

.empty-state {
  margin: auto;
  text-align: center;
  max-width: 440px;
  padding: 24px;
}

.empty-icon {
  font-size: 3.5rem;
  margin-bottom: 12px;
}

.empty-state h2 {
  font-size: 1.25rem;
  margin-bottom: 8px;
}

.empty-state p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 20px;
  line-height: 1.5;
}

.lead-active-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

/* Lead Header */
.lead-header {
  padding: 10px 16px;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.lead-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.lead-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
}

.lead-handle-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lead-handle-row h2 {
  font-size: 1rem;
  font-weight: 700;
}

.badge {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 4px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--accent-cyan);
}

.lead-subdetails {
  font-size: 0.78rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.dot-separator {
  color: var(--text-muted);
}

.lead-header-actions {
  display: flex;
  gap: 6px;
}

/* Conversion Card */
.conversion-card {
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.conversion-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.conversion-metric {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
}

.conversion-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.conversion-score-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
}

.conversion-score {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--accent-cyan);
}

.conversion-tag {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent-amber);
}

.conversion-bar-container {
  flex: 1;
  height: 8px;
  background-color: var(--bg-primary);
  border-radius: 4px;
  overflow: hidden;
}

.conversion-bar {
  height: 100%;
  background: linear-gradient(90deg, #06b6d4, #10b981);
  border-radius: 4px;
  transition: width 0.4s ease;
}

.conversion-rationale {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.3;
}

.signals-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
}

.signal-tag {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}

/* Split Layout */
.chat-copilot-split {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.thread-pane {
  flex: 1.1;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-color);
  background-color: var(--bg-primary);
  overflow: hidden;
}

.copilot-pane {
  flex: 1.2;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-secondary);
  overflow: hidden;
}

.pane-title {
  padding: 8px 14px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
}

.copilot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-right: 12px;
  border-bottom: 1px solid var(--border-color);
}

.copilot-header .pane-title {
  border-bottom: none;
  color: var(--accent-cyan);
}

/* Messages Container */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg-bubble {
  max-width: 80%;
  padding: 9px 13px;
  border-radius: var(--radius-lg);
  font-size: 0.88rem;
  line-height: 1.4;
  position: relative;
  word-break: break-word;
}

.msg-inbound {
  align-self: flex-start;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-bottom-left-radius: var(--radius-sm);
}

.msg-outbound {
  align-self: flex-end;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #ffffff;
  border-bottom-right-radius: var(--radius-sm);
}

.msg-time {
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.6);
  margin-top: 4px;
  text-align: right;
}

.msg-inbound .msg-time {
  color: var(--text-muted);
}

/* Message Composer */
.message-composer {
  padding: 10px 12px;
  background-color: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.composer-type-switch {
  display: flex;
  gap: 6px;
}

.type-btn {
  padding: 4px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.type-btn.active {
  background-color: var(--bg-card);
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
}

.composer-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.composer-input-row textarea {
  flex: 1;
  padding: 8px 12px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.85rem;
  resize: none;
  font-family: inherit;
}

.composer-input-row textarea:focus {
  outline: none;
  border-color: var(--accent-cyan);
}

/* Copilot Drafts */
.drafts-container {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.draft-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: all 0.15s ease;
}

.draft-card:hover {
  border-color: var(--border-highlight);
}

.draft-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.draft-tone {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 0.82rem;
}

.tone-warm { color: #f59e0b; }
.tone-direct { color: #06b6d4; }
.tone-low_pressure { color: #10b981; }

.draft-text {
  font-size: 0.86rem;
  line-height: 1.45;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  user-select: text;
}

.draft-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

/* Loader */
.drafts-loading {
  padding: 24px;
  display: flex;
  justify-content: center;
}

.ai-loader {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent-cyan);
  font-size: 0.85rem;
  font-weight: 600;
}

.loader-pulse {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: var(--accent-cyan);
  animation: pulse 1s infinite alternate;
}

@keyframes pulse {
  0% { transform: scale(0.8); opacity: 0.5; }
  100% { transform: scale(1.3); opacity: 1; }
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  width: 90%;
  max-width: 480px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  z-index: 55;
  overflow: hidden;
}

.modal-xl {
  max-width: 900px;
}

.modal-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 1rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-body.p-0 {
  padding: 0;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-group input, .form-group textarea {
  padding: 8px 12px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-family: inherit;
}

.form-group input:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--accent-cyan);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

/* CRM Table */
.table-wrapper {
  overflow-x: auto;
  max-height: 60vh;
}

.crm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  text-align: left;
}

.crm-table th {
  background-color: var(--bg-card);
  padding: 10px 12px;
  font-weight: 700;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.crm-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-secondary);
  white-space: nowrap;
}

.crm-table tr:hover td {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.hidden {
  display: none !important;
}

/* Responsive Mobile Layout */
@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 280px;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .chat-copilot-split {
    flex-direction: column;
  }

  .thread-pane {
    flex: 1;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }

  .copilot-pane {
    flex: 1;
    max-height: 45vh;
  }

  .desktop-only {
    display: none;
  }
}

@media (min-width: 769px) {
  .mobile-only {
    display: none;
  }
}
