/**
 * Chatbot Voice Styles
 * 음성 인식(STT) 및 음성 합성(TTS) UI 스타일
 */

/* ========== Voice Button ========== */
.voice-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: var(--wa-bg-input);
    color: var(--wa-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
    position: relative;
}

.voice-btn:hover {
    background: var(--wa-bg-hover);
    color: var(--wa-green);
}

.voice-btn i {
    font-size: 1.1rem;
    transition: transform 0.2s ease;
}

/* 듣는 중 상태 */
.voice-btn.listening {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    animation: voice-pulse 1.5s ease-in-out infinite;
}

.voice-btn.listening i {
    animation: voice-bounce 0.6s ease-in-out infinite;
}

/* 말하는 중 상태 */
.voice-btn.speaking {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
}

.voice-btn.speaking i {
    animation: voice-wave 0.8s ease-in-out infinite;
}

/* 에러 상태 */
.voice-btn.error {
    background: var(--wa-bg-input);
    color: #ef4444;
}

/* Voice Button Animation Keyframes */
@keyframes voice-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5);
    }
    50% {
        box-shadow: 0 0 0 12px rgba(239, 68, 68, 0);
    }
}

@keyframes voice-bounce {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.15);
    }
}

@keyframes voice-wave {
    0%, 100% {
        transform: scale(1);
    }
    25% {
        transform: scale(1.1);
    }
    50% {
        transform: scale(1);
    }
    75% {
        transform: scale(1.1);
    }
}

/* ========== Voice Indicator (Waveform) ========== */
.voice-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1px;
    height: 1px;
    padding: 0 1px;
    background: var(--wa-bg-darker);
    border-radius: 12px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.voice-indicator.listening,
.voice-indicator.speaking {
    opacity: 1;
    visibility: visible;
}

.voice-indicator.hidden {
    opacity: 0;
    visibility: hidden;
}

.voice-indicator .bar {
    width: 3px;
    height: 8px;
    background: var(--wa-green);
    border-radius: 3px;
    animation: waveform 0.8s ease-in-out infinite;
}

.voice-indicator .bar:nth-child(1) { animation-delay: 0s; }
.voice-indicator .bar:nth-child(2) { animation-delay: 0.1s; }
.voice-indicator .bar:nth-child(3) { animation-delay: 0.2s; }
.voice-indicator .bar:nth-child(4) { animation-delay: 0.3s; }
.voice-indicator .bar:nth-child(5) { animation-delay: 0.4s; }

.voice-indicator.listening .bar {
    background: #ef4444;
}

.voice-indicator.speaking .bar {
    background: #3b82f6;
}

@keyframes waveform {
    0%, 100% {
        height: 8px;
    }
    50% {
        height: 20px;
    }
}

/* ========== Voice Status ========== */
.voice-status {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--wa-bg-panel);
    color: var(--wa-text);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.75rem;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--wa-border);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 100;
}

.voice-status.visible {
    opacity: 1;
    visibility: visible;
}

.voice-status.error {
    background: rgba(239, 68, 68, 0.1);
    border-color: #ef4444;
    color: #ef4444;
}

.voice-status::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--wa-border);
}

/* ========== Voice Settings Modal ========== */
.voice-settings-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.voice-settings-modal.show {
    display: flex;
}

.voice-settings-content {
    background: var(--wa-bg-panel);
    border-radius: 16px;
    padding: 24px;
    width: 90%;
    max-width: 420px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
    animation: modalSlideIn 0.3s ease;
}

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

.voice-settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--wa-border);
}

.voice-settings-header h5 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.voice-settings-header h5 i {
    color: var(--wa-green);
}

.voice-settings-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--wa-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.voice-settings-close:hover {
    background: var(--wa-bg-hover);
    color: var(--wa-text);
}

.voice-settings-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.voice-setting-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.voice-setting-group label {
    font-size: 0.85rem;
    color: var(--wa-text);
    font-weight: 500;
}

.voice-setting-group select,
.voice-setting-group input[type="range"] {
    width: 100%;
    background: var(--wa-bg-input);
    border: 1px solid var(--wa-border);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--wa-text);
    font-size: 0.9rem;
}

.voice-setting-group select:focus,
.voice-setting-group input:focus {
    outline: none;
    border-color: var(--wa-green);
}

