/* AI 助手：工作区右侧的对话面板，以及设置页的接口配置项。
   与桌面版 EsprinNemo 的 styles/ai.css 逐条对应。 */

/* 标题栏入口：面板展开时高亮 */
.btn-action-icon.active {
    color: var(--accent);
    background-color: var(--accent-bg);
}

/* 1. 对话面板 */
.ai-panel {
    position: relative;
    --ai-panel-width: 360px;
    width: var(--ai-panel-width);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    background-color: var(--bg-list);
    border-left: 1px solid var(--border-color);
    transition: width var(--motion-slow) cubic-bezier(0.22, 0.61, 0.36, 1),
                border-left-width var(--motion-slow) ease;
}
.ai-panel.ai-collapsed {
    width: 0;
    border-left-width: 0;
}
.ai-panel-header,
.ai-messages,
.ai-composer {
    min-width: var(--ai-panel-width);
}

/* 现代布局的窗口拖动区：垫在面板顶栏上方的一条空白（见 styles/mode.css） */
.ai-panel-drag-strip {
    display: none;
    height: 40px;
    flex-shrink: 0;
}

.ai-panel-header {
    height: 40px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 6px 0 12px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
}
.ai-panel-title {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}
.ai-panel-model {
    max-width: 88px;
    padding: 1px 8px;
    border-radius: var(--radius-pill);
    background: var(--item-hover);
    font-family: var(--font-mono);
    font-size: 10.5px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ai-panel-header .btn-action-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}
.ai-panel-spacer {
    flex: 1;
}

/* 2. 对话记录抽屉 */
.ai-drawer {
    position: absolute;
    top: 40px;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 6;
    display: flex;
    flex-direction: column;
    background: var(--bg-list);
}
.ai-drawer-header {
    height: 36px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 6px 0 12px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
}
.ai-drawer-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
}
.ai-drawer-new {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 24px;
    padding: 0 10px;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: var(--accent-fg);
    font-size: 11.5px;
    font-weight: 500;
    transition: opacity 0.15s;
}
.ai-drawer-new:hover {
    opacity: 0.9;
}
.ai-chat-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.ai-chat-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background-color 0.15s;
}
.ai-chat-item:hover {
    background: var(--item-hover);
}
.ai-chat-item.active {
    background: var(--accent-bg);
}
.ai-chat-item-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.ai-chat-item-title {
    font-size: 12.5px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ai-chat-item.active .ai-chat-item-title {
    color: var(--accent);
    font-weight: 500;
}
.ai-chat-item-meta {
    font-size: 10.5px;
    color: var(--text-muted);
}
.ai-chat-item-meta.streaming {
    color: var(--accent);
}
.ai-chat-item-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.15s;
}
.ai-chat-item:hover .ai-chat-item-actions,
.ai-chat-item.active .ai-chat-item-actions {
    opacity: 1;
}
.ai-chat-action {
    width: 22px;
    height: 22px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    transition: background-color 0.15s, color 0.15s;
}
.ai-chat-action:hover {
    background: var(--item-active);
    color: var(--text-primary);
}
.ai-chat-action.danger:hover {
    color: var(--danger);
}
.ai-chat-empty {
    padding: 24px 12px;
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
}
.ai-drawer-footer {
    flex-shrink: 0;
    padding: 8px 12px;
    border-top: 1px solid var(--border-light);
    font-size: 10.5px;
    color: var(--text-muted);
}
.ai-scope-select {
    flex-shrink: 0;
    padding: 3px 6px;
    background: var(--item-hover);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 11.5px;
    cursor: pointer;
}
.ai-scope-select option {
    background: var(--bg-list);
    color: var(--text-primary);
}

/* 3. 对话记录（消息气泡） */
.ai-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 14px 12px 18px 12px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.ai-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 28px 8px;
    text-align: center;
    color: var(--text-muted);
}
.ai-empty > .ms-icon {
    font-size: 34px;
    color: var(--text-muted);
    opacity: 0.6;
}
.ai-empty p {
    font-size: 12.5px;
    line-height: 1.6;
}
.ai-empty .ai-empty-hint {
    font-size: 11.5px;
    color: var(--text-muted);
    opacity: 0.85;
}
.ai-example {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    margin-top: 2px;
}
.ai-example-chip {
    padding: 4px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-pill);
    color: var(--text-secondary);
    font-size: 11.5px;
    transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}
.ai-example-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-bg);
}

