/* ============================================================
   BAILU Agent Studio — components.css
   按钮 / 表单 / 开关 / 滑杆 / 徽章 / 弹窗 / Toast / 菜单 / 下拉
   ============================================================ */

/* ------- 图标 ------- */
.icon {
    width: 16px;
    height: 16px;
    flex: none;
    stroke-width: 2;
}

.icon-sm {
    width: 14px;
    height: 14px;
}

.icon-lg {
    width: 20px;
    height: 20px;
}

/* ------- 按钮 ------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    height: 34px;
    padding: 0 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 550;
    line-height: 1;
    white-space: nowrap;
    border: 1px solid transparent;
    transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease),
        color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease),
        transform var(--t-fast) var(--ease), opacity var(--t-fast) var(--ease);
    user-select: none;
}

.btn:active {
    transform: scale(0.97);
}

.btn:disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* 视觉禁用但可点击（用于给出提示反馈，如 AI 优化字数门槛） */
.btn.is-disabled {
    opacity: 0.45;
    box-shadow: none;
}

.btn.is-disabled:active {
    transform: none;
}

.btn-primary {
    background: var(--primary);
    color: var(--on-primary);
    box-shadow: 0 1px 2px rgba(11, 108, 242, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.btn-primary:hover {
    background: var(--primary-strong);
    box-shadow: 0 2px 10px var(--primary-glow), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.btn-grad {
    background: var(--grad-brand);
    color: #fff;
    box-shadow: 0 1px 2px rgba(11, 108, 242, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.btn-grad:hover {
    filter: brightness(1.06);
    box-shadow: 0 4px 16px var(--primary-glow), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.btn-ghost {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text-2);
    box-shadow: var(--shadow-1);
}

.btn-ghost:hover {
    border-color: var(--border-strong);
    color: var(--text);
    background: var(--surface-2);
}

.btn-soft {
    background: var(--primary-soft);
    color: var(--primary);
}

.btn-soft:hover {
    background: var(--primary-soft-2);
}

.btn-danger-soft {
    background: var(--err-soft);
    color: var(--err);
}

.btn-danger-soft:hover {
    background: var(--err);
    color: #fff;
}

.btn-danger {
    background: var(--err);
    color: #fff;
}

.btn-danger:hover {
    filter: brightness(1.08);
}

.btn-sm {
    height: 28px;
    padding: 0 10px;
    font-size: 12px;
    border-radius: var(--radius-xs);
    gap: 5px;
}

.btn-sm .icon {
    width: 13px;
    height: 13px;
}

.btn-lg {
    height: 40px;
    padding: 0 20px;
    font-size: 14px;
    border-radius: var(--radius-md);
}

/* 图标按钮 */
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: var(--radius-xs);
    color: var(--text-3);
    transition: all var(--t-fast) var(--ease);
    flex: none;
}

.icon-btn:hover {
    background: var(--surface-3);
    color: var(--text);
}

.icon-btn.danger:hover {
    background: var(--err-soft);
    color: var(--err);
}

.icon-btn:active {
    transform: scale(0.92);
}

/* ------- 表单 ------- */
.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.field-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-2);
    letter-spacing: 0.01em;
}

.field-label .hint {
    font-weight: 400;
    color: var(--text-3);
    font-size: 11.5px;
}

.input,
.textarea {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 13.5px;
    color: var(--text);
    transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease),
        background var(--t-fast) var(--ease);
}

.input {
    height: 36px;
}

.textarea {
    resize: vertical;
    min-height: 80px;
    line-height: 1.65;
}

.input:hover,
.textarea:hover {
    border-color: var(--border-strong);
}

.input:focus,
.textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

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

.textarea.code {
    font-family: var(--font-mono);
    font-size: 12.5px;
    line-height: 1.6;
    background: var(--surface-2);
    white-space: pre;
    tab-size: 2;
}

.input.invalid,
.textarea.invalid {
    border-color: var(--err);
    box-shadow: 0 0 0 3px var(--err-soft);
}

.form-error {
    font-size: 12px;
    color: var(--err);
    display: flex;
    align-items: center;
    gap: 5px;
}

/* 模型选择下方的说明：默认模型解析结果 / 模型已下线告警（编辑器 + 发布面板 + 设置） */
.model-note {
    font-size: 11.5px;
    line-height: 1.6;
    color: var(--text-3);
}

.model-note:empty {
    display: none;
}

.model-note.warn {
    color: var(--warn);
}

/* ------- 开关 ------- */
.switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 21px;
    flex: none;
    cursor: pointer;
}

.switch input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    z-index: 1;
}

.switch .track {
    position: absolute;
    inset: 0;
    background: var(--border-strong);
    border-radius: 99px;
    transition: background var(--t) var(--ease);
}

