/* =====================================================
   咨询助手 v2.3 全量重构样式表（1:1 复刻简洁扁平模块矩阵 + 严格左右边缘对齐 + 右下角大号发送按钮）（新增：01研究背景 -> 多行业切换 -> 02研究概览 -> 03研究框架 -> 04分章研究 结构化工作台）
   支持三套完整皮肤主题色：
   1. 深空宇宙蓝商务风 (data-theme="cosmic"，默认)
   2. 经典浅色青绿 (data-theme="light")
   3. 暖色调护眼 (data-theme="warm")
   ===================================================== */

/* 1. 默认：深空宇宙蓝商务风 */
:root,
[data-theme="cosmic"] {
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-soft: rgba(59, 130, 246, 0.16);
  --primary-border: rgba(96, 165, 250, 0.38);
  --primary-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);

  --bg-page: #070d19;
  --bg-card: #0f172a;
  --bg-card-user: #13223a;
  --bg-sidebar: #0a1120;
  --bg-surface: #141f35;
  --bg-surface-hover: #1d2c49;
  --bg-input: #0b1324;
  --bg-api-panel: #080f1d;
  --bg-quote: #111d33;

  --group-tag-bg: rgba(59, 130, 246, 0.18);
  --group-tag-text: #93c5fd;
  --group-tag-border: rgba(96, 165, 250, 0.32);

  --pill-bg: #16233b;
  --pill-border: #283b5e;
  --pill-text: #dbeafe;
  --pill-hover-bg: #1e3152;
  --pill-hover-border: #60a5fa;

  --border: #1e2d48;
  --border-strong: #2d4268;

  --text-main: #e2e8f0;
  --text-strong: #f8fafc;
  --text-sub: #94a3b8;
  --text-muted: #64748b;

  --danger: #ef4444;
  --error-bg: rgba(239, 68, 68, 0.14);
  --error-border: rgba(248, 113, 113, 0.4);
  --error-text: #fca5a5;

  --warn-bg: rgba(245, 158, 11, 0.14);
  --warn-border: rgba(245, 158, 11, 0.38);
  --warn-text: #fcd34d;

  --badge-personal-bg: rgba(14, 165, 233, 0.18);
  --badge-personal-text: #7dd3fc;
  --badge-need-bg: rgba(239, 68, 68, 0.18);
  --badge-need-text: #fca5a5;

  --logo-bg: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  --module-icon-bg: linear-gradient(135deg, #1e3a8a 0%, #172554 100%);
  --shadow-popover: 0 12px 30px rgba(0, 0, 0, 0.55);
}

