/* ============================================================
   BAILU Agent Studio — editor.css
   Agent 编辑器：三栏布局 / 提示词列 / 配置卡片 / 工具与知识库
   ============================================================ */

.editor {
    height: 100%;
    display: grid;
    grid-template-columns: minmax(340px, 420px) minmax(320px, 384px) minmax(420px, 1fr);
    gap: 0;
    animation: fade-in var(--t-slow) var(--ease);
    background: var(--bg);
}

.editor-col {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--bg);
}

.editor-col:last-child {
    border-right: none;
}

.editor-col-head {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    height: 46px;
    padding: 0 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-glass);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    /* backdrop-filter 已创建层叠上下文，但缺省 z-index 时向下弹出的 tooltip
       会整体落入列身区域、被其后绘制的内容背景盖住（顶栏靠 z-index:50 避开）。
       抬升到 5：高于列身普通内容，低于悬浮按钮(20)/运行详情抽屉(40)。 */
    position: relative;
    z-index: 5;
}

.editor-col-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.01em;
    color: var(--text);
}

.editor-col-title .icon {
    width: 15px;
    height: 15px;
    color: var(--primary);
}

.editor-col-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* ------- 左列：提示词 ------- */
.prompt-col .editor-col-body {
    padding: 0;
    gap: 0;
}

.prompt-textarea-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    position: relative;
}

.prompt-textarea {
    flex: 1;
    width: 100%;
    border: none;
    resize: none;
    padding: 18px 18px 48px;
    background: transparent;
    font-size: 13.5px;
    line-height: 1.8;
    color: var(--text);
    outline: none;
    min-height: 0;
    /* 高于变量高亮覆盖层：文字由 textarea 渲染，色块在其下方透出 */
    position: relative;
    z-index: 1;
}

.prompt-textarea::placeholder {
    color: var(--text-3);
}

/* 变量高亮覆盖层：与 textarea 同字体/行高/内边距重排同一份文本，只给变量画色块。
   字号、行高、内边距与宽高全部由 JS 从 textarea 的计算样式同步（见 ui/editor.js
   的 syncHlBox），下面几条只是 JS 接管前的初值，改动无需与 textarea 对齐。 */
.prompt-hl {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
    box-sizing: border-box;
    padding: 18px 18px 48px;
    font-size: 13.5px;
    line-height: 1.8;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    overflow: hidden;
    color: transparent;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
}

