/* ============================================
   chat.css - AI 对话页面样式（重构版）
   仿首页搜索栏风格，左历史栏，右对话区
   ============================================ */

/* === 页面基础 === */
.chat-body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

.chat-body .site-main { padding-top: 0; }
.chat-body .site-nav { position: relative; }

/* ==================== 整体布局 ==================== */
.chat-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  height: calc(100vh - var(--nav-height, 72px));
  position: relative;
  gap: 10px;
}

.chat-sidebar {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  transition: width .32s cubic-bezier(.4,0,.2,1), opacity .32s ease;
  overflow: hidden;
  padding: 10px 0 10px 10px;
}

.chat-sidebar.collapsed {
  width: 52px;
}

.chat-sidebar-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 220px;
  border: 1px solid var(--border);
  border-radius: var(--radius, 22px);
  box-shadow: var(--shadow);
  overflow: hidden;
  background: transparent;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.chat-sidebar-inner::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--card);
  opacity: 0.92;
  z-index: 0;
  pointer-events: none;
}

.chat-sidebar-inner > * {
  position: relative;
  z-index: 1;
}

.chat-sidebar-header {
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  padding-bottom: 9px;
}

.chat-history-search-wrap { display: block; padding: 0 10px; }
.chat-history-search {
  width: 100%;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 11px;
  background: rgba(255,255,255,.52);
  color: var(--text);
  outline: none;
}
[data-theme="dark"] .chat-history-search { background: rgba(255,255,255,.04); }
.chat-history-search:focus { border-color: var(--accent-solid); box-shadow: 0 0 0 2px rgba(142,92,255,.1); }
.collapsed .chat-history-search-wrap { display: none; }
.chat-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.chat-sidebar-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 10px;
}

/* 折叠按钮（渐变背景，同首页 bookmark-toggle-btn） */
.chat-sidebar-toggle-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .82rem;
  flex-shrink: 0;
  transition: transform .28s ease;
}

.chat-sidebar-toggle-btn:hover {
  transform: scale(1.05);
}

.chat-sidebar-toggle-icon {
  display: inline-block;
  transition: transform .28s ease;
}

/* 折叠时箭头翻转 */
.collapsed .chat-sidebar-toggle-icon {
  transform: rotate(180deg);
}

.chat-sidebar-title {
  flex: 1;
  font-weight: 800;
  font-size: .92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

/* 折叠时隐藏标题 */
.collapsed .chat-sidebar-title {
  display: none;
}

.chat-sidebar-new-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .92rem;
  flex-shrink: 0;
  transition: transform .2s ease, box-shadow .2s ease;
}

.chat-sidebar-new-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

/* 折叠时隐藏新建按钮 */
.collapsed .chat-sidebar-new-btn {
  display: none;
}

.chat-sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px;
  transition: opacity .32s ease, max-height .32s ease, padding .32s ease;
  max-height: 100%;
  opacity: 1;
}

.chat-sidebar-list::-webkit-scrollbar { width: 4px; }
.chat-sidebar-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }

/* 折叠时隐藏列表 */
.collapsed .chat-sidebar-list {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
  overflow: hidden;
  pointer-events: none;
}

.chat-sidebar-empty {
  text-align: center;
  padding: 28px 12px;
  color: var(--muted);
  font-size: 0.8rem;
}

.chat-sidebar-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  margin: 2px 6px;
  border-radius: 12px;
  cursor: pointer;
  transition: background .2s ease;
  position: relative;
  border: 1px solid transparent;
}

.chat-sidebar-item:hover {
  background: rgba(127,127,127,0.12);
  border-color: rgba(127,127,127,0.18);
}

.chat-sidebar-item--active {
  background: rgba(127,127,127,0.18);
  border-color: rgba(127,127,127,0.24);
}

.chat-sidebar-item-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1;
}

.chat-sidebar-item-title {
  font-size: .86rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.chat-sidebar-item-time {
  font-size: 0.72rem;
  color: var(--muted);
  opacity: 0.75;
}

.chat-sidebar-item-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .18s ease; }
.chat-sidebar-item:hover .chat-sidebar-item-actions,
.chat-sidebar-item--active .chat-sidebar-item-actions { opacity: 1; }
.chat-sidebar-item-delete,
.chat-sidebar-item-rename {
  width: 22px;
  height: 22px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: .7rem;
  opacity: 0;
  transition: opacity .2s ease;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  flex-shrink: 0;
}

