/**
 * AI 助手输入框内置命令（/状态、/压缩）的浮层与消息流提示
 *
 * 浮层挂在 .ai-drawer-footer 里、输入框正上方（#aiCommandPanel），随底栏走，不另算定位。
 * 颜色全部取 reading-theme.css 的 --kb-* 变量，亮暗主题各自跟随。
 */

/* 上下边距由 ai-search.css「输入框上方叠放的几行」统一管（V3.196）：排在最上面时往上收 8px，前面有行露出来时不收 */

.ai-command-panel[hidden] {
    display: none;
}

.ai-command-card,
.ai-command-progress {
    background: var(--kb-paper-panel);
    border: 1px solid var(--kb-paper-line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    color: var(--kb-ink);
    font-size: 0.8125rem;
}

.ai-command-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--kb-paper-line);
}

.ai-command-card-title {
    font-weight: 600;
    /* 标题只有「状态」「压缩」一两个词，窄面板（移动端抽屉 / 输入区宽度被挤压）下
       也要单行；空间让给右侧关闭按钮，超长时省略号兜底 */
    flex: 0 1 auto;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-command-close {
    min-width: 44px;
    min-height: 32px;
    padding: 0 8px;
    border: none;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--kb-ink-muted);
    font: inherit;
    cursor: pointer;
    /* 与标题同处一行：按钮文字（关闭）也不换行，且不被压缩 */
    flex: 0 0 auto;
    white-space: nowrap;
}

.ai-command-close:hover {
    background: var(--kb-accent-soft);
    color: var(--kb-ink);
}

.ai-command-card-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 12px 12px;
}

/*
 * 底栏空间不够时（窗口矮、任务进度 / 插件 chip 同时展开）卡片跟着 #aiCommandPanel 一起缩，
 * 标题行与「关闭」不动、只滚内容（ai-search.css「底栏不许撑出聊天区」）；平时最多占半屏，不把对话全挤没
 */
.ai-command-card {
    display: flex;
    flex: 0 1 auto;
    flex-direction: column;
    min-height: 0;
}

.ai-command-card-head {
    flex-shrink: 0;
}

.ai-command-card-body {
    min-height: 0;
    max-height: 50vh;
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* 第一列按最长标签「会话/对话串」max-content 取宽、不参与压缩，保证标签一行不折；
   第二列才是可伸缩的弹性列（之前固定 5.5em 装不下「会话/对话串」5 个中文字） */
.ai-command-row {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    gap: 12px;
    align-items: baseline;
    line-height: 1.6;
}

.ai-command-label {
    color: var(--kb-ink-muted);
    /* 标签列禁止换行（grid 已给 max-content，这里兜底防斜杠处断行） */
    white-space: nowrap;
}

.ai-command-value {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-width: 0;
    word-break: break-all;
}

.ai-command-value code {
    font-size: 0.75rem;
    color: var(--kb-ink-soft);
}

.ai-command-muted {
    color: var(--kb-ink-muted);
}

/* 用量条：已用部分实心、剩余部分只留底色（Codex 的样子，去掉了限额那两行） */
.ai-command-meter {
    position: relative;
    display: inline-block;
    flex: 0 0 160px;
    height: 8px;
    overflow: hidden;
    border-radius: var(--radius-full);
    background: var(--kb-accent-soft);
}

.ai-command-meter > span {
    position: absolute;
    inset: 0 auto 0 0;
    border-radius: inherit;
    background: var(--kb-accent);
}

.ai-command-progress {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: var(--radius-full);
}

.ai-command-spin {
    font-size: 1rem;
    color: var(--kb-accent);
    animation: ai-command-spin 1s linear infinite;
}

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

/* 压缩完成后插在消息流末尾的一行分隔提示（不落库，刷新即消失） */
.ai-command-notice {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin: 12px 0;
    color: var(--kb-ink-muted);
    font-size: 0.75rem;
}

.ai-command-notice::before,
.ai-command-notice::after {
    content: '';
    flex: 1 1 auto;
    height: 1px;
    background: var(--kb-paper-line);
}

@media (max-width: 1023px) {
    .ai-command-row {
        /* 移动端同样由内容决定标签列宽，避免「会话/对话串」折行；
           仅收紧列间距以省横向空间 */
        gap: 8px;
    }

    .ai-command-meter {
        flex-basis: 100%;
    }
}