.pv-mark {
    color: transparent;
    background: var(--pv-soft);
    border-radius: 4px;
    /* 外扩阴影把色块撑到接近行高：padding/border 会改变文字排版，只能用阴影 */
    box-shadow: 0 0 0 2.5px var(--pv-soft), 0 0 0 3.5px var(--pv-line);
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

.prompt-meta {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    font-size: 11.5px;
    color: var(--text-3);
    background: linear-gradient(to top, var(--bg) 55%, transparent);
    pointer-events: none;
}

.prompt-tips {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    flex: none;
}

/* ------- 动态变量：变量栏 / 高亮色块 / 悬浮说明 共用配色 -------
   每个变量一个色档，变量栏芯片、提示词里的色块、悬浮卡片的 token 用同一档，
   便于一眼对上号（新增变量时同步补一档，见 js/prompt-vars.js 的 color 字段） */
.pv-c0 {
    --pv-ink: #0b6cf2;
    --pv-soft: rgba(11, 108, 242, 0.12);
    --pv-line: rgba(11, 108, 242, 0.3);
}

.pv-c1 {
    --pv-ink: #0d8f86;
    --pv-soft: rgba(13, 143, 134, 0.13);
    --pv-line: rgba(13, 143, 134, 0.32);
}

.pv-c2 {
    --pv-ink: #7c50e6;
    --pv-soft: rgba(124, 80, 230, 0.13);
    --pv-line: rgba(124, 80, 230, 0.3);
}

.pv-c3 {
    --pv-ink: #c07310;
    --pv-soft: rgba(192, 115, 16, 0.14);
    --pv-line: rgba(192, 115, 16, 0.32);
}

.pv-c4 {
    --pv-ink: #15955e;
    --pv-soft: rgba(21, 149, 94, 0.13);
    --pv-line: rgba(21, 149, 94, 0.3);
}

[data-theme="dark"] .pv-c0 {
    --pv-ink: #74acff;
    --pv-soft: rgba(61, 139, 255, 0.2);
    --pv-line: rgba(61, 139, 255, 0.42);
}

[data-theme="dark"] .pv-c1 {
    --pv-ink: #3fd3c2;
    --pv-soft: rgba(63, 211, 194, 0.17);
    --pv-line: rgba(63, 211, 194, 0.38);
}

[data-theme="dark"] .pv-c2 {
    --pv-ink: #b394ff;
    --pv-soft: rgba(179, 148, 255, 0.19);
    --pv-line: rgba(179, 148, 255, 0.4);
}

[data-theme="dark"] .pv-c3 {
    --pv-ink: #edad4e;
    --pv-soft: rgba(237, 173, 78, 0.18);
    --pv-line: rgba(237, 173, 78, 0.4);
}

[data-theme="dark"] .pv-c4 {
    --pv-ink: #45d193;
    --pv-soft: rgba(69, 209, 147, 0.17);
    --pv-line: rgba(69, 209, 147, 0.38);
}

/* 变量栏：点击把 {time} 等占位符插入提示词光标处 */
.prompt-vars {
    flex: none;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 9px 14px 10px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.prompt-vars-label {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 3px;
    font-size: 11.5px;
    color: var(--text-3);
    cursor: help;
    transition: color var(--t-fast) var(--ease);
}

.prompt-vars-label:hover {
    color: var(--text-2);
}

.prompt-vars-label .icon {
    width: 12px;
    height: 12px;
    color: var(--primary);
}

/* 换行而不是横向滚动：五个芯片在窄列里必须全部可见（滚动会把末尾的截断） */
.prompt-vars-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-width: 0;
}

.prompt-var-chip {
    flex: none;
    padding: 3px 9px;
    border: 1px solid var(--pv-line);
    border-radius: 999px;
    background: var(--pv-soft);
    color: var(--pv-ink);
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.55;
    cursor: pointer;
    transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}

.prompt-var-chip:hover {
    box-shadow: 0 0 0 3px var(--pv-soft);
}

.prompt-var-chip:active {
    transform: translateY(0) scale(0.96);
}

.prompt-var-chip:focus-visible {
    outline: 2px solid var(--pv-ink);
    outline-offset: 2px;
}

/* 变量悬浮说明：多行卡片，挂在 body 上按锚点定位（列身是滚动容器，会裁掉浮层） */
.var-pop {
    position: fixed;
    z-index: 260;
    max-width: 268px;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-pop);
    font-size: 12px;
    line-height: 1.65;
    color: var(--text-2);
    pointer-events: none;
    animation: scale-in 0.14s var(--ease);
    transform-origin: bottom center;
}

.var-pop.below {
    transform-origin: top center;
}

.var-pop-head {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 7px;
    margin-bottom: 7px;
}

.var-pop-token {
    padding: 1px 7px;
    border: 1px solid var(--pv-line);
    border-radius: 6px;
    background: var(--pv-soft);
    color: var(--pv-ink);
    font-family: var(--font-mono);
    font-size: 11.5px;
}

.var-pop-desc {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
}

.var-pop-title {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    font-weight: 700;
    color: var(--text);
}

.var-pop-title .icon {
    width: 13px;
    height: 13px;
    color: var(--primary);
}

.var-pop-text b {
    font-weight: 600;
    color: var(--text);
}

