/**
 * EVA Widget - Unified Voice & Text Chat Widget
 *
 * Supports three modes:
 * - text: Text chat only
 * - voice: Voice only (Siri-like ball)
 * - both: Text + Voice toggle
 */

/* ========================================
   Base Container
   ======================================== */

.eva-widget {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ========================================
   Toggle Button (Minimized State)
   ======================================== */

.eva-toggle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #06AED5 0%, #8B5CF6 100%);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(6, 174, 213, 0.4);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.eva-toggle:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 25px rgba(6, 174, 213, 0.5);
}

.eva-toggle-icon {
  width: 28px;
  height: 28px;
  color: white;
}

/* Connection indicator on toggle */
.eva-toggle .eva-connection-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ef4444;
  border: 2px solid white;
  opacity: 1;
  transition: all 0.3s ease;
}

.eva-toggle .eva-connection-dot.connected {
  background: #4ade80;
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.8);
}

/* Voice mode toggle - connected state glow */
.eva-widget[data-active-mode="voice"] .eva-toggle.connected {
  box-shadow: 0 4px 20px rgba(74, 222, 128, 0.5), 0 0 30px rgba(6, 174, 213, 0.3);
}

/* Voice mode toggle - disconnected state */
.eva-widget[data-active-mode="voice"] .eva-toggle:not(.connected) {
  opacity: 0.8;
}

/* Hide toggle when panel is open (text mode only) */
.eva-widget.open[data-active-mode="text"] .eva-toggle {
  display: none;
}

/* In voice mode, always show toggle (it's the voice ball) */
.eva-widget[data-active-mode="voice"] .eva-toggle {
  display: flex;
}

/* Voice mode toggle - show mic icon instead of chat */
.eva-widget[data-active-mode="voice"] .eva-toggle .eva-toggle-icon-chat {
  display: none;
}

.eva-widget[data-active-mode="voice"] .eva-toggle .eva-toggle-icon-mic {
  display: block;
}

.eva-toggle .eva-toggle-icon-mic {
  display: none;
}

/* Voice mode toggle states */
.eva-widget[data-active-mode="voice"] .eva-toggle.connected {
  animation: eva-pulse-idle 3s ease-in-out infinite;
}

.eva-widget[data-active-mode="voice"] .eva-toggle.listening {
  width: 70px;
  height: 70px;
  box-shadow: 0 0 30px rgba(6, 174, 213, 0.8), 0 0 60px rgba(6, 174, 213, 0.4);
  animation: eva-pulse-listening 1.5s ease-in-out infinite;
}

.eva-widget[data-active-mode="voice"] .eva-toggle.speaking {
  width: 70px;
  height: 70px;
  animation: eva-wave-speaking 0.6s ease-in-out infinite;
}

.eva-widget[data-active-mode="voice"] .eva-toggle.thinking {
  animation: eva-rotate-thinking 2s linear infinite;
}

/* Ensure ball stays on top during all states */
.eva-widget[data-active-mode="voice"] .eva-toggle.listening,
.eva-widget[data-active-mode="voice"] .eva-toggle.speaking,
.eva-widget[data-active-mode="voice"] .eva-toggle.thinking {
  z-index: 10;
}

/* ========================================
   Chat Panel
   ======================================== */

.eva-panel {
  width: 380px;
  height: 520px;
  background: #1a1a1a;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.eva-widget.open .eva-panel {
  display: flex;
}

/* In voice mode, position panel above the toggle ball */
.eva-widget[data-active-mode="voice"] .eva-panel {
  position: absolute;
  bottom: 90px;
  right: 0;
}

.eva-widget[data-active-mode="voice"] .eva-toggle {
  position: absolute;
  bottom: 0;
  right: 0;
  z-index: 10;
}


/* ========================================
   Header
   ======================================== */

.eva-header {
  background: linear-gradient(135deg, #06AED5 0%, #8B5CF6 100%);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

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

.eva-header-title {
  color: white;
  font-size: 16px;
  font-weight: 600;
}

.eva-connection-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.4);
  transition: background 0.3s ease;
}

.eva-connection-indicator.connected {
  background: #4ade80;
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.6);
}

