/* ========== Reset & Base ========== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #eef2ff;
  --bg: #f8f9fa;
  --bg-white: #ffffff;
  --bg-sidebar: #ffffff;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --text: #1a1a2e;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --radius: 8px;
  --radius-sm: 4px;
  --toolbar-height: 48px;
  --sidebar-width: 380px;
  --sidebar-min-width: 300px;
  --sidebar-max-width: 600px;
  --left-sidebar-width: 200px;
  --left-sidebar-min-width: 0px;
  --left-sidebar-max-width: 300px;
}

/* ========== DARK MODE ========== */
[data-theme="dark"] {
  --bg: #1a1a2e;
  --bg-white: #252540;
  --bg-sidebar: #252540;
  --border: #333355;
  --border-light: #2a2a48;
  --primary-light: #2d2d50;
  --text: #e5e7eb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
}

[data-theme="dark"] html,
[data-theme="dark"] body {
  background: var(--bg);
  color: var(--text);
}

/* ---- N5: 护眼阅读模式 (米黄 sepia / 灰绿 green) ----
   作用于 PDF 页面 canvas（染色+调暗）+ 阅读区背景，不改位图数据。
   与暗黑模式正交（可叠加，暗黑下护眼仍给 canvas 暖色调）。 */
[data-readermode="sepia"] #viewerContainer { background: #f5ecd7; }
[data-readermode="sepia"] .page .canvasWrapper canvas {
  filter: sepia(0.45) saturate(0.85) brightness(0.96) contrast(0.98);
}
[data-readermode="green"] #viewerContainer { background: #dde8d8; }
[data-readermode="green"] .page .canvasWrapper canvas {
  filter: hue-rotate(-15deg) saturate(0.7) brightness(0.97) contrast(0.98);
}

[data-theme="dark"] .toolbar {
  background: var(--bg-white);
  border-bottom-color: var(--border);
}

[data-theme="dark"] .toolbar-btn:hover {
  background: var(--border-light);
  color: var(--text);
}

[data-theme="dark"] .toolbar-btn.active {
  background: var(--primary-light);
  color: var(--primary);
}

[data-theme="dark"] .page-indicator input {
  background: var(--bg);
  border-color: var(--border);
  color: var(--text);
}

[data-theme="dark"] .pdf-area {
  background: #12122a;
}

[data-theme="dark"] .page {
  background: #1e1e38;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

[data-theme="dark"] .right-sidebar {
  background: var(--bg-sidebar);
  border-left-color: var(--border);
}

[data-theme="dark"] .sidebar-tab-strip {
  background: var(--bg-white);
  border-bottom-color: var(--border);
}

[data-theme="dark"] .sidebar-tab {
  color: var(--text-muted);
}

[data-theme="dark"] .sidebar-tab:hover {
  color: var(--text-secondary);
}

[data-theme="dark"] .sidebar-tab.active {
  color: var(--primary);
}

[data-theme="dark"] .panel-header {
  border-bottom-color: var(--border-light);
}

[data-theme="dark"] .panel-btn:hover {
  background: var(--border-light);
  color: var(--text);
}

[data-theme="dark"] .chat-input-area {
  background: var(--bg-white);
  border-top-color: var(--border);
}

[data-theme="dark"] .chat-input-area textarea {
  background: var(--bg);
  border-color: var(--border);
  color: var(--text);
}

[data-theme="dark"] .chat-msg-ai .chat-bubble {
  background: var(--border-light);
  color: var(--text);
}

[data-theme="dark"] .chat-msg-ai .chat-bubble code,
[data-theme="dark"] .chat-msg-ai .chat-bubble pre {
  background: rgba(0,0,0,0.3);
}

[data-theme="dark"] .highlight-item {
  background: var(--bg);
  border-color: var(--border);
}

[data-theme="dark"] .comment-item {
  background: var(--bg);
  border-color: var(--border);
}

[data-theme="dark"] .context-menu {
  background: var(--bg-white);
  border-color: var(--border);
}

[data-theme="dark"] .ctx-item:hover {
  background: var(--primary-light);
}

[data-theme="dark"] .selection-toolbar {
  background: var(--bg-white);
  border-color: var(--border);
}

[data-theme="dark"] .sel-btn:hover {
  background: var(--border-light);
}

[data-theme="dark"] .summary-loading {
  background: var(--primary-light);
}

[data-theme="dark"] .markdown-body code,
[data-theme="dark"] .markdown-body pre {
  background: rgba(0,0,0,0.3);
}

[data-theme="dark"] .llm-warning {
  background: #3b2f10;
  border-bottom-color: #92600a;
  color: #fbbf24;
}

[data-theme="dark"] .llm-warning svg {
  color: #f59e0b;
}

[data-theme="dark"] .llm-warning-text p {
  color: #d97706;
}

[data-theme="dark"] .llm-warning-btn {
  background: #d97706;
}

[data-theme="dark"] .llm-warning-btn:hover {
  background: #b45309;
}

[data-theme="dark"] .left-sidebar {
  background: var(--bg-sidebar);
  border-right-color: var(--border);
}

[data-theme="dark"] .left-sidebar-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

[data-theme="dark"] .left-sidebar-toggle {
  background: var(--bg-white);
  border-color: var(--border);
  color: var(--text-secondary);
}

[data-theme="dark"] .thumbnail-item {
  border-color: var(--border);
}

[data-theme="dark"] .thumbnail-item.active {
  border-color: var(--primary);
}

[data-theme="dark"] .thumbnail-item:hover {
  border-color: var(--primary);
}

[data-theme="dark"] .outline-item {
  color: var(--text-secondary);
}

[data-theme="dark"] .outline-item:hover {
  color: var(--primary);
  background: var(--primary-light);
}

[data-theme="dark"] .drawing-toolbar {
  background: rgba(37, 37, 64, 0.9);
  border-color: var(--border);
}

[data-theme="dark"] .draw-tool-btn:hover {
  background: var(--border-light);
}

[data-theme="dark"] .draw-tool-btn.active {
  background: var(--primary-light);
  color: var(--primary);
}

[data-theme="dark"] .quiz-item {
  background: var(--bg);
  border-color: var(--border);
}

[data-theme="dark"] .citation-card {
  background: var(--bg);
  border-color: var(--border);
}

[data-theme="dark"] .bibtex-block {
  background: rgba(0,0,0,0.3);
  color: var(--text);
}

[data-theme="dark"] .btn-add-comment {
  border-color: var(--border);
  color: var(--text-secondary);
}

[data-theme="dark"] .btn-add-comment:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

[data-theme="dark"] .highlights-toolbar {
  border-bottom-color: var(--border-light);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text);
  background: var(--bg);
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* ========== TOOLBAR ========== */
.toolbar {
  flex-shrink: 0;
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 100;
}

.toolbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--toolbar-height);
  padding: 0 12px;
  gap: 12px;
}

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

