/* ============ 设计 token ============ */
:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", "Fira Code", ui-monospace, Consolas, monospace;

  --bg: #0e1016;
  --bg-elevated: #161922;
  --bg-input: #1c202b;
  --bg-hover: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #e7e9f0;
  --text-dim: #99a0b0;
  --text-faint: #6b7280;
  --accent: #6d5efc;
  --accent-hi: #8b7bff;
  --accent-2: #22d3ee;
  --danger: #f4506b;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --radius-sm: 10px;
  --sidebar-w: 268px;
}

[data-theme="light"] {
  --bg: #f6f7f9;
  --bg-elevated: #ffffff;
  --bg-input: #ffffff;
  --bg-hover: rgba(0, 0, 0, 0.045);
  --border: rgba(0, 0, 0, 0.09);
  --border-strong: rgba(0, 0, 0, 0.16);
  --text: #14161c;
  --text-dim: #5b616e;
  --text-faint: #9096a1;
  --accent: #5b4bf0;
  --accent-hi: #6d5efc;
  --shadow: 0 10px 30px rgba(20, 22, 40, 0.12);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font-family: inherit; cursor: pointer; }
::selection { background: color-mix(in srgb, var(--accent) 40%, transparent); }

/* 滚动条 */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 99px;
  border: 2px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: content-box; }

/* ============ 布局 ============ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100dvh;
  overflow: hidden;
}
.app[hidden] { display: none; }
.app.sidebar-collapsed { grid-template-columns: 0 1fr; }

/* ============ 侧边栏 ============ */
.sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  transition: transform 0.25s ease;
}
.sidebar-head {
  padding: 14px 14px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.2px;
}
.brand .logo {
  width: 28px; height: 28px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center;
  color: #fff; font-weight: 800;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 45%, transparent);
}
.new-chat {
  margin: 4px 12px 10px;
  padding: 11px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  display: flex; align-items: center; gap: 9px;
  font-size: 14px; font-weight: 600;
  transition: background 0.15s, border-color 0.15s;
}
.new-chat:hover { background: var(--bg-hover); border-color: var(--accent); }

.chat-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.chat-list-empty { color: var(--text-faint); font-size: 13px; text-align: center; padding: 24px 12px; }
.chat-item {
  position: relative;
  padding: 9px 34px 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 13.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background 0.12s, color 0.12s;
  margin-bottom: 2px;
}
.chat-item:hover { background: var(--bg-hover); color: var(--text); }
.chat-item.active { background: var(--bg-hover); color: var(--text); }
.chat-item.active::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px;
  width: 3px; border-radius: 3px; background: var(--accent);
}
.chat-item .del {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  opacity: 0; border: none; background: transparent; color: var(--text-faint);
  padding: 4px; border-radius: 6px; line-height: 0;
  transition: opacity 0.12s, color 0.12s, background 0.12s;
}
.chat-item:hover .del { opacity: 1; }
.chat-item .del:hover { color: var(--danger); background: var(--bg-hover); }
.chat-item .del.confirm {
  opacity: 1; color: #fff; background: var(--danger);
  animation: del-pulse 0.9s ease-in-out infinite;
}
@keyframes del-pulse { 50% { filter: brightness(1.2); } }

/* 会话列表骨架屏 */
.chat-skel {
  height: 34px; margin: 0 4px 6px; border-radius: var(--radius-sm);
  background: linear-gradient(100deg, var(--bg-hover) 40%, var(--border) 50%, var(--bg-hover) 60%);
  background-size: 240% 100%;
  animation: skel-sweep 1.4s linear infinite;
}
@keyframes skel-sweep { from { background-position: 130% 0; } to { background-position: -110% 0; } }

.sidebar-foot { border-top: 1px solid var(--border); padding: 10px 12px; }
.side-btn {
  width: 100%;
  padding: 9px 12px; border-radius: var(--radius-sm);
  background: transparent; border: none; color: var(--text-dim);
  display: flex; align-items: center; gap: 10px; font-size: 13.5px;
  transition: background 0.12s, color 0.12s;
}
.side-btn:hover { background: var(--bg-hover); color: var(--text); }

