/**
 * AI Phone 360 Voice Widget Styles
 */

/* Variables */
:root {
  --vw-primary: #2563eb;
  --vw-primary-hover: #1d4ed8;
  --vw-primary-light: rgba(37, 99, 235, 0.1);
  --vw-bg: #ffffff;
  --vw-bg-dark: #0a0a0f;
  --vw-text: #1f2937;
  --vw-text-secondary: #6b7280;
  --vw-border: #e5e7eb;
  --vw-error: #ef4444;
  --vw-mute-color: #ff6b6b;
  --vw-success: #22c55e;
  --vw-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
  --vw-radius: 16px;
  --vw-radius-sm: 12px;
  --vw-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark mode */
[data-theme="dark"] {
  --vw-bg: #1f2937;
  --vw-bg-dark: #111827;
  --vw-text: #f9fafb;
  --vw-text-secondary: #9ca3af;
  --vw-border: #374151;
  --vw-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .voice-widget-button {
  background: #374151;
  border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .voice-widget-button:hover {
  background: #4B5563;
}

[data-theme="dark"] .voice-widget-button .button-text {
  color: #f9fafb;
}

[data-theme="dark"] .call-bar {
  background: #374151;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .call-bar-timer {
  color: #E5E7EB;
}

[data-theme="dark"] .call-bar-expand {
  background: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .call-bar-expand:hover {
  background: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] .call-bar-expand svg {
  color: #9ca3af;
}

[data-theme="dark"] .voice-widget-panel {
  background: #1f2937;
  border: 1px solid #374151;
}

[data-theme="dark"] .panel-header {
  background: transparent;
}


[data-theme="dark"] .panel-minimize,
[data-theme="dark"] .panel-fullscreen {
  background: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .panel-minimize:hover,
[data-theme="dark"] .panel-fullscreen:hover {
  background: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] .panel-minimize svg,
[data-theme="dark"] .panel-fullscreen svg {
  color: #9ca3af;
}

[data-theme="dark"] .agent-name-large {
  color: #E5E7EB;
}

[data-theme="dark"] .agent-subtitle {
  color: #9ca3af;
}

[data-theme="dark"] .start-prompt p {
  color: #9ca3af;
}

[data-theme="dark"] .listening-text,
[data-theme="dark"] .speaking-text {
  color: #9ca3af;
}

[data-theme="dark"] .state-connecting p {
  color: #9ca3af;
}

[data-theme="dark"] .panel-footer-text {
  color: #9ca3af;
}

[data-theme="dark"] .control-mute {
  background: #374151;
  color: #E5E7EB;
}

[data-theme="dark"] .control-mute:hover {
  background: #4B5563;
}

[data-theme="dark"] .control-mute.muted {
  background: var(--vw-mute-color);
  color: white;
}

[data-theme="dark"] .control-end {
  background: var(--vw-error);
  color: white;
}

[data-theme="dark"] .control-end:hover {
  background: #dc2626;
}

[data-theme="dark"] .error-icon {
  background: rgba(239, 68, 68, 0.2);
}

[data-theme="dark"] .error-message {
  color: #fca5a5;
}

[data-theme="dark"] .voice-orb {
  box-shadow: 
    0 12px 40px rgba(37, 99, 235, 0.4),
    inset 0 0 40px rgba(96, 165, 250, 0.3);
}

/* Enhanced orb pulse for dark mode */
@keyframes orb-pulse-dark {
  0%, 100% {
    transform: scale(1);
    box-shadow: 
      0 12px 40px rgba(37, 99, 235, 0.4),
      inset 0 0 40px rgba(96, 165, 250, 0.3);
  }
  50% {
    transform: scale(1.02);
    box-shadow: 
      0 15px 45px rgba(37, 99, 235, 0.5),
      inset 0 0 45px rgba(96, 165, 250, 0.4);
  }
}

[data-theme="dark"] .voice-orb {
  animation: orb-pulse-dark 3s ease-in-out infinite;
}

[data-theme="dark"] .visualizer-bars span {
  background: #60a5fa;
}

[data-theme="dark"] .voice-visualizer.agent-speaking .visualizer-bars span {
  background: var(--vw-success);
}

[data-theme="dark"] .spinner {
  border-color: rgba(96, 165, 250, 0.2);
  border-top-color: #60a5fa;
}

/* Widget Container */
.voice-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Floating Button - Pill Shape */
.voice-widget-button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-radius: 50px;
  background: #EFEFEF;
  border: 1px solid rgba(255, 255, 255, 0.3);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: transform var(--vw-transition), box-shadow var(--vw-transition), background var(--vw-transition);
  position: relative;
  overflow: visible;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.voice-widget-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  background: #E5E5E5;
}

.voice-widget-button:active {
  transform: translateY(0);
}

/* Blue Faceted Icon */
.voice-widget-button .icon-faceted {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #60a5fa 0%, #2563eb 50%, #1e40af 100%);
  position: relative;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.voice-widget-button .icon-faceted::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.4) 0%, transparent 60%);
}

.voice-widget-button .icon-faceted::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: 
    radial-gradient(circle at 70% 30%, rgba(255, 255, 255, 0.2) 0%, transparent 40%),
    radial-gradient(circle at 30% 70%, rgba(255, 255, 255, 0.15) 0%, transparent 50%);
}

.voice-widget-button .button-text {
  font-size: 15px;
  font-weight: 500;
  color: #1f2937;
  white-space: nowrap;
}

/* Panel */
.voice-widget-panel {
  position: absolute;
  bottom: 72px;
  right: 0;
  width: 320px;
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - 120px);
  background: #F5F5F5;
  border-radius: var(--vw-radius);
  box-shadow: var(--vw-shadow);
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transform-origin: bottom right;
  transition: opacity var(--vw-transition), visibility var(--vw-transition), transform var(--vw-transition);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.voice-widget.expanded .voice-widget-panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.voice-widget.expanded .voice-widget-button {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* Compact Call Bar */
.call-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: #EFEFEF;
  border-radius: 50px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  position: absolute;
  bottom: 0;
  right: 0;
  z-index: 9998;
  min-width: 200px;
  transition: transform var(--vw-transition), box-shadow var(--vw-transition), opacity var(--vw-transition), visibility var(--vw-transition);
}

.call-bar:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.call-bar-icon {
  flex-shrink: 0;
}

.icon-faceted-small {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #60a5fa 0%, #2563eb 50%, #1e40af 100%);
  position: relative;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.icon-faceted-small::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.4) 0%, transparent 60%);
}

