/**
 * AImate - AI智能客服样式
 */

/* 基础变量 */
:root {
    --ai-chatbot-primary: #2563eb;
    --ai-chatbot-primary-dark: #1d4ed8;
    --ai-chatbot-bg: #ffffff;
    --ai-chatbot-bg-dark: #1f2937;
    --ai-chatbot-text: #1f2937;
    --ai-chatbot-text-light: #6b7280;
    --ai-chatbot-border: #e5e7eb;
    --ai-chatbot-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    --ai-chatbot-radius: 12px;
    --ai-chatbot-user-bg: #2563eb;
    --ai-chatbot-assistant-bg: #f3f4f6;
}

/* 主容器 */
.ai-chatbot {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--ai-chatbot-text);
}

/* 浮动模式 */
.ai-chatbot-floating {
    position: fixed;
    z-index: 9999;
}

.ai-chatbot-floating .ai-chatbot-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ai-chatbot-primary), var(--ai-chatbot-primary-dark));
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(37, 99, 235, 0.4);
    transition: transform 0.3s, box-shadow 0.3s;
}

.ai-chatbot-floating .ai-chatbot-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(37, 99, 235, 0.5);
}

.ai-chatbot-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    background: #ef4444;
    color: white;
    font-size: 12px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}

/* 聊天窗口 */
.ai-chatbot-window {
    width: 390px;
    height: 560px;
    background: var(--ai-chatbot-bg);
    border-radius: 16px;
    box-shadow: var(--ai-chatbot-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity 0.3s, transform 0.3s;
    border: 1px solid rgba(226, 232, 240, .6);
}

.ai-chatbot-floating .ai-chatbot-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
}

.ai-chatbot-closed {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
}

/* 头部 */
.ai-chatbot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: linear-gradient(135deg, var(--ai-chatbot-primary), var(--ai-chatbot-primary-dark));
    color: white;
}

.ai-chatbot-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 16px;
}

.ai-chatbot-actions {
    display: flex;
    gap: 8px;
}

.ai-chatbot-actions button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.ai-chatbot-actions button:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* 消息区域 */
.ai-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #e9edf2;
}

/* 欢迎消息 */
.ai-chatbot-welcome {
    text-align: center;
    padding: 24px 16px;
    color: var(--ai-chatbot-text-light);
}

.ai-chatbot-welcome-icon {
    font-size: 42px;
    margin-bottom: 12px;
}

.ai-chatbot-welcome-text {
    font-size: 14px;
    line-height: 1.6;
    background: #fff;
    display: inline-block;
    padding: 12px 20px;
    border-radius: 14px;
    border: 1px solid #eef2f7;
    box-shadow: 0 1px 4px rgba(15, 23, 42, .05);
}