/* 2. 经典浅色青绿配色 */
[data-theme="light"] {
  --primary: #0f766e;
  --primary-hover: #0d645d;
  --primary-soft: #e6f4f1;
  --primary-border: #99d5cc;
  --primary-shadow: 0 4px 12px rgba(15, 118, 110, 0.24);

  --bg-page: #f3f6f8;
  --bg-card: #ffffff;
  --bg-card-user: #edf8f6;
  --bg-sidebar: #fafbfc;
  --bg-surface: #f4f8f8;
  --bg-surface-hover: #e7f0ef;
  --bg-input: #ffffff;
  --bg-api-panel: #f6f8fa;
  --bg-quote: #f4f8f8;

  --group-tag-bg: #e2f2ef;
  --group-tag-text: #0f766e;
  --group-tag-border: #b5dfd8;

  --pill-bg: #ffffff;
  --pill-border: #cde3df;
  --pill-text: #1e3a38;
  --pill-hover-bg: #e6f4f1;
  --pill-hover-border: #0f766e;

  --border: #e2e8ee;
  --border-strong: #cbd5e1;

  --text-main: #1f2937;
  --text-strong: #111827;
  --text-sub: #64748b;
  --text-muted: #94a3b8;

  --danger: #dc2626;
  --error-bg: #fef2f2;
  --error-border: #fecaca;
  --error-text: #991b1b;

  --warn-bg: #fffbeb;
  --warn-border: #f59e0b;
  --warn-text: #92400e;

  --badge-personal-bg: #e0f2fe;
  --badge-personal-text: #0369a1;
  --badge-need-bg: #fef2f2;
  --badge-need-text: #dc2626;

  --logo-bg: linear-gradient(135deg, #0f766e 0%, #115e59 100%);
  --module-icon-bg: #1e293b;
  --shadow-popover: 0 10px 25px rgba(15, 23, 42, 0.14);
}

/* 3. 暖色调护眼配色 */
[data-theme="warm"] {
  --primary: #b45309;
  --primary-hover: #92400e;
  --primary-soft: #f5e6d3;
  --primary-border: #deb88c;
  --primary-shadow: 0 4px 12px rgba(180, 83, 9, 0.24);

  --bg-page: #f3ede2;
  --bg-card: #fbf8f1;
  --bg-card-user: #f3eadc;
  --bg-sidebar: #ede5d8;
  --bg-surface: #f5efe3;
  --bg-surface-hover: #e7dcc8;
  --bg-input: #fdfbf6;
  --bg-api-panel: #e8dfd0;
  --bg-quote: #f3ece0;

  --group-tag-bg: #efe0ca;
  --group-tag-text: #92400e;
  --group-tag-border: #dcc09b;

  --pill-bg: #fdfaf3;
  --pill-border: #dec9ac;
  --pill-text: #452c16;
  --pill-hover-bg: #f5e6d3;
  --pill-hover-border: #b45309;

  --border: #ddd2bf;
  --border-strong: #cbbba2;

  --text-main: #3b2f26;
  --text-strong: #231912;
  --text-sub: #736051;
  --text-muted: #9b8878;

  --danger: #c2410c;
  --error-bg: #fef2ee;
  --error-border: #f5c6b5;
  --error-text: #9a3412;

  --warn-bg: #f8eed9;
  --warn-border: #d9a05b;
  --warn-text: #854d0e;

  --badge-personal-bg: #e6efe9;
  --badge-personal-text: #276749;
  --badge-need-bg: #fce8e4;
  --badge-need-text: #c2410c;

  --logo-bg: linear-gradient(135deg, #b45309 0%, #92400e 100%);
  --module-icon-bg: #5c4033;
  --shadow-popover: 0 10px 25px rgba(59, 47, 38, 0.16);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  background: var(--bg-page);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
  line-height: 1.65;
  transition: background-color 0.2s ease, color 0.2s ease;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 99px;
}

.app-shell {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ================= 左侧边栏 ================= */
.sidebar {
  width: 276px;
  min-width: 276px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width 0.2s ease, min-width 0.2s ease;
  z-index: 20;
}

.sidebar.collapsed {
  width: 0;
  min-width: 0;
  overflow: hidden;
  border-right: none;
}

.sidebar-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 14px 12px 10px;
  gap: 6px;
}

.brand {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 9px;
  background: var(--logo-bg);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}

.brand-text {
  min-width: 0;
}

.brand-title-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.brand-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-strong);
  line-height: 1.25;
}

.version-tag {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-soft);
  border: 1px solid var(--primary-border);
  padding: 0 5px;
  border-radius: 4px;
  line-height: 1.45;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-sub);
  line-height: 1.35;
  margin-top: 2px;
}

.brand-author {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.35;
  margin-top: 1px;
  font-weight: 500;
}

.sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

/* 主题设置弹出菜单 */
.theme-menu-wrap {
  position: relative;
}

.theme-popover {
  position: absolute;
  top: 34px;
  right: 0;
  width: 196px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 6px;
  box-shadow: var(--shadow-popover);
  z-index: 60;
}

.theme-popover[hidden] {
  display: none;
}

.theme-popover-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-sub);
  padding: 4px 8px 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.theme-option {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-main);
  font-size: 12.5px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}

.theme-option:hover {
  background: var(--bg-surface-hover);
}

