/* ============================================
   Voice Input Button
   ============================================ */

.voice-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--color-text-muted, #8a7e6b);
  cursor: pointer;
  border-radius: 50%;
  transition: all 0.2s ease;
  flex-shrink: 0;
  padding: 0;
}

.voice-btn svg {
  width: 20px;
  height: 20px;
}

.voice-btn:hover {
  color: var(--color-river, #2d5a3d);
  background: var(--color-paper-warm, #f5f0e8);
}

.voice-btn.listening {
  color: #c0392b;
  background: rgba(192, 57, 43, 0.1);
  animation: voice-pulse 1.5s ease-in-out infinite;
}

@keyframes voice-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(192, 57, 43, 0.3); }
  50% { box-shadow: 0 0 0 8px rgba(192, 57, 43, 0); }
}

[data-theme="dark"] .voice-btn {
  color: var(--dm-text-muted, #8888aa);
}

[data-theme="dark"] .voice-btn:hover {
  color: var(--dm-primary, #5da888);
  background: var(--dm-surface, #1a1a2e);
}

[data-theme="dark"] .voice-btn.listening {
  color: #e74c3c;
  background: rgba(231, 76, 60, 0.15);
}

.voice-btn .hidden {
  display: none;
}

/* ============================================
   Voice Output / TTS
   ============================================ */

/* Voice mode toggle in header */
#voice-mode-toggle.active {
  color: var(--color-river, #2d5a3d);
  background: rgba(45, 90, 61, 0.1);
}

#voice-mode-toggle .hidden {
  display: none;
}

[data-theme="dark"] #voice-mode-toggle.active {
  color: var(--dm-primary, #5da888);
  background: rgba(93, 168, 136, 0.15);
}

/* ============================================
   Voice Mode Panel - Dedicated Voice View
   ============================================ */

.voice-mode-panel {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  background: var(--color-river-dark, #152840);
  padding: var(--space-6);
  overflow: hidden;
}

.voice-mode-panel.hidden {
  display: none;
}

/* Ambient background canvas */
.voice-ambient-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.35;
  z-index: 0;
}

/* Orb */
.voice-mode-orb-container {
  position: relative;
  width: 220px;
  height: 220px;
  flex-shrink: 0;
  z-index: 1;
}

/* Waveform canvas — fills orb container */
.voice-waveform-canvas {
  position: absolute;
  inset: -40px;
  width: calc(100% + 80px);
  height: calc(100% + 80px);
  pointer-events: none;
  z-index: 0;
}

.voice-mode-orb {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.orb-ring {
  position: absolute;
  border-radius: 50%;
  border: 1.5px solid rgba(91, 138, 184, 0.3);
  opacity: 0.3;
  transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.orb-ring-outer {
  width: 100%;
  height: 100%;
  animation: orb-pulse 4s ease-in-out infinite;
}

.orb-ring-middle {
  width: 72%;
  height: 72%;
  animation: orb-pulse 4s ease-in-out infinite 0.4s;
}

.orb-ring-inner {
  width: 46%;
  height: 46%;
  animation: orb-pulse 4s ease-in-out infinite 0.8s;
}

.orb-core {
  position: relative;
  z-index: 2;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-river-light) 0%, var(--color-river) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 0 30px rgba(30, 58, 95, 0.5),
    0 0 60px rgba(30, 58, 95, 0.2),
    inset 0 1px 1px rgba(255, 255, 255, 0.15);
  transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.orb-core svg {
  width: 30px;
  height: 30px;
  color: rgba(255, 255, 255, 0.9);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
}

/* Orb idle animation — slow, meditative breathing */
@keyframes orb-pulse {
  0%, 100% { transform: scale(1); opacity: 0.2; }
  50% { transform: scale(1.04); opacity: 0.35; }
}

/* Subtle glow pulse on idle core */
.voice-mode-orb.idle .orb-core,
.voice-mode-orb:not(.listening):not(.speaking) .orb-core {
  animation: core-breathe 4s ease-in-out infinite;
}

@keyframes core-breathe {
  0%, 100% {
    box-shadow:
      0 0 30px rgba(30, 58, 95, 0.5),
      0 0 60px rgba(30, 58, 95, 0.2),
      inset 0 1px 1px rgba(255, 255, 255, 0.15);
  }
  50% {
    box-shadow:
      0 0 40px rgba(45, 90, 135, 0.6),
      0 0 80px rgba(30, 58, 95, 0.3),
      inset 0 1px 1px rgba(255, 255, 255, 0.2);
  }
}

/* Orb listening state — warm brass, more energetic */
.voice-mode-orb.listening .orb-ring {
  border-color: rgba(184, 149, 110, 0.5);
  opacity: 0.6;
}

.voice-mode-orb.listening .orb-ring-outer {
  animation: orb-listening 1.4s ease-in-out infinite;
}

.voice-mode-orb.listening .orb-ring-middle {
  animation: orb-listening 1.4s ease-in-out infinite 0.2s;
}

.voice-mode-orb.listening .orb-ring-inner {
  animation: orb-listening 1.4s ease-in-out infinite 0.4s;
}

.voice-mode-orb.listening .orb-core {
  background: linear-gradient(135deg, var(--color-brass-light) 0%, var(--color-brass) 100%);
  box-shadow:
    0 0 35px rgba(184, 149, 110, 0.5),
    0 0 70px rgba(184, 149, 110, 0.25),
    inset 0 1px 1px rgba(255, 255, 255, 0.2);
  animation: none;
}

@keyframes orb-listening {
  0%, 100% { transform: scale(1); opacity: 0.35; }
  50% { transform: scale(1.1); opacity: 0.7; }
}

/* Orb speaking state — sage green, driven by waveform canvas */
.voice-mode-orb.speaking .orb-ring {
  border-color: rgba(107, 142, 107, 0.4);
  opacity: 0.5;
  animation: none;
}

.voice-mode-orb.speaking .orb-ring-outer {
  animation: orb-speaking-ring 2s ease-in-out infinite;
}

.voice-mode-orb.speaking .orb-ring-middle {
  animation: orb-speaking-ring 2s ease-in-out infinite 0.25s;
}

.voice-mode-orb.speaking .orb-ring-inner {
  animation: orb-speaking-ring 2s ease-in-out infinite 0.5s;
}

.voice-mode-orb.speaking .orb-core {
  background: linear-gradient(135deg, var(--color-sage-light) 0%, var(--color-sage) 100%);
  box-shadow:
    0 0 35px rgba(107, 142, 107, 0.5),
    0 0 70px rgba(107, 142, 107, 0.25),
    inset 0 1px 1px rgba(255, 255, 255, 0.2);
  animation: none;
}

@keyframes orb-speaking-ring {
  0%, 100% { transform: scale(1); opacity: 0.3; }
  25% { transform: scale(1.06); opacity: 0.55; }
  75% { transform: scale(0.97); opacity: 0.4; }
}

/* Status text — light on dark background */
.voice-mode-status {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  color: rgba(255, 255, 255, 0.9);
  margin: 0;
  text-align: center;
  z-index: 1;
  letter-spacing: var(--tracking-wide);
}

.voice-mode-hint {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: rgba(255, 255, 255, 0.5);
  margin: 0;
  text-align: center;
  min-height: 1.4em;
  font-style: italic;
  z-index: 1;
}

/* Transcript area */
.voice-mode-transcript {
  width: 100%;
  max-width: 480px;
  max-height: 40vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
  z-index: 1;
}

.voice-transcript-item {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  line-height: 1.5;
  padding: var(--space-2) var(--space-3);
  border-radius: 12px;
  max-width: 85%;
  animation: transcript-slide-in 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* Collapsible bot messages — default shows ~4 lines */
.voice-transcript-item.bot.collapsible {
  position: relative;
  cursor: pointer;
}

.voice-transcript-item.bot.collapsible .transcript-text {
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.voice-transcript-item.bot.collapsible.expanded .transcript-text {
  display: block;
  -webkit-line-clamp: unset;
  overflow: visible;
}

.voice-transcript-item .transcript-toggle {
  display: none;
}

.voice-transcript-item.bot.collapsible .transcript-toggle {
  display: inline-block;
  margin-top: 6px;
  font-size: var(--text-xs);
  color: rgba(255, 255, 255, 0.45);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.voice-transcript-item.bot.collapsible.expanded .transcript-toggle {
  color: rgba(255, 255, 255, 0.35);
}

@keyframes transcript-slide-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.voice-transcript-item.user {
  align-self: flex-end;
  background: rgba(45, 90, 135, 0.6);
  color: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(91, 138, 184, 0.3);
}

.voice-transcript-item.bot {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Typing indicator for bot responses */
.voice-transcript-typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 4px;
  padding: var(--space-2) var(--space-3);
  background: rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: transcript-slide-in 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.voice-transcript-typing .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.4);
  animation: typing-bounce 1.4s ease-in-out infinite;
}

.voice-transcript-typing .dot:nth-child(2) {
  animation-delay: 0.15s;
}

.voice-transcript-typing .dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 0.9; }
}

/* Controls */
.voice-mode-controls {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  flex-shrink: 0;
  z-index: 1;
}

.voice-mode-mic-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 2px solid rgba(91, 138, 184, 0.5);
  background: rgba(30, 58, 95, 0.3);
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.voice-mode-mic-btn svg {
  width: 32px;
  height: 32px;
}

.voice-mode-mic-btn .hidden {
  display: none;
}

.voice-mode-mic-btn:hover {
  background: rgba(45, 90, 135, 0.4);
  border-color: rgba(91, 138, 184, 0.7);
  box-shadow: 0 0 20px rgba(30, 58, 95, 0.3);
}

.voice-mode-mic-btn.listening {
  border-color: rgba(184, 149, 110, 0.7);
  color: var(--color-brass-light);
  background: rgba(184, 149, 110, 0.15);
  animation: mic-pulse 1.5s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(184, 149, 110, 0.3); }
  50% { box-shadow: 0 0 0 14px rgba(184, 149, 110, 0); }
}

/* Playback speed toggle */
.voice-speed-btn {
  min-width: 48px;
  height: 36px;
  padding: var(--space-1) var(--space-2);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.7);
  font-family: var(--font-mono, 'JetBrains Mono', monospace);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  letter-spacing: -0.02em;
  z-index: 1;
}

.voice-speed-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.9);
  border-color: rgba(255, 255, 255, 0.35);
}

