/* ============================================================
   AI 助手全局悬浮球 + 对话小窗（可拖动、可调大小）
   引入方式：<link rel="stylesheet" href=".../ai-fab.css"> + <script src=".../ai-fab.js">
   依赖：jQuery、tenant.js（TenantApp）、marked.min.js、highlight.min.js（可选）
   2026-09-29：全站暗紫主题统一（原蓝白配色 → 暗紫）
   ============================================================ */

/* 悬浮球 */
#aiFab {
    position: fixed; right: 28px; bottom: 100px; z-index: 2147483000;
    display: flex; align-items: center; gap: 8px;
    height: 52px; padding: 0 18px;
    border-radius: 26px;
    color: #fff; cursor: pointer;
    background: linear-gradient(135deg, #a855f7 0%, #7c3aed 100%);
    box-shadow: 0 10px 28px rgba(168, 85, 247, .38);
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
    transition: transform .2s ease, box-shadow .2s ease;
    user-select: none;
    touch-action: none;
}
#aiFab:hover { transform: translateY(-3px); box-shadow: 0 16px 36px rgba(168, 85, 247, .48); }
#aiFab.dragging { cursor: grabbing; transform: scale(1.05); box-shadow: 0 16px 36px rgba(168, 85, 247, .48); transition: none; }
#aiFab i { font-size: 22px; }
#aiFab .ai-fab-label { font-size: 14px; font-weight: 600; }

/* 对话小窗 */
#aiFabPanel {
    position: fixed; z-index: 2147483001;
    right: 28px; bottom: 170px;
    width: 460px; height: 640px; min-width: 360px; min-height: 460px;
    display: flex; flex-direction: column;
    background: #16102a; border-radius: 18px;
    box-shadow: 0 24px 64px rgba(4, 2, 10, .6);
    border: 1px solid rgba(168, 85, 247, .25);
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
    color-scheme: dark;
}
#aiFabPanel.hidden { display: none; }

/* 面板头部（可拖动区域） */
#aiFabPanel .aif-header {
    flex: 0 0 auto;
    display: flex; align-items: center; gap: 10px;
    padding: 12px 14px;
    background: linear-gradient(135deg, #a855f7 0%, #7c3aed 100%);
    color: #fff; cursor: move; user-select: none;
}
#aiFabPanel .aif-header .aif-logo {
    width: 30px; height: 30px; border-radius: 8px; background: rgba(255,255,255,.16);
    display: flex; align-items: center; justify-content: center; overflow: hidden;
}
#aiFabPanel .aif-header .aif-logo img { width: 100%; height: 100%; object-fit: contain; }
#aiFabPanel .aif-header .aif-logo i { color: #fff; font-size: 18px; }
#aiFabPanel .aif-header .aif-title { font-size: 15px; font-weight: 600; flex: 1; }
#aiFabPanel .aif-header .aif-close,
#aiFabPanel .aif-header .aif-clear {
    width: 26px; height: 26px; border-radius: 8px; border: none; background: rgba(255,255,255,.18);
    color: #fff; font-size: 15px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
#aiFabPanel .aif-header .aif-close:hover,
#aiFabPanel .aif-header .aif-clear:hover { background: rgba(255,255,255,.32); }

