/* ============================================================================
   AI Phone Assistant Design System & Styling
   Glassmorphic Dark Theme with Rich Micro-Animations
   ============================================================================ */

:root {
  --bg-main: #0a0b0e;
  --bg-card: rgba(18, 20, 29, 0.7);
  --bg-card-hover: rgba(26, 29, 42, 0.85);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-glow: rgba(99, 102, 241, 0.35);

  --accent-primary: #6366f1;
  --accent-primary-hover: #4f46e5;
  --accent-cyan: #06b6d4;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --shadow-panel: 0 20px 40px -15px rgba(0, 0, 0, 0.6), 0 0 0 1px var(--border-color);
  --shadow-glow: 0 0 25px rgba(99, 102, 241, 0.4);
}

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

body.dark-theme {
  background-color: var(--bg-main);
  color: var(--text-main);
  font-family: var(--font-sans);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Background Ambient Orbs */
.glow-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(120px);
  pointer-events: none;
  z-index: 0;
  opacity: 0.25;
}
.orb-1 {
  width: 450px;
  height: 450px;
  background: radial-gradient(circle, #6366f1, transparent);
  top: -100px;
  left: -50px;
}
.orb-2 {
  width: 550px;
  height: 550px;
  background: radial-gradient(circle, #06b6d4, transparent);
  bottom: -150px;
  right: -100px;
}
.orb-3 {
  width: 350px;
  height: 350px;
  background: radial-gradient(circle, #ec4899, transparent);
  top: 40%;
  left: 45%;
}

.app-container {
  position: relative;
  z-index: 1;
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ============================================================================
   TOP NAVIGATION
   ============================================================================ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-panel);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo-box {
  display: flex;
  align-items: center;
  gap: 14px;
}

.pulse-indicator {
  position: relative;
  width: 20px;
  height: 20px;
}
.pulse-core {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 12px;
  height: 12px;
  background-color: var(--accent-emerald);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--accent-emerald);
}
.pulse-wave {
  position: absolute;
  top: 0;
  left: 0;
  width: 20px;
  height: 20px;
  background-color: rgba(16, 185, 129, 0.4);
  border-radius: 50%;
  animation: pulseRipple 2s infinite ease-out;
}

@keyframes pulseRipple {
  0% { transform: scale(0.6); opacity: 0.8; }
  100% { transform: scale(1.6); opacity: 0; }
}

.logo-text h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #fff 0%, #cbd5e1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.logo-text .subtitle {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--accent-cyan);
}

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

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: all 0.25s ease;
}
.status-pill.online {
  border-color: rgba(16, 185, 129, 0.3);
  background: rgba(16, 185, 129, 0.08);
  color: #a7f3d0;
}
.status-pill.online .status-dot {
  background-color: var(--accent-emerald);
  box-shadow: 0 0 8px var(--accent-emerald);
}
.status-pill.offline .status-dot {
  background-color: var(--text-dim);
}
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.metric-card {
  display: flex;
  flex-direction: column;
  padding: 4px 12px;
  border-left: 2px solid rgba(255, 255, 255, 0.08);
}
.metric-title {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.metric-val {
  font-size: 1rem;
  font-weight: 700;
  font-family: var(--font-mono);
}
.cost-accent {
  color: var(--accent-emerald);
}

.icon-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}
.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  border-color: var(--accent-primary);
  transform: translateY(-1px);
}

/* ============================================================================
   GRID & PANELS
   ============================================================================ */
.dashboard-grid {
  display: grid;
  grid-template-columns: 440px 1fr;
  gap: 24px;
}

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

.glass-panel {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-panel);
  display: flex;
  flex-direction: column;
  gap: 20px;
  transition: border-color 0.3s ease;
}
.glass-panel:hover {
  border-color: rgba(255, 255, 255, 0.14);
}

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

.panel-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}
.panel-icon {
  font-size: 1.25rem;
}
.panel-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.badge {
  padding: 4px 10px;
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: #a5b4fc;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-full);
}

/* ============================================================================
   LAUNCHER FORM (LEFT)
   ============================================================================ */
