/**
 * Voice UI Styles
 * Styles for sound wave visualization, status indicator, mode toggle, and voice selection
 */

/* Container for voice UI elements */
.voice-ui-container {
    position: fixed;
    bottom: 45%; /* Moved even higher up from 40% */
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    pointer-events: none; /* Allow clicks to pass through except on interactive elements */
}

/* Sound Wave Visualization */
.waveform-container {
    width: 100%;
    max-width: 600px;
    height: 120px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 20px;
    backdrop-filter: blur(0px);
    padding: 15px;
    opacity: 0;
    transform: translateY(10px) scale(0.95);
    visibility: hidden;
    transition: 
        opacity 0.4s cubic-bezier(0.4, 0.0, 0.2, 1),
        transform 0.4s cubic-bezier(0.4, 0.0, 0.2, 1),
        backdrop-filter 0.4s cubic-bezier(0.4, 0.0, 0.2, 1),
        visibility 0ms linear 0.4s;
    will-change: opacity, transform, backdrop-filter;
}

.waveform-container.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    backdrop-filter: blur(10px);
    visibility: visible;
    transition: 
        opacity 0.4s cubic-bezier(0.4, 0.0, 0.2, 1),
        transform 0.4s cubic-bezier(0.4, 0.0, 0.2, 1),
        backdrop-filter 0.4s cubic-bezier(0.4, 0.0, 0.2, 1),
        visibility 0ms linear 0ms;
}

#waveform-canvas {
    width: 100%;
    height: 100%;
}

/* Fallback for browsers that don't support backdrop-filter */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .waveform-container {
        background: rgba(0, 0, 0, 0.4);
    }
}

/* Respect user preference for reduced motion */
@media (prefers-reduced-motion: reduce) {
    .waveform-container {
        transition: opacity 0.2s ease;
        transform: none !important;
    }
    
    .waveform-container.active {
        transform: none !important;
    }
}

/* Status Indicator */
.status-indicator {
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    border-radius: 25px;
    padding: 10px 25px;
    color: #ffffff;
    font-size: 16px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.3s ease;
    min-width: 150px;
    justify-content: center;
}

.status-indicator .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #7ef8ec;
    animation: pulse 2s infinite;
}

.status-indicator.listening {
    background: rgba(126, 248, 236, 0.2);
    border: 1px solid rgba(126, 248, 236, 0.5);
}

.status-indicator.listening .status-dot {
    background: #7ef8ec;
    animation: pulse 1s infinite;
}

.status-indicator.processing {
    background: rgba(255, 236, 126, 0.2);
    border: 1px solid rgba(255, 236, 126, 0.5);
}

.status-indicator.processing .status-dot {
    background: #ffec7e;
    animation: rotate 1s linear infinite;
}

.status-indicator.speaking {
    background: rgba(179, 227, 188, 0.2);
    border: 1px solid rgba(179, 227, 188, 0.5);
}

.status-indicator.speaking .status-dot {
    background: #b3e3bc;
    animation: pulse 0.8s infinite;
}

.status-indicator.ready {
    background: rgba(126, 248, 236, 0.1);
    border: 1px solid rgba(126, 248, 236, 0.3);
}

.status-indicator.ready .status-dot {
    background: #7ef8ec;
    animation: none;
}

.status-indicator.offline {
    background: rgba(128, 128, 128, 0.2);
    border: 1px solid rgba(128, 128, 128, 0.5);
}

.status-indicator.offline .status-dot {
    background: #808080;
    animation: none;
}

/* Mode Toggle Switch - White Background Design System */
.mode-toggle-container {
    position: fixed;
    bottom: 110px; /* Lowered slightly from 120px */
    right: 30px;
    z-index: 101;
    pointer-events: all;
}

.mode-toggle {
    /* Clean white background with glassmorphism blur */
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    
    /* Border with app turquoise color */
    border: 1px solid rgba(126, 248, 236, 0.4);
    border-radius: 25px;
    
    /* Layout - symmetric spacing */
    padding: 10px 16px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 12px;
    
    /* Typography */
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    
    /* Interaction */
    cursor: pointer;
    user-select: none;
    
    /* Animation */
    transition: all 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    
    /* Shadow for depth */
    box-shadow: 
        0 4px 20px rgba(126, 248, 236, 0.1),
        0 1px 3px rgba(0, 0, 0, 0.1);
}

.mode-toggle:hover {
    background: rgba(255, 255, 255, 0.98);
    border-color: rgba(126, 248, 236, 0.6);
    transform: translateY(-1px);
    box-shadow: 
        0 6px 25px rgba(126, 248, 236, 0.15),
        0 2px 8px rgba(0, 0, 0, 0.1);
}