.switch .track::after {
    content: "";
    position: absolute;
    top: 2.5px;
    left: 2.5px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    transition: transform var(--t) var(--ease);
}

.switch input:checked+.track {
    background: var(--primary);
}

.switch input:checked+.track::after {
    transform: translateX(15px);
}

.switch input:focus-visible+.track {
    box-shadow: 0 0 0 3px var(--primary-soft);
}

/* ------- 滑杆 ------- */
.slider-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.slider-row .slider-value {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-2);
    background: var(--surface-3);
    border-radius: 6px;
    padding: 2px 8px;
    min-width: 44px;
    text-align: center;
    flex: none;
}

input[type="range"].slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 99px;
    background: linear-gradient(to right, var(--primary) 0%, var(--primary) var(--fill, 50%), var(--border-strong) var(--fill, 50%), var(--border-strong) 100%);
    outline: none;
}

input[type="range"].slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--primary);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
    cursor: grab;
    transition: transform var(--t-fast) var(--ease);
}

input[type="range"].slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

input[type="range"].slider::-moz-range-thumb {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--primary);
    cursor: grab;
}

/* ------- 徽章 / chip ------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 21px;
    padding: 0 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    background: var(--surface-3);
    color: var(--text-2);
    white-space: nowrap;
}

.badge .icon {
    width: 11px;
    height: 11px;
}

.badge-primary {
    background: var(--primary-soft);
    color: var(--primary);
}

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

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

.badge-err {
    background: var(--err-soft);
    color: var(--err);
}

.badge-mono {
    font-family: var(--font-mono);
    font-weight: 500;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 13px;
    border-radius: 99px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-2);
    font-size: 12.5px;
    cursor: pointer;
    transition: all var(--t-fast) var(--ease);
    box-shadow: var(--shadow-1);
}

/* 触屏没有真正的 hover：点一下会把高亮"粘"住，与选中态混淆 */
@media (hover: hover) {
    .chip:hover {
        border-color: var(--primary);
        color: var(--primary);
        background: var(--primary-soft);
    }
}

/* ------- 卡片 ------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-1);
}

/* ------- 弹窗 ------- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: var(--backdrop);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    /* --kb-inset 由 components.js 按 visualViewport 写入（软键盘高度，桌面端恒为 0）：
       弹窗被抬到键盘之上，底部提交按钮不会被键盘盖住 */
    padding-top: max(24px, var(--safe-t, 0px));
    padding-bottom: calc(24px + var(--kb-inset, 0px) + var(--safe-b, 0px));
    padding-left: max(24px, var(--safe-l, 0px));
    padding-right: max(24px, var(--safe-r, 0px));
    transition: padding-bottom var(--t) var(--ease);
    animation: fade-in var(--t) var(--ease);
}

.modal-backdrop.closing {
    animation: fade-in var(--t) var(--ease) reverse forwards;
}