.ai-msg {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.ai-msg-role {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text-muted);
}
.ai-msg-context {
    margin-left: 4px;
    padding: 0 6px;
    border-radius: var(--radius-pill);
    background: var(--item-hover);
    font-size: 10.5px;
    opacity: 0.9;
}
.ai-msg-body {
    padding: 9px 11px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-body);
    font-size: 12.5px;
    line-height: 1.65;
    color: var(--text-primary);
    word-break: break-word;
    overflow-wrap: anywhere;
}
.ai-msg-user .ai-msg-body {
    background: var(--accent-bg);
    border-color: transparent;
    white-space: pre-wrap;
}
.ai-msg-failed .ai-msg-body {
    background: var(--danger-bg);
    border-color: var(--danger);
    color: var(--danger);
}
.ai-msg-canceled .ai-msg-body {
    background: transparent;
    border-style: dashed;
    color: var(--text-muted);
}
/* 回复正文允许拖选，与桌面版（EsprinNemo 的 src/renderer/styles/ai.css）同一条规则：
   桌面版那边是必需的——全局重置把每个元素都写成 user-select: none，而该属性不继承，
   子节点不会从父节点顺回 text，所以正文与它内部的 Markdown 节点必须一起放行；
   网页版再补一份 -webkit- 前缀，iOS Safari 的长按拖选才认。
   Agent 卡片里的步骤摘要与详情同理 */
.ai-msg-content,
.ai-msg-content *,
.ai-step-label,
.ai-step-detail {
    -webkit-user-select: text;
    user-select: text;
    cursor: text;
}
.ai-msg-body .markdown-body {
    font-size: 12.5px;
    line-height: 1.65;
}
.ai-msg-body .markdown-body > *:first-child { margin-top: 0; }
.ai-msg-body .markdown-body > *:last-child { margin-bottom: 0; }
.ai-msg-body .markdown-body h1 { font-size: 15px; }
.ai-msg-body .markdown-body h2 { font-size: 14px; }
.ai-msg-body .markdown-body h3,
.ai-msg-body .markdown-body h4 { font-size: 13px; }
.ai-typing {
    color: var(--text-muted);
}

/* 回答下方的操作：复制 / 插入当前笔记 / 存为新笔记 */
.ai-msg-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.15s;
}
.ai-msg:hover .ai-msg-actions,
.ai-msg:focus-within .ai-msg-actions {
    opacity: 1;
}
.ai-msg-action {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 7px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 11px;
    transition: background-color 0.15s, color 0.15s;
}
.ai-msg-action:hover {
    background: var(--item-hover);
    color: var(--text-primary);
}

/* 4. 输入区 */
.ai-composer {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px 12px 12px;
}
/* 输入框这一层「字段」：边框、底色与圆角挂在它身上，正文与内部那条底栏各占一行。
   底栏排在正文下方而不是叠在正文上，所以输入框内部滚动时正文不会钻到按钮底下；
   底栏左端是附带范围下拉，右端依次是 Agent 模式开关、附件与发送按钮。 */
.ai-input-wrap {
    display: flex;
    flex-direction: column;
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-body);
    color: var(--text-primary);
    transition: border-color 0.15s;
}
.ai-input-wrap:focus-within {
    border-color: var(--accent);
}
.ai-input {
    width: 100%;
    min-height: 62px;
    max-height: 170px;
    padding: 8px 10px 4px 10px;
    background: transparent;
    font-family: inherit;
    font-size: 12.5px;
    line-height: 1.6;
    resize: none;
    user-select: text;
}
.ai-composer-bar {
    display: flex;
    align-items: center;
    /* 靠左排：下拉留在左端，右端按钮组由下拉的 auto 外边距顶到最右缘 */
    justify-content: flex-start;
    gap: 6px;
    /* 贴在输入框内沿：左边与正文的左内边距对齐，右边与底边各留一点余量 */
    padding: 0 6px 6px 10px;
}
/* 附带范围下拉（自绘下拉的外层见 styles/overlays.css）：笔记名可能很长，
   所以它得会缩——缩到放不下时由触发器里的 .dropdown-label 显示省略号；
   它右侧的 auto 外边距负责把右端按钮组顶到最右缘 */
