/* =====================================================
 * 智能健康助手 - Chat 界面样式
 * 白色简洁风格，移动端优先
 * ===================================================== */

/* ========== 布局 ========== */
.chat-section {
    min-height: calc(100vh - var(--hz-header-h));
    display: flex;
    flex-direction: column;
    background: #f5f5f7;
}

.chat-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    background: #ffffff;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.04);
}

/* ========== 顶部导航 ========== */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
    background: #ffffff;
    flex-shrink: 0;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    color: #6b7280;
    transition: background 0.15s, color 0.15s;
}

.chat-back:hover {
    background: #f3f4f6;
    color: #374151;
}

.chat-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-brand-icon {
    color: #4f46e5;
    flex-shrink: 0;
}

.chat-title {
    font-size: 16px;
    font-weight: 600;
    color: #111827;
    margin: 0;
    line-height: 1.3;
}

.chat-subtitle {
    font-size: 11px;
    color: #9ca3af;
    margin: 0;
    line-height: 1.2;
}

.chat-header-right {
    flex-shrink: 0;
}

.chat-user-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-user-name {
    font-size: 13px;
    color: #6b7280;
}

.chat-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #4f46e5;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
}

/* ========== 消息区域 ========== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #f9fafb;
    scroll-behavior: smooth;
}

/* 消息通用 */
.message {
    display: flex;
    gap: 10px;
    max-width: 85%;
    animation: messageIn 0.25s ease-out;
}

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

/* AI 消息 - 左对齐 */
.message-ai {
    align-self: flex-start;
}

/* 用户消息 - 右对齐 */
.message-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

/* 头像 */
.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
}

.ai-avatar {
    background: #eef2ff;   /* indigo-50 */
    color: #4f46e5;
}

.user-avatar {
    background: #6366f1;
    color: #fff;
}

/* 消息气泡 */
.message-bubble {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
    position: relative;
}

.ai-bubble {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    color: #374151;
    border-top-left-radius: 4px;
}

.user-bubble {
    background: #4f46e5;
    color: #ffffff;
    border-top-right-radius: 4px;
}

.user-bubble p {
    margin: 0;
}

/* 气泡内文字样式 */
.message-bubble p {
    margin: 0;
}

.message-bubble strong {
    font-weight: 600;
}

/* 欢迎消息 */
.welcome-bubble {
    background: linear-gradient(135deg, #faf5ff, #eef2ff);
    border-color: #e4e4f0;
}

.welcome-title {
    font-size: 16px;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 8px !important;
}

.welcome-brand {
    color: #4f46e5;
}

.welcome-text {
    color: #4b5563;
    margin-bottom: 8px !important;
}

.welcome-tip {
    color: #6366f1;
    font-weight: 500;
}

/* ========== 输入区域 ========== */
.chat-input-area {
    flex-shrink: 0;
    padding: 12px 16px 8px;
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
}

.chat-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 6px 6px 6px 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
    overflow: hidden;
}

.chat-input-wrapper:focus-within {
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
    background: #ffffff;
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 8px 0;
    font-size: 15px;
    color: #111827;
    outline: none;
    resize: none;
    max-height: 120px;
    line-height: 1.5;
    font-family: inherit;
}

.chat-input::placeholder {
    color: #9ca3af;
}

.chat-send-btn {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: none;
    background: #4f46e5;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.chat-send-btn:hover {
    background: #4338ca;
}

.chat-send-btn:active {
    transform: scale(0.95);
}

.chat-send-btn:disabled {
    background: #d1d5db;
    cursor: not-allowed;
    transform: none;
}

/* 停止回答按钮 */
.chat-stop-btn {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: #ef4444;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}
.chat-stop-btn:hover { background: #dc2626; }
.chat-stop-btn:active { transform: scale(0.95); }

/* 登录提示 */
.chat-login-prompt {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 4px 0;
}

.chat-login-text {
    font-size: 14px;
    color: #6b7280;
    margin: 0;
}

.chat-login-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 20px;
    background: #4f46e5;
    color: #ffffff;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.15s;
}

.chat-login-btn:hover {
    background: #4338ca;
    color: #ffffff;
}

/* 免责声明 */
.chat-disclaimer {
    text-align: center;
    font-size: 11px;
    color: #9ca3af;
    margin: 8px 0 0;
    padding: 0;
}

/* ========== 产品选择按钮 ========== */
.product-select-area {
    padding: 8px 16px 12px;
    text-align: center;
    animation: messageIn 0.3s ease-out;
}

.product-select-label {
    font-size: 13px;
    color: #6b7280;
    margin: 0 0 10px;
}

.product-btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.product-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0;
    padding: 8px 16px 8px 14px;
    border: 1.5px solid #d1d5db;
    border-radius: 20px;
    background: #ffffff;
    color: #374151;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    outline: none;
}

