/* ===================== 布局 ===================== */
.app {
  display: grid;
  grid-template-columns: var(--sider-w) minmax(0, 1fr);
  /* 显式约束行高：否则隐式行是 auto，会被内容撑高，
     .main 的 height:100% 就失去意义，内部再怎么写 overflow 也滚不动 */
  grid-template-rows: minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  transition: grid-template-columns var(--t);
}
.app.sider-collapsed { grid-template-columns: 0 minmax(0, 1fr); }
.app.sider-collapsed .sider { opacity: 0; pointer-events: none; }

/* ===================== 侧边栏 ===================== */
.sider {
  background: var(--sider-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  transition: opacity var(--t);
}
.sider-top {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 12px 12px 8px;
}
.btn-new {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  border-radius: var(--radius);
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  box-shadow: var(--shadow-sm);
  transition: background var(--t-fast), transform var(--t-fast);
  white-space: nowrap;
}
.btn-new:hover { background: var(--brand-strong); }
.btn-new:active { transform: scale(0.985); }

.session-list {
  flex: 1 1 0%;
  min-height: 0; /* 同上：否则会话一多会把底部「设置」挤出可视区 */
  overflow-y: auto;
  padding: 4px 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.session-group-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-mute);
  padding: 12px 8px 4px;
  letter-spacing: 0.02em;
}
.session-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 13.5px;
  width: 100%;
  text-align: left;
  transition: background var(--t-fast), color var(--t-fast);
  position: relative;
}
.session-item:hover { background: var(--bg-hover); color: var(--text); }
.session-item.active { background: var(--bg-active); color: var(--text); font-weight: 500; }
.session-item .s-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-item .s-actions {
  display: none;
  gap: 2px;
  flex-shrink: 0;
}
.session-item:hover .s-actions,
.session-item.active .s-actions { display: flex; }
.s-mini {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: var(--text-mute);
}
.s-mini:hover { background: var(--bg-active); color: var(--text); }
.s-mini.danger:hover { color: var(--danger); }
.session-empty {
  color: var(--text-mute);
  font-size: 13px;
  padding: 16px 10px;
  text-align: center;
}

.sider-bottom {
  border-top: 1px solid var(--border);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.sider-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text-dim);
  text-align: left;
  transition: background var(--t-fast), color var(--t-fast);
}
.sider-item:hover { background: var(--bg-hover); color: var(--text); }
.sider-scrim { display: none; }

