/* ============================================
   Real-Time Voice AI Agent - Styles
   Modern dark theme with smooth animations
   ============================================ */

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: #1a1a2e;
  --bg-card-hover: #1e1e35;
  --border: #2a2a40;
  --text-primary: #e8e8f0;
  --text-secondary: #8888a0;
  --text-muted: #555570;
  --accent: #6c63ff;
  --accent-glow: rgba(108, 99, 255, 0.3);
  --accent-hover: #7b73ff;
  --success: #4ade80;
  --warning: #fbbf24;
  --error: #f87171;
  --user-color: #38bdf8;
  --agent-color: #a78bfa;
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ---- Layout ---- */

.app-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 32px 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ---- Header ---- */

.header {
  text-align: center;
  padding-bottom: 8px;
}

.header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--agent-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.header .subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ---- Provider Selector ---- */

.provider-selector {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.provider-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.provider-options {
  display: flex;
  gap: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}

.provider-btn {
  padding: 8px 18px;
  font-size: 0.82rem;
  font-weight: 500;
  font-family: inherit;
  border: none;
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  border-right: 1px solid var(--border);
}

.provider-btn:last-child {
  border-right: none;
}

.provider-btn:hover:not(:disabled) {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.provider-btn.active {
  background: var(--accent);
  color: white;
}

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

.provider-btn:disabled.active {
  opacity: 0.85;
}

/* ---- Status Bar ---- */

.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 20px;
}

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

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s;
}

.status-dot.connected {
  background: var(--success);
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.5);
}

.status-dot.connecting {
  background: var(--warning);
  animation: pulse 1s ease-in-out infinite;
}

.status-dot.error {
  background: var(--error);
}

.status-dot.disconnected {
  background: var(--text-muted);
}

.status-text {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

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

.active-provider {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  padding: 2px 10px;
  border-radius: 10px;
  background: rgba(108, 99, 255, 0.12);
}

.active-provider:empty {
  display: none;
}

.latency-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

#latency {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--success);
  font-variant-numeric: tabular-nums;
}

/* ---- Visualizer (animated orb) ---- */

.visualizer-container {
  display: flex;
  justify-content: center;
  padding: 20px 0;
}

.visualizer {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, var(--accent), #3a35a0);
  box-shadow: 0 0 40px var(--accent-glow);
  transition: all 0.4s ease;
  position: relative;
}

.visualizer::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid transparent;
  transition: border-color 0.3s;
}

.visualizer.listening {
  box-shadow: 0 0 60px var(--accent-glow);
  animation: breathe 3s ease-in-out infinite;
}

.visualizer.user-speaking {
  box-shadow: 0 0 80px rgba(56, 189, 248, 0.4);
  background: radial-gradient(circle at 40% 40%, var(--user-color), #1e6fa0);
  animation: speak-pulse 0.3s ease-in-out infinite alternate;
}

.visualizer.thinking {
  animation: think-spin 2s linear infinite;
  box-shadow: 0 0 50px rgba(251, 191, 36, 0.3);
  background: radial-gradient(circle at 40% 40%, var(--warning), #a07520);
}

.visualizer.speaking {
  animation: speak-pulse 0.4s ease-in-out infinite alternate;
  box-shadow: 0 0 80px rgba(167, 139, 250, 0.4);
  background: radial-gradient(circle at 40% 40%, var(--agent-color), #6040c0);
}

/* ---- Connect Button ---- */

.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.controls-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0;
}

.connect-btn {
  padding: 14px 40px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent), #5548d9);
  color: white;
  transition: all 0.3s ease;
  letter-spacing: 0.01em;
}

.connect-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--accent-hover), #6860e0);
  transform: translateY(-1px);
  box-shadow: 0 4px 20px var(--accent-glow);
}

.connect-btn:active:not(:disabled) {
  transform: translateY(0);
}

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

