/* ==========================================================================
   天门 306 · 西综 AI 智能助教专属样式 (全站统一色彩设计规范版)
   严格继承主页面 CSS 变量：--bg-page, --bg-panel, --border-color, --text-main, --primary
   ========================================================================== */

/* 抽屉全屏半透明遮罩 (层级高于做题自测模态框 100005，确保绝对顶层) */
.ai-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(10, 11, 16, 0.72);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 200000;
    display: flex;
    justify-content: flex-end;
    align-items: stretch;
    transition: opacity 0.22s ease;
}

/* AI 助教主抽屉侧边栏 */
.ai-assistant-drawer {
    width: 500px;
    max-width: 95vw;
    height: 100vh;
    height: 100dvh;
    background: var(--bg-panel, #131520);
    border-left: 1px solid var(--border-color, #23273a);
    display: flex;
    flex-direction: column;
    box-shadow: -12px 0 45px rgba(0, 0, 0, 0.55);
    animation: aiDrawerSlideIn 0.24s cubic-bezier(0.16, 1, 0.3, 1);
    color: var(--text-main, #f1f5f9);
    font-family: inherit;
}

@keyframes aiDrawerSlideIn {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

/* 顶部导航控制条 */
.ai-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--border-color, #23273a);
    background: var(--bg-panel, #131520);
    flex-shrink: 0;
}

.ai-drawer-title {
    display: flex;
    align-items: center;
    gap: 9px;
    flex-shrink: 0;
}

.ai-robot-badge {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.32);
    color: var(--primary, #3b82f6);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
    transition: all 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}

.ai-robot-badge.brand-deepseek {
    background: transparent;
    border-color: transparent;
    color: #4d6bfe;
    box-shadow: none;
}

.ai-robot-badge.brand-qwen {
    background: rgba(99, 102, 241, 0.18);
    border-color: rgba(99, 102, 241, 0.45);
    color: #6366f1;
    box-shadow: 0 0 14px rgba(99, 102, 241, 0.35);
}

.ai-robot-badge.brand-openai {
    background: #111111;
    border-color: #111111;
    border-radius: 50%;
    color: #ffffff;
    box-shadow: none;
}

.ai-robot-badge.brand-claude {
    background: rgba(217, 119, 6, 0.18);
    border-color: rgba(217, 119, 6, 0.45);
    color: #d97706;
    box-shadow: 0 0 14px rgba(217, 119, 6, 0.35);
}

.ai-brand-svg {
    display: inline-block;
    vertical-align: middle;
    transition: transform 0.2s ease;
}

.ai-brand-icon-slot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.ai-brand-title,
.ai-title-text {
    font-size: 0.96rem;
    font-weight: 800;
    color: var(--text-main, #f1f5f9) !important;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.ai-drawer-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
    justify-content: flex-end;
}

/* 优雅暗黑/浅色自适应模型选择下拉框 */
.ai-model-select {
    padding: 6px 24px 6px 11px;
    font-size: 0.76rem;
    font-weight: 700;
    border-radius: 8px;
    background-color: var(--bg-panel-hover, #1b1e2e);
    border: 1px solid var(--border-hover, #323752);
    color: var(--text-main, #f1f5f9) !important;
    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    max-width: 220px;
    min-width: 120px;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
}

.ai-model-select:hover {
    border-color: var(--primary, #3b82f6);
    box-shadow: 0 0 0 1px var(--primary, #3b82f6);
}

.ai-model-select option {
    background-color: #131520;
    color: #f1f5f9;
    padding: 8px;
}

/* 图标动作按钮 */
.ai-icon-btn {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: transparent;
    border: 1px solid var(--border-color, #23273a);
    color: var(--text-muted, #94a3b8);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.18s ease;
    flex-shrink: 0;
}

.ai-icon-btn:hover {
    background: var(--bg-panel-hover, #1b1e2e);
    border-color: var(--border-hover, #323752);
    color: var(--text-main, #f1f5f9);
}

.ai-icon-btn.close-btn:hover {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.35);
    color: #ef4444;
}

/* 题目上下文卡片 (完整阅读模式，题干 + 全部选项在 AI 界面内一目了然) */
.ai-context-banner {
    padding: 12px 16px;
    background: rgba(59, 130, 246, 0.08);
    border-bottom: 1px solid rgba(59, 130, 246, 0.2);
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 280px;
    overflow-y: auto;
}

.ai-context-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.ai-context-left-badges {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.ai-context-tag {
    font-size: 0.7rem;
    font-weight: 800;
    padding: 2px 8px;
    border-radius: 5px;
    background: rgba(59, 130, 246, 0.22);
    color: var(--primary-light, #60a5fa);
    border: 1px solid rgba(59, 130, 246, 0.35);
}

.ai-context-toggle-btn {
    background: transparent;
    border: 1px solid rgba(59, 130, 246, 0.2);
    color: var(--text-muted, #94a3b8);
    font-size: 0.7rem;
    cursor: pointer;
    padding: 2px 7px;
    border-radius: 5px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all 0.15s ease;
}

.ai-context-toggle-btn:hover {
    color: var(--primary-light, #60a5fa);
    border-color: var(--primary, #3b82f6);
}

.ai-context-stem {
    font-size: 0.82rem;
    font-weight: 700;
    line-height: 1.45;
    color: var(--text-main, #f1f5f9);
    word-break: break-word;
}

.ai-context-stem.collapsed {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 题目选项列表 (AI 面板内部完整展示) */
.ai-context-options-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 2px;
}

.ai-context-option-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 0.76rem;
    padding: 4px 8px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    color: var(--text-muted, #94a3b8);
    line-height: 1.35;
}

.ai-context-option-row.correct {
    background: rgba(16, 185, 129, 0.12);
    border-color: rgba(16, 185, 129, 0.3);
    color: #34d399;
}

.ai-context-option-row.user-wrong {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.3);
    color: #f87171;
}

.ai-context-option-key {
    font-weight: 800;
    flex-shrink: 0;
}

.ai-context-meta {
    font-size: 0.74rem;
    color: var(--text-muted, #94a3b8);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding-top: 4px;
    border-top: 1px dashed rgba(59, 130, 246, 0.18);
}

/* 顶部快捷问题预设胶囊栏 */
.ai-quick-pills-bar {
    display: flex;
    gap: 8px;
    padding: 9px 16px;
    overflow-x: auto;
    white-space: nowrap;
    border-bottom: 1px solid var(--border-color, #23273a);
    background: var(--bg-page, #0a0b10);
}

.ai-quick-pills-bar::-webkit-scrollbar {
    height: 4px;
}
.ai-quick-pills-bar::-webkit-scrollbar-thumb {
    background: var(--border-color, #23273a);
    border-radius: 4px;
}

/* 学习档案状态条：展示助教已了解的学习进度 */
.ai-study-status {
    margin: 0 0 8px;
    padding: 7px 12px;
    border-radius: 10px;
    border: 1px solid rgba(59, 130, 246, 0.25);
    background: rgba(59, 130, 246, 0.08);
    color: var(--text-muted, #94a3b8);
    font-size: 0.72rem;
    line-height: 1.55;
}

.ai-study-status strong {
    color: var(--text-main, #e2e8f0);
    font-weight: 800;
}

.ai-pill-btn {
    padding: 5px 12px;
    font-size: 0.74rem;
    font-weight: 700;
    border-radius: 999px;
    background: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(59, 130, 246, 0.3);
    color: var(--primary-light, #60a5fa);
    cursor: pointer;
    transition: all 0.18s ease;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
}

.ai-pill-btn:hover {
    background: var(--primary, #3b82f6);
    border-color: var(--primary, #3b82f6);
    color: #ffffff;
    box-shadow: 0 2px 8px var(--primary-glow, rgba(59, 130, 246, 0.3));
    transform: translateY(-1px);
}

.ai-pill-btn.highlight {
    background: rgba(239, 68, 68, 0.14);
    border-color: rgba(239, 68, 68, 0.35);
    color: #fca5a5;
}

.ai-pill-btn.highlight:hover {
    background: #ef4444;
    border-color: #ef4444;
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.35);
}

/* 消息流滚动区域 */
.ai-messages-scroller {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--bg-page, #0a0b10);
}

/* 空状态欢迎展牌 */
.ai-empty-welcome {
    text-align: center;
    padding: 45px 20px;
    color: var(--text-muted, #94a3b8);
}

.ai-welcome-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    margin: 0 auto 14px;
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.32);
    color: var(--primary, #3b82f6);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 16px var(--primary-glow, rgba(59, 130, 246, 0.2));
}

.ai-empty-welcome h3 {
    font-size: 1.02rem;
    font-weight: 800;
    color: var(--text-main, #f1f5f9) !important;
    margin-bottom: 8px;
}

.ai-empty-welcome p {
    font-size: 0.8rem;
    line-height: 1.6;
    color: var(--text-muted, #94a3b8) !important;
    max-width: 320px;
    margin: 0 auto;
}

/* 对话消息单行与气泡 */
.ai-msg-row {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.ai-msg-row.user {
    justify-content: flex-end;
}

.ai-msg-bubble.user {
    max-width: 82%;
    padding: 10px 15px;
    border-radius: 14px 14px 2px 14px;
    background: var(--primary, #3b82f6);
    color: #ffffff;
    font-size: 0.84rem;
    font-weight: 600;
    line-height: 1.55;
    box-shadow: 0 3px 12px var(--primary-glow, rgba(59, 130, 246, 0.35));
    word-break: break-word;
}

.ai-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.3);
    color: var(--primary, #3b82f6);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.ai-msg-avatar.brand-openai {
    background: #111111;
    border-color: #111111;
    border-radius: 50%;
    color: #ffffff;
}

.ai-msg-avatar.brand-deepseek {
    background: transparent;
    border-color: transparent;
    color: #4d6bfe;
}

.ai-robot-badge.brand-deepseek .ai-brand-svg,
.ai-msg-avatar.brand-deepseek .ai-brand-svg {
    width: 24px;
    height: 24px;
}

.ai-msg-body {
    flex: 1;
    background: var(--bg-panel, #131520);
    border: 1px solid var(--border-color, #23273a);
    border-radius: 12px;
    padding: 14px 16px;
    color: var(--text-main, #f1f5f9);
    font-size: 0.84rem;
    line-height: 1.68;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

/* DeepSeek R1 深度推导思维链折叠盒 */
.ai-thought-box {
    margin-bottom: 12px;
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 8px;
    background: rgba(59, 130, 246, 0.06);
    overflow: hidden;
}

.ai-thought-summary {
    padding: 7px 12px;
    font-size: 0.74rem;
    font-weight: 800;
    color: var(--primary-light, #60a5fa);
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(59, 130, 246, 0.12);
}

.ai-thought-content {
    padding: 10px 14px;
    font-size: 0.76rem;
    line-height: 1.55;
    color: var(--text-muted, #94a3b8);
    border-top: 1px dashed rgba(59, 130, 246, 0.2);
    max-height: 220px;
    overflow-y: auto;
}

/* 消息底部控制项 */
.ai-msg-foot {
    display: flex;
    justify-content: flex-end;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px dashed var(--border-color, #23273a);
}

.ai-copy-btn {
    background: transparent;
    border: 1px solid var(--border-color, #23273a);
    color: var(--text-muted, #94a3b8);
    font-size: 0.7rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    border-radius: 5px;
    transition: all 0.15s ease;
}

.ai-copy-btn:hover {
    color: var(--primary-light, #60a5fa);
    border-color: var(--primary, #3b82f6);
    background: rgba(59, 130, 246, 0.12);
}

.ai-typing-cursor {
    display: inline-block;
    width: 6px;
    height: 14px;
    background: var(--primary, #3b82f6);
    vertical-align: middle;
    animation: aiCursorBlink 0.8s infinite;
}

@keyframes aiCursorBlink {
    0%, 100% { opacity: 0; }
    50% { opacity: 1; }
}

/* 底部输入工作区 (Codex 风格：输入框在上，功能控制 Dock 在下) */
.ai-input-bar {
    padding: 12px 16px;
    border-top: 1px solid var(--border-color, #23273a);
    background: var(--bg-panel, #131520);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-input-textarea {
    width: 100%;
    min-height: 52px;
    max-height: 140px;
    padding: 10px 12px;
    border-radius: 9px;
    border: 1px solid var(--border-color, #23273a);
    background: var(--bg-page, #0a0b10);
    color: var(--text-main, #f1f5f9);
    font-size: 0.85rem;
    font-family: inherit;
    resize: none;
    outline: none;
    line-height: 1.5;
    box-sizing: border-box;
    transition: all 0.2s ease;
}

.ai-input-textarea:focus {
    border-color: var(--primary, #3b82f6);
    box-shadow: 0 0 0 2px var(--primary-glow, rgba(59, 130, 246, 0.25));
}

/* 底部操作条：左侧配置入口，右侧模型选择与发送按钮紧凑排列 */
.ai-input-bottom-dock {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.ai-dock-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-dock-link-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: transparent;
    border: none;
    color: var(--text-muted, #94a3b8);
    font-size: 0.74rem;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    transition: all 0.15s ease;
}

.ai-dock-link-btn:hover {
    color: var(--primary-light, #60a5fa);
    background: rgba(59, 130, 246, 0.1);
}

.ai-dock-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 发送按钮左侧紧邻的模型选择框 (Codex 风格) */
.ai-dock-model-select {
    max-width: 170px;
    font-size: 0.74rem;
    padding: 6px 26px 6px 10px;
    background-color: var(--bg-page, #0a0b10);
    border: 1px solid var(--border-color, #23273a);
    border-radius: 8px;
    color: var(--text-main, #f1f5f9);
    font-weight: 600;
}

.ai-dock-model-select:hover {
    border-color: var(--primary, #3b82f6);
}

/* 刷新/拉取模型专属按钮与动画 */
.ai-dock-refresh-btn {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background-color: var(--bg-page, #0a0b10);
    border: 1px solid var(--border-color, #23273a);
    color: var(--text-muted, #94a3b8);
    cursor: pointer;
    transition: all 0.18s ease;
    padding: 0;
    flex-shrink: 0;
}

.ai-dock-refresh-btn:hover, .ai-icon-refresh-btn:hover {
    color: var(--primary-light, #60a5fa);
    border-color: var(--primary, #3b82f6);
    background: rgba(59, 130, 246, 0.12);
}

.ai-dock-refresh-btn.spinning svg, .ai-icon-refresh-btn.spinning svg {
    animation: aiSpin 0.8s linear infinite;
}

@keyframes aiSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* 浮动轻量 Toast 提示 (仿移动端气泡) */
.ai-toast-notice {
    position: absolute;
    bottom: 85px;
    left: 50%;
    transform: translateX(-50%) translateY(16px);
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid var(--primary, #3b82f6);
    color: #f1f5f9;
    padding: 7px 16px;
    border-radius: 20px;
    font-size: 0.76rem;
    font-weight: 600;
    pointer-events: none;
    opacity: 0;
    transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 200005;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
    white-space: nowrap;
    max-width: 90%;
    text-align: center;
}

.ai-toast-notice.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.ai-send-btn, .ai-stop-btn {
    padding: 7px 16px;
    font-size: 0.8rem;
    font-weight: 800;
    border-radius: 8px;
    cursor: pointer;
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.18s ease;
    white-space: nowrap;
}

.ai-send-btn {
    background: var(--primary, #3b82f6);
    color: #ffffff;
    box-shadow: 0 3px 10px var(--primary-glow, rgba(59, 130, 246, 0.3));
}

.ai-send-btn:hover {
    background: var(--primary-light, #60a5fa);
    transform: translateY(-1px);
}

.ai-stop-btn {
    background: rgba(239, 68, 68, 0.18);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.35);
}

/* ==================== 接口与密钥配置弹窗 ==================== */
.ai-settings-dialog {
    width: 440px;
    max-width: 90vw;
    background: var(--bg-panel, #131520);
    border: 1px solid var(--border-color, #23273a);
    border-radius: 14px;
    box-shadow: 0 20px 55px rgba(0, 0, 0, 0.7);
    overflow: hidden;
    margin: auto;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
    color: var(--text-main, #f1f5f9);
}

.ai-settings-head {
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color, #23273a);
}

.ai-settings-head h3 {
    font-size: 0.98rem;
    font-weight: 800;
    margin: 0;
    color: var(--text-main, #f1f5f9) !important;
}

.ai-settings-body {
    min-height: 0;
    overflow-y: auto;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.ai-settings-foot { flex-shrink: 0; }
.ai-maimemo-doc { font-size: 12px; color: var(--primary-light, #93c5fd); }
body.light-theme .ai-maimemo-doc { color: #1d4ed8; }

.ai-settings-tip {
    font-size: 0.74rem;
    line-height: 1.5;
    color: var(--text-muted, #94a3b8);
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.25);
    border-radius: 8px;
    padding: 9px 12px;
}

.ai-form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.ai-form-label {
    font-size: 0.78rem;
    font-weight: 800;
    color: var(--text-main, #f1f5f9);
}

.ai-form-input, .ai-form-select {
    width: 100%;
    padding: 9px 12px;
    font-size: 0.82rem;
    border-radius: 8px;
    border: 1px solid var(--border-color, #23273a);
    background: var(--bg-page, #0a0b10);
    color: var(--text-main, #f1f5f9);
    outline: none;
    box-sizing: border-box;
}

.ai-form-input:focus, .ai-form-select:focus {
    border-color: var(--primary, #3b82f6);
    box-shadow: 0 0 0 2px var(--primary-glow, rgba(59, 130, 246, 0.2));
}

.ai-pwd-toggle-btn {
    position: absolute;
    right: 8px;
    padding: 3px 8px;
    font-size: 0.7rem;
    background: var(--bg-panel-hover, #1b1e2e);
    border: 1px solid var(--border-color, #23273a);
    border-radius: 5px;
    color: var(--text-muted, #94a3b8);
    cursor: pointer;
}

.ai-form-hint {
    font-size: 0.7rem;
    color: var(--text-muted, #94a3b8);
}

.ai-test-status-box {
    padding: 9px 12px;
    border-radius: 7px;
    font-size: 0.76rem;
    line-height: 1.45;
}

.ai-test-status-box.info {
    background: rgba(59, 130, 246, 0.12);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.25);
}

.ai-test-status-box.success {
    background: rgba(16, 185, 129, 0.12);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.ai-test-status-box.error {
    background: rgba(239, 68, 68, 0.14);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.ai-test-status-box.warning {
    background: rgba(245, 158, 11, 0.14);
    color: #fbbf24;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.ai-settings-foot {
    padding: 13px 18px;
    border-top: 1px solid var(--border-color, #23273a);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    background: var(--bg-panel, #131520);
}

.ai-btn-primary, .ai-btn-secondary {
    padding: 8px 16px;
    border-radius: 7px;
    font-size: 0.8rem;
    font-weight: 800;
    cursor: pointer;
    border: none;
    transition: all 0.18s ease;
}

.ai-btn-primary {
    background: var(--primary, #3b82f6);
    color: #ffffff;
    box-shadow: 0 3px 10px var(--primary-glow, rgba(59, 130, 246, 0.3));
}

.ai-btn-secondary {
    background: var(--bg-panel-hover, #1b1e2e);
    border: 1px solid var(--border-color, #23273a);
    color: var(--text-main, #f1f5f9);
}

/* 做题卡片专属 AI 按钮 */
.wrong-ai-btn, .action-ai-btn {
    padding: 5px 12px;
    border-radius: 7px;
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.38);
    color: var(--primary-light, #60a5fa);
    font-size: 0.78rem;
    font-weight: 800;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.wrong-ai-btn:hover, .action-ai-btn:hover {
    background: var(--primary, #3b82f6);
    border-color: var(--primary, #3b82f6);
    color: #ffffff;
    box-shadow: 0 3px 12px var(--primary-glow, rgba(59, 130, 246, 0.35));
    transform: translateY(-1px);
}

/* ==================== 浅色模式全套同步匹配 (Light Theme) ==================== */
body.light-theme .ai-assistant-drawer {
    background: #ffffff;
    border-left-color: #e2e8f0;
    box-shadow: -10px 0 40px rgba(0, 0, 0, 0.12);
    color: #0f172a;
}

body.light-theme .ai-drawer-header {
    background: #ffffff;
    border-bottom-color: #e2e8f0;
}

body.light-theme .ai-title-text,
body.light-theme .ai-brand-title {
    color: #0f172a !important;
}

body.light-theme .ai-model-select {
    background-color: #f8fafc;
    border-color: #cbd5e1;
    color: #0f172a !important;
}

body.light-theme .ai-model-select option {
    background-color: #ffffff;
    color: #0f172a;
}

body.light-theme .ai-icon-btn {
    border-color: #e2e8f0;
    color: #64748b;
}

body.light-theme .ai-icon-btn:hover {
    background: #f1f5f9;
    color: #0f172a;
}

body.light-theme .ai-quick-pills-bar,
body.light-theme .ai-messages-scroller {
    background: #f8fafc;
    border-bottom-color: #e2e8f0;
}

body.light-theme .ai-empty-welcome h3 {
    color: #0f172a !important;
}

body.light-theme .ai-empty-welcome p {
    color: #64748b !important;
}

body.light-theme .ai-msg-body {
    background: #ffffff;
    border-color: #e2e8f0;
    color: #0f172a;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

body.light-theme .ai-thought-box {
    border-color: rgba(59, 130, 246, 0.2);
    background: rgba(59, 130, 246, 0.04);
}

body.light-theme .ai-thought-summary {
    background: rgba(59, 130, 246, 0.08);
    color: #2563eb;
}

body.light-theme .ai-thought-content {
    color: #475569;
}

body.light-theme .ai-input-bar {
    background: #ffffff;
    border-top-color: #e2e8f0;
}

body.light-theme .ai-input-textarea {
    background: #f8fafc;
    border-color: #cbd5e1;
    color: #0f172a;
}

body.light-theme .ai-dock-model-select {
    background-color: #f8fafc;
    border-color: #cbd5e1;
    color: #0f172a;
}

body.light-theme .ai-dock-link-btn {
    color: #64748b;
}

body.light-theme .ai-dock-link-btn:hover {
    color: #2563eb;
    background: rgba(59, 130, 246, 0.08);
}

body.light-theme .ai-settings-dialog {
    background: #ffffff;
    border-color: #e2e8f0;
    color: #0f172a;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
}

body.light-theme .ai-settings-head,
body.light-theme .ai-settings-foot {
    border-color: #e2e8f0;
    background: #ffffff;
}

body.light-theme .ai-settings-head h3,
body.light-theme .ai-form-label {
    color: #0f172a !important;
}

body.light-theme .ai-form-input,
body.light-theme .ai-form-select {
    background: #f8fafc;
    border-color: #cbd5e1;
    color: #0f172a;
}

body.light-theme .ai-btn-secondary {
    background: #f1f5f9;
    border-color: #e2e8f0;
    color: #0f172a;
}

/* ==================== 题目与 AI 同屏双栏并排 (Split Screen 体验) ==================== */
@media (min-width: 1024px) {
    body.ai-drawer-active .wrong-practice-modal-backdrop {
        justify-content: flex-start !important;
        padding-left: max(24px, calc(50vw - 570px)) !important;
        pointer-events: auto !important;
    }
    body.ai-drawer-active .wrong-practice-box {
        max-width: 580px !important;
        box-shadow: 0 16px 45px rgba(0, 0, 0, 0.6) !important;
        transition: all 0.26s cubic-bezier(0.16, 1, 0.3, 1);
    }
    body.ai-drawer-active .ai-modal-backdrop {
        background: rgba(10, 11, 16, 0.35) !important;
        pointer-events: none !important;
    }
    body.ai-drawer-active .ai-assistant-drawer {
        pointer-events: auto !important;
    }
}
/* Connection settings remain interactive above the desktop drawer. */
body.ai-drawer-active #ai-settings-modal-backdrop { pointer-events:auto !important; }
/* Per-question history controls, sized for phones and tablets. */
.ai-history-toolbar { display:flex; flex-wrap:wrap; align-items:center; gap:8px; padding:8px 14px; border-bottom:1px solid var(--border-color, #34303a); font-size:12px; }
.ai-history-toolbar label { display:flex; align-items:center; gap:4px; white-space:nowrap; cursor:pointer; }
.ai-history-toolbar input { accent-color:var(--primary, #cc85ae); }
.ai-history-toolbar [role=status] { flex:1; min-width:130px; color:var(--text-muted, #94a3b8); }
.ai-history-toolbar button { background:transparent; border:1px solid var(--border-color, #443443); color:inherit; border-radius:7px; padding:5px 8px; cursor:pointer; }
.ai-history-toolbar button:disabled { opacity:.45; cursor:default; }
.ai-msg-content { overflow-wrap:anywhere; min-width:0; }
.ai-msg-content table { display:block; overflow-x:auto; border-collapse:collapse; margin:10px 0; max-width:100%; }
.ai-msg-content th, .ai-msg-content td { padding:7px 10px; border:1px solid var(--border-color, #48404a); text-align:left; }
.ai-msg-content blockquote { border-left:3px solid var(--primary, #cc85ae); padding:4px 12px; margin:8px 0; background:rgba(148,163,184,.06); }
.ai-msg-content pre { overflow:auto; padding:12px; border-radius:8px; background:rgba(0,0,0,.2); white-space:pre; }
.ai-msg-content p { margin:8px 0; }
.ai-msg-content .katex-display { overflow-x:auto; overflow-y:hidden; padding:5px 0; max-width:100%; }
.ai-history-toolbar { flex-wrap:nowrap; padding:4px 12px; gap:6px; font-size:11px; }
.ai-history-toolbar [role=status] { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.ai-history-toolbar button { font-size:11px; padding:3px 6px; white-space:nowrap; }
.ai-context-banner.ai-context-collapsed { padding:7px 12px; gap:4px; }
.ai-context-collapsed .ai-context-options-list, .ai-context-collapsed .ai-context-meta { display:none !important; }
.ai-context-collapsed .ai-context-stem { display:block; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-height:22px; line-height:22px; font-size:12px; }
.ai-quick-tools { flex-shrink:0; padding:4px 12px; border-bottom:1px solid rgba(148,163,184,.12); font-size:12px; }
.ai-quick-tools summary { cursor:pointer; color:var(--text-muted,#94a3b8); }
.ai-quick-tools .ai-quick-pills-bar { padding:7px 0 3px; }
.ai-input-bar { padding:8px 12px !important; }
.ai-input-textarea { min-height:38px !important; max-height:100px !important; padding:8px 10px !important; }
.ai-input-bottom-dock { margin-top:5px !important; }
.ai-assistant-drawer { box-sizing:border-box; min-width:0; }
.ai-attachments { display:flex; flex-direction:column; gap:5px; max-height:130px; overflow:auto; }
.ai-attachment-chip { display:flex; align-items:center; gap:7px; padding:5px 8px; border:1px solid var(--border-color,#48404a); border-radius:8px; font-size:12px; }
.ai-attachment-chip>span { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.ai-attachment-thumbnail { width:48px; height:48px; object-fit:cover; flex-shrink:0; border-radius:5px; }
.ai-attachment-chip small { max-width:52%; overflow-wrap:anywhere; color:var(--text-muted,#94a3b8); }
.ai-attachment-chip button { border:0; background:transparent; color:inherit; cursor:pointer; padding:4px 7px; font-size:18px; }
.ai-attachment-hint { font-size:10px; color:var(--text-muted,#94a3b8); line-height:1.5; margin:5px 0; }
.ai-attachment-add { font-size:23px; padding:0 9px; }
.ai-attachment-add:disabled { opacity:.4; }
.ai-attachment-chip .ai-attachment-preview-btn { font-size:11px; white-space:nowrap; padding:5px; }
.ai-attachment-preview { position:fixed; inset:0; z-index:220000; padding:16px; background:rgba(0,0,0,.65); display:flex; align-items:center; justify-content:center; }
.ai-attachment-preview section { width:700px; max-width:100%; background:var(--bg-panel,#22212a); color:var(--text-main,#e5e7eb); border:1px solid var(--border-color,#48404a); border-radius:12px; padding:16px; }
.ai-attachment-preview section { max-height:90dvh; box-sizing:border-box; overflow:auto; }
.ai-attachment-preview img { display:block; width:auto; max-width:100%; max-height:65dvh; object-fit:contain; margin:12px auto; background:#fff; }
.ai-preview-pages { display:flex; justify-content:center; gap:12px; margin:10px 0; }
.ai-attachment-preview img ~ textarea { height:22dvh; }
.ai-attachment-preview header { display:flex; align-items:center; gap:12px; justify-content:space-between; }
.ai-attachment-preview h3 { min-width:0; overflow-wrap:anywhere; font-size:15px; margin:0; }
.ai-attachment-preview p { font-size:12px; color:var(--text-muted,#94a3b8); }
.ai-attachment-preview textarea { box-sizing:border-box; width:100%; height:55dvh; resize:none; background:var(--bg-page,#19181f); color:inherit; padding:10px; border:1px solid var(--border-color,#48404a); border-radius:8px; font-size:13px; line-height:1.6; }
.ai-attachment-preview button { padding:6px 10px; border-radius:6px; border:1px solid var(--border-color,#48404a); background:transparent; color:inherit; white-space:nowrap; cursor:pointer; }
.ai-drawer-header { flex-shrink:0; }
.ai-drawer-title { min-width:0; }
@media(max-width:600px) {
    .ai-assistant-drawer { width:100vw; max-width:100vw; }
    .ai-drawer-header { padding:8px 12px; }
    .ai-drawer-header-actions #ai-model-select { max-width: 140px; font-size: 11px; padding: 4px 20px 4px 8px; }
    .ai-brand-title { font-size: 13px; }
    .ai-history-toolbar [role=status] { font-size:10px; }
    .ai-input-bottom-dock { gap:6px; }
    .ai-dock-left { flex-shrink:0; gap:4px; }
    .ai-dock-right { flex:1; min-width:0; gap:5px; }
    .ai-dock-model-select { flex:1; width:0; min-width:40px; max-width:170px; padding-left:6px; padding-right:18px; }
    .ai-send-btn,.ai-stop-btn { flex-shrink:0; padding:7px 10px; }
    .ai-drawer-header-actions #ai-model-select { flex:1; width:0; min-width:40px; }
}
.ai-reply-actions { display:flex; flex-wrap:wrap; align-items:center; gap:8px; margin-top:12px; }
.ai-reply-actions button { width:auto; margin:0; padding:6px 9px; border:1px solid var(--border-color,#48404a); border-radius:7px; background:transparent; color:inherit; font-size:12px; cursor:pointer; }
.ai-reply-status,.ai-operation-status { width:100%; font-size:12px; color:var(--text-muted,#94a3b8); overflow-wrap:anywhere; }
.ai-reply-speech { display:flex; flex-wrap:wrap; gap:7px; width:100%; }
.ai-reply-speech select { max-width:100%; color:inherit; background:var(--bg-panel,#22212a); padding:6px; border-radius:7px; }
.ai-reply-speech select[aria-label="朗读声音"] { flex:1 1 100%; min-width:0; }
.ai-reply-speech select,.ai-reply-speech button { min-height:36px; }
.ai-reply-visual { width:100%; overflow:auto; }
.ai-reply-visual svg { max-width:100%; height:auto; }
.ai-reply-review { width:100%; border:1px solid var(--border-color,#48404a); padding:10px; border-radius:8px; }
.ai-reply-review p { white-space:pre-wrap; overflow-wrap:anywhere; }
.ai-reply-review div { display:flex; flex-wrap:wrap; gap:6px; margin-top:8px; }
.ai-reply-review [hidden] { display:none!important; }
.ai-msg-content pre[hidden] { display:none!important; }
.ai-attachment-preview header { flex-direction:row; flex-wrap:nowrap; }
.ai-attachment-preview button { width:auto; margin:0; flex:none; }
.ai-attachment-preview h3,.ai-attachment-preview button,.ai-reply-actions button,.ai-reply-review summary { color:var(--text-main,#f8fafc); }

/* Chat reading layout: fixed available width through reasoning and tool calls.
   Keep all rules scoped so chapter controls retain their own layout. */
.ai-assistant-drawer { width:680px; max-width:100vw; overflow:hidden; box-shadow:-8px 0 32px rgba(0,0,0,.16); }
.ai-assistant-drawer *, .ai-assistant-drawer *::before, .ai-assistant-drawer *::after { box-sizing:border-box; }
.ai-drawer-header { padding:14px 20px; gap:12px; }
.ai-drawer-title { gap:8px; }
.ai-brand-title { font-weight:600; }
.ai-drawer-header-actions { gap:7px; }
.ai-model-select { min-height:36px; font-weight:500; box-shadow:none; border-radius:10px; }
.ai-robot-badge.brand-openai,.ai-msg-avatar.brand-openai { background:transparent; border-color:transparent; color:var(--text-main,#f1f5f9); border-radius:0; }
.ai-brand-svg { display:block; flex-shrink:0; }
.ai-model-select optgroup { color:var(--text-main,#f1f5f9); background:var(--bg-panel,#131520); font-style:normal; }
.ai-model-select option { font-weight:400; }
.ai-custom-model { margin-top:12px; font-size:12px; color:var(--text-muted); }
.ai-custom-model summary { cursor:pointer; padding:5px 0; }
.ai-custom-model>div { display:flex; gap:8px; margin-top:8px; }
.ai-custom-model input { min-width:0; flex:1; }
.ai-model-control { flex:1; width:0; min-width:48px; max-width:200px; }
.ai-model-control>select { display:none!important; }
.ai-model-control>.ai-model-select { width:100%; min-width:0; max-width:none; text-align:left; }
.ai-model-picker-overlay { position:fixed; inset:0; z-index:220000; background:rgba(0,0,0,.12); }
.ai-model-picker-panel { position:fixed; display:flex; flex-direction:column; background:var(--bg-panel,#131520); color:var(--text-main,#f1f5f9); border:1px solid var(--border-color); border-radius:14px; padding:10px; box-shadow:0 14px 45px rgba(0,0,0,.25); box-sizing:border-box; }
.ai-model-picker-panel header { display:flex; align-items:center; justify-content:space-between; padding:2px 4px 8px; font-size:14px; }
.ai-model-picker-panel header button { border:0; background:transparent; color:var(--text-muted); font-size:22px; cursor:pointer; min-width:32px; min-height:32px; }
.ai-model-picker-panel input { width:100%; box-sizing:border-box; border:1px solid var(--border-color); border-radius:9px; padding:10px; background:var(--bg-panel-hover); color:var(--text-main); font:inherit; font-size:13px; }
.ai-model-picker-list { min-height:0; overflow-y:auto; overscroll-behavior:contain; touch-action:pan-y; padding-top:4px; }
.ai-model-picker-group { margin:12px 8px 5px; font-size:11px; color:var(--text-muted); }
.ai-model-picker-option { display:flex; width:100%; align-items:center; gap:10px; border:0; border-radius:8px; background:transparent; color:var(--text-main); padding:10px 8px; min-height:42px; text-align:left; cursor:pointer; font:inherit; font-size:13px; }
.ai-model-picker-option span { min-width:0; overflow-wrap:anywhere; flex:1; }
.ai-model-picker-option small { color:var(--primary); font-size:15px; }
.ai-model-picker-option:hover,.ai-model-picker-option[aria-pressed="true"] { background:var(--bg-panel-hover); }
.ai-model-picker-empty { color:var(--text-muted); text-align:center; padding:14px; font-size:13px; }
.ai-icon-btn { width:34px; height:34px; border-color:transparent; }
.ai-icon-btn:focus-visible, .ai-copy-btn:focus-visible, .ai-history-toolbar button:focus-visible { outline:2px solid var(--primary,#cc85ae); outline-offset:2px; }
.ai-history-toolbar { min-height:38px; padding:5px 20px; gap:8px; color:var(--text-muted,#94a3b8); font-size:12px; }
.ai-history-toolbar button { min-height:28px; border-color:transparent; font-weight:500; }
.ai-history-toolbar button:hover { background:var(--bg-panel-hover,#22212a); color:var(--text-main,#f1f5f9); }
.ai-history-toolbar label { color:var(--text-main,#f1f5f9); }
.ai-quick-tools { padding:8px 20px; }
.ai-messages-scroller { min-height:0; min-width:0; width:100%; padding:24px; gap:0; overflow-x:hidden; overscroll-behavior:contain; scrollbar-gutter:stable; background:var(--bg-panel,#131520); }
body.light-theme .ai-messages-scroller { background:#fff; }
.ai-messages-list { display:flex; flex-direction:column; gap:28px; width:100%; min-width:0; max-width:100%; }
.ai-msg-row { width:100%; min-width:0; max-width:100%; gap:12px; }
.ai-msg-body { flex:1 1 0%; width:0; min-width:0; max-width:100%; padding:3px 0; border:0; border-radius:0; font-size:14px; line-height:1.85; background:transparent; box-shadow:none; overflow-wrap:anywhere; }
body.light-theme .ai-msg-body { background:transparent; border:0; box-shadow:none; }
.ai-msg-avatar { width:26px; height:26px; margin-top:5px; }
.ai-msg-content { width:100%; min-width:0; max-width:100%; overflow-wrap:anywhere; word-break:normal; }
.ai-msg-content > * { max-width:100%; }
.ai-msg-content p { margin:0 0 14px; }
.ai-msg-content p:last-child { margin-bottom:0; }
.ai-msg-content h1,.ai-msg-content h2,.ai-msg-content h3 { margin:22px 0 10px; line-height:1.5; font-weight:600; }
.ai-msg-content h1 { font-size:20px; } .ai-msg-content h2 { font-size:18px; } .ai-msg-content h3 { font-size:16px; }
.ai-msg-content ul,.ai-msg-content ol { padding-left:22px; margin:10px 0 16px; }
.ai-msg-content li { margin:5px 0; }
.ai-msg-content pre { width:100%; margin:14px 0; background:var(--bg-page,#0a0b10); border:1px solid var(--border-color,#34303a); }
.ai-msg-content table { width:100%; font-size:13px; line-height:1.6; }
.ai-msg-content th { background:var(--bg-page,#0a0b10); font-weight:600; }
.ai-msg-content th,.ai-msg-content td { padding:10px 12px; min-width:80px; vertical-align:top; }
.ai-msg-content img,.ai-msg-content svg { max-width:100%; height:auto; }
.ai-msg-bubble.user { min-width:0; max-width:85%; padding:11px 16px; border-radius:16px 16px 4px 16px; font-size:14px; font-weight:500; box-shadow:none; white-space:pre-wrap; }
.ai-thought-box { width:100%; min-width:0; margin:0 0 16px; border:1px solid var(--border-color,#34303a); background:var(--bg-page,#0a0b10); border-radius:10px; }
body.light-theme .ai-thought-box { border-color:#e2e8f0; background:#f8fafc; }
.ai-thought-summary { padding:10px 12px; font-size:12px; font-weight:500; background:transparent; color:var(--text-muted,#94a3b8); list-style:none; }
body.light-theme .ai-thought-summary { color:#64748b; background:transparent; }
.ai-thought-summary::-webkit-details-marker { display:none; }
.ai-thought-summary svg { width:15px; height:15px; flex:none; }
.ai-thought-chevron { margin-left:auto; transition:transform .15s; }
.ai-thought-box[open] .ai-thought-chevron { transform:rotate(180deg); }
.ai-thought-content { max-height:260px; padding:12px 14px; border-top:1px solid var(--border-color,#34303a); font-size:13px; line-height:1.8; overflow:auto; overflow-wrap:anywhere; }
.ai-thought-content pre,.ai-thought-content table { max-width:100%; overflow:auto; }
.ai-operation-status { display:flex; align-items:flex-start; gap:8px; width:100%; min-width:0; margin:0 0 12px; padding:0; font-size:12px; color:var(--text-muted,#94a3b8); line-height:1.65; overflow-wrap:anywhere; }
.ai-operation-status::before { content:''; width:6px; height:6px; margin-top:7px; flex:none; border-radius:50%; background:var(--primary,#cc85ae); }
.ai-msg-foot { justify-content:flex-start; border:0; margin-top:16px; padding:0; }
.ai-copy-btn { min-height:30px; padding:5px 8px; border-color:transparent; font-weight:400; font-size:12px; }
.ai-reply-actions { margin-top:4px; gap:6px; }
.ai-reply-actions button { border-color:transparent; min-height:30px; font-weight:400; color:var(--text-muted,#94a3b8); }
.ai-input-bar { flex-shrink:0; padding:14px 20px max(14px,env(safe-area-inset-bottom)) !important; gap:6px; }
.ai-input-textarea { padding:12px 14px !important; min-height:48px !important; max-height:160px !important; font-size:14px; line-height:1.6; border-radius:12px; resize:none; box-shadow:none; }
.ai-input-textarea:focus { outline:none; border-color:var(--primary,#cc85ae); box-shadow:0 0 0 2px var(--primary-glow,rgba(204,133,174,.15)); }
.ai-input-bottom-dock { min-width:0; gap:10px; margin-top:4px !important; }
.ai-dock-left { min-width:0; flex:none; gap:6px; }
.ai-dock-right { min-width:0; flex:1; justify-content:flex-end; }
.ai-dock-model-select { flex:1; width:0; min-width:48px; max-width:200px; }
.ai-dock-link-btn,.ai-dock-refresh-btn { min-height:34px; box-shadow:none; }
.ai-send-btn,.ai-stop-btn { min-height:36px; flex:none; border-radius:9px; font-weight:500; box-shadow:none; }
.ai-assistant-drawer [hidden] { display:none !important; }
@media(max-width:700px) {
    .ai-assistant-drawer { width:100vw; max-width:100vw; }
    .ai-drawer-header { padding:12px 14px; gap:8px; }
    .ai-drawer-header-actions { gap:4px; }
    .ai-drawer-header-actions #ai-model-select { flex:1; width:0; min-width:40px; max-width:200px; }
    .ai-brand-title { font-size:13px; }
    .ai-history-toolbar { padding:6px 14px; gap:4px; font-size:11px; }
    .ai-quick-tools { padding:8px 14px; }
    .ai-messages-scroller { padding:20px 14px; }
    .ai-messages-list { gap:24px; }
    .ai-msg-row { gap:9px; }
    .ai-input-bar { padding:12px 14px max(12px,env(safe-area-inset-bottom)) !important; }
    .ai-dock-left .ai-dock-link-btn:not(.ai-attachment-add) span { display:none; }
}
@media(prefers-reduced-motion:reduce) { .ai-assistant-drawer,.ai-thought-chevron { animation:none; transition:none; } }
