/* ============================================================
   AI Chat Hub · 温暖护眼设计系统
   暖灰米白底 + 单一琥珀橙强调 · 柔和扩散阴影
   不依赖外部字体 CDN，使用系统字体栈，稳定可靠
   ============================================================ */

/* ---------- 主题变量 ---------- */
:root {
  /* 暖色灰阶（米白/驼色系，非冷灰）*/
  --bg: #faf7f2;
  --bg-sidebar: #f3ede3;
  --bg-elevated: #fffdf9;
  --bg-hover: rgba(146, 99, 52, 0.07);
  --bg-active: rgba(146, 99, 52, 0.11);
  --bg-user-bubble: #f0e7d8;

  --border: rgba(120, 90, 60, 0.14);
  --border-strong: rgba(120, 90, 60, 0.22);

  --text: #3a2e25;
  --text-soft: #5c4d40;
  --text-muted: #8c7a68;
  --text-faint: #b6a590;

  /* 单一强调色：琥珀暖橙 */
  --accent: #d97706;
  --accent-hover: #b45309;
  --accent-soft: rgba(217, 119, 6, 0.12);

  --danger: #c0392b;
  --warn: #c2410c;
  --success: #65a30d;

  /* 柔和扩散阴影（暖色调染）*/
  --shadow-sm: 0 1px 2px rgba(120, 80, 40, 0.06);
  --shadow-md: 0 4px 14px rgba(120, 80, 40, 0.10), 0 1px 3px rgba(120, 80, 40, 0.06);
  --shadow-lg: 0 16px 40px rgba(120, 80, 40, 0.16), 0 4px 10px rgba(120, 80, 40, 0.08);

  --radius: 14px;
  --radius-sm: 9px;
  --radius-lg: 18px;
  --radius-pill: 999px;

  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', 'Hiragino Sans GB', sans-serif;
  --font-mono: 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
}

[data-theme="dark"] {
  --bg: #1a1611;
  --bg-sidebar: #211c16;
  --bg-elevated: #2a241d;
  --bg-hover: rgba(255, 220, 180, 0.06);
  --bg-active: rgba(255, 220, 180, 0.10);
  --bg-user-bubble: #302820;

  --border: rgba(255, 220, 180, 0.10);
  --border-strong: rgba(255, 220, 180, 0.18);

  --text: #f5ede2;
  --text-soft: #d4c8b6;
  --text-muted: #a89a86;
  --text-faint: #786c5c;

  --accent: #f59e0b;
  --accent-hover: #fbbf24;
  --accent-soft: rgba(245, 158, 11, 0.16);

  --danger: #f87171;
  --warn: #fb923c;
  --success: #a3e635;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

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

button, input, textarea { font-family: inherit; }
button { cursor: pointer; }

/* ---------- 滚动条（极细，融入背景）---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ============================================================
   登录页
   ============================================================ */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}
/* 暖色光晕背景 */
.login-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(60% 50% at 20% 15%, rgba(217, 119, 6, 0.14), transparent 60%),
    radial-gradient(50% 45% at 85% 85%, rgba(192, 100, 30, 0.12), transparent 60%),
    radial-gradient(40% 40% at 70% 20%, rgba(245, 158, 11, 0.08), transparent 60%);
  pointer-events: none;
}
.login-card {
  position: relative;
  width: 100%;
  max-width: 392px;
  padding: 40px 34px 32px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.login-logo {
  width: 52px; height: 52px;
  margin: 0 auto 22px;
  border-radius: 15px;
  background: linear-gradient(145deg, #f59e0b, #b45309);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 24px;
  letter-spacing: -0.5px;
  box-shadow: 0 8px 20px rgba(217, 119, 6, 0.35);
}
.login-title {
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 5px;
  letter-spacing: -0.4px;
}
.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin: 0 0 30px;
}
.login-form .field { margin-bottom: 15px; }
.login-form label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-soft);
  margin-bottom: 7px;
}
.login-error {
  background: rgba(192, 57, 43, 0.10);
  color: var(--danger);
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  margin-bottom: 15px;
  display: none;
}
.login-error.show { display: block; animation: shake 0.35s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}
.login-foot {
  margin-top: 26px;
  text-align: center;
  font-size: 11px;
  color: var(--text-faint);
}

