/* ============ 凡凡 全站悬浮窗 ============ */
#sa-fab {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 99999;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    user-select: none;
    -webkit-user-select: none;
}
#sa-fab.dragging { transition: none; }

/* 提示气泡 */
#sa-fab .sa-bubble {
    background: #fff;
    color: #333;
    border-radius: 14px;
    padding: 10px 14px;
    max-width: 220px;
    font-size: 0.85rem;
    line-height: 1.5;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.16);
    border: 1px solid rgba(0, 0, 0, 0.06);
    position: relative;
    animation: saBubbleIn 0.3s ease;
    cursor: pointer;
}
#sa-fab .sa-bubble::after {
    content: '';
    position: absolute;
    right: -7px;
    bottom: 16px;
    width: 0; height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: 8px solid #fff;
}
#sa-fab .sa-bubble .sa-b-close {
    position: absolute;
    top: -8px; right: -8px;
    width: 20px; height: 20px;
    border-radius: 50%;
    background: #c0c0c0;
    color: #fff;
    border: none;
    font-size: 11px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
#sa-fab .sa-bubble .sa-b-close:hover { background: #999; }
@keyframes saBubbleIn {
    from { opacity: 0; transform: translateY(8px) scale(0.95); }
    to { opacity: 1; transform: none; }
}

/* 精灵按钮 */
#sa-fab .sa-orb {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 10px 30px rgba(37, 99, 235, 0.35);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    border: 2px solid rgba(255, 255, 255, 0.9);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
    padding: 0;
}
#sa-fab .sa-orb .sa-orb-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    pointer-events: none;
}
#sa-fab .sa-orb:hover { transform: scale(1.06); box-shadow: 0 12px 36px rgba(37, 99, 235, 0.45); }
#sa-fab .sa-orb:active { transform: scale(0.96); }
#sa-fab .sa-orb .sa-orb-ring {
    position: absolute; inset: -6px;
    border-radius: 50%;
    border: 2px solid rgba(37, 99, 235, 0.3);
    animation: saRing 2.4s ease-out infinite;
    pointer-events: none;
}
@keyframes saRing {
    0% { transform: scale(0.9); opacity: 0.8; }
    100% { transform: scale(1.35); opacity: 0; }
}

/* 对话框 */
#sa-panel {
    position: fixed;
    right: 24px;
    bottom: 96px;
    z-index: 99999;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 140px);
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.08);
    animation: saPanelIn 0.25s ease;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}
@keyframes saPanelIn {
    from { opacity: 0; transform: translateY(16px) scale(0.97); }
    to { opacity: 1; transform: none; }
}

/* 头部 */
#sa-panel .sa-head {
    background: linear-gradient(135deg, #2563eb, #3b82f6 55%, #38bdf8);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
#sa-panel .sa-head .sa-avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.95);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    overflow: hidden;
}
#sa-panel .sa-head .sa-avatar-img {
    width: 100%; height: 100%;
    object-fit: cover;
    border-radius: 50%;
}
#sa-panel .sa-head .sa-h-title { font-weight: 700; font-size: 0.98rem; }
#sa-panel .sa-head .sa-h-sub { font-size: 0.72rem; opacity: 0.9; }
/* 头部操作按钮组：清除 + 收起，紧挨着 */
#sa-panel .sa-head .sa-head-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
#sa-panel .sa-head .sa-h-clear,
#sa-panel .sa-head .sa-h-close {
    background: rgba(255, 255, 255, 0.18);
    border: none;
    color: #fff;
    width: 28px; height: 28px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s ease;
    padding: 0;
}
/* 清除：悬停微红提示删除语义 */
#sa-panel .sa-head .sa-h-clear:hover { background: rgba(239, 68, 68, 0.4); }
#sa-panel .sa-head .sa-h-close:hover { background: rgba(255, 255, 255, 0.35); }

/* 消息区 */
#sa-panel .sa-msgs {
    flex: 1;
    overflow-y: auto;
    padding: 14px 14px 8px;
    background: #f7f8fc;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
#sa-panel .sa-msg { display: flex; gap: 8px; max-width: 88%; }
#sa-panel .sa-msg .sa-m-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: #fff;
    color: #fff;
    font-size: 14px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}
