/* ============================================================================
 *  styles.css —— 界面样式
 *  设计语言：黑白 + 单一蓝，克制动效（扁平、安静、快速）
 *  不使用渐变光晕、不使用紫色、不做夸张位移与弹跳
 * ========================================================================== */

/* ------------------------------ 主题变量 ------------------------------ */
:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

  /* 唯一强调色：蓝 */
  --accent: #4d6bfe;
  --accent-hover: #3d5bf2;
  --accent-soft: #eef2ff;
  --accent-line: #d7dffd;

  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --bg-hover: #f0f1f4;
  --surface: #ffffff;
  --text: #1f2329;
  --text-2: #4a5058;
  --text-3: #8a919b;
  --line: #ebedf0;
  --line-strong: #dcdfe4;
  --code-bg: #f7f8fa;
  --code-head: #eff1f4;
  --danger: #e5484d;
  --ok: #18a058;

  --warn-bg: #fff9db;
  --warn-text: #8a6d00;
  --warn-line: #f0e2a6;
  --bar-bg: #1f2329;
  --bar-text: #f7c948;

  --shadow-sm: 0 1px 2px rgba(16, 21, 40, .05);
  --shadow-md: 0 6px 20px -8px rgba(16, 21, 40, .18);

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --bar-h: 34px;
  --sidebar-w: 268px;
  --topbar-h: 56px;
  --dur: .15s;
  --ease: cubic-bezier(.2, 0, 0, 1);
}

[data-theme="dark"] {
  --accent: #5b7bff;
  --accent-hover: #6f8bff;
  --accent-soft: #1d2540;
  --accent-line: #2c3a63;

  --bg: #1a1a1a;
  --bg-soft: #141414;
  --bg-hover: #262626;
  --surface: #202020;
  --text: #e9e9ea;
  --text-2: #b6b6ba;
  --text-3: #86868c;
  --line: #2a2a2c;
  --line-strong: #3a3a3d;
  --code-bg: #161616;
  --code-head: #232323;
  --danger: #f56b6f;
  --ok: #3fbf7f;

  --warn-bg: #2b2410;
  --warn-text: #e8c766;
  --warn-line: #4a3d16;
  --bar-bg: #0e0e10;
  --bar-text: #f7c948;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 8px 24px -10px rgba(0, 0, 0, .7);
}

/* ------------------------------ 基础 ------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  overscroll-behavior: none;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
[hidden] { display: none !important; }

::selection { background: var(--accent-soft); color: var(--text); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.scroller, .history, .gate-terms, .modal-body { scrollbar-width: thin; }
.scroller::-webkit-scrollbar, .history::-webkit-scrollbar,
.gate-terms::-webkit-scrollbar, .modal-body::-webkit-scrollbar { width: 8px; height: 8px; }
.scroller::-webkit-scrollbar-thumb, .history::-webkit-scrollbar-thumb,
.gate-terms::-webkit-scrollbar-thumb, .modal-body::-webkit-scrollbar-thumb {
  background: var(--line-strong); border-radius: 99px;
}
.scroller::-webkit-scrollbar-track, .history::-webkit-scrollbar-track { background: transparent; }

/* ------------------------------ 顶部 demo 提示条 ------------------------------ */
.notice-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 130;
  height: var(--bar-h);
  display: flex; align-items: center; justify-content: center;
  padding: 0 14px;
  font-size: 12.5px; font-weight: 600; letter-spacing: .01em;
  color: var(--bar-text);
  background: var(--bar-bg);
  border-bottom: 1px solid var(--bar-bg);
  text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ------------------------------ 通用小件 ------------------------------ */