.modal {
    width: 520px;
    max-width: 100%;
    max-height: min(86vh, 900px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: scale-in var(--t) var(--ease);
}

.modal-backdrop.closing .modal {
    animation: scale-in var(--t) var(--ease) reverse forwards;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 22px 14px;
    flex: none;
}

.modal-title {
    font-size: 16px;
    font-weight: 650;
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: 9px;
}

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

.modal-body {
    padding: 4px 22px 20px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-foot {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 22px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    flex: none;
}

.modal-foot .grow {
    margin-right: auto;
}

@media (max-width: 720px) {
    .modal-backdrop {
        padding: 10px;
        padding-top: max(10px, var(--safe-t, 0px));
        padding-bottom: calc(10px + var(--kb-inset, 0px) + var(--safe-b, 0px));
        padding-left: max(10px, var(--safe-l, 0px));
        padding-right: max(10px, var(--safe-r, 0px));
    }

    .modal {
        max-height: 94vh;
        max-height: 94dvh;
        border-radius: var(--radius-lg);
    }

    /* 窄屏（尤其键盘弹出时）可视高度可能低于这个下限；
       min-height 优先级高于 max-height，留着会把弹窗顶出屏幕 */
    .modal.gen-modal.gen-phase-intro {
        min-height: 0;
    }

    /* 键盘弹出时同步收缩，避免弹窗比可视区还高被顶出屏幕。
       含 var() 的声明在不认识 dvh 的浏览器上会"计算时失效"退化成 max-height:none
       （而不是回落到上一条），因此必须先用 @supports 挡一层 */
    @supports (height: 100dvh) {
        .modal {
            max-height: min(94dvh, calc(100dvh - var(--kb-inset, 0px) - 24px));
        }
    }

    .modal-head {
        padding: 15px 16px 12px;
    }

    .modal-body {
        padding: 2px 16px 16px;
    }

    /* 底部操作区按钮多时（发布面板 4 个）换行铺满，不再挤成一行溢出 */
    .modal-foot {
        padding: 12px 16px;
        flex-wrap: wrap;
    }

    .modal-foot .btn {
        flex: 1 1 auto;
        min-width: 104px;
    }
}

/* ------- Toast ------- */
.toast-root {
    position: fixed;
    bottom: 24px;
    bottom: calc(24px + var(--safe-b, 0px));
    left: 50%;
    transform: translateX(-50%);
    max-width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    z-index: 300;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 10px 18px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 99px;
    box-shadow: var(--shadow-pop);
    font-size: 13px;
    font-weight: 500;
    animation: rise-in var(--t) var(--ease);
    pointer-events: auto;
    max-width: min(88vw, 560px);
    word-break: break-word;
}

.toast.leaving {
    animation: rise-in var(--t) var(--ease) reverse forwards;
}

.toast .icon {
    flex: none;
}

.toast-ok .icon {
    color: var(--ok);
}

.toast-err .icon {
    color: var(--err);
}

.toast-warn .icon {
    color: var(--warn);
}

.toast-info .icon {
    color: var(--primary);
}

.toast-action {
    margin-left: 6px;
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.toast-action:hover {
    text-decoration: underline;
}

/* ------- 浮层菜单 ------- */
.popover {
    position: fixed;
    z-index: 260;
    min-width: 160px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-pop);
    padding: 5px;
    animation: scale-in 0.16s var(--ease);
    transform-origin: top;
}

/* 菜单比视口还高时才开内部滚动（由 openMenu 写行内样式触发）。
   常规菜单保持非滚动容器：overflow 会让 Chrome 换一条绘制路径，
   图标抗锯齿有亚像素差异，桌面端不必要地引入变化 */

.menu-item {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 8px 11px;
    border-radius: var(--radius-xs);
    font-size: 13px;
    color: var(--text-2);
    text-align: left;
    transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}

.menu-item:hover {
    background: var(--surface-3);
    color: var(--text);
}

.menu-item.danger {
    color: var(--err);
}

.menu-item.danger:hover {
    background: var(--err-soft);
}

/* 列表型菜单（如学院步骤切换器）：标题占满、行尾放次要说明与状态勾 */
.menu-item-lb {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.menu-item-hint {
    flex: none;
    font-size: 11.5px;
    color: var(--text-3);
}

.menu-item-tick {
    flex: none;
    width: 14px;
    height: 14px;
}

/* 已到达过的项：弱化的对勾，不与当前项抢视觉 */
.menu-item.is-done .menu-item-tick {
    color: var(--ok);
    opacity: 0.6;
}

.menu-item.is-active,
.menu-item.is-active:hover {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 650;
}

.menu-item.is-active .menu-item-hint {
    color: var(--primary);
    opacity: 0.85;
}

.menu-item.is-active .menu-item-tick {
    color: var(--primary);
    opacity: 1;
}

.menu-sep {
    height: 1px;
    background: var(--border);
    margin: 5px 8px;
}

/* 附件类型：图片 / 视频 / 音频 三选（线性图标，非 emoji） */
.popover.popover-kinds {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 4px;
    min-width: 0;
    padding: 8px;
    transform-origin: bottom right;
}

.attach-kind {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 7px;
    width: 78px;
    padding: 10px 8px 9px;
    border-radius: 10px;
    color: var(--text-2);
    transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}

.attach-kind:hover {
    background: var(--surface-3);
    color: var(--text);
}

.attach-kind-ic {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--primary-soft);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.attach-kind-ic .icon {
    width: 18px;
    height: 18px;
}

.attach-kind-lb {
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.02em;
}

.attach-kind.is-off {
    opacity: 0.42;
}

.attach-kind.is-off:hover {
    background: var(--surface-2);
    color: var(--text-2);
}

.attach-kind.is-off .attach-kind-ic {
    background: var(--surface-3);
    color: var(--text-3);
}

/* ------- 自定义下拉选择 ------- */
.select {
    position: relative;
    min-width: 0;
}

.select-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    height: 36px;
    padding: 0 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    cursor: pointer;
    transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}

.select-trigger:hover {
    border-color: var(--border-strong);
}

.select.open .select-trigger {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.select-trigger .value {
    flex: 1;
    text-align: left;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.select-trigger .value.placeholder {
    color: var(--text-3);
}

.select-trigger .icon {
    color: var(--text-3);
    transition: transform var(--t) var(--ease);
}

.select.open .select-trigger .icon-chevron {
    transform: rotate(180deg);
}

.select-panel {
    position: fixed;
    z-index: 260;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-pop);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: calc(100vh - 16px);
    animation: scale-in 0.16s var(--ease);
    transform-origin: top;
}

.select-search {
    padding: 8px;
    border-bottom: 1px solid var(--border);
    flex: none;
}

.select-search input {
    width: 100%;
    height: 30px;
    padding: 0 10px;
    border: none;
    background: var(--surface-3);
    border-radius: var(--radius-xs);
    font-size: 12.5px;
    outline: none;
    color: var(--text);
}

.select-list {
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    max-height: 280px;
    padding: 5px;
}

.select-option {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 10px;
    border-radius: var(--radius-xs);
    font-size: 13px;
    color: var(--text-2);
    text-align: left;
    cursor: pointer;
    transition: background var(--t-fast) var(--ease);
}

.select-option:hover {
    background: var(--surface-3);
    color: var(--text);
}

.select-option.active {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 600;
}

.select-option-tags {
    margin-left: auto;
    display: inline-flex;
    gap: 4px;
    flex: none;
}

.select-option .tag {
    font-size: 10.5px;
    padding: 1px 6px;
    border-radius: 5px;
    background: var(--surface-3);
    color: var(--text-3);
    font-weight: 500;
    flex: none;
}

.select-option.active .tag {
    background: var(--primary-soft-2);
    color: var(--primary);
}

.select-empty {
    padding: 18px;
    text-align: center;
    font-size: 12.5px;
    color: var(--text-3);
}

/* ------- Tabs ------- */
.seg-tabs {
    display: inline-flex;
    background: var(--surface-3);
    border-radius: var(--radius-sm);
    padding: 3px;
    gap: 2px;
}

.seg-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 28px;
    padding: 0 13px;
    border-radius: 7px;
    font-size: 12.5px;
    font-weight: 550;
    color: var(--text-3);
    transition: all var(--t-fast) var(--ease);
}

.seg-tab:hover {
    color: var(--text-2);
}

.seg-tab.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-1);
}

