/* Hestini Writer — Workspace Layout (Quiet Canvas Design) */

/* === Top Bar === */
.topbar {
  display: flex;
  align-items: center;
  height: var(--topbar-height);
  padding: 0 16px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
  gap: 10px;
  flex-shrink: 0;
  z-index: 10;
}
.topbar-home {
  color: var(--text-tertiary);
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}
.topbar-home:hover {
  color: var(--accent-blue);
  background: rgba(4, 151, 175, 0.06);
}
.topbar-brand {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}
.topbar-spacer { flex: 1; }
.topbar-progress-bar { flex: 1; }
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 3px;
}
.topbar-action-btn {
  font-size: 11px !important;
  padding: 4px 10px !important;
  border-color: transparent !important;
  color: var(--text-tertiary) !important;
  background: transparent !important;
  gap: 5px !important;
  border-radius: var(--radius-sm) !important;
}
.topbar-action-btn:hover {
  color: var(--text-primary) !important;
  background: rgba(0, 0, 0, 0.04) !important;
  transform: none !important;
}
.topbar-action-btn svg {
  opacity: 0.6;
}
.topbar-action-btn:hover svg {
  opacity: 1;
}
.btn-present {
  color: var(--accent-purple) !important;
}
.pres-theme-select {
  font-size: 10px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-tertiary);
  font-family: var(--font-sans);
  cursor: pointer;
}

/* === Main Workspace === */
/* Fills whatever the topbar + ribbon leave over (.screen-workspace is a
   flex column; #ribbon-slot sits between topbar and this). */