.chat-sidebar-item:hover .chat-sidebar-item-delete,
.chat-sidebar-item:hover .chat-sidebar-item-rename {
  opacity: .5;
}

.chat-sidebar-item-delete:hover {
  opacity: 1 !important;
  background: rgba(231,76,60,0.1);
  color: #e74c3c;
}
.chat-sidebar-item-rename:hover { color: var(--accent-solid); background: rgba(142,92,255,.1); }

/* 移动端侧栏切换按钮 */
.chat-sidebar-toggle-btn--mobile {
  display: none;
}

/* ==================== 主区域 ==================== */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  padding: 0 12px 0 0;
}

/* ==================== 顶部栏 ==================== */
.chat-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 10px 16px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.chat-topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-topbar-title {
  font-weight: 800;
  font-size: 1rem;
  color: var(--text);
}

.chat-topbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-connection-status {
  max-width: 330px;
  color: var(--muted);
  font-size: .76rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-connection-status.is-ready { color: #26865b; }

.chat-topbar-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-topbar-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.chat-topbar-btn--icon {
  width: 34px;
  height: 34px;
  justify-content: center;
  padding: 0;
  font-size: 1rem;
}

/* More 下拉菜单 */
.chat-topbar-dropdown-wrap {
  position: relative;
}

.chat-topbar-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 180px;
  background: var(--bg-2, var(--bg));
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
  z-index: 100;
  padding: 6px;
  backdrop-filter: blur(20px);
}

.chat-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s ease;
  text-align: left;
}

.chat-dropdown-item:hover {
  background: rgba(127, 127, 127, 0.1);
}

.chat-dropdown-item--danger:hover {
  background: rgba(231, 76, 60, 0.1);
  color: #e74c3c;
}

.chat-dropdown-icon {
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.chat-dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* ==================== 消息列表 ==================== */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
}

/* 欢迎界面 */
.chat-welcome {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}

.chat-welcome-icon { font-size: 3rem; margin-bottom: 12px; }
.chat-welcome h2 { font-size: 1.6rem; margin: 0 0 10px; color: var(--text); }
.chat-welcome p { max-width: 480px; margin: 0 auto 12px; line-height: 1.6; }
.chat-welcome-hints { font-size: 0.85rem; opacity: 0.7; }
.chat-welcome-status {
  display: inline-flex;
  margin-top: 14px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  font-size: .8rem;
}
.chat-welcome-status.is-ready { color: #26865b; border-color: rgba(38,134,91,.28); }
.chat-starter-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  width: min(680px, 100%);
  margin: 22px auto 14px;
}
.chat-starter {
  min-height: 64px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--card);
  color: var(--text);
  box-shadow: 0 8px 22px rgba(31,35,48,.07);
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.chat-starter:hover { transform: translateY(-2px); border-color: var(--accent-solid); box-shadow: var(--shadow); }
.chat-config-link { display: inline-block; color: var(--accent-solid); font-weight: 700; font-size: .86rem; }

/* === 单条消息 === */
.chat-msg {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  max-width: 85%;
}

.chat-msg--user { align-self: flex-end; flex-direction: row-reverse; }
.chat-msg--ai { align-self: flex-start; }
.chat-msg--system { align-self: center; max-width: 90%; opacity: 0.8; font-size: 0.88rem; }

.chat-msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card);
  border: 1px solid var(--border);
  flex-shrink: 0;
  font-size: 0.9rem;
}

.chat-msg-time {
  font-size: 0.65rem;
  color: var(--muted);
  opacity: 0.5;
  align-self: center;
}

.chat-msg--user .chat-msg-time { margin-right: 6px; }
.chat-msg--ai .chat-msg-time { margin-left: 6px; }

.chat-msg-bubble {
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  line-height: 1.7;
  font-size: 0.95rem;
  word-wrap: break-word;
  overflow-wrap: break-word;
  min-width: 60px;
}
.chat-msg--ai .chat-msg-bubble { max-width: min(720px, 100%); }

.chat-msg--user .chat-msg-bubble {
  background: var(--accent);
  color: white;
  border-color: transparent;
}

