/* ===== AI 助手聊天窗（右下角悬浮） =====
   使用固定配色，不依赖站点主题变量，保证任何主题下文字与背景都有对比度。
   深色主题（html[data-theme="dark"]）有专门的覆盖。 */

.ai-chat {
    font-family: inherit;
    color-scheme: light;
}

/* 悬浮按钮 */
.ai-chat-fab {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 1000;
    width: 56px;
    height: 56px;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    background: #2563eb;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.2s;
}
.ai-chat-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}
.ai-chat-fab svg {
    width: 26px;
    height: 26px;
}
.ai-chat-fab .ai-chat-fab-close {
    display: none;
}
.ai-chat-fab.open .ai-chat-fab-open {
    display: none;
}
.ai-chat-fab.open .ai-chat-fab-close {
    display: block;
}

/* 聊天面板 */
.ai-chat-panel {
    position: fixed;
    right: 22px;
    bottom: 90px;
    z-index: 999;
    width: min(380px, calc(100vw - 32px));
    height: min(560px, calc(100vh - 150px));
    display: none;
    flex-direction: column;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 18px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    overflow: hidden;
}
.ai-chat-panel.open {
    display: flex;
    animation: ai-chat-in 0.25s cubic-bezier(0.25, 1, 0.5, 1);
}
@keyframes ai-chat-in {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* 头部 */
.ai-chat-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid #e5e7eb;
    background: #f8fafc;
}
.ai-chat-title {
    font-weight: 700;
    color: #111827;
    display: flex;
    align-items: center;
    gap: 8px;
}
.ai-chat-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
}
.ai-chat-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}
.ai-chat-actions button {
    border: 0;
    background: transparent;
    color: #6b7280;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 4px 8px;
    border-radius: 8px;
    transition: color 0.15s, background 0.15s;
}
.ai-chat-actions button:hover {
    color: #111827;
    background: rgba(127, 127, 127, 0.12);
}
.ai-chat-close {
    font-size: 1.1rem !important;
    line-height: 1;
}

/* 消息区 */
.ai-chat-msgs {
    flex: 1;
    overflow-y: auto;
    padding: 14px 14px 6px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scrollbar-width: thin;
    background: #ffffff;
}
.ai-msg {
    max-width: 86%;
    padding: 9px 13px;
    border-radius: 14px;
    line-height: 1.65;
    font-size: 0.92rem;
    word-break: break-word;
    white-space: normal;
}
.ai-msg-user {
    align-self: flex-end;
    background: #2563eb;
    color: #ffffff;
    border-bottom-right-radius: 4px;
}
.ai-msg-assistant {
    align-self: flex-start;
    background: #f1f5f9;
    border: 1px solid #e5e7eb;
    color: #1f2937;
    border-bottom-left-radius: 4px;
}
.ai-msg code {
    background: rgba(0, 0, 0, 0.08);
    padding: 1px 5px;
    border-radius: 5px;
    font-size: 0.85em;
    color: #1f2937;
}
.ai-msg pre {
    background: rgba(0, 0, 0, 0.06);
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 8px 10px;
    overflow-x: auto;
    margin: 6px 0;
    font-size: 0.85em;
    line-height: 1.5;
    color: #1f2937;
}

/* 打字动画 */
.ai-typing {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 12px 14px;
}
.ai-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    animation: ai-typing-blink 1.2s infinite;
}
.ai-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-typing-blink {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30%           { opacity: 1;   transform: translateY(-3px); }
}

/* 参考来源 */
.ai-sources {
    align-self: flex-start;
    font-size: 0.75rem;
    color: #6b7280;
    padding: 0 4px;
}

/* 未登录提示后的登录链接 */
.ai-login-link {
    display: block;
    align-self: flex-start;
    font-size: 0.85rem;
    color: #2563eb;
    text-decoration: none;
    padding: 4px 6px;
    border-radius: 8px;
}
.ai-login-link:hover {
    text-decoration: underline;
}
[data-theme="dark"] .ai-login-link {
    color: #3b82f6;
}

