/* ============================================================
   强度研究院 · AI 助手 — 样式
   设计基调：浅色底 + 近黑文字，克制的中性灰 + 墨绿强调色
   ============================================================ */

/* ---------- 变量 ---------- */
:root {
  --bg: #ffffff;
  --bg-subtle: #f7f7f6;
  --bg-sidebar: #f8f8f7;
  --bg-hover: rgba(17, 17, 17, 0.045);
  --bg-active: rgba(17, 17, 17, 0.075);
  --border: #e9e9e6;
  --border-strong: #dcdcd8;
  --text: #17171a;
  --text-2: #65656d;
  --text-3: #9b9ba3;
  --accent: #1f6f5c;
  --accent-hover: #185a4a;
  --accent-contrast: #ffffff;
  --accent-soft: #e8f2ee;
  --user-bubble: #f2f2f0;
  --code-bg: #f6f6f4;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --shadow-sm: 0 1px 2px rgba(17, 17, 17, 0.05);
  --shadow-md: 0 4px 16px rgba(17, 17, 17, 0.07);
  --shadow-lg: 0 24px 64px rgba(17, 17, 17, 0.18);
  --radius: 14px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas,
               "Liberation Mono", "Courier New", monospace;
  --fs-base: 15px;
  --sidebar-w: 264px;
  --chat-max: 764px;
  --ease: cubic-bezier(0.2, 0.8, 0.3, 1);
}

[data-theme="dark"] {
  --bg: #17181a;
  --bg-subtle: #1c1d20;
  --bg-sidebar: #121315;
  --bg-hover: rgba(255, 255, 255, 0.055);
  --bg-active: rgba(255, 255, 255, 0.09);
  --border: #2a2b2f;
  --border-strong: #3a3b40;
  --text: #ececee;
  --text-2: #a2a2ab;
  --text-3: #6f6f79;
  --accent: #4fbd99;
  --accent-hover: #62cba8;
  --accent-contrast: #0d1a16;
  --accent-soft: rgba(79, 189, 153, 0.13);
  --user-bubble: #24262a;
  --code-bg: #1f2124;
  --danger: #f27d72;
  --danger-soft: rgba(242, 125, 114, 0.14);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 18px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.55);
}

html[data-font="sm"] { --fs-base: 14px; }
html[data-font="md"] { --fs-base: 15px; }
html[data-font="lg"] { --fs-base: 16.5px; }

/* ---------- 基础 ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

/* 关键：组件用 display:grid 会覆盖浏览器默认的 [hidden]{display:none} */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  transition: background-color 0.25s ease, color 0.25s ease;
}

button, input, textarea {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:disabled { cursor: not-allowed; opacity: 0.5; }

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

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* 滚动条 */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: content-box; }

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

/* ---------- 布局 ---------- */
.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ---------- 侧栏 ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  transition: background-color 0.25s ease, border-color 0.25s ease, transform 0.26s var(--ease);
}

.sidebar-head {
  padding: 18px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 4px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-contrast);
  display: grid;
  place-items: center;
  flex: none;
}

.brand-mark svg { width: 24px; height: 24px; }

.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong { font-size: 14.5px; font-weight: 650; letter-spacing: 0.01em; }
.brand-text span { font-size: 11.5px; color: var(--text-3); letter-spacing: 0.06em; }

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 550;
  box-shadow: var(--shadow-sm);
  transition: background 0.16s, border-color 0.16s, transform 0.12s var(--ease);
}

.new-chat-btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.new-chat-btn:active { transform: scale(0.985); }
.new-chat-btn .icon { width: 16px; height: 16px; color: var(--text-2); }

.session-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 6px 10px 10px;
  scrollbar-gutter: stable;
}

.session-group-label {
  padding: 14px 8px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-3);
  text-transform: uppercase;
}

.session-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 9px;
  margin-bottom: 2px;
  border-radius: 9px;
  cursor: pointer;
  color: var(--text-2);
  transition: background 0.14s, color 0.14s;
  animation: itemIn 0.22s var(--ease) both;
}

.session-item:hover { background: var(--bg-hover); color: var(--text); }
.session-item.active { background: var(--bg-active); color: var(--text); }
.session-item .icon { width: 15px; height: 15px; opacity: 0.75; }

.session-title {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-rename-input {
  flex: 1;
  min-width: 0;
  padding: 2px 6px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  outline: none;
}

.session-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.14s;
}

.session-item:hover .session-actions,
.session-item:focus-within .session-actions { opacity: 1; }

.mini-btn {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  color: var(--text-3);
  transition: background 0.14s, color 0.14s;
}

.mini-btn:hover { background: var(--bg-hover); color: var(--text); }
.mini-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.mini-btn .icon { width: 14px; height: 14px; }