.mono { font-family: var(--mono); font-size: .92em; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--r-sm);
  color: var(--text-2);
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 18px; border-radius: var(--r-md);
  font-size: 14px; font-weight: 500;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.btn-primary { color: #fff; background: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-soft { color: var(--text); background: var(--bg-soft); border: 1px solid var(--line); }
.btn-soft:hover { background: var(--bg-hover); }
.btn-ghost { color: var(--text-2); background: transparent; border: 1px solid var(--line-strong); }
.btn-ghost:hover { color: var(--text); background: var(--bg-soft); }
.btn[disabled] { opacity: .45; pointer-events: none; }

kbd {
  font-family: var(--mono); font-size: 10.5px; line-height: 1;
  padding: 3px 5px; border-radius: 4px;
  color: var(--text-3); background: var(--bg);
  border: 1px solid var(--line);
}

/* ------------------------------ 品牌 ------------------------------ */
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.logo { display: block; width: 28px; height: 28px; flex: none; }
.logo svg, .welcome-logo svg { display: block; width: 100%; height: 100%; }
.logo-lg { width: 44px; height: 44px; }
.logo-sm { width: 28px; height: 28px; }

/* 品牌图标位：优先显示 tb.jpg，加载失败则回退到内置 SVG */
.logo, .welcome-logo {
  overflow: hidden; border-radius: 8px;
  background: #fff; line-height: 0;
}
.welcome-logo { border-radius: 12px; }
.logo-img { display: none; width: 100%; height: 100%; object-fit: cover; transform: scale(1.16); }
.has-img .logo-img { display: block; }
.has-img svg { display: none; }
.brand-name {
  margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-tag { margin: 1px 0 0; font-size: 11.5px; color: var(--text-3); }

/* ------------------------------ 协议门 ------------------------------ */
.gate {
  position: fixed; inset: var(--bar-h) 0 0 0; z-index: 90;
  display: grid; place-items: center; padding: 24px;
  background: var(--bg);
  animation: fadeIn var(--dur) var(--ease) both;
}
.gate-card {
  position: relative; width: min(560px, 100%); max-height: 100%;
  display: flex; flex-direction: column; gap: 16px;
  padding: 26px 26px 22px;
  border-radius: var(--r-lg);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-md);
}
.gate-title { margin: 2px 0 0; font-size: 16px; font-weight: 600; }
.gate-terms {
  flex: 1; min-height: 120px; overflow-y: auto;
  padding: 14px 16px; border-radius: var(--r-md);
  background: var(--bg-soft); border: 1px solid var(--line);
  font-size: 13.5px; color: var(--text-2); line-height: 1.75;
}
.gate-terms p { margin: 0 0 8px; }
.gate-terms p:last-child { margin-bottom: 0; }
.gate-actions { display: flex; gap: 10px; }
.gate-actions .btn { flex: 1; }

/* ------------------------------ 应用骨架 ------------------------------ */
.app {
  height: calc(100dvh - var(--bar-h));
  margin-top: var(--bar-h);
  display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  overflow: hidden;
  transition: grid-template-columns .2s var(--ease);
}
.app[data-sidebar="closed"] { grid-template-columns: 0 minmax(0, 1fr); }

/* ------------------------------ 侧边栏 ------------------------------ */
.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  padding: 12px 10px 8px;
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  transition: opacity var(--dur) var(--ease), transform .2s var(--ease);
}
.app[data-sidebar="closed"] .sidebar { opacity: 0; pointer-events: none; }

.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 12px; gap: 8px; }
.app[data-sidebar="open"] .sidebar-close { display: none; }

.new-chat {
  display: flex; align-items: center; gap: 8px;
  width: 100%; height: 40px; padding: 0 12px; margin-bottom: 10px;
  border-radius: var(--r-md);
  color: var(--accent); font-size: 14px; font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--line);
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.new-chat:hover { background: var(--bg-hover); border-color: var(--line-strong); }
.new-chat svg { width: 17px; height: 17px; }
.new-chat span { flex: 1; text-align: left; }
.new-chat kbd { background: var(--bg-soft); }

.search {
  display: flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 10px; margin-bottom: 14px;
  border-radius: var(--r-sm); color: var(--text-3);
  background: var(--surface); border: 1px solid var(--line);
  transition: border-color var(--dur) var(--ease);
}
.search:focus-within { border-color: var(--accent-line); }
.search svg { width: 15px; height: 15px; flex: none; }
.search input {
  flex: 1; min-width: 0; border: 0; background: none; outline: none;
  font-size: 13.5px; color: var(--text);
}
.search input::placeholder { color: var(--text-3); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }

