/* ============================================
   Realtime Voice Agent — Phase 2 Styles
   ============================================ */

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: #1a1a27;
  --bg-card-hover: #22223a;
  --border: #2a2a3e;
  --border-glow: #4f46e5;

  --text-primary: #e8e8f0;
  --text-secondary: #8888a0;
  --text-muted: #55556a;

  --accent: #6366f1;
  --accent-light: #818cf8;
  --accent-dark: #4338ca;

  --green: #22c55e;
  --green-glow: rgba(34, 197, 94, 0.3);
  --red: #ef4444;
  --red-glow: rgba(239, 68, 68, 0.3);
  --yellow: #eab308;
  --blue: #3b82f6;

  --radius: 12px;
  --radius-sm: 8px;
  --transition: 200ms ease;
}

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

body {
  font-family:
    "Inter",
    -apple-system,
    BlinkMacSystemFont,
    sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}

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

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

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

.btn-mute {
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--green);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-mute:hover {
  background: var(--bg-card-hover);
  border-color: var(--green);
}

.btn-mute.muted {
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.3);
}

.btn-mute.muted:hover {
  border-color: var(--red);
}

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

.logo-icon {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 0 20px rgba(99, 102, 241, 0.3);
}

.logo h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.phase-badge {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: var(--accent);
  color: white;
  padding: 3px 8px;
  border-radius: 20px;
  vertical-align: middle;
  margin-left: 6px;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 500;
}

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

.connection-status.connected .status-dot {
  background: var(--green);
  box-shadow: 0 0 8px var(--green-glow);
  animation: pulse 2s ease-in-out infinite;
}

.connection-status.error .status-dot {
  background: var(--red);
  box-shadow: 0 0 8px var(--red-glow);
}

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

/* Controls */
.controls {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  background: var(--bg-card);
  color: var(--text-primary);
}

.btn:hover:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: var(--accent);
}

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

.btn-connect {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  border-color: var(--accent);
  color: white;
}

.btn-connect:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--accent-light), var(--accent));
  box-shadow: 0 0 16px rgba(99, 102, 241, 0.3);
}

.btn-disconnect {
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.3);
}

.btn-disconnect:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.1);
  border-color: var(--red);
}

/* Mic Visualizer */
.mic-visualizer {
  display: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 20px;
  overflow: hidden;
}

.mic-visualizer.active {
  display: block;
}

#micCanvas {
  width: 100%;
  height: 60px;
  display: block;
}

/* Panels */
.panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

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

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color var(--transition);
}

.panel.active {
  border-color: var(--accent);
  box-shadow: 0 0 16px rgba(99, 102, 241, 0.1);
}

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

.panel-header h2 {
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.indicator {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--bg-secondary);
  color: var(--text-muted);
}

.indicator.listening {
  background: rgba(34, 197, 94, 0.15);
  color: var(--green);
}

.indicator.processing {
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent-light);
  animation: pulse 1s ease-in-out infinite;
}

.indicator.speaking {
  background: rgba(234, 179, 8, 0.15);
  color: var(--yellow);
  animation: pulse 1s ease-in-out infinite;
}

.panel-indicators {
  display: flex;
  gap: 6px;
}

.panel-content {
  padding: 18px;
  min-height: 160px;
  max-height: 300px;
  overflow-y: auto;
  font-size: 0.92rem;
  line-height: 1.7;
}

.panel-content::-webkit-scrollbar {
  width: 4px;
}

.panel-content::-webkit-scrollbar-track {
  background: transparent;
}

.panel-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.placeholder {
  color: var(--text-muted);
  font-style: italic;
}

.transcript-partial {
  color: var(--text-secondary);
  opacity: 0.7;
}

.transcript-final {
  color: var(--text-primary);
  margin-bottom: 8px;
  padding: 6px 10px;
  background: rgba(99, 102, 241, 0.08);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
}

.llm-response {
  margin-bottom: 12px;
  padding: 10px 14px;
  background: rgba(34, 197, 94, 0.06);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--green);
}

.llm-streaming {
  border-left-color: var(--yellow);
}

.llm-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent-light);
  animation: blink 0.8s step-end infinite;
  vertical-align: text-bottom;
  margin-left: 2px;
}

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

/* Barge-in status badges */
.status-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 12px;
  margin-right: 8px;
  vertical-align: middle;
  letter-spacing: 0.02em;
}

.status-badge.speaking {
  background: rgba(34, 197, 94, 0.2);
  color: var(--green);
  animation: pulse 1.5s ease-in-out infinite;
}

.status-badge.interrupted {
  background: rgba(239, 68, 68, 0.2);
  color: var(--red);
}

.llm-response.interrupted {
  border-left-color: var(--red);
  opacity: 0.6;
}

/* Metrics */
.metrics {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.metrics h3 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

@media (max-width: 600px) {
  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.metric-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.metric-value {
  font-size: 1.3rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent-light);
}

.metric-card-tts .metric-value {
  color: var(--yellow);
}

.metric-card-pipeline .metric-value {
  color: var(--green);
}

.timing-history h4 {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}

.timing-table-wrapper {
  overflow-x: auto;
}

.timing-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.timing-table th {
  text-align: left;
  padding: 8px 10px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.timing-table td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(42, 42, 62, 0.5);
  color: var(--text-secondary);
}

.timing-table td:first-child {
  color: var(--text-muted);
  font-weight: 600;
}

.timing-table td:nth-child(n + 3) {
  font-variant-numeric: tabular-nums;
  color: var(--accent-light);
  font-weight: 500;
}

.timing-table .user-text {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* TTS Selection */
.tts-select-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.select-tts {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition);
}

.select-tts:hover {
  border-color: var(--accent);
}

.select-tts:focus {
  border-color: var(--accent);
}

.metric-card-wait .metric-value {
  color: var(--accent);
}

/* Scrollbar for panel content */
.panel-content {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