.toolbar-logo {
  display: flex;
  align-items: center;
  gap: 6px;
}

.logo-text {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
}

.toolbar-center {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s;
  text-decoration: none;
}

.toolbar-btn:hover {
  background: var(--border-light);
  color: var(--text);
}

.toolbar-btn.active {
  background: var(--primary-light);
  color: var(--primary);
}

.nav-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.page-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-secondary);
}

.page-indicator input {
  width: 40px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px 4px;
  font-size: 13px;
  outline: none;
}

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

.page-divider {
  color: var(--text-muted);
}

.zoom-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.zoom-label {
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 40px;
  text-align: center;
}

.divider-v {
  width: 1px;
  height: 20px;
  background: var(--border);
}

.sidebar-toggle-btn {
  position: relative;
}

/* Loading bar */
.loading-bar {
  height: 2px;
  background: var(--border-light);
  overflow: hidden;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: none;
}

.loading-bar.visible {
  display: block;
}

.loading-progress {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.3s ease;
}

/* ========== MAIN CONTENT ========== */
.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ========== LEFT SIDEBAR ========== */
.left-sidebar {
  width: var(--left-sidebar-width);
  min-width: var(--left-sidebar-min-width);
  max-width: var(--left-sidebar-max-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  transition: width 0.25s ease;
}

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

.left-sidebar.collapsed .left-sidebar-content {
  opacity: 0;
  pointer-events: none;
}

.left-sidebar-tab-strip {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.left-sidebar-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 12px;
  transition: all 0.15s;
  border-bottom: 2px solid transparent;
}

.left-sidebar-tab:hover {
  color: var(--text-secondary);
}

.left-sidebar-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.left-sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  transition: opacity 0.2s ease;
}

/* Panels */
.left-sidebar-panel {
  display: none;
  height: 100%;
}

.left-sidebar-panel.active {
  display: block;
}

.thumbnail-item {
  width: 100%;
  max-width: 160px;
  cursor: pointer;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
  position: relative;
}

.thumbnail-item:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
}

.thumbnail-item.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.thumbnail-item canvas {
  display: block;
  width: 100%;
  height: auto;
}

.thumbnail-item canvas {
  display: block;
  width: 100%;
  height: auto;
}

/* Outline panel */
.outline-item {
  padding: 6px 8px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.1s;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.outline-item:hover {
  color: var(--primary);
  background: var(--primary-light);
}

/* ========== PDF AREA ========== */
.pdf-area {
  flex: 1;
  overflow: hidden;
  background: #e5e7eb;
  position: relative;
  padding: 16px;
  overflow-anchor: none;
}

/* PDFViewer container：PDFViewer 要求 container 为 position:absolute。
   inset:0 填满 #pdfArea 的 content 区（padding 内）。滚动由它承担。 */
.viewerContainer {
  position: absolute;
  inset: 0;
  overflow: auto;
}
.viewerContainer.grab-mode { cursor: grab; }
.viewerContainer.grab-mode .textLayer,
.viewerContainer.grab-mode .text-layer,
.viewerContainer.grab-mode .highlight-layer,
.viewerContainer.grab-mode .drawing-canvas { pointer-events: none; }
.viewerContainer.grabbing { cursor: grabbing !important; user-select: none; }
.viewerContainer .pdfViewer .page { margin: 0 auto 12px; box-shadow: 0 2px 8px rgba(0,0,0,.2); background: white; }

.pdf-pages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-start;
  width: fit-content;
}

/* ========== PDFViewer 容器（阶段1：官方 PDFViewer 接管）==========
   #pdfArea 作 PDFViewer 的 container（已 overflow:auto + position:relative），
   .pdfViewer 是 viewer 元素，.page 是每页容器（替代旧 .page）。
   参考 spike.html：.page 水平居中 + 阴影，垂直间距由 PDFViewer 自身管理。 */
.pdfViewer .page {
  margin: 10px auto;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  background: white;
}

.page {
  background: white;
  box-shadow: var(--shadow);
  position: relative;
  line-height: 0;
}

/* Grab / pan tool */
.pdf-area.grab-mode {
  cursor: grab;
}
.pdf-area.grab-mode .text-layer,
.pdf-area.grab-mode .highlight-layer,
.pdf-area.grab-mode .drawing-canvas {
  pointer-events: none;
}
.pdf-area.grabbing {
  cursor: grabbing !important;
  user-select: none;
}
.toolbar-btn.grab-active {
  background: var(--primary);
  color: white;
}

.page canvas {
  display: block;
}

.page .textLayer {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  opacity: 1;
  /* Bug3: PDF.js positions spans with transform (fontSize + tx/ty), NOT
     line-height, so shrinking line-height does not shift the text layer.
     But ::selection renders against the span's line-box (= lineHeight), so
     lowering it from 1 → 0.9 narrows the selection to fit the glyph instead
     of ringing it with a full font-size band. */
  line-height: 0.9;
}

.page .textLayer > span {
  color: transparent;
  position: absolute;
  white-space: pre;
  transform-origin: 0% 0%;
  cursor: text;
}

.page .textLayer ::selection {
  background: rgba(99, 102, 241, 0.5);
}

/* Highlight overlay */
.page .highlight-layer {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
}

.page .highlight-rect {
  position: absolute;
  border-radius: 2px;
  opacity: 0.35;
  /* pointer-events 不继承父层（.highlight-layer 的 none），子元素默认 auto 会拦截
     鼠标 → marker 区域无法选中/复制。显式 none 让鼠标穿透到 textLayer。 */
  pointer-events: none;
}