/* ===================== 主区 ===================== */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  /* 作为 grid 子项，默认 min-height:auto 会被内容撑高，
     必须显式归零，内部的 .scroll 才能拿到受限高度并真正滚动 */
  min-height: 0;
  height: 100%;
  background: var(--bg);
}
.topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border-bottom: 1px solid transparent;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  position: relative;
  z-index: 5;
}
.topbar-title {
  flex: 1;
  font-size: 14.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-right { display: flex; align-items: center; gap: 8px; }
.model-badge {
  font-size: 11.5px;
  font-family: var(--mono);
  color: var(--text-mute);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 2px 9px;
  white-space: nowrap;
}
.only-mobile { display: none !important; }
/* 侧边栏开关：折叠后必须在顶栏留一个入口，否则收进去就再也点不出来 */
#expandBtn { display: none; }
.app.sider-collapsed #expandBtn { display: grid; }

.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  transition: background var(--t-fast), color var(--t-fast);
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

/* 自定义聊天背景：半透明遮罩 + 图片叠成两层背景，
   文字在遮罩之上，图片固定在容器上（不随内容滚动） */
.app.has-bg .scroll {
  background-image: linear-gradient(var(--bg-veil), var(--bg-veil)), var(--chat-bg);
  /* 填充方式由 --bg-fit 控制：cover / contain / 100% 100% */
  background-size: var(--bg-fit, cover), var(--bg-fit, cover);
  background-position: center center, center center;
  background-repeat: no-repeat, no-repeat;
  background-attachment: scroll, scroll;
}
.app.has-bg .msg-user .bubble {
  box-shadow: var(--shadow-sm);
}

/* 覆盖范围：整个窗口（含侧栏、顶栏、输入区） */
.app.has-bg.bg-full {
  background-image: linear-gradient(var(--bg-veil), var(--bg-veil)), var(--chat-bg);
  background-size: var(--bg-fit, cover), var(--bg-fit, cover);
  background-position: center center, center center;
  background-repeat: no-repeat, no-repeat;
}
.app.has-bg.bg-full .scroll { background-image: none; }
.app.bg-full .main { background: transparent; }
.app.bg-full .topbar { background: transparent; backdrop-filter: none; }
.app.bg-full .sider {
  background: color-mix(in srgb, var(--sider-bg) 76%, transparent);
  backdrop-filter: blur(12px);
}
.app.bg-full .composer {
  background: color-mix(in srgb, var(--bg-elev) 86%, transparent);
  backdrop-filter: blur(12px);
}

/* 文字底板模式：正文/气泡各自带毛玻璃底框，遮罩可以调很低 */
.app.bg-panel .answer {
  background: color-mix(in srgb, var(--bg) 74%, transparent);
  backdrop-filter: blur(8px);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  box-shadow: var(--shadow-sm);
}
.app.bg-panel .msg-user .bubble {
  background: color-mix(in srgb, var(--user-bubble) 82%, transparent);
  backdrop-filter: blur(8px);
}

.scroll {
  /* flex-basis 必须是 0 且 min-height 必须归零：
     flex 子项默认 min-height:auto，会先被内容撑满，overflow-y:auto 就永远不触发，
     表现为"鼠标滚轮完全没反应"（内容被 body 的 overflow:hidden 裁掉）。 */
  flex: 1 1 0%;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  /* 滚动条出现/消失时预留空间，避免流式输出时内容左右抖动 */
  scrollbar-gutter: stable;
  /* 注意：不要写 scroll-behavior: smooth。自动滚到底由 JS 按需传 behavior，
     常驻 smooth 会与用户滚轮抢控制权，也会让流式跟随变得迟滞。 */
}
.messages {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 8px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

/* ===================== 欢迎页 ===================== */
.welcome {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(28px, 9vh, 96px) 20px 0;
  text-align: center;
}
.welcome.hidden { display: none; }
.welcome-logo { color: var(--brand); display: flex; justify-content: center; margin-bottom: 18px; }
.welcome h2 {
  font-size: clamp(19px, 2.6vw, 25px);
  font-weight: 650;
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}
.welcome-sub { color: var(--text-mute); font-size: 13.5px; margin: 0 auto 26px; max-width: 520px; }
.suggestions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
  text-align: left;
}
.suggestion {
  border: 1px solid var(--border);
  background: var(--bg-soft);
  border-radius: var(--radius);
  padding: 11px 13px;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
  transition: border-color var(--t-fast), background var(--t-fast), transform var(--t-fast);
}
.suggestion:hover {
  border-color: var(--brand-weak-2);
  background: var(--brand-weak);
  color: var(--text);
  transform: translateY(-1px);
}

/* ===================== 消息 ===================== */
.msg { display: flex; flex-direction: column; animation: fade-in 240ms ease both; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.msg-user { align-items: flex-end; gap: 6px; }
.bubble {
  max-width: min(100%, 620px);
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  border-radius: var(--radius-lg);
  border-bottom-right-radius: 6px;
  padding: 10px 15px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: var(--chat-fs);
  font-family: var(--read-font);
}
.msg-user .attachments-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  max-width: min(100%, 620px);
}
.thumb {
  width: 88px;
  height: 88px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  cursor: zoom-in;
}
.file-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  border-radius: 9px;
  padding: 6px 11px;
  font-size: 12.5px;
  color: var(--text-dim);
  max-width: 260px;
}
.file-pill .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-pill .sz { color: var(--text-mute); font-size: 11px; flex-shrink: 0; }

.msg-assistant { align-items: stretch; gap: 10px; }
.answer {
  font-size: var(--chat-fs);
  font-family: var(--read-font);
  line-height: 1.72;
  min-width: 0;
  word-break: break-word;
}
.answer > *:first-child { margin-top: 0; }
.answer > *:last-child { margin-bottom: 0; }