.theme-option.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.theme-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(128, 128, 128, 0.35);
  flex-shrink: 0;
}

.swatch-cosmic {
  background: linear-gradient(135deg, #0b132b 45%, #3b82f6 100%);
}

.swatch-light {
  background: linear-gradient(135deg, #f5f7f9 45%, #0f766e 100%);
}

.swatch-warm {
  background: linear-gradient(135deg, #f4efe6 45%, #b45309 100%);
}

.theme-name {
  flex: 1;
}

.theme-check {
  opacity: 0;
  font-size: 12px;
  font-weight: 700;
}

.theme-option.active .theme-check {
  opacity: 1;
}

.sidebar-actions {
  padding: 0 12px 10px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-full {
  width: 100%;
}

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-sub);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

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

/* 历史会话区 */
.history-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0 10px;
}

.section-label {
  font-size: 12px;
  color: var(--text-sub);
  padding: 2px 6px 6px;
  font-weight: 500;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-main);
  font-size: 13px;
  transition: background 0.15s;
}

.history-item:hover {
  background: var(--bg-surface-hover);
}

.history-item.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.history-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  margin-right: 6px;
}

.history-ops {
  display: none;
  gap: 4px;
}

.history-item:hover .history-ops {
  display: flex;
}

.mini-op-btn {
  border: none;
  background: transparent;
  color: var(--text-sub);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 4px;
}

.mini-op-btn:hover {
  background: var(--bg-surface);
  color: var(--text-strong);
}

.backup-bar {
  display: flex;
  gap: 6px;
  padding: 8px 4px;
  border-top: 1px dashed var(--border);
  margin-top: 6px;
}

.btn-ghost {
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-sub);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12px;
  cursor: pointer;
}

.btn-ghost:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* 左下角 API 与模型控制面板 */
.api-panel {
  border-top: 1px solid var(--border);
  padding: 10px 12px 12px;
  background: var(--bg-api-panel);
}

.api-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.api-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-strong);
}

.channel-badge {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 99px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 500;
}

.channel-badge.personal {
  background: var(--badge-personal-bg);
  color: var(--badge-personal-text);
}

.channel-badge.need-key {
  background: var(--badge-need-bg);
  color: var(--badge-need-text);
}

.key-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.key-input {
  width: 100%;
  padding: 6px 28px 6px 9px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 12px;
  background: var(--bg-input);
  color: var(--text-main);
  outline: none;
}

.key-input:focus {
  border-color: var(--primary);
}

.eye-btn {
  position: absolute;
  right: 6px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-sub);
  font-size: 13px;
}

.api-tip {
  font-size: 11px;
  color: var(--warn-text);
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 6px;
  padding: 5px 8px;
  margin: 7px 0 9px;
  line-height: 1.4;
}

.model-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-strong);
}

.model-select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg-input);
  font-size: 12px;
  color: var(--text-main);
  outline: none;
}

.model-select:focus {
  border-color: var(--primary);
}

/* ================= 右侧主区 ================= */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-page);
}

.topbar {
  height: 52px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 12px;
  flex-shrink: 0;
}

.mobile-menu-btn {
  display: inline-flex;
}

.module-badge-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--module-icon-bg);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

.module-title {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text-strong);
  line-height: 1.3;
}

.module-desc {
  font-size: 11.5px;
  color: var(--text-sub);
  line-height: 1.3;
}

/* ================= 对话视口与严格左右对齐几何 =================
   几何规范（以主内容列左右边界为基准）：
   - 左侧统一留白：24px
   - 右侧发送按钮区预留：16px(右边距) + 126px(大号发送按钮) + 14px(间距) = 156px
   - 上方输出框（.welcome-card / .msg-card.assistant）、三组功能区（.module-matrix）、
     以及下方输入框（.input-box）全部严格对齐：
     左边缘 = 24px，右边缘 = 156px！
   ================================================================ */
.chat-viewport {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px 16px 24px;
}