.chat-msg--system .chat-msg-bubble {
  background: transparent;
  border-color: transparent;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}

.chat-msg--ai .chat-msg-bubble { background: var(--card); color: var(--text); }

/* AI 消息的 Markdown */
.chat-msg--ai .chat-msg-bubble h1,
.chat-msg--ai .chat-msg-bubble h2,
.chat-msg--ai .chat-msg-bubble h3,
.chat-msg--ai .chat-msg-bubble h4 { margin: 1em 0 0.5em; line-height: 1.3; }
.chat-msg--ai .chat-msg-bubble h1 { font-size: 1.4rem; }
.chat-msg--ai .chat-msg-bubble h2 { font-size: 1.2rem; }
.chat-msg--ai .chat-msg-bubble h3 { font-size: 1.1rem; }
.chat-msg--ai .chat-msg-bubble p { margin: 0.5em 0; }
.chat-msg--ai .chat-msg-bubble ul,
.chat-msg--ai .chat-msg-bubble ol { padding-left: 1.5em; margin: 0.5em 0; }
.chat-msg--ai .chat-msg-bubble li { margin: 0.25em 0; }
.chat-msg--ai .chat-msg-bubble code {
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(127, 127, 127, 0.12);
  font-size: 0.88em;
}
.chat-msg--ai .chat-msg-bubble pre {
  position: relative;
  overflow-x: auto;
  padding: 14px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.06);
  margin: 0.8em 0;
}
[data-theme="dark"] .chat-msg--ai .chat-msg-bubble pre { background: rgba(255, 255, 255, 0.04); }
.chat-msg--ai .chat-msg-bubble pre code { padding: 0; background: none; font-size: 0.85rem; }
.chat-msg--ai .chat-msg-bubble blockquote {
  border-left: 3px solid var(--accent-solid);
  padding-left: 12px;
  margin: 0.5em 0;
  color: var(--muted);
}
.chat-msg--ai .chat-msg-bubble table { border-collapse: collapse; margin: 0.8em 0; width: 100%; }
.chat-msg--ai .chat-msg-bubble th,
.chat-msg--ai .chat-msg-bubble td { padding: 8px 12px; border: 1px solid var(--border); text-align: left; }
.chat-msg--ai .chat-msg-bubble th { background: rgba(127, 127, 127, 0.08); font-weight: 700; }
.chat-msg--ai .chat-msg-bubble a { color: var(--accent-solid); text-decoration: underline; }
.chat-msg--ai .chat-msg-bubble hr { border: none; border-top: 1px solid var(--border); margin: 1em 0; }

/* 思考中占位 */
.chat-msg-thinking {
  color: var(--muted);
  font-style: italic;
  font-size: 0.9rem;
}

/* 代码复制按钮 */
.chat-code-copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  border: none;
  background: rgba(127, 127, 127, 0.15);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 0.85rem;
  opacity: 0.6;
  transition: opacity 0.2s ease;
}
.chat-code-copy-btn:hover { opacity: 1; }

/* ==================== 底部一体化输入栏（仿 search-panel 风格） ==================== */
.chat-input-panel {
  width: 100%;
  padding: 10px 14px;
  border-radius: 28px;
  background: var(--card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  flex-shrink: 0;
  max-width: 900px;
  margin: 0 auto 10px;
  box-shadow: 0 4px 24px rgba(31, 35, 48, 0.08);
}

.chat-input-panel .chat-input-row--main {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: var(--bg-2, var(--bg));
  padding: 6px 6px 6px 4px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-input-panel .chat-input-row--main:focus-within {
  border-color: var(--accent-solid, #8e5cff);
  box-shadow: 0 0 0 2px rgba(142, 92, 255, 0.12);
}

.chat-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* 第一行：展开 + 输入框 + 发送 */
.chat-input-row--main {
  margin-bottom: 8px;
}

.chat-expand-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.5);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .9rem;
  flex-shrink: 0;
  transition: transform .2s ease, box-shadow .2s ease;
}
[data-theme="dark"] .chat-expand-btn {
  background: rgba(255,255,255,.04);
}
.chat-expand-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.chat-input-wrap {
  flex: 1;
  display: flex;
}

.chat-textarea {
  flex: 1;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(255,255,255,0.62);
  color: var(--text);
  font-size: .92rem;
  resize: none;
  outline: none;
  line-height: 1.5;
  max-height: 160px;
  min-height: 42px;
  font-family: inherit;
  transition: border-color .2s ease;
}
[data-theme="dark"] .chat-textarea {
  background: rgba(255,255,255,.04);
}
.chat-textarea:focus {
  border-color: var(--border);
}
.chat-textarea::placeholder {
  color: var(--muted);
  opacity: .6;
}

.chat-send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 1.05rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform .2s ease, box-shadow .2s ease;
}
.chat-send-btn:hover {
  transform: scale(1.05);
  box-shadow: var(--shadow);
}
.chat-send-btn:disabled { opacity: .38; cursor: not-allowed; transform: none; box-shadow: none; }

