/**
 * PMERIT Avatar Styles
 * Phase 3.3-A: Virtual Human avatar UI components
 */

:root {
  /* VH container dimensions */
  --vh-container-max-width: 820px;
  --vh-container-height: 420px;
}

/* VH Root Container - Pinned viewport at top of center panel */
.vh-root {
  position: relative;
  width: 100%;
  max-width: var(--vh-container-max-width);
  height: var(--vh-container-height);  /* finite height so chat below is visible */
  margin: 0 auto;
  overflow: hidden;
  border-radius: 12px;
  background: #1f2630;
  z-index: 1;          /* keep under any sticky headers/tooltips */
}

.vh-root[hidden],
.vh-root.is-hidden { 
  display: none !important; 
}

/* WebGL Canvas */
#vh-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #1f2630;
  cursor: default;
}

/* VH Status Badge - positioned inside VH viewport */
.vh-status-badge {
  position: absolute;
  left: 12px;
  bottom: 12px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.55);
  color: #eaf2ff;
  font-size: 12px;
  z-index: 10;
}

/* Avatar loading state */
.vh-container.loading #vh-canvas {
  opacity: 0.5;
  pointer-events: none;
}

.vh-container.loading::after {
  content: 'Loading avatar...';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--color-primary, #2A5B8C);
  font-size: 1.1rem;
  font-weight: 500;
  text-align: center;
}

/* Captions Container - positioned at bottom of VH viewport */
#vh-captions {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.85);
  color: #eaf2ff;
  padding: 1rem 1.5rem;
  font-size: 1rem;
  line-height: 1.5;
  text-align: center;
  max-height: 120px;
  overflow-y: auto;
  backdrop-filter: blur(10px);
  border-top: 2px solid rgba(102, 252, 241, 0.3);
}

#vh-captions:empty {
  display: none;
}

/* Virtual Human Toggle */
.vh-toggle-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  background: rgba(31, 40, 51, 0.5);
  border-radius: 8px;
  margin-bottom: 1rem;
}

.vh-toggle-label {
  font-size: 0.95rem;
  font-weight: 500;
  color: #e8eef8;
  user-select: none;
  cursor: pointer;
}

.vh-toggle {
  position: relative;
  width: 52px;
  height: 28px;
  background: var(--color-primary, #2A5B8C);
  border-radius: 14px;
  cursor: pointer;
  transition: background-color 0.3s ease;
  border: none;
  padding: 0;
  outline: none;
}

.vh-toggle:focus {
  box-shadow: 0 0 0 3px rgba(102, 252, 241, 0.3);
}

.vh-toggle.off {
  background: #666;
}

.vh-toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 24px;
  height: 24px;
  background: white;
  border-radius: 50%;
  transition: transform 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.vh-toggle:not(.off)::after {
  transform: translateX(24px);
}

/* Audio-only mode */
.vh-container.audio-only {
  height: auto;
}

.vh-container.audio-only #vh-canvas {
  display: none;
}

.vh-container.audio-only .audio-only-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 2rem;
  color: var(--color-primary, #2A5B8C);
}

.audio-only-placeholder {
  display: none;
}

.audio-only-placeholder .avatar-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  opacity: 0.7;
}

.audio-only-placeholder .status-text {
  font-size: 1.1rem;
  font-weight: 500;
  text-align: center;
}

/* Speaking indicator */
.vh-speaking-indicator {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: none;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: rgba(42, 91, 140, 0.2);
  border-radius: 20px;
  color: var(--color-primary, #2A5B8C);
  font-size: 0.85rem;
  font-weight: 500;
  backdrop-filter: blur(10px);
}

.vh-container.speaking .vh-speaking-indicator {
  display: flex;
}

.vh-speaking-indicator::before {
  content: '';
  width: 8px;
  height: 8px;
  background: var(--color-primary, #2A5B8C);
  border-radius: 50%;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.5;
    transform: scale(1.2);
  }
}

/* Error state */
.vh-error {
  padding: 2rem;
  text-align: center;
  color: #ff6b6b;
}

.vh-error .error-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.vh-error .error-message {
  font-size: 1rem;
  margin-bottom: 1rem;
}

.vh-error .error-retry {
  margin-top: 1rem;
  padding: 0.5rem 1.5rem;
  background: var(--color-primary, #2A5B8C);
  color: var(--text-inverse, #FFFFFF);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  transition: background-color 0.2s;
}

.vh-error .error-retry:hover {
  background: #1E4567;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  #vh-canvas {
    height: 320px;
  }

  .vh-toggle-container {
    padding: 0.75rem;
  }

  #vh-captions {
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
  }

  .audio-only-placeholder {
    padding: 2rem 1rem;
  }

  .audio-only-placeholder .avatar-icon {
    font-size: 3rem;
  }

  .audio-only-placeholder .status-text {
    font-size: 1rem;
  }
}

/* Ensure chat containers have proper positioning and stacking */
.chat-stream,
.chat-panel,
.desktop-chat-messages,
.desktop-chat-container,
#desktopChatMessages,
#desktop-chat-messages,
#chat-stream { 
  position: relative; 
  z-index: 0; 
}

/* Never hide chat when VH is on */
body.vh-mode #chat-stream,
body.vh-mode .chat-stream,
body.vh-mode .interaction-bar { 
  display: block !important; 
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
  .vh-toggle::after,
  .vh-speaking-indicator::before {
    animation: none;
    transition: none;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  #vh-captions {
    background: #000;
    border-top-width: 3px;
  }

  .vh-toggle {
    border: 2px solid currentColor;
  }
}