/* 快捷问题 */
.ai-chat-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 14px 10px;
    border-top: 1px dashed #e5e7eb;
    background: #ffffff;
}
.ai-chat-chips.hidden {
    display: none;
}
.ai-chip {
    border: 1px solid #e5e7eb;
    background: #f8fafc;
    color: #475569;
    font-size: 0.8rem;
    padding: 5px 11px;
    border-radius: 9999px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}
.ai-chip:hover {
    border-color: #2563eb;
    color: #2563eb;
}

/* 输入区 */
.ai-chat-form {
    display: flex;
    gap: 8px;
    padding: 10px 14px 8px;
    border-top: 1px solid #e5e7eb;
    background: #ffffff;
}
.ai-chat-input {
    flex: 1;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    background: #ffffff;
    color: #111827;
    padding: 9px 12px;
    font-size: 0.92rem;
    outline: none;
    transition: border-color 0.15s;
}
.ai-chat-input:focus {
    border-color: #2563eb;
}
.ai-chat-input::placeholder {
    color: #9ca3af;
}
.ai-chat-send {
    border: 0;
    border-radius: 14px;
    background: #2563eb;
    color: #ffffff;
    padding: 0 16px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
}
.ai-chat-send:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}
.ai-chat-tip {
    margin: 0;
    padding: 0 14px 10px;
    font-size: 0.72rem;
    color: #94a3b8;
    text-align: center;
    background: #ffffff;
}

/* ===== 深色主题覆盖（站点深色模式时生效） ===== */
[data-theme="dark"] .ai-chat-panel {
    background: #0f172a;
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}
[data-theme="dark"] .ai-chat-head {
    background: #1e293b;
    border-bottom-color: rgba(255, 255, 255, 0.08);
}
[data-theme="dark"] .ai-chat-title {
    color: #f8fafc;
}
[data-theme="dark"] .ai-chat-actions button {
    color: #94a3b8;
}
[data-theme="dark"] .ai-chat-actions button:hover {
    color: #f8fafc;
    background: rgba(255, 255, 255, 0.1);
}
[data-theme="dark"] .ai-chat-msgs {
    background: #0f172a;
}
[data-theme="dark"] .ai-msg-assistant {
    background: #1e293b;
    border-color: rgba(255, 255, 255, 0.08);
    color: #e2e8f0;
}
[data-theme="dark"] .ai-msg code {
    background: rgba(255, 255, 255, 0.12);
    color: #e2e8f0;
}
[data-theme="dark"] .ai-msg pre {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
    color: #e2e8f0;
}
[data-theme="dark"] .ai-sources {
    color: #94a3b8;
}
[data-theme="dark"] .ai-chat-chips {
    border-top-color: rgba(255, 255, 255, 0.1);
    background: #0f172a;
}
[data-theme="dark"] .ai-chip {
    border-color: rgba(255, 255, 255, 0.12);
    background: #1e293b;
    color: #cbd5e1;
}
[data-theme="dark"] .ai-chip:hover {
    border-color: #3b82f6;
    color: #3b82f6;
}
[data-theme="dark"] .ai-chat-form {
    border-top-color: rgba(255, 255, 255, 0.1);
    background: #0f172a;
}
[data-theme="dark"] .ai-chat-input {
    border-color: rgba(255, 255, 255, 0.12);
    background: #1e293b;
    color: #f8fafc;
}
[data-theme="dark"] .ai-chat-input::placeholder {
    color: #64748b;
}
[data-theme="dark"] .ai-chat-tip {
    color: #64748b;
    background: #0f172a;
}

/* 移动端适配 */
@media (max-width: 620px) {
    .ai-chat-fab {
        right: 14px;
        bottom: 14px;
    }
    .ai-chat-panel {
        right: 14px;
        bottom: 78px;
        width: calc(100vw - 28px);
    }
}