.chat-stop-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: #e74c3c;
  color: white;
  font-size: 1.05rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform .2s ease;
}
.chat-stop-btn:hover {
  transform: scale(1.05);
}

/* 第二行：工具 */
.chat-input-row--tools {
  justify-content: space-between;
}

.chat-input-tools-left {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* 自定义下拉 */
.chat-select-wrap {
  position: relative;
}

.chat-select-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.6);
  color: var(--text);
  font-size: 0.78rem;
  cursor: pointer;
  min-width: 140px;
  max-width: 220px;
  transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease;
}
[data-theme="dark"] .chat-select-btn {
  background: rgba(255,255,255,.05);
}
.chat-select-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}
.chat-select-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}
.chat-select-label {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}
.chat-select-caret {
  opacity: 0.7;
  font-size: 0.75rem;
}

.chat-select-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 220px;
  max-height: 280px;
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.18);
  padding: 6px;
  display: none;
  z-index: 120;
  backdrop-filter: blur(18px);
}
.chat-select-menu::-webkit-scrollbar { width: 4px; }
.chat-select-menu::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }

.chat-select-wrap.is-open .chat-select-menu {
  display: block;
}

.chat-select-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 10px;
  background: none;
  color: var(--text);
  font-size: 0.82rem;
  cursor: pointer;
  text-align: left;
  transition: background .15s ease;
}
.chat-select-item:hover {
  background: rgba(127,127,127,0.12);
}
.chat-select-item.is-active {
  background: rgba(127,127,127,0.18);
  font-weight: 700;
}

/* 思考深度 */
.chat-depth-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,0.5);
}
[data-theme="dark"] .chat-depth-control {
  background: rgba(255,255,255,.04);
}
.chat-depth-label {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
}
.chat-depth-slider {
  width: 70px;
  height: 4px;
  appearance: none;
  background: var(--border);
  border-radius: 999px;
  outline: none;
}
.chat-depth-slider::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-solid);
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.chat-depth-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-solid);
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.chat-depth-value {
  font-size: 0.72rem;
  color: var(--text);
  min-width: 26px;
  text-align: center;
}

.chat-input-tools-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-select {
  padding: 4px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.5);
  color: var(--text);
  font-size: .78rem;
  cursor: pointer;
  outline: none;
  max-width: 140px;
  transition: border-color .2s ease;
}
[data-theme="dark"] .chat-select {
  background: rgba(255,255,255,.04);
}
.chat-select:focus {
  border-color: var(--accent-solid);
}

/* 工具芯片按钮（深度、联网搜索） */
.chat-tool-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.5);
  color: var(--text);
  font-size: .78rem;
  cursor: pointer;
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}
[data-theme="dark"] .chat-tool-chip {
  background: rgba(255,255,255,.04);
}
.chat-tool-chip:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}
.chat-tool-chip:disabled { opacity: .38; cursor: not-allowed; transform: none; box-shadow: none; }
.chat-tool-chip.chat-web-toggle--active {
  border-color: var(--accent-solid);
}

.chat-input-hint {
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
  opacity: 0.5;
  margin-top: 6px;
}
.chat-draft-status { margin-left: 10px; color: #b26b00; }

/* ==================== 模态框 ==================== */
/* Toast */
.chat-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: 12px;
  font-size: 0.88rem;
  font-weight: 600;
  z-index: 3000;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
  display: none;
  white-space: nowrap;
}

/* ==================== 响应式 ==================== */
@media (max-width: 900px) {
  .chat-sidebar {
    width: 220px;
  }
  .chat-sidebar-inner {
    width: 220px;
  }
}