/* ============================================================
   通用控件
   ============================================================ */
.input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder { color: var(--text-faint); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(145deg, var(--accent), var(--accent-hover));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 12px rgba(217, 119, 6, 0.28);
}
.btn-primary:hover { background: linear-gradient(145deg, var(--accent-hover), var(--accent)); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-icon { width: 36px; height: 36px; padding: 0; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: rgba(192, 57, 43, 0.10); }

/* ============================================================
   主布局
   ============================================================ */
.app { display: flex; height: 100vh; width: 100%; }

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: 268px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 30;
}
.sidebar-head {
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.3px;
  flex: 1;
}
.brand-version {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-faint);
  background: var(--bg-hover);
  padding: 1px 6px;
  border-radius: 5px;
  letter-spacing: 0;
}
.brand-logo {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: linear-gradient(145deg, #f59e0b, #b45309);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  font-weight: 800;
  box-shadow: 0 3px 8px rgba(217, 119, 6, 0.3);
}
.sidebar-actions { padding: 4px 12px 10px; }
.new-chat-btn {
  width: 100%;
  justify-content: flex-start;
  padding: 11px 14px;
  font-size: 13px;
  background: var(--bg-elevated);
  border-color: var(--border);
}
.new-chat-btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px 12px;
}
.session-empty {
  text-align: center;
  color: var(--text-faint);
  font-size: 12px;
  padding: 28px 12px;
  line-height: 1.7;
}
.session-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-soft);
  font-size: 13px;
  margin-bottom: 2px;
  transition: background 0.12s, color 0.12s;
  position: relative;
}
.session-item:hover { background: var(--bg-hover); color: var(--text); }
.session-item.active { background: var(--bg-active); color: var(--text); font-weight: 600; }
.session-item .s-ico { font-size: 13px; opacity: 0.55; flex-shrink: 0; }
.session-item .s-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-item .s-del, .session-item .s-clean {
  opacity: 0;
  width: 22px; height: 22px;
  border: none;
  background: transparent;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-faint);
  font-size: 11px;
  transition: opacity 0.12s, background 0.12s, color 0.12s;
  flex-shrink: 0;
}
.session-item:hover .s-del, .session-item:hover .s-clean { opacity: 1; }
.session-item .s-del:hover { background: rgba(192, 57, 43, 0.12); color: var(--danger); }
.session-item .s-clean:hover { background: rgba(243, 156, 18, 0.15); color: var(--accent, #e67e22); }

.sidebar-foot {
  padding: 8px;
  border-top: 1px solid var(--border);
  position: relative;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s;
}
.user-chip:hover { background: var(--bg-hover); }
.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: linear-gradient(145deg, #d97706, #b45309);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.user-info { flex: 1; overflow: hidden; }
.user-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 11px; color: var(--text-faint); }
.user-chev { color: var(--text-faint); font-size: 13px; }

/* 用户菜单 */
.user-menu {
  position: absolute;
  bottom: 56px;
  left: 8px;
  right: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 5px;
  z-index: 40;
  display: none;
  animation: menuIn 0.15s ease;
}
.user-menu.show { display: block; }
@keyframes menuIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.user-menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-soft);
  transition: background 0.1s, color 0.1s;
}
.user-menu-item:hover { background: var(--bg-hover); color: var(--text); }
.user-menu-item.danger:hover { background: rgba(192, 57, 43, 0.10); color: var(--danger); }
.user-menu-sep { height: 1px; background: var(--border); margin: 4px 0; }

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

/* 顶栏 */
.topbar {
  height: 56px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.menu-toggle { display: none; }
.topbar-spacer { flex: 1; }

/* 模型选择器：pill 风格 */
.model-picker { position: relative; }
.model-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px 7px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  transition: border-color 0.15s, background 0.15s;
  max-width: 250px;
}
.model-btn:hover { border-color: var(--accent); background: var(--bg-hover); }
.model-btn .m-ico { font-size: 9px; color: var(--accent); }
.model-btn .m-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-btn .m-tag {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  flex-shrink: 0;
  letter-spacing: 0.2px;
}
.model-btn .m-tag.img { background: rgba(194, 65, 12, 0.14); color: var(--warn); }
.model-btn .m-chev { color: var(--text-faint); font-size: 11px; margin-left: 2px; }