/* ------- 空状态 ------- */
.empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 40px 20px;
    text-align: center;
    color: var(--text-3);
}

.empty .icon {
    width: 36px;
    height: 36px;
    stroke-width: 1.5;
    opacity: 0.5;
}

.empty .empty-title {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text-2);
}

.empty .empty-desc {
    font-size: 12.5px;
    max-width: 300px;
    line-height: 1.6;
}

/* ------- Spinner / 骨架 ------- */
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-strong);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex: none;
}

.spinner-lg {
    width: 28px;
    height: 28px;
    border-width: 3px;
}

.skeleton {
    background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s ease infinite;
    border-radius: var(--radius-sm);
}

/* ------- Tooltip -------
   仅在真鼠标设备渲染：触屏没有 hover，点一下会留下"粘滞悬停"的气泡，
   且 tooltip 不能是控件的唯一说明（图标按钮一律另配 aria-label） */
[data-tip] {
    position: relative;
}

@media (hover: hover) and (pointer: fine) {
    [data-tip]::after {
        content: attr(data-tip);
        position: absolute;
        bottom: calc(100% + 7px);
        left: 50%;
        transform: translateX(-50%) translateY(3px);
        background: var(--text);
        color: var(--bg);
        font-size: 11.5px;
        font-weight: 500;
        padding: 4px 9px;
        border-radius: 6px;
        white-space: nowrap;
        opacity: 0;
        pointer-events: none;
        transition: opacity var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
        z-index: 100;
    }

    [data-tip]:hover::after {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
        transition-delay: 0.3s;
    }

    /* 贴顶栏的 tooltip 向下显示，否则会被 .view overflow:hidden、
       顶栏 z-index、视口上沿或父级 overflow:hidden（如 .cad-card）裁切 */
    .topbar [data-tip]::after,
    .editor-col-head [data-tip]::after,
    .academy-lesson-head [data-tip]::after,
    .lb-topbar [data-tip]::after,
    .cad-head [data-tip]::after {
        bottom: auto;
        top: calc(100% + 7px);
        transform: translateX(-50%) translateY(-3px);
    }

    .topbar [data-tip]:hover::after,
    .editor-col-head [data-tip]:hover::after,
    .academy-lesson-head [data-tip]:hover::after,
    .lb-topbar [data-tip]:hover::after,
    .cad-head [data-tip]:hover::after {
        transform: translateX(-50%) translateY(0);
    }
}

/* ------- kbd ------- */
.kbd {
    font-family: var(--font-mono);
    font-size: 10.5px;
    padding: 1px 5px;
    border-radius: 5px;
    border: 1px solid var(--border-strong);
    border-bottom-width: 2px;
    background: var(--surface-2);
    color: var(--text-3);
}