.icon-faceted-small::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: 
    radial-gradient(circle at 70% 30%, rgba(255, 255, 255, 0.2) 0%, transparent 40%),
    radial-gradient(circle at 30% 70%, rgba(255, 255, 255, 0.15) 0%, transparent 50%);
}

.call-bar-timer {
  flex: 1;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  color: #4B5563;
}

.call-bar-expand {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.05);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--vw-transition);
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.call-bar-expand:hover {
  background: rgba(0, 0, 0, 0.1);
}

.call-bar-expand svg {
  width: 16px;
  height: 16px;
  color: #6B7280;
}

/* Panel Header */
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: transparent;
  position: relative;
}

.panel-timer {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 14px;
  font-weight: 500;
  color: var(--vw-text-secondary);
}

.panel-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.panel-minimize,
.panel-fullscreen {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.05);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--vw-transition);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  min-width: 32px;
  min-height: 32px;
}

.panel-minimize:hover,
.panel-fullscreen:hover {
  background: rgba(0, 0, 0, 0.1);
}

.panel-minimize svg,
.panel-fullscreen svg {
  width: 14px;
  height: 14px;
  color: var(--vw-text-secondary);
}

/* Panel Content */
.panel-content {
  padding: 24px 20px;
  min-height: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

/* Blue Orb/Eye */
.voice-orb {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #60a5fa 0%, #2563eb 40%, #1e40af 70%, #1e3a8a 100%);
  position: relative;
  box-shadow: 
    0 12px 40px rgba(37, 99, 235, 0.3),
    inset 0 0 40px rgba(96, 165, 250, 0.2);
  animation: orb-pulse 3s ease-in-out infinite;
}

.voice-orb::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 25% 25%, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0.2) 30%, transparent 60%);
}

.voice-orb::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: 
    radial-gradient(circle at 70% 30%, rgba(255, 255, 255, 0.3) 0%, transparent 40%),
    radial-gradient(circle at 30% 70%, rgba(255, 255, 255, 0.2) 0%, transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(96, 165, 250, 0.4) 0%, transparent 70%);
}

