/* ===== AI 多配置选择器 ===== */
.ai-config-selector {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 14px;
}
.ai-config-selector select {
    flex: 1;
    padding: 8px 10px;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    font-size: 13px;
    background: #f8fafc;
    color: var(--text-main);
    cursor: pointer;
    transition: border-color 0.2s;
}
.ai-config-selector select:focus {
    border-color: var(--primary-color);
    outline: none;
}
.ai-config-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    background: #f8fafc;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    color: var(--text-secondary);
}
.ai-config-btn:hover {
    background: #e2e8f0;
    color: var(--text-main);
}
.ai-config-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.ai-config-btn-danger:hover:not(:disabled) {
    background: #fee2e2;
    border-color: #fca5a5;
    color: #dc2626;
}

/* 配置命名弹窗 */
.ai-config-name-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0.15s;
}
.ai-config-name-dialog {
    background: #fff;
    border-radius: 14px;
    padding: 22px 24px;
    width: 320px;
    max-width: 90vw;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.ai-config-name-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 14px;
}
.ai-config-name-input {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    font-size: 13px;
    background: #f8fafc;
    margin-bottom: 14px;
    transition: border-color 0.2s;
    box-sizing: border-box;
}
.ai-config-name-input:focus {
    border-color: var(--primary-color);
    outline: none;
}
.ai-config-name-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}
.ai-config-name-btn {
    padding: 8px 18px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.ai-config-name-btn.cancel {
    background: #f1f5f9;
    color: var(--text-secondary);
}
.ai-config-name-btn.cancel:hover {
    background: #e2e8f0;
}
.ai-config-name-btn.confirm {
    background: var(--primary-color);
    color: #fff;
}
.ai-config-name-btn.confirm:hover {
    filter: brightness(1.1);
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ===== AI配置 ===== */
.ai-input-field {
    margin-bottom: 12px;
}
.ai-input-field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 6px;
}
.ai-input-field input, .ai-input-field select {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    font-size: 13px;
    transition: 0.2s;
    background: #f8fafc;
}
.ai-model-input-wrap {
    position: relative;
}
.ai-model-input-wrap input {
    padding-right: 42px;
}
.ai-model-dropdown-toggle {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s;
}
.ai-model-dropdown-toggle:hover,
.ai-model-dropdown-toggle.active {
    background: #e2e8f0;
    color: var(--text-main);
}
.ai-model-dropdown {
    display: none;
    margin-top: 6px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    overflow: hidden;
}
.ai-model-dropdown.show {
    display: block;
}
.ai-model-dropdown-item {
    width: 100%;
    padding: 10px 12px;
    border: none;
    border-bottom: 1px solid #f1f5f9;
    background: #fff;
    text-align: left;
    font-size: 13px;
    color: var(--text-main);
    cursor: pointer;
    transition: background 0.2s;
}
.ai-model-dropdown-item:last-child {
    border-bottom: none;
}
.ai-model-dropdown-item:hover {
    background: #f8fafc;
}
.ai-model-dropdown-item.empty {
    color: var(--text-secondary);
    cursor: default;
}
.ai-input-field input:focus, .ai-input-field select:focus {
    outline: none;
    border-color: var(--primary-color);
    background: white;
    box-shadow: 0 0 0 3px rgba(78,110,242,0.1);
}
.ai-input-field input[type="password"] {
    font-family: monospace;
}
.ai-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}
.ai-status.connected {
    background: #d1fae5;
    color: #065f46;
}
.ai-status.disconnected {
    background: #fee2e2;
    color: #991b1b;
}

