/* AI Plus Frontend Chat Widget */
#ai-plus-chat-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, #2271b1, #135e96);
    color: #fff;
    border-radius: 50%;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    z-index: 99998;
    transition: transform 0.2s;
}
#ai-plus-chat-btn:hover { transform: scale(1.1); }

#ai-plus-chat-window {
    position: fixed;
    bottom: 90px;
    right: 24px;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    z-index: 99999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ai-chat-header {
    background: linear-gradient(135deg, #2271b1, #135e96);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    font-weight: bold;
    font-size: 15px;
}

.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ai-chat-msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}
.ai-chat-msg.user {
    background: #2271b1;
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}
.ai-chat-msg.assistant {
    background: #f0f0f0;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.ai-chat-input {
    padding: 12px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 8px;
}
.ai-chat-input input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 24px;
    outline: none;
    font-size: 14px;
}
.ai-chat-input input:focus { border-color: #2271b1; }
.ai-chat-input button {
    background: #2271b1;
    color: #fff;
    border: none;
    padding: 10px 18px;
    border-radius: 24px;
    cursor: pointer;
    font-size: 14px;
}
.ai-chat-input button:hover { background: #135e96; }

/* 嵌入短代码样式 */
.ai-plus-embed-chat {
    border: 1px solid #ddd;
    border-radius: 12px;
    overflow: hidden;
    max-width: 600px;
}
.ai-plus-embed-chat .ai-chat-messages {
    min-height: 300px;
}

/* Markdown 渲染样式（浮窗 + 嵌入聊天） */
.ai-chat-msg.assistant strong { font-weight: 600; }
.ai-chat-msg.assistant code {
    background: rgba(0,0,0,0.08);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}
.ai-chat-msg.assistant pre {
    background: rgba(0,0,0,0.08);
    padding: 10px;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 13px;
    margin: 6px 0;
}
.ai-chat-msg.assistant a {
    color: #2271b1;
    text-decoration: underline;
}
.ai-chat-msg.assistant ul, .ai-chat-msg.assistant ol {
    margin: 6px 0 6px 20px;
    padding-left: 4px;
}
.ai-chat-msg.assistant li { margin-bottom: 3px; }
.ai-chat-msg.assistant blockquote {
    border-left: 3px solid #ccc;
    margin: 6px 0;
    padding-left: 10px;
    color: #666;
}

/* ══ 文章嵌入 Chat 区块样式 ═══════════════════════════════════════════ */
.ai-plus-chat-rendered {
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 24px;
    margin: 24px auto;
    background: #fff;
    max-width: 700px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.ai-plus-chat-rendered .ai-plus-chat-title {
    font-weight: 600;
    margin-bottom: 16px;
    font-size: 16px;
    color: #1a1a1a;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 12px;
}
.ai-plus-chat-rendered .ai-plus-chat-messages {
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 16px;
    padding: 12px;
    background: #f9fafb;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.ai-plus-chat-rendered .ai-plus-chat-empty {
    color: #9ca3af;
    font-size: 14px;
    text-align: center;
    padding: 40px 0;
}
.ai-plus-chat-rendered .ai-plus-msg {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.6;
    max-width: 85%;
    word-break: break-word;
}
.ai-plus-chat-rendered .ai-plus-msg.user {
    background: #2271b1;
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}
.ai-plus-chat-rendered .ai-plus-msg.assistant {
    background: #f0f0f0;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.ai-plus-chat-rendered .ai-plus-chat-bar {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.ai-plus-chat-rendered .ai-plus-chat-input {
    flex: 1;
    resize: none;
    font-size: 14px;
    padding: 12px 16px;
    border: 1px solid #dcdcde;
    border-radius: 8px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
    line-height: 1.5;
}
.ai-plus-chat-rendered .ai-plus-chat-input:focus {
    border-color: #2271b1;
    box-shadow: 0 0 0 2px rgba(34,113,177,0.15);
}
.ai-plus-chat-rendered .ai-plus-chat-send {
    padding: 12px 20px;
    background: linear-gradient(135deg, #2271b1, #135e96);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    white-space: nowrap;
    font-weight: 500;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: all 0.2s;
}
.ai-plus-chat-rendered .ai-plus-chat-send:hover {
    background: linear-gradient(135deg, #135e96, #0a4b78);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    transform: translateY(-1px);
}
.ai-plus-chat-rendered .ai-plus-chat-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}
.ai-plus-chat-rendered .ai-plus-chat-loading {
    display: none;
    color: #2271b1;
    font-size: 14px;
    padding: 0 8px;
}

/* Markdown in chat block messages */
.ai-plus-chat-rendered .ai-plus-msg.assistant strong { font-weight: 600; }
.ai-plus-chat-rendered .ai-plus-msg.assistant code {
    background: rgba(0,0,0,0.08);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}
.ai-plus-chat-rendered .ai-plus-msg.assistant pre {
    background: rgba(0,0,0,0.08);
    padding: 10px;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 13px;
    margin: 6px 0;
}
.ai-plus-chat-rendered .ai-plus-msg.assistant a {
    color: #2271b1;
    text-decoration: underline;
}

/* ══ 暗色模式 ════════════════════════════════════════════════════════════ */
[data-theme="dark"] .ai-plus-chat-rendered,
.dark-mode .ai-plus-chat-rendered {
    background: #252525;
    border-color: #3c3c3c;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-chat-title,
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-chat-title {
    color: #e8e8e8;
    border-bottom-color: #3c3c3c;
}
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-chat-messages,
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-chat-messages {
    background: #1a1a1a;
}
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-msg.assistant,
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-msg.assistant {
    background: #333;
    color: #e8e8e8;
}
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-msg.user,
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-msg.user {
    background: #1a5a8a;
    color: #e8e8e8;
}
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-chat-input,
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-chat-input {
    background: #1a1a1a;
    border-color: #3c3c3c;
    color: #e8e8e8;
}
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-chat-input:focus,
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-chat-input:focus {
    border-color: #8ab4f8;
    box-shadow: 0 0 0 2px rgba(138,180,248,0.2);
}
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-chat-send,
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-chat-send {
    background: linear-gradient(135deg, #1a5a8a, #0d4a70);
}
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-chat-send:hover,
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-chat-send:hover {
    background: linear-gradient(135deg, #0d4a70, #083a5a);
}
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-chat-empty,
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-chat-empty {
    color: #666;
}
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-chat-loading,
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-chat-loading {
    color: #8ab4f8;
}
/* Dark markdown in chat */
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-msg.assistant code,
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-msg.assistant code {
    background: rgba(255,255,255,0.1);
}
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-msg.assistant pre,
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-msg.assistant pre {
    background: rgba(255,255,255,0.08);
}
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-msg.assistant a,
[data-theme="dark"] .ai-plus-chat-rendered .ai-plus-msg.assistant a {
    color: #8ab4f8;
}

/* 暗色模式：浮窗/嵌入聊天 */
[data-theme="dark"] #ai-plus-chat-window,
[data-theme="dark"] #ai-plus-chat-window {
    background: #252525;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
[data-theme="dark"] .ai-chat-msg.assistant,
[data-theme="dark"] .ai-chat-msg.assistant {
    background: #333;
    color: #e8e8e8;
}
[data-theme="dark"] .ai-chat-msg.user,
[data-theme="dark"] .ai-chat-msg.user {
    background: #1a5a8a;
    color: #e8e8e8;
}
[data-theme="dark"] .ai-chat-input input,
[data-theme="dark"] .ai-chat-input input {
    background: #1a1a1a;
    border-color: #3c3c3c;
    color: #e8e8e8;
}
[data-theme="dark"] .ai-chat-input button,
[data-theme="dark"] .ai-chat-input button {
    background: #1a5a8a;
}
[data-theme="dark"] .ai-plus-embed-chat,
[data-theme="dark"] .ai-plus-embed-chat {
    border-color: #3c3c3c;
    background: #252525;
}
[data-theme="dark"] .ai-chat-msg.assistant code,
[data-theme="dark"] .ai-chat-msg.assistant code {
    background: rgba(255,255,255,0.1);
}
[data-theme="dark"] .ai-chat-msg.assistant pre,
[data-theme="dark"] .ai-chat-msg.assistant pre {
    background: rgba(255,255,255,0.08);
}