.mode-label {
    /* Turquoise text colors matching design system */
    color: #0d9488;
    font-size: 13px;
    font-weight: 500;
    transition: color 0.3s ease;
    text-align: center;
    white-space: nowrap;
}

.mode-label:first-child {
    /* Left label - align right to center content */
    text-align: right;
}

.mode-label-right {
    /* Right label - align left and add padding for symmetry */
    text-align: left;
    padding-left: 8px; /* Compensate for shorter text to center toggle */
}

.mode-toggle:hover .mode-label {
    color: #0f766e;
}

.mode-switch {
    position: relative;
    width: 46px;
    height: 24px;
    background: rgba(126, 248, 236, 0.15);
    border: 1px solid rgba(126, 248, 236, 0.3);
    border-radius: 12px;
    transition: all 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.mode-switch-handle {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: #7ef8ec;
    border-radius: 50%;
    transition: all 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.mode-toggle.tap-mode .mode-switch {
    background: rgba(13, 148, 136, 0.15);
    border-color: rgba(13, 148, 136, 0.4);
}

.mode-toggle.tap-mode .mode-switch-handle {
    transform: translateX(22px);
    background: #0d9488;
}

/* Mode Icons */
.mode-icon {
    width: 20px;
    height: 20px;
    opacity: 0.8;
}

/* Animations */
@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 currentColor;
        opacity: 1;
    }
    70% {
        box-shadow: 0 0 0 8px transparent;
        opacity: 0.7;
    }
    100% {
        box-shadow: 0 0 0 0 transparent;
        opacity: 1;
    }
}

@keyframes rotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Keyboard hint */
.keyboard-hint {
    position: fixed;
    bottom: 105px; /* Aligned with updated avatar positioning */
    left: 90px; /* Positioned to the right of avatar */
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 8px 15px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 12px;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.keyboard-hint.visible {
    opacity: 1;
}

.keyboard-hint kbd {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    padding: 2px 6px;
    margin: 0 4px;
    font-family: monospace;
}

/* Desktop Adjustments - Move components lower */
@media (min-width: 769px) {
    .mode-toggle-container {
        bottom: 80px; /* Moved down from 110px for desktop */
    }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .voice-ui-container {
        bottom: 30%; /* Moved even higher from 25% for mobile */
    }

    .mode-toggle-container {
        bottom: 100px; /* Lowered slightly from 110px for mobile */
        right: 20px;
    }

    .keyboard-hint {
        display: none; /* Hide on mobile */
    }
}

/* Hide keyboard hint completely */
.keyboard-hint {
    display: none !important;
}


/* Continue mobile styles */
@media (max-width: 768px) {
    .waveform-container {
        max-width: 450px;
        height: 100px;
        padding: 12px;
    }

    /* Hide status indicator on mobile only */
    .status-indicator {
        display: none !important;
    }

}

/* Make sure voice UI elements appear above other elements */
.voice-ui-container > * {
    pointer-events: all;
}

/* Voice Selection Panel */
.voice-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: 25px;
    max-width: 400px;
    width: 90%;
    max-height: 70vh;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.voice-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.voice-panel-header h3 {
    margin: 0;
    color: #333;
    font-size: 18px;
    font-weight: 600;
}

.voice-panel-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #666;
    cursor: pointer;
    padding: 5px;
    line-height: 1;
    transition: color 0.2s ease;
}

.voice-panel-close:hover {
    color: #333;
}

.voice-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.voice-option {
    display: flex;
    align-items: center;
    padding: 15px;
    background: rgba(255, 255, 255, 0.5);
    border: 2px solid transparent;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.voice-option:hover {
    background: rgba(126, 248, 236, 0.1);
    border-color: rgba(126, 248, 236, 0.3);
}

.voice-option.selected {
    background: rgba(126, 248, 236, 0.2);
    border-color: #7ef8ec;
}

.voice-info {
    flex: 1;
}

.voice-name {
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
}

.voice-details {
    font-size: 12px;
    color: #666;
}

.voice-test-btn {
    background: #7ef8ec;
    border: none;
    border-radius: 8px;
    padding: 8px 12px;
    color: #333;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.voice-test-btn:hover {
    background: #5de8d7;
}

.voice-status {
    text-align: center;
    padding: 15px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
    margin-top: 10px;
}

.voice-engine {
    font-size: 14px;
    color: #666;
    font-weight: 500;
}

/* Loading indicator for voice panel */
.voice-loading {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #7ef8ec;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 8px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Voice panel mobile adjustments */
@media (max-width: 768px) {
    .voice-panel {
        width: 95%;
        padding: 20px;
        max-height: 80vh;
    }

    .voice-option {
        padding: 12px;
    }

    .voice-name {
        font-size: 14px;
    }

    .voice-details {
        font-size: 11px;
    }
}

/* TTS Strategy Configuration Panel */
.tts-strategy-section {
    margin-bottom: 20px;
    padding: 15px;
    background: rgba(126, 248, 236, 0.1);
    border-radius: 10px;
    border: 1px solid rgba(126, 248, 236, 0.3);
}

.tts-strategy-section h4 {
    margin: 0 0 10px 0;
    color: #333;
    font-size: 16px;
    font-weight: 600;
}

.device-info {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 15px;
}

.device-info span {
    padding: 5px 10px;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 5px;
    font-size: 14px;
    color: #333;
}

#device-type {
    font-weight: 600;
    background: rgba(126, 248, 236, 0.3);
}

#tts-method {
    font-style: italic;
}

