/* ============ 对话区 ============ */
.msgs{
  padding:0 1rem;
  display:flex;flex-direction:column;
}
.msg{margin-bottom:1.5rem;animation:msgIn .26s cubic-bezier(.2,.7,.3,1) both;contain:layout style;}
@keyframes msgIn{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}

/* 用户消息 */
.msg.user{display:flex;flex-direction:column;align-items:flex-end;}
.msg.user .bubble{
  max-width:82%;
  background:var(--accent);
  color:#fff;
  padding:.625rem .9375rem;
  border-radius:1.125rem 1.125rem .3125rem 1.125rem;
  font-size:1rem;line-height:1.55;
  word-break:break-word;
  white-space:pre-wrap;
  box-shadow:0 2px 10px rgba(var(--accent-rgb),.18);
}
.msg.user .bubble img{
  border-radius:.625rem;margin-top:.375rem;max-width:100%;
}

/* AI 消息 */
.msg.ai .ai-body{
  font-size:1rem;line-height:1.72;color:var(--text);
  word-break:break-word;
}
.msg.ai .ai-body > *:first-child{margin-top:0;}
.msg.ai .ai-body > *:last-child{margin-bottom:0;}

/* 思考过程 */
.think-block{
  background:#F6F6F8;
  border-radius:.75rem;
  margin:0 0 .75rem;
  overflow:hidden;
  border:1px solid #EFEFF3;
}
.think-head{
  display:flex;align-items:center;gap:.375rem;
  padding:.625rem .75rem;
  font-size:.8125rem;color:var(--text-2);
  width:100%;text-align:left;
}
.think-head .ico{width:.9375rem;height:.9375rem;color:var(--text-3);transition:transform .2s ease;}
.think-block.open .think-head .ico.chev{transform:rotate(90deg);}
.think-head .chev{width:.875rem;height:.875rem;margin-left:auto;}
.think-body{
  display:none;
  padding:0 .75rem .75rem;
  font-size:.8125rem;line-height:1.75;color:var(--text-2);
  white-space:pre-wrap;
  border-top:1px solid #EFEFF3;
  padding-top:.625rem;
  max-height:16rem;overflow-y:auto;
}
.think-block.open .think-body{display:block;}

/* 搜索状态 */
.search-status{
  display:flex;align-items:center;gap:.5rem;
  font-size:.8125rem;color:var(--accent);
  background:var(--accent-soft-2);
  border-radius:.625rem;
  padding:.5rem .75rem;
  margin-bottom:.625rem;
}
.spinner{
  width:.875rem;height:.875rem;flex:none;
  border:2px solid rgba(var(--accent-rgb),.25);
  border-top-color:var(--accent);
  border-radius:50%;
  animation:spin .7s linear infinite;
}
@keyframes spin{to{transform:rotate(360deg)}}

/* 流式光标 */
.caret{
  display:inline-block;
  width:.5em;height:1.02em;
  background:var(--accent);
  border-radius:2px;
  vertical-align:-.16em;
  margin-left:2px;
  animation:blink 1s steps(2,start) infinite;
}
@keyframes blink{0%,50%{opacity:1}50.1%,100%{opacity:0}}

