/* 聊天小部件主容器 - 修复移动端定位问题 */
#simple-ai-chat-widget {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 9999;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* 聊天泡泡（悬浮按钮） */
#simple-ai-chat-bubble {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    position: relative;
    margin: 0;
    padding: 0;
}

#simple-ai-chat-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

#simple-ai-chat-bubble svg {
    width: 28px;
    height: 28px;
    fill: white;
}

.chat-status-indicator {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 12px;
    height: 12px;
    background-color: #10B981;
    border: 2px solid white;
    border-radius: 50%;
    z-index: 1;
}

/* 聊天框 - 修复移动端定位 */
#simple-ai-chat-box {
    position: fixed; /* 改为fixed定位 */
    bottom: 80px; /* 距离底部80px，在按钮上方 */
    right: 0;
    width: 380px;
    height: 500px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    display: none;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box;
    z-index: 10000;
    margin: 0;
    padding: 0;
    /* 防止超出屏幕 */
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 100px);
}

/* 确保显示状态正确 */
#simple-ai-chat-box.default-open,
#simple-ai-chat-box.show {
    display: flex !important;
}

/* 聊天头部 */
#simple-ai-chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    box-sizing: border-box;
}

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

.chat-status-dot {
    width: 8px;
    height: 8px;
    background-color: #10B981;
    border-radius: 50%;
}

#simple-ai-status-indicator {
    font-size: 12px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 12px;
    background-color: rgba(255, 255, 255, 0.2);
}

#simple-ai-close-chat {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* 消息区域 */
#simple-ai-chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: #f8fafc;
    box-sizing: border-box;
    min-height: 0; /* 允许flex子项收缩 */
    -webkit-overflow-scrolling: touch; /* iOS滚动优化 */
    overscroll-behavior: contain; /* 防止滚动传播 */
}

.message-wrapper {
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
    width: 100%;
    box-sizing: border-box;
}

.message-wrapper.align-self-end {
    align-items: flex-end;
}

.message-wrapper.align-self-start {
    align-items: flex-start;
}

.message-header {
    font-size: 12px;
    color: #64748b;
    margin-bottom: 4px;
    padding-left: 12px;
}

.message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    line-height: 1.5;
    word-wrap: break-word;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    position: relative;
    box-sizing: border-box;
    word-break: break-word; /* 长单词换行 */
}

.user-message {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.ai-message {
    background: white;
    color: #334155;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
}

.human-message {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    border-bottom-left-radius: 4px;
}

.system-message {
    background: #f1f5f9;
    color: #64748b;
    border: 1px solid #cbd5e1;
}

.message-timestamp {
    font-size: 10px;
    opacity: 0.7;
    margin-top: 4px;
    text-align: right;
}

/* 输入区域 */
#simple-ai-chat-input-area {
    padding: 16px;
    background: white;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    box-sizing: border-box;
}

#simple-ai-user-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 20px;
    resize: none;
    outline: none;
    font-family: inherit;
    font-size: 14px;
    max-height: 100px;
    min-height: 44px; /* 触摸友好高度 */
    transition: border-color 0.3s ease;
    box-sizing: border-box;
    -webkit-appearance: none; /* 移除iOS默认样式 */
    appearance: none;
}

#simple-ai-user-input:focus {
    border-color: #667eea;
}

#simple-ai-send-button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 12px 20px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
    flex-shrink: 0;
    min-height: 44px; /* 触摸友好高度 */
    min-width: 44px; /* 触摸友好宽度 */
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}

#simple-ai-send-button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

#simple-ai-send-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* 打字指示器 */
.typing-indicator {
    align-self: flex-start;
    padding: 8px 12px;
    background: white;
    border-radius: 20px;
    border: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    gap: 4px;
    box-sizing: border-box;
}

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

.typing-dots span {
    width: 6px;
    height: 6px;
    background: #64748b;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) {
    animation-delay: 0s;
}

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

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

/* 动画 */
@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-5px);
    }
}

.animate-message {
    animation: slideIn 0.3s ease-out;
}

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

.shake {
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    25% {
        transform: translateX(-5px);
    }
    75% {
        transform: translateX(5px);
    }
}
/* ==================== 移动端修复 ==================== */

/* 通用移动端调整 */
@media (max-width: 768px) {
    #simple-ai-chat-widget {
        bottom: max(16px, env(safe-area-inset-bottom, 16px));
        right: max(16px, env(safe-area-inset-right, 16px));
        left: auto;
    }
    
    #simple-ai-chat-box {
        position: fixed !important; /* 确保使用fixed定位 */
        bottom: calc(70px + env(safe-area-inset-bottom, 0px)); /* 在按钮上方 */
        left: 16px;
        right: 16px;
        width: calc(100vw - 32px) !important; /* 强制使用窗口宽度 */
        height: 70vh;
        max-height: 500px;
        margin: 0 auto;
        border-radius: 12px;
    }
    
    /* 安全区域支持 - 仅在移动端应用 */
    @supports (padding: max(0px)) {
        #simple-ai-chat-widget {
            bottom: max(16px, env(safe-area-inset-bottom, 16px));
            right: max(16px, env(safe-area-inset-right, 16px));
        }
        
        #simple-ai-chat-box {
            left: max(16px, env(safe-area-inset-left, 16px));
            right: max(16px, env(safe-area-inset-right, 16px));
            bottom: calc(70px + env(safe-area-inset-bottom, 0px));
            width: calc(100vw - max(16px, env(safe-area-inset-left, 16px)) - max(16px, env(safe-area-inset-right, 16px))) !important;
        }
    }
    
    .message {
        max-width: 85%;
    }
    
    #simple-ai-chat-bubble {
        width: 56px;
        height: 56px;
    }
    
    #simple-ai-chat-bubble svg {
        width: 24px;
        height: 24px;
    }
}

/* 小屏幕手机 */
@media (max-width: 480px) {
    #simple-ai-chat-box {
        width: calc(100vw - 32px) !important;
        height: 65vh;
        max-height: 450px;
        bottom: calc(65px + env(safe-area-inset-bottom, 0px));
        left: 16px;
        right: 16px;
    }
    
    #simple-ai-chat-widget {
        bottom: max(12px, env(safe-area-inset-bottom, 12px));
        right: max(12px, env(safe-area-inset-right, 12px));
    }
    
    /* 安全区域支持 - 仅在移动端应用 */
    @supports (padding: max(0px)) {
        #simple-ai-chat-box {
            left: max(12px, env(safe-area-inset-left, 12px));
            right: max(12px, env(safe-area-inset-right, 12px));
            width: calc(100vw - max(12px, env(safe-area-inset-left, 12px)) - max(12px, env(safe-area-inset-right, 12px))) !important;
        }
    }
    
    /* ... 其他样式保持不变 ... */
}

/* 超小屏幕手机 */
@media (max-width: 360px) {
    #simple-ai-chat-box {
        width: calc(100vw - 24px) !important;
        height: 60vh;
        max-height: 400px;
        bottom: calc(60px + env(safe-area-inset-bottom, 0px));
        left: 12px;
        right: 12px;
    }
    
    /* 安全区域支持 - 仅在移动端应用 */
    @supports (padding: max(0px)) {
        #simple-ai-chat-box {
            left: max(12px, env(safe-area-inset-left, 12px));
            right: max(12px, env(safe-area-inset-right, 12px));
            width: calc(100vw - max(12px, env(safe-area-inset-left, 12px)) - max(12px, env(safe-area-inset-right, 12px))) !important;
        }
    }
    
    /* ... 其他样式保持不变 ... */
}