:root {
  --bg: #ffffff;
  --bg-side: #f9f9fa;
  --bg-soft: #f4f4f6;
  --text: #0f1115;
  --text-2: #5c5d66;
  --text-3: #9a9ba3;
  --line: #e7e7ea;
  --bubble: #f2f3f7;
  --accent: #4d6bfe;
  --accent-soft: rgba(77, 107, 254, 0.09);
  --danger: #e5484d;
  --shadow: 0 12px 48px rgba(15, 17, 21, 0.14);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar-w: 260px;
  --content-w: 820px;
}

:root[data-theme="dark"] {
  --bg: #1b1c1d;
  --bg-side: #202123;
  --bg-soft: #26282b;
  --text: #ececef;
  --text-2: #a8a9b1;
  --text-3: #76777e;
  --line: #323438;
  --bubble: #2a2d31;
  --accent: #7b90ff;
  --accent-soft: rgba(123, 144, 255, 0.15);
  --shadow: 0 12px 48px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body { height: 100vh; height: 100dvh; overflow: hidden; }

.app { display: flex; height: 100vh; height: 100dvh; width: 100%; overflow: hidden; }

/* ============ 侧边栏 ============ */
.sidebar {
  flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w);
  height: 100%;
  background: var(--bg-side);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  transition: margin-left .24s cubic-bezier(.32,.72,.3,1), transform .24s cubic-bezier(.32,.72,.3,1);
  z-index: 45;
}

.sb-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 14px 12px 8px 20px; }
.brand { font-size: 17px; font-weight: 700; color: var(--accent); letter-spacing: -.01em; white-space: nowrap; }

.new-chat {
  margin: 8px 12px 10px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.new-chat:hover { border-color: var(--accent); color: var(--accent); }
.new-chat:active { transform: scale(.99); }

.sb-search { padding: 0 12px 6px; }
.sb-search input {
  width: 100%;
  border: 1px solid transparent;
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 12.5px;
  outline: none;
  font-family: inherit;
}
.sb-search input:focus { border-color: var(--line); background: var(--bg); }

.sb-list { flex: 1; overflow-y: auto; padding: 2px 8px 10px; }

.group-label {
  font-size: 11px;
  color: var(--text-3);
  padding: 12px 10px 6px;
  position: sticky;
  top: 0;
  background: var(--bg-side);
  z-index: 1;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 6px 8px 10px;
  border-radius: 9px;
  cursor: pointer;
  color: var(--text);
  border: 1px solid transparent;
}
.conv-item:hover { background: var(--bg-soft); }
.conv-item.active { background: var(--bg); border-color: var(--line); }
.conv-main { flex: 1; min-width: 0; }
.conv-name { font-size: 13.5px; line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 11px; color: var(--text-3); margin-top: 1px; }

.conv-del {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: var(--text-3);
  width: 26px;
  height: 26px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s, color .15s;
}
.conv-item:hover .conv-del { opacity: 1; }
@media (hover: none) { .conv-del { opacity: .5; } }
.conv-del:hover { color: var(--danger); background: var(--bg); }

.sb-empty { padding: 36px 14px; text-align: center; color: var(--text-3); font-size: 12.5px; line-height: 1.75; }
.sb-empty .ghost-btn { margin: 10px auto 0; }
.sb-empty-tip { margin-bottom: 10px; }

.sb-foot {
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
}
.repo-label {
  font-size: 11px;
  color: var(--text-3);
  padding: 4px 10px 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sb-item {
  width: 100%;
  height: 36px;
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 10px;
  border-radius: 8px;
  cursor: pointer;
}
.sb-item:hover { background: var(--bg-soft); color: var(--text); }

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

.main-head {
  flex: 0 0 auto;
  height: calc(52px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 10px 0;
  display: flex;
  align-items: center;
  gap: 4px;
}
.head-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 0 4px; }
#chatTitle {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.title-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
  padding: 3px 6px;
  margin-left: -6px;
  border-radius: 8px;
  cursor: pointer;
}
.title-btn:hover { background: var(--bg-soft); }
.title-btn:hover #chatTitle { color: var(--text); }
.title-btn[hidden] { display: none; }
.title-btn svg { flex: 0 0 auto; color: var(--text-3); opacity: 0; transition: opacity .15s; }
.title-btn:hover svg { opacity: 1; }
@media (hover: none) { .title-btn svg { opacity: .55; } }

.title-input {
  flex: 1;
  min-width: 0;
  max-width: 300px;
  border: 1px solid var(--accent);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  padding: 4px 9px;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.title-input[hidden] { display: none; }

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-2);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s, color .15s;
  flex: 0 0 auto;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--text); }
