/**
 * AI 助手输入框的 / 斜杠指令下拉与指令 chip
 *
 * 变量与交互规则复用 ai-mention.css（面板 fixed 挂 body、键盘模式屏蔽 hover、
 * 窄屏加大触摸目标），只在配色上区分：提及是蓝色，指令是紫色，
 * 让一条消息里同时出现两种 chip 时一眼能分清。
 */

:root {
    --ai-slash-bg: #ffffff;
    --ai-slash-border: #e5e7eb;
    --ai-slash-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
    --ai-slash-text: #111827;
    --ai-slash-muted: #6b7280;
    --ai-slash-active-bg: #f5f3ff;
    --ai-slash-active-text: #6d28d9;
}

[data-theme="dark"],
html.dark {
    --ai-slash-bg: #1f2937;
    --ai-slash-border: #374151;
    --ai-slash-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    --ai-slash-text: #f3f4f6;
    --ai-slash-muted: #9ca3af;
    --ai-slash-active-bg: rgba(139, 92, 246, 0.18);
    --ai-slash-active-text: #c4b5fd;
}

.ai-slash-panel {
    position: fixed;
    z-index: 12000;
    max-height: 280px;
    overflow-y: auto;
    background: var(--ai-slash-bg);
    border: 1px solid var(--ai-slash-border);
    border-radius: 10px;
    box-shadow: var(--ai-slash-shadow);
    padding: 4px;
    font-size: 13px;
    color: var(--ai-slash-text);
}

.ai-slash-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 7px;
    cursor: pointer;
    min-height: 36px;
}

/* 键盘导航时屏蔽 hover，否则会同时亮两行——理由见 ai-mention.css 的同名规则 */
.ai-slash-item.active {
    background: var(--ai-slash-active-bg);
    color: var(--ai-slash-active-text);
}

.ai-slash-panel:not(.is-keyboard) .ai-slash-item:hover {
    background: var(--ai-slash-active-bg);
    color: var(--ai-slash-active-text);
}

/* 图标槽位：回退层（拼图字形）与 <img> 叠在一起，<img> 加载失败时被藏掉、露出回退层。
   见 js/utils/plugin-icon.js —— 「失败」和「压根没配图标」在界面上就该长得一样 */
.ai-slash-item-icon-slot {
    position: relative;
    flex: 0 0 auto;
    display: inline-flex;
    width: 16px;
    height: 16px;
}

.ai-slash-item-icon {
    flex: 0 0 auto;
    font-size: 15px;
    opacity: 0.8;
}

.ai-slash-item-icon-slot .ai-slash-item-icon {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

/* 插件图标是 <img>，字号撑不出尺寸，得显式给宽高。
   contain 而非 cover：非正方形的品牌 logo 一裁就认不出是谁。
   底片固定浅色、不随主题反色 —— 单色深色 logo（GitHub 那类）在深色底上会直接消失，
   而 <img> 的颜色不归 CSS 管，靠主题变量救不回来 */
.ai-slash-item-icon-slot img.ai-slash-item-icon {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    object-fit: contain;
    padding: 1px;
    background: #fff;
    opacity: 1;
}

/* 未授权/待配置的插件仍然列出来——隐藏掉用户会以为插件没装上 */
.ai-slash-item.is-disabled .ai-slash-item-name,
.ai-slash-item.is-disabled .ai-slash-item-desc {
    opacity: 0.55;
}

/* 分组小标题：内建工具 / 插件。首个不加上边线，其余与上一组隔开 */
.ai-slash-group {
    padding: 4px 10px;
    font-size: 12px;
    color: var(--ai-slash-muted);
    user-select: none;
}

.ai-slash-group + .ai-slash-group,
.ai-slash-item + .ai-slash-group {
    margin-top: 4px;
    padding-top: 8px;
    border-top: 1px solid var(--ai-slash-border);
}

/* 内建组用字体图标，尺寸对齐插件 <img> 的 16px 槽位 */
.ai-slash-item-icon--builtin {
    width: 16px;
    text-align: center;
    font-size: 15px;
}

.ai-slash-item-name {
    flex: 0 1 auto;
    min-width: 0;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* basis 设 0：描述只吃剩余空间、也最先被压没，永远不跟工具名抢宽度 */
.ai-slash-item-desc {
    flex: 1 1 0;
    min-width: 0;
    color: var(--ai-slash-muted);
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-slash-item-plugin {
    flex: 0 0 auto;
    margin-left: auto;
    padding: 1px 6px;
    border-radius: 4px;
    border: 1px solid var(--ai-slash-border);
    color: var(--ai-slash-muted);
    font-size: 11px;
    line-height: 16px;
    max-width: 40%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-slash-hint {
    padding: 6px 10px 4px;
    border-top: 1px solid var(--ai-slash-border);
    margin-top: 4px;
    color: var(--ai-slash-muted);
    font-size: 11px;
}

.ai-slash-empty {
    padding: 10px 12px;
    color: var(--ai-slash-muted);
    font-size: 12px;
}

/* 冷启动首次取插件清单要连上每个 MCP 子进程，面板先出来、清单随后填 */
.ai-slash-empty.is-loading::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-left: 6px;
    border-radius: 50%;
    background: currentColor;
    animation: ai-slash-loading-pulse 1s ease-in-out infinite;
}

@keyframes ai-slash-loading-pulse {
    0%, 100% { opacity: 0.25; }
    50% { opacity: 1; }
}

@media (max-width: 1023px) {
    .ai-slash-item {
        min-height: 44px;
        padding: 10px 12px;
    }

    .ai-slash-item-desc,
    .ai-slash-hint {
        display: none;
    }
}

/* ============================================================
 * 指令 chip
 *
 * 与提及 chip 同构：contenteditable="false" 的原子节点，整体选中、退格一次整块删除。
 * ============================================================ */
.ai-slash-chip {
    display: inline;
    padding: 0 6px;
    margin: 0 1px;
    border-radius: 5px;
    background: var(--ai-slash-active-bg);
    color: var(--ai-slash-active-text);
    font-size: 0.875rem;
    line-height: 1.5;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
    cursor: default;
    user-select: all;
}

/* 消息气泡中的指令复用输入框 chip，只取消编辑态专属的交互语义。与 @ 提及同构 */
.ai-message-slash-chip {
    vertical-align: baseline;
    cursor: text;
    user-select: text;
}

/* 深色阅读主题下用户气泡是浅色纸张底，紫色要压深一档才看得清（同 ai-mention.css） */
[data-theme="dark"] .kb-paper-app .message-user .ai-message-slash-chip,
html.dark .kb-paper-app .message-user .ai-message-slash-chip {
    color: #5b21b6;
}

.ai-slash-chip::selection,
.ai-slash-chip ::selection {
    background: var(--ai-slash-active-text);
    color: var(--ai-slash-bg);
}

/*
 * 输入框里存在斜杠指令时，联网与图片按钮锁定。
 *
 * 独立类名而不是复用 setInputDisabled 的那几个 class：两者的生效条件不同，
 * 混在一起时「AI 未配置 + 有指令」解锁一次就会把两种锁一起放开。
 */
.ai-web-search-btn.is-slash-locked,
.ai-upload-btn.is-slash-locked {
    pointer-events: none;
    cursor: not-allowed;
    color: var(--kb-control-disabled-text);
}