#sa-panel .sa-msg .sa-m-avatar img {
    width: 100%; height: 100%;
    object-fit: cover;
    border-radius: 50%;
}
#sa-panel .sa-msg.user { align-self: flex-end; flex-direction: row-reverse; }
#sa-panel .sa-msg.user .sa-m-avatar { background: linear-gradient(135deg, #4ade80, #22d3ee); }
#sa-panel .sa-msg .sa-m-body {
    background: #fff;
    border-radius: 14px;
    padding: 9px 12px;
    font-size: 0.87rem;
    line-height: 1.55;
    color: #333;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    word-break: break-word;
    min-width: 0;
}
#sa-panel .sa-msg.user .sa-m-body { background: #7c5cff; color: #fff; border-radius: 14px 14px 4px 14px; }
#sa-panel .sa-msg .sa-m-body p { margin: 0 0 6px; }
#sa-panel .sa-msg .sa-m-body p:last-child { margin-bottom: 0; }
#sa-panel .sa-msg .sa-m-body pre {
    background: #f1f3f7;
    border-radius: 8px;
    padding: 8px 10px;
    overflow-x: auto;
    font-size: 0.8rem;
    margin: 6px 0;
}
#sa-panel .sa-msg .sa-m-body code { background: #f1f3f7; border-radius: 4px; padding: 1px 4px; font-size: 0.82em; }
#sa-panel .sa-msg .sa-m-body ul, #sa-panel .sa-msg .sa-m-body ol { margin: 4px 0; padding-left: 18px; }
#sa-panel .sa-msg .sa-m-body li { margin: 2px 0; }
#sa-panel .sa-msg .sa-m-body strong { font-weight: 700; }
#sa-panel .sa-msg .sa-m-body a { color: #7c5cff; }
#sa-panel .sa-msg .sa-m-body table { border-collapse: collapse; margin: 6px 0; font-size: 0.8rem; }
#sa-panel .sa-msg .sa-m-body th, #sa-panel .sa-msg .sa-m-body td { border: 1px solid #ddd; padding: 4px 8px; }
#sa-panel .sa-msg .sa-m-body th { background: #f3f0ff; }

/* 助手思考/工具指示 */
#sa-panel .sa-tooltip {
    background: #eef0ff;
    color: #6d5bd0;
    border-radius: 10px;
    padding: 7px 11px;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 6px;
    animation: saBubbleIn 0.2s ease;
}
#sa-panel .sa-tooltip .sa-spin {
    width: 12px; height: 12px;
    border: 2px solid #c7bfff;
    border-top-color: #7c5cff;
    border-radius: 50%;
    animation: saSpin 0.8s linear infinite;
    flex-shrink: 0;
}
@keyframes saSpin { to { transform: rotate(360deg); } }
#sa-panel .sa-err-msg {
    background: #fff0f0;
    color: #d63031;
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 0.83rem;
}

/* 输入区 */
#sa-panel .sa-inputbar {
    padding: 10px 12px 12px;
    background: #fff;
    border-top: 1px solid #eee;
    flex-shrink: 0;
}
#sa-panel .sa-inputrow { display: flex; gap: 8px; align-items: flex-end; }
#sa-panel .sa-inputrow textarea {
    flex: 1;
    border: 1.5px solid #e2e6f0;
    border-radius: 12px;
    padding: 9px 12px;
    font-size: 0.87rem;
    resize: none;
    outline: none;
    font-family: inherit;
    max-height: 96px;
    line-height: 1.45;
    min-height: 38px;
    box-sizing: border-box;
}
#sa-panel .sa-inputrow textarea:focus { border-color: #7c5cff; }
#sa-panel .sa-inputrow .sa-send {
    background: linear-gradient(135deg, #2563eb, #38bdf8);
    color: #fff;
    border: none;
    border-radius: 12px;
    width: 42px; height: 38px;
    cursor: pointer;
    font-size: 16px;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
}
#sa-panel .sa-inputrow .sa-send:hover { filter: brightness(1.08); }
#sa-panel .sa-inputrow .sa-send:disabled { opacity: 0.55; cursor: not-allowed; }
#sa-panel .sa-hint {
    font-size: 0.7rem;
    color: #aaa;
    text-align: center;
    margin-top: 6px;
}
#sa-panel .sa-stopbar { display: flex; justify-content: center; padding-bottom: 6px; }
#sa-panel .sa-stopbar button {
    background: #fff;
    border: 1.5px solid #e2e6f0;
    color: #666;
    border-radius: 10px;
    padding: 5px 14px;
    font-size: 0.8rem;
    cursor: pointer;
}
#sa-panel .sa-stopbar button:hover { border-color: #d63031; color: #d63031; }