.var-pop-value {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 6px 9px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.var-pop-k {
    flex: none;
    font-size: 11px;
    color: var(--text-3);
}

.var-pop-v {
    font-family: var(--font-mono);
    font-size: 11.5px;
    color: var(--text);
    word-break: break-all;
}

.var-pop-foot {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 7px;
    font-size: 11px;
    color: var(--text-3);
}

.var-pop-foot .icon {
    width: 12px;
    height: 12px;
}

/* ------- 中列：配置区块 ------- */
.cfg-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-1);
    overflow: hidden;
    flex: none;
}

.cfg-card-head {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 13px 16px;
    cursor: pointer;
    user-select: none;
    transition: background var(--t-fast) var(--ease);
}

.cfg-card-head:hover {
    background: var(--surface-2);
}

.cfg-card-head .icon-title {
    width: 26px;
    height: 26px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-soft);
    color: var(--primary);
    flex: none;
}

.cfg-card-head .icon-title .icon {
    width: 14px;
    height: 14px;
}

.cfg-card-title {
    font-size: 13.5px;
    font-weight: 650;
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.cfg-card-title .badge {
    font-weight: 550;
}

.cfg-card-chevron {
    color: var(--text-3);
    transition: transform var(--t) var(--ease);
}

.cfg-card.collapsed .cfg-card-chevron {
    transform: rotate(-90deg);
}

.cfg-card-body {
    padding: 2px 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.cfg-card.collapsed .cfg-card-body {
    display: none;
}

.cfg-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* 基本信息：头像 + 名称 */
.identity-row {
    display: flex;
    gap: 14px;
    align-items: flex-start;
}

.avatar-btn {
    position: relative;
    border-radius: 14px;
    transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
    flex: none;
}

/* 触屏上 :hover 会在点击后粘住（放大态不复原），缩放类悬停收敛到真鼠标环境 */
@media (hover: hover) {
    .avatar-btn:hover {
        transform: scale(1.05);
        box-shadow: 0 0 0 3px var(--primary-soft);
    }
}

.avatar-btn .avatar-edit-hint {
    position: absolute;
    right: -4px;
    bottom: -4px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-2);
    box-shadow: var(--shadow-1);
}

.avatar-btn .avatar-edit-hint .icon {
    width: 10px;
    height: 10px;
}

.identity-fields {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* 建议问题列表 */
.sug-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sug-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sug-item .input {
    height: 32px;
    font-size: 12.5px;
}

/* ------- 工具列表 ------- */
.tool-row {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-2);
    transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}

.tool-row:hover {
    border-color: var(--border-strong);
}

.tool-row.enabled {
    background: var(--surface);
    border-color: var(--primary-soft-2);
}

.tool-ico {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
    background: var(--surface-3);
    color: var(--text-3);
    transition: all var(--t) var(--ease);
}

.tool-ico .icon {
    width: 15px;
    height: 15px;
}

.tool-row.enabled .tool-ico {
    background: var(--primary-soft);
    color: var(--primary);
}

.tool-info {
    flex: 1;
    min-width: 0;
}

.tool-name {
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 7px;
}

.tool-name .fn {
    font-family: var(--font-mono);
    font-size: 10.5px;
    color: var(--text-3);
    font-weight: 400;
}

.tool-desc {
    font-size: 11.5px;
    color: var(--text-3);
    line-height: 1.5;
    margin-top: 1px;
}

.tool-actions {
    display: flex;
    align-items: center;
    gap: 3px;
    flex: none;
}

/* ------- 知识库 ------- */
.kb-doc-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-2);
    cursor: pointer;
    transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}

.kb-doc-row:hover {
    border-color: var(--primary-soft-2);
    background: var(--surface);
}

.kb-doc-preview {
    font-size: 13px;
    line-height: 1.8;
    white-space: pre-wrap;
    word-break: break-word;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    max-height: 56vh;
    overflow-y: auto;
    color: var(--text-2);
}

.kb-doc-ico {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--warn-soft);
    color: var(--warn);
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
}

.kb-doc-ico .icon {
    width: 14px;
    height: 14px;
}