.icon-btn:active { transform: scale(.95); }

.save-state {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--text-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
  white-space: nowrap;
}
.save-state[data-s=""] { display: none; }
.save-state[data-s="saving"] { color: var(--accent); border-color: var(--accent-soft); }
.save-state[data-s="saved"] { color: #2fa36b; border-color: rgba(47,163,107,.3); }
.save-state[data-s="error"] { color: var(--danger); border-color: rgba(229,72,77,.35); }
.save-state[data-s="local"], .save-state[data-s="dirty"] { color: #c07f13; border-color: rgba(192,127,19,.3); }

/* ============ 对话 ============ */
.chat {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  padding: 8px 24px 4px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.msg {
  flex: 0 0 auto;
  width: 100%;
  max-width: var(--content-w);
  margin: 0 auto 24px;
  display: flex;
  animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  max-width: 82%;
  background: var(--bubble);
  padding: 10px 14px;
  border-radius: 18px 18px 6px 18px;
  font-size: 15px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user .bubble.files-only { padding: 6px 8px; }

.msg.assistant { flex-direction: column; align-items: stretch; }
.msg.assistant .bubble { font-size: 15px; line-height: 1.75; word-break: break-word; }

.msg-actions { display: flex; gap: 2px; margin-top: 2px; opacity: 0; transition: opacity .15s; }
.msg.assistant:hover .msg-actions, .msg.user:hover .msg-actions { opacity: 1; }
@media (hover: none) { .msg-actions { opacity: .6; } }
@media (max-width: 640px) { .msg.user { flex-direction: column; align-items: flex-end; } }

.act-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-3);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 7px;
  cursor: pointer;
}
.act-btn:hover { background: var(--bg-soft); color: var(--text); }

/* 思考过程 */
.think { border-left: 2px solid var(--line); padding-left: 12px; margin-bottom: 10px; color: var(--text-3); font-size: 13px; }
.think summary {
  cursor: pointer;
  list-style: none;
  color: var(--text-2);
  font-size: 12.5px;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}
.think summary::-webkit-details-marker { display: none; }
.think summary::before { content: "▸"; font-size: 10px; transition: transform .15s; }
.think[open] summary::before { transform: rotate(90deg); }
.think-body { margin-top: 6px; white-space: pre-wrap; line-height: 1.6; max-height: 280px; overflow-y: auto; }

/* 搜索来源 */
.sources {
  margin: 0 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-soft);
  padding: 8px 12px;
}
.sources summary {
  cursor: pointer;
  list-style: none;
  font-size: 12.5px;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}
.sources summary::-webkit-details-marker { display: none; }
.sources summary::before { content: "▸"; font-size: 10px; transition: transform .15s; }
.sources[open] summary::before { transform: rotate(90deg); }
.sources-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.source { display: flex; gap: 8px; align-items: baseline; font-size: 12.5px; color: var(--text-2); text-decoration: none; line-height: 1.5; }
.source:hover .stitle { color: var(--accent); text-decoration: underline; }
.source .idx {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transform: translateY(1px);
}
.source .stitle { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source .host { flex: 0 0 auto; color: var(--text-3); font-size: 11px; }

.searching { display: inline-flex; align-items: center; gap: 8px; color: var(--text-3); font-size: 13px; padding: 4px 0; }
.spinner {
  width: 13px;
  height: 13px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* markdown */
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: 0 0 .85em; }
.md h1, .md h2, .md h3, .md h4 { margin: 1.2em 0 .55em; line-height: 1.35; font-weight: 600; }
.md h1 { font-size: 1.35em; }
.md h2 { font-size: 1.2em; }
.md h3 { font-size: 1.08em; }
.md ul, .md ol { margin: 0 0 .85em; padding-left: 1.4em; }
.md li { margin: .25em 0; }
.md li > p { margin: 0; }
.md a { color: var(--accent); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md blockquote { margin: .8em 0; padding: .2em 0 .2em 12px; border-left: 3px solid var(--line); color: var(--text-2); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
.md img { max-width: 100%; border-radius: 10px; }
.md table { border-collapse: collapse; width: 100%; margin: .8em 0; font-size: 13.5px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.md th { background: var(--bg-soft); font-weight: 600; }
.md code {
  font-family: var(--mono);
  font-size: .9em;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  padding: .1em .35em;
  border-radius: 5px;
}
.md pre {
  position: relative;
  background: #0f1115;
  color: #e6e6e6;
  border-radius: 12px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: .8em 0;
  border: 1px solid rgba(255,255,255,.06);
}
.md pre code { background: transparent; border: 0; padding: 0; font-size: 13px; line-height: 1.6; color: inherit; }
.md .copy-code {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 11px;
  color: #b9bcc4;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 6px;
  padding: 3px 8px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s;
}
.md pre:hover .copy-code { opacity: 1; }
@media (hover: none) { .md .copy-code { opacity: .8; } }

.cursor {
  display: inline-block;
  width: 7px;
  height: 1.05em;
  background: var(--accent);
  vertical-align: -2px;
  margin-left: 2px;
  border-radius: 2px;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.typing { display: inline-flex; gap: 5px; padding: 6px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); animation: bounce 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .4; } 40% { transform: translateY(-4px); opacity: 1; } }

/* 空状态 */
.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  padding: 24px 0 56px;
  width: 100%;
}
.empty h1 { font-size: 26px; margin: 0; font-weight: 600; letter-spacing: -.01em; }
.empty p { color: var(--text-3); font-size: 13px; margin: 0; }

/* 配置引导 */
.setup-card {
  margin-top: 20px;
  width: 100%;
  max-width: 420px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  border-radius: 14px;
  padding: 12px 14px;
  text-align: left;
}
.setup-head { font-size: 12px; color: var(--text-2); margin-bottom: 8px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.setup-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-2); padding: 5px 0; }
.setup-row .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); flex: 0 0 auto; }
.setup-row .dot.on { background: #2fa36b; }
.setup-row b { color: var(--text); font-weight: 500; margin-right: auto; }
.setup-row .state { font-size: 11.5px; color: var(--text-3); }
.setup-card .mini-btn {
  appearance: none;
  border: 0;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
}

/* ============ 输入区 ============ */
.composer {
  flex: 0 0 auto;
  padding: 4px 24px calc(14px + env(safe-area-inset-bottom));
  background: var(--bg);
}
.composer-inner { max-width: var(--content-w); margin: 0 auto; }

.input-card {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--bg);
  padding: 10px 10px 8px 15px;
  box-shadow: 0 2px 12px rgba(15, 17, 21, 0.035);
  transition: border-color .15s, box-shadow .15s;
}
:root[data-theme="dark"] .input-card { box-shadow: none; background: var(--bg-soft); }
.input-card:focus-within { border-color: rgba(77,107,254,.5); box-shadow: 0 0 0 3px var(--accent-soft); }