/* pm-marker 是绝对定位的覆盖 div（盖在 textLayer 文字上），不含文本节点。
   文本节点始终留在原生 textLayer span 内——这是 PDF.js 选区/复制正常的前提
   （若文本被移入 marker，拖拽选区锚点会漂移到 page div，选区失效）。
   ⚠️ pointer-events:none：让鼠标穿透到下层原生 textLayer span，PDF.js 选区/copy 正常。
   marker 纯作视觉层（背景/下划线），不承载点击（跳转走侧边栏列表 → citeJump）。
   position/left/top/width/height/backgroundColor/borderBottom 由 JS 内联设置。 */
.textLayer .pm-highlight {
  position: absolute;
  pointer-events: none;
  border-radius: 2px;
  box-sizing: border-box;
}

.textLayer .pm-underline {
  position: absolute;
  pointer-events: none;
  box-sizing: border-box;
}

.pdf-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 14px;
}

.pdf-error {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-secondary);
}

.pdf-error p {
  font-size: 14px;
}

.btn-retry {
  padding: 8px 20px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-spinner.small {
  width: 18px;
  height: 18px;
  border-width: 2px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ========== RIGHT SIDEBAR ========== */
.right-sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-min-width);
  max-width: var(--sidebar-max-width);
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: relative;
  transition: width 0.05s;
}

.right-sidebar.hidden {
  display: none;
}

.sidebar-resize-handle {
  position: absolute;
  left: -3px;
  top: 0;
  bottom: 0;
  width: 6px;
  cursor: col-resize;
  z-index: 10;
}

.sidebar-resize-handle:hover,
.sidebar-resize-handle.active {
  background: rgba(99, 102, 241, 0.2);
}

/* Tab strip */
.sidebar-tab-strip {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 4px;
  background: var(--bg-white);
  flex-shrink: 0;
}

.sidebar-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  height: 42px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-muted);
  position: relative;
  transition: color 0.15s;
}

.sidebar-tab:hover {
  color: var(--text-secondary);
}

.sidebar-tab.active {
  color: var(--primary);
}

.sidebar-tab.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 20%;
  right: 20%;
  height: 2px;
  background: var(--primary);
  border-radius: 2px 2px 0 0;
}

/* Panels */
.sidebar-panels {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.sidebar-panel {
  display: none;
  flex-direction: column;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

.sidebar-panel.active {
  display: flex;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.panel-header h3 {
  font-size: 14px;
  font-weight: 600;
}

.panel-header-actions {
  display: flex;
  gap: 4px;
}

.panel-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s;
}

.panel-btn:hover {
  background: var(--border-light);
  color: var(--text);
}

/* ========== CHAT PANEL ========== */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 13px;
}

.chat-msg {
  max-width: 100%;
}

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

.chat-msg-ai {
  align-self: flex-start;
}

.chat-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  word-wrap: break-word;
}

.chat-msg-user .chat-bubble {
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-msg-ai .chat-bubble {
  background: var(--border-light);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.chat-msg-ai .chat-bubble p {
  margin: 0 0 8px 0;
}

.chat-msg-ai .chat-bubble p:last-child {
  margin-bottom: 0;
}

.chat-msg-ai .chat-bubble code {
  background: rgba(0,0,0,0.06);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 12px;
}

.chat-msg-ai .chat-bubble pre {
  background: rgba(0,0,0,0.06);
  padding: 8px 10px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 12px;
}

.chat-typing {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1); }
}

.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-white);
  flex-shrink: 0;
}

.chat-input-area textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  max-height: 120px;
  line-height: 1.4;
}

.chat-input-area textarea:focus {
  border-color: var(--primary);
}

.btn-send {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--primary);
  color: white;
  border-radius: var(--radius);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}

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

.btn-send:disabled {
  background: var(--text-muted);
  cursor: not-allowed;
}

/* ========== SUMMARY PANEL ========== */
.summary-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.summary-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  background: var(--primary-light);
  border-radius: var(--radius);
  color: var(--primary);
  font-size: 13px;
  margin-bottom: 16px;
}

.summary-section {
  margin-bottom: 16px;
}

.summary-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.summary-text {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
}

.summary-placeholder {
  color: var(--text-muted);
  font-style: italic;
}

.summary-divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
  margin-top: 12px;
  margin-bottom: 6px;
  font-weight: 600;
}

.markdown-body h1 { font-size: 16px; }
.markdown-body h2 { font-size: 15px; }
.markdown-body h3 { font-size: 14px; }

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

.markdown-body ul, .markdown-body ol {
  padding-left: 20px;
  margin-bottom: 8px;
}

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

.markdown-body code {
  background: var(--border-light);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 12px;
}

.markdown-body pre {
  background: var(--border-light);
  padding: 8px 10px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 12px;
}

.markdown-body blockquote {
  border-left: 3px solid var(--primary);
  padding-left: 12px;
  margin: 8px 0;
  color: var(--text-secondary);
}

.markdown-body strong {
  font-weight: 600;
}

/* ========== MARKDOWN EXTENSIONS: tables / task lists / KaTeX ==========
   Added when renderMarkdown() moved to marked.js + KaTeX. These rules apply
   to both .markdown-body (summary/talk-script panels) and .chat-bubble
   (AI chat). Tables, task list checkboxes, and block/display math need
   explicit styling since marked/KaTeX emit the structure but the old
   hand-rolled renderer never had these elements. */

/* Tables — GFM pipe tables from marked */
.markdown-body table,
.chat-bubble table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 12.5px;
  display: block;            /* allow horizontal scroll on narrow sidebar */
  overflow-x: auto;
}
.markdown-body th,
.chat-bubble th {
  border: 1px solid var(--border);
  padding: 5px 8px;
  text-align: left;
  background: var(--border-light);
  font-weight: 600;
  white-space: nowrap;
}
.markdown-body td,
.chat-bubble td {
  border: 1px solid var(--border);
  padding: 5px 8px;
  vertical-align: top;
}
.markdown-body tr:nth-child(even) td,
.chat-bubble tr:nth-child(even) td {
  background: rgba(0, 0, 0, 0.02);
}

/* Task list checkboxes (GFM: - [ ] / - [x]) */
.markdown-body ul.contains-task-list,
.chat-bubble ul.contains-task-list,
.markdown-body li.task-list-item,
.chat-bubble li.task-list-item {
  list-style: none;
  padding-left: 4px;
}
.markdown-body input[type="checkbox"],
.chat-bubble input[type="checkbox"] {
  margin-right: 6px;
  vertical-align: middle;
  cursor: default;
  accent-color: var(--primary);
}

