/* ============================================================
 * AI Chat Widget - lexicx.net
 * 主色: #1d2088 | 辅色: #24aaff | 圆角卡片风格
 * ============================================================ */

/* --- 聊天气泡按钮 --- */
.ai-chat-bubble {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #1d2088;
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(29, 32, 136, 0.35);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.ai-chat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(29, 32, 136, 0.45);
}
.ai-chat-bubble svg {
    width: 28px;
    height: 28px;
    fill: #fff;
}
.ai-chat-bubble.active {
    display: none;
}

/* --- 聊天窗口 --- */
.ai-chat-window {
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 380px;
    height: 520px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    z-index: 99999;
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
}
.ai-chat-window.open {
    display: flex;
}

/* --- 标题栏 --- */
.ai-chat-header {
    background: #1d2088;
    color: #fff;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.ai-chat-header-title {
    font-size: 15px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}
.ai-chat-header-title .dot {
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
    display: inline-block;
}
.ai-chat-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s;
}
.ai-chat-close:hover {
    opacity: 1;
}

/* --- 消息区域 --- */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f7f8fa;
}
.ai-chat-messages::-webkit-scrollbar {
    width: 4px;
}
.ai-chat-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 2px;
}

/* --- 消息气泡 --- */
.ai-chat-msg {
    display: flex;
    gap: 10px;
    max-width: 85%;
    animation: ai-chat-fadeIn 0.25s ease;
}
.ai-chat-msg.ai {
    align-self: flex-start;
}
.ai-chat-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.ai-chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}
.ai-chat-msg.ai .ai-chat-avatar {
    background: #1d2088;
    color: #fff;
}
.ai-chat-msg.user .ai-chat-avatar {
    background: #e8eaf6;
    color: #1d2088;
}

.ai-chat-text {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
}
.ai-chat-msg.ai .ai-chat-text {
    background: #fff;
    color: #333;
    border: 1px solid #e8eaf6;
    border-top-left-radius: 4px;
}
.ai-chat-msg.user .ai-chat-text {
    background: #1d2088;
    color: #fff;
    border-top-right-radius: 4px;
    white-space: pre-wrap;
}

/* --- 输入区域 --- */
.ai-chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 8px;
    background: #fff;
    flex-shrink: 0;
}
.ai-chat-input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 9px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}
.ai-chat-input:focus {
    border-color: #1d2088;
}
.ai-chat-input:disabled {
    background: #f5f5f5;
    cursor: not-allowed;
}
.ai-chat-send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #1d2088;
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, opacity 0.2s;
    flex-shrink: 0;
}
.ai-chat-send:hover {
    background: #24aaff;
}
.ai-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #1d2088;
}
.ai-chat-send svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

/* --- 正在输入动画 --- */
.ai-chat-typing {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    background: #fff;
    border-radius: 12px;
    border: 1px solid #e8eaf6;
    border-top-left-radius: 4px;
    align-self: flex-start;
}
.ai-chat-typing span {
    width: 6px;
    height: 6px;
    background: #1d2088;
    border-radius: 50%;
    animation: ai-chat-bounce 1.2s infinite;
}
.ai-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-chat-typing span:nth-child(3) { animation-delay: 0.3s; }

/* --- 错误/重试提示 --- */
.ai-chat-error {
    font-size: 12px;
    color: #e53935;
    text-align: center;
    padding: 6px 0;
}
.ai-chat-retry {
    font-size: 12px;
    color: #1d2088;
    cursor: pointer;
    text-decoration: underline;
    background: none;
    border: none;
    padding: 2px 6px;
    font-family: inherit;
}
.ai-chat-retry:hover {
    color: #24aaff;
}

/* --- 转接通知 --- */
.ai-chat-notice {
    font-size: 12px;
    color: #888;
    text-align: center;
    padding: 8px 12px;
    margin: 4px 0;
    background: #f0f0f8;
    border-radius: 12px;
    align-self: center;
    max-width: 80%;
    animation: ai-chat-fadeIn 0.3s ease;
}