.msg-tools {
  display: flex;
  gap: 4px;
  align-items: center;
  min-height: 26px;
  flex-wrap: wrap;
}
.mini-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-mute);
  padding: 4px 8px;
  border-radius: 7px;
  transition: background var(--t-fast), color var(--t-fast);
}
.mini-btn:hover { background: var(--bg-hover); color: var(--text); }
.mini-btn.danger:hover { color: var(--danger); }
.mini-btn.is-disabled { opacity: .45; cursor: not-allowed; }
.mini-btn.is-disabled:hover { background: none; color: var(--text-mute); }
.mini-btn.active { background: var(--brand-weak); color: var(--brand-strong); }

/* 思考块 */
.think {
  border-left: 2px solid var(--border-strong);
  padding-left: 12px;
  margin: 0 0 12px;
}
.think-head {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.8px;
  color: var(--text-mute);
  padding: 3px 0;
  user-select: none;
}
.think-head:hover { color: var(--text-dim); }
.think-head .spin {
  width: 12px;
  height: 12px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.think-body {
  font-size: 13.5px;
  color: var(--text-mute);
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 4px 0 0;
  max-height: 420px;
  overflow-y: auto;
}
.think.collapsed .think-body { display: none; }

/* 搜索 / 阅读卡片 */
.tool-card {
  border: 1px solid var(--border);
  background: var(--bg-soft);
  border-radius: var(--radius);
  margin: 0 0 12px;
  overflow: hidden;
  font-size: 13px;
}
.tool-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  color: var(--text-dim);
  width: 100%;
  text-align: left;
}
.tool-card-head:hover { background: var(--bg-hover); }
.tool-card-head .ttl { font-weight: 550; }
.tool-card-head .meta { color: var(--text-mute); font-size: 12px; }
.tool-card-head .caret { margin-left: auto; color: var(--text-mute); transition: transform var(--t-fast); }
.tool-card.open .caret { transform: rotate(180deg); }
.tool-card-body { display: none; border-top: 1px solid var(--border); padding: 6px; }
.tool-card.open .tool-card-body { display: block; }

.step {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 8px;
  font-size: 12.5px;
  color: var(--text-mute);
}
.step .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--brand); flex-shrink: 0; }
.step code { font-family: var(--mono); font-size: 11.5px; }

.src-item {
  display: block;
  padding: 8px 10px;
  border-radius: 9px;
  transition: background var(--t-fast);
}
.src-item:hover { background: var(--bg-hover); }
.src-item .src-title { font-size: 13px; color: var(--text); line-height: 1.45; }
.src-item .src-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-mute);
  margin-top: 2px;
}
.src-item .src-meta img { width: 13px; height: 13px; border-radius: 3px; }
.src-item .src-snippet {
  font-size: 12.2px;
  color: var(--text-mute);
  margin-top: 3px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* 引用角标 */
.cite-ref {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  margin: 0 1px;
  border-radius: 4px;
  background: var(--brand-weak-2);
  color: var(--brand-strong);
  font-size: 10px;
  font-weight: 600;
  vertical-align: super;
  line-height: 1;
  cursor: pointer;
  transition: background var(--t-fast);
}
.cite-ref:hover { background: var(--brand); color: #fff; }
.cite-strip {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}
.cite-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  border-radius: 99px;
  padding: 4px 11px 4px 7px;
  font-size: 11.8px;
  color: var(--text-dim);
  transition: border-color var(--t-fast), background var(--t-fast);
}
.cite-chip:hover { border-color: var(--brand-weak-2); background: var(--brand-weak); color: var(--text); }
.cite-chip .n {
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--brand-weak-2); color: var(--brand-strong);
  display: grid; place-items: center; font-size: 9.5px; font-weight: 700;
}
.cite-chip .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 190px; }

/* 拒答 / 错误 */
.notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13.5px;
  line-height: 1.6;
}
.notice-refusal { background: rgba(217, 119, 6, 0.1); color: var(--warn); border: 1px solid rgba(217, 119, 6, 0.25); }
.notice-error { background: rgba(220, 38, 38, 0.09); color: var(--danger); border: 1px solid rgba(220, 38, 38, 0.22); }
.notice b { font-weight: 650; }

.usage {
  font-size: 11.5px;
  color: var(--text-mute);
  font-family: var(--mono);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
}

