/* ===================================================================
   GDOH Sales Dialer — Styles
   =================================================================== */

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #dc2626;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius: 0.5rem;
  --shadow: 0 1px 3px rgba(0,0,0,.1);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.15);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.5;
}

/* --- Login Screen --- */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1e3a5f, #2563eb);
}

.login-card {
  background: white;
  padding: 2.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 380px;
}

.login-card h1 {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
  color: var(--gray-900);
}

.login-card .subtitle {
  color: var(--gray-500);
  font-size: 0.875rem;
  margin-bottom: 1.5rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 0.25rem;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s, opacity 0.15s;
}

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

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover:not(:disabled) { background: #15803d; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-warning { background: var(--warning); color: white; }
.btn-outline {
  background: white;
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
}
.btn-outline:hover:not(:disabled) { background: var(--gray-50); }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.75rem; }
.btn-full { width: 100%; justify-content: center; }
.btn-icon { padding: 0.375rem; border-radius: 50%; }

.error-text { color: var(--danger); font-size: 0.75rem; margin-top: 0.5rem; }

/* --- App Layout --- */
#app-screen { display: none; min-height: 100vh; }

.header {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header h1 {
  font-size: 1.125rem;
  color: var(--gray-900);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.connection-status {
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  border-radius: 9999px;
  font-weight: 500;
}

.connection-status.connected { background: #dcfce7; color: #166534; }
.connection-status.disconnected { background: #fee2e2; color: #991b1b; }
.connection-status.connecting { background: #fef9c3; color: #854d0e; }

.auto-dial-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--gray-600);
}

.toggle-switch {
  position: relative;
  width: 36px;
  height: 20px;
}

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

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--gray-300);
  border-radius: 10px;
  transition: 0.2s;
}

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

.toggle-switch input:checked + .toggle-slider { background: var(--primary); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(16px); }

/* --- Tabs --- */
.tabs {
  display: flex;
  background: white;
  border-bottom: 1px solid var(--gray-200);
  padding: 0 1.5rem;
}

.tab-btn {
  padding: 0.75rem 1rem;
  border: none;
  background: none;
  font-size: 0.875rem;
  color: var(--gray-500);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  font-weight: 500;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* --- Main Content --- */
.main-content {
  padding: 1.5rem;
}

/* --- Active Call Panel --- */
.call-panel {
  display: none;
  background: var(--gray-900);
  color: white;
  padding: 1rem 1.5rem;
  align-items: center;
  justify-content: space-between;
}

.call-panel.active { display: flex; }

.call-info {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.call-info .name { font-weight: 600; font-size: 1rem; }
.call-info .detail { font-size: 0.75rem; color: var(--gray-400); }

.call-timer {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.call-controls {
  display: flex;
  gap: 0.5rem;
}

.call-controls .btn {
  padding: 0.5rem 1rem;
}

/* --- Incoming Call Popup --- */
.incoming-call-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.incoming-call-overlay.active { display: flex; }

.incoming-call-card {
  background: white;
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  width: 320px;
  box-shadow: var(--shadow-lg);
  animation: pulse-ring 1.5s ease-out infinite;
}

@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(37,99,235,.4); }
  70% { box-shadow: 0 0 0 15px rgba(37,99,235,0); }
  100% { box-shadow: 0 0 0 0 rgba(37,99,235,0); }
}

.incoming-call-card .caller-name {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0.5rem 0;
}

.incoming-call-card .caller-detail {
  color: var(--gray-500);
  font-size: 0.875rem;
  margin-bottom: 1.5rem;
}

.incoming-call-card .call-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

/* --- Auto-Dial Countdown --- */
.autodial-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.autodial-overlay.active { display: flex; }

.autodial-card {
  background: white;
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  width: 360px;
  box-shadow: var(--shadow-lg);
}

.autodial-card .countdown {
  font-size: 4rem;
  font-weight: 700;
  color: var(--primary);
  margin: 1rem 0;
}

.autodial-card .next-lead-name {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

/* --- Lead Queue Table --- */
.queue-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.queue-header h2 { font-size: 1.125rem; }

.queue-filters {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.queue-filters input,
.queue-filters select {
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.8125rem;
}

.lead-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.lead-table th {
  background: var(--gray-50);
  padding: 0.625rem 0.75rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--gray-200);
}

.lead-table td {
  padding: 0.625rem 0.75rem;
  font-size: 0.8125rem;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

.lead-table tr:hover { background: var(--gray-50); }
.lead-table tr.expanded { background: #eff6ff; }

.lead-name {
  font-weight: 600;
  color: var(--gray-900);
  cursor: pointer;
}

.lead-name:hover { color: var(--primary); }

/* --- Badges --- */
.badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-new { background: #dbeafe; color: #1e40af; }
.badge-contacted { background: #fef3c7; color: #92400e; }
.badge-callback { background: #e0e7ff; color: #3730a3; }
.badge-booked { background: #dcfce7; color: #166534; }
.badge-unresponsive { background: #fee2e2; color: #991b1b; }
.badge-disqualified { background: var(--gray-200); color: var(--gray-600); }

.score-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: help;
}

.score-low { background: #fee2e2; color: #991b1b; }
.score-mid { background: #fef3c7; color: #92400e; }
.score-high { background: #dcfce7; color: #166534; }

/* --- Lead Detail (Expanded Row) --- */
.lead-detail {
  display: none;
  padding: 1rem 1.5rem;
  background: #f8fafc;
  border-bottom: 2px solid var(--gray-200);
}

.lead-detail.active { display: block; }

.detail-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.detail-tab-btn {
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--gray-300);
  background: white;
  border-radius: var(--radius);
  font-size: 0.75rem;
  cursor: pointer;
  color: var(--gray-600);
}

.detail-tab-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.detail-panel { display: none; }
.detail-panel.active { display: block; }

/* --- Call History --- */
.call-history-item {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-bottom: 0.5rem;
}

.call-history-item .call-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.375rem;
}

.call-history-item .call-meta {
  font-size: 0.75rem;
  color: var(--gray-500);
}

.call-history-item .call-notes {
  font-size: 0.8125rem;
  color: var(--gray-700);
  margin-top: 0.375rem;
}

.ai-summary-banner {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  margin-top: 0.375rem;
}

.transcript-toggle {
  font-size: 0.75rem;
  color: var(--primary);
  cursor: pointer;
  margin-top: 0.375rem;
  display: inline-block;
}

.transcript-content {
  display: none;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-top: 0.375rem;
  font-size: 0.8125rem;
  max-height: 300px;
  overflow-y: auto;
  white-space: pre-wrap;
}

.transcript-content.active { display: block; }

/* --- Audio Player --- */
.audio-player {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.375rem;
}

.audio-player audio { height: 32px; }

/* --- Messaging --- */
.message-compose {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 0.75rem;
}

.channel-toggle {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.channel-btn {
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--gray-300);
  background: white;
  border-radius: var(--radius);
  font-size: 0.75rem;
  cursor: pointer;
}

.channel-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

.message-history {
  max-height: 300px;
  overflow-y: auto;
  margin-top: 0.75rem;
}

.message-item {
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.375rem;
  border-radius: var(--radius);
  font-size: 0.8125rem;
}

.message-item.outbound { background: #dbeafe; text-align: right; }
.message-item.inbound { background: var(--gray-100); }

.message-item .msg-meta {
  font-size: 0.6875rem;
  color: var(--gray-500);
  margin-top: 0.25rem;
}

/* --- Disposition Modal --- */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.5);
  z-index: 500;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal {
  background: white;
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.modal-body { padding: 1.5rem; }
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--gray-200);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.ai-processing-banner {
  background: #fef3c7;
  border: 1px solid #fde68a;
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  margin-bottom: 1rem;
  display: none;
}

.ai-processing-banner.active { display: block; }

/* --- Analytics --- */
.analytics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: white;
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.kpi-card .kpi-label {
  font-size: 0.75rem;
  color: var(--gray-500);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.kpi-card .kpi-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-top: 0.25rem;
}

.kpi-card .kpi-sub {
  font-size: 0.75rem;
  color: var(--gray-500);
  margin-top: 0.125rem;
}

.chart-container {
  background: white;
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.chart-container h3 {
  font-size: 0.875rem;
  margin-bottom: 0.75rem;
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 0.25rem;
  height: 120px;
}

.bar {
  flex: 1;
  background: var(--primary);
  border-radius: 2px 2px 0 0;
  min-height: 2px;
  position: relative;
  cursor: help;
}

.bar:hover { opacity: 0.8; }

.disposition-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.disposition-item {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
}

.disposition-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

/* --- Payment Banner --- */
.payment-banner {
  display: none;
  background: #dcfce7;
  border: 1px solid #86efac;
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: #166534;
  margin-bottom: 1rem;
  text-align: center;
}

.payment-banner.active { display: block; }

/* --- Sequence Status --- */
.sequence-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--gray-100);
  font-size: 0.8125rem;
}

.sequence-item .step-status {
  font-size: 0.6875rem;
  font-weight: 600;
}

.step-pending { color: var(--warning); }
.step-sent { color: var(--success); }
.step-cancelled { color: var(--gray-400); }

/* --- Responsive --- */
@media (max-width: 768px) {
  .main-content { padding: 1rem; }
  .lead-table { font-size: 0.75rem; }
  .analytics-grid { grid-template-columns: repeat(2, 1fr); }
  .header { padding: 0.5rem 1rem; }
}

/* --- Score Tooltip --- */
.score-tooltip {
  position: absolute;
  background: var(--gray-900);
  color: white;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.6875rem;
  z-index: 200;
  white-space: nowrap;
  pointer-events: none;
  display: none;
}

/* --- Spinner --- */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--gray-300);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--gray-500);
}

.empty-state .icon { font-size: 2rem; margin-bottom: 0.5rem; }