#input {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15.5px;
  line-height: 1.6;
  resize: none;
  outline: none;
  max-height: 200px;
  padding: 5px 5px 8px 0;
}
#input::placeholder { color: var(--text-3); }

.card-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.toggles { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }

.toggle {
  appearance: none;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text-2);
  font-size: 12.5px;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
}
.toggle:hover { color: var(--text); border-color: var(--text-3); }
.toggle.active { color: var(--accent); border-color: rgba(77,107,254,.45); background: var(--accent-soft); }
:root[data-theme="dark"] .toggle { background: transparent; }
:root[data-theme="dark"] .toggle.active { background: var(--accent-soft); }

.model-select {
  appearance: none;
  height: 32px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text-2);
  font-size: 12.5px;
  font-family: inherit;
  padding: 0 24px 0 10px;
  border-radius: 999px;
  cursor: pointer;
  max-width: 150px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 12px) 52%, calc(100% - 8px) 52%;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
}
:root[data-theme="dark"] .model-select { background-color: transparent; }

/* 附件 */
.tool-btn {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all .15s;
}
.tool-btn:hover { color: var(--text); border-color: var(--text-3); }
.tool-btn:active { transform: scale(.94); }
:root[data-theme="dark"] .tool-btn { background: transparent; }

.attach-strip { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 0 6px; }
.attach-strip[hidden] { display: none !important; }
.attach-chip {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 240px;
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-soft);
  overflow: hidden;
}
.attach-chip.error { border-color: rgba(229, 72, 77, .45); }
.ac-thumb {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text-2);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.ac-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ac-info { display: flex; flex-direction: column; min-width: 0; max-width: 160px; line-height: 1.3; }
.ac-name {
  font-size: 12.5px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ac-state {
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attach-chip.error .ac-state { color: var(--danger); }
.ac-del {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-3);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.ac-del:hover { background: var(--bg); color: var(--text); }
.ac-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; display: none; background: var(--accent-soft); }
.ac-bar.show { display: block; }
.ac-bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.ac-bar i.indeterminate { width: 40% !important; animation: acSlide 1.1s infinite ease-in-out; }
@keyframes acSlide { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }

.attach-strip.in-msg { justify-content: flex-end; padding: 0; margin-top: 6px; gap: 5px; }
.in-msg .attach-chip { max-width: 220px; padding: 4px 6px; background: var(--bg); }
.in-msg .ac-thumb { width: 26px; height: 26px; border-radius: 6px; }

.send-btn {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
}
.send-btn:disabled { opacity: .28; cursor: default; }
.send-btn:active:not(:disabled) { transform: scale(.93); }
.send-btn .ic-stop { display: none; }
.send-btn.streaming .ic-send { display: none; }
.send-btn.streaming .ic-stop { display: block; }

.composer-hint { text-align: center; font-size: 11px; color: var(--text-3); padding-top: 7px; }

/* ============ 遮罩 ============ */
.scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.42);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s;
  z-index: 40;
}
@media (max-width: 860px) {
  .scrim { display: block; }
  .scrim.show { opacity: 1; pointer-events: auto; }
}