/* Ordered lists (marked emits <ol>; old CSS only styled <ul>) */
.markdown-body ol,
.chat-bubble ol {
  padding-left: 22px;
  margin: 8px 0;
}

/* Strikethrough, links, images, hr — elements the old renderer never produced */
.markdown-body del,
.chat-bubble del {
  color: var(--text-muted);
}
.markdown-body a,
.chat-bubble a {
  color: var(--primary);
  text-decoration: underline;
  word-break: break-all;
}
.markdown-body img,
.chat-bubble img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  margin: 6px 0;
}
.markdown-body hr,
.chat-bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

/* KaTeX math rendering. .katex is inline; .katex-display is block.
   Both come from katex.min.css; we add layout/scroll/spacing rules here. */
.markdown-body .katex,
.chat-bubble .katex {
  font-size: 1.05em;          /* slightly larger than body for legibility */
  white-space: nowrap;        /* avoid inline formula wrapping mid-symbol */
}
.markdown-body .katex-display,
.chat-bubble .katex-display {
  margin: 10px 0;
  overflow-x: auto;           /* long display formulas scroll, not overflow */
  overflow-y: hidden;
  padding: 2px 0;
  text-align: center;
}
/* KaTeX parse-error annotation (throwOnError:false output) — make it readable */
.markdown-body .katex-error,
.chat-bubble .katex-error,
.markdown-body .katex .mathnormal,
.chat-bubble .katex .mathnormal {
  color: inherit;
}
.markdown-body .katex-mathml,
.chat-bubble .katex-mathml {
  display: none;
}

/* In chat bubbles (light-gray bg) keep code/formula readable; KaTeX inherits
   the bubble text color, which already adapts via --text in dark mode. */
.chat-msg-user .chat-bubble .katex {
  color: #fff;                /* user bubble has primary bg → white math */
}

/* ========== CITATION SECTION ========== */
.citation-card {
  padding: 12px;
  background: var(--bg-white);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.citation-field {
  margin-bottom: 8px;
  font-size: 12px;
}

.citation-field:last-child {
  margin-bottom: 0;
}

.citation-label {
  font-weight: 600;
  color: var(--text-secondary);
  margin-right: 4px;
}

.citation-value {
  color: var(--text);
}

.bibtex-block {
  position: relative;
  background: var(--border-light);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-top: 8px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 200px;
  overflow-y: auto;
}

.bibtex-copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  background: var(--bg-white);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}

.bibtex-copy-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

.bibtex-copy-btn.copied {
  color: #16a34a;
  border-color: #16a34a;
}

/* ========== HIGHLIGHTS PANEL ========== */
.highlights-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border-light);
}

.color-pick {
  cursor: pointer;
  display: flex;
  align-items: center;
}

.color-pick input {
  display: none;
}

.color-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid transparent;
  transition: all 0.15s;
}

.color-pick input:checked + .color-dot {
  border-color: var(--text);
  transform: scale(1.15);
}

.highlights-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px;
}

/* ---- T1: 中英对照面板 ---- */
.translate-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px;
}
.translate-item {
  padding: 10px 12px;
  background: var(--bg-white);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  margin-bottom: 8px;
}
.translate-orig {
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-muted);
  /* 原文稍弱化，突出译文 */
}
.translate-trans {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--border-light);
}
.translate-trans.loading {
  color: var(--text-muted);
  font-style: italic;
}
.translate-page-tag {
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg-hover);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  display: inline-block;
}

/* ---- C3: 个人词表 ---- */
.glossary-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px;
}
.glossary-item {
  padding: 10px 12px;
  background: var(--bg-white);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  margin-bottom: 8px;
  position: relative;
}
.glossary-term {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.glossary-translation {
  font-weight: normal;
  color: var(--primary);
  margin-left: 2px;
}
.glossary-explanation {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
}
.glossary-meta {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
}
.glossary-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
}

/* ---- T4: 内联翻译气泡 ---- */
.translate-bubble {
  position: fixed;
  z-index: 1000;
  max-width: 340px;
  min-width: 160px;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  padding: 10px 28px 10px 12px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
}
.translate-bubble-text {
  white-space: pre-wrap;
  word-break: break-word;
}
.translate-bubble-text.loading {
  color: var(--text-muted);
  font-style: italic;
}
.translate-bubble-close {
  position: absolute;
  top: 4px;
  right: 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-sm);
}

/* ========== 悬浮翻译面板（可拖拽/PIN/折叠 + 虚线锚点）==========
   每段翻译一个独立面板，position:fixed 挂 body，z-index 高于普通气泡。 */
.translate-links {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1099;            /* 高于 .translate-bubble(1000)，低于 selectionToolbar(10001) */
}
.translate-links line.tp-link {
  stroke: var(--primary);
  stroke-width: 1.5;
  stroke-dasharray: 4 4;
  opacity: 0.5;
}

/* ========== 悬浮翻译面板（页内定位：钉在 PDF 内容上，滚动跟随）==========
   结构：.translate-panel 容器(position:absolute 挂 .page 内) 内含
   .tp-chip(常驻球，左上角) + .tp-card(译文卡，折叠时隐藏)。
   球始终可见、位置不变；展开时附加译文卡。 */
.translate-panel {
  position: absolute;
  z-index: 8;               /* 高于 textLayer(5)/drawing(6)，低于选区工具条 */
  width: 300px;
  min-height: 34px;         /* 球的高度，保证容器不塌陷（chip/card 绝对定位不撑父） */
}
.translate-panel.pinned .tp-chip { border-color: var(--primary); }

/* 常驻球：始终可见，容器左上角。折叠/展开点的都是它 */
.translate-panel .tp-chip {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid var(--text-muted);
  background: var(--bg-white);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  user-select: none;
  transition: transform 0.1s, border-color 0.15s, color 0.15s;
}
.translate-panel.pinned .tp-chip { color: var(--primary); }
.translate-panel .tp-chip:hover { transform: scale(1.08); }
.translate-panel .tp-chip:active { cursor: grabbing; }

