/* ============== 基础 ============== */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #f4f5f7;
  color: #222;
  display: flex; flex-direction: column;
}

button { cursor: pointer; border: 1px solid #d0d4dc; background: #fff;
  padding: 6px 12px; border-radius: 6px; font-size: 13px; }
button:hover { background: #f0f2f5; }
button.primary { background: #2b6cff; color: #fff; border-color: #2b6cff; }
button.primary:hover { background: #1f55d8; }
button.ghost { background: transparent; border-color: transparent; color: #555; }
button.ghost:hover { background: #e7eaef; }

input, select, textarea {
  font-family: inherit; font-size: 13px;
  padding: 6px 10px; border: 1px solid #d0d4dc; border-radius: 6px;
  background: #fff; outline: none;
}
textarea { resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: #2b6cff; }

.hidden { display: none !important; }

/* ============== Header ============== */
header {
  height: 48px;
  background: #fff;
  border-bottom: 1px solid #e3e6eb;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  position: relative; z-index: 100;
}
.brand { font-weight: 600; font-size: 15px; }
.header-actions { display: flex; align-items: center; gap: 10px; }

/* ── 在线创作氛围徽章 ── */
.online-count {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: #6b5e4a; white-space: nowrap;
  background: linear-gradient(135deg, #fef9ef 0%, #fdf3e0 100%);
  border: 1px solid #f0d9a8;
  border-radius: 20px;
  padding: 4px 14px 4px 10px;
  position: relative;
  box-shadow: 0 0 0 0 rgba(240, 180, 80, 0.35);
  animation: online-glow 3s ease-in-out infinite;
}
@keyframes online-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(240, 180, 80, 0.35); }
  50%      { box-shadow: 0 0 0 4px rgba(240, 180, 80, 0.08); }
}
.online-count .avatar-dots {
  display: flex; align-items: center;
}
.online-count .adot {
  width: 18px; height: 18px; border-radius: 50%;
  font-size: 9px; font-weight: 700; color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  margin-right: -6px;
  border: 2px solid #fef9ef;
  box-shadow: 0 1px 3px rgba(0,0,0,.1);
  text-transform: uppercase;
}
.online-count .adot:nth-child(1) { background: #e8865c; z-index: 3; }
.online-count .adot:nth-child(2) { background: #5c9ce8; z-index: 2; }
.online-count .adot:nth-child(3) { background: #6cc070; z-index: 1; }
.online-count .adot:nth-child(4) { background: #c07ae8; z-index: 0; }
.online-count .adot:nth-child(5) { background: #e8b85c; z-index: -1; }
.online-count .count-text {
  font-weight: 600; margin-left: 2px;
}
.online-count .count-emoji {
  font-size: 13px; line-height: 1;
}
#user-badge { cursor: pointer; font-size: 13px; color: #555; user-select: none; }
.user-dropdown {
  position: absolute; right: 0; top: calc(100% + 8px);
  background: #fff; border: 1px solid #e3e6eb; border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12); min-width: 140px; z-index: 999;
  padding: 6px 0;
}
.user-dropdown-name { padding: 8px 14px; font-size: 13px; color: #888; }
.user-dropdown-hr { margin: 0; border: none; border-top: 1px solid #e3e6eb; }
.user-dropdown-item {
  display: block; width: 100%; padding: 8px 14px; text-align: left;
  background: none; border: none; cursor: pointer; font-size: 14px; color: #333;
}
.user-dropdown-item:hover { background: #f5f6fa; }

/* ============== View ============== */
.view {
  flex: 1; min-height: 0;
  display: flex;
}

/* ---------- 首页：左导航 + 中工作区 ---------- */
.sidebar {
  width: 180px; background: #fff;
  border-right: 1px solid #e3e6eb;
  padding: 12px 0;
  flex-shrink: 0;
  overflow: hidden;
  transition: width 0.2s ease;
}
.sidebar.collapsed { width: 0; border-right: none; }
.brand-area { display: flex; align-items: center; gap: 8px; }
.sidebar-toggle {
  width: 26px; height: 26px; padding: 0;
  border: 1px solid #e3e6eb; background: #fff;
  border-radius: 6px; font-size: 15px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  color: #666; flex-shrink: 0;
}
.sidebar-toggle:hover { background: #f0f2f5; color: #333; }
.nav { list-style: none; margin: 0; padding: 0; }
.nav-item {
  padding: 10px 18px; cursor: pointer; font-size: 14px;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: #f4f5f7; }
.nav-item.active {
  background: #eef3ff; border-left-color: #2b6cff;
  color: #2b6cff; font-weight: 500;
}

.workspace {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  padding: 16px 20px; overflow-x: hidden; overflow-y: auto;
}
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; gap: 12px; flex-wrap: wrap;
}
.toolbar h2, .toolbar h3 { margin: 0; }
.toolbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
button.filter-toggle.active {
  background: #e6f8ef;
  border-color: #7ad9a4;
  color: #16783c;
}
button.filter-toggle.active:hover { background: #d8f3e5; }

/* 卡片网格 */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.card {
  background: #fff; border: 1px solid #e3e6eb;
  border-radius: 8px; padding: 14px;
  display: flex; flex-direction: column; gap: 8px;
  transition: box-shadow .15s;
}
.card:hover { box-shadow: 0 2px 12px rgba(0,0,0,.06); }
.card-type {
  font-size: 11px; color: #2b6cff;
  background: #eef3ff; padding: 2px 8px; border-radius: 10px;
  align-self: flex-start;
}
.card-title { margin: 0; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-summary {
  margin: 0; font-size: 12px; color: #666;
  line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-foot {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: auto; font-size: 11px; color: #999;
}
.card-foot .actions { display: flex; gap: 6px; }

.empty { color: #999; padding: 40px; text-align: center; }

/* ============== Overlay / Modal ============== */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal {
  background: #fff; border-radius: 10px; padding: 22px;
  min-width: 360px; max-width: 90vw; max-height: 90vh; overflow: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,.15);
}
.modal.wide { min-width: 640px; }

/* 素材详情双栏弹窗 */
.detail-modal {
  width: min(92vw, 1100px); height: min(85vh, 800px);
  display: flex; flex-direction: column;
  padding: 0; overflow: hidden;
}
.detail-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 16px 20px 12px; border-bottom: 1px solid #e3e6eb; flex-shrink: 0;
}
.detail-header h2 { margin: 0 0 4px; font-size: 16px; }
.detail-body { display: flex; flex: 1; min-height: 0; }

/* 右侧 tabs + 内容/分析面板 */
.detail-right {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
}
.detail-tabs {
  display: flex; gap: 0;
  border-bottom: 1px solid #e3e6eb; flex-shrink: 0;
  padding: 0 16px;
}
.detail-tab {
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 10px 16px; font-size: 13px; color: #666; cursor: pointer;
  margin-bottom: -1px; border-radius: 0;
}
.detail-tab:hover { color: #333; background: none; }
.detail-tab.active { color: #2b6cff; border-bottom-color: #2b6cff; font-weight: 500; }

/* 页内详情区域 */
.detail-workspace {
  overflow: hidden;
  padding: 0;
}
.detail-workspace .toolbar {
  padding: 10px 20px;
  border-bottom: 1px solid #e3e6eb;
  flex-shrink: 0;
}
.detail-title-block h2 { margin: 0; font-size: 15px; }
.detail-title-block .meta { margin-top: 2px; }
.detail-list {
  width: 220px; min-width: 160px; overflow-y: auto;
  border-right: 1px solid #e3e6eb;
  list-style: none; margin: 0; padding: 6px 0; flex-shrink: 0;
}
.detail-list li {
  padding: 9px 14px; cursor: pointer; font-size: 13px;
  border-left: 3px solid transparent;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.4;
}
.detail-list li:hover { background: #f4f5f7; }
.detail-list li.active {
  background: #eef3ff; border-left-color: #2b6cff; color: #2b6cff; font-weight: 500;
}
.detail-pane { flex: 1; overflow-y: auto; padding: 16px 20px; }
.detail-analysis { flex: 1; overflow-y: auto; padding: 16px 20px; }
.detail-pane pre {
  white-space: pre-wrap; word-break: break-word;
  font-family: inherit; font-size: 13px; line-height: 1.8;
  margin: 0; background: none; padding: 0;
}
.detail-pane video {
  width: 100%; max-height: 70vh; border-radius: 6px; background: #000;
  display: block;
}
.detail-hint { color: #bbb; text-align: center; margin-top: 80px; font-size: 14px; }
.detail-list-note {
  color: #bbb; padding: 12px; cursor: default;
}
.detail-list .load-more-btn {
  text-align: center; color: #2b6cff; padding: 10px;
  cursor: pointer; font-size: 13px; user-select: none;
  border-top: 1px solid #eee;
}
.detail-list .load-more-btn:hover { background: #f0f3ff; }
.detail-list .load-more-btn:disabled { color: #bbb; cursor: default; }
.detail-video-caption {
  font-size: 12px; color: #888; margin-top: 8px;
}

/* 分析面板 */
.analysis-section {
  margin-bottom: 14px; padding: 14px 16px;
  background: #fafbfc; border: 1px solid #e3e6eb; border-radius: 8px;
}
.analysis-section h4 { margin: 0 0 8px; font-size: 14px; }
.analysis-placeholder { color: #bbb; font-size: 13px; margin: 0; font-style: italic; }
.analysis-text { font-size: 13px; line-height: 1.8; margin: 0; color: #333; white-space: pre-wrap; }

/* 特色元素标签 */
.appeal-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.appeal-tag {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  background: #eff6ff; border: 1px solid #bfdbfe;
  color: #2563eb; font-size: 12px; font-weight: 500;
}
.appeal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px; margin-top: 10px;
}
.appeal-item {
  padding: 10px 12px; border-radius: 8px;
  background: #eff6ff; border: 1px solid #bfdbfe;
}
.appeal-item-desc {
  font-size: 12px; color: #374151; margin: 6px 0 0; line-height: 1.5;
}

/* 人物卡片网格 */
.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin-top: 4px; }
.char-card {
  padding: 12px 14px; border-radius: 8px;
  background: #fff; border: 1px solid #e3e6eb;
}
.char-card.protagonist { border-color: #fbbf24; background: #fffbeb; }
.char-role {
  display: inline-block; margin-bottom: 4px;
  font-size: 11px; color: #888; font-weight: 500; letter-spacing: 0.03em;
}
.char-card strong { display: block; font-size: 14px; margin-bottom: 4px; color: #111; }
.char-card p { font-size: 12px; color: #555; margin: 0; line-height: 1.6; }

/* 分析加载动效 */
.analysis-spinner { display: flex; flex-direction: column; align-items: center; padding: 60px 0; gap: 14px; }
.analysis-spinner p { color: #888; font-size: 13px; margin: 0; }
.spinner-ring {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid #e3e6eb; border-top-color: #2563eb;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* series 文件卡片 */
.series-file-card {
  display: flex; align-items: center; gap: 14px;
  padding: 16px; border: 1px solid #e3e6eb; border-radius: 8px; margin-top: 8px;
}
.series-file-card .file-icon { font-size: 32px; }
.series-file-card .file-name { font-size: 15px; font-weight: 500; }
.series-file-card .file-key { font-size: 12px; color: #888; margin-top: 4px; word-break: break-all; }
.modal h2 { margin: 0 0 12px; font-size: 17px; }
.modal h3 { margin: 16px 0 8px; font-size: 14px; }
.modal input:not([type=radio]):not([type=checkbox]) { display: block; width: 100%; margin-bottom: 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.modal .hint { color: #888; font-size: 12px; margin: 0 0 10px; }
.modal .meta { color: #888; font-size: 12px; margin-bottom: 10px; }
.chat-export-modal { width: min(560px, 92vw); }
.export-pick-toolbar {
  display: flex; align-items: center; gap: 8px;
  margin: 12px 0 10px;
}
.export-pick-toolbar button { padding: 4px 10px; font-size: 12px; }
.export-pick-count { margin-left: auto; font-size: 12px; color: #888; }
.export-pick-list {
  max-height: min(52vh, 420px); overflow: auto;
  border: 1px solid #e3e6eb; border-radius: 8px;
  background: #fafbfc;
}
.export-pick-row {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px; border-bottom: 1px solid #e9edf3;
  cursor: pointer;
}
.export-pick-row:last-child { border-bottom: none; }
.export-pick-row:hover { background: #f2f5fb; }
.export-pick-row input { margin-top: 3px; flex-shrink: 0; }
.export-pick-body { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.export-pick-head { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #333; }
.export-pick-meta { font-size: 11px; color: #2b6cff; }
.export-pick-preview {
  font-size: 12px; color: #777; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.export-pick-error { min-height: 18px; }
.auth-switch { margin-top: 12px; font-size: 13px; color: #888; text-align: center; }
.auth-switch a { color: #4a6cf7; text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }
.modal pre {
  background: #f6f8fa; padding: 12px; border-radius: 6px;
  max-height: 60vh; overflow: auto; white-space: pre-wrap; font-size: 12px;
}

.progress { margin-top: 14px; }
.progress pre {
  background: #1e1e2a; color: #cdd6e0; padding: 10px;
  border-radius: 6px; max-height: 240px; overflow: auto;
  font-size: 11px; white-space: pre-wrap;
}
.spinner {
  width: 16px; height: 16px; border: 2px solid #ddd; border-top-color: #2b6cff;
  border-radius: 50%; animation: spin 0.8s linear infinite;
  display: inline-block; margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.err { color: #e54545; font-size: 12px; margin-top: 6px; }

/* 入库弹窗：模式切换 & 表单标签 */
.ingest-mode-tabs {
  display: flex; gap: 16px; margin-bottom: 12px;
  font-size: 13px;
}
.ingest-mode-tabs label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.spec-mode-tabs {
  display: flex; gap: 16px; margin-bottom: 8px;
  font-size: 13px;
}
.spec-mode-tabs label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.field-label {
  display: block; font-size: 12px; color: #666; margin-bottom: 3px; margin-top: 10px;
}
.field-label:first-child { margin-top: 0; }

/* 用户表 */
#users-table { width: 100%; border-collapse: collapse; }
#users-table th, #users-table td { padding: 8px 10px; border-bottom: 1px solid #eee; text-align: left; font-size: 13px; }

/* 响应式 */
@media (max-width: 900px) {
  .sidebar { width: 130px; }
}

/* ============== 创作导航项 ============== */
.nav-item-create {
  margin-top: 8px;
  border-top: 1px solid #eee;
  padding-top: 14px;
  color: #2b6cff;
}
.nav-item-create.active { background: #eef3ff; border-left-color: #2b6cff; }

/* ============== Agent 创作聊天页 ============== */
.agent-chat-sidebar {
  width: 220px; min-width: 180px; flex-shrink: 0;
  background: #fff; border-right: 1px solid #e3e6eb;
  display: flex; flex-direction: column;
}
/* ---- 拖拽调整宽度 ---- */
.resize-handle {
  width: 5px; flex-shrink: 0; cursor: col-resize;
  background: transparent;
  position: relative; z-index: 10;
  transition: background .15s;
}
.resize-handle:hover,
.resize-handle.active {
  background: #2b6cff;
}
.agent-chat-sidebar-hd {
  padding: 12px;
  border-bottom: 1px solid #e3e6eb;
}
.agent-new-btn { width: 100%; font-size: 13px; }

.agent-session-list {
  list-style: none; margin: 0; padding: 6px 0;
  flex: 1; overflow-y: auto;
}
.session-item {
  padding: 10px 12px; cursor: pointer; font-size: 13px;
  border-left: 3px solid transparent;
  position: relative; display: flex; flex-direction: column; gap: 3px;
}
.session-item:hover { background: #f4f5f7; }
.session-item.active {
  background: #eef3ff; border-left-color: #2b6cff;
}
.session-item-title {
  font-size: 13px; font-weight: 500; color: #222;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding-right: 20px;
}
.session-item.active .session-item-title { color: #2b6cff; }
.session-item-date { font-size: 11px; color: #999; }
.session-actions {
  position: absolute; right: 8px; top: 8px;
  display: none; gap: 2px;
}
.session-item:hover .session-actions { display: flex; }
.session-rename,
.session-delete {
  width: 18px; height: 18px; padding: 0; line-height: 1;
  border: none; background: none; color: #bbb; font-size: 14px;
  border-radius: 3px; cursor: pointer;
}
.session-rename:hover { background: #e8f0ff; color: #2b6cff; }
.session-delete:hover { background: #fee; color: #e54545; }
.session-rename-input {
  width: 100%; font-size: 13px; font-weight: 500;
  border: 1px solid #2b6cff; border-radius: 3px;
  padding: 1px 4px; outline: none;
  background: #fff; color: #222;
}
.no-sessions { padding: 20px 12px; color: #bbb; font-size: 13px; list-style: none; }

/* Agent 聊天主区 */
.agent-chat-main {
  width: 560px; min-width: 560px; flex-shrink: 0;
  display: flex; flex-direction: column;
  border-left: 1px solid #e3e6eb;
  transition: width .2s ease, min-width .2s ease;
}
/* 折叠 AI 助手面板 */
#view-agent.agent-collapsed .agent-chat-main {
  width: 0 !important; min-width: 0 !important; overflow: hidden; border-left: none;
}
.agent-chat-main.no-transition,
.agent-chat-sidebar.no-transition { transition: none !important; }
#view-agent.agent-collapsed #resize-handle-right { display: none; }
.agent-chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid #e3e6eb;
  background: #fff; flex-shrink: 0;
}
.agent-chat-title { font-size: 14px; font-weight: 500; color: #333; flex: 1; }

.agent-messages {
  flex: 1; overflow-y: auto; overflow-x: hidden; padding: 16px 20px;
  display: flex; flex-direction: column; gap: 12px;
  background: #f8f9fb;
}
.agent-hint { color: #bbb; text-align: center; font-size: 14px; margin: 80px auto 0; }

/* 消息气泡 */
.chat-msg { max-width: 100%; }

/* 手动编辑通知卡片 */
.edit-notice-msg {
  align-self: center; width: 90%;
  background: #fffbf0; border: 1px solid #f0c040;
  border-radius: 10px; padding: 10px 14px;
  font-size: 13px; line-height: 1.6; margin: 8px 0;
}
.edit-notice-header {
  font-weight: 600; color: #b45309; margin-bottom: 6px;
  font-size: 13px;
}
.edit-diff-body {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 12px; line-height: 1.6;
}
.edit-diff-line {
  padding: 1px 6px; border-radius: 2px;
  white-space: pre-wrap; word-break: break-word;
}
.edit-diff-line.ctx { color: #888; }
.edit-diff-line.del {
  background: #ffeef0; color: #cb2431;
}
.edit-diff-line.add {
  background: #e6ffed; color: #22863a;
}

.user-msg {
  align-self: flex-end;
  background: #2b6cff; color: #fff;
  padding: 10px 14px; border-radius: 12px 12px 2px 12px;
  font-size: 13px; line-height: 1.6; max-width: 75%; white-space: pre-wrap;
}
.assistant-msg {
  align-self: flex-start; width: 100%;
  background: #fff; border: 1px solid #e3e6eb;
  border-radius: 2px 12px 12px 12px;
  padding: 12px 14px; font-size: 13px; line-height: 1.7;
}
.assistant-msg .msg-text { white-space: pre-wrap; word-break: break-word; color: #222; }
.assistant-msg .msg-error { color: #e54545; margin-top: 6px; font-size: 12px; }

/* ask_user 等待确认卡片 */
.auto-run-btn.active { background: #e8f5e9; border-color: #4caf50; color: #2e7d32; font-weight: 600; }
.auto-run-btn.active:hover { background: #c8e6c9; }

/* 模型切换按钮 */
.model-toggle-btn { font-weight: 600; transition: all .2s; }
.model-toggle-btn.flash { background: #e3f2fd; border-color: #2196f3; color: #0d47a1; }
.model-toggle-btn.flash:hover { background: #bbdefb; }

.ask-user-card {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 18px; margin: 10px 16px;
  background: #fffbeb; border: 2px solid #fbbf24;
  border-radius: 12px; font-size: 13px; color: #92400e;
  animation: slideIn .25s ease;
}
.ask-user-icon { font-size: 22px; flex-shrink: 0; line-height: 1; }
.ask-user-body { display: flex; flex-direction: column; gap: 4px; }
.ask-user-stage {
  display: inline-block; background: #fde68a; color: #78350f;
  font-size: 11px; font-weight: 600; padding: 1px 8px;
  border-radius: 20px; width: fit-content;
}
.ask-user-q { margin: 0; line-height: 1.65; }
.ask-user-body { flex: 1; }
.ask-user-actions { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.ask-user-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.ask-user-confirm {
  align-self: flex-start;
  background: #10b981; color: #fff; border: none;
  padding: 5px 14px; border-radius: 6px; cursor: pointer;
  font-size: 12px; font-weight: 600; transition: background .15s;
}
.ask-user-confirm:hover:not(:disabled) { background: #059669; }
.ask-user-qcfix {
  background: #f59e0b; color: #fff; border: none;
  padding: 5px 14px; border-radius: 6px; cursor: pointer;
  font-size: 12px; font-weight: 600; transition: background .15s;
}
.ask-user-qcfix:hover:not(:disabled) { background: #d97706; }
.ask-user-feedback { display: flex; gap: 6px; align-items: center; }
.ask-user-input {
  flex: 1; padding: 4px 8px;
  border: 1px solid #fbbf24; border-radius: 6px;
  font-size: 12px; background: #fff; color: #92400e; outline: none;
}
.ask-user-input:focus { border-color: #f59e0b; box-shadow: 0 0 0 2px #fde68a55; }
.ask-user-submit {
  background: transparent; border: 1px solid #fbbf24;
  color: #92400e; padding: 4px 10px; border-radius: 6px;
  cursor: pointer; font-size: 12px; transition: background .15s;
}
.ask-user-submit:hover:not(:disabled) { background: #fef3c7; }
.ask-user-done { opacity: 0.5; pointer-events: none; }

/* 思考块 */
.think-block {
  margin-bottom: 8px; border-left: 3px solid #a570ff;
  padding-left: 10px;
}
.think-block .think-header {
  display: flex; align-items: center; gap: 6px;
  cursor: pointer; user-select: none;
  font-size: 12px; color: #a570ff; font-weight: 500;
}
.think-block .think-toggle { font-size: 10px; }
.think-block .think-body {
  display: none; margin-top: 6px;
  font-size: 12px; color: #777; white-space: pre-wrap;
  line-height: 1.6;
}

/* 工具调用标记 */
.tool-call-badge {
  display: inline-block; margin: 4px 2px;
  padding: 2px 8px; border-radius: 10px;
  background: #fff7ed; border: 1px solid #fed7aa;
  color: #c2410c; font-size: 11px;
}
.tool-call-badge.done {
  background: #f0fdf4; border-color: #bbf7d0; color: #166534;
}

/* 工具执行进度提示 */
.tool-progress-msg {
  margin: 6px 0; padding: 4px 10px;
  font-size: 12px; color: #6b7280;
  border-left: 2px solid #f59e0b;
  animation: progress-pulse 1.5s ease-in-out infinite;
}
.tool-progress {
  color: #f59e0b;
  font-style: italic;
}
@keyframes progress-pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* 输入栏 */
.agent-input-bar {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 12px 16px; border-top: 1px solid #e3e6eb;
  background: #fff; flex-shrink: 0; position: relative;
}
.agent-input-bar textarea {
  flex: 1; resize: none; min-height: 40px; padding: 10px; overflow: hidden; max-height: 180px;
  box-sizing: border-box;
  font-size: 13px; line-height: 1.55;
}
.agent-input-bar textarea:disabled {
  background: #f3f5f8;
  color: #8b95a5;
  cursor: not-allowed;
}
.agent-input-btns {
  display: flex; flex-direction: column; gap: 6px;
  flex-shrink: 0; align-self: flex-end;
}
.agent-input-btns button {
  width: 32px; height: 32px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0; line-height: 1; border-radius: 999px;
  white-space: nowrap;
  position: relative;
  box-shadow: 0 2px 6px rgba(43,108,255,.25);
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.agent-input-btns button::before {
  content: "";
  width: 14px; height: 14px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12 7-7 7 7'/%3E%3Cpath d='M12 19V5'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12 7-7 7 7'/%3E%3Cpath d='M12 19V5'/%3E%3C/svg%3E") center / contain no-repeat;
}
.agent-input-btns button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(43,108,255,.32);
}
.agent-input-btns button:disabled {
  transform: none;
  box-shadow: none;
}
.agent-input-btns button.is-processing {
  background: #fff5f5;
  border-color: #f5c8c8;
  color: #e05555;
  cursor: pointer;
}
.agent-input-btns button.is-processing::before {
  width: 8px; height: 8px;
  border-radius: 999px;
  background: #e05555;
  -webkit-mask: none;
  mask: none;
  animation: agentPulseDot 1s ease-in-out infinite;
}

@keyframes agentPulseDot {
  0%, 100% { opacity: .35; transform: scale(.72); }
  50% { opacity: 1; transform: scale(1); }
}

/* slash 命令提示 */
.slash-popup {
  position: absolute; bottom: 100%; left: 16px; right: 88px;
  background: #fff; border: 1px solid #d0d5e0; border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.1); max-height: 240px;
  overflow-y: auto; z-index: 100; display: none; margin-bottom: 4px;
}
.slash-popup.open { display: block; }
.slash-item { padding: 8px 14px; cursor: pointer; font-size: 13px; display: flex; gap: 10px; align-items: baseline; }
.slash-item:hover, .slash-item.selected { background: #eef3ff; }
.slash-item .cmd { font-weight: 600; color: #2b6cff; white-space: nowrap; }
.slash-item .desc { color: #666; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
[data-theme="dark"] .slash-popup { background: #242528; border-color: #3a3b3d; }
[data-theme="dark"] .slash-item:hover, [data-theme="dark"] .slash-item.selected { background: #2f3033; }
[data-theme="dark"] .slash-item .desc { color: #aaa; }

/* 分析工具栏 */
.analysis-toolbar {
  display: flex; gap: 8px; align-items: center;
  padding: 8px 0 12px; border-bottom: 1px solid #e3e6eb; margin-bottom: 12px;
}

/* ============== 创作文档面板（中央主区，宽） ============== */
.agent-doc-panel {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  border-left: 1px solid #e3e6eb; background: #fff;
}
.doc-panel-hd {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-bottom: 1px solid #e3e6eb;
  flex-shrink: 0;
}
.doc-panel-title { font-size: 13px; font-weight: 600; color: #333; flex: 1; }
button.small { padding: 3px 8px; font-size: 12px; height: auto; }
button.danger { color: #e54545; }
button.danger:hover { background: #fff0f0; }

/* 分节标签导航 */
.doc-tabs-nav {
  display: flex; flex-wrap: nowrap; gap: 4px;
  padding: 8px 10px; border-bottom: 1px solid #e3e6eb;
  flex-shrink: 0; min-height: 38px; align-items: center;
  overflow-x: auto; overflow-y: hidden;
  max-height: 40px; scrollbar-width: thin;
}
.doc-tabs-nav.expanded {
  flex-wrap: wrap;
  overflow-x: hidden; overflow-y: auto;
  max-height: 128px;
  align-content: flex-start;
}
.doc-tabs-toggle {
  width: 26px; padding-left: 0; padding-right: 0;
  font-size: 13px; line-height: 1;
}
.doc-tabs-toggle.active {
  background: #eef3ff;
  border-color: #bfd0ff;
  color: #2b6cff;
}
.doc-empty-hint { font-size: 12px; color: #bbb; }
.doc-tab {
  flex: 0 0 auto;
  padding: 3px 10px; border-radius: 12px; border: 1px solid #ddd;
  background: #f5f6f8; font-size: 12px; cursor: pointer; white-space: nowrap;
  color: #555; line-height: 1.6;
}
.doc-tab:hover { background: #e8edf5; border-color: #aac; }
.doc-tab.active {
  background: #2b6cff; border-color: #2b6cff; color: #fff;
}
.doc-tab.dragging { opacity: 0.4; }
.doc-tab.drag-over {
  border-color: #2b6cff; border-style: dashed;
  background: #e8f0ff;
}

/* 文档编辑区 */
.doc-section-body {
  flex: 1; display: flex; flex-direction: column; min-height: 0;
  padding: 16px 10px; width: 100%; max-width: 920px;
  margin: 0 auto; align-items: stretch;
}
.doc-editor {
  flex: 1; resize: none; width: 100%; min-height: 0;
  font-size: 15px; line-height: 1.9; color: #222;
  border: 1px solid #e3e6eb; border-radius: 6px; padding: 18px 22px;
  font-family: inherit;
}
.doc-editor:focus { border-color: #2b6cff; outline: none; }
/* 失焦时保持选区高亮可见（浏览器默认选区在失焦后变灰，此处保持主色） */
.doc-editor::selection { background: #b3d4ff; }
.doc-editor::-moz-selection { background: #b3d4ff; }

/* 选区浮动工具栏 */
.doc-sel-toolbar {
  position: absolute; z-index: 200; display: flex; gap: 4px; align-items: center;
  background: #1f2937; border-radius: 8px; padding: 6px 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.doc-sel-input {
  padding: 4px 8px; border: 1px solid #4b5563; border-radius: 5px;
  background: #374151; color: #fff; font-size: 12px; outline: none;
  min-width: 220px;
}
.doc-sel-input::placeholder { color: #9ca3af; }
.doc-sel-input:focus { border-color: #6b7280; }
.doc-sel-confirm {
  background: #10b981; border: none; color: #fff;
  font-size: 12px; padding: 4px 10px; border-radius: 5px; cursor: pointer;
  white-space: nowrap; flex-shrink: 0;
}
.doc-sel-confirm:hover { background: #059669; }

/* ============== 深色模式 ============== */
[data-theme="dark"] body { background: #1a1b1e; color: #d8d8d8; }

/* Header */
[data-theme="dark"] header { background: #242528; border-bottom-color: #3a3b3d; }
[data-theme="dark"] .brand { color: #e0e0e0; }
[data-theme="dark"] .online-count {
  color: #c8b896;
  background: linear-gradient(135deg, #2a2520 0%, #252118 100%);
  border-color: #4a3828;
  animation: online-glow-dark 3s ease-in-out infinite;
}
@keyframes online-glow-dark {
  0%, 100% { box-shadow: 0 0 0 0 rgba(180, 140, 60, 0.25); }
  50%      { box-shadow: 0 0 0 4px rgba(180, 140, 60, 0.06); }
}
[data-theme="dark"] .online-count .adot {
  border-color: #2a2520;
}
[data-theme="dark"] #user-badge { color: #aaa; }
[data-theme="dark"] .sidebar-toggle { background: #2d2e31; border-color: #444; color: #aaa; }
[data-theme="dark"] .sidebar-toggle:hover { background: #3a3b3e; color: #e0e0e0; }

/* 用户下拉 */
[data-theme="dark"] .user-dropdown { background: #2a2b2e; border-color: #3a3b3d; box-shadow: 0 4px 16px rgba(0,0,0,.4); }
[data-theme="dark"] .user-dropdown-name { color: #777; }
[data-theme="dark"] .user-dropdown-hr { border-top-color: #3a3b3d; }
[data-theme="dark"] .user-dropdown-item { color: #d0d0d0; }
[data-theme="dark"] .user-dropdown-item:hover { background: #333438; }

/* 通用 button / input */
[data-theme="dark"] button { background: #2d2e31; border-color: #444; color: #d0d0d0; }
[data-theme="dark"] button:hover { background: #3a3b3e; }
[data-theme="dark"] button.primary { background: #2b6cff; border-color: #2b6cff; color: #fff; }
[data-theme="dark"] button.primary:hover { background: #1f55d8; }
[data-theme="dark"] button.ghost { background: transparent; border-color: transparent; color: #999; }
[data-theme="dark"] button.ghost:hover { background: #2e2f32; }
[data-theme="dark"] button.small { }
[data-theme="dark"] button.danger { color: #f87171; }
[data-theme="dark"] button.danger:hover { background: #2d1f1f; }
[data-theme="dark"] button.filter-toggle.active {
  background: #16351f;
  border-color: #2f8f57;
  color: #4ade80;
}
[data-theme="dark"] button.filter-toggle.active:hover { background: #1d4428; }
[data-theme="dark"] input, [data-theme="dark"] select, [data-theme="dark"] textarea {
  background: #2a2b2e; border-color: #444; color: #e0e0e0;
}
[data-theme="dark"] .agent-input-bar textarea:disabled {
  background: #242528; border-color: #3a3b3d; color: #777;
}
[data-theme="dark"] .agent-input-btns button.is-processing {
  background: #3a2525; border-color: #6b3838; color: #f58888;
}
[data-theme="dark"] input:focus, [data-theme="dark"] select:focus, [data-theme="dark"] textarea:focus { border-color: #2b6cff; }

/* 侧边栏 */
[data-theme="dark"] .sidebar { background: #242528; border-right-color: #3a3b3d; }
[data-theme="dark"] .nav-item:hover { background: #2e2f32; }
[data-theme="dark"] .nav-item.active { background: #1a2a4a; border-left-color: #2b6cff; color: #2b6cff; }
[data-theme="dark"] .nav-item-create { border-top-color: #3a3b3d; }

/* 素材卡片 */
[data-theme="dark"] .card { background: #242528; border-color: #3a3b3d; }
[data-theme="dark"] .card:hover { box-shadow: 0 2px 12px rgba(0,0,0,.3); }
[data-theme="dark"] .card-summary { color: #888; }
[data-theme="dark"] .card-foot { color: #666; }

/* 详情页 */
[data-theme="dark"] .detail-workspace .toolbar { border-bottom-color: #3a3b3d; }
[data-theme="dark"] .detail-list { border-right-color: #3a3b3d; }
[data-theme="dark"] .detail-list li:hover { background: #2e2f32; }
[data-theme="dark"] .detail-list li.active { background: #1a2a4a; border-left-color: #2b6cff; color: #2b6cff; }
[data-theme="dark"] .detail-tabs { border-bottom-color: #3a3b3d; }
[data-theme="dark"] .detail-tab { color: #888; }
[data-theme="dark"] .detail-tab:hover { color: #ccc; }
[data-theme="dark"] .detail-tab.active { color: #2b6cff; border-bottom-color: #2b6cff; }
[data-theme="dark"] .detail-title-block .meta { color: #888; }

/* 分析面板 */
[data-theme="dark"] .analysis-section { background: #1e1f22; border-color: #3a3b3d; }
[data-theme="dark"] .analysis-section h4 { color: #d0d0d0; }
[data-theme="dark"] .analysis-text { color: #bbb; }
[data-theme="dark"] .analysis-placeholder { color: #555; }
[data-theme="dark"] .analysis-toolbar { border-bottom-color: #3a3b3d; }
[data-theme="dark"] .appeal-tag { background: #1a2a4a; border-color: #2b4a8a; color: #7eb3ff; }
[data-theme="dark"] .appeal-item { background: #1a2a4a; border-color: #2b4a8a; }
[data-theme="dark"] .appeal-item-desc { color: #aaa; }
[data-theme="dark"] .char-card { background: #2a2b2e; border-color: #3a3b3d; }
[data-theme="dark"] .char-card.protagonist { border-color: #92400e; background: #2a2010; }
[data-theme="dark"] .char-role { color: #666; }
[data-theme="dark"] .char-card strong { color: #e0e0e0; }
[data-theme="dark"] .char-card p { color: #999; }

/* Agent Chat 侧边栏 */
[data-theme="dark"] .agent-chat-sidebar { background: #242528; border-right-color: #3a3b3d; }
[data-theme="dark"] .resize-handle:hover,
[data-theme="dark"] .resize-handle.active { background: #4a6fc9; }
[data-theme="dark"] .agent-chat-sidebar-hd { border-bottom-color: #3a3b3d; }
[data-theme="dark"] .session-item:hover { background: #2e2f32; }
[data-theme="dark"] .session-item.active { background: #1a2a4a; border-left-color: #2b6cff; }
[data-theme="dark"] .session-item-title { color: #d0d0d0; }
[data-theme="dark"] .session-item.active .session-item-title { color: #2b6cff; }
[data-theme="dark"] .session-item-date { color: #666; }
[data-theme="dark"] .session-rename:hover { background: #1a2a4a; color: #2b6cff; }
[data-theme="dark"] .session-delete:hover { background: #3d1f1f; color: #f87171; }
[data-theme="dark"] .session-rename-input { background: #2a2b2e; border-color: #2b6cff; color: #d0d0d0; }

/* Agent 聊天主区 */
[data-theme="dark"] .agent-chat-main { border-left-color: #3a3b3d; }
[data-theme="dark"] .agent-chat-header { background: #242528; border-bottom-color: #3a3b3d; }
[data-theme="dark"] .agent-chat-title { color: #d0d0d0; }
[data-theme="dark"] .agent-messages { background: #18191c; }
[data-theme="dark"] .assistant-msg { background: #242528; border-color: #3a3b3d; }
[data-theme="dark"] .assistant-msg .msg-text { color: #d0d0d0; }
[data-theme="dark"] .agent-input-bar { background: #242528; border-top-color: #3a3b3d; }

/* 深色模式补全：避免组件露出浅色底 */
[data-theme="dark"] .workspace { color: #d8d8d8; }
[data-theme="dark"] .toolbar,
[data-theme="dark"] .detail-header,
[data-theme="dark"] .analysis-toolbar {
  border-color: #3a3b3d;
}
[data-theme="dark"] .modal {
  background: #242528;
  border-color: #3a3b3d;
  color: #d8d8d8;
}
[data-theme="dark"] .modal {
  box-shadow: 0 8px 32px rgba(0,0,0,.45);
}
[data-theme="dark"] .export-pick-count,
[data-theme="dark"] .export-pick-preview { color: #888; }
[data-theme="dark"] .export-pick-list { background: #1e1f22; border-color: #3a3b3d; }
[data-theme="dark"] .export-pick-row { border-bottom-color: #333538; }
[data-theme="dark"] .export-pick-row:hover { background: #2a2b2e; }
[data-theme="dark"] .export-pick-head { color: #d0d0d0; }
[data-theme="dark"] .export-pick-meta { color: #7eb3ff; }
[data-theme="dark"] .modal pre {
  background: #1e1f22;
  color: #d0d0d0;
}
[data-theme="dark"] .modal .hint,
[data-theme="dark"] .modal .meta,
[data-theme="dark"] .auth-switch,
[data-theme="dark"] .field-label,
[data-theme="dark"] .empty,
[data-theme="dark"] .detail-hint,
[data-theme="dark"] .agent-hint,
[data-theme="dark"] .no-sessions {
  color: #777;
}
[data-theme="dark"] .auth-switch a { color: #7eb3ff; }
[data-theme="dark"] .progress pre {
  background: #18191c;
  color: #c9d1d9;
}
[data-theme="dark"] .spinner,
[data-theme="dark"] .spinner-ring {
  border-color: #3a3b3d;
  border-top-color: #7eb3ff;
}
[data-theme="dark"] #users-table th,
[data-theme="dark"] #users-table td {
  border-bottom-color: #3a3b3d;
}

/* 深色模式：素材与详情 */
[data-theme="dark"] .card-title { color: #e0e0e0; }
[data-theme="dark"] .card-type {
  background: #1a2a4a;
  color: #7eb3ff;
}
[data-theme="dark"] .nav-item-create.active { background: #1a2a4a; }
[data-theme="dark"] .detail-pane pre { color: #d0d0d0; }
[data-theme="dark"] .detail-list-note { color: #777; }
[data-theme="dark"] .detail-list .load-more-btn { color: #7eb3ff; border-top-color: #3a3b3d; }
[data-theme="dark"] .detail-list .load-more-btn:hover { background: #1a2a4a; }
[data-theme="dark"] .detail-video-caption { color: #888; }
[data-theme="dark"] .series-file-card {
  background: #242528;
  border-color: #3a3b3d;
}
[data-theme="dark"] .series-file-card .file-name { color: #e0e0e0; }
[data-theme="dark"] .series-file-card .file-key { color: #777; }

[data-theme="dark"] .think-block .think-body {
  background: #1f1b2f;
  color: #aaa;
}

/* 深色模式：Agent 消息状态卡片 */
[data-theme="dark"] .edit-notice-msg {
  background: #2a2415;
  border-color: #8a6d1f;
  color: #d6c58a;
}
[data-theme="dark"] .edit-notice-header { color: #f0c040; }
[data-theme="dark"] .edit-diff-line.ctx { color: #888; }
[data-theme="dark"] .edit-diff-line.del {
  background: #3d1f1f;
  color: #f87171;
}
[data-theme="dark"] .edit-diff-line.add {
  background: #16351f;
  color: #4ade80;
}
[data-theme="dark"] .auto-run-btn.active {
  background: #16351f;
  border-color: #2f7d46;
  color: #4ade80;
}
[data-theme="dark"] .auto-run-btn.active:hover { background: #1d472a; }
[data-theme="dark"] .model-toggle-btn.flash {
  background: #0d2137;
  border-color: #1565c0;
  color: #64b5f6;
}
[data-theme="dark"] .model-toggle-btn.flash:hover { background: #1a3150; }
[data-theme="dark"] .ask-user-card {
  background: #2a2415;
  border-color: #8a6d1f;
  color: #e3c76e;
}
[data-theme="dark"] .ask-user-stage {
  background: #3a2f16;
  color: #f0c040;
}
[data-theme="dark"] .ask-user-input {
  background: #1f1f22;
  border-color: #8a6d1f;
  color: #f2d98a;
}
[data-theme="dark"] .ask-user-input:focus {
  border-color: #f0c040;
  box-shadow: 0 0 0 2px rgba(240,192,64,.18);
}
[data-theme="dark"] .ask-user-submit {
  border-color: #8a6d1f;
  color: #f0c040;
}
[data-theme="dark"] .ask-user-submit:hover:not(:disabled) { background: #3a2f16; }
[data-theme="dark"] .tool-call-badge {
  background: #3a2615;
  border-color: #7c4a16;
  color: #f59e0b;
}
[data-theme="dark"] .tool-call-badge.done {
  background: #16351f;
  border-color: #2f7d46;
  color: #4ade80;
}
[data-theme="dark"] .tool-progress-msg {
  color: #9ca3af;
  border-left-color: #d97706;
}

/* 深色模式：输入与 slash */
[data-theme="dark"] .agent-input-btns button.is-processing {
  background: #3a2525;
  border-color: #6b3838;
  color: #f58888;
}
[data-theme="dark"] .slash-popup {
  background: #242528;
  border-color: #3a3b3d;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
}
[data-theme="dark"] .slash-item .cmd { color: #7eb3ff; }

/* 深色模式：创作文档面板 */
[data-theme="dark"] .agent-doc-panel {
  background: #1e1f22;
  border-left-color: #3a3b3d;
}
[data-theme="dark"] .doc-panel-hd,
[data-theme="dark"] .doc-tabs-nav {
  border-bottom-color: #3a3b3d;
}
[data-theme="dark"] .doc-panel-title { color: #d0d0d0; }
[data-theme="dark"] .doc-tab {
  background: #2a2b2e;
  border-color: #444;
  color: #d0d0d0;
}
[data-theme="dark"] .doc-tab:hover {
  background: #34363a;
  border-color: #555;
}
[data-theme="dark"] .doc-tab.active {
  background: #2b6cff;
  border-color: #2b6cff;
  color: #fff;
}
[data-theme="dark"] .doc-tabs-toggle.active {
  background: #1a2a4a;
  border-color: #2b4a8a;
  color: #7eb3ff;
}
[data-theme="dark"] .doc-tab.drag-over {
  background: #1a2a4a;
  border-color: #2b6cff;
}
[data-theme="dark"] .doc-editor {
  background: #242528;
  border-color: #3a3b3d;
  color: #d8d8d8;
}
[data-theme="dark"] .doc-editor:focus { border-color: #2b6cff; }

/* ============== Phase 1 Visual Upgrade ============== */
:root {
  --ui-bg: #f3f5f9;
  --ui-bg-accent: #eef2f8;
  --ui-surface: #ffffff;
  --ui-surface-soft: #f8fafd;
  --ui-border: #dbe2ee;
  --ui-border-strong: #c8d2e2;
  --ui-text: #162033;
  --ui-text-soft: #596579;
  --ui-brand: #245dff;
  --ui-brand-strong: #1f4fda;
  --ui-shadow-sm: 0 6px 16px rgba(19, 33, 68, 0.06);
  --ui-shadow-md: 0 14px 36px rgba(19, 33, 68, 0.1);
  --ui-radius-sm: 8px;
  --ui-radius-md: 12px;
  --ui-radius-lg: 16px;
  --ui-ease: cubic-bezier(.22,.61,.36,1);
  --ui-ease-out: cubic-bezier(.22, 1, .36, 1);
}

body {
  font-family: "Source Han Sans SC", "Noto Sans SC", "PingFang SC", "Microsoft YaHei UI", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 0% 0%, rgba(36, 93, 255, 0.06), transparent 28%),
    radial-gradient(circle at 100% 100%, rgba(48, 122, 255, 0.04), transparent 30%),
    var(--ui-bg);
  color: var(--ui-text);
}

header {
  height: 54px;
  border-bottom: 1px solid var(--ui-border);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(10px);
}

.brand {
  font-size: 16px;
  letter-spacing: 0.01em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.ui-icon {
  display: inline-flex;
  width: 14px;
  height: 14px;
  vertical-align: -2px;
  background: currentColor;
  opacity: 0.88;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
  -webkit-mask-size: contain;
  mask-repeat: no-repeat;
  mask-position: center;
  mask-size: contain;
}

.i-spark { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='m12 2 1.9 5.7L20 10l-6.1 2.3L12 18l-1.9-5.7L4 10l6.1-2.3z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='m12 2 1.9 5.7L20 10l-6.1 2.3L12 18l-1.9-5.7L4 10l6.1-2.3z'/%3E%3C/svg%3E"); }
.i-book { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M4 5.5C4 4.1 5.1 3 6.5 3H20v16H6.5A2.5 2.5 0 0 0 4 21zM6.5 5A.5.5 0 0 0 6 5.5V17a4.4 4.4 0 0 1 .5 0H18V5z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M4 5.5C4 4.1 5.1 3 6.5 3H20v16H6.5A2.5 2.5 0 0 0 4 21zM6.5 5A.5.5 0 0 0 6 5.5V17a4.4 4.4 0 0 1 .5 0H18V5z'/%3E%3C/svg%3E"); }
.i-film { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M3 5h18v14H3zm2 2v10h14V7zm1 1h2v2H6zm0 3h2v2H6zm0 3h2v2H6zm10-6h2v2h-2zm0 3h2v2h-2zm0 3h2v2h-2z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M3 5h18v14H3zm2 2v10h14V7zm1 1h2v2H6zm0 3h2v2H6zm0 3h2v2H6zm10-6h2v2h-2zm0 3h2v2h-2zm0 3h2v2h-2z'/%3E%3C/svg%3E"); }
.i-script { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M7 3h7l5 5v13H7zm8 1.5V9h4.5zM9 12h8v1.8H9zm0 3.3h8V17H9z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M7 3h7l5 5v13H7zm8 1.5V9h4.5zM9 12h8v1.8H9zm0 3.3h8V17H9z'/%3E%3C/svg%3E"); }
.i-pen { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='m4 16.5 10-10 3.5 3.5-10 10H4zm11-11 2-2a1.5 1.5 0 0 1 2.1 0l1.4 1.4a1.5 1.5 0 0 1 0 2.1l-2 2z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='m4 16.5 10-10 3.5 3.5-10 10H4zm11-11 2-2a1.5 1.5 0 0 1 2.1 0l1.4 1.4a1.5 1.5 0 0 1 0 2.1l-2 2z'/%3E%3C/svg%3E"); }
.i-chart { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M4 4h2v16H4zm4 9h2v7H8zm4-4h2v11h-2zm4-5h2v16h-2z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M4 4h2v16H4zm4 9h2v7H8zm4-4h2v11h-2zm4-5h2v16h-2z'/%3E%3C/svg%3E"); }
.i-chat { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M4 4h16v12H8l-4 4zm2 2v9.2L7.2 14H18V6z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M4 4h16v12H8l-4 4zm2 2v9.2L7.2 14H18V6z'/%3E%3C/svg%3E"); }
.i-folder { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M3 6h7l2 2h9v10H3zm2 2v8h14V10h-7.8l-2-2z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M3 6h7l2 2h9v10H3zm2 2v8h14V10h-7.8l-2-2z'/%3E%3C/svg%3E"); }
.i-users { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M9 11a3 3 0 1 1 0-6 3 3 0 0 1 0 6m7 1a2.5 2.5 0 1 1 0-5 2.5 2.5 0 0 1 0 5M4 19c0-2.8 2.3-5 5-5s5 2.2 5 5zm10.5 0c0-2 1.5-3.6 3.5-3.9V19z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M9 11a3 3 0 1 1 0-6 3 3 0 0 1 0 6m7 1a2.5 2.5 0 1 1 0-5 2.5 2.5 0 0 1 0 5M4 19c0-2.8 2.3-5 5-5s5 2.2 5 5zm10.5 0c0-2 1.5-3.6 3.5-3.9V19z'/%3E%3C/svg%3E"); }
.i-robot { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M11 2h2v2h3a3 3 0 0 1 3 3v8a3 3 0 0 1-3 3h-1v3h-2v-3h-2v3H9v-3H8a3 3 0 0 1-3-3V7a3 3 0 0 1 3-3h3zm-1 8a1.5 1.5 0 1 0 0 .1zm4.5 0a1.5 1.5 0 1 0 0 .1zM8 6a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V7a1 1 0 0 0-1-1z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M11 2h2v2h3a3 3 0 0 1 3 3v8a3 3 0 0 1-3 3h-1v3h-2v-3h-2v3H9v-3H8a3 3 0 0 1-3-3V7a3 3 0 0 1 3-3h3zm-1 8a1.5 1.5 0 1 0 0 .1zm4.5 0a1.5 1.5 0 1 0 0 .1zM8 6a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V7a1 1 0 0 0-1-1z'/%3E%3C/svg%3E"); }

.sidebar,
.agent-chat-sidebar,
.agent-doc-panel,
.agent-chat-main,
.modal,
.detail-workspace,
.card,
.analysis-section {
  background: var(--ui-surface);
  border-color: var(--ui-border);
}

.workspace { padding: 20px 24px; }
.toolbar { margin-bottom: 16px; }
.toolbar h2,
.toolbar h3 {
  color: var(--ui-text);
  letter-spacing: 0.01em;
}

button {
  border: 1px solid var(--ui-border);
  background: var(--ui-surface);
  border-radius: var(--ui-radius-sm);
  padding: 7px 13px;
  font-size: 13px;
  color: var(--ui-text-soft);
  transition: background-color .16s ease, border-color .16s ease, color .16s ease, box-shadow .18s ease, transform .18s ease;
}
button:hover {
  background: #f1f5fb;
  border-color: var(--ui-border-strong);
}
button:active {
  transform: translateY(0);
  box-shadow: none;
}
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(36, 93, 255, 0.2);
}
button:disabled {
  opacity: .58;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

button.primary {
  background: linear-gradient(180deg, #2f6dff 0%, var(--ui-brand) 100%);
  border-color: var(--ui-brand);
  color: #fff;
  box-shadow: 0 8px 16px rgba(36, 93, 255, 0.22);
}
button.primary:hover {
  background: linear-gradient(180deg, #2a63ea 0%, var(--ui-brand-strong) 100%);
  border-color: var(--ui-brand-strong);
  transform: translateY(-1px);
}
button.ghost { color: var(--ui-text-soft); }
button.ghost:hover { background: #eef3fb; }

input,
select,
textarea {
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-sm);
  color: var(--ui-text);
}
input:focus,
select:focus,
textarea:focus {
  border-color: #8dadff;
  box-shadow: 0 0 0 3px rgba(36, 93, 255, 0.12);
}

.nav-item {
  margin-right: 8px;
  border-radius: 0 var(--ui-radius-sm) var(--ui-radius-sm) 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.nav-item:hover { background: #f1f5fb; }
.nav-item.active { background: #ecf2ff; }

.grid { gap: 16px; }
.card {
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-md);
  padding: 16px;
  box-shadow: var(--ui-shadow-sm);
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
  animation: riseIn .34s var(--ui-ease) both;
}
.card:hover {
  transform: translateY(-2px);
  border-color: #c6d6f8;
  box-shadow: var(--ui-shadow-md);
}
.card-title { font-size: 16px; color: var(--ui-text); }
.card-summary { font-size: 12px; color: var(--ui-text-soft); }
.card-foot { color: #7f899a; }

.detail-workspace .toolbar,
.agent-chat-header,
.doc-panel-hd,
.doc-tabs-nav,
.agent-chat-sidebar-hd,
.agent-input-bar,
.analysis-toolbar { border-color: var(--ui-border); }

.detail-pane,
.detail-analysis { background: var(--ui-surface-soft); animation: softFade .26s ease both; }

.analysis-section {
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-md);
  background: #fcfdff;
  animation: riseIn .34s var(--ui-ease) both;
}

.assistant-msg {
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-sm) var(--ui-radius-md) var(--ui-radius-md) var(--ui-radius-md);
  box-shadow: var(--ui-shadow-sm);
  animation: riseIn .34s var(--ui-ease) both;
}

/* Phase 3: Agent hierarchy */
.agent-chat-sidebar { background: #f7f9fd; }
.agent-doc-panel {
  background: linear-gradient(180deg, #ffffff 0%, #fbfcff 100%);
  box-shadow: inset 1px 0 0 rgba(36, 93, 255, 0.04), inset -1px 0 0 rgba(36, 93, 255, 0.04);
}
.agent-chat-main { background: #f6f8fc; }
.agent-chat-header,
.doc-panel-hd { background: rgba(255, 255, 255, 0.88); backdrop-filter: blur(8px); }
.agent-messages { background: #f4f7fd; }

.doc-editor {
  border-radius: var(--ui-radius-md);
  border-color: var(--ui-border);
  box-shadow: inset 0 1px 2px rgba(20, 28, 44, 0.03);
}
.doc-tab { border-radius: 999px; }

@keyframes riseIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes softFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

[data-theme="dark"] {
  --ui-bg: #16181d;
  --ui-bg-accent: #1c2028;
  --ui-surface: #20242c;
  --ui-surface-soft: #1a1e25;
  --ui-border: #313949;
  --ui-border-strong: #3d475b;
  --ui-text: #e4eaf5;
  --ui-text-soft: #a1adbf;
  --ui-brand: #4b83ff;
  --ui-brand-strong: #3f72e0;
  --ui-shadow-sm: 0 8px 20px rgba(0, 0, 0, 0.22);
  --ui-shadow-md: 0 16px 32px rgba(0, 0, 0, 0.34);
}

[data-theme="dark"] body {
  background:
    radial-gradient(circle at 0% 0%, rgba(75, 131, 255, 0.08), transparent 28%),
    radial-gradient(circle at 100% 100%, rgba(75, 131, 255, 0.05), transparent 32%),
    var(--ui-bg);
}
[data-theme="dark"] header {
  background: rgba(32, 36, 44, 0.86);
  border-bottom-color: var(--ui-border);
}
[data-theme="dark"] button {
  background: #252b36;
  border-color: var(--ui-border);
  color: var(--ui-text-soft);
}
[data-theme="dark"] button:hover {
  background: #2b3340;
  border-color: var(--ui-border-strong);
}
[data-theme="dark"] button.primary {
  background: linear-gradient(180deg, #5a8eff 0%, var(--ui-brand) 100%);
  border-color: var(--ui-brand);
}
[data-theme="dark"] .card:hover { border-color: #4f6080; }
[data-theme="dark"] .agent-chat-sidebar { background: #1c212a; }
[data-theme="dark"] .agent-doc-panel {
  background: linear-gradient(180deg, #20242c 0%, #1d2128 100%);
  box-shadow: inset 1px 0 0 rgba(88, 129, 255, 0.07), inset -1px 0 0 rgba(88, 129, 255, 0.07);
}
[data-theme="dark"] .agent-chat-main { background: #171b22; }
[data-theme="dark"] .agent-chat-header,
[data-theme="dark"] .doc-panel-hd { background: rgba(32, 36, 44, 0.88); }
[data-theme="dark"] .agent-messages { background: #151a21; }

@media (max-width: 980px) {
  .workspace { padding: 14px 14px 18px; }
  .toolbar { gap: 8px; margin-bottom: 12px; }
  .toolbar h2 { font-size: 18px; }
  .grid { grid-template-columns: 1fr; gap: 12px; }
  .card { border-radius: 10px; padding: 14px; }
  .agent-chat-sidebar { width: 168px; min-width: 148px; }
  .agent-chat-main { min-width: 320px; width: 320px; }
  .doc-section-body { padding: 10px 8px; }
  .doc-editor { padding: 14px; font-size: 14px; line-height: 1.8; }
  .agent-input-bar { padding: 10px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    transform: none !important;
    scroll-behavior: auto !important;
  }
}

/* ============== Final redesign polish ============== */

/* --- Smooth scroll --- */
html {
  scroll-behavior: smooth;
}

/* --- Heading balance --- */
h1, h2, h3, h4, .card-title, .detail-title-block h2, .brand {
  text-wrap: balance;
}

/* --- Footer --- */
.site-footer {
  height: 36px;
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--ui-border, #dbe2ee);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  z-index: 50;
}
[data-theme="dark"] .site-footer {
  background: rgba(32, 36, 44, 0.78);
  border-top-color: #313949;
}
.footer-copy { font-size: 11px; color: #8892a6; }
[data-theme="dark"] .footer-copy { color: #8899b8; }
.footer-links { display: flex; gap: 16px; }
.footer-links a {
  font-size: 11px; color: #6a7790; text-decoration: none;
  transition: color .16s ease;
}
.footer-links a:hover { color: var(--ui-brand, #245dff); }
[data-theme="dark"] .footer-links a { color: #8899b8; }
[data-theme="dark"] .footer-links a:hover { color: #7eb3ff; }

/* --- Skeleton loading cards --- */
.skeleton-card {
  background: var(--ui-surface, #fff);
  border: 1px solid var(--ui-border, #dbe2ee);
  border-radius: var(--ui-radius-md, 12px);
  padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
  min-height: 140px;
  animation: skeleton-pulse 1.6s ease-in-out infinite;
}
.skeleton-line {
  height: 12px; border-radius: 6px;
  background: linear-gradient(90deg, #e8ecf4 25%, #dce2ee 50%, #e8ecf4 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.6s ease-in-out infinite;
}
.skeleton-line.wide { width: 100%; }
.skeleton-line.half { width: 58%; }
.skeleton-line.short { width: 34%; }
.skeleton-line.title { height: 16px; width: 72%; border-radius: 8px; }
[data-theme="dark"] .skeleton-card {
  background: var(--ui-surface, #20242c);
  border-color: #313949;
}
[data-theme="dark"] .skeleton-line {
  background: linear-gradient(90deg, #2b3340 25%, #384154 50%, #2b3340 75%);
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
@keyframes skeleton-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .84; }
}

/* --- Improved empty state --- */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 64px 24px; text-align: center; gap: 12px;
  color: var(--ui-text-soft, #596579); font-size: 14px;
}
.empty::before {
  content: "";
  width: 56px; height: 56px;
  background: var(--ui-text-soft, #8892a6);
  opacity: .2;
  border-radius: var(--ui-radius-md, 12px);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M4 5.5C4 4.1 5.1 3 6.5 3H20v16H6.5A2.5 2.5 0 0 0 4 21zM6.5 5A.5.5 0 0 0 6 5.5V17a4.4 4.4 0 0 1 .5 0H18V5z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M4 5.5C4 4.1 5.1 3 6.5 3H20v16H6.5A2.5 2.5 0 0 0 4 21zM6.5 5A.5.5 0 0 0 6 5.5V17a4.4 4.4 0 0 1 .5 0H18V5z'/%3E%3C/svg%3E") center / contain no-repeat;
  margin-bottom: 4px;
}
.empty .empty-action {
  margin-top: 8px;
  font-size: 13px;
  color: var(--ui-brand, #245dff);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  font-weight: 500;
}

/* --- Button active press feedback (reinforce) --- */
button:active:not(:disabled) {
  transform: scale(.97);
  transition: transform .08s ease;
}

/* --- Modal exit animation --- */
.modal { animation: modalIn .22s var(--ui-ease, cubic-bezier(.22,.61,.36,1)) both; }
@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
[data-theme="dark"] .modal {
  box-shadow: 0 8px 36px rgba(0,0,0,.5);
}

/* --- Inline error/warning polish --- */
.err {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-radius: var(--ui-radius-sm, 8px);
  background: #fff5f5; border: 1px solid #fdd;
  color: #d32f2f; font-size: 12px; margin-top: 8px;
}
[data-theme="dark"] .err {
  background: #2d1f1f; border-color: #4a2b2b; color: #f87171;
}

/* --- Nav skip-to-content (accessibility) --- */
.skip-link {
  position: absolute; top: -100px; left: 12px;
  z-index: 9999; padding: 8px 16px;
  background: var(--ui-brand, #245dff); color: #fff;
  border-radius: 0 0 8px 8px; font-size: 13px; text-decoration: none;
  transition: top .18s ease;
}
.skip-link:focus { top: 0; }

/* --- Link polish: kill dead # links --- */
a[href="#"] {
  opacity: .4; pointer-events: none; cursor: default;
}

/* --- Subtle grain overlay for depth --- */
body::after {
  content: "";
  position: fixed; inset: 0; 
  z-index: 99999; pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.03'/%3E%3C/svg%3E");
  opacity: 1;
}
@media (prefers-reduced-motion: reduce) {
  body::after { display: none; }
}

/* --- Ensure sidebar collapses cleanly --- */
.sidebar.collapsed + .workspace {
  margin-left: 0;
}