.model-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 312px;
  max-height: 440px;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  display: none;
  animation: menuIn 0.15s ease;
}
.model-menu.show { display: flex; }
.model-search { padding: 9px; border-bottom: 1px solid var(--border); }
.model-list { flex: 1; overflow-y: auto; padding: 5px; }
.model-group-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-faint);
  padding: 11px 9px 5px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.model-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.1s;
}
.model-option:hover { background: var(--bg-hover); }
.model-option.selected { background: var(--accent-soft); }
.model-option.selected .mo-name { color: var(--accent); }
.model-option .mo-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}
.model-option.image .mo-dot { background: var(--warn); }
.model-option.web .mo-dot { background: var(--accent); }
.model-option .mo-name { flex: 1; font-size: 13px; font-weight: 600; }
.model-option .mo-note {
  font-size: 10px;
  color: var(--text-faint);
  background: var(--bg-active);
  padding: 2px 7px;
  border-radius: 5px;
}

/* 主题切换 */
.icon-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--bg-hover); }

/* ============================================================
   消息区
   ============================================================ */
.messages {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
}
.messages-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 34px 32px 52px;
  display: flex;
  flex-direction: column;
  gap: 30px;
}

/* 欢迎空状态 */
.welcome {
  max-width: 660px;
  margin: 10vh auto 0;
  text-align: left;
  padding: 0 24px;
  animation: fadeIn 0.4s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.welcome-greet {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.6px;
  margin: 0 0 10px;
  color: var(--text);
  background: linear-gradient(120deg, var(--text), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.welcome-sub {
  color: var(--text-muted);
  font-size: 15px;
  margin: 0 0 32px;
  line-height: 1.6;
}
.suggest-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.suggest-card {
  text-align: left;
  padding: 15px 17px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.15s, box-shadow 0.15s;
}
.suggest-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}
.suggest-card h4 { margin: 0 0 4px; font-size: 13px; font-weight: 700; color: var(--text); }
.suggest-card p { margin: 0; font-size: 12px; color: var(--text-muted); line-height: 1.5; }

/* ---------- 消息气泡 ---------- */
.msg {
  display: flex;
  gap: 16px;
  animation: msgIn 0.3s ease;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg-avatar {
  width: 32px; height: 32px;
  border-radius: 9px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  font-weight: 700;
  margin-top: 2px;
}
.msg.user .msg-avatar { background: linear-gradient(145deg, #8c6a4a, #6b5236); color: #fff; }
.msg.assistant .msg-avatar {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--accent);
}
.msg-body { flex: 1; min-width: 0; }
.msg-name {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 5px;
  color: var(--text);
}
.msg-content {
  font-size: 15px;
  line-height: 1.72;
  color: var(--text);
  word-break: break-word;
}
/* 用户消息：暖色浅气泡 */
.msg.user .msg-content {
  background: var(--bg-user-bubble);
  padding: 11px 15px;
  border-radius: 5px var(--radius) var(--radius) var(--radius);
  display: inline-block;
  max-width: 100%;
}
/* AI 消息：无气泡，纯文本 */

/* 打字光标 */
.typing-cursor::after {
  content: '▍';
  color: var(--accent);
  animation: blink 0.9s steps(2) infinite;
  margin-left: 1px;
  font-size: 0.8em;
}
@keyframes blink { 50% { opacity: 0; } }

/* 思考中三点 */
.thinking-dots { display: inline-flex; gap: 5px; padding: 5px 0; }
.thinking-dots span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: dotPulse 1.2s infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotPulse {
  0%, 60%, 100% { transform: scale(0.8); opacity: 0.4; }
  30% { transform: scale(1.15); opacity: 1; }
}

/* 图片消息 */
.msg-images {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}
.msg-images.one { grid-template-columns: auto; justify-items: start; }
.msg-images.two { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 520px; }
.msg-images.one { max-width: 300px; justify-items: start; }
.msg-images img, .msg-content img {
  width: 280px !important;
  height: auto !important;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: zoom-in;
  transition: transform 0.25s;
  display: block;
  object-fit: contain;
}
.msg-images img:hover, .msg-content img:hover { transform: scale(1.03); }

.img-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 14, 8, 0.94);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 40px;
  animation: fadeIn 0.2s;
}
.img-overlay.show { display: flex; }
.img-overlay img { max-width: 90%; max-height: 90%; border-radius: 8px; }
.img-toolbar { position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%); display: flex; gap: 10px; z-index: 5; }
.img-toolbar .btn-sm { font-size: 13px !important; padding: 8px 16px !important; }

/* 消息操作栏（常驻可见，方便移动端点击"再次提问/复制"）*/
.msg-actions {
  display: flex;
  gap: 2px;
  margin-top: 7px;
  opacity: 0.75;
  transition: opacity 0.15s;
}
.msg:hover .msg-actions { opacity: 1; }
.msg-action {
  font-size: 11px;
  color: var(--text-faint);
  padding: 4px 8px;
  border-radius: 6px;
  border: none;
  background: transparent;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
}
.msg-action:hover { background: var(--bg-hover); color: var(--text); }
/* 触屏设备：始终完全可见（无 hover）*/
@media (hover: none) {
  .msg-actions { opacity: 1; }
}

/* ============================================================
   Markdown 渲染
   ============================================================ */
.msg-content p { margin: 0 0 12px; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content h1, .msg-content h2, .msg-content h3 {
  margin: 22px 0 11px; font-weight: 700; line-height: 1.3; letter-spacing: -0.3px;
}
.msg-content h1 { font-size: 1.4em; }
.msg-content h2 { font-size: 1.25em; }
.msg-content h3 { font-size: 1.1em; }
.msg-content ul, .msg-content ol { margin: 8px 0 12px; padding-left: 24px; }
.msg-content li { margin: 4px 0; }
.msg-content blockquote {
  border-left: 3px solid var(--accent);
  margin: 12px 0;
  padding: 4px 16px;
  color: var(--text-soft);
  background: var(--bg-hover);
  border-radius: 0 8px 8px 0;
}
.msg-content a { color: var(--accent); text-decoration: none; }
.msg-content a:hover { text-decoration: underline; }
.msg-content table {
  border-collapse: collapse;
  margin: 12px 0;
  display: block;
  overflow-x: auto;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.msg-content th, .msg-content td {
  border: 1px solid var(--border);
  padding: 8px 13px;
  text-align: left;
}
.msg-content th { background: var(--bg-hover); font-weight: 700; }
.msg-content hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.msg-content code:not(pre code) {
  background: var(--bg-active);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.88em;
  font-family: var(--font-mono);
  color: var(--accent-hover);
}
[data-theme="dark"] .msg-content code:not(pre code) { color: var(--accent); }

/* 代码块 */
.code-block {
  margin: 12px 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
}
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 13px;
  background: var(--bg-hover);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
}
.code-lang { color: var(--text-faint); font-weight: 700; font-family: var(--font-mono); text-transform: lowercase; }
.code-copy {
  font-size: 11px;
  color: var(--text-faint);
  border: none;
  background: transparent;
  padding: 3px 9px;
  border-radius: 5px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background 0.1s, color 0.1s;
}
.code-copy:hover { background: var(--bg-active); color: var(--text); }
.code-copy.copied { color: var(--success); }
.code-block pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.62;
}
.code-block pre code { font-family: var(--font-mono); background: transparent; padding: 0; }

/* ============================================================
   输入区
   ============================================================ */
.composer {
  flex-shrink: 0;
  padding: 12px 24px 22px;
  background: var(--bg);
}
.composer-inner { max-width: 1100px; margin: 0 auto; }
.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 9px 9px 9px 17px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-md);
}
.composer textarea {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  max-height: 200px;
  padding: 8px 0;
  font-family: var(--font-sans);
}
.composer textarea::placeholder { color: var(--text-faint); }
.send-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(145deg, var(--accent), var(--accent-hover));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 16px;
  box-shadow: 0 3px 8px rgba(217, 119, 6, 0.32);
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}
.send-btn:hover:not(:disabled) { background: linear-gradient(145deg, var(--accent-hover), var(--accent)); }
.send-btn:active:not(:disabled) { transform: scale(0.92); }
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; box-shadow: none; }
.composer-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 9px;
}