@media (max-width: 760px) {
  .chat-sidebar-toggle-btn--mobile { display: flex; }
  .chat-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 200;
    width: 240px;
    padding: 8px 0 8px 8px;
  }
  .chat-sidebar.collapsed {
    transform: translateX(-100%);
  }
  .chat-main { padding: 0 8px; }
  .chat-msg { max-width: 92%; }
  .chat-input-tools-left {
    gap: 4px;
  }
  .chat-tool-chip {
    font-size: 0.75rem;
    padding: 4px 8px;
  }
  .chat-select-btn {
    min-width: 120px;
    max-width: 180px;
  }
  .chat-depth-slider { width: 56px; }
  .chat-modal {
    width: calc(100vw - 16px);
    max-height: 90vh;
  }
  .chat-api-card { flex-direction: column; align-items: stretch; }
  .chat-api-key-input,
  .chat-api-url-input { min-width: auto; }
}

@media (max-width: 480px) {
  .chat-msg-avatar { width: 28px; height: 28px; font-size: 0.85rem; }
  .chat-msg-bubble { padding: 10px 12px; font-size: 0.9rem; }
  .chat-send-btn, .chat-stop-btn { width: 38px; height: 38px; font-size: 0.95rem; }
  .chat-expand-btn { width: 34px; height: 34px; }
  .chat-messages { padding: 12px 12px; }
  .chat-input-panel { padding: 8px 10px; border-radius: 22px; }
}

/* ================================================================
   新增组件样式：推理块 / 消息操作按钮 / 代码语言标签 /
   展开按钮状态 / 滚动到底部按钮 / 编辑输入框 / 重试按钮
   ================================================================ */

/* --- 推理内容区块 --- */
.chat-msg-reasoning {
  background: rgba(142, 92, 255, 0.06);
  border: 1px solid rgba(142, 92, 255, 0.15);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 10px;
  font-size: 0.85rem;
}
[data-theme="dark"] .chat-msg-reasoning {
  background: rgba(142, 92, 255, 0.10);
  border-color: rgba(142, 92, 255, 0.25);
}

.chat-reasoning-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  color: var(--accent-solid, #8e5cff);
  margin-bottom: 6px;
  font-size: 0.8rem;
  letter-spacing: 0.02em;
}

.chat-reasoning-icon {
  font-size: 0.9rem;
}

.chat-reasoning-content {
  color: var(--muted);
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 0.85rem;
  max-height: 240px;
  overflow-y: auto;
}

/* --- 消息操作按钮容器 --- */
.chat-msg-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s ease;
  align-items: center;
  margin-top: 4px;
  padding-left: 42px; /* 与头像对齐 */
}

.chat-msg:hover .chat-msg-actions {
  opacity: 1;
}

.chat-msg--user .chat-msg-actions {
  padding-left: 0;
  padding-right: 42px;
  justify-content: flex-end;
}

/* 单个操作按钮 */
.chat-msg-action-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
  padding: 0;
  line-height: 1;
}

.chat-msg-action-btn:hover {
  background: rgba(127, 127, 127, 0.12);
  color: var(--text);
  transform: translateY(-1px);
}

.chat-msg-action-btn--del:hover {
  background: rgba(231, 76, 60, 0.1);
  color: #e74c3c;
}

/* --- 内联编辑输入框 --- */
.chat-edit-textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--accent-solid, #8e5cff);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.92rem;
  font-family: inherit;
  resize: vertical;
  outline: none;
  line-height: 1.5;
  min-height: 60px;
  transition: box-shadow 0.2s ease;
}

.chat-edit-textarea:focus {
  box-shadow: 0 0 0 3px rgba(142, 92, 255, 0.15);
}

/* --- 重试按钮（错误消息底部） --- */
.chat-retry-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--accent-solid, #8e5cff);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chat-retry-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

/* --- 代码块语言标签 --- */
.chat-code-lang {
  padding: 4px 10px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  background: rgba(127, 127, 127, 0.08);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-radius: 12px 12px 0 0;
}

/* --- 展开按钮 is-expanded 状态 --- */
.chat-expand-btn.is-expanded {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

/* --- 滚动到底部按钮 --- */
.chat-scroll-down-btn {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: var(--shadow-strong);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, opacity 0.2s ease;
  animation: chat-bounce-up 2s ease infinite;
}

.chat-scroll-down-btn:hover {
  transform: translateX(-50%) scale(1.1);
}

@keyframes chat-bounce-up {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-6px); }
}

