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

:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface2: #faf9f6;
  --border: #e0ddd6;
  --border-strong: #b8b3a8;
  --text: #1c1c1c;
  --text-dim: #6e6a62;
  --accent: #7a3b2e;
  --accent-light: #f2e4e0;
  --accent-mid: #c47a68;
  --code-bg: #f4f1ea;
  --patch-bg: #eef4ee;
  --patch-border: #6a8b6a;
  --toolbar-bg: #eeecea;
  --pane-label: #8c8880;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  /* App-chrome font (menus, toolbar, modals, sidebar, status pills). The
     editor body uses a separate `--clean-font-family` so the writer's
     Format-menu choice (Charter, Bookman, etc.) is independent of the UI.
     Noto Sans matches Overleaf's chrome; the system stack covers the brief
     moment before the web font loads and the case where the user has
     blocked fonts.googleapis.com. */
  --ui-font: 'Noto Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
}

html, body { height: 100%; font-family: var(--ui-font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }

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

/* Header */
header {
  display: flex; align-items: center;
  padding: 0 18px; height: 48px;
  background: var(--accent); color: white;
  flex-shrink: 0; box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}
header h1 { font-size: 17px; font-weight: normal; letter-spacing: 0.6px; color: white; }
.header-spacer { flex: 1; }
.status {
  font-size: 11px; font-family: 'Courier New', monospace;
  padding: 3px 9px; border-radius: 20px;
  background: rgba(255,255,255,0.15); color: rgba(255,255,255,0.8);
  border: 1px solid rgba(255,255,255,0.25);
}
.status.connected { background: rgba(255,255,255,0.25); color: white; }

.save-status {
  font-size: 11px; font-family: 'Courier New', monospace;
  padding: 3px 9px; margin-left: 6px; border-radius: 20px;
  background: rgba(255,255,255,0.15); color: rgba(255,255,255,0.85);
  border: 1px solid rgba(255,255,255,0.25);
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}
.save-status.save-saved   { background: rgba(124,207,138,0.30); border-color: rgba(124,207,138,0.55); color: #e6ffec; }
.save-status.save-saving  { background: rgba(255,217,102,0.25); border-color: rgba(255,217,102,0.55); color: #fff7d6; }
.save-status.save-offline { background: rgba(255,120,120,0.30); border-color: rgba(255,120,120,0.55); color: #ffe0e0; }

/* Views */
#main { flex: 1; overflow: hidden; display: flex; }
.view { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.view.hidden { display: none; }
/* The editor view manages its own internal panes, so .view clips overflow.
   The landing (document list) view has no inner scroll region of its own, so
   it must scroll as a whole when the list is taller than the viewport. */
#landing-view { overflow-y: auto; }

/* Landing */
.landing-container { max-width: 680px; width: 100%; margin: 56px auto; padding: 0 24px; }
.landing-container h2 { font-size: 26px; font-weight: normal; margin-bottom: 28px; }
.new-doc-row { display: flex; gap: 10px; margin-bottom: 32px; }
.new-doc-row input {
  flex: 1; padding: 10px 14px; font-family: inherit; font-size: 15px;
  border: 1px solid var(--border-strong); border-radius: 4px; background: var(--surface);
}
.new-doc-row input:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

button {
  padding: 8px 16px; font-family: inherit; font-size: 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 4px; cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
button:hover { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.doc-list { list-style: none; }
.doc-list li {
  display: flex; align-items: center; padding: 14px 16px;
  border: 1px solid var(--border); border-radius: 5px; margin-bottom: 8px;
  background: var(--surface); cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.doc-list li:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.doc-list .doc-title-cell { flex: 1; font-size: 15px; }
.doc-list .doc-meta { font-size: 12px; color: var(--text-dim); margin-right: 12px; }
.doc-list .delete-btn { padding: 4px 8px; font-size: 12px; color: var(--text-dim); }
/* Appendices render indented under their paper, with a smaller, dimmer title
   and a connector tick so the hierarchy reads at a glance. */
.doc-list li.doc-appendix { margin-left: 28px; margin-top: -4px; background: var(--surface2, #faf8f5); }
.doc-list li.doc-appendix .doc-title-cell { font-size: 13px; color: var(--text-dim); }
.doc-list li.doc-appendix .doc-title-cell::before { content: "↳ "; opacity: 0.6; }

/* Editor header */
.editor-header {
  display: flex; align-items: center; padding: 6px 14px; min-height: 50px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  gap: 10px; flex-shrink: 0; flex-wrap: wrap;
}
.icon-btn { padding: 5px 11px; font-size: 16px; }
.doc-title {
  flex: 1; padding: 6px 10px; font-family: inherit; font-size: 16px;
  border: 1px solid transparent; background: transparent; border-radius: 4px;
}
.doc-title:hover { border-color: var(--border); }
.doc-title:focus { outline: 2px solid var(--accent); border-color: var(--accent); background: var(--surface); }
.editor-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; row-gap: 6px; }
.model-select {
  padding: 5px 8px; font-family: inherit; font-size: 13px;
  border: 1px solid var(--border-strong); border-radius: 4px;
  background: var(--surface); color: var(--text); cursor: pointer;
}
.extended-thinking-label {
  display: flex; align-items: center; gap: 5px; font-size: 13px;
  color: var(--text-dim); cursor: pointer; white-space: nowrap;
}
.extended-thinking-label input { accent-color: var(--accent); }
.compile-btn {
  background: var(--accent); color: white; border-color: var(--accent);
  padding: 6px 16px; white-space: nowrap;
}
.compile-btn:hover { background: #923f30; border-color: #923f30; color: white; }
.compile-status { font-size: 12px; color: var(--text-dim); font-family: 'Courier New', monospace; white-space: nowrap; }
.compile-status.error { color: #b33; }
.compile-status.success { color: #2d7a2d; }
.compile-status.importing { font-weight: 700; color: var(--text); animation: compile-blink 1s steps(2, start) infinite; }
@keyframes compile-blink { to { visibility: hidden; } }

/* Toolbar */
.toolbar {
  display: flex; flex-direction: column; gap: 4px; padding: 6px 12px;
  background: var(--toolbar-bg); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.toolbar-row {
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
}
.toolbar-label {
  font-size: 11px; color: var(--text-dim); text-transform: uppercase;
  letter-spacing: 0.5px; margin-right: 4px; font-family: 'Courier New', monospace;
}
.tb-btn {
  padding: 3px 9px; font-size: 13px; border-radius: 3px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); cursor: pointer; font-family: var(--ui-font);
  min-width: 28px;
}
.tb-btn:hover { background: var(--accent-light); border-color: var(--accent-mid); color: var(--accent); }
.tb-bold { font-weight: bold; }
.tb-italic { font-style: italic; }
.tb-under { text-decoration: underline; }
.tb-strike { text-decoration: line-through; }
.tb-divider { width: 1px; height: 20px; background: var(--border-strong); margin: 0 4px; }

/* Toolbar dropdown menus (heading, insert) -- reuses the doc-menu aesthetic */
.tb-menu-wrap { position: relative; display: inline-block; }
.tb-menu-btn {
  padding: 3px 10px; font-size: 13px; border-radius: 3px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); cursor: pointer; font-family: var(--ui-font);
  white-space: nowrap;
}
.tb-menu-btn:hover { background: var(--accent-light); border-color: var(--accent-mid); color: var(--accent); }
.tb-menu {
  position: absolute; top: calc(100% + 4px); left: 0;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 5px; box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  min-width: 180px; z-index: 100; overflow: hidden;
}
.tb-menu.hidden { display: none; }
.tb-menu-scroll { max-height: 320px; overflow-y: auto; }
.tb-menu .menu-item {
  display: block; width: 100%; text-align: left;
  padding: 8px 14px; font-size: 13px; font-family: var(--ui-font);
  background: none; border: none; border-radius: 0; cursor: pointer;
  color: var(--text);
}
.tb-menu .menu-item:hover { background: var(--accent-light); color: var(--accent); }

/* Five panes when outline is open: outline | splitter | editor | splitter | chat.
   Collapses to three when the outline is hidden. The outline splitter is
   wider than the chat splitter (14px vs 6px) so the stacked ‹/› chevrons
   that signal toggle-on-click fit comfortably. */
.editor-body {
  flex: 1; display: grid;
  grid-template-columns: var(--outline-pane-width, 220px) 14px 1fr 6px var(--chat-pane-width, 400px);
  overflow: hidden;
}
/* Collapsed state: pane shrinks to zero, but the splitter stays visible on
   the left edge so the user can click it to re-expand. Widened to 20px
   (vs 6px when expanded) so the strip is easy to spot and click. The pane
   keeps its grid slot (display:none would let auto-flow shift the splitter
   into column 1, collapsing it to its 2px borders); .pane already has
   overflow:hidden, so zero-width is enough to hide the content. */
.editor-body.outline-collapsed {
  grid-template-columns: 0 20px 1fr 6px var(--chat-pane-width, 400px);
}
.editor-body.outline-collapsed #outline-pane { border-right: none; }

/* Chat (AI) pane collapse — mirrors the outline pane but on the right edge.
   The pane shrinks to zero while its splitter widens to 20px and stays on the
   right so it can be clicked to re-expand. Four grid permutations cover the
   independent outline/chat collapse states. */
.editor-body.chat-collapsed {
  grid-template-columns: var(--outline-pane-width, 220px) 14px 1fr 20px 0;
}
.editor-body.outline-collapsed.chat-collapsed {
  grid-template-columns: 0 20px 1fr 20px 0;
}
.editor-body.chat-collapsed .chat-pane { border-left: none; }
#pane-splitter { position: relative; }
/* Stacked ›/‹ chevrons signal "click to toggle" (mirrors #outline-splitter).
   Arrows point the way the pane would move: collapse to the right. */
#pane-splitter::before {
  content: '›\A‹';
  white-space: pre;
  text-align: center;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 12px; line-height: 1.05;
  color: var(--text-dim, #888);
  pointer-events: none;
  letter-spacing: 0;
}
#pane-splitter:hover::before { color: var(--accent, #7a3b2e); }
.editor-body.chat-collapsed #pane-splitter { background: var(--surface2); }
.editor-body.chat-collapsed #pane-splitter::before { font-size: 16px; }
.editor-body.chat-collapsed #pane-splitter:hover {
  background: var(--accent-mid, rgba(122, 59, 46, 0.4));
}
/* Stacked ‹/› chevrons on the outline splitter signal "click to toggle".
   Always visible — collapsed grows them slightly to match the wider strip. */
#outline-splitter { position: relative; }
#outline-splitter::before {
  content: '‹\A›';
  white-space: pre;
  text-align: center;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 12px; line-height: 1.05;
  color: var(--text-dim, #888);
  pointer-events: none;
  letter-spacing: 0;
}
#outline-splitter:hover::before { color: var(--accent, #7a3b2e); }
.editor-body.outline-collapsed #outline-splitter { background: var(--surface2); }
.editor-body.outline-collapsed #outline-splitter::before { font-size: 16px; }
.editor-body.outline-collapsed #outline-splitter:hover {
  background: var(--accent-mid, rgba(122, 59, 46, 0.4));
}

/* Outline pane */
.outline-pane { background: #fdfcf8; }
.outline-header {
  padding: 6px 14px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--pane-label); background: var(--surface2); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.outline-list {
  list-style: none; margin: 0; padding: 6px 0; overflow-y: auto; flex: 1;
  font-size: 13px; line-height: 1.4;
}
.outline-list li {
  padding: 3px 14px; cursor: pointer; user-select: none;
  color: var(--text, #222); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.outline-list li:hover { background: rgba(122, 59, 46, 0.08); }
.outline-list li.outline-empty {
  cursor: default; color: var(--text-dim, #888); font-style: italic; white-space: normal;
  padding: 8px 14px; line-height: 1.45;
}
.outline-list li.outline-empty:hover { background: transparent; }
.outline-list li.outline-level-1 { font-weight: 600; }
.outline-list li.outline-level-2 { padding-left: 28px; }
.outline-list li.outline-level-3 { padding-left: 42px; color: var(--text-dim, #555); }
/* Synthesized AI-suggestion entries read as AI notes (purple ✦), matching the
   AI Notes tab / in-text [N] pill. */
.outline-list li.outline-suggestion { color: #7b5cd6; }
.outline-list li.outline-suggestion:hover { background: rgba(123, 92, 214, 0.10); }
.pane { display: flex; flex-direction: column; border-right: 1px solid var(--border); overflow: hidden; background: var(--surface); }
.pane:last-child { border-right: none; }
.pane.chat-pane { border-right: none; min-width: 0; }
.pane-splitter {
  cursor: col-resize; background: transparent;
  border-left: 1px solid var(--border); border-right: 1px solid var(--border);
  transition: background 0.12s;
}
.pane-splitter:hover, .pane-splitter.dragging {
  background: var(--accent-mid, rgba(122, 59, 46, 0.4));
  border-left-color: var(--accent, #7a3b2e);
  border-right-color: var(--accent, #7a3b2e);
}
body.col-resizing { cursor: col-resize; user-select: none; }
body.col-resizing iframe { pointer-events: none; }

/* Claude controls (model selector + extended thinking) inside the chat pane */
.claude-controls {
  display: flex; gap: 10px; align-items: center;
  padding: 6px 10px; flex-shrink: 0;
  background: var(--surface2); border-bottom: 1px solid var(--border);
}
.claude-controls .model-select { font-size: 12px; padding: 3px 6px; }
.claude-controls .extended-thinking-label { font-size: 11px; color: var(--text-dim, #888); }
.pane-label {
  padding: 6px 14px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--pane-label); background: var(--surface2); border-bottom: 1px solid var(--border);
  flex-shrink: 0; display: flex; align-items: center; gap: 10px;
}
.pane-hint { font-size: 11px; color: var(--border-strong); text-transform: none; letter-spacing: 0; }

/* Editor pane */
.editor-pane { background: #fdfcf8; position: relative; }

/* Page-number indicator: shown in Clean view at the configured corner.
   Decorative hint — Clean view does not paginate, so this is one badge
   at the editor-pane corner, not per-page. */
.cm-clean-pagenum-badge {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  font-family: var(--ui-font);
  font-size: 16px;
  font-weight: 500;
  color: var(--text, #333);
  background: rgba(253, 252, 248, 0.94);
  padding: 4px 12px;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  min-width: 30px;
  text-align: center;
}
.cm-clean-pagenum-badge.is-hidden { display: none; }
.cm-clean-pagenum-badge.pos-top-left     { top: 10px; left: 14px; }
.cm-clean-pagenum-badge.pos-top-center   { top: 10px; left: 50%; transform: translateX(-50%); }
.cm-clean-pagenum-badge.pos-top-right    { top: 10px; right: 14px; }
.cm-clean-pagenum-badge.pos-bottom-left  { bottom: 10px; left: 14px; }
.cm-clean-pagenum-badge.pos-bottom-center{ bottom: 10px; left: 50%; transform: translateX(-50%); }
.cm-clean-pagenum-badge.pos-bottom-right { bottom: 10px; right: 14px; }

/* Clean-view page-layout status banner. Floats at the top-centre of the
   editor pane while a document has no page map yet — first compile running
   ("Generating page layout…") or failed (".is-error"). Hidden once the
   page transitions exist. */
.clean-page-status {
  position: absolute;
  z-index: 6;
  top: 46px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 80%;
  pointer-events: none;
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica, sans-serif;
  font-size: 12.5px;
  font-weight: 500;
  color: rgba(122, 78, 46, 0.92);
  background: #fdf6e3;
  padding: 7px 16px;
  border-radius: 16px;
  border: 1px solid rgba(122, 78, 46, 0.30);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.clean-page-status.is-error {
  color: rgba(150, 45, 20, 0.96);
  background: #fbeadb;
  border-color: rgba(180, 70, 30, 0.45);
  white-space: normal;
  /* The error state carries an actionable button; re-enable pointer events
     (the base pill is pointer-events:none for the passive "generating…" tip). */
  pointer-events: auto;
  max-width: 460px;
  padding: 11px 18px;
  text-align: left;
  line-height: 1.4;
}
.clean-page-status-detail {
  display: block;
  margin-top: 4px;
  font-weight: 400;
}
.clean-page-status-fix {
  display: inline-block;
  margin-top: 10px;
}
.clean-page-status.is-hidden { display: none; }

#editor { flex: 1; overflow: auto; font-family: 'Menlo', 'Courier New', monospace; font-size: 14px; }
#editor .cm-editor { height: 100%; }
#editor .cm-scroller { font-family: inherit; overflow: auto; }
#editor .cm-content { padding: 16px 14px; }

/* PDF pane */
.pdf-placeholder {
  flex: 1; display: flex; align-items: center; justify-content: center;
  background: #e8e6e1;
}
.pdf-placeholder-inner { text-align: center; color: var(--text-dim); }
.pdf-icon { font-size: 52px; margin-bottom: 14px; opacity: 0.45; }
.pdf-placeholder-inner p { font-size: 14px; line-height: 1.7; }
#pdf-frame { flex: 1; width: 100%; border: none; background: #888; }
.compile-log {
  flex: 1; padding: 14px; font-family: 'Menlo', 'Courier New', monospace;
  font-size: 12px; color: #a33; background: #fcf6f6; overflow: auto;
  white-space: pre-wrap; line-height: 1.5;
}
.compile-log.hidden { display: none; }

/* Chat pane */
.chat-pane { background: #fdfcf8; }
.chat-messages { flex: 1; overflow-y: auto; padding: 14px; }
.msg { margin-bottom: 18px; font-size: 14px; line-height: 1.6; }
.msg .role {
  font-family: 'Courier New', monospace; font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.8px;
  color: var(--text-dim); margin-bottom: 5px;
}
.msg.user .role { color: var(--accent); }

/* CodeMirror Find & Replace panel, themed to the app palette. */
.cm-panels { background: var(--surface2); color: var(--text); }
.cm-panels.cm-panels-top { border-bottom: 1px solid var(--border); }
.cm-panel.cm-search { padding: 8px 10px; font-family: var(--ui-font); }
.cm-panel.cm-search label { font-size: 12px; color: var(--text-dim); }
.cm-panel.cm-search .cm-textfield {
  font-size: 13px; padding: 3px 7px; margin: 2px 4px 2px 0;
  border: 1px solid var(--border); border-radius: 5px;
  background: var(--surface); color: var(--text);
}
.cm-panel.cm-search .cm-button {
  font-size: 12px; padding: 3px 9px; border-radius: 5px;
  border: 1px solid var(--border-strong); background: var(--surface);
  background-image: none; color: var(--text); text-transform: none;
}
.cm-panel.cm-search .cm-button:hover { background: var(--accent-light); border-color: var(--accent-mid); }
.cm-panel.cm-search [name=close] { color: var(--text-dim); font-size: 18px; }
/* Your own messages sit in a faint box, a touch darker than the chat pane
   (--chat-pane bg #fdfcf8), so they read as distinct from the AI's replies. */
.msg.user {
  background: #f6f2ec;
  border: 1px solid #efe8dc;
  border-radius: 8px;
  padding: 8px 12px;
}
.msg .content { white-space: pre-wrap; word-wrap: break-word; }
.msg code { font-family: 'Menlo', monospace; font-size: 12px; background: var(--code-bg); padding: 1px 5px; border-radius: 3px; }
.msg pre { background: var(--code-bg); padding: 10px 12px; border-radius: 4px; overflow-x: auto; font-size: 12px; line-height: 1.45; margin: 8px 0; }
.msg pre code { background: none; padding: 0; }

.patch-block { border: 1px solid var(--patch-border); background: var(--patch-bg); border-radius: 4px; margin: 8px 0; overflow: hidden; }
.patch-block pre { background: transparent; margin: 0; border-radius: 0; }
.patch-actions { padding: 7px 10px; border-top: 1px solid var(--patch-border); background: #e4ede4; display: flex; gap: 6px; flex-wrap: wrap; }
.patch-actions button { font-size: 12px; padding: 3px 10px; }

/* AI suggested-edit breadcrumb: the change itself is staged in the document
   as an Accept/Reject tracked change; this chip just records it in the chat. */
.ai-edit-chip { border: 1px solid var(--patch-border); border-left: 3px solid #7b5cd6; background: var(--patch-bg); border-radius: 4px; margin: 8px 0; padding: 8px 10px; }
.ai-edit-chip-head { font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-dim); }
.ai-edit-chip-diff { font-family: 'Menlo', monospace; font-size: 12px; line-height: 1.5; margin-top: 5px; word-break: break-word; }
.ai-edit-del { color: #b3261e; text-decoration: line-through; }
.ai-edit-ins { color: #1a7f37; }
.ai-edit-chip.is-clickable { cursor: pointer; transition: background 0.12s, border-color 0.12s; }
.ai-edit-chip.is-clickable:hover { background: var(--accent-light); border-left-color: var(--accent); }
.ai-edit-chip.ai-edit-chip-missing { border-left-color: var(--border-strong); opacity: 0.7; cursor: default; }
.chat-note { font-size: 12px; color: var(--text-dim); font-style: italic; margin: 4px 0 10px; }

/* "Include another AI's chat" context picker (in each chat input area) */
.ai-context-ctl { position: relative; display: flex; align-items: center; gap: 8px; margin: 0 0 6px; flex-wrap: wrap; }
.ai-context-btn {
  font-size: 11px; padding: 2px 8px; border-radius: 5px;
  border: 1px solid var(--border, #e0ddd6); background: transparent; color: var(--text-dim, #888); cursor: pointer;
}
.ai-context-btn:hover { border-color: var(--accent-mid, #c47a68); color: var(--accent, #7a3b2e); }
.ai-context-active { font-size: 11px; color: var(--accent, #7a3b2e); font-style: italic; }
.ai-context-menu {
  position: absolute; z-index: 20; bottom: 100%; margin-bottom: 4px; min-width: 150px;
  background: var(--surface, #fff); border: 1px solid var(--border-strong, #ddd);
  border-radius: 6px; box-shadow: 0 4px 14px rgba(0,0,0,0.14); padding: 4px;
}
.ai-context-item {
  display: flex; align-items: center; gap: 7px; padding: 6px 8px; font-size: 13px;
  cursor: pointer; border-radius: 4px; color: var(--text);
}
.ai-context-item:hover { background: var(--accent-light, #f2e4e0); }
.ai-context-item input { accent-color: var(--accent, #7a3b2e); margin: 0; }

.thinking-block { background: #f0eee8; border-left: 3px solid var(--border-strong); padding: 8px 12px; margin-bottom: 8px; border-radius: 0 4px 4px 0; }
.thinking-block summary { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-dim); cursor: pointer; font-family: 'Courier New', monospace; user-select: none; }
.thinking-block pre { background: transparent; font-size: 12px; color: var(--text-dim); white-space: pre-wrap; margin: 6px 0 0; padding: 0; }

/* ChatGPT pane assistant content uses real DOM structure (paragraphs,
   lists, headings) instead of pre-wrap whitespace, so override the default
   .msg .content { white-space: pre-wrap; } and style the markdown blocks. */
#gpt-chat-messages .msg.assistant .content,
#more-chat-messages .msg.assistant .content { white-space: normal; }
#gpt-chat-messages .msg.assistant .content p,
#more-chat-messages .msg.assistant .content p { margin: 0 0 8px 0; }
#gpt-chat-messages .msg.assistant .content p:last-child,
#more-chat-messages .msg.assistant .content p:last-child { margin-bottom: 0; }
#gpt-chat-messages .msg.assistant .content h3,
#gpt-chat-messages .msg.assistant .content h4,
#gpt-chat-messages .msg.assistant .content h5,
#more-chat-messages .msg.assistant .content h3,
#more-chat-messages .msg.assistant .content h4,
#more-chat-messages .msg.assistant .content h5 {
  margin: 12px 0 6px;
  font-size: 1.05em;
  font-weight: 600;
}
#gpt-chat-messages .msg.assistant .content h3:first-child,
#gpt-chat-messages .msg.assistant .content h4:first-child,
#gpt-chat-messages .msg.assistant .content h5:first-child,
#more-chat-messages .msg.assistant .content h3:first-child,
#more-chat-messages .msg.assistant .content h4:first-child,
#more-chat-messages .msg.assistant .content h5:first-child { margin-top: 0; }
#gpt-chat-messages .msg.assistant .content ul,
#gpt-chat-messages .msg.assistant .content ol,
#more-chat-messages .msg.assistant .content ul,
#more-chat-messages .msg.assistant .content ol {
  margin: 6px 0 8px; padding-left: 22px;
}
#gpt-chat-messages .msg.assistant .content li,
#more-chat-messages .msg.assistant .content li { margin: 2px 0; }
#gpt-chat-messages .msg.assistant .content strong,
#more-chat-messages .msg.assistant .content strong { font-weight: 600; }
#gpt-chat-messages .msg.assistant .content em,
#more-chat-messages .msg.assistant .content em { font-style: italic; }

/* Context panel */
.context-panel { border-top: 1px solid var(--border); background: var(--surface2); flex-shrink: 0; }
.context-panel-fullpane { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.context-panel-fullpane .context-list { max-height: none; flex: 1 1 auto; padding: 8px 14px; }
.context-panel-fullpane .context-list li { font-size: 13px; padding: 6px 0; }
.context-header { display: flex; align-items: center; padding: 5px 10px; gap: 8px; }
.context-title { font-size: 10px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-dim); font-family: 'Courier New', monospace; flex: 1; }
.context-add-btn { font-size: 12px; padding: 3px 8px; color: var(--accent); border-color: var(--accent-mid); }
.context-list { list-style: none; padding: 0 10px 6px; max-height: 90px; overflow-y: auto; }
.context-list li { display: flex; align-items: center; gap: 6px; padding: 3px 0; font-size: 12px; }
.context-list .ctx-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.context-list .ctx-size { color: var(--text-dim); font-family: 'Courier New', monospace; font-size: 11px; }
.context-list .ctx-toggle { accent-color: var(--accent); }
.context-list .ctx-remove { padding: 1px 5px; font-size: 11px; color: var(--text-dim); border-color: var(--border); }
.context-list .ctx-loading { color: var(--text-dim); font-style: italic; }
.context-list .ctx-share { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; color: var(--text-dim); white-space: nowrap; cursor: pointer; }
.context-list .ctx-share .ctx-share-toggle { accent-color: var(--accent); margin: 0; }
.context-list .ctx-owner { color: var(--text-dim); font-style: italic; font-size: 11px; }
.context-list li.ctx-shared-in .ctx-name { font-style: italic; }

/* Skills tab */
.context-hint { margin: 0; padding: 0 12px 6px; font-size: 11px; color: var(--text-dim); line-height: 1.35; }
.skills-section-label { padding: 6px 12px 2px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-dim); }
.skill-toggle { accent-color: var(--accent); }
.skill-view { padding: 1px 6px; font-size: 11px; color: var(--accent); border-color: var(--accent-mid); white-space: nowrap; }
.context-list li.skill-builtin, .context-list li.ctx-mine, .context-list li.ctx-shared-in { flex-wrap: wrap; }
.skill-desc { flex-basis: 100%; color: var(--text-dim); font-size: 11px; line-height: 1.35; padding-left: 22px; }
.skill-body { flex-basis: 100%; margin: 4px 0 2px; padding: 8px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; font-size: 11px; white-space: pre-wrap; word-break: break-word; max-height: 220px; overflow-y: auto; }
.skill-scope { font-size: 11px; padding: 1px 4px; }
.skill-scope-label { font-size: 11px; color: var(--text-dim); font-style: italic; }
.skill-empty { color: var(--text-dim); font-style: italic; }
/* Skill authoring form */
.skill-form { display: flex; flex-direction: column; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.skill-form input[type=text], .skill-form textarea { width: 100%; box-sizing: border-box; font-size: 13px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }
.skill-form textarea { min-height: 90px; resize: vertical; font-family: inherit; }
.skill-form-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; }
.skill-form-row label { display: inline-flex; align-items: center; gap: 6px; color: var(--text-dim); }
.skill-form-actions { display: inline-flex; gap: 6px; }

/* Chat input */
.chat-input-area { border-top: 1px solid var(--border); padding: 10px; background: var(--surface); }
.chat-option { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-dim); margin-bottom: 7px; cursor: pointer; }
.chat-option input { accent-color: var(--accent); }
#chat-input {
  width: 100%; min-height: 68px; max-height: 180px; padding: 8px 10px;
  font-family: inherit; font-size: 14px; border: 1px solid var(--border-strong);
  border-radius: 4px; resize: vertical; background: var(--surface); margin-bottom: 8px; line-height: 1.5;
}
#chat-input:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
#send-btn { width: 100%; background: var(--accent); color: white; border-color: var(--accent); }
#send-btn:hover { background: #923f30; border-color: #923f30; color: white; }
#send-btn:disabled { opacity: 0.45; }
/* Stop button: shown beside Send while a request is in flight (all panes). */
.stop-btn { width: 100%; margin-top: 6px; background: #b33; color: white; border-color: #b33; }
.stop-btn:hover { background: #962a2a; border-color: #962a2a; color: white; }
/* ChatGPT input panel inherits the same pinned-at-bottom layout as Claude:
   the surrounding .chat-input-area has `border-top` + `padding`, and the
   textarea / send button match the Claude sizing so the user sees one
   identical writing panel regardless of which provider is active. */
#gpt-chat-input {
  width: 100%; min-height: 68px; max-height: 180px; padding: 8px 10px;
  font-family: inherit; font-size: 14px; border: 1px solid var(--border-strong);
  border-radius: 4px; resize: vertical; background: var(--surface); margin-bottom: 8px; line-height: 1.5;
  box-sizing: border-box;
}
#gpt-chat-input:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
#gpt-send-btn { width: 100%; background: var(--accent); color: white; border-color: var(--accent); }
#gpt-send-btn:hover { background: #923f30; border-color: #923f30; color: white; }
#gpt-send-btn:disabled { opacity: 0.45; }
.thinking { font-style: italic; color: var(--text-dim); padding: 6px 0; font-size: 13px; }

/* Document menu */
.doc-menu-wrap { position: relative; }
.doc-menu-btn {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); padding: 6px 13px;
  font-size: 14px; border-radius: 4px; cursor: pointer; white-space: nowrap;
}
.doc-menu-btn:hover { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }
/* Compile is a primary action — accent-filled so it is easy to find from
   any tab (Clean view in particular, which has no other compile control). */
#header-compile-btn { background: var(--accent, #7a3b2e); border-color: var(--accent, #7a3b2e); color: #fff; }
#header-compile-btn:hover { background: var(--accent-dark, #5a2a1e); border-color: var(--accent-dark, #5a2a1e); color: #fff; }
#header-compile-btn:disabled { opacity: 0.55; cursor: default; }
/* Check & fix appears only after a failed compile — warning-tinted. */
/* Online / offline indicator (P1-7) */
.connection-badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 10px;
  background: rgba(45, 122, 45, 0.10);
  color: #1f5a1f;
  border: 1px solid rgba(45, 122, 45, 0.35);
  font-family: 'Courier New', monospace;
  white-space: nowrap;
}
.connection-badge.is-offline {
  background: rgba(180, 50, 50, 0.10);
  color: #a02020;
  border-color: rgba(180, 50, 50, 0.45);
}
/* Local folder sync pill (P1-8). Shows folder name + last-synced age when
   the writer has enabled "Sync .docx to a folder" for this doc. Clicking
   opens the change-folder / stop-syncing popover via the same menu item. */
.local-sync-pill {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 10px;
  background: rgba(122, 59, 46, 0.08);
  color: var(--accent, #7a3b2e);
  border: 1px solid rgba(122, 59, 46, 0.30);
  font-family: 'Courier New', monospace;
  white-space: nowrap;
  cursor: pointer;
}
.local-sync-pill:hover {
  background: rgba(122, 59, 46, 0.14);
}
.local-sync-pill.hidden { display: none; }
.local-sync-pill.is-syncing { opacity: 0.6; }
.local-sync-pill.is-error {
  background: rgba(180, 50, 50, 0.10);
  color: #a02020;
  border-color: rgba(180, 50, 50, 0.45);
}
/* "offline ✓" pill next to a doc in the landing list. Quieter than the
   header badge — informational, not a status. */
.doc-offline-pill {
  font-size: 10px;
  padding: 2px 6px;
  margin-left: 6px;
  border-radius: 8px;
  background: rgba(122, 59, 46, 0.08);
  color: var(--accent, #7a3b2e);
  border: 1px solid rgba(122, 59, 46, 0.25);
  font-family: 'Courier New', monospace;
  vertical-align: middle;
}
#header-fix-btn { background: #fbeadb; border-color: rgba(180, 70, 30, 0.45); color: rgba(150, 45, 20, 0.95); }
#header-fix-btn:hover { background: #f6dcc6; border-color: rgba(180, 70, 30, 0.65); color: rgba(150, 45, 20, 1); }
#header-fix-btn.is-hidden { display: none; }
/* Grammar pair: main button + caret expand menu. The two render as a
   contiguous button group; the caret is narrower so the pair reads as one
   control. */
#header-grammar-btn { background: var(--surface); border-color: var(--border-strong); color: var(--text); border-top-right-radius: 0; border-bottom-right-radius: 0; }
#header-grammar-btn:hover { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }
#header-grammar-btn:disabled { opacity: 0.55; cursor: default; }
.doc-menu-caret { padding: 6px 7px; border-top-left-radius: 0; border-bottom-left-radius: 0; border-left-width: 0; }
.doc-menu.grammar-menu { min-width: 220px; padding: 4px 0; }
.grammar-menu .grammar-menu-section { padding: 4px 0; }
.grammar-menu .grammar-menu-label { padding: 4px 16px 6px; font-size: 12px; color: var(--text-dim, #888); font-family: var(--ui-font); }
.grammar-menu .grammar-menu-label span { color: var(--accent, #7a3b2e); font-weight: 600; }
#grammar-status.warn { color: #b8730a; font-weight: 600; }
#grammar-status.ok { color: #2d7a2d; font-weight: 600; }
#grammar-status.error { color: #b33; font-weight: 600; }
#fix-modal-apply.is-hidden { display: none; }
.fix-issue-list { margin: 0; padding-left: 20px; }
.fix-issue-list li { font-size: 13px; color: var(--text); margin: 5px 0; line-height: 1.4; }
.doc-menu {
  position: absolute; top: calc(100% + 4px); right: 0;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 5px; box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  min-width: 210px; z-index: 100; overflow: hidden;
}
.doc-menu.hidden { display: none; }
.menu-item {
  display: block; width: 100%; text-align: left;
  padding: 10px 16px; font-size: 14px; font-family: var(--ui-font);
  background: none; border: none; border-radius: 0; cursor: pointer;
  color: var(--text);
}
.menu-item:hover { background: var(--accent-light); color: var(--accent); border-color: transparent; }
.menu-divider { height: 1px; background: var(--border); margin: 2px 0; }

/* Format menu: collapsible sections + scroll so the bottom options stay
   reachable even when many sections are expanded. Open state persists per
   section in localStorage (see app.js → wireFormatMenu). */
.doc-menu.format-menu {
  max-height: 70vh;
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 240px;
}
.format-section { margin: 0; }
.format-section > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  padding: 8px 14px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--pane-label, #888);
  background: var(--surface2, rgba(0,0,0,0.02));
  border-top: 1px solid var(--border, rgba(0,0,0,0.06));
}
.format-section:first-of-type > summary { border-top: none; }
.format-section > summary::-webkit-details-marker { display: none; }
.format-section > summary::before {
  content: '▸';
  display: inline-block;
  margin-right: 6px;
  font-size: 9px;
  color: var(--text-dim, #999);
  transition: transform 0.1s ease;
}
.format-section[open] > summary::before { transform: rotate(90deg); }
.format-section > .menu-item { padding-left: 26px; }
.format-indent-row { display: flex; align-items: center; gap: 8px; padding: 6px 14px 4px 26px; font-size: 13px; color: var(--text-dim); }
.format-indent-row input { width: 64px; padding: 3px 6px; }
.format-indent-hint { padding: 0 14px 8px 26px; font-size: 11px; color: var(--text-dim); }

/* ---------- Thread controls ---------- */
.thread-controls {
  display: flex; align-items: center; gap: 6px;
  margin-left: auto;
}
.thread-selector-wrap { position: relative; }
.thread-selector-btn {
  font-size: 12px; padding: 3px 9px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 4px; cursor: pointer; color: var(--text);
  max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: var(--ui-font);
}
.thread-selector-btn:hover { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }
.thread-dropdown {
  position: absolute; top: calc(100% + 4px); right: 0;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 5px; box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  min-width: 240px; max-height: 280px; overflow-y: auto;
  z-index: 200;
}
.thread-dropdown.hidden { display: none; }
.thread-item {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.thread-item:last-child { border-bottom: none; }
.thread-item:hover { background: var(--accent-light); }
.thread-item.active { background: var(--accent-light); }
.thread-item-title {
  flex: 1; font-size: 13px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.thread-item-date { font-size: 11px; color: var(--text-dim); font-family: 'Courier New', monospace; white-space: nowrap; }
.thread-item-del {
  padding: 1px 6px; font-size: 11px; color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 3px; background: none;
  flex-shrink: 0;
}
.thread-item-del:hover { color: #a33; border-color: #a33; background: #fcf6f6; }
.new-thread-btn {
  font-size: 12px; padding: 3px 9px;
  color: var(--accent); border-color: var(--accent-mid);
  border-radius: 4px; white-space: nowrap;
}
.thread-empty {
  padding: 14px 12px; font-size: 13px;
  color: var(--text-dim); text-align: center; font-style: italic;
}

/* ---------- References panel ---------- */
.ref-panel {
  border-top: 1px solid var(--border);
  background: var(--surface2);
  flex-shrink: 0;
  max-height: 260px;
  display: flex;
  flex-direction: column;
}
.ref-header {
  display: flex; align-items: center; padding: 5px 10px; gap: 6px;
  flex-shrink: 0;
}
.ref-title {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--text-dim); font-family: 'Courier New', monospace; flex: 1;
}
.ref-header-actions { display: flex; gap: 5px; }
.ref-action-btn {
  font-size: 11px; padding: 2px 7px;
  color: var(--accent); border-color: var(--accent-mid); border-radius: 3px;
}
.ref-tabs {
  display: flex; gap: 4px; padding: 0 10px 6px; flex-shrink: 0;
}
.ref-tab {
  font-size: 11px; padding: 3px 10px; border-radius: 3px;
  background: transparent; border: 1px solid var(--border-strong);
  color: var(--text-dim); cursor: pointer;
}
.ref-tab.active {
  background: var(--accent-mid, rgba(122, 59, 46, 0.12));
  border-color: var(--accent, #7a3b2e);
  color: var(--accent, #7a3b2e);
}
.ref-tab:hover:not(.active) { background: rgba(0,0,0,0.04); }

.ref-connect {
  display: flex; gap: 6px; padding: 4px 10px 6px; flex-shrink: 0;
}
.ref-connect button {
  font-size: 11px; padding: 3px 10px; border-radius: 3px;
  border: 1px solid var(--accent-mid); color: var(--accent); cursor: pointer;
  background: transparent;
}
.ref-connect button:hover { background: rgba(122, 59, 46, 0.08); }
.ref-connect.hidden, .ref-connect button.hidden { display: none; }

/* EndNote tab: file-based RIS export/import (EndNote has no live API). */
.ref-endnote-panel { padding: 10px 12px; flex-shrink: 0; }
.ref-endnote-panel.hidden { display: none; }
.ref-endnote-note { font-size: 12px; color: var(--text-muted, #6b5d52); margin: 0 0 10px; line-height: 1.5; }
.ref-endnote-note code { font-size: 11px; background: rgba(0,0,0,0.05); padding: 1px 4px; border-radius: 3px; }
.ref-endnote-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.ref-endnote-hint { font-size: 11px; color: var(--text-muted, #8a7c70); margin-top: 8px; }
.ref-endnote-imported-head { font-size: 12px; color: var(--accent, #7a3b2e); padding: 6px 4px; font-weight: 500; }

.ref-search-row {
  display: flex; gap: 6px; padding: 0 10px 6px; flex-shrink: 0;
}
.ref-search-row input {
  flex: 1; padding: 5px 8px; font-family: inherit; font-size: 13px;
  border: 1px solid var(--border-strong); border-radius: 3px; background: var(--surface);
}
.ref-search-row input:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
.ref-search-row button { font-size: 13px; padding: 4px 10px; }
.ref-results {
  overflow-y: auto; flex: 1;
  padding: 0 10px 6px;
}
.ref-item {
  border: 1px solid var(--border); border-radius: 4px;
  background: var(--surface); padding: 7px 9px;
  margin-bottom: 5px; font-size: 12px; line-height: 1.45;
}
.ref-item-title {
  font-weight: bold; color: var(--text); margin-bottom: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.ref-item-meta { color: var(--text-dim); font-size: 11px; margin-bottom: 5px; }
.ref-item-actions { display: flex; gap: 5px; flex-wrap: wrap; }
.ref-item-actions button { font-size: 11px; padding: 2px 8px; }
.ref-cite-btn { color: var(--accent); border-color: var(--accent-mid); }
.ref-loading { padding: 10px; font-size: 13px; color: var(--text-dim); font-style: italic; text-align: center; }
.ref-empty { padding: 10px; font-size: 13px; color: var(--text-dim); text-align: center; }
.ref-error { padding: 10px; font-size: 12px; color: #a33; }
.ref-uploaded-badge {
  font-size: 11px; color: #2d7a2d; padding: 3px 8px;
  background: #eef4ee; border: 1px solid var(--patch-border);
  border-radius: 3px; margin: 0 10px 6px;
}

/* Citation style row in menu */
.menu-style-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; border-bottom: 1px solid var(--border);
}
.menu-style-label { font-size: 13px; color: var(--text-dim); white-space: nowrap; }
.citation-style-select {
  flex: 1; padding: 4px 6px; font-family: inherit; font-size: 13px;
  border: 1px solid var(--border-strong); border-radius: 3px;
  background: var(--surface); color: var(--text); cursor: pointer;
}

/* Citation style in toolbar */
.tb-label {
  font-size: 11px; color: var(--text-dim); text-transform: uppercase;
  letter-spacing: 0.5px; font-family: 'Courier New', monospace; white-space: nowrap;
}
.tb-select {
  padding: 3px 6px; font-family: inherit; font-size: 13px;
  border: 1px solid var(--border); border-radius: 3px;
  background: var(--surface); color: var(--text); cursor: pointer;
}
.tb-select:focus { outline: 1px solid var(--accent); border-color: var(--accent); }

/* ---------- Modal (image manager) ---------- */
.modal-backdrop {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.42);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 6px; box-shadow: 0 10px 40px rgba(0,0,0,0.22);
  min-width: 480px; max-width: 720px; max-height: 80vh;
  display: flex; flex-direction: column;
}
.modal-header {
  padding: 12px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { margin: 0; font-size: 15px; font-family: var(--ui-font); }
.modal-close {
  background: none; border: none; font-size: 22px; cursor: pointer;
  color: var(--text-dim); padding: 0 4px; line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 14px 18px; overflow-y: auto; flex: 1; }

/* OneDrive file browser modal — bigger panel because users will scroll
   through nested folders, and a dedicated footer with the Add button. */
.onedrive-modal-card { min-width: 560px; max-width: 720px; min-height: 360px; max-height: 76vh; }
.onedrive-body { padding: 12px 16px; }
.onedrive-breadcrumbs { font-size: 13px; margin-bottom: 8px; color: var(--text-dim); }
.onedrive-crumb { background: none; border: none; color: var(--accent, #7a3b2e); cursor: pointer; padding: 0; font: inherit; }
.onedrive-crumb:hover { text-decoration: underline; }
.onedrive-crumb-sep { color: var(--text-dim); }
.onedrive-list { list-style: none; padding: 0; margin: 0; max-height: 48vh; overflow-y: auto; border: 1px solid var(--border); border-radius: 4px; }
.onedrive-item { border-bottom: 1px solid var(--border); }
.onedrive-item:last-child { border-bottom: none; }
.onedrive-row { display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 12px; background: none; border: none; text-align: left; cursor: pointer; font: inherit; }
.onedrive-folder .onedrive-row:hover, .onedrive-file .onedrive-row:hover { background: rgba(0,0,0,0.04); }
.onedrive-icon { width: 18px; text-align: center; }
.onedrive-name { flex: 1; word-break: break-word; }
.onedrive-size { color: var(--text-dim); font-size: 12px; }
.onedrive-check { margin: 0 4px 0 0; }
.onedrive-loading { padding: 16px; color: var(--text-dim); text-align: center; font-size: 13px; }
.onedrive-loading.hidden { display: none; }
.onedrive-empty { padding: 16px; color: var(--text-dim); font-style: italic; text-align: center; }
.modal-footer { padding: 10px 16px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.onedrive-status { font-size: 12px; color: var(--text-dim); }
.primary-btn { padding: 6px 14px; background: var(--accent, #7a3b2e); color: white; border: 1px solid var(--accent, #7a3b2e); border-radius: 4px; cursor: pointer; font-size: 13px; }
.primary-btn:hover { background: #923f30; border-color: #923f30; }

.equation-loading { padding: 20px; color: var(--text-dim); text-align: center; font-size: 13px; }
.equation-host { min-height: 120px; display: flex; align-items: center; justify-content: center; padding: 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface2); }
.equation-host math-field {
  width: 100%; min-height: 80px; font-size: 22px;
  background: #fff; padding: 10px; border-radius: 4px;
  --selection-background-color: var(--accent-light);
  --selection-color: var(--text);
}
.equation-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; gap: 12px; }
.equation-mode-label { font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; cursor: pointer; }
.equation-buttons { display: flex; gap: 8px; }
.tb-btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.tb-btn.primary:hover { background: var(--accent-hover, var(--accent)); }
#equation-modal .modal { max-width: 720px; width: 90vw; }

/* Insert Table modal — paste cells, edit a grid, emit longtable LaTeX. */
.insert-table-card { min-width: 640px; max-width: 920px; width: 90vw; max-height: 86vh; }
.insert-table-header-actions { display: flex; align-items: center; gap: 8px; }
.insert-table-paste-zone {
  border: 1px dashed var(--border); border-radius: 6px;
  padding: 10px 12px; min-height: 32px; margin-bottom: 12px;
  font-size: 13px; color: var(--text-dim); background: var(--surface2);
  outline: none;
}
.insert-table-paste-zone[data-empty="false"] { color: var(--text); }
.insert-table-paste-zone:focus { border-color: var(--accent); }
.insert-table-toolbar {
  display: flex; gap: 18px; align-items: center; margin-bottom: 10px; flex-wrap: wrap;
}
.insert-table-cell-fmt { display: flex; gap: 4px; }
.insert-table-fmt-btn {
  width: 26px; height: 26px; border: 1px solid var(--border); background: var(--surface2);
  border-radius: 4px; cursor: pointer; font-size: 13px; line-height: 1; color: var(--text);
  padding: 0; display: inline-flex; align-items: center; justify-content: center;
}
.insert-table-fmt-btn:hover { background: var(--surface); }
.insert-table-fmt-btn:active { transform: translateY(1px); }
.insert-table-col-align {
  width: 100%; padding: 2px; border: 1px solid var(--border); border-radius: 3px;
  background: var(--surface); font-size: 11px; margin-bottom: 2px; color: var(--text);
}
.insert-table-col-width {
  width: 100%; padding: 2px; border: 1px solid var(--border); border-radius: 3px;
  background: var(--surface); font-size: 11px; margin-bottom: 2px; color: var(--text);
  text-align: right;
}
.insert-table-layout-toolbar { font-size: 12px; }
.insert-table-radio-group {
  border: 1px solid var(--border); border-radius: 4px; padding: 2px 8px 4px;
  display: flex; gap: 10px; align-items: center;
}
.insert-table-radio-group legend { font-size: 11px; color: var(--text-dim); padding: 0 4px; }
.insert-table-radio-group label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.insert-table-width-hint { color: var(--text-dim); font-size: 11px; }
/* Grid-borders preview: when the user picks "Full grid" we set this class on
   the grid so the modal preview mirrors what the longtable output will
   look like in PDF/DOCX. The default already shows borders on every cell,
   so the "rules" variant is what needs to peel them back. */
.insert-table-grid.borders-rules td:not(.insert-table-row-ctrls),
.insert-table-grid.borders-rules th:not(.insert-table-col-ctrls):not(.insert-table-row-ctrls) {
  border-left-color: transparent; border-right-color: transparent;
}
.insert-table-toggle { font-size: 13px; display: flex; align-items: center; gap: 6px; cursor: pointer; }
.insert-table-caption-label { font-size: 13px; display: flex; align-items: center; gap: 6px; flex: 1; min-width: 240px; }
.insert-table-caption-label input { flex: 1; padding: 4px 8px; border: 1px solid var(--border); border-radius: 4px; font: inherit; }
.insert-table-grid-wrap { overflow: auto; max-height: 48vh; border: 1px solid var(--border); border-radius: 6px; }
.insert-table-grid { border-collapse: collapse; width: 100%; font-size: 13px; }
.insert-table-grid th, .insert-table-grid td {
  border: 1px solid var(--border-strong); padding: 6px 8px; min-width: 80px; vertical-align: top;
  outline: none; position: relative;
}
/* Excel-style header labels: column letters in the col-controls row,
   row numbers in the row-controls column. Small, dim text so they don't
   visually compete with the editable cell contents. */
.insert-table-col-letter {
  font-size: 11px; font-weight: 600; color: var(--text-dim);
  text-align: center; margin-bottom: 2px; letter-spacing: 0.5px;
}
.insert-table-row-number {
  font-size: 11px; font-weight: 600; color: var(--text-dim);
  text-align: center; margin-bottom: 2px;
}
/* Corner label cell (top-left). Vertical rhythm matches each col-ctrl
   cell's stacked inputs: the spacer block matches the column letter row,
   then "Align" lines up with the alignment dropdown, "Width %" lines up
   with the width input (when shown). The labels are right-aligned so they
   read as captions for the inputs immediately to their right. */
.insert-table-corner-labels { vertical-align: top; padding: 2px 6px !important; }
.insert-table-corner-letter-spacer {
  font-size: 11px; height: 14px; visibility: hidden;
}
.insert-table-corner-label {
  font-size: 11px; color: var(--text-dim); text-align: right;
  margin-bottom: 2px; line-height: 1.6em;
}
/* Header cells: background-only cue. Force `font-weight: normal` to
   override the user-agent stylesheet (every browser bolds `<th>` by
   default). With the computed weight being bold, `execCommand('bold')`
   inside a `<th>` interprets the click as a toggle-off and injects
   `<span style="font-weight: normal">` instead of the intended `<b>`.
   Pandoc + the reference docx styles the header row bold on export
   anyway, so the visual matches at export time. */
.insert-table-grid th { background: var(--surface2); font-weight: normal; }
.insert-table-grid td:focus, .insert-table-grid th:focus { background: var(--accent-light, #fdf3ee); }
.insert-table-col-ctrls { background: transparent !important; border-bottom: none !important; padding: 2px !important; }
.insert-table-row-ctrls { background: transparent !important; border-right: none !important; padding: 2px !important; }
.insert-table-icon-btn {
  width: 20px; height: 20px; border: 1px solid var(--border); background: var(--surface2);
  border-radius: 3px; cursor: pointer; font-size: 12px; line-height: 1; color: var(--text-dim);
  padding: 0; display: inline-flex; align-items: center; justify-content: center;
}
.insert-table-icon-btn:hover { color: var(--text); background: var(--surface); }
.insert-table-icon-btn.danger:hover { color: #b3261e; }
.insert-table-ctrl-row { display: flex; gap: 4px; justify-content: center; }
.insert-table-hint { font-size: 12px; color: var(--text-dim); margin-top: 8px; }
.patch-view-modal-card { max-width: 900px; width: 90vw; }
.patch-view-text {
  background: var(--code-bg);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 4px;
  padding: 16px;
  font-family: 'Menlo', monospace;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 65vh;
  overflow-y: auto;
  margin: 0 0 12px 0;
}
/* Lift the MathLive virtual keyboard above the equation modal backdrop
   (z-index 200) so its keys remain clickable while the modal is open. */
:root { --keyboard-zindex: 250; }
body > .ML__keyboard { z-index: var(--keyboard-zindex); }

.media-toolbar {
  display: flex; align-items: center; gap: 10px; margin-bottom: 12px;
}
.media-hint { font-size: 12px; color: var(--text-dim); }

.media-list {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 6px;
}
.media-item {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 4px; background: var(--surface2);
}
.media-item.drag-over { border-color: var(--accent); background: var(--accent-light); }
.media-thumb {
  width: 48px; height: 48px; object-fit: contain;
  background: #fff; border: 1px solid var(--border); border-radius: 3px;
  flex-shrink: 0;
}
.media-thumb-fallback {
  width: 48px; height: 48px; display: flex; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 10px; color: var(--text-dim); border-radius: 3px; flex-shrink: 0;
}
.media-name {
  flex: 1; font-family: 'Menlo', monospace; font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.media-drag-handle {
  cursor: grab; color: var(--text-dim); font-size: 16px;
  padding: 0 4px; user-select: none;
}
.media-drag-handle:active { cursor: grabbing; }
.media-order {
  width: 48px; padding: 2px 4px; font-size: 12px;
  border: 1px solid var(--border); border-radius: 3px; background: var(--surface);
  font-family: inherit;
}
.media-actions {
  display: flex; gap: 4px;
}
.media-actions button {
  padding: 3px 8px; font-size: 12px; border-radius: 3px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); cursor: pointer; font-family: var(--ui-font);
}
.media-actions button:hover { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }
.media-actions .btn-delete:hover { background: #fbe9e9; border-color: #c44; color: #a33; }
.media-empty { color: var(--text-dim); font-style: italic; padding: 20px 0; text-align: center; }

/* Clickable thumbnails in the media manager */
.media-thumb { cursor: zoom-in; transition: transform 0.1s; }
.media-thumb:hover { transform: scale(1.05); }

/* Lightbox overlay */
.lightbox-backdrop {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.85);
  display: flex; align-items: center; justify-content: center;
  z-index: 400; flex-direction: column; gap: 12px;
  padding: 40px;
}
.lightbox-backdrop.hidden { display: none; }
.lightbox-img {
  max-width: 90vw; max-height: 80vh;
  background: #fff; border-radius: 4px;
  box-shadow: 0 10px 50px rgba(0,0,0,0.5);
}
.lightbox-caption {
  color: #fff; font-family: 'Menlo', monospace; font-size: 13px;
  text-align: center; opacity: 0.9;
}
.lightbox-close {
  position: absolute; top: 16px; right: 20px;
  background: none; border: none; color: #fff; font-size: 32px;
  cursor: pointer; line-height: 1; padding: 4px 10px;
  border-radius: 4px;
}
.lightbox-close:hover { background: rgba(255,255,255,0.15); }

/* Table preview modal — opened by clicking a Clean-view table chip. Reuses
   .lightbox-backdrop for the dim overlay; the inner .table-preview-card is a
   white panel that holds a real HTML <table> rendered from the parsed LaTeX. */
.table-preview-card {
  background: #fff; border-radius: 6px;
  box-shadow: 0 10px 50px rgba(0,0,0,0.5);
  max-width: 92vw; max-height: 86vh;
  overflow: auto; padding: 24px 28px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.table-preview-caption {
  font-size: 14px; color: #444; margin-bottom: 12px;
  font-weight: 600; text-align: center;
}
.table-preview-table {
  border-collapse: collapse; margin: 0 auto;
  font-size: 13px;
}
.table-preview-table th,
.table-preview-table td {
  border: 1px solid rgba(0,0,0,0.15);
  padding: 6px 12px; vertical-align: top; text-align: left;
}
.table-preview-table th {
  background: rgba(46, 92, 122, 0.08);
  font-weight: 600; color: #2e5c7a;
}
.table-preview-table tbody tr:nth-child(even) {
  background: rgba(0,0,0,0.02);
}
.table-preview-empty {
  color: #777; font-style: italic; padding: 12px;
}

/* ---------- Round 1: Format menu, View menu, Highlight popover, editor zoom ---------- */

/* Editor text zoom: a CSS variable drives the font size of the CodeMirror content.
   Default 100%. Changed via the View menu, persisted in localStorage. */
:root {
  --editor-zoom: 1;
}

.cm-content, .cm-gutters {
  font-size: calc(13px * var(--editor-zoom)) !important;
  line-height: calc(1.5 * var(--editor-zoom)) !important;
}

/* Section titles inside the Format/View dropdown menus */
.menu-section-title {
  padding: 6px 12px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim, #888);
  border-bottom: 1px solid var(--border-light, #eee);
  margin-bottom: 2px;
}

.menu-note {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-dim, #888);
  font-size: 10px;
  margin-left: 4px;
}

.menu-note-inline {
  padding: 6px 12px;
  color: var(--text-dim, #888);
  font-size: 11px;
  font-style: italic;
}

/* Active-value indicator in Format/View menus: a thin left bar on the
   currently-selected option. Toggled by JS when the menu opens. */
.menu-item.is-active {
  background: var(--accent-bg, #f2e4e0);
  border-left: 3px solid var(--accent, #7a3b2e);
  padding-left: 9px;
}

/* Highlight popover (toolbar child menu) */
.tb-highlight-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.hl-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  border: 1px solid rgba(0, 0, 0, 0.2);
  margin-right: 6px;
  vertical-align: middle;
}

/* ---------- Soft-conceal LaTeX rendering (Overleaf-style) ---------- */
/* Decorations applied to the inner content of \textbf, \textit, \emph,
   \hl, and \sethlcolor{c}\hl. Markup tokens themselves remain visible. */

.cm-sc-bold       { font-weight: 700; }
.cm-sc-italic     { font-style: italic; }

/* Source-view LaTeX syntax highlighting (latexSyntaxPass). Colours match the
   reference "Code" view token-for-token. */
.cm-tex-comment   { color: #4c886b; } /* %% comments              — green  */
.cm-tex-command   { color: #0000ff; } /* \commands, \\            — blue   */
.cm-tex-literal   { color: #833fba; } /* \{ \% \& escapes         — purple */
.cm-tex-option    { color: #318495; } /* [optional] values        — teal   */
.cm-tex-math      { color: #036a07; } /* $math$ text, $, numbers  — green  */
.cm-tex-punct     { color: #000000; } /* { } braces inside math   — black  */

/* Source ("Code") view chrome — white page + light gutter, like the
   reference editor. Scoped to Source mode (cm-cw-source) so Clean view's
   paper styling is untouched. */
.cm-editor.cm-cw-source { background: #ffffff; }
.cm-editor.cm-cw-source .cm-gutters { background: #f0f0f0; color: #333333; border-right: 1px solid #e6e6e6; }
.cm-editor.cm-cw-source .cm-lineNumbers .cm-gutterElement { color: #333333; }

.cm-sc-hl-yellow  { background-color: rgba(255, 224, 102, 0.55); }
.cm-sc-hl-green   { background-color: rgba(182, 230, 182, 0.55); }
.cm-sc-hl-pink    { background-color: rgba(247, 184, 209, 0.55); }
.cm-sc-hl-blue    { background-color: rgba(182, 212, 236, 0.55); }
.cm-sc-hl-default { background-color: rgba(255, 224, 102, 0.55); }

/* ---------- Clean view ---------- */
.cm-clean-bold      { font-weight: 700; }
.cm-clean-italic    { font-style: italic; }
.cm-clean-under     { text-decoration: underline; }
.cm-clean-strike    { text-decoration: line-through; }
.cm-clean-super     { vertical-align: super; font-size: 0.78em; }
.cm-clean-sub       { vertical-align: sub;   font-size: 0.78em; }
.cm-clean-link      { color: #0563c1; text-decoration: underline; }
.cm-clean-mono      { font-family: 'Menlo', 'Courier New', monospace; font-size: 0.92em; background: rgba(0,0,0,0.04); padding: 0 3px; border-radius: 3px; }
.cm-clean-footnote-marker { vertical-align: super; font-size: 0.72em; color: #555; cursor: help; padding: 0 1px; }
/* Heading marks (`\section{}` / `\subsection{}` / `\subsubsection{}`) now
   render the inner text identically to body text in Clean view — the marker
   tokens are still hidden by softConcealPass, so the user sees plain text
   while the LaTeX source retains the section structure for outline + PDF.
   The classes stay so the soft-conceal pass has something non-null to apply. */
.cm-clean-h2, .cm-clean-h3 { /* visually transparent */ }
.cm-clean-hl-yellow  { background-color: rgba(255, 224, 102, 0.55); }
.cm-clean-hl-green   { background-color: rgba(182, 230, 182, 0.55); }
.cm-clean-hl-pink    { background-color: rgba(247, 184, 209, 0.55); }
.cm-clean-hl-blue    { background-color: rgba(182, 212, 236, 0.55); }
.cm-clean-cite-chip {
  display: inline-block; padding: 0 5px; margin: 0 1px;
  background: rgba(46, 92, 122, 0.10); color: rgba(46, 92, 122, 0.95);
  border: 1px solid rgba(46, 92, 122, 0.30); border-radius: 6px;
  font-size: 0.8em; line-height: 1.25;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  vertical-align: middle; cursor: pointer;
}
.cm-clean-cite-chip:hover {
  background: rgba(46, 92, 122, 0.18);
  border-color: rgba(46, 92, 122, 0.50);
}
.cm-clean-cite-popover {
  position: absolute; z-index: 9999; min-width: 220px; max-width: 320px;
  background: #fff; border: 1px solid rgba(0, 0, 0, 0.18); border-radius: 4px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12); padding: 8px 10px;
  font-family: var(--ui-font); font-size: 13px;
}
.cm-clean-cite-popover-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-dim, #888); margin-bottom: 6px;
  font-family: 'Courier New', monospace;
}
.cm-clean-cite-popover-row {
  display: flex; align-items: center; gap: 8px;
  padding: 3px 0; font-size: 13px;
}
.cm-clean-cite-popover-key {
  flex: 1; font-family: 'Menlo', 'Courier New', monospace; font-size: 12px;
  color: var(--text, #222); word-break: break-all;
}
.cm-clean-cite-popover-remove {
  font-size: 11px; padding: 2px 8px; cursor: pointer;
  background: #fff; border: 1px solid rgba(0, 0, 0, 0.20); border-radius: 3px;
  color: #a33;
}
.cm-clean-cite-popover-remove:hover {
  background: #fbecec; border-color: #c66;
}
.cm-clean-cite-popover-hint {
  font-size: 11px; color: var(--text-dim, #888); margin-top: 6px;
  font-style: italic;
}
.cm-clean-cite-popover-add {
  margin-top: 8px; padding-top: 8px;
  border-top: 1px solid rgba(0, 0, 0, 0.10);
}
.cm-clean-cite-popover-add-btn {
  width: 100%; padding: 4px 10px; font-size: 12px; cursor: pointer;
  background: var(--accent, #7a3b2e); color: white;
  border: 1px solid var(--accent, #7a3b2e); border-radius: 3px;
}
.cm-clean-cite-popover-add-btn:hover { opacity: 0.9; }
.cm-clean-bib-list {
  display: block; margin: 24px 0 12px;
  padding: 14px 16px 12px;
  border-top: 1px solid rgba(0, 0, 0, 0.12);
  font-family: var(--clean-font-family, Georgia, serif);
}
.cm-clean-bib-list-heading {
  font-size: 1.2em; font-weight: 700; margin-bottom: 10px;
  color: var(--accent, #7a3b2e);
}
.cm-clean-bib-list-empty {
  font-style: italic; color: var(--text-dim, #888); font-size: 0.95em;
}
.cm-clean-bib-list-entry {
  margin: 0 0 8px; padding-left: 24px; text-indent: -24px;
  font-size: 0.95em; line-height: 1.5;
}
.cm-bib-citekey { font-family: 'Menlo', monospace; font-size: 0.9em; }
.cm-bib-missing { color: var(--text-dim, #888); font-style: italic; }
/* Word-style movable icon chip for figures and tables in Clean view. The
   chip is an inline-block draggable span. The full LaTeX block (figure /
   center+image / longtable / tabular) is hidden behind it via
   Decoration.replace; the user moves the chip and the underlying source
   range moves with it as a single CM6 dispatch. */
.cm-clean-block-chip {
  display: inline-block; vertical-align: middle;
  padding: 3px 10px 3px 8px; margin: 2px 2px;
  border-radius: 14px;
  border: 1px solid rgba(0, 0, 0, 0.10);
  background: rgba(0, 0, 0, 0.03);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.88em; line-height: 1.4;
  color: var(--text-dim, #555);
  cursor: grab; user-select: none;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.cm-clean-block-chip:hover {
  background: rgba(0, 0, 0, 0.06);
  border-color: rgba(0, 0, 0, 0.20);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}
.cm-clean-block-chip:active { cursor: grabbing; }
.cm-clean-chip-dragging { opacity: 0.45; }
.cm-clean-figure-chip { background: rgba(46, 92, 122, 0.07); border-color: rgba(46, 92, 122, 0.20); color: rgba(46, 92, 122, 0.95); }
.cm-clean-figure-chip:hover { background: rgba(46, 92, 122, 0.12); border-color: rgba(46, 92, 122, 0.35); }
.cm-clean-table-chip  { background: rgba(122, 78, 46, 0.07); border-color: rgba(122, 78, 46, 0.20); color: rgba(122, 78, 46, 0.95); }
.cm-clean-table-chip:hover  { background: rgba(122, 78, 46, 0.12); border-color: rgba(122, 78, 46, 0.35); }
.cm-clean-chip-icon  { margin-right: 4px; }
.cm-clean-chip-label { font-weight: 600; }
.cm-clean-chip-caption { font-weight: 400; opacity: 0.85; }
.cm-clean-chip-handle {
  margin-left: 6px; opacity: 0.30; letter-spacing: -1px;
  font-size: 0.85em; line-height: 1;
}
.cm-clean-block-chip:hover .cm-clean-chip-handle,
.cm-clean-inline-chip:hover .cm-clean-chip-handle { opacity: 0.70; }
.cm-clean-chip-handle-inline {
  margin-left: 4px; opacity: 0.40;
  cursor: grab; vertical-align: middle;
}
.cm-clean-inline-chip { cursor: grab; }
.cm-clean-inline-chip:active { cursor: grabbing; }
.cm-clean-chip-edit-btn {
  margin-left: 6px; padding: 0 4px; border: none; background: transparent;
  cursor: pointer; font-size: 0.95em; line-height: 1; opacity: 0.45;
  color: inherit;
}
.cm-clean-chip-edit-btn:hover { opacity: 1; }

/* Word-style figure preview: the actual image rendered inline at the same
   body-width fraction it will occupy on the PDF page. A right-edge handle
   lets the user drag-resize; the readout floats next to the handle and
   shows the current body-width percentage during the gesture. The wrap is
   a `display: block` element so it can sit on its own line within an
   inline `Decoration.replace`; `margin: 0 auto` centers it like the
   `\begin{center}…\end{center}` block does in the PDF. */
.cm-clean-figure-image {
  display: block; position: relative;
  width: var(--fig-width-pct, 60%);
  margin: 8px auto;
  user-select: none;
}
.cm-clean-figure-img {
  display: block; width: 100%; height: auto;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.02);
  cursor: zoom-in;
}
.cm-clean-figure-image:hover .cm-clean-figure-img { border-color: rgba(0, 0, 0, 0.20); }
.cm-clean-figure-meta {
  display: inline-block; margin-top: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(46, 92, 122, 0.07);
  border: 1px solid rgba(46, 92, 122, 0.20);
  color: rgba(46, 92, 122, 0.95);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.82em; line-height: 1.4;
  cursor: grab;
}
.cm-clean-figure-meta:active { cursor: grabbing; }
.cm-clean-figure-resize-handle {
  position: absolute;
  right: -4px; top: 0; bottom: 0;
  width: 10px;
  cursor: ew-resize;
  background: linear-gradient(to right, transparent 0%, transparent 35%,
              rgba(46, 92, 122, 0.45) 35%, rgba(46, 92, 122, 0.45) 65%,
              transparent 65%, transparent 100%);
  opacity: 0;
  transition: opacity 0.12s;
  touch-action: none;
}
.cm-clean-figure-image:hover .cm-clean-figure-resize-handle,
.cm-clean-figure-resizing .cm-clean-figure-resize-handle { opacity: 1; }
.cm-clean-figure-readout {
  position: absolute; top: 6px; right: 6px;
  padding: 2px 6px;
  background: rgba(46, 92, 122, 0.85); color: #fff;
  border-radius: 3px;
  font: 11px/1 -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s;
}
.cm-clean-figure-image:hover .cm-clean-figure-readout,
.cm-clean-figure-resizing .cm-clean-figure-readout { opacity: 1; }
.cm-clean-figure-resizing .cm-clean-figure-img {
  outline: 2px solid rgba(46, 92, 122, 0.45);
  outline-offset: -1px;
}

/* Inline table grid. The wrapper stacks a chip-style header strip (label,
   caption, edit button, drag handle) on top of an HTML <table> that renders
   the parsed longtable at its source-declared column proportions. The
   strip preserves all the drag-to-reorder and open-in-editor affordances
   the legacy chip had, so the inline grid is strictly additive. */
.cm-clean-table-grid {
  display: block;
  margin: 8px 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.cm-clean-table-grid-strip {
  display: inline-flex; align-items: center; gap: 4px;
  margin-bottom: 4px;
  cursor: pointer;
}
.cm-clean-table-caret {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.9em; height: 1.9em; padding: 0;
  margin-right: 4px;
  border: none; background: transparent;
  cursor: pointer;
  font-size: 1.15em; line-height: 1;
  color: inherit; opacity: 0.75;
  border-radius: 4px;
  transition: opacity 0.12s, background 0.12s;
}
.cm-clean-table-caret:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.08);
}

/* Grid body is the absolute-positioning context for the column-edge drag
   handles, so they can be placed at percent-of-body x-positions and span
   the full table height. */
.cm-clean-table-grid-body {
  position: relative;
}
.cm-clean-table-grid-body-collapsed { display: none; }

/* Column-edge drag handle: a 6px-wide invisible hit zone centered on the
   column boundary. A 1px tinted bar in the middle shows on hover so the
   user can see where the handle is. Spans the table's full height via
   top: 0; bottom: 0 — the body's relative positioning gives the right
   reference frame. */
.cm-clean-table-col-handle {
  position: absolute;
  top: 0; bottom: 0;
  width: 6px;
  margin-left: -3px;
  cursor: col-resize;
  z-index: 2;
  background: transparent;
  transition: background 0.12s;
}
.cm-clean-table-col-handle::before {
  content: '';
  position: absolute;
  left: 50%; top: 0; bottom: 0;
  width: 1px;
  background: transparent;
  transition: background 0.12s;
}
.cm-clean-table-grid-body:hover .cm-clean-table-col-handle::before {
  background: rgba(46, 92, 122, 0.20);
}
.cm-clean-table-col-handle:hover::before,
.cm-clean-table-resizing .cm-clean-table-col-handle::before {
  background: rgba(46, 92, 122, 0.80);
  width: 2px;
  left: calc(50% - 1px);
}

/* Page-boundary widget for paginated Clean view. PageBreakWidget is an
   INLINE widget rendered as a full-width flex column, so it sits inside the
   paragraph's line box and splits the paragraph across the page boundary
   (the leading lines render above it, the rest below). Three stacked
   children, each with a fixed inline `height` set by the widget:

   - paper-bottom: white, the outgoing page's bottom margin. Hosts the folio.
   - gutter: canvas-gray, bleeds past page edges via the existing
     --clean-landscape-extra-pct negative margins. Hosts the chip.
   - paper-top: white, the incoming page's top margin.

   The widget never pads to fill a page, so there is no blank-void state and
   no measurement phase. Multi-page (collapsed) groups carry
   `data-page-end > data-page-start` and a "Pages N–M" chip label. */
.is-clean-view .cm-clean-page-break-block {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  background: #ffffff;
  pointer-events: none;
  user-select: none;
}
/* Mid-paragraph (inline) dividers render inline-flex so the wrapped row before
   them is justified flush to the margin like every other line. A block-level
   divider makes that row the "last line" of its inline segment, which
   text-align: justify leaves ragged — visibly short of the right margin. As an
   inline atom the divider wraps like a normal word, so the preceding line is a
   normal justified wrap. vertical-align: top keeps it off the text baseline. */
.is-clean-view .cm-clean-page-break-block.is-inline {
  display: inline-flex;
  vertical-align: top;
}
.is-clean-view .cm-clean-page-break-paper-bottom,
.is-clean-view .cm-clean-page-break-paper-top {
  position: relative;
  background: transparent;
  flex: 0 0 auto;
}
/* Folio: the outgoing page number, sitting in the bottom-margin band of
   the page that just ended (the paper-bottom region of the widget). */
.is-clean-view .cm-clean-page-break-folio {
  position: absolute;
  left: 50%;
  bottom: 6px;
  transform: translateX(-50%);
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica, sans-serif;
  font-size: 11px;
  font-variant-numeric: lining-nums;
  color: rgba(60, 40, 20, 0.5);
  letter-spacing: 0.04em;
}
/* Canvas-gray gutter bleeds past the body width using the same negative-
   margin proportion the landscape block uses (--clean-landscape-extra-pct
   = margin / body-width, exactly what's needed to reach the page's outer
   edge). Subtle inset shadows at top and bottom give a paper-edge feel. */
.is-clean-view .cm-clean-page-break-gutter {
  position: relative;
  background: #e6e3dc;
  flex: 0 0 auto;
  margin-left:  calc(-1 * var(--clean-landscape-extra-pct, 15.4%));
  margin-right: calc(-1 * var(--clean-landscape-extra-pct, 15.4%));
  box-shadow:
    inset 0  6px 6px -6px rgba(0, 0, 0, 0.20),
    inset 0 -6px 6px -6px rgba(0, 0, 0, 0.20);
}
.is-clean-view .cm-clean-page-break-chip {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #fdf6e3;
  border: 1px solid rgba(122, 78, 46, 0.35);
  border-radius: 14px;
  padding: 0.32em 1.1em;
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica, sans-serif;
  font-size: 0.78em;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(122, 78, 46, 0.85);
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
/* Per-row drag handle: a thin horizontal hit zone at the bottom edge of each
   tbody row. Invisible by default; a 1px tinted bar shows on hover so the
   user knows where the handle is. Drag vertically to adjust that row's
   trailing space (`\\[Xem]` in source). Sits absolutely inside the body
   wrapper at `top: <row.bottom - body.top - 3>`. */
.cm-clean-table-row-handle {
  position: absolute;
  left: 0; right: 0;
  height: 6px;
  margin-top: 0;
  cursor: ns-resize;
  z-index: 2;
  background: transparent;
  touch-action: none;
}
.cm-clean-table-row-handle::before {
  content: '';
  position: absolute;
  left: 0; right: 0;
  top: 50%;
  height: 1px;
  background: transparent;
  transition: background 0.12s;
}
.cm-clean-table-grid-body:hover .cm-clean-table-row-handle::before {
  background: rgba(46, 92, 122, 0.20);
}
.cm-clean-table-row-handle:hover::before,
.cm-clean-table-row-handle.is-dragging::before {
  background: rgba(46, 92, 122, 0.80);
  height: 2px;
  top: calc(50% - 1px);
}
.cm-clean-table-grid-tbl {
  /* fixed layout so <colgroup> widths actually drive column sizes instead
     of the browser auto-stretching to widest content (which makes the
     Clean view rendering diverge from the PDF's body-width-based widths). */
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.85em;
  line-height: 1.35;
  background: #fff;
}
.cm-clean-table-grid-tbl th,
.cm-clean-table-grid-tbl td {
  border: 1px solid rgba(0, 0, 0, 0.10);
  /* Vertical padding scales with --table-stretch so the compactness
     handle's drag is visible in real time. The horizontal padding stays
     fixed — column widths are driven by colgroup, not padding. */
  padding: calc(4px * var(--table-stretch, 1)) 6px;
  line-height: calc(1.35 * var(--table-stretch, 1));
  vertical-align: top;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.cm-clean-table-grid-tbl thead th {
  font-weight: 600;
  background: rgba(122, 78, 46, 0.05);
  border-bottom: 2px solid rgba(122, 78, 46, 0.35);
}
.cm-clean-table-grid-tbl tbody tr:nth-child(even) td {
  background: rgba(0, 0, 0, 0.015);
}

/* Drop indicator: a thin bar shown while a chip is being dragged.
   Block-chip drag uses the horizontal variant (a line spanning the editor
   width above the destination line). Inline-chip drag (cite, math) uses the
   vertical variant — a caret positioned at the character-precise drop
   location. Positioned absolutely inside the editor's scroll container. */
.cm-clean-drop-indicator {
  position: absolute;
  background: rgba(46, 92, 122, 0.85);
  border-radius: 2px;
  pointer-events: none; z-index: 5;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.6);
}
.cm-clean-drop-indicator-block {
  left: 8px; right: 8px; height: 2px;
}
.cm-clean-drop-indicator-inline {
  width: 2px;
}
/* Clean view defaults to justified text — matches LaTeX's default body
   alignment so a paragraph that compiles justified in the PDF also
   *renders* justified in Clean view. Per-paragraph alignment overrides
   come from the line decorations added by buildCleanDecorations when the
   source contains \begin{center|flushleft|flushright}. The override
   selectors carry an extra class to outrank the default's specificity. */
/* CodeMirror's default highlightActiveLine extension paints the active line
   with a pale-blue background. In Clean view, a paragraph is one logical
   line that wraps across many visual rows, so the highlight covers the
   whole paragraph and reads as "this paragraph is selected/highlighted."
   Suppress it in Clean view; Source view keeps the indicator. */
#editor.is-clean-view .cm-content .cm-line.cm-activeLine,
#editor.is-clean-view .cm-content .cm-activeLine { background-color: transparent; }
#editor.is-clean-view .cm-content .cm-line                          { text-align: justify; }
#editor.is-clean-view .cm-content .cm-line.cm-clean-line-centered   { text-align: center; }
#editor.is-clean-view .cm-content .cm-line.cm-clean-line-flushleft  { text-align: left; }
#editor.is-clean-view .cm-content .cm-line.cm-clean-line-flushright { text-align: right; }
/* Quote envs: 0.5 ruler-inch indent on each side. The ruler stretches the
   document page (default 8.5in) across the editor width, so its "inch" is
   editor-width-relative, not the CSS-screen-inch (96px). Using `0.5in` here
   would yield 48px regardless of editor width, which mismatches the ruler.
   --quote-indent-pct is set by renderCleanRuler() from the parsed page
   geometry (0.5in / body width × 100). The 7.69% fallback matches default
   8.5in × 11in with 1in margins (= 0.5/6.5 × 100). */
#editor.is-clean-view .cm-content .cm-line.cm-clean-line-quote      { padding-left: var(--quote-indent-pct, 7.69%); padding-right: var(--quote-indent-pct, 7.69%); }
/* List items: marker sits flush with the body-text left edge (Word-style),
   item content begins 0.25 ruler-inch past it, wrapped lines align under
   the content. CSS-em units would diverge from the ruler scale on resize;
   --ruler-inch-pct keeps the indent proportional to the document's body
   width regardless of editor width. The +6px padding pairs with CodeMirror's
   default .cm-line padding so the marker lines up with body-paragraph text
   (same offset compensation used by .cm-clean-line-quote). */
#editor.is-clean-view .cm-content .cm-line.cm-clean-line-list-item {
  padding-left: calc(6px + var(--ruler-inch-pct, 15.38%) * 0.25);
  text-indent: calc(var(--ruler-inch-pct, 15.38%) * -0.25);
}
/* Word-like paragraph flow (see paragraphFlowPass). The first-line indent is
   an inline-style line decoration sized to the document's \parindent, so it is
   not a static rule here. This rule collapses the blank line pandoc inserts
   between two paragraphs so they sit together as in Word. */
#editor.is-clean-view .cm-content .cm-line.cm-clean-line-para-gap {
  height: 0;
  line-height: 0;
  overflow: hidden;
  padding-top: 0;
  padding-bottom: 0;
}
.cm-clean-list-marker {
  display: inline-block;
  min-width: calc(var(--ruler-inch-pct, 15.38%) * 0.25);
  color: #444;
  user-select: none;
  font-variant-numeric: tabular-nums;
}

/* Math symbol picker popover (Overleaf-style: tabs + grid). Anchored under
   the toolbar button via tb-menu-wrap's relative positioning. */
.symbol-popover {
  position: absolute; top: calc(100% + 4px); left: 0;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 5px; box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  z-index: 1200; padding: 8px; width: 360px;
}
.symbol-popover.hidden { display: none; }
.symbol-tabs { display: flex; gap: 2px; flex-wrap: wrap; margin-bottom: 6px; }
.symbol-tab {
  padding: 4px 8px; font-size: 11px; cursor: pointer;
  background: transparent; border: 1px solid transparent; border-radius: 3px;
  color: var(--text-dim, #666);
}
.symbol-tab:hover { background: rgba(122, 59, 46, 0.08); }
.symbol-tab.active { color: var(--accent); border-color: var(--accent-mid); background: rgba(122, 59, 46, 0.06); }
.symbol-grid {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
  max-height: 280px; overflow-y: auto;
}
.symbol-cell {
  padding: 6px 4px; cursor: pointer; text-align: center;
  font-size: 16px; line-height: 1.2;
  background: transparent; border: 1px solid transparent; border-radius: 3px;
  color: var(--text, #333); font-family: 'STIX Two Math', 'Cambria Math', 'Latin Modern Math', serif;
  user-select: none;
}
.symbol-cell:hover { background: rgba(122, 59, 46, 0.08); border-color: var(--accent-mid); }
.symbol-hint { font-size: 11px; color: var(--text-dim, #888); margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border, #ddd); }

/* Inline / display math widgets (KaTeX-rendered). The KaTeX stylesheet (loaded
   in index.html) provides the .katex / .katex-display classes; we just adjust
   spacing so the rendered span sits naturally inline with body text. */
.cm-clean-math-inline { display: inline; }
.cm-clean-math-display { display: block; margin: 0.5em 0; text-align: center; }
.cm-clean-math-error { color: #d33; font-family: 'Menlo', monospace; font-size: 0.9em; background: rgba(211, 51, 51, 0.06); padding: 0 4px; border-radius: 3px; }

/* Clean view ruler: a Word-style horizontal rule above the editor that shows
   inches (US Letter assumed unless geometry overrides) with margin shading
   pulled from \usepackage[margin=...]{geometry}. Only visible in Clean view;
   informational, not interactive. */
.clean-ruler {
  position: relative;
  height: 22px;
  background: #faf7f3;
  border-bottom: 1px solid #e6dccc;
  user-select: none;
  overflow: hidden;
  flex-shrink: 0;
}
.clean-ruler.hidden { display: none; }
.clean-ruler .ruler-margin {
  position: absolute;
  top: 0; bottom: 0;
  background: rgba(122, 59, 46, 0.10);
}
.clean-ruler .ruler-tick {
  position: absolute;
  bottom: 0;
  width: 1px;
  height: 4px;
  background: rgba(60, 40, 30, 0.35);
}
.clean-ruler .ruler-tick-mid   { height: 7px; }
.clean-ruler .ruler-tick-major { height: 10px; background: rgba(60, 40, 30, 0.6); }
.clean-ruler .ruler-label {
  position: absolute;
  top: 2px;
  transform: translateX(-50%);
  font-size: 9px;
  color: rgba(60, 40, 30, 0.7);
  line-height: 1;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* Clean view: render the editor in the user's chosen LaTeX font / size /
   line spacing. Source view inherits the monospace baseline from #editor.
   We target .cm-line as well as .cm-content because CodeMirror 6's base
   theme can set line-height on .cm-line directly, which would otherwise
   mask our --clean-line-height variable. */
#editor.is-clean-view .cm-scroller,
#editor.is-clean-view .cm-content,
#editor.is-clean-view .cm-content .cm-line {
  font-family: var(--clean-font-family, Georgia, serif);
  /* Zoom multiplier composes with the Format-menu base size so Clean view
     responds to View → Zoom (the source/PDF-tab base rule already does). */
  font-size: calc(var(--clean-font-size, 15px) * var(--editor-zoom, 1));
  line-height: var(--clean-line-height, 1.5);
}

/* Clean view: drop the source-line gutter (line numbers + fold arrows). They
   map to LaTeX source lines, not the visible reading lines, so they confuse
   more than they help in a Word-like view. */
#editor.is-clean-view .cm-gutters { display: none !important; }

/* Clean view: shrink the content area to the ruler's unshaded zone so the
   text physically sits between the margins shown by #clean-ruler. The
   percentage is set by renderCleanRuler() from \usepackage[margin=...]{geometry}. */
#editor.is-clean-view .cm-content {
  padding-left:  var(--clean-margin-pct, 12%);
  padding-right: var(--clean-margin-pct, 12%);
}

/* ---------- Paper-frame (Word-style) ---------- */
/* Decorative page chrome only — Clean view still flows continuously through
   a single CodeMirror instance, but the cm-content now looks like a stacked
   sheet of paper sitting on a gray canvas. The page-break widget (already
   inserted at SyncTeX / heuristic break positions by clean-view.js) provides
   the visual gap between "pages". This is theatre: content does not
   physically fit a page sheet, so a paragraph long enough to overflow a
   real page will just keep flowing past where the PDF would break. The PDF
   tab remains the authoritative print-layout view. */

/* Gray canvas around the page sheet. With the per-page sheet overlay
   painting individual white rectangles, the editor pane shows through as
   the canvas BETWEEN sheets (the gutter zone). Editor and scroller bg
   remain transparent so the pane's color is the single source of truth. */
#editor-view .editor-pane:has(#editor.is-clean-view) {
  background: #e6e3dc;
}
#editor.is-clean-view {
  background: #e6e3dc;
}
#editor.is-clean-view .cm-scroller {
  background: transparent;
}

/* Constrain the ruler to the page width so it sits directly above the
   paper sheet rather than spanning the entire pane. `width: 100%` is needed
   alongside `margin: 0 auto` because in a flex column container, auto
   cross-axis margins override the default `align-items: stretch`; without an
   explicit width the ruler collapses to its intrinsic width of zero (its
   children are absolutely positioned and contribute no width). */
#editor-view .editor-pane:has(#editor.is-clean-view) .clean-ruler {
  max-width: var(--clean-page-width-px, 100%);
  width: 100%;
  margin: 0 auto;
}

/* The CM6 content. In path D1 the sheet overlay (below) paints the actual
   white sheets per PDF page; cm-content's own background is transparent so
   it doesn't double-paint over the sheet rectangles. max-width widens to
   --clean-canvas-width-px when any page in the doc is landscape, so the
   editor pane reserves room for the wider landscape sheet. */
/* The white paper. A single continuous cm-content element with an opaque
   white background — paper is ALWAYS visible with zero JS dependency.
   Centred via margin:0 auto inside the gray #editor canvas so the canvas
   shows on the left/right; the page-break widgets interrupt the white
   with gray gutter bands to separate pages. max-width widens to
   --clean-canvas-width-px when the doc has landscape pages. */
#editor.is-clean-view .cm-content {
  max-width: var(--clean-canvas-width-px, var(--clean-page-width-px, 100%));
  margin: 0 auto;
  background: #ffffff;
  padding-top:    var(--clean-page-pad-vert, 1in);
  padding-bottom: var(--clean-page-pad-vert, 1in);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.06),
    0 2px 6px rgba(0, 0, 0, 0.08),
    0 12px 28px rgba(0, 0, 0, 0.10);
}

/* Vertical ruler: pinned to the left edge of #editor (parent of CM6's
   .cm-editor). Stays fixed in viewport space; the painter writes tick /
   label / margin div positions in viewport coordinates derived from the
   scrollTop of the current sheet. */
#editor {
  position: relative;
}
#editor > .clean-vruler {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 22px;
  background: #f3ecd9;
  border-right: 1px solid rgba(60, 40, 30, 0.18);
  z-index: 6;
  pointer-events: none;
  overflow: hidden;
}
#editor:not(.is-clean-view) > .clean-vruler {
  display: none;
}
.clean-vruler-track {
  position: relative;
  width: 100%;
  height: 100%;
}
/* Top/bottom page-margin shading — the vertical analog of the horizontal
   ruler's .ruler-margin, same tint so borders read identically on both axes. */
.clean-vruler .vruler-margin {
  position: absolute;
  left: 0;
  right: 0;
  background: rgba(122, 59, 46, 0.10);
}
.clean-vruler .vruler-tick {
  position: absolute;
  right: 0;
  width: 4px;
  height: 1px;
  background: rgba(60, 40, 30, 0.35);
}
.clean-vruler .vruler-tick.ruler-tick-mid {
  width: 7px;
}
.clean-vruler .vruler-tick.ruler-tick-major {
  width: 10px;
  background: rgba(60, 40, 30, 0.6);
}
.clean-vruler .vruler-label {
  position: absolute;
  right: 12px;
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica, sans-serif;
  font-size: 9px;
  color: rgba(60, 40, 20, 0.55);
  transform: translateY(-50%);
}
/* CM6 draws the selection rectangles inside .cm-selectionLayer at z-index -2
   (set INLINE on the element by CM6's runtime), intended for a transparent
   .cm-content. Our paper sheet paints opaque white over that layer, hiding
   the highlight. Override the inline z-index with !important so the layer
   sits ABOVE cm-content, and tint the rectangles with a translucent blue so
   the user sees a Word-style highlight while the underlying text remains
   readable through the overlay. CRUCIAL: also set pointer-events: none — CM6
   only sets it on .cm-cursorLayer because the selection layer normally sits
   at z:-2 (below everything) and never catches mouse events; once we lift it
   above cm-content, the overlay otherwise intercepts mousedown on highlighted
   text, blocking the drag-from-selection gesture entirely. */
#editor.is-clean-view .cm-selectionLayer {
  z-index: 1 !important;
  pointer-events: none;
}
#editor.is-clean-view .cm-selectionBackground,
#editor.is-clean-view .cm-content ::selection {
  background-color: rgba(80, 130, 220, 0.28);
}

/* Landscape page markers — block widgets at each `\begin{landscape}…\end{
   landscape}` boundary. Reverted from the per-line band styling (R2 trial
   2026-05-19) because CM6's class-merge for `Decoration.line` silently
   drops landscape classes under common conditions (cursor-on-line via
   highlightActiveLine, post-edit re-renders, prelude-hide co-location),
   making the band visually vanish for individual landscapes. Block
   widgets render reliably independent of cm-line decoration. */
#editor.is-clean-view .cm-content .cm-clean-landscape-start-marker,
#editor.is-clean-view .cm-content .cm-clean-landscape-end-marker {
  margin-left:  calc(-1 * var(--clean-landscape-extra-pct, 15.4%));
  margin-right: calc(-1 * var(--clean-landscape-extra-pct, 15.4%));
  padding: 4px 0.6em;
  background: rgba(122, 59, 46, 0.05);
  font-family: system-ui, sans-serif;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: rgba(122, 59, 46, 0.85);
}
#editor.is-clean-view .cm-content .cm-clean-landscape-start-marker {
  border-top: 1px dashed rgba(122, 59, 46, 0.35);
  margin-top: 10px;
}
#editor.is-clean-view .cm-content .cm-clean-landscape-end-marker {
  border-bottom: 1px dashed rgba(122, 59, 46, 0.35);
  margin-bottom: 10px;
}
#editor.is-clean-view .cm-content .cm-clean-landscape-badge {
  display: inline-block;
  background: rgba(255, 255, 255, 0.9);
  padding: 1px 6px;
  border-radius: 3px;
  font-weight: 600;
}

/* Pandoc `\noindent ` hide — implemented as a mark (not a replace) so it
   doesn't co-locate with line decorations at line.from and silently drop
   them. Hide via font-size + line-height collapse; keeps the element in
   layout for CM6 caret measurement without contributing visible space. */
#editor.is-clean-view .cm-content .cm-clean-noindent-hide {
  font-size: 0;
  line-height: 0;
  display: inline-block;
  width: 0;
}


/* ---------- Fold placeholder (longtable etc.) ---------- */
.cm-foldPlaceholder {
  background: rgba(122, 59, 46, 0.08);
  border: 1px solid rgba(122, 59, 46, 0.25);
  color: rgba(122, 59, 46, 0.85);
  padding: 1px 8px;
  border-radius: 3px;
  font-size: 0.9em;
  cursor: pointer;
}

/* Fold gutter arrows: make them visible and obviously clickable. */
.cm-foldGutter {
  min-width: 14px;
}
.cm-foldGutter .cm-gutterElement {
  cursor: pointer;
  color: rgba(122, 59, 46, 0.55);
  font-size: 1.05em;
  padding: 0 3px;
  user-select: none;
}
.cm-foldGutter .cm-gutterElement:hover {
  color: rgba(122, 59, 46, 1);
}

/* Inline "collapse" chip rendered after \begin{figure}/\begin{longtable} */
.cm-collapse-chip {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  font-size: 0.8em;
  font-weight: 500;
  background: rgba(122, 59, 46, 0.12);
  border: 1px solid rgba(122, 59, 46, 0.35);
  border-radius: 3px;
  color: rgba(122, 59, 46, 0.9);
  cursor: pointer;
  user-select: none;
  vertical-align: middle;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.cm-collapse-chip:hover {
  background: rgba(122, 59, 46, 0.28);
  border-color: rgba(122, 59, 46, 0.6);
  color: rgba(122, 59, 46, 1);
}

/* ---------- Inline comments ---------- */
.cm-comment-anchor {
  background-color: rgba(255, 200, 100, 0.18);
  border-bottom: 1.5px dotted rgba(200, 130, 50, 0.7);
  cursor: pointer;
}
.cm-comment-anchor:hover {
  background-color: rgba(255, 200, 100, 0.32);
}

.cm-comment-context-menu {
  position: fixed;
  background: white;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 4px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  padding: 4px 0;
  min-width: 150px;
  z-index: 9999;
  font-size: 13px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.cm-comment-context-menu .menu-item {
  padding: 6px 14px;
  cursor: pointer;
  user-select: none;
}
.cm-comment-context-menu .menu-item:hover {
  background: rgba(122, 59, 46, 0.10);
}
.cm-comment-context-menu .menu-subhead {
  padding: 4px 14px 2px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-dim);
  user-select: none;
}
.cm-comment-context-menu .menu-synonym-status {
  padding: 4px 14px 6px;
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
  user-select: none;
}
.cm-comment-context-menu .menu-synonym { text-transform: capitalize; }

:where(.cm-comment-tooltip, .cm-proposal-tooltip) {
  background: white;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  padding: 8px 12px;
  max-width: 360px;
  font-size: 13px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.cm-comment-tooltip .cm-comment-author {
  font-size: 11px;
  color: var(--text-dim, #888);
  margin-bottom: 4px;
}
.cm-comment-tooltip .cm-comment-body {
  color: var(--text, #2a2a2a);
  margin-bottom: 8px;
  white-space: pre-wrap;
  line-height: 1.4;
}
.cm-comment-tooltip .cm-comment-actions {
  display: flex;
  gap: 6px;
}
.cm-comment-tooltip .cm-comment-edit,
.cm-comment-tooltip .cm-comment-delete {
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 3px;
  padding: 3px 10px;
  cursor: pointer;
  font-size: 11px;
  color: var(--text, #2a2a2a);
}
.cm-comment-tooltip .cm-comment-edit:hover,
.cm-comment-tooltip .cm-comment-delete:hover {
  background: rgba(122, 59, 46, 0.10);
  border-color: rgba(122, 59, 46, 0.4);
}

/* ---------- Grammar findings (P1-6) ---------- */
/* The squiggle uses an inline SVG so it stays crisp at any zoom level and
   doesn't depend on font metrics. `text-decoration: wavy` is the simpler
   alternative but renders inconsistently across CodeMirror's line height. */
.cm-grammar-finding {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='6' height='3' viewBox='0 0 6 3'><path d='M0 2 Q1.5 0 3 2 T6 2' fill='none' stroke='%23d63333' stroke-width='1'/></svg>");
  background-repeat: repeat-x;
  background-position: bottom 0 left 0;
  padding-bottom: 1px;
  cursor: pointer;
}
.cm-grammar-tooltip {
  background: white;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  padding: 10px 12px;
  max-width: 380px;
  font-size: 13px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.cm-grammar-reason {
  font-size: 12px;
  color: var(--text-dim, #888);
  margin-bottom: 8px;
  line-height: 1.4;
}
.cm-grammar-compare {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  font-family: var(--ui-font);
  font-size: 13px;
  line-height: 1.4;
}
.cm-grammar-original {
  color: #b33;
  text-decoration: line-through;
  text-decoration-color: rgba(180, 50, 50, 0.5);
}
.cm-grammar-suggestion {
  color: #2d7a2d;
  font-weight: 500;
}
.cm-grammar-actions {
  display: flex;
  gap: 6px;
}
.cm-grammar-accept,
.cm-grammar-dismiss {
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 3px;
  padding: 4px 12px;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  color: var(--text, #2a2a2a);
}
.cm-grammar-accept {
  background: rgba(45, 122, 45, 0.10);
  border-color: rgba(45, 122, 45, 0.45);
  color: #1f5a1f;
}
.cm-grammar-accept:hover { background: rgba(45, 122, 45, 0.20); }
.cm-grammar-dismiss:hover { background: rgba(0, 0, 0, 0.08); }

/* ---------- Suggesting mode (track-changes layer) ---------- */
.cm-proposal-insert {
  color: var(--proposal-color, #7a3b2e);
  background: color-mix(in srgb, var(--proposal-color, #7a3b2e) 22%, transparent);
  border-bottom: 2px solid var(--proposal-color, #7a3b2e);
  text-decoration: none;
  cursor: pointer;
  padding: 0 1px;
  font-weight: 500;
}
.cm-proposal-insert:hover {
  background: color-mix(in srgb, var(--proposal-color, #7a3b2e) 34%, transparent);
}
.cm-proposal-strike {
  color: var(--proposal-color, #7a3b2e);
  text-decoration: line-through;
  text-decoration-color: var(--proposal-color, #7a3b2e);
  text-decoration-thickness: 2px;
  background: color-mix(in srgb, var(--proposal-color, #7a3b2e) 14%, transparent);
  cursor: pointer;
}
.cm-proposal-strike:hover {
  background: color-mix(in srgb, var(--proposal-color, #7a3b2e) 26%, transparent);
}
/* When a strike is nested inside an insert-range (same author typed it then
   deleted it), CM6 produces nested spans rather than merging classes. Style
   the inner strike so the strikethrough still wins visually and the meaning
   reads as "inserted then retracted" rather than two unrelated annotations. */
.cm-proposal-insert .cm-proposal-strike {
  text-decoration: line-through;
  text-decoration-color: var(--proposal-color, #7a3b2e);
  text-decoration-thickness: 2px;
  background: color-mix(in srgb, var(--proposal-color, #7a3b2e) 28%, transparent);
}
.cm-proposal-tooltip {
  /* Inherits chrome from the .cm-comment-tooltip rule via :where() above. */
  border-left: 3px solid var(--proposal-color, #7a3b2e);
}
.cm-proposal-tooltip .cm-proposal-meta {
  font-size: 11px;
  color: var(--text-dim, #888);
  margin-bottom: 8px;
}
.cm-proposal-tooltip .cm-proposal-actions {
  display: flex;
  gap: 6px;
}
.cm-proposal-tooltip button {
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 3px;
  padding: 3px 10px;
  cursor: pointer;
  font-size: 11px;
  color: var(--text, #2a2a2a);
}
.cm-proposal-tooltip .cm-proposal-accept:hover {
  background: rgba(46, 122, 70, 0.12);
  border-color: rgba(46, 122, 70, 0.4);
  color: rgb(36, 90, 56);
}
.cm-proposal-tooltip .cm-proposal-reject:hover,
.cm-proposal-tooltip .cm-proposal-withdraw:hover {
  background: rgba(180, 60, 60, 0.10);
  border-color: rgba(180, 60, 60, 0.4);
  color: rgb(135, 40, 40);
}

/* ---------- Auth + user menu + settings/share modals ---------- */
.header-action-btn {
  margin-left: 8px; padding: 4px 12px; font-size: 13px; cursor: pointer;
  background: transparent; color: white;
  border: 1px solid rgba(255,255,255,0.4); border-radius: 4px;
}
.header-action-btn:hover { background: rgba(255,255,255,0.15); border-color: rgba(255,255,255,0.75); color: white; }
.header-action-btn.hidden { display: none; }

/* Wider modal for the references panel which needs space for results. */
.modal-wide { max-width: 720px; width: 90vw; }
.modal-header-actions { display: flex; align-items: center; gap: 6px; }

/* Inline help inside settings sections — click to expand */
.settings-help { margin-top: 8px; }
.settings-help summary {
  cursor: pointer; color: var(--accent, #7a3b2e); font-size: 12px;
  padding: 2px 0; user-select: none;
}
.settings-help summary:hover { text-decoration: underline; }
.settings-help ol {
  margin: 6px 0 0 18px; padding: 8px 12px 4px 12px;
  background: rgba(122, 59, 46, 0.05); border-left: 2px solid var(--accent-mid, rgba(122, 59, 46, 0.3));
  border-radius: 0 4px 4px 0; font-size: 12px; line-height: 1.5;
}
.settings-help ol li { margin-bottom: 4px; }
.settings-help a { color: var(--accent, #7a3b2e); }

.user-menu { position: relative; margin-left: 12px; }
.user-menu.hidden { display: none; }
.user-menu-btn {
  background: transparent; border: 1px solid rgba(255,255,255,0.4); border-radius: 4px;
  padding: 4px 10px; cursor: pointer; font-size: 13px; color: white;
  display: inline-flex; align-items: center; gap: 6px;
}
.user-menu-btn:hover { background: rgba(255,255,255,0.15); border-color: rgba(255,255,255,0.75); }
.user-menu-color-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.5); background: var(--user-color, #7a3b2e);
}
.user-menu-dropdown {
  position: absolute; right: 0; top: 100%; margin-top: 4px;
  background: white; border: 1px solid rgba(0,0,0,0.15); border-radius: 4px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.15); min-width: 220px; z-index: 1000;
}
.user-menu-dropdown.hidden { display: none; }
.user-menu-account { padding: 10px 14px 8px; }
.user-menu-account-email { font-size: 13px; font-weight: 600; color: #333; word-break: break-all; }
.user-menu-account-role { font-size: 11px; color: #888; margin-top: 2px; text-transform: uppercase; letter-spacing: 0.04em; }
.user-menu-dropdown .menu-item {
  display: block; width: 100%; text-align: left; background: transparent; border: none;
  padding: 8px 14px; cursor: pointer; font-size: 13px;
}
.user-menu-dropdown .menu-item:hover { background: rgba(122, 59, 46, 0.08); }

.signin-container {
  max-width: 420px; margin: 80px auto; padding: 24px; text-align: left;
  background: white; border: 1px solid var(--border-strong, #ddd); border-radius: 6px;
}
.signin-container h2 { margin-top: 0; }
.signin-hint { font-size: 13px; color: var(--text-dim, #888); }
#signin-form { display: flex; gap: 8px; margin-top: 12px; }
#signin-form input { flex: 1; padding: 8px 10px; border: 1px solid var(--border-strong, #ddd); border-radius: 4px; }
#signin-form button { padding: 8px 14px; background: var(--accent, #7a3b2e); color: white; border: none; border-radius: 4px; cursor: pointer; }
.signin-result { margin-top: 12px; font-size: 13px; }

.share-btn {
  margin-left: 8px; padding: 4px 12px; font-size: 12px; cursor: pointer;
  background: transparent; color: var(--accent, #7a3b2e);
  border: 1px solid var(--accent-mid, rgba(122, 59, 46, 0.4)); border-radius: 4px;
}
.share-btn:hover { background: rgba(122, 59, 46, 0.08); }

/* Modal scaffolding (settings, share) */
.settings-section { margin-bottom: 14px; }
.settings-section label { display: block; font-size: 12px; color: var(--text-dim, #888); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.settings-section input[type=text],
.settings-section input[type=password],
.settings-section input[type=color] {
  width: 100%; padding: 6px 10px; border: 1px solid var(--border-strong, #ddd); border-radius: 4px; font-family: inherit; font-size: 13px;
}
.settings-section input[type=color] { padding: 2px; height: 36px; cursor: pointer; }
.settings-row { display: flex; gap: 8px; align-items: center; }
.settings-row input { flex: 1; }
.settings-state { font-size: 11px; color: var(--text-dim, #888); }
.settings-actions { display: flex; gap: 12px; align-items: center; margin-top: 16px; }
.settings-actions button { padding: 6px 16px; background: var(--accent, #7a3b2e); color: white; border: none; border-radius: 4px; cursor: pointer; }
.settings-saved-msg { color: #2a7a2a; font-size: 12px; }

/* Settings service list + per-service detail popup */
.service-list { list-style: none; padding: 0; margin: 0; }
.service-list li { margin: 0 0 6px; }
.service-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; text-align: left; padding: 10px 12px;
  background: var(--surface, #fff); border: 1px solid var(--border, #e0ddd6);
  border-radius: 6px; cursor: pointer; font-family: inherit; font-size: 14px; color: var(--text);
}
.service-row:hover { border-color: var(--accent-mid, #c47a68); background: var(--accent-light, #f2e4e0); }
.service-row-name { font-weight: 500; }
.service-row-state { font-size: 11px; color: var(--text-dim, #888); white-space: nowrap; }
.service-row-state.is-ok { color: #2a7a2a; }
.service-instructions { margin-top: 12px; }
.service-instructions ol { margin: 0; padding-left: 20px; font-size: 13px; color: var(--text-dim, #555); line-height: 1.5; }
.service-instructions ol li { margin-bottom: 5px; }
.service-instructions a { color: var(--accent, #7a3b2e); }

/* Share modal */
.share-section { margin-bottom: 16px; }
.share-section label { display: block; font-size: 12px; color: var(--text-dim, #888); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.share-owner-line { font-size: 13px; color: var(--text-dim, #888); margin-bottom: 8px; }
.share-list { list-style: none; padding: 0; margin: 0; }
.share-list li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid rgba(0,0,0,0.06); }
.share-email { color: var(--text-dim, #888); font-size: 12px; flex: 1; }
.share-remove { background: transparent; border: 1px solid var(--border-strong, #ddd); border-radius: 3px; padding: 2px 8px; font-size: 11px; cursor: pointer; }
.share-remove:hover { background: rgba(122, 59, 46, 0.08); border-color: var(--accent, #7a3b2e); color: var(--accent, #7a3b2e); }
.share-empty { color: var(--text-dim, #888); font-size: 13px; }
.share-invite-row { display: flex; gap: 8px; }
.share-invite-row input { flex: 1; padding: 6px 10px; border: 1px solid var(--border-strong, #ddd); border-radius: 4px; }
.share-invite-row button { padding: 6px 14px; background: var(--accent, #7a3b2e); color: white; border: none; border-radius: 4px; cursor: pointer; }
.share-invite-msg { font-size: 12px; margin-top: 6px; color: var(--text-dim, #888); }
.share-invite-link { display: flex; gap: 6px; align-items: center; margin-top: 6px; padding: 6px 8px; background: rgba(122, 59, 46, 0.06); border: 1px solid rgba(122, 59, 46, 0.25); border-radius: 4px; }
.share-invite-link a { flex: 1; font-family: monospace; font-size: 11px; word-break: break-all; color: var(--accent, #7a3b2e); }
.share-copy-btn { padding: 2px 10px; background: var(--accent, #7a3b2e); color: white; border: none; border-radius: 3px; cursor: pointer; font-size: 11px; }
.share-copy-btn:hover { background: var(--accent-dark, #5a2a1e); }
.share-link-btn { background: transparent; border: 1px solid var(--accent-mid, rgba(122, 59, 46, 0.4)); color: var(--accent, #7a3b2e); border-radius: 3px; padding: 2px 8px; font-size: 11px; cursor: pointer; margin-right: 4px; }
.share-link-btn:hover { background: rgba(122, 59, 46, 0.08); }
.share-link-popover { width: 100%; margin-top: 6px; padding: 6px 8px; background: rgba(122, 59, 46, 0.05); border: 1px solid rgba(122, 59, 46, 0.2); border-radius: 4px; font-size: 12px; }

/* Chat tabs (Claude / Team) */
/* Horizontal scroll when the pane is too narrow to show every tab.
   Native scrollbars are unreliable here — macOS Chromium uses overlay
   bars that disappear at rest and ignore most ::-webkit-scrollbar
   styling. We hide them entirely and provide explicit chevron buttons
   (rendered by JS when scrollWidth > clientWidth). min-width: 0 on the
   parent pane (below) lets the chat pane actually shrink to its
   flex-allocated width instead of expanding to fit the tabs. */
.chat-tabs-wrap {
  position: relative; display: flex; align-items: stretch;
  padding: 6px 10px 0; min-width: 0;
}
.chat-tabs {
  display: flex; gap: 2px; flex: 1 1 auto;
  flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden;
  scrollbar-width: none;
}
.chat-tabs::-webkit-scrollbar { display: none; }
.chat-tabs-chevron {
  flex: 0 0 auto; align-self: center;
  background: var(--surface2); border: 1px solid var(--border-strong);
  border-radius: 4px; color: var(--accent, #7a3b2e);
  cursor: pointer; padding: 2px 6px; margin: 0 2px;
  font-size: 14px; line-height: 1; user-select: none;
}
.chat-tabs-chevron:hover { background: var(--surface); }
.chat-tabs-chevron[disabled] { opacity: 0.35; cursor: default; }
.chat-tab {
  padding: 4px 12px; font-size: 12px; cursor: pointer; flex: 0 0 auto;
  white-space: nowrap;
  background: transparent; border: 1px solid var(--border-strong, #ddd);
  border-bottom: none; border-radius: 4px 4px 0 0; color: var(--text-dim, #888);
}
.chat-tab.active {
  background: white; color: var(--accent, #7a3b2e);
  border-color: var(--accent-mid, rgba(122, 59, 46, 0.4));
}
.chat-tab-dynamic { display: inline-flex; align-items: center; gap: 6px; }
.chat-tab-close {
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; border-radius: 3px; font-size: 13px; line-height: 1;
  color: var(--text-dim, #888);
}
.chat-tab-close:hover { background: rgba(122, 59, 46, 0.12); color: var(--accent, #7a3b2e); }

/* "More AIs" launcher */
.more-chooser { padding: 18px; }
.more-chooser-hint { font-size: 13px; color: var(--text-dim, #888); margin: 0 0 12px; }
.more-chooser-btns { display: flex; flex-direction: column; gap: 8px; }
.more-chooser-btn {
  text-align: left; padding: 10px 12px; font-size: 14px; cursor: pointer;
  background: var(--surface, #fff); border: 1px solid var(--border, #e0ddd6);
  border-radius: 6px; color: var(--text);
}
.more-chooser-btn:hover { border-color: var(--accent-mid, #c47a68); background: var(--accent-light, #f2e4e0); }
/* Comments side panel */
.comments-empty { padding: 16px; color: var(--text-dim, #888); font-size: 13px; text-align: center; }
.comment-card {
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 4px;
  padding: 10px 12px;
  margin: 8px 10px;
  background: #fff;
}
.comment-card-jumpable { cursor: pointer; transition: background 120ms; }
.comment-card-jumpable:hover { background: rgba(122, 59, 46, 0.04); }

/* "More AIs" tab — BoodleBox iframe panel. The bar at the top carries the
   open-in-new-tab fallback for visitors whose browser (or BoodleBox's
   X-Frame-Options) blocks the embed. */
.more-iframe-wrap { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.more-iframe-wrap.hidden { display: none; }
.more-iframe-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px; border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--text-dim); background: var(--surface2);
}
.more-iframe-bar a { color: var(--accent, #7a3b2e); text-decoration: none; }
.more-iframe-bar a:hover { text-decoration: underline; }
#more-iframe { flex: 1; width: 100%; border: 0; min-height: 0; }

/* Version history modal. Each row carries the timestamp + author + a
   small badge for the trigger (auto / compile / export / manual). */
.version-history-card { min-width: 560px; max-width: 800px; width: 80vw; max-height: 80vh; }
.version-history-actions { display: flex; align-items: center; gap: 8px; }
.version-list { list-style: none; padding: 0; margin: 0; max-height: 60vh; overflow-y: auto; }
.version-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
}
.version-row:hover { background: rgba(0,0,0,0.02); }
.version-meta { flex: 1; min-width: 0; }
.version-meta-line { font-size: 13px; color: var(--text); }
.version-meta-sub { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.version-badge {
  display: inline-block; font-size: 10px; font-weight: 600; text-transform: uppercase;
  padding: 1px 6px; border-radius: 3px; margin-right: 6px; letter-spacing: 0.4px;
}
.version-badge-manual   { background: rgba(122, 59, 46, 0.15); color: #7a3b2e; }
.version-badge-compile  { background: rgba(46, 92, 122, 0.15); color: #2e5c7a; }
.version-badge-export   { background: rgba(46, 122, 70, 0.15); color: #2e7a46; }
.version-badge-auto     { background: rgba(0,0,0,0.06);        color: var(--text-dim); }
.version-actions { display: flex; gap: 6px; }
.version-actions button { font-size: 12px; padding: 4px 10px; cursor: pointer; }
.version-empty { padding: 24px 12px; color: var(--text-dim); text-align: center; font-size: 13px; }
.version-preview-card { min-width: 640px; max-width: 1000px; width: 90vw; max-height: 86vh; }
.version-preview-actions { display: flex; align-items: center; gap: 8px; }
.version-preview-body {
  background: var(--code-bg, #fafafa); border: 1px solid var(--border);
  border-radius: 4px; padding: 12px; font-family: 'Menlo', monospace;
  font-size: 12px; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
  max-height: 60vh; overflow: auto; margin: 0;
}
.comment-head { font-size: 11px; margin-bottom: 4px; }
.comment-author { font-weight: 600; }
.comment-time { color: var(--text-dim, #888); margin-left: 6px; }
.comment-snippet {
  font-size: 12px;
  font-style: italic;
  color: var(--text-dim, #555);
  background: rgba(0, 0, 0, 0.03);
  border-left: 3px solid rgba(122, 59, 46, 0.35);
  padding: 4px 8px;
  margin: 4px 0 6px;
  cursor: pointer;
  border-radius: 0 3px 3px 0;
}
.comment-snippet:hover { background: rgba(122, 59, 46, 0.08); }
.comment-snippet-lost { color: #a33; font-style: normal; cursor: default; border-left-color: #a33; }
.comment-snippet-lost:hover { background: rgba(0, 0, 0, 0.03); }
.comment-body { font-size: 13px; white-space: pre-wrap; }
.comment-actions { display: flex; gap: 6px; margin-top: 6px; }
.comment-action {
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 3px;
  padding: 2px 8px;
  cursor: pointer;
  font-size: 11px;
  color: var(--text, #2a2a2a);
}
.comment-action:hover { background: rgba(122, 59, 46, 0.10); border-color: rgba(122, 59, 46, 0.4); }
.comment-action-danger:hover { background: rgba(170, 51, 51, 0.10); border-color: rgba(170, 51, 51, 0.55); color: #a33; }
.comment-replies { margin-top: 8px; padding-left: 12px; border-left: 2px solid rgba(0, 0, 0, 0.06); display: flex; flex-direction: column; gap: 6px; }
.comment-reply { background: rgba(0, 0, 0, 0.02); border-radius: 3px; padding: 6px 8px; }
.comment-reply-form { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.comment-reply-form textarea { width: 100%; min-height: 50px; padding: 6px 8px; box-sizing: border-box; resize: vertical; font: inherit; }
.comment-reply-form button { align-self: flex-end; padding: 4px 12px; background: var(--accent, #7a3b2e); color: #fff; border: none; border-radius: 3px; cursor: pointer; font-size: 12px; }
.comment-reply-form button:hover { background: #923f30; }

.team-msg { padding: 6px 10px; border-bottom: 1px solid rgba(0,0,0,0.05); position: relative; }
.team-msg-head { font-size: 11px; }
.team-msg-name { font-weight: 600; }
.team-msg-time { color: var(--text-dim, #888); margin-left: 6px; }
.team-msg-body { font-size: 13px; white-space: pre-wrap; margin-top: 2px; }
.team-msg-actions { display: none; gap: 6px; margin-top: 4px; }
.team-msg:hover .team-msg-actions { display: flex; }
.team-msg-edit, .team-msg-delete {
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 3px;
  padding: 2px 8px;
  cursor: pointer;
  font-size: 11px;
  color: var(--text, #2a2a2a);
}
.team-msg-edit:hover, .team-msg-delete:hover {
  background: rgba(122, 59, 46, 0.10);
  border-color: rgba(122, 59, 46, 0.4);
}

/* Editor-side tabs (Source | PDF) */
.editor-tabs {
  display: flex; gap: 2px; padding: 6px 10px 0; flex-shrink: 0;
  background: var(--surface2); border-bottom: 1px solid var(--border);
}
/* A tab being dragged to reorder (editor or chat tabs). */
.tab-dragging { opacity: 0.45; cursor: grabbing; }
.editor-tab {
  padding: 4px 14px; font-size: 12px; cursor: pointer;
  background: transparent; border: 1px solid var(--border-strong, #ddd);
  border-bottom: none; border-radius: 4px 4px 0 0; color: var(--text-dim, #888);
}
.editor-tab.active {
  background: white; color: var(--accent, #7a3b2e);
  border-color: var(--accent-mid, rgba(122, 59, 46, 0.4));
}
.editor-tab.hidden { display: none; }

/* Appendix family row: document-selector chips + create button, separated
   from the Source/Clean/PDF view-mode tabs by a thin divider. */
.appendix-tabs {
  display: flex; gap: 2px; align-items: flex-end;
  margin-left: 8px; padding-left: 8px;
  border-left: 1px solid var(--border-strong, #ddd);
}
.appendix-tabs:empty { margin-left: 0; padding-left: 0; border-left: none; }
.appendix-tab { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.add-appendix-btn {
  margin-left: 6px; color: var(--accent, #7a3b2e);
  font-size: 15px; line-height: 1; font-weight: 600;
}
.add-appendix-btn:hover { background: var(--surface, #faf8f5); }
.add-appendix-btn:disabled { opacity: 0.5; cursor: default; }
/* The AI-suggestions appendix chip reads distinctly from ordinary appendices. */
.appendix-tab-ai { color: #7b5cd6; }
.appendix-tab-ai.active { color: #7b5cd6; border-color: rgba(123, 92, 214, 0.5); }

/* Clean-view AI-suggestion reference marker: a distinct "✦ N" pill the reader
   clicks to open the linked entry in the AI Notes appendix. Deliberately styled
   as an AI-note chip (the same ✦ as the AI Notes tab and chat breadcrumb), not
   a bare superscript, so it stands out from citations and is not overlooked.
   The number is the literal source digit (the \aisuggestionref{ } wrapper is
   hidden), so a pending tracked-change still underlines it. */
.cm-clean-aisug-ref {
  font-size: 0.72em; font-weight: 700;
  color: #5a3fb0;
  background: rgba(123, 92, 214, 0.16);
  border: 1px solid rgba(123, 92, 214, 0.45);
  border-radius: 8px;
  padding: 0 5px;
  margin: 0 2px;
  vertical-align: 0.22em;
  cursor: pointer;
  white-space: nowrap;
}
.cm-clean-aisug-ref::before { content: "\2726\00a0"; } /* "✦ " */
.cm-clean-aisug-ref:hover { background: rgba(123, 92, 214, 0.32); }

/* When the source pane is "hidden" via tab switching, hide it but keep CodeMirror's
   layout intact; toggling display back doesn't blow away decorations. */
#editor.hidden { display: none; }

/* PDF tab */
.pdf-pane { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.pdf-pane.hidden { display: none; }

/* Split view: editor on the left, PDF on the right, within the editor pane.
   The tabs span the top; the clean-ruler (row 2, collapses to 0 when hidden in
   source mode) and #editor stack in the left column; #pdf-pane fills the right
   column across both content rows. Badges stay position:absolute over the pane. */
.editor-pane.split-view {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto 1fr;
}
.editor-pane.split-view .editor-tabs { grid-column: 1 / 3; grid-row: 1; }
.editor-pane.split-view #clean-ruler  { grid-column: 1; grid-row: 2; }
.editor-pane.split-view #editor       { grid-column: 1; grid-row: 3; min-width: 0; }
.editor-pane.split-view #pdf-pane     { grid-column: 2; grid-row: 2 / 4; border-left: 1px solid var(--border); min-width: 0; }
/* The split toggle reads as engaged when active. */
#pdf-split-btn.is-active { background: var(--accent-dark, #5a2a1e); box-shadow: inset 0 0 0 2px rgba(255,255,255,0.35); }
.pdf-toolbar {
  display: flex; gap: 8px; align-items: center; padding: 6px 10px;
  background: var(--surface2); border-bottom: 1px solid var(--border);
}
.pdf-toolbar button {
  padding: 4px 12px; font-size: 12px; cursor: pointer;
  background: var(--accent, #7a3b2e); color: white; border: none; border-radius: 3px;
}
.pdf-toolbar button:hover { background: var(--accent-dark, #5a2a1e); }
.pdf-toolbar #pdf-download-btn { background: transparent; color: var(--accent, #7a3b2e); border: 1px solid var(--accent-mid, rgba(122, 59, 46, 0.4)); }
.pdf-toolbar #pdf-download-btn.hidden { display: none; }
.pdf-status { font-size: 12px; color: var(--text-dim, #888); }
.pdf-status.ok { color: #2a7a2a; }
.pdf-status.warn { color: #b07a00; }
.pdf-status.error { color: #b00; }
.pdf-prewarn {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: #fff7e6; border: 1px solid #f5c97a;
  border-left: 3px solid #d97706; font-size: 12px; color: #6b3a04;
}
.pdf-prewarn.hidden { display: none; }
.pdf-prewarn-text { flex: 1; line-height: 1.45; }
.pdf-prewarn button {
  padding: 4px 10px; font-size: 12px; cursor: pointer;
  background: #d97706; color: white; border: 1px solid #b76304; border-radius: 3px;
}
.pdf-prewarn button:hover { background: #b76304; }
.pdf-frame { flex: 1; width: 100%; border: none; background: #555; }
.pdf-log {
  flex: 0 0 auto; max-height: 40%; margin: 0; padding: 8px 10px;
  background: #1f1f1f; color: #f0a0a0; font-size: 11px; overflow: auto;
  white-space: pre-wrap; word-break: break-word;
}
.pdf-log.hidden { display: none; }

/* Generic hidden helper: any element with class="hidden" goes away. Used by
   chat tab switching, settings modal sections, and the user menu dropdown.
   Existing element-specific .hidden rules above still match, but the
   important keyword guarantees this wins regardless of source order. */
.hidden { display: none !important; }

/* Team chat panel takes the full chat-pane height when active. */
#team-chat-messages { flex: 1; overflow-y: auto; padding: 6px 0; }
#team-chat-input-area textarea { width: 100%; padding: 6px 10px; box-sizing: border-box; min-height: 60px; resize: vertical; }
#team-chat-input-area button { margin-top: 6px; padding: 6px 14px; background: var(--accent, #7a3b2e); color: white; border: none; border-radius: 4px; cursor: pointer; }