/* ============ 响应式 ============ */
.only-mobile { display: none; }
.sb-expand { display: none; }

@media (min-width: 861px) {
  .only-mobile { display: none !important; }
  .app.collapsed .sidebar { margin-left: calc(-1 * var(--sidebar-w)); }
  .app.collapsed .sb-expand { display: inline-flex; }
  .main-head { padding-left: 20px; }
}

@media (max-width: 860px) {
  .only-mobile { display: inline-flex; }
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    transform: translateX(-102%);
    box-shadow: 12px 0 40px rgba(0,0,0,.18);
  }
  .sidebar.show { transform: none; }
  .sb-collapse { display: none; }
  .main-head { padding-left: 8px; }
  .chat { padding: 6px 16px 2px; }
  .composer { padding: 4px 12px calc(10px + env(safe-area-inset-bottom)); }
  .empty { padding-bottom: 40px; }
  .empty h1 { font-size: 22px; }
  .msg { margin-bottom: 20px; }
}

@media (max-width: 420px) {
  .toggles { gap: 5px; }
  .toggle { padding: 0 10px; font-size: 12px; }
  .model-select { max-width: 126px; }
  .attach-chip { max-width: 190px; }
  .ac-info { max-width: 112px; }
  .in-msg .attach-chip { max-width: 180px; }
}