/* ------- 提示条 ------- */
.note {
    display: flex;
    gap: 9px;
    padding: 10px 13px;
    border-radius: var(--radius-sm);
    background: var(--primary-soft);
    color: var(--text-2);
    font-size: 12.5px;
    line-height: 1.6;
}

.note .icon {
    color: var(--primary);
    margin-top: 2px;
}

.note-warn {
    background: var(--warn-soft);
}

.note-warn .icon {
    color: var(--warn);
}

/* ------- 顶栏账户区（与 icon-btn 同基线：透明底 + hover 浮起） ------- */
.account-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 30px;
    padding: 0 8px 0 4px;
    border-radius: var(--radius-xs);
    border: none;
    background: transparent;
    color: var(--text-2);
    font-size: 12.5px;
    font-weight: 550;
    max-width: 168px;
    cursor: pointer;
    transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}

.account-chip:hover {
    background: var(--surface-3);
    color: var(--text);
}

.account-chip:active {
    transform: scale(0.97);
}

.account-chip .account-caret {
    width: 12px;
    height: 12px;
    color: var(--text-3);
    flex: none;
}

.account-avatar {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--grad-brand);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.account-name {
    max-width: 104px;
    min-width: 0;
}

@media (max-width: 720px) {
    .account-name,
    .account-chip .account-caret {
        display: none;
    }

    .account-chip {
        padding: 0 4px;
    }
}

/* ------- API 发布面板 ------- */
.publish-scope {
    display: flex;
    flex-direction: column;
    gap: 7px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
}

.publish-scope-row {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 12.5px;
    color: var(--text-2);
}

.publish-scope-row .icon {
    width: 14px;
    height: 14px;
    flex: none;
}

.publish-scope-row.ok .icon {
    color: var(--ok, #16a34a);
}

.publish-scope-row.no {
    color: var(--text-3);
}

.publish-scope-row.no .icon {
    color: var(--text-3);
}

.publish-code-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
}

.publish-code-main {
    flex: 1;
    min-width: 0;
}

.publish-code-label {
    font-size: 11px;
    color: var(--text-3);
    margin-bottom: 3px;
}

.publish-code {
    font-size: 15px;
    font-weight: 650;
    letter-spacing: 0.3px;
    color: var(--text-1);
    user-select: all;
}

.publish-meta {
    font-size: 12px;
    margin-top: 8px;
    line-height: 1.6;
}

.publish-stale {
    color: var(--warn, #d97706);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.publish-stale .icon {
    width: 12px;
    height: 12px;
}

.publish-example-wrap {
    position: relative;
}

.publish-example {
    margin: 0;
    padding: 12px 40px 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2, var(--surface));
    font-size: 12px;
    line-height: 1.7;
    overflow-x: auto;
    /* 横滑到头不要连带把弹窗/页面一起拖走 */
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    white-space: pre;
    color: var(--text-2);
}

.publish-example-copy {
    position: absolute;
    top: 8px;
    right: 8px;
}

/* ------- AI 生成按钮（渐变描边；悬停铺满渐变 + 白字） ------- */
.btn-ai {
    position: relative;
    background:
        linear-gradient(var(--surface), var(--surface)) padding-box,
        var(--grad-brand) border-box;
    border: 1.5px solid transparent;
    color: var(--primary);
    box-shadow: var(--shadow-1);
}

.btn-ai:hover {
    background: var(--grad-brand) padding-box;
    border-color: transparent;
    color: #fff;
    box-shadow: 0 2px 10px var(--primary-glow);
}

/* ------- 一句话生成 Agent 向导 -------
   弹窗高度跟着内容走（气泡变多、输入框长高都会把弹窗撑高），
   上限交给 max-height，超出后由对话区自己滚动，不留大片空白 */
.modal.gen-modal {
    max-height: min(88vh, 880px);
}

.modal.gen-modal.gen-phase-intro {
    min-height: 380px;
}

.modal.gen-modal .modal-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* 对话阶段只保留 .gen-chat 一个滚动面 */
.modal.gen-modal.gen-phase-chat .modal-body {
    overflow: hidden;
}

/* [hidden] 的 UA 规则会被 .btn 的 display:inline-flex 盖掉，这里补回来 */
.gen-footer .btn[hidden] {
    display: none;
}

.gen-wizard {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.gen-phase-intro .gen-wizard {
    justify-content: center;
}

/* 阶段一：描述输入 */
.gen-intro {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 10px;
    padding: 8px 4px 4px;
}

.gen-intro-icon {
    width: 52px;
    height: 52px;
    border-radius: 15px;
    background: var(--grad-brand);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px var(--primary-glow);
}

.gen-intro-icon .icon {
    width: 24px;
    height: 24px;
}

.gen-intro-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
}