/* 译文卡：展开时显示在球右侧，折叠时隐藏 */
.translate-panel .tp-card {
  position: absolute;
  left: 42px;               /* 球宽 34 + 间距 8 */
  top: 0;
  z-index: 1;
  width: 258px;             /* 总宽 300 = 42 + 258 */
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.translate-panel.pinned .tp-card { border-color: var(--primary); box-shadow: 0 6px 24px rgba(99,102,241,0.25); }
.translate-panel.folded .tp-card { display: none; }

/* hover 球预览：折叠态下鼠标移到球上自动展开 card（与展开态样式一致，含标题栏），
   移开恢复折叠。预览态与展开态的区别：header 底色微调 + card 外加一圈虚线轮廓，
   暗示"未展开，移开即消失"。这些预览标识都限定 .folded，点击展开(folded移除)后立即
   切换为展开态样式，无需等鼠标移开。*/
.translate-panel.folded.previewing .tp-card { display: flex; }
.translate-panel.folded.previewing .tp-resize { display: none; }  /* 折叠预览态不可调大小 */
.translate-panel.folded.previewing .tp-card {
  outline: 1.5px dashed var(--primary);                          /* 外圈虚线轮廓，预览标识 */
  outline-offset: 2px;
}
.translate-panel.folded.previewing .translate-panel-header {
  background: var(--primary-light);                             /* 标题栏底色微调，区分展开态 */
}
.translate-panel.previewing .tp-chip { transition: none; }

/* 右下角 resize 手柄 */
.translate-panel .tp-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  z-index: 2;
  background: linear-gradient(135deg, transparent 50%, var(--text-muted) 50%);
  background-size: 8px 8px;
  background-repeat: no-repeat;
  background-position: bottom right;
  opacity: 0.5;
}
.translate-panel .tp-resize:hover { opacity: 1; }
.translate-panel.folded .tp-resize { display: none; }

.translate-panel-header {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 4px 4px 6px;
  border-bottom: 1px solid var(--border-light);
  background: var(--border-light);
  cursor: grab;
  user-select: none;
  flex-shrink: 0;
}
.translate-panel-header:active { cursor: grabbing; }
.tp-drag-handle {
  display: flex;
  align-items: center;
  color: var(--text-muted);
  margin-right: 2px;
}
.tp-header-spacer { flex: 1; }
.tp-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}
.tp-icon-btn:hover { background: rgba(0,0,0,0.06); color: var(--text); }
.tp-icon-btn.active { background: var(--primary-light); color: var(--primary); }
[data-theme="dark"] .tp-icon-btn:hover { background: rgba(255,255,255,0.08); }

.translate-panel-body {
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  flex: 1 1 auto;            /* 撑满 card 剩余高度，resize card height 时自适应 */
  min-height: 60px;
  overflow-y: auto;
  word-break: break-word;
  scrollbar-width: thin;
  scrollbar-color: var(--text-muted) transparent;
}
.translate-panel-body.loading { color: var(--text-muted); font-style: italic; }
.translate-panel-body::-webkit-scrollbar { width: 8px; }
.translate-panel-body::-webkit-scrollbar-track { background: rgba(0,0,0,0.05); border-radius: 4px; }
.translate-panel-body::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 4px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.translate-panel-body::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); background-clip: padding-box; }
[data-theme="dark"] .translate-panel-body::-webkit-scrollbar-track { background: rgba(255,255,255,0.05); }

/* 原文浅高亮（比常规高亮更淡，标识"这段被翻译了"） */
.page .translate-source-hl {
  position: absolute;
  background: rgba(99, 102, 241, 0.13);
  border-radius: 2px;
  pointer-events: none;
  z-index: 3;
}
.page .translate-source-hl.pinned { background: rgba(99, 102, 241, 0.2); }


.term-map-box {
  border-bottom: 1px solid var(--border-light);
  padding: 8px 12px;
  background: var(--bg-hover);
}
.term-map-header {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.term-map-list {
  max-height: 120px;
  overflow-y: auto;
  margin-bottom: 6px;
}
.term-map-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 2px 0;
}
.term-map-row .tm-orig { color: var(--text); flex: 1; }
.term-map-row .tm-arrow { color: var(--text-muted); }
.term-map-row .tm-trans { color: var(--text); flex: 1; }
.term-map-row .tm-lock { color: #f59e0b; font-size: 11px; }
.term-map-row .tm-del {
  border: none; background: transparent; color: var(--text-muted);
  cursor: pointer; font-size: 14px; width: 18px; height: 18px;
}
.term-map-add {
  display: flex;
  gap: 4px;
}
.term-map-add input {
  flex: 1;
  font-size: 12px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-white);
  color: var(--text);
  min-width: 0;
}