.connect-btn.active {
  background: linear-gradient(135deg, var(--error), #d04040);
}

.connect-btn.active:hover:not(:disabled) {
  background: linear-gradient(135deg, #ff8080, #e04040);
  box-shadow: 0 4px 20px rgba(248, 113, 113, 0.3);
}

.connect-btn-retry {
  margin-top: 12px;
}

/* ---- Microphone permission banner ---- */

.mic-permission-banner {
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.35);
  border-radius: var(--radius);
  padding: 20px;
}

.mic-permission-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--warning);
  margin-bottom: 8px;
}

.mic-permission-text {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.mic-permission-steps {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 12px;
}

.mic-permission-steps strong {
  color: var(--text-primary);
}

.mic-permission-steps ul {
  margin: 8px 0 8px 20px;
}

.mic-permission-steps li {
  margin-bottom: 6px;
}

.mic-permission-steps code {
  background: var(--bg-secondary);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.8em;
}

/* ---- Agent State Badge ---- */

.agent-state-container {
  display: flex;
  justify-content: center;
}

.agent-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  transition: all 0.3s;
}

.agent-state.state-listening {
  border-color: var(--accent);
  color: var(--accent);
}

.agent-state.state-thinking {
  border-color: var(--warning);
  color: var(--warning);
}

.agent-state.state-speaking {
  border-color: var(--agent-color);
  color: var(--agent-color);
}

/* ---- Panels ---- */

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}

.panel-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* ---- Transcript Panel ---- */

#transcript {
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text-secondary);
  min-height: 24px;
  transition: color 0.3s;
}

#transcript.final {
  color: var(--text-primary);
}

#transcript.speaking {
  color: var(--user-color);
}

/* ---- Agent Response Panel ---- */

#agentResponse {
  font-size: 1rem;
  line-height: 1.6;
  color: var(--agent-color);
  min-height: 24px;
  max-height: 150px;
  overflow-y: auto;
}

/* ---- Conversation Log ---- */

.conversation-panel {
  flex: 1;
  min-height: 200px;
  max-height: 400px;
  display: flex;
  flex-direction: column;
}

#conversationLog {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 350px;
  padding-right: 8px;
}

#conversationLog::-webkit-scrollbar {
  width: 4px;
}

#conversationLog::-webkit-scrollbar-track {
  background: transparent;
}

#conversationLog::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.log-entry {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: fadeIn 0.3s ease;
}

.log-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: 4px;
  flex-shrink: 0;
  min-width: 32px;
  text-align: center;
}

.log-entry.user .log-label {
  background: rgba(56, 189, 248, 0.15);
  color: var(--user-color);
}

.log-entry.assistant .log-label {
  background: rgba(167, 139, 250, 0.15);
  color: var(--agent-color);
}

.log-text {
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-primary);
  padding-top: 2px;
}

/* ---- Footer ---- */

.footer {
  text-align: center;
  padding: 12px 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ---- Animations ---- */

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

@keyframes breathe {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 40px var(--accent-glow);
  }
  50% {
    transform: scale(1.05);
    box-shadow: 0 0 60px var(--accent-glow);
  }
}

@keyframes speak-pulse {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.08);
  }
}

@keyframes think-spin {
  0% {
    box-shadow: 0 0 40px rgba(251, 191, 36, 0.2);
  }
  50% {
    box-shadow: 0 0 60px rgba(251, 191, 36, 0.4);
  }
  100% {
    box-shadow: 0 0 40px rgba(251, 191, 36, 0.2);
  }
}

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

/* ---- Responsive ---- */

@media (max-width: 600px) {
  .app-container {
    padding: 16px 12px;
  }

  .header h1 {
    font-size: 1.4rem;
  }

  .visualizer {
    width: 90px;
    height: 90px;
  }

  .connect-btn {
    padding: 12px 32px;
    font-size: 0.9rem;
  }

  .status-bar {
    flex-direction: column;
    gap: 8px;
  }
}