/* ===== AI出题模态框 ===== */
.ai-modal-overlay { z-index: 1500; }
.ai-modal-content {
    background: white;
    border-radius: 18px;
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    animation: scaleIn 0.3s;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.ai-prompt-area {
    width: 100%;
    min-height: 120px;
    padding: 12px;
    border: 1.5px solid #e2e8f0;
    border-radius: 12px;
    resize: vertical;
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 15px;
}
.ai-prompt-area:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(78,110,242,0.1);
}
.ai-result-box {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 15px;
    margin-top: 15px;
    max-height: 300px;
    overflow-y: auto;
    display: none;
}
.ai-result-box.show { display: block; }
.ai-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-secondary);
    font-size: 14px;
}
.ai-loading-spinner {
    width: 20px;
    height: 20px;
    border: 3px solid #e2e8f0;
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ===== AI 生成详情（流式输出） ===== */
.ai-stream-details {
    margin-top: 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
}
.ai-stream-summary {
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    background: #f1f5f9;
    transition: background 0.2s, color 0.2s;
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
}
.ai-stream-summary::-webkit-details-marker { display: none; }
.ai-stream-summary::before {
    content: '▶';
    font-size: 10px;
    transition: transform 0.2s;
}
details[open] > .ai-stream-summary::before {
    transform: rotate(90deg);
}
.ai-stream-summary:hover {
    background: #e2e8f0;
    color: var(--text-main);
}
.ai-stream-content {
    margin: 0;
    padding: 12px;
    font-size: 12px;
    line-height: 1.7;
    color: var(--text-main);
    background: #f8fafc;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 200px;
    overflow-y: auto;
    font-family: 'Menlo', 'Consolas', 'Monaco', monospace;
}

/* ===== AI历史记录 ===== */
.ai-history-section {
    margin-top: 30px;
    padding: 0 20px 20px;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}
.ai-history-toggle-btn {
    width: 100%;
    padding: 14px 20px;
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.ai-history-toggle-btn:hover {
    border-color: var(--primary-color);
    background: #f8fafc;
}
.ai-history-toggle-icon {
    font-size: 16px;
    transition: transform 0.3s;
}
.ai-history-toggle-btn.expanded .ai-history-toggle-icon {
    transform: rotate(180deg);
}
.ai-history-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}
.ai-history-content.expanded {
    max-height: 2000px;
}
.ai-history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 15px 0;
}
.ai-history-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-main);
}
.ai-history-clear-btn {
    padding: 6px 12px;
    background: #fee2e2;
    color: #991b1b;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: 0.2s;
}
.ai-history-clear-btn:hover {
    background: #fca5a5;
}
.ai-history-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.ai-history-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    font-size: 13px;
}
.ai-history-card {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 15px;
    transition: all 0.2s;
    cursor: pointer;
}
.ai-history-card:hover {
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(78,110,242,0.15);
    transform: translateY(-2px);
}
.ai-history-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
}
.ai-history-card-info {
    flex: 1;
}
.ai-history-card-model {
    font-size: 13px;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 4px;
}
.ai-history-card-meta {
    font-size: 11px;
    color: var(--text-secondary);
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}
.ai-history-card-preview {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 10px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ai-history-card-actions {
    display: flex;
    gap: 8px;
}
.ai-history-btn {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
}
.ai-history-btn-import {
    background: var(--primary-color);
    color: white;
}
.ai-history-btn-import:hover {
    background: var(--primary-hover);
}
.ai-history-btn-view {
    background: #f1f5f9;
    color: var(--text-secondary);
}
.ai-history-btn-view:hover {
    background: #e2e8f0;
    color: var(--text-main);
}
.ai-history-btn-delete {
    background: #fee2e2;
    color: #991b1b;
    flex: 0;
    padding: 8px 10px;
}
.ai-history-btn-delete:hover {
    background: #fca5a5;
}

/* ===== AI解析悬浮球 ===== */
.ai-analyze-fab {
    position: fixed;
    bottom: 76px;
    right: 24px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 100%);
    border: 1px solid #c7d2fe;
    box-shadow: 0 4px 15px rgba(79, 70, 229, 0.2);
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: box-shadow 0.2s, border-color 0.2s, transform 0.2s;
    z-index: 2000;
    user-select: none;
    touch-action: none;
    color: #4f46e5;
    font-size: 20px;
    font-weight: 700;
}
.ai-analyze-fab:hover {
    border-color: #818cf8;
    box-shadow: 0 8px 24px rgba(79, 70, 229, 0.28);
    transform: translateY(-1px);
}
.ai-analyze-fab.dragging {
    cursor: grabbing;
    opacity: 0.9;
    transition: none !important;
    will-change: transform;
}
.ai-analyze-fab.snapping {
    transition: right 0.3s ease, bottom 0.3s ease, box-shadow 0.2s, border-color 0.2s;
}

