/* ============================================================
   语音搜索样式
   麦克风按钮 + 录音动画 + 优雅降级
   策略：按钮默认可见，JS检测不支持时添加 .voice-search-unsupported 隐藏
   ============================================================ */

/* --- 麦克风按钮：位于输入框与提交按钮之间，默认可见 --- */
.search-fields .voice-search-btn {
    flex: 0 0 auto;
    width: 48px;
    min-width: 48px;
    padding: 0;
    background: transparent;
    color: var(--ri-gray-500, #a1a1a8);
    border: none;
    border-radius: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    transition: color 0.2s ease, background 0.2s ease;
    outline: none;
    position: relative;
    z-index: 1;
}
.search-fields .voice-search-btn:hover {
    color: var(--ri-primary, #2163e8);
    background: rgba(33, 99, 232, 0.06);
}
.search-fields .voice-search-btn:active {
    transform: scale(0.95);
}

/* 按住状态：图标微缩 + 背景高亮 */
.voice-search-btn.pressing .voice-icon {
    transform: scale(0.92);
    background: rgba(33, 99, 232, 0.08);
}

/* 识别出错时，图标红色抖动 */
.voice-search-btn.voice-error .voice-icon {
    animation: voice-error-shake 0.4s ease;
    color: var(--ri-danger, #d6293e);
    background: rgba(214, 41, 62, 0.1);
}
@keyframes voice-error-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-3px); }
    40% { transform: translateX(3px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(3px); }
}

/* 浏览器不支持语音API时，JS添加此类进行隐藏 */
.voice-search-unsupported .voice-search-btn {
    display: none !important;
}

/* --- 麦克风图标 --- */
.voice-search-btn .voice-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    transition: all 0.25s ease;
}
.voice-search-btn .voice-icon i {
    font-size: 1.15rem;
    line-height: 1;
}

/* ============================================================
   录音中状态 - 脉冲动画
   ============================================================ */

/* 录音中按钮状态 */
.search-fields .voice-search-btn.listening {
    color: var(--ri-danger, #d6293e);
    background: transparent;
}

/* 录音中图标：红色背景 + 脉冲波纹 */
.voice-search-btn.listening .voice-icon {
    background: var(--ri-danger, #d6293e);
    color: #fff;
    animation: voice-pulse-ring 1.5s ease-out infinite;
    box-shadow:
        0 0 0 0 rgba(214, 41, 62, 0.6),
        0 0 0 0 rgba(214, 41, 62, 0.4);
}
.voice-search-btn.listening .voice-icon i {
    font-size: 0.95rem;
    animation: voice-wave 0.8s ease-in-out infinite;
}

/* 波纹扩散 */
@keyframes voice-pulse-ring {
    0% {
        box-shadow:
            0 0 0 0 rgba(214, 41, 62, 0.6),
            0 0 0 0 rgba(214, 41, 62, 0.3);
    }
    30% {
        box-shadow:
            0 0 0 8px rgba(214, 41, 62, 0),
            0 0 0 6px rgba(214, 41, 62, 0.15);
    }
    60% {
        box-shadow:
            0 0 0 0 rgba(214, 41, 62, 0),
            0 0 0 12px rgba(214, 41, 62, 0);
    }
    100% {
        box-shadow:
            0 0 0 0 rgba(214, 41, 62, 0),
            0 0 0 16px rgba(214, 41, 62, 0);
    }
}

/* 图标大小微动 */
@keyframes voice-wave {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.08);
    }
}

/* 录音中 placeholder 提示色 */
.search-fields .voice-search-btn.listening ~ input[type="text"]::placeholder,
.search-fields input[type="text"].listening-placeholder::placeholder {
    color: var(--ri-danger, #d6293e);
    opacity: 0.7;
}

/* ============================================================
   录制中声音波纹提示条（在按钮上方显示）
   ============================================================ */
.voice-search-btn.listening::before {
    content: '';
    position: absolute;
    top: -4px;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: 12px;
    border-radius: 2px;
    background: var(--ri-danger, #d6293e);
    animation: voice-bar-1 0.6s ease-in-out infinite;
    opacity: 0.9;
}

/* 波纹条动画 */
@keyframes voice-bar-1 {
    0%, 100% {
        height: 8px;
        box-shadow:
            6px 4px 0 0 currentColor,
            -6px 4px 0 0 currentColor;
    }
    50% {
        height: 18px;
        box-shadow:
            6px -4px 0 0 currentColor,
            -6px -4px 0 0 currentColor;
    }
}

/* ============================================================
   响应式适配
   ============================================================ */

/* 平板竖屏 / 大手机 ≤768px */
@media (max-width: 767.98px) {
    .search-fields .voice-search-btn {
        width: 42px;
        min-width: 42px;
    }
    .voice-search-btn .voice-icon {
        width: 32px;
        height: 32px;
    }
    .voice-search-btn .voice-icon i {
        font-size: 1rem;
    }
    .voice-search-btn.listening .voice-icon i {
        font-size: 0.85rem;
    }
}

/* 小屏手机 ≤480px */
@media (max-width: 480px) {
    .search-fields .voice-search-btn {
        width: 38px;
        min-width: 38px;
    }
    .voice-search-btn .voice-icon {
        width: 30px;
        height: 30px;
    }
    .voice-search-btn .voice-icon i {
        font-size: 0.95rem;
    }
    .voice-search-btn.listening .voice-icon i {
        font-size: 0.8rem;
    }

    /* 小屏上减弱波纹效果 */
    @keyframes voice-pulse-ring-sm {
        0% {
            box-shadow:
                0 0 0 0 rgba(214, 41, 62, 0.5),
                0 0 0 0 rgba(214, 41, 62, 0.2);
        }
        40% {
            box-shadow:
                0 0 0 4px rgba(214, 41, 62, 0),
                0 0 0 8px rgba(214, 41, 62, 0);
        }
        100% {
            box-shadow:
                0 0 0 0 rgba(214, 41, 62, 0),
                0 0 0 10px rgba(214, 41, 62, 0);
        }
    }
    .voice-search-btn.listening .voice-icon {
        animation-name: voice-pulse-ring-sm;
    }
}

/* ============================================================
   navbar 导航栏中的搜索框特殊适配
   ============================================================ */
.navbar-search .search-fields .voice-search-btn {
    width: 40px;
    min-width: 40px;
}
.navbar-search .search-fields .voice-search-btn .voice-icon {
    width: 32px;
    height: 32px;
}
.navbar-search .search-fields .voice-search-btn .voice-icon i {
    font-size: 1rem;
}

/* navbar 搜索框录音动画减弱 */
.navbar-search .voice-search-btn.listening::before {
    display: none;
}

/* navbar 搜索框响应式 */
@media (max-width: 991.98px) {
    .navbar-search .search-fields .voice-search-btn {
        width: 38px;
        min-width: 38px;
    }
}

/* 移动端 navbar 搜索展开样式 */
@media (max-width: 767.98px) {
    .navbar-search .search-fields .voice-search-btn {
        width: 38px;
        min-width: 38px;
    }
    .navbar-search .search-fields .voice-search-btn .voice-icon {
        width: 30px;
        height: 30px;
    }
}