/* ===================== 输入区 ===================== */
.composer-wrap {
  flex: 0 0 auto;
  /* 底部安全区：全面屏/手势条不会挡住输入框 */
  padding: 0 20px max(14px, env(safe-area-inset-bottom));
  max-width: calc(var(--maxw) + 40px);
  margin: 0 auto;
  width: 100%;
}
.attachments {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 0 0 9px;
}
.att-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  border-radius: 10px;
  padding: 5px 26px 5px 6px;
  font-size: 12.5px;
  max-width: 230px;
}
.att-item img.preview { width: 30px; height: 30px; border-radius: 6px; object-fit: cover; }
.att-item .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-item .sz { color: var(--text-mute); font-size: 11px; }
.att-item .rm {
  position: absolute; right: 3px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; border-radius: 5px; display: grid; place-items: center;
  color: var(--text-mute); font-size: 12px;
}
.att-item .rm:hover { background: var(--bg-active); color: var(--danger); }
.att-item.uploading { opacity: 0.65; }
.att-item.error { border-color: var(--danger); }

.composer {
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  border-radius: var(--radius-xl);
  padding: 9px 10px 8px 14px;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.composer:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-weak); }
.composer.drag { border-color: var(--brand); background: var(--brand-weak); }
.composer textarea {
  width: 100%;
  border: 0;
  background: none;
  resize: none;
  outline: none;
  max-height: 220px;
  min-height: 24px;
  padding: 2px 0 6px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
}
.composer textarea::placeholder { color: var(--text-mute); }
.composer-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 10px;
  border-radius: 99px;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12.5px;
  transition: all var(--t-fast);
  white-space: nowrap;
}
.chip:hover { background: var(--bg-hover); color: var(--text); }
.chip[data-on="true"] {
  border-color: transparent;
  background: var(--brand-weak-2);
  color: var(--brand-strong);
  font-weight: 550;
}
.send-area { display: flex; align-items: center; gap: 4px; }
.btn-send {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  transition: background var(--t-fast), transform var(--t-fast), opacity var(--t-fast);
}
.btn-send:hover { background: var(--brand-strong); }
.btn-send:disabled { background: var(--border-strong); color: var(--text-mute); opacity: 1; cursor: not-allowed; }
.btn-send.stop { background: var(--text-dim); }
.icon-btn.mic.recording { color: var(--danger); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }
.composer-hint {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-mute);
  padding-top: 7px;
  min-height: 16px;
}

/* ===================== 弹窗 ===================== */
.dlg {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: min(560px, 92vw);
  width: 100%;
  color: var(--text);
}
.dlg.dlg-wide { max-width: min(760px, 94vw); }
.dlg::backdrop { background: var(--scrim); backdrop-filter: blur(2px); }
.dlg[open] { animation: dlg-in 180ms cubic-bezier(0.2, 0, 0.2, 1); }
@keyframes dlg-in { from { opacity: 0; transform: translateY(8px) scale(0.99); } }
.dlg-inner {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: min(86vh, 820px);
}
.dlg-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 14px 13px 18px;
  border-bottom: 1px solid var(--border);
}
.dlg-head h3 { margin: 0; font-size: 15px; font-weight: 650; }
.dlg-body { padding: 16px 18px 20px; overflow-y: auto; min-height: 0; }

.field-group { margin-bottom: 20px; }
.field-group h4 {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 650;
  color: var(--text-mute);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 5px; }
.field input[type="text"],
.field input[type="password"],
.field input[type="number"],
.field select {
  width: 100%;
  height: 36px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  padding: 0 10px;
  font-size: 13.5px;
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.field input:focus, .field select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-weak); }
.field small { display: block; color: var(--text-mute); font-size: 11.5px; margin-top: 5px; line-height: 1.5; }
.field-row { display: flex; gap: 8px; }
.field-row input { flex: 1; }