/* ===== AI解析对话窗口 ===== */
.ai-chat-panel {
    position: fixed;
    right: 78px;
    bottom: 76px;
    width: min(360px, calc(100vw - 24px));
    height: min(520px, calc(100vh - 120px));
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.16);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 1999;
}
.ai-chat-panel.active { display: flex; animation: scaleIn 0.2s ease; }
.ai-chat-header {
    height: 46px;
    padding: 0 12px;
    border-bottom: 1px solid #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    font-weight: 700;
    color: #312e81;
    background: linear-gradient(90deg, #eef2ff, #f8fafc);
    cursor: grab;
    user-select: none;
}
.ai-chat-panel.dragging {
    will-change: transform;
}
.ai-chat-panel.dragging .ai-chat-header {
    cursor: grabbing;
}
.ai-chat-close {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: 1px solid #dbeafe;
    background: #fff;
    color: #64748b;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    touch-action: auto;
    pointer-events: auto;
    position: relative;
    z-index: 1;
}
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.ai-chat-msg {
    max-width: 88%;
    font-size: 13px;
    line-height: 1.55;
    padding: 8px 10px;
    border-radius: 10px;
    white-space: pre-wrap;
    word-break: break-word;
}
.ai-chat-msg.user {
    margin-left: auto;
    color: #1e3a8a;
    background: #dbeafe;
    border: 1px solid #bfdbfe;
}
.ai-chat-msg.assistant {
    margin-right: auto;
    color: #334155;
    background: transparent;
    border: none;
    padding: 0;
    border-radius: 0;
}
.ai-chat-msg.loading {
    color: #64748b;
    font-style: italic;
}
.ai-chat-msg.markdown {
    white-space: normal;
}
.ai-chat-msg.streaming {
    min-height: 20px;
}
.streaming-cursor::after {
    content: '▍';
    display: inline;
    animation: ai-cursor-blink 0.6s steps(2) infinite;
    color: var(--primary-color, #6366f1);
    font-weight: bold;
}
@keyframes ai-cursor-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}
.ai-chat-msg.markdown h1,
.ai-chat-msg.markdown h2,
.ai-chat-msg.markdown h3,
.ai-chat-msg.markdown h4 {
    margin: 0 0 8px;
    line-height: 1.4;
    color: #0f172a;
}
.ai-chat-msg.markdown h3 { font-size: 14px; }
.ai-chat-msg.markdown p {
    margin: 0 0 8px;
    line-height: 1.65;
}
.ai-chat-msg.markdown hr {
    border: none;
    border-top: 1px dashed #cbd5e1;
    margin: 10px 0;
}
.ai-chat-msg.markdown ul {
    margin: 0 0 8px;
    padding-left: 18px;
}
.ai-chat-msg.markdown li {
    margin: 4px 0;
    line-height: 1.6;
}
.ai-chat-msg.markdown code {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 1px 5px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 12px;
}
.ai-chat-msg.markdown strong {
    color: #1e293b;
    font-weight: 700;
}
.ai-chat-footer {
    border-top: 1px solid #f1f5f9;
    padding: 10px;
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.ai-chat-quick {
    width: 100%;
    border: 1px solid #c7d2fe;
    background: #eef2ff;
    color: #4338ca;
    border-radius: 8px;
    padding: 7px 10px;
    font-size: 12px;
    cursor: pointer;
    font-weight: 600;
}
.ai-chat-input-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
.ai-chat-input {
    flex: 1;
    min-width: 0;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 13px;
    outline: none;
}
.ai-chat-input:focus {
    border-color: #818cf8;
    box-shadow: 0 0 0 3px rgba(99,102,241,0.12);
    background: #fff;
}
.ai-chat-send {
    border: none;
    background: var(--primary-color);
    color: #fff;
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 12px;
    cursor: pointer;
    font-weight: 700;
    white-space: nowrap;
}
.ai-chat-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ===== 数学公式渲染 ===== */
.math-inline {
    display: inline;
    vertical-align: baseline;
}
.math-inline .katex {
    font-size: 1em;
}
.math-block {
    display: block;
    text-align: center;
    margin: 8px 0;
    overflow-x: auto;
}
.math-block .katex-display {
    margin: 0;
}
.ai-chat-msg .math-block,
.ai-chat-msg .math-inline {
    color: inherit;
}
.option-item .katex,
#questionText .katex,
#analysisContent .katex {
    font-size: 1em;
}

/* ===== 自定义 AI Prompt 编辑区 ===== */
.ai-prompt-edit-block {
    margin-bottom: 14px;
}
.ai-prompt-edit-block:last-child {
    margin-bottom: 0;
}
.ai-prompt-edit-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-main);
    margin-bottom: 6px;
}
.ai-prompt-reset-btn {
    font-size: 12px;
    padding: 3px 10px;
    border: 1.5px solid #e2e8f0;
    border-radius: 6px;
    background: #f8fafc;
    color: var(--text-sub, #64748b);
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s, background 0.2s;
    line-height: 1.5;
}
.ai-prompt-reset-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: #eff6ff;
}
.ai-prompt-textarea {
    width: 100%;
    box-sizing: border-box;
    padding: 9px 11px;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    color: var(--text-main);
    background: #f8fafc;
    resize: vertical;
    min-height: 72px;
    line-height: 1.6;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}
.ai-prompt-textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.10);
    background: #fff;
}
.ai-prompt-hint {
    font-size: 11.5px;
    color: var(--text-sub, #94a3b8);
    margin-top: 5px;
    line-height: 1.5;
}