.chat-container {
  width: 100%;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.welcome-card {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px 26px;
}

.welcome-card h2 {
  font-size: 17px;
  color: var(--primary);
  margin-bottom: 10px;
}

.welcome-card p {
  color: var(--text-sub);
  margin-bottom: 12px;
}

.welcome-tips {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-main);
}

.welcome-tips li {
  margin-left: 18px;
  margin-bottom: 4px;
}

.msg-card {
  border-radius: 12px;
  padding: 16px 22px;
  border: 1px solid var(--border);
  background: var(--bg-card);
}

.msg-card.assistant {
  align-self: flex-start;
  width: 100%;
  border-radius: 14px 14px 14px 4px;
}

.msg-card.user {
  align-self: flex-end;
  margin-left: auto;
  width: fit-content;
  min-width: 180px;
  max-width: 78%;
  padding: 12px 18px;
  background: var(--bg-card-user);
  border-color: var(--primary-border);
  border-radius: 14px 14px 4px 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.msg-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.msg-img-thumb {
  max-width: 200px;
  max-height: 150px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  object-fit: cover;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.msg-img-thumb:hover {
  transform: scale(1.02);
}

.attach-thumb {
  width: 18px;
  height: 18px;
  border-radius: 3px;
  object-fit: cover;
  border: 1px solid var(--primary-border);
}

.msg-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--text-sub);
}

.msg-role {
  font-weight: 700;
  color: var(--text-strong);
}

.msg-actions {
  display: flex;
  gap: 8px;
}

.msg-action-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-sub);
  border-radius: 6px;
  padding: 2px 9px;
  font-size: 12px;
  cursor: pointer;
}

.msg-action-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* Markdown 正文排版 */
.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  margin-top: 14px;
  margin-bottom: 7px;
  color: var(--text-strong);
  line-height: 1.4;
}

.markdown-body h2 {
  font-size: 16px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--border);
}

.markdown-body h3 {
  font-size: 14.5px;
}

.markdown-body p {
  margin-bottom: 9px;
}

.markdown-body ul,
.markdown-body ol {
  margin: 6px 0 10px 22px;
}

.markdown-body li {
  margin-bottom: 4px;
}

.markdown-body blockquote {
  border-left: 3.5px solid var(--primary);
  background: var(--bg-quote);
  padding: 9px 14px;
  margin: 9px 0;
  border-radius: 0 8px 8px 0;
  color: var(--text-main);
}

.markdown-body hr {
  border: none;
  border-top: 1px dashed var(--border-strong);
  margin: 14px 0;
}

.markdown-body strong {
  color: var(--text-strong);
}

.markdown-body code {
  background: var(--bg-surface);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12.5px;
}

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

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

.markdown-body th {
  background: var(--bg-surface);
  color: var(--text-strong);
  font-weight: 600;
}

.loading-hint {
  color: var(--text-sub);
}

.error-banner {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error-text);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
}

/* ================= 底部控制区：精致主题三组矩阵 + 对齐拉宽输入框 + 右下角大号发送按钮 ================= */
.composer-area {
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 10px 24px 14px 24px;
  flex-shrink: 0;
}

/* 三组功能区（参考图1简洁扁平质感，无多余外框，严格左对齐） */
.module-matrix {
  width: 100%;
  margin: 0 0 8px 0;
  padding: 2px 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.matrix-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.matrix-group-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-sub);
  min-width: 68px;
  line-height: 1.4;
}

.module-pill {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-main);
  border-radius: 6px;
  padding: 3px 11px;
  font-size: 12.5px;
  line-height: 1.4;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.module-pill:hover:not(.disabled) {
  background: var(--bg-surface-hover);
  color: var(--primary);
}

.module-pill.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.16);
}

.module-pill.disabled {
  background: transparent;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  opacity: 0.72;
  cursor: not-allowed;
}

/* 附件 & 临时标准预览条 */
.attachment-strip {
  width: auto;
  margin: 0 0 8px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid var(--primary-border);
  border-radius: 6px;
  padding: 2px 9px;
  font-size: 11.5px;
}

