/**
 * AI健康助手前端样式
 * 包含助手按钮和对话窗口的所有样式
 */

/* AI助手悬浮按钮 - 优化版本（上下布局，AI助手在上方，增加间距避免误触） */
.ai-assistant-button {
    position: fixed;
    bottom: 130px; /* 增加间距，从110px改为130px，避免误触 */
    right: 30px; /* 与返回顶部按钮垂直对齐 */
    width: 70px;
    height: 70px;
    background: linear-gradient(135deg, #28a745, #20c997);
    border-radius: 50%;
    box-shadow: 0 6px 25px rgba(40, 167, 69, 0.5), 0 0 0 0 rgba(40, 167, 69, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    transition: all 0.3s ease;
    animation: ai-button-pulse 2.5s infinite;
}

.ai-assistant-button:hover {
    transform: scale(1.15) translateY(-3px);
    box-shadow: 0 10px 35px rgba(40, 167, 69, 0.7), 0 0 0 8px rgba(40, 167, 69, 0.2);
}

.ai-assistant-button svg {
    width: 36px;
    height: 36px;
    color: white;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.ai-assistant-button::before {
    content: '';
    position: absolute;
    top: -5px;
    right: -5px;
    width: 20px;
    height: 20px;
    background: #ff4444;
    border-radius: 50%;
    border: 3px solid white;
    opacity: 0;
    animation: notification-appear 0.3s ease;
}

.ai-assistant-button.has-badge::before {
    opacity: 1;
}

/* 按钮脉冲动画 - 增强版 */
@keyframes ai-button-pulse {
    0%, 100% {
        box-shadow: 0 6px 25px rgba(40, 167, 69, 0.5), 0 0 0 0 rgba(40, 167, 69, 0.4);
    }
    50% {
        box-shadow: 0 8px 35px rgba(40, 167, 69, 0.7), 0 0 0 15px rgba(40, 167, 69, 0.1);
    }
}

@keyframes notification-appear {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* 新消息提示 */
.ai-assistant-button .notification-badge {
    position: absolute;
    top: 0;
    right: 0;
    width: 20px;
    height: 20px;
    background: #dc3545;
    border-radius: 50%;
    border: 2px solid white;
    display: none;
}

.ai-assistant-button.has-notification .notification-badge {
    display: block;
    animation: notification-bounce 0.5s;
}

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

/* AI助手对话窗口 */
.ai-chat-window {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 400px;
    height: 600px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    display: none;
    flex-direction: column;
    z-index: 1000;
    overflow: hidden;
    animation: slide-up 0.3s ease;
}

.ai-chat-window.show {
    display: flex;
}

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

/* 窗口头部 */
.ai-chat-header {
    background: linear-gradient(135deg, #28a745, #20c997);
    color: white;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.ai-chat-avatar {
    width: 40px;
    height: 40px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chat-avatar svg {
    width: 24px;
    height: 24px;
    color: #28a745;
}

.ai-chat-header-info h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.ai-chat-header-info p {
    margin: 0;
    font-size: 12px;
    opacity: 0.9;
}

.ai-chat-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 8px; /* 增加内边距，扩大点击区域 */
    border-radius: 50%;
    transition: background 0.3s;
    /* 确保按钮可点击 */
    position: relative;
    z-index: 10;
    /* 移动端优化：增加最小触摸区域 */
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    /* 防止事件穿透 */
    pointer-events: auto;
}

.ai-chat-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.ai-chat-close:active {
    background: rgba(255, 255, 255, 0.3); /* 移动端点击反馈 */
}

.ai-chat-close svg {
    width: 24px;
    height: 24px;
    /* 防止SVG阻止点击事件 */
    pointer-events: none;
}

/* 消息区域 */
.ai-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f8f9fa;
}

.ai-chat-message {
    margin-bottom: 15px;
    display: flex;
    gap: 10px;
    animation: message-fade-in 0.3s ease;
}

@keyframes message-fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-chat-message.user {
    flex-direction: row-reverse;
}

.ai-chat-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.ai-chat-message.ai .ai-chat-message-avatar {
    background: linear-gradient(135deg, #28a745, #20c997);
    color: white;
}

.ai-chat-message.user .ai-chat-message-avatar {
    background: #007bff;
    color: white;
}

.ai-chat-message-content {
    max-width: 70%;
}

.ai-chat-message-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    line-height: 1.5;
    font-size: 14px;
}

.ai-chat-message.ai .ai-chat-message-bubble {
    background: white;
    color: #212529;
    border-bottom-left-radius: 4px;
}

.ai-chat-message.user .ai-chat-message-bubble {
    background: #28a745;
    color: white;
    border-bottom-right-radius: 4px;
}

.ai-chat-message-time {
    font-size: 11px;
    color: #6c757d;
    margin-top: 4px;
    padding: 0 8px;
}

.ai-chat-message.user .ai-chat-message-time {
    text-align: right;
}

/* 输入状态提示 */
.ai-typing-indicator {
    display: none;
    padding: 12px 16px;
    background: white;
    border-radius: 18px;
    width: fit-content;
    margin-bottom: 15px;
}

.ai-typing-indicator.show {
    display: block;
    animation: message-fade-in 0.3s ease;
}

.ai-typing-dots {
    display: flex;
    gap: 4px;
}

.ai-typing-dot {
    width: 8px;
    height: 8px;
    background: #28a745;
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite;
}

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

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

@keyframes typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

/* 输入区域 */
.ai-chat-input-area {
    padding: 15px 20px;
    background: white;
    border-top: 1px solid #e9ecef;
}

.ai-chat-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.ai-chat-input {
    flex: 1;
    padding: 10px 15px;
    border: 1px solid #ced4da;
    border-radius: 20px;
    font-size: 16px; /* 从14px改为16px，防止iOS自动缩放 */
    resize: none;
    max-height: 100px;
    font-family: inherit;
    transition: border-color 0.3s;
    /* 防止移动端自动缩放 */
    -webkit-text-size-adjust: 100%;
    touch-action: manipulation;
}

.ai-chat-input:focus {
    outline: none;
    border-color: #28a745;
}

.ai-chat-send-button {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #28a745, #20c997);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s, opacity 0.3s;
}

.ai-chat-send-button:hover:not(:disabled) {
    transform: scale(1.1);
}

.ai-chat-send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-chat-send-button svg {
    width: 20px;
    height: 20px;
}

/* 快捷问题 */
.ai-quick-questions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 15px;
}

.ai-quick-question {
    padding: 8px 12px;
    background: white;
    border: 1px solid #28a745;
    color: #28a745;
    border-radius: 16px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s;
}

.ai-quick-question:hover {
    background: #28a745;
    color: white;
}

/* 错误提示 */
.ai-error-message {
    padding: 12px 16px;
    background: #f8d7da;
    color: #721c24;
    border-radius: 12px;
    font-size: 14px;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-error-message svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .ai-chat-window {
        width: calc(100vw - 20px);
        /* 增加移动端窗口高度，确保内容完整显示 */
        max-height: 70vh;
        height: 70vh;
        right: 10px;
        left: 10px;
        bottom: 20px;
        margin: 0 auto;
        /* 移除 display: flex，避免覆盖基础的 display: none */
        /* display 和 flex-direction 由基础样式和 .show 类控制 */
    }
    
    /* 键盘弹出时调整窗口高度，避免被键盘遮挡 */
    .ai-chat-window.keyboard-active {
        bottom: 10px;
        height: 50vh;
        max-height: 50vh;
    }
    
    .ai-assistant-button {
        right: 15px; /* 移动端：与返回顶部按钮垂直对齐 */
        bottom: 110px; /* 移动端：增加间距，从90px改为110px，避免误触 */
        width: 60px;
        height: 60px;
    }
    
    .ai-assistant-button svg {
        width: 30px;
        height: 30px;
    }
    
    /* 移动端关闭按钮优化 */
    .ai-chat-close {
        padding: 12px; /* 增加触摸区域 */
        min-width: 48px; /* iOS建议最小触摸目标 44x44pt */
        min-height: 48px;
        margin: -4px; /* 负边距补偿，不影响布局 */
    }
    
    .ai-chat-close svg {
        width: 28px; /* 移动端图标稍大 */
        height: 28px;
    }
    
    /* 移动端头部优化 */
    .ai-chat-header {
        padding: 16px; /* 稍微减小padding，给关闭按钮更多空间 */
    }
}

/* 滚动条样式 */
.ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

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

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #218838;
}

/* 加载动画 */
.ai-loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #28a745;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

