/* ===== 基础 ===== */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif;
    font-size: 15px; line-height: 1.7;
    color: #1f2328; background: #ffffff;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}
a { color: #10a37f; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== 登录页 ===== */
.login-page { display: flex; align-items: center; justify-content: center; background: #f7f7f8; padding: 20px; }
.login-box {
    width: 100%; max-width: 360px; background: #fff;
    padding: 32px 28px; border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0,0,0,.08);
}
.login-box h1 { margin: 0 0 24px; font-size: 24px; text-align: center; color: #10a37f; }
.login-box input {
    width: 100%; padding: 12px 14px; margin-bottom: 12px;
    border: 1px solid #d9d9e3; border-radius: 10px; font-size: 16px; outline: none;
}
.login-box input:focus { border-color: #10a37f; }
.login-box button {
    width: 100%; padding: 12px; border: none; border-radius: 10px;
    background: #10a37f; color: #fff; font-size: 16px; cursor: pointer;
}
.login-box button:hover { background: #0d8f6f; }
.error-text { color: #c00; text-align: center; margin: 0 0 12px; font-size: 14px; }

/* ===== 布局 ===== */
body.layout-with-sidebar {
    display: flex; height: 100vh; height: 100dvh;
    overflow: hidden; background: #fff;
}

.conv-sidebar {
    width: 280px; flex-shrink: 0;
    background: #f7f7f8;
    border-right: 1px solid #ececf1;
    display: flex; flex-direction: column;
    height: 100vh; height: 100dvh;
}
.conv-sidebar-top { padding: 14px 12px; border-bottom: 1px solid #ececf1; }
.btn-new-chat {
    display: block; text-align: center; padding: 10px 12px;
    background: #10a37f; color: #fff !important;
    border-radius: 10px; font-size: 14px; text-decoration: none;
}
.btn-new-chat:hover { background: #0d8f6f; text-decoration: none; }

.conv-list { flex: 1; overflow-y: auto; padding: 8px; -webkit-overflow-scrolling: touch; }

.conv-group { margin-bottom: 4px; }
.conv-group-label {
    padding: 12px 10px 6px;
    font-size: 12px; font-weight: 500;
    color: #9b9ba3; letter-spacing: .3px; user-select: none;
}
.conv-group:first-child .conv-group-label { padding-top: 6px; }

.conv-item { display: flex; align-items: center; border-radius: 8px; margin-bottom: 2px; }
.conv-item:hover { background: #ececf1; }
.conv-item.active { background: #e6f6f0; }
.conv-link {
    flex: 1; padding: 9px 10px;
    color: #333 !important; font-size: 14px; text-decoration: none;
    overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.conv-link:hover { text-decoration: none; }
.conv-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-del {
    padding: 4px 10px; color: #aaa !important;
    font-size: 18px; line-height: 1; text-decoration: none;
    visibility: hidden;
}
.conv-item:hover .conv-del { visibility: visible; }
.conv-del:hover { color: #dc2626 !important; }
.conv-empty { padding: 20px 10px; text-align: center; color: #aaa; font-size: 13px; }

.conv-edit {
    padding: 4px 6px; border: none; background: transparent;
    color: #aaa; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    visibility: hidden; border-radius: 4px;
}
.conv-edit:hover { color: #10a37f; background: #e6f6f0; }
.conv-item:hover .conv-edit { visibility: visible; }
.conv-item.editing .conv-edit { visibility: hidden; }

.conv-rename-input {
    flex: 1; min-width: 0; margin: 0 4px;
    padding: 6px 8px; font-size: 14px; font-family: inherit;
    color: #333; border: 1px solid #10a37f; border-radius: 6px;
    outline: none; background: #fff;
}

.conv-sidebar-bottom {
    padding: 14px 16px; border-top: 1px solid #ececf1;
    font-size: 14px; color: #444;
}
.conv-sidebar-bottom .user-info { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; min-width: 0; }
.conv-sidebar-bottom .user-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: #10a37f; color: #fff;
    font-size: 15px; font-weight: 600;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; text-transform: uppercase;
}
.conv-sidebar-bottom .user-name {
    font-size: 15px; font-weight: 600; color: #1f2328;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv-sidebar-bottom .user-links { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; }
.conv-sidebar-bottom .user-links a { color: #10a37f !important; }
.conv-sidebar-bottom .user-links a:hover { text-decoration: underline; }

/* ===== 主聊天区 ===== */
.chat-main {
    flex: 1; min-width: 0;
    display: flex; flex-direction: column;
    height: 100vh; height: 100dvh;
    overflow: hidden; position: relative;
}
.mobile-topbar { display: none; }

.chat-scroll {
    flex: 1; overflow-y: auto;
    width: 100%; max-width: 820px; margin: 0 auto;
    padding: 24px 20px 20px;
    display: flex; flex-direction: column; gap: 24px;
    -webkit-overflow-scrolling: touch;
}

.empty-hint { text-align: center; color: #888; margin-top: 80px; }
.empty-hint h2 { font-size: 22px; color: #333; margin-bottom: 8px; }

.msg { display: flex; gap: 12px; scroll-margin-top: 80px; }
.msg .avatar {
    width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; color: #fff; font-weight: 600;
}
.msg.user .avatar { background: #10a37f; }
.msg.assistant .avatar { background: #444; }
.msg .body { flex: 1; min-width: 0; }
.msg.user .body {
    background: #f0f0f0; border-radius: 14px; padding: 10px 14px;
    display: inline-block; max-width: 100%;
}
.msg.assistant .body { padding-top: 2px; }

.msg.assistant .body.streaming::after {
    content: '▋'; display: inline-block; margin-left: 2px;
    color: #10a37f; animation: blink 1s steps(1) infinite; font-weight: 400;
}
@keyframes blink { 50% { opacity: 0; } }

/* ===== Markdown ===== */
.markdown-body { font-size: 15px; line-height: 1.75; word-wrap: break-word; }
.markdown-body p { margin: 0 0 12px; }
.markdown-body h1, .markdown-body h2, .markdown-body h3 { margin: 18px 0 10px; line-height: 1.4; }
.markdown-body ul, .markdown-body ol { padding-left: 22px; margin: 0 0 12px; }
.markdown-body blockquote {
    margin: 0 0 12px; padding: 4px 14px; border-left: 4px solid #10a37f;
    color: #555; background: #f7f7f8; border-radius: 4px;
}
.markdown-body code {
    background: #f0f0f0; padding: 2px 5px; border-radius: 4px;
    font-size: 13px; font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}
.markdown-body pre {
    position: relative; background: #f6f8fa; border-radius: 10px;
    padding: 12px 14px; overflow-x: auto; margin: 0 0 14px;
}
.markdown-body pre code {
    background: transparent; padding: 0; font-size: 13px; line-height: 1.6;
}
.markdown-body table { border-collapse: collapse; margin: 0 0 14px; width: 100%; }
.markdown-body th, .markdown-body td { border: 1px solid #d9d9e3; padding: 6px 10px; text-align: left; }
.markdown-body img { max-width: 100%; }

/* ===== 复制按钮 ===== */
.code-copy-btn {
    position: absolute; right: 8px; top: 8px;
    background: #fff; border: 1px solid #d9d9e3; border-radius: 6px;
    padding: 3px 8px; font-size: 12px; color: #555; cursor: pointer;
    opacity: 0; visibility: hidden;
    transition: opacity .12s;
    z-index: 5;
}
.markdown-body pre:hover .code-copy-btn { opacity: 1; visibility: visible; }
.code-copy-btn:hover { background: #f0f0f0; }

/* ===== 右侧消息导航（还原 DeepSeek 悬停弹出摘要样式） ===== */
.msg-nav {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    padding: 10px 4px;
    z-index: 20;
    max-height: 60vh;
    overflow-y: auto;
    scrollbar-width: none;
}
.msg-nav::-webkit-scrollbar { display: none; }

.msg-nav-item-wrapper {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 6px 4px;
    cursor: pointer;
    transition: background 0.2s;
    border-radius: 6px;
}

.msg-nav-text {
    font-size: 13px;
    color: #555;
    max-width: 160px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0;
    transform: translateX(10px);
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
}

.msg-nav:hover .msg-nav-text {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
}

.msg-nav-item-wrapper:hover .msg-nav-text {
    color: #10a37f;
}

.msg-nav-item-wrapper:hover {
    background: rgba(0, 0, 0, 0.03);
}

.msg-nav-item {
    width: 16px;
    height: 2px;
    border-radius: 1px;
    background: #d1d1d6;
    transition: all 0.2s;
    flex-shrink: 0;
}

.msg-nav-item-wrapper:hover .msg-nav-item,
.msg-nav-item.active {
    background: #10a37f;
    width: 22px;
}

/* ===== 附件卡片 ===== */
.attach-bar {
    max-width: 820px;
    margin: 0 auto 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 4px;
}
.attach-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 240px;
    padding: 6px 8px 6px 10px;
    background: #f0faf7;
    border: 1px solid #cdeee3;
    border-radius: 10px;
    font-size: 13px;
    color: #1f2328;
}
.attach-chip .attach-icon { font-size: 14px; }
.attach-chip .attach-name {
    overflow: hidden; white-space: nowrap; text-overflow: ellipsis; max-width: 170px;
}
.attach-chip .attach-size { color: #888; font-size: 11px; }
.attach-chip .attach-close {
    border: none; background: transparent; color: #888;
    font-size: 16px; line-height: 1; cursor: pointer;
    padding: 0 2px; border-radius: 4px;
}
.attach-chip .attach-close:hover { color: #dc2626; background: #ffe5e5; }

/* ===== 底部输入区 ===== */
.chat-main .composer-wrap {
    flex-shrink: 0;
    background: #fff;
    border-top: 1px solid #f0f0f0;
    padding: 10px 20px 14px;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
}
.composer {
    max-width: 820px; margin: 0 auto;
    display: flex; align-items: flex-end; gap: 8px;
    background: #fff;
    border: 1px solid #d9d9e3; border-radius: 16px;
    padding: 8px 8px 8px 14px;
    box-shadow: 0 2px 12px rgba(0,0,0,.06);
}
.composer textarea {
    flex: 1; border: none; outline: none; resize: none;
    font-size: 16px; line-height: 1.5; font-family: inherit;
    max-height: 160px; min-height: 72px; padding: 6px 0; background: transparent;
}
.composer button {
    width: 36px; height: 36px; border: none; border-radius: 10px;
    background: #10a37f; color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.composer button:hover:not(:disabled) { background: #0d8f6f; }
.composer button.stopping { background: #dc2626; }
.composer button.stopping:hover { background: #b91c1c; }
.composer .continue-btn {
    width: 36px; height: 36px;
    border: 1px solid #10a37f; border-radius: 10px;
    background: #fff; color: #10a37f;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.composer .continue-btn:hover { background: #e6f6f0; }

.composer-tip {
    max-width: 820px; margin: 6px auto 0; text-align: center;
    font-size: 12px; color: #aaa;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #d0d0d8; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #b8b8c2; }

/* ===== 移动端遮罩 ===== */
.sidebar-mask {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.45); z-index: 40;
    opacity: 0; transition: opacity .25s ease;
}
.sidebar-mask.show { display: block; opacity: 1; }

/* ===== 移动端 ===== */
@media (max-width: 800px) {
    body.layout-with-sidebar { display: block; height: 100dvh; overflow: hidden; }
    .conv-sidebar {
        position: fixed; top: 0; left: 0;
        width: 82vw; max-width: 320px; height: 100dvh;
        z-index: 50; transform: translateX(-100%);
        transition: transform .28s cubic-bezier(.4,0,.2,1);
        box-shadow: 2px 0 16px rgba(0,0,0,.12);
        border-right: none;
    }
    .conv-sidebar.open { transform: translateX(0); }

    .conv-del { visibility: visible; }
    .conv-edit { visibility: visible; }
    .conv-rename-input { font-size: 16px; }

    .chat-main { height: 100dvh; width: 100%; }

    .mobile-topbar {
        display: flex; align-items: center; justify-content: space-between;
        height: 52px; padding: 0 8px;
        border-bottom: 1px solid #ececf1;
        background: #fff; flex-shrink: 0; z-index: 10;
    }
    .mobile-topbar .menu-btn,
    .mobile-topbar .mobile-new {
        width: 40px; height: 40px;
        display: flex; align-items: center; justify-content: center;
        border: none; background: transparent; color: #333;
        border-radius: 10px; cursor: pointer;
    }
    .mobile-topbar .menu-btn:active,
    .mobile-topbar .mobile-new:active { background: #f0f0f0; }
    .mobile-topbar .mobile-title {
        flex: 1; text-align: center;
        font-size: 15px; font-weight: 600; color: #1f2328;
        overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
        padding: 0 6px;
    }

    .chat-scroll { padding: 16px 14px 16px; gap: 18px; max-width: 100%; }
    .empty-hint { margin-top: 50px; }
    .empty-hint h2 { font-size: 19px; }

    .msg { gap: 10px; }
    .msg .avatar { width: 28px; height: 28px; font-size: 11px; }
    .markdown-body { font-size: 15px; }

    .chat-main .composer-wrap { padding: 8px 12px 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
    .composer { padding: 6px 6px 6px 12px; border-radius: 22px; }
    .composer textarea { min-height: 40px; max-height: 120px; font-size: 16px; }
    .composer button { width: 40px; height: 40px; border-radius: 50%; }
    .composer .continue-btn { width: 40px; height: 40px; border-radius: 50%; }
    .composer-tip { display: none; }

    body.sidebar-open { overflow: hidden; }

    .code-copy-btn { opacity: 1; visibility: visible; top: 6px; right: 6px; }

    .msg-nav { right: 2px; gap: 4px; padding: 6px 2px; }
    .msg-nav-item-wrapper { padding: 4px 2px; gap: 8px; }
    .msg-nav-text { max-width: 120px; font-size: 12px; }
    .msg-nav-item { width: 12px; }
    .msg-nav-item-wrapper:hover .msg-nav-item, .msg-nav-item.active { width: 16px; }
}