/**
 * Speech-to-Text Component Styles
 * Light, modern, minimalist design with clean activity layout (matches input-validator pattern)
 */

/* Main wrapper */
.speech-input-wrapper {
    position: relative;
    display: block;
    width: 100%;
}

/* Ensure input/textarea are relatively positioned for proper button placement */
.speech-input-wrapper input,
.speech-input-wrapper textarea {
    position: relative;
}

/* Input field - no styling applied, handled by parent application */

/* Microphone buttons - positioned inside input/textarea border */
.speech-mic-button {
    position: absolute;
    right: 8px;
    top: 50%;
    background: #cccccc;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
}
.speech-mic-stop {
    color: #ffffff;
}

/* Ensure both buttons have same positioning */
.speech-mic-start,
.speech-mic-stop {
    position: absolute;
}

/* Position for text inputs - centered vertically, inside border */
.speech-input-wrapper .speech-mic-start,
.speech-input-wrapper .speech-mic-stop {
    top: 50%;
}

/* Position for textareas - bottom right corner, inside border */
.speech-input-wrapper:has(textarea) .speech-mic-start,
.speech-input-wrapper:has(textarea) .speech-mic-stop {
    top: auto;
    bottom: 40px;
    right: 12px;
    transform: none;
}

/* Fallback for browsers without :has() support */
.speech-input-wrapper textarea ~ .speech-mic-start,
.speech-input-wrapper textarea ~ .speech-mic-stop {
    top: auto;
    bottom: 40px;
    right: 12px;
    transform: none;
}

.speech-mic-button:hover {
    background: #e5e7eb;
    border-color: #9ca3af;
}

.speech-mic-button.listening {
    background: #dc2626;
    border-color: #dc2626;
    color: white;
    animation: pulse 1.5s infinite;
}

.speech-mic-button.success {
    background: #16a34a;
    border-color: #16a34a;
    color: white;
}



/* Hover effects for inputs */
.speech-input-wrapper .speech-mic-start:hover,
.speech-input-wrapper .speech-mic-stop:hover {
    /* transform: translateY(-50%) scale(1.05); */
}

/* Hover effects for textareas */
.speech-input-wrapper:has(textarea) .speech-mic-start:hover,
.speech-input-wrapper:has(textarea) .speech-mic-stop:hover,
.speech-input-wrapper textarea ~ .speech-mic-start:hover,
.speech-input-wrapper textarea ~ .speech-mic-stop:hover {
    transform: scale(1.05);
}

.speech-mic-button:focus {
    outline: 1px solid #9ca3af;
    outline-offset: 1px;
}

/* Active effects for inputs */
.speech-input-wrapper .speech-mic-start:active,
.speech-input-wrapper .speech-mic-stop:active {
    /* transform: translateY(-50%) scale(0.95); */
}

/* Active effects for textareas */
.speech-input-wrapper:has(textarea) .speech-mic-start:active,
.speech-input-wrapper:has(textarea) .speech-mic-stop:active,
.speech-input-wrapper textarea ~ .speech-mic-start:active,
.speech-input-wrapper textarea ~ .speech-mic-stop:active {
    transform: scale(0.95);
}

/* Listening state - visible red (for stop button) */
.speech-mic-stop.listening {
    background-color: #b91c1c;
    animation: mic-recording 1.5s infinite;
}

.speech-mic-stop.listening:hover {
    background-color: #991b1b;
}