.kb-doc-info {
    flex: 1;
    min-width: 0;
}

.kb-doc-name {
    font-size: 12.5px;
    font-weight: 600;
}

.kb-doc-meta {
    font-size: 11px;
    color: var(--text-3);
    font-family: var(--font-mono);
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
    margin-top: 1px;
}

.kb-dot {
    color: var(--border-strong);
}

/* 向量化状态徽标（含所用模型简名） */
.kb-vec-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 10px;
    font-weight: 600;
    font-family: var(--font-sans);
    padding: 1.5px 6px;
    border-radius: 99px;
    background: var(--surface-3);
    color: var(--text-3);
    line-height: 1.5;
}

.kb-vec-badge .icon {
    width: 10px;
    height: 10px;
}

.kb-vec-badge.ok {
    background: var(--ok-soft);
    color: var(--ok);
}

.kb-vec-badge.stale {
    background: var(--warn-soft);
    color: var(--warn);
}

/* 文档行操作（悬停浮现） */
.kb-doc-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: none;
    opacity: 0;
    transition: opacity var(--t-fast) var(--ease);
}

.kb-doc-row:hover .kb-doc-actions,
.kb-doc-row:focus-within .kb-doc-actions {
    opacity: 1;
}

@media (hover: none) {
    .kb-doc-actions {
        opacity: 1;
    }
}

/* 拖拽/点击上传区 */
.kb-dropzone {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px 14px;
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--radius-md);
    background: var(--surface-2);
    color: var(--text-3);
    cursor: pointer;
    text-align: left;
    transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease),
        color var(--t-fast) var(--ease);
}

.kb-dropzone .icon {
    width: 18px;
    height: 18px;
    flex: none;
    transition: transform var(--t-fast) var(--ease);
}

.kb-dropzone:hover,
.kb-dropzone:focus-visible {
    border-color: var(--primary-soft-2);
    background: var(--primary-soft);
    color: var(--primary);
}

.kb-dropzone.dragover {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.kb-dropzone.dragover .icon {
    transform: translateY(-2px);
}

.kb-dropzone-title {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-2);
}

.kb-dropzone:hover .kb-dropzone-title,
.kb-dropzone.dragover .kb-dropzone-title {
    color: var(--primary);
}

.kb-dropzone-hint {
    font-size: 11px;
    font-family: var(--font-mono);
    margin-top: 1px;
}

/* 解析/向量化进度 */
.kb-progress {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-2);
}

.kb-progress-label {
    font-size: 12px;
    color: var(--text-2);
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.kb-progress-pct {
    margin-left: auto;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-3);
    flex: none;
}

.kb-progress-track {
    height: 4px;
    border-radius: 99px;
    background: var(--surface-3);
    overflow: hidden;
}

.kb-progress-fill {
    height: 100%;
    width: 0;
    border-radius: 99px;
    background: var(--grad-brand);
    transition: width 0.25s var(--ease);
}

.kb-progress-track.indeterminate .kb-progress-fill {
    animation: kb-indeterminate 1.2s ease-in-out infinite;
}

@keyframes kb-indeterminate {
    0% {
        margin-left: -40%;
    }

    100% {
        margin-left: 100%;
    }
}

/* 切换模型后的重新向量化提示 */
.kb-revec {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 12px;
    border: 1px solid var(--warn-soft);
    border-radius: var(--radius-md);
    background: var(--warn-soft);
}

.kb-revec-text {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 12px;
    color: var(--warn);
    min-width: 0;
}

.kb-revec-text .icon {
    width: 13px;
    height: 13px;
    flex: none;
}

.kb-revec .btn {
    flex: none;
}

/* 文档编辑弹窗 */
.kb-edit-modal .kb-edit-ta {
    min-height: 340px;
    max-height: 52vh;
    font-size: 12.5px;
    line-height: 1.7;
    font-family: var(--font-mono);
    resize: vertical;
}