.history-label {
  padding: 0 8px 6px; font-size: 12px; color: var(--text-3);
}

.history { flex: 1; min-height: 0; overflow-y: auto; padding: 0 0 8px; }
.history-empty {
  padding: 22px 12px; text-align: center; font-size: 12.5px; color: var(--text-3);
}

.chat-item {
  position: relative; display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 8px 9px; margin-bottom: 2px;
  border-radius: var(--r-sm); text-align: left;
  color: var(--text-2); font-size: 13.5px;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
  touch-action: pan-y;
}
.chat-item:hover { background: var(--bg-hover); color: var(--text); }
.chat-item[aria-current="true"] { color: var(--text); background: var(--accent-soft); font-weight: 500; }
.ci-icon { width: 15px; height: 15px; flex: none; opacity: .7; display: grid; place-items: center; }
.ci-icon svg { width: 15px; height: 15px; }
.chat-item-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-del {
  display: grid; place-items: center;
  width: 22px; height: 22px; flex: none; border-radius: 5px;
  color: var(--text-3); opacity: 0;
  transition: opacity var(--dur) var(--ease), background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.ci-del svg { width: 13px; height: 13px; }
.chat-item:hover .ci-del { opacity: 1; }
.ci-del:hover { background: rgba(229, 72, 77, .1); color: var(--danger); }
.chat-item.swiping { transition: none; }
.chat-item.removing { transform: translateX(-110%) !important; opacity: 0; transition: transform .2s var(--ease), opacity .2s var(--ease); }

.sidebar-foot {
  display: flex; flex-direction: column; gap: 1px;
  padding-top: 8px; border-top: 1px solid var(--line);
}
.foot-btn {
  display: flex; align-items: center; gap: 9px;
  height: 34px; padding: 0 9px; border-radius: var(--r-sm);
  font-size: 13.5px; color: var(--text-2); text-align: left;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.foot-btn:hover { background: var(--bg-hover); color: var(--text); }
.foot-icon { display: grid; place-items: center; width: 17px; height: 17px; }
.foot-icon svg { width: 16px; height: 16px; }

/* ------------------------------ 主区域 ------------------------------ */
.main {
  position: relative; display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  background: var(--bg);
}

.topbar {
  display: flex; align-items: center; gap: 8px;
  height: var(--topbar-h); padding: 0 14px; flex: none;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  z-index: 4;
}
.topbar-title {
  flex: 1; min-width: 0; font-size: 14.5px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar-right { display: flex; align-items: center; gap: 6px; flex: none; }
.app[data-sidebar="open"] #menu-btn { display: none; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 9px; border-radius: 99px;
  font-size: 12px; color: var(--text-2);
  background: var(--bg-soft); border: 1px solid var(--line);
  max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); flex: none; }

.notice {
  display: flex; align-items: flex-start; gap: 9px;
  width: min(780px, calc(100% - 32px));
  margin: 12px auto 0; padding: 10px 12px;
  border-radius: var(--r-md); font-size: 13px; line-height: 1.55;
  color: var(--warn-text); background: var(--warn-bg); border: 1px solid var(--warn-line);
}
.notice svg { width: 16px; height: 16px; flex: none; margin-top: 2px; }
.notice code {
  font-family: var(--mono); font-size: .92em; padding: 1px 5px;
  border-radius: 4px; background: rgba(138, 109, 0, .1);
}
[data-theme="dark"] .notice code { background: rgba(232, 199, 102, .14); }

/* 滚动区 */
.scroller {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden;
  overscroll-behavior: contain;
  display: flex; flex-direction: column;
  scroll-behavior: smooth;
}
.thread {
  width: 100%; max-width: 780px; margin: 0 auto;
  padding: 18px 20px 0; display: flex; flex-direction: column;
}
.thread-pad { height: 8px; flex: none; }

/* ------------------------------ 欢迎空态 ------------------------------ */
.welcome {
  width: 100%; max-width: 780px; margin: auto;
  padding: 30px 20px 10px; text-align: center;
  display: flex; flex-direction: column; align-items: center;
}
.welcome-logo { width: 48px; height: 48px; display: block; margin-bottom: 16px; }
.welcome-title {
  margin: 0 0 6px; font-size: 22px; font-weight: 600;
  letter-spacing: -.01em; line-height: 1.35; color: var(--text);
}
.welcome-sub { margin: 0 0 24px; font-size: 14px; color: var(--text-3); max-width: 46ch; }
.suggestions {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px; width: 100%;
}
.suggestion {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 12px 13px; border-radius: var(--r-md); text-align: left;
  font-size: 13.5px; line-height: 1.5; color: var(--text-2);
  background: var(--surface); border: 1px solid var(--line);
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.suggestion:hover { color: var(--text); border-color: var(--line-strong); background: var(--bg-soft); }
.suggestion-ico {
  display: grid; place-items: center; flex: none;
  width: 24px; height: 24px; border-radius: 6px;
  color: var(--accent); background: var(--accent-soft);
}
.suggestion-ico svg { width: 14px; height: 14px; }

/* ------------------------------ 消息 ------------------------------ */
.msg {
  display: flex; gap: 11px; margin-bottom: 20px;
  animation: fadeIn var(--dur) var(--ease) both;
}
.msg-user { flex-direction: row-reverse; }

.avatar {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; margin-top: 3px;
  font-size: 11.5px; font-weight: 600;
}
.msg-user .avatar { color: var(--text-2); background: var(--bg-hover); }
.msg-assistant .avatar { background: var(--accent); color: #fff; }
.avatar svg { width: 100%; height: 100%; border-radius: inherit; }

.msg-body { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.msg-user .msg-body { align-items: flex-end; flex: 0 1 auto; max-width: 82%; }

.bubble {
  position: relative; font-size: 14.8px; line-height: 1.75;
  word-break: break-word; overflow-wrap: anywhere;
  user-select: text;
}
.msg-user .bubble {
  padding: 9px 14px; border-radius: 14px;
  color: var(--text); background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  white-space: pre-wrap;
}
.msg-assistant .bubble { color: var(--text); padding: 0; }

/* 流式光标 */
.caret {
  display: inline-block; width: 6px; height: 1em;
  margin-left: 2px; vertical-align: -1px;
  background: var(--accent); animation: blink 1s steps(1) infinite;
}

/* 消息操作 */
.msg-actions {
  display: flex; gap: 2px; margin-top: 4px;
  opacity: 0; transition: opacity var(--dur) var(--ease);
}
.msg:hover .msg-actions, .msg-actions:focus-within { opacity: 1; }
.act {
  display: inline-flex; align-items: center; gap: 4px;
  height: 24px; padding: 0 7px; border-radius: 6px;
  font-size: 12px; color: var(--text-3);
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.act svg { width: 12px; height: 12px; }
.act:hover { background: var(--bg-hover); color: var(--text); }
.act.done { color: var(--ok); }

.msg-note { margin-top: 4px; font-size: 11.5px; color: var(--text-3); }

/* 推理过程 */
.reason-box {
  margin: 0 0 8px; padding: 9px 12px; border-radius: var(--r-md);
  background: var(--bg-soft); border: 1px solid var(--line);
  font-size: 12.5px; color: var(--text-3); line-height: 1.65;
  max-height: 148px; overflow: auto;
}
.reason-box b { color: var(--text-2); font-weight: 600; font-size: 12px; }
.reason-box .reason-text { margin-top: 4px; }
.reason-box .reason-text p { margin: 0 0 .4em; }
.reason-box .reason-text p:last-child { margin-bottom: 0; }

/* 思考中 */
.thinking { display: inline-flex; align-items: center; gap: 5px; }
.thinking i { width: 5px; height: 5px; border-radius: 50%; background: var(--text-3); animation: pulse 1.2s infinite ease-in-out both; }
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }
.thinking span { margin-left: 4px; font-size: 13px; color: var(--text-3); }

/* 错误气泡 */
.msg-error .bubble {
  padding: 9px 14px; border-radius: var(--r-md);
  color: var(--danger); background: var(--bg-soft); border: 1px solid var(--line-strong);
}

/* ------------------------------ 消息内 Markdown ------------------------------ */
.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.bubble p { margin: 0 0 .75em; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4, .bubble h5, .bubble h6 {
  margin: 1.1em 0 .45em; font-weight: 600; line-height: 1.4;
}
.bubble h1 { font-size: 1.34em; }
.bubble h2 { font-size: 1.2em; }
.bubble h3 { font-size: 1.08em; }
.bubble h4, .bubble h5, .bubble h6 { font-size: 1em; }
.bubble ul, .bubble ol { margin: .3em 0 .8em; padding-left: 1.4em; }
.bubble li { margin: .25em 0; }
.bubble li > ul, .bubble li > ol { margin: .25em 0; }
.bubble ul { list-style: disc; }
.bubble ol { list-style: decimal; }
.bubble li::marker { color: var(--text-3); }
.bubble blockquote {
  margin: .7em 0; padding: .45em .9em;
  border-left: 2px solid var(--line-strong); border-radius: 0 6px 6px 0;
  color: var(--text-2); background: var(--bg-soft);
}
.bubble blockquote p:last-child { margin-bottom: 0; }
.bubble hr { margin: 1em 0; border: 0; border-top: 1px solid var(--line); }
.bubble a { color: var(--accent); text-decoration: none; }
.bubble a:hover { text-decoration: underline; }
.bubble strong { font-weight: 600; }
.bubble del { opacity: .7; }

.bubble code {
  font-family: var(--mono); font-size: .88em;
  padding: .15em .4em; border-radius: 4px;
  background: var(--bg-hover); color: var(--text);
  word-break: break-word;
}

.code-block {
  margin: .8em 0; border-radius: var(--r-md); overflow: hidden;
  border: 1px solid var(--line); background: var(--code-bg);
}
.code-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 6px 8px 6px 12px;
  background: var(--code-head); border-bottom: 1px solid var(--line);
}
.code-lang {
  font-family: var(--mono); font-size: 11.5px;
  color: var(--text-3); text-transform: lowercase;
}
.code-copy {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 7px; border-radius: 5px;
  font-size: 11.5px; color: var(--text-2);
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.code-copy svg { width: 12px; height: 12px; }
.code-copy:hover { background: rgba(0, 0, 0, .06); color: var(--text); }
[data-theme="dark"] .code-copy:hover { background: rgba(255, 255, 255, .08); }
.code-copy.done { color: var(--ok); }
.code-block pre {
  margin: 0; padding: 12px 14px; overflow-x: auto;
  font-family: var(--mono); font-size: 13px; line-height: 1.65;
  tab-size: 4; color: var(--text); background: none;
}
.code-block pre code {
  padding: 0; background: none; color: inherit; font-size: inherit;
  border-radius: 0; white-space: pre;
}

.table-wrap {
  margin: .8em 0; overflow-x: auto;
  border: 1px solid var(--line); border-radius: 6px;
}
.bubble table {
  width: 100%; border-collapse: collapse; font-size: .93em; margin: 0;
}
.bubble th, .bubble td {
  padding: 7px 11px; text-align: left;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
.bubble th { font-weight: 600; background: var(--bg-soft); }
.bubble tr:last-child td { border-bottom: 0; }

/* ------------------------------ 回到最新 ------------------------------ */
.to-bottom {
  position: absolute; right: 20px; bottom: 122px; z-index: 5;
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 50%;
  color: var(--text-2); background: var(--surface);
  border: 1px solid var(--line-strong);
  opacity: 0; pointer-events: none;
  transition: opacity var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.to-bottom svg { width: 17px; height: 17px; }
.to-bottom.show { opacity: 1; pointer-events: auto; }
.to-bottom:hover { background: var(--bg-soft); color: var(--text); }

/* ------------------------------ 输入区 ------------------------------ */
.composer-wrap {
  flex: none; padding: 8px 20px max(14px, env(safe-area-inset-bottom));
}
.composer {
  width: 100%; max-width: 780px; margin: 0 auto;
  padding: 9px 9px 7px 14px;
  border-radius: var(--r-lg);
  background: var(--surface); border: 1px solid var(--line-strong);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.composer.is-focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
#input {
  display: block; width: 100%; max-height: 180px; min-height: 24px;
  padding: 3px 4px 2px; border: 0; outline: none; resize: none;
  background: none; font-size: 15px; line-height: 1.6; color: var(--text);
}
#input::placeholder { color: var(--text-3); }

.composer-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-top: 2px;
}
.composer-hint {
  font-size: 11.5px; color: var(--text-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.composer-actions { display: flex; align-items: center; gap: 6px; flex: none; }

.send {
  position: relative; display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 50%;
  color: #fff; background: var(--accent);
  transition: background-color var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.send svg { width: 17px; height: 17px; }
.send .i-stop { display: none; }
.send:hover { background: var(--accent-hover); }
.send[disabled] { color: var(--text-3); background: var(--bg-hover); cursor: not-allowed; }
.composer.streaming .send { background: var(--danger); }
.composer.streaming .send:hover { background: #d13f44; }
.composer.streaming .send .i-send { display: none; }
.composer.streaming .send .i-stop { display: block; }

.composer-tip {
  max-width: 780px; margin: 7px auto 0; text-align: center;
  font-size: 11.5px; color: var(--text-3);
}

/* ------------------------------ 弹窗 ------------------------------ */
.modal {
  position: fixed; inset: var(--bar-h) 0 0 0; z-index: 80;
  display: grid; place-items: center; padding: 22px;
  background: rgba(15, 18, 24, .38);
  animation: fadeIn var(--dur) var(--ease) both;
}
.modal-card {
  width: min(440px, 100%); max-height: min(84dvh, 680px);
  display: flex; flex-direction: column;
  border-radius: var(--r-lg); overflow: hidden;
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow-md);
}
.modal-sm { width: min(400px, 100%); }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 12px 12px 10px 18px; border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.modal-body { padding: 16px 18px 18px; overflow-y: auto; }

.about-body { text-align: center; }
.about-logo { width: 52px; height: 52px; margin: 0 auto 12px; }
.about-name { margin: 0 0 3px; font-size: 18px; font-weight: 600; }
.about-ver { margin: 0 0 12px; font-size: 12.5px; color: var(--text-3); }
.about-desc { margin: 0 0 16px; font-size: 13.5px; color: var(--text-2); line-height: 1.65; }
.about-meta {
  display: flex; flex-direction: column; gap: 1px;
  border-radius: var(--r-md); overflow: hidden;
  border: 1px solid var(--line); background: var(--line);
  text-align: left;
}
.about-meta > div {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 12px; background: var(--surface); font-size: 13px;
}
.about-meta span { color: var(--text-3); flex: none; }
.about-meta b {
  font-weight: 500; color: var(--text); min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.about-actions { display: flex; gap: 8px; margin-top: 16px; }
.about-actions .btn { flex: 1; }
.about-note { margin: 12px 0 0; font-size: 11.5px; color: var(--text-3); line-height: 1.6; }

.update-state { text-align: center; padding: 6px 0 2px; }
.update-state .spinner {
  display: inline-block; width: 26px; height: 26px; margin-bottom: 12px;
  border-radius: 50%; border: 2px solid var(--line-strong);
  border-top-color: var(--accent); animation: spin .8s linear infinite;
}
.update-state .state-ico { display: grid; place-items: center; width: 40px; height: 40px; margin: 0 auto 10px; border-radius: 50%; }
.update-state .state-ico svg { width: 22px; height: 22px; }
.state-ico.ok { color: var(--ok); background: var(--bg-soft); }
.state-ico.warn { color: var(--accent); background: var(--accent-soft); }
.state-ico.err { color: var(--danger); background: var(--bg-soft); }
.update-title { margin: 0 0 3px; font-size: 14.5px; font-weight: 600; }
.update-sub { margin: 0; font-size: 12.5px; color: var(--text-3); line-height: 1.6; }
.update-detail { margin-top: 14px; }
.update-detail h4 { margin: 0 0 7px; font-size: 13px; color: var(--text-2); font-weight: 500; }
.update-log {
  padding: 10px 12px; border-radius: var(--r-sm); font-size: 13px;
  line-height: 1.65; color: var(--text-2); white-space: pre-line;
  background: var(--bg-soft); border: 1px solid var(--line);
}
.update-actions { display: flex; gap: 8px; margin-top: 16px; }
.update-actions .btn { flex: 1; }
.announce-text { margin: 0; font-size: 14px; line-height: 1.7; color: var(--text-2); white-space: pre-line; }

/* ------------------------------ Toast ------------------------------ */
.toast {
  position: fixed; left: 50%; top: calc(var(--bar-h) + 14px); z-index: 120;
  transform: translate(-50%, -6px);
  max-width: min(86vw, 420px); padding: 8px 15px;
  border-radius: var(--r-md); font-size: 13px; color: var(--text);
  background: var(--surface); border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-md);
  opacity: 0; pointer-events: none;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------ 遮罩（移动端） ------------------------------ */
.backdrop {
  position: fixed; inset: var(--bar-h) 0 0 0; z-index: 19;
  background: rgba(15, 18, 24, .34);
  opacity: 0; pointer-events: none;
  transition: opacity var(--dur) var(--ease);
}
.backdrop.show { opacity: 1; pointer-events: auto; }

/* ------------------------------ 动画 ------------------------------ */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse {
  0%, 100% { opacity: .3; }
  50% { opacity: 1; }
}

/* ------------------------------ 响应式 ------------------------------ */
@media (max-width: 900px) {
  :root { --bar-h: 48px; }
  .notice-bar { font-size: 11px; white-space: normal; line-height: 1.3; padding: 0 10px; }
  .code-block pre { font-size: 12px; }

  .app { grid-template-columns: minmax(0, 1fr); }
  .app[data-sidebar="closed"] { grid-template-columns: minmax(0, 1fr); }

  .sidebar {
    position: fixed; inset: var(--bar-h) auto 0 0; z-index: 20;
    width: min(82vw, 310px);
    background: var(--bg-soft);
    border-right: 1px solid var(--line);
    transform: translateX(-102%);
  }
  .app[data-sidebar="open"] .sidebar { transform: none; opacity: 1; pointer-events: auto; }
  .app[data-sidebar="closed"] .sidebar { transform: translateX(-102%); opacity: 1; }
  .app[data-sidebar="open"] .sidebar-close { display: inline-flex; }
  .app[data-sidebar="open"] #menu-btn { display: none; }
  .app[data-sidebar="closed"] #menu-btn { display: inline-flex; }

  .topbar { height: 52px; padding: 0 10px; }
  .thread { padding: 14px 14px 0; }
  .welcome { padding: 22px 16px 8px; }
  .welcome-logo { width: 44px; height: 44px; }
  .suggestions { grid-template-columns: minmax(0, 1fr); }
  .msg { gap: 9px; margin-bottom: 18px; }
  .avatar { width: 24px; height: 24px; font-size: 11px; }
  .msg-user .msg-body { max-width: 88%; }
  .bubble { font-size: 14.5px; }
  .composer-wrap { padding: 8px 12px max(10px, env(safe-area-inset-bottom)); }
  .composer { border-radius: var(--r-md); }
  .composer-tip { display: none; }
  .to-bottom { right: 14px; bottom: 108px; }
  .msg-actions { opacity: 1; }
  .new-chat kbd { display: none; }
  .chat-item[aria-current="true"] .ci-del { opacity: 1; }
  .gate-card { padding: 20px 16px 16px; }
  .gate-actions { flex-direction: column-reverse; }
}

@media (max-width: 380px) {
  .chip { display: none; }
  .brand-name { font-size: 14.5px; }
}

/* 触屏设备常显操作按钮 */
@media (hover: none) {
  .msg-actions { opacity: 1; }
  .ci-del { opacity: 1; }
}

/* 尊重系统减少动效 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