.sidebar-empty {
  padding: 26px 12px;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-3);
  line-height: 1.8;
}

.sidebar-foot {
  padding: 10px 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.foot-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-2);
  transition: background 0.14s, color 0.14s;
}

.foot-btn:hover { background: var(--bg-hover); color: var(--text); }
.foot-btn .icon { width: 16px; height: 16px; }

.foot-version { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }

/* ---------- 主区 ---------- */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  transition: background-color 0.25s ease;
}

.topbar {
  flex: none;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  border-bottom: 1px solid transparent;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  position: relative;
  z-index: 5;
  transition: border-color 0.2s ease;
}

.topbar.scrolled { border-bottom-color: var(--border); }

.topbar-title {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 550;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right { display: flex; align-items: center; gap: 8px; }

.model-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-2);
  white-space: nowrap;
}

.model-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  color: var(--text-2);
  transition: background 0.14s, color 0.14s;
}

.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.menu-btn { display: none; }

/* ---------- 聊天滚动区 ---------- */
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
}

.chat-inner {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--chat-max);
  margin: 0 auto;
  padding: 18px 24px 36px;
}

.scroll-bottom-btn {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  color: var(--text-2);
  display: grid;
  place-items: center;
  animation: popIn 0.18s var(--ease);
  z-index: 6;
}

.scroll-bottom-btn:hover { color: var(--text); background: var(--bg-hover); }
.scroll-bottom-btn .icon { width: 17px; height: 17px; }

/* ---------- 空状态 ---------- */
.empty-state {
  margin: auto 0;
  padding: 24px 0 40px;
  text-align: center;
  animation: fadeUp 0.4s var(--ease) both;
}

.empty-mark {
  width: 60px;
  height: 60px;
  margin: 0 auto 20px;
  border-radius: 18px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
}

.empty-mark svg { width: 38px; height: 38px; }

.empty-state h1 {
  margin: 0 0 8px;
  font-size: clamp(20px, 2.6vw, 26px);
  font-weight: 620;
  letter-spacing: -0.01em;
}

.empty-sub {
  margin: 0 auto;
  max-width: 460px;
  color: var(--text-2);
  font-size: 14px;
  line-height: 1.7;
}

.suggestions {
  margin: 30px auto 0;
  max-width: 560px;
  display: grid;
  gap: 8px;
}

.suggestion {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  text-align: left;
  color: var(--text);
  transition: border-color 0.16s, background 0.16s, transform 0.16s var(--ease), box-shadow 0.16s;
}

.suggestion:hover {
  border-color: var(--border-strong);
  background: var(--bg-subtle);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.suggestion:active { transform: translateY(0) scale(0.995); }

.suggestion-tag {
  flex: none;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.suggestion-text {
  font-size: 13.5px;
  color: var(--text-2);
  line-height: 1.5;
}

/* ---------- 消息 ---------- */
.messages { display: flex; flex-direction: column; }

.msg {
  display: flex;
  gap: 13px;
  padding: 16px 0;
  animation: msgIn 0.3s var(--ease) both;
}

.msg.user { justify-content: flex-end; }

.msg.user .bubble {
  max-width: 82%;
  padding: 10px 16px;
  border-radius: 18px 18px 5px 18px;
  background: var(--user-bubble);
  font-size: 14.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  animation: popIn 0.2s var(--ease);
}

.msg.assistant .avatar {
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  margin-top: 2px;
}

.msg.assistant .avatar svg { width: 18px; height: 18px; }

.msg.assistant .content { flex: 1; min-width: 0; padding-top: 1px; }

.assistant-body { font-size: 14.5px; line-height: 1.75; word-break: break-word; }

/* 思考卡片 */
.thinking-card {
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-subtle);
  overflow: hidden;
  transition: border-color 0.2s;
}

.thinking-head {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 12px;
  font-size: 12.5px;
  color: var(--text-2);
  text-align: left;
  transition: background 0.14s;
}

.thinking-head:hover { background: var(--bg-hover); }
.thinking-head .icon { width: 15px; height: 15px; color: var(--accent); }

.thinking-title { flex: 1; font-weight: 500; }

.thinking-chevron {
  width: 14px;
  height: 14px;
  color: var(--text-3);
  transition: transform 0.24s var(--ease);
}

.thinking-card.open .thinking-chevron { transform: rotate(180deg); }

.thinking-collapse {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.26s var(--ease);
}

.thinking-card.open .thinking-collapse { grid-template-rows: 1fr; }

.thinking-collapse > div { overflow: hidden; }

.thinking-body {
  padding: 0 14px 12px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-2);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 340px;
  overflow-y: auto;
}

.thinking-live-dot {
  display: inline-flex;
  gap: 3px;
  align-items: center;
  margin-left: 2px;
}