/* ============ 主区 ============ */
.main { display: flex; flex-direction: column; min-width: 0; height: 100dvh; }
.topbar {
  height: 56px; flex: 0 0 56px;
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  position: relative; z-index: 5;
}
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  border: none; background: transparent; color: var(--text-dim);
  display: grid; place-items: center;
  transition: background 0.12s, color 0.12s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.model-select {
  appearance: none;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 34px 8px 12px;
  font-size: 13.5px; font-weight: 600;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2399a0b0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
  transition: border-color 0.15s;
}
.model-select:hover { border-color: var(--border-strong); }
.model-select:focus { outline: none; border-color: var(--accent); }
.topbar-spacer { flex: 1; }
.upstream-badge {
  font-size: 12px; color: var(--text-faint);
  padding: 5px 10px; border-radius: 99px; border: 1px solid var(--border);
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ============ 消息区 ============ */
.scroll {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  /* 不用 smooth：切换会话/贴底要瞬时到位，否则超长会话会出现"从上滚到下"的滚屏 */
  overflow-anchor: none;
}
.messages {
  max-width: 820px; margin: 0 auto; padding: 26px 20px 20px;
  display: flex; flex-direction: column; gap: 22px;
  min-height: 100%;
}
.msg { display: flex; gap: 14px; animation: rise 0.28s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.avatar {
  flex: 0 0 30px; width: 30px; height: 30px; border-radius: 9px;
  display: grid; place-items: center; font-size: 13px; font-weight: 700; margin-top: 2px;
}
.msg.assistant .avatar { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.msg.user .avatar { background: var(--bg-input); border: 1px solid var(--border); color: var(--text-dim); }
.msg .body { min-width: 0; flex: 1; }
.msg .role { font-size: 12.5px; color: var(--text-faint); margin-bottom: 3px; font-weight: 600; }

.bubble { }
.msg.user .content {
  display: inline-block;
  background: linear-gradient(135deg, var(--accent), var(--accent-hi));
  color: #fff; padding: 11px 15px; border-radius: 14px 14px 14px 4px;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 32%, transparent);
  white-space: pre-wrap; word-break: break-word;
}
.msg.assistant .content { color: var(--text); }

/* Markdown 正文 */
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: 0.5em 0; }
.md h1, .md h2, .md h3 { margin: 1em 0 0.5em; line-height: 1.3; }
.md h1 { font-size: 1.5em; } .md h2 { font-size: 1.3em; } .md h3 { font-size: 1.12em; }
.md ul, .md ol { padding-left: 1.5em; margin: 0.5em 0; }
.md li { margin: 0.25em 0; }
.md a { color: var(--accent-hi); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md blockquote {
  margin: 0.6em 0; padding: 0.2em 1em; border-left: 3px solid var(--accent);
  color: var(--text-dim); background: var(--bg-hover); border-radius: 0 8px 8px 0;
}
.md :not(pre) > code {
  font-family: var(--font-mono); font-size: 0.88em;
  background: var(--bg-hover); padding: 0.15em 0.4em; border-radius: 6px;
  border: 1px solid var(--border);
}
.md table { border-collapse: collapse; margin: 0.7em 0; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 12px; }
.md th { background: var(--bg-hover); }
.md hr { border: none; border-top: 1px solid var(--border); margin: 1.2em 0; }

/* 代码块 */
.code-wrap {
  margin: 0.7em 0; border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; background: #0b0d13;
}
[data-theme="light"] .code-wrap { background: #f4f5f8; }
.code-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px; font-size: 12px; color: var(--text-dim);
  background: var(--bg-hover); border-bottom: 1px solid var(--border);
}
.code-head .lang { font-family: var(--font-mono); text-transform: lowercase; }
.copy-btn {
  border: none; background: transparent; color: var(--text-dim);
  display: flex; align-items: center; gap: 5px; font-size: 12px;
  padding: 3px 8px; border-radius: 7px; transition: background 0.12s, color 0.12s;
}
.copy-btn:hover { background: var(--bg-hover); color: var(--text); }
.copy-btn.ok { color: #43c98a; }
.code-wrap pre { margin: 0; padding: 13px 14px; overflow-x: auto; }
.code-wrap code { font-family: var(--font-mono); font-size: 13px; line-height: 1.55; background: none; }

/* 光标 + loading */
.cursor-blink::after {
  content: "▋"; margin-left: 1px; color: var(--accent-hi);
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.typing { display: inline-flex; gap: 5px; padding: 4px 0; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint);
  animation: bounce 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-5px); opacity: 1; } }

.msg-actions { margin-top: 8px; display: flex; gap: 4px; opacity: 0; transition: opacity 0.15s; }
.msg:hover .msg-actions { opacity: 1; }
.msg-act {
  border: none; background: transparent; color: var(--text-faint);
  padding: 4px 7px; border-radius: 7px; font-size: 12px;
  display: inline-flex; align-items: center; gap: 4px; transition: background 0.12s, color 0.12s;
}
.msg-act:hover { background: var(--bg-hover); color: var(--text); }
.msg-act.ok { color: #43c98a; }

/* 消息区居中状态（载入中 / 载入失败） */
.center-state {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; color: var(--text-dim); font-size: 14px; text-align: center;
}
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ 欢迎空态 ============ */
.welcome {
  flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px; gap: 6px;
}
.welcome .big-logo {
  width: 62px; height: 62px; border-radius: 18px; margin-bottom: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; color: #fff; font-size: 28px; font-weight: 800;
  box-shadow: 0 12px 34px color-mix(in srgb, var(--accent) 40%, transparent);
}
.welcome h1 { font-size: 25px; margin: 6px 0 2px; }
.welcome p { color: var(--text-dim); margin: 0 0 20px; }
.suggest-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 240px)); gap: 12px; width: 100%; max-width: 520px;
}
.suggest {
  text-align: left; padding: 14px 16px; border: 1px solid var(--border);
  border-radius: 14px; background: var(--bg-elevated); color: var(--text);
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
}
.suggest:hover { border-color: var(--accent); transform: translateY(-2px); }
.suggest .t { font-weight: 600; font-size: 14px; }
.suggest .d { color: var(--text-faint); font-size: 12.5px; margin-top: 3px; }