.attach-chip.temp-standard {
  background: var(--warn-bg);
  color: var(--warn-text);
  border-color: var(--warn-border);
}

.attach-remove {
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
  line-height: 1;
}

/* 下方输入框 + 右下角大号发送按钮 */
.composer-row {
  width: 100%;
  margin: 0;
  display: flex;
  align-items: stretch;
  gap: 14px;
}

.input-box {
  flex: 1;
  min-width: 0;
  margin: 0;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--bg-input);
  padding: 8px 12px 6px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}

.input-box textarea {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.45;
  min-height: 42px;
  max-height: 120px;
  background: transparent;
  color: var(--text-main);
}

.input-box textarea::placeholder {
  color: var(--text-muted);
}

.input-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 5px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  gap: 10px;
}

.toolbar-left-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.toolbar-divider {
  width: 1px;
  height: 14px;
  background: var(--border-strong);
  display: inline-block;
}

.toolbar-hint {
  font-size: 11.5px;
  color: var(--text-muted);
}

.tool-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-sub);
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.tool-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}

.kb-trigger-btn.active {
  background: var(--primary-soft);
  border-color: var(--primary-border);
  color: var(--primary);
  font-weight: 600;
}

.btn-send {
  width: 132px;
  min-height: 84px;
  flex-shrink: 0;
  background: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: 12px;
  padding: 0 20px;
  font-size: 16.5px;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  box-shadow: var(--primary-shadow);
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.btn-send:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-send:active {
  transform: scale(0.98);
}

.btn-send.stop {
  background: var(--danger);
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.35);
}

/* ================= 知识库双层弹窗 ================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(7, 13, 25, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

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

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  width: 92%;
  max-width: 580px;
  box-shadow: var(--shadow-popover);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 84vh;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 15px;
  color: var(--text-strong);
}

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.modal-footer {
  padding: 11px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-footer-hint {
  font-size: 11.5px;
  color: var(--text-sub);
}

.kb-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.kb-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.kb-section-title {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-strong);
}

.kb-section-sub {
  font-size: 11.5px;
  color: var(--text-sub);
  margin-top: 1px;
}

.kb-upload-btn {
  background: var(--warn-bg);
  color: var(--warn-text);
  border: 1px solid var(--warn-border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.kb-upload-btn:hover {
  filter: brightness(1.06);
}

.kb-divider {
  border: none;
  border-top: 1px dashed var(--border-strong);
}

.kb-empty {
  background: var(--bg-surface);
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 12.5px;
  color: var(--text-sub);
  line-height: 1.55;
}

.kb-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-main);
  background: var(--bg-surface);
}

.kb-item:hover {
  border-color: var(--primary);
}

.kb-item-desc {
  font-size: 12px;
  color: var(--text-sub);
}

.temp-std-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 11px;
  border: 1px solid var(--warn-border);
  background: var(--warn-bg);
  color: var(--warn-text);
  border-radius: 8px;
  font-size: 12.5px;
}

.temp-std-info {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.temp-std-remove {
  border: none;
  background: transparent;
  color: var(--warn-text);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

.temp-std-remove:hover {
  background: rgba(0, 0, 0, 0.12);
}

.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-strong);
  color: var(--bg-page);
  padding: 7px 16px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 500;
  z-index: 99;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

/* ================= 结构化研究工作台（行业研究、标杆研究：左侧 80% 工作台 + 右侧 20% 对话栏） ================= */
.workspace-body {
  flex: 1;
  display: flex;
  min-height: 0;
  min-width: 0;
  width: 100%;
  overflow: hidden;
}