/* ============ 设置弹窗 ============ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.modal.show { opacity: 1; pointer-events: auto; }
.modal-card {
  width: min(560px, 100%);
  max-height: 92dvh;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transform: translateY(16px);
  transition: transform .24s cubic-bezier(.32,.72,.3,1);
}
.modal.show .modal-card { transform: none; }
@media (min-width: 700px) {
  .modal { align-items: center; }
  .modal-card { border-radius: 20px; }
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 12px 10px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 16px; margin: 0; font-weight: 600; }
.modal-sub { margin: 3px 0 0; font-size: 11.5px; color: var(--text-3); }
.modal-body { overflow-y: auto; padding: 16px 20px 4px; }
.form-section { margin-bottom: 22px; }
.form-section h3 { font-size: 12px; letter-spacing: .02em; color: var(--text-3); margin: 0 0 12px; }
.section-note { font-size: 12px; color: var(--text-3); line-height: 1.6; margin: -4px 0 12px; }

.usage-card {
  border: 1px solid var(--line);
  background: var(--bg-soft);
  border-radius: 12px;
  padding: 12px 14px;
}
.usage-head { display: flex; align-items: center; justify-content: space-between; font-size: 12.5px; color: var(--text-2); }
.usage-head b { font-size: 13px; font-weight: 600; color: var(--text); }
.usage-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line);
  overflow: hidden;
  margin: 9px 0 8px;
}
.usage-bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .3s; }
.usage-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 11.5px; color: var(--text-3); }
.usage-meta b { color: var(--text-2); font-weight: 500; }
.usage-tip { margin: 8px 0 0; font-size: 11.5px; line-height: 1.6; color: var(--text-3); }
.usage-card.warn .usage-head b { color: #c07f13; }
.usage-card.warn .usage-bar i { background: #c07f13; }
.usage-card.warn .usage-tip { color: var(--text-2); }
.usage-card.full .usage-head b { color: var(--danger); }
.usage-card.full .usage-bar i { background: var(--danger); }
.usage-card.full .usage-tip { color: var(--text-2); }
.usage-refresh { margin-top: 10px; padding: 7px 14px; font-size: 12.5px; }
.field { display: block; margin-bottom: 12px; flex: 1; min-width: 0; }
.field > span { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; }
.field input, .field select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
}
.field input:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field-row { display: flex; gap: 10px; }
@media (max-width: 480px) { .field-row { flex-direction: column; gap: 0; } }

.modal-foot { flex: 0 0 auto; padding: 12px 20px calc(16px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg); }
.modal-foot .footnote { margin: 0 0 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.ghost-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text-2);
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.ghost-btn:hover { color: var(--text); border-color: var(--text-3); }
.danger-btn {
  appearance: none;
  border: 0;
  background: var(--danger);
  color: #fff;
  border-radius: 10px;
  padding: 9px 18px;
  font-size: 13.5px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
}
.danger-btn:hover { background: #d13c41; }
.danger-btn:active { transform: scale(.98); }

/* 二次确认 */
.modal.confirm { align-items: center; z-index: 70; }
.confirm-card { width: min(400px, calc(100% - 36px)); border-radius: 18px; overflow: hidden; }
.confirm-body { padding: 20px 20px 6px; }
.confirm-body h2 { font-size: 16px; margin: 0 0 8px; font-weight: 600; }
.confirm-body p { margin: 0; font-size: 13px; line-height: 1.7; color: var(--text-2); word-break: break-word; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px 18px; }
@media (max-width: 420px) {
  .confirm-card { width: calc(100% - 28px); border-radius: 16px; }
  .confirm-body { padding: 18px 18px 4px; }
  .confirm-actions { padding: 14px 18px 16px; }
}
.primary-btn {
  appearance: none;
  border: 0;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  padding: 9px 22px;
  font-size: 13.5px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
}
.footnote { font-size: 11.5px; color: var(--text-3); line-height: 1.65; margin: 14px 0 0; }

/* ============ toast ============ */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(110px + env(safe-area-inset-bottom));
  transform: translate(-50%, 10px);
  background: rgba(30,30,34,.94);
  color: #fff;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 10px;
  max-width: 82vw;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 80;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.sources-host:empty { display: none; }
.search-note { font-size: 12px; color: var(--text-3); margin: 0 0 10px; }

@media (max-width: 440px) {
  .toggle { padding: 0 9px; font-size: 11.5px; gap: 5px; }
  .toggle svg { width: 13px; height: 13px; }
  .model-select { max-width: 112px; font-size: 11.5px; padding: 0 20px 0 9px; background-position: calc(100% - 10px) 52%, calc(100% - 6px) 52%; }
  .card-row { gap: 6px; }
}

@media (max-width: 440px) {
  .model-select { max-width: 92px; }
}
.toast { bottom: calc(168px + env(safe-area-inset-bottom)); }

/* 思考强度 */
.effort-wrap { position: relative; display: inline-flex; align-items: center; }
.effort-chip {
  appearance: none;
  height: 26px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--text-3);
  font-family: inherit;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.effort-chip:hover { color: var(--text); border-color: var(--text-3); }
.effort-chip[hidden] { display: none; }
.effort-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  min-width: 94px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(15, 17, 21, .16);
  padding: 4px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.effort-menu[hidden] { display: none; }
.effort-menu button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  text-align: left;
  padding: 7px 10px;
  border-radius: 7px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.effort-menu button:hover { background: var(--bg-soft); }
.effort-menu button.active { color: var(--accent); font-weight: 600; }
.effort-menu button.active::after { content: "✓"; font-size: 11px; margin-left: 12px; }
