/**
 * Enhanced Voice Input Styles
 * 微信风格的语音输入交互
 */

/* 语音按钮增强状态 */
.voice-button {
    position: relative;
    transition: all 0.2s ease;
}

/* 文字模式：小按钮 */
.voice-button.text-mode {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
}

/* 语音模式：大按钮，占据剩余空间 */
.voice-button.voice-mode {
    flex: 1;
    height: 56px !important;
    min-height: 56px !important;
    border-radius: 28px;
    background-color: #f5f5f5;
    border: 2px solid #e0e0e0;
}

.voice-button.voice-mode .hold-to-talk {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    height: 100%;
}

.voice-button.voice-mode .hold-text {
    font-size: 16px;
    font-weight: 500;
    color: #666;
}

/* 键盘切换按钮（语音模式下显示） */
.keyboard-switch-button {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border: none;
    border-radius: 4px;
    background-color: var(--background-light);
    color: var(--text-gray);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.keyboard-switch-button:hover {
    background-color: #e8e8e8;
}

.keyboard-switch-button:active {
    transform: scale(0.95);
}

.voice-button.pressed {
    transform: scale(0.95);
    background-color: var(--primary-dark);
    color: white;
}

.voice-button.recording {
    background-color: var(--accent-red);
    color: white;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

/* 录音遮罩层 - 灰色渐变 */
.voice-recording-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(180deg, 
        rgba(255, 255, 255, 0) 0%, 
        rgba(240, 240, 240, 0.3) 35%, 
        rgba(220, 220, 220, 0.7) 55%, 
        rgba(200, 200, 200, 0.9) 75%, 
        rgba(180, 180, 180, 0.95) 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    padding-bottom: 80px;
}

.voice-recording-overlay.show {
    opacity: 1;
    visibility: visible;
}

/* 录音内容区域 */
.recording-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding-bottom: 40px;
}

/* 波纹动画容器 */
.recording-wave-container {
    position: relative;
    width: 160px;
    height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 30px;
    filter: drop-shadow(0 0 20px rgba(150, 150, 150, 0.3));
}

/* 中心圆点 */
.recording-center-dot {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background-color: white;
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 25px rgba(180, 180, 180, 0.5), 
                0 0 50px rgba(200, 200, 200, 0.3),
                0 4px 16px rgba(0, 0, 0, 0.15);
    animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% {
        box-shadow: 0 0 25px rgba(180, 180, 180, 0.5), 
                    0 0 50px rgba(200, 200, 200, 0.3),
                    0 4px 16px rgba(0, 0, 0, 0.15);
    }
    50% {
        box-shadow: 0 0 35px rgba(160, 160, 160, 0.7), 
                    0 0 70px rgba(180, 180, 180, 0.5),
                    0 4px 20px rgba(0, 0, 0, 0.2);
    }
}

/* 麦克风图标 */
.recording-mic-icon {
    width: 35px;
    height: 35px;
    color: #888;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

/* 波纹圆环 - 灰白色调 */
.recording-ripple {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    border: 3px solid rgba(160, 160, 160, 0.6);
    box-shadow: 0 0 15px rgba(180, 180, 180, 0.5),
                inset 0 0 15px rgba(200, 200, 200, 0.3);
    animation: ripple-enhanced 2s ease-out infinite;
}

.recording-ripple:nth-child(2) {
    animation-delay: 0.5s;
}

.recording-ripple:nth-child(3) {
    animation-delay: 1s;
}

.recording-ripple:nth-child(4) {
    animation-delay: 1.5s;
}

@keyframes ripple-enhanced {
    0% {
        width: 70px;
        height: 70px;
        opacity: 1;
        border-width: 3px;
        box-shadow: 0 0 15px rgba(180, 180, 180, 0.5),
                    inset 0 0 15px rgba(200, 200, 200, 0.3);
    }
    50% {
        opacity: 0.6;
        border-width: 2px;
        box-shadow: 0 0 25px rgba(160, 160, 160, 0.7),
                    inset 0 0 25px rgba(180, 180, 180, 0.5);
    }
    100% {
        width: 160px;
        height: 160px;
        opacity: 0;
        border-width: 1px;
        box-shadow: 0 0 30px rgba(200, 200, 200, 0.3),
                    inset 0 0 30px rgba(220, 220, 220, 0.2);
    }
}

/* 录音时长显示 */
.recording-duration {
    font-size: 28px;
    font-weight: 300;
    color: #333;
    margin-bottom: 15px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    letter-spacing: 1px;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* 松手发送提示 */
.release-hint {
    font-size: 15px;
    color: #666;
    font-weight: 400;
    text-align: center;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

/* 切换提示Toast */
.switch-hint-toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 16px 32px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.switch-hint-toast.show {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

/* 取消Toast */
.cancel-toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 16px 32px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    z-index: 9998;
    opacity: 0;
    transition: all 0.3s ease;
}

.cancel-toast.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* 隐藏类 */
.hidden {
    display: none !important;
}

/* 输入区域布局优化 */
.input-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* 当语音模式时，输入区域只显示语音按钮 */
.input-area.voice-only {
    justify-content: center;
}

/* 文字输入容器动画 */
.text-input-container {
    animation: fadeIn 0.3s ease;
}

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

/* 触摸反馈优化 */
@media (hover: none) and (pointer: coarse) {
    .voice-button {
        -webkit-tap-highlight-color: transparent;
        user-select: none;
        -webkit-user-select: none;
        touch-action: none;
    }
}


/* 移动端优化 */
@media (max-width: 768px) {
    .voice-button.voice-mode {
        height: 52px !important;
        min-height: 52px !important;
        border-radius: 26px;
    }
    
    .voice-button.voice-mode .hold-text {
        font-size: 15px;
    }
    
    .voice-button.text-mode,
    .keyboard-switch-button {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
    }
    
    .voice-recording-overlay {
        padding-bottom: 60px;
    }
    
    .recording-wave-container {
        width: 140px;
        height: 140px;
        margin-bottom: 25px;
        filter: drop-shadow(0 0 15px rgba(150, 150, 150, 0.3));
    }
    
    .recording-center-dot {
        width: 60px;
        height: 60px;
        box-shadow: 0 0 20px rgba(180, 180, 180, 0.5), 
                    0 0 40px rgba(200, 200, 200, 0.3),
                    0 4px 12px rgba(0, 0, 0, 0.15);
    }
    
    @keyframes pulse-glow {
        0%, 100% {
            box-shadow: 0 0 20px rgba(180, 180, 180, 0.5), 
                        0 0 40px rgba(200, 200, 200, 0.3),
                        0 4px 12px rgba(0, 0, 0, 0.15);
        }
        50% {
            box-shadow: 0 0 30px rgba(160, 160, 160, 0.7), 
                        0 0 60px rgba(180, 180, 180, 0.5),
                        0 4px 16px rgba(0, 0, 0, 0.2);
        }
    }
    
    .recording-mic-icon {
        width: 30px;
        height: 30px;
    }
    
    @keyframes ripple-enhanced {
        0% {
            width: 60px;
            height: 60px;
            opacity: 1;
            border-width: 3px;
            box-shadow: 0 0 15px rgba(180, 180, 180, 0.5),
                        inset 0 0 15px rgba(200, 200, 200, 0.3);
        }
        50% {
            opacity: 0.6;
            border-width: 2px;
            box-shadow: 0 0 25px rgba(160, 160, 160, 0.7),
                        inset 0 0 25px rgba(180, 180, 180, 0.5);
        }
        100% {
            width: 140px;
            height: 140px;
            opacity: 0;
            border-width: 1px;
            box-shadow: 0 0 30px rgba(200, 200, 200, 0.3),
                        inset 0 0 30px rgba(220, 220, 220, 0.2);
        }
    }
    
    .recording-duration {
        font-size: 24px;
        margin-bottom: 12px;
    }
    
    .release-hint {
        font-size: 14px;
    }
    
    .switch-hint-toast,
    .cancel-toast {
        font-size: 14px;
        padding: 14px 28px;
    }
}

/* PC端优化 */
@media (min-width: 769px) {
    .voice-button.voice-mode {
        height: 60px !important;
        min-height: 60px !important;
        border-radius: 30px;
    }
    
    .voice-button.voice-mode .hold-text {
        font-size: 17px;
    }
    
    .voice-button.text-mode,
    .keyboard-switch-button {
        width: 48px;
        height: 48px;
        min-width: 48px;
        min-height: 48px;
    }
    
    .voice-button.voice-mode:hover {
        background-color: #eeeeee;
        border-color: #d0d0d0;
    }
    
    .voice-button.text-mode:hover,
    .keyboard-switch-button:hover {
        background-color: #e8e8e8;
    }
    
    .voice-recording-overlay {
        padding-bottom: 100px;
    }
    
    .recording-wave-container {
        width: 180px;
        height: 180px;
        margin-bottom: 35px;
        filter: drop-shadow(0 0 25px rgba(150, 150, 150, 0.4));
    }
    
    .recording-center-dot {
        width: 80px;
        height: 80px;
        box-shadow: 0 0 30px rgba(180, 180, 180, 0.6), 
                    0 0 60px rgba(200, 200, 200, 0.4),
                    0 4px 20px rgba(0, 0, 0, 0.2);
    }
    
    @keyframes pulse-glow {
        0%, 100% {
            box-shadow: 0 0 30px rgba(180, 180, 180, 0.6), 
                        0 0 60px rgba(200, 200, 200, 0.4),
                        0 4px 20px rgba(0, 0, 0, 0.2);
        }
        50% {
            box-shadow: 0 0 40px rgba(160, 160, 160, 0.8), 
                        0 0 80px rgba(180, 180, 180, 0.6),
                        0 4px 24px rgba(0, 0, 0, 0.25);
        }
    }
    
    .recording-mic-icon {
        width: 40px;
        height: 40px;
    }
    
    @keyframes ripple-enhanced {
        0% {
            width: 80px;
            height: 80px;
            opacity: 1;
            border-width: 3px;
            box-shadow: 0 0 15px rgba(180, 180, 180, 0.5),
                        inset 0 0 15px rgba(200, 200, 200, 0.3);
        }
        50% {
            opacity: 0.6;
            border-width: 2px;
            box-shadow: 0 0 25px rgba(160, 160, 160, 0.7),
                        inset 0 0 25px rgba(180, 180, 180, 0.5);
        }
        100% {
            width: 180px;
            height: 180px;
            opacity: 0;
            border-width: 1px;
            box-shadow: 0 0 30px rgba(200, 200, 200, 0.3),
                        inset 0 0 30px rgba(220, 220, 220, 0.2);
        }
    }
    
    .recording-duration {
        font-size: 32px;
        margin-bottom: 18px;
    }
    
    .release-hint {
        font-size: 16px;
    }
}

/* Voice recording gesture — focused, interruptible mobile interaction */
.voice-recording-overlay {
    justify-content: center;
    padding: 0;
    overflow: hidden;
    pointer-events: none;
    background: rgba(16, 22, 19, 0.72);
    -webkit-backdrop-filter: blur(12px) saturate(115%);
    backdrop-filter: blur(12px) saturate(115%);
}

.voice-recording-overlay .recording-content {
    width: min(100%, 440px);
    padding: 0 24px 18vh;
    box-sizing: border-box;
}

.voice-recording-overlay .recording-wave-container {
    width: min(300px, 72vw);
    height: 148px;
    margin: 0 0 24px;
    border-radius: 38px;
    color: #146b3a;
    background: #72e18e;
    background: color-mix(in srgb, var(--chat-theme) 66%, white);
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.36);
    filter: none;
    will-change: transform, opacity;
}

.voice-recording-overlay .recording-wave-container::after {
    content: '';
    position: absolute;
    left: 50%;
    bottom: -13px;
    width: 28px;
    height: 28px;
    background: inherit;
    transform: translateX(-50%) rotate(45deg);
    border-radius: 0 0 7px 0;
}

.recording-waveform {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 58px;
}

.recording-waveform i {
    display: block;
    width: 4px;
    height: 18px;
    border-radius: 999px;
    background: currentColor;
    transform-origin: center;
    animation: voice-wave 0.82s ease-in-out infinite alternate;
}

.recording-waveform i:nth-child(2n) { animation-delay: -0.18s; }
.recording-waveform i:nth-child(3n) { animation-delay: -0.34s; }
.recording-waveform i:nth-child(4n) { animation-delay: -0.52s; }

@keyframes voice-wave {
    from { transform: scaleY(0.55); opacity: 0.68; }
    to { transform: scaleY(2.2); opacity: 1; }
}

.voice-recording-overlay .recording-duration {
    margin: 0 0 8px;
    color: #fff;
    font-size: 25px;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -0.01em;
    text-shadow: none;
}

.voice-recording-overlay .release-hint {
    color: rgba(255, 255, 255, 0.82);
    font-size: 17px;
    font-weight: 550;
    letter-spacing: 0.01em;
    text-shadow: none;
}

.recording-actions {
    position: absolute;
    right: max(16px, env(safe-area-inset-right));
    bottom: calc(28px + env(safe-area-inset-bottom));
    left: max(16px, env(safe-area-inset-left));
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    max-width: 560px;
    margin: 0 auto;
}

.recording-action {
    min-height: 82px;
    padding: 14px 10px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 28px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 7px;
    color: rgba(255, 255, 255, 0.9);
    background: rgba(255, 255, 255, 0.12);
    -webkit-backdrop-filter: blur(18px) saturate(130%);
    backdrop-filter: blur(18px) saturate(130%);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
    font-size: 14px;
    font-weight: 600;
    transition: transform 180ms ease-out, background-color 180ms ease-out, border-color 180ms ease-out;
}

.recording-action-icon {
    display: grid;
    width: 26px;
    height: 26px;
    place-items: center;
    border: 1px solid currentColor;
    border-radius: 50%;
    font-size: 20px;
    line-height: 1;
}

.recording-cancel-zone.active {
    color: #fff;
    border-color: rgba(255, 116, 116, 0.74);
    background: rgba(220, 54, 54, 0.72);
    transform: scale(1.035);
}

.recording-send-zone {
    color: #fff;
    background: rgba(255, 255, 255, 0.18);
}

.voice-recording-overlay.cancel-active .recording-wave-container {
    color: #8f1d1d;
    background: #ff8a8a;
}

.voice-status-toast {
    position: fixed;
    top: 48%;
    left: 50%;
    z-index: 10001;
    width: min(220px, calc(100vw - 64px));
    min-height: 150px;
    padding: 24px 20px;
    box-sizing: border-box;
    border-radius: 22px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: #fff;
    background: rgba(34, 37, 35, 0.9);
    -webkit-backdrop-filter: blur(18px) saturate(125%);
    backdrop-filter: blur(18px) saturate(125%);
    box-shadow: 0 22px 58px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.14);
    font-size: 17px;
    font-weight: 600;
    line-height: 1.35;
    text-align: center;
    opacity: 0;
    transform: translate(-50%, -45%) scale(0.92);
    transition: opacity 180ms ease-out, transform 260ms cubic-bezier(0.22, 1, 0.36, 1);
}

.voice-status-toast.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.voice-status-icon {
    display: grid;
    width: 54px;
    height: 54px;
    place-items: center;
    border-radius: 50%;
    color: #313633;
    background: #fff;
    font-size: 38px;
    font-weight: 500;
    line-height: 1;
}

.voice-status-toast.cancel .voice-status-icon {
    font-size: 32px;
}

@media (max-height: 650px) {
    .voice-recording-overlay .recording-content { padding-bottom: 22vh; }
    .voice-recording-overlay .recording-wave-container { height: 118px; }
    .recording-action { min-height: 68px; }
}

@media (prefers-reduced-motion: reduce) {
    .recording-waveform i { animation: none; }
    .voice-recording-overlay .recording-wave-container,
    .recording-action,
    .voice-status-toast { transition: opacity 160ms ease; }
}

@media (prefers-reduced-transparency: reduce) {
    .voice-recording-overlay { background: rgba(20, 24, 22, 0.94); backdrop-filter: none; }
    .recording-action, .voice-status-toast { backdrop-filter: none; }
}