/* ============ 输入区 ============ */
.composer-wrap { padding: 8px 20px 18px; }
.composer {
  max-width: 820px; margin: 0 auto;
  border: 1px solid var(--border-strong); border-radius: 20px;
  background: var(--bg-input); padding: 8px;
  display: flex; flex-direction: column; align-items: stretch; gap: 6px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.composer-row { display: flex; align-items: flex-end; gap: 6px; min-width: 0; }
.composer textarea {
  flex: 1; min-width: 0; border: none; background: transparent; color: var(--text);
  resize: none; outline: none; font-size: 15px; line-height: 1.6;
  max-height: 200px; padding: 8px 4px 8px 6px; font-family: inherit;
}
.composer textarea::placeholder { color: var(--text-faint); }
.send-btn {
  flex: 0 0 40px; width: 40px; height: 40px; border-radius: 12px; border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-hi)); color: #fff;
  display: grid; place-items: center; transition: opacity 0.15s, transform 0.1s, filter 0.15s;
}
.send-btn:hover:not(:disabled) { filter: brightness(1.08); }
.send-btn:active:not(:disabled) { transform: scale(0.94); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.send-btn.stop { background: var(--danger); }
.composer-hint { max-width: 820px; margin: 8px auto 0; text-align: center; color: var(--text-faint); font-size: 12px; }

/* composer 工具按钮（回形针 / 麦克风） */
.tool-btn {
  flex: 0 0 38px; width: 38px; height: 38px; border-radius: 12px; border: none;
  background: transparent; color: var(--text-dim);
  display: grid; place-items: center;
  transition: background 0.12s, color 0.12s, box-shadow 0.15s;
}
.tool-btn:hover { background: var(--bg-hover); color: var(--text); }
.tool-btn:active { transform: scale(0.94); }
.tool-btn.unavailable { opacity: 0.35; cursor: not-allowed; }
.tool-btn.unavailable:hover { background: transparent; color: var(--text-dim); }
.tool-btn.rec {
  background: color-mix(in srgb, var(--danger) 15%, transparent);
  color: var(--danger);
  animation: rec-pulse 1.2s ease-in-out infinite;
}
@keyframes rec-pulse {
  50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--danger) 16%, transparent); }
}