/* 消息操作栏 */
.msg-tools{
  display:flex;align-items:center;gap:.125rem;
  margin-top:.625rem;
  margin-left:-.375rem;
  opacity:0;transition:opacity .2s ease;
}
.msg.ai.done .msg-tools{opacity:1;}
.msg-tools button{
  width:1.875rem;height:1.875rem;
  display:flex;align-items:center;justify-content:center;
  color:var(--text-3);border-radius:.5rem;
  transition:background .15s,color .15s;
}
.msg-tools button:active{background:#F2F2F5;color:var(--text-2);}
.msg-tools .ico{width:1rem;height:1rem;}
.msg-tools .liked{color:var(--accent);}

/* 附件预览（已选图片） */
.attach-strip{display:flex;flex-wrap:wrap;gap:.5rem;padding-bottom:.5rem;}
.attach-strip:empty{display:none;}
.chip-file{
  display:flex;align-items:center;gap:.5rem;
  background:#F4F4F6;border-radius:.625rem;
  padding:.375rem .625rem .375rem .5rem;
  font-size:.8125rem;color:var(--text-2);
  max-width:100%;
}
.chip-file .ico{width:1rem;height:1rem;flex:none;color:var(--text-3);}
.chip-file span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:11rem;}
.chip-file .rm{color:var(--text-3);font-size:1rem;line-height:1;padding:0 .125rem;}
.thumb-mini{
  position:relative;width:3.25rem;height:3.25rem;border-radius:.5rem;overflow:hidden;flex:none;
  background:#F2F2F5;
}
.thumb-mini img{width:100%;height:100%;object-fit:cover;}
.thumb-mini .rm{
  position:absolute;top:2px;right:2px;
  width:1rem;height:1rem;border-radius:50%;
  background:rgba(0,0,0,.55);color:#fff;
  display:flex;align-items:center;justify-content:center;
  font-size:.6875rem;line-height:1;
}

/* ============ 输入区 ============ */
.composer{
  position:absolute;left:0;right:0;bottom:0;z-index:30;
  padding:0 .75rem calc(.75rem + var(--sab));
  background:linear-gradient(to bottom,rgba(255,255,255,0) 0%,#fff 1.25rem,#fff 100%);
  display:flex;flex-direction:column;
}
.composer-box{
  background:#fff;
  border:1px solid var(--line);
  border-radius:1.5rem;
  padding:.875rem 1rem .75rem;
  box-shadow:0 2px 14px rgba(23,23,27,.045);
  transition:border-color .18s ease,box-shadow .18s ease;
}
.composer-box.focus{
  border-color:rgba(var(--accent-rgb),.35);
  box-shadow:0 2px 18px rgba(var(--accent-rgb),.12);
}
#input{
  display:block;width:100%;
  min-height:2.75rem;max-height:9.5rem;
  line-height:1.55;
  padding:.375rem .125rem .625rem;
  resize:none;overflow-y:auto;
  font-size:1rem;
  caret-color:var(--accent);
}
.composer-tools{
  display:flex;align-items:center;gap:.4375rem;
}
.grow{flex:1;}

