/* ============================================================
 * AI 智能助手聊天页样式
 * ============================================================ */

/* ---------- 会话列表 ---------- */
.ai-conv-list {
    max-height: 520px;
    overflow-y: auto;
    margin: 0 -4px;
}

.ai-conv-item {
    position: relative;
    padding: 8px 30px 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background .15s, border-color .15s;
}

.ai-conv-item:hover {
    background: rgba(13, 110, 253, .06);
}

.ai-conv-item.active {
    background: rgba(13, 110, 253, .1);
    border-color: rgba(13, 110, 253, .35);
}

.ai-conv-item .ai-conv-title {
    font-size: .875rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-conv-item .ai-conv-meta {
    font-size: .72rem;
    color: #8a8f99;
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-conv-del {
    position: absolute;
    top: 6px;
    right: 4px;
    width: 22px;
    height: 22px;
    line-height: 1;
    border: 0;
    background: transparent;
    color: #b6bac2;
    border-radius: 50%;
    font-size: .8rem;
    opacity: 0;
    transition: opacity .15s, color .15s;
}

.ai-conv-item:hover .ai-conv-del {
    opacity: 1;
}

.ai-conv-del:hover {
    color: #dc3545;
    background: rgba(220, 53, 69, .1);
}

.ai-empty {
    color: #9aa0a6;
    font-size: .82rem;
    text-align: center;
    padding: 18px 6px;
}

/* ---------- 消息区 ---------- */
.ai-msg-box {
    height: 560px;
    overflow-y: auto;
    background: #f7f8fa;
    padding: 16px;
}

.ai-msg {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    align-items: flex-start;
}

.ai-msg .ai-avatar {
    flex: 0 0 34px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: #fff;
    background: #0d6efd;
}

.ai-msg.user {
    flex-direction: row-reverse;
}

.ai-msg.user .ai-avatar {
    background: #6c757d;
}

.ai-msg .ai-bubble {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid #e6e8ec;
    word-break: break-word;
    overflow-wrap: anywhere;
    font-size: .92rem;
    line-height: 1.75;
}

.ai-msg.user .ai-bubble {
    background: #0d6efd;
    border-color: #0d6efd;
    color: #fff;
}

.ai-msg .ai-time {
    font-size: .7rem;
    color: #a2a7ae;
    margin-top: 4px;
}

.ai-msg.user .ai-time {
    color: rgba(255, 255, 255, .75);
    text-align: right;
}

.ai-msg .ai-cost {
    display: inline-block;
    font-size: .7rem;
    color: #dc3545;
    margin-top: 4px;
}

/* ---------- Markdown 内容 ---------- */
.ai-bubble p { margin: 0 0 .6em; }
.ai-bubble p:last-child { margin-bottom: 0; }
.ai-bubble h1, .ai-bubble h2, .ai-bubble h3, .ai-bubble h4 {
    font-size: 1.05rem;
    font-weight: 700;
    margin: .8em 0 .4em;
}
.ai-bubble ul, .ai-bubble ol { margin: 0 0 .6em; padding-left: 1.4em; }
.ai-bubble li { margin: .15em 0; }
.ai-bubble a { color: #0d6efd; text-decoration: underline; }
.ai-msg.user .ai-bubble a { color: #cfe2ff; }
.ai-bubble strong { font-weight: 700; }
.ai-bubble blockquote {
    margin: .6em 0;
    padding: .4em .8em;
    border-left: 3px solid #cfd4da;
    background: #f6f7f9;
    color: #606670;
}
.ai-bubble hr { margin: .8em 0; border-color: #e6e8ec; }

.ai-inline-code {
    background: rgba(27, 31, 35, .08);
    border-radius: 4px;
    padding: 1px 5px;
    font-size: .86em;
    font-family: Consolas, Monaco, "Courier New", monospace;
}

.ai-code {
    background: #1e222a;
    color: #e6edf3;
    border-radius: 8px;
    padding: 10px 12px;
    overflow-x: auto;
    font-size: .82rem;
    line-height: 1.6;
    margin: .6em 0;
}

.ai-code code {
    font-family: Consolas, Monaco, "Courier New", monospace;
    white-space: pre;
    color: inherit;
    background: transparent;
    padding: 0;
}

/* 打字光标 */
.ai-cursor::after {
    content: '▍';
    display: inline-block;
    color: #0d6efd;
    animation: ai-blink 1s step-start infinite;
}

@keyframes ai-blink {
    50% { opacity: 0; }
}

/* ---------- 站内推荐卡片 ---------- */
.ai-refs {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px dashed #e2e5ea;
}

.ai-refs-title {
    font-size: .76rem;
    color: #6c757d;
    margin-bottom: 6px;
}

.ai-ref {
    display: block;
    padding: 6px 10px;
    margin-bottom: 6px;
    border-radius: 8px;
    background: #fff;
    border: 1px solid #e6e8ec;
    text-decoration: none;
    color: inherit;
    transition: border-color .15s, box-shadow .15s;
}

.ai-ref:hover {
    border-color: #0d6efd;
    box-shadow: 0 2px 8px rgba(13, 110, 253, .12);
}

.ai-ref .ai-ref-type {
    display: inline-block;
    font-size: .68rem;
    padding: 1px 6px;
    border-radius: 4px;
    background: rgba(13, 110, 253, .1);
    color: #0d6efd;
    margin-right: 6px;
    vertical-align: middle;
}

.ai-ref .ai-ref-title {
    font-size: .85rem;
    font-weight: 600;
    color: #212529;
}

.ai-ref .ai-ref-excerpt {
    font-size: .76rem;
    color: #8a8f99;
    margin-top: 2px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ---------- 输入区 ---------- */
#input {
    resize: none;
    min-height: 46px;
}

/* ---------- 附件缩略图 ---------- */
#attachList:empty {
    display: none;
}

.ai-att-item {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 52px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #e0e3e8;
    background: #fff;
}

.ai-att-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.ai-att-del {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    line-height: 16px;
    text-align: center;
    border: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, .55);
    color: #fff;
    font-size: .75rem;
    padding: 0;
    cursor: pointer;
}

.ai-att-del:hover {
    background: #dc3545;
}

/* ---------- AI 生成的图片 / 视频 ---------- */
.ai-gen-media {
    max-width: 100%;
    max-height: 420px;
    border-radius: 10px;
    display: block;
    margin: .4em 0;
}

video.ai-gen-media {
    width: 100%;
    max-width: 520px;
    background: #000;
}

/* ---------- 下载按钮组 ---------- */
.ai-dl {
    margin-top: 6px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.ai-dl a,
.ai-dl button {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: .8rem;
    padding: 3px 12px;
    border-radius: 6px;
    border: 1px solid #d3d8df;
    background: #fff;
    color: #0d6efd;
    text-decoration: none;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}

.ai-dl a:hover,
.ai-dl button:hover {
    border-color: #0d6efd;
    background: rgba(13, 110, 253, .06);
}

/* ---------- 文档面板 ---------- */
#docPanel {
    background: #f8f9fb;
    border: 1px dashed #dde1e7;
    border-radius: 8px;
    padding: 10px 12px;
}

#docText {
    resize: vertical;
    font-size: .85rem;
}

#docStatus {
    color: #6c757d;
}

/* ---------- 历史对话抽屉辅助元素：桌面端不显示 ---------- */
.ai-side-head {
    display: none;
}

.ai-side-mask {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1055;
    background: rgba(15, 23, 42, .45);
}

/* ---------- 移动端 ---------- */
@media (max-width: 991.98px) {
    /* 消息区高度由脚本按可视区计算，此处仅给兜底值 */
    .ai-chat-card .ai-msg-box {
        height: 60vh;
        min-height: 200px;
    }
    .ai-msg .ai-bubble { max-width: 92%; }

    /* 输入区固定在屏幕底部，页面内容给底栏留出空间 */
    .ai-chat-footer {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1045;
        max-height: 62vh;
        overflow-y: auto;
        padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
        border-top: 1px solid #e6e8ec;
        box-shadow: 0 -4px 16px rgba(15, 23, 42, .10);
    }
    .ai-chat-tip { display: none; }
    #input { min-height: 42px; }

    /* 历史对话：折叠为左侧抽屉 */
    .ai-side-col { display: none; }
    .ai-side-col.ai-side-open {
        display: block;
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: 82%;
        max-width: 340px;
        z-index: 1060;
        padding: 12px;
        background: #fff;
        border-radius: 0;
        box-shadow: 2px 0 20px rgba(15, 23, 42, .22);
        overflow-y: auto;
    }
    .ai-side-col.ai-side-open .card {
        height: auto !important;
        border: 0;
        box-shadow: none;
    }
    .ai-side-col.ai-side-open .ai-conv-list { max-height: none; }
    .ai-side-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 10px;
        padding-bottom: 8px;
        border-bottom: 1px solid #eceef2;
    }
    .ai-side-mask.show { display: block; }
}