.gen-intro-sub {
    font-size: 12.5px;
    color: var(--text-3);
    line-height: 1.7;
    max-width: 420px;
}

.gen-desc {
    width: 100%;
    margin-top: 6px;
    min-height: 76px;
    max-height: 220px;
    font-size: 13.5px;
    resize: none;
    overflow-y: auto;
}

.gen-examples {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    justify-content: center;
}

.gen-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-2);
    font-size: 12px;
    cursor: pointer;
    transition: all var(--t-fast) var(--ease);
}

@media (hover: hover) {
    .gen-chip:hover {
        border-color: var(--primary);
        color: var(--primary);
        background: var(--primary-soft);
    }

    .gen-chip.static:hover {
        border-color: var(--border);
        color: var(--text-2);
        background: var(--surface);
    }

    .gen-chip.static.gen-cap-skill:hover {
        background: var(--primary-soft);
        border-color: transparent;
        color: var(--primary);
    }
}

.gen-chip.static {
    cursor: default;
}

.gen-chip .icon {
    width: 12px;
    height: 12px;
}

.gen-start {
    margin-top: 6px;
    width: 200px;
    justify-content: center;
}

/* 阶段二：对话收集 */
.gen-chatwrap {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    gap: 10px;
}

.gen-chat {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    gap: 10px;
    min-height: 132px;
    max-height: min(46vh, 380px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 4px 2px;
}

.gen-bubble {
    max-width: 88%;
    padding: 9px 13px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.7;
    word-break: break-word;
}

.gen-bubble.user {
    align-self: flex-end;
    background: var(--primary);
    color: var(--on-primary);
    border-bottom-right-radius: 4px;
}

.gen-bubble.ai {
    align-self: flex-start;
    background: var(--surface-2, var(--surface));
    border: 1px solid var(--border);
    color: var(--text-2);
    border-bottom-left-radius: 4px;
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

.gen-ai-avatar {
    width: 20px;
    height: 20px;
    border-radius: 6px;
    background: var(--grad-brand);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    margin-top: 2px;
}

.gen-ai-avatar .icon {
    width: 11px;
    height: 11px;
}

/* 等待气泡：三点 + 轮播安抚文案（扫光见 base.css 的 .ac-shimmer）。
   窄屏放不下时让文案整行换到点点下方，不撑破气泡 */
.gen-typing-main {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px 9px;
    min-width: 0;
}

.gen-typing-tip {
    font-size: 12.5px;
    font-weight: 600;
}

.gen-dots {
    display: inline-flex;
    gap: 4px;
    padding: 4px 2px;
}

.gen-dots i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-3);
    animation: gen-bounce 1.2s infinite ease-in-out;
}

.gen-dots i:nth-child(2) {
    animation-delay: 0.15s;
}

.gen-dots i:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes gen-bounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.5;
    }

    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

.gen-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    flex: none;
}

.gen-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex: none;
}

.gen-answer {
    flex: 1;
    min-height: 38px;
    max-height: 160px;
    resize: none;
    overflow-y: auto;
}

.gen-send {
    width: 38px;
    height: 38px;
    padding: 0;
    border-radius: 50%;
    flex: none;
    box-shadow: 0 2px 8px var(--primary-glow);
}

/* 生成中变停止钮（与调试面板的 .chat-send.stop 同一语义） */
.gen-send.stop {
    background: var(--err);
    box-shadow: 0 2px 8px rgba(217, 45, 32, 0.3);
}

.gen-send.stop:hover {
    background: var(--err);
    filter: brightness(1.06);
}

.gen-send .icon {
    width: 16px;
    height: 16px;
}

.gen-send:not(.stop) .icon {
    margin-left: 1px;
}

.gen-answer:disabled {
    background: var(--surface-2, var(--surface));
    color: var(--text-3);
    cursor: default;
}

.gen-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 24px;
    flex: none;
}

.gen-footer [data-clear] {
    flex: none;
}

.gen-footer [data-status] {
    flex: 1;
    min-width: 0;
    text-align: center;
}

.gen-footer [data-skip] {
    flex: none;
}

.gen-footer [data-clear]:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.gen-status {
    font-size: 11.5px;
}

/* 阶段三：预览 */
.gen-preview {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.gen-preview-head {
    display: flex;
    align-items: center;
    gap: 12px;
}

.gen-preview-avatar {
    width: 46px;
    height: 46px;
    border-radius: 13px;
    background: var(--grad-brand);
    font-size: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
}

.gen-preview-title {
    flex: 1;
    min-width: 0;
}

.gen-preview-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

.gen-preview-desc {
    font-size: 12px;
    color: var(--text-3);
    margin-top: 2px;
}

.gen-preview-block {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    padding: 10px 13px;
}

.gen-preview-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
    margin-bottom: 7px;
}