.product-btn:hover {
    border-color: #818cf8;
    background: #f5f3ff;
}

.product-btn.active {
    border-color: #4f46e5;
    background: #eef2ff;
    color: #4338ca;
    font-weight: 600;
    box-shadow: 0 0 0 1px rgba(79,70,229,0.2);
}

.product-check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 0;
    height: 0;
    overflow: hidden;
    border-radius: 50%;
    background: transparent;
    color: transparent;
    font-size: 11px;
    font-weight: 700;
    transition: all 0.2s;
    flex-shrink: 0;
}

.product-btn.active .product-check {
    width: 16px;
    height: 16px;
    margin-right: 5px;
    background: #4f46e5;
    color: #ffffff;
}

/* 脉冲提示（未选产品时闪烁） */
.product-select-area.highlight-pulse .product-btn-group {
    animation: pulse-highlight 1.5s ease;
}

@keyframes pulse-highlight {
    0%, 100% { opacity: 1; }
    25% { opacity: 0.5; }
    50% { opacity: 1; }
    75% { opacity: 0.6; }
}

/* ========== 加载指示器 ========== */
.chat-loading {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    max-width: 800px;
    width: calc(100% - 32px);
    z-index: 10;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 0;
}

.typing-indicator span {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4f46e5;
    animation: typing 1.4s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ========== 响应式：移动端 ========== */
@media (max-width: 768px) {
    .chat-section {
        min-height: calc(100vh - var(--hz-header-h));
    }

    .chat-container {
        flex: 1;
        max-width: 100%;
        box-shadow: none;
    }

    .chat-header {
        padding: 10px 12px;
    }

    .chat-messages {
        padding: 16px 12px;
        gap: 12px;
    }

    .message {
        max-width: 90%;
    }

    .chat-input-area {
        padding: 8px 12px 6px;
    }

    .chat-input-wrapper {
        padding: 4px 4px 4px 12px;
    }

    .chat-input {
        font-size: 16px; /* 防止 iOS 自动缩放 */
        padding: 6px 0;
    }

    .chat-loading {
        width: calc(100% - 24px);
        bottom: 90px;
    }

    .chat-login-btn {
        padding: 10px 24px;
        font-size: 15px;
    }
}

/* ========== 桌面端优化 ========== */
@media (min-width: 769px) {
    .chat-container {
        border-radius: 0;
        box-shadow: 0 0 0 1px rgba(0,0,0,0.04);
    }

    .chat-messages {
        padding: 24px 24px 16px;
    }

    .message {
        max-width: 75%;
    }

    .chat-input-area {
        padding: 16px 24px 12px;
    }
}

/* ========== 滚动条美化 ========== */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* ========== 语音按钮 ========== */
/* 文字模式切换按钮（话筒图标 → 文本图标） */
#voiceToggleBtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #9ca3af;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    padding: 0;
}
#voiceToggleBtn:hover { color: var(--hz-primary); background: #f3f4f6; }
#voiceToggleBtn.active { color: var(--hz-primary); background: #eef2ff; }

/* 语音模式下的按住说话按钮 */
#chatMicBtn {
    display: none;
    flex: 1 1 auto;
    max-width: 560px;
    min-width: 100px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 52px;
    margin: 0;
    border: none;
    border-radius: 26px;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: #ffffff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
    -webkit-user-select: none;
    letter-spacing: 0.5px;
    box-shadow: 0 4px 14px rgba(99,102,241,0.25);
    position: relative;
    overflow: hidden;
}
#chatMicBtn::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 26px;
    background: linear-gradient(135deg, rgba(255,255,255,0.12) 0%, transparent 60%);
    pointer-events: none;
}
#chatMicBtn .chat-mic-icon {
    display: block;
    flex-shrink: 0;
}
#chatMicBtn:hover {
    box-shadow: 0 6px 20px rgba(99,102,241,0.35);
    transform: translateY(-1px);
}
#chatMicBtn:active,
#chatMicBtn.recording {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    box-shadow: 0 2px 8px rgba(99,102,241,0.3);
    transform: scale(0.97);
}
#chatMicBtn.recording {
    animation: micBtnPulse 1.2s ease-in-out infinite;
}
@keyframes micBtnPulse {
    0%, 100% { box-shadow: 0 4px 14px rgba(239,68,68,0.3); }
    50% { box-shadow: 0 4px 24px rgba(239,68,68,0.5); }
}

