/* ==========================================================================
   Voice Mode — Conversational UI
   All values from tokens.css — zero hardcoded colors or @keyframes.
   ========================================================================== */

/* ---------- Full-screen overlay ---------- */
.voice-panel {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 14, 0.95);
  backdrop-filter: blur(40px) saturate(1.5);
  -webkit-backdrop-filter: blur(40px) saturate(1.5);
  z-index: var(--z-voice);
  display: none;
  flex-direction: column;
  align-items: center;
  font-family: var(--font-body);
}

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

/* ---------- Close button ---------- */
.voice-close {
  position: absolute;
  top: calc(env(safe-area-inset-top, var(--space-3)) + var(--space-3));
  right: var(--space-4);
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-light);
  background: var(--accent-subtle);
  color: var(--text-secondary);
  font-size: var(--text-xl);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--duration-normal) var(--ease-default);
  z-index: var(--z-sticky);
}

.voice-close:hover {
  background: var(--bg-surface-hover);
  color: var(--text);
  border-color: var(--border-hover);
}

/* ---------- Conversation transcript ---------- */
.voice-conversation {
  flex: 1;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, var(--space-5)) + 64px) var(--space-5) var(--space-6);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
}

.voice-conversation::-webkit-scrollbar {
  width: var(--space-1);
}

.voice-conversation::-webkit-scrollbar-track {
  background: transparent;
}

.voice-conversation::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: var(--space-1);
}

/* ---------- Turn wrapper ---------- */
.voice-turn {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  max-width: 85%;
  animation: fadeIn var(--duration-slow) var(--ease-default) forwards;
}

/* User turn — right-aligned accent bubble */
.voice-turn.user {
  align-self: flex-end;
  align-items: flex-end;
}

.voice-turn.user .voice-turn-text {
  background: var(--accent);
  color: var(--text-inverse);
  border-radius: 18px 18px 4px 18px;
  font-weight: 500;
}

/* Assistant turn — left-aligned subtle bubble */
.voice-turn.assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.voice-turn.assistant .voice-turn-text {
  background: var(--bg-surface);
  color: var(--text);
  border-radius: 18px 18px 18px 4px;
  border: 1px solid var(--border-light);
}

/* Turn label ("You", bot name) */
.voice-turn .voice-turn-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--text-secondary);
  padding: 0 var(--space-2);
}

.voice-turn.user .voice-turn-label {
  color: var(--accent);
}

/* Turn text bubble */
.voice-turn .voice-turn-text {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-md);
  line-height: var(--leading-relaxed);
  word-break: break-word;
}

.voice-turn .voice-turn-text ul,
.voice-turn .voice-turn-text ol {
  padding-left: var(--space-5);
  margin: var(--space-2) 0;
}

.voice-turn .voice-turn-text ul {
  list-style: none;
}

.voice-turn .voice-turn-text ul li {
  position: relative;
  padding-left: var(--space-4);
  margin-bottom: var(--space-1);
}

.voice-turn .voice-turn-text ul li::before {
  content: "";
  position: absolute;
  left: var(--space-1);
  top: 0.6em;
  width: 5px;
  height: 5px;
  border-radius: var(--radius-full);
  background: var(--text-muted);
}

.voice-turn .voice-turn-text ol li {
  margin-bottom: var(--space-1);
}

.voice-turn .voice-turn-text li::marker {
  color: var(--text-muted);
}

.voice-turn .voice-turn-text p {
  margin-bottom: var(--space-2);
}

.voice-turn .voice-turn-text p:last-child {
  margin-bottom: 0;
}

/* Interim / currently-being-spoken */
.voice-turn.interim .voice-turn-text {
  animation: pulse 1.5s ease-in-out infinite;
}

/* ---------- Orb container ---------- */
.voice-orb-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5) var(--space-2);
  flex-shrink: 0;
}

.voice-waveform {
  width: 280px;
  height: var(--space-10);
  opacity: 0.8;
}

/* ---------- Orb ---------- */
.voice-orb {
  width: 120px;
  height: 120px;
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  border: 2px solid var(--border-light);
  position: relative;
  transition: background var(--duration-slow) var(--ease-default),
              border-color var(--duration-slow) var(--ease-default),
              box-shadow var(--duration-slow) var(--ease-default);
  cursor: pointer;
}

/* Idle state */
.voice-orb.idle {
  background: var(--accent-subtle);
  border-color: var(--border-light);
  box-shadow: none;
}

/* Listening — accent glow pulse */
.voice-orb.listening {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 var(--space-8) var(--accent-glow);
  animation: orbListenPulse 2s ease-in-out infinite;
}