.kb-edit-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 7px;
    font-size: 11px;
    color: var(--text-3);
    font-family: var(--font-mono);
}

.kb-edit-meta .over {
    color: var(--err);
    font-weight: 600;
}

.kb-edit-status {
    text-align: right;
}

/* ------- 自定义工具编辑弹窗 ------- */
.tool-editor-modal {
    width: 720px;
}

.tool-test-zone {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-2);
    overflow: hidden;
}

.tool-test-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-2);
}

.tool-test-body {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tool-test-result {
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.6;
    background: var(--code-bg);
    color: var(--code-text);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    max-height: 220px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.tool-test-result .ok-line {
    color: #7ee2a8;
}

.tool-test-result .err-line {
    color: #ff9d94;
}

.tool-test-result .log-line {
    color: #9fb6dd;
}

/* ------- 头像选择器 ------- */
.avatar-picker {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.gradient-row {
    display: flex;
    gap: 9px;
    flex-wrap: wrap;
}

.gradient-swatch {
    width: 34px;
    height: 34px;
    border-radius: 11px;
    cursor: pointer;
    transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}

@media (hover: hover) {
    .gradient-swatch:hover {
        transform: scale(1.1);
    }
}

.gradient-swatch.active {
    box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--primary);
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 5px;
}

.emoji-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 21px;
    border-radius: 9px;
    cursor: pointer;
    transition: background var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}

@media (hover: hover) {
    .emoji-cell:hover {
        background: var(--surface-3);
        transform: scale(1.12);
    }
}

.emoji-cell.active {
    background: var(--primary-soft-2);
}

.avatar-preview-row {
    display: flex;
    align-items: center;
    gap: 14px;
}

.avatar-preview-row .avatar {
    width: 56px;
    height: 56px;
    border-radius: 17px;
    font-size: 30px;
}

/* ------- AI 优化提示词 ------- */
.optimize-preview {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-2);
    padding: 14px 16px;
    font-size: 13px;
    line-height: 1.8;
    max-height: 340px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
    min-height: 120px;
}

.optimize-preview.streaming::after {
    content: "";
    display: inline-block;
    width: 7px;
    height: 15px;
    background: var(--primary);
    border-radius: 2px;
    margin-left: 3px;
    vertical-align: text-bottom;
    animation: blink-caret 0.9s ease infinite;
}

/* ------- 响应式 ------- */
.editor-mobile-tabs {
    display: none;
}

@media (max-width: 1400px) {
    .editor {
        grid-template-columns: minmax(280px, 0.95fr) minmax(280px, 1fr) minmax(360px, 1.3fr);
    }
}

@media (max-width: 980px) {
    .editor {
        --editor-mtab-h: 52px;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    /* Tab 栏吸顶：编排 Tab 下整个 .editor 滚动，不吸顶就会滑出视野、
       只能滚回顶部才能切回调试。整行铺满 + 等分，两个 Tab 都是大命中区。 */
    .editor-mobile-tabs {
        display: flex;
        position: sticky;
        top: 0;
        z-index: 6;
        flex: none;
        align-self: stretch;
        height: var(--editor-mtab-h);
        margin: 0;
        gap: 6px;
        padding: 6px 14px;
        padding-left: max(14px, env(safe-area-inset-left, 0px));
        padding-right: max(14px, env(safe-area-inset-right, 0px));
        border-radius: 0;
        border-bottom: 1px solid var(--border);
    }

    .editor-mobile-tabs .seg-tab {
        flex: 1;
        justify-content: center;
        height: 100%;
        font-size: 13px;
    }

    .editor-col {
        display: none;
        border-right: none;
    }

    /* 列头吸在 Tab 栏下方；同时去掉 backdrop-filter——吸顶元素每帧重绘
       毛玻璃在移动端 GPU 上代价很高，且此处底色不透明即可 */
    .editor-col-head {
        position: sticky;
        top: calc(var(--editor-mtab-h) - 1px);
        background: var(--bg);
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }

    /* 编排 Tab：提示词 + 配置 上下堆叠，整页滚动 */
    .editor.show-config {
        overflow-y: auto;
        overscroll-behavior-y: contain;
        -webkit-overflow-scrolling: touch;
    }

    .editor.show-config .prompt-col,
    .editor.show-config .config-col {
        display: flex;
        flex: none;
        border-bottom: 1px solid var(--border);
    }

    /* 列身高度此时由内容撑开，滚动统一交给 .editor，避免嵌套滚动容器 */
    .editor.show-config .editor-col-body {
        overflow-y: visible;
    }

    .editor.show-config .prompt-col .editor-col-body {
        min-height: 0;
    }

    .editor.show-config .prompt-textarea {
        min-height: 240px;
    }

    /* 调试 Tab：撑满剩余高度 */
    .editor.show-debug .debug-col {
        display: flex;
        flex: 1;
        min-height: 0;
    }
}

/* ------- 技能 Skills ------- */
.skill-mode {
    display: inline-block;
    margin-left: 7px;
    font-size: 10px;
    font-weight: 600;
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--surface-3);
    color: var(--text-3);
    vertical-align: 1px;
}