.voice-speed-btn:active {
  transform: scale(0.95);
}

.voice-mode-exit-btn {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.6);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1;
}

.voice-mode-exit-btn svg {
  width: 16px;
  height: 16px;
}

.voice-mode-exit-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.85);
  border-color: rgba(255, 255, 255, 0.3);
}

/* Dark mode: voice panel already uses dark theme — no overrides needed for panel itself */
[data-theme="dark"] .voice-mode-mic-btn {
  border-color: rgba(91, 138, 184, 0.5);
  color: rgba(255, 255, 255, 0.8);
}

[data-theme="dark"] .voice-mode-mic-btn:hover {
  background: rgba(45, 90, 135, 0.4);
}

[data-theme="dark"] .voice-mode-mic-btn.listening {
  border-color: rgba(201, 168, 130, 0.7);
  color: var(--color-brass-light);
  background: rgba(201, 168, 130, 0.15);
}

[data-theme="dark"] .voice-transcript-item.user {
  background: rgba(45, 90, 135, 0.5);
}

[data-theme="dark"] .voice-transcript-item.bot {
  background: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .voice-mode-exit-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* Mobile responsive voice mode */
@media (max-width: 768px) {
  .voice-mode-orb-container {
    width: 170px;
    height: 170px;
  }

  .voice-waveform-canvas {
    inset: -30px;
    width: calc(100% + 60px);
    height: calc(100% + 60px);
  }

  .orb-core {
    width: 56px;
    height: 56px;
  }

  .orb-core svg {
    width: 24px;
    height: 24px;
  }

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

  .voice-mode-mic-btn svg {
    width: 26px;
    height: 26px;
  }

  .voice-mode-transcript {
    max-height: 35vh;
  }

  .voice-mode-status {
    font-size: var(--text-lg);
  }
}

/* Landscape orientation — horizontal layout */
@media (max-height: 500px) and (orientation: landscape) {
  .voice-mode-panel {
    flex-direction: row;
    padding: var(--space-3) var(--space-4);
    gap: var(--space-4);
  }

  .voice-mode-orb-container {
    width: 120px;
    height: 120px;
  }

  .voice-waveform-canvas {
    inset: -20px;
    width: calc(100% + 40px);
    height: calc(100% + 40px);
  }

  .orb-core {
    width: 44px;
    height: 44px;
  }

  .orb-core svg {
    width: 20px;
    height: 20px;
  }

  .voice-mode-transcript {
    flex: 1;
    max-height: 100%;
    max-width: none;
  }

  .voice-mode-status,
  .voice-mode-hint {
    display: none;
  }

  .voice-mode-controls {
    position: absolute;
    bottom: var(--space-3);
    right: var(--space-4);
    gap: var(--space-3);
  }

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

  .voice-mode-mic-btn svg {
    width: 22px;
    height: 22px;
  }
}

/* Message input disabled state */
.message-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: var(--bg-sunken);
}

/* Input wrapper when contents are disabled */
.input-wrapper:has(.message-input:disabled) {
  opacity: 0.8;
  border-color: var(--border-light);
}

/* Character counter for message input */
.char-counter {
  position: absolute;
  right: 60px;
  top: 50%;
  transform: translateY(-50%);
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-family: var(--font-mono);
  opacity: 0;
  transition: opacity var(--transition-fast);
  pointer-events: none;
}

.char-counter.visible {
  opacity: 1;
}

.char-counter.warning {
  color: var(--color-amber);
}

.char-counter.limit {
  color: var(--color-error);
  font-weight: 600;
}

.input-wrapper {
  position: relative;
}