@keyframes orb-pulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 
      0 12px 40px rgba(37, 99, 235, 0.3),
      inset 0 0 40px rgba(96, 165, 250, 0.2);
  }
  50% {
    transform: scale(1.02);
    box-shadow: 
      0 15px 45px rgba(37, 99, 235, 0.4),
      inset 0 0 45px rgba(96, 165, 250, 0.3);
  }
}

/* Agent Name */
.agent-name-large {
  font-size: 20px;
  font-weight: 700;
  color: #4B5563;
  margin: 0;
  text-align: center;
}

.agent-subtitle {
  font-size: 12px;
  color: #6B7280;
  margin: 0;
  text-align: center;
}

/* Idle State */
.state-idle {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
}

.start-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.start-prompt p {
  color: #6B7280;
  font-size: 14px;
  margin: 0;
}

.start-button {
  padding: 10px 24px;
  background: linear-gradient(135deg, var(--vw-primary) 0%, #1d4ed8 100%);
  color: white;
  border: none;
  border-radius: 50px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--vw-transition), box-shadow var(--vw-transition);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  min-height: 44px;
}

.start-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.4);
}

.start-button:active {
  transform: translateY(0);
}

/* Connecting State */
.state-connecting {
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.connecting-animation {
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--vw-primary-light);
  border-top-color: var(--vw-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.state-connecting p {
  color: #6B7280;
  font-size: 12px;
  margin: 0;
  font-weight: 500;
}

/* Connected State */
.state-connected {
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.voice-visualizer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin-top: 4px;
}

.visualizer-bars {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 40px;
}

.visualizer-bars span {
  width: 6px;
  background: var(--vw-primary);
  border-radius: 3px;
  animation: equalizer 1s ease-in-out infinite;
}

.visualizer-bars span:nth-child(1) { height: 20px; animation-delay: 0s; }
.visualizer-bars span:nth-child(2) { height: 35px; animation-delay: 0.1s; }
.visualizer-bars span:nth-child(3) { height: 50px; animation-delay: 0.2s; }
.visualizer-bars span:nth-child(4) { height: 35px; animation-delay: 0.3s; }
.visualizer-bars span:nth-child(5) { height: 20px; animation-delay: 0.4s; }

@keyframes equalizer {
  0%, 100% { transform: scaleY(0.5); }
  50% { transform: scaleY(1); }
}

.voice-visualizer.agent-speaking .visualizer-bars span {
  background: var(--vw-success);
}

.listening-text,
.speaking-text {
  color: #6B7280;
  font-size: 12px;
  margin: 0;
  font-weight: 500;
}

.speaking-text {
  color: var(--vw-success);
  font-weight: 500;
}

/* Error State */
.state-error {
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}

.error-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(239, 68, 68, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.error-icon svg {
  width: 30px;
  height: 30px;
  color: var(--vw-error);
}

.error-message {
  color: var(--vw-error);
  font-size: 14px;
  margin: 0;
}

.retry-button {
  padding: 10px 24px;
  background: var(--vw-error);
  color: white;
  border: none;
  border-radius: 50px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--vw-transition), opacity var(--vw-transition);
}

.retry-button:hover {
  opacity: 0.9;
  transform: translateY(-2px);
}

/* Panel Controls */
.panel-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px 20px;
  background: transparent;
}

.panel-controls button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--vw-transition), background var(--vw-transition);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.panel-controls button svg {
  width: 18px;
  height: 18px;
}

.control-mute {
  background: #E5E5E5;
  color: #4B5563;
}

.control-mute:hover {
  background: #D5D5D5;
}

.control-mute.muted {
  background: var(--vw-mute-color);
  color: white;
}

.control-mute.muted:hover {
  background: #ff5252;
}

.control-end {
  background: var(--vw-error);
  color: white;
}

.control-end:hover {
  background: #dc2626;
  transform: scale(1.05);
}

/* Bottom Text */
.panel-footer-text {
  text-align: center;
  padding: 0 20px 16px;
  font-size: 11px;
  color: #6B7280;
  line-height: 1.4;
}

/* Tablet Responsive */
@media (max-width: 768px) {
  .voice-widget-panel {
    width: 360px;
  }
}