.launcher-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.input-with-icon {
  position: relative;
  display: flex;
  align-items: center;
}
.input-icon {
  position: absolute;
  left: 14px;
  font-size: 1rem;
  pointer-events: none;
}
.input-with-icon input {
  padding-left: 42px !important;
}

input[type="text"],
input[type="tel"],
input[type="password"],
textarea,
select {
  width: 100%;
  padding: 12px 16px;
  background: rgba(10, 11, 16, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  transition: all 0.2s ease;
  outline: none;
}

input[type="text"]:focus,
input[type="tel"]:focus,
input[type="password"]:focus,
textarea:focus,
select:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

.field-hint {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.scenario-chips {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 500;
  text-align: left;
  transition: all 0.2s ease;
}
.chip:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
}
.chip.active {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--accent-primary);
  color: #fff;
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.25);
}

/* Range Slider */
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: var(--accent-primary);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 8px var(--accent-primary);
  transition: transform 0.15s ease;
}
input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

/* Toggle Switch Card */
.toggle-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}
.toggle-info {
  display: flex;
  flex-direction: column;
}
.toggle-title {
  font-size: 0.85rem;
  font-weight: 600;
}
.toggle-sub {
  font-size: 0.72rem;
  color: var(--text-dim);
}

.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 24px;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: rgba(255, 255, 255, 0.15);
  transition: 0.3s;
}
.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
}
input:checked + .slider {
  background-color: var(--accent-emerald);
}
input:checked + .slider:before {
  transform: translateX(22px);
}
.slider.round {
  border-radius: 34px;
}
.slider.round:before {
  border-radius: 50%;
}

/* Primary Button */
.primary-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 20px;
  background: linear-gradient(135deg, var(--accent-primary) 0%, #4338ca 100%);
  border: none;
  border-radius: var(--radius-md);
  color: #fff;
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
  transition: all 0.25s ease;
}
.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(99, 102, 241, 0.6);
}
.primary-btn:active {
  transform: translateY(0);
}

.secondary-btn {
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}
.secondary-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.danger-btn {
  padding: 8px 16px;
  background: rgba(244, 63, 94, 0.15);
  border: 1px solid rgba(244, 63, 94, 0.4);
  border-radius: var(--radius-sm);
  color: #fda4af;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}
.danger-btn:hover {
  background: rgba(244, 63, 94, 0.25);
  border-color: var(--accent-rose);
}

/* ============================================================================
   CALL MONITOR & PIPELINE (RIGHT)
   ============================================================================ */
.live-tag {
  display: inline-block;
  padding: 4px 8px;
  background: var(--accent-rose);
  color: white;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  border-radius: var(--radius-sm);
  animation: liveBlink 1.5s infinite;
}
@keyframes liveBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.call-controls {
  display: flex;
  gap: 8px;
}

/* State Machine Pipeline */
.call-pipeline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}
.pipeline-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.step-circle {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  color: var(--text-dim);
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}
.step-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  font-weight: 500;
  text-align: center;
}
.pipeline-step.active .step-circle {
  background: var(--accent-primary);
  border-color: #a5b4fc;
  color: white;
  box-shadow: 0 0 12px var(--accent-primary);
  transform: scale(1.1);
}
.pipeline-step.active .step-label {
  color: #fff;
  font-weight: 600;
}
.pipeline-step.done .step-circle {
  background: var(--accent-emerald);
  border-color: #6ee7b7;
  color: white;
}
.pipeline-step.done .step-label {
  color: #a7f3d0;
}
.pipeline-line {
  flex: 1;
  height: 2px;
  background: rgba(255, 255, 255, 0.08);
  margin: 0 8px;
  position: relative;
  top: -12px;
}