.thinking-live-dot i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  animation: dotPulse 1.2s ease-in-out infinite;
}

.thinking-live-dot i:nth-child(2) { animation-delay: 0.15s; }
.thinking-live-dot i:nth-child(3) { animation-delay: 0.3s; }

/* 生成光标 */
.cursor {
  display: inline-block;
  width: 7px;
  height: 1.02em;
  margin-left: 2px;
  vertical-align: -0.14em;
  border-radius: 2px;
  background: var(--text);
  animation: blink 1s steps(2, start) infinite;
}

/* 消息操作条 */
.msg-tools {
  display: flex;
  gap: 2px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity 0.16s;
}

.msg:hover .msg-tools,
.msg-tools:focus-within { opacity: 1; }

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 7px;
  border-radius: 7px;
  font-size: 12px;
  color: var(--text-3);
  transition: background 0.14s, color 0.14s;
}

.tool-btn:hover { background: var(--bg-hover); color: var(--text-2); }
.tool-btn .icon { width: 14px; height: 14px; }

/* 错误卡片 */
.msg-error {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 13px;
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  border-radius: 11px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  line-height: 1.6;
}

.msg-error .retry-btn {
  margin-left: auto;
  flex: none;
  padding: 4px 10px;
  border-radius: 7px;
  border: 1px solid currentColor;
  font-size: 12px;
  color: inherit;
  transition: background 0.14s;
}

.msg-error .retry-btn:hover { background: rgba(0, 0, 0, 0.04); }

/* ---------- Markdown ---------- */
.markdown > *:first-child { margin-top: 0; }
.markdown > *:last-child { margin-bottom: 0; }

.markdown p { margin: 0 0 0.9em; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 {
  margin: 1.4em 0 0.6em;
  line-height: 1.35;
  font-weight: 620;
  letter-spacing: -0.01em;
}
.markdown h1 { font-size: 1.42em; }
.markdown h2 { font-size: 1.24em; }
.markdown h3 { font-size: 1.1em; }
.markdown h4 { font-size: 1em; }

.markdown ul, .markdown ol { margin: 0 0 0.9em; padding-left: 1.45em; }
.markdown li { margin: 0.22em 0; }
.markdown li > p { margin: 0 0 0.4em; }

.markdown a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.markdown a:hover { text-decoration-thickness: 2px; }

.markdown blockquote {
  margin: 0 0 0.9em;
  padding: 2px 0 2px 14px;
  border-left: 3px solid var(--border-strong);
  color: var(--text-2);
}

.markdown hr { border: 0; border-top: 1px solid var(--border); margin: 1.4em 0; }

.markdown strong { font-weight: 650; }

.markdown :not(pre) > code {
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--code-bg);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.88em;
}

.code-block {
  margin: 0 0 0.95em;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--code-bg);
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px 6px 12px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-3);
}

.code-copy {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11.5px;
  color: var(--text-3);
  transition: background 0.14s, color 0.14s;
}

.code-copy:hover { background: var(--bg-hover); color: var(--text); }
.code-copy .icon { width: 12px; height: 12px; }

.markdown pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12.8px;
  line-height: 1.65;
}

.markdown pre code { font-family: inherit; font-size: inherit; }

.table-wrap {
  margin: 0 0 1em;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
}

.table-wrap::-webkit-scrollbar { height: 6px; }

.markdown table {
  width: 100%;
  border-collapse: collapse;
  margin: 0;
  font-size: 13.5px;
}

.markdown th, .markdown td {
  padding: 7px 10px;
  border: 1px solid var(--border);
  text-align: left;
}

.markdown th { background: var(--bg-subtle); font-weight: 600; }

.markdown img { max-width: 100%; border-radius: 8px; }

.markdown kbd {
  padding: 1px 6px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  font-family: var(--font-mono);
  font-size: 0.85em;
}

/* ---------- 输入区 ---------- */
.composer-wrap {
  flex: none;
  padding: 8px 24px 14px;
  max-width: var(--chat-max);
  margin: 0 auto;
  width: 100%;
}

.composer {
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  background: var(--bg);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.18s, box-shadow 0.18s, background-color 0.25s;
}

.composer:focus-within {
  border-color: color-mix(in srgb, var(--accent) 34%, var(--border-strong));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 9%, transparent);
}

.composer-input { padding: 13px 16px 4px; }

#input {
  display: block;
  width: 100%;
  min-height: 24px;
  max-height: 200px;
  padding: 0;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font-size: 14.8px;
  line-height: 1.6;
  scrollbar-width: thin;
}

#input::placeholder { color: var(--text-3); }

.composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 9px 9px 12px;
}

.composer-actions { display: flex; align-items: center; gap: 8px; }