/* ============ 附件 chips（composer 顶部） ============ */
.att-strip { display: flex; flex-wrap: wrap; gap: 9px; padding: 6px 4px 2px; }
.att-strip[hidden] { display: none; }
.att-chip {
  position: relative; display: flex; align-items: center;
  border: 1px solid var(--border-strong); border-radius: 12px;
  background: var(--bg-elevated);
  animation: rise 0.18s ease both;
}
.att-chip.loading { opacity: 0.75; }
.att-chip.img img {
  width: 56px; height: 56px; object-fit: cover;
  border-radius: 11px; display: block; cursor: zoom-in;
}
.att-chip.img .att-spin { margin: 21px; }
.att-chip.file { padding: 6px 30px 6px 10px; gap: 8px; max-width: 230px; }
.att-fic { color: var(--accent-hi); line-height: 0; flex: 0 0 auto; }
.att-meta { display: flex; flex-direction: column; min-width: 0; }
.att-meta .n {
  font-size: 12.5px; font-weight: 600; line-height: 1.35;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.att-meta .s { font-size: 11px; color: var(--text-faint); line-height: 1.3; }
.att-rm {
  position: absolute; top: -7px; right: -7px;
  width: 20px; height: 20px; padding: 0; line-height: 0;
  border-radius: 99px; border: 2px solid var(--bg-input);
  background: var(--text-dim); color: var(--bg-input);
  display: grid; place-items: center;
  transition: background 0.12s, transform 0.1s;
}
.att-rm:hover { background: var(--danger); color: #fff; transform: scale(1.08); }
.att-spin {
  display: inline-block; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

/* ============ 语音输入「正在聆听」条 ============ */
.listen-bar {
  display: flex; align-items: center; gap: 8px;
  margin: 2px 4px 0; padding: 6px 11px;
  border-radius: 11px; font-size: 12.5px; color: var(--text-dim); min-width: 0;
  background: color-mix(in srgb, var(--danger) 7%, transparent);
  border: 1px dashed color-mix(in srgb, var(--danger) 38%, transparent);
  animation: rise 0.18s ease both;
}
.listen-bar[hidden] { display: none; }
.listen-dot {
  flex: 0 0 8px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger);
  animation: listen-blink 1.1s ease-in-out infinite;
}
@keyframes listen-blink { 50% { opacity: 0.3; transform: scale(0.8); } }
.listen-label { flex: 0 0 auto; color: var(--danger); font-weight: 600; }
.listen-preview {
  flex: 1; min-width: 0; font-style: italic;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ============ 消息内附件（多模态回显） ============ */
.msg.user .content.rich {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  background: none; box-shadow: none; padding: 0; border-radius: 0;
  max-width: 100%; white-space: normal;
}
.msg.user .content.rich .u-text {
  background: linear-gradient(135deg, var(--accent), var(--accent-hi));
  color: #fff; padding: 11px 15px; border-radius: 14px 14px 14px 4px;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 32%, transparent);
  white-space: pre-wrap; word-break: break-word;
}

/* 文本/PDF 附件折叠块 */
.att-fold {
  width: 100%; max-width: 480px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg-elevated); overflow: hidden;
}
.att-fold summary {
  list-style: none; cursor: pointer; user-select: none;
  padding: 9px 12px; font-size: 13px; font-weight: 600; color: var(--text-dim);
  display: flex; align-items: center; gap: 6px;
  transition: background 0.12s, color 0.12s;
}
.att-fold summary::-webkit-details-marker { display: none; }
.att-fold summary:hover { background: var(--bg-hover); color: var(--text); }
.att-fold[open] summary { border-bottom: 1px solid var(--border); color: var(--text); }
.att-fold pre {
  margin: 0; padding: 10px 12px; max-height: 260px; overflow: auto;
  font-family: var(--font-mono); font-size: 12px; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word; color: var(--text-dim);
}

/* 图片附件缩略图 */
.msg-imgs { display: flex; flex-wrap: wrap; gap: 8px; }
.msg-img {
  display: block; max-height: 180px; max-width: min(320px, 100%);
  border-radius: 12px; border: 1px solid var(--border);
  cursor: zoom-in; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.16);
  transition: transform 0.15s, filter 0.15s;
}
.msg-img:hover { filter: brightness(1.06); transform: translateY(-1px); }

/* 朗读中的操作按钮 */
.msg-act.speaking { color: var(--accent-hi); }

/* ============ 拖拽遮罩 ============ */
.drop-overlay {
  position: fixed; inset: 0; z-index: 70;
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  backdrop-filter: blur(4px);
  pointer-events: none; /* drop 事件由 window 接管，遮罩只做提示 */
}
.drop-overlay[hidden] { display: none; }
.drop-card {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 34px 46px; border-radius: 22px;
  border: 2px dashed var(--accent);
  background: color-mix(in srgb, var(--bg-elevated) 94%, transparent);
  color: var(--accent-hi); box-shadow: var(--shadow);
  animation: rise 0.18s ease both;
}
.drop-title { font-size: 16px; font-weight: 700; color: var(--text); }
.drop-sub { font-size: 12.5px; color: var(--text-dim); }

/* ============ 图片灯箱 ============ */
.lightbox {
  position: fixed; inset: 0; z-index: 80;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.78); backdrop-filter: blur(6px);
  cursor: zoom-out; animation: fade 0.15s ease;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: 92vw; max-height: 92vh; border-radius: 14px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
}