.primary-column {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.main-area.split-mode .primary-column {
  flex: 0 0 80%;
  width: 80%;
  max-width: 80%;
}

/* 在行业研究/标杆研究工作台模式下，去掉底部重复大输入框，只保留三组模块切换矩阵 */
.main-area.split-mode .composer-area {
  padding: 8px 20px 10px 20px;
}

.main-area.split-mode .module-matrix {
  margin: 0;
  width: 100%;
}

.main-area.split-mode .attachment-strip,
.main-area.split-mode .composer-row {
  display: none !important;
}

/* 左侧 80% 结构化工作台主滚动区 */
.research-workbench {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.research-workbench[hidden] {
  display: none;
}

.wb-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 15px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.wb-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.wb-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex-wrap: wrap;
}

.wb-step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11.5px;
  font-weight: 800;
  color: #ffffff;
  background: var(--primary);
  border-radius: 5px;
  padding: 1px 7px;
  line-height: 1.4;
}

.wb-card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-strong);
}

.wb-card-sub {
  font-size: 12px;
  color: var(--text-sub);
}

.wb-header-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.wb-ai-btn {
  background: var(--primary);
  color: #ffffff;
  border: 1px solid var(--primary);
  border-radius: 6px;
  padding: 4px 11px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease;
}

.wb-ai-btn:hover {
  background: var(--primary-hover);
}

.wb-ai-btn-outline {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary-border);
}

.wb-ai-btn-outline:hover {
  background: var(--primary);
  color: #ffffff;
}

/* 01 研究背景输入框 */
.wb-bg-textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg-input);
  color: var(--text-main);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.45;
  padding: 7px 11px;
  resize: vertical;
  min-height: 44px;
  outline: none;
  transition: border-color 0.15s;
}

.wb-bg-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}

/* 研究行业 / 标杆切换条 */
.wb-target-bar {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 8px 15px;
  gap: 12px;
  flex-wrap: wrap;
}

.wb-target-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.wb-target-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-strong);
}

.wb-add-btn {
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid var(--primary-border);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.wb-add-btn:hover {
  background: var(--primary);
  color: #ffffff;
}

.wb-target-tabs {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  min-width: 0;
}

.wb-empty-inline {
  font-size: 12px;
  color: var(--text-muted);
}

.wb-target-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: 7px;
  border: 1px solid var(--pill-border);
  background: var(--pill-bg);
  color: var(--pill-text);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.wb-target-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.wb-target-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  font-weight: 600;
}

.wb-target-del {
  border: none;
  background: transparent;
  color: inherit;
  opacity: 0.75;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0 2px;
}

.wb-target-del:hover {
  opacity: 1;
}

/* 02 研究概览（左右双栏：研究对象与范围 + 核心研究问题） */
.wb-overview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.wb-overview-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.wb-sub-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-sub);
}

.wb-overview-textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg-input);
  color: var(--text-main);
  font-family: inherit;
  font-size: 12.5px;
  line-height: 1.45;
  padding: 7px 10px;
  resize: vertical;
  min-height: 62px;
  outline: none;
}

.wb-overview-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}

/* 03 研究框架（左 32%） + 04 分章研究（右 68%） */
.wb-bottom-split {
  flex: 1;
  min-height: 310px;
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.wb-framework-card {
  flex: 0 0 32%;
  width: 32%;
  min-width: 230px;
  display: flex;
  flex-direction: column;
}

.wb-tree-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.wb-icon-op {
  width: 28px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-main);
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.wb-icon-op:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}

.wb-chapter-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding-right: 2px;
}

.wb-chapter-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-main);
  font-size: 12.5px;
  line-height: 1.4;
  cursor: pointer;
  transition: all 0.15s;
}

.wb-chapter-item:hover {
  border-color: var(--primary);
  background: var(--bg-surface-hover);
}

.wb-chapter-item.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--text-strong);
  font-weight: 600;
}

.wb-chapter-name {
  flex: 1;
  min-width: 0;
}

.wb-chapter-status {
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 4px;
  flex-shrink: 0;
  background: var(--bg-card);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.wb-chapter-status.done {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary-border);
  font-weight: 600;
}