/* ============================================================
   模态框 / Toast / 状态卡 / 错误卡
   ============================================================ */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(40, 28, 16, 0.45);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 90;
  padding: 20px;
}
.modal-mask.show { display: flex; animation: fadeIn 0.2s; }
.modal {
  width: 100%;
  max-width: 760px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 28px;
  animation: modalIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal h3 { margin: 0 0 5px; font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
.modal p.desc { color: var(--text-muted); font-size: 13px; margin: 0 0 22px; }
.modal .field { margin-bottom: 15px; }
.modal .field label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 7px; color: var(--text-soft); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 22px; }

.user-list { max-height: 300px; overflow-y: auto; margin: 12px 0; }
.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 7px;
}
.user-row .u-name { flex: 1; font-size: 13px; font-weight: 600; }
.user-row .u-meta { font-size: 11px; color: var(--text-faint); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.badge-admin { font-size: 10px; padding: 2px 7px; border-radius: 5px; background: var(--accent-soft); color: var(--accent); font-weight: 700; }

/* 用户行操作按钮 + 权限标签 */
.u-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.btn-sm { font-size: 11px !important; padding: 4px 8px !important; border-radius: 6px !important; }
.u-perm { font-size: 10px; padding: 1px 6px; border-radius: 4px; background: var(--bg-hover); color: var(--text-faint); }
.u-perm.all { background: var(--accent-soft); color: var(--accent); }
.u-perm.none { background: rgba(220,80,80,.12); color: #c0484d; }

/* 重置密码结果框 */
.pwd-box { display: flex; align-items: center; gap: 8px; margin-top: 10px; background: var(--bg-hover); border: 1px dashed var(--border); border-radius: var(--radius-sm); padding: 12px 14px; }
.pwd-box code { flex: 1; font-family: 'SF Mono', Menlo, monospace; font-size: 16px; font-weight: 700; letter-spacing: 1px; color: var(--accent); word-break: break-all; }

/* 模型权限勾选 */
.perm-list { max-height: 46vh; overflow-y: auto; margin-top: 10px; }
.perm-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13px; border: 1px solid transparent; }
.perm-item:hover { background: var(--bg-hover); }
.perm-item.on { background: var(--accent-soft); border-color: var(--accent-soft); }
.perm-item input { accent-color: var(--accent); }
.perm-item .perm-name { flex: 1; }
.perm-item .perm-tag { font-size: 10px; padding: 1px 6px; border-radius: 4px; background: var(--bg-hover); color: var(--text-faint); }
.perm-item .perm-tag.img { background: rgba(200,120,40,.15); color: #b06a20; }
.perm-toolbar { padding: 4px 0 8px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }

/* 会话记录查看器(管理员) */
.turn-list { max-height: 65vh; overflow-y: auto; margin-top: 10px; }
.turn-row { border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 6px; overflow: hidden; }
.turn-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; cursor: pointer; font-size: 12px; flex-wrap: wrap; }
.turn-head:hover { background: var(--bg-hover); }
.turn-time { color: var(--text-faint); font-family: 'SF Mono', Menlo, monospace; font-size: 11px; white-space: nowrap; }
.turn-user { font-weight: 600; color: var(--text); }
.turn-model { font-size: 10px; padding: 1px 6px; border-radius: 4px; background: var(--bg-hover); color: var(--text-faint); }
.turn-st { font-size: 10px; padding: 1px 6px; border-radius: 4px; font-weight: 600; }
.turn-st.ok { background: rgba(60,160,90,.15); color: #3ca05a; }
.turn-st.fail { background: rgba(200,70,70,.15); color: #c04040; }
.turn-q { flex: 1; color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 100px; }
.turn-chev { color: var(--text-faint); }
.turn-row.open .turn-chev { transform: rotate(180deg); }
.turn-body { padding: 10px 12px; border-top: 1px solid var(--border); background: var(--bg-soft); }
.turn-field { margin-bottom: 8px; font-size: 12px; }
.turn-field b { color: var(--text-soft); }
.turn-text { margin-top: 4px; white-space: pre-wrap; word-break: break-word; color: var(--text); line-height: 1.5; }
.turn-meta { font-size: 10px; color: var(--text-faint); margin-top: 4px; }
.turn-md p { margin: 4px 0; }
.turn-md ul, .turn-md ol { margin: 4px 0; padding-left: 18px; }
.turn-md strong { font-weight: 700; }
.turn-md table { border-collapse: collapse; font-size: 11px; margin: 4px 0; }
.turn-md th, .turn-md td { border: 1px solid var(--border); padding: 3px 6px; }
.turn-md th { background: var(--bg-hover); }
.turn-md code { background: var(--bg-hover); padding: 1px 4px; border-radius: 3px; font-size: 11px; }

/* 顶栏会话信息 */
.session-meta { display: flex; align-items: center; gap: 10px; font-size: 11px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-right: 6px; }
.sess-id { font-weight: 700; color: var(--text-soft); }
.sess-time { color: var(--text-faint); }
.sess-upstream { font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 1px 6px; border-radius: 4px; }

/* 模型维护 textarea */
.model-input { width: 100%; background: var(--bg-soft); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; font-family: 'SF Mono',Menlo,monospace; font-size: 12px; resize: vertical; box-sizing: border-box; }

/* 排队卡片（503 busy 多人等待） */
.queue-card { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 20px; border: 2px dashed var(--accent-soft); border-radius: var(--radius); background: var(--accent-soft); max-width: 360px; }
.queue-spin { font-size: 28px; animation: spin 1.5s linear infinite; }
.queue-msg { font-size: 13px; color: var(--text-soft); text-align: center; }
.queue-cancel { margin-top: 4px; color: var(--text-faint) !important; }
.queue-cancel:hover { color: var(--danger) !important; }

/* 新版本提示条 */
.version-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 9999;
  display: flex; align-items: center; gap: 10px; justify-content: center;
  background: linear-gradient(90deg, var(--accent), #d97a3a);
  color: #fff; font-size: 13px; padding: 8px 16px;
  box-shadow: 0 2px 10px rgba(0,0,0,.18);
  animation: slideDown .25s ease;
}
.version-bar .btn-sm { color: var(--accent); }
.version-bar .btn-ghost { color: #fff; border: 1px solid rgba(255,255,255,.5); }
@keyframes slideDown { from { transform: translateY(-100%); } to { transform: translateY(0); } }

/* Toast */
.toast-wrap {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 7px;
  pointer-events: none;
}
.toast {
  padding: 10px 17px;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: var(--bg-elevated);
  font-size: 12px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: auto;
}
.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--success); color: #fff; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 状态提示（排队/重试中）*/
.status-hint {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 8px 13px;
  background: var(--bg-hover);
  color: var(--text-soft);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
}
.status-icon { display: inline-block; animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 错误卡片 */
.err-card {
  display: flex;
  gap: 13px;
  padding: 15px 17px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  max-width: 560px;
}
.err-card.rate-limit { border-color: rgba(194, 65, 12, 0.35); background: rgba(194, 65, 12, 0.06); }
.err-ico { font-size: 22px; line-height: 1.3; flex-shrink: 0; }
.err-body { flex: 1; min-width: 0; }
.err-title { font-size: 13px; font-weight: 700; margin-bottom: 4px; color: var(--text); }
.err-desc { font-size: 12px; color: var(--text-soft); line-height: 1.55; }
.err-alt-label { font-size: 11px; color: var(--text-faint); margin-top: 11px; margin-bottom: 7px; }
.err-alt-list { display: flex; flex-wrap: wrap; gap: 7px; }
.err-alt-btn {
  padding: 6px 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: var(--bg-elevated);
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 600;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}
.err-alt-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.sidebar-mask { display: none; position: fixed; inset: 0; background: rgba(40, 28, 16, 0.35); z-index: 25; }
.sidebar-mask.show { display: block; }

/* ============================================================
   响应式
   ============================================================ */
@media (max-width: 860px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: inline-flex; }
  .messages-inner { padding: 24px 16px 36px; }
  .composer { padding: 10px 16px 18px; }
  .suggest-grid { grid-template-columns: 1fr; }
  .model-btn { max-width: 168px; }
  .model-menu { width: 290px; }
  .welcome { margin-top: 7vh; }
  .welcome-greet { font-size: 25px; }
}

/* ============================================================
   收藏夹面板
   ============================================================ */
.fav-list { display: flex; flex-direction: column; gap: 6px; max-height: 60vh; overflow-y: auto; margin-bottom: 12px; }
.fav-section-title { font-size: 13px; font-weight: 700; color: var(--text-soft); margin: 12px 0 6px; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.fav-row { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--bg-soft); }
.fav-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; cursor: pointer; transition: background 0.12s; }
.fav-head:hover { background: var(--bg-hover, rgba(0,0,0,0.03)); }
.fav-note { font-weight: 600; font-size: 13px; color: var(--text); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fav-info { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
.fav-time { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
.fav-chev { color: var(--text-faint); font-size: 12px; flex-shrink: 0; transition: transform 0.15s; }
.fav-row.open .fav-chev { transform: rotate(180deg); }
.fav-del-btn { flex-shrink: 0; padding: 4px 10px; border: 1px solid var(--border); border-radius: var(--radius-pill); background: transparent; color: var(--text-muted); font-size: 11px; font-weight: 600; cursor: pointer; transition: border-color 0.12s, color 0.12s, background 0.12s; }
.fav-del-btn:hover { border-color: var(--danger); color: var(--danger); background: rgba(192,57,43,0.08); }

/* 敏感词标签 */
.kw-tag { display: inline-flex; align-items: center; gap: 4px; padding: 5px 10px; background: var(--bg-hover); border: 1px solid var(--border); border-radius: var(--radius-pill); font-size: 13px; color: var(--text); }
.kw-del { width: 18px; height: 18px; border: none; background: transparent; color: var(--text-faint); border-radius: 50%; cursor: pointer; font-size: 11px; display: inline-flex; align-items: center; justify-content: center; transition: background 0.12s, color 0.12s; }
.kw-del:hover { background: rgba(192,57,43,0.15); color: var(--danger); }
.fav-body { padding: 0 12px 12px; border-top: 1px solid var(--border); }
.fav-field { margin-top: 8px; font-size: 13px; }
.fav-field b { color: var(--text-soft); font-weight: 600; }
.fav-text { margin-top: 4px; color: var(--text); line-height: 1.6; }
.fav-meta { margin-top: 8px; font-size: 11px; color: var(--text-muted); }

/* 顶栏收藏按钮 + 会话ID - 比模型选择器更大更醒目 */
.session-meta { display: flex; align-items: center; gap: 8px; margin-left: 4px; }
.sess-id-pair {
  display: inline-flex; align-items: center;
  font-size: 14px; font-weight: 700;
  color: var(--text-muted); font-family: monospace;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg-elevated);
}
.btn-fav-session {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 14px; font-weight: 700;
  cursor: pointer; white-space: nowrap;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.btn-fav-session:hover { border-color: var(--warning, #f39c12); color: var(--warning, #f39c12); background: rgba(243,156,18,0.06); }
.btn-fav-session.favorited { border-color: var(--warning, #f39c12); color: var(--warning, #f39c12); background: rgba(243,156,18,0.1); }

/* AI 助手名称旁的会话收藏星标 */
.sess-fav-star { color: var(--warning, #f39c12); font-size: 13px; font-weight: 700; }

/* 会话列表图标 */
.session-item .s-icon { flex-shrink: 0; }
.session-item .s-icon-star { color: var(--warning, #f39c12); }
.session-item .s-icon-chat { color: var(--text-faint); }
.session-item .s-star { color: var(--warning, #f39c12); font-size: 11px; flex-shrink: 0; opacity: 0.8; }

/* 消息时间戳 */
.msg-time { font-size: 11px; color: var(--text-faint); margin-top: 4px; }

/* 侧边栏底部清理按钮 */
.sidebar-actions-bottom { padding: 8px 12px; border-top: 1px solid var(--border); }
.btn-clean-all { width: 100%; justify-content: center; font-size: 12px; color: var(--text-muted); }
.btn-clean-all:hover { color: var(--warning, #f39c12); background: rgba(243,156,18,0.08); }