/* 消息容器相对定位，供滚动按钮定位 */
.chat-messages {
  position: relative;
}

/* --- Chat 消息气泡微调 --- */
.chat-msg-bubble {
  transition: box-shadow 0.2s ease;
}

.chat-msg--ai .chat-msg-bubble:hover {
  box-shadow: 0 2px 12px rgba(31, 35, 48, 0.06);
}

/* ==================== 2026-08 Chat 视觉收敛 ==================== */
.chat-layout {
  gap: 14px;
  padding: 14px;
}

.chat-sidebar {
  width: 248px;
  padding: 0;
}

.chat-sidebar.collapsed {
  width: 40px;
  overflow: visible;
}

.chat-sidebar-inner {
  width: 248px;
  border-radius: 26px;
  box-shadow: 0 14px 36px rgba(31,35,48,.09);
}

.chat-sidebar.collapsed .chat-sidebar-inner {
  width: 40px;
  height: 40px;
  overflow: visible;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.chat-sidebar.collapsed .chat-sidebar-inner::before {
  border: 0;
  background: transparent;
  opacity: 0;
}

.chat-sidebar.collapsed .chat-sidebar-header {
  border: 0;
  padding: 0;
  background: transparent;
}

.chat-sidebar.collapsed .chat-sidebar-title-row {
  padding: 0;
}

.chat-sidebar.collapsed .chat-sidebar-toggle-btn {
  position: relative;
  z-index: 3;
  box-shadow: var(--shadow);
}

.chat-sidebar-inner::before { opacity: .76; }

.chat-sidebar-header {
  padding: 5px 4px 13px;
}

.chat-sidebar-title-row { padding: 11px 10px 9px; }

.chat-history-search-wrap { padding: 0 10px; }

.chat-history-search {
  height: 38px;
  padding: 0 13px;
  border-color: transparent;
  border-radius: 14px;
  background: rgba(127,127,127,.08);
  font-size: .8rem;
}

[data-theme="dark"] .chat-history-search { background: rgba(255,255,255,.055); }

.chat-history-search:focus {
  border-color: rgba(142,92,255,.26);
  background: color-mix(in srgb, var(--card-strong) 86%, transparent);
  box-shadow: 0 0 0 3px rgba(142,92,255,.08);
}

.chat-sidebar-list {
  padding: 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(142,92,255,.28) transparent;
}

.chat-sidebar-list::-webkit-scrollbar { width: 6px; }
.chat-sidebar-list::-webkit-scrollbar-track { background: transparent; }
.chat-sidebar-list::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: rgba(142,92,255,.32);
  background-clip: padding-box;
}

.chat-sidebar-empty {
  margin: 12px 4px;
  padding: 18px 14px;
  border: 1px solid color-mix(in srgb, var(--border) 78%, transparent);
  border-radius: 16px;
  background: linear-gradient(135deg,rgba(142,92,255,.06),rgba(35,213,255,.035));
  line-height: 1.6;
  color: var(--muted);
  font-size: .82rem;
}

.chat-sidebar-item {
  min-height: 58px;
  margin: 0 0 7px;
  padding: 10px 9px 10px 13px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255,255,255,.1);
  box-shadow: 0 5px 16px rgba(31,35,48,.035);
  overflow: hidden;
  transition: transform .18s ease, background .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.chat-sidebar-item::before {
  content: '';
  align-self: stretch;
  width: 3px;
  margin: -2px 2px -2px -5px;
  border-radius: 999px;
  background: transparent;
  flex: 0 0 auto;
}

.chat-sidebar-item:hover {
  transform: translateY(-2px);
  border-color: rgba(142,92,255,.18);
  background: color-mix(in srgb, var(--card-strong) 82%, transparent);
  box-shadow: 0 10px 24px rgba(31,35,48,.07);
}

.chat-sidebar-item--active {
  border-color: rgba(142,92,255,.24);
  background: linear-gradient(135deg,rgba(142,92,255,.12),rgba(35,213,255,.055));
  box-shadow: 0 8px 22px rgba(142,92,255,.08);
}

