/* 爆单AI · 豆包式UI（会话72迭代·K哥定·回归黑白极简）
 * 设计原则：和现有正式服页面一致，纯黑白灰，告别橙红
 * 配色基准(来自index.html): 黑#1a1a1a + 白#FFFFFF + 灰#f7f7f8/#e8e8ea
 * 会话72迭代: 去掉头像(豆包式纯内容) + 加搜索框 + 列表...菜单(编辑/删除/置顶)
 */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    /* 会话72迭代3: 反转配色(豆包式) - 背景白/AI气泡浅灰，告别灰底白气泡 */
    --bg-main: #ffffff;          /* 主区背景: 白(原#f7f7f8灰) */
    --bg-sidebar: #f7f7f8;       /* 侧边栏背景: 浅灰(原白) */
    --bg-card: #ffffff;
    --bg-bubble-ai: #f1f1f3;     /* AI气泡: 浅灰(原白带边框) - 豆包式 */
    --border: #e8e8ea;
    --text-primary: #1a1a1a;
    --text-secondary: #666;
    --text-tertiary: #999;
    --bubble-user: #1a1a1a;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.06);
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

/* === 整体双栏布局 === */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* === 侧边栏（豆包式极简纯文字）=== */
.sidebar {
    width: 240px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.25s ease;
}

.sidebar-header {
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand {
    display: flex;
    align-items: center;
    text-decoration: none;
}
.brand-logo {
    height: 28px;
    width: auto;
}

/* 豆包式新建对话：小图标按钮，不要大橙按钮 */
.new-chat-icon {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.new-chat-icon:hover { background: rgba(0,0,0,0.05); color: var(--text-primary); }

/* 搜索框（豆包式极简）*/
.search-box {
    margin: 0 12px 8px;
    position: relative;
    display: flex;
    align-items: center;
}
.search-icon {
    position: absolute;
    left: 10px;
    color: var(--text-tertiary);
    pointer-events: none;
}
.search-input {
    width: 100%;
    padding: 7px 10px 7px 30px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    background: #f5f5f7;
    outline: none;
    transition: background 0.15s;
    font-family: inherit;
    color: var(--text-primary);
}
.search-input::placeholder { color: var(--text-tertiary); }
.search-input:focus { background: #ededf0; }

/* 会话列表（豆包式：纯文字左对齐 + ...菜单）*/
.conv-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

.conv-item {
    display: flex;
    align-items: center;
    padding: 9px 12px 9px 16px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 14px;
    transition: background 0.12s;
    position: relative;
    line-height: 1.4;
}
.conv-item:hover { background: rgba(0,0,0,0.04); color: var(--text-primary); }
.conv-item.active { background: rgba(0,0,0,0.06); color: var(--text-primary); font-weight: 500; }
.conv-item.pinned .conv-title::before {
    content: '📌 ';
    font-size: 11px;
}

.conv-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 4px;
}

/* 豆包式 ... 菜单按钮 */
.conv-menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    flex-shrink: 0;
    font-size: 16px;
    line-height: 1;
    font-weight: bold;
}
.conv-item:hover .conv-menu-btn,
.conv-item.active .conv-menu-btn { display: block; }
.conv-menu-btn:hover { background: rgba(0,0,0,0.08); color: var(--text-primary); }

/* 下拉菜单 */
.conv-menu {
    position: absolute;
    right: 8px;
    top: 36px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    padding: 4px;
    z-index: 50;
    min-width: 100px;
}
.conv-menu-item {
    display: block;
    width: 100%;
    padding: 7px 12px;
    background: none;
    border: none;
    text-align: left;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 4px;
    font-family: inherit;
}
.conv-menu-item:hover { background: #f5f5f7; }
.conv-menu-item.danger:hover { background: #fff1f0; color: #cf1322; }

/* === 主区 === */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-main);
}

.chat-header {
    height: 52px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
    position: relative;  /* 会话72: 让标题绝对居中 */
}
.chat-title {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
    position: absolute;  /* 豆包式: 标题绝对居中 */
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    max-width: calc(100% - 200px);  /* 两侧避开菜单/头像 */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
}
.header-spacer { flex: 1; }

.icon-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
}
.icon-btn:hover { background: rgba(0,0,0,0.04); }