.skill-mode.always {
    background: var(--warn-soft);
    color: var(--warn);
}

.skill-preview {
    margin: 0;
    font-size: 12px;
    line-height: 1.75;
    color: var(--text-2);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 420px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
}

/* 技能库弹窗：我的技能 / 预置技能 双页签 */
.skill-lib-tabs {
    display: flex;
    width: 100%;
    margin-bottom: 12px;
}

.skill-lib-tabs .seg-tab {
    flex: 1;
    justify-content: center;
}

.skill-lib-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 34px 24px 30px;
    text-align: center;
}

.skill-lib-empty>.icon {
    width: 30px;
    height: 30px;
    color: var(--text-3);
    margin-bottom: 4px;
}

.skill-lib-empty-title {
    font-size: 13.5px;
    font-weight: 600;
}

/* 技能编辑弹窗底部「同时保存到我的技能库」 */
.skill-lib-check {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 12.5px;
    color: var(--text-2);
    cursor: pointer;
    user-select: none;
}

.skill-lib-check input {
    width: 14px;
    height: 14px;
    margin: 0;
    accent-color: var(--primary);
    cursor: pointer;
}

/* 编辑弹窗顶部「AI 生成」区块（渐变描边卡片，呼应 .btn-ai）：技能与自定义工具共用 */
.ai-gen-box {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px;
    border: 1.5px solid transparent;
    border-radius: var(--radius-sm);
    background:
        linear-gradient(var(--surface-2), var(--surface-2)) padding-box,
        var(--grad-brand) border-box;
    margin-bottom: 20px;
}

/* 开发新工具：AI 区块与下方人工填写再拉开一档 */
.tool-editor-modal .ai-gen-box {
    margin-bottom: 28px;
}

.ai-gen-head {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--primary);
}

.ai-gen-head .icon {
    width: 14px;
    height: 14px;
}

.ai-gen-head .hint {
    font-weight: 400;
    font-size: 11.5px;
    color: var(--text-3);
}

.ai-gen-row {
    display: flex;
    gap: 8px;
}

.ai-gen-row .input {
    flex: 1;
    background: var(--surface);
}

.ai-gen-row .btn {
    flex: none;
}

.ai-gen-row .spinner {
    width: 13px;
    height: 13px;
}

/* ============================================================
   移动端适配
   全部收在窄断点 / 触摸媒体查询内，桌面（>980px，真鼠标）不受影响。
   放在文件末尾：媒体查询规则与基础规则特异性相同，靠源码顺序取胜。
   ============================================================ */