/* Processing / Thinking — accent-subtle with spinning ring */
.voice-orb.processing,
.voice-orb.thinking {
  background: var(--accent-subtle);
  border-color: var(--accent);
  box-shadow: 0 0 var(--space-5) var(--accent-glow);
  animation: orbThinkPulse 1.2s ease-in-out infinite;
}

.voice-orb.processing::after,
.voice-orb.thinking::after {
  content: '';
  position: absolute;
  inset: -8px;
  border-radius: var(--radius-full);
  border: 3px solid transparent;
  border-top-color: var(--accent);
  border-right-color: var(--accent-glow);
  animation: orbSpin 1s linear infinite;
}

/* Speaking — success glow */
.voice-orb.speaking {
  background: var(--success);
  border-color: var(--success);
  box-shadow: 0 0 var(--space-8) var(--success-subtle);
  animation: orbSpeakPulse 1.6s ease-in-out infinite;
}

/* Drag-to-cancel state */
.voice-orb.drag-cancel {
  background: var(--danger-subtle);
  border-color: var(--danger);
  box-shadow: 0 0 var(--space-5) var(--danger-subtle);
  animation: none;
  transform: scale(0.9);
  opacity: 0.6;
}

.voice-orb.drag-cancel svg {
  color: var(--danger);
}

/* ---------- Orb inner icon centering ---------- */
.voice-orb svg {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-secondary);
  transition: color var(--duration-slow) var(--ease-default);
}

.voice-orb.listening svg,
.voice-orb.processing svg,
.voice-orb.speaking svg {
  color: var(--text-inverse);
}

/* ---------- Status text ---------- */
.voice-status-text {
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--text-secondary);
  text-align: center;
  letter-spacing: var(--tracking-normal);
  min-height: var(--space-5);
  transition: color var(--duration-slow) var(--ease-default);
}

.voice-status-text.thinking-anim {
  color: var(--accent);
  font-weight: 600;
}

.voice-orb.listening ~ .voice-status-text {
  color: var(--accent);
}

.voice-orb.speaking ~ .voice-status-text {
  color: var(--success);
}

/* ---------- Controls row ---------- */
.voice-controls {
  display: flex;
  gap: var(--space-4);
  align-items: center;
  justify-content: center;
  padding: var(--space-1) var(--space-5) var(--space-4);
  flex-shrink: 0;
}

.voice-btn {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xl);
  transition: all var(--duration-normal) var(--ease-default);
}

.voice-btn:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-hover);
}

.voice-btn.mic {
  width: 64px;
  height: 64px;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text-inverse);
  font-size: var(--text-2xl);
}

.voice-btn.mic:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 var(--space-5) var(--accent-glow);
}

.voice-btn.mic.active {
  background: var(--danger);
  border-color: var(--danger);
  box-shadow: 0 0 var(--space-5) var(--danger-subtle);
}

.voice-btn.secondary {
  background: var(--accent-subtle);
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
}

.voice-btn.secondary:hover {
  background: var(--bg-surface-hover);
  color: var(--text);
}

/* ---------- Hidden audio player ---------- */
.voice-audio-player {
  display: none;
}

/* ---------- Voice Settings ---------- */
.voice-settings .voice-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.voice-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color var(--duration-normal) var(--ease-default);
  background: var(--bg);
}

.voice-item:hover,
.voice-item.selected {
  border-color: var(--accent);
}

.voice-item .voice-name {
  flex: 1;
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--text);
}

.voice-item .voice-badge {
  font-size: var(--text-xs);
  padding: var(--space-0-5) var(--space-2);
  border-radius: var(--radius-full);
  background: var(--accent-subtle);
  color: var(--accent);
  font-weight: 600;
}

.voice-item .voice-badge.clone {
  background: var(--success-subtle);
  color: var(--success);
}

/* ---------- Clone Upload ---------- */
.clone-upload {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--duration-normal) var(--ease-default),
              background var(--duration-normal) var(--ease-default);
}

.clone-upload:hover,
.clone-upload.dragover {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .voice-close {
    right: auto;
    left: var(--space-4);
  }

  .voice-conversation {
    padding: 60px var(--space-4) var(--space-4);
    max-width: 100%;
  }

  .voice-orb {
    width: 96px;
    height: 96px;
  }

  .voice-turn {
    max-width: 92%;
  }

  .voice-turn .voice-turn-text {
    font-size: var(--text-base);
    padding: var(--space-3) var(--space-3);
  }

  .voice-btn.mic {
    width: 56px;
    height: 56px;
  }

  .voice-btn {
    width: 44px;
    height: 44px;
  }
}