/* 移动端 */
@media (max-width: 640px) {
    #sa-panel {
        right: 8px;
        left: 8px;
        width: auto;
        bottom: 84px;
        height: calc(100vh - 110px);
        max-height: none;
        border-radius: 16px;
    }
    #sa-fab .sa-orb { width: 54px; height: 54px; font-size: 25px; }
    #sa-fab .sa-bubble { max-width: 180px; font-size: 0.8rem; }
    #sa-fab { right: 14px; bottom: 14px; }
}

/* 自动操作：目标元素高亮反馈 */
.sa-auto-flash {
    outline: 3px solid #ff6b35 !important;
    outline-offset: 2px !important;
    animation: sa-flash-ring 0.9s ease-in-out 3;
    border-radius: 4px;
}
@keyframes sa-flash-ring {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 107, 53, 0.5); }
    50% { box-shadow: 0 0 0 10px rgba(255, 107, 53, 0); }
}

/* ============ 贴边吸附：拖到屏幕边缘 → 缩成小条；悬停 → 展开 ============ */
#sa-fab {
    transition: left 0.22s ease, right 0.22s ease, top 0.22s ease, bottom 0.22s ease;
}
#sa-fab.dragging { transition: none; }

/* 贴边时隐藏气泡 */
#sa-fab.sa-docked .sa-bubble { display: none !important; }

/* orb 移出屏幕，只露 14px 小条（transform 由 transition 平滑过渡） */
#sa-fab.sa-dock-left .sa-orb {
    transform: translateX(calc(-100% + 14px));
}
#sa-fab.sa-dock-right .sa-orb {
    transform: translateX(calc(100% - 14px));
}
#sa-fab.sa-dock-top .sa-orb {
    transform: translateY(calc(-100% + 14px));
}
#sa-fab.sa-dock-bottom .sa-orb {
    transform: translateY(calc(100% - 14px));
}

/* 悬停展开：鼠标移入 → orb 平滑滑回视口 */
#sa-fab.sa-dock-left:hover .sa-orb,
#sa-fab.sa-dock-left.sa-dock-open .sa-orb {
    transform: translateX(0) scale(1.05);
}
#sa-fab.sa-dock-right:hover .sa-orb,
#sa-fab.sa-dock-right.sa-dock-open .sa-orb {
    transform: translateX(0) scale(1.05);
}
#sa-fab.sa-dock-top:hover .sa-orb,
#sa-fab.sa-dock-top.sa-dock-open .sa-orb {
    transform: translateY(0) scale(1.05);
}
#sa-fab.sa-dock-bottom:hover .sa-orb,
#sa-fab.sa-dock-bottom.sa-dock-open .sa-orb {
    transform: translateY(0) scale(1.05);
}

/* 贴边小条本身也有一点悬停反馈 */
#sa-fab.sa-docked .sa-orb { box-shadow: 0 6px 18px rgba(37, 99, 235, 0.4); }

/* ============ 思考中显示块（等待时实时展示思考过程，思考完隐藏） ============ */
.sa-thinking {
    margin: 6px 0;
    padding: 8px 10px;
    background: rgba(124, 92, 255, 0.07);
    border-left: 3px solid #7c5cff;
    border-radius: 6px;
}
.sa-thinking-head {
    font-size: 0.75rem;
    color: #7c5cff;
    margin-bottom: 4px;
    font-weight: 600;
}
.sa-thinking-body {
    font-size: 0.8rem;
    color: #8a8f9d;
    max-height: 120px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
    line-height: 1.45;
}
.sa-thinking-done {
    background: rgba(124, 92, 255, 0.04);
    border-left-color: rgba(124, 92, 255, 0.4);
}
.sa-thinking-done .sa-thinking-body { max-height: none; }

/* 站内相对路径链接（模型输出 [文字](/flasher) 之类） */
.sa-link-rel {
    color: #2563eb;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}
.sa-link-rel:hover { color: #1d4ed8; }