@media (max-width: 720px) {

    /* iOS 聚焦自动缩放：输入控件计算字号需 ≥16px。
       chat.css 已统一覆盖 .input / .textarea（0,1,0），此处补齐编辑器内
       特异性更高、仍会触发缩放的三处 */
    .textarea.code {
        font-size: 16px;
        /* 字号抬到 16px 后 rows=11/14 的代码框会有 350px+，键盘弹起时
           把弹窗底栏顶出屏幕；限高改为内部滚动 */
        max-height: 46vh;
        max-height: 46dvh;
    }

    .kb-edit-modal .kb-edit-ta {
        font-size: 16px;
        min-height: 180px;
        max-height: 42vh;
        max-height: 42dvh;
    }

    .sug-item .input {
        height: 40px;
        font-size: 16px;
    }

    /* 命中区扩到 44px 后相邻按钮会互吃，先把行内间距拉开 */
    .tool-actions {
        gap: 8px;
    }

    .kb-doc-actions {
        gap: 6px;
    }

    /* 含输入框的高弹窗：底栏避让 Home Indicator */
    .tool-editor-modal .modal-foot,
    .kb-edit-modal .modal-foot,
    .skill-editor-modal .modal-foot {
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }

    /* 技能编辑器底栏：「同时保存到我的技能库」+ 两个按钮在 360px 下会互相
       挤压（.btn 是 nowrap 且可收缩，文字会溢出按钮），让勾选项独占一行 */
    .skill-editor-modal .modal-foot {
        flex-wrap: wrap;
    }

    .skill-editor-modal .modal-foot .skill-lib-check {
        flex: 1 0 100%;
        margin-right: 0;
    }
}

@media (max-width: 480px) {

    /* 工具 / 技能行：ico + 名称 + 描述 + 开关 + 2~3 个按钮在 360px 下放不下，
       操作区整体换到第二行右对齐 */
    .tool-row {
        flex-wrap: wrap;
    }

    .tool-actions {
        flex: 1 0 100%;
        justify-content: flex-end;
        margin-top: 2px;
    }

    .cfg-row-2 {
        grid-template-columns: 1fr;
    }

    /* 8 列在 360px 下约 34px/格，低于 44px 命中标准 */
    .emoji-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* 触摸设备：保持视觉尺寸不变，用透明 ::after 把命中区补到 ~44px。
   tooltip 的 [data-tip]::after 只在 (hover:hover) and (pointer:fine) 内生成，
   与本块互斥，不会互相覆盖。 */
@media (hover: none) {

    .editor-col-head .icon-btn,
    .tool-actions .icon-btn,
    .kb-doc-actions .icon-btn,
    .sug-item .icon-btn,
    .tool-row .switch,
    .gradient-swatch,
    .editor-mobile-tabs .seg-tab,
    .skill-lib-tabs .seg-tab,
    .skill-editor-modal .seg-tab {
        position: relative;
    }

    .editor-col-head .icon-btn::after,
    .tool-actions .icon-btn::after,
    .kb-doc-actions .icon-btn::after,
    .sug-item .icon-btn::after,
    .tool-row .switch::after,
    .gradient-swatch::after,
    .editor-mobile-tabs .seg-tab::after,
    .skill-lib-tabs .seg-tab::after,
    .skill-editor-modal .seg-tab::after {
        content: "";
        position: absolute;
    }

    /* 30×30 → 44×44 */
    .editor-col-head .icon-btn::after,
    .tool-actions .icon-btn::after,
    .kb-doc-actions .icon-btn::after,
    .sug-item .icon-btn::after {
        inset: -7px;
    }

    /* 36×21 开关 → 46×45 */
    .tool-row .switch::after {
        inset: -12px -5px;
    }

    /* 34×34 → 44×44 */
    .gradient-swatch::after {
        inset: -5px;
    }

    /* 28px 高的分段 Tab → 44px */
    .editor-mobile-tabs .seg-tab::after,
    .skill-lib-tabs .seg-tab::after,
    .skill-editor-modal .seg-tab::after {
        inset: -8px 0;
    }
}