/* Mobile Responsive */
@media (max-width: 480px) {
  .voice-widget {
    bottom: 16px;
    right: 16px;
    left: 16px;
  }

  .call-bar {
    bottom: 0;
    right: 0;
    left: 0;
    min-width: auto;
    width: 100%;
    padding: 8px 14px;
    border-radius: 50px;
  }

  .icon-faceted-small {
    width: 28px;
    height: 28px;
  }

  .call-bar-timer {
    font-size: 13px;
  }

  .call-bar-expand {
    width: 28px;
    height: 28px;
  }

  .call-bar-expand svg {
    width: 14px;
    height: 14px;
  }

  .voice-widget-button {
    padding: 10px 16px;
    width: auto;
    max-width: 100%;
  }

  .voice-widget-button .icon-faceted {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
  }

  .voice-widget-button .button-text {
    font-size: 13px;
  }

  .voice-widget-panel {
    width: calc(100vw - 32px);
    max-width: calc(100vw - 32px);
    bottom: 68px;
    right: 0;
    left: 0;
    margin: 0 auto;
    border-radius: 20px;
  }

  .panel-header {
    padding: 10px 16px;
  }

  .panel-timer {
    font-size: 13px;
  }

  .panel-fullscreen {
    width: 32px;
    height: 32px;
  }

  .panel-fullscreen svg {
    width: 16px;
    height: 16px;
  }

  .panel-content {
    padding: 20px 16px;
    min-height: 200px;
    gap: 12px;
  }

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

  .agent-name-large {
    font-size: 18px;
  }

  .agent-subtitle {
    font-size: 11px;
  }

  .start-button {
    padding: 10px 20px;
    font-size: 13px;
    width: 100%;
    max-width: 200px;
  }

  .state-idle,
  .state-connecting,
  .state-connected {
    gap: 12px;
  }

  .voice-visualizer {
    gap: 10px;
  }

  .visualizer-bars {
    height: 36px;
    gap: 3px;
  }

  .visualizer-bars span {
    width: 5px;
  }

  .listening-text,
  .speaking-text {
    font-size: 11px;
  }

  .panel-controls {
    padding: 14px 16px;
    gap: 12px;
  }

  .panel-controls button {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }

  .panel-controls button svg {
    width: 20px;
    height: 20px;
  }

  .panel-footer-text {
    padding: 0 16px 14px;
    font-size: 10px;
  }

  .connecting-animation {
    width: 44px;
    height: 44px;
  }

  .spinner {
    width: 28px;
    height: 28px;
  }

  .state-connecting p {
    font-size: 11px;
  }

  .error-icon {
    width: 50px;
    height: 50px;
  }

  .error-icon svg {
    width: 24px;
    height: 24px;
  }

  .error-message {
    font-size: 12px;
  }

  .retry-button {
    padding: 10px 20px;
    font-size: 13px;
  }
}

/* Small Mobile (very small screens) */
@media (max-width: 360px) {
  .voice-widget {
    bottom: 12px;
    right: 12px;
    left: 12px;
  }

  .voice-widget-button {
    padding: 8px 14px;
  }

  .voice-widget-button .icon-faceted {
    width: 24px;
    height: 24px;
  }

  .voice-widget-button .button-text {
    font-size: 12px;
  }

  .voice-widget-panel {
    width: calc(100vw - 24px);
    bottom: 60px;
    border-radius: 16px;
  }

  .panel-content {
    padding: 16px 12px;
    min-height: 180px;
  }

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

  .agent-name-large {
    font-size: 16px;
  }

  .panel-controls button {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
  }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
  .voice-widget-panel {
    max-height: calc(100vh - 100px);
    overflow-y: auto;
  }

  .panel-content {
    min-height: auto;
    padding: 16px 20px;
  }

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

  .agent-name-large {
    font-size: 16px;
  }

  .agent-subtitle {
    font-size: 11px;
  }
}

/* Ensure panel doesn't overflow viewport */
@media (max-height: 600px) {
  .voice-widget-panel {
    max-height: calc(100vh - 100px);
    overflow-y: auto;
  }

  .panel-content {
    min-height: auto;
    padding: 16px 20px;
  }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  .pulse-ring,
  .spinner,
  .visualizer-bars span {
    animation: none;
  }

  .voice-widget-button,
  .voice-widget-panel,
  .start-button,
  .retry-button {
    transition: none;
  }
}

/* Print - Hide widget */
@media print {
  .voice-widget {
    display: none !important;
  }
}
