/* ============================================================
   AI 助手全局悬浮球 + 对话小窗（可拖动、可调大小）
   引入方式：<link rel="stylesheet" href=".../ai-fab.css"> + <script src=".../ai-fab.js">
   依赖：jQuery、tenant.js（TenantApp）、marked.min.js、highlight.min.js（可选）
   ============================================================ */

/* 悬浮球 */
#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, #4A82F0 0%, #0A48E6 100%);
    box-shadow: 0 10px 28px rgba(46, 108, 236, .35);
    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(46, 108, 236, .42); }
#aiFab.dragging { cursor: grabbing; transform: scale(1.05); box-shadow: 0 16px 36px rgba(46, 108, 236, .42); 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: #fff; border-radius: 18px;
    box-shadow: 0 24px 64px rgba(15, 23, 42, .28);
    border: 1px solid #e7eaf0;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}
#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, #4A82F0 0%, #0A48E6 100%);
    color: #fff; cursor: move; user-select: none;
}
#aiFabPanel .aif-header .aif-logo {
    width: 30px; height: 30px; border-radius: 8px; background: #fff;
    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: #2E6CEC; 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: #f8f9fc;
}
#aiFabPanel .aif-empty {
    text-align: center; color: #a1a5ae; 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: #EEF3FF; border: 1px solid #DCE7FB;
}
#aiFabPanel .aif-login-logo img { width: 100%; height: 100%; object-fit: contain; }
#aiFabPanel .aif-login-logo i { font-size: 28px; color: #2E6CEC; }
#aiFabPanel .aif-login-title { font-size: 16px; font-weight: 650; color: #1F2329; margin-bottom: 8px; }
#aiFabPanel .aif-login-desc { font-size: 12.5px; color: #8A93A3; 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, #4A82F0 0%, #2E6CEC 100%);
    color: #fff; font-size: 14px; font-weight: 600; cursor: pointer;
    box-shadow: 0 8px 20px rgba(46,108,236,.28); 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(46,108,236,.36); }
#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, #4c86f6, #2458d8); color: #fff; font-size: 15px;
}
#aiFabPanel .aif-msg.user .aif-avatar { background: linear-gradient(145deg, #9aa8c0, #6b7a94); }
#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: #fff; border: 1px solid #eceff5; color: #2a2f38; border-top-left-radius: 4px; }
#aiFabPanel .aif-msg.user .aif-bubble { background: linear-gradient(135deg, #4A82F0, #0A48E6); 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; }
#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: #f4f7fb;
    border-left: 3px solid #c2d3f0; border-radius: 0 6px 6px 0; color: #4a5364;
}
#aiFabPanel .aif-bubble.markdown code {
    padding: 1px 5px; background: #eef0f3; color: #c7254e; border-radius: 4px; font-size: 12px;
}
#aiFabPanel .aif-bubble.markdown pre {
    margin: 6px 0; padding: 10px 12px; background: #f6f7f9; border: 1px solid #e7eaf0;
    border-radius: 8px; overflow-x: auto; font-size: 12px; line-height: 1.55;
}
#aiFabPanel .aif-bubble.markdown pre code { background: transparent; color: #383d47; 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 #e3e7ee; padding: 4px 8px; }
#aiFabPanel .aif-bubble.markdown th { background: #f4f7fb; }
#aiFabPanel .aif-bubble.markdown a { color: #2E6CEC; }
#aiFabPanel .aif-bubble.markdown hr { border: none; border-top: 1px solid #e7eaf0; margin: 8px 0; }

/* 本次消耗积分（操作栏行末小字，靠右，与按钮同行） */
#aiFabPanel .aif-points-info {
    margin-left: auto; padding-left: 8px; font-size: 11px; color: #b3b9c2; 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: #b3b9c2;
    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: #2E6CEC; background: #eef3fd; }
#aiFabPanel .aif-act.on { color: #2E6CEC; }
#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: #fff; border: 1px solid #e7eaf0; border-radius: 10px;
    box-shadow: 0 8px 24px rgba(31,42,61,.14); padding: 5px;
}
.aif-more-item {
    display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 7px;
    font-size: 13px; color: #454b57; cursor: pointer;
}
.aif-more-item:hover { background: #f4f7fb; color: #2E6CEC; }
.aif-more-item i { font-size: 15px; }

/* 打字光标 */
#aiFabPanel .aif-typing-dot::after {
    content: ''; display: inline-block; width: 2px; height: 13px;
    background: #2E6CEC; 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 #eceff5; padding: 10px 12px; background: #fff; }
/* 待发送图片预览区 */
#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 #eceff5; }
#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 #e3e7ee;
    border-radius: 10px; padding: 8px 10px; font-size: 13px; line-height: 1.5;
    font-family: inherit; outline: none; background: #fafbfd;
}
#aiFabPanel .aif-input:focus { border-color: #BFD0F7; background: #fff; }
#aiFabPanel .aif-send {
    flex: 0 0 auto; height: 36px; padding: 0 16px; border: none; border-radius: 10px;
    background: linear-gradient(135deg, #4A82F0, #0A48E6); 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 #c4cbd6; border-bottom: 2px solid #c4cbd6;
}

@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; }
}