.eva-connection-indicator.error {
  background: #ef4444;
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.6);
}

/* Connection status text */
.eva-connection-status {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.6);
  margin-left: 4px;
}

.eva-connection-status.connected {
  color: #4ade80;
}

.eva-connection-status.error {
  color: #ef4444;
}

.eva-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* Mode Toggle Buttons (only visible in 'both' mode) */
.eva-mode-toggle {
  display: none;
  gap: 4px;
}

.eva-widget[data-widget-mode="both"] .eva-mode-toggle {
  display: flex;
}

.eva-mode-btn {
  padding: 6px 12px;
  border-radius: 6px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
}

.eva-mode-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: white;
}

.eva-mode-btn.active {
  background: rgba(255, 255, 255, 0.25);
  color: white;
}

.eva-mode-btn svg {
  width: 14px;
  height: 14px;
}

/* Voice Toggle Button (start/stop) - only visible in voice mode */
.eva-voice-toggle-btn {
  display: none;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: #4ade80;
  color: white;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.eva-voice-toggle-btn:hover {
  transform: scale(1.05);
}

.eva-voice-toggle-btn svg {
  width: 14px;
  height: 14px;
}

/* Show in voice mode */
.eva-widget[data-active-mode="voice"] .eva-voice-toggle-btn {
  display: flex;
}

/* Default: show play icon (when disconnected) */
.eva-voice-toggle-btn .eva-icon-stop {
  display: none;
}

.eva-voice-toggle-btn .eva-icon-play {
  display: block;
}

/* When connected: show stop icon, red background */
.eva-widget.voice-connected .eva-voice-toggle-btn {
  background: #ef4444;
}

.eva-widget.voice-connected .eva-voice-toggle-btn:hover {
  background: #dc2626;
}

.eva-widget.voice-connected .eva-voice-toggle-btn .eva-icon-stop {
  display: block;
}

.eva-widget.voice-connected .eva-voice-toggle-btn .eva-icon-play {
  display: none;
}

/* Close Button */
.eva-close {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.eva-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ========================================
   Messages Area (Text Mode)
   ======================================== */

.eva-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

/* Scrollbar styling */
.eva-messages::-webkit-scrollbar {
  width: 6px;
}

.eva-messages::-webkit-scrollbar-track {
  background: transparent;
}

.eva-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

.eva-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Message Bubbles */
.eva-message {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: eva-message-appear 0.3s ease;
}

@keyframes eva-message-appear {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.eva-message.user {
  background: #333;
  color: #e0e0e0;
  margin-left: auto;
  border-bottom-right-radius: 4px;
}

.eva-message.assistant {
  background: linear-gradient(135deg, rgba(6, 174, 213, 0.15) 0%, rgba(139, 92, 246, 0.15) 100%);
  color: #e0e0e0;
  margin-right: auto;
  border-bottom-left-radius: 4px;
  border-left: 3px solid #06AED5;
}

.eva-message.system {
  background: rgba(255, 255, 255, 0.05);
  color: #999;
  font-size: 12px;
  text-align: center;
  margin: 4px auto;
  padding: 6px 12px;
  border-radius: 8px;
  max-width: 90%;
}

/* Streaming cursor indicator */
.eva-message.streaming::after {
  content: '|';
  animation: eva-blink 0.8s infinite;
  margin-left: 2px;
  color: #06AED5;
}

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

/* ========================================
   Processing Indicator (Typing Dots)
   ======================================== */

.eva-typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: linear-gradient(135deg, rgba(6, 174, 213, 0.1) 0%, rgba(139, 92, 246, 0.1) 100%);
  border-radius: 12px;
  border-left: 3px solid #06AED5;
  margin-right: auto;
  max-width: 85%;
  animation: eva-message-appear 0.3s ease;
}

.eva-typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
}

.eva-typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: linear-gradient(135deg, #06AED5 0%, #8B5CF6 100%);
  animation: eva-typing-bounce 1.4s ease-in-out infinite;
}

.eva-typing-dot:nth-child(1) {
  animation-delay: 0s;
}

.eva-typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.eva-typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

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

.eva-typing-text {
  color: #999;
  font-size: 13px;
  margin-left: 4px;
  animation: eva-fade-in 0.3s ease;
}

@keyframes eva-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Empty state */
.eva-messages-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #666;
  font-size: 14px;
  text-align: center;
  padding: 20px;
}