@keyframes mic-recording {
    0% { background-color: #b91c1c; }
    50% { background-color: #dc2626; }
    100% { background-color: #b91c1c; }
}

/* Success state - visible green */
.speech-mic-button.success {
    background-color: #047857;
}

/* Success animations for inputs */
@keyframes speech-success-input {
    0% { transform: translateY(-50%) scale(1); }
    50% { transform: translateY(-50%) scale(1.1); }
    100% { transform: translateY(-50%) scale(1); }
}

/* Success animations for textareas */
@keyframes speech-success-textarea {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Apply appropriate success animation */
.speech-input-wrapper .speech-mic-button.success {
    animation: speech-success-input 0.3s ease-in-out;
}

.speech-input-wrapper:has(textarea) .speech-mic-button.success,
.speech-input-wrapper textarea ~ .speech-mic-button.success {
    animation: speech-success-textarea 0.3s ease-in-out;
}

/* Loading state */
.speech-mic-button.loading {
    background-color: #d97706;
}

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

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

/* Activity container - positioned under input */
.speech-activity {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    min-height: 16px;
    font-size: 12px;
    line-height: 1.2;
    color: #6b7280;
}

/* Status indicators */
.speech-status {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

/* Status icons - removed for cleaner design */

/* Message text */
.speech-message {
    flex: 1;
    color: #374151;
    font-weight: 400;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Only show min-height when message container has content */
.speech-message:not(:empty) {
    min-height: 20px;
}

/* Consistent status message styling - never changes */
.speech-message .status-message {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    background-color: #fef3c7;
    color: #92400e;
    border-left: 3px solid #f59e0b;
    flex-shrink: 0;
}

/* Interim text container - always present, consistent size */
.speech-message .interim-text {
    padding: 2px 6px;
    background-color: transparent;
    border-radius: 4px;
    border-left: 3px solid transparent;
    font-size: 11px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0;
    transition: all 0.2s ease-in-out;
    min-height: 16px;
    min-width: 80px; /* Consistent width to prevent jumping */
    flex-shrink: 0;
}

/* When interim text is visible */
.speech-message .interim-text.visible {
    opacity: 0.9;
    background-color: #e5f3ff;
    border-left-color: #3b82f6;
    font-style: italic;
}

/* Interim text labels */
.speech-message .interim-text .interim-label {
    color: #6b7280;
    font-weight: 500;
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
}

.speech-message .interim-text.visible .interim-label {
    opacity: 1;
}

/* Interim text content */
.speech-message .interim-text .interim-content {
    color: #1f2937;
    font-weight: 500;
    font-style: normal;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
}

.speech-message .interim-text.visible .interim-content {
    opacity: 1;
}

/* Audio visualizer - minimal */
.audio-visualizer {
    display: flex;
    align-items: center;
    gap: 1px;
    flex-shrink: 0;
}

.audio-visualizer .bar {
    width: 2px;
    height: 0;
    background-color: #d1d5db;
    border-radius: 1px;
    transition: all 0.2s ease;
}

/* Show bars only when speech is active */
.speech-activity.state-active .audio-visualizer .bar {
    height: 8px;
}

.audio-visualizer .bar.animate {
    background-color: #b91c1c;
    animation: audio-bar 1.2s infinite ease-in-out;
}

.audio-visualizer .bar:nth-child(1).animate {
    animation-delay: 0s;
}

.audio-visualizer .bar:nth-child(2).animate {
    animation-delay: 0.2s;
}

.audio-visualizer .bar:nth-child(3).animate {
    animation-delay: 0.4s;
}

@keyframes audio-bar {
    0%, 100% { height: 4px; }
    50% { height: 12px; }
}

/* Hidden state */
.speech-hidden {
    display: none !important;
}

/* Activity states - fade out transition then hide completely */
.speech-activity.state-idle {
    display: none;
}

.speech-activity.state-active {
    display: flex;
    opacity: 1;
    transition: opacity 0.3s ease;
}

/* Fading state - intermediate step for smooth transition */
.speech-activity.state-fading {
    display: flex;
    opacity: 0;
    transition: opacity 0.3s ease;
}

/* Busy state styling */
.speech-message .status-message {
    color: #d97706;
}

.speech-message.busy .status-message {
    color: #dc2626;
    font-weight: 500;
}

.speech-activity.state-busy {
    border-color: #fbbf24;
    background-color: #fef3c7;
}

/* Responsive design */
@media (max-width: 640px) {
    .speech-activity {
        font-size: 11px;
        gap: 4px;
    }
    
    .speech-mic-button {
        width: 22px;
        height: 22px;
        right: 3px;
    }
    
    /* Responsive positioning for textareas */
    .speech-input-wrapper:has(textarea) .speech-mic-start,
    .speech-input-wrapper:has(textarea) .speech-mic-stop,
    .speech-input-wrapper textarea ~ .speech-mic-start,
    .speech-input-wrapper textarea ~ .speech-mic-stop {
        bottom: 8px;
        right: 8px;
    }
    

}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .speech-activity {
        color: #9ca3af;
    }
    
    .speech-message {
        color: #d1d5db;
    }
    
    /* Consistent status message in dark mode */
    .speech-message .status-message {
        background-color: #451a03;
        color: #fbbf24;
        border-left-color: #f59e0b;
    }
    
    /* Dark mode interim results */
    .speech-message .interim-text.visible {
        background-color: #1e3a8a;
        border-left-color: #60a5fa;
    }
    
    .speech-message .interim-text.visible .interim-label {
        color: #9ca3af;
    }
    
    .speech-message .interim-text.visible .interim-content {
        color: #dbeafe;
    }
    
    .audio-visualizer .bar.animate {
        background-color: #fca5a5;
    }
    

    
    .speech-message.busy .status-message {
        color: #f87171;
    }
    
    .speech-activity.state-busy {
        border-color: #f59e0b;
        background-color: #451a03;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    /* Reserved for future high-contrast enhancements */
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .speech-mic-button {
        transition: none;
    }
    
    .speech-mic-button.listening {
        animation: none;
        background-color: #b91c1c;
    }
    
    .audio-visualizer .bar.animate {
        animation: none;
        background-color: #b91c1c;
        height: 8px;
    }
    
    .speech-message .interim-text {
        transition: none;
    }
    
    .speech-message .interim-text .interim-label,
    .speech-message .interim-text .interim-content {
        transition: none;
    }
}

/* Component coexistence - when used with other validators */
.ax-components-wrapper.has-speech-input .input-validator-wrapper {
    margin-top: 2px;
}

.ax-components-wrapper.has-file-validator .speech-input-wrapper {
    margin-top: 2px;
}

/* Focus improvements */
.speech-activity[aria-live="polite"] {
    transition: opacity 0.3s ease;
}

.speech-message[role="alert"] {
    font-weight: 500;
}

/* Print styles */
@media print {
    .speech-activity {
        display: none;
    }
} 