/* 3099 题库编辑器 — 工具界面样式 */

:root {
    --bg: #eef2f7;
    --panel: #ffffff;
    --panel-2: #f7f9fc;
    --border: #d8e0ea;
    --border-strong: #c2cddb;
    --text: #22303c;
    --muted: #6b7c8f;
    --accent: #2f6fb4;
    --accent-2: #4c8fd8;
    --accent-soft: #e8f1fb;
    --danger: #d9534f;
    --danger-soft: #fdeceb;
    --warn: #b8860b;
    --warn-soft: #fff7e0;
    --ok: #3d8b40;
    --ok-soft: #eaf6ea;
    --radius: 10px;
    --shadow: 0 2px 10px rgba(28, 52, 84, 0.08);
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
}

body {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    overflow: hidden;
}

button {
    font: inherit;
    color: inherit;
    background: #fff;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .05s;
}

button:hover { background: var(--accent-soft); border-color: var(--accent-2); }
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-2); }
button.danger { color: var(--danger); border-color: #ecc4c2; }
button.danger:hover { background: var(--danger-soft); }
button.link { border: none; background: none; color: var(--accent); padding: 0 2px; text-decoration: underline; }
button.wide { width: 100%; }
button.accent { color: var(--accent); }

input[type="text"], select, textarea {
    font: inherit;
    color: inherit;
    background: #fff;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    padding: 6px 8px;
    width: 100%;
}

input[type="text"]:focus, select:focus, textarea:focus {
    outline: 2px solid var(--accent-soft);
    border-color: var(--accent-2);
}

.muted { color: var(--muted); font-size: 12px; }

/* ---------------- 顶栏 ---------------- */

.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 16px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    z-index: 5;
    flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand .logo { font-size: 22px; }
.brand .ver { color: var(--muted); font-size: 12px; margin-left: 6px; }

.meta-inputs { display: flex; gap: 8px; flex: 1 1 320px; min-width: 240px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.pill {
    display: inline-block;
    min-width: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 11px;
    text-align: center;
}

.pill.has-error { background: var(--danger-soft); color: var(--danger); }

/* ---------------- 三栏工作区 ---------------- */

.workspace {
    display: grid;
    grid-template-columns: 268px minmax(420px, 1fr) minmax(400px, 1.05fr);
    gap: 12px;
    padding: 12px;
    min-height: 0;
    overflow: hidden;
}

.sidebar, .editor, .preview {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.sidebar-head, .editor-head, .preview-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--panel-2);
    font-weight: 600;
}

.sidebar-foot { padding: 10px 12px; border-top: 1px solid var(--border); }

/* 题目列表 */
.question-list {
    list-style: none;
    margin: 0;
    padding: 8px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.question-item {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    padding: 8px;
    margin-bottom: 6px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}

.question-item:hover { background: var(--panel-2); }
.question-item.active { border-color: var(--accent-2); background: var(--accent-soft); }
.question-item.dragging { opacity: .4; }
.question-item.drop-target { border-top: 3px solid var(--accent); }

.question-item .num {
    flex: 0 0 24px;
    height: 24px;
    border-radius: 6px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.question-item .body { flex: 1; min-width: 0; }
.question-item .snippet {
    font-size: 12.5px;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
}
.question-item .tags { margin-top: 4px; display: flex; gap: 4px; flex-wrap: wrap; }

.badge {
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 6px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--muted);
}
.badge.ans { background: var(--ok-soft); color: var(--ok); border-color: #c5e3c6; }
.badge.img { background: var(--accent-soft); color: var(--accent); border-color: #c8ddf3; }
.badge.err { background: var(--danger-soft); color: var(--danger); border-color: #ecc4c2; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: #eadfb8; }

/* 编辑器 */
.editor { overflow: hidden; }
.editor > *:not(.editor-head) { padding-left: 12px; padding-right: 12px; }
.editor-head { padding-right: 12px; }
.q-index-label { font-weight: 600; }
.q-actions { display: flex; gap: 6px; }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    padding: 8px 12px !important;
    border-bottom: 1px solid var(--border);
    background: var(--panel-2);
}

.toolbar button { padding: 4px 8px; font-size: 13px; }
.toolbar .sep { width: 1px; height: 18px; background: var(--border-strong); margin: 0 4px; }
.active-field-hint { margin-left: auto; font-size: 12px; color: var(--muted); }

.editor-scroll, .editor { overflow-y: auto; }
.editor { padding-bottom: 12px; }

.field-group { margin-top: 10px; }
.field-label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    font-size: 12.5px;
    font-weight: 600;
    color: #35485a;
    margin-bottom: 4px;
}

textarea.md-input {
    resize: vertical;
    min-height: 64px;
    line-height: 1.5;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 13px;
}

textarea.compact { min-height: 44px; }

.options-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

.option-label { display: flex; align-items: center; gap: 8px; }
.option-label .letter {
    width: 20px; height: 20px; border-radius: 5px;
    background: var(--accent-soft); color: var(--accent);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700;
}
.option-label .ans-pick { margin-left: auto; font-weight: 400; font-size: 12px; color: var(--muted); }
.option-label .ans-pick input { vertical-align: -2px; }
.option-label.correct .letter { background: var(--ok); color: #fff; }

.field-row { display: grid; grid-template-columns: 1fr 180px; gap: 12px; }
.field-row .narrow { display: flex; flex-direction: column; gap: 4px; }

/* 预览 */
.preview-scroll { flex: 1; overflow: auto; background: #e9eef5; padding: 12px; min-height: 0; }
.preview-body { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.preview-foot { padding: 8px 12px; border-top: 1px solid var(--border); }

.preview-frame {
    width: 100%;
    background: #f7f7f7e6;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .12);
    padding: 20px;
    display: flex;
    justify-content: center;
}

.preview-frame.game-width { width: 100%; }
.preview-note { font-size: 11px; color: var(--muted); text-align: center; }

/* ---------------- 状态栏 ---------------- */

.statusbar {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 16px;
    background: var(--panel);
    border-top: 1px solid var(--border);
    font-size: 12.5px;
    color: #40566b;
}

/* ---------------- 模态框 ---------------- */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(20, 35, 52, .45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    padding: 24px;
}

.modal[hidden] { display: none; }

.modal-card {
    background: var(--panel);
    border-radius: 12px;
    box-shadow: 0 18px 50px rgba(16, 32, 50, .3);
    width: min(720px, 100%);
    max-height: 86vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-card.wide-modal { width: min(980px, 100%); }

.modal-head, .modal-foot {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.modal-foot { border-bottom: none; border-top: 1px solid var(--border); justify-content: flex-end; }
.modal-foot .muted { margin-right: auto; }
.modal-head b { font-size: 15px; }
.modal-close { margin-left: auto; border: none; background: none; font-size: 20px; line-height: 1; padding: 0 4px; color: var(--muted); }
.modal-body { padding: 14px 16px; overflow-y: auto; }

.issue {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    padding: 8px 10px;
    border-radius: 8px;
    margin-bottom: 6px;
    border: 1px solid var(--border);
    cursor: pointer;
    background: #fff;
}
.issue:hover { border-color: var(--accent-2); }
.issue.error { background: var(--danger-soft); border-color: #ecc4c2; }
.issue.warning { background: var(--warn-soft); border-color: #eadfb8; }
.issue .kind { flex: 0 0 auto; font-size: 11px; padding: 1px 6px; border-radius: 6px; background: #fff; border: 1px solid var(--border); }
.issue.ok { background: var(--ok-soft); border-color: #c5e3c6; }

/* 资源管理 */
.dropzone {
    border: 2px dashed var(--border-strong);
    border-radius: 10px;
    padding: 16px;
    text-align: center;
    color: var(--muted);
    margin-bottom: 14px;
    background: var(--panel-2);
}
.dropzone.hover { border-color: var(--accent-2); background: var(--accent-soft); color: var(--accent); }

.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 12px; }

.asset-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
    display: flex;
    flex-direction: column;
}

.asset-card .thumb {
    height: 104px;
    background: repeating-conic-gradient(#f0f3f7 0% 25%, #fff 0% 50%) 50% / 16px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.asset-card .thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.asset-card .thumb .missing { color: var(--danger); font-size: 12px; text-align: center; padding: 8px; }
.asset-card .info { padding: 8px; font-size: 12px; display: flex; flex-direction: column; gap: 3px; }
.asset-card .name { word-break: break-all; font-weight: 600; }
.asset-card .row { display: flex; gap: 6px; }
.asset-card .row button { flex: 1; padding: 3px 6px; font-size: 12px; }

.help-body h3 { margin: 16px 0 6px; font-size: 14px; }
.help-body h3:first-child { margin-top: 0; }
.help-body code, .help-body kbd {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 1px 5px;
    font-size: 12px;
}
.help-body ul { margin: 6px 0; padding-left: 20px; line-height: 1.7; }
.help-body table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 13px; }
.help-body th, .help-body td { border: 1px solid var(--border); padding: 5px 8px; text-align: left; }
.help-body th { background: var(--panel-2); }

/* toast */
.toast-host {
    position: fixed;
    right: 16px;
    bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 100;
    pointer-events: none;
}

.toast {
    background: #22303c;
    color: #fff;
    padding: 9px 14px;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
    max-width: 420px;
    font-size: 13px;
    line-height: 1.45;
    animation: toast-in .18s ease-out;
    pointer-events: auto;
}
.toast.ok { background: #2f6b33; }
.toast.error { background: #a3312d; }
.toast.warn { background: #8a6100; }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

/* 窄屏回退 */
@media (max-width: 1280px) {
    .workspace { grid-template-columns: 220px minmax(360px, 1fr) minmax(340px, 1fr); }
    .options-grid { grid-template-columns: 1fr; }
    .field-row { grid-template-columns: 1fr; }
}

/* ---------------- 图形化公式编辑器 ---------------- */

#modal-math { align-items: flex-start; }

.math-modal {
    width: min(920px, 100%);
    margin-top: 18px;
    /* 底部要给 MathLive 虚拟键盘留出空间 */
    max-height: min(62vh, calc(100vh - 300px));
    min-height: 320px;
}

.math-modes {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 10px;
    font-size: 13px;
}

.math-modes .spacer { flex: 1; }
.math-modes code { background: var(--panel-2); border: 1px solid var(--border); border-radius: 5px; padding: 0 5px; }

.math-field-wrap {
    border: 2px solid var(--accent-2);
    border-radius: 10px;
    background: #fff;
    padding: 10px 14px;
    min-height: 76px;
    display: flex;
    align-items: center;
}

.math-field-wrap math-field {
    width: 100%;
    font-size: 1.5rem;
    border: none;
    outline: none;
    background: transparent;
}

.math-fallback {
    color: var(--warn);
    background: var(--warn-soft);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 12.5px;
    width: 100%;
}

.math-section-title {
    font-size: 12px;
    color: var(--muted);
    margin: 12px 0 5px;
    font-weight: 600;
}

.math-structures, .math-palette { display: flex; flex-wrap: wrap; gap: 5px; }
.math-structures button { font-size: 12.5px; padding: 4px 9px; }
.math-palette button { min-width: 34px; padding: 3px 6px; font-size: 15px; line-height: 1.2; }

.math-preview {
    border: 1px dashed var(--border-strong);
    border-radius: 10px;
    background: #fff;
    padding: 14px;
    min-height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-x: auto;
    font-size: 1.4em;
    color: #333;
}

.math-error {
    margin-top: 8px;
    color: var(--danger);
    background: var(--danger-soft);
    border: 1px solid #ecc4c2;
    border-radius: 8px;
    padding: 7px 10px;
    font-size: 12.5px;
    line-height: 1.5;
}

.math-source { margin-top: 10px; }
.math-source summary { cursor: pointer; font-size: 12.5px; color: var(--muted); }
.math-source textarea { margin-top: 6px; }

/* 预览里可点击编辑的公式 */
.math-edit {
    cursor: pointer;
    border-radius: 5px;
    transition: background .15s, box-shadow .15s;
}

.math-edit:hover {
    background: rgba(76, 143, 216, .16);
    box-shadow: 0 0 0 1px var(--accent-2);
}

/* ---------------- TXT 简单模式导入 ---------------- */

.txt-hint {
    background: var(--accent-soft);
    border: 1px solid #c8ddf3;
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 12.5px;
    line-height: 1.7;
    margin-bottom: 10px;
}

.txt-hint code {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 1px 5px;
    margin: 0 1px;
}

.txt-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    font-size: 12.5px;
    margin-bottom: 8px;
}

.txt-toolbar .spacer { flex: 1; }
.txt-toolbar label { display: inline-flex; align-items: center; gap: 5px; }
.txt-toolbar select { width: auto; }

#txt-input {
    min-height: 190px;
    font-family: "SFMono-Regular", Consolas, Menlo, monospace;
    font-size: 12.5px;
    line-height: 1.6;
}

.txt-summary { margin: 10px 0 6px; font-size: 13px; }
.txt-bad { color: var(--danger); font-weight: 600; }
.txt-warn { color: var(--warn); font-weight: 600; }

.txt-issue {
    font-size: 12.5px;
    padding: 5px 9px;
    border-radius: 7px;
    margin-bottom: 4px;
    border: 1px solid var(--border);
}

.txt-issue.error { background: var(--danger-soft); border-color: #ecc4c2; color: #8d2f2b; }
.txt-issue.warning { background: var(--warn-soft); border-color: #eadfb8; color: #7a5600; }

.txt-preview {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 10px;
    margin-top: 6px;
}

.txt-q {
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 9px 11px;
    background: var(--panel-2);
    font-size: 12.5px;
}

.txt-q-head { font-weight: 600; margin-bottom: 5px; display: flex; align-items: center; gap: 6px; }
.txt-q-stem { margin-bottom: 5px; word-break: break-word; }
.txt-opt { padding: 1px 0; color: #3c4d5e; word-break: break-word; }
.txt-opt.is-answer { color: var(--ok); font-weight: 600; }

/* ---------------- AI 分析 ---------------- */

#modal-ai { align-items: center; }

.ai-modal {
    width: min(1240px, 100%);
    max-height: 90vh;
    height: 90vh;
}

.ai-body {
    display: grid;
    grid-template-columns: 360px minmax(0, 1fr);
    gap: 16px;
    padding: 14px 16px;
    min-height: 0;
    overflow: hidden;
}

.ai-col-left, .ai-col-right {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow-y: auto;
    gap: 6px;
}

.ai-col-right { overflow: hidden; }

.ai-section-title {
    font-size: 12px;
    font-weight: 700;
    color: #35485a;
    margin: 10px 0 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.ai-col-left .ai-section-title:first-child, .ai-col-right .ai-section-title:first-child { margin-top: 0; }

.ai-sources { display: flex; gap: 6px; flex-wrap: wrap; }
.ai-sources button { font-size: 12.5px; padding: 5px 9px; }

.dropzone.small { padding: 10px; font-size: 12.5px; margin: 6px 0; }

.ai-docinfo {
    font-size: 12.5px;
    color: #35485a;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 6px 9px;
    margin: 4px 0;
    word-break: break-all;
    min-height: 0;
}
.ai-docinfo:empty { display: none; }

#ai-text { min-height: 120px; font-size: 12.5px; }

.ai-field { display: block; font-size: 12.5px; color: #35485a; margin-top: 6px; }
.ai-field input, .ai-field select { margin-top: 3px; }
.ai-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ai-checks { display: flex; gap: 14px; margin-top: 8px; font-size: 12.5px; }
.ai-privacy { margin-top: 8px; line-height: 1.5; }

/* 步骤时间线 */
.ai-steps {
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--panel-2);
    padding: 6px 8px;
    max-height: 178px;
    overflow-y: auto;
    flex: 0 0 auto;
}

.ai-step {
    display: flex;
    gap: 8px;
    align-items: baseline;
    font-size: 12.5px;
    padding: 3px 2px;
    border-bottom: 1px dashed #e3e9f1;
}
.ai-step:last-child { border-bottom: none; }
.ai-step-icon { flex: 0 0 14px; text-align: center; }
.ai-step.pending { color: var(--muted); }
.ai-step.running { color: var(--accent); font-weight: 600; }
.ai-step.running .ai-step-icon { animation: ai-spin 1s linear infinite; display: inline-block; }
.ai-step.done { color: #2f6b33; }
.ai-step.error { color: var(--danger); }
.ai-step.skip { color: var(--warn); }
.ai-step-body { display: flex; gap: 8px; flex-wrap: wrap; }
.ai-step-meta { color: var(--muted); font-size: 11.5px; }

@keyframes ai-spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }

/* 流式输出 */
.ai-stream {
    margin: 0;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: #fbfcfe;
    padding: 8px 10px;
    font: 12px/1.55 "SFMono-Regular", Consolas, Menlo, monospace;
    white-space: pre-wrap;
    word-break: break-word;
    height: 150px;
    overflow-y: auto;
    flex: 0 0 auto;
}

.ai-reasoning { flex: 0 0 auto; }
.ai-reasoning summary { cursor: pointer; font-size: 12px; color: var(--muted); }
.ai-reasoning pre {
    max-height: 110px;
    overflow: auto;
    background: #fbfcfe;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 7px 9px;
    font: 11.5px/1.5 monospace;
    white-space: pre-wrap;
    margin: 5px 0 0;
}

/* 结果 */
.ai-result { flex: 1 1 auto; overflow-y: auto; min-height: 80px; }
.ai-result-head { font-size: 13px; margin-bottom: 6px; }

.ai-note {
    font-size: 12.5px;
    border-radius: 7px;
    padding: 6px 9px;
    margin-bottom: 5px;
    background: var(--accent-soft);
    border: 1px solid #c8ddf3;
}
.ai-note.warn { background: var(--warn-soft); border-color: #eadfb8; color: #7a5600; }
.ai-note.error { background: var(--danger-soft); border-color: #ecc4c2; color: #8d2f2b; }

.ai-qlist { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }

.ai-q {
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 9px 11px;
    background: #fff;
    font-size: 13px;
}
.ai-q-head { font-weight: 600; margin-bottom: 5px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.ai-q-stem { margin-bottom: 6px; }
.ai-q-stem img, .ai-opt img { max-width: 100%; max-height: 120px; border-radius: 5px; }
.ai-opt { padding: 2px 0; color: #3c4d5e; }
.ai-opt.is-answer { color: var(--ok); font-weight: 600; }
.ai-q .katex { font-size: 1.02em; }

.ai-issue {
    border-radius: 8px;
    padding: 7px 10px;
    margin-bottom: 6px;
    font-size: 12.5px;
    border: 1px solid var(--border);
    background: #fff;
}
.ai-issue.error { background: var(--danger-soft); border-color: #ecc4c2; }
.ai-issue.warning { background: var(--warn-soft); border-color: #eadfb8; }
.ai-issue-head { font-weight: 600; margin-bottom: 2px; }

@media (max-width: 1100px) {
    .ai-body { grid-template-columns: 1fr; overflow-y: auto; }
    .ai-modal { height: auto; }
}

/* ---------------- 多智能体 · 规划视图 ---------------- */

.ai-advanced { margin-top: 8px; font-size: 12.5px; }
.ai-advanced summary { cursor: pointer; color: var(--muted); }
.ai-advanced > *:not(summary) { margin-top: 6px; }
.ai-advanced button { font-size: 12px; padding: 3px 8px; }

select.spaced { margin-top: 6px; }

.ai-plan-toolbar {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 8px;
    position: sticky;
    top: 0;
    z-index: 3;
    background: var(--panel);
    padding: 2px 0 8px;
    border-bottom: 1px solid var(--border);
}
.ai-plan-toolbar button { font-size: 12.5px; padding: 5px 9px; }
.ai-plan-foot { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.ai-plan-foot button { font-size: 12.5px; }

.ai-plan { flex: 1 1 auto; overflow-y: auto; min-height: 100px; }

.plan-head {
    font-size: 13px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}

.plan-derive {
    margin: 0 0 8px;
    padding-left: 20px;
    font-size: 12.5px;
    line-height: 1.85;
    color: #3c4d5e;
}
.plan-derive b { color: var(--accent); }

.plan-verdict {
    font-size: 12.5px;
    border-radius: 8px;
    padding: 7px 10px;
    background: var(--accent-soft);
    border: 1px solid #c8ddf3;
    margin-bottom: 8px;
    line-height: 1.6;
}
.plan-verdict.warn { background: var(--warn-soft); border-color: #eadfb8; color: #7a5600; }

.plan-totals {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
    gap: 6px;
    margin-bottom: 8px;
}

.plan-stat {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 8px;
}
.plan-stat-label { font-size: 11px; color: var(--muted); }
.plan-stat-value { font-size: 13px; font-weight: 600; }

.plan-chunks { display: flex; flex-direction: column; gap: 5px; }

.plan-chunk {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    font-size: 12.5px;
}
.plan-chunk.excluded { opacity: .5; background: var(--panel-2); }
.plan-chunk-main { display: flex; align-items: center; gap: 8px; padding: 6px 9px; flex-wrap: wrap; }
.plan-chunk-no { font-weight: 700; color: var(--accent); flex: 0 0 auto; }
.plan-chunk-meta { color: var(--muted); font-size: 11.5px; }
.plan-chunk-actions { margin-left: auto; display: flex; gap: 5px; }
.plan-chunk-actions button { font-size: 11.5px; padding: 2px 7px; }

.plan-chunk-prompt { border-top: 1px dashed var(--border); padding: 8px 10px; background: #fbfcfe; }
.plan-chunk-prompt pre {
    margin: 4px 0 8px;
    max-height: 200px;
    overflow: auto;
    font: 11.5px/1.55 monospace;
    white-space: pre-wrap;
    word-break: break-word;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 7px 9px;
}
.plan-prompt-label { font-size: 11px; color: var(--muted); font-weight: 600; }

/* 预算四路约束表 */
.plan-limits {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel-2);
    padding: 4px 8px;
    margin-bottom: 6px;
}
.limit-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-size: 12px;
    padding: 3px 0;
    border-bottom: 1px dashed #e3e9f1;
    color: var(--muted);
}
.limit-row:last-child { border-bottom: none; }
.limit-row .limit-name { flex: 0 0 108px; }
.limit-row .limit-expr { flex: 1 1 auto; font-family: Consolas, Menlo, monospace; font-size: 11.5px; }
.limit-row .limit-val { flex: 0 0 auto; font-variant-numeric: tabular-nums; }
.limit-row.binding { color: var(--accent); font-weight: 600; }
.limit-row.binding .limit-tag {
    flex: 0 0 auto;
    font-size: 10.5px;
    background: var(--accent-soft);
    border-radius: 5px;
    padding: 0 5px;
}
.plan-final { font-size: 12.5px; margin-bottom: 8px; }

/* ---------------- 执行（Filter）与缺陷确认 ---------------- */

#ai-plan-exec { margin-top: 10px; }
#ai-exec-stream { height: 120px; }
#ai-plan-result { margin-top: 10px; }

.plan-chunk.running { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-soft) inset; }
.plan-chunk.done { border-color: #bcd9be; }
.plan-chunk.error { border-color: #ecc4c2; background: var(--danger-soft); }
.plan-chunk.skipped { opacity: .55; }
.plan-chunk-status { font-size: 11.5px; color: var(--muted); }
.plan-chunk.done .plan-chunk-status { color: var(--ok); }
.plan-chunk.error .plan-chunk-status { color: var(--danger); }
.plan-chunk.running .plan-chunk-status { color: var(--accent); font-weight: 600; }

.modal-card.narrow { width: min(760px, 100%); max-height: 84vh; }

.defects-toolbar { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.defects-toolbar button { font-size: 12.5px; padding: 4px 9px; }

.defect-item {
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 9px 11px;
    margin-bottom: 7px;
    background: #fff;
}
.defect-item.drop { opacity: .45; background: var(--panel-2); }
.defect-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.defect-head .badge.error { background: var(--danger-soft); border-color: #ecc4c2; color: #8d2f2b; }
.defect-head .badge.warning { background: var(--warn-soft); border-color: #eadfb8; color: #7a5600; }
.defect-head .badge.info { background: var(--accent-soft); border-color: #c8ddf3; }
.defect-msg { font-size: 12.5px; }
.defect-excerpt {
    font: 11.5px/1.5 monospace;
    background: #fbfcfe;
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 6px 8px;
    margin: 5px 0;
    white-space: pre-wrap;
    max-height: 110px;
    overflow: auto;
}
.defect-stem { font-size: 12.5px; color: #3c4d5e; margin: 4px 0; }
.review-choice-diff { margin: 8px 0; padding: 8px 10px; border-left: 2px solid var(--accent); background: var(--panel-2); font-size: 12px; line-height: 1.6; overflow-wrap: anywhere; }
.review-choice-diff > div + div { margin-top: 4px; }
.review-choice-diff del, .review-choice-diff ins { white-space: pre-wrap; }
.defect-actions { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.defect-actions button { font-size: 12px; padding: 3px 10px; }
.defect-actions button:disabled { opacity: .45; cursor: not-allowed; }
.defect-actions button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.defect-actions button.on.drop { background: var(--danger); border-color: var(--danger); }

/* 缺陷确认是从 AI 面板里弹出的二级弹窗，必须盖在 #modal-ai 之上 */
#modal-defects { z-index: 60; }


/* ---------------- 审查与纠错（diff） ---------------- */

.ai-check {
    display: flex;
    gap: 7px;
    align-items: flex-start;
    margin-top: 9px;
    font-size: 12.5px;
    line-height: 1.5;
    cursor: pointer;
    padding: 7px 9px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel-2);
}
.ai-check input { margin-top: 2px; flex: 0 0 auto; }
.ai-check .muted { display: block; font-size: 11.5px; }

/* 审查结果卡片 */
.q-review {
    margin-top: 8px;
    border-top: 1px dashed var(--border);
    padding-top: 7px;
}
.q-review-head { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; margin-bottom: 5px; }
.q-review-verdict { font-size: 11.5px; font-weight: 700; }
.q-review-verdict.ok { color: var(--ok); }
.q-review-verdict.bad { color: var(--danger); }
.q-review-verdict.warn { color: var(--warn); }
.q-review-reason { font-size: 11.5px; color: var(--muted); }

.q-review-issue {
    font-size: 12px;
    border-left: 3px solid var(--border);
    padding: 4px 8px;
    margin: 4px 0;
    background: var(--panel-2);
    border-radius: 0 6px 6px 0;
}
.q-review-issue.error { border-left-color: var(--danger); }
.q-review-issue.warning { border-left-color: var(--warn); }
.q-review-field { font-weight: 600; color: #35485a; }

/* diff 展示 */
.q-diff {
    margin: 6px 0 4px;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    font-size: 12.5px;
}
.q-diff-row { display: flex; gap: 0; border-bottom: 1px solid var(--border); }
.q-diff-row:last-child { border-bottom: none; }
.q-diff-label {
    flex: 0 0 74px;
    background: var(--panel-2);
    padding: 5px 8px;
    font-size: 11px;
    color: var(--muted);
    border-right: 1px solid var(--border);
}
.q-diff-body { flex: 1 1 auto; padding: 5px 9px; line-height: 1.65; word-break: break-word; }
.q-diff-body .katex { font-size: 1em; }

.df-del {
    background: #fdeceb;
    color: #8d2f2b;
    text-decoration: line-through;
    border-radius: 2px;
    padding: 0 1px;
}
.df-ins {
    background: #e6f4e7;
    color: #2f6b33;
    text-decoration: none;
    border-radius: 2px;
    padding: 0 1px;
    font-weight: 600;
}
.df-same { color: #55677a; }

.q-diff-actions { display: flex; gap: 6px; margin: 5px 0 2px; flex-wrap: wrap; }
.q-diff-actions button { font-size: 11.5px; padding: 2px 9px; }
.q-diff-actions button.primary { font-size: 11.5px; padding: 3px 10px; }

.answer-missing-badge {
    font-size: 11px;
    background: var(--warn-soft);
    border: 1px solid #eadfb8;
    color: #7a5600;
    border-radius: 5px;
    padding: 0 5px;
}

/* 执行时审查进度 */
.review-stat { font-size: 11.5px; color: var(--muted); }