.manual-override {
    display: flex;
    align-items: center;
    gap: 10px;
}

.manual-override label {
    font-weight: 500;
    color: #333;
    font-size: 14px;
}

.manual-override select {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid rgba(126, 248, 236, 0.5);
    border-radius: 5px;
    background: white;
    color: #333;
    font-size: 14px;
}

/* Usage Statistics */
.usage-stats {
    margin-bottom: 20px;
    padding: 15px;
    background: rgba(179, 227, 188, 0.1);
    border-radius: 10px;
    border: 1px solid rgba(179, 227, 188, 0.3);
}

.usage-stats h4 {
    margin: 0 0 10px 0;
    color: #333;
    font-size: 16px;
    font-weight: 600;
}

.usage-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.usage-bar {
    width: 100%;
    height: 8px;
    background: rgba(179, 227, 188, 0.3);
    border-radius: 4px;
    overflow: hidden;
}

.usage-fill {
    height: 100%;
    background: linear-gradient(90deg, #7ef8ec 0%, #b3e3bc 100%);
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 0%;
}

.usage-info span {
    font-size: 12px;
    color: #666;
}

#usage-text {
    font-weight: 500;
}

#usage-cost {
    font-style: italic;
}

/* Mobile adjustments for TTS panel */
@media (max-width: 768px) {
    .tts-strategy-section,
    .usage-stats {
        padding: 12px;
        margin-bottom: 15px;
    }
    
    .tts-strategy-section h4,
    .usage-stats h4 {
        font-size: 14px;
    }
    
    .device-info span,
    .manual-override select {
        font-size: 13px;
    }
    
    .manual-override {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
}

/* Mobile Drag Prevention for Push-to-Talk Button */
@media only screen and (max-width: 768px) {
    /* Prevent dragging on mobile devices ONLY */
    #ai-model-button,
    #ai-model-button img,
    .ai-model-interface img,
    .ai-model-interface {
        /* Disable text/image selection */
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        
        /* Disable dragging */
        -webkit-user-drag: none;
        -moz-user-drag: none;
        user-drag: none;
        
        /* Disable long-press context menu (iOS specific) */
        -webkit-touch-callout: none;
        
        /* Touch handling optimization */
        touch-action: manipulation;
        pointer-events: auto;
    }
    
    /* Specific iOS image drag prevention */
    #ai-model-button img {
        /* Force the image to not be draggable */
        -webkit-user-drag: none !important;
        -khtml-user-drag: none !important;
        -moz-user-drag: none !important;
        -o-user-drag: none !important;
        user-drag: none !important;
        
        /* iOS Safari specific fixes */
        -webkit-touch-callout: none !important;
        -webkit-user-select: none !important;
        
        /* Prevent image save dialog */
        pointer-events: none !important;
        
        /* Make image non-interactive for iOS */
        -webkit-tap-highlight-color: transparent !important;
    }
    
    /* Button container optimizations for iOS */
    #ai-model-button {
        /* Ensure proper touch handling */
        -webkit-tap-highlight-color: transparent;
        /* Prevent iOS context menus */
        -webkit-touch-callout: none;
        /* Prevent selection */
        -webkit-user-select: none;
        /* iOS drag prevention */
        -webkit-user-drag: none;
        /* Optimize touch response */
        touch-action: manipulation;
    }
    
    /* Background Image iOS Drag Prevention - MOBILE ONLY */
    .background-img {
        /* Disable iOS context menu (Save Image, Copy Image) */
        -webkit-touch-callout: none !important;
        
        /* Disable text/image selection */
        -webkit-user-select: none !important;
        -moz-user-select: none !important;
        -ms-user-select: none !important;
        user-select: none !important;
        
        /* Disable dragging */
        -webkit-user-drag: none !important;
        -khtml-user-drag: none !important;
        -moz-user-drag: none !important;
        -o-user-drag: none !important;
        user-drag: none !important;
        
        /* Prevent interaction events */
        pointer-events: none !important;
        
        /* iOS Safari specific optimizations */
        -webkit-tap-highlight-color: transparent !important;
        
        /* Touch action optimization */
        touch-action: none !important;
    }
}