.chip{
  display:inline-flex;align-items:center;gap:.3125rem;
  height:1.875rem;padding:0 .625rem;
  border:1px solid #E8E8EC;border-radius:1rem;
  font-size:.8125rem;color:var(--text);
  background:#fff;
  transition:all .18s ease;
  white-space:nowrap;
}
.chip .ico{width:.875rem;height:.875rem;}
.chip:active{background:#F7F7F9;}
.chip.on{
  background:var(--accent-soft);
  border-color:var(--accent);
  color:var(--accent);
}
#chipSearch .ico{color:var(--accent);}
#chipThink .ico{color:var(--text);}
#chipThink.on .ico{color:var(--accent);}

.rbtn{
  width:1.875rem;height:1.875rem;flex:none;
  display:flex;align-items:center;justify-content:center;
  color:var(--text);border-radius:50%;
  transition:background .15s ease,transform .12s ease;
}
.rbtn .ico{width:1.375rem;height:1.375rem;}
.rbtn:active{background:#F2F2F5;}
.rbtn.send{
  background:var(--accent);color:#fff;
  display:none;
  box-shadow:0 2px 8px rgba(var(--accent-rgb),.3);
}
.rbtn.send .ico{width:1.125rem;height:1.125rem;}
.rbtn.send.show{display:flex;}
.composer.has-text .rbtn.attach,
.composer.has-text .rbtn.voice{display:none;}

/* 附件按钮双态 */
#btnAttach .ic-close{display:none;}
.composer.attach-open #btnAttach .ic-plus{display:none;}
.composer.attach-open #btnAttach .ic-close{display:block;}

/* 附件面板 */
.attach-panel{
  max-height:0;overflow:hidden;
  transition:max-height .28s cubic-bezier(.32,.72,0,1),opacity .2s ease;
  opacity:0;
  background:#fff;
}
.attach-panel.open{max-height:16rem;opacity:1;}
.attach-recent{
  display:flex;gap:.5rem;overflow-x:auto;
  padding:.75rem .125rem .25rem;
}
.attach-recent:empty{display:none;}
.recent-thumb{
  width:5.25rem;height:5.25rem;flex:none;
  border-radius:.75rem;object-fit:cover;
  background:#F2F2F4;
}
.attach-actions{
  display:grid;grid-template-columns:repeat(3,1fr);gap:.625rem;
  padding:.625rem .125rem .5rem;
}
.attach-btn{
  background:#F4F4F6;
  border-radius:.875rem;
  height:4.75rem;
  display:flex;flex-direction:column;align-items:center;justify-content:center;gap:.4375rem;
  font-size:.875rem;color:var(--text);
  transition:background .15s ease,transform .12s ease;
}
.attach-btn:active{background:#EBEBEF;transform:scale(.97);}
.attach-btn .ico{width:1.4375rem;height:1.4375rem;color:var(--text);}

/* ============ Markdown ============ */
.ai-body h1,.ai-body h2,.ai-body h3,.ai-body h4{
  margin:1.25em 0 .5em;line-height:1.4;font-weight:650;
}
.ai-body h1{font-size:1.25rem;}
.ai-body h2{font-size:1.125rem;}
.ai-body h3{font-size:1.0625rem;}
.ai-body h4{font-size:1rem;}
.ai-body p{margin:0 0 .75em;}
.ai-body ul,.ai-body ol{margin:0 0 .75em;padding-left:1.375em;}
.ai-body li{margin:.25em 0;}
.ai-body li > p{margin:0;}
.ai-body strong{font-weight:650;}
.ai-body em{font-style:italic;}
.ai-body a{color:var(--accent);border-bottom:1px solid rgba(var(--accent-rgb),.3);}
.ai-body hr{border:none;border-top:1px solid var(--line);margin:1.25em 0;}
.ai-body blockquote{
  margin:0 0 .75em;padding:.125rem 0 .125rem .75rem;
  border-left:3px solid #C8C8D4;color:var(--text-2);
}
.ai-body code{
  font-family:var(--mono);
  font-size:.875em;
  background:#F2F2F6;
  padding:.125em .375em;
  border-radius:.3125rem;
  color:#C7254E;
  word-break:break-word;
}
.table-wrap{
  overflow-x:auto;
  -webkit-overflow-scrolling:touch;
  overscroll-behavior-x:contain;
  margin:0 0 .875em;
}
.ai-body table{
  border-collapse:collapse;
  font-size:.9375rem;
  width:100%;
  min-width:100%;
}
.ai-body th,.ai-body td{
  border:1px solid var(--line-2);
  padding:.4375rem .625rem;
  text-align:left;
  word-break:normal;
  overflow-wrap:break-word;
  min-width:5.25rem;
}
.ai-body th{background:#F7F7F9;font-weight:600;}

/* 代码块 */
.code-block{
  margin:0 0 .875em;
  border-radius:.75rem;
  overflow:hidden;
  background:#17171D;
  border:1px solid #23232B;
}
.code-head{
  display:flex;align-items:center;justify-content:space-between;
  padding:.4375rem .75rem;
  background:#1D1D25;
  font-size:.75rem;color:#8E8E9C;
  font-family:var(--font);
}
.code-head .lang{letter-spacing:.04em;text-transform:uppercase;font-size:.6875rem;}
.code-copy{
  display:flex;align-items:center;gap:.25rem;
  color:#A8A8B8;font-size:.75rem;
  padding:.125rem .375rem;border-radius:.375rem;
}
.code-copy:active{background:rgba(255,255,255,.08);}
.code-copy .ico{width:.875rem;height:.875rem;}
.code-body{
  padding:.75rem;
  overflow-x:auto;
  -webkit-overflow-scrolling:touch;
}
.code-body pre{margin:0;}
.code-body code{
  font-family:var(--mono);
  font-size:.75rem;
  line-height:1.66;
  color:#DCDCE6;
  background:none;padding:0;border-radius:0;
  white-space:pre;
  display:block;
}
.tk-key{color:#FF7B9C;}
.tk-str{color:#A8E06E;}
.tk-num{color:#F3B87A;}
.tk-com{color:#6E6E80;font-style:italic;}
.tk-fn{color:#79C0FF;}
.tk-type{color:#C9A6FF;}
.tk-op{color:#A8A8B8;}

/* ============ 参考来源 ============ */
.sources{
  margin:0 0 .75rem;
  background:#F7F7F9;
  border:1px solid #EFEFF3;
  border-radius:.75rem;
  overflow:hidden;
}
.sources-head{
  display:flex;align-items:center;gap:.375rem;
  width:100%;padding:.625rem .75rem;
  font-size:.8125rem;color:var(--text-2);
  text-align:left;
}
.sources-head .ico{width:.9375rem;height:.9375rem;color:var(--text-3);flex:none;}
.sources-head .chev{width:.875rem;height:.875rem;margin-left:auto;transition:transform .2s ease;}
.sources.open .sources-head .chev{transform:rotate(90deg);}
.sources-list{display:none;padding:0 .5rem .5rem;max-height:14rem;overflow-y:auto;-webkit-overflow-scrolling:touch;}
.sources.open .sources-list{display:block;}
.source-item{
  display:flex;align-items:flex-start;gap:.5rem;
  padding:.4375rem .375rem;
  border-radius:.5rem;
  text-decoration:none;
  transition:background .15s ease;
}
.source-item:active{background:#EDEDF2;}
.s-idx{
  flex:none;width:1.125rem;height:1.125rem;
  border-radius:.3125rem;
  background:var(--accent-soft);color:var(--accent);
  font-size:.6875rem;font-weight:600;
  display:flex;align-items:center;justify-content:center;
  margin-top:.0625rem;
}
.s-main{flex:1;min-width:0;display:flex;flex-direction:column;gap:.125rem;}
.s-title{
  font-size:.8125rem;color:var(--text);line-height:1.45;
  display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;
  overflow:hidden;border:none;
}
.s-site{font-size:.6875rem;color:var(--text-3);}
[data-theme="dark"] .sources{background:#17171E;border-color:#24242E;}
[data-theme="dark"] .source-item:active{background:#24242E;}
[data-theme="dark"] .s-idx{background:var(--accent-soft);}

/* ============ 数学公式 ============ */
.katex-inline-color{font-weight:500;}
.math-block{
  margin:.5em 0 .875em;
  overflow-x:auto;
  overflow-y:hidden;
  -webkit-overflow-scrolling:touch;
  padding:.375rem 0;
  max-width:100%;
}
.math-block .katex{font-size:1.05em;}
.math-block .katex-display{margin:0;}
.ai-body .katex{color:inherit;}
.math-raw{
  font-family:var(--mono);
  font-size:.8125rem;
  color:var(--text-2);
  background:#F2F2F6;
  padding:.125em .375em;
  border-radius:.25rem;
  word-break:break-all;
}
[data-theme="dark"] .math-raw{background:#22222C;color:#A2A2B0;}

/* ============ LaTeX 视觉卡片（气泡 / 标签） ============ */
.tex-visual{display:inline;}
.tex-colorbox{
  display:inline-block;
  padding:.14em .58em;
  border-radius:.4em;
  line-height:1.55;
  vertical-align:baseline;
}
.tex-fcolorbox{
  display:inline-block;
  padding:.16em .62em;
  border-radius:.5em;
  border:1px solid;
  line-height:1.55;
  vertical-align:baseline;
}
.tex-boxed{
  display:inline-block;
  padding:.14em .58em;
  border-radius:.45em;
  border:1px solid currentColor;
  line-height:1.55;
  vertical-align:baseline;
}
.tex-tt{
  font-family:var(--mono);
  font-size:.9em;
  background:#F2F2F6;
  padding:.1em .3em;
  border-radius:.25em;
}
[data-theme="dark"] .tex-tt{background:#22222C;}

.tex-ovalbox{
  display:inline-block;
  padding:.2em .8em;
  border-radius:999px;
  border:1px solid rgba(120,142,172,.42);
  line-height:1.5;
  vertical-align:baseline;
}
[data-theme="dark"] .tex-ovalbox{border-color:rgba(150,170,200,.38);}

/* 用户上传的图片：保持原始比例，不裁切 */
.msg-imgs{
  display:flex;flex-wrap:wrap;gap:.375rem;
  margin-bottom:.375rem;
  justify-content:flex-end;
}
.msg-img{
  max-width:10.5rem;
  max-height:14rem;
  width:auto;height:auto;
  object-fit:contain;
  border-radius:.625rem;
  display:block;
  background:#F2F2F5;
  border:1px solid var(--line);
}
[data-theme="dark"] .msg-img{background:#1E1E26;border-color:#2A2A34;}


/* ============ 微交互 ============ */
.chip{
  transition:transform .2s cubic-bezier(.34,1.56,.64,1), background .18s ease,
             border-color .18s ease, color .18s ease, box-shadow .22s ease;
}
.chip:active{transform:scale(.93);}
.chip.on{
  box-shadow:0 6px 16px -8px rgba(var(--accent-rgb),.75);
}
.chip.on .ico{animation:chipPop .45s cubic-bezier(.34,1.56,.64,1);}
@keyframes chipPop{
  0%{transform:scale(.55) rotate(-14deg);}
  55%{transform:scale(1.22) rotate(6deg);}
  100%{transform:scale(1) rotate(0);}
}

/* 深度思考开启：呼吸 */
#chipThink.on .ico{animation:thinkBreath 2.4s ease-in-out infinite;}
@keyframes thinkBreath{
  0%,100%{transform:scale(1);opacity:1;}
  50%{transform:scale(1.14);opacity:.72;}
}

/* 智能搜索开启：缓慢自转 */
#chipSearch.on .ico{animation:globeSpin 6s linear infinite;}
@keyframes globeSpin{
  from{transform:rotate(0deg);}
  to{transform:rotate(360deg);}
}

/* 发送按钮 */
.rbtn.send{
  transition:transform .2s cubic-bezier(.34,1.56,.64,1), box-shadow .2s ease, background .15s;
}
.rbtn.send:active{transform:scale(.88);}
.composer.has-text .rbtn.send{animation:sendIn .28s cubic-bezier(.34,1.56,.64,1);}
@keyframes sendIn{
  from{transform:scale(.5);opacity:0;}
  to{transform:scale(1);opacity:1;}
}

/* 附件按钮：展开时旋转 */
#btnAttach{transition:transform .25s cubic-bezier(.34,1.56,.64,1), background .15s;}
.composer.attach-open #btnAttach{transform:rotate(135deg);}
#btnAttach:active{transform:scale(.9);}
.composer.attach-open #btnAttach:active{transform:rotate(135deg) scale(.9);}

/* 附件面板弹出 */
.attach-panel{
  transition:max-height .28s cubic-bezier(.22,1,.36,1), opacity .2s ease, transform .28s cubic-bezier(.22,1,.36,1);
  transform:translateY(6px);
}
.attach-panel.open{transform:translateY(0);}

/* 思考块展开 */
.think-block{transition:background .18s ease;}
.think-head:active{background:#EDEDF2;}

@media (prefers-reduced-motion: reduce){
  *,*::before,*::after{
    animation-duration:.001ms !important;
    animation-iteration-count:1 !important;
    transition-duration:.001ms !important;
  }
}

/* ============ 按住说话 ============ */
.hold-bar{display:none;padding:.125rem 0 .25rem;}
.composer.voice-mode .hold-bar{display:block;}
.composer.voice-mode #input{display:none;}
.composer.voice-mode .chip,
.composer.voice-mode #btnAttach,
.composer.voice-mode .rbtn.voice,
.composer.voice-mode .rbtn.send{display:none;}
.composer.voice-mode #btnKeyboard{display:flex;}
#btnKeyboard{display:none;}

.hold-btn{
  width:100%;height:2.75rem;border-radius:.875rem;
  background:#F4F4F6;color:var(--text);
  display:flex;align-items:center;justify-content:center;gap:.375rem;
  font-size:.9375rem;font-weight:600;letter-spacing:.05em;
  user-select:none;-webkit-user-select:none;-webkit-touch-callout:none;
  touch-action:none;
  transition:background .15s ease,color .15s ease,transform .12s ease;
}
.hold-btn .hold-ico{width:1.125rem;height:1.125rem;}
.hold-btn.recording{background:var(--accent-soft);color:var(--accent);transform:scale(.985);}
.hold-btn.cancel{background:#FDE8E8;color:#D33A3A;}

/* 语音模式下：按住说话与键盘按钮同一行 */
.composer.voice-mode .composer-box{
  display:flex;align-items:center;gap:.5rem;
  padding:.75rem .75rem .75rem .875rem;
}
.composer.voice-mode .hold-bar{flex:1;min-width:0;padding:0;}
.composer.voice-mode .composer-tools{flex:none;}
.composer.voice-mode .composer-tools .grow{display:none;}


/* ============ 长按菜单 / 文本选择 ============ */
.msg-menu{
  position:fixed;z-index:150;display:none;
  min-width:8.5rem;padding:.375rem;
  background:#fff;border-radius:.875rem;
  box-shadow:0 12px 32px rgba(0,0,0,.16),0 0 0 1px rgba(0,0,0,.05);
  transform-origin:top left;
}
.msg-menu.show{display:block;animation:menuIn .16s cubic-bezier(.34,1.56,.64,1);}
@keyframes menuIn{from{opacity:0;transform:scale(.92);}to{opacity:1;transform:scale(1);}}
.msg-menu button{
  display:flex;align-items:center;gap:.625rem;width:100%;
  padding:.625rem .75rem;border-radius:.5rem;
  font-size:.875rem;color:var(--text);text-align:left;
}
.msg-menu button:active{background:#F4F4F6;}
.msg-menu .ico{width:1.0625rem;height:1.0625rem;color:var(--text-2);flex:none;}

/* 默认禁止长按选字，只有「选择文本」后才允许 */
body{-webkit-user-select:none;user-select:none;-webkit-touch-callout:none;}
input,textarea,.msg.selecting,.msg.selecting *{
  -webkit-user-select:text;user-select:text;-webkit-touch-callout:default;
}

/* ---------- 消息头像 ---------- */
.msg{position:relative;}
.msg.has-avatar{padding-left:calc(var(--ava-size, 2.5rem) + .5rem);}
.msg.user.has-avatar{padding-left:0;padding-right:calc(var(--ava-size, 2.5rem) + .5rem);}
.msg-avatar{
  position:absolute;left:0;top:.125rem;
  width:var(--ava-size, 2.5rem);height:var(--ava-size, 2.5rem);
  border-radius:50%;overflow:hidden;
  padding:0;border:none;background:rgba(255,255,255,.72);
  box-shadow:0 2px 8px rgba(23,23,27,.10), inset 0 0 0 1px rgba(255,255,255,.8);
}
.msg-avatar img{width:100%;height:100%;object-fit:cover;display:block;}
.msg-avatar.user-ava{left:auto;right:0;}
.msg-avatar.ai-ava:active{transform:scale(.94);}

/* 切换会话时不要每条消息都重播入场动画 */
.msgs.bulk .msg{animation:none;}

/* 切换会话时不要每条消息都重播入场动画 */
.msgs.bulk .msg{animation:none;}