/* 右侧按钮容器 */
.chat-right-btns {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    align-self: center;
}

/* 按住说话气泡（上方弹出） */
.voice-bubble {
    position: fixed;
    left: 50%;
    top: 30%;
    transform: translateX(-50%);
    background: #1f2937;
    color: #fff;
    padding: 20px 32px;
    border-radius: 16px;
    z-index: 200;
    text-align: center;
    box-shadow: 0 8px 30px rgba(0,0,0,0.3);
    transition: opacity 0.2s, transform 0.2s;
    opacity: 0;
    pointer-events: none;
}
.voice-bubble.show {
    opacity: 1;
    pointer-events: auto;
}

/* 气泡内声波动画 */
.voice-bubble .wave-box {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 40px;
    margin-bottom: 12px;
}
.voice-bubble .wave-box span {
    display: block;
    width: 4px;
    height: 16px;
    background: #818cf8;
    border-radius: 2px;
    animation: voiceWavePop 0.6s ease-in-out infinite;
}
.voice-bubble .wave-box span:nth-child(1) { animation-delay: 0s; height: 12px; }
.voice-bubble .wave-box span:nth-child(2) { animation-delay: 0.1s; height: 28px; }
.voice-bubble .wave-box span:nth-child(3) { animation-delay: 0.2s; height: 36px; }
.voice-bubble .wave-box span:nth-child(4) { animation-delay: 0.3s; height: 22px; }
.voice-bubble .wave-box span:nth-child(5) { animation-delay: 0.4s; height: 14px; }

@keyframes voiceWavePop {
    0%, 100% { transform: scaleY(0.6); }
    50% { transform: scaleY(1.2); }
}

.voice-bubble .voice-bubble-label {
    font-size: 14px;
    color: #d1d5db;
}