/* 消息列表 */
#aiFabPanel .aif-body {
    flex: 1 1 auto; overflow-y: auto; padding: 16px 14px;
    background: #120d22;
}
#aiFabPanel .aif-empty {
    text-align: center; color: #8b83a8; font-size: 13px; padding: 40px 0;
}
/* 未登录引导卡 */
#aiFabPanel .aif-login-tip { display: flex; flex-direction: column; align-items: center; gap: 0; padding: 48px 24px; }
#aiFabPanel .aif-login-logo {
    width: 58px; height: 58px; margin-bottom: 18px; border-radius: 16px;
    display: flex; align-items: center; justify-content: center; overflow: hidden;
    background: rgba(168, 85, 247, .12); border: 1px solid rgba(168, 85, 247, .3);
}
#aiFabPanel .aif-login-logo img { width: 100%; height: 100%; object-fit: contain; }
#aiFabPanel .aif-login-logo i { font-size: 28px; color: #c084fc; }
#aiFabPanel .aif-login-title { font-size: 16px; font-weight: 650; color: #f5f3ff; margin-bottom: 8px; }
#aiFabPanel .aif-login-desc { font-size: 12.5px; color: #b8b0d0; line-height: 1.6; margin-bottom: 22px; }
#aiFabPanel .aif-login-btn {
    height: 42px; padding: 0 32px; border: none; border-radius: 12px;
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    background: linear-gradient(135deg, #a855f7 0%, #7c3aed 100%);
    color: #fff; font-size: 14px; font-weight: 600; cursor: pointer;
    box-shadow: 0 8px 20px rgba(168,85,247,.3); transition: all .2s ease;
}
#aiFabPanel .aif-login-btn i { font-size: 16px; }
#aiFabPanel .aif-login-btn:hover { transform: translateY(-2px); box-shadow: 0 12px 26px rgba(168,85,247,.4); }
#aiFabPanel .aif-msg { display: flex; gap: 8px; margin-bottom: 14px; }
#aiFabPanel .aif-msg.user { flex-direction: row-reverse; }
#aiFabPanel .aif-avatar {
    width: 30px; height: 30px; border-radius: 50%; flex: 0 0 30px;
    display: flex; align-items: center; justify-content: center; overflow: hidden;
    background: linear-gradient(145deg, #c084fc, #a855f7); color: #fff; font-size: 15px;
}
#aiFabPanel .aif-msg.user .aif-avatar { background: linear-gradient(145deg, #6d6488, #4d4668); }
#aiFabPanel .aif-avatar img { width: 100%; height: 100%; object-fit: cover; }
#aiFabPanel .aif-bubble {
    max-width: 78%; padding: 9px 12px; border-radius: 12px;
    font-size: 13px; line-height: 1.65; word-break: break-word;
}
#aiFabPanel .aif-msg.ai .aif-bubble { background: rgba(40, 28, 70, .75); border: 1px solid rgba(168, 85, 247, .2); color: #e9e4f8; border-top-left-radius: 4px; }
#aiFabPanel .aif-msg.user .aif-bubble { background: linear-gradient(135deg, #a855f7, #7c3aed); color: #fff; border-top-right-radius: 4px; }

/* Markdown 渲染样式（精简） */
#aiFabPanel .aif-bubble.markdown { white-space: normal; }
#aiFabPanel .aif-bubble.markdown p { margin: 4px 0; }
#aiFabPanel .aif-bubble.markdown h1, #aiFabPanel .aif-bubble.markdown h2,
#aiFabPanel .aif-bubble.markdown h3, #aiFabPanel .aif-bubble.markdown h4 { font-weight: 700; margin: 10px 0 4px; line-height: 1.4; color: #f5f3ff; }
#aiFabPanel .aif-bubble.markdown h1 { font-size: 17px; }
#aiFabPanel .aif-bubble.markdown h2 { font-size: 16px; }
#aiFabPanel .aif-bubble.markdown h3 { font-size: 15px; }
#aiFabPanel .aif-bubble.markdown h4 { font-size: 14px; }
#aiFabPanel .aif-bubble.markdown strong { font-weight: 650; }
#aiFabPanel .aif-bubble.markdown ul, #aiFabPanel .aif-bubble.markdown ol { margin: 4px 0; padding-left: 20px; }
#aiFabPanel .aif-bubble.markdown li { margin: 2px 0; }
#aiFabPanel .aif-bubble.markdown blockquote {
    margin: 6px 0; padding: 6px 10px; background: rgba(168, 85, 247, .1);
    border-left: 3px solid rgba(168, 85, 247, .45); border-radius: 0 6px 6px 0; color: #c9c1e3;
}
#aiFabPanel .aif-bubble.markdown code {
    padding: 1px 5px; background: rgba(168, 85, 247, .16); color: #f0a8d0; border-radius: 4px; font-size: 12px;
}
#aiFabPanel .aif-bubble.markdown pre {
    margin: 6px 0; padding: 10px 12px; background: #0f0a1e; border: 1px solid rgba(168, 85, 247, .22);
    border-radius: 8px; overflow-x: auto; font-size: 12px; line-height: 1.55;
}
#aiFabPanel .aif-bubble.markdown pre code { background: transparent; color: #d8d2ee; padding: 0; }
#aiFabPanel .aif-bubble.markdown table { border-collapse: collapse; margin: 6px 0; font-size: 12px; }
#aiFabPanel .aif-bubble.markdown th, #aiFabPanel .aif-bubble.markdown td { border: 1px solid rgba(168, 85, 247, .22); padding: 4px 8px; }
#aiFabPanel .aif-bubble.markdown th { background: rgba(168, 85, 247, .12); }
#aiFabPanel .aif-bubble.markdown a { color: #c084fc; }
#aiFabPanel .aif-bubble.markdown hr { border: none; border-top: 1px solid rgba(168, 85, 247, .2); margin: 8px 0; }

/* 本次消耗积分（操作栏行末小字，靠右，与按钮同行） */
#aiFabPanel .aif-points-info {
    margin-left: auto; padding-left: 8px; font-size: 11px; color: #8b83a8; line-height: 1; white-space: nowrap;
    align-self: center;
}

