/* ═══════════════════════════════════════════════════════════
   AI Caller Agent — Dashboard Styles
   Premium dark theme with glassmorphism
   ═══════════════════════════════════════════════════════════ */

:root {
  --bg-primary:    #0a0e1a;
  --bg-secondary:  #111827;
  --bg-card:       #1a1f35;
  --bg-card-hover: #222845;
  --bg-sidebar:    #0d1224;
  --border:        rgba(255,255,255,0.06);
  --border-active: rgba(99,102,241,0.4);

  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:     #64748b;

  --accent:        #6366f1;
  --accent-light:  #818cf8;
  --accent-glow:   rgba(99,102,241,0.15);

  --green:  #22c55e;
  --amber:  #f59e0b;
  --red:    #ef4444;
  --cyan:   #06b6d4;

  --radius:     12px;
  --radius-sm:  8px;
  --radius-lg:  16px;
  --shadow:     0 4px 24px rgba(0,0,0,0.3);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  overflow: hidden;
}

/* ─── Sidebar ──────────────────────────────────────────── */
.sidebar {
  width: 260px;
  min-width: 260px;
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  position: relative;
  z-index: 10;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 28px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), #a855f7);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 0 20px rgba(99,102,241,0.3);
}

.brand-icon svg {
  width: 20px;
  height: 20px;
}

.brand-title {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #fff, var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.nav-link:hover {
  background: var(--accent-glow);
  color: var(--text-primary);
}

.nav-link.active {
  background: linear-gradient(135deg, rgba(99,102,241,0.15), rgba(168,85,247,0.1));
  color: var(--accent-light);
  border: 1px solid var(--border-active);
}

.nav-link svg { opacity: 0.7; flex-shrink: 0; }
.nav-link.active svg { opacity: 1; }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 8px 0;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ─── Main Content ─────────────────────────────────────── */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 32px 40px;
  background: var(--bg-primary);
}

.page { display: none; }
.page.active { display: block; animation: fadeUp 0.3s ease; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

.page-title {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ─── Buttons ──────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  font-family: var(--font);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent-light);
  background: var(--accent-glow);
}

/* ─── Stats Grid ───────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: all 0.25s ease;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: var(--radius) var(--radius) 0 0;
}

.stat-total::before  { background: linear-gradient(90deg, var(--accent), var(--cyan)); }
.stat-active::before { background: var(--green); }
.stat-completed::before { background: var(--cyan); }
.stat-score::before  { background: linear-gradient(90deg, var(--amber), #f97316); }
.stat-duration::before { background: linear-gradient(90deg, #a855f7, var(--accent)); }

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: var(--border-active);
}

.stat-icon { font-size: 28px; }

.stat-value {
  display: block;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -1px;
}

.stat-label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ─── Cards ────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ─── Tables ───────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

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

thead th {
  text-align: left;
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  vertical-align: middle;
}

tbody tr {
  transition: background 0.15s ease;
  cursor: pointer;
}

tbody tr:hover {
  background: var(--bg-card-hover);
}

/* ─── Badges ───────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-green    { background: rgba(34,197,94,0.12); color: var(--green); }
.badge-amber    { background: rgba(245,158,11,0.12); color: var(--amber); }
.badge-red      { background: rgba(239,68,68,0.12); color: var(--red); }
.badge-cyan     { background: rgba(6,182,212,0.12); color: var(--cyan); }
.badge-purple   { background: rgba(168,85,247,0.12); color: #a855f7; }

/* ─── Score Stars ──────────────────────────────────────── */
.score {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
}

.score-high   { color: var(--green); }
.score-mid    { color: var(--amber); }
.score-low    { color: var(--red); }

/* ─── Modal ────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(6px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 720px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 1;
}

.modal-title { font-size: 18px; font-weight: 700; }

.modal-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.modal-close:hover {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}

.modal-body { padding: 24px; }

/* ─── Call Detail Sections ─────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.detail-item label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.detail-item span {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

/* Transcript */
.transcript {
  margin-top: 20px;
}

.transcript h4 {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text-primary);
}

.transcript-msg {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

.transcript-msg .avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
  margin-top: 2px;
  overflow: hidden;
}

.msg-user .avatar {
  background: rgba(6,182,212,0.15);
}

.msg-ai .avatar {
  background: rgba(99,102,241,0.15);
}

.transcript-msg .text {
  background: var(--bg-secondary);
  border-radius: 12px 12px 12px 4px;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
  max-width: 85%;
}

.msg-ai .text {
  border-radius: 12px 12px 4px 12px;
  background: rgba(99,102,241,0.08);
  border: 1px solid rgba(99,102,241,0.15);
}

.transcript-msg .time {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ─── Lead Info ─────────────────────────────────────────── */
.lead-section {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.lead-section h4 {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 12px;
}

/* ─── Empty State ──────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

.empty-state .icon {
  font-size: 40px;
  margin-bottom: 12px;
}

/* ─── Caller number ────────────────────────────────────── */
.caller-num {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 13px;
  color: var(--cyan);
}

/* ─── Summary ──────────────────────────────────────────── */
.summary-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
  margin-top: 16px;
}

/* ─── Responsive ───────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-content { padding: 20px 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-grid { grid-template-columns: 1fr; }
  .modal { width: 96%; }
  .page-title { font-size: 22px; }
  .settings-grid { grid-template-columns: 1fr; }
  .flow-diagram { flex-direction: column; }
  .flow-arrow { transform: rotate(90deg); }
}

/* ─── Scrollbar ────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ─── Nav Divider ──────────────────────────────────────── */
.nav-divider {
  height: 1px;
  background: var(--border);
  margin: 12px 8px;
}

/* ─── Primary Button ───────────────────────────────────── */
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #a855f7);
  color: #fff;
  padding: 12px 24px;
  font-size: 14px;
  border: none;
  box-shadow: 0 4px 16px rgba(99,102,241,0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(99,102,241,0.4);
}

.btn-primary:active {
  transform: translateY(0);
}

/* ═══════════════════════════════════════════════════════════
   SETTINGS PAGE
   ═══════════════════════════════════════════════════════════ */

.status-banner {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 24px;
}

.status-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 13px;
}