/* ---- N1: 区域注释锚点 + 编辑器 ---- */
.note-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}
.region-note-anchor {
  position: absolute;
  pointer-events: auto;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
  user-select: none;
}
.region-note-anchor:hover {
  transform: translate(-50%, -50%) scale(1.25);
}
.region-note-bubble {
  font-size: 12px;
  max-width: 280px;
}
.region-note-editor {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1001;
  width: 320px;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
  padding: 14px;
  display: none;
}
.region-note-editor-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}
.region-note-editor textarea {
  width: 100%;
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-white);
  color: var(--text);
  resize: vertical;
  box-sizing: border-box;
}
.region-note-editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}
.region-note-editor-actions button {
  padding: 4px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-white);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
}
.region-note-editor-actions button.primary {
  background: var(--primary, #3b82f6);
  color: #fff;
  border-color: var(--primary, #3b82f6);
}

/* ---- L1: 本地 PDF 库 ---- */
.library-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  margin-bottom: 6px;
}
.library-item-main { flex: 1; min-width: 0; }
.library-item-name {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.library-item-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.library-item-open {
  padding: 3px 10px;
  font-size: 12px;
  border: 1px solid var(--primary, #3b82f6);
  background: transparent;
  color: var(--primary, #3b82f6);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.library-item-open:hover { background: var(--primary, #3b82f6); color: #fff; }
.library-item-del {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-sm);
}
button.primary { background: var(--primary, #3b82f6); color: #fff; border: none; }

/* ---- X4: 参考文献面板 ---- */
.references-panel {
  background: var(--bg-hover);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin-top: 6px;
  max-height: 280px;
  overflow-y: auto;
  display: none;
}
.ref-item {
  font-size: 11px;
  line-height: 1.5;
  color: var(--text);
  padding: 3px 0;
  border-bottom: 1px dashed var(--border-light);
}
.ref-num {
  color: var(--primary, #3b82f6);
  font-weight: 600;
  margin-right: 4px;
}
.ref-text { color: var(--text-muted); }

/* ---- L3: 笔记检索 ---- */
.note-search-item {
  padding: 8px 10px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 12px;
}
.note-search-item:hover { background: var(--bg-hover); }
.note-search-type {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  background: var(--primary, #3b82f6);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  margin-right: 6px;
}
.note-search-text {
  color: var(--text);
  line-height: 1.5;
}
.note-search-meta {
  display: block;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 3px;
}

.highlight-item {
  padding: 10px 12px;
  background: var(--bg-white);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  margin-bottom: 8px;
  position: relative;
}

.highlight-item-color {
  width: 100%;
  height: 3px;
  border-radius: 2px;
  margin-bottom: 8px;
}

.highlight-item-text {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.highlight-item-page {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.highlight-item-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
}

.highlight-item:hover .highlight-item-delete {
  opacity: 1;
}

.highlight-item-delete:hover {
  background: var(--border-light);
  color: #ef4444;
}

/* ========== COMMENTS PANEL ========== */
.comments-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px;
}

.comment-item {
  padding: 10px 12px;
  background: var(--bg-white);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.comment-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.comment-item-page {
  font-size: 11px;
  color: var(--primary);
  font-weight: 500;
}

.comment-item-delete {
  width: 18px;
  height: 18px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
}

.comment-item:hover .comment-item-delete {
  opacity: 1;
}

.comment-item-delete:hover {
  color: #ef4444;
}

.comment-item-text {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
}

.btn-add-comment {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  margin: 8px 16px 16px;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: all 0.15s;
}

.btn-add-comment:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 80px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 20px;
}

/* ========== QUIZ PANEL ========== */
.quiz-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.quiz-item {
  padding: 12px;
  background: var(--bg-white);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  margin-bottom: 12px;
}

.quiz-question {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 10px;
  line-height: 1.5;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.quiz-option {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text);
}

.quiz-option:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.quiz-option input[type="radio"] {
  margin-top: 2px;
  accent-color: var(--primary);
  flex-shrink: 0;
}

.quiz-option.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.quiz-score {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  margin-bottom: 16px;
  background: var(--primary-light);
  border-radius: var(--radius);
  text-align: center;
}

/* ========== CONTEXT MENU ========== */
/* ---- D3/D1/C4: 区域框选盒 ---- */
.region-select-box {
  position: absolute;
  border: 2px dashed #3b82f6;
  background: rgba(59, 130, 246, 0.12);
  pointer-events: none;
  z-index: 6;
}

/* ---- L2: 阅读进度条（页码指示器内的细横条）---- */
.read-progress {
  display: inline-block;
  width: 48px;
  height: 4px;
  background: var(--border-light);
  border-radius: 2px;
  margin-left: 8px;
  vertical-align: middle;
  overflow: hidden;
}
.read-progress-fill {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--primary, #3b82f6);
  border-radius: 2px;
  transition: width 0.2s ease;
}

.context-menu {
  position: fixed;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  z-index: 10000;
  min-width: 180px;
}

/* ========== LLM ACTIVITY (U6) ========== */
.llm-activity {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  z-index: 9000;
  font-size: 12px;
  color: var(--text-secondary);
}

.llm-stop-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  background: var(--bg-white);
  color: var(--text-muted);
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.15s;
}

.llm-stop-btn:hover {
  background: #fef2f2;
  color: #dc2626;
}

/* ========== WELCOME CARD (U1) ========== */
.llm-welcome {
  flex-direction: row !important;
  align-items: flex-start !important;
  gap: 12px !important;
  padding: 14px !important;
  background: linear-gradient(135deg, #eef2ff 0%, #f0fdf4 100%) !important;
  border: 1px solid var(--border) !important;
  border-left: 3px solid var(--primary) !important;
}

[data-theme="dark"] .llm-welcome {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(16, 185, 129, 0.1) 100%) !important;
}

.llm-welcome-icon {
  flex-shrink: 0;
  color: var(--primary);
  margin-top: 2px;
}

.llm-welcome-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.llm-welcome-body strong {
  font-size: 13px;
  color: var(--text);
}

.llm-welcome-body p {
  font-size: 11px;
  color: var(--text-secondary);
  margin: 4px 0 2px;
}

.llm-welcome-body ol {
  margin: 0;
  padding-left: 18px;
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.7;
}

.llm-welcome-body ol li::marker {
  color: var(--primary);
  font-weight: 600;
}

.llm-welcome-btn {
  flex-shrink: 0;
  align-self: center;
  padding: 6px 12px;
  background: var(--primary);
  color: white !important;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.llm-welcome-btn:hover {
  background: var(--primary-dark, #4f46e5);
  transform: translateY(-1px);
}

/* ========== AI DISCLAIMER (U5) ========== */
.ai-disclaimer {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #92400e;
  margin-top: 8px;
  padding: 6px 10px;
  background: #fffbeb;
  border-radius: var(--radius-sm);
  border-left: 2px solid #f59e0b;
}

[data-theme="dark"] .ai-disclaimer {
  color: #fcd34d;
  background: rgba(245, 158, 11, 0.1);
}

/* ========== TOAST with UNDO (U3) ========== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px 10px 18px;
  background: #1f2937;
  color: #f9fafb;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 9500;
  font-size: 13px;
  animation: toast-in 0.2s ease;
}

[data-theme="dark"] .toast {
  background: #fef9c3;
  color: #1c1917;
}

.toast-undo {
  background: transparent;
  border: none;
  color: #c7d2fe;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}

[data-theme="dark"] .toast-undo {
  color: #1e40af;
}

.toast-undo:hover {
  background: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .toast-undo:hover {
  background: rgba(0, 0, 0, 0.1);
}

@keyframes toast-in {
  from { transform: translate(-50%, 12px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

.ctx-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.1s;
}

.ctx-item:hover {
  background: var(--primary-light);
  color: var(--primary);
}

/* ========== SELECTION TOOLBAR ========== */
.selection-toolbar {
  position: fixed;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 4px 6px;
  z-index: 10001;
  display: flex;
  align-items: center;
  gap: 2px;
}

/* 词表译法：划词/双击命中词表时追加在工具条末尾，与高亮/下划线按钮共存。
   只显示中文译法（原文+解放在 title 悬停）。允许换行确保长译法完整可见。 */
.sel-glossary-hint {
  display: inline-block;
  align-items: center;
  padding: 2px 10px 2px 8px;
  margin-left: 2px;
  border-left: 1px solid var(--border);
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--primary);
  font-weight: 600;
  max-width: 320px;
  white-space: normal;
  word-break: break-word;
}
.sel-glossary-hint .sel-glossary-orig {
  color: var(--text-secondary);
  font-weight: normal;
}

/* ========== GLOSSARY BAR (PDF 区浮动词表提取入口) ==========
   与右上角 findBar 对称，放左上角。词表提取的主入口在此，
   右侧侧边栏的词表面板仅作预览/管理。 */
.glossary-bar {
  position: absolute;
  top: 12px;
  left: 16px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 8px);
  box-shadow: var(--shadow-lg);
}
.glossary-bar-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 12px;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.glossary-bar-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
}
.glossary-bar-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
[data-theme="dark"] .glossary-bar {
  background: var(--bg-white);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

/* ========== FIND BAR (Bug 3: pdf.js FindController) ========== */
.find-bar {
  position: absolute;
  top: 12px;
  right: 16px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 6px;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 8px);
  box-shadow: var(--shadow-lg);
}
.find-input {
  width: 180px;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.find-input:focus { border-color: var(--primary); }
.find-count {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 56px;
  text-align: center;
  white-space: nowrap;
}
.find-count.no-match { color: var(--danger, #ef4444); }
.find-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background 0.15s;
}
.find-btn:hover { background: var(--border-light); color: var(--text); }
[data-theme="dark"] .find-bar { background: var(--bg-white); box-shadow: 0 4px 16px rgba(0,0,0,.5); }

.sel-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--text-secondary);
}

.sel-btn:hover {
  background: var(--border-light);
}

.sel-color-dot {
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  transition: transform 0.15s;
}

.sel-btn:hover .sel-color-dot {
  transform: scale(1.15);
}

.sel-btn.sel-underline:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.sel-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 2px;
}

/* Underline overlay */
.page .underline-rect {
  position: absolute;
  height: 2px;
  opacity: 0.7;
  pointer-events: none;
}

/* ========== DRAWING TOOLS ========== */
.drawing-toolbar {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--shadow-lg);
  z-index: 50;
}

.drawing-toolbar.hidden {
  display: none;
}

.draw-tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s;
}

.draw-tool-btn:hover {
  background: var(--border-light);
}

.draw-tool-btn.active {
  background: var(--primary-light);
  color: var(--primary);
}

.drawing-color-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
}

.drawing-color-btn:hover {
  transform: scale(1.15);
}

.drawing-color-btn.active {
  border-color: var(--text);
  transform: scale(1.15);
}

.drawing-stroke-slider {
  width: 60px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.drawing-stroke-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
}

.drawing-toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
}

.drawing-canvas {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 5;
}

.drawing-canvas.active {
  pointer-events: auto;
  cursor: crosshair;
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ---- PDF 内容区滚动条：全局 thumb 颜色恰好与 .pdf-area 背景 (#e5e7eb) 同色，
   导致滚动条"隐形"。这里给 #viewerContainer 单独一套高对比、易抓取的滚动条，
   宽度加到 12px，thumb 用 text-muted（在浅/深色背景下都可见），hover 加深。 */
#viewerContainer {
  scrollbar-width: thin;                       /* Firefox: 保留细滚动条 */
  scrollbar-color: var(--text-muted) transparent;
}
#viewerContainer::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}
#viewerContainer::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.06);
  border-radius: 6px;
}
#viewerContainer::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 6px;
  border: 3px solid transparent;
  background-clip: padding-box;                /* border 让 thumb 视觉收窄到 ~6px，更精致 */
}
#viewerContainer::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
  background-clip: padding-box;
}
[data-theme="dark"] #viewerContainer::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
}

