@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --bg-primary: #0a0a1a;
  --bg-secondary: #111128;
  --bg-card: rgba(20, 20, 50, 0.6);
  --bg-card-hover: rgba(30, 30, 70, 0.7);
  --primary: #8b5cf6;
  --primary-hover: #7c3aed;
  --primary-glow: rgba(139, 92, 246, 0.3);
  --accent: #c084fc;
  --accent-2: #a78bfa;
  --text: #f1f1f9;
  --text-secondary: #a3a3c2;
  --text-muted: #6b6b8a;
  --border: rgba(139, 92, 246, 0.15);
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;
  --user-msg-bg: rgba(139, 92, 246, 0.1);
  --ai-msg-bg: rgba(16, 185, 129, 0.08);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body,
#root {
  height: 100%;
  width: 100%;
  overflow: hidden;
}

body {
  background: var(--bg-primary);
  color: var(--text);
}

/* ─── App Container ─── */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(139, 92, 246, 0.12), transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(59, 130, 246, 0.08), transparent 50%),
    radial-gradient(ellipse at 50% 50%, rgba(192, 132, 252, 0.04), transparent 60%);
}

/* ─── Header ─── */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 2rem;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(20px);
  background: rgba(10, 10, 26, 0.85);
  z-index: 10;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #fff 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-icon {
  font-size: 1.6rem;
  -webkit-text-fill-color: initial;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.avatar-toggle-btn {
  padding: 0.5rem 1.2rem;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  transition: all 0.3s;
}

.avatar-toggle-btn:hover:not(:disabled) {
  background: var(--primary);
  border-color: var(--primary);
}

.avatar-toggle-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 0 15px var(--primary-glow);
}

.avatar-toggle-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.spin {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

.status-badge {
  padding: 0.4rem 1rem;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid var(--border);
  background: var(--bg-card);
}

.status-badge.connected {
  border-color: rgba(16, 185, 129, 0.3);
}

.status-badge.disconnected {
  border-color: rgba(239, 68, 68, 0.3);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-badge.connected .status-dot {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.status-badge.disconnected .status-dot {
  background: var(--error);
  box-shadow: 0 0 8px var(--error);
}

/* ─── Main Content ─── */
.main-content {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ─── Avatar Section ─── */
.avatar-section {
  flex: 0 0 40%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  position: relative;
}

.avatar-frame {
  width: 100%;
  max-width: 450px;
  aspect-ratio: 1 / 1;
  border-radius: 2rem;
  padding: 1rem;
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 40%, rgba(139, 92, 246, 0.08), var(--bg-secondary));
  border: 1px solid var(--border);
  box-shadow:
    0 0 40px rgba(139, 92, 246, 0.1),
    0 20px 60px rgba(0, 0, 0, 0.3),
    inset 0 0 30px rgba(139, 92, 246, 0.05);
}

.avatar-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 1.5rem;
}

.avatar-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  padding: 2rem;
  text-align: center;
}

.placeholder-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: rgba(139, 92, 246, 0.1);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}

.placeholder-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.placeholder-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  max-width: 280px;
}

.avatar-select {
  padding: 0.6rem 1.2rem;
  border-radius: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  min-width: 200px;
  transition: border-color 0.3s;
}

.avatar-select:focus {
  border-color: var(--primary);
}

.avatar-select option {
  background: var(--bg-secondary);
  color: var(--text);
}

.start-avatar-btn {
  padding: 0.7rem 2rem;
  border-radius: 9999px;
  background: linear-gradient(135deg, var(--primary), #6d28d9);
  color: white;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.3s;
  box-shadow: 0 4px 20px var(--primary-glow);
}

.start-avatar-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px var(--primary-glow);
}

.start-avatar-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.avatar-error {
  padding: 0.6rem 1rem;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 0.75rem;
  color: #fca5a5;
  font-size: 0.8rem;
  max-width: 320px;
  text-align: center;
  line-height: 1.4;
}

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  color: var(--text-secondary);
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loading-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.avatar-name {
  margin-top: 1rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent-2);
  letter-spacing: 0.3px;
  text-align: center;
}

.speaking-badge {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(139, 92, 246, 0.9);
  backdrop-filter: blur(10px);
  color: white;
  padding: 0.3rem 1rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4);
  z-index: 5;
}

.thinking-badge {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(245, 158, 11, 0.9);
  backdrop-filter: blur(10px);
  color: white;
  padding: 0.3rem 1rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
  z-index: 5;
}

.thinking-dots {
  display: flex;
  gap: 3px;
}

