/**
 * AI 全局浮窗助手样式（模块八）
 *
 * 设计要点：
 *   1. 右下角悬浮触发器，点击展开为右侧抽屉式面板（不遮挡主内容）
 *   2. 适配三角色（admin/partner_admin/sales）显示不同快捷功能入口
 *   3. 暗色 + 海茂蓝主色，与 trade-theme.css 颜色变量协同
 *   4. 响应式：移动端展开为全屏，桌面端固定 380px 宽
 *   5. 多轮对话气泡 + RAG 溯源标签 + 加载动画
 */

/* ============ 触发器（悬浮按钮） ============ */
.ai-assistant-trigger {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1e88e5 0%, #0d47a1 100%);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(13, 71, 161, 0.35);
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.ai-assistant-trigger:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 10px 28px rgba(13, 71, 161, 0.45);
}
.ai-assistant-trigger svg { width: 26px; height: 26px; }
.ai-assistant-trigger .ai-trigger-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ff5252;
    color: #fff;
    font-size: 11px;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    padding: 0 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
}

/* ============ 抽屉面板 ============ */
.ai-assistant-panel {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: 400px;
    max-width: 100vw;
    background: #fff;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
.ai-assistant-panel.open { transform: translateX(0); }
@media (max-width: 600px) {
    .ai-assistant-panel { width: 100vw; }
}

/* ============ 顶部 Header ============ */
.ai-assistant-header {
    background: linear-gradient(135deg, #1e88e5 0%, #0d47a1 100%);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.ai-assistant-title { font-size: 15px; font-weight: 600; }
.ai-assistant-subtitle { font-size: 12px; opacity: 0.85; margin-top: 2px; }
.ai-assistant-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.ai-assistant-close:hover { background: rgba(255, 255, 255, 0.28); }
.ai-assistant-close svg { width: 16px; height: 16px; }

/* ============ 快捷功能入口（场景化） ============ */
.ai-assistant-shortcuts {
    padding: 10px 12px 6px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    border-bottom: 1px solid #f0f0f0;
}
.ai-shortcut-btn {
    background: #f5f7fa;
    border: 1px solid #e8eaef;
    border-radius: 6px;
    padding: 8px 4px;
    font-size: 11px;
    color: #1e88e5;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}
.ai-shortcut-btn:hover {
    background: #e3f2fd;
    border-color: #1e88e5;
}
.ai-shortcut-btn svg { width: 16px; height: 16px; }

/* ============ 对话区 ============ */
.ai-assistant-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px;
    background: #f8f9fb;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.ai-msg {
    max-width: 88%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
}
.ai-msg-user {
    align-self: flex-end;
    background: #1e88e5;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.ai-msg-assistant {
    align-self: flex-start;
    background: #fff;
    color: #2c3e50;
    border: 1px solid #e8eaef;
    border-bottom-left-radius: 4px;
}
.ai-msg-system {
    align-self: center;
    background: #fff3e0;
    color: #e65100;
    font-size: 12px;
    padding: 4px 10px;
}
.ai-msg-rag-tag {
    display: inline-block;
    background: #e8f5e9;
    color: #2e7d32;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
    margin-top: 6px;
    margin-right: 4px;
}
.ai-msg-rag-tag::before { content: "📚 "; }

/* ============ 加载动画 ============ */
.ai-typing {
    align-self: flex-start;
    background: #fff;
    border: 1px solid #e8eaef;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    padding: 10px 14px;
    display: flex;
    gap: 4px;
}
.ai-typing span {
    width: 6px;
    height: 6px;
    background: #bdc3c7;
    border-radius: 50%;
    animation: ai-typing-bounce 1.2s infinite ease-in-out;
}
.ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes ai-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ============ 输入区 ============ */
.ai-assistant-input {
    border-top: 1px solid #f0f0f0;
    padding: 10px 12px;
    background: #fff;
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.ai-assistant-input textarea {
    flex: 1;
    border: 1px solid #e8eaef;
    border-radius: 18px;
    padding: 8px 14px;
    font-size: 13px;
    resize: none;
    min-height: 36px;
    max-height: 120px;
    outline: none;
    font-family: inherit;
    transition: border-color 0.2s;
}
.ai-assistant-input textarea:focus { border-color: #1e88e5; }
.ai-assistant-send {
    background: #1e88e5;
    border: none;
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}
.ai-assistant-send:hover:not(:disabled) { background: #1976d2; }
.ai-assistant-send:disabled { background: #bdc3c7; cursor: not-allowed; }
.ai-assistant-send svg { width: 18px; height: 18px; }

/* ============ 会话切换器 ============ */
.ai-assistant-conv-bar {
    padding: 6px 12px;
    background: #fff;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    gap: 6px;
    align-items: center;
    font-size: 12px;
}
.ai-conv-select {
    flex: 1;
    border: 1px solid #e8eaef;
    border-radius: 4px;
    padding: 4px 6px;
    font-size: 12px;
    background: #fff;
}
.ai-conv-new {
    background: #e3f2fd;
    border: 1px solid #1e88e5;
    color: #1e88e5;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 12px;
    cursor: pointer;
}

/* ============ 遮罩（移动端） ============ */
.ai-assistant-mask {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 9997;
    display: none;
}
.ai-assistant-mask.show { display: block; }
@media (min-width: 601px) {
    .ai-assistant-mask { display: none !important; }
}