.chat-sidebar-item--active::before { background: var(--accent); }
.chat-sidebar-item-title { font-size: .82rem; font-weight: 700; }
.chat-sidebar-item-time { font-size: .66rem; }

.chat-sidebar-item-delete,
.chat-sidebar-item-rename {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: rgba(127,127,127,.06);
}

.chat-main {
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: linear-gradient(135deg,rgba(18,23,40,.58),rgba(18,23,40,.34));
  box-shadow: 0 14px 38px rgba(31,35,48,.07);
  overflow: hidden;
}

.chat-topbar { padding: 11px 16px; }
.chat-topbar-right { gap: 8px; }
.chat-topbar-btn--icon,
.chat-topbar-settings {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: rgba(127,127,127,.07);
  box-shadow: none;
  text-decoration: none;
}
.chat-topbar-settings {
  width: auto;
  gap: 7px;
  padding: 0 12px;
  color: var(--text);
  font-size: .78rem;
  font-weight: 800;
}
.chat-topbar-settings:hover {
  background: rgba(142,92,255,.1);
  color: var(--accent-solid);
}

.chat-connection-status { max-width: 250px; }

.chat-messages {
  padding: 22px 24px;
  scrollbar-width: thin;
  scrollbar-color: rgba(142,92,255,.3) transparent;
}

.chat-messages::-webkit-scrollbar { width: 8px; }
.chat-messages::-webkit-scrollbar-track { margin: 14px 0; background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: rgba(142,92,255,.46);
  background-clip: padding-box;
}

.chat-welcome {
  width: min(700px, 100%);
  margin: auto;
  padding: 18px;
}

.chat-welcome-panel {
  display: grid;
  justify-items: center;
  padding: 28px 30px 26px;
  border: 1px solid color-mix(in srgb, var(--border) 82%, transparent);
  border-radius: 26px;
  background: linear-gradient(135deg,rgba(18,23,40,.78),rgba(18,23,40,.54));
  box-shadow: 0 18px 44px rgba(0,0,0,.16);
  backdrop-filter: blur(14px);
}

[data-theme="dark"] .chat-welcome-panel {
  background: linear-gradient(135deg,rgba(20,25,42,.72),rgba(20,25,42,.42));
}

.chat-welcome-panel h2 {
  margin-top: 12px;
}

.chat-welcome-panel p {
  max-width: 520px;
}

.chat-starter-grid {
  width: 100%;
  gap: 12px;
}

.chat-starter {
  min-height: 68px;
  justify-content: flex-start;
  align-items: flex-start;
  gap: 7px;
  padding: 15px 16px;
  border: 1px solid color-mix(in srgb, var(--border) 84%, transparent);
  border-radius: 16px;
  background: rgba(255,255,255,.035);
  text-align: left;
  box-shadow: none;
}

.chat-starter:hover {
  background: rgba(142,92,255,.09);
  border-color: rgba(142,92,255,.24);
}

.chat-starter span {
  color: var(--accent-solid);
  font-size: .68rem;
  font-weight: 900;
}

.chat-starter strong {
  color: var(--text);
  font-size: .9rem;
  line-height: 1.35;
}

.chat-input-panel {
  width: calc(100% - 32px);
  margin: 0 auto 16px;
  padding: 9px 11px 8px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--card-strong) 88%, transparent);
  box-shadow: 0 14px 38px rgba(31,35,48,.12);
  position: relative;
  z-index: 20;
}

.chat-input-panel .chat-input-row--main {
  border-color: color-mix(in srgb, var(--border) 88%, transparent);
  background: rgba(127,127,127,.055);
}

.chat-input-panel .chat-input-row--main:focus-within {
  border-color: rgba(142,92,255,.38);
  box-shadow: 0 0 0 3px rgba(142,92,255,.09);
}

.chat-textarea { border-color: transparent; background: transparent; }
[data-theme="dark"] .chat-textarea { background: transparent; }

.chat-depth-control {
  gap: 7px;
  min-height: 34px;
  border-color: transparent;
  border-radius: 13px;
  background: rgba(127,127,127,.07);
}

[data-theme="dark"] .chat-depth-control { background: rgba(255,255,255,.055); }

.chat-depth-slider {
  width: 76px;
  height: 18px;
  margin: 0;
  cursor: pointer;
  background: transparent;
}

