:root{color-scheme:dark;--bg:#181a1d;--surface:#22252a;--text:#ddd9d2;--muted:#969a9f;--accent:#a6b5aa;--error:#c29a8a}
*{box-sizing:border-box}html,body{margin:0;height:100%;background:var(--bg);color:var(--text);font-family:"Microsoft YaHei",-apple-system,BlinkMacSystemFont,sans-serif}
.cabin{width:min(100%,900px);height:100dvh;height:var(--viewport-height,100dvh);margin:auto;display:flex;flex-direction:column;padding:16px 24px 12px;padding-bottom:max(12px,env(safe-area-inset-bottom));overflow:hidden}
header{flex:none}.heading{display:flex;justify-content:space-between;font-size:14px;letter-spacing:.04em}header p,.mode{font-size:11px;color:var(--muted)}header p{margin:8px 0}
#messages{flex:1;min-height:0;overflow-y:auto;padding:8px 4px 20px;overscroll-behavior:contain;scrollbar-color:#41474c var(--bg)}
.bubble{width:fit-content;min-width:0;max-width:82%;padding:12px 14px;margin:0 0 16px;background:var(--surface);border-radius:6px}
.bubble.user{margin-left:auto;margin-right:14px;max-width:70%;background:#27292d;padding:10px 12px}.name{font-size:11px;color:#929f96;margin-bottom:5px}.user .name{color:#9a9289}.body{min-width:0;max-width:100%;white-space:pre-wrap;word-break:normal;overflow-wrap:break-word;line-break:strict;font-size:16px;line-height:1.7;letter-spacing:normal}.thinking{color:var(--muted);font-size:12px;margin:0 0 14px}
footer{flex:none}form{display:flex;align-items:stretch;gap:10px}textarea{flex:1;min-width:0;resize:none;max-height:160px;overflow:auto;white-space:pre-wrap;overflow-wrap:anywhere;background:var(--surface);border:1px solid transparent;border-radius:4px;color:var(--text);padding:10px;font:16px/1.5 inherit;font-family:inherit;font-size:16px;line-height:1.5}textarea:focus{outline:none;border-color:#41474c}
button{background:var(--surface);border:0;border-radius:4px;color:var(--accent);font:inherit;font-size:14px;padding:10px 16px;cursor:pointer;min-height:44px}button:hover{background:#2e3338}button:disabled{opacity:.55;cursor:default}.bottom{display:flex;align-items:center;gap:12px;margin-top:8px}.bottom button{background:transparent;color:var(--muted);padding-left:0}#status{font-size:11px;color:var(--muted);overflow-wrap:anywhere}#status.error{color:var(--error)}
@media(max-width:480px){.cabin{padding:12px 12px max(10px,env(safe-area-inset-bottom))}.bubble{max-width:92%;padding:11px 12px}.bubble.user{max-width:90%;margin-right:6px}.body{font-size:16px}.heading{font-size:13px}button{padding:10px 12px}form{gap:8px}}

#input-hint{font-size:11px;color:var(--muted);margin-top:5px;overflow-wrap:anywhere}
.lan-login{margin-top:36px;color:var(--muted);font-size:13px}.lan-login form{flex-direction:column;max-width:360px}.lan-login input{background:var(--surface);color:var(--text);border:1px solid #41474c;border-radius:4px;padding:12px;font-size:16px}.lan-login [role=status]{color:var(--error)}
/* 可视区域是唯一外层容器，键盘缩小时只压缩中间聊天区。 */
html,body{overflow:hidden;overscroll-behavior:none}
.cabin{position:fixed;top:0;left:50%;transform:translate(-50%,var(--viewport-top,0px));min-height:0;padding-top:max(12px,env(safe-area-inset-top));padding-left:max(12px,env(safe-area-inset-left));padding-right:max(12px,env(safe-area-inset-right))}
textarea{height:118px;max-height:min(160px,calc(var(--viewport-height,100dvh)*.28));min-height:48px;font-family:inherit;font-size:16px;line-height:1.5}
.cabin,header,#messages,form{min-width:0}footer{min-width:0}.bottom{align-items:flex-start}.bottom button{flex-shrink:0}#status,#input-hint{max-height:3em;overflow:auto}
.keyboard-open .cabin{padding-bottom:8px}.keyboard-open header p{margin:4px 0}
.lan-login{overflow:auto;min-height:0;padding-bottom:24px}
@media(min-width:481px){.cabin{padding-left:max(24px,env(safe-area-inset-left));padding-right:max(24px,env(safe-area-inset-right))}}

.bubble.system{background:transparent;max-width:95%;padding:4px;color:var(--muted)}.bubble.system .body{font-size:12px}.bottom{flex-wrap:wrap}
.text-phrase{white-space:nowrap}
.reply-actions{display:flex;justify-content:flex-end;height:32px;margin-top:4px}
.copy-reply{min-height:32px;height:32px;min-width:32px;padding:4px 7px;font-size:12px;line-height:1;color:var(--muted);background:transparent;opacity:.7;touch-action:manipulation}
.copy-reply:hover,.copy-reply:focus-visible,.bubble.zero:hover .copy-reply{opacity:1}
.copy-reply:focus-visible{outline:1px solid #899b90;outline-offset:1px}
#memory-candidate{flex:none;min-width:0;max-height:132px;margin:0 0 8px;padding:8px 10px;background:var(--surface);border-radius:4px;color:var(--muted);font-size:12px}
#memory-candidate[hidden]{display:none}
#memory-candidate-text{max-height:64px;overflow:auto;white-space:pre-wrap;overflow-wrap:break-word;line-height:1.5}
.memory-candidate-actions{display:flex;align-items:center;justify-content:flex-end;gap:8px}
.memory-candidate-actions span{margin-right:auto;font-size:11px}
.memory-candidate-actions button{font-size:12px;padding:6px 8px;min-height:44px}
@media(max-width:480px){#memory-candidate{max-height:116px;padding:6px 8px}#memory-candidate-text{max-height:54px}.memory-candidate-actions{gap:4px}}
/* 临时复制选区独立于 composer，不影响页面流或键盘高度。 */
textarea.copy-buffer{position:fixed;top:0;left:0;width:1px;height:1px;min-height:0;max-height:none;padding:0;border:0;opacity:0;font-size:16px;pointer-events:none}
#attachment-panel{max-height:min(150px,calc(var(--viewport-height,100dvh)*.22));overflow:auto;min-width:0;font-size:12px;color:var(--muted)}
.attachment-chip{display:flex;align-items:center;flex-wrap:wrap;gap:6px;margin-bottom:6px;min-width:0}
.attachment-chip img{width:44px;height:44px;object-fit:contain;border-radius:3px}
.attachment-name{overflow-wrap:break-word;min-width:0;max-width:100%}
.attachment-chip button{font-size:12px;padding:4px 8px;min-height:36px}
.document-range{display:flex;flex-wrap:wrap;gap:6px;align-items:center;width:100%}
.document-range input{width:90px;min-width:0;background:var(--surface);color:var(--text);border:1px solid #41474c;padding:5px;font:inherit}
#attach{align-self:flex-end;display:flex;align-items:center;justify-content:center;width:44px;height:44px;min-width:44px;padding:10px;flex-shrink:0;color:#a6b5aa;background:#272c30;border:1px solid #3a4246;border-radius:6px;touch-action:manipulation}
#attach svg{display:block;width:24px;height:24px;flex-shrink:0;pointer-events:none}
#attach:hover:not(:disabled){background:#31393d;border-color:#59635f;color:#c1cbc3}
#attach:focus-visible{outline:2px solid #899b90;outline-offset:3px}

/* 手机 composer：高度有界，附件横向排列；桌面规则保持原样。 */
@media(max-width:480px){
  #chat-form{align-items:flex-end;gap:8px}
  #message{height:88px;min-height:80px;max-height:136px;max-height:max(80px,min(136px,calc(var(--viewport-height,100dvh)*.28)));padding:8px;overflow-y:auto;line-height:1.5}
  #send{align-self:flex-end;height:44px;min-height:44px}
  #attachment-panel{display:flex;gap:8px;max-height:104px;overflow-x:auto;overflow-y:auto;overscroll-behavior:contain}
  #attachment-panel:empty{display:none}
  .attachment-chip{flex:0 0 280px;align-content:flex-start;gap:4px;margin:0 0 6px}
  .attachment-chip img{width:28px;height:28px;flex-shrink:0}
  .attachment-name{flex:1;max-width:none;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .attachment-chip button{min-height:44px;padding:4px 6px}
  .document-range{gap:4px;flex-wrap:nowrap}
  .document-range input{width:64px}
}