.ai-composer-bar .dropdown {
    flex: 0 1 auto;
    min-width: 0;
    margin-right: auto;
}
.ai-composer-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
/* 发送按钮：只留一枚图标、不带按钮底色，颜色用主题色（--accent 跟随品牌色设置） */
.ai-send-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: var(--radius-sm);
    color: var(--accent);
    transition: color 0.15s, opacity 0.15s;
}
.ai-send-btn .ms-icon {
    font-size: 20px;
}
.ai-send-btn:hover:not(:disabled) {
    opacity: 0.75;
}
/* 不可发送时（输入框空着）淡淡地留在原地：颜色仍是主题色，只是褪下去一档 */
.ai-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
/* 停止按钮：占的是同一个位置，换成中性色以便与「发送」区分开 */
#btn-ai-stop {
    color: var(--text-secondary);
}
#btn-ai-stop:hover:not(:disabled) {
    color: var(--text-primary);
    opacity: 1;
}
/* Agent 开关与附件按钮与发送同尺寸；开关开启时由 .btn-action-icon.active 点亮，不必另写样式 */
.ai-composer-bar .btn-action-icon {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}
.ai-composer-bar .ai-scope-select {
    /* 触发器继承了原生 select 的 flex-shrink: 0，这里放开，笔记名过长时才能收缩 */
    flex-shrink: 1;
    min-width: 0;
}

/* 5. 附件：待发送条、缩略图与消息里的附件卡片 */
.ai-attach-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 132px;
    overflow-y: auto;
}
.ai-attach-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}
.ai-attach-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    max-width: 100%;
    padding: 4px 6px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-body);
    color: var(--text-secondary);
}
.ai-attach-strip .ai-attach-chip {
    background: var(--item-hover);
}
.ai-attach-chip.image {
    padding-left: 4px;
}
.ai-attach-thumb {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    border-radius: var(--radius-xs);
    object-fit: cover;
    background: var(--item-active);
}
.ai-attach-info {
    min-width: 0;
}
.ai-attach-name {
    font-size: 11.5px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 190px;
}
.ai-attach-meta {
    font-size: 10px;
    color: var(--text-muted);
}
.ai-attach-remove {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    transition: color 0.15s, background-color 0.15s;
}
.ai-attach-remove:hover {
    background: var(--item-active);
    color: var(--danger);
}
.ai-panel.drop-active {
    outline: 2px dashed var(--accent);
    outline-offset: -6px;
}
.ai-panel.drop-active .ai-input-wrap {
    border-color: var(--accent);
}

/* Agent 操作卡片：一轮工具调用与它们的执行结果 */
.ai-msg-agent .ai-msg-body {
    border-style: dashed;
}
.ai-msg-agent .ai-agent-steps {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.ai-agent-steps .ai-msg-content + .ai-step {
    margin-top: 8px;
}
.ai-step {
    display: flex;
    align-items: flex-start;
    gap: 6px;
}
.ai-step > .ms-icon {
    margin-top: 2px;
    color: var(--accent);
}
.ai-step.running > .ms-icon {
    color: var(--text-muted);
    animation: aiStepSpin 1s linear infinite;
}
.ai-step.failed > .ms-icon {
    color: var(--danger);
}
@keyframes aiStepSpin {
    to { transform: rotate(360deg); }
}
.ai-step-info {
    flex: 1;
    min-width: 0;
}
.ai-step-label {
    font-size: 12px;
    color: var(--text-primary);
}
.ai-step-detail {
    margin-top: 2px;
    font-size: 11px;
    color: var(--text-muted);
    word-break: break-word;
}

/* 7. 设置页：AI 分类里的输入控件 */
.settings-input {
    flex-shrink: 0;
    width: 260px;
    padding: 7px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-body);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 13px;
    user-select: text;
    transition: border-color 0.15s;
}
.settings-input.mono {
    font-family: var(--font-mono);
    font-size: 12px;
}
.settings-input.short {
    width: 90px;
}
.settings-input.textarea {
    width: 300px;
    min-height: 68px;
    line-height: 1.6;
    resize: vertical;
}
.settings-input:focus {
    border-color: var(--accent);
}
.ai-input-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.ai-input-stack {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    flex-shrink: 0;
}
.ai-quick-fill {
    display: flex;
    align-items: center;
    gap: 6px;
}
.ai-key-hint {
    font-size: 11px;
    color: var(--text-muted);
}
.ai-quick-fill-label {
    font-size: 11px;
    color: var(--text-muted);
}
.ai-quick-chip {
    padding: 2px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-pill);
    background: var(--bg-body);
    color: var(--text-secondary);
    font-size: 11.5px;
    transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}
.ai-quick-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-bg);
}
.settings-btn.icon-only {
    width: 30px;
    padding: 0;
}
.ai-status[data-tone='ok'] {
    color: var(--accent);
}
.ai-status[data-tone='error'] {
    color: var(--danger);
}

@media (prefers-reduced-motion: reduce) {
    .ai-panel {
        transition: none !important;
    }
}