.thinking-dots span {
  width: 5px;
  height: 5px;
  background: white;
  border-radius: 50%;
  animation: dotBounce 1.2s infinite;
}

.thinking-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.thinking-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes dotBounce {

  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }

  40% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

/* ─── Chat Section ─── */
.chat-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: rgba(10, 10, 26, 0.5);
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.messages-container::-webkit-scrollbar {
  width: 4px;
}

.messages-container::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.messages-container::-webkit-scrollbar-track {
  background: transparent;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  gap: 0.75rem;
  color: var(--text-secondary);
  padding: 2rem;
}

.empty-state p:first-child {
  font-size: 1.15rem;
  color: var(--text);
}

.empty-state p:last-child {
  font-size: 0.9rem;
  max-width: 380px;
  line-height: 1.6;
}

/* ─── Messages ─── */
.message {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.8rem 1rem;
  border-radius: 1rem;
  transition: background 0.2s;
}

.message.user {
  background: var(--user-msg-bg);
  border: 1px solid rgba(139, 92, 246, 0.1);
}

.message.ai {
  background: var(--ai-msg-bg);
  border: 1px solid rgba(16, 185, 129, 0.1);
}

.message.interim {
  opacity: 0.6;
}

.message-avatar {
  font-size: 1.4rem;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--bg-card);
}

.message-content {
  flex: 1;
  min-width: 0;
}

.message-role {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.2rem;
  display: block;
}

.message.user .message-role {
  color: var(--accent);
}

.message.ai .message-role {
  color: var(--success);
}

.message-content p {
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--text);
  word-break: break-word;
}

.interim-text {
  font-style: italic;
  color: var(--text-muted) !important;
}

/* ─── Input Area ─── */
.input-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: rgba(10, 10, 26, 0.9);
  backdrop-filter: blur(20px);
}

.mic-button {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  color: white;
  transition: all 0.3s ease;
  flex-shrink: 0;
  box-shadow: 0 0 20px var(--primary-glow);
}

.mic-button:hover {
  transform: scale(1.05);
  background: var(--primary-hover);
}

.mic-button.active {
  background: var(--error);
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.4);
  animation: micPulse 1.5s infinite;
}

@keyframes micPulse {
  0% {
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.4);
  }

  50% {
    box-shadow: 0 0 30px rgba(239, 68, 68, 0.6), 0 0 60px rgba(239, 68, 68, 0.2);
  }

  100% {
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.4);
  }
}

.text-form {
  flex: 1;
  display: flex;
  gap: 0.5rem;
}

.text-input {
  flex: 1;
  padding: 0.75rem 1.2rem;
  border-radius: 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: all 0.3s;
}

.text-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 15px var(--primary-glow);
}

.text-input::placeholder {
  color: var(--text-muted);
}

.send-button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  transition: all 0.3s;
  flex-shrink: 0;
}

.send-button:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: scale(1.05);
}

.send-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ─── Responsive ─── */
@media (max-width: 900px) {
  .main-content {
    flex-direction: column;
  }

  .avatar-section {
    flex: 0 0 auto;
    padding: 1rem;
  }

  .avatar-frame {
    max-width: 320px;
  }

  .chat-section {
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

@media (max-width: 600px) {
  .header {
    padding: 0.6rem 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .logo {
    font-size: 1rem;
  }

  .avatar-section {
    padding: 0.5rem;
  }

  .avatar-frame {
    max-width: 280px;
  }

  .avatar-name {
    font-size: 0.85rem;
  }

  .input-area {
    padding: 0.75rem 1rem;
  }
}/* --- Custom Integration Styles --- */
.status-badge.online { border-color: rgba(16, 185, 129, 0.3); }
.status-badge.online .status-dot { background: var(--success); box-shadow: 0 0 8px var(--success); }
.status-badge.recording { border-color: rgba(245, 158, 11, 0.3); }
.status-badge.recording .status-dot { background: var(--warning); box-shadow: 0 0 8px var(--warning); }
.status-badge.speaking { border-color: rgba(139, 92, 246, 0.3); }
.status-badge.speaking .status-dot { background: var(--primary); box-shadow: 0 0 8px var(--primary); }

.mic-button.recording {
  background: var(--error);
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.4);
  animation: micPulse 1.5s infinite;
}
.mic-button.disabled { opacity: 0.5; pointer-events: none; }

#processingBar {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
#processingBar.visible { opacity: 1; pointer-events: auto; }

#avatarConnecting { display: flex !important; }
#avatarConnecting[style*="none"] { display: none !important; }
