*{margin:0;padding:0;box-sizing:border-box;font-family:system-ui,-apple-system,BlinkMacSystemFont,"PingFang SC","Microsoft YaHei",sans-serif}

#app{position:fixed;inset:0;display:flex;flex-direction:row;overflow:hidden}

:root{--bg-body:#f2f4f9;--bg-panel:#fff;--user-msg:#1677ff;--ai-msg:#f0f2f6;--text-user:#fff;--text-ai:#1e2129;--border:#e2e5ec;--btn-gray:#eef1f6;--btn-gray-active:#d8dde6;--code-bg:#1e1e2a;--code-color:#e4e4e7;--accent:#1677ff;--shadow:0 2px 16px rgba(0,0,0,.07);--safe-bottom:env(safe-area-inset-bottom,0px);--avatar-size:38px;--header-height:56px;--sidebar-width:280px;--focus-ring:0 0 0 3px rgba(22,119,255,.25)}
body.dark{--bg-body:#13151c;--bg-panel:#1f222b;--ai-msg:#2d313e;--text-ai:#e7e9ee;--border:#383d4b;--btn-gray:#2b303b;--btn-gray-active:#3a3f4b;--shadow:0 2px 16px rgba(0,0,0,.45);--code-bg:#0d0f14;--code-color:#d4d4d8}
html,body{height:100%;width:100%;background:var(--bg-body);background-image:var(--bg-custom);background-size:cover;background-position:center;overflow:hidden;position:relative;transition:background-color .25s ease,color .25s ease;font-size:14px;color:var(--text-ai)}
.bg-overlay{position:fixed;inset:0;background:rgba(255,255,255,.70);z-index:0;pointer-events:none;display:var(--overlay-show,none)}
body.dark .bg-overlay{background:rgba(0,0,0,.60)}
button{font-family:inherit;cursor:pointer;border:none;background:var(--btn-gray);color:var(--text-ai);border-radius:10px;transition:background-color .15s ease,transform .15s ease;touch-action:manipulation;-webkit-tap-highlight-color:transparent}
button:focus-visible{outline:none;box-shadow:var(--focus-ring)}
button:active{transform:scale(.96)}
button:disabled{opacity:.5;cursor:not-allowed}
.sidebar{background:var(--bg-panel);border-right:1px solid var(--border);display:flex;flex-direction:column;z-index:99;transition:transform .3s ease;box-shadow:var(--shadow);flex-shrink:0;width:var(--sidebar-width);height:100%;position:relative}
.side-top{padding:18px 16px 14px;border-bottom:1px solid var(--border)}
.side-top h3{color:var(--text-ai);font-size:18px;font-weight:600}
.side-user{font-size:12px;color:var(--text-ai);opacity:.7;margin-top:4px;line-height:1.5}
.side-tablist{flex:1;overflow-y:auto;padding:12px 10px;min-height:0}
.tab-item{padding:12px 14px;margin-bottom:6px;border-radius:10px;background:var(--btn-gray);cursor:pointer;display:flex;justify-content:space-between;align-items:center;font-size:14px;color:var(--text-ai);min-height:48px}
.tab-item:active{transform:scale(.98)}
.tab-item.active{background:var(--accent);color:#fff}
.tab-item .tab-name{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;padding-right:8px}
.tab-item .del{width:26px;height:26px;border-radius:50%;background:rgba(0,0,0,.18);text-align:center;font-size:14px;line-height:26px;cursor:pointer;color:#fff;flex-shrink:0}
.side-bottom{padding:14px 12px;border-top:1px solid var(--border);display:flex;flex-direction:column;gap:8px}
.side-bottom button{width:100%;padding:12px 0;border-radius:10px;background:var(--accent);color:#fff;font-size:15px;font-weight:500}
.side-bottom .profile-btn,.side-bottom .login-btn{background:var(--btn-gray);color:var(--text-ai)}
.mask{position:fixed;inset:0;background:rgba(0,0,0,.45);z-index:98;display:none;opacity:0;transition:opacity .25s ease}
.mask.show{display:block;opacity:1}
.main-wrap{flex:1;display:flex;flex-direction:column;min-width:0;min-height:0;position:relative;z-index:1;overflow:hidden}
.header-bar{padding:8px 16px;display:flex;align-items:center;gap:8px;background:var(--bg-panel);border-bottom:1px solid var(--border);z-index:10;position:relative;box-shadow:var(--shadow);flex-shrink:0;flex-wrap:wrap;min-height:var(--header-height)}
.header-bar .menu-btn{flex-shrink:0;font-size:22px;width:42px;height:42px;background:transparent;display:flex;align-items:center;justify-content:center}
.btn-group-left,.header-right-group{display:flex;gap:6px;flex-wrap:wrap;align-items:center}
.header-right-group{margin-left:auto}
.btn-group-left button,.header-right-group button{padding:8px 12px;border-radius:8px;font-size:13px;min-height:38px;white-space:nowrap;background:var(--btn-gray);color:var(--text-ai)}
#chatBox{flex:1;min-height:0;overflow-y:auto;padding:12px 16px 6px;position:relative;z-index:1;-webkit-overflow-scrolling:touch}
.empty-hint{text-align:center;color:var(--text-ai);opacity:.55;padding:48px 20px;font-size:14px;user-select:none}
.msg-row{display:grid;grid-template-columns:var(--avatar-size) 1fr;gap:4px 10px;margin:8px 0;animation:msgIn .22s ease both;align-items:start}
@keyframes msgIn{0%{opacity:0;transform:translateY(6px)}100%{opacity:1;transform:translateY(0)}}
.user-row{grid-template-columns:1fr var(--avatar-size)}
.user-row .avatar{grid-column:2;grid-row:1}
.user-row .bubble{grid-column:1;grid-row:1}
.user-row .msg-opt{grid-column:1;grid-row:2;justify-self:end}
.ai-row .avatar{grid-column:1;grid-row:1}
.ai-row .bubble{grid-column:2;grid-row:1}
.ai-row .msg-opt{grid-column:2;grid-row:2;justify-self:start}
.sys-row{display:flex;justify-content:center}
.avatar{width:var(--avatar-size);height:var(--avatar-size);border-radius:50%;background:var(--btn-gray);overflow:hidden;border:1px solid var(--border);display:flex;align-items:center;justify-content:center;font-size:19px;color:var(--text-ai);user-select:none}
.avatar img{width:100%;height:100%;object-fit:cover;display:block}
.bubble{max-width:70%;min-width:44px;padding:9px 14px 11px;border-radius:16px;line-height:1.6;word-break:break-word;white-space:pre-wrap;background:var(--ai-msg);color:var(--text-ai);position:relative;box-shadow:0 1px 3px rgba(0,0,0,.04);text-align:left;width:fit-content;font-size:15px}
.user-row .bubble{background:var(--user-msg);color:var(--text-user);border-bottom-right-radius:4px;justify-self:end}
.ai-row .bubble{background:var(--ai-msg);color:var(--text-ai);border-bottom-left-radius:4px;justify-self:start}
.chat-imgs{display:flex;flex-wrap:wrap;gap:4px;margin-bottom:6px}
.chat-img{max-width:200px;max-height:200px;border-radius:10px;cursor:pointer;display:block;border:1px solid var(--border)}
.chat-imgs .chat-img{max-width:160px;max-height:160px}
.chat-img:active{transform:scale(.97)}
.attach-mark{font-size:13px;opacity:.7;margin-top:4px;display:block}
.quote-block{display:flex;gap:8px;padding:6px 10px;margin-bottom:8px;background:rgba(0,0,0,.05);border-left:3px solid var(--accent);border-radius:6px;font-size:13px;line-height:1.5;color:inherit;opacity:.85;max-height:80px;overflow:hidden;position:relative;cursor:pointer;transition:background-color .15s ease}
.quote-block:hover{background:rgba(0,0,0,.09)}
.user-row .quote-block{background:rgba(255,255,255,.18);border-left-color:rgba(255,255,255,.65)}
.user-row .quote-block:hover{background:rgba(255,255,255,.25)}
body.dark .quote-block{background:rgba(255,255,255,.08)}
body.dark .user-row .quote-block{background:rgba(255,255,255,.15)}
.quote-block .q-label{flex-shrink:0;font-size:16px;line-height:1.2;opacity:.6}
.quote-block .q-text{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;word-break:break-word}
.quote-block::after{content:'';position:absolute;left:0;right:0;bottom:0;height:16px;background:linear-gradient(to bottom,transparent,var(--ai-msg));pointer-events:none}
.user-row .quote-block::after{background:linear-gradient(to bottom,transparent,var(--user-msg))}
.think-box{margin-bottom:8px;border:1px dashed var(--border);border-radius:10px;background:rgba(0,0,0,.02);overflow:hidden;font-size:13px;color:var(--text-ai)}
body.dark .think-box{background:rgba(255,255,255,.03)}
.think-box summary{padding:8px 12px;cursor:pointer;font-weight:500;font-size:13px;opacity:.75;user-select:none;list-style:none;display:flex;align-items:center;gap:6px;transition:opacity .15s ease}
.think-box summary::-webkit-details-marker{display:none}
.think-box summary::before{content:'▸';transition:transform .2s ease;display:inline-block;font-size:11px}
.think-box[open] summary::before{transform:rotate(90deg)}
.think-box summary:hover{opacity:1}
.think-box .think-content{padding:0 12px 10px;line-height:1.6;opacity:.85;white-space:pre-wrap;word-break:break-word;max-height:400px;overflow-y:auto;font-size:13px}
.think-box.streaming summary{opacity:.55;cursor:default}
.think-box.streaming summary::after{content:'思考中…';font-size:11px;opacity:.6;margin-left:auto;font-weight:400}
.msg-opt{display:flex;gap:6px;padding:6px 0 0;flex-wrap:wrap}
.msg-opt button{padding:6px 14px;font-size:13px;border-radius:8px;min-height:34px;white-space:nowrap;background:var(--btn-gray);color:var(--text-ai)}
.msg-opt .quote-btn{background:var(--accent);color:#fff}
@media (min-width:768px){.msg-opt{opacity:0;transition:opacity .18s ease}.msg-row:hover .msg-opt{opacity:1}}
.sys-msg{text-align:center;font-size:13px;color:var(--text-ai);opacity:.65;padding:6px 0;margin:4px 0;user-select:none}
.msg-row.loading-row{animation:loadingFadeIn .2s ease both}
@keyframes loadingFadeIn{0%{opacity:0}100%{opacity:1}}
.loading-dots{display:inline-flex;align-items:center;gap:5px;padding:5px 2px;min-height:24px;color:var(--text-ai)}
.loading-dots span{width:7px;height:7px;border-radius:50%;background:currentColor;opacity:.35;animation:dotBounce 1.4s infinite ease-in-out both}
.loading-dots span:nth-child(1){animation-delay:-0.32s}
.loading-dots span:nth-child(2){animation-delay:-0.16s}
@keyframes dotBounce{0%,80%,100%{transform:scale(0);opacity:.3}40%{transform:scale(1);opacity:1}}

/* ===== 代码块容器 ===== */
.code-container{position:relative;width:100%;margin:8px 0 6px;border-radius:10px;overflow:hidden;border:1px solid var(--border);background:var(--code-bg)}
.code-btn-group{position:absolute;top:8px;right:10px;display:flex;gap:6px;z-index:4}
.code-btn-group button{padding:5px 12px;font-size:12px;min-height:30px;background:rgba(255,255,255,.12);color:#e4e4e7;border:1px solid rgba(255,255,255,.08);border-radius:6px;font-weight:500;cursor:pointer;transition:background-color .15s ease;font-family:inherit;backdrop-filter:blur(4px)}
.code-btn-group button:hover{background:rgba(255,255,255,.22)}
.code-btn-group button:active{transform:scale(.95)}
.code-btn-group .preview-btn{background:rgba(22,119,255,.55);border-color:rgba(22,119,255,.35);color:#fff}
.code-btn-group .preview-btn:hover{background:rgba(22,119,255,.75)}
.code-box{width:100%;background:var(--code-bg);max-height:380px;overflow:auto;padding:38px 14px 10px;position:relative}
.code-box pre{margin:0;padding:0;background:transparent}
.code-box code{display:block;color:var(--code-color);font-family:'Fira Code',Consolas,'Courier New',monospace;font-size:13px;line-height:1.6;white-space:pre;overflow-x:auto;tab-size:2;-webkit-font-smoothing:antialiased}
body.dark .code-container{border-color:#2a2a35}
body.dark .code-box{background:var(--code-bg)}

.input-bar{padding:8px 14px calc(8px + var(--safe-bottom));background:var(--bg-panel);border-top:1px solid var(--border);display:flex;flex-direction:column;gap:6px;flex-shrink:0}
.attach-tip{width:100%;padding:10px 14px;background:#e8f3ff;border-radius:10px;display:none;flex-direction:column;gap:10px}
body.dark .attach-tip{background:#1e3450}
.attach-tip.show{display:flex}
.attach-tip-head{display:flex;justify-content:space-between;align-items:center;font-size:13px;color:var(--accent);gap:10px}
body.dark .attach-tip-head{color:#7cb8ff}
.attach-tip-head b{font-weight:600}
.attach-tip .cancel-attach{color:#ff4d4f;cursor:pointer;font-weight:500;padding:4px 10px;border-radius:6px;font-size:13px;flex-shrink:0}
.attach-tip .cancel-attach:active{background:rgba(255,77,79,.15)}
.attach-thumbs{display:flex;flex-wrap:wrap;gap:8px}
.attach-thumb{position:relative;width:72px;height:72px;border-radius:10px;overflow:hidden;border:1px solid rgba(0,0,0,.08);background:#fff;flex-shrink:0}
body.dark .attach-thumb{border-color:rgba(255,255,255,.1);background:#2b303b}
.attach-thumb img{width:100%;height:100%;object-fit:cover;display:block}
.attach-thumb .remove{position:absolute;top:2px;right:2px;width:20px;height:20px;border-radius:50%;background:rgba(0,0,0,.6);color:#fff;font-size:14px;line-height:1;display:flex;align-items:center;justify-content:center;cursor:pointer;border:none;padding:0;transition:background-color .15s ease}
.attach-thumb .remove:hover,.attach-thumb .remove:active{background:rgba(220,50,50,.95)}
.quote-indicator{display:none;background:var(--ai-msg);border-left:3px solid var(--accent);padding:6px 12px;border-radius:6px;font-size:13px;color:var(--text-ai);align-items:center;gap:8px}
.quote-indicator.show{display:flex}
.quote-indicator .cancel-quote{color:#ff4d4f;cursor:pointer;font-weight:500;padding:4px 8px;border-radius:4px;min-height:30px;display:inline-flex;align-items:center}
.input-row{display:flex;width:100%;gap:8px;align-items:flex-end}
#msgText{flex:1;min-height:44px;max-height:140px;resize:none;outline:none;border:1px solid var(--border);border-radius:22px;padding:11px 18px;background:var(--bg-panel);color:var(--text-ai);font-size:15px;line-height:1.5;font-family:inherit;white-space:pre-wrap}
#msgText:focus{border-color:var(--accent);box-shadow:var(--focus-ring)}
#msgText::placeholder{color:var(--text-ai);opacity:.45}
.icon-btn,.send-btn{width:46px;height:46px;border-radius:50%;padding:0;font-size:20px;flex-shrink:0;display:flex;align-items:center;justify-content:center;background:var(--btn-gray);color:var(--text-ai)}
.send-btn{background:var(--accent);color:#fff;font-size:22px}
#fileInput,#bgFileInput,#avatarFileInput{display:none}
.modal-overlay{position:fixed;inset:0;background:rgba(0,0,0,.55);display:none;align-items:center;justify-content:center;z-index:999;opacity:0;transition:opacity .22s ease;padding:20px}
.modal-overlay.show{display:flex;opacity:1}
.modal-box{background:var(--bg-panel);padding:24px 28px;border-radius:16px;display:flex;flex-direction:column;gap:14px;min-width:320px;max-width:92vw;box-shadow:0 20px 60px rgba(0,0,0,.25);transform:scale(.94);transition:transform .25s ease,opacity .25s ease;opacity:0;max-height:90vh;overflow-y:auto}
.modal-overlay.show .modal-box{transform:scale(1);opacity:1}
.modal-box .modal-title{font-size:17px;font-weight:600;color:var(--text-ai)}
.modal-box .field-label{font-size:14px;color:var(--text-ai);opacity:.8;display:block}
.modal-box input,.modal-box select,.modal-box textarea{padding:11px 14px;border:1px solid var(--border);border-radius:10px;outline:none;color:var(--text-ai);background:var(--bg-body);font-size:14px;width:100%;font-family:inherit}
.modal-box input:focus,.modal-box select:focus,.modal-box textarea:focus{border-color:var(--accent);box-shadow:var(--focus-ring)}
.modal-box textarea{min-height:90px;resize:vertical}
.modal-btns{display:flex;gap:10px;justify-content:flex-end;margin-top:4px;flex-wrap:wrap}
.modal-btns button{padding:10px 22px;border-radius:10px;font-size:14px;min-height:42px;font-weight:500}
.modal-btns .btn-cancel{background:var(--btn-gray);color:var(--text-ai)}
.modal-btns .btn-confirm{background:var(--accent);color:#fff}
.img-modal{position:fixed;inset:0;background:rgba(0,0,0,.88);display:none;align-items:center;justify-content:center;padding:20px;z-index:1000;opacity:0;transition:opacity .22s ease;cursor:zoom-out}
.img-modal.show{display:flex;opacity:1}
.img-modal img{max-width:95%;max-height:95%;border-radius:8px;box-shadow:0 20px 60px rgba(0,0,0,.5);transform:scale(.94);transition:transform .28s ease}
.img-modal.show img{transform:scale(1)}
.snackbar{position:fixed;left:50%;top:20px;transform:translateX(-50%) translateY(-16px);background:rgba(0,0,0,.82);color:#fff;padding:12px 20px;border-radius:12px;z-index:9999;opacity:0;transition:opacity .28s ease,transform .28s ease;pointer-events:none;font-size:14px;max-width:90vw;display:flex;align-items:center;gap:16px;box-shadow:0 8px 32px rgba(0,0,0,.35);backdrop-filter:blur(6px);-webkit-backdrop-filter:blur(6px)}
.snackbar.show{opacity:1;transform:translateX(-50%) translateY(0)}
.snackbar.no-undo{padding:12px 24px;justify-content:center}
.snackbar:not(.no-undo){pointer-events:auto}
.snackbar #snackbarText{flex:1;min-width:0;word-break:break-word;text-align:center}
.snackbar:not(.no-undo) #snackbarText{text-align:left}
.snackbar #snackbarUndo{background:transparent;color:#7cb8ff;font-size:14px;font-weight:600;padding:4px 12px;min-height:32px;border:none;cursor:pointer;border-radius:6px;flex-shrink:0;display:none}
.snackbar:not(.no-undo) #snackbarUndo{display:inline-block}
.snackbar #snackbarUndo:hover{background:rgba(124,184,255,.15)}
.guest-banner{display:none;padding:6px 12px;background:#fff8e6;color:#8a6d00;border-radius:8px;font-size:13px;margin-bottom:6px;text-align:center;line-height:1.5}
.guest-banner.show{display:block}
.guest-banner a{color:#1677ff;text-decoration:none;font-weight:600;cursor:pointer}
.model-select{padding:6px 12px;border-radius:8px;border:1px solid var(--border);background:var(--bg-panel);color:var(--text-ai);font-size:13px;font-family:inherit;min-height:38px;max-width:180px;cursor:pointer;outline:none}
.model-select:focus{border-color:var(--accent);box-shadow:var(--focus-ring)}

/* ★ 流式生成中指示 */
.streaming-indicator{margin-top:8px;padding:6px 10px;display:inline-flex;align-items:center;gap:5px;font-size:12px;color:var(--accent);opacity:.8}
.streaming-indicator .sdot{width:5px;height:5px;border-radius:50%;background:currentColor;animation:streamDot 1.2s infinite ease-in-out both}
.streaming-indicator .sdot:nth-child(1){animation-delay:-0.24s}
.streaming-indicator .sdot:nth-child(2){animation-delay:-0.12s}
@keyframes streamDot{0%,80%,100%{transform:scale(0.3);opacity:.3}40%{transform:scale(1);opacity:1}}

/* ★ 中断提示 */
.interrupted-warn{margin-top:8px;padding:8px 12px;background:#fff8e6;border-left:3px solid #ffc16b;border-radius:6px;font-size:13px;color:#8a6d00;line-height:1.5}
body.dark .interrupted-warn{background:#3a2f14;color:#ffc16b;border-left-color:#8a6d00}

@media (max-width:767px){
.sidebar{position:fixed;top:0;left:0;width:var(--sidebar-width);height:100%;transform:translateX(-100%);border-radius:0 16px 16px 0;z-index:100}
.sidebar.show{transform:translateX(0)}
.header-bar{padding:6px 10px;gap:4px;min-height:52px}
.header-bar .menu-btn{width:40px;height:40px;font-size:20px}
.btn-group-left button,.header-right-group button{font-size:12px;padding:6px 10px;min-height:36px}
#chatBox{padding:8px 10px 4px}
.bubble{max-width:80%;padding:8px 12px 10px;font-size:15px}
.msg-row{gap:4px 8px;margin:6px 0}
:root{--avatar-size:34px;--header-height:52px}
.input-bar{padding:6px 10px calc(6px + var(--safe-bottom))}
.icon-btn,.send-btn{width:42px;height:42px}
#msgText{min-height:42px;padding:10px 14px;font-size:15px}
.modal-box{min-width:0;width:100%;padding:20px 18px;max-height:85vh}
.msg-opt{opacity:1 !important}
.model-select{max-width:120px;font-size:12px;padding:5px 8px}
.chat-imgs .chat-img{max-width:120px;max-height:120px}
.attach-thumb{width:60px;height:60px}
.code-box{padding:34px 10px 8px}
.code-box code{font-size:12px}
.code-btn-group button{font-size:11px;padding:4px 10px;min-height:28px}
}

@media (min-width:768px){
.header-bar .menu-btn{display:none !important}
.mask{display:none !important}
.sidebar{transform:none !important;border-radius:0;box-shadow:2px 0 8px rgba(0,0,0,.05)}
.bubble{max-width:62%}
}
/* ★ 退出按钮：跟随主题灰底 + 红字，深浅都协调 */
.side-bottom .logout-btn{
    background: var(--btn-gray) !important;
    color: #ff4d4f !important;
}
.side-bottom .logout-btn:hover{ background: var(--btn-gray-active) !important; }