/* 消息操作栏（重新生成/赞/踩/更多） */
#aiFabPanel .aif-actions { display: flex; gap: 2px; margin-top: 3px; }
#aiFabPanel .aif-actions-user { justify-content: flex-end; }
#aiFabPanel .aif-act {
    width: 24px; height: 24px; border: none; background: transparent; color: #8b83a8;
    font-size: 14px; cursor: pointer; border-radius: 6px; display: flex; align-items: center; justify-content: center;
    transition: color .15s, background .15s;
}
#aiFabPanel .aif-act:hover { color: #c084fc; background: rgba(168, 85, 247, .14); }
#aiFabPanel .aif-act.on { color: #c084fc; }
#aiFabPanel .aif-like.on i, #aiFabPanel .aif-dislike.on i { font-weight: 700; }

/* 更多菜单 */
.aif-more-menu {
    position: fixed; z-index: 2147483002; min-width: 110px;
    background: #1e1437; border: 1px solid rgba(168, 85, 247, .28); border-radius: 10px;
    box-shadow: 0 8px 24px rgba(4,2,10,.55); padding: 5px;
}
.aif-more-item {
    display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 7px;
    font-size: 13px; color: #d8d2ee; cursor: pointer;
}
.aif-more-item:hover { background: rgba(168, 85, 247, .14); color: #c084fc; }
.aif-more-item i { font-size: 15px; }

/* 打字光标 */
#aiFabPanel .aif-typing-dot::after {
    content: ''; display: inline-block; width: 2px; height: 13px;
    background: #c084fc; margin-left: 2px; vertical-align: -2px;
    animation: aifBlink 1s steps(1) infinite;
}
@keyframes aifBlink { 50% { opacity: 0; } }

/* 输入区 */
#aiFabPanel .aif-footer { flex: 0 0 auto; border-top: 1px solid rgba(168, 85, 247, .2); padding: 10px 12px; background: #16102a; }
/* 待发送图片预览区 */
#aiFabPanel .aif-attach { display: none; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
#aiFabPanel .aif-attach-item { position: relative; width: 56px; height: 56px; border-radius: 8px; overflow: hidden; }
#aiFabPanel .aif-attach-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
#aiFabPanel .aif-attach-del {
    position: absolute; top: 0; right: 0; width: 16px; height: 16px; line-height: 14px;
    text-align: center; background: rgba(0,0,0,.55); color: #fff; font-size: 12px; cursor: pointer;
    border-radius: 0 0 0 6px;
}
/* 消息内容容器（图片 + 气泡） */
#aiFabPanel .aif-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }
#aiFabPanel .aif-msg.ai .aif-main { align-items: flex-start; }
#aiFabPanel .aif-msg.user .aif-main { align-items: flex-end; }
#aiFabPanel .aif-msg-imgs { display: flex; flex-wrap: wrap; gap: 6px; }
#aiFabPanel .aif-msg-imgs img { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; display: block; border: 1px solid rgba(168, 85, 247, .22); }
#aiFabPanel .aif-main .aif-bubble { max-width: 100%; }
#aiFabPanel .aif-input-row { display: flex; gap: 8px; align-items: flex-end; }
#aiFabPanel .aif-input {
    flex: 1; min-height: 36px; max-height: 120px; resize: none; border: 1px solid rgba(168, 85, 247, .28);
    border-radius: 10px; padding: 8px 10px; font-size: 13px; line-height: 1.5;
    font-family: inherit; outline: none; background: #140e28; color: #f0edff;
}
#aiFabPanel .aif-input::placeholder { color: #7d759a; }
#aiFabPanel .aif-input:focus { border-color: #a855f7; background: #171133; box-shadow: 0 0 0 3px rgba(168, 85, 247, .16); }
#aiFabPanel .aif-send {
    flex: 0 0 auto; height: 36px; padding: 0 16px; border: none; border-radius: 10px;
    background: linear-gradient(135deg, #a855f7, #7c3aed); color: #fff;
    font-size: 13px; font-weight: 600; cursor: pointer;
}
#aiFabPanel .aif-send:disabled { opacity: .6; cursor: not-allowed; }

/* 调整大小手柄 */
#aiFabPanel .aif-resize {
    position: absolute; right: 0; bottom: 0; width: 18px; height: 18px; cursor: nwse-resize;
}
#aiFabPanel .aif-resize::after {
    content: ''; position: absolute; right: 4px; bottom: 4px;
    width: 8px; height: 8px; border-right: 2px solid rgba(192, 132, 252, .65); border-bottom: 2px solid rgba(192, 132, 252, .65);
}

@media (max-width: 680px) {
    #aiFab { right: 16px; bottom: 80px; height: 46px; padding: 0 14px; }
    #aiFab .ai-fab-label { display: none; }
    #aiFabPanel { width: calc(100vw - 24px); height: 62vh; min-width: 0; min-height: 0; left: 12px !important; right: 12px !important; }
}