/* ========== 浮动音频播放器 ========== */
.voice-float-player {
    position: fixed;
    inset: 0;
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    cursor: pointer;
}
.voice-float-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    background: #ffffff;
    padding: 40px 48px;
    border-radius: 24px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    cursor: default;
}
.voice-float-wave {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 60px;
}
.voice-float-wave span {
    display: block;
    width: 6px;
    background: var(--hz-primary, #4f46e5);
    border-radius: 3px;
    animation: floatWave 0.8s ease-in-out infinite;
}
.voice-float-wave span:nth-child(1) { height: 20px; animation-delay: 0s; }
.voice-float-wave span:nth-child(2) { height: 40px; animation-delay: 0.15s; }
.voice-float-wave span:nth-child(3) { height: 60px; animation-delay: 0.3s; }
.voice-float-wave span:nth-child(4) { height: 40px; animation-delay: 0.15s; }
.voice-float-wave span:nth-child(5) { height: 20px; animation-delay: 0s; }

@keyframes floatWave {
    0%, 100% { transform: scaleY(0.6); }
    50% { transform: scaleY(1.2); }
}

.voice-float-label {
    font-size: 14px;
    color: #9ca3af;
    text-align: center;
}

/* ========== 浮动提示 ========== */
.voice-float-tip {
    position: fixed;
    left: 50%;
    top: 30%;
    transform: translateX(-50%);
    z-index: 999;
    background: #1f2937;
    color: #fff;
    padding: 14px 28px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 500;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    animation: tipFadeInOut 2s ease-in-out forwards;
    pointer-events: none;
}

@keyframes tipFadeInOut {
    0% { opacity: 0; transform: translateX(-50%) scale(0.9); }
    15% { opacity: 1; transform: translateX(-50%) scale(1); }
    75% { opacity: 1; transform: translateX(-50%) scale(1); }
    100% { opacity: 0; transform: translateX(-50%) scale(0.9); }
}

/* ========== 语音播放按钮（AI气泡内） ========== */
.chat-voice-play {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 18px;
    margin-top: 10px;
    border: 1.5px solid #c7d2fe;
    border-radius: 20px;
    background: #f5f3ff;
    color: var(--hz-primary, #4f46e5);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s;
}
.chat-voice-play:hover { background: #eef2ff; border-color: var(--hz-primary); }
.chat-voice-play:active { transform: scale(0.96); }
.chat-voice-play.playing { background: #dbeafe; border-color: #6366f1; }
.chat-voice-play .voice-wave {
    display: flex;
    align-items: center;
    gap: 3px;
    height: 20px;
}
.chat-voice-play .voice-wave span {
    display: block;
    width: 3px;
    background: #818cf8;
    border-radius: 2px;
    animation: voiceWave 1s ease-in-out infinite;
}
.chat-voice-play .voice-wave span:nth-child(1) { height: 6px; animation-delay: 0s; }
.chat-voice-play .voice-wave span:nth-child(2) { height: 10px; animation-delay: 0.2s; }
.chat-voice-play .voice-wave span:nth-child(3) { height: 14px; animation-delay: 0.4s; }
.chat-voice-play .voice-wave span:nth-child(4) { height: 10px; animation-delay: 0.6s; }
.chat-voice-play .voice-wave span:nth-child(5) { height: 6px; animation-delay: 0.8s; }
.chat-voice-play.playing .voice-wave span { background: #2563eb; }

@keyframes voiceWave {
    0%, 100% { transform: scaleY(0.6); }
    50% { transform: scaleY(1.2); }
}

/* ========== 相关问题推荐 ========== */
.chat-related-questions {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid #e5e7eb;
}
.chat-rq-label {
    font-size: 12px;
    color: #9ca3af;
    margin-bottom: 8px;
}
.chat-rq-btn {
    display: block;
    width: 100%;
    padding: 10px 14px;
    margin-bottom: 8px;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    background: #f9fafb;
    color: #374151;
    font-size: 14px;
    text-align: left;
    cursor: pointer;
    transition: all 0.15s;
    line-height: 1.4;
}
.chat-rq-btn:hover {
    background: #eef2ff;
    border-color: var(--hz-primary, #4f46e5);
    color: var(--hz-primary, #4f46e5);
}
.chat-rq-btn:active {
    transform: scale(0.98);
}

/* ========== 浮动TTS播报按钮（页面右侧居中） ========== */
.floating-tts-btn {
    position: fixed;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 999;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 20px;
    background: rgba(15,23,42,0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: #e2e8f0;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
    white-space: nowrap;
    box-shadow: 0 2px 12px rgba(0,0,0,0.3), 0 0 0 1px rgba(99,102,241,0.15);
}
.floating-tts-btn:hover {
    background: rgba(30,41,59,0.92);
    border-color: rgba(99,102,241,0.4);
    color: #f1f5f9;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4), 0 0 0 1px rgba(99,102,241,0.3);
    transform: translateY(-50%) scale(1.03);
}
.floating-tts-btn:active {
    transform: translateY(-50%) scale(0.97);
}
.floating-tts-btn.playing {
    border-color: rgba(129,140,248,0.5);
    box-shadow: 0 0 0 2px rgba(99,102,241,0.2);
}

/* 按钮内声波动画 */
.floating-tts-btn .tts-wave {
    display: flex;
    align-items: center;
    gap: 2px;
    height: 16px;
}
.floating-tts-btn .tts-wave span {
    display: block;
    width: 2px;
    background: #818cf8;
    border-radius: 1px;
    animation: ttsWaveAnim 0.8s ease-in-out infinite;
}
.floating-tts-btn .tts-wave span:nth-child(1) { height: 6px;  animation-delay: 0s; }
.floating-tts-btn .tts-wave span:nth-child(2) { height: 10px; animation-delay: 0.15s; }
.floating-tts-btn .tts-wave span:nth-child(3) { height: 14px; animation-delay: 0.3s; }
.floating-tts-btn .tts-wave span:nth-child(4) { height: 10px; animation-delay: 0.15s; }
.floating-tts-btn .tts-wave span:nth-child(5) { height: 6px;  animation-delay: 0s; }

@keyframes ttsWaveAnim {
    0%, 100% { transform: scaleY(0.5); opacity: 0.5; }
    50%      { transform: scaleY(1.2); opacity: 1; }
}

/* 隐藏状态 */
.floating-tts-btn-hidden {
    display: none !important;
}

/* 移动端适配 */
@media (max-width: 768px) {
    .floating-tts-btn {
        right: 10px;
        padding: 7px 12px;
        font-size: 12px;
        gap: 5px;
        border-radius: 18px;
    }
    .floating-tts-btn .tts-wave { height: 14px; }
}