/* Audio Visualizer Bar */
.audio-visualizer-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}
.viz-text {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
}
.equalizer-bars {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 18px;
}
.equalizer-bars .bar {
  width: 3px;
  height: 4px;
  background-color: var(--accent-cyan);
  border-radius: 2px;
  transition: height 0.1s ease;
}
.equalizer-bars.active .bar {
  animation: soundBounce 0.8s infinite ease-in-out alternate;
}
.equalizer-bars.active .bar:nth-child(2) { animation-delay: 0.15s; }
.equalizer-bars.active .bar:nth-child(3) { animation-delay: 0.3s; }
.equalizer-bars.active .bar:nth-child(4) { animation-delay: 0.45s; }
.equalizer-bars.active .bar:nth-child(5) { animation-delay: 0.2s; }
.equalizer-bars.active .bar:nth-child(6) { animation-delay: 0.35s; }
.equalizer-bars.active .bar:nth-child(7) { animation-delay: 0.5s; }
.equalizer-bars.active .bar:nth-child(8) { animation-delay: 0.25s; }

@keyframes soundBounce {
  0% { height: 3px; }
  100% { height: 18px; background-color: var(--accent-emerald); }
}

.codec-tag {
  margin-left: auto;
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--accent-cyan);
}

/* Transcript Viewport */
.transcript-viewport {
  height: 380px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  padding: 20px;
  overflow-y: auto;
  position: relative;
  display: flex;
  flex-direction: column;
}

.empty-state {
  margin: auto;
  text-align: center;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.empty-icon {
  font-size: 2.5rem;
  opacity: 0.4;
}
.empty-state h3 {
  font-size: 1rem;
  color: var(--text-muted);
}
.empty-state p {
  font-size: 0.8rem;
  color: var(--text-dim);
  line-height: 1.5;
}

.transcript-messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chat-bubble {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 80%;
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-bubble.assistant {
  align-self: flex-start;
}
.chat-bubble.customer {
  align-self: flex-end;
}
.chat-bubble.system {
  align-self: center;
  max-width: 90%;
}

.bubble-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text-dim);
  font-weight: 600;
}
.assistant .bubble-meta {
  color: var(--accent-cyan);
}
.customer .bubble-meta {
  color: #a5b4fc;
}

.bubble-content {
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  line-height: 1.5;
}
.assistant .bubble-content {
  background: rgba(6, 182, 212, 0.12);
  border: 1px solid rgba(6, 182, 212, 0.3);
  color: #e0f2fe;
  border-bottom-left-radius: 2px;
}
.customer .bubble-content {
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: #ede9fe;
  border-bottom-right-radius: 2px;
}
.system .bubble-content {
  background: rgba(255, 255, 255, 0.05);
  border: 1px dashed var(--border-color);
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
  border-radius: var(--radius-full);
  padding: 6px 16px;
}

/* Delegation Footer */
.delegation-footer {
  padding: 12px 16px;
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.25);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.del-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fde68a;
}
.del-items {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.del-badge {
  padding: 4px 10px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(245, 158, 11, 0.4);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: #fef3c7;
  font-family: var(--font-mono);
}

/* ============================================================================
   CALL HISTORY TABLE (BOTTOM)
   ============================================================================ */
.table-container {
  overflow-x: auto;
}
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.history-table th {
  text-align: left;
  padding: 12px 16px;
  color: var(--text-dim);
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.history-table td {
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.history-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}
.empty-cell {
  color: var(--text-dim);
  padding: 30px !important;
}

.status-tag {
  display: inline-block;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
}
.status-tag.completed {
  background: rgba(16, 185, 129, 0.15);
  color: #6ee7b7;
}
.status-tag.failed {
  background: rgba(244, 63, 94, 0.15);
  color: #fda4af;
}

/* ============================================================================
   SETTINGS MODAL
   ============================================================================ */
.modal-backdrop {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-box {
  background: #11131c;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 580px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8);
  display: flex;
  flex-direction: column;
}
.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 {
  font-size: 1.1rem;
}
.close-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-dim);
  cursor: pointer;
}
.close-btn:hover { color: var(--text-main); }

.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.settings-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
}
.settings-section h4 {
  font-size: 0.95rem;
  color: var(--accent-cyan);
}
.info-alert {
  padding: 12px;
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: #c7d2fe;
}
.info-alert code {
  background: rgba(0, 0, 0, 0.3);
  padding: 2px 6px;
  border-radius: 4px;
}
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

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

#whatsapp-qr-container {
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

#whatsapp-qr-container:hover {
  transform: scale(1.02);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}