.status-check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 12px;
}

.status-ok {
  background: rgba(34,197,94,0.1);
  color: var(--green);
}

.status-missing {
  background: rgba(239,68,68,0.1);
  color: var(--red);
}

.status-partial {
  background: rgba(245,158,11,0.1);
  color: var(--amber);
}

/* Settings Cards */
.settings-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  transition: border-color 0.2s ease;
}

.settings-card:hover {
  border-color: var(--border-active);
}

.settings-card-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.settings-card-header h3 {
  font-size: 16px;
  font-weight: 700;
}

.settings-card-header p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.settings-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.twilio-icon      { background: rgba(242,47,70,0.12); }
.openai-icon      { background: rgba(99,102,241,0.12); }
.brand-icon-set   { background: rgba(6,182,212,0.12); }
.optional-icon    { background: rgba(168,85,247,0.12); }

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* Form Groups */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.form-group input {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font);
  transition: all 0.2s ease;
  outline: none;
}

.form-group input::placeholder {
  color: var(--text-muted);
  font-size: 12px;
}

.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group input:not(:placeholder-shown) {
  border-color: rgba(34,197,94,0.3);
}

.form-hint {
  font-size: 11px;
  color: var(--text-muted);
}

/* Settings Actions */
.settings-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 8px;
  padding-top: 20px;
}

.save-hint {
  font-size: 12px;
  color: var(--text-muted);
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 14px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  z-index: 2000;
  animation: slideUp 0.3s ease;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.toast-success {
  background: linear-gradient(135deg, #065f46, #047857);
  color: #d1fae5;
  border: 1px solid rgba(34,197,94,0.3);
}

.toast-error {
  background: linear-gradient(135deg, #7f1d1d, #991b1b);
  color: #fecaca;
  border: 1px solid rgba(239,68,68,0.3);
}

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

/* ═══════════════════════════════════════════════════════════
   HOW IT WORKS PAGE
   ═══════════════════════════════════════════════════════════ */

.howit-steps {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.step-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  gap: 20px;
  transition: all 0.25s ease;
}

.step-card:hover {
  border-color: var(--border-active);
  transform: translateX(4px);
}

.step-number {
  width: 48px;
  height: 48px;
  min-width: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 800;
  box-shadow: 0 0 16px rgba(99,102,241,0.25);
}

.step-content h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 12px;
}

.step-details {
  font-size: 14px;
  line-height: 1.8;
  color: var(--text-secondary);
}

.step-details p { margin-bottom: 8px; }
.step-details a {
  color: var(--accent-light);
  text-decoration: none;
}
.step-details a:hover { text-decoration: underline; }

.step-details strong { color: var(--text-primary); }

.step-item {
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 10px;
}

.step-item strong {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
}

.step-note {
  background: rgba(245,158,11,0.08);
  border: 1px solid rgba(245,158,11,0.15);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-top: 10px;
  font-size: 13px;
  color: var(--amber);
}

.code-block {
  background: #0d1117;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  margin: 12px 0;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 13px;
  color: var(--green);
  line-height: 1.8;
  overflow-x: auto;
}

.step-list {
  padding-left: 20px;
  margin: 8px 0;
}

.step-list li {
  margin-bottom: 6px;
  padding-left: 4px;
}

.step-list ul {
  padding-left: 20px;
  margin-top: 6px;
}

.step-list code {
  background: var(--bg-secondary);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--cyan);
  font-family: 'SF Mono', 'Fira Code', monospace;
}

/* Flow Diagram */
.step-flow {
  border-color: rgba(99,102,241,0.2);
  background: linear-gradient(135deg, var(--bg-card), rgba(99,102,241,0.03));
}

.flow-diagram {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px 0;
  flex-wrap: wrap;
}

.flow-node {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  min-width: 120px;
  transition: all 0.2s ease;
}

.flow-node:hover { transform: scale(1.05); }

.flow-phone  { border-color: rgba(34,197,94,0.3); }
.flow-twilio { border-color: rgba(242,47,70,0.3); }
.flow-server { border-color: rgba(6,182,212,0.3); }
.flow-openai { border-color: rgba(99,102,241,0.3); }

.flow-node small {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 400;
}

.flow-arrow {
  font-size: 24px;
  color: var(--accent);
  font-weight: 700;
}

.flow-desc {
  margin-top: 16px;
  padding: 16px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.8;
  color: var(--text-secondary);
}

.flow-desc strong { color: var(--text-primary); }

/* ─── Auth Page ─────────────────────────────────────────── */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: 100vw;
  background: radial-gradient(circle at center, #111827 0%, #0a0e1a 100%);
  margin: 0;
  padding: 0;
}

.login-card {
  background: rgba(26, 31, 53, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  animation: fadeUp 0.4s ease;
}

.login-card h2 {
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 24px;
  text-align: center;
  background: linear-gradient(135deg, #fff, var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.login-hint {
  font-size: 13px;
  color: var(--red);
  text-align: center;
  min-height: 18px;
  display: block;
}