/* ============ 弹窗 ============ */
.overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5);
  display: none; align-items: center; justify-content: center; z-index: 50;
  backdrop-filter: blur(3px); animation: fade 0.18s ease;
}
.overlay.show { display: flex; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: min(480px, calc(100vw - 32px)); background: var(--bg-elevated);
  border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow);
  padding: 22px; animation: rise 0.22s ease both;
}
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.modal .sub { color: var(--text-dim); font-size: 13px; margin: 0 0 18px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field .desc { color: var(--text-faint); font-size: 12px; margin-bottom: 6px; }
.field input[type="text"], .field input[type="password"], .field textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg-input); color: var(--text);
  font-size: 14px; font-family: inherit; outline: none; transition: border-color 0.15s;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { resize: vertical; min-height: 68px; }
.range-row { display: flex; align-items: center; gap: 12px; }
.range-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.range-row .val { font-family: var(--font-mono); font-size: 13px; color: var(--text-dim); width: 34px; text-align: right; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.btn {
  padding: 9px 16px; border-radius: 10px; font-size: 14px; font-weight: 600; border: 1px solid var(--border);
  background: transparent; color: var(--text); transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--bg-hover); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-hi)); color: #fff; border: none; }
.btn.primary:hover { filter: brightness(1.08); }

/* ============ toast ============ */
.toast-host { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border);
  padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow); font-size: 13.5px;
  animation: rise 0.2s ease both; max-width: 80vw;
}
.toast.err { border-color: color-mix(in srgb, var(--danger) 60%, var(--border)); }

/* ============ 移动端遮罩 ============ */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 8; display: none; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 20; top: 0; bottom: 0; left: 0; width: var(--sidebar-w);
    transform: translateX(-100%);
  }
  .app.sidebar-open .sidebar { transform: translateX(0); box-shadow: var(--shadow); }
  .app.sidebar-open .scrim { display: block; }
  .suggest-grid { grid-template-columns: 1fr; }
  .messages { padding: 18px 14px; }
  .composer-wrap { padding: 6px 12px 14px; }
}