.gen-preview-label .icon {
    width: 13px;
    height: 13px;
    color: var(--primary);
}

.gen-preview-prompt {
    margin: 0;
    font-size: 12px;
    line-height: 1.75;
    color: var(--text-2);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: min(28vh, 240px);
    overflow-y: auto;
}

.gen-preview-text {
    font-size: 12.5px;
    color: var(--text-2);
    line-height: 1.7;
}

.gen-preview-sugs,
.gen-preview-caps {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.gen-cap-skill {
    background: var(--primary-soft);
    border-color: transparent;
    color: var(--primary);
}

.gen-cap-tool {
    background: var(--surface-2, var(--surface));
}

.gen-preview-meta {
    font-size: 11.5px;
    text-align: center;
}

.gen-modal .modal-foot .gen-create-btn {
    flex: 1;
    justify-content: center;
}

/* ============================================================
   移动端适配
   触屏点按区 / iOS 聚焦缩放 / 浮层改底部抽屉
   ============================================================ */

/* ------- 触屏：点按目标不小于 44×44 ------- */
@media (hover: none) {

    /* 图标按钮遍布顶栏与各类密集工具行，直接放大会把布局撑破：
       用透明伪元素把命中区撑到 44×44，视觉尺寸与占位保持不变 */
    .icon-btn {
        position: relative;
    }

    /* 本文件里唯一被绝对定位的 .icon-btn，特异性与上面同级且声明在前，
       这里补回来，否则平板（hover:none 但宽于 720px）上复制按钮会掉进文档流 */
    .publish-example-copy {
        position: absolute;
    }

    .icon-btn::before {
        content: "";
        position: absolute;
        left: 50%;
        top: 50%;
        width: var(--tap, 44px);
        height: var(--tap, 44px);
        transform: translate(-50%, -50%);
    }

    .switch::before {
        content: "";
        position: absolute;
        left: 50%;
        top: 50%;
        width: var(--tap, 44px);
        height: var(--tap, 44px);
        transform: translate(-50%, -50%);
    }

    /* 有独立占位的控件直接长高（顺序不可调换：.btn 在前，变体在后覆盖） */
    .btn {
        height: 40px;
    }

    .btn-sm {
        height: 34px;
    }

    .btn-lg {
        height: 46px;
    }

    /* 圆形发送钮：覆盖上面 .btn { height:40px }，保持正圆且点按区 ≥44 */
    .btn.gen-send {
        width: var(--tap, 44px);
        height: var(--tap, 44px);
        min-height: var(--tap, 44px);
        padding: 0;
        border-radius: 50%;
    }

    .seg-tab {
        height: 38px;
    }

    /* 一句话生成向导的示例 / 快捷回答 chip 默认只有约 28px 高。它们在换行的
       flex 流里各自占位，直接长高不会挤到别的控件（与 .chat-suggestions .chip 同法）。
       .gen-chip.static 是预览里纯展示的推荐问题（span，不可点），不需要点按区 */
    .gen-chip:not(.static) {
        min-height: var(--tap, 44px);
    }

    .menu-item {
        padding: 12px;
    }

    .select-option {
        padding: 11px 10px;
    }

    .toast-action {
        padding: 6px 4px;
    }

    /* 滑杆：15px 的把手在手指下几乎抓不住 */
    input[type="range"].slider {
        height: 6px;
    }

    input[type="range"].slider::-webkit-slider-thumb {
        width: 22px;
        height: 22px;
    }

    input[type="range"].slider::-moz-range-thumb {
        width: 20px;
        height: 20px;
    }

    /* iOS Safari：聚焦时计算字号 <16px 会自动放大整页且不再还原 */
    .input,
    .textarea,
    .textarea.code,
    .select-trigger,
    .select-search input {
        font-size: 16px;
    }

    .input,
    .select-trigger {
        height: 42px;
    }

    /* 注意：这里不要给 .textarea 加 min-height ——
       .gen-desc / .gen-answer 都带 .textarea 类且声明在前，
       会被反向覆盖成同一个高度（生成向导的单行回答框会被撑成大方块） */
}

/* ------- 手机端浮层：菜单 / 下拉改为底部抽屉 -------
   原逻辑按锚点做 window.innerWidth 夹取定位，窄屏上很容易贴边、
   顶出视口或被键盘盖住；抽屉形态既好点又不会算错位置。
   由 js/ui/components.js 在 (max-width: 720px) 时加类启用 */
@keyframes sheet-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 255;
    background: rgba(15, 23, 42, 0.32);
    animation: fade-in var(--t-fast) var(--ease);
    touch-action: manipulation;
    overscroll-behavior: contain;
}