/* ---- 左侧边栏滚动条：背景为白色 (--bg-sidebar)，全局 thumb 色 (#e5e7eb) 在白底
   上对比度极低，几乎不可见。这里给 .left-sidebar-content（真正滚动容器）单独一套
   高对比滚动条。左栏较窄(200px)，用 8px 比 PDF 区(12px)略细，thumb 仍用 text-muted。 */
.left-sidebar-content {
  scrollbar-width: thin;
  scrollbar-color: var(--text-muted) transparent;
}
.left-sidebar-content::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
.left-sidebar-content::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.05);
  border-radius: 4px;
}
.left-sidebar-content::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 4px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.left-sidebar-content::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
  background-clip: padding-box;
}
[data-theme="dark"] .left-sidebar-content::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
}

/* ========== Selection styles ========== */
::selection {
  background: rgba(99, 102, 241, 0.4);
}

/* ========== LLM WARNING BANNER ========== */
.llm-warning {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: #fef3c7;
  border-bottom: 1px solid #fbbf24;
  color: #92400e;
  flex-shrink: 0;
}

.llm-warning svg {
  flex-shrink: 0;
  margin-top: 1px;
  color: #d97706;
}

.llm-warning-text {
  flex: 1;
  font-size: 12px;
  line-height: 1.4;
}

.llm-warning-text strong {
  display: block;
  font-size: 13px;
  margin-bottom: 2px;
}

.llm-warning-text p {
  margin: 0;
  color: #a16207;
}

.llm-warning-btn {
  flex-shrink: 0;
  padding: 4px 12px;
  background: #d97706;
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  align-self: center;
}

.llm-warning-btn:hover {
  background: #b45309;
}

/* ---- U10: Shortcut help modal ---- */
.shortcut-help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: shortcut-fade-in 0.15s ease-out;
}

.shortcut-help-modal {
  background: #ffffff;
  color: #1f2937;
  border-radius: 10px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.25);
  width: min(520px, 92vw);
  max-height: 86vh;
  overflow-y: auto;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

[data-theme="dark"] .shortcut-help-modal {
  background: #1f2937;
  color: #e5e7eb;
}