.switch { display: flex; align-items: center; gap: 9px; padding: 6px 0; font-size: 13.5px; color: var(--text-dim); cursor: pointer; }
.switch input {
  appearance: none;
  width: 36px; height: 20px;
  border-radius: 99px;
  background: var(--border-strong);
  position: relative;
  transition: background var(--t-fast);
  flex-shrink: 0;
  cursor: pointer;
}
.switch input::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform var(--t-fast);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
.switch input:checked { background: var(--brand); }
.switch input:checked::after { transform: translateX(16px); }
.switch-hint { display: block; margin: -2px 0 10px 45px; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-ghost {
  height: 34px;
  padding: 0 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  font-size: 13px;
  color: var(--text-dim);
  transition: all var(--t-fast);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-ghost.danger:hover { border-color: var(--danger); color: var(--danger); background: rgba(220, 38, 38, 0.06); }
.btn-primary {
  height: 36px;
  padding: 0 18px;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  transition: background var(--t-fast);
}
.btn-primary:hover { background: var(--brand-strong); }
.muted { color: var(--text-mute); font-size: 12.5px; line-height: 1.6; }
.save-hint { font-size: 12px; color: var(--ok); margin: 0; min-height: 16px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tab {
  padding: 7px 13px;
  font-size: 13px;
  color: var(--text-mute);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.active { color: var(--brand-strong); border-bottom-color: var(--brand); font-weight: 600; }
.tool-pane { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.tool-out {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-family: var(--mono);
  font-size: 11.8px;
  line-height: 1.6;
  max-height: 300px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  color: var(--text-dim);
}

/* 来源面板 */
.src-row {
  display: flex;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}
.src-row:last-child { border-bottom: 0; }
.src-row .idx {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--brand-weak-2); color: var(--brand-strong);
  font-size: 10.5px; font-weight: 700;
  display: grid; place-items: center; flex-shrink: 0; margin-top: 2px;
}
.src-row .body { min-width: 0; }
.src-row .t { font-size: 13.5px; font-weight: 550; margin-bottom: 2px; }
.src-row .u { font-size: 11.5px; color: var(--text-mute); word-break: break-all; }
.src-row .sn { font-size: 12.5px; color: var(--text-dim); margin-top: 4px; line-height: 1.55; }

/* Toast */
.toast-stack {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 999;
  pointer-events: none;
  align-items: center;
}
.toast {
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 99px;
  box-shadow: var(--shadow);
  animation: toast-in 200ms ease both;
  max-width: 80vw;
}
.toast.err { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* 拖拽遮罩 */
.drag-mask {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 900;
  font-size: 16px;
  font-weight: 600;
  color: var(--brand);
  border: 3px dashed var(--brand);
  pointer-events: none;
}
.drag-mask-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px 34px;
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  box-shadow: var(--shadow);
}
.drag-mask-title { font-size: 16px; }
.drag-mask-sub { font-size: 12.5px; font-weight: 500; color: var(--text-mute); }

/* 图片查看 */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: grid;
  place-items: center;
  z-index: 1000;
  cursor: zoom-out;
}
.lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 8px; }

/* ===================== 响应式 ===================== */
@media (max-width: 860px) {
  .app { grid-template-columns: 0 minmax(0, 1fr); }
  .sider {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: 82vw;
    max-width: 300px;
    z-index: 60;
    transform: translateX(-102%);
    transition: transform var(--t);
    box-shadow: var(--shadow-lg);
    opacity: 1 !important;
  }
  .app.sider-open .sider { transform: none; pointer-events: auto; }
  .app.sider-open .sider-scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: var(--scrim);
    z-index: 50;
  }
  .app.sider-collapsed .sider { opacity: 1 !important; pointer-events: none; }
  .only-mobile { display: grid !important; }
  /* 移动端：侧边栏是浮层，汉堡按钮常显 */
  #expandBtn { display: grid; }
  #collapseBtn { display: none; }
  .messages { padding: 6px 14px 32px; gap: 22px; }
  .composer-wrap { padding: 0 12px max(10px, env(safe-area-inset-bottom)); }
  /* 独立窗口（PWA）时顶部也要避开状态栏/刘海 */
  .topbar { padding-top: env(safe-area-inset-top); height: calc(var(--topbar-h) + env(safe-area-inset-top)); }
  /* 16px 起跳，避免部分移动端浏览器聚焦输入框时整页放大 */
  .composer textarea { font-size: 16px; }
  .model-badge { display: none; }
  .bubble { font-size: 14.5px; }
  .suggestions { grid-template-columns: 1fr; }
  .cite-chip .t { max-width: 120px; }
}
