/**
 * Voice Agent Styles
 * Styles for voice input buttons, animations, and feedback
 */

/* ============================================================================
   INPUT WRAPPER WITH MIC BUTTON
   ============================================================================ */

.voice-input-wrapper {
    position: relative;
    display: block; /* Changed from flex */
    width: 100%;
}

.voice-input-wrapper input,
.voice-input-wrapper textarea,
.voice-input-wrapper select {
    width: 100%;
    /* Add padding to the right so text doesn't go behind the mic button */
    padding-right: 50px !important; 
}

/* ============================================================================
   MICROPHONE BUTTON
   ============================================================================ */

.voice-mic-button {
    position: absolute;
    top: 50%;
    right: 5px; /* Position inside the input on the right */
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    min-width: 36px;
    border: none; /* Remove border for cleaner look */
    background: transparent; /* Transparent background */
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

/* Adjust hover state for the "inside" look */
.voice-mic-button:hover {
    background: rgba(0,0,0,0.05);
    border-radius: 50%;
    transform: translateY(-50%) scale(1.1); /* Keep the Y centering */
}

.voice-mic-button:active {
    transform: scale(0.95);
}

.voice-mic-button:focus {
    outline: 2px solid #4CAF50;
    outline-offset: 2px;
}

.voice-mic-button:focus:not(:focus-visible) {
    outline: none;
}

/* Mic icon */
.mic-icon {
    width: 20px;
    height: 20px;
    color: #666;
    transition: color 0.3s ease;
}

.voice-mic-button:hover .mic-icon {
    color: #4CAF50;
}

/* ============================================================================
   SPEAKING STATE (Text-to-Speech Active)
   ============================================================================ */

.voice-mic-button.speaking {
    background: linear-gradient(135deg, #2196F3 0%, #1976D2 100%);
    border-color: #2196F3;
    animation: pulse-blue 1s infinite;
}

.voice-mic-button.speaking .mic-icon {
    color: white;
}

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

/* ============================================================================
   LISTENING STATE (Speech-to-Text Active)
   ============================================================================ */

.voice-mic-button.listening {
    background: linear-gradient(135deg, #4CAF50 0%, #388E3C 100%);
    border-color: #4CAF50;
    animation: pulse-green 1.5s infinite;
}

.voice-mic-button.listening .mic-icon {
    color: white;
}

@keyframes pulse-green {
    0%, 100% { 
        transform: scale(1); 
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7);
    }
    50% { 
        transform: scale(1.05); 
        box-shadow: 0 0 0 10px rgba(76, 175, 80, 0);
    }
}

/* Listening indicator (pulsing dot) */
.listening-indicator {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 12px;
    height: 12px;
    background: #4CAF50;
    border-radius: 50%;
    border: 2px solid white;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.voice-mic-button.listening .listening-indicator {
    opacity: 1;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ============================================================================
   ERROR STATE
   ============================================================================ */

.voice-mic-button.error {
    background: linear-gradient(135deg, #f44336 0%, #d32f2f 100%);
    border-color: #f44336;
    animation: shake 0.5s;
}

.voice-mic-button.error .mic-icon {
    color: white;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* ============================================================================
   DISABLED STATE
   ============================================================================ */

.voice-mic-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.voice-mic-button:disabled:hover {
    background: white;
    border-color: #ddd;
    transform: none;
}

/* ============================================================================
   FIELD FILL ANIMATION
   ============================================================================ */

input.voice-filled,
textarea.voice-filled,
select.voice-filled {
    animation: highlight-green 1s;
}

@keyframes highlight-green {
    0%, 100% { 
        background: white;
        border-color: initial;
    }
    50% { 
        background: #E8F5E9;
        border-color: #4CAF50;
    }
}

/* ============================================================================
   TOAST NOTIFICATIONS
   ============================================================================ */

.voice-toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 8px;
    background: #333;
    color: white;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 10000;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
    max-width: 300px;
}

.voice-toast.show {
    opacity: 1;
    transform: translateY(0);
}

.voice-toast-error {
    background: linear-gradient(135deg, #f44336 0%, #d32f2f 100%);
}

.voice-toast-success {
    background: linear-gradient(135deg, #4CAF50 0%, #388E3C 100%);
}

.voice-toast-info {
    background: linear-gradient(135deg, #2196F3 0%, #1976D2 100%);
}

.voice-toast-warning {
    background: linear-gradient(135deg, #FF9800 0%, #F57C00 100%);
}

/* ============================================================================
   MOBILE RESPONSIVE
   ============================================================================ */

@media (max-width: 768px) {
    /* Larger buttons on mobile for easier tapping */
    .voice-mic-button {
        width: 44px;
        height: 44px;
        min-width: 44px;
    }

    .mic-icon {
        width: 22px;
        height: 22px;
    }

    /* Ensure the textarea button sits at the top-right, not centered vertically */
    .voice-input-wrapper textarea + .voice-mic-button {
        top: 10px;
        transform: none;
    }

    /* Adjust toast on mobile */
    .voice-toast {
        bottom: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }

}

    /* Prevent iOS zoom on input focus */
    @media (max-width: 768px) {
        input, textarea, select {
            font-size: 16px !important; /* Prevents iOS zoom */
        }
    }

/* ============================================================================
   ADDITIONAL ANIMATIONS
   ============================================================================ */

/* Ripple effect on click */
.voice-mic-button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(76, 175, 80, 0.5);
    transform: translate(-50%, -50%);
    transition: width 0.3s, height 0.3s;
}

.voice-mic-button:active::before {
    width: 100%;
    height: 100%;
}

/* Fade in animation for wrapper */
.voice-input-wrapper {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================================================
   ACCESSIBILITY
   ============================================================================ */

/* High contrast mode support */
@media (prefers-contrast: high) {
    .voice-mic-button {
        border-width: 3px;
    }

    .voice-mic-button:focus {
        outline-width: 3px;
    }
}

/* Reduced motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .voice-mic-button,
    .voice-toast,
    .listening-indicator {
        animation: none !important;
        transition: none !important;
    }

    .voice-mic-button:hover {
        transform: none;
    }
}

/* ============================================================================
   DARK MODE SUPPORT
   ============================================================================ */

@media (prefers-color-scheme: dark) {
    .voice-mic-button {
        background: #2d2d2d;
        border-color: #444;
    }

    .voice-mic-button:hover {
        background: #3d3d3d;
    }

    .mic-icon {
        color: #aaa;
    }

    .voice-mic-button:hover .mic-icon {
        color: #4CAF50;
    }

    input.voice-filled,
    textarea.voice-filled,
    select.voice-filled {
        animation: highlight-green-dark 1s;
    }

    @keyframes highlight-green-dark {
        0%, 100% { 
            background: #2d2d2d;
            border-color: initial;
        }
        50% { 
            background: #1B5E20;
            border-color: #4CAF50;
        }
    }
}

/* ============================================================================
   PRINT STYLES
   ============================================================================ */

@media print {
    .voice-mic-button,
    .voice-toast,
    .listening-indicator {
        display: none !important;
    }

    .voice-input-wrapper {
        display: block;
    }
}

/* ============================================================================
   CUSTOM VARIANTS (Optional - comment out if not needed)
   ============================================================================ */

/* Small variant */
.voice-mic-button.voice-mic-button-sm {
    width: 32px;
    height: 32px;
    min-width: 32px;
}

.voice-mic-button-sm .mic-icon {
    width: 16px;
    height: 16px;
}

/* Large variant */
.voice-mic-button.voice-mic-button-lg {
    width: 48px;
    height: 48px;
    min-width: 48px;
}

.voice-mic-button-lg .mic-icon {
    width: 24px;
    height: 24px;
}

/* Pill shape variant */
.voice-mic-button.voice-mic-button-pill {
    border-radius: 20px;
    padding: 0 16px;
    width: auto;
}

/* ============================================================================
   LOADING STATE (Optional)
   ============================================================================ */

.voice-mic-button.loading .mic-icon {
    animation: spin 1s linear infinite;
}

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