*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #f5f6f8; color: #1a1d23; }

.hidden { display: none !important; }
.loading { color: #6b7280; padding: 24px 0; }
.error { color: #dc2626; padding: 24px 0; }
.empty-state { color: #6b7280; padding: 16px 0; font-size: 0.9rem; }
.empty-state-page { padding: 40px 0; color: #6b7280; }
.link { color: #2563eb; text-decoration: none; font-size: 0.875rem; }
.link:hover { text-decoration: underline; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
code { font-family: 'Menlo', 'Monaco', monospace; background: #f3f4f6; padding: 2px 5px; border-radius: 3px; font-size: 0.85em; }

/* Login */
.login-overlay { position: fixed; inset: 0; background: #f5f6f8; display: flex; align-items: center; justify-content: center; z-index: 100; }
.login-card { background: white; padding: 40px; border-radius: 12px; box-shadow: 0 4px 24px rgba(0,0,0,0.08); width: 100%; max-width: 400px; }
.login-card h1 { font-size: 1.5rem; margin-bottom: 8px; }
.login-card > p { color: #6b7280; margin-bottom: 24px; font-size: 0.9rem; }
#login-form .form-group { margin-bottom: 16px; }
#login-form label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 6px; }
#login-form input { width: 100%; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 0.9rem; }
#login-form .btn { width: 100%; padding: 10px; font-size: 0.9rem; margin-top: 4px; }
.error-msg { font-size: 0.875rem; color: #dc2626; margin-bottom: 12px; }

/* App shell */
.app-shell { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar { width: 240px; background: #1a1d23; color: white; display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-header { padding: 24px 20px 16px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.business-name { font-weight: 600; font-size: 0.95rem; word-break: break-word; }
.sidebar-nav { flex: 1; padding: 12px 0; }
.nav-link { display: block; padding: 10px 20px; color: rgba(255,255,255,0.7); text-decoration: none; font-size: 0.875rem; transition: background 0.15s, color 0.15s; cursor: pointer; }
.nav-link:hover { background: rgba(255,255,255,0.06); color: white; }
.nav-link--active { background: rgba(255,255,255,0.1) !important; color: white !important; }
.nav-link--disabled { opacity: 0.4; pointer-events: none; }
.badge { display: inline-block; font-size: 0.65rem; background: rgba(255,255,255,0.15); padding: 1px 6px; border-radius: 10px; margin-left: 6px; vertical-align: middle; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.08); }

/* Content area */
.content-area { flex: 1; padding: 32px 40px; overflow-y: auto; max-width: 1100px; }
.page-header { margin-bottom: 24px; }
.page-header h1 { font-size: 1.5rem; font-weight: 600; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; padding: 8px 16px; border-radius: 6px; font-size: 0.875rem; font-weight: 500; cursor: pointer; border: none; transition: opacity 0.15s, background 0.15s; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: #2563eb; color: white; }
.btn-primary:hover:not(:disabled) { background: #1d4ed8; }
.btn-secondary { background: white; color: #374151; border: 1px solid #d1d5db; }
.btn-secondary:hover:not(:disabled) { background: #f9fafb; }
.btn-ghost { background: transparent; color: rgba(255,255,255,0.7); width: 100%; justify-content: flex-start; padding: 8px 0; font-size: 0.875rem; }
.btn-ghost:hover { color: white; }
.btn-danger { background: #dc2626; color: white; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }

/* Forms */
.config-form { max-width: 640px; background: white; padding: 28px; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
.form-group { margin-bottom: 20px; }
.form-group label, label.toggle-label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 6px; color: #374151; }
label.toggle-label { display: flex; align-items: center; gap: 8px; font-weight: normal; cursor: pointer; margin-bottom: 0; }
input[type="text"], input[type="password"], input[type="date"], input[type="email"], textarea, .form-group input[type="text"] { width: 100%; padding: 8px 12px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 0.875rem; color: #1a1d23; background: white; }
input[type="color"] { padding: 2px 4px; height: 36px; width: 80px; cursor: pointer; border: 1px solid #d1d5db; border-radius: 6px; }
textarea { resize: vertical; font-family: inherit; }
.field-hint { font-size: 0.8rem; color: #6b7280; margin-top: 6px; }
.form-actions { display: flex; align-items: center; gap: 12px; margin-top: 24px; }
.save-status { font-size: 0.875rem; }
.save-status.success { color: #16a34a; }
.save-status.error { color: #dc2626; }
.radio-group { display: flex; gap: 20px; }
.radio-group label { display: flex; align-items: center; gap: 6px; font-weight: normal; cursor: pointer; margin-bottom: 0; }
.read-only-value { font-size: 0.9rem; color: #374151; padding: 8px 0; }

/* Stat cards */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 32px; }
.stat-card { background: white; padding: 20px; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
.stat-label { font-size: 0.75rem; color: #6b7280; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }
.stat-value { font-size: 2rem; font-weight: 700; color: #1a1d23; }

/* Tables */
.section { background: white; padding: 24px; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.section-header h2 { font-size: 1rem; font-weight: 600; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.data-table th { text-align: left; padding: 10px 12px; border-bottom: 2px solid #e5e7eb; font-weight: 600; color: #374151; white-space: nowrap; }
.data-table td { padding: 10px 12px; border-bottom: 1px solid #f3f4f6; color: #4b5563; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f9fafb; }

/* Filter / pagination */
.filter-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; background: white; padding: 16px; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
.filter-bar label { display: flex; align-items: center; gap: 6px; font-size: 0.875rem; font-weight: normal; margin-bottom: 0; }
.filter-bar input[type="date"] { width: auto; }
.pagination { display: flex; align-items: center; gap: 12px; margin-top: 16px; font-size: 0.875rem; color: #6b7280; }
#leads-table-container { background: white; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); overflow: hidden; min-height: 60px; padding: 0 0 8px; }

/* Embed */
.embed-section { background: white; padding: 28px; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); max-width: 640px; }
.embed-section > p { margin-bottom: 16px; font-size: 0.9rem; color: #4b5563; }
.code-block { background: #f8f9fa; border: 1px solid #e5e7eb; border-radius: 6px; padding: 16px; font-family: 'Menlo','Monaco',monospace; font-size: 0.8rem; margin-bottom: 16px; white-space: pre-wrap; word-break: break-all; }

/* Lead form config */
.lead-form-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
.lead-form-controls, .lead-form-preview { background: white; padding: 24px; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
.preview-label { font-size: 0.75rem; color: #6b7280; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 16px; }
.form-section { margin-bottom: 24px; }
.form-section h3 { font-size: 0.875rem; font-weight: 600; margin-bottom: 12px; color: #374151; }
.timing-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.timing-card { display: block; padding: 12px; border: 2px solid #e5e7eb; border-radius: 8px; cursor: pointer; transition: border-color 0.15s; }
.timing-card:hover { border-color: #93c5fd; }
.timing-card--active { border-color: #2563eb; background: #eff6ff; }
.timing-card-title { font-size: 0.875rem; font-weight: 600; margin-bottom: 2px; }
.timing-card-desc { font-size: 0.75rem; color: #6b7280; }
.field-row { margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid #f3f4f6; }
.field-row:last-child { border-bottom: none; }
.field-options { margin-left: 24px; margin-top: 8px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.field-label-input { width: 180px !important; padding: 4px 8px !important; }
.form-preview-card { padding: 20px; border: 1px solid #e5e7eb; border-radius: 8px; }
.preview-field { margin-bottom: 14px; }
.preview-field label { display: block; font-size: 0.8rem; font-weight: 500; margin-bottom: 4px; }
.preview-field input[type="text"], .preview-field input[type="email"] { width: 100%; padding: 6px 10px; border: 1px solid #d1d5db; border-radius: 4px; font-size: 0.8rem; background: #f9fafb; }
.required-star { color: #dc2626; }
.btn-preview-submit { width: 100%; padding: 8px; border: none; border-radius: 6px; color: white; font-size: 0.875rem; cursor: not-allowed; margin-top: 8px; opacity: 0.9; }

/* Account */
.token-display { display: flex; align-items: center; gap: 12px; }
.token-masked { font-family: 'Menlo','Monaco',monospace; font-size: 1rem; letter-spacing: 2px; color: #6b7280; }
.danger-zone { margin-top: 32px; padding: 24px; border: 1px solid #fecaca; border-radius: 10px; background: #fff5f5; max-width: 640px; }
.danger-zone h3 { color: #dc2626; font-size: 1rem; margin-bottom: 8px; }
.danger-zone > p { font-size: 0.875rem; color: #6b7280; margin-bottom: 16px; }
.delete-confirm { margin-top: 16px; padding: 16px; background: white; border-radius: 8px; border: 1px solid #fecaca; }
.delete-confirm p { margin-bottom: 12px; font-size: 0.875rem; }
.delete-confirm input { margin-bottom: 12px; }

/* Billing plan gating */
body[data-plan="starter"] .nav-link[data-pro]::after {
  content: " 🔒";
  font-size: 0.7em;
  opacity: 0.6;
}

.upgrade-prompt {
  margin-top: 3rem;
  text-align: center;
}

.upgrade-prompt p {
  color: #666;
  margin-bottom: 1.25rem;
  font-size: 1rem;
}

.upgrade-banner {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  color: #1e40af;
}

.upgrade-banner a {
  color: #1d4ed8;
  font-weight: 600;
}

/* Billing page */
.billing-section {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}

.billing-section h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: #374151;
}

.plan-summary {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.plan-badge {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.plan-badge--pro { background: #dbeafe; color: #1d4ed8; }
.plan-badge--starter { background: #f3f4f6; color: #374151; }

.billing-period { font-size: 0.9rem; color: #6b7280; }

.billing-status { font-size: 0.9rem; color: #374151; margin-top: 0.25rem; }
.billing-status--warning { color: #92400e; }
.billing-status--error { color: #dc2626; font-weight: 600; }

.progress-bar {
  height: 6px;
  background: #e5e7eb;
  border-radius: 3px;
  margin-top: 0.5rem;
  overflow: hidden;
}

.progress-bar__fill {
  height: 100%;
  background: #0066FF;
  border-radius: 3px;
  transition: width 0.3s;
}

.billing-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.billing-upgrade-form {
  width: 100%;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid #e5e7eb;
}

.billing-upgrade-form p {
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

.radio-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.text-link {
  font-size: 0.875rem;
  color: #0066FF;
  text-decoration: none;
  cursor: pointer;
}

.text-link:hover { text-decoration: underline; }
.text-danger { color: #dc2626; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 2px solid #e5e7eb;
  color: #6b7280;
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.data-table td {
  padding: 0.75rem 0.75rem;
  border-bottom: 1px solid #f3f4f6;
  color: #374151;
}

.data-table a { color: #0066FF; text-decoration: none; font-size: 0.85rem; }
.data-table a:hover { text-decoration: underline; }

.badge--success { background: #d1fae5; color: #065f46; padding: 0.15rem 0.5rem; border-radius: 20px; font-size: 0.75rem; font-weight: 600; }
.badge--warning { background: #fef3c7; color: #92400e; padding: 0.15rem 0.5rem; border-radius: 20px; font-size: 0.75rem; font-weight: 600; }

.billing-cancel {
  border-color: transparent;
  background: transparent;
  padding-top: 0.5rem;
  padding-left: 0;
}

.empty-state {
  color: #9ca3af;
  font-size: 0.9rem;
  font-style: italic;
}

.btn-danger {
  background: #dc2626;
  color: #fff;
  border: none;
  padding: 0.6rem 1.25rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
}

.btn-danger:hover { background: #b91c1c; }
.btn-danger:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-secondary {
  background: #f3f4f6;
  color: #374151;
  border: 1px solid #d1d5db;
  padding: 0.6rem 1.25rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
}

.btn-secondary:hover { background: #e5e7eb; }

/* Conversations page — three-pane master-detail */
.content-area--flush { padding: 0; max-width: none; height: 100vh; overflow: hidden; }

.conversations-layout { display: flex; height: 100%; }

.conversation-list-pane { width: 280px; flex-shrink: 0; border-right: 1px solid #e5e7eb; display: flex; flex-direction: column; background: #fff; overflow: hidden; }
.conversation-list-header { padding: 16px 16px 12px; font-weight: 600; border-bottom: 1px solid #e5e7eb; }
.conversation-list-body { flex: 1; overflow-y: auto; }
.conversation-list { display: flex; flex-direction: column; }
.conversation-row { padding: 12px 16px; border-bottom: 1px solid #f3f4f6; cursor: pointer; border-left: 3px solid transparent; }
.conversation-row:hover { background: #f9fafb; }
.conversation-row--selected { background: #eff6ff; border-left-color: #2563eb; }
.conversation-preview { font-weight: 600; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation-meta { font-size: 0.85em; color: #6b7280; }
.lead-badge { color: #2563eb; }

.conversation-detail-pane { flex: 1; min-width: 0; overflow-y: auto; background: #f9fafb; }
.conversation-detail-pane .back-btn { display: none; margin: 16px 16px 0; }

.detail-lead-header { background: #fff; border-bottom: 1px solid #e5e7eb; padding: 16px 20px; }
.detail-lead-badge { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.lead-pill { background: #dcfce7; color: #166534; font-size: 0.7rem; font-weight: 600; padding: 2px 10px; border-radius: 10px; }
.detail-lead-time { color: #9ca3af; font-size: 0.85em; }
.detail-lead-fields { display: flex; flex-wrap: wrap; gap: 24px; }
.lead-field { display: flex; flex-direction: column; }
.lead-field-label { color: #9ca3af; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.03em; }
.lead-field-value { font-weight: 600; color: #111827; }
.detail-meta { background: #fff; border-bottom: 1px solid #e5e7eb; padding: 16px 20px; color: #6b7280; font-size: 0.9em; }

.transcript { display: flex; flex-direction: column; gap: 10px; padding: 20px; }
.message { max-width: 75%; padding: 8px 12px; border-radius: 12px; }
.message-role { font-size: 0.75em; font-weight: 600; opacity: 0.7; margin-bottom: 2px; }
.message-content { white-space: pre-wrap; word-break: break-word; }
.message-time { font-size: 0.7em; opacity: 0.6; margin-top: 4px; }
.message--user { align-self: flex-end; background: #2563eb; color: #fff; }
.message--bot { align-self: flex-start; background: #f3f4f6; color: #111827; }

/* Narrow screens: collapse to list OR detail */
@media (max-width: 900px) {
  .conversation-list-pane { width: 100%; }
  .conversation-detail-pane { display: none; }
  .conversations-layout--detail .conversation-list-pane { display: none; }
  .conversations-layout--detail .conversation-detail-pane { display: block; }
  .conversations-layout--detail .conversation-detail-pane .back-btn { display: inline-flex; }
}