.popover.popover-sheet {
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    min-width: 0;
    max-height: 72vh;
    max-height: 72dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    border-bottom: none;
    padding: 6px 8px calc(8px + var(--safe-b, 0px));
    padding-left: max(8px, var(--safe-l, 0px));
    padding-right: max(8px, var(--safe-r, 0px));
    box-shadow: 0 -6px 32px rgba(16, 24, 40, 0.22);
    animation: sheet-up 0.22s var(--ease);
    transform-origin: bottom;
}

/* 抽屉把手 */
.popover-sheet::before {
    content: "";
    display: block;
    width: 36px;
    height: 4px;
    margin: 4px auto 8px;
    border-radius: 99px;
    background: var(--border-strong);
}

.popover-sheet .menu-item {
    padding: 13px 14px;
    font-size: 14.5px;
    border-radius: var(--radius-sm);
}

.popover-sheet .menu-item .icon {
    width: 18px;
    height: 18px;
}

.popover-sheet .menu-item-hint {
    font-size: 13px;
}

.popover-sheet .menu-sep {
    margin: 6px 10px;
}

.popover-sheet.popover-kinds {
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    gap: 8px;
    padding: 10px 14px calc(14px + var(--safe-b, 0px));
}

.popover-sheet .attach-kind {
    flex: 1;
    width: auto;
    max-width: 120px;
    padding: 14px 8px 12px;
}

.popover-sheet .attach-kind-ic {
    width: 44px;
    height: 44px;
    border-radius: 12px;
}

.popover-sheet .attach-kind-ic .icon {
    width: 20px;
    height: 20px;
}

.popover-sheet .attach-kind-lb {
    font-size: 13px;
}

.select-panel.select-panel-sheet {
    left: 0;
    right: 0;
    top: auto;
    /* --kb-inset：软键盘高度，由 components.js 写入，抽屉随键盘抬起 */
    bottom: var(--kb-inset, 0px);
    min-width: 0;
    max-width: none;
    max-height: min(72vh, calc(100vh - var(--kb-inset, 0px) - 16px));
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    border-bottom: none;
    box-shadow: 0 -6px 32px rgba(16, 24, 40, 0.22);
    animation: sheet-up 0.22s var(--ease);
    transform-origin: bottom;
    transition: bottom var(--t) var(--ease);
}

@supports (height: 100dvh) {
    .select-panel.select-panel-sheet {
        max-height: min(72dvh, calc(100dvh - var(--kb-inset, 0px) - 16px));
    }
}

.select-panel-sheet .select-search {
    padding: 10px;
    padding-left: max(10px, var(--safe-l, 0px));
    padding-right: max(10px, var(--safe-r, 0px));
}

.select-panel-sheet .select-search input {
    height: 40px;
    font-size: 16px;
}

.select-panel-sheet .select-list {
    flex: 1;
    min-height: 0;
    max-height: none;
    padding: 6px 8px calc(6px + var(--safe-b, 0px));
    padding-left: max(8px, var(--safe-l, 0px));
    padding-right: max(8px, var(--safe-r, 0px));
}

.select-panel-sheet .select-option {
    padding: 12px;
    font-size: 14px;
}

/* ------- 窄屏排版 ------- */
@media (max-width: 720px) {

    /* 标签数量多的标签组（发布面板 4 个接口示例页签）改为横向可滑，
       不再撑破弹窗。只作用于显式声明 .seg-tabs-scroll 的实例，
       编辑器/技能库那种等分铺满的标签组不受影响 */
    .seg-tabs-scroll {
        display: flex;
        max-width: 100%;
        overflow-x: auto;
        overflow-y: hidden;
        overscroll-behavior-x: contain;
        scrollbar-width: none;
    }

    .seg-tabs-scroll::-webkit-scrollbar {
        display: none;
    }

    .seg-tabs-scroll .seg-tab {
        flex: none;
    }

    .publish-code-row {
        flex-wrap: wrap;
    }

    .publish-code-main {
        flex: 1 1 100%;
    }

    .publish-example {
        padding: 12px 14px;
    }

    /* 复制按钮改为跟在示例下方，避免压住第一行命令 */
    .publish-example-copy {
        position: static;
        margin-top: 6px;
        margin-left: auto;
    }

    .publish-example-wrap {
        display: flex;
        flex-direction: column;
    }

    .gen-chat {
        max-height: 46vh;
        max-height: 46dvh;
    }

    .gen-start {
        width: 100%;
    }

    .empty {
        padding: 32px 14px;
    }
}