/* 消息行（头像 + 气泡） */
.ai-chatbot-msg-row {
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

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

.ai-chatbot-avatar {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #34d399, #059669);
    color: #fff;
    box-shadow: 0 2px 6px rgba(5, 150, 105, .3);
}

.ai-chatbot-avatar-user {
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    box-shadow: 0 2px 6px rgba(37, 99, 235, .3);
}

.ai-chatbot-msg-body {
    max-width: 82%;
    min-width: 0;
}

/* 消息气泡 */
.ai-chatbot-message {
    margin-bottom: 14px;
    animation: fadeIn 0.3s ease;
}

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

.ai-chatbot-message-content {
    padding: 10px 14px;
    border-radius: 16px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.65;
    box-shadow: 0 1px 3px rgba(15, 23, 42, .06);
}

.ai-chatbot-message-user .ai-chatbot-message-content {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;
}

.ai-chatbot-message-assistant .ai-chatbot-message-content {
    background: #ffffff;
    color: var(--ai-chatbot-text);
    border: 1px solid #e8edf3;
    border-bottom-left-radius: 4px;
}

.ai-chatbot-message-error .ai-chatbot-message-content {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

.ai-chatbot-message-system .ai-chatbot-message-content {
    background: #fef3c7;
    color: #92400e;
    text-align: center;
    margin: 0 auto;
    font-size: 13px;
}

/* 挂件内 Markdown 图文样式 */
.ai-chatbot-message-content.md-content img { max-width: 100%; border-radius: 8px; margin: 6px 0; }
.ai-chatbot-message-content.md-content table { border-collapse: collapse; margin: 6px 0; width: 100%; }
.ai-chatbot-message-content.md-content th, .ai-chatbot-message-content.md-content td { border: 1px solid #e2e8f0; padding: 4px 8px; font-size: 12.5px; }
.ai-chatbot-message-content.md-content code { background: rgba(15,23,42,.07); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.ai-chatbot-message-content.md-content pre { background: #1e293b; color: #e2e8f0; padding: 10px; border-radius: 8px; overflow-x: auto; }
.ai-chatbot-message-content.md-content pre code { background: none; color: inherit; padding: 0; }
.ai-chatbot-message-content.md-content blockquote { border-left: 3px solid #cbd5e1; margin: 6px 0; padding: 2px 10px; opacity: .85; }
.ai-chatbot-message-content.md-content p { margin: 0 0 6px; }
.ai-chatbot-message-content.md-content p:last-child { margin-bottom: 0; }
.ai-chatbot-message-content.md-content ul, .ai-chatbot-message-content.md-content ol { margin: 4px 0; padding-left: 18px; }
.ai-chatbot-message-content.md-content a { color: #2563eb; text-decoration: none; }
.ai-chatbot-message-user .ai-chatbot-message-content.md-content a { color: #bfdbfe; text-decoration: none; }

.ai-chatbot-message-time {
    font-size: 11px;
    color: var(--ai-chatbot-text-light);
    margin-top: 4px;
    padding: 0 4px;
}

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

/* 正在输入 */
.ai-chatbot-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--ai-chatbot-assistant-bg);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    animation: fadeIn 0.3s ease;
}

.ai-chatbot-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ai-chatbot-text-light);
    animation: typing 1.4s infinite ease-in-out;
}

.ai-chatbot-typing-dot:nth-child(1) { animation-delay: 0s; }
.ai-chatbot-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-chatbot-typing-dot:nth-child(3) { animation-delay: 0.4s; }

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

/* 输入区域 */
.ai-chatbot-input-area {
    display: flex;
    gap: 8px;
    padding: 16px;
    background: var(--ai-chatbot-bg);
    border-top: 1px solid var(--ai-chatbot-border);
}

.ai-chatbot-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--ai-chatbot-border);
    border-radius: 24px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.ai-chatbot-input:focus {
    border-color: var(--ai-chatbot-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.ai-chatbot-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ai-chatbot-primary), var(--ai-chatbot-primary-dark));
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

.ai-chatbot-send:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(37, 99, 235, 0.4);
}

/* 底部信息 */
.ai-chatbot-powered {
    text-align: center;
    padding: 8px;
    font-size: 11px;
    color: var(--ai-chatbot-text-light);
    background: var(--ai-chatbot-bg);
    border-top: 1px solid var(--ai-chatbot-border);
}

/* 暗色主题 */
.ai-chatbot-theme-dark {
    --ai-chatbot-bg: #1f2937;
    --ai-chatbot-text: #f9fafb;
    --ai-chatbot-text-light: #9ca3af;
    --ai-chatbot-border: #374151;
    --ai-chatbot-assistant-bg: #374151;
}

.ai-chatbot-theme-dark .ai-chatbot-messages {
    background: #111827;
}

.ai-chatbot-theme-dark .ai-chatbot-input {
    background: #374151;
    color: #f9fafb;
}

/* 响应式 */
@media (max-width: 480px) {
    .ai-chatbot-floating .ai-chatbot-window {
        width: 100vw;
        height: 100dvh;
        bottom: 0;
        right: 0;
        left: 0;
        border-radius: 0;
        border: none;
    }

    .ai-chatbot-floating .ai-chatbot-toggle {
        bottom: 14px;
        right: 14px;
    }

    /* 小屏字体加大（参考微信），16px 防止 iOS 聚焦自动放大 */
    .ai-chatbot-message-content { font-size: 16px; line-height: 1.6; padding: 10px 13px; }
    .ai-chatbot-message-content.md-content th,
    .ai-chatbot-message-content.md-content td { font-size: 14px; }
    .ai-chatbot-message-content.md-content code { font-size: 14px; }
    .ai-chatbot-message-time { font-size: 12px; }
    .ai-chatbot-input { font-size: 16px; }
    .ai-chatbot-welcome-text { font-size: 15px; }
    .ai-chatbot-msg-body { max-width: 84%; }
}

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

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

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

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