.workspace {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

/* Edge reopen tabs — half-pills hugging the workspace edges while their
   panel is collapsed (the hide control lives inside the panel). */
.panel-reopen-tab {
  position: absolute;
  top: 12px;
  z-index: 45;
  width: 24px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated, #fff);
  border: 1px solid var(--border-light, #e5e5e5);
  color: var(--text-secondary);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.panel-reopen-left { left: 0; border-left: none; border-radius: 0 8px 8px 0; }
.panel-reopen-right { right: 0; border-right: none; border-radius: 8px 0 0 8px; }
.panel-reopen-tab:hover { color: var(--accent-blue); background: var(--bg-hover, #f2f2f2); }

/* Panel toggles — close button lives INSIDE the panel; the topbar button
   only shows while its panel is collapsed (Notion pattern). */
.panel-toggle-btn { color: var(--text-tertiary); }
.panel-toggle-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.panel-close-btn {
  position: absolute;
  top: 10px;
  right: 8px;
  color: var(--text-hint);
  opacity: 0;
  transition: opacity var(--transition-fast);
}
.left-panel:hover .panel-close-btn { opacity: 1; }
.panel-close-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.sidebar-header { position: relative; }
.chat-sidebar-actions .panel-close-btn { position: static; opacity: 1; }
@media (max-width: 768px) {
  .panel-toggle-btn, .panel-close-btn { display: none; }  /* mobile has sheet toggles */
}

/* === Left Panel (Sidebar Nav) === */
.left-panel {
  width: var(--left-panel-width);
  min-width: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width var(--transition-normal), min-width var(--transition-normal);
  overflow: hidden;
}
.left-panel.collapsed {
  width: 0 !important;
  min-width: 0 !important;
  border-right: none;
}

/* Sidebar header — one slim row: back-to-TOC (only in tool views) +
   view title + hide button. The panel is a pure TOC by default; project
   title lives in the topbar #ws-title (Thầy 2026-07-13). */
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 8px 8px 16px;
  flex-shrink: 0;
}
.sidebar-header .panel-close-btn { position: static; margin-left: auto; }
.sidebar-panel-title {
  min-width: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-back-btn { color: var(--text-secondary); flex-shrink: 0; margin-left: -6px; }
.sidebar-back-btn:hover { color: var(--accent-blue); background: var(--bg-hover); }
.sidebar-add-btn { color: var(--text-secondary); flex-shrink: 0; margin-left: auto; }
.sidebar-add-btn:hover { color: var(--accent-blue); background: var(--bg-hover); }
/* with the add button present, the close button no longer needs auto-push */
.sidebar-header .sidebar-add-btn + .panel-close-btn { margin-left: 0; }

/* L13: project ↔ playbook pill (now inside the Automation panel view) */
.project-playbook-pill {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.playbook-pill-header {
  display: flex;
  align-items: center;
}
.playbook-pill-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: var(--bg-elevated, rgba(0,0,0,.06));
  color: var(--text-secondary, #444);
  border: 1px solid var(--border-subtle, rgba(0,0,0,.08));
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.playbook-pill-running { color: #fff; background: #0075de; border-color: #0075de; }
.playbook-pill-paused  { color: #fff; background: #dd5b00; border-color: #dd5b00; }
.playbook-pill-completed { color: #fff; background: #1aae39; border-color: #1aae39; }
.playbook-pill-failed  { color: #fff; background: #e03e3e; border-color: #e03e3e; }
.playbook-pill-idle    { color: var(--text-secondary); }
.playbook-pill-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.playbook-pill-actions .btn-sm {
  font-size: 11px;
  padding: 3px 8px;
}

/* L13: novel dashboard mount (sidebar) */
.novel-dashboard-mount {
  margin-top: 10px;
  max-height: 240px;
  overflow: auto;
  border-top: 1px solid var(--border-subtle, rgba(0,0,0,.06));
  padding-top: 8px;
}

/* Sidebar nav */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
/* Panel views (former accordion tabs — trigger buttons now live in the
   ribbon Tools group; only one view shows at a time) */
.left-tab-content {
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.left-tab-content.active {
  display: flex;
  flex: 1;
  min-height: 120px;
}

/* Sidebar tab actions & body */
.sidebar-tab-actions {
  padding: 6px 12px;
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.sidebar-tab-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 8px;
}
.sidebar-sub-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.sidebar-sub-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-hint);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

/* Chunk list — fills the whole TOC view (the sidebar mini graph moved to
   ribbon Tools → Graph full view, Thầy 2026-07-13) */
.chunk-list-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chunk-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

/* Chunk item */
.chunk-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  cursor: pointer;
  transition: background var(--transition-fast);
  border-left: 2px solid transparent;
  font-size: 13px;
}
.chunk-item:hover {
  background: rgba(0, 0, 0, 0.02);
}
.chunk-item.active {
  background: rgba(4, 151, 175, 0.06);
  border-left-color: var(--accent-blue);
}
.chunk-item .chunk-order {
  font-size: 11px;
  color: var(--text-hint);
  min-width: 16px;
}
.chunk-item .chunk-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-primary);
}
.chunk-item .chunk-words {
  font-size: 11px;
  color: var(--text-hint);
}
.chunk-item .chunk-icon {
  font-size: 12px;
  color: var(--node-illustration);
}
/* L20_003 — badge node xuất từ report nghiên cứu: click mở briefing */
.chunk-item .chunk-research {
  font-size: 12px;
  cursor: pointer;
  opacity: 0.75;
}
.chunk-item .chunk-research:hover {
  opacity: 1;
}
.chunk-item.dragging {
  opacity: 0.4;
}
.chunk-item.drag-over {
  border-top: 2px solid var(--accent-blue);
  background: rgba(91, 156, 246, 0.08);
}
.chunk-item .status-dot {
  cursor: pointer;
  transition: transform 0.15s;
}
.chunk-item .status-dot:hover {
  transform: scale(1.4);
}
.chunk-item .chunk-edit,
.chunk-item .chunk-del {
  font-size: 13px;
  color: var(--text-hint);
  opacity: 0;
  cursor: pointer;
  transition: opacity 0.1s;
  padding: 0 2px;
  flex-shrink: 0;
}
.chunk-item:hover .chunk-edit,
.chunk-item:hover .chunk-del { opacity: 1; }
.chunk-item .chunk-edit:hover { color: var(--accent-blue); }
.chunk-item .chunk-del:hover { color: var(--accent-red); }
.chunk-rename-input {
  width: 100%;
  border: 1px solid var(--accent-blue);
  border-radius: 3px;
  padding: 1px 4px;
  font-size: 13px;
  font-family: var(--font-sans);
  outline: none;
  background: var(--bg-surface);
  color: var(--text-primary);
}

/* Narration child items */
.chunk-item.chunk-child {
  padding-left: 28px;
  font-size: 12px;
  border-left: 2px solid transparent;
  background: rgba(0,0,0,0.015);
  min-height: 28px;
}
.chunk-item.chunk-child .chunk-order { display: none; }
.chunk-item.chunk-child .chunk-title { font-size: 12px; color: var(--text-secondary); }
.chunk-item.chunk-child.active { background: rgba(4,151,175,0.08); }
.chunk-item .narration-icon { color: #e57373; font-size: 11px; }
.chunk-item .slide-icon { color: var(--accent-blue); font-size: 11px; }
/* Sheet nodes: Google-Sheets-green grid glyph — instantly reads "bảng tính" */
.chunk-item .sheet-icon { color: #1AAE39; font-size: 12px; font-weight: 700; }

/* TTS buttons: generate (gear) + play (triangle) */
.chunk-item .chunk-tts-gen,
.chunk-item .chunk-tts-play {
  font-size: 11px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
  padding: 0 2px;
  flex-shrink: 0;
}
.chunk-item .chunk-tts-gen { color: var(--text-hint); }
.chunk-item .chunk-tts-play { color: var(--accent-green, #1aae39); }
.chunk-item:hover .chunk-tts-gen,
.chunk-item:hover .chunk-tts-play { opacity: 1; }
.chunk-item .chunk-tts-play:not(.hidden) { opacity: 1; } /* always visible if audio exists */
.chunk-item .chunk-tts-gen:hover { color: var(--accent-blue); }
.chunk-item .chunk-tts-play:hover { color: #0d8a2a; }
.chunk-item .chunk-tts-play.tts-active { color: var(--accent-red, #e57373); opacity: 1; }
.chunk-item .chunk-tts-gen.tts-loading { opacity: 1; animation: pulse-tts 1s infinite; }
@keyframes pulse-tts { 0%,100%{opacity:0.4} 50%{opacity:1} }

/* Add narration button */
.chunk-add-narration {
  padding: 3px 8px 3px 28px;
  font-size: 11px;
  color: var(--text-hint);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  gap: 4px;
}
.chunk-add-narration:hover {
  color: var(--accent-blue);
  background: rgba(4,151,175,0.04);
}
.chunk-add-narration .narration-add-icon {
  font-weight: 600;
  font-size: 13px;
}

/* === Center Panel === */
.center-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* Graph full view */
.graph-full {
  flex: 1;
  position: relative;
  background: var(--bg-graph);
  overflow: hidden;
}
#cy-main {
  width: 100%;
  height: 100%;
}

/* Star field canvas (behind cytoscape) */
#star-field {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

/* Editor area */
.editor-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
/* Docs-style page: white sheet floating on a gray desk (Thầy 2026-07-11).
   The scroll container is the AREA; the content is the paper. */
.editor-area { background: var(--bg-secondary, #f5f5f5); }

/* === Editor toolbar — sync visual language with .sg-toolbar (sheet grid),
   P6.C1 2026-07-12. #editor-toolbar (id, already on the element) guarantees
   these win over components.css regardless of stylesheet load order; child
   rules use the extra .editor-toolbar ancestor class for the same reason.
   Only CSS changes here — .toolbar-btn/.toolbar-select/.toolbar-sep class
   names and #editor-toolbar id stay exactly what editor.js and the
   find/history/table popups already reuse. */
#editor-toolbar {
  gap: 4px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  box-shadow: none;
}
.editor-toolbar .toolbar-btn {
  height: 28px;
  padding: 0 6px;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.editor-toolbar .toolbar-btn:hover {
  background: var(--bg-secondary);
}
.editor-toolbar .toolbar-btn.active {
  background: var(--bg-secondary);
  border-color: var(--border);
}
.editor-toolbar .toolbar-select {
  height: 28px;
  padding: 0 6px;
  max-width: 110px;
}

.editor-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.editor-content {
  /* Real paper size: A4 (210mm ≈ 794px @96dpi) with Word-default 1in
     margins. EditorView overrides --page-w/--page-h from the per-project
     page setup (ribbon View tab) — exports carry the same size. */
  --page-w: 794px;
  --page-margin: 96px;
  flex: 1 0 auto;
  padding: var(--page-margin) var(--page-margin) calc(var(--page-margin) + 24px);
  /* Per-project document font (ribbon View → Phông tài liệu). Per-run
     <span style="font-family"> overrides still win, like Word. */
  font-family: var(--doc-font, inherit);
  font-size: 15px;
  line-height: 1.75;
  color: var(--text-primary);
  outline: none;
  min-height: 560px;
  width: var(--page-w);
  max-width: calc(100% - 48px);
  margin: 22px auto;
  background: var(--bg-primary, #ffffff);
  border: 1px solid var(--border-light, #ebebeb);
  border-radius: 2px;
  box-shadow: var(--shadow-sm);
  box-sizing: border-box;
}
@media (max-width: 900px) {
  .editor-content { padding: 28px 26px 48px; margin: 10px auto; width: auto; max-width: calc(100% - 20px); }
}
.editor-content:empty::before {
  content: attr(data-placeholder);
  color: var(--text-hint);
  font-style: italic;
}
.editor-content h1 { font-size: 1.4em; margin: 0.6em 0 0.3em; line-height: 1.25; }
.editor-content h2 { font-size: 1.2em; margin: 0.5em 0 0.3em; line-height: 1.3; }
.editor-content h3 { font-size: 1.08em; margin: 0.4em 0 0.2em; }
.editor-content p { margin-bottom: 0.8em; }
.editor-content ul, .editor-content ol { margin: 6px 0; padding-left: 24px; }
.editor-content li { margin: 3px 0; line-height: 1.6; }
.editor-content hr { border: 0; border-top: 1px solid var(--border, rgba(0,0,0,0.1)); margin: 16px 0; }
/* Page-break marker — dashed rule with a centered label pulled from the
   title attr (set at insert time in the active UI language). Export turns
   it into a real page break; on screen it is just a visual divider. */
.editor-content .page-break {
  position: relative;
  border: 0;
  border-top: 2px dashed var(--border, rgba(0,0,0,0.18));
  margin: 22px 0;
  cursor: default;
  user-select: none;
}
.editor-content .page-break::after {
  content: attr(title);
  position: absolute;
  top: -0.75em;
  left: 50%;
  transform: translateX(-50%);
  padding: 0 8px;
  font-size: 10.5px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-hint);
  background: var(--bg-primary, #ffffff);
}
.editor-content blockquote {
  border-left: 3px solid var(--accent-blue);
  padding-left: 14px;
  margin: 0.8em 0;
  color: var(--text-secondary);
}
/* Verse = stanza block. No vertical bar, centered serif italic — the
   convention for poetry in printed books. Preserves existing line breaks. */
.editor-content blockquote.verse,
.editor-content .verse {
  border-left: 0;
  padding-left: 0;
  text-align: center;
  font-family: var(--font-serif, 'Noto Serif', Georgia, serif);
  font-style: italic;
  color: var(--text-primary);
  margin: 1.2em auto;
  max-width: 32em;
  white-space: pre-wrap;  /* honor newlines typed inside a single block */
}
/* Per-span text sizes — used by the toolbar Size dropdown. */
.editor-content .txt-sm { font-size: 0.85em; }
.editor-content .txt-lg { font-size: 1.2em; }
/* Block alignment classes — set by _setBlockAlign so saved HTML has classes
   instead of inline style="text-align:…" (which would be wiped by paste sanitize). */
.editor-content .align-center  { text-align: center; }
.editor-content .align-right   { text-align: right; }
.editor-content .align-justify { text-align: justify; }
/* Block indent — 3 steps. */
.editor-content .indent-1 { padding-left: 2em; }
.editor-content .indent-2 { padding-left: 4em; }
.editor-content .indent-3 { padding-left: 6em; }
/* Line spacing — class-based (set by Editor.exec 'lineSpacing' from the ribbon)
   so saved HTML survives paste-sanitize like the alignment/indent classes. */
.editor-content .ls-100 { line-height: 1.0; }
.editor-content .ls-115 { line-height: 1.15; }
.editor-content .ls-150 { line-height: 1.5; }
.editor-content .ls-200 { line-height: 2.0; }
/* Inline text color — class-based so paste-sanitizer keeps them
   (inline style="color:…" would be stripped on save/paste). */
.editor-content .tc-red    { color: var(--accent-red, #e03e3e); }
.editor-content .tc-orange { color: var(--accent-orange, #dd5b00); }
.editor-content .tc-green  { color: var(--accent-green, #1aae39); }
.editor-content .tc-teal   { color: var(--accent-cyan, #2a9d99); }
.editor-content .tc-blue   { color: var(--accent-blue, #0497AF); }
.editor-content .tc-purple { color: var(--accent-purple, #6b3fa0); }
/* Highlight (background color) — rgba so it reads well on both light and dark
   surfaces without an extra dark-mode override. */
.editor-content .hl-yellow { background: rgba(250, 204, 21, 0.38); padding: 0 2px; border-radius: 2px; }
.editor-content .hl-green  { background: rgba(52, 211, 153, 0.32); padding: 0 2px; border-radius: 2px; }
.editor-content .hl-blue   { background: rgba(96, 165, 250, 0.32); padding: 0 2px; border-radius: 2px; }
.editor-content .hl-pink   { background: rgba(236, 72, 153, 0.30); padding: 0 2px; border-radius: 2px; }
.editor-content .hl-orange { background: rgba(249, 115, 22, 0.32); padding: 0 2px; border-radius: 2px; }
.editor-content .hl-red    { background: rgba(239, 68, 68, 0.30); padding: 0 2px; border-radius: 2px; }
/* KaTeX math rendering — display equations breathing room */
.editor-content .katex-display { margin: 0.9em 0; overflow-x: auto; overflow-y: hidden; }
.editor-content .katex { font-size: 1.05em; }
.editor-content .katex-error { color: #c33; font-family: var(--font-mono, monospace); }
.editor-content code {
  background: var(--bg-elevated);
  padding: 2px 5px;
  border-radius: 3px;
  font-size: 0.9em;
}
/* Audio player */
.editor-content .inline-audio {
  margin: 16px 0;
  padding: 12px;
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
}
.editor-content .inline-audio audio {
  width: 100%;
  height: 36px;
}
.editor-content .audio-caption {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 6px;
  font-style: italic;
}

.editor-content img {
  max-width: 100%;
  border-radius: var(--radius-md);
  margin: 12px 0;
}

/* Paragraph numbers (toggle) */
.editor-content.show-paranums > * {
  position: relative;
  counter-increment: para;
}
.editor-content.show-paranums > *::before {
  content: counter(para);
  position: absolute;
  left: -28px;
  top: 2px;
  font-size: var(--text-xs);
  color: var(--text-hint);
  font-weight: 600;
  width: 20px;
  text-align: right;
  user-select: none;
  pointer-events: none;
}
.editor-content.show-paranums {
  counter-reset: para;
  padding-left: 36px !important;
}
.toolbar-btn.active {
  background: var(--accent-blue);
  color: #fff;
  border-color: var(--accent-blue);
}

.toolbar-btn.is-loading {
  opacity: 0.6;
  cursor: wait;
}

.toolbar-btn.is-playing {
  background: var(--accent-blue, #3b82f6);
  color: #fff;
  border-color: var(--accent-blue, #3b82f6);
  animation: tts-pulse 1.4s ease-in-out infinite;
}

@keyframes tts-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.55); }
  50%      { box-shadow: 0 0 0 6px rgba(59, 130, 246, 0); }
}

/* Inline notes (footnote-style superscript) */
.editor-content .inline-note {
  display: inline;
  cursor: help;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--accent-purple);
  background: rgba(107, 63, 160, 0.08);
  padding: 0 3px;
  border-radius: 3px;
  margin: 0 1px;
  user-select: none;
  vertical-align: super;
  line-height: 1;
}
.editor-content .inline-note:hover {
  background: rgba(107, 63, 160, 0.16);
}

/* Note list in panel */
.note-item {
  font-size: 11px;
  padding: 3px 0;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-secondary);
}
.note-num {
  color: var(--accent-purple);
  font-weight: 700;
  font-size: 10px;
}
.note-text {
  color: var(--text-primary);
}

/* Citations */
.editor-content sup.citation {
  color: var(--accent-blue);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  margin-left: 1px;
}
.editor-content sup.citation:hover {
  text-decoration: underline;
}

/* Report citations from phase_report (Sophia output: [^bibkey] → <sup>) */
sup.report-cite {
  color: var(--accent-blue);
  font-size: 10px;
  font-weight: 600;
  margin-left: 1px;
  white-space: nowrap;
}
sup.report-cite::before { content: "["; }
sup.report-cite::after  { content: "]"; }

/* Comment highlights */
.editor-content mark.comment-hl {
  background: rgba(245, 158, 11, 0.12);
  border-bottom: 2px solid rgba(245, 158, 11, 0.5);
  cursor: pointer;
  padding: 0 1px;
  border-radius: 2px;
}
.editor-content mark.comment-hl:hover {
  background: rgba(245, 158, 11, 0.22);
}

/* Comment popup */
.comment-popup {
  position: absolute;
  z-index: 100;
  width: 280px;
  max-width: calc(100vw - 16px);
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 8px;
}

/* Inline spinner used in Research plan task rows ("searching…" etc.) */
.spin-inline {
  display: inline-block;
  animation: spin-inline 1.1s linear infinite;
  color: var(--color-primary, #09D3D3);
}
@keyframes spin-inline {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
.comment-popup textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font-size: 12px;
  resize: none;
  margin-bottom: 6px;
  font-family: var(--font-sans);
}

/* Comment panel below editor */
.comment-panel {
  max-height: 120px;
  overflow-y: auto;
  padding: 4px 16px 6px;
  flex-shrink: 0;
  border-top: 1px solid var(--border-light);
}
.comment-panel:empty { display: none; }
.comment-panel-header {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-hint);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 2px;
}
.comment-item {
  padding: 6px 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 12px;
}
.comment-selected {
  color: var(--text-tertiary);
  font-style: italic;
  margin-bottom: 2px;
}
.comment-text {
  color: var(--text-primary);
  margin-bottom: 2px;
}
.comment-meta {
  font-size: 11px;
  color: var(--text-hint);
}
.comment-meta a {
  color: var(--accent-blue);
  text-decoration: none;
}

/* Resolve popup (click on highlight) */
.resolve-popup {
  position: absolute;
  z-index: 100;
  width: 240px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 10px;
}
.resolve-comment-text {
  font-size: 12px;
  color: var(--text-primary);
  margin-bottom: 2px;
}
.resolve-author {
  font-size: 11px;
  color: var(--text-hint);
}

/* Resolve button in comment list */
.comment-resolve-btn {
  min-width: 28px;
  height: 28px;
  padding: 0;
  font-size: 14px;
  color: var(--accent-green);
  border-color: var(--accent-green);
  flex-shrink: 0;
}
.comment-resolve-btn:hover {
  background: rgba(26, 174, 57, 0.1);
}

/* Editor footer — hidden, info duplicated in statusbar */
/* Word-style status bar docked at the very bottom of the editor column — full
   width, thin, never floating over the page (Thầy 2026-07-14: "footer đâu
   rồi?"). It sits after #editor-scroll in the flex column, so the scroll area
   shrinks to make room and the sheet is never covered. */
.editor-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  height: 26px;
  padding: 0 14px;
  background: var(--bg-elevated, #fff);
  border-top: 1px solid var(--border, #e5e7eb);
  font-size: 11px;
  color: var(--text-secondary, #6b7280);
  user-select: none;
}
.editor-footer .save-status {
  display: flex;
  align-items: center;
  gap: 4px;
}
.editor-footer-sep {
  width: 1px;
  height: 13px;
  background: var(--border, #e5e7eb);
}
#page-indicator { font-weight: 600; color: var(--text-primary, #111827); }
/* Zoom control on the right (Word status-bar corner). */
.editor-zoom {
  display: flex;
  align-items: center;
  gap: 6px;
}
.editor-zoom .ez-btn {
  width: 18px;
  height: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 4px;
  background: var(--bg-primary, #fff);
  color: var(--text-secondary, #6b7280);
  cursor: pointer;
  font-size: 13px;
  padding: 0;
}
.editor-zoom .ez-btn:hover { background: var(--bg-secondary, #f3f4f6); color: var(--text-primary, #111827); }
#ez-level {
  min-width: 40px;
  text-align: center;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
#ez-level:hover { color: var(--text-primary, #111827); }
/* The floating pill is replaced by the docked footer above. */
.statusbar { display: none !important; }
/* Footer is desktop chrome; the mobile layout keeps its own bar. */
@media (max-width: 900px) {
  .editor-footer { display: none; }
}
.save-status.saving { color: var(--accent-orange); }
.save-status.saved { color: var(--accent-green); }
.save-status.error { color: var(--accent-red); }

/* === Right Panel (AI Muse) === */
.right-panel {
  width: var(--right-panel-width);
  min-width: 0;
  background: var(--bg-elevated);
  border-left: none;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width var(--transition-normal), min-width var(--transition-normal);
  overflow: hidden;
  position: relative;
}
.right-panel.collapsed {
  /* !important — the AI panel's resize handle persists an INLINE width
     (app.js restores writer-right-panel-width on boot), and inline beats
     any class. This is why "TOC ẩn OK" but the AI panel refused to hide
     (Thầy 2026-07-12). Reopening drops the class → the inline width the
     user dragged comes right back. */
  width: 0 !important;
  min-width: 0 !important;
  border-left: none;
}

/* Chat sidebar header */
.chat-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 12px;
  flex-shrink: 0;
}
.chat-sidebar-title {
  font-size: 11px;
  font-weight: 800;
  color: var(--accent-blue);
  text-transform: uppercase;
  letter-spacing: 0.2em;
}
.chat-sidebar-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}
.chat-sidebar-actions .btn-icon {
  color: var(--text-hint);
  padding: 4px;
  border-radius: var(--radius-sm);
}
.chat-sidebar-actions .btn-icon:hover {
  color: var(--text-tertiary);
  background: rgba(0, 0, 0, 0.04);
}

/* Jiva segment control */
.jiva-segment-wrap {
  padding: 0 16px 8px;
  flex-shrink: 0;
}
/* Design mockup: one hairline frame, buttons split by inner rules, active =
   accent tint + inset ring (project colors, mockup geometry). */
.right-panel .jiva-chips {
  display: flex;
  gap: 0;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  flex-wrap: nowrap;
  overflow: hidden;
}
.right-panel .jiva-chip {
  flex: 1;
  padding: 7px 4px;
  border-radius: 0;
  font-size: 10px;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
  font-weight: 600;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.right-panel .jiva-chip + .jiva-chip { border-left: 1px solid var(--border); }
.right-panel .jiva-chip.active {
  background: var(--hover-bg, rgba(7, 157, 157, 0.08));
  color: var(--accent-blue);
  box-shadow: inset 0 0 0 1px var(--accent-blue);
}
.right-panel .jiva-chip:hover:not(.active) {
  color: var(--text-primary);
  background: rgba(0, 0, 0, 0.03);
}
.right-panel .jiva-more-toggle {
  flex: none;
  padding: 7px 8px;
  background: transparent;
  color: var(--text-hint);
  font-size: 10px;
}

/* AI messages */
.ai-draft-area {
  margin-bottom: 12px;
}
.ai-messages {
  min-height: 150px;
  overflow-y: auto;
  margin-bottom: 0;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.right-panel .ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px;
  min-height: 80px;
}
.right-panel .ai-draft-area {
  flex-shrink: 0;
  max-height: 200px;
  overflow-y: auto;
}

/* AI input area */
.ai-input-area {
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  flex-shrink: 0;
}
.ai-input-inner {
  position: relative;
}
.ai-input-field {
  width: 100%;
  background: var(--bg-graph);
  border: none;
  border-radius: var(--radius-lg);
  padding: 12px 48px 12px 44px;
  font-size: 13px;
  font-family: var(--font-sans);
  color: var(--text-primary);
  resize: none;
  min-height: 44px;
  max-height: 120px;
  line-height: 1.4;
  outline: none;
  transition: box-shadow 0.15s, background-color 0.15s;
}
.ai-input-field::placeholder {
  color: var(--text-hint);
}
.ai-input-field:focus {
  box-shadow: 0 0 0 2px rgba(4, 151, 175, 0.15);
}
.ai-input-field.drag-over {
  background: rgba(4, 151, 175, 0.08);
  box-shadow: 0 0 0 2px rgba(4, 151, 175, 0.35);
}
.ai-attach-btn {
  position: absolute;
  bottom: 8px;
  left: 8px;
  width: 28px;
  height: 28px;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
}
.ai-attach-btn:hover {
  background: var(--bg-elevated);
  color: var(--accent-blue);
}
.ai-send-btn {
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  background: var(--accent-blue);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: var(--shadow-sm);
}
.ai-send-btn:hover {
  background: var(--accent-blue-hover);
  transform: scale(1.05);
}
.ai-send-btn:active {
  transform: scale(0.95);
}
/* Staged attachment chips — shown above input when user queues files for this turn */
.ai-attach-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.ai-attach-chips.hidden { display: none; }
.ai-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px 4px 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 11px;
  color: var(--text-primary);
  max-width: 220px;
  overflow: hidden;
  position: relative;
}
.ai-chip.chip-uploading { opacity: 0.65; }
.ai-chip.chip-error { border-color: var(--accent-red); color: var(--accent-red); }
.ai-chip .chip-thumb {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
}
.ai-chip .chip-ico {
  font-size: 14px;
  line-height: 1;
  flex-shrink: 0;
}
.ai-chip .chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.ai-chip .chip-status {
  font-size: 10px;
  color: var(--text-hint);
  flex-shrink: 0;
}
.ai-chip .chip-remove {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-hint);
  cursor: pointer;
  border-radius: 50%;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
}
.ai-chip .chip-remove:hover { background: var(--bg-graph); color: var(--accent-red); }

/* Legacy ai-input-row support */
.ai-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border-light);
  background: var(--bg-primary);
  align-items: flex-end;
}

/* Workflow controls */
.workflow-controls {
  margin-bottom: 0;
  padding: 0 10px;
  border-bottom: 1px solid var(--border);
}
.workflow-toggle {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 0; cursor: pointer; user-select: none;
  font-size: 11px; color: var(--text-tertiary); text-transform: uppercase;
  letter-spacing: 0.5px; font-weight: 600;
}
.workflow-toggle:hover { color: var(--text-secondary); }
.workflow-toggle .wf-arrow {
  transition: transform 0.2s; font-size: 10px;
}
.workflow-toggle .wf-arrow.collapsed { transform: rotate(-90deg); }
.workflow-body { overflow: hidden; transition: max-height 0.25s ease; }
.workflow-body.collapsed { max-height: 0 !important; padding: 0; }
.attach-actions {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* === World items (abilities/artifacts) === */
.world-item-wrap {
  margin-bottom: 2px;
}
.world-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 6px;
  border-radius: var(--radius-sm);
  transition: background 0.1s;
}
.world-item:hover { background: rgba(0, 0, 0, 0.02); }
.world-item-main { flex: 1; min-width: 0; }
.world-item-name { font-size: 12px; font-weight: 600; color: var(--text-primary); display: block; }
.world-item-meta { font-size: 10px; color: var(--text-tertiary); }
.world-item-del { font-size: 14px; color: var(--text-hint); opacity: 0; transition: opacity 0.1s; }
.world-item:hover .world-item-del { opacity: 1; }
.world-item-del:hover { color: var(--accent-red); }
.world-item-detail {
  display: none;
  padding: 4px 6px 8px 6px;
}
.world-item-wrap.expanded .world-item-detail {
  display: block;
}

/* === Character Relation Graph Modal === */
.char-graph-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.char-graph-modal {
  width: 80vw;
  height: 70vh;
  max-width: 900px;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}
.char-graph-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.char-graph-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}
.char-graph-legend {
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}
.char-graph-detail {
  position: absolute;
  bottom: 50px;
  right: 16px;
  width: 280px;
  max-height: 250px;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 10px;
  z-index: 10;
}
.char-graph-detail.hidden { display: none; }

/* === Sidebar-scoped component sizing === */
.sidebar-tab-body .btn-sm,
.sidebar-tab-actions .btn-sm {
  font-size: 10px;
  padding: 3px 8px;
}
.sidebar-tab-actions .btn-primary {
  font-weight: 600;
}
.left-tab-content .char-card {
  border-color: var(--border-light) !important;
  background: var(--bg-surface) !important;
  transition: border-color 0.15s;
}
.left-tab-content .char-card:hover {
  border-color: var(--border) !important;
}
.char-card:hover .char-del-btn {
  opacity: 1 !important;
}
.char-del-btn:hover {
  color: var(--accent-red) !important;
}

/* === Outline tree === */
.outline-tree {
  font-size: 13px;
  color: var(--text-secondary);
}

/* Panel collapse buttons */
.panel-toggle {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  cursor: pointer;
  z-index: 20;
  color: var(--text-hint);
  font-size: 10px;
  transition: all var(--transition-fast);
}
.panel-toggle:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}
.panel-toggle.left {
  left: 0;
  border-left: none;
}
.panel-toggle.right {
  right: 0;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  border-right: none;
}

/* === Floating Status Pill === */
.statusbar {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  pointer-events: auto;
}
/* Sheet grid / slide canvas open: the pill would cover the sheet tab bar
   or the lower canvas, and words/node mean nothing there — Thầy 2026-07-13. */
body.sg-open .statusbar,
body.sc-open .statusbar { display: none; }
.statusbar-pill {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 8px 20px;
  background: rgba(26, 28, 28, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 9999px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15), 0 1px 6px rgba(0, 0, 0, 0.1);
  color: #fff;
}
.statusbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
}
.statusbar-label {
  font-size: 8px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: rgba(255, 255, 255, 0.4);
  font-weight: 500;
}
.statusbar-value {
  font-size: 11px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
}
.statusbar-divider {
  width: 1px;
  height: 16px;
  background: rgba(255, 255, 255, 0.15);
}
/* Legacy statusbar-item & statusbar-spacer support */
.statusbar-item {
  display: flex;
  align-items: center;
  gap: 4px;
}
.statusbar-spacer { flex: 1; }
.statusbar kbd {
  font-size: 10px;
  padding: 1px 4px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 2px;
  font-family: var(--font-sans);
  color: rgba(255, 255, 255, 0.6);
}

/* === Preview Content — Word-style A4 sheet on a gray desk === */
.preview-scroll-desk {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-secondary, #f5f5f5);
}
.preview-content {
  --page-w: 794px;
  --page-margin: 96px;
  padding: var(--page-margin);
  width: var(--page-w);
  max-width: calc(100% - 48px);
  min-height: 560px;
  margin: 22px auto;
  background: var(--bg-primary, #ffffff);
  border: 1px solid var(--border-light, #ebebeb);
  border-radius: 2px;
  box-shadow: var(--shadow-sm);
  box-sizing: border-box;
  font-family: var(--font-serif);
  font-size: 17px;
  line-height: 1.8;
  color: var(--text-primary);
}

/* === Welcome Screen === */
.screen-welcome {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: var(--bg-elevated);
}
.welcome-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  box-shadow: var(--shadow-sm);
  position: relative;
  z-index: 5; /* shadow drops onto the body below (mockup top bar) */
  flex-shrink: 0;
}
.welcome-brand {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.welcome-brand .brand-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.welcome-brand .brand-star {
  flex-shrink: 0;
  align-self: center;
  margin-right: 2px;
}
.brand-org {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--accent-blue, #0497AF);
  line-height: 1;
}
/* Masked logo: source SVG ships as white raster → use CSS mask so we control
   the final color. --logo-url is set inline by the bootstrap script. */
.welcome-brand .brand-logo {
  display: inline-block;
  width: 125px;
  height: 27px;
  background-color: var(--accent-blue, #0497AF);
  -webkit-mask-image: var(--logo-url);
  mask-image: var(--logo-url);
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: left center;
  mask-position: left center;
}
.brand-wordmark {
  font-size: 21px;
  font-weight: 300;
  letter-spacing: 0.04em;
  color: var(--text-primary);
  line-height: 1;
}
.welcome-title {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-blue);
  line-height: 1.2;
}
.welcome-subtitle {
  font-size: 10px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-hint);
  margin-top: 2px;
}
.topbar-brand {
  display: inline-flex !important;
  align-items: baseline;
  gap: 6px;
}
.topbar-brand .topbar-star {
  flex-shrink: 0;
  align-self: center;
  margin-right: 1px;
}
.topbar-org {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--accent-blue, #0497AF);
  line-height: 1;
}
.topbar-brand .topbar-logo {
  display: inline-block;
  width: 80px;
  height: 18px;
  vertical-align: middle;
  background-color: var(--accent-blue, #0497AF);
  -webkit-mask-image: var(--logo-url);
  mask-image: var(--logo-url);
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: left center;
  mask-position: left center;
}
.topbar-wordmark {
  font-size: 16px;
  font-weight: 400;
  letter-spacing: 0.03em;
  color: var(--text-primary);
  line-height: 1;
}
/* Document title — Office-style centre slot between the two spacers */
.topbar-doc-title {
  min-width: 0;
  max-width: 38vw;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.welcome-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
/* Language pill: globe icon + bare select share one bordered capsule */
.home-lang-wrap {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 5px 6px 5px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-surface);
  color: var(--text-secondary);
}
.home-lang-select {
  padding: 0 4px;
  border: 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  cursor: pointer;
  font-family: var(--font-sans);
}
.welcome-header .user-badge {
  position: static;
}

/* Home toolbar: OWNED by home.css (L19 Drive-style) — a legacy duplicate
   here used to zero the top padding and won the cascade (loaded later),
   which is why the row sat glued to the edge (Thầy 2026-07-12 ×2). */
.home-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.home-search-icon {
  position: absolute;
  left: 10px;
  color: var(--text-hint);
  pointer-events: none;
}
.home-search {
  padding: 7px 12px 7px 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  width: 220px;
  background: var(--bg-surface);
  font-family: var(--font-sans);
  transition: border-color 0.15s;
}
.home-search:focus {
  border-color: var(--accent-blue);
  outline: none;
  box-shadow: 0 0 0 3px rgba(4, 151, 175, 0.08);
}
.home-filter {
  padding: 7px 28px 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 12px;
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23a39e98'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.home-toolbar-spacer { flex: 1; }
.home-view-btn {
  padding: 6px;
  color: var(--text-hint);
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}
.home-view-btn.active {
  color: var(--accent-blue);
  background: rgba(4, 151, 175, 0.08);
}
.home-view-btn:hover:not(.active) {
  color: var(--text-secondary);
}
.home-new-btn {
  background: var(--accent-blue) !important;
  border-color: var(--accent-blue) !important;
  color: #fff !important;
  font-weight: 600 !important;
  gap: 6px !important;
  padding: 6px 16px !important;
  border-radius: var(--radius-md) !important;
  letter-spacing: 0.02em;
}
.home-new-btn:hover {
  background: var(--accent-blue-hover) !important;
  transform: none !important;
  box-shadow: var(--shadow-sm);
}

/* Project container */
.project-container {
  flex: 1;
  overflow-y: auto;
  padding: 0 40px 24px;
}

.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.project-grid.hidden { display: none; }

/* Project table */
.project-table { width: 100%; }
.project-table.hidden { display: none; }
.project-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.project-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-hint);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border-bottom: 1px solid var(--border);
}
.project-row {
  cursor: pointer;
  transition: background 0.12s;
}
.project-row:hover { background: rgba(4, 151, 175, 0.04); }
.project-row td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
}
.project-row-title {
  font-weight: 600;
  color: var(--text-primary);
}

/* Card delete button */
.card-actions { display: flex; justify-content: flex-end; margin-top: 8px; }
.card-del {
  font-size: 16px;
  color: var(--text-hint);
  opacity: 0;
  transition: opacity 0.15s;
}
.project-card:hover .card-del,
.project-row:hover .card-del { opacity: 1; }
.card-del:hover { color: var(--accent-red); }

/* === Workspace Screen === */
.screen-workspace {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  position: relative;
}

/* === Preview Screen === */
.screen-preview {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* === New Project Screen === */
.screen-new-project {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: var(--bg-elevated);
  overflow: hidden;
}
.new-project-content {
  max-width: 640px;
  margin: 0 auto;
  padding: 32px 40px calc(40px + env(safe-area-inset-bottom, 0px));
  width: 100%;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.new-project-heading {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text-primary);
  letter-spacing: -0.2px;
}

.type-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.form-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* === New-project attachments (files + YouTube/audio URL, RAG-indexed) === */
.form-hint {
  font-size: 11.5px;
  color: var(--text-secondary);
  margin: -4px 0 8px;
  line-height: 1.4;
}
.attach-dropzone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 18px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s;
  background: var(--bg-elevated);
  margin-bottom: 8px;
}
.attach-dropzone:hover { border-color: var(--accent-blue); background: var(--bg-subtle, var(--bg-elevated)); }
.attach-dropzone.dragover { border-color: var(--accent-blue); background: color-mix(in srgb, var(--accent-blue) 8%, transparent); }
.attach-dropzone-label {
  display: flex; align-items: center; gap: 8px;
  color: var(--text-secondary); font-size: 12.5px;
}
.attach-staged-list {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px;
}
.attach-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 8px 4px 8px;
  background: var(--bg-subtle, var(--bg-elevated));
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11.5px; max-width: 100%;
}
.attach-chip-url { border-color: var(--accent-blue); }
.attach-chip-icon { font-size: 13px; line-height: 1; }
.attach-chip-kind {
  text-transform: uppercase; font-size: 9.5px; font-weight: 600;
  color: var(--accent-blue); letter-spacing: 0.4px;
}
.attach-chip-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 220px; color: var(--text-primary);
}
.attach-chip-size { color: var(--text-secondary); font-size: 10.5px; }
.attach-chip-remove {
  background: transparent; border: none; cursor: pointer;
  color: var(--text-secondary); font-size: 14px; line-height: 1;
  padding: 0 2px; margin-left: 2px;
}
.attach-chip-remove:hover { color: var(--accent-red, #d03838); }

/* === Resizable Right Panel === */
.resize-handle {
  position: absolute;
  left: -3px;
  top: 0;
  bottom: 0;
  width: 6px;
  cursor: col-resize;
  z-index: 20;
  background: transparent;
  transition: background 0.15s;
}
.resize-handle:hover,
.resize-handle.active {
  background: var(--accent-blue);
}
.editor-content pre {
  background: var(--bg-elevated, #f6f5f4);
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  margin: 12px 0;
}
.editor-content pre code {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  white-space: pre;
  background: none;
  padding: 0;
}
.editor-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 14px;
}
.editor-content th {
  background: var(--bg-elevated, #f6f5f4);
  padding: 8px 12px;
  text-align: left;
  border-bottom: 2px solid var(--border, rgba(0,0,0,0.1));
  font-weight: 600;
}
.editor-content td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border, rgba(0,0,0,0.1));
}
.editor-content tr:hover td {
  background: rgba(0,0,0,0.02);
}
/* Empty cells still need a click target */
.editor-content th:empty::after,
.editor-content td:empty::after { content: '\00a0'; }

/* ── Table insert picker + floating table toolbar (editor-table.js) ── */
.table-picker-popup {
  position: absolute;
  z-index: 3000;
  background: var(--bg-elevated, #ffffff);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: var(--radius-sm, 6px);
  padding: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.35);
}
.table-picker-grid { display: grid; gap: 3px; }
.table-picker-cell {
  width: 16px;
  height: 16px;
  border: 1px solid var(--border, #d7dade);
  border-radius: 2px;
  cursor: pointer;
}
.table-picker-cell.on {
  background: var(--accent-blue, #079d9d);
  border-color: var(--accent-blue, #079d9d);
}
.table-picker-label {
  margin-top: 6px;
  text-align: center;
  font-size: 11px;
  color: var(--text-secondary, #6b7280);
}
.tbl-toolbar {
  position: fixed;
  z-index: 2500;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 3px 6px;
  background: var(--bg-elevated, #ffffff);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: var(--radius-sm, 6px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

/* ── Find & replace panel (editor-find.js) ── */
.editor-find-panel {
  position: absolute;
  top: 46px;
  right: 16px;
  z-index: 2600;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  background: var(--bg-elevated, #ffffff);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: var(--radius-sm, 6px);
  box-shadow: 0 6px 24px rgba(0,0,0,0.3);
}
.editor-find-panel .ef-row { display: flex; align-items: center; gap: 5px; }
.editor-find-panel input {
  width: 190px;
  height: 26px;
  padding: 0 8px;
  font-size: 12.5px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: var(--radius-sm, 4px);
  background: var(--bg-secondary, #f5f5f5);
  color: var(--text-primary, #1a1a1a);
}
.ef-count {
  min-width: 42px;
  text-align: center;
  font-size: 11.5px;
  color: var(--text-secondary, #6b7280);
}
::highlight(writer-find) { background: rgba(250, 204, 21, 0.35); }
::highlight(writer-find-current) { background: rgba(249, 115, 22, 0.8); color: #111; }

/* ── Version history modal (editor-history.js) ── */
.eh-overlay {
  position: fixed;
  inset: 0;
  z-index: 4000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
}
.eh-modal {
  display: flex;
  flex-direction: column;
  width: min(920px, 92vw);
  height: min(640px, 86vh);
  background: var(--bg-primary, #ffffff);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: var(--radius-md, 8px);
  box-shadow: 0 12px 48px rgba(0,0,0,0.5);
  overflow: hidden;
}
.eh-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border, #e5e7eb);
}
.eh-title { font-weight: 600; font-size: 14px; }
.eh-body { display: flex; flex: 1; min-height: 0; }
.eh-list {
  width: 270px;
  flex-shrink: 0;
  overflow-y: auto;
  border-right: 1px solid var(--border, #e5e7eb);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.eh-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 10px;
  text-align: left;
  border: 1px solid var(--border, #e9ebee);
  border-radius: var(--radius-sm, 6px);
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
}
.eh-item:hover { background: var(--bg-hover, rgba(255,255,255,0.05)); }
.eh-item-active { border-color: var(--accent-blue, #079d9d); background: rgba(74,158,255,0.08); }
.eh-item-top { display: flex; align-items: center; gap: 6px; }
.eh-author {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 8px;
  letter-spacing: 0.4px;
}
.eh-author-ai { background: rgba(74,158,255,0.2); color: var(--accent-blue, #079d9d); }
.eh-author-user { background: rgba(52,211,153,0.18); color: var(--accent-green, #34d399); }
.eh-action { font-size: 12px; font-weight: 600; }
.eh-meta { font-size: 11px; color: var(--text-hint, #9ca3af); }
.eh-preview-wrap { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.eh-preview {
  flex: 1;
  overflow-y: auto;
  padding: 16px 22px;
  max-width: none;
}
.eh-actions {
  display: flex;
  justify-content: flex-end;
  padding: 10px 14px;
  border-top: 1px solid var(--border, #e5e7eb);
}

/* ── Slash menu (editor-shortcuts.js) — base popup style comes from
   .sc-menu-popup in slide-canvas.css (loaded app-wide) ── */
.slash-menu { max-height: 320px; overflow-y: auto; min-width: 230px; }
.slash-menu .sc-menu-item.slash-active { background: var(--bg-hover, rgba(255,255,255,0.08)); }
.slash-ai-badge {
  margin-left: auto;
  font-size: 9.5px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 7px;
  background: rgba(74, 158, 255, 0.2);
  color: var(--accent-blue, #079d9d);
  letter-spacing: 0.4px;
}

/* ── Focus mode (UX #8): panels hidden, editor centered, chrome dimmed ── */
.focus-mode .left-panel,
.focus-mode .right-panel,
.focus-mode .comment-panel { display: none !important; }
.focus-mode .editor-content {
  max-width: 72ch;
  padding-top: 40px;
}
.focus-mode .editor-toolbar { opacity: 0.25; transition: opacity 0.25s; }
.focus-mode .editor-toolbar:hover { opacity: 1; }
#btn-focus-mode.active { background: var(--accent-blue, #079d9d); color: #fff; }

.inline-diagram {
  margin: 20px 0;
  text-align: center;
  user-select: none;
}
.inline-diagram img {
  max-width: 100%;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.inline-diagram figcaption {
  font-size: 13px;
  color: var(--text-tertiary, #888);
  margin-top: 8px;
  font-style: italic;
}
.editor-content .inline-diagram {
  cursor: default;
}

/* Verse / text size / align / indent — mirror of .editor-content so the
   preview surface renders what the user sees while editing. */
.preview-content blockquote.verse,
.preview-content .verse {
  border-left: 0;
  padding-left: 0;
  text-align: center;
  font-family: var(--font-serif, 'Noto Serif', Georgia, serif);
  font-style: italic;
  color: var(--text-primary);
  margin: 1.4em auto;
  max-width: 34em;
  white-space: pre-wrap;
}
.preview-content .txt-sm { font-size: 0.85em; }
.preview-content .txt-lg { font-size: 1.2em; }
.preview-content .align-center  { text-align: center; }
.preview-content .align-right   { text-align: right; }
.preview-content .align-justify { text-align: justify; }
.preview-content .indent-1 { padding-left: 2em; }
.preview-content .indent-2 { padding-left: 4em; }
.preview-content .indent-3 { padding-left: 6em; }
.preview-content .tc-red    { color: var(--accent-red, #e03e3e); }
.preview-content .tc-orange { color: var(--accent-orange, #dd5b00); }
.preview-content .tc-green  { color: var(--accent-green, #1aae39); }
.preview-content .tc-teal   { color: var(--accent-cyan, #2a9d99); }
.preview-content .tc-blue   { color: var(--accent-blue, #0497AF); }
.preview-content .tc-purple { color: var(--accent-purple, #6b3fa0); }
.preview-content .hl-yellow { background: rgba(250, 204, 21, 0.38); padding: 0 2px; border-radius: 2px; }
.preview-content .hl-green  { background: rgba(52, 211, 153, 0.32); padding: 0 2px; border-radius: 2px; }
.preview-content .hl-blue   { background: rgba(96, 165, 250, 0.32); padding: 0 2px; border-radius: 2px; }
.preview-content .hl-pink   { background: rgba(236, 72, 153, 0.30); padding: 0 2px; border-radius: 2px; }
.preview-content .hl-orange { background: rgba(249, 115, 22, 0.32); padding: 0 2px; border-radius: 2px; }
.preview-content .hl-red    { background: rgba(239, 68, 68, 0.30); padding: 0 2px; border-radius: 2px; }

/* Heading sizes tuned for reading, not grabbing attention. Border-bottom on
   h2 is gone — it looked like a "chapter divider" on literary projects but
   report-style content doesn't need it either: use <hr> if you want a rule. */
.preview-content h1 { font-size: 1.5em;  margin: 0.9em 0 0.35em; line-height: 1.25; }
.preview-content h2 { font-size: 1.22em; margin: 1em 0 0.3em;   line-height: 1.3; }
.preview-content h3 { font-size: 1.1em;  margin: 0.8em 0 0.25em; line-height: 1.35; }
.preview-content h4 { font-size: 1.02em; margin: 0.7em 0 0.2em;  line-height: 1.4; }
.preview-content h5 { font-size: 0.98em; margin: 0.6em 0 0.2em;  font-weight: 600; }
.preview-content ul, .preview-content ol { margin: 8px 0; padding-left: 28px; }
.preview-content li { margin: 4px 0; line-height: 1.7; }
.preview-content hr { border: 0; border-top: 1px solid var(--border, rgba(0,0,0,0.1)); margin: 20px 0; }
.preview-content pre {
  background: var(--bg-elevated);
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  margin: 16px 0;
}
.preview-content pre code {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  white-space: pre;
  background: none;
  padding: 0;
}
.preview-content code {
  background: var(--bg-elevated);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}
.preview-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 15px;
}
.preview-content th {
  background: var(--bg-elevated, #f6f5f4);
  padding: 10px 14px;
  text-align: left;
  border-bottom: 2px solid var(--border, rgba(0,0,0,0.1));
  font-weight: 600;
}
.preview-content td {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border, rgba(0,0,0,0.1));
}
.preview-content tr:hover td {
  background: rgba(255,255,255,0.03);
}

/* Figures and images — both <figure><img></figure> (illustrations) and bare
   <img> must scale to fit the reading column. Without these rules, raw
   figures inserted via Calliope (write_node path, no inline style) render
   at natural width and overflow the 720px reading column. Editor surface
   already has its own `.editor-content img` rule; figure/figcaption added
   here for completeness so what the user sees while editing matches preview. */
.preview-content figure,
.editor-content figure {
  margin: 20px 0;
  text-align: center;
}
.preview-content figure img,
.preview-content img,
.editor-content figure img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  display: inline-block;
}
.preview-content figcaption,
.editor-content figcaption {
  font-size: 14px;
  color: var(--text-tertiary);
  margin-top: 8px;
  font-style: italic;
  line-height: 1.5;
}

/* ── Block flash animation (AI content update) ── */
@keyframes block-flash-anim {
  0% { background-color: rgba(0, 117, 222, 0.18); }
  70% { background-color: rgba(0, 117, 222, 0.08); }
  100% { background-color: transparent; }
}
.editor-content .block-flash {
  animation: block-flash-anim 2s ease-out;
  border-radius: 4px;
}
/* ── Flow mode (editor-flow.js): Word-style continuous document.
   Node titles render as REAL document headings (Thầy 2026-07-13) — the
   same hierarchy the docx export writes — not decorative dividers. The
   seam stays non-editable; sizes mirror .editor-content h1/h2. ── */
.flow-seam {
  display: block;
  margin: 1.6em 0 0.3em;
  user-select: none;
  cursor: default;
}
.editor-content > .flow-seam:first-child { margin-top: 0; }
.flow-seam-title {
  display: block;
  font-size: 1.4em;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text-primary);
}
.flow-seam--h2 .flow-seam-title {
  font-size: 1.2em;
  line-height: 1.3;
}
#btn-flow-mode.active { background: var(--accent-blue); color: #fff; border-color: var(--accent-blue); }

/* ── Font-family picker (class-based — inline styles get sanitized away;
   classes survive save/reload and the P4 docx mapper translates them) ── */
.editor-content .ff-serif,  .preview-content .ff-serif  { font-family: 'Noto Serif', Georgia, serif; }
.editor-content .ff-times,  .preview-content .ff-times  { font-family: 'Times New Roman', 'Noto Serif', serif; }
.editor-content .ff-arial,  .preview-content .ff-arial  { font-family: Arial, 'Noto Sans', sans-serif; }
.editor-content .ff-georgia, .preview-content .ff-georgia { font-family: Georgia, 'Noto Serif', serif; }
.editor-content .ff-mono,   .preview-content .ff-mono   { font-family: var(--font-mono); }