.composer-hint {
  font-size: 11.5px;
  color: var(--text-3);
  white-space: nowrap;
  transition: opacity 0.2s;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 12.5px;
  transition: background 0.16s, color 0.16s, border-color 0.16s;
}

.pill-btn .icon { width: 14px; height: 14px; }
.pill-btn:hover { background: var(--bg-hover); color: var(--text); }

.pill-btn[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}

.send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-contrast);
  display: grid;
  place-items: center;
  transition: background 0.16s, transform 0.14s var(--ease), opacity 0.16s;
}

.send-btn .icon { width: 17px; height: 17px; }
.send-btn:hover { background: var(--accent-hover); }
.send-btn:active { transform: scale(0.93); }

.send-btn:disabled {
  background: var(--border-strong);
  color: var(--bg);
  opacity: 1;
}

.send-btn.stop { background: var(--text); color: var(--bg); }
.send-btn.stop:hover { background: var(--text-2); }

.disclaimer {
  margin: 9px 0 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--text-3);
}

/* ---------- 弹窗 ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 10, 12, 0.36);
  backdrop-filter: blur(3px);
  animation: fadeIn 0.18s ease;
}

.modal-backdrop[hidden] { display: none; }

.modal {
  width: min(520px, 100%);
  max-height: min(86vh, 760px);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.22s var(--ease);
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 12px;
}

.modal-head h2 { margin: 0; font-size: 16px; font-weight: 620; }

.modal-body {
  padding: 4px 20px 20px;
  overflow-y: auto;
}

.setting-group { padding: 14px 0; border-top: 1px solid var(--border); }
.setting-group:first-child { border-top: 0; padding-top: 4px; }

.setting-group h3 {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-3);
  text-transform: uppercase;
}

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 11px;
}

.segmented button {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 6px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-2);
  transition: background 0.16s, color 0.16s, box-shadow 0.16s;
}

.segmented button .icon { width: 15px; height: 15px; }
.segmented button:hover { color: var(--text); }

.segmented button.active {
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  font-weight: 550;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  cursor: pointer;
}

.switch-label { display: flex; flex-direction: column; gap: 2px; }
.switch-label strong { font-size: 13.5px; font-weight: 550; }
.switch-label small { font-size: 12px; color: var(--text-3); line-height: 1.5; }

.switch {
  appearance: none;
  flex: none;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: var(--border-strong);
  position: relative;
  cursor: pointer;
  transition: background 0.18s;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.18s var(--ease);
}

.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }

.data-row { display: flex; gap: 8px; flex-wrap: wrap; }

.ghost-btn {
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  font-size: 13px;
  color: var(--text-2);
  transition: background 0.14s, color 0.14s, border-color 0.14s;
}

.ghost-btn:hover { background: var(--bg-hover); color: var(--text); }

.danger-btn {
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 9px;
  font-size: 13px;
  background: var(--danger-soft);
  color: var(--danger);
  transition: filter 0.14s;
}

.danger-btn:hover { filter: brightness(0.96); }

.about p { margin: 0 0 6px; font-size: 12.5px; }
.about .muted { color: var(--text-3); }
.muted { color: var(--text-3); }

/* ---------- Toast ---------- */
.toast-wrap {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 9px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: 12.8px;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.22s var(--ease);
  max-width: 80vw;
}

.toast.out { animation: toastOut 0.2s ease forwards; }

/* ---------- 移动端遮罩 ---------- */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(10, 10, 12, 0.34);
  backdrop-filter: blur(2px);
  animation: fadeIn 0.18s ease;
}

.sidebar-backdrop[hidden] { display: none; }

/* ---------- 动效 ---------- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes msgIn { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }
@keyframes popIn { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes itemIn { from { opacity: 0; transform: translateX(-4px); } to { opacity: 1; transform: none; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(14px) scale(0.985); } to { opacity: 1; transform: none; } }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(6px); } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes dotPulse { 0%, 60%, 100% { opacity: 0.25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-2px); } }

/* ---------- 响应式 ---------- */
@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open { transform: none; }

  .menu-btn { display: grid; }

  .topbar { padding: 0 12px; }
  .chat-inner { padding: 14px 15px 28px; }
  .markdown table { font-size: 12.5px; }
  .markdown th, .markdown td { padding: 6px 8px; }
  .composer-wrap { padding: 6px 12px 10px; }
  .composer-hint { display: none; }
  .msg { padding: 13px 0; }
  .msg.user .bubble { max-width: 88%; }
  .topbar-title { font-size: 13.5px; }
  .empty-state { padding-top: 12vh; }
}

@media (max-width: 480px) {
  .model-badge { display: none; }
  .suggestion { align-items: flex-start; }
  .suggestion-text { line-height: 1.45; }
}

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