.chat-depth-slider::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent-solid) 44%, var(--border));
}

.chat-depth-slider::-moz-range-track {
  height: 5px;
  border: 0;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent-solid) 44%, var(--border));
}

.chat-depth-slider::-webkit-slider-thumb {
  width: 15px;
  height: 15px;
  margin-top: -5px;
  border: 3px solid color-mix(in srgb,var(--bg-2) 86%,white);
  background: var(--accent-solid);
  box-shadow: 0 3px 10px rgba(142,92,255,.35);
}

.chat-depth-slider::-moz-range-thumb {
  width: 11px;
  height: 11px;
  border: 3px solid color-mix(in srgb,var(--bg-2) 86%,white);
  background: var(--accent-solid);
  box-shadow: 0 3px 10px rgba(142,92,255,.35);
}

.chat-input-tools-left,
.chat-select-wrap {
  position: relative;
}

.chat-select-menu {
  top: auto;
  bottom: calc(100% + 8px);
  z-index: 500;
  background: color-mix(in srgb, var(--card-strong) 94%, transparent);
}

[data-theme="dark"] .chat-msg--ai .chat-msg-bubble:hover {
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
}

/* 2026-08 对话消息层级：气泡、元信息和操作按钮组成一个稳定纵向组 */
.chat-msg {
  max-width: min(88%, 860px);
}

.chat-msg-body {
  display: flex;
  min-width: 0;
  max-width: 100%;
  flex-direction: column;
  align-items: flex-start;
}

.chat-msg--user .chat-msg-body { align-items: flex-end; }

.chat-msg--user .chat-msg-bubble {
  max-width: min(720px, 100%);
  border-color: rgba(142,92,255,.24);
  background: linear-gradient(135deg,rgba(142,92,255,.22),rgba(35,213,255,.10));
  color: var(--text);
  box-shadow: 0 10px 28px rgba(31,35,48,.08);
}

[data-theme="dark"] .chat-msg--user .chat-msg-bubble {
  border-color: rgba(142,92,255,.28);
  background: linear-gradient(135deg,rgba(76,58,133,.72),rgba(29,76,104,.58));
  color: #f5f6ff;
}

.chat-msg--ai .chat-msg-bubble {
  width: min(760px, 100%);
  max-width: 100%;
  border-color: color-mix(in srgb, var(--border) 86%, transparent);
  border-radius: 20px;
  background: color-mix(in srgb, var(--card-strong) 88%, transparent);
  box-shadow: 0 10px 30px rgba(31,35,48,.07);
}

.chat-msg-time {
  margin: 5px 5px 0 !important;
  opacity: .55;
}

.chat-msg-actions,
.chat-msg--user .chat-msg-actions {
  min-height: 28px;
  margin: 5px 4px 0;
  padding: 0;
  justify-content: flex-start;
}

.chat-msg--user .chat-msg-actions { justify-content: flex-end; }
.chat-msg:focus-within .chat-msg-actions { opacity: 1; }

.chat-msg-reasoning {
  margin: 0 0 14px;
  padding: 11px 13px;
  border-color: rgba(142,92,255,.18);
  border-radius: 14px;
  background: rgba(142,92,255,.065);
}

.chat-reasoning-header { margin: 0; cursor: default; }
.chat-msg-reasoning.is-complete .chat-reasoning-header { cursor: pointer; }
.chat-msg-reasoning.is-complete .chat-reasoning-header::after {
  content: '›';
  margin-left: auto;
  transform: rotate(90deg);
  transition: transform .18s ease;
}
.chat-msg-reasoning.is-complete.is-collapsed .chat-reasoning-header::after { transform: rotate(0); }
.chat-msg-reasoning.is-collapsed .chat-reasoning-content { display: none; }
.chat-reasoning-content {
  max-height: none;
  margin-top: 8px;
  overflow: visible;
}

.chat-stop-btn {
  width: 42px;
  height: 42px;
  border: 1px solid rgba(239,90,81,.38);
  background: rgba(239,90,81,.15);
  color: #ff6b62;
  font-size: .78rem;
  box-shadow: none;
}

.chat-stop-btn:hover {
  background: rgba(239,90,81,.23);
  box-shadow: 0 8px 20px rgba(239,90,81,.15);
}