.wb-chapter-detail-card {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.wb-chapter-content {
  flex: 1;
  overflow-y: auto;
  padding: 10px 6px 6px 2px;
  line-height: 1.72;
}

.wb-empty-block {
  padding: 16px 14px;
  border-radius: 8px;
  border: 1px dashed var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-sub);
  font-size: 12.5px;
  line-height: 1.6;
}

/* ================= 右侧 20% 固定对话研讨区 ================= */
.side-discuss-panel {
  flex: 0 0 20%;
  width: 20%;
  min-width: 265px;
  height: 100%;
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.side-discuss-panel[hidden] {
  display: none;
}

.side-discuss-header {
  padding: 11px 12px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
  flex-shrink: 0;
}

.side-discuss-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-strong);
  line-height: 1.3;
}

.side-discuss-sub {
  font-size: 11px;
  color: var(--text-sub);
  margin-top: 2px;
  line-height: 1.3;
}

.side-discuss-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.side-empty-tip {
  font-size: 12px;
  color: var(--text-sub);
  background: var(--bg-surface);
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.55;
}

.side-msg {
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 12.5px;
  line-height: 1.55;
  border: 1px solid var(--border);
  word-break: break-word;
}

.side-msg.user {
  align-self: flex-end;
  max-width: 92%;
  background: var(--bg-card-user);
  border-color: var(--primary-border);
  color: var(--text-strong);
}

.side-msg.assistant {
  align-self: flex-start;
  width: 100%;
  background: var(--bg-card);
  color: var(--text-main);
}

.side-msg-meta {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-sub);
  margin-bottom: 4px;
}

.side-msg .markdown-body p {
  margin-bottom: 6px;
}

.side-msg .markdown-body ul,
.side-msg .markdown-body ol {
  margin: 4px 0 6px 16px;
}

.side-attach-strip {
  padding: 5px 10px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.side-discuss-composer {
  padding: 8px 10px 10px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.side-sync-actions {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.btn-sync-report {
  width: 100%;
  background: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-sync-report:hover {
  background: var(--primary-hover);
}

.btn-sync-secondary {
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid var(--primary-border);
}

.btn-sync-secondary:hover {
  background: var(--primary);
  color: #ffffff;
}

.side-tools-bar {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tool-btn-xs {
  padding: 2px 8px;
  font-size: 11.5px;
}

.side-input-wrap {
  display: flex;
  flex-direction: column;
  gap: 5px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg-input);
  padding: 6px 8px;
}

.side-input-wrap:focus-within {
  border-color: var(--primary);
}

.side-input-wrap textarea {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 12.5px;
  line-height: 1.4;
  min-height: 44px;
  max-height: 100px;
  background: transparent;
  color: var(--text-main);
}

.btn-side-send {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 5px;
  padding: 3px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.btn-side-send:hover {
  background: var(--primary-hover);
}

.btn-side-send.stop {
  background: var(--danger);
}

@media (max-width: 1100px) {
  .main-area.split-mode .primary-column {
    flex: 1;
    width: auto;
    max-width: none;
  }
  .side-discuss-panel {
    flex: 0 0 275px;
    width: 275px;
  }
  .wb-overview-grid {
    grid-template-columns: 1fr;
  }
  .wb-bottom-split {
    flex-direction: column;
  }
  .wb-framework-card {
    flex: none;
    width: 100%;
  }
}

@media (max-width: 768px) {
  .workspace-body {
    flex-direction: column;
  }
  .main-area.split-mode .primary-column {
    flex: 1;
    width: 100%;
    max-width: 100%;
    height: 62%;
  }
  .side-discuss-panel {
    flex: 0 0 38%;
    width: 100%;
    min-width: 0;
    height: 38%;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .sidebar {
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.25);
  }
  .chat-viewport {
    padding: 12px;
  }
  .composer-area {
    padding: 8px 12px 10px;
  }
  .module-matrix,
  .attachment-strip {
    margin-right: 0;
  }
  .msg-card.user {
    max-width: 88%;
  }
  .btn-send {
    width: 84px;
    min-height: 64px;
    font-size: 14px;
    padding: 0 10px;
  }
}