/* --- Sales 模式标题指示灯 --- */
.ai-chat-header-title .dot.sales {
    background: #facc15;
    box-shadow: 0 0 6px rgba(250, 204, 21, 0.6);
}

/* === Markdown 渲染样式（AI 消息内） === */

/* 段落 */
.ai-chat-msg.ai .ai-chat-text p {
    margin: 0 0 6px 0;
}
.ai-chat-msg.ai .ai-chat-text p:last-child {
    margin-bottom: 0;
}

/* 标题 */
.ai-chat-msg.ai .ai-chat-text h3,
.ai-chat-msg.ai .ai-chat-text h4,
.ai-chat-msg.ai .ai-chat-text h5,
.ai-chat-msg.ai .ai-chat-text h6 {
    margin: 8px 0 4px 0;
    font-weight: 600;
    line-height: 1.4;
}
.ai-chat-msg.ai .ai-chat-text h3 { font-size: 15px; color: #1d2088; }
.ai-chat-msg.ai .ai-chat-text h4 { font-size: 14px; color: #1d2088; }
.ai-chat-msg.ai .ai-chat-text h5 { font-size: 13px; color: #333; }
.ai-chat-msg.ai .ai-chat-text h6 { font-size: 13px; color: #666; }

/* 加粗 */
.ai-chat-msg.ai .ai-chat-text strong {
    font-weight: 600;
    color: #222;
}

/* 斜体 */
.ai-chat-msg.ai .ai-chat-text em {
    font-style: italic;
}

/* 链接 */
.ai-chat-msg.ai .ai-chat-text a {
    color: #24aaff;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s;
}
.ai-chat-msg.ai .ai-chat-text a:hover {
    border-bottom-color: #24aaff;
}

/* 列表 */
.ai-chat-msg.ai .ai-chat-text ul {
    margin: 4px 0;
    padding-left: 18px;
    list-style: disc;
}
.ai-chat-msg.ai .ai-chat-text li {
    margin: 2px 0;
}

/* 表格 */
.ai-chat-msg.ai .ai-chat-text table {
    width: 100%;
    border-collapse: collapse;
    margin: 6px 0;
    font-size: 12px;
}
.ai-chat-msg.ai .ai-chat-text th,
.ai-chat-msg.ai .ai-chat-text td {
    border: 1px solid #e0e0e0;
    padding: 5px 8px;
    text-align: left;
}
.ai-chat-msg.ai .ai-chat-text th {
    background: #f0f0f8;
    font-weight: 600;
    color: #1d2088;
}
.ai-chat-msg.ai .ai-chat-text td {
    background: #fff;
}

/* 行内代码 */
.ai-chat-msg.ai .ai-chat-text code {
    background: #f0f0f8;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 12px;
    font-family: 'SFMono-Regular', Consolas, monospace;
    color: #1d2088;
}

/* 引用 */
.ai-chat-msg.ai .ai-chat-text blockquote {
    margin: 4px 0;
    padding: 4px 10px;
    border-left: 3px solid #1d2088;
    background: #f7f8fa;
    color: #555;
    font-size: 13px;
}

/* 水平线 */
.ai-chat-msg.ai .ai-chat-text hr {
    border: none;
    border-top: 1px solid #e0e0e0;
    margin: 8px 0;
}

/* 换行 */
.ai-chat-msg.ai .ai-chat-text br {
    line-height: 0.5;
}

/* --- 动画 --- */
@keyframes ai-chat-fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes ai-chat-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* --- 移动端适配 --- */
@media (max-width: 768px) {
    .ai-chat-bubble {
        bottom: 20px;
        right: 20px;
        width: 50px;
        height: 50px;
    }
    .ai-chat-window {
        bottom: 0;
        right: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
    }
    .ai-chat-window.open {
        position: fixed;
        top: 0;
        left: 0;
    }
}