/* 右上角个人中心入口（和正式服index.html一致：头像按钮+下拉菜单）*/
.avatar-wrap {
    position: relative;
    flex-shrink: 0;
}
.avatar-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #f0f0f2;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    flex-shrink: 0;
    transition: all 0.15s;
    border: 1px solid var(--border);
    cursor: pointer;
    overflow: hidden;
    padding: 0;
}
.avatar-btn:hover { background: #e8e8ea; }
.avatar-placeholder { font-size: 15px; }
#avatarImg { width: 100%; height: 100%; object-fit: cover; display: none; }

/* 下拉菜单（和正式服dropdownMenu一致结构）*/
.dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    top: 42px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0,0,0,0.13);
    min-width: 200px;
    z-index: 100;
    overflow: hidden;
}
.dropdown-menu.show { display: block; }
.dd-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid #f5f5f7;
}
.dd-user .dd-icon { font-size: 16px; }
.dd-nickname { font-size: 14px; font-weight: 500; color: var(--text-primary); }
.dd-uid { font-size: 11px; color: var(--text-tertiary); margin-top: 2px; }
.dd-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 13px;
    transition: background 0.12s;
}
.dd-item:hover { background: #f7f7f8; color: var(--text-primary); }
.dd-icon-gray { color: var(--text-tertiary); }
.dd-icon-orange { color: #ff6b00; }
.dd-logout { border-top: 1px solid #f5f5f7; color: #cf1322; }
.dd-logout:hover { background: #fff1f0; color: #cf1322; }

/* === 消息流 === */
.messages-wrap {
    flex: 1;
    overflow-y: auto;
    scroll-behavior: smooth;
}
.messages {
    max-width: 820px;
    margin: 0 auto;
    padding: 24px 20px 32px;
}

.msg {
    display: flex;
    margin-bottom: 24px;
}
.msg.user { justify-content: flex-end; }

/* 豆包式：无头像，纯内容 */
.bubble-wrap {
    max-width: 78%;
    display: flex;
    flex-direction: column;
}
.msg.user .bubble-wrap { align-items: flex-end; }

.bubble {
    padding: 11px 15px;
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}
.msg.user .bubble {
    background: var(--bubble-user);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.msg.assistant .bubble {
    background: var(--bg-bubble-ai);  /* 豆包式: 浅灰气泡,无边框 */
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}
/* AI bubble 内的 markdown 渲染 */
.msg.assistant .bubble { white-space: normal; }
.msg.assistant .bubble p { margin: 8px 0; white-space: pre-wrap; }
.msg.assistant .bubble p:first-child { margin-top: 0; }
.msg.assistant .bubble p:last-child { margin-bottom: 0; }
.msg.assistant .bubble h1,
.msg.assistant .bubble h2,
.msg.assistant .bubble h3 {
    margin: 16px 0 8px;
    font-weight: 600;
    line-height: 1.3;
}
.msg.assistant .bubble h1 { font-size: 18px; }
.msg.assistant .bubble h2 { font-size: 16px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.msg.assistant .bubble h3 { font-size: 15px; }
.msg.assistant .bubble ul,
.msg.assistant .bubble ol { margin: 8px 0; padding-left: 24px; }
.msg.assistant .bubble li { margin: 4px 0; }
.msg.assistant .bubble code {
    background: #f5f5f7;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: "SF Mono", Consolas, Monaco, monospace;
    font-size: 13px;
}
.msg.assistant .bubble pre {
    background: #1a1a1a;
    color: #f1f1f3;
    padding: 12px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 8px 0;
}
.msg.assistant .bubble pre code { background: none; color: inherit; padding: 0; }
.msg.assistant .bubble table {
    border-collapse: collapse;
    width: 100%;
    margin: 12px 0;
    font-size: 13px;
    display: block;
    overflow-x: auto;
}
.msg.assistant .bubble th,
.msg.assistant .bubble td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
}
.msg.assistant .bubble th { background: #f5f5f7; font-weight: 600; }
.msg.assistant .bubble tr:nth-child(even) { background: #fafafa; }
.msg.assistant .bubble a { color: var(--text-primary); text-decoration: underline; text-underline-offset: 2px; }
.msg.assistant .bubble img {
    max-width: 220px;
    max-height: 220px;
    border-radius: var(--radius-sm);
    margin: 8px 0;
    cursor: pointer;
}
.msg.assistant .bubble strong { font-weight: 600; }
.msg.assistant .bubble blockquote {
    border-left: 3px solid var(--border);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--text-secondary);
}

/* 流式中的loading状态 */
.loading {
    color: var(--text-tertiary);
    font-style: italic;
}
.loading::after {
    content: '...';
    animation: dots 1.4s infinite;
}
@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* OPTIONS按钮区（保留会话67逻辑）*/
.options-container {
    max-width: 820px;
    margin: 0 auto 20px;
    padding: 0 20px;
}
.options-container.dismissed { display: none; }
.options-prompt {
    font-size: 13px;
    color: var(--text-tertiary);
    margin-bottom: 8px;
}
.option-btn {
    display: inline-block;
    padding: 7px 14px;
    margin: 4px 6px 4px 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 18px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.15s;
}
.option-btn:hover { border-color: var(--text-primary); }
.option-btn.recommended {
    background: var(--bubble-user);
    color: #fff;
    border-color: var(--bubble-user);
}
.option-btn.recommended:hover { background: #333; }

/* 文件卡片（保留会话67逻辑）*/
.file-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    max-width: 320px;
    transition: all 0.15s;
}
.file-card:hover { box-shadow: var(--shadow); }
.file-card-icon { font-size: 28px; }
.file-card-info { flex: 1; min-width: 0; }
.file-card-name { font-size: 14px; font-weight: 500; color: var(--text-primary); }
.file-card-meta { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; }
.file-card-action { color: var(--text-tertiary); font-size: 18px; }

/* === 输入栏（豆包式：白底+浅灰输入框）=== */
.chat-input-bar {
    background: var(--bg-card);  /* 白底 */
    padding: 12px 20px 12px;
}
.chat-input-bar.active .input-row {
    border-color: var(--text-primary);
}
.input-row {
    max-width: 820px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-bubble-ai);  /* 浅灰输入框(豆包式) */
    border: 1px solid transparent;    /* 无边框(豆包式) */
    border-radius: 22px;
    padding: 5px 5px 5px 8px;
    transition: all 0.15s;
}
.attach-btn {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    color: var(--text-secondary);
    flex-shrink: 0;
}
.attach-btn:hover { background: rgba(0,0,0,0.06); }

.chat-input {
    flex: 1;
    border: none;
    background: none;
    outline: none;
    resize: none;
    font-size: 14px;
    line-height: 1.5;
    padding: 8px 4px;
    max-height: 160px;
    font-family: inherit;
    color: var(--text-primary);
}
.chat-input::placeholder { color: var(--text-tertiary); }

.send-btn {
    background: var(--bubble-user);
    color: #fff;
    border: none;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
}
.send-btn:hover:not(:disabled) { background: #333; }
.send-btn:disabled { background: #ccc; cursor: not-allowed; }

/* === 响应式：移动端侧边栏可折叠 === */
.mobile-only { display: none; }

@media (max-width: 768px) {
    .mobile-only { display: block; }
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 100;
        width: 260px;
        transform: translateX(-100%);
        box-shadow: 2px 0 12px rgba(0,0,0,0.1);
    }
    .sidebar.open { transform: translateX(0); }
    .messages { padding: 16px 12px 24px; }
    .bubble-wrap { max-width: 85%; }
    .chat-header { padding: 0 12px; }
    .chat-input-bar { padding: 10px 12px 6px; }
}

/* 滚动条美化 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d0d0d4; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #b0b0b4; }


/* === 爆单侠公众号异步任务扫码弹窗（会话73·对齐扫码登录样式） === */
.async-modal {
    position: fixed; inset: 0; z-index: 1000;
    display: flex; align-items: center; justify-content: center;
}
.async-modal.hidden { display: none; }
.async-overlay {
    position: absolute; inset: 0;
    background: rgba(0,0,0,0.5);
}
/* 卡片:对齐扫码登录(w-80=320px px-8=32px py-7=28px rounded-2xl=16px) */
.async-card {
    position: relative; z-index: 10;
    background: #fff; border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.16);
    width: 320px; padding: 28px 32px;
    display: flex; flex-direction: column; align-items: center;
}
.async-header {
    width: 100%; display: flex; align-items: center; justify-content: center;
    margin-bottom: 24px; position: relative;
}
.async-title {
    font-size: 16px; font-weight: 600; color: var(--text-primary);
}
.async-close {
    position: absolute; right: 0; top: 50%; transform: translateY(-50%);
    background: none; border: none; font-size: 22px;
    color: var(--text-tertiary); cursor: pointer; line-height: 1;
    padding: 4px 8px;
}
.async-close:hover { color: var(--text-primary); }
/* 二维码容器:对齐扫码登录(130x130) */
.async-qr-container {
    width: 130px; height: 130px;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 20px auto;
    overflow: hidden;
}
.async-qr-container img {
    width: 130px; height: 130px; object-fit: contain;
}
.async-qr-loading {
    font-size: 13px; color: var(--text-tertiary);
}
/* 微信icon:对齐扫码登录(w-10 h-10容器+w-14 h-14图) */
.async-icon {
    width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 4px;
}
.async-icon img {
    width: 56px; height: 56px; object-fit: contain;
}
.async-subtitle {
    font-size: 12px; color: var(--text-tertiary);
    margin-bottom: 28px; text-align: center;
}
.async-status {
    font-size: 12px; color: var(--text-secondary);
    text-align: center; margin-bottom: 16px;
    padding: 8px 12px; background: #f1f1f3; border-radius: 6px;
    width: 100%;
}
.async-status.hidden { display: none; }
/* 确认按钮:对齐扫码登录的黑色按钮 */
.async-btn-primary {
    width: 100%; padding: 10px;
    background: var(--bubble-user); color: #fff;
    border: none; border-radius: 8px;
    font-size: 14px; font-weight: 500; cursor: pointer;
}
.async-btn-primary:hover { opacity: 0.9; }