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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f5f5;
  color: #333;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

/* Navbar */
.navbar {
  background: white;
  padding: 15px 30px;
  border-radius: 8px;
  margin-bottom: 20px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.navbar h1 {
  margin: 0;
  font-size: 24px;
  color: #1a1a1a;
}

.navbar-links {
  display: flex;
  gap: 5px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.navbar-links.loaded {
  opacity: 1;
}

.navbar-links a,
.navbar-links button {
  padding: 10px 20px;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  background: #f3f4f6;
  color: #374151;
}

.navbar-links a:hover,
.navbar-links button:hover {
  background: #e5e7eb;
}

.navbar-links a.active {
  background: #2563eb;
  color: white;
}

.navbar-links button.logout {
  background: #dc2626;
  color: white;
}

.navbar-links button.logout:hover {
  background: #b91c1c;
}

.logged-in-label {
  font-size: 12px;
  color: #6b7280;
  text-align: right;
  margin-top: -14px;
  margin-bottom: 4px;
}

/* Dashboard header / stats */
header {
  background: white;
  padding: 30px;
  border-radius: 8px;
  margin-bottom: 20px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

header h1 {
  margin-bottom: 20px;
  color: #1a1a1a;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}

.stat-box {
  display: flex;
  flex-direction: column;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 6px;
}

.stat-label {
  font-size: 14px;
  color: #666;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 32px;
  font-weight: bold;
  color: #2563eb;
}

/* AI toggle */
.ai-toggle-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  background: #f8f9fa;
  border-radius: 6px;
}

.ai-toggle-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ai-toggle-title {
  font-size: 14px;
  font-weight: 600;
  color: #1a1a1a;
}

.ai-toggle-desc {
  font-size: 11px;
  color: #6b7280;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  cursor: pointer;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #d1d5db;
  border-radius: 24px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
  background: #10b981;
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

/* Main layout */
.main-content {
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 20px;
  height: calc(100vh - 240px);
}

.sidebar,
.chat-area {
  background: white;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
}

/* Search & filters */
.search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.search-row input {
  flex: 1;
  padding: 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
}

.filter-btn {
  padding: 10px 14px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: white;
  cursor: pointer;
  font-size: 14px;
  color: #374151;
  white-space: nowrap;
}

.filter-btn:hover { background: #f3f4f6; }

.filter-btn.has-filters {
  border-color: #2563eb;
  color: #2563eb;
  background: #eff6ff;
}

.filter-panel {
  display: none;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.filter-panel h4 {
  margin: 0 0 10px;
  font-size: 13px;
  color: #6b7280;
  text-transform: uppercase;
}

.filter-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.filter-tag {
  padding: 5px 12px;
  border: 1px solid #d1d5db;
  border-radius: 20px;
  background: white;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: #374151;
  transition: all 0.15s;
}

.filter-tag:hover { background: #f3f4f6; }

.filter-tag.active {
  background: #2563eb;
  color: white;
  border-color: #2563eb;
}

.filter-clear {
  font-size: 12px;
  color: #6b7280;
  cursor: pointer;
  border: none;
  background: none;
  text-decoration: underline;
}

.filter-clear:hover { color: #374151; }

/* Tabs */
.tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
  padding-bottom: 15px;
  border-bottom: 1px solid #e5e5e5;
}

.tab {
  padding: 8px 16px;
  border: none;
  background: #f0f0f0;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}

.tab.active {
  background: #2563eb;
  color: white;
}

/* Conversation list */
#conversationsList {
  flex: 1;
  overflow-y: auto;
  max-height: calc(100vh - 350px);
}

.conversation-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 15px;
  border-bottom: 1px solid #e5e5e5;
  transition: background 0.2s;
  gap: 10px;
}

.conversation-content {
  flex: 1;
  cursor: pointer;
  min-width: 0;
}

.conversation-item:hover {
  background: #f8f9fa;
}

.conversation-item.selected {
  background: #e3f2fd;
  border-left: 3px solid #2563eb;
}

.conversation-phone {
  font-weight: 600;
  margin-bottom: 5px;
}

.conversation-preview {
  font-size: 14px;
  color: #666;
  margin-bottom: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #999;
}

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.status-new { background: #fef3c7; color: #92400e; }
.status-active { background: #d1fae5; color: #065f46; }
.status-complete { background: #e5e7eb; color: #374151; }
.status-opted_out { background: #fee2e2; color: #991b1b; }
.status-paused { background: #fed7aa; color: #9a3412; }

/* Conversation menu */
.conversation-menu {
  position: relative;
  flex-shrink: 0;
}

.menu-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 5px 10px;
  color: #666;
}

.menu-btn:hover {
  background: #f0f0f0;
  border-radius: 4px;
}

.menu-dropdown {
  position: absolute;
  right: 0;
  top: 30px;
  background: white;
  border: 1px solid #ddd;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 1000;
  min-width: 150px;
}

.menu-dropdown button {
  display: block;
  width: 100%;
  padding: 10px 15px;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  font-size: 14px;
}

.menu-dropdown button:hover {
  background: #f5f5f5;
}

.menu-dropdown button.danger {
  color: #dc2626;
}

.menu-dropdown button.danger:hover {
  background: #fee2e2;
}

/* Chat area */
#conversationHeader {
  padding-bottom: 15px;
  border-bottom: 2px solid #e5e5e5;
  margin-bottom: 15px;
}

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

.convo-header-info p {
  margin-top: 4px;
}

.convo-header-info .convo-phone {
  color: #666;
  font-size: 14px;
}

.convo-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-close-convo {
  background: #6b7280;
  color: white;
  padding: 10px 20px;
  border-radius: 6px;
  border: none;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.btn-reopen-convo {
  background: #10b981;
  color: white;
  padding: 10px 20px;
  border-radius: 6px;
  border: none;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.hubspot-btn {
  background: #ff7a59;
  color: white;
  padding: 10px 20px;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  display: inline-block;
}

.hubspot-btn:hover {
  background: #ff6243;
}

/* Messages */
#messagesList {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
  max-height: calc(100vh - 450px);
}

.message {
  margin-bottom: 15px;
  padding: 12px;
  border-radius: 8px;
  max-width: 80%;
}

.message.incoming {
  background: #f0f0f0;
  margin-right: auto;
}

.message.outgoing {
  background: #2563eb;
  color: white;
  margin-left: auto;
}

.message-text {
  margin-bottom: 5px;
}

.message-time {
  font-size: 11px;
  opacity: 0.7;
}

/* Message input */
#messageInput {
  border-top: 2px solid #e5e5e5;
  padding-top: 15px;
  margin-top: 15px;
}

#replyText {
  width: 100%;
  padding: 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  min-height: 80px;
}

.input-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.input-actions button {
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}

#sendBtn {
  background: #2563eb;
  color: white;
}

#commentBtn {
  background: #ffebd1;
  color: #333;
}

#pauseBtn {
  background: white;
  color: #374151;
  border: 1px solid #d1d5db !important;
}

button:hover {
  opacity: 0.9;
}

/* ===== Login Page ===== */
.login-container {
  max-width: 400px;
  margin: 100px auto;
  padding: 40px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.login-container h1 {
  text-align: center;
  margin-bottom: 30px;
  color: #1a1a1a;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  color: #333;
}

.form-group input {
  width: 100%;
  padding: 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
}

.login-btn {
  width: 100%;
  padding: 12px;
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
}

.login-btn:hover {
  opacity: 0.9;
}

.error-message {
  background: #fee2e2;
  color: #991b1b;
  padding: 12px;
  border-radius: 6px;
  margin-bottom: 20px;
  display: none;
}

/* ===== Settings Page ===== */
.settings-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
}

.settings-section {
  background: white;
  padding: 30px;
  border-radius: 8px;
  margin-bottom: 20px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.settings-section h2 {
  margin-bottom: 20px;
  color: #1a1a1a;
  border-bottom: 2px solid #e5e5e5;
  padding-bottom: 10px;
}

.setting-item {
  margin-bottom: 20px;
}

.setting-item label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  color: #333;
}

.setting-item input[type="text"],
.setting-item input[type="password"],
.setting-item input[type="number"],
.setting-item textarea,
.setting-item select {
  width: 100%;
  padding: 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
}

.setting-item textarea {
  min-height: 100px;
  resize: vertical;
}

.setting-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
}

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

.slider-container {
  display: flex;
  align-items: center;
  gap: 15px;
}

.slider-container input[type="range"] {
  flex: 1;
}

.slider-value {
  font-weight: 600;
  min-width: 40px;
}

.save-btn {
  background: #2563eb;
  color: white;
  padding: 12px 24px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 16px;
}

.save-btn:hover {
  opacity: 0.9;
}

.help-text {
  font-size: 13px;
  color: #666;
  margin-top: 5px;
}

.success-message {
  background: #d1fae5;
  color: #065f46;
  padding: 12px;
  border-radius: 6px;
  margin-bottom: 20px;
  display: none;
}

.test-btn {
  background: #10b981;
  margin-right: 10px;
}

.test-result {
  font-weight: 600;
}

/* ===== Admin Page ===== */
.admin-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
}

.admin-section {
  background: white;
  padding: 30px;
  border-radius: 8px;
  margin-bottom: 20px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.admin-list {
  margin-top: 20px;
}

.admin-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px;
  border: 1px solid #e5e5e5;
  border-radius: 6px;
  margin-bottom: 10px;
}

.admin-info {
  flex: 1;
}

.admin-info h3 {
  margin: 0 0 5px 0;
}

.admin-info p {
  margin: 0;
  color: #666;
  font-size: 14px;
}

.edit-btn {
  background: #2563eb;
  color: white;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}

.edit-btn:hover {
  background: #1d4ed8;
}

.delete-btn {
  background: #dc2626;
  color: white;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}

.add-admin-form {
  display: grid;
  gap: 15px;
  margin-top: 20px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}

.admin-section input,
.admin-section select {
  width: 100%;
  padding: 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
}

.admin-section input[type="checkbox"] {
  width: auto;
  padding: 0;
}

.add-btn {
  background: #4e85af;
  color: white;
  padding: 12px 24px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}

/* ===== Reports Page ===== */
.reports-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.report-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.report-header h2 {
  margin: 0;
  color: #1a1a1a;
}

.refresh-btn {
  background: #2563eb;
  color: white;
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
}

.refresh-btn:hover {
  opacity: 0.9;
}

.refresh-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 15px;
  margin-bottom: 30px;
}

.report-stat {
  background: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  text-align: center;
}

.report-stat .stat-number {
  font-size: 36px;
  font-weight: 700;
  line-height: 1.2;
}

.report-stat .stat-label {
  font-size: 13px;
  color: #666;
  margin-top: 6px;
}

.report-stat .stat-pct {
  font-size: 14px;
  font-weight: 600;
  margin-top: 4px;
}

.stat-appointments .stat-number { color: #2563eb; }
.stat-appointments .stat-pct { color: #2563eb; }
.stat-hot .stat-number { color: #dc2626; }
.stat-hot .stat-pct { color: #dc2626; }
.stat-warm .stat-number { color: #f59e0b; }
.stat-warm .stat-pct { color: #f59e0b; }
.stat-cold .stat-number { color: #6b7280; }
.stat-cold .stat-pct { color: #6b7280; }
.stat-minimal .stat-number { color: #9ca3af; }
.stat-minimal .stat-pct { color: #9ca3af; }
.stat-total .stat-number { color: #1a1a1a; }
.stat-engagement .stat-number { color: #10b981; }
.stat-engagement .stat-pct { color: #10b981; }

.category-section {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  margin-bottom: 20px;
  overflow: hidden;
}

.category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.category-header:hover {
  background: #f8f9fa;
}

.category-header h3 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
}

.category-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 700;
  color: white;
}

.count-appointments { background: #2563eb; }
.count-hot { background: #dc2626; }
.count-warm { background: #f59e0b; }
.count-cold { background: #6b7280; }
.count-minimal { background: #9ca3af; }

.category-toggle {
  font-size: 18px;
  color: #666;
  transition: transform 0.2s;
}

.category-toggle.open {
  transform: rotate(180deg);
}

.category-body {
  display: none;
  border-top: 1px solid #e5e5e5;
}

.category-body.open {
  display: block;
}

.lead-table {
  width: 100%;
  border-collapse: collapse;
}

.lead-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: #6b7280;
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
}

.lead-table td {
  padding: 12px 16px;
  font-size: 14px;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: top;
}

.lead-table tr:last-child td {
  border-bottom: none;
}

.lead-table tr:hover td {
  background: #f8f9fa;
}

.lead-name {
  font-weight: 600;
  color: #1a1a1a;
}

.lead-phone {
  font-size: 12px;
  color: #6b7280;
}

.lead-last-msg {
  max-width: 300px;
  font-size: 13px;
  color: #374151;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lead-link {
  color: #2563eb;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}

.lead-link:hover {
  text-decoration: underline;
}

.retrigger-btn {
  background: #2563eb;
  color: #fff;
  border: none;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}

.retrigger-btn:hover {
  background: #1d4ed8;
}

.retrigger-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.exchange-badge {
  display: inline-block;
  background: #f3f4f6;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  color: #374151;
}

.loading-state {
  text-align: center;
  padding: 60px 20px;
  color: #6b7280;
  font-size: 16px;
}

.loading-spinner {
  display: inline-block;
  width: 32px;
  height: 32px;
  border: 3px solid #e5e7eb;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty-state {
  text-align: center;
  padding: 30px;
  color: #9ca3af;
  font-size: 14px;
}

/* ===== Mobile back button ===== */
.mobile-back-btn {
  display: none;
  background: none;
  border: none;
  font-size: 14px;
  font-weight: 600;
  color: #2563eb;
  cursor: pointer;
  padding: 8px 0;
  margin-bottom: 8px;
}

/* ===== Follow-up System Settings ===== */
.followup-days-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}

.day-checkbox {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  padding: 6px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  user-select: none;
}

.day-checkbox:hover {
  background: #f3f4f6;
}

.day-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

.delay-input-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.delay-value-input {
  width: 100px !important;
  flex: none !important;
}

.delay-unit-select {
  width: 130px !important;
  flex: none !important;
}

.time-window-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.time-window-row input[type="time"] {
  padding: 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  width: 150px;
}

.time-window-row span {
  color: #666;
  font-size: 14px;
}

.followup-delay-row {
  background: #f9fafb;
  padding: 15px;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
  margin-bottom: 10px;
}

.followup-delay-row label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  color: #333;
}

/* ===== Conversation Detail Page (3-Panel) ===== */
.conversation-detail-layout {
  display: grid;
  grid-template-columns: 300px 350px 1fr;
  gap: 20px;
  height: calc(100vh - 100px);
}

.contact-info-panel {
  background: white;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  overflow-y: auto;
}

.contact-name-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 15px;
  border-bottom: 2px solid #e5e5e5;
  margin-bottom: 15px;
}

.contact-name-header h2 {
  margin: 0;
  font-size: 20px;
  color: #1a1a1a;
}

.name-edit-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: #6b7280;
  padding: 2px 6px;
  border-radius: 4px;
  transition: all 0.2s;
}

.name-edit-btn:hover {
  background: #f3f4f6;
  color: #374151;
}

.contact-name-expanded {
  background: #f9fafb;
  padding: 12px;
  border-radius: 6px;
  margin-bottom: 15px;
  border: 1px solid #e5e7eb;
}

.contact-info-fields {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.contact-info-field {
  padding: 8px 0;
  border-bottom: 1px solid #f3f4f6;
}

.contact-field-label {
  display: block;
  font-size: 12px;
  color: #6b7280;
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.contact-field-value {
  display: block;
  font-size: 14px;
  color: #1a1a1a;
}

.opt-status-section {
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px solid #e5e5e5;
}

.opt-status-section .opted-out-text {
  color: #dc2626;
  font-weight: 600;
}

.opt-status-section .opted-in-text {
  color: #16a34a;
  font-weight: 600;
}

.opt-in-btn {
  margin-top: 8px;
  padding: 5px 14px;
  font-size: 12px;
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s;
}

.opt-in-btn:hover {
  background: #1d4ed8;
}

.conversations-list-panel {
  background: white;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.conversations-list-panel h3 {
  margin: 0 0 15px 0;
  padding-bottom: 10px;
  border-bottom: 2px solid #e5e5e5;
  color: #1a1a1a;
}

.conversations-list-panel #conversationsList {
  flex: 1;
  overflow-y: auto;
}

.conversation-messages-panel {
  background: white;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.conversation-messages-panel #messagesList {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
}

.conversation-messages-panel #messageInput {
  border-top: 2px solid #e5e5e5;
  padding-top: 15px;
  margin-top: 15px;
}

.conversation-messages-panel #replyText {
  width: 100%;
  padding: 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  min-height: 80px;
  box-sizing: border-box;
}

/* View More button */
.btn-view-more {
  background: #8b5cf6;
  color: white;
  padding: 10px 20px;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  display: inline-block;
}

.btn-view-more:hover {
  background: #7c3aed;
}

/* Toast for conversation detail page */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 12px 24px;
  border-radius: 8px;
  color: white;
  font-weight: 600;
  z-index: 10000;
  animation: slideIn 0.3s ease;
}
.toast-success { background: #10b981; }
.toast-error { background: #dc2626; }
@keyframes slideIn {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ===== Mobile Responsive ===== */
@media (max-width: 768px) {
  .container {
    padding: 10px;
  }

  /* Navbar stacks */
  .navbar {
    flex-direction: column;
    gap: 12px;
    padding: 12px 16px;
    text-align: center;
  }

  .navbar h1 {
    font-size: 20px;
  }

  .navbar-links {
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
  }

  .navbar-links a,
  .navbar-links button {
    padding: 8px 12px;
    font-size: 13px;
  }

  /* Stats grid */
  header {
    padding: 16px;
  }

  .stats {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .stat-box {
    padding: 12px;
  }

  .stat-value {
    font-size: 24px;
  }

  .stat-label {
    font-size: 12px;
  }

  /* Conversation detail: stack panels */
  .conversation-detail-layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .contact-info-panel,
  .conversations-list-panel,
  .conversation-messages-panel {
    max-height: 50vh;
  }

  /* Dashboard: single column, show/hide panels */
  .main-content {
    grid-template-columns: 1fr;
    height: auto;
    min-height: calc(100vh - 300px);
  }

  .sidebar {
    min-height: 300px;
    max-height: 50vh;
  }

  .chat-area {
    min-height: 400px;
  }

  .chat-area.mobile-hidden {
    display: none;
  }

  .sidebar.mobile-hidden {
    display: none;
  }

  .mobile-back-btn {
    display: block;
  }

  #conversationsList {
    max-height: none;
  }

  #messagesList {
    max-height: none;
    min-height: 200px;
  }

  /* Conversation header actions stack */
  .convo-header-row {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }

  .convo-header-actions {
    flex-wrap: wrap;
    width: 100%;
  }

  .convo-header-actions a,
  .convo-header-actions button {
    flex: 1;
    text-align: center;
    min-width: 0;
    padding: 8px 10px;
    font-size: 13px;
  }

  .hubspot-btn {
    padding: 8px 12px;
    font-size: 13px;
  }

  /* Input actions wrap */
  .input-actions {
    flex-wrap: wrap;
  }

  .input-actions button {
    flex: 1;
    min-width: 0;
    padding: 10px 8px;
    font-size: 13px;
  }

  /* Reports */
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .report-stat .stat-number {
    font-size: 28px;
  }

  .reports-container {
    padding: 10px;
  }

  .report-header {
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
  }

  .lead-table th,
  .lead-table td {
    padding: 8px 10px;
    font-size: 12px;
  }

  .lead-last-msg {
    max-width: 120px;
  }

  .category-header {
    padding: 14px 16px;
  }

  /* Settings */
  .settings-container,
  .admin-container {
    padding: 10px;
  }

  .settings-section,
  .admin-section {
    padding: 20px;
  }

  /* Admin form row */
  .form-row {
    grid-template-columns: 1fr;
  }

  .admin-item {
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
  }

  /* Login */
  .login-container {
    margin: 40px auto;
    padding: 24px;
    width: 90%;
  }

  /* Tabs scroll horizontally */
  .tabs {
    overflow-x: auto;
    gap: 6px;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .tab {
    white-space: nowrap;
    flex-shrink: 0;
    padding: 8px 12px;
    font-size: 13px;
  }

  /* Follow-up responsive */
  .followup-days-grid {
    gap: 6px;
  }

  .delay-input-row {
    flex-wrap: wrap;
  }

  .time-window-row {
    flex-wrap: wrap;
  }

  .time-window-row input[type="time"] {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .stats {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .convo-header-actions {
    flex-direction: column;
  }

  .convo-header-actions a,
  .convo-header-actions button {
    width: 100%;
  }
}

/* Distribution Page */
.dist-container {
  background: white;
  border-radius: 8px;
  padding: 30px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.dist-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}

.dist-header h2 {
  font-size: 22px;
  color: #1a1a1a;
}

.dist-subtitle {
  color: #6b7280;
  font-size: 14px;
  margin-top: 4px;
  margin-bottom: 20px;
}

.dist-message {
  display: none;
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 500;
}

.dist-success {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.dist-error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.dist-section {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
}

.dist-section h3 {
  font-size: 16px;
  color: #1a1a1a;
  margin-bottom: 4px;
}

.dist-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.dist-webhook-list {
  margin-top: 16px;
}

.dist-webhook-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  margin-bottom: 10px;
  background: #fafafa;
}

.dist-webhook-name {
  font-weight: 600;
  font-size: 14px;
  color: #1a1a1a;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dist-webhook-badge {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 10px;
}

.badge-active {
  background: #ecfdf5;
  color: #065f46;
}

.badge-disabled {
  background: #f3f4f6;
  color: #6b7280;
}

.dist-webhook-url {
  font-size: 12px;
  color: #6b7280;
  margin-top: 4px;
  word-break: break-all;
}

.dist-webhook-event {
  font-size: 12px;
  color: #9ca3af;
  margin-top: 2px;
}

.dist-webhook-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.dist-btn {
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.dist-btn-primary {
  background: #2563eb;
  color: white;
}

.dist-btn-primary:hover {
  background: #1d4ed8;
}

.dist-btn-secondary {
  background: #f3f4f6;
  color: #374151;
  border: 1px solid #d1d5db;
}

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

.dist-btn-sm {
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid #d1d5db;
  font-size: 12px;
  cursor: pointer;
  background: white;
  color: #374151;
  transition: all 0.2s;
}

.dist-btn-test:hover {
  background: #eff6ff;
  border-color: #93c5fd;
  color: #1d4ed8;
}

.dist-btn-toggle:hover {
  background: #fefce8;
  border-color: #fde68a;
  color: #92400e;
}

.dist-btn-edit:hover {
  background: #f0fdf4;
  border-color: #86efac;
  color: #166534;
}

.dist-btn-delete {
  color: #dc2626;
  border-color: #fecaca;
}

.dist-btn-delete:hover {
  background: #fef2f2;
  border-color: #f87171;
}

.dist-empty {
  text-align: center;
  padding: 20px;
  color: #9ca3af;
  font-size: 14px;
}

.dist-empty-sm {
  padding: 10px;
  color: #9ca3af;
  font-size: 13px;
}

.dist-toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}

.dist-toggle-row label:last-child {
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.dist-checkboxes {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dist-checkboxes label {
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.dist-recipients {
  margin-top: 20px;
}

.dist-recipients > label {
  font-size: 14px;
  font-weight: 600;
  display: block;
  margin-bottom: 8px;
}

.dist-recipient-list {
  margin-bottom: 10px;
}

.dist-recipient {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  margin-bottom: 6px;
  font-size: 14px;
}

.dist-add-recipient {
  display: flex;
  gap: 8px;
}

.dist-add-recipient input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
}

.dist-add-recipient input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

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

.dist-log-table th {
  text-align: left;
  padding: 8px 12px;
  background: #f9fafb;
  border-bottom: 2px solid #e5e7eb;
  font-weight: 600;
  color: #374151;
}

.dist-log-table td {
  padding: 8px 12px;
  border-bottom: 1px solid #f3f4f6;
  color: #4b5563;
}

.dist-status-badge {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 10px;
}

.status-success {
  background: #ecfdf5;
  color: #065f46;
}

.status-failed {
  background: #fef2f2;
  color: #991b1b;
}

.dist-actions {
  margin-top: 10px;
  padding-top: 20px;
  border-top: 1px solid #e5e7eb;
}

/* Distribution Modal */
.dist-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.dist-modal-content {
  background: white;
  border-radius: 8px;
  padding: 24px;
  width: 480px;
  max-width: 90vw;
  position: relative;
}

.dist-modal-content h2 {
  font-size: 18px;
  margin-bottom: 16px;
}

.dist-modal-close {
  position: absolute;
  top: 16px;
  right: 20px;
  font-size: 24px;
  cursor: pointer;
  color: #6b7280;
  line-height: 1;
}

.dist-modal-close:hover {
  color: #1a1a1a;
}

.dist-form-group {
  margin-bottom: 16px;
}

.dist-form-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 6px;
  color: #374151;
}

.dist-form-group input,
.dist-form-group select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
}

.dist-form-group input:focus,
.dist-form-group select:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.dist-modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

@media (max-width: 768px) {
  .dist-webhook-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .dist-webhook-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .dist-section-header {
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
  }

  .dist-add-recipient {
    flex-direction: column;
  }
}

/* ===== Settings Confirm Modal ===== */
.confirm-modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.confirm-modal {
  background: white;
  border-radius: 8px;
  width: 480px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
}

.confirm-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px 0;
}

.confirm-modal-header h3 {
  margin: 0;
  font-size: 18px;
  color: #1a1a1a;
}

.confirm-modal-close {
  font-size: 24px;
  cursor: pointer;
  color: #6b7280;
  line-height: 1;
}

.confirm-modal-close:hover {
  color: #1a1a1a;
}

.confirm-modal-body {
  padding: 20px 24px;
}

.confirm-modal-user {
  font-size: 14px;
  color: #374151;
  margin-bottom: 4px;
}

.confirm-modal-prompt {
  font-size: 14px;
  color: #6b7280;
  margin-bottom: 12px;
}

.confirm-changes-list {
  list-style: none;
  padding: 0;
  margin: 0 0 20px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  overflow: hidden;
}

.confirm-changes-list li {
  padding: 10px 14px;
  font-size: 13px;
  color: #374151;
  border-bottom: 1px solid #f3f4f6;
}

.confirm-changes-list li:last-child {
  border-bottom: none;
}

.confirm-changes-list li strong {
  color: #1a1a1a;
}

.confirm-password-group {
  margin-top: 8px;
}

.confirm-password-group label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
  color: #374151;
}

.confirm-password-group input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}

.confirm-password-group input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.confirm-error {
  color: #dc2626;
  font-size: 13px;
  margin-top: 6px;
  min-height: 18px;
}

.confirm-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0 24px 20px;
}

@media (max-width: 768px) {
  .confirm-modal {
    width: 95vw;
  }
}

/* ===== Test Environment ===== */
.test-env-container {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 120px);
  overflow: hidden;
}

.test-env-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
  flex-shrink: 0;
}

.test-env-toolbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.test-env-prompt-label {
  font-weight: 600;
  font-size: 14px;
  color: #374151;
  white-space: nowrap;
}

.test-env-prompt-select {
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: white;
  min-width: 220px;
  max-width: 350px;
  cursor: pointer;
}

.test-env-prompt-select:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.test-env-toolbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 12px;
}

.test-env-icon-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: white;
  color: #6b7280;
  cursor: pointer;
  transition: all 0.15s;
}

.test-env-icon-btn:hover {
  background: #f3f4f6;
  color: #1a1a1a;
  border-color: #9ca3af;
}

.test-env-fyi {
  padding: 10px 20px;
  background: #eff6ff;
  border-bottom: 1px solid #bfdbfe;
  font-size: 13px;
  color: #1e40af;
  line-height: 1.5;
  flex-shrink: 0;
}

.test-env-fyi strong {
  color: #1e3a8a;
}

.test-env-chat {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.test-env-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.test-env-input {
  border-top: 2px solid #e5e7eb;
  padding: 16px 20px;
  background: #f9fafb;
  flex-shrink: 0;
}

.test-env-input textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  resize: none;
  min-height: 50px;
  max-height: 120px;
}

.test-env-input textarea:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.test-env-input-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.test-env-send-btn {
  padding: 10px 24px;
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.test-env-send-btn:hover {
  background: #1d4ed8;
}

.test-env-send-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.test-env-reset-btn {
  padding: 10px 20px;
  background: white;
  color: #374151;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.test-env-reset-btn:hover {
  background: #f3f4f6;
}

.test-env-prompt-textarea {
  width: 100%;
  min-height: 260px;
  padding: 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
  resize: vertical;
}

.test-env-prompt-textarea:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

/* Typing indicator */
.test-env-typing {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.test-env-typing span {
  width: 8px;
  height: 8px;
  background: rgba(0,0,0,0.3);
  border-radius: 50%;
  animation: testTypingBounce 1.4s infinite ease-in-out;
}

.test-env-typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.test-env-typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes testTypingBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Toast */
.test-env-toast {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 12px 20px;
  background: #d1fae5;
  color: #065f46;
  border-radius: 6px;
  font-weight: 600;
  font-size: 14px;
  z-index: 9999;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

@media (max-width: 768px) {
  .test-env-toolbar {
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
  }

  .test-env-toolbar-left {
    width: 100%;
  }

  .test-env-prompt-select {
    flex: 1;
    min-width: 0;
  }

  .test-env-toolbar-right {
    margin-left: 0;
  }
}