.shortcut-help-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] .shortcut-help-header {
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

.shortcut-help-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.shortcut-help-close {
  background: transparent;
  border: none;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  color: inherit;
  opacity: 0.6;
  padding: 4px 8px;
  border-radius: 4px;
}

.shortcut-help-close:hover {
  background: rgba(0, 0, 0, 0.06);
  opacity: 1;
}

[data-theme="dark"] .shortcut-help-close:hover {
  background: rgba(255, 255, 255, 0.08);
}

.shortcut-help-body {
  padding: 8px 20px 16px;
}

.shortcut-section {
  padding: 10px 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .shortcut-section {
  border-bottom-color: rgba(255, 255, 255, 0.05);
}

.shortcut-section:last-child {
  border-bottom: none;
}

.shortcut-section h4 {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
}

[data-theme="dark"] .shortcut-section h4 {
  color: #9ca3af;
}

.shortcut-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  font-size: 13px;
}

.shortcut-row span {
  color: #4b5563;
}

[data-theme="dark"] .shortcut-row span {
  color: #d1d5db;
}

.shortcut-row kbd {
  display: inline-block;
  padding: 2px 7px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-weight: 600;
  color: #1f2937;
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08);
  min-width: 20px;
  text-align: center;
}

[data-theme="dark"] .shortcut-row kbd {
  background: #374151;
  border-color: #4b5563;
  color: #f9fafb;
}

@keyframes shortcut-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ---- U8: inline comment editor ---- */
.comment-editor {
  margin: 8px 12px 12px;
  padding: 10px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  animation: comment-editor-in 0.15s ease-out;
}

[data-theme="dark"] .comment-editor {
  background: #1f2937;
  border-color: #374151;
}

.comment-editor textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 13px;
  color: inherit;
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  resize: vertical;
  min-height: 60px;
}

[data-theme="dark"] .comment-editor textarea {
  background: #111827;
  border-color: #4b5563;
  color: #f3f4f6;
}

.comment-editor textarea:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.comment-editor-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.comment-editor-page {
  margin-right: auto;
  font-size: 11px;
  color: #6b7280;
}

[data-theme="dark"] .comment-editor-page {
  color: #9ca3af;
}

.comment-editor-btn {
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid transparent;
}

.comment-editor-btn.cancel {
  background: transparent;
  color: #6b7280;
  border-color: #d1d5db;
}

[data-theme="dark"] .comment-editor-btn.cancel {
  color: #d1d5db;
  border-color: #4b5563;
}

.comment-editor-btn.cancel:hover {
  background: #f3f4f6;
}

[data-theme="dark"] .comment-editor-btn.cancel:hover {
  background: #374151;
}

.comment-editor-btn.save {
  background: #3b82f6;
  color: #ffffff;
}

.comment-editor-btn.save:hover {
  background: #2563eb;
}

@keyframes comment-editor-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---- U7: more-tabs dropdown ---- */
.sidebar-more {
  position: relative;
  margin-left: auto;
}

.sidebar-more-trigger {
  /* inherits .sidebar-tab styles */
}

.sidebar-more-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
  padding: 4px;
  min-width: 140px;
  z-index: 100;
  animation: more-menu-in 0.12s ease-out;
}

[data-theme="dark"] .sidebar-more-menu {
  background: #1f2937;
  border-color: #374151;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.sidebar-more-item {
  display: flex !important;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px !important;
  border: none;
  background: transparent;
  color: #1f2937;
  font-size: 13px;
  border-radius: 4px;
  cursor: pointer;
  text-transform: none;
}

[data-theme="dark"] .sidebar-more-item {
  color: #e5e7eb;
}

.sidebar-more-item:hover {
  background: #f3f4f6;
}

[data-theme="dark"] .sidebar-more-item:hover {
  background: #374151;
}

.sidebar-more-item.active {
  background: #eff6ff;
  color: #2563eb;
}

[data-theme="dark"] .sidebar-more-item.active {
  background: #1e3a8a;
  color: #93c5fd;
}

.sidebar-more-item span {
  font-weight: 500;
}

@keyframes more-menu-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ========== C1: CITATION CHIPS ========== */
/* Inline clickable [p3, §2.1] marker appended to AI sentences. Clicking jumps
   to the cited page and flashes the source text. */
.citation-chip {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  padding: 0 6px;
  margin: 0 1px;
  font-size: 11px;
  font-family: inherit;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, color 0.15s, transform 0.1s;
  vertical-align: baseline;
  white-space: nowrap;
  border: 1px solid transparent;
}

.citation-chip:hover {
  background: var(--primary);
  color: #ffffff;
  transform: translateY(-1px);
}

.citation-chip:active {
  transform: translateY(0);
}

[data-theme="dark"] .citation-chip {
  background: rgba(99, 102, 241, 0.18);
}

/* Citation list footer under AI messages — shows deduped [pN, §X] summary */
.citation-list {
  margin-top: 8px;
  padding: 6px 10px;
  background: var(--bg);
  border-left: 2px solid var(--primary);
  border-radius: 0 4px 4px 0;
  font-size: 11px;
}

[data-theme="dark"] .citation-list {
  background: rgba(99, 102, 241, 0.06);
}

.cite-list-title {
  color: var(--text-secondary);
  font-weight: 500;
}

.citation-list ul {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  list-style: none;
  padding: 4px 0 0;
  margin: 0;
}

.cite-list-page {
  color: var(--primary);
  font-weight: 500;
}

/* C1: transient flash highlight hugging the cited text. Painted INTO the
   .textLayer (same mount point + box model as .pm-highlight, so the geometry
   lines up exactly with user highlights — no offset). The animation blinks 3
   times within 1s (user-perceived "闪烁一秒钟"), then fades over 0.5s. Total
   ~1.5s; the element is removed at 1.6s. */
.textLayer .citation-flash {
  position: absolute;
  background: #fbbf24;
  border-radius: 2px;
  pointer-events: none;
  box-sizing: border-box;
  animation: cite-flash 1.5s ease-out forwards;
}

@keyframes cite-flash {
  0%   { opacity: 0; }
  10%  { opacity: 0.85; }
  25%  { opacity: 0.15; }
  40%  { opacity: 0.85; }
  55%  { opacity: 0.15; }
  70%  { opacity: 0.85; }
  80%  { opacity: 0.7; }
  100% { opacity: 0; }
}