/* ========================================
   Input Area (Text Mode)
   ======================================== */

.eva-input-area {
  padding: 12px;
  border-top: 1px solid #333;
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.eva-input {
  flex: 1;
  background: #333;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 12px;
  color: white;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  transition: border-color 0.2s ease;
}

.eva-input:focus {
  outline: none;
  border-color: #8B5CF6;
}

.eva-input::placeholder {
  color: #666;
}

.eva-send {
  background: linear-gradient(135deg, #06AED5 0%, #8B5CF6 100%);
  border: none;
  border-radius: 8px;
  padding: 12px 16px;
  color: white;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.eva-send:hover {
  transform: scale(1.02);
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

.eva-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.eva-send svg {
  width: 18px;
  height: 18px;
}

/* ========================================
   Voice Area (Voice Mode) - Hidden since ball is outside
   ======================================== */

.eva-voice-area {
  display: none;
}

/* In voice mode: hide input area, show only messages for transcript */
.eva-widget[data-active-mode="voice"] .eva-input-area {
  display: none;
}

/* Voice mode panel is just for transcripts */
.eva-widget[data-active-mode="voice"] .eva-messages {
  flex: 1;
  background: #1a1a1a;
}

/* Voice mode - simpler header */
.eva-widget[data-active-mode="voice"] .eva-header {
  padding: 10px 12px;
}

.eva-widget[data-active-mode="voice"] .eva-header-left {
  flex-shrink: 0;
}

.eva-widget[data-active-mode="voice"] .eva-header-title {
  font-size: 14px;
}

/* Hide status text in voice mode - dot indicator is enough */
.eva-widget[data-active-mode="voice"] .eva-connection-status {
  display: none;
}

/* Back to text button - hidden, use mode toggle instead */
.eva-back-to-text {
  display: none !important;
}

/* Siri Ball (in panel) */
.eva-siri-ball {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(135deg, #06AED5 0%, #8B5CF6 100%);
  box-shadow: 0 4px 20px rgba(6, 174, 213, 0.4);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.eva-siri-ball:hover {
  transform: scale(1.05);
}

.eva-siri-ball-icon {
  width: 32px;
  height: 32px;
  color: white;
  transition: opacity 0.3s ease;
}

/* Shine effect */
.eva-siri-ball::before {
  content: '';
  position: absolute;
  top: 20%;
  left: 20%;
  width: 50%;
  height: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.4) 0%, transparent 70%);
  border-radius: 50%;
  filter: blur(12px);
  pointer-events: none;
}

/* Siri Ball States */
.eva-siri-ball.idle {
  animation: eva-pulse-idle 3s ease-in-out infinite;
}

@keyframes eva-pulse-idle {
  0%, 100% {
    transform: scale(1);
    opacity: 0.9;
  }
  50% {
    transform: scale(1.02);
    opacity: 1;
  }
}

.eva-siri-ball.listening {
  width: 90px;
  height: 90px;
  box-shadow: 0 0 30px rgba(6, 174, 213, 0.8), 0 0 60px rgba(6, 174, 213, 0.4);
  animation: eva-pulse-listening 1.5s ease-in-out infinite;
}

.eva-siri-ball.listening .eva-siri-ball-icon {
  opacity: 0;
}

@keyframes eva-pulse-listening {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 40px rgba(6, 174, 213, 0.8), 0 0 80px rgba(6, 174, 213, 0.4);
  }
  50% {
    transform: scale(1.08);
    box-shadow: 0 0 50px rgba(6, 174, 213, 1), 0 0 100px rgba(6, 174, 213, 0.6);
  }
}

.eva-siri-ball.speaking {
  width: 90px;
  height: 90px;
  animation: eva-wave-speaking 0.6s ease-in-out infinite;
}

.eva-siri-ball.speaking .eva-siri-ball-icon {
  opacity: 0;
}

@keyframes eva-wave-speaking {
  0%, 100% {
    transform: scale(1) translateY(0);
    border-radius: 50%;
  }
  25% {
    transform: scale(1.05, 0.95) translateY(-3px);
    border-radius: 48% 52% 50% 50%;
  }
  50% {
    transform: scale(0.95, 1.05) translateY(0);
    border-radius: 50% 50% 48% 52%;
  }
  75% {
    transform: scale(1.05, 0.95) translateY(3px);
    border-radius: 52% 48% 50% 50%;
  }
}

.eva-siri-ball.thinking {
  animation: eva-rotate-thinking 2s linear infinite;
}

.eva-siri-ball.thinking .eva-siri-ball-icon {
  opacity: 0;
}

@keyframes eva-rotate-thinking {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Voice status text */
.eva-voice-status {
  color: #999;
  font-size: 14px;
  text-align: center;
}

/* Voice transcript (optional live display) */
.eva-voice-transcript {
  max-width: 100%;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  color: #e0e0e0;
  font-size: 14px;
  text-align: center;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ========================================
   Voice-Only Mode (No Panel - Just Ball)
   ======================================== */

.eva-widget[data-widget-mode="voice"] .eva-panel {
  display: none !important;
}

.eva-widget[data-widget-mode="voice"] .eva-toggle {
  display: none;
}

.eva-widget[data-widget-mode="voice"] .eva-voice-ball-standalone {
  display: flex;
}

.eva-voice-ball-standalone {
  display: none;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(135deg, #06AED5 0%, #8B5CF6 100%);
  box-shadow: 0 4px 20px rgba(6, 174, 213, 0.4);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  align-items: center;
  justify-content: center;
}

.eva-voice-ball-standalone:hover {
  transform: scale(1.05);
}

.eva-voice-ball-standalone .eva-ball-icon {
  width: 32px;
  height: 32px;
  color: white;
}

/* Connection indicator on standalone ball */
.eva-voice-ball-standalone .eva-connection-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #4ade80;
  border: 2px solid white;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.eva-voice-ball-standalone .eva-connection-dot.connected {
  opacity: 1;
}

/* Standalone ball states */
.eva-voice-ball-standalone.idle {
  animation: eva-pulse-idle 3s ease-in-out infinite;
}

.eva-voice-ball-standalone.listening {
  width: 100px;
  height: 100px;
  box-shadow: 0 0 40px rgba(6, 174, 213, 0.8), 0 0 80px rgba(6, 174, 213, 0.4);
  animation: eva-pulse-listening 1.5s ease-in-out infinite;
}

.eva-voice-ball-standalone.listening .eva-ball-icon {
  opacity: 0;
}

.eva-voice-ball-standalone.speaking {
  width: 100px;
  height: 100px;
  animation: eva-wave-speaking 0.6s ease-in-out infinite;
}

.eva-voice-ball-standalone.speaking .eva-ball-icon {
  opacity: 0;
}

.eva-voice-ball-standalone.thinking {
  width: 90px;
  height: 90px;
  animation: eva-rotate-thinking 2s linear infinite;
}

.eva-voice-ball-standalone.thinking .eva-ball-icon {
  opacity: 0;
}

/* ========================================
   Responsive Design
   ======================================== */

@media (max-width: 480px) {
  .eva-widget {
    right: 10px;
    bottom: 10px;
  }

  .eva-panel {
    width: calc(100vw - 20px);
    height: calc(100vh - 80px);
    max-height: 600px;
    border-radius: 12px;
  }

  .eva-toggle {
    width: 54px;
    height: 54px;
  }

  .eva-voice-ball-standalone {
    width: 70px;
    height: 70px;
  }

  .eva-voice-ball-standalone.listening,
  .eva-voice-ball-standalone.speaking {
    width: 85px;
    height: 85px;
  }

  .eva-mode-toggle {
    display: none;
  }

  /* On mobile, show simplified mode switch */
  .eva-widget[data-widget-mode="both"] .eva-mode-mobile {
    display: flex;
  }
}

/* ========================================
   Dark Mode Support (matches site)
   ======================================== */

@media (prefers-color-scheme: dark) {
  /* Already dark themed, no changes needed */
}