.voice-setting-group input[type="range"] {
    height: 6px;
    padding: 0;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

.voice-setting-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--wa-green);
    border-radius: 50%;
    cursor: pointer;
}

.voice-setting-group input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--wa-green);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

/* Toggle Switch */
.voice-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
}

.voice-toggle-label {
    font-size: 0.9rem;
    color: var(--wa-text);
}

.voice-toggle-label small {
    display: block;
    font-size: 0.75rem;
    color: var(--wa-text-secondary);
    margin-top: 2px;
}

.voice-toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
}

.voice-toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.voice-toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--wa-bg-input);
    border: 1px solid var(--wa-border);
    transition: 0.3s;
    border-radius: 24px;
}

.voice-toggle-slider::before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background-color: var(--wa-text-secondary);
    transition: 0.3s;
    border-radius: 50%;
}

.voice-toggle-switch input:checked + .voice-toggle-slider {
    background-color: var(--wa-green);
    border-color: var(--wa-green);
}

.voice-toggle-switch input:checked + .voice-toggle-slider::before {
    transform: translateX(20px);
    background-color: white;
}

/* Settings Footer */
.voice-settings-footer {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--wa-border);
}

.voice-settings-footer button {
    flex: 1;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-voice-test {
    background: var(--wa-bg-input);
    border: 1px solid var(--wa-border);
    color: var(--wa-text);
}

.btn-voice-test:hover {
    background: var(--wa-bg-hover);
    border-color: var(--wa-green);
}

.btn-voice-save {
    background: var(--wa-green);
    border: none;
    color: white;
}

.btn-voice-save:hover {
    background: #00c896;
}

/* ========== Voice Support Badge ========== */
.voice-support-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 500;
}

.voice-support-badge.supported {
    background: rgba(0, 168, 132, 0.15);
    color: var(--wa-green);
}

.voice-support-badge.not-supported {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

/* ========== Input Area Voice Integration ========== */
.chat-input-row .voice-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Voice button wrapper for status positioning */
.voice-btn-wrapper {
    position: relative;
}

/* Voice Settings Button (Gear icon) */
.voice-settings-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--wa-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.voice-settings-btn:hover {
    background: var(--wa-bg-hover);
    color: var(--wa-green);
}

.voice-settings-btn i {
    font-size: 0.9rem;
}

/* ========== Mobile Styles ========== */
@media (max-width: 768px) {
    .voice-btn {
        min-width: 44px;
        min-height: 44px;
    }

    .voice-status {
        font-size: 0.7rem;
        padding: 4px 10px;
    }

    .voice-settings-content {
        width: 95%;
        padding: 20px 16px;
    }

    .voice-settings-footer {
        flex-direction: column;
    }

    .voice-settings-footer button {
        min-height: 44px;
    }
}

@media (max-width: 480px) {
    .voice-indicator {
        display: none;
    }
}

/* ========== Voice Mode Active Overlay ========== */
.voice-mode-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 900;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
}

.voice-mode-overlay.active {
    display: flex;
}

.voice-mode-visual {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: voice-mode-pulse 2s ease-in-out infinite;
}

.voice-mode-visual i {
    font-size: 48px;
    color: white;
}

.voice-mode-text {
    color: white;
    font-size: 1.2rem;
    text-align: center;
}

.voice-mode-transcript {
    color: var(--wa-text-secondary);
    font-size: 1rem;
    max-width: 80%;
    text-align: center;
    min-height: 2em;
}

.voice-mode-close {
    margin-top: 20px;
    padding: 12px 32px;
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.voice-mode-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

@keyframes voice-mode-pulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 0 30px rgba(239, 68, 68, 0);
    }
}

/* ========== Speaking Animation for AI Messages ========== */
.message.ai.speaking-now {
    position: relative;
}

.message.ai.speaking-now::before {
    content: '';
    position: absolute;
    left: -20px;
    top: 50%;
    transform: translateY(-50%);
    width: 12px;
    height: 12px;
    background: #3b82f6;
    border-radius: 50%;
    animation: speaking-dot 1s ease-in-out infinite;
}

@keyframes speaking-dot {
    0%, 100% {
        opacity: 1;
        transform: translateY(-50%) scale(1);
    }
    50% {
        opacity: 0.5;
        transform: translateY(-50%) scale(0.8);
    }
}
