/* AllScience — Writing Studio */

/* ── CRITICAL FIX: Hide all slide-out panels by default ────────────── */
.rd-panel, .ld-panel, .tof-panel, .en-panel, .gi-panel, .dom-panel,
.pr-panel, .vr-panel, .ab-panel, .abm-panel, .ald-panel, .ccb-panel,
.comments-panel, .fn-panel, .hhv-panel, .odr-panel, .on-panel,
.pc-panel, .pmp-panel, .scs-panel, .st-panel, .ts-panel, .twh-panel,
.wfa-panel, .xr-panel {
  pointer-events: none !important;
  visibility: hidden !important;
}
.rd-panel.rd-panel-open, .ld-panel.ld-panel-open, .ab-panel.ab-panel-open,
.abm-panel.abm-panel-open, .ald-panel.ald-panel-open, .ccb-panel.ccb-panel-open,
.comments-panel.comments-panel-open, .fn-panel.fn-panel-open,
.hhv-panel.hhv-panel-open, .odr-panel.odr-panel-open, .on-panel.on-panel-open,
.pc-panel.pc-panel-open, .pmp-panel.pmp-panel-open, .scs-panel.scs-panel-open,
.st-panel.st-panel-open, .ts-panel.ts-panel-open, .twh-panel.twh-panel-open,
.wfa-panel.wfa-panel-open, .xr-panel.xr-panel-open {
  pointer-events: auto !important;
  visibility: visible !important;
}

.writing-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Top Bar ───────────────────────────────────────────────────────── */
.writing-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  height: 52px;
  background: var(--color-bg-secondary, #111827);
  border-bottom: 1px solid var(--color-border, #1e293b);
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 1;
  min-width: 0;
  overflow: hidden;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  color: var(--color-text, #e2e8f0);
  text-decoration: none;
  font-size: 0.9375rem;
  white-space: nowrap;
}

.project-title {
  font-size: 0.875rem;
  color: var(--color-text-muted, #8896ab);
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-center {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.progress-label {
  font-size: 0.75rem;
  color: var(--color-text-muted, #8896ab);
  white-space: nowrap;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.save-status {
  font-size: 0.75rem;
  color: var(--color-success, #10b981);
  font-weight: 500;
}

/* ── Main Layout ───────────────────────────────────────────────────── */
.writing-layout {
  display: grid;
  grid-template-columns: 240px 1fr 280px;
  flex: 1;
  overflow: hidden;
}

/* ── Outline Panel ─────────────────────────────────────────────────── */
.outline-panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--color-border, #1e293b);
  background: var(--color-bg-secondary, #111827);
  overflow: hidden;
}

.outline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem 0.75rem;
}

.outline-header h4 {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
}

.outline-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 0.5rem;
}

.outline-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 0.75rem;
  margin-bottom: 2px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8125rem;
  color: var(--color-text-muted, #8896ab);
  transition: background 0.15s, color 0.15s;
  user-select: none;
}

.outline-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--color-text, #e2e8f0);
}

.outline-item.active {
  background: rgba(59, 130, 246, 0.12);
  color: var(--color-primary, #3b82f6);
  font-weight: 600;
}

.outline-item-icon {
  font-size: 0.75rem;
  opacity: 0.6;
  width: 16px;
  text-align: center;
}

.outline-item-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.outline-item-wc {
  font-size: 0.6875rem;
  color: var(--color-text-dim, #5a6a80);
  font-family: 'JetBrains Mono', monospace;
  white-space: nowrap;
}

.outline-footer {
  padding: 0.75rem;
  border-top: 1px solid var(--color-border, #1e293b);
}

/* ── Editor Panel ──────────────────────────────────────────────────── */
.editor-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 1.5rem;
  border-bottom: 1px solid var(--color-border, #1e293b);
  background: var(--color-bg, #0a0e17);
  flex-shrink: 0;
}

.toolbar-section-name {
  font-weight: 600;
  font-size: 0.9375rem;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.word-count-label {
  font-size: 0.8125rem;
  font-family: 'JetBrains Mono', monospace;
  color: var(--color-text, #e2e8f0);
}

.target-label {
  font-size: 0.8125rem;
  color: var(--color-text-dim, #5a6a80);
}

.editor-area {
  flex: 1;
  overflow-y: auto;
  padding: 2rem 3rem;
}

.editor-empty {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--color-text-muted, #8896ab);
}

.editor-empty h3 { color: var(--color-text, #e2e8f0); margin-bottom: 0.5rem; }
.editor-empty > p { margin-bottom: 1.5rem; }
.onboard-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; max-width: 700px; margin: 0 auto 1.5rem; }
.onboard-card { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; padding: 1.25rem 1rem; background: var(--color-bg-card, #1e293b); border: 1px solid var(--color-border, #334155); border-radius: 10px; text-decoration: none; color: var(--color-text-muted, #8896ab); transition: border-color 0.2s, transform 0.2s; }
.onboard-card:hover { border-color: var(--color-primary, #3b82f6); transform: translateY(-2px); }
.onboard-icon { font-size: 1.75rem; }
.onboard-card strong { color: var(--color-text, #e2e8f0); font-size: 0.9375rem; }
.onboard-card span { font-size: 0.8125rem; line-height: 1.4; }
.onboard-features { display: flex; justify-content: center; gap: 1.25rem; flex-wrap: wrap; font-size: 0.8125rem; color: var(--color-text-muted, #64748b); }

.editor-textarea {
  width: 100%;
  min-height: 400px;
  background: transparent;
  border: none;
  color: var(--color-text, #e2e8f0);
  font-family: 'Inter', sans-serif;
  font-size: 1rem;
  line-height: 1.8;
  resize: none;
  outline: none;
}

.editor-textarea::placeholder {
  color: var(--color-text-dim, #5a6a80);
}

.section-progress {
  margin-top: 1rem;
}

.section-progress-text {
  font-size: 0.75rem;
  color: var(--color-text-dim, #5a6a80);
  margin-bottom: 0.25rem;
}

/* ── Tools Sidebar ─────────────────────────────────────────────────── */
.tools-sidebar {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--color-border, #1e293b);
  background: var(--color-bg-secondary, #111827);
  overflow: hidden;
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--color-border, #1e293b);
  flex-shrink: 0;
}

.sidebar-tab {
  flex: 1;
  padding: 0.75rem 0.5rem;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-muted, #8896ab);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.sidebar-tab:hover { color: var(--color-text, #e2e8f0); }

.sidebar-tab.active {
  color: var(--color-primary, #3b82f6);
  border-bottom-color: var(--color-primary, #3b82f6);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.sidebar-hint {
  font-size: 0.8125rem;
  color: var(--color-text-dim, #5a6a80);
  margin-bottom: 1rem;
  line-height: 1.5;
}

.sidebar-source-item {
  padding: 0.625rem 0.75rem;
  margin-bottom: 0.5rem;
  background: var(--color-bg, #0a0e17);
  border: 1px solid var(--color-border, #1e293b);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.sidebar-source-item:hover { border-color: var(--color-primary, #3b82f6); }

.sidebar-source-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text, #e2e8f0);
  margin-bottom: 0.25rem;
}

.sidebar-source-meta {
  font-size: 0.6875rem;
  color: var(--color-text-dim, #5a6a80);
}

.citation-entry {
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.5rem;
  background: var(--color-bg, #0a0e17);
  border: 1px solid var(--color-border, #1e293b);
  border-radius: 6px;
  font-size: 0.75rem;
  color: var(--color-text-muted, #8896ab);
  line-height: 1.5;
}

.citation-marker {
  display: inline-block;
  padding: 0.125rem 0.375rem;
  background: rgba(59, 130, 246, 0.15);
  color: var(--color-primary, #3b82f6);
  border-radius: 3px;
  font-size: 0.6875rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  cursor: pointer;
}

.citation-marker:hover { background: rgba(59, 130, 246, 0.3); }

.ref-list-output {
  font-size: 0.75rem;
  color: var(--color-text-muted, #8896ab);
  line-height: 1.6;
  white-space: pre-wrap;
  background: var(--color-bg, #0a0e17);
  padding: 1rem;
  border-radius: 6px;
  border: 1px solid var(--color-border, #1e293b);
}

/* Stats panel */
.stat-section {
  margin-bottom: 1.25rem;
}

.stat-section-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.8125rem;
  margin-bottom: 0.375rem;
}

.stat-section-name { font-weight: 600; }
.stat-section-count { font-family: 'JetBrains Mono', monospace; color: var(--color-text-muted, #8896ab); }

/* ── Review Modal ──────────────────────────────────────────────────── */
.review-score-big {
  font-size: 3rem;
  font-weight: 800;
  text-align: center;
  margin: 1rem 0;
}

.review-score-big.score-high { color: var(--color-success, #10b981); }
.review-score-big.score-mid { color: var(--color-warning, #f59e0b); }
.review-score-big.score-low { color: var(--color-danger, #ef4444); }

.review-category {
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: var(--color-bg, #0a0e17);
  border-radius: 6px;
}

.review-cat-header {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
}

.review-finding {
  font-size: 0.8125rem;
  padding: 0.375rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  color: var(--color-text-muted, #8896ab);
}

.review-finding:last-child { border-bottom: none; }

.finding-issue { color: var(--color-warning, #f59e0b); font-weight: 500; }
.finding-suggestion { font-style: italic; }

.review-strengths, .review-weaknesses {
  margin-top: 1rem;
}

.review-strengths li { color: var(--color-success, #10b981); }
.review-weaknesses li { color: var(--color-warning, #f59e0b); }

/* ── Drag-and-Drop Section Reorder ─────────────────────────────── */
.outline-drag-handle {
  cursor: grab; font-size: 0.625rem; color: var(--color-text-dim, #5a6a80);
  opacity: 0.4; transition: opacity 0.15s; padding: 0 0.125rem;
  user-select: none; flex-shrink: 0;
}
.outline-item:hover .outline-drag-handle { opacity: 1; }
.outline-drag-handle:active { cursor: grabbing; }

.outline-item.dragging {
  opacity: 0.4; background: rgba(59,130,246,0.08);
  border: 1px dashed var(--color-primary, #3b82f6); border-radius: 6px;
}
.outline-item.drag-over {
  border-top: 2px solid var(--color-primary, #3b82f6);
  background: rgba(59,130,246,0.06);
}

/* Outline item info layout (with mini progress bar) */
.outline-item-info { flex: 1; min-width: 0; }
.outline-item-progress { display: flex; align-items: center; gap: 0.375rem; margin-top: 0.125rem; }
.outline-mini-bar {
  flex: 1; height: 3px; background: rgba(255,255,255,0.06);
  border-radius: 2px; overflow: hidden;
}
.outline-mini-fill { height: 100%; border-radius: 2px; transition: width 0.3s; }

/* ── Section Reorder + Source Actions ──────────────────────────── */
.outline-item-actions { display: flex; gap: 0.125rem; margin-left: auto; flex-shrink: 0; }
.outline-move-btn {
  background: none; border: none; color: var(--color-text-dim, #5a6a80);
  cursor: pointer; font-size: 0.75rem; padding: 0 0.25rem; line-height: 1;
}
.outline-move-btn:hover { color: var(--color-primary, #3b82f6); }
.sidebar-source-actions { display: flex; gap: 0.25rem; margin-top: 0.375rem; }
.src-action-btn {
  padding: 0.125rem 0.375rem; border: 1px solid var(--color-border, #1e293b);
  border-radius: 3px; background: transparent; color: var(--color-text-dim, #5a6a80);
  font-size: 0.625rem; cursor: pointer; transition: all 0.15s;
}
.src-action-btn:hover { border-color: var(--color-primary, #3b82f6); color: var(--color-primary, #3b82f6); }

/* ── Rich Text Format Toolbar ──────────────────────────────────── */
.format-toolbar {
  display: flex; align-items: center; gap: 0.25rem;
  padding: 0.375rem 0.75rem;
  background: var(--color-bg-secondary, #111827);
  border-bottom: 1px solid var(--color-border, #1e293b);
  flex-wrap: wrap;
}
.fmt-btn {
  padding: 0.25rem 0.5rem; border: 1px solid transparent; border-radius: 4px;
  background: transparent; color: var(--color-text-muted, #8896ab);
  cursor: pointer; font-size: 0.8125rem; min-width: 28px; text-align: center;
  transition: all 0.15s;
}
.fmt-btn:hover { background: rgba(255,255,255,0.06); color: var(--color-text, #e2e8f0); border-color: var(--color-border, #1e293b); }
.fmt-btn:active, .fmt-btn.active { background: rgba(59,130,246,0.15); color: var(--color-primary, #3b82f6); border-color: var(--color-primary, #3b82f6); }
.fmt-sep { width: 1px; height: 20px; background: var(--color-border, #1e293b); margin: 0 0.25rem; }
.fmt-select {
  padding: 0.25rem 0.5rem; border: 1px solid var(--color-border, #1e293b);
  border-radius: 4px; background: var(--color-bg, #0a0e17);
  color: var(--color-primary, #3b82f6); font-size: 0.75rem; cursor: pointer;
}

/* Rich text editor area */
.rich-editor {
  flex: 1; padding: 2rem 3rem; overflow-y: auto;
  font-family: 'Lora', serif; font-size: 1.0625rem; line-height: 2;
  color: var(--color-text, #e2e8f0); outline: none;
  min-height: 300px;
}
.rich-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--color-text-dim, #5a6a80);
}
.rich-editor h2 { font-size: 1.375rem; margin: 1em 0 0.5em; border-bottom: 1px solid rgba(255,255,255,0.06); padding-bottom: 0.25em; }
.rich-editor h3 { font-size: 1.125rem; margin: 0.75em 0 0.375em; }
.rich-editor blockquote { border-left: 3px solid var(--color-primary, #3b82f6); padding-left: 1rem; margin: 1em 0; color: var(--color-text-muted, #8896ab); font-style: italic; }
.rich-editor ul, .rich-editor ol { padding-left: 1.5em; margin: 0.5em 0; }
.rich-editor sup { font-size: 0.75em; }
.rich-editor sub { font-size: 0.75em; }

/* ── Toolbar Nav Links ─────────────────────────────────────────── */
.topbar-nav { display: flex; align-items: center; gap: 0.25rem; margin-left: 1rem; }
.topbar-nav a {
  font-size: 0.75rem; padding: 0.25rem 0.625rem; border-radius: 4px;
  color: var(--color-text-muted, #8896ab); text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.topbar-nav a:hover { background: rgba(255,255,255,0.06); color: var(--color-text, #e2e8f0); }
.topbar-nav a.active { background: rgba(59,130,246,0.15); color: var(--color-primary, #3b82f6); }

/* ── Cite Button (toolbar) ────────────────────────────────────────── */
.fmt-cite-btn {
  background: rgba(59,130,246,0.1) !important;
  color: var(--color-primary, #3b82f6) !important;
  border-color: rgba(59,130,246,0.3) !important;
  font-size: 0.75rem !important;
  padding: 0.25rem 0.625rem !important;
}
.fmt-cite-btn:hover { background: rgba(59,130,246,0.2) !important; }

/* ── Citation Picker Modal ────────────────────────────────────────── */
.cite-picker { max-height: 400px; overflow-y: auto; }
.cite-picker-item {
  padding: 0.625rem 0.75rem; margin-bottom: 0.375rem;
  background: var(--color-bg, #0a0e17); border: 1px solid var(--color-border, #1e293b);
  border-radius: 6px; cursor: pointer; transition: border-color 0.15s;
}
.cite-picker-item:hover { border-color: var(--color-primary, #3b82f6); }
.cite-picker-item .cite-preview {
  font-size: 0.75rem; color: var(--color-primary, #3b82f6); margin-top: 0.25rem; font-style: italic;
}

/* ── AI Generate Button ──────────────────────────────────────────── */
#generate-section-btn {
  font-size: 0.75rem; padding: 0.25rem 0.75rem; white-space: nowrap;
}

/* ── Generate Modal ──────────────────────────────────────────────── */
.gen-instructions-area {
  width: 100%; min-height: 80px; padding: 0.75rem;
  background: var(--color-bg, #0a0e17); border: 1px solid var(--color-border, #1e293b);
  border-radius: 6px; color: var(--color-text, #e2e8f0);
  font-size: 0.875rem; font-family: inherit; resize: vertical;
}
.gen-instructions-area::placeholder { color: var(--color-text-dim, #5a6a80); }

.tone-preset-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.375rem; margin-top: 0.5rem; }
.tone-preset-btn {
  padding: 0.375rem 0.5rem; border: 1px solid var(--color-border, #1e293b);
  border-radius: 4px; background: transparent; color: var(--color-text-muted, #8896ab);
  font-size: 0.75rem; cursor: pointer; transition: all 0.15s; text-align: center;
}
.tone-preset-btn:hover { border-color: var(--color-primary, #3b82f6); color: var(--color-primary, #3b82f6); }
.tone-preset-btn.selected { background: rgba(59,130,246,0.15); border-color: var(--color-primary, #3b82f6); color: var(--color-primary, #3b82f6); }

.gen-result-box {
  margin-top: 1rem; padding: 1rem; background: var(--color-bg, #0a0e17);
  border: 1px solid var(--color-border, #1e293b); border-radius: 6px;
  font-size: 0.875rem; line-height: 1.7; white-space: pre-wrap; max-height: 300px; overflow-y: auto;
}

.gen-actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; }
.gen-actions .btn { flex: 1; }

/* ── Comments Panel (Threaded + Mentions) ─────────────────────────── */
.comment-compose { margin-bottom: 0.75rem; }
.comment-compose-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.375rem;
}
.comment-compose-label {
  font-size: 0.75rem; font-weight: 600; color: var(--color-text, #e2e8f0);
}
.comment-input-wrap { position: relative; }
.comment-input {
  width: 100%; min-height: 60px; padding: 0.625rem;
  background: var(--color-bg, #0a0e17); border: 1px solid var(--color-border, #1e293b);
  border-radius: 6px; color: var(--color-text, #e2e8f0);
  font-size: 0.8125rem; font-family: inherit; resize: vertical;
}
.comment-input::placeholder { color: var(--color-text-dim, #5a6a80); }
.comment-reply-textarea { min-height: 44px; font-size: 0.75rem; }

/* Comment badge on sidebar tab */
.comment-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 16px; height: 16px; padding: 0 4px;
  background: var(--color-danger, #ef4444); color: #fff;
  border-radius: 99px; font-size: 0.5625rem; font-weight: 700;
  margin-left: 3px; vertical-align: middle; line-height: 1;
}
[data-theme="light"] .comment-badge { background: #dc2626; }

/* Filter tabs inside the comments panel */
.comment-filter-tabs {
  display: flex; gap: 2px; margin-bottom: 0.75rem;
  background: var(--color-bg, #0a0e17); border-radius: 6px; padding: 2px;
}
.comment-filter-tab {
  flex: 1; text-align: center; padding: 0.375rem 0.5rem;
  font-size: 0.6875rem; font-weight: 600; border: none;
  background: transparent; color: var(--color-text-dim, #5a6a80);
  border-radius: 4px; cursor: pointer; transition: all 0.15s;
}
.comment-filter-tab:hover { color: var(--color-text, #e2e8f0); }
.comment-filter-tab.active {
  background: var(--color-bg-secondary, #111827);
  color: var(--color-primary, #3b82f6);
}
[data-theme="light"] .comment-filter-tabs { background: #f3f4f6; }
[data-theme="light"] .comment-filter-tab.active { background: #fff; }

/* Comment list */
.comments-list { display: flex; flex-direction: column; gap: 0.5rem; }
.comments-empty {
  text-align: center; padding: 2rem 0.5rem;
  color: var(--color-text-dim, #5a6a80); font-size: 0.8125rem; line-height: 1.6;
}

/* Comment card */
.comment-card {
  padding: 0.625rem 0.75rem;
  background: var(--color-bg, #0a0e17);
  border: 1px solid var(--color-border, #1e293b);
  border-radius: 6px; border-left: 3px solid var(--color-primary, #3b82f6);
  transition: opacity 0.2s, max-height 0.3s;
}
.comment-card.comment-reply {
  margin-left: 1.25rem; border-left-color: var(--color-text-dim, #5a6a80);
  background: rgba(255, 255, 255, 0.01);
}
[data-theme="light"] .comment-card.comment-reply { background: rgba(0, 0, 0, 0.01); }

.comment-card.comment-resolved {
  opacity: 0.5; border-left-color: var(--color-success, #10b981);
}
.comment-card.comment-collapsed .comment-body,
.comment-card.comment-collapsed .comment-actions,
.comment-card.comment-collapsed .comment-replies,
.comment-card.comment-collapsed .comment-reply-input-slot {
  display: none;
}
.comment-card.comment-collapsed.comment-expanded .comment-body,
.comment-card.comment-collapsed.comment-expanded .comment-actions,
.comment-card.comment-collapsed.comment-expanded .comment-replies,
.comment-card.comment-collapsed.comment-expanded .comment-reply-input-slot {
  display: block;
}
.comment-card.comment-collapsed { cursor: pointer; }
.comment-card.comment-collapsed::after {
  content: 'Click to expand';
  display: block; font-size: 0.625rem; color: var(--color-text-dim, #5a6a80);
  margin-top: 0.25rem; font-style: italic;
}
.comment-card.comment-collapsed.comment-expanded::after { display: none; }

/* Comment header with avatar */
.comment-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 0.375rem;
}
.comment-author-wrap {
  display: flex; align-items: center; gap: 0.5rem;
}
.comment-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.5625rem; font-weight: 700; color: #fff;
  background: var(--color-primary, #3b82f6); flex-shrink: 0;
}
.comment-reply .comment-avatar { width: 22px; height: 22px; font-size: 0.5rem; }
.comment-author-info { display: flex; flex-direction: column; }
.comment-author {
  font-size: 0.75rem; font-weight: 600; color: var(--color-primary, #3b82f6); line-height: 1.2;
}
.comment-time {
  font-size: 0.5625rem; color: var(--color-text-dim, #5a6a80); line-height: 1.2;
}

/* Resolve toggle */
.comment-resolve-toggle {
  width: 22px; height: 22px; border-radius: 50%;
  border: 1.5px solid var(--color-border, #1e293b);
  background: transparent; color: var(--color-text-dim, #5a6a80);
  font-size: 0.6875rem; cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  transition: all 0.15s; flex-shrink: 0;
}
.comment-resolve-toggle:hover {
  border-color: var(--color-success, #10b981); color: var(--color-success, #10b981);
}
.comment-resolve-toggle.resolved {
  background: var(--color-success, #10b981); border-color: var(--color-success, #10b981);
  color: #fff;
}
.comment-resolve-toggle.resolved:hover {
  background: transparent; color: var(--color-success, #10b981);
}

.comment-body {
  font-size: 0.8125rem; color: var(--color-text-muted, #8896ab);
  line-height: 1.5; margin-bottom: 0.375rem;
}
.comment-actions { display: flex; gap: 0.375rem; align-items: center; }
.comment-reply-btn {
  padding: 0.125rem 0.375rem; border: 1px solid var(--color-border, #1e293b);
  border-radius: 3px; background: transparent; color: var(--color-text-dim, #5a6a80);
  font-size: 0.625rem; cursor: pointer; transition: all 0.15s;
}
.comment-reply-btn:hover { border-color: var(--color-primary, #3b82f6); color: var(--color-primary); }
.comment-resolved-label {
  font-size: 0.625rem; color: var(--color-success, #10b981); font-weight: 500;
}

/* Nested replies container */
.comment-replies { margin-top: 0.5rem; display: flex; flex-direction: column; gap: 0.375rem; }

/* Reply input slot (inline) */
.comment-reply-input-slot { margin-top: 0.5rem; }
.comment-reply-actions {
  display: flex; gap: 0.375rem; margin-top: 0.375rem;
}
.comment-reply-actions .btn { font-size: 0.6875rem; padding: 0.25rem 0.625rem; }

/* @Mention dropdown */
.mention-dropdown {
  position: absolute; left: 0; right: 0; bottom: 100%;
  background: var(--color-bg-secondary, #111827);
  border: 1px solid var(--color-border, #1e293b);
  border-radius: 6px; box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.3);
  max-height: 180px; overflow-y: auto; z-index: 50;
}
[data-theme="light"] .mention-dropdown {
  background: #fff; border-color: #d1d5db;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
}
.mention-item {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 0.625rem; cursor: pointer;
  transition: background 0.1s;
}
.mention-item:hover, .mention-item.active {
  background: rgba(59, 130, 246, 0.1);
}
.mention-item-avatar {
  width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--color-primary, #3b82f6); color: #fff;
  font-size: 0.5rem; font-weight: 700; flex-shrink: 0;
}
.mention-item-name {
  font-size: 0.8125rem; font-weight: 500; color: var(--color-text, #e2e8f0);
}
.mention-item-role {
  font-size: 0.625rem; color: var(--color-text-dim, #5a6a80); margin-left: auto;
}

/* @Mention pill in comment body */
.mention-pill {
  display: inline-block;
  padding: 0.0625rem 0.375rem;
  background: rgba(59, 130, 246, 0.12);
  color: var(--color-primary, #3b82f6);
  border-radius: 3px; font-size: 0.8125em; font-weight: 600;
  white-space: nowrap;
}
[data-theme="light"] .mention-pill { background: rgba(37, 99, 235, 0.1); }

/* ── Export Preview Modal ────────────────────────────────────────── */
.export-preview-frame {
  max-height: 400px; overflow-y: auto;
  border: 1px solid var(--color-border, #1e293b);
  border-radius: 6px; padding: 1.5rem;
  background: #fff; color: #1a1a2e;
  font-family: 'Times New Roman', serif; font-size: 0.9375rem; line-height: 1.7;
}
.export-preview-frame h1 { font-size: 1.375rem; margin-bottom: 1rem; color: #1a1a2e; }
.export-preview-frame h2 { font-size: 1.125rem; margin: 1rem 0 0.5rem; color: #1a1a2e; border-bottom: 1px solid #ddd; padding-bottom: 0.25rem; }
.export-preview-content { line-height: 1.8; }
.export-warnings { margin-top: 0.75rem; }
.export-warning-item {
  font-size: 0.75rem; color: var(--color-warning, #f59e0b);
  padding: 0.25rem 0; border-bottom: 1px solid rgba(255,255,255,0.04);
}

/* In-text citation markers in editor */
.citation-marker-inline {
  display: inline; padding: 0.125rem 0.25rem;
  background: rgba(59,130,246,0.12); color: var(--color-primary, #3b82f6);
  border-radius: 3px; font-size: 0.875em; font-weight: 600;
  cursor: default; user-select: all;
}

/* ── Collaboration Avatars ────────────────────────────────────────── */
.collab-avatars {
  display: flex;
  align-items: center;
  gap: 0;
  margin-right: 0.25rem;
}
.collab-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.625rem; font-weight: 700;
  color: #fff; border: 2px solid var(--color-bg-secondary, #111827);
  margin-left: -6px; cursor: default;
  position: relative; z-index: 1;
  transition: transform 0.15s;
}
.collab-avatar:first-child { margin-left: 0; }
.collab-avatar:hover { transform: scale(1.15); z-index: 2; }
.collab-avatar.owner { background: var(--color-primary, #3b82f6); }
.collab-avatar.editor { background: var(--color-accent, #06d6a0); }
.collab-avatar.viewer { background: var(--color-text-dim, #5a6a80); }
.collab-avatar.commenter { background: var(--color-warning, #f59e0b); }
.collab-count {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.625rem; font-weight: 700;
  background: var(--color-bg-hover, #1f2d42);
  color: var(--color-text-muted, #8896ab);
  border: 2px solid var(--color-bg-secondary, #111827);
  margin-left: -6px;
}

/* Share modal member list */
.share-member-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.5rem 0; border-bottom: 1px solid var(--color-border, #1e293b);
}
.share-member-info { display: flex; align-items: center; gap: 0.5rem; }
.share-member-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 700; color: #fff;
}
.share-member-name { font-size: 0.875rem; font-weight: 500; }
.share-member-role {
  font-size: 0.6875rem; color: var(--color-text-dim, #5a6a80);
  text-transform: capitalize;
}
.share-role-select {
  font-size: 0.75rem; padding: 0.125rem 0.375rem;
  background: var(--color-bg, #0a0e17);
  border: 1px solid var(--color-border, #1e293b);
  border-radius: 4px; color: var(--color-text, #e2e8f0);
}

/* ── Export Modal ──────────────────────────────────────────────────── */
.export-modal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
.export-modal-option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--color-bg, #0a0e17);
  border: 2px solid var(--color-border, #1e293b);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.export-modal-option:hover { border-color: var(--color-primary, #3b82f6); }
.export-modal-option:has(input:checked) {
  border-color: var(--color-accent, #06d6a0);
  background: rgba(6,214,160,0.05);
}
.export-modal-option input[type="radio"] { display: none; }
.export-modal-icon { font-size: 1.5rem; flex-shrink: 0; }
.export-modal-label { font-size: 0.8125rem; line-height: 1.3; }
.export-modal-label strong { color: var(--color-text, #e2e8f0); }
.export-modal-label small { color: var(--color-text-dim, #5a6a80); font-size: 0.6875rem; }

/* ── Focus Mode ────────────────────────────────────────────────────── */

/* Smooth transitions for all panels when entering/exiting focus mode */
.writing-topbar,
.outline-panel,
.tools-sidebar,
.editor-toolbar,
.format-toolbar,
.writing-layout {
  transition: opacity 0.35s ease, transform 0.35s ease, grid-template-columns 0.4s ease;
}

/* Vignette overlay (always present, hidden by default) */
.focus-vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 90;
  transition: opacity 0.4s ease;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.45) 100%);
}

/* Floating mini toolbar (hidden by default) */
.focus-floating-toolbar {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(-60px);
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  background: var(--color-bg-secondary, #111827);
  border: 1px solid var(--color-border, #1e293b);
  border-radius: 8px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.focus-word-count {
  font-size: 0.75rem;
  font-family: 'JetBrains Mono', monospace;
  color: var(--color-text-muted, #8896ab);
  white-space: nowrap;
}

/* ── Focus Mode Active State ────────────────────────────────────── */

.writing-app.focus-mode .writing-topbar {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-100%);
  position: absolute;
  width: 100%;
}

.writing-app.focus-mode .writing-layout {
  grid-template-columns: 1fr;
  height: 100vh;
}

.writing-app.focus-mode .outline-panel {
  display: none;
}

.writing-app.focus-mode .tools-sidebar {
  display: none;
}

.writing-app.focus-mode .editor-toolbar {
  opacity: 0;
  pointer-events: none;
  height: 0;
  padding: 0;
  overflow: hidden;
  border: none;
}

.writing-app.focus-mode .format-toolbar {
  opacity: 0;
  pointer-events: none;
  height: 0;
  padding: 0;
  overflow: hidden;
  border: none;
}

.writing-app.focus-mode .editor-area {
  padding: 3rem 6rem;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.writing-app.focus-mode .rich-editor {
  padding: 2rem 0;
  line-height: 2.2;
  font-size: 1.125rem;
}

/* Show vignette and floating toolbar when focus mode is active */
.writing-app.focus-mode .focus-vignette {
  opacity: 1;
}

.writing-app.focus-mode .focus-floating-toolbar {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

/* Typewriter scroll: keep cursor area vertically centered */
.writing-app.focus-mode .editor-area {
  scroll-padding-top: 45vh;
  scroll-padding-bottom: 45vh;
}

.writing-app.focus-mode .rich-editor {
  padding-top: 40vh;
  padding-bottom: 40vh;
}

/* Focus toggle button styling */
#focus-toggle-btn {
  font-size: 0.75rem;
  letter-spacing: 0.02em;
}

.writing-app.focus-mode #focus-toggle-btn {
  display: none;
}

/* Hide floating tools in focus mode */
.writing-app.focus-mode ~ .abm-trigger-btn,
.writing-app.focus-mode ~ .abm-panel,
.writing-app.focus-mode ~ .rte-widget,
.writing-app.focus-mode ~ .wa-toggle,
.writing-app.focus-mode ~ .wa-panel,
body.focus-mode-active .abm-trigger-btn,
body.focus-mode-active .abm-panel,
body.focus-mode-active .rte-widget,
body.focus-mode-active .wa-toggle,
body.focus-mode-active .wa-panel {
  display: none !important;
}

/* ── Writing Goals Panel ───────────────────────────────────────────── */

.goals-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.goals-title {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--color-text, #e2e8f0);
  margin: 0;
}

/* Progress ring */
.goals-progress-ring-wrap {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 0 auto 1rem;
}

.goals-progress-ring {
  width: 120px;
  height: 120px;
  transform: rotate(-90deg);
}

.goals-ring-bg {
  fill: none;
  stroke: var(--color-border, #1e293b);
  stroke-width: 8;
}

.goals-ring-fill {
  fill: none;
  stroke: var(--color-primary, #3b82f6);
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.4s ease;
}

.goals-ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.goals-ring-count {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--color-text, #e2e8f0);
  line-height: 1.2;
}

.goals-ring-of {
  font-size: 0.6875rem;
  color: var(--color-text-muted, #8896ab);
}

/* Stats row */
.goals-stats-row {
  display: flex;
  justify-content: space-around;
  margin-bottom: 1.25rem;
  padding: 0.75rem 0;
  border-top: 1px solid var(--color-border, #1e293b);
  border-bottom: 1px solid var(--color-border, #1e293b);
}

.goals-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.goals-stat-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text, #e2e8f0);
}

.goals-stat-label {
  font-size: 0.6875rem;
  color: var(--color-text-muted, #8896ab);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Streak badge */
.goals-streak-badge {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  background: var(--color-bg-secondary, #111827);
  border: 1px solid var(--color-border, #1e293b);
  transition: border-color 0.3s, box-shadow 0.3s;
}

.goals-streak-badge.active {
  border-color: #f59e0b;
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.3);
}

.goals-streak-fire {
  font-size: 0.875rem;
}

.goals-streak-count {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text, #e2e8f0);
}

/* Weekly chart */
.goals-weekly-wrap {
  margin-top: 0.25rem;
}

.goals-weekly-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-muted, #8896ab);
  margin: 0 0 0.5rem;
}

#goals-weekly-chart {
  position: relative;
}

.goals-chart-bars {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 4px;
  height: 80px;
}

.goals-bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  height: 100%;
}

.goals-bar-track {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: flex-end;
}

.goals-bar {
  width: 100%;
  min-height: 2px;
  background: var(--color-primary, #3b82f6);
  border-radius: 3px 3px 0 0;
  opacity: 0.5;
  transition: height 0.3s ease;
}

.goals-bar.met {
  background: var(--color-success, #10b981);
  opacity: 1;
}

.goals-bar.today {
  opacity: 1;
  box-shadow: 0 0 6px rgba(59, 130, 246, 0.4);
}

.goals-bar.today.met {
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.4);
}

.goals-bar-label {
  font-size: 0.625rem;
  color: var(--color-text-dim, #5a6a80);
}

.goals-chart-goal-line {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px dashed var(--color-text-dim, #5a6a80);
  pointer-events: none;
}

.goals-chart-goal-line span {
  position: absolute;
  right: 0;
  top: -14px;
  font-size: 0.5625rem;
  color: var(--color-text-dim, #5a6a80);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Word Count Goal Colors (custom properties) ──────────────────── */
:root {
  --goal-red: #ef4444;
  --goal-yellow: #f59e0b;
  --goal-green: #10b981;
  --goal-blue: #3b82f6;
}

[data-theme="light"] {
  --goal-red: #dc2626;
  --goal-yellow: #d97706;
  --goal-green: #059669;
  --goal-blue: #2563eb;
}

/* ── Outline Mini Progress Bar (clickable) ───────────────────────── */
.outline-mini-bar {
  cursor: pointer;
  transition: opacity 0.15s;
}
.outline-mini-bar:hover {
  opacity: 0.8;
  box-shadow: 0 0 0 1px var(--color-primary, #3b82f6);
  border-radius: 2px;
}

/* ── Section Goal Popover ────────────────────────────────────────── */
.goal-popover {
  background: var(--color-bg-secondary, #111827);
  border: 1px solid var(--color-border, #1e293b);
  border-radius: 8px;
  padding: 0.75rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  width: 180px;
}

[data-theme="light"] .goal-popover {
  background: #fff;
  border-color: #d1d5db;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.goal-popover-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--color-text, #e2e8f0);
  margin-bottom: 0.5rem;
}

.goal-popover-label {
  font-size: 0.6875rem;
  color: var(--color-text-muted, #8896ab);
  display: block;
  margin-bottom: 0.25rem;
}

.goal-popover-input {
  width: 100%;
  padding: 0.375rem 0.5rem;
  font-size: 0.8125rem;
  margin-bottom: 0.5rem;
}

.goal-popover-actions {
  display: flex;
  gap: 0.375rem;
}

.goal-popover-actions .btn {
  flex: 1;
  font-size: 0.6875rem;
  padding: 0.25rem 0.5rem;
}

/* ── Streak Toolbar Badge ────────────────────────────────────────── */
.streak-toolbar-badge {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  background: var(--color-bg, #0a0e17);
  border: 1px solid var(--color-border, #1e293b);
  font-size: 0.8125rem;
  cursor: default;
  transition: border-color 0.3s, box-shadow 0.3s;
}

.streak-toolbar-badge.streak-active {
  border-color: #f59e0b;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.3);
}

[data-theme="light"] .streak-toolbar-badge {
  background: #f9fafb;
  border-color: #d1d5db;
}

[data-theme="light"] .streak-toolbar-badge.streak-active {
  border-color: #d97706;
  box-shadow: 0 0 6px rgba(217, 119, 6, 0.2);
}

.streak-toolbar-fire {
  font-size: 0.875rem;
  line-height: 1;
}

.streak-toolbar-count {
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  color: var(--color-text, #e2e8f0);
  font-size: 0.75rem;
}

/* ── Goals Dashboard Modal ───────────────────────────────────────── */
.gd-top {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--color-border, #1e293b);
}

.gd-ring-wrap {
  position: relative;
  width: 100px;
  height: 100px;
  flex-shrink: 0;
}

.gd-ring {
  width: 100px;
  height: 100px;
  transform: rotate(-90deg);
}

.gd-ring-bg {
  fill: none;
  stroke: var(--color-border, #1e293b);
  stroke-width: 6;
}

.gd-ring-fill {
  fill: none;
  stroke: var(--color-primary, #3b82f6);
  stroke-width: 6;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.4s ease;
}

.gd-ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.gd-ring-pct {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--color-text, #e2e8f0);
}

.gd-ring-sub {
  font-size: 0.625rem;
  color: var(--color-text-muted, #8896ab);
}

.gd-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  flex: 1;
}

.gd-summary-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.gd-summary-val {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text, #e2e8f0);
}

.gd-summary-lbl {
  font-size: 0.6875rem;
  color: var(--color-text-muted, #8896ab);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.gd-table-header {
  display: flex;
  align-items: center;
  padding: 0.375rem 0.5rem;
  font-size: 0.6875rem;
  color: var(--color-text-dim, #5a6a80);
  border-bottom: 1px solid var(--color-border, #1e293b);
  margin-bottom: 0.25rem;
}

.gd-table {
  max-height: 300px;
  overflow-y: auto;
}

.gd-row {
  display: flex;
  align-items: center;
  padding: 0.5rem;
  border-radius: 4px;
  transition: background 0.15s;
}

.gd-row:hover {
  background: rgba(255, 255, 255, 0.03);
}

[data-theme="light"] .gd-row:hover {
  background: rgba(0, 0, 0, 0.03);
}

.gd-row-name {
  flex: 2;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text, #e2e8f0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gd-row-counts {
  flex: 1.5;
  font-size: 0.75rem;
  font-family: 'JetBrains Mono', monospace;
  color: var(--color-text-muted, #8896ab);
  text-align: center;
}

.gd-row-pct {
  flex: 0.75;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text, #e2e8f0);
  text-align: center;
}

.gd-row-bar {
  flex: 1.5;
  padding-left: 0.5rem;
}

.gd-mini-bar {
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 3px;
  overflow: hidden;
}

[data-theme="light"] .gd-mini-bar {
  background: rgba(0, 0, 0, 0.06);
}

.gd-mini-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}

/* ── Version History Browser ───────────────────────────────────────── */

.history-badge {
  display: inline-block;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  font-size: 0.625rem;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  border-radius: 100px;
  background: var(--color-primary, #3b82f6);
  color: #fff;
  margin-left: 4px;
  vertical-align: middle;
}

#panel-history {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.vh-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-border, #1e293b);
}

.vh-section-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-muted, #8896ab);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
}

.vh-timeline {
  flex: 1;
  overflow-y: auto;
}

.vh-entries {
  position: relative;
  padding-left: 16px;
}

/* Vertical timeline line */
.vh-entries::before {
  content: '';
  position: absolute;
  left: 5px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: var(--color-border, #1e293b);
  border-radius: 1px;
}

.vh-entry {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.5rem 0;
  cursor: default;
}

.vh-timeline-dot {
  position: absolute;
  left: -16px;
  top: 0.75rem;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-border, #1e293b);
  border: 2px solid var(--color-bg-secondary, #111827);
  z-index: 1;
  flex-shrink: 0;
}

.vh-dot-current {
  background: var(--color-primary, #3b82f6);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.vh-entry-body {
  flex: 1;
  background: var(--color-bg, #0a0e17);
  border: 1px solid var(--color-border, #1e293b);
  border-radius: 6px;
  padding: 0.5rem 0.625rem;
  transition: border-color 0.15s;
}

.vh-entry-current .vh-entry-body {
  border-left: 3px solid var(--color-primary, #3b82f6);
}

.vh-entry-body:hover {
  border-color: var(--color-primary, #3b82f6);
}

.vh-entry-top {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.vh-version-num {
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--color-text, #e2e8f0);
}

.vh-current-badge {
  font-size: 0.625rem;
  background: rgba(59, 130, 246, 0.15);
  color: var(--color-primary, #3b82f6);
  padding: 0.0625rem 0.375rem;
  border-radius: 100px;
  font-weight: 600;
}

.vh-autosave-badge {
  font-size: 0.5625rem;
  background: rgba(16, 185, 129, 0.12);
  color: var(--color-success, #10b981);
  padding: 0.0625rem 0.3125rem;
  border-radius: 100px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.vh-entry-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.125rem;
}

.vh-wc {
  font-size: 0.6875rem;
  color: var(--color-text-muted, #8896ab);
  font-family: 'JetBrains Mono', monospace;
}

.vh-wc-diff {
  font-size: 0.6875rem;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
}

.vh-diff-pos { color: var(--color-success, #10b981); }
.vh-diff-neg { color: var(--color-danger, #ef4444); }
.vh-diff-initial { color: var(--color-primary, #3b82f6); }

.vh-entry-time {
  font-size: 0.625rem;
  color: var(--color-text-dim, #5a6a80);
  margin-top: 0.125rem;
}

.vh-entry-actions {
  display: flex;
  gap: 0.375rem;
  margin-top: 0.375rem;
}

.vh-entry-actions .btn {
  font-size: 0.6875rem;
  padding: 0.125rem 0.5rem;
}

.vh-compare-check {
  width: 14px;
  height: 14px;
  cursor: pointer;
  accent-color: var(--color-primary, #3b82f6);
}

.vh-compare-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem;
  margin-top: 0.5rem;
  background: var(--color-bg, #0a0e17);
  border: 1px solid var(--color-border, #1e293b);
  border-radius: 6px;
  font-size: 0.75rem;
  color: var(--color-text-muted, #8896ab);
}

/* ── Diff Overlay ── */

.vh-diff-overlay,
.vh-preview-overlay {
  position: absolute;
  inset: 0;
  background: var(--color-bg-secondary, #111827);
  z-index: 10;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.vh-diff-header,
.vh-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--color-border, #1e293b);
  flex-shrink: 0;
  gap: 0.5rem;
}

.vh-diff-title,
.vh-preview-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text, #e2e8f0);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.vh-diff-stats {
  font-size: 0.75rem;
  font-weight: 400;
  margin-left: 0.5rem;
}

.vh-preview-actions {
  display: flex;
  gap: 0.375rem;
  flex-shrink: 0;
}

.vh-preview-actions .btn {
  font-size: 0.6875rem;
}

.vh-diff-body,
.vh-preview-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  font-size: 0.875rem;
  line-height: 1.7;
  color: var(--color-text, #e2e8f0);
}

.vh-diff-content {
  white-space: pre-wrap;
  word-wrap: break-word;
}

.vh-diff-added {
  background: rgba(16, 185, 129, 0.18);
  color: var(--color-success, #10b981);
  border-radius: 2px;
  padding: 0 1px;
}

.vh-diff-removed {
  background: rgba(239, 68, 68, 0.18);
  color: var(--color-danger, #ef4444);
  text-decoration: line-through;
  border-radius: 2px;
  padding: 0 1px;
}

/* Light theme overrides */
[data-theme="light"] .vh-diff-added {
  background: rgba(16, 185, 129, 0.15);
  color: #047857;
}

[data-theme="light"] .vh-diff-removed {
  background: rgba(239, 68, 68, 0.12);
  color: #b91c1c;
}

[data-theme="light"] .vh-timeline-dot {
  border-color: var(--color-bg-secondary, #f8fafc);
}

[data-theme="light"] .vh-dot-current {
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

[data-theme="light"] .vh-current-badge {
  background: rgba(59, 130, 246, 0.1);
}

[data-theme="light"] .vh-autosave-badge {
  background: rgba(16, 185, 129, 0.08);
}

/* ── Table / Figure Manager ───────────────────────────────────────── */

/* Toolbar buttons */
.fmt-figtable-btn {
  color: var(--color-accent, #f59e0b) !important;
  font-size: 0.75rem !important;
  white-space: nowrap;
}

/* Block container (table or figure) */
.ft-block {
  margin: 1.25rem 0;
  border: 1px solid var(--color-border, #1e293b);
  border-radius: 8px;
  overflow: hidden;
  background: var(--color-bg-secondary, #111827);
  position: relative;
}

[data-theme="light"] .ft-block {
  background: var(--color-bg-secondary, #f8fafc);
  border-color: var(--color-border, #e2e8f0);
}

/* Table styles */
.ft-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.ft-table th,
.ft-table td {
  border: 1px solid var(--color-border, #1e293b);
  padding: 0.5rem 0.75rem;
  text-align: left;
  min-width: 60px;
}

.ft-table th {
  background: var(--color-bg-tertiary, #1e293b);
  font-weight: 600;
  color: var(--color-text, #e2e8f0);
}

.ft-table td {
  color: var(--color-text, #e2e8f0);
}

[data-theme="light"] .ft-table th {
  background: var(--color-bg-tertiary, #e2e8f0);
  color: var(--color-text, #1e293b);
}

[data-theme="light"] .ft-table td {
  color: var(--color-text, #1e293b);
  border-color: var(--color-border, #e2e8f0);
}

/* Figure styles */
.ft-figure-img {
  display: block;
  max-width: 100%;
  max-height: 400px;
  margin: 0 auto;
  object-fit: contain;
}

.ft-figure-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 200px;
  background: var(--color-bg-tertiary, #1e293b);
  color: var(--color-text-muted, #8896ab);
  font-size: 0.9375rem;
  gap: 0.375rem;
}

[data-theme="light"] .ft-figure-placeholder {
  background: var(--color-bg-tertiary, #e2e8f0);
  color: var(--color-text-muted, #64748b);
}

/* Caption bar */
.ft-caption {
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  font-style: italic;
  color: var(--color-text-muted, #8896ab);
  background: var(--color-bg-tertiary, #1e293b);
  border-top: 1px solid var(--color-border, #1e293b);
}

[data-theme="light"] .ft-caption {
  background: var(--color-bg-tertiary, #f1f5f9);
  color: var(--color-text-muted, #64748b);
  border-color: var(--color-border, #e2e8f0);
}

.ft-caption-text {
  font-weight: 500;
}

/* Cross-reference links */
.ft-crossref {
  color: var(--color-primary, #6366f1);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  font-weight: 500;
  white-space: nowrap;
}

.ft-crossref:hover {
  text-decoration-style: solid;
}

/* Cross-reference picker list */
.ft-crossref-list {
  max-height: 300px;
  overflow-y: auto;
}

/* Manager panel */
.ft-manager {
  min-height: 100px;
}

.ft-manager-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.ft-mgr-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--color-border, #1e293b);
  border-radius: 6px;
  background: var(--color-bg-secondary, #111827);
}

[data-theme="light"] .ft-mgr-item {
  background: var(--color-bg-secondary, #f8fafc);
  border-color: var(--color-border, #e2e8f0);
}

.ft-mgr-preview {
  flex-shrink: 0;
  width: 64px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  overflow: hidden;
  background: var(--color-bg-tertiary, #1e293b);
  font-size: 0.6875rem;
  color: var(--color-text-muted, #8896ab);
}

[data-theme="light"] .ft-mgr-preview {
  background: var(--color-bg-tertiary, #e2e8f0);
}

.ft-mgr-preview-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ft-mgr-preview-table {
  font-size: 0.6875rem;
  text-align: center;
  line-height: 1.3;
}

.ft-mgr-preview-placeholder {
  font-size: 0.625rem;
  opacity: 0.6;
}

.ft-mgr-info {
  flex: 1;
  min-width: 0;
}

.ft-mgr-label {
  font-weight: 600;
  font-size: 0.8125rem;
  margin-bottom: 0.25rem;
  color: var(--color-text, #e2e8f0);
}

.ft-mgr-caption-input {
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
}

.ft-mgr-actions {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex-shrink: 0;
}

.ft-mgr-actions .btn {
  padding: 0.125rem 0.375rem;
  font-size: 0.75rem;
  min-width: 28px;
}

/* ── Responsive ────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .writing-layout {
    grid-template-columns: 200px 1fr;
  }
  .tools-sidebar { display: none; }
  /* Comments panel as full-width overlay on tablet/mobile */
  .tools-sidebar.comments-overlay-active {
    display: flex;
    position: fixed; inset: 52px 0 0 0;
    z-index: 80; width: 100%;
    border-left: none;
  }
}

@media (max-width: 768px) {
  .writing-layout {
    grid-template-columns: 1fr;
  }
  .outline-panel { display: none; }
  .editor-area { padding: 1rem; }
  .topbar-center { display: none; }
  .writing-topbar { padding: 0 0.75rem; gap: 0.5rem; }
  .topbar-left { gap: 0.5rem; }
  .topbar-nav { display: none; }
  .collab-avatars { display: none; }
  .export-modal-grid { grid-template-columns: 1fr; }
  /* Comments panel as full-width overlay on mobile */
  .tools-sidebar.comments-overlay-active {
    display: flex;
    position: fixed; inset: 52px 0 0 0;
    z-index: 80; width: 100%;
    border-left: none;
  }
  .comment-card.comment-reply { margin-left: 0.75rem; }
  /* History panel responsive */
  .vh-diff-overlay,
  .vh-preview-overlay {
    position: fixed;
    inset: 52px 0 0 0;
    z-index: 90;
  }
  .vh-preview-actions { flex-direction: column; }
  .vh-preview-actions .btn { width: 100%; }
  /* Table/figure manager: full-width on mobile */
  .ft-mgr-item {
    flex-wrap: wrap;
  }
  .ft-mgr-info {
    width: 100%;
    order: 2;
  }
  .ft-mgr-actions {
    flex-direction: row;
    order: 3;
    width: 100%;
    justify-content: flex-end;
  }
  .ft-block .ft-table {
    font-size: 0.75rem;
  }
  .ft-block .ft-table th,
  .ft-block .ft-table td {
    padding: 0.375rem 0.5rem;
  }
}

/* ── Footnotes & Endnotes ────────────────────────────────────────── */

/* Toolbar buttons */
.fmt-footnote-btn {
  color: var(--color-primary, #6366f1) !important;
  font-size: 0.75rem !important;
  white-space: nowrap;
}
.fmt-footnote-mode-btn {
  font-size: 0.6875rem !important;
  font-weight: 700;
  border-radius: 3px;
  padding: 0.125rem 0.375rem !important;
  min-width: unset;
}
.fmt-footnote-mode-btn.active {
  background: var(--color-primary, #6366f1);
  color: #fff !important;
}

/* Inline footnote marker in the editor */
.fn-marker {
  display: inline;
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--color-primary, #6366f1);
  background: var(--color-bg-tertiary, #1e293b);
  border: 1px solid var(--color-border, #334155);
  border-radius: 3px;
  padding: 0 0.2rem;
  cursor: pointer;
  vertical-align: super;
  line-height: 1;
  user-select: none;
  position: relative;
  transition: background 0.15s, color 0.15s;
}
.fn-marker:hover {
  background: var(--color-primary, #6366f1);
  color: #fff;
}

/* Hover tooltip */
.fn-tooltip {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-bg-secondary, #111827);
  color: var(--color-text, #e2e8f0);
  border: 1px solid var(--color-border, #334155);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 400;
  white-space: normal;
  max-width: 280px;
  min-width: 120px;
  z-index: 200;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  pointer-events: none;
  line-height: 1.4;
}
.fn-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--color-border, #334155);
}

/* Footnotes area below editor */
.footnotes-area {
  border-top: 1px solid var(--color-border, #1e293b);
  padding: 0.75rem 1.25rem;
  max-height: 220px;
  overflow-y: auto;
  background: var(--color-bg-primary, #0f172a);
  flex-shrink: 0;
}
.footnotes-area-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}
.footnotes-area-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text, #e2e8f0);
  margin: 0;
}
.footnotes-area-count {
  font-size: 0.75rem;
  color: var(--color-text-muted, #8896ab);
}
.footnotes-area-list {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}
.fn-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.375rem 0.5rem;
  border-radius: 4px;
  background: var(--color-bg-secondary, #111827);
  border: 1px solid var(--color-border, #1e293b);
  font-size: 0.8125rem;
  transition: background 0.15s;
}
.fn-item:hover {
  background: var(--color-bg-tertiary, #1e293b);
}
.fn-item-number {
  font-weight: 700;
  color: var(--color-primary, #6366f1);
  min-width: 1.5rem;
  flex-shrink: 0;
  padding-top: 0.125rem;
}
.fn-item-text {
  flex: 1;
  color: var(--color-text, #e2e8f0);
  line-height: 1.4;
  min-height: 1.4em;
  outline: none;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: inherit;
  padding: 0;
  cursor: text;
}
.fn-item-text:focus {
  background: var(--color-bg-primary, #0f172a);
  border-radius: 3px;
  padding: 0.125rem 0.25rem;
}
.fn-item-delete {
  background: none;
  border: none;
  color: var(--color-text-dim, #64748b);
  cursor: pointer;
  font-size: 0.875rem;
  padding: 0 0.25rem;
  flex-shrink: 0;
  line-height: 1;
  transition: color 0.15s;
}
.fn-item-delete:hover {
  color: var(--color-danger, #ef4444);
}

/* Endnotes panel */
.endnotes-panel {
  border-top: 2px solid var(--color-primary, #6366f1);
  padding: 1rem 1.25rem;
  max-height: 320px;
  overflow-y: auto;
  background: var(--color-bg-primary, #0f172a);
  flex-shrink: 0;
}
.endnotes-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.endnotes-panel-title {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--color-text, #e2e8f0);
  margin: 0;
}
.endnotes-section-group {
  margin-bottom: 0.75rem;
}
.endnotes-section-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-muted, #8896ab);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.375rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--color-border, #1e293b);
}
.endnotes-note {
  display: flex;
  gap: 0.5rem;
  padding: 0.25rem 0;
  font-size: 0.8125rem;
  color: var(--color-text, #e2e8f0);
}
.endnotes-note-num {
  font-weight: 700;
  color: var(--color-primary, #6366f1);
  min-width: 2.5rem;
  flex-shrink: 0;
}

/* Footnote input modal inline */
.fn-input-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1.25rem;
  background: var(--color-bg-secondary, #111827);
  border-top: 1px solid var(--color-border, #1e293b);
  flex-shrink: 0;
}
.fn-input-bar label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-muted, #8896ab);
  white-space: nowrap;
}
.fn-input-bar input {
  flex: 1;
  background: var(--color-bg-primary, #0f172a);
  border: 1px solid var(--color-border, #334155);
  border-radius: 4px;
  color: var(--color-text, #e2e8f0);
  font-size: 0.8125rem;
  padding: 0.375rem 0.5rem;
  font-family: inherit;
}
.fn-input-bar input:focus {
  outline: none;
  border-color: var(--color-primary, #6366f1);
}
.fn-input-bar .btn {
  flex-shrink: 0;
}

/* Light theme overrides */
[data-theme="light"] .fn-marker {
  background: #e0e7ff;
  border-color: #a5b4fc;
  color: #4338ca;
}
[data-theme="light"] .fn-marker:hover {
  background: #6366f1;
  color: #fff;
}
[data-theme="light"] .fn-tooltip {
  background: #ffffff;
  color: #1e293b;
  border-color: #cbd5e1;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
[data-theme="light"] .fn-tooltip::after {
  border-top-color: #cbd5e1;
}
[data-theme="light"] .fn-item {
  background: #f8fafc;
  border-color: #e2e8f0;
}
[data-theme="light"] .fn-item:hover {
  background: #f1f5f9;
}
[data-theme="light"] .fn-item-text:focus {
  background: #ffffff;
}
[data-theme="light"] .footnotes-area,
[data-theme="light"] .endnotes-panel {
  background: #ffffff;
  border-top-color: #e2e8f0;
}
[data-theme="light"] .fn-input-bar {
  background: #f8fafc;
  border-top-color: #e2e8f0;
}
[data-theme="light"] .fn-input-bar input {
  background: #ffffff;
  border-color: #cbd5e1;
  color: #1e293b;
}

/* Responsive */
@media (max-width: 768px) {
  .footnotes-area {
    max-height: 160px;
    padding: 0.5rem 0.75rem;
  }
  .endnotes-panel {
    max-height: 240px;
    padding: 0.75rem;
  }
  .fn-tooltip {
    max-width: 200px;
    font-size: 0.75rem;
  }
}

/* ── Glossary & Abbreviations ─────────────────────────────────────── */

/* Badge on toolbar button */
.fmt-glossary-btn {
  position: relative;
}
.glossary-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--color-primary, #6366f1);
  color: #fff;
  font-size: 0.625rem;
  font-weight: 700;
  line-height: 1;
  margin-left: 4px;
  vertical-align: middle;
}

/* Slide-in side panel */
.glossary-panel {
  position: fixed;
  top: 52px;
  right: 0;
  bottom: 0;
  width: 400px;
  max-width: 100vw;
  background: var(--color-bg, #0a0e17);
  border-left: 1px solid var(--color-border, #1e293b);
  z-index: 85;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.3);
  animation: glossarySlideIn 0.2s ease-out;
}
@keyframes glossarySlideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

.glossary-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border, #1e293b);
  flex-shrink: 0;
}
.glossary-panel-title {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--color-text, #e2e8f0);
  margin: 0;
}
.glossary-panel-actions {
  display: flex;
  gap: 0.5rem;
}

/* Search */
.glossary-panel-search {
  padding: 0.625rem 1rem;
  border-bottom: 1px solid var(--color-border, #1e293b);
  flex-shrink: 0;
}
.glossary-search-input {
  width: 100%;
  font-size: 0.8125rem;
}

/* Add term form */
.glossary-add-form {
  padding: 0.625rem 1rem;
  border-bottom: 1px solid var(--color-border, #1e293b);
  flex-shrink: 0;
}
.glossary-form-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.glossary-form-row:last-child {
  margin-bottom: 0;
}
.glossary-input-abbr {
  width: 35%;
  font-size: 0.8125rem;
}
.glossary-input-full {
  flex: 1;
  font-size: 0.8125rem;
}
.glossary-input-def {
  flex: 1;
  font-size: 0.8125rem;
}

/* Import/Export bar */
.glossary-io-bar {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--color-border, #1e293b);
  flex-shrink: 0;
}

/* Term list */
.glossary-term-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}
.glossary-empty {
  text-align: center;
  color: var(--color-text-dim, #5a6a80);
  font-size: 0.8125rem;
  padding: 2rem 1rem;
}

/* Individual term card */
.glossary-term-card {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  padding: 0.625rem 1rem;
  border-bottom: 1px solid var(--color-border, #1e293b);
  transition: background 0.15s;
}
.glossary-term-card:hover {
  background: var(--color-bg-secondary, #111827);
}
.glossary-term-info {
  flex: 1;
  min-width: 0;
}
.glossary-term-abbr {
  font-weight: 700;
  font-size: 0.875rem;
  color: var(--color-primary, #6366f1);
  font-family: 'JetBrains Mono', monospace;
}
.glossary-term-full {
  font-size: 0.8125rem;
  color: var(--color-text, #e2e8f0);
  margin-top: 0.125rem;
}
.glossary-term-def {
  font-size: 0.75rem;
  color: var(--color-text-dim, #5a6a80);
  margin-top: 0.25rem;
  font-style: italic;
}
.glossary-term-actions {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}
.glossary-term-actions button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0.25rem 0.375rem;
  border-radius: 4px;
  color: var(--color-text-muted, #8896ab);
  transition: background 0.15s, color 0.15s;
}
.glossary-term-actions button:hover {
  background: var(--color-bg-tertiary, #1e293b);
  color: var(--color-text, #e2e8f0);
}
.glossary-term-actions .glossary-delete-btn:hover {
  color: var(--color-error, #ef4444);
}

/* Abbreviation highlight in editor */
abbr.glossary-abbr {
  text-decoration: underline dotted var(--color-primary, #6366f1);
  text-underline-offset: 3px;
  cursor: help;
  position: relative;
}

/* Glossary tooltip on hover */
.glossary-tooltip {
  position: fixed;
  z-index: 200;
  background: var(--color-bg-secondary, #111827);
  border: 1px solid var(--color-border, #1e293b);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  max-width: 320px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  font-size: 0.8125rem;
  pointer-events: none;
  animation: glossaryTipFadeIn 0.15s ease-out;
}
@keyframes glossaryTipFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.glossary-tooltip-full {
  font-weight: 600;
  color: var(--color-text, #e2e8f0);
}
.glossary-tooltip-def {
  color: var(--color-text-dim, #5a6a80);
  margin-top: 0.25rem;
  font-style: italic;
}

/* Generated glossary section preview */
.glossary-generated-section {
  padding: 1rem;
  background: var(--color-bg-secondary, #111827);
  border-radius: 8px;
  max-height: 400px;
  overflow-y: auto;
  font-size: 0.8125rem;
  line-height: 1.7;
}
.glossary-generated-section dt {
  font-weight: 700;
  color: var(--color-primary, #6366f1);
  font-family: 'JetBrains Mono', monospace;
}
.glossary-generated-section dd {
  margin: 0 0 0.75rem 0;
  color: var(--color-text, #e2e8f0);
}

/* Light theme overrides */
[data-theme="light"] .glossary-panel {
  background: #ffffff;
  border-left-color: #e2e8f0;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.08);
}
[data-theme="light"] .glossary-panel-header,
[data-theme="light"] .glossary-panel-search,
[data-theme="light"] .glossary-add-form,
[data-theme="light"] .glossary-io-bar,
[data-theme="light"] .glossary-term-card {
  border-color: #e2e8f0;
}
[data-theme="light"] .glossary-term-card:hover {
  background: #f8fafc;
}
[data-theme="light"] .glossary-term-actions button:hover {
  background: #f1f5f9;
  color: #1e293b;
}
[data-theme="light"] .glossary-tooltip {
  background: #ffffff;
  border-color: #e2e8f0;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}
[data-theme="light"] .glossary-generated-section {
  background: #f8fafc;
}

/* Responsive: full-width on mobile */
@media (max-width: 768px) {
  .glossary-panel {
    width: 100vw;
    max-width: 100vw;
  }
  .glossary-form-row {
    flex-wrap: wrap;
  }
  .glossary-input-abbr {
    width: 100%;
  }
}

/* ── Citation Preview Tooltips ─────────────────────────────────────── */

/* Inline citation markers that have a matching source */
.citation-linked {
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-color: var(--color-primary, #6366f1);
  text-underline-offset: 2px;
  cursor: pointer;
}

/* The tooltip card */
.cite-tooltip {
  position: fixed;
  z-index: var(--z-tooltip);
  max-width: 380px;
  min-width: 240px;
  background: var(--color-bg-secondary, #1e293b);
  border: 1px solid var(--color-border, #334155);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35), 0 2px 8px rgba(0, 0, 0, 0.2);
  padding: 0.875rem 1rem;
  pointer-events: auto;
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms ease, visibility 200ms ease;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--color-text, #e2e8f0);
}
.cite-tooltip.visible {
  opacity: 1;
  visibility: visible;
}
.cite-tooltip.pinned {
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.25), 0 2px 8px rgba(0, 0, 0, 0.2);
  border-color: var(--color-primary, #6366f1);
}

/* Tooltip inner elements */
.cite-tooltip-authors {
  font-weight: 700;
  margin-bottom: 0.25rem;
  color: var(--color-text, #e2e8f0);
}
.cite-tooltip-title {
  font-style: italic;
  margin-bottom: 0.25rem;
  color: var(--color-text, #e2e8f0);
}
.cite-tooltip-journal {
  font-size: 0.75rem;
  color: var(--color-text-muted, #8896ab);
  margin-bottom: 0.25rem;
}
.cite-tooltip-year {
  font-size: 0.75rem;
  color: var(--color-text-muted, #8896ab);
  margin-bottom: 0.25rem;
}
.cite-tooltip-doi {
  font-size: 0.75rem;
  margin-bottom: 0.25rem;
}
.cite-tooltip-doi a {
  color: var(--color-primary, #6366f1);
  text-decoration: none;
}
.cite-tooltip-doi a:hover {
  text-decoration: underline;
}
.cite-tooltip-abstract {
  font-size: 0.6875rem;
  color: var(--color-text-dim, #64748b);
  margin-top: 0.375rem;
  border-top: 1px solid var(--color-border, #334155);
  padding-top: 0.375rem;
}
.cite-tooltip-notfound {
  color: var(--color-text-muted, #8896ab);
  font-style: italic;
}
.cite-tooltip-notfound a {
  color: var(--color-primary, #6366f1);
  text-decoration: none;
  margin-left: 0.5rem;
  font-style: normal;
  font-weight: 500;
}
.cite-tooltip-notfound a:hover {
  text-decoration: underline;
}

/* Light theme overrides for citation tooltip */
[data-theme="light"] .cite-tooltip {
  background: #ffffff;
  color: #1e293b;
  border-color: #cbd5e1;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1), 0 2px 8px rgba(0, 0, 0, 0.06);
}
[data-theme="light"] .cite-tooltip.pinned {
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.15), 0 2px 8px rgba(0, 0, 0, 0.06);
  border-color: var(--color-primary, #6366f1);
}
[data-theme="light"] .cite-tooltip-authors {
  color: #1e293b;
}
[data-theme="light"] .cite-tooltip-title {
  color: #334155;
}
[data-theme="light"] .cite-tooltip-journal,
[data-theme="light"] .cite-tooltip-year {
  color: #64748b;
}
[data-theme="light"] .cite-tooltip-abstract {
  color: #94a3b8;
  border-top-color: #e2e8f0;
}
[data-theme="light"] .cite-tooltip-notfound {
  color: #94a3b8;
}
[data-theme="light"] .citation-linked {
  text-decoration-color: var(--color-primary, #6366f1);
}

/* Responsive: tooltips full-width fixed at bottom on mobile */
@media (max-width: 768px) {
  .cite-tooltip {
    position: fixed;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    max-width: 100%;
    width: 100%;
    border-radius: 12px 12px 0 0;
    border-bottom: none;
  }
}

/* ── Smart Suggestions Panel ──────────────────────────────────────── */

.suggestions-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 16px; height: 16px; padding: 0 4px;
  background: var(--color-accent, #f59e0b); color: #000;
  border-radius: 99px; font-size: 0.5625rem; font-weight: 700;
  margin-left: 3px; vertical-align: middle; line-height: 1;
}
[data-theme="light"] .suggestions-badge { background: #d97706; color: #fff; }

/* Score ring */
.sug-score-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0.75rem auto 0.5rem;
  width: 100px;
  height: 100px;
}
.sug-score-ring {
  width: 100px;
  height: 100px;
  transform: rotate(-90deg);
}
.sug-ring-bg {
  fill: none;
  stroke: var(--color-border, #1e293b);
  stroke-width: 8;
}
.sug-ring-fill {
  fill: none;
  stroke: var(--color-success, #10b981);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 326.73;
  stroke-dashoffset: 326.73;
  transition: stroke-dashoffset 0.6s ease, stroke 0.3s ease;
}
.sug-ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.sug-ring-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--color-text, #e2e8f0);
  line-height: 1;
}
.sug-ring-caption {
  font-size: 0.625rem;
  font-weight: 600;
  color: var(--color-text-muted, #8896ab);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 2px;
}

.sug-reanalyze-btn {
  display: block;
  width: 100%;
  margin-bottom: 0.75rem;
}

/* Category cards */
.sug-category {
  border: 1px solid var(--color-border, #1e293b);
  border-radius: 8px;
  margin-bottom: 0.5rem;
  overflow: hidden;
}
.sug-category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  background: var(--color-bg-secondary, #111827);
  transition: background 0.15s;
  user-select: none;
}
.sug-category-header:hover {
  background: var(--color-bg-elevated, #1a2236);
}
.sug-category-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.sug-category-icon {
  font-size: 0.875rem;
}
.sug-category-name {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text, #e2e8f0);
}
.sug-category-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 99px; font-size: 0.625rem; font-weight: 700;
  line-height: 1;
}
.sug-count-red { background: var(--color-danger, #ef4444); color: #fff; }
.sug-count-yellow { background: var(--color-warning, #f59e0b); color: #000; }
.sug-count-green { background: var(--color-success, #10b981); color: #fff; }
.sug-count-blue { background: var(--color-primary, #3b82f6); color: #fff; }
.sug-count-gray { background: var(--color-text-dim, #5a6a80); color: #fff; }

.sug-category-chevron {
  font-size: 0.625rem;
  color: var(--color-text-dim, #5a6a80);
  transition: transform 0.2s;
}
.sug-category.open .sug-category-chevron {
  transform: rotate(90deg);
}

.sug-category-body {
  display: none;
  padding: 0.25rem 0;
}
.sug-category.open .sug-category-body {
  display: block;
}

/* Individual suggestion item */
.sug-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--color-border, #1e293b);
  font-size: 0.75rem;
}
.sug-item-top {
  display: flex;
  align-items: flex-start;
  gap: 0.375rem;
}
.sug-severity-icon {
  flex-shrink: 0;
  margin-top: 1px;
}
.sug-flagged-text {
  color: var(--color-text, #e2e8f0);
  line-height: 1.4;
  word-break: break-word;
}
.sug-flagged-text mark {
  background: rgba(245, 158, 11, 0.25);
  color: var(--color-warning, #f59e0b);
  border-radius: 2px;
  padding: 0 2px;
}
.sug-flagged-text mark.sug-mark-red {
  background: rgba(239, 68, 68, 0.2);
  color: var(--color-danger, #ef4444);
}
.sug-suggestion {
  color: var(--color-text-dim, #5a6a80);
  font-style: italic;
  line-height: 1.4;
  padding-left: 1.125rem;
}
.sug-item-actions {
  display: flex;
  gap: 0.375rem;
  padding-left: 1.125rem;
  margin-top: 0.125rem;
}
.sug-item-actions .btn {
  padding: 0.125rem 0.5rem;
  font-size: 0.625rem;
}

/* Readability gauge */
.sug-readability-gauge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--color-border, #1e293b);
}
.sug-gauge-bar {
  flex: 1;
  height: 6px;
  background: var(--color-border, #1e293b);
  border-radius: 3px;
  overflow: hidden;
}
.sug-gauge-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease, background 0.3s ease;
}
.sug-gauge-label {
  font-size: 0.6875rem;
  font-weight: 600;
  white-space: nowrap;
}

/* Light theme overrides */
[data-theme="light"] .sug-category-header {
  background: #f8fafc;
}
[data-theme="light"] .sug-category-header:hover {
  background: #f1f5f9;
}
[data-theme="light"] .sug-flagged-text mark {
  background: rgba(245, 158, 11, 0.15);
  color: #92400e;
}
[data-theme="light"] .sug-flagged-text mark.sug-mark-red {
  background: rgba(239, 68, 68, 0.12);
  color: #991b1b;
}

/* Responsive */
@media (max-width: 768px) {
  .sug-score-wrap { width: 80px; height: 80px; }
  .sug-score-ring { width: 80px; height: 80px; }
  .sug-ring-value { font-size: 1.25rem; }
}

/* ── Citation Preview Tooltips ──────────────────────────────────────── */
.cite-tooltip {
  position: fixed;
  z-index: 6000;
  width: 320px;
  max-width: 90vw;
  background: var(--color-bg-card, #1a2233);
  border: 1px solid var(--color-border, #2a3a52);
  border-radius: var(--radius-md, 10px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  padding: 1rem;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  pointer-events: none;
}

.cite-tooltip.cite-tooltip-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.cite-tooltip-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text, #e2e8f0);
  margin-bottom: 0.25rem;
  line-height: 1.35;
}

.cite-tooltip-authors {
  font-size: 0.75rem;
  color: var(--color-primary, #3b82f6);
  margin-bottom: 0.125rem;
}

.cite-tooltip-meta {
  font-size: 0.6875rem;
  color: var(--color-text-dim, #5a6a80);
  margin-bottom: 0.5rem;
}

.cite-tooltip-abstract {
  font-size: 0.75rem;
  color: var(--color-text-muted, #8896ab);
  line-height: 1.5;
  margin-bottom: 0.625rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cite-tooltip-actions {
  display: flex;
  gap: 0.5rem;
  border-top: 1px solid var(--color-border, #2a3a52);
  padding-top: 0.5rem;
}

.cite-tooltip-btn {
  flex: 1;
  padding: 0.375rem 0.5rem;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.2);
  border-radius: var(--radius-sm, 6px);
  color: var(--color-primary, #3b82f6);
  font-size: 0.6875rem;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: all 0.12s ease;
}

.cite-tooltip-btn:hover {
  background: rgba(59, 130, 246, 0.18);
  border-color: rgba(59, 130, 246, 0.35);
}

.cite-tooltip-arrow {
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--color-bg-card, #1a2233);
  border: 1px solid var(--color-border, #2a3a52);
  transform: rotate(45deg);
}

.cite-tooltip-arrow.arrow-top {
  bottom: -6px;
  left: 50%;
  margin-left: -5px;
  border-top: none;
  border-left: none;
}

.cite-tooltip-arrow.arrow-bottom {
  top: -6px;
  left: 50%;
  margin-left: -5px;
  border-bottom: none;
  border-right: none;
}

[data-theme="light"] .cite-tooltip {
  background: #fff;
  border-color: #e2e8f0;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .cite-tooltip-arrow {
  background: #fff;
  border-color: #e2e8f0;
}

[data-theme="light"] .cite-tooltip-actions {
  border-top-color: #e2e8f0;
}

@media (max-width: 768px) {
  .cite-tooltip { width: 280px; }
}

/* ── Smart Suggestions Sidebar ──────────────────────────────────────── */
.suggestions-toggle {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 4500;
  width: 36px;
  height: 36px;
  background: var(--color-bg-card, #1a2233);
  border: 1px solid var(--color-border, #2a3a52);
  border-right: none;
  border-radius: 8px 0 0 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  color: var(--color-text-muted, #8896ab);
  transition: all 0.2s ease;
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.15);
}

.suggestions-toggle:hover {
  background: rgba(59, 130, 246, 0.1);
  color: var(--color-primary, #3b82f6);
  width: 42px;
}

.suggestions-toggle .suggestion-count {
  position: absolute;
  top: -4px;
  left: -4px;
  min-width: 16px;
  height: 16px;
  background: var(--color-accent, #06d6a0);
  color: #000;
  font-size: 0.5625rem;
  font-weight: 700;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

.suggestions-sidebar {
  position: fixed;
  right: -340px;
  top: 0;
  bottom: 0;
  width: 320px;
  background: var(--color-bg-secondary, #111827);
  border-left: 1px solid var(--color-border, #2a3a52);
  z-index: 4400;
  display: flex;
  flex-direction: column;
  transition: right 0.25s ease;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.2);
}

.suggestions-sidebar.suggestions-open {
  right: 0;
}

.suggestions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border, #2a3a52);
  flex-shrink: 0;
}

.suggestions-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--color-text, #e2e8f0);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.suggestions-close {
  background: none;
  border: none;
  color: var(--color-text-muted, #8896ab);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
  transition: color 0.15s;
}

.suggestions-close:hover {
  color: var(--color-text, #e2e8f0);
}

.suggestions-filters {
  display: flex;
  gap: 0.375rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--color-border, #2a3a52);
  flex-shrink: 0;
  overflow-x: auto;
}

.suggestions-filter {
  padding: 0.25rem 0.625rem;
  background: none;
  border: 1px solid var(--color-border, #2a3a52);
  border-radius: 999px;
  color: var(--color-text-muted, #8896ab);
  font-size: 0.6875rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.12s ease;
}

.suggestions-filter:hover {
  border-color: var(--color-primary, #3b82f6);
  color: var(--color-primary, #3b82f6);
}

.suggestions-filter.filter-active {
  background: rgba(59, 130, 246, 0.12);
  border-color: var(--color-primary, #3b82f6);
  color: var(--color-primary, #3b82f6);
}

.suggestions-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
}

.suggestion-card {
  background: var(--color-bg-card, #1a2233);
  border: 1px solid var(--color-border, #2a3a52);
  border-radius: var(--radius-md, 10px);
  padding: 0.875rem;
  margin-bottom: 0.625rem;
  transition: border-color 0.15s ease;
}

.suggestion-card:hover {
  border-color: rgba(59, 130, 246, 0.3);
}

.suggestion-card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.375rem;
}

.suggestion-icon {
  font-size: 0.875rem;
  flex-shrink: 0;
}

.suggestion-badge {
  font-size: 0.5625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.125rem 0.375rem;
  border-radius: 3px;
  flex-shrink: 0;
}

.suggestion-badge.badge-clarity {
  background: rgba(59, 130, 246, 0.12);
  color: #60a5fa;
}

.suggestion-badge.badge-style {
  background: rgba(168, 85, 247, 0.12);
  color: #c084fc;
}

.suggestion-badge.badge-structure {
  background: rgba(6, 214, 160, 0.12);
  color: #06d6a0;
}

.suggestion-badge.badge-citations {
  background: rgba(251, 191, 36, 0.12);
  color: #fbbf24;
}

.suggestion-desc {
  font-size: 0.8125rem;
  color: var(--color-text-muted, #8896ab);
  line-height: 1.5;
  margin-bottom: 0.625rem;
}

.suggestion-actions {
  display: flex;
  gap: 0.375rem;
}

.suggestion-apply {
  flex: 1;
  padding: 0.3125rem 0.5rem;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.2);
  border-radius: var(--radius-sm, 6px);
  color: var(--color-primary, #3b82f6);
  font-size: 0.6875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s ease;
}

.suggestion-apply:hover {
  background: rgba(59, 130, 246, 0.18);
}

.suggestion-dismiss {
  padding: 0.3125rem 0.5rem;
  background: none;
  border: 1px solid var(--color-border, #2a3a52);
  border-radius: var(--radius-sm, 6px);
  color: var(--color-text-dim, #5a6a80);
  font-size: 0.6875rem;
  cursor: pointer;
  transition: all 0.12s ease;
}

.suggestion-dismiss:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--color-text-muted, #8896ab);
}

.suggestions-empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--color-text-dim, #5a6a80);
  font-size: 0.8125rem;
}

.suggestions-empty-icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  opacity: 0.5;
}

[data-theme="light"] .suggestions-sidebar {
  background: #f8fafc;
  border-left-color: #e2e8f0;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .suggestions-toggle {
  background: #fff;
  border-color: #e2e8f0;
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .suggestion-card {
  background: #fff;
  border-color: #e2e8f0;
}

@media (max-width: 768px) {
  .suggestions-sidebar {
    width: 100%;
    right: -100%;
  }
  .suggestions-toggle {
    top: auto;
    bottom: 5rem;
    transform: none;
  }
}

/* ── Drag and Drop Section Reorder ──────────────────────────────────── */
.section-item[draggable="true"] {
  cursor: grab;
  user-select: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.section-item[draggable="true"]:active {
  cursor: grabbing;
}

.section-item.dragging {
  opacity: 0.4;
  transform: scale(0.97);
  background: rgba(59, 130, 246, 0.06);
  border: 1px dashed var(--color-primary, #3b82f6);
  border-radius: var(--radius-sm, 6px);
}

.section-item.drag-over-above {
  border-top: 2px solid var(--color-primary, #3b82f6);
}

.section-item.drag-over-below {
  border-bottom: 2px solid var(--color-primary, #3b82f6);
}

.drop-indicator {
  height: 2px;
  background: var(--color-primary, #3b82f6);
  border-radius: 1px;
  margin: 0 0.5rem;
  transition: opacity 0.1s ease;
  box-shadow: 0 0 6px rgba(59, 130, 246, 0.4);
}

.section-item .drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  color: var(--color-text-dim, #5a6a80);
  cursor: grab;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s ease;
  font-size: 0.875rem;
  margin-right: 0.25rem;
}

.section-item:hover .drag-handle {
  opacity: 1;
}

.section-item .drag-handle:active {
  cursor: grabbing;
  color: var(--color-primary, #3b82f6);
}

[data-theme="light"] .section-item.dragging {
  background: rgba(59, 130, 246, 0.04);
  border-color: #93c5fd;
}

[data-theme="light"] .drop-indicator {
  box-shadow: 0 0 6px rgba(59, 130, 246, 0.25);
}

@media (max-width: 768px) {
  .section-item .drag-handle {
    opacity: 1;
  }
}

/* ── Auto-Save & Version Snapshots ──────────────────────────────────── */
.autosave-indicator {
  position: fixed;
  bottom: 1rem;
  left: 1rem;
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  background: var(--color-bg-card, #1a2233);
  border: 1px solid var(--color-border, #2a3a52);
  border-radius: 999px;
  font-size: 0.6875rem;
  color: var(--color-text-dim, #5a6a80);
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 100;
  pointer-events: none;
}

.autosave-indicator.autosave-visible {
  opacity: 1;
}

.autosave-indicator.autosave-saving {
  color: var(--color-primary, #3b82f6);
}

.autosave-indicator.autosave-saved {
  color: var(--color-accent, #06d6a0);
}

.autosave-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.autosave-saving .autosave-dot {
  animation: autosavePulse 0.6s ease infinite;
}

@keyframes autosavePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Snapshot Manager Modal */
.snapshot-manager {
  max-height: 60vh;
  overflow-y: auto;
}

.snapshot-create-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--color-border, #2a3a52);
}

.snapshot-create-input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  background: var(--color-bg-secondary, #111827);
  border: 1px solid var(--color-border, #2a3a52);
  border-radius: var(--radius-sm, 6px);
  color: var(--color-text, #e2e8f0);
  font-size: 0.8125rem;
  outline: none;
}

.snapshot-create-input:focus {
  border-color: var(--color-primary, #3b82f6);
}

.snapshot-create-btn {
  padding: 0.5rem 0.875rem;
  background: var(--color-primary, #3b82f6);
  border: none;
  border-radius: var(--radius-sm, 6px);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s;
}

.snapshot-create-btn:hover {
  background: #2563eb;
}

.snapshot-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.snapshot-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--color-bg-secondary, #111827);
  border: 1px solid var(--color-border, #2a3a52);
  border-radius: var(--radius-sm, 6px);
  transition: border-color 0.12s;
}

.snapshot-item:hover {
  border-color: rgba(59, 130, 246, 0.3);
}

.snapshot-item.snapshot-auto {
  border-left: 3px solid var(--color-text-dim, #5a6a80);
}

.snapshot-item.snapshot-manual {
  border-left: 3px solid var(--color-accent, #06d6a0);
}

.snapshot-info {
  flex: 1;
  min-width: 0;
}

.snapshot-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text, #e2e8f0);
  margin-bottom: 0.125rem;
}

.snapshot-meta {
  font-size: 0.6875rem;
  color: var(--color-text-dim, #5a6a80);
}

.snapshot-actions {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

.snapshot-btn {
  padding: 0.25rem 0.5rem;
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(59, 130, 246, 0.15);
  border-radius: 4px;
  color: var(--color-primary, #3b82f6);
  font-size: 0.625rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
}

.snapshot-btn:hover {
  background: rgba(59, 130, 246, 0.15);
}

.snapshot-btn.snapshot-delete {
  color: var(--color-danger, #ef4444);
  background: rgba(239, 68, 68, 0.06);
  border-color: rgba(239, 68, 68, 0.12);
}

.snapshot-btn.snapshot-delete:hover {
  background: rgba(239, 68, 68, 0.12);
}

/* Diff view */
.snapshot-diff {
  max-height: 300px;
  overflow-y: auto;
  padding: 0.75rem;
  background: var(--color-bg-secondary, #111827);
  border: 1px solid var(--color-border, #2a3a52);
  border-radius: var(--radius-sm, 6px);
  font-size: 0.8125rem;
  line-height: 1.6;
  margin-top: 0.75rem;
}

.snapshot-diff ins {
  background: rgba(6, 214, 160, 0.15);
  color: var(--color-accent, #06d6a0);
  text-decoration: none;
  padding: 0.0625rem 0.125rem;
  border-radius: 2px;
}

.snapshot-diff del {
  background: rgba(239, 68, 68, 0.15);
  color: var(--color-danger, #ef4444);
  text-decoration: line-through;
  padding: 0.0625rem 0.125rem;
  border-radius: 2px;
}

.snapshot-empty {
  text-align: center;
  padding: 1.5rem;
  color: var(--color-text-dim, #5a6a80);
  font-size: 0.8125rem;
}

[data-theme="light"] .autosave-indicator {
  background: #fff;
  border-color: #e2e8f0;
}

[data-theme="light"] .snapshot-item {
  background: #f8fafc;
  border-color: #e2e8f0;
}

[data-theme="light"] .snapshot-diff {
  background: #f8fafc;
  border-color: #e2e8f0;
}

@media (max-width: 768px) {
  .autosave-indicator {
    bottom: 4rem;
    left: 0.75rem;
    font-size: 0.625rem;
  }
}

/* ── Print Styles (Writing Studio) ──────────────────────────────────── */
@media print {
  .writing-topbar,
  .writing-sidebar,
  .sidebar-tabs,
  .editor-toolbar,
  .focus-vignette,
  .glossary-panel,
  .cite-tooltip,
  .suggestions-sidebar,
  .suggestions-toggle,
  .autosave-indicator,
  .word-goal-bar,
  .comments-panel,
  .version-panel,
  .footnote-panel,
  .table-figure-panel {
    display: none !important;
  }

  .writing-main {
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: none !important;
  }

  .editor-area,
  .section-editor {
    border: none !important;
    padding: 0 !important;
    min-height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }

  .section-editor [contenteditable] {
    border: none !important;
    outline: none !important;
    padding: 0 !important;
  }

  /* Show all sections, not just active */
  .section-panel {
    display: block !important;
    page-break-before: auto;
  }

  .section-panel h2 {
    page-break-after: avoid;
  }
}

/* ── Inline Collaboration Comments ──────────────────────────────────── */
.comment-highlight {
  background: rgba(251, 191, 36, 0.2);
  border-bottom: 2px solid rgba(251, 191, 36, 0.5);
  cursor: pointer;
  transition: background 0.12s;
  border-radius: 2px;
}

.comment-highlight:hover {
  background: rgba(251, 191, 36, 0.35);
}

.comment-highlight.comment-resolved {
  background: rgba(100, 116, 139, 0.1);
  border-bottom-color: rgba(100, 116, 139, 0.3);
}

.comment-highlight.comment-active {
  background: rgba(251, 191, 36, 0.4);
  outline: 2px solid rgba(251, 191, 36, 0.6);
  outline-offset: 1px;
}

/* Comments Panel */
.comments-inline-panel {
  position: fixed;
  right: -360px;
  top: 56px;
  bottom: 0;
  width: 340px;
  background: var(--color-bg-secondary, #111827);
  border-left: 1px solid var(--color-border, #2a3a52);
  z-index: 4500;
  display: flex;
  flex-direction: column;
  transition: right 0.25s ease;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.2);
}

.comments-inline-panel.comments-panel-open {
  right: 0;
}

.comments-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border, #2a3a52);
  flex-shrink: 0;
}

.comments-panel-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--color-text, #e2e8f0);
}

.comments-panel-close {
  background: none;
  border: none;
  color: var(--color-text-muted, #8896ab);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
}

.comments-filter-tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.625rem 1.25rem;
  border-bottom: 1px solid var(--color-border, #2a3a52);
  flex-shrink: 0;
}

.comments-filter-tab {
  padding: 0.25rem 0.625rem;
  background: none;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--color-text-muted, #8896ab);
  font-size: 0.6875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
}

.comments-filter-tab:hover {
  color: var(--color-text, #e2e8f0);
}

.comments-filter-tab.active {
  background: rgba(59, 130, 246, 0.1);
  border-color: rgba(59, 130, 246, 0.2);
  color: var(--color-primary, #3b82f6);
}

.comments-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
}

.comment-card {
  background: var(--color-bg-card, #1a2233);
  border: 1px solid var(--color-border, #2a3a52);
  border-radius: var(--radius-md, 10px);
  padding: 0.875rem;
  margin-bottom: 0.625rem;
  transition: border-color 0.12s;
}

.comment-card:hover {
  border-color: rgba(251, 191, 36, 0.3);
}

.comment-card.comment-card-resolved {
  opacity: 0.6;
  border-left: 3px solid var(--color-text-dim, #5a6a80);
}

.comment-card.comment-card-active {
  border-color: rgba(251, 191, 36, 0.5);
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.1);
}

.comment-quoted-text {
  font-size: 0.75rem;
  font-style: italic;
  color: var(--color-text-dim, #5a6a80);
  padding: 0.375rem 0.5rem;
  background: rgba(255, 255, 255, 0.02);
  border-left: 2px solid var(--color-warning, #fbbf24);
  border-radius: 2px;
  margin-bottom: 0.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.comment-text {
  font-size: 0.8125rem;
  color: var(--color-text, #e2e8f0);
  line-height: 1.5;
  margin-bottom: 0.375rem;
}

.comment-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.625rem;
  color: var(--color-text-dim, #5a6a80);
  margin-bottom: 0.5rem;
}

.comment-actions {
  display: flex;
  gap: 0.25rem;
}

.comment-action-btn {
  padding: 0.1875rem 0.375rem;
  background: none;
  border: 1px solid var(--color-border, #2a3a52);
  border-radius: 4px;
  color: var(--color-text-dim, #5a6a80);
  font-size: 0.5625rem;
  cursor: pointer;
  transition: all 0.12s;
}

.comment-action-btn:hover {
  border-color: var(--color-primary, #3b82f6);
  color: var(--color-primary, #3b82f6);
}

.comment-action-btn.resolve-btn {
  color: var(--color-accent, #06d6a0);
  border-color: rgba(6, 214, 160, 0.3);
}

.comment-action-btn.delete-btn:hover {
  border-color: var(--color-danger, #ef4444);
  color: var(--color-danger, #ef4444);
}

/* Replies */
.comment-replies {
  margin-top: 0.5rem;
  padding-left: 0.75rem;
  border-left: 1px solid var(--color-border, #2a3a52);
}

.comment-reply {
  padding: 0.375rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

.comment-reply:last-child {
  border-bottom: none;
}

.comment-reply-text {
  font-size: 0.75rem;
  color: var(--color-text-muted, #8896ab);
  line-height: 1.4;
}

.comment-reply-meta {
  font-size: 0.5625rem;
  color: var(--color-text-dim, #5a6a80);
  margin-top: 0.125rem;
}

.comment-reply-input {
  display: flex;
  gap: 0.375rem;
  margin-top: 0.375rem;
}

.comment-reply-input input {
  flex: 1;
  padding: 0.3125rem 0.5rem;
  background: var(--color-bg-secondary, #111827);
  border: 1px solid var(--color-border, #2a3a52);
  border-radius: 4px;
  color: var(--color-text, #e2e8f0);
  font-size: 0.6875rem;
  outline: none;
}

.comment-reply-input input:focus {
  border-color: var(--color-primary, #3b82f6);
}

.comment-reply-input button {
  padding: 0.3125rem 0.5rem;
  background: var(--color-primary, #3b82f6);
  border: none;
  border-radius: 4px;
  color: #fff;
  font-size: 0.625rem;
  font-weight: 600;
  cursor: pointer;
}

/* Comment count badge */
.comment-toolbar-badge {
  min-width: 16px;
  height: 16px;
  background: var(--color-warning, #fbbf24);
  color: #000;
  font-size: 0.5625rem;
  font-weight: 700;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  margin-left: 0.25rem;
}

.comments-empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--color-text-dim, #5a6a80);
  font-size: 0.8125rem;
}

[data-theme="light"] .comments-inline-panel {
  background: #f8fafc;
  border-left-color: #e2e8f0;
}

[data-theme="light"] .comment-card {
  background: #fff;
  border-color: #e2e8f0;
}

[data-theme="light"] .comment-highlight {
  background: rgba(251, 191, 36, 0.15);
}

@media (max-width: 768px) {
  .comments-inline-panel {
    width: 100%;
    right: -100%;
  }
}

/* ── Enhanced Focus Mode ───────────────────────────────────────── */
.focus-enhanced-active .writing-sidebar,
.focus-enhanced-active .writing-topbar,
.focus-enhanced-active .sources-panel,
.focus-enhanced-active .suggestions-sidebar,
.focus-enhanced-active .comments-inline-panel {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.focus-enhanced-active .writing-main {
  max-width: 720px;
  margin: 0 auto;
  transition: max-width 0.4s ease;
}

.focus-timer {
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-primary, #3b82f6);
  padding: 0 0.5rem;
  min-width: 48px;
  text-align: center;
}

.focus-typewriter-btn.active,
.focus-ambient-btn.active,
.focus-goal-btn.active {
  background: var(--color-primary, #3b82f6);
  color: #fff;
  border-radius: 6px;
}

.focus-goal-progress {
  height: 3px;
  background: var(--color-border, #2a3a52);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 0.25rem;
}
.focus-goal-progress-fill {
  height: 100%;
  background: var(--color-primary, #3b82f6);
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* Typewriter mode — dim non-active paragraphs */
.focus-enhanced-active.typewriter-active [contenteditable] p {
  opacity: 0.4;
  transition: opacity 0.3s ease;
}
.focus-enhanced-active.typewriter-active [contenteditable] p:focus-within,
.focus-enhanced-active.typewriter-active [contenteditable] p.typewriter-active {
  opacity: 1;
}

@media (max-width: 768px) {
  .focus-timer { font-size: 0.6875rem; min-width: 40px; }
}

/* ── Citation Style Switcher ───────────────────────────────────── */
.citation-style-switcher {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  margin-left: 0.75rem;
}
.citation-style-label {
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--color-text-muted, #8896ab);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.citation-style-select {
  background: var(--color-bg, #0a0e17);
  border: 1px solid var(--color-border, #2a3a52);
  border-radius: 6px;
  color: var(--color-text, #e2e8f0);
  font-family: inherit;
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  transition: border-color 0.15s;
}
.citation-style-select:focus { outline: none; border-color: var(--color-primary, #3b82f6); }
.citation-preview-btn {
  background: none;
  border: 1px solid var(--color-border, #2a3a52);
  border-radius: 6px;
  padding: 0.2rem 0.4rem;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.citation-preview-btn:hover { border-color: var(--color-primary, #3b82f6); background: rgba(59,130,246,0.08); }

/* Reference list modal */
.ref-list-style-badge {
  display: inline-block;
  background: rgba(59, 130, 246, 0.12);
  color: var(--color-primary, #3b82f6);
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  margin-bottom: 0.75rem;
}
.ref-list-entries { margin-bottom: 0.75rem; }
.ref-list-item {
  font-size: 0.8125rem;
  color: var(--color-text, #e2e8f0);
  line-height: 1.55;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--color-border, #2a3a52);
}
.ref-list-item:last-child { border-bottom: none; }
.ref-list-item em { font-style: italic; }
.ref-list-count {
  font-size: 0.6875rem;
  color: var(--color-text-dim, #5a6a80);
  text-align: right;
}

[data-theme="light"] .citation-style-select { background: #f1f5f9; }

@media (max-width: 768px) {
  .citation-style-switcher { margin-left: 0; margin-top: 0.5rem; }
  .citation-style-label { display: none; }
}

/* ── Version Diff Viewer ───────────────────────────────────────── */
.diff-viewer-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: transparent;
  color: var(--color-text-muted, #94a3b8);
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.375rem;
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.diff-viewer-btn:hover {
  color: var(--color-primary, #6366f1);
  border-color: var(--color-primary, #6366f1);
}
.diff-btn-label { font-weight: 600; }
.diff-controls {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.diff-select-group {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
  min-width: 140px;
}
.diff-select-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--color-text-muted, #94a3b8);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.diff-select {
  background: var(--color-bg, #0f172a);
  color: var(--color-text, #e2e8f0);
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.375rem;
  padding: 0.4rem 0.5rem;
  font-size: 0.8rem;
}
.diff-arrow {
  color: var(--color-text-muted, #64748b);
  font-size: 1.1rem;
  padding-bottom: 0.3rem;
}
.diff-stats {
  display: flex;
  gap: 1rem;
  margin-bottom: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
}
.diff-stat-added { color: #22c55e; }
.diff-stat-removed { color: #ef4444; }
.diff-stat-unchanged { color: var(--color-text-muted, #64748b); }
.diff-panes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  background: var(--color-border, #334155);
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.5rem;
  overflow: hidden;
  max-height: 420px;
}
.diff-pane {
  background: var(--color-bg, #0f172a);
  overflow-y: auto;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.75rem;
  line-height: 1.6;
}
.diff-line {
  display: flex;
  align-items: baseline;
  padding: 0 0.5rem;
  min-height: 1.5em;
}
.diff-line-same { background: transparent; }
.diff-line-added { background: rgba(34, 197, 94, 0.12); }
.diff-line-removed { background: rgba(239, 68, 68, 0.12); }
.diff-line-empty { background: var(--color-surface, #1e293b); opacity: 0.5; }
.diff-line-num {
  display: inline-block;
  width: 2.5em;
  text-align: right;
  color: var(--color-text-muted, #475569);
  user-select: none;
  flex-shrink: 0;
  padding-right: 0.4rem;
  font-size: 0.65rem;
}
.diff-prefix {
  display: inline-block;
  width: 1em;
  text-align: center;
  flex-shrink: 0;
  font-weight: 700;
  color: var(--color-text-muted, #64748b);
}
.diff-line-added .diff-prefix { color: #22c55e; }
.diff-line-removed .diff-prefix { color: #ef4444; }
.diff-text {
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--color-text, #e2e8f0);
}

[data-theme="light"] .diff-select { background: #f8fafc; color: #1e293b; }
[data-theme="light"] .diff-pane { background: #ffffff; }
[data-theme="light"] .diff-line-added { background: rgba(34, 197, 94, 0.08); }
[data-theme="light"] .diff-line-removed { background: rgba(239, 68, 68, 0.08); }
[data-theme="light"] .diff-line-empty { background: #f1f5f9; }

@media (max-width: 768px) {
  .diff-panes { grid-template-columns: 1fr; max-height: 300px; }
  .diff-controls { flex-direction: column; }
  .diff-arrow { transform: rotate(90deg); align-self: center; }
}

/* ── Outline Navigator ─────────────────────────────────────────── */
.outline-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: transparent;
  color: var(--color-text-muted, #94a3b8);
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.375rem;
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.outline-toggle-btn:hover,
.outline-btn-active {
  color: var(--color-primary, #6366f1);
  border-color: var(--color-primary, #6366f1);
}
.outline-btn-label { font-weight: 600; }

.outline-nav-panel {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 280px;
  background: var(--color-surface, #1e293b);
  border-right: 1px solid var(--color-border, #334155);
  z-index: 90;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  box-shadow: 4px 0 20px rgba(0,0,0,0.2);
}
.outline-nav-panel.on-panel-open {
  transform: translateX(0);
}
.on-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem 0.5rem;
  border-bottom: 1px solid var(--color-border, #334155);
}
.on-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-text, #e2e8f0);
  margin: 0;
}
.on-close-btn {
  background: transparent;
  border: none;
  color: var(--color-text-muted, #94a3b8);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 0.25rem;
  line-height: 1;
}
.on-close-btn:hover { color: var(--color-text, #e2e8f0); background: rgba(255,255,255,0.05); }
.on-stats {
  display: flex;
  gap: 1rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--color-border, #334155);
}
.on-stat {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--color-text-muted, #64748b);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.on-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}
.on-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 1rem;
  cursor: pointer;
  transition: background 0.1s;
  border-left: 2px solid transparent;
}
.on-item:hover { background: rgba(99, 102, 241, 0.06); }
.on-item-active {
  background: rgba(99, 102, 241, 0.1);
  border-left-color: var(--color-primary, #6366f1);
}
.on-indent-0 { padding-left: 1rem; }
.on-indent-1 { padding-left: 1.75rem; }
.on-indent-2 { padding-left: 2.5rem; }
.on-indent-3 { padding-left: 3.25rem; }
.on-indent-4 { padding-left: 4rem; }
.on-indent-5 { padding-left: 4.75rem; }
.on-drag-handle {
  color: var(--color-text-muted, #475569);
  cursor: grab;
  font-size: 1rem;
  user-select: none;
  flex-shrink: 0;
  opacity: 0.4;
  transition: opacity 0.15s;
}
.on-item:hover .on-drag-handle { opacity: 1; }
.on-item-text {
  flex: 1;
  font-size: 0.8rem;
  color: var(--color-text, #e2e8f0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.on-level-1 { font-weight: 700; font-size: 0.85rem; }
.on-level-2 { font-weight: 600; }
.on-level-3 { font-weight: 500; color: var(--color-text-muted, #94a3b8); }
.on-level-4, .on-level-5, .on-level-6 {
  font-weight: 400;
  color: var(--color-text-muted, #64748b);
  font-size: 0.75rem;
}
.on-item-words {
  font-size: 0.65rem;
  color: var(--color-text-muted, #64748b);
  background: var(--color-bg, #0f172a);
  padding: 0.1rem 0.35rem;
  border-radius: 0.25rem;
  flex-shrink: 0;
  font-weight: 600;
}
.on-item-dragging { opacity: 0.4; }
.on-item-dragover {
  border-top: 2px solid var(--color-primary, #6366f1);
  background: rgba(99, 102, 241, 0.08);
}
.on-heading-flash {
  animation: onFlash 1.5s ease;
}
@keyframes onFlash {
  0%, 100% { background: transparent; }
  20% { background: rgba(99, 102, 241, 0.15); }
}

[data-theme="light"] .outline-nav-panel {
  background: var(--color-surface, #ffffff);
  border-right-color: var(--color-border, #e2e8f0);
  box-shadow: 4px 0 20px rgba(0,0,0,0.06);
}
[data-theme="light"] .on-item-words { background: #f1f5f9; }
[data-theme="light"] .on-item:hover { background: rgba(99, 102, 241, 0.05); }

@media (max-width: 768px) {
  .outline-nav-panel { width: 100%; }
  .outline-btn-label { display: none; }
}

/* ── Word Goal & Session Timer ─────────────────────────────────── */
.wg-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: transparent;
  color: var(--color-text-muted, #94a3b8);
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.375rem;
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.wg-toggle-btn:hover {
  color: var(--color-primary, #6366f1);
  border-color: var(--color-primary, #6366f1);
}
.wg-btn-label { font-weight: 600; }

/* Setup modal */
.wg-setup { display: flex; flex-direction: column; gap: 1rem; }
.wg-setup-field { display: flex; flex-direction: column; gap: 0.3rem; }
.wg-setup-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-muted, #94a3b8);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.wg-input {
  background: var(--color-bg, #0f172a);
  color: var(--color-text, #e2e8f0);
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.375rem;
  padding: 0.45rem 0.6rem;
  font-size: 0.85rem;
}
.wg-preset-row { display: flex; gap: 0.4rem; margin-bottom: 0.3rem; }
.wg-preset {
  background: var(--color-surface, #1e293b);
  color: var(--color-text-muted, #94a3b8);
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.375rem;
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.wg-preset:hover, .wg-preset-active {
  background: var(--color-primary, #6366f1);
  color: #fff;
  border-color: var(--color-primary, #6366f1);
}

/* Floating widget */
.wg-widget {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--color-surface, #1e293b);
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.75rem;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  z-index: 85;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  animation: wgSlideIn 0.3s ease;
}
@keyframes wgSlideIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.wg-widget-complete {
  border-color: var(--color-success, #22c55e);
  box-shadow: 0 0 20px rgba(34, 197, 94, 0.2);
}
.wg-ring-wrap {
  position: relative;
  width: 76px;
  height: 76px;
  flex-shrink: 0;
}
.wg-ring-progress {
  transition: stroke-dashoffset 0.5s ease;
}
.wg-ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.wg-ring-pct {
  font-size: 1rem;
  font-weight: 800;
  color: var(--color-text, #e2e8f0);
}
.wg-info { flex: 1; min-width: 0; }
.wg-words-written {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--color-text, #e2e8f0);
}
.wg-remaining {
  font-size: 0.7rem;
  color: var(--color-text-muted, #64748b);
  margin-bottom: 0.25rem;
}
.wg-timer { display: flex; align-items: baseline; gap: 0.35rem; }
.wg-timer-display {
  font-size: 1.1rem;
  font-weight: 700;
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--color-text, #e2e8f0);
}
.wg-timer-label {
  font-size: 0.6rem;
  color: var(--color-text-muted, #64748b);
  text-transform: uppercase;
}
.wg-controls { display: flex; flex-direction: column; gap: 0.3rem; }
.wg-play-btn, .wg-reset-btn {
  background: transparent;
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.375rem;
  color: var(--color-text-muted, #94a3b8);
  width: 2rem;
  height: 2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  transition: all 0.15s;
}
.wg-play-btn:hover {
  color: var(--color-primary, #6366f1);
  border-color: var(--color-primary, #6366f1);
}
.wg-reset-btn:hover {
  color: var(--color-danger, #ef4444);
  border-color: var(--color-danger, #ef4444);
}

[data-theme="light"] .wg-widget {
  background: #ffffff;
  border-color: #e2e8f0;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}
[data-theme="light"] .wg-input { background: #f8fafc; color: #1e293b; }
[data-theme="light"] .wg-preset { background: #f1f5f9; }

@media (max-width: 640px) {
  .wg-widget {
    left: 0.5rem;
    right: 0.5rem;
    bottom: 0.5rem;
    padding: 0.5rem;
  }
  .wg-ring-wrap { width: 56px; height: 56px; }
  .wg-ring-wrap svg { width: 56px; height: 56px; }
  .wg-btn-label { display: none; }
}

/* ── Markdown / Rich Formatting Toolbar ────────────────────────── */
.md-toolbar {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.4rem 0.6rem;
  background: var(--color-surface, #1e293b);
  border: 1px solid var(--color-border, #334155);
  border-bottom: none;
  border-radius: 0.5rem 0.5rem 0 0;
  flex-wrap: wrap;
}
.md-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 0.3rem;
  color: var(--color-text-muted, #94a3b8);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.12s;
  padding: 0;
}
.md-btn:hover {
  background: rgba(99, 102, 241, 0.1);
  color: var(--color-text, #e2e8f0);
  border-color: var(--color-border, #334155);
}
.md-btn:active {
  background: rgba(99, 102, 241, 0.2);
}
.md-btn strong { font-weight: 800; font-size: 0.85rem; }
.md-btn em { font-style: italic; font-size: 0.85rem; }
.md-btn u { text-decoration: underline; font-size: 0.85rem; }
.md-btn s { text-decoration: line-through; font-size: 0.85rem; }
.md-btn svg { width: 14px; height: 14px; }
.md-sep {
  width: 1px;
  height: 1.25rem;
  background: var(--color-border, #334155);
  margin: 0 0.25rem;
  flex-shrink: 0;
}

/* Link/Image insert forms */
.md-link-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.md-form-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--color-text-muted, #94a3b8);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.md-form-input {
  background: var(--color-bg, #0f172a);
  color: var(--color-text, #e2e8f0);
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.375rem;
  padding: 0.45rem 0.6rem;
  font-size: 0.85rem;
}

[data-theme="light"] .md-toolbar {
  background: var(--color-surface, #f8fafc);
  border-color: var(--color-border, #e2e8f0);
}
[data-theme="light"] .md-btn:hover {
  background: rgba(99, 102, 241, 0.06);
}
[data-theme="light"] .md-sep { background: #e2e8f0; }
[data-theme="light"] .md-form-input { background: #f8fafc; color: #1e293b; }

@media (max-width: 640px) {
  .md-toolbar { padding: 0.25rem 0.4rem; gap: 0.1rem; }
  .md-btn { width: 1.75rem; height: 1.75rem; font-size: 0.7rem; }
}

/* ── Table of Contents Generator ───────────────────────────────── */
.toc-gen-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: transparent;
  color: var(--color-text-muted, #94a3b8);
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.375rem;
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.toc-gen-btn:hover {
  color: var(--color-primary, #6366f1);
  border-color: var(--color-primary, #6366f1);
}
.toc-btn-label { font-weight: 600; }

/* TOC Preview Modal */
.toc-preview {
  background: var(--color-bg, #0f172a);
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.5rem;
  padding: 1.25rem 1.5rem;
  max-height: 400px;
  overflow-y: auto;
  font-family: 'Times New Roman', 'Georgia', serif;
}
.toc-preview-title {
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  color: var(--color-text, #e2e8f0);
  margin-bottom: 0.5rem;
}
.toc-preview-rule {
  height: 2px;
  background: var(--color-border, #334155);
  margin-bottom: 0.75rem;
}
.toc-entry {
  display: flex;
  align-items: baseline;
  padding: 0.2rem 0;
  cursor: pointer;
  transition: color 0.1s;
}
.toc-entry:hover { color: var(--color-primary, #6366f1); }
.toc-entry-level-0 { padding-left: 0; }
.toc-entry-level-1 { padding-left: 1.25rem; }
.toc-entry-level-2 { padding-left: 2.5rem; }
.toc-entry-level-3 { padding-left: 3.75rem; }
.toc-entry-level-4 { padding-left: 5rem; }
.toc-entry-text {
  flex-shrink: 0;
  color: var(--color-text, #e2e8f0);
  font-size: 0.85rem;
}
.toc-text-level-1 { font-weight: 700; font-size: 0.9rem; }
.toc-text-level-2 { font-weight: 600; }
.toc-text-level-3 { font-weight: 500; color: var(--color-text-muted, #94a3b8); }
.toc-text-level-4, .toc-text-level-5, .toc-text-level-6 {
  font-weight: 400; color: var(--color-text-muted, #64748b); font-size: 0.8rem;
}
.toc-dots {
  flex: 1;
  border-bottom: 1px dotted var(--color-border, #475569);
  margin: 0 0.4rem;
  min-width: 1rem;
  align-self: center;
}
.toc-entry-page {
  flex-shrink: 0;
  font-size: 0.8rem;
  color: var(--color-text-muted, #64748b);
  font-variant-numeric: tabular-nums;
}
.toc-actions-row {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}
.toc-option {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: var(--color-text-muted, #94a3b8);
  cursor: pointer;
}
.toc-option input[type="number"] {
  background: var(--color-bg, #0f172a);
  color: var(--color-text, #e2e8f0);
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.25rem;
  padding: 0.15rem 0.3rem;
  font-size: 0.75rem;
}

/* Inserted TOC in editor */
.generated-toc {
  background: var(--color-surface, #1e293b);
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.5rem;
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}
.generated-toc h2 {
  font-size: 1rem;
  margin: 0 0 0.5rem;
}
.generated-toc-item { padding: 0.15rem 0; }
.generated-toc-item a {
  color: var(--color-primary, #6366f1);
  text-decoration: none;
  font-size: 0.85rem;
}
.generated-toc-item a:hover { text-decoration: underline; }
.generated-toc-level-2 { padding-left: 1.25rem; }
.generated-toc-level-3 { padding-left: 2.5rem; }
.generated-toc-level-4 { padding-left: 3.75rem; }

[data-theme="light"] .toc-preview { background: #f8fafc; border-color: #e2e8f0; }
[data-theme="light"] .generated-toc { background: #ffffff; border-color: #e2e8f0; }
[data-theme="light"] .toc-option input[type="number"] { background: #f8fafc; color: #1e293b; }

@media (max-width: 640px) {
  .toc-preview { padding: 0.75rem 1rem; }
  .toc-actions-row { flex-direction: column; gap: 0.5rem; }
  .toc-btn-label { display: none; }
}

/* ── Distraction-Free Mode ────────────────────────────────────── */
.df-enter-btn {
  position: fixed;
  bottom: 5.5rem;
  right: 1.25rem;
  z-index: 90;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--color-border, #334155);
  background: var(--color-surface, #1e293b);
  color: var(--color-text-secondary, #94a3b8);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.df-enter-btn:hover {
  background: var(--color-primary, #6366f1);
  color: #fff;
  transform: scale(1.1);
}

body.df-active { overflow: hidden !important; }

.df-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-tooltip);
  background: var(--color-bg, #0f172a);
  display: flex;
  flex-direction: column;
  animation: dfFadeIn 0.3s ease;
}
.df-overlay.df-exit-anim {
  animation: dfFadeOut 0.3s ease forwards;
}
@keyframes dfFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes dfFadeOut { from { opacity: 1; } to { opacity: 0; } }

.df-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1.5rem;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(99, 102, 241, 0.15);
  transition: opacity 0.5s, transform 0.5s;
  flex-shrink: 0;
  z-index: var(--z-max);
}
.df-toolbar-hidden {
  opacity: 0;
  transform: translateY(-100%);
  pointer-events: none;
}
.df-toolbar-left,
.df-toolbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.df-word-count {
  font-size: 0.8rem;
  color: var(--color-text-secondary, #94a3b8);
  font-variant-numeric: tabular-nums;
}
.df-time {
  font-size: 0.8rem;
  color: var(--color-text-muted, #64748b);
}
.df-opt-btn {
  background: transparent;
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.375rem;
  color: var(--color-text-secondary, #94a3b8);
  padding: 0.3rem 0.5rem;
  cursor: pointer;
  transition: all 0.15s;
}
.df-opt-btn:hover { border-color: var(--color-primary, #6366f1); color: var(--color-primary, #6366f1); }
.df-opt-active { background: var(--color-primary, #6366f1); color: #fff; border-color: var(--color-primary, #6366f1); }
.df-ambient-select {
  background: var(--color-surface, #1e293b);
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.375rem;
  color: var(--color-text, #e2e8f0);
  padding: 0.25rem 0.4rem;
  font-size: 0.8rem;
  cursor: pointer;
}
.df-exit-btn {
  background: transparent;
  border: 1px solid rgba(239,68,68,0.4);
  border-radius: 0.375rem;
  color: #ef4444;
  padding: 0.25rem 0.6rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s;
}
.df-exit-btn:hover { background: #ef4444; color: #fff; }

.df-editor-wrap {
  flex: 1;
  overflow-y: auto;
  display: flex;
  justify-content: center;
  padding: 3rem 1rem;
}
.df-editor {
  max-width: 720px;
  width: 100%;
  min-height: 60vh;
  color: var(--color-text, #e2e8f0);
  font-family: 'Georgia', 'Times New Roman', serif;
  font-size: 1.15rem;
  line-height: 1.9;
  outline: none;
  caret-color: var(--color-primary, #6366f1);
}
.df-editor:empty::before {
  content: 'Start writing…';
  color: var(--color-text-muted, #64748b);
  font-style: italic;
}
.df-editor p { margin: 0 0 1rem; }
.df-editor h1, .df-editor h2, .df-editor h3 {
  font-family: inherit;
  margin: 1.5rem 0 0.75rem;
}

[data-theme="light"] .df-overlay { background: #fefefe; }
[data-theme="light"] .df-toolbar { background: rgba(248,250,252,0.9); border-color: #e2e8f0; }
[data-theme="light"] .df-editor { color: #1e293b; }
[data-theme="light"] .df-enter-btn { background: #fff; border-color: #e2e8f0; color: #64748b; }
[data-theme="light"] .df-ambient-select { background: #f8fafc; color: #1e293b; border-color: #e2e8f0; }

@media (max-width: 640px) {
  .df-editor-wrap { padding: 1.5rem 0.75rem; }
  .df-editor { font-size: 1rem; line-height: 1.75; }
  .df-toolbar { padding: 0.4rem 0.75rem; }
  .df-toolbar-left { gap: 0.5rem; }
  .df-toolbar-right { gap: 0.5rem; }
}

/* ── Footnote Manager ─────────────────────────────────────────── */
.fn-insert-btn,
.fn-panel-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--color-border, #334155);
  background: var(--color-surface, #1e293b);
  color: var(--color-text-secondary, #94a3b8);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}
.fn-insert-btn:hover,
.fn-panel-btn:hover {
  background: var(--color-primary, #6366f1);
  color: #fff;
  border-color: var(--color-primary, #6366f1);
}

.fn-ref {
  color: var(--color-primary, #6366f1);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.75em;
  vertical-align: super;
  transition: color 0.15s;
}
.fn-ref:hover { color: var(--color-primary-light, #818cf8); text-decoration: underline; }

.fn-tooltip {
  position: absolute;
  z-index: var(--z-popover);
  max-width: 320px;
  padding: 0.5rem 0.75rem;
  background: var(--color-surface, #1e293b);
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.5rem;
  color: var(--color-text, #e2e8f0);
  font-size: 0.8rem;
  line-height: 1.5;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  pointer-events: none;
  animation: fnTipIn 0.15s ease;
}
@keyframes fnTipIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }

.fn-side-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 340px;
  height: 100vh;
  background: var(--color-bg, #0f172a);
  border-left: 1px solid var(--color-border, #334155);
  z-index: 500;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 20px rgba(0,0,0,0.25);
}
.fn-panel-open { transform: translateX(0); }

.fn-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border, #334155);
  flex-shrink: 0;
}
.fn-panel-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-text, #e2e8f0);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.fn-count-badge {
  background: var(--color-primary, #6366f1);
  color: #fff;
  font-size: 0.7rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-weight: 700;
}
.fn-panel-actions { display: flex; gap: 0.5rem; }
.fn-export-btn {
  background: transparent;
  border: 1px solid var(--color-border, #334155);
  color: var(--color-text-secondary, #94a3b8);
  border-radius: 0.375rem;
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
}
.fn-export-btn:hover { border-color: var(--color-primary, #6366f1); color: var(--color-primary, #6366f1); }
.fn-close-panel {
  background: transparent;
  border: none;
  color: var(--color-text-muted, #64748b);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0 0.25rem;
}
.fn-close-panel:hover { color: #ef4444; }

.fn-panel-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}
.fn-panel-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.6rem 0.5rem;
  border-radius: 0.5rem;
  cursor: grab;
  transition: background 0.15s;
  border: 1px solid transparent;
}
.fn-panel-item:hover { background: var(--color-surface, #1e293b); }
.fn-dragging { opacity: 0.4; }
.fn-drag-over { border-color: var(--color-primary, #6366f1); background: rgba(99,102,241,0.08); }

.fn-item-num {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--color-primary, #6366f1);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.fn-item-body { flex: 1; min-width: 0; }
.fn-item-text {
  font-size: 0.8rem;
  color: var(--color-text, #e2e8f0);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.fn-item-controls { display: flex; gap: 0.25rem; flex-shrink: 0; opacity: 0; transition: opacity 0.15s; }
.fn-panel-item:hover .fn-item-controls { opacity: 1; }
.fn-edit-btn, .fn-delete-btn {
  background: transparent;
  border: none;
  color: var(--color-text-muted, #64748b);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.15rem 0.3rem;
  border-radius: 0.25rem;
}
.fn-edit-btn:hover { color: var(--color-primary, #6366f1); }
.fn-delete-btn:hover { color: #ef4444; }

.fn-empty {
  text-align: center;
  color: var(--color-text-muted, #64748b);
  font-size: 0.8rem;
  padding: 2rem 1rem;
  line-height: 1.5;
}

.fn-modal-body { padding: 0.5rem 0; }
.fn-label { display: block; font-size: 0.85rem; color: var(--color-text-secondary, #94a3b8); margin-bottom: 0.5rem; }
.fn-textarea {
  width: 100%;
  background: var(--color-surface, #1e293b);
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.5rem;
  color: var(--color-text, #e2e8f0);
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  resize: vertical;
  font-family: inherit;
}
.fn-textarea:focus { outline: none; border-color: var(--color-primary, #6366f1); }
.fn-modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.75rem; }
.fn-cancel-btn {
  background: transparent;
  border: 1px solid var(--color-border, #334155);
  color: var(--color-text-secondary, #94a3b8);
  padding: 0.4rem 1rem;
  border-radius: 0.375rem;
  cursor: pointer;
  font-size: 0.8rem;
}
.fn-save-btn {
  background: var(--color-primary, #6366f1);
  border: none;
  color: #fff;
  padding: 0.4rem 1rem;
  border-radius: 0.375rem;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
}
.fn-save-btn:hover { filter: brightness(1.1); }

[data-theme="light"] .fn-side-panel { background: #ffffff; border-color: #e2e8f0; }
[data-theme="light"] .fn-panel-item:hover { background: #f8fafc; }
[data-theme="light"] .fn-tooltip { background: #fff; border-color: #e2e8f0; color: #1e293b; box-shadow: 0 4px 16px rgba(0,0,0,0.1); }
[data-theme="light"] .fn-textarea { background: #f8fafc; color: #1e293b; border-color: #e2e8f0; }
[data-theme="light"] .fn-insert-btn,
[data-theme="light"] .fn-panel-btn { background: #fff; border-color: #e2e8f0; color: #64748b; }

@media (max-width: 640px) {
  .fn-side-panel { width: 100%; }
  .fn-panel-item { padding: 0.5rem 0.4rem; }
}

/* ── Find & Replace ───────────────────────────────────────────── */
.fr-bar {
  position: fixed;
  top: 0;
  right: 1rem;
  z-index: var(--z-overlay);
  background: var(--color-bg, #0f172a);
  border: 1px solid var(--color-border, #334155);
  border-top: none;
  border-radius: 0 0 0.75rem 0.75rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.35);
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 420px;
  animation: frSlideDown 0.2s ease;
}
@keyframes frSlideDown { from { transform: translateY(-100%); } to { transform: translateY(0); } }

.fr-search-row,
.fr-replace-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.fr-input {
  flex: 1;
  background: var(--color-surface, #1e293b);
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.375rem;
  color: var(--color-text, #e2e8f0);
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
  font-family: inherit;
  outline: none;
  min-width: 0;
}
.fr-input:focus { border-color: var(--color-primary, #6366f1); }
.fr-input::placeholder { color: var(--color-text-muted, #64748b); }

.fr-toggles { display: flex; gap: 0.2rem; }
.fr-toggle-btn {
  background: transparent;
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.25rem;
  color: var(--color-text-muted, #64748b);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.4rem;
  cursor: pointer;
  transition: all 0.15s;
  font-family: monospace;
}
.fr-toggle-btn:hover { border-color: var(--color-primary, #6366f1); color: var(--color-primary, #6366f1); }
.fr-toggle-active {
  background: var(--color-primary, #6366f1);
  color: #fff;
  border-color: var(--color-primary, #6366f1);
}

.fr-match-count {
  font-size: 0.72rem;
  color: var(--color-text-secondary, #94a3b8);
  white-space: nowrap;
  min-width: 5rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.fr-nav-btn {
  background: transparent;
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.25rem;
  color: var(--color-text-secondary, #94a3b8);
  padding: 0.15rem 0.35rem;
  cursor: pointer;
  font-size: 0.65rem;
  transition: all 0.15s;
}
.fr-nav-btn:hover { border-color: var(--color-primary, #6366f1); color: var(--color-primary, #6366f1); }

.fr-close-btn {
  background: transparent;
  border: none;
  color: var(--color-text-muted, #64748b);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 0.3rem;
  line-height: 1;
}
.fr-close-btn:hover { color: #ef4444; }

.fr-action-btn {
  background: var(--color-surface, #1e293b);
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.375rem;
  color: var(--color-text, #e2e8f0);
  padding: 0.3rem 0.7rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.fr-action-btn:hover { background: var(--color-primary, #6366f1); color: #fff; border-color: var(--color-primary, #6366f1); }

mark.fr-highlight {
  background: rgba(250, 204, 21, 0.3);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}
mark.fr-highlight-active {
  background: rgba(250, 204, 21, 0.7);
  outline: 2px solid #facc15;
  outline-offset: 1px;
}

[data-theme="light"] .fr-bar { background: #fff; border-color: #e2e8f0; box-shadow: 0 4px 20px rgba(0,0,0,0.1); }
[data-theme="light"] .fr-input { background: #f8fafc; color: #1e293b; border-color: #e2e8f0; }
[data-theme="light"] .fr-action-btn { background: #f8fafc; color: #1e293b; border-color: #e2e8f0; }
[data-theme="light"] mark.fr-highlight { background: rgba(250, 204, 21, 0.35); }
[data-theme="light"] mark.fr-highlight-active { background: rgba(250, 204, 21, 0.65); }

@media (max-width: 640px) {
  .fr-bar { min-width: unset; left: 0.5rem; right: 0.5rem; }
  .fr-match-count { min-width: 3.5rem; font-size: 0.65rem; }
  .fr-toggles { gap: 0.15rem; }
}

/* ── Smart Paste ──────────────────────────────────────────────── */
.sp-popup { display: flex; flex-direction: column; gap: 0.75rem; }
.sp-detected {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: rgba(99,102,241,0.1);
  border: 1px solid rgba(99,102,241,0.25);
  border-radius: 0.5rem;
}
.sp-detected-icon { font-size: 1.2rem; }
.sp-detected-label { font-size: 0.85rem; color: var(--color-text, #e2e8f0); }
.sp-detected-label strong { color: var(--color-primary, #6366f1); }

.sp-preview-box {
  max-height: 160px;
  overflow-y: auto;
  background: var(--color-surface, #1e293b);
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.5rem;
  padding: 0.6rem 0.75rem;
}
.sp-preview-text {
  margin: 0;
  font-size: 0.78rem;
  color: var(--color-text-secondary, #94a3b8);
  white-space: pre-wrap;
  word-break: break-word;
  font-family: 'Consolas', 'Monaco', monospace;
  line-height: 1.5;
}

.sp-options {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.sp-option {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--color-text-secondary, #94a3b8);
  cursor: pointer;
}
.sp-option input[type="radio"] { accent-color: var(--color-primary, #6366f1); }

.sp-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}
.sp-cancel-btn {
  background: transparent;
  border: 1px solid var(--color-border, #334155);
  color: var(--color-text-secondary, #94a3b8);
  padding: 0.4rem 1rem;
  border-radius: 0.375rem;
  cursor: pointer;
  font-size: 0.8rem;
}
.sp-cancel-btn:hover { border-color: var(--color-text-muted, #64748b); }
.sp-paste-btn {
  background: var(--color-primary, #6366f1);
  border: none;
  color: #fff;
  padding: 0.4rem 1.25rem;
  border-radius: 0.375rem;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
}
.sp-paste-btn:hover { filter: brightness(1.1); }

/* Pasted content styles */
.sp-code-block {
  background: var(--color-surface, #1e293b);
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 0.85rem;
  overflow-x: auto;
  margin: 0.5rem 0;
}
.sp-citation { color: var(--color-primary, #6366f1); font-style: italic; }
.sp-citation-formatted { font-size: 0.9rem; }
.sp-pasted-list { margin: 0.5rem 0; padding-left: 1.5rem; }
.sp-pasted-list li { margin-bottom: 0.25rem; }
.doi-link { color: var(--color-primary, #6366f1); text-decoration: none; font-size: 0.85rem; }
.doi-link:hover { text-decoration: underline; }

[data-theme="light"] .sp-detected { background: rgba(99,102,241,0.06); border-color: rgba(99,102,241,0.15); }
[data-theme="light"] .sp-preview-box { background: #f8fafc; border-color: #e2e8f0; }
[data-theme="light"] .sp-code-block { background: #f8fafc; border-color: #e2e8f0; }

@media (max-width: 640px) {
  .sp-options { flex-direction: column; gap: 0.4rem; }
  .sp-actions { flex-direction: column; }
  .sp-paste-btn, .sp-cancel-btn { width: 100%; text-align: center; }
}

/* ── Keyboard Shortcuts Panel ─────────────────────────────────── */
.ks-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-popover);
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: ksFadeIn 0.2s ease;
}
.ks-overlay.ks-exit { animation: ksFadeOut 0.2s ease forwards; }
@keyframes ksFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes ksFadeOut { from { opacity: 1; } to { opacity: 0; } }

.ks-panel {
  background: var(--color-bg, #0f172a);
  border: 1px solid var(--color-border, #334155);
  border-radius: 1rem;
  width: 600px;
  max-width: 95vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 40px rgba(0,0,0,0.4);
  animation: ksSlideUp 0.25s ease;
}
@keyframes ksSlideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.ks-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border, #334155);
  flex-shrink: 0;
}
.ks-title { font-size: 1.1rem; font-weight: 700; color: var(--color-text, #e2e8f0); margin: 0; }
.ks-header-actions { display: flex; align-items: center; gap: 0.5rem; }
.ks-search {
  background: var(--color-surface, #1e293b);
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.375rem;
  color: var(--color-text, #e2e8f0);
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  width: 160px;
  outline: none;
}
.ks-search:focus { border-color: var(--color-primary, #6366f1); }
.ks-search::placeholder { color: var(--color-text-muted, #64748b); }
.ks-print-btn, .ks-close-btn {
  background: transparent;
  border: none;
  color: var(--color-text-muted, #64748b);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.15rem 0.3rem;
}
.ks-print-btn:hover { color: var(--color-primary, #6366f1); }
.ks-close-btn:hover { color: #ef4444; }

.ks-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1.25rem;
}
.ks-category { margin-bottom: 1rem; }
.ks-cat-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-primary, #6366f1);
  margin: 0 0 0.4rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid rgba(99,102,241,0.15);
}
.ks-cat-list { display: flex; flex-direction: column; }
.ks-shortcut-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0.25rem;
  border-radius: 0.25rem;
  transition: background 0.1s;
}
.ks-shortcut-row:hover { background: var(--color-surface, #1e293b); }
.ks-keys { display: flex; align-items: center; gap: 0.2rem; flex-shrink: 0; }
.ks-key {
  background: var(--color-surface, #1e293b);
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.25rem;
  padding: 0.15rem 0.45rem;
  font-size: 0.72rem;
  font-family: 'Consolas', 'Monaco', monospace;
  color: var(--color-text, #e2e8f0);
  min-width: 1.5rem;
  text-align: center;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.ks-plus { color: var(--color-text-muted, #64748b); font-size: 0.65rem; margin: 0 0.1rem; }
.ks-desc { font-size: 0.8rem; color: var(--color-text-secondary, #94a3b8); text-align: right; }

.ks-footer {
  padding: 0.6rem 1.25rem;
  border-top: 1px solid var(--color-border, #334155);
  text-align: center;
  flex-shrink: 0;
}
.ks-hint { font-size: 0.72rem; color: var(--color-text-muted, #64748b); }
.ks-hint kbd {
  background: var(--color-surface, #1e293b);
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.2rem;
  padding: 0.1rem 0.35rem;
  font-size: 0.68rem;
  font-family: monospace;
}
.ks-empty { text-align: center; color: var(--color-text-muted, #64748b); padding: 2rem; font-size: 0.85rem; }

[data-theme="light"] .ks-panel { background: #fff; border-color: #e2e8f0; box-shadow: 0 8px 40px rgba(0,0,0,0.12); }
[data-theme="light"] .ks-search { background: #f8fafc; color: #1e293b; border-color: #e2e8f0; }
[data-theme="light"] .ks-key { background: #f1f5f9; border-color: #e2e8f0; color: #1e293b; }
[data-theme="light"] .ks-shortcut-row:hover { background: #f8fafc; }
[data-theme="light"] .ks-hint kbd { background: #f1f5f9; border-color: #e2e8f0; }

@media (max-width: 640px) {
  .ks-panel { width: 100%; max-width: 100%; border-radius: 0; max-height: 100vh; }
  .ks-search { width: 100px; }
  .ks-shortcut-row { flex-direction: column; align-items: flex-start; gap: 0.15rem; }
  .ks-desc { text-align: left; }
}

@media print {
  .ks-overlay { position: static; background: none; }
  .ks-panel { box-shadow: none; border: none; max-height: none; }
  .ks-header-actions, .ks-footer { display: none; }
}

/* ── Reading Time Estimator ───────────────────────────────────── */
.rte-widget {
  position: fixed;
  bottom: 1.25rem;
  left: 1.25rem;
  z-index: 90;
  background: var(--color-bg, #0f172a);
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.75rem;
  padding: 0.5rem 0.75rem;
  min-width: 180px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  font-size: 0.8rem;
}
.rte-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.rte-icon { font-size: 1rem; }
.rte-time {
  font-weight: 700;
  color: var(--color-text, #e2e8f0);
  flex: 1;
}
.rte-toggle {
  background: transparent;
  border: none;
  color: var(--color-text-muted, #64748b);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0 0.2rem;
}
.rte-details { margin-top: 0.5rem; }
.rte-stat-row {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.rte-stat { display: flex; flex-direction: column; align-items: center; }
.rte-stat-val {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--color-text, #e2e8f0);
  font-variant-numeric: tabular-nums;
}
.rte-stat-lbl {
  font-size: 0.6rem;
  color: var(--color-text-muted, #64748b);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.rte-complexity { margin-bottom: 0.5rem; }
.rte-complexity-bar {
  height: 4px;
  background: var(--color-surface, #1e293b);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 0.2rem;
}
.rte-complexity-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.4s, background 0.4s;
  width: 0%;
}
.rte-complexity-label {
  font-size: 0.65rem;
  color: var(--color-text-secondary, #94a3b8);
}
.rte-audience-row {
  display: flex;
  gap: 0.25rem;
}
.rte-audience-btn {
  flex: 1;
  background: transparent;
  border: 1px solid var(--color-border, #334155);
  border-radius: 0.25rem;
  color: var(--color-text-muted, #64748b);
  padding: 0.2rem 0;
  font-size: 0.65rem;
  cursor: pointer;
  transition: all 0.15s;
}
.rte-audience-btn:hover { border-color: var(--color-primary, #6366f1); color: var(--color-primary, #6366f1); }
.rte-audience-active {
  background: var(--color-primary, #6366f1);
  color: #fff;
  border-color: var(--color-primary, #6366f1);
}

[data-theme="light"] .rte-widget { background: #fff; border-color: #e2e8f0; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
[data-theme="light"] .rte-complexity-bar { background: #f1f5f9; }

@media (max-width: 640px) {
  .rte-widget { left: 0.5rem; bottom: 0.5rem; min-width: 160px; padding: 0.4rem 0.6rem; }
  .rte-stat-row { gap: 0.4rem; }
}

/* ── Text Statistics Panel ─────────────────────────────────── */
.ts-trigger-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.15);
  color: #c4c9d4;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.ts-trigger-btn:hover { border-color: var(--color-primary, #6366f1); color: var(--color-primary, #6366f1); }
.ts-panel {
  position: fixed;
  top: 0;
  right: -380px;
  width: 370px;
  height: 100vh;
  background: #1e1e2e;
  border-left: 1px solid rgba(255,255,255,0.08);
  box-shadow: -4px 0 24px rgba(0,0,0,0.3);
  z-index: var(--z-sidebar);
  overflow-y: auto;
  transition: right 0.25s ease;
  padding: 1.2rem;
}
.ts-panel-open { right: 0; }
.ts-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.ts-header h3 { margin: 0; font-size: 1rem; color: #e2e8f0; }
.ts-close-btn {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.2rem;
}
.ts-close-btn:hover { color: #e2e8f0; }
.ts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-bottom: 1.2rem;
}
.ts-grid-item {
  background: rgba(255,255,255,0.04);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  text-align: center;
}
.ts-grid-item .ts-label {
  font-size: 0.65rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.2rem;
}
.ts-grid-item .ts-value {
  font-size: 1.15rem;
  font-weight: 700;
  color: #e2e8f0;
}
.ts-section-title {
  font-size: 0.75rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 1rem 0 0.5rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.ts-score-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.55rem;
}
.ts-score-name {
  font-size: 0.78rem;
  color: #c4c9d4;
  flex: 0 0 110px;
}
.ts-score-bar {
  flex: 1;
  height: 8px;
  background: rgba(255,255,255,0.06);
  border-radius: 4px;
  overflow: hidden;
}
.ts-score-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
}
.ts-score-val {
  font-size: 0.75rem;
  color: #94a3b8;
  flex: 0 0 36px;
  text-align: right;
}
.ts-metric-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.ts-metric-row:last-child { border-bottom: none; }
.ts-metric-label { font-size: 0.78rem; color: #c4c9d4; }
.ts-metric-value { font-size: 0.78rem; font-weight: 600; color: #e2e8f0; }
.ts-refresh-btn {
  width: 100%;
  margin-top: 1rem;
  padding: 0.5rem;
  background: var(--color-primary, #6366f1);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: opacity 0.15s;
}
.ts-refresh-btn:hover { opacity: 0.85; }

[data-theme="light"] .ts-panel { background: #fff; border-color: #e2e8f0; box-shadow: -4px 0 24px rgba(0,0,0,0.1); }
[data-theme="light"] .ts-header { border-color: #e2e8f0; }
[data-theme="light"] .ts-header h3 { color: #1e293b; }
[data-theme="light"] .ts-close-btn { color: #64748b; }
[data-theme="light"] .ts-close-btn:hover { color: #1e293b; }
[data-theme="light"] .ts-grid-item { background: #f8fafc; }
[data-theme="light"] .ts-grid-item .ts-label { color: #64748b; }
[data-theme="light"] .ts-grid-item .ts-value { color: #1e293b; }
[data-theme="light"] .ts-section-title { color: #64748b; border-color: #e2e8f0; }
[data-theme="light"] .ts-score-name { color: #475569; }
[data-theme="light"] .ts-score-bar { background: #f1f5f9; }
[data-theme="light"] .ts-metric-label { color: #475569; }
[data-theme="light"] .ts-metric-value { color: #1e293b; }
[data-theme="light"] .ts-metric-row { border-color: #f1f5f9; }
[data-theme="light"] .ts-trigger-btn { color: #475569; border-color: #e2e8f0; }

@media (max-width: 640px) {
  .ts-panel { width: 100%; right: -100%; }
  .ts-grid { grid-template-columns: 1fr 1fr; gap: 0.4rem; }
}

/* ── Section Templates ─────────────────────────────────────── */
.st-trigger-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.15);
  color: #c4c9d4;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.st-trigger-btn:hover { border-color: var(--color-primary, #6366f1); color: var(--color-primary, #6366f1); }
.st-panel {
  position: fixed;
  top: 0;
  right: -420px;
  width: 410px;
  height: 100vh;
  background: #1e1e2e;
  border-left: 1px solid rgba(255,255,255,0.08);
  box-shadow: -4px 0 24px rgba(0,0,0,0.3);
  z-index: var(--z-sidebar);
  overflow-y: auto;
  transition: right 0.25s ease;
  padding: 1.2rem;
}
.st-panel-open { right: 0; }
.st-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.st-header h3 { margin: 0; font-size: 1rem; color: #e2e8f0; }
.st-close-btn {
  background: none; border: none; color: #94a3b8; font-size: 1.2rem; cursor: pointer;
}
.st-close-btn:hover { color: #e2e8f0; }
.st-desc { font-size: 0.78rem; color: #94a3b8; margin: 0 0 1rem; line-height: 1.4; }
.st-template-list { display: flex; flex-direction: column; gap: 0.8rem; }
.st-template-card {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 0.8rem;
  transition: border-color 0.15s;
}
.st-template-card:hover { border-color: var(--color-primary, #6366f1); }
.st-card-header { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.st-card-icon { font-size: 1.2rem; }
.st-card-label { font-size: 0.9rem; font-weight: 600; color: #e2e8f0; flex: 1; }
.st-card-count { font-size: 0.7rem; color: #94a3b8; background: rgba(255,255,255,0.06); padding: 0.15rem 0.5rem; border-radius: 10px; }
.st-card-sections { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-bottom: 0.6rem; }
.st-section-preview { display: flex; align-items: center; gap: 0.3rem; font-size: 0.72rem; color: #94a3b8; }
.st-sec-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--color-primary, #6366f1); flex-shrink: 0;
}
.st-card-actions { display: flex; gap: 0.5rem; }
.st-insert-btn, .st-preview-btn {
  flex: 1; padding: 0.4rem; border-radius: 6px; border: none; cursor: pointer;
  font-size: 0.75rem; transition: opacity 0.15s;
}
.st-insert-btn { background: var(--color-primary, #6366f1); color: #fff; }
.st-insert-btn:hover { opacity: 0.85; }
.st-preview-btn { background: rgba(255,255,255,0.08); color: #c4c9d4; }
.st-preview-btn:hover { background: rgba(255,255,255,0.12); }
.st-section-title {
  font-size: 0.75rem; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.05em;
  margin: 1.2rem 0 0.5rem; padding-bottom: 0.3rem; border-bottom: 1px solid rgba(255,255,255,0.06);
}
.st-custom-section { margin-top: 1rem; }
.st-custom-name {
  width: 100%; padding: 0.45rem 0.6rem; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px; color: #e2e8f0; font-size: 0.8rem; margin-bottom: 0.5rem; box-sizing: border-box;
}
.st-custom-name:focus { outline: none; border-color: var(--color-primary, #6366f1); }
.st-custom-row {
  display: flex; gap: 0.4rem; margin-bottom: 0.4rem; align-items: center;
}
.st-custom-heading, .st-custom-prompt {
  flex: 1; padding: 0.35rem 0.5rem; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 5px; color: #e2e8f0; font-size: 0.75rem;
}
.st-custom-heading:focus, .st-custom-prompt:focus { outline: none; border-color: var(--color-primary, #6366f1); }
.st-custom-remove {
  background: none; border: none; color: #ef4444; cursor: pointer; font-size: 1rem; padding: 0 0.3rem;
}
.st-add-section-btn {
  width: 100%; padding: 0.4rem; background: rgba(255,255,255,0.06); border: 1px dashed rgba(255,255,255,0.15);
  border-radius: 6px; color: #94a3b8; font-size: 0.75rem; cursor: pointer; margin: 0.4rem 0;
}
.st-add-section-btn:hover { border-color: var(--color-primary, #6366f1); color: var(--color-primary, #6366f1); }
.st-custom-actions { display: flex; gap: 0.5rem; margin-top: 0.4rem; }
.st-save-custom-btn, .st-insert-custom-btn {
  flex: 1; padding: 0.4rem; border-radius: 6px; border: none; cursor: pointer; font-size: 0.75rem;
}
.st-save-custom-btn { background: rgba(255,255,255,0.08); color: #c4c9d4; }
.st-save-custom-btn:hover { background: rgba(255,255,255,0.12); }
.st-insert-custom-btn { background: var(--color-primary, #6366f1); color: #fff; }
.st-insert-custom-btn:hover { opacity: 0.85; }
.st-saved-section { margin-top: 0.8rem; }
.st-saved-item {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.4rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.st-saved-name { flex: 1; font-size: 0.8rem; color: #e2e8f0; }
.st-saved-count { font-size: 0.7rem; color: #94a3b8; }
.st-saved-insert {
  background: var(--color-primary, #6366f1); color: #fff; border: none; border-radius: 4px;
  padding: 0.2rem 0.5rem; font-size: 0.7rem; cursor: pointer;
}
.st-saved-delete {
  background: none; border: none; color: #ef4444; cursor: pointer; font-size: 1rem;
}
.st-prompt-placeholder { color: #94a3b8; font-style: italic; }
.st-preview-modal h4 { margin: 0; font-size: 0.85rem; color: #e2e8f0; }

[data-theme="light"] .st-panel { background: #fff; border-color: #e2e8f0; box-shadow: -4px 0 24px rgba(0,0,0,0.1); }
[data-theme="light"] .st-header { border-color: #e2e8f0; }
[data-theme="light"] .st-header h3 { color: #1e293b; }
[data-theme="light"] .st-desc { color: #64748b; }
[data-theme="light"] .st-template-card { background: #f8fafc; border-color: #e2e8f0; }
[data-theme="light"] .st-card-label { color: #1e293b; }
[data-theme="light"] .st-card-count { color: #64748b; background: #f1f5f9; }
[data-theme="light"] .st-section-preview { color: #64748b; }
[data-theme="light"] .st-preview-btn { background: #f1f5f9; color: #475569; }
[data-theme="light"] .st-custom-name,
[data-theme="light"] .st-custom-heading,
[data-theme="light"] .st-custom-prompt { background: #f8fafc; border-color: #e2e8f0; color: #1e293b; }
[data-theme="light"] .st-add-section-btn { background: #f8fafc; border-color: #e2e8f0; color: #64748b; }
[data-theme="light"] .st-saved-name { color: #1e293b; }
[data-theme="light"] .st-trigger-btn { color: #475569; border-color: #e2e8f0; }

@media (max-width: 640px) {
  .st-panel { width: 100%; right: -100%; }
  .st-custom-row { flex-wrap: wrap; }
  .st-custom-heading, .st-custom-prompt { flex: 1 1 100%; }
}

/* ── Plagiarism Checker ────────────────────────────────────── */
.pc-trigger-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.15);
  color: #c4c9d4;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.pc-trigger-btn:hover { border-color: var(--color-primary, #6366f1); color: var(--color-primary, #6366f1); }
.pc-panel {
  position: fixed;
  top: 0;
  right: -420px;
  width: 410px;
  height: 100vh;
  background: #1e1e2e;
  border-left: 1px solid rgba(255,255,255,0.08);
  box-shadow: -4px 0 24px rgba(0,0,0,0.3);
  z-index: var(--z-sidebar);
  overflow-y: auto;
  transition: right 0.25s ease;
  padding: 1.2rem;
}
.pc-panel-open { right: 0; }
.pc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.pc-header h3 { margin: 0; font-size: 1rem; color: #e2e8f0; }
.pc-close-btn { background: none; border: none; color: #94a3b8; font-size: 1.2rem; cursor: pointer; }
.pc-close-btn:hover { color: #e2e8f0; }
.pc-desc { font-size: 0.78rem; color: #94a3b8; margin: 0 0 0.8rem; line-height: 1.4; }
.pc-ref-textarea {
  width: 100%;
  padding: 0.6rem;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  color: #e2e8f0;
  font-size: 0.8rem;
  resize: vertical;
  min-height: 100px;
  box-sizing: border-box;
  font-family: inherit;
}
.pc-ref-textarea:focus { outline: none; border-color: var(--color-primary, #6366f1); }
.pc-options {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin: 0.6rem 0;
  flex-wrap: wrap;
}
.pc-option {
  font-size: 0.75rem;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.pc-select {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 4px;
  color: #e2e8f0;
  font-size: 0.75rem;
  padding: 0.2rem 0.4rem;
}
.pc-run-btn {
  width: 100%;
  padding: 0.55rem;
  background: var(--color-primary, #6366f1);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  margin: 0.5rem 0;
  transition: opacity 0.15s;
}
.pc-run-btn:hover { opacity: 0.85; }
.pc-results { margin-top: 0.8rem; }
.pc-score-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1rem;
}
.pc-score-ring { position: relative; width: 70px; height: 70px; flex-shrink: 0; }
.pc-ring-svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.pc-ring-bg { fill: none; stroke: rgba(255,255,255,0.08); stroke-width: 3; }
.pc-ring-fill { fill: none; stroke-width: 3; stroke-linecap: round; transition: stroke-dasharray 0.6s ease; }
.pc-score-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1rem;
  font-weight: 700;
  color: #e2e8f0;
}
.pc-score-info { display: flex; flex-direction: column; gap: 0.2rem; }
.pc-score-label { font-size: 0.9rem; font-weight: 600; }
.pc-score-detail { font-size: 0.75rem; color: #94a3b8; }
.pc-matches-header {
  font-size: 0.75rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.pc-matches-list { display: flex; flex-direction: column; gap: 0.4rem; max-height: 300px; overflow-y: auto; }
.pc-match-item {
  background: rgba(239,68,68,0.08);
  border-left: 3px solid #ef4444;
  border-radius: 0 6px 6px 0;
  padding: 0.5rem 0.6rem;
}
.pc-match-len {
  display: inline-block;
  font-size: 0.65rem;
  color: #ef4444;
  background: rgba(239,68,68,0.15);
  padding: 0.1rem 0.4rem;
  border-radius: 8px;
  margin-bottom: 0.2rem;
}
.pc-match-text { display: block; font-size: 0.78rem; color: #e2e8f0; line-height: 1.4; }
.pc-no-matches {
  text-align: center;
  padding: 1.5rem;
  font-size: 0.85rem;
  color: #22c55e;
  background: rgba(34,197,94,0.08);
  border-radius: 8px;
}
.pc-clear-btn {
  width: 100%;
  margin-top: 0.6rem;
  padding: 0.4rem;
  background: rgba(255,255,255,0.08);
  color: #c4c9d4;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.78rem;
}
.pc-clear-btn:hover { background: rgba(255,255,255,0.12); }
mark.pc-highlight {
  background: rgba(239,68,68,0.25);
  color: inherit;
  border-bottom: 2px solid #ef4444;
  border-radius: 2px;
  padding: 0 1px;
}

[data-theme="light"] .pc-panel { background: #fff; border-color: #e2e8f0; box-shadow: -4px 0 24px rgba(0,0,0,0.1); }
[data-theme="light"] .pc-header { border-color: #e2e8f0; }
[data-theme="light"] .pc-header h3 { color: #1e293b; }
[data-theme="light"] .pc-desc { color: #64748b; }
[data-theme="light"] .pc-ref-textarea { background: #f8fafc; border-color: #e2e8f0; color: #1e293b; }
[data-theme="light"] .pc-select { background: #f8fafc; border-color: #e2e8f0; color: #1e293b; }
[data-theme="light"] .pc-score-card { background: #f8fafc; }
[data-theme="light"] .pc-score-text { color: #1e293b; }
[data-theme="light"] .pc-ring-bg { stroke: #e2e8f0; }
[data-theme="light"] .pc-match-item { background: rgba(239,68,68,0.05); }
[data-theme="light"] .pc-match-text { color: #1e293b; }
[data-theme="light"] .pc-trigger-btn { color: #475569; border-color: #e2e8f0; }
[data-theme="light"] mark.pc-highlight { background: rgba(239,68,68,0.15); }

@media (max-width: 640px) {
  .pc-panel { width: 100%; right: -100%; }
  .pc-options { flex-direction: column; gap: 0.4rem; }
}

/* ── Auto-Bibliography ─────────────────────────────────────── */
.ab-trigger-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.15);
  color: #c4c9d4;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.ab-trigger-btn:hover { border-color: var(--color-primary, #6366f1); color: var(--color-primary, #6366f1); }
.ab-panel {
  position: fixed;
  top: 0;
  right: -420px;
  width: 410px;
  height: 100vh;
  background: #1e1e2e;
  border-left: 1px solid rgba(255,255,255,0.08);
  box-shadow: -4px 0 24px rgba(0,0,0,0.3);
  z-index: var(--z-sidebar);
  overflow-y: auto;
  transition: right 0.25s ease;
  padding: 1.2rem;
}
.ab-panel-open { right: 0; }
.ab-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 0.6rem; padding-bottom: 0.6rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.ab-header h3 { margin: 0; font-size: 1rem; color: #e2e8f0; }
.ab-close-btn { background: none; border: none; color: #94a3b8; font-size: 1.2rem; cursor: pointer; }
.ab-close-btn:hover { color: #e2e8f0; }
.ab-desc { font-size: 0.78rem; color: #94a3b8; margin: 0 0 0.8rem; line-height: 1.4; }
.ab-style-row {
  display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.6rem;
}
.ab-label { font-size: 0.78rem; color: #94a3b8; flex-shrink: 0; }
.ab-select {
  flex: 1; padding: 0.35rem 0.5rem; background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1); border-radius: 6px;
  color: #e2e8f0; font-size: 0.78rem;
}
.ab-select:focus { outline: none; border-color: var(--color-primary, #6366f1); }
.ab-scan-btn {
  width: 100%; padding: 0.5rem; background: var(--color-primary, #6366f1);
  color: #fff; border: none; border-radius: 6px; cursor: pointer;
  font-size: 0.8rem; font-weight: 600; margin-bottom: 0.8rem; transition: opacity 0.15s;
}
.ab-scan-btn:hover { opacity: 0.85; }
.ab-section-title {
  font-size: 0.75rem; color: #94a3b8; text-transform: uppercase;
  letter-spacing: 0.05em; margin: 0.8rem 0 0.4rem;
  padding-bottom: 0.3rem; border-bottom: 1px solid rgba(255,255,255,0.06);
}
.ab-citation-list { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.6rem; }
.ab-citation-item {
  display: flex; align-items: center; gap: 0.5rem;
  background: rgba(255,255,255,0.04); border-radius: 6px;
  padding: 0.4rem 0.6rem; cursor: grab; transition: background 0.15s;
}
.ab-citation-item:hover { background: rgba(255,255,255,0.07); }
.ab-dragging { opacity: 0.5; }
.ab-dragover { border: 1px dashed var(--color-primary, #6366f1); }
.ab-drag-handle { color: #64748b; font-size: 0.9rem; cursor: grab; }
.ab-citation-marker { font-size: 0.8rem; color: #e2e8f0; font-weight: 600; flex: 1; }
.ab-citation-type {
  font-size: 0.65rem; color: #94a3b8; background: rgba(255,255,255,0.06);
  padding: 0.1rem 0.4rem; border-radius: 8px;
}
.ab-bib-list { display: flex; flex-direction: column; gap: 0.5rem; }
.ab-bib-entry {
  font-size: 0.8rem; color: #e2e8f0; line-height: 1.5;
  padding: 0.5rem 0.6rem; background: rgba(255,255,255,0.04);
  border-left: 3px solid var(--color-primary, #6366f1);
  border-radius: 0 6px 6px 0;
}
.ab-bib-entry em { font-style: italic; }
.ab-empty {
  text-align: center; padding: 1.2rem; font-size: 0.8rem;
  color: #94a3b8; background: rgba(255,255,255,0.03); border-radius: 8px;
}
.ab-actions { display: flex; gap: 0.5rem; margin-top: 0.8rem; }
.ab-insert-btn {
  flex: 1; padding: 0.45rem; background: var(--color-primary, #6366f1);
  color: #fff; border: none; border-radius: 6px; cursor: pointer;
  font-size: 0.78rem; transition: opacity 0.15s;
}
.ab-insert-btn:hover { opacity: 0.85; }
.ab-copy-btn {
  flex: 1; padding: 0.45rem; background: rgba(255,255,255,0.08);
  color: #c4c9d4; border: none; border-radius: 6px; cursor: pointer;
  font-size: 0.78rem;
}
.ab-copy-btn:hover { background: rgba(255,255,255,0.12); }

[data-theme="light"] .ab-panel { background: #fff; border-color: #e2e8f0; box-shadow: -4px 0 24px rgba(0,0,0,0.1); }
[data-theme="light"] .ab-header { border-color: #e2e8f0; }
[data-theme="light"] .ab-header h3 { color: #1e293b; }
[data-theme="light"] .ab-desc { color: #64748b; }
[data-theme="light"] .ab-select { background: #f8fafc; border-color: #e2e8f0; color: #1e293b; }
[data-theme="light"] .ab-citation-item { background: #f8fafc; }
[data-theme="light"] .ab-citation-marker { color: #1e293b; }
[data-theme="light"] .ab-bib-entry { background: #f8fafc; color: #1e293b; }
[data-theme="light"] .ab-empty { background: #f8fafc; color: #64748b; }
[data-theme="light"] .ab-trigger-btn { color: #475569; border-color: #e2e8f0; }
[data-theme="light"] .ab-section-title { color: #64748b; border-color: #e2e8f0; }

@media (max-width: 640px) {
  .ab-panel { width: 100%; right: -100%; }
  .ab-actions { flex-direction: column; }
}

/* ── Cross-Reference Manager ───────────────────────────────── */
.xr-trigger-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.15);
  color: #c4c9d4;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.xr-trigger-btn:hover { border-color: var(--color-primary, #6366f1); color: var(--color-primary, #6366f1); }
.xr-panel {
  position: fixed;
  top: 0; right: -420px; width: 410px; height: 100vh;
  background: #1e1e2e;
  border-left: 1px solid rgba(255,255,255,0.08);
  box-shadow: -4px 0 24px rgba(0,0,0,0.3);
  z-index: var(--z-sidebar); overflow-y: auto;
  transition: right 0.25s ease; padding: 1.2rem;
}
.xr-panel-open { right: 0; }
.xr-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 0.6rem; padding-bottom: 0.6rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.xr-header h3 { margin: 0; font-size: 1rem; color: #e2e8f0; }
.xr-close-btn { background: none; border: none; color: #94a3b8; font-size: 1.2rem; cursor: pointer; }
.xr-close-btn:hover { color: #e2e8f0; }
.xr-desc { font-size: 0.78rem; color: #94a3b8; margin: 0 0 0.8rem; line-height: 1.4; }
.xr-add-form {
  display: flex; gap: 0.4rem; margin-bottom: 1rem; flex-wrap: wrap;
}
.xr-select {
  padding: 0.35rem 0.5rem; background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1); border-radius: 6px;
  color: #e2e8f0; font-size: 0.78rem; flex: 0 0 auto;
}
.xr-select:focus { outline: none; border-color: var(--color-primary, #6366f1); }
.xr-num-input {
  width: 50px; padding: 0.35rem 0.4rem; background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1); border-radius: 6px;
  color: #e2e8f0; font-size: 0.78rem; text-align: center;
}
.xr-num-input:focus { outline: none; border-color: var(--color-primary, #6366f1); }
.xr-caption-input {
  flex: 1; min-width: 100px; padding: 0.35rem 0.5rem;
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px; color: #e2e8f0; font-size: 0.78rem;
}
.xr-caption-input:focus { outline: none; border-color: var(--color-primary, #6366f1); }
.xr-add-btn {
  padding: 0.35rem 0.7rem; background: var(--color-primary, #6366f1);
  color: #fff; border: none; border-radius: 6px; cursor: pointer;
  font-size: 0.78rem; transition: opacity 0.15s;
}
.xr-add-btn:hover { opacity: 0.85; }
.xr-group { margin-bottom: 0.8rem; }
.xr-group-title {
  font-size: 0.75rem; color: #94a3b8; text-transform: uppercase;
  letter-spacing: 0.05em; margin-bottom: 0.4rem; padding-bottom: 0.3rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.xr-item {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.45rem 0.5rem; background: rgba(255,255,255,0.04);
  border-radius: 6px; margin-bottom: 0.3rem; transition: background 0.15s;
}
.xr-item:hover { background: rgba(255,255,255,0.07); }
.xr-item-label {
  font-size: 0.82rem; font-weight: 600; color: var(--color-primary, #6366f1);
  flex-shrink: 0; min-width: 60px;
}
.xr-item-caption {
  flex: 1; font-size: 0.75rem; color: #94a3b8;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.xr-item-caption em { font-style: italic; opacity: 0.6; }
.xr-item-actions { display: flex; gap: 0.3rem; flex-shrink: 0; }
.xr-insert-btn, .xr-goto-btn {
  padding: 0.2rem 0.45rem; font-size: 0.68rem; border-radius: 4px;
  border: none; cursor: pointer; transition: opacity 0.15s;
}
.xr-insert-btn { background: var(--color-primary, #6366f1); color: #fff; }
.xr-insert-btn:hover { opacity: 0.85; }
.xr-goto-btn { background: rgba(255,255,255,0.08); color: #c4c9d4; }
.xr-goto-btn:hover { background: rgba(255,255,255,0.12); }
.xr-edit-btn, .xr-delete-btn {
  background: none; border: none; cursor: pointer; font-size: 0.8rem; padding: 0 0.2rem;
}
.xr-edit-btn { color: #94a3b8; }
.xr-edit-btn:hover { color: #e2e8f0; }
.xr-delete-btn { color: #ef4444; }
.xr-delete-btn:hover { color: #f87171; }
.xr-empty {
  text-align: center; padding: 1.2rem; font-size: 0.8rem;
  color: #94a3b8; background: rgba(255,255,255,0.03); border-radius: 8px;
}
.xr-footer-actions { display: flex; gap: 0.5rem; margin-top: 1rem; }
.xr-renumber-btn {
  flex: 1; padding: 0.45rem; background: var(--color-primary, #6366f1);
  color: #fff; border: none; border-radius: 6px; cursor: pointer;
  font-size: 0.78rem; transition: opacity 0.15s;
}
.xr-renumber-btn:hover { opacity: 0.85; }
.xr-export-btn {
  flex: 1; padding: 0.45rem; background: rgba(255,255,255,0.08);
  color: #c4c9d4; border: none; border-radius: 6px; cursor: pointer;
  font-size: 0.78rem;
}
.xr-export-btn:hover { background: rgba(255,255,255,0.12); }

[data-theme="light"] .xr-panel { background: #fff; border-color: #e2e8f0; box-shadow: -4px 0 24px rgba(0,0,0,0.1); }
[data-theme="light"] .xr-header { border-color: #e2e8f0; }
[data-theme="light"] .xr-header h3 { color: #1e293b; }
[data-theme="light"] .xr-desc { color: #64748b; }
[data-theme="light"] .xr-select,
[data-theme="light"] .xr-num-input,
[data-theme="light"] .xr-caption-input { background: #f8fafc; border-color: #e2e8f0; color: #1e293b; }
[data-theme="light"] .xr-group-title { color: #64748b; border-color: #e2e8f0; }
[data-theme="light"] .xr-item { background: #f8fafc; }
[data-theme="light"] .xr-item-caption { color: #64748b; }
[data-theme="light"] .xr-empty { background: #f8fafc; color: #64748b; }
[data-theme="light"] .xr-trigger-btn { color: #475569; border-color: #e2e8f0; }

@media (max-width: 640px) {
  .xr-panel { width: 100%; right: -100%; }
  .xr-add-form { flex-direction: column; }
  .xr-num-input { width: 100%; }
  .xr-footer-actions { flex-direction: column; }
}

/* ── Revision History Diff ─────────────────────────────────── */
.rd-trigger-btn {
  background: none; border: 1px solid rgba(255,255,255,0.15); color: #c4c9d4;
  padding: 0.35rem 0.7rem; border-radius: 6px; cursor: pointer;
  font-size: 0.8rem; transition: all 0.15s; display: inline-flex; align-items: center; gap: 0.3rem;
}
.rd-trigger-btn:hover { border-color: var(--color-primary, #6366f1); color: var(--color-primary, #6366f1); }
.rd-panel {
  position: fixed; top: 0; right: -450px; width: 440px; height: 100vh;
  background: #1e1e2e; border-left: 1px solid rgba(255,255,255,0.08);
  box-shadow: -4px 0 24px rgba(0,0,0,0.3); z-index: var(--z-sidebar);
  overflow-y: auto; transition: right 0.25s ease; padding: 1.2rem;
}
.rd-panel-open { right: 0; }
.rd-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 0.6rem; padding-bottom: 0.6rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.rd-header h3 { margin: 0; font-size: 1rem; color: #e2e8f0; }
.rd-close-btn { background: none; border: none; color: #94a3b8; font-size: 1.2rem; cursor: pointer; }
.rd-close-btn:hover { color: #e2e8f0; }
.rd-toolbar-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.8rem;
}
.rd-snapshot-btn {
  padding: 0.4rem 0.7rem; background: var(--color-primary, #6366f1); color: #fff;
  border: none; border-radius: 6px; cursor: pointer; font-size: 0.78rem; transition: opacity 0.15s;
}
.rd-snapshot-btn:hover { opacity: 0.85; }
.rd-version-count { font-size: 0.75rem; color: #94a3b8; }
.rd-compare-row { display: flex; gap: 0.6rem; margin-bottom: 0.5rem; }
.rd-compare-col { flex: 1; display: flex; flex-direction: column; gap: 0.2rem; }
.rd-label { font-size: 0.7rem; color: #94a3b8; }
.rd-select {
  padding: 0.35rem 0.5rem; background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1); border-radius: 6px;
  color: #e2e8f0; font-size: 0.72rem;
}
.rd-select:focus { outline: none; border-color: var(--color-primary, #6366f1); }
.rd-compare-btn {
  width: 100%; padding: 0.45rem; background: var(--color-primary, #6366f1);
  color: #fff; border: none; border-radius: 6px; cursor: pointer;
  font-size: 0.8rem; font-weight: 600; margin-bottom: 0.8rem; transition: opacity 0.15s;
}
.rd-compare-btn:hover { opacity: 0.85; }
.rd-diff-output { margin-bottom: 1rem; }
.rd-diff-lines {
  font-family: 'Consolas', 'Monaco', monospace; font-size: 0.72rem;
  background: rgba(0,0,0,0.2); border-radius: 8px; padding: 0.6rem;
  max-height: 350px; overflow-y: auto; line-height: 1.6;
}
.rd-diff-line { display: flex; gap: 0.4rem; padding: 0.1rem 0.3rem; border-radius: 2px; }
.rd-diff-same { color: #94a3b8; }
.rd-diff-added { background: rgba(34,197,94,0.12); color: #4ade80; }
.rd-diff-removed { background: rgba(239,68,68,0.12); color: #f87171; }
.rd-diff-prefix { flex-shrink: 0; width: 14px; text-align: center; font-weight: 700; }
.rd-diff-text { word-break: break-word; }
.rd-diff-stats {
  display: flex; gap: 1rem; margin-top: 0.5rem; font-size: 0.75rem;
}
.rd-stat-added { color: #22c55e; font-weight: 600; }
.rd-stat-removed { color: #ef4444; font-weight: 600; }
.rd-section-title {
  font-size: 0.75rem; color: #94a3b8; text-transform: uppercase;
  letter-spacing: 0.05em; margin: 1rem 0 0.4rem; padding-bottom: 0.3rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.rd-version-list { display: flex; flex-direction: column; gap: 0.3rem; }
.rd-version-item {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.45rem 0.5rem;
  background: rgba(255,255,255,0.04); border-radius: 6px; flex-wrap: wrap;
}
.rd-version-item:hover { background: rgba(255,255,255,0.07); }
.rd-version-label { font-size: 0.8rem; color: #e2e8f0; font-weight: 600; flex: 1; min-width: 80px; }
.rd-version-date { font-size: 0.7rem; color: #94a3b8; }
.rd-version-words { font-size: 0.68rem; color: #64748b; background: rgba(255,255,255,0.06); padding: 0.1rem 0.4rem; border-radius: 8px; }
.rd-version-actions { display: flex; gap: 0.3rem; }
.rd-restore-btn {
  padding: 0.2rem 0.5rem; font-size: 0.68rem; background: rgba(34,197,94,0.15);
  color: #22c55e; border: none; border-radius: 4px; cursor: pointer;
}
.rd-restore-btn:hover { background: rgba(34,197,94,0.25); }
.rd-delete-ver-btn { background: none; border: none; color: #ef4444; cursor: pointer; font-size: 0.9rem; }
.rd-empty {
  text-align: center; padding: 1.2rem; font-size: 0.8rem;
  color: #94a3b8; background: rgba(255,255,255,0.03); border-radius: 8px; margin-bottom: 0.8rem;
}

[data-theme="light"] .rd-panel { background: #fff; border-color: #e2e8f0; box-shadow: -4px 0 24px rgba(0,0,0,0.1); }
[data-theme="light"] .rd-header { border-color: #e2e8f0; }
[data-theme="light"] .rd-header h3 { color: #1e293b; }
[data-theme="light"] .rd-select { background: #f8fafc; border-color: #e2e8f0; color: #1e293b; }
[data-theme="light"] .rd-diff-lines { background: #f8fafc; }
[data-theme="light"] .rd-diff-same { color: #64748b; }
[data-theme="light"] .rd-diff-added { background: rgba(34,197,94,0.08); color: #16a34a; }
[data-theme="light"] .rd-diff-removed { background: rgba(239,68,68,0.08); color: #dc2626; }
[data-theme="light"] .rd-version-item { background: #f8fafc; }
[data-theme="light"] .rd-version-label { color: #1e293b; }
[data-theme="light"] .rd-empty { background: #f8fafc; color: #64748b; }
[data-theme="light"] .rd-trigger-btn { color: #475569; border-color: #e2e8f0; }

@media (max-width: 640px) {
  .rd-panel { width: 100%; right: -100%; }
  .rd-compare-row { flex-direction: column; }
}

/* ── Language Detector ─────────────────────────────────────── */
.ld-trigger-btn {
  background: none; border: 1px solid rgba(255,255,255,0.15); color: #c4c9d4;
  padding: 0.35rem 0.7rem; border-radius: 6px; cursor: pointer;
  font-size: 0.8rem; transition: all 0.15s; display: inline-flex; align-items: center; gap: 0.3rem;
}
.ld-trigger-btn:hover { border-color: var(--color-primary, #6366f1); color: var(--color-primary, #6366f1); }
.ld-panel {
  position: fixed; top: 0; right: -400px; width: 390px; height: 100vh;
  background: #1e1e2e; border-left: 1px solid rgba(255,255,255,0.08);
  box-shadow: -4px 0 24px rgba(0,0,0,0.3); z-index: var(--z-sidebar);
  overflow-y: auto; transition: right 0.25s ease; padding: 1.2rem;
}
.ld-panel-open { right: 0; }
.ld-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 0.8rem; padding-bottom: 0.6rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.ld-header h3 { margin: 0; font-size: 1rem; color: #e2e8f0; }
.ld-close-btn { background: none; border: none; color: #94a3b8; font-size: 1.2rem; cursor: pointer; }
.ld-close-btn:hover { color: #e2e8f0; }
.ld-primary {
  display: flex; align-items: center; gap: 0.6rem; margin-bottom: 1rem;
}
.ld-primary-badge {
  font-size: 1.1rem; font-weight: 700; color: #e2e8f0;
  border: 2px solid; padding: 0.3rem 0.8rem; border-radius: 8px;
}
.ld-confidence { font-size: 0.78rem; color: #94a3b8; }
.ld-section-title {
  font-size: 0.75rem; color: #94a3b8; text-transform: uppercase;
  letter-spacing: 0.05em; margin: 1rem 0 0.5rem; padding-bottom: 0.3rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.ld-lang-list { display: flex; flex-direction: column; gap: 0.4rem; }
.ld-lang-row { display: flex; align-items: center; gap: 0.5rem; }
.ld-lang-name { font-size: 0.78rem; color: #c4c9d4; flex: 0 0 100px; }
.ld-lang-bar {
  flex: 1; height: 8px; background: rgba(255,255,255,0.06);
  border-radius: 4px; overflow: hidden;
}
.ld-lang-fill { height: 100%; border-radius: 4px; transition: width 0.3s; }
.ld-lang-pct { font-size: 0.72rem; color: #94a3b8; flex: 0 0 36px; text-align: right; }
.ld-no-detect { font-size: 0.8rem; color: #94a3b8; padding: 0.6rem; text-align: center; }
.ld-stats-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem;
}
.ld-stat-card {
  background: rgba(255,255,255,0.04); border-radius: 8px;
  padding: 0.6rem; text-align: center;
}
.ld-stat-value { font-size: 1.15rem; font-weight: 700; color: #e2e8f0; }
.ld-stat-label { font-size: 0.65rem; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.03em; margin-top: 0.15rem; }
.ld-suggestions { display: flex; flex-direction: column; gap: 0.3rem; }
.ld-suggestion-item {
  font-size: 0.78rem; color: #c4c9d4; padding: 0.4rem 0.5rem;
  background: rgba(255,255,255,0.04); border-radius: 6px; line-height: 1.4;
}
.ld-refresh-btn {
  width: 100%; margin-top: 1rem; padding: 0.5rem;
  background: var(--color-primary, #6366f1); color: #fff; border: none;
  border-radius: 6px; cursor: pointer; font-size: 0.8rem; transition: opacity 0.15s;
}
.ld-refresh-btn:hover { opacity: 0.85; }
.ld-empty {
  text-align: center; padding: 1.5rem; font-size: 0.8rem; color: #94a3b8;
  background: rgba(255,255,255,0.03); border-radius: 8px;
}

[data-theme="light"] .ld-panel { background: #fff; border-color: #e2e8f0; box-shadow: -4px 0 24px rgba(0,0,0,0.1); }
[data-theme="light"] .ld-header { border-color: #e2e8f0; }
[data-theme="light"] .ld-header h3 { color: #1e293b; }
[data-theme="light"] .ld-primary-badge { color: #1e293b; }
[data-theme="light"] .ld-lang-name { color: #475569; }
[data-theme="light"] .ld-lang-bar { background: #f1f5f9; }
[data-theme="light"] .ld-stat-card { background: #f8fafc; }
[data-theme="light"] .ld-stat-value { color: #1e293b; }
[data-theme="light"] .ld-suggestion-item { background: #f8fafc; color: #475569; }
[data-theme="light"] .ld-empty { background: #f8fafc; color: #64748b; }
[data-theme="light"] .ld-trigger-btn { color: #475569; border-color: #e2e8f0; }
[data-theme="light"] .ld-section-title { color: #64748b; border-color: #e2e8f0; }

@media (max-width: 640px) {
  .ld-panel { width: 100%; right: -100%; }
  .ld-stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── Spell Check Overlay ─────────────────────────────────── */
.sc-trigger-btn {
  background: transparent; border: 1px solid rgba(255,255,255,0.12); color: #c4c9d4;
  padding: 0.35rem 0.7rem; border-radius: 6px; cursor: pointer; font-size: 0.78rem;
  display: inline-flex; align-items: center; gap: 0.35rem; transition: all 0.15s;
}
.sc-trigger-btn:hover { border-color: rgba(255,255,255,0.25); color: #e2e8f0; }
.sc-trigger-btn.sc-active { border-color: var(--color-primary, #6366f1); color: var(--color-primary, #6366f1); background: rgba(99,102,241,0.08); }
.sc-error {
  text-decoration: wavy underline;
  text-decoration-color: #ef4444;
  text-underline-offset: 3px;
  cursor: pointer;
  position: relative;
}
.sc-popup {
  position: absolute; z-index: var(--z-popover); min-width: 220px; max-width: 300px;
  background: #1e2030; border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px; box-shadow: 0 8px 32px rgba(0,0,0,0.45);
  padding: 0; overflow: hidden; animation: scFadeIn 0.12s ease-out;
}
@keyframes scFadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.sc-popup-header {
  padding: 0.5rem 0.65rem; border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex; align-items: center; justify-content: space-between;
}
.sc-popup-header .sc-word { font-size: 0.8rem; font-weight: 600; color: #ef4444; }
.sc-popup-header .sc-close-btn {
  background: none; border: none; color: #94a3b8; cursor: pointer; font-size: 0.9rem;
  padding: 0; line-height: 1;
}
.sc-popup-header .sc-close-btn:hover { color: #e2e8f0; }
.sc-suggestions { list-style: none; margin: 0; padding: 0.3rem 0; }
.sc-suggestion {
  padding: 0.35rem 0.65rem; font-size: 0.78rem; color: #e2e8f0; cursor: pointer;
  transition: background 0.1s;
}
.sc-suggestion:hover { background: rgba(99,102,241,0.15); }
.sc-no-suggestions {
  padding: 0.5rem 0.65rem; font-size: 0.75rem; color: #64748b; font-style: italic;
}
.sc-popup-actions {
  display: flex; gap: 0; border-top: 1px solid rgba(255,255,255,0.08);
}
.sc-popup-actions button {
  flex: 1; background: none; border: none; padding: 0.4rem 0.5rem;
  font-size: 0.72rem; color: #94a3b8; cursor: pointer; transition: all 0.1s;
}
.sc-popup-actions button:hover { background: rgba(255,255,255,0.06); color: #e2e8f0; }
.sc-popup-actions button:first-child { border-right: 1px solid rgba(255,255,255,0.08); }
.sc-ignore-btn::before { content: '⊘ '; }
.sc-add-btn::before { content: '＋ '; }
.sc-status {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-size: 0.72rem; padding: 0.2rem 0.5rem; border-radius: 12px;
  margin-left: 0.5rem;
}
.sc-status-ok { color: #22c55e; background: rgba(34,197,94,0.1); }
.sc-status-err { color: #f59e0b; background: rgba(245,158,11,0.1); }

/* Light theme overrides */
[data-theme="light"] .sc-trigger-btn { color: #475569; border-color: #e2e8f0; }
[data-theme="light"] .sc-trigger-btn:hover { border-color: #cbd5e1; color: #1e293b; }
[data-theme="light"] .sc-popup { background: #fff; border-color: #e2e8f0; box-shadow: 0 8px 32px rgba(0,0,0,0.12); }
[data-theme="light"] .sc-popup-header { border-color: #e2e8f0; }
[data-theme="light"] .sc-suggestion { color: #1e293b; }
[data-theme="light"] .sc-suggestion:hover { background: rgba(99,102,241,0.08); }
[data-theme="light"] .sc-popup-actions { border-color: #e2e8f0; }
[data-theme="light"] .sc-popup-actions button { color: #64748b; }
[data-theme="light"] .sc-popup-actions button:hover { background: #f8fafc; color: #1e293b; }
[data-theme="light"] .sc-popup-actions button:first-child { border-color: #e2e8f0; }
[data-theme="light"] .sc-no-suggestions { color: #94a3b8; }

@media (max-width: 640px) {
  .sc-popup { min-width: 180px; max-width: 260px; }
}

/* ── Table of Figures ────────────────────────────────────── */
.tof-trigger-btn {
  background: transparent; border: 1px solid rgba(255,255,255,0.12); color: #c4c9d4;
  padding: 0.35rem 0.7rem; border-radius: 6px; cursor: pointer; font-size: 0.78rem;
  display: inline-flex; align-items: center; gap: 0.35rem; transition: all 0.15s;
}
.tof-trigger-btn:hover { border-color: rgba(255,255,255,0.25); color: #e2e8f0; }
.tof-trigger-btn.tof-active { border-color: var(--color-primary, #6366f1); color: var(--color-primary, #6366f1); background: rgba(99,102,241,0.08); }
.tof-icon { font-size: 0.9rem; }
.tof-panel {
  position: fixed; top: 0; right: -380px; width: 370px; height: 100vh;
  background: #1a1b2e; border-left: 1px solid rgba(255,255,255,0.08);
  box-shadow: -4px 0 24px rgba(0,0,0,0.35); z-index: var(--z-toast);
  display: flex; flex-direction: column; transition: right 0.25s cubic-bezier(0.4,0,0.2,1);
}
.tof-panel--open { right: 0; }
.tof-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.tof-header h3 { margin: 0; font-size: 0.95rem; font-weight: 600; color: #e2e8f0; }
.tof-close-btn { background: none; border: none; color: #94a3b8; font-size: 1.2rem; cursor: pointer; padding: 0; line-height: 1; }
.tof-close-btn:hover { color: #e2e8f0; }
.tof-controls {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding: 0.5rem 1rem; border-bottom: 1px solid rgba(255,255,255,0.06);
}
.tof-filter-tabs { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.tof-tab {
  background: rgba(255,255,255,0.05); border: 1px solid transparent; color: #94a3b8;
  padding: 0.2rem 0.5rem; border-radius: 4px; cursor: pointer; font-size: 0.68rem;
  transition: all 0.12s;
}
.tof-tab:hover { color: #e2e8f0; background: rgba(255,255,255,0.08); }
.tof-tab--active { color: var(--color-primary, #6366f1); border-color: var(--color-primary, #6366f1); background: rgba(99,102,241,0.1); }
.tof-refresh-btn {
  background: none; border: 1px solid rgba(255,255,255,0.1); color: #94a3b8;
  padding: 0.2rem 0.5rem; border-radius: 4px; cursor: pointer; font-size: 0.7rem;
  transition: all 0.12s; white-space: nowrap;
}
.tof-refresh-btn:hover { color: #e2e8f0; border-color: rgba(255,255,255,0.2); }
.tof-list {
  flex: 1; overflow-y: auto; padding: 0.5rem 0.75rem;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.tof-section-header {
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  color: #64748b; padding: 0.6rem 0 0.25rem; border-bottom: 1px solid rgba(255,255,255,0.06);
  margin-bottom: 0.3rem;
}
.tof-item {
  display: flex; align-items: baseline; gap: 0.3rem; padding: 0.35rem 0.4rem;
  border-radius: 5px; cursor: pointer; transition: background 0.1s; font-size: 0.78rem;
}
.tof-item:hover { background: rgba(99,102,241,0.1); }
.tof-item-num { font-weight: 600; color: var(--color-primary, #6366f1); white-space: nowrap; flex-shrink: 0; }
.tof-item-dots { flex: 1; border-bottom: 1px dotted rgba(255,255,255,0.15); min-width: 10px; margin-bottom: 3px; }
.tof-item-caption { color: #c4c9d4; flex-shrink: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.tof-item-page { font-size: 0.65rem; color: #64748b; white-space: nowrap; flex-shrink: 0; }
.tof-empty {
  text-align: center; padding: 1.5rem 1rem; font-size: 0.78rem; color: #64748b;
  background: rgba(255,255,255,0.03); border-radius: 8px; line-height: 1.5;
}
.tof-actions {
  display: flex; gap: 0.5rem; padding: 0.65rem 1rem;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.tof-insert-btn, .tof-copy-btn {
  flex: 1; padding: 0.45rem 0.5rem; border: none; border-radius: 6px;
  font-size: 0.75rem; cursor: pointer; transition: all 0.12s;
}
.tof-insert-btn { background: var(--color-primary, #6366f1); color: #fff; }
.tof-insert-btn:hover { opacity: 0.85; }
.tof-copy-btn { background: rgba(255,255,255,0.08); color: #c4c9d4; }
.tof-copy-btn:hover { background: rgba(255,255,255,0.12); color: #e2e8f0; }

/* Light theme */
[data-theme="light"] .tof-trigger-btn { color: #475569; border-color: #e2e8f0; }
[data-theme="light"] .tof-panel { background: #fff; border-color: #e2e8f0; box-shadow: -4px 0 24px rgba(0,0,0,0.1); }
[data-theme="light"] .tof-header { border-color: #e2e8f0; }
[data-theme="light"] .tof-header h3 { color: #1e293b; }
[data-theme="light"] .tof-controls { border-color: #f1f5f9; }
[data-theme="light"] .tof-tab { color: #64748b; background: #f8fafc; }
[data-theme="light"] .tof-tab:hover { color: #1e293b; }
[data-theme="light"] .tof-section-header { color: #94a3b8; border-color: #e2e8f0; }
[data-theme="light"] .tof-item:hover { background: rgba(99,102,241,0.06); }
[data-theme="light"] .tof-item-caption { color: #475569; }
[data-theme="light"] .tof-item-dots { border-color: #cbd5e1; }
[data-theme="light"] .tof-empty { background: #f8fafc; color: #94a3b8; }
[data-theme="light"] .tof-actions { border-color: #e2e8f0; }
[data-theme="light"] .tof-copy-btn { background: #f1f5f9; color: #475569; }
[data-theme="light"] .tof-refresh-btn { color: #64748b; border-color: #e2e8f0; }

@media (max-width: 640px) {
  .tof-panel { width: 100%; right: -100%; }
  .tof-item-caption { max-width: 100px; }
  .tof-filter-tabs { gap: 0.15rem; }
}

/* ── Endnote Manager ─────────────────────────────────────── */
.en-trigger-btn {
  background: transparent; border: 1px solid rgba(255,255,255,0.12); color: #c4c9d4;
  padding: 0.35rem 0.7rem; border-radius: 6px; cursor: pointer; font-size: 0.78rem;
  display: inline-flex; align-items: center; gap: 0.35rem; transition: all 0.15s;
}
.en-trigger-btn:hover { border-color: rgba(255,255,255,0.25); color: #e2e8f0; }
.en-trigger-btn.en-active { border-color: var(--color-primary, #6366f1); color: var(--color-primary, #6366f1); background: rgba(99,102,241,0.08); }
.en-icon { font-size: 0.9rem; }
.en-panel {
  position: fixed; top: 0; right: -380px; width: 370px; height: 100vh;
  background: #1a1b2e; border-left: 1px solid rgba(255,255,255,0.08);
  box-shadow: -4px 0 24px rgba(0,0,0,0.35); z-index: var(--z-toast);
  display: flex; flex-direction: column; transition: right 0.25s cubic-bezier(0.4,0,0.2,1);
}
.en-panel--open { right: 0; }
.en-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.en-header h3 { margin: 0; font-size: 0.95rem; font-weight: 600; color: #e2e8f0; }
.en-header-actions { display: flex; align-items: center; gap: 0.5rem; }
.en-count-badge {
  background: var(--color-primary, #6366f1); color: #fff; font-size: 0.65rem; font-weight: 700;
  padding: 0.1rem 0.4rem; border-radius: 10px; min-width: 1.2rem; text-align: center;
}
.en-close-btn { background: none; border: none; color: #94a3b8; font-size: 1.2rem; cursor: pointer; padding: 0; line-height: 1; }
.en-close-btn:hover { color: #e2e8f0; }
.en-toolbar-row {
  display: flex; gap: 0.4rem; padding: 0.5rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.en-add-btn, .en-scan-btn {
  flex: 1; padding: 0.35rem 0.5rem; border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04); color: #c4c9d4; border-radius: 5px;
  cursor: pointer; font-size: 0.72rem; transition: all 0.12s;
}
.en-add-btn:hover { background: rgba(99,102,241,0.15); border-color: var(--color-primary, #6366f1); color: #e2e8f0; }
.en-scan-btn:hover { background: rgba(255,255,255,0.08); color: #e2e8f0; }
.en-list {
  flex: 1; overflow-y: auto; padding: 0.5rem 0.75rem;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.en-note-card {
  background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px; padding: 0.5rem; margin-bottom: 0.4rem;
  transition: background 0.15s;
}
.en-note-card:hover { background: rgba(255,255,255,0.05); }
.en-note-header {
  display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.3rem;
}
.en-note-num {
  background: var(--color-primary, #6366f1); color: #fff; font-size: 0.65rem; font-weight: 700;
  width: 1.4rem; height: 1.4rem; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; flex-shrink: 0;
}
.en-note-marker { font-size: 0.68rem; color: #64748b; font-family: monospace; }
.en-note-actions { margin-left: auto; display: flex; gap: 0.2rem; }
.en-note-actions button {
  background: none; border: none; color: #64748b; cursor: pointer; font-size: 0.8rem;
  padding: 0.1rem 0.25rem; border-radius: 3px; transition: all 0.1s;
}
.en-note-actions button:hover { color: #e2e8f0; background: rgba(255,255,255,0.08); }
.en-note-text {
  width: 100%; background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08);
  border-radius: 5px; color: #e2e8f0; font-size: 0.76rem; padding: 0.35rem 0.5rem;
  resize: vertical; min-height: 2.5rem; font-family: inherit; line-height: 1.4;
}
.en-note-text:focus { border-color: var(--color-primary, #6366f1); outline: none; }
.en-note-text::placeholder { color: #4a5068; }
.en-empty {
  text-align: center; padding: 1.5rem 1rem; font-size: 0.78rem; color: #64748b;
  background: rgba(255,255,255,0.03); border-radius: 8px; line-height: 1.5;
}
.en-actions {
  display: flex; gap: 0.35rem; padding: 0.6rem 1rem;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.en-insert-all-btn { flex: 2; }
.en-copy-btn, .en-export-btn { flex: 1; }
.en-insert-all-btn, .en-copy-btn, .en-export-btn {
  padding: 0.4rem 0.4rem; border: none; border-radius: 6px;
  font-size: 0.72rem; cursor: pointer; transition: all 0.12s;
}
.en-insert-all-btn { background: var(--color-primary, #6366f1); color: #fff; }
.en-insert-all-btn:hover { opacity: 0.85; }
.en-copy-btn { background: rgba(255,255,255,0.08); color: #c4c9d4; }
.en-copy-btn:hover { background: rgba(255,255,255,0.12); }
.en-export-btn { background: rgba(255,255,255,0.05); color: #94a3b8; }
.en-export-btn:hover { background: rgba(255,255,255,0.1); color: #c4c9d4; }

/* Light theme */
[data-theme="light"] .en-trigger-btn { color: #475569; border-color: #e2e8f0; }
[data-theme="light"] .en-panel { background: #fff; border-color: #e2e8f0; box-shadow: -4px 0 24px rgba(0,0,0,0.1); }
[data-theme="light"] .en-header { border-color: #e2e8f0; }
[data-theme="light"] .en-header h3 { color: #1e293b; }
[data-theme="light"] .en-toolbar-row { border-color: #f1f5f9; }
[data-theme="light"] .en-add-btn, [data-theme="light"] .en-scan-btn { color: #475569; background: #f8fafc; border-color: #e2e8f0; }
[data-theme="light"] .en-note-card { background: #f8fafc; border-color: #e2e8f0; }
[data-theme="light"] .en-note-text { background: #fff; border-color: #e2e8f0; color: #1e293b; }
[data-theme="light"] .en-note-text::placeholder { color: #94a3b8; }
[data-theme="light"] .en-note-marker { color: #94a3b8; }
[data-theme="light"] .en-empty { background: #f8fafc; color: #94a3b8; }
[data-theme="light"] .en-actions { border-color: #e2e8f0; }
[data-theme="light"] .en-copy-btn { background: #f1f5f9; color: #475569; }
[data-theme="light"] .en-export-btn { background: #f8fafc; color: #64748b; }

@media (max-width: 640px) {
  .en-panel { width: 100%; right: -100%; }
}

/* ── Glossary Index ──────────────────────────────────────── */
.gi-trigger-btn {
  background: transparent; border: 1px solid rgba(255,255,255,0.12); color: #c4c9d4;
  padding: 0.35rem 0.7rem; border-radius: 6px; cursor: pointer; font-size: 0.78rem;
  display: inline-flex; align-items: center; gap: 0.35rem; transition: all 0.15s;
}
.gi-trigger-btn:hover { border-color: rgba(255,255,255,0.25); color: #e2e8f0; }
.gi-trigger-btn.gi-active { border-color: var(--color-primary, #6366f1); color: var(--color-primary, #6366f1); background: rgba(99,102,241,0.08); }
.gi-icon { font-size: 0.9rem; }
.gi-panel {
  position: fixed; top: 0; right: -380px; width: 370px; height: 100vh;
  background: #1a1b2e; border-left: 1px solid rgba(255,255,255,0.08);
  box-shadow: -4px 0 24px rgba(0,0,0,0.35); z-index: var(--z-toast);
  display: flex; flex-direction: column; transition: right 0.25s cubic-bezier(0.4,0,0.2,1);
}
.gi-panel--open { right: 0; }
.gi-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.gi-header h3 { margin: 0; font-size: 0.95rem; font-weight: 600; color: #e2e8f0; }
.gi-header-actions { display: flex; align-items: center; gap: 0.5rem; }
.gi-count { font-size: 0.68rem; color: #64748b; }
.gi-close-btn { background: none; border: none; color: #94a3b8; font-size: 1.2rem; cursor: pointer; padding: 0; line-height: 1; }
.gi-close-btn:hover { color: #e2e8f0; }
.gi-toolbar-row {
  display: flex; gap: 0.35rem; padding: 0.4rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.gi-search {
  flex: 1; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 5px; color: #e2e8f0; font-size: 0.75rem; padding: 0.3rem 0.5rem;
}
.gi-search:focus { border-color: var(--color-primary, #6366f1); outline: none; }
.gi-search::placeholder { color: #4a5068; }
.gi-scan-btn {
  background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1);
  color: #94a3b8; border-radius: 5px; cursor: pointer; padding: 0.3rem 0.5rem;
  font-size: 0.78rem; transition: all 0.12s;
}
.gi-scan-btn:hover { color: #e2e8f0; border-color: rgba(255,255,255,0.2); }
.gi-add-row {
  display: flex; gap: 0.3rem; padding: 0.4rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.gi-add-term, .gi-add-def {
  flex: 1; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 5px; color: #e2e8f0; font-size: 0.72rem; padding: 0.28rem 0.4rem;
}
.gi-add-term:focus, .gi-add-def:focus { border-color: var(--color-primary, #6366f1); outline: none; }
.gi-add-term::placeholder, .gi-add-def::placeholder { color: #4a5068; }
.gi-add-btn {
  background: var(--color-primary, #6366f1); color: #fff; border: none;
  border-radius: 5px; width: 2rem; cursor: pointer; font-size: 0.85rem; font-weight: 700;
  transition: opacity 0.12s;
}
.gi-add-btn:hover { opacity: 0.85; }
.gi-alpha-bar {
  display: flex; gap: 0.15rem; padding: 0.35rem 1rem; flex-wrap: wrap;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.gi-alpha-btn {
  background: rgba(255,255,255,0.05); border: none; color: #64748b;
  width: 1.4rem; height: 1.4rem; border-radius: 3px; cursor: pointer;
  font-size: 0.62rem; font-weight: 600; transition: all 0.1s;
  display: flex; align-items: center; justify-content: center;
}
.gi-alpha-btn:hover { color: var(--color-primary, #6366f1); background: rgba(99,102,241,0.1); }
.gi-list {
  flex: 1; overflow-y: auto; padding: 0.4rem 0.75rem;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.gi-letter-header {
  font-size: 0.75rem; font-weight: 700; color: var(--color-primary, #6366f1);
  padding: 0.5rem 0 0.2rem; border-bottom: 1px solid rgba(99,102,241,0.2);
  margin-bottom: 0.25rem; margin-top: 0.3rem;
}
.gi-term-card {
  background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.06);
  border-radius: 7px; padding: 0.4rem 0.5rem; margin-bottom: 0.3rem;
}
.gi-term-card:hover { background: rgba(255,255,255,0.05); }
.gi-term-row {
  display: flex; align-items: center; gap: 0.35rem; margin-bottom: 0.15rem;
}
.gi-term-name { font-size: 0.78rem; font-weight: 600; color: #e2e8f0; }
.gi-custom-badge {
  font-size: 0.55rem; color: #a855f7; background: rgba(168,85,247,0.12);
  padding: 0.05rem 0.3rem; border-radius: 8px; text-transform: uppercase;
  font-weight: 600; letter-spacing: 0.03em;
}
.gi-line-ref {
  font-size: 0.6rem; color: #64748b; font-family: monospace; margin-left: auto;
}
.gi-del-btn {
  background: none; border: none; color: #475569; cursor: pointer; font-size: 0.8rem;
  padding: 0 0.2rem; line-height: 1; transition: color 0.1s;
}
.gi-del-btn:hover { color: #ef4444; }
.gi-term-def { font-size: 0.72rem; color: #94a3b8; line-height: 1.4; }
.gi-empty {
  text-align: center; padding: 1.5rem 1rem; font-size: 0.78rem; color: #64748b;
  background: rgba(255,255,255,0.03); border-radius: 8px; line-height: 1.5;
}
.gi-actions {
  display: flex; gap: 0.35rem; padding: 0.6rem 1rem;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.gi-insert-btn { flex: 2; }
.gi-copy-btn, .gi-export-btn { flex: 1; }
.gi-insert-btn, .gi-copy-btn, .gi-export-btn {
  padding: 0.4rem 0.4rem; border: none; border-radius: 6px;
  font-size: 0.72rem; cursor: pointer; transition: all 0.12s;
}
.gi-insert-btn { background: var(--color-primary, #6366f1); color: #fff; }
.gi-insert-btn:hover { opacity: 0.85; }
.gi-copy-btn { background: rgba(255,255,255,0.08); color: #c4c9d4; }
.gi-copy-btn:hover { background: rgba(255,255,255,0.12); }
.gi-export-btn { background: rgba(255,255,255,0.05); color: #94a3b8; }
.gi-export-btn:hover { background: rgba(255,255,255,0.1); color: #c4c9d4; }

/* Light theme */
[data-theme="light"] .gi-trigger-btn { color: #475569; border-color: #e2e8f0; }
[data-theme="light"] .gi-panel { background: #fff; border-color: #e2e8f0; box-shadow: -4px 0 24px rgba(0,0,0,0.1); }
[data-theme="light"] .gi-header { border-color: #e2e8f0; }
[data-theme="light"] .gi-header h3 { color: #1e293b; }
[data-theme="light"] .gi-search { background: #f8fafc; border-color: #e2e8f0; color: #1e293b; }
[data-theme="light"] .gi-search::placeholder { color: #94a3b8; }
[data-theme="light"] .gi-add-term, [data-theme="light"] .gi-add-def { background: #f8fafc; border-color: #e2e8f0; color: #1e293b; }
[data-theme="light"] .gi-alpha-btn { color: #94a3b8; background: #f8fafc; }
[data-theme="light"] .gi-letter-header { border-color: rgba(99,102,241,0.15); }
[data-theme="light"] .gi-term-card { background: #f8fafc; border-color: #e2e8f0; }
[data-theme="light"] .gi-term-name { color: #1e293b; }
[data-theme="light"] .gi-term-def { color: #475569; }
[data-theme="light"] .gi-empty { background: #f8fafc; color: #94a3b8; }
[data-theme="light"] .gi-actions { border-color: #e2e8f0; }
[data-theme="light"] .gi-copy-btn { background: #f1f5f9; color: #475569; }
[data-theme="light"] .gi-scan-btn { color: #64748b; border-color: #e2e8f0; background: #f8fafc; }

@media (max-width: 640px) {
  .gi-panel { width: 100%; right: -100%; }
  .gi-add-row { flex-wrap: wrap; }
  .gi-add-term, .gi-add-def { min-width: 40%; }
}

/* ── Document Outline Map ────────────────────────────────── */
.dom-trigger-btn {
  background: transparent; border: 1px solid rgba(255,255,255,0.12); color: #c4c9d4;
  padding: 0.35rem 0.7rem; border-radius: 6px; cursor: pointer; font-size: 0.78rem;
  display: inline-flex; align-items: center; gap: 0.35rem; transition: all 0.15s;
}
.dom-trigger-btn:hover { border-color: rgba(255,255,255,0.25); color: #e2e8f0; }
.dom-trigger-btn.dom-active { border-color: var(--color-primary, #6366f1); color: var(--color-primary, #6366f1); background: rgba(99,102,241,0.08); }
.dom-icon { font-size: 0.9rem; }
.dom-panel {
  position: fixed; top: 0; right: -400px; width: 390px; height: 100vh;
  background: #1a1b2e; border-left: 1px solid rgba(255,255,255,0.08);
  box-shadow: -4px 0 24px rgba(0,0,0,0.35); z-index: var(--z-toast);
  display: flex; flex-direction: column; transition: right 0.25s cubic-bezier(0.4,0,0.2,1);
}
.dom-panel--open { right: 0; }
.dom-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 0.8rem; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.dom-header h3 { margin: 0; font-size: 0.92rem; font-weight: 600; color: #e2e8f0; }
.dom-header-actions { display: flex; align-items: center; gap: 0.25rem; }
.dom-zoom-btn, .dom-refresh-btn {
  background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.08);
  color: #94a3b8; width: 1.6rem; height: 1.6rem; border-radius: 4px;
  cursor: pointer; font-size: 0.75rem; display: flex; align-items: center;
  justify-content: center; transition: all 0.1s;
}
.dom-zoom-btn:hover, .dom-refresh-btn:hover { color: #e2e8f0; border-color: rgba(255,255,255,0.2); }
.dom-close-btn { background: none; border: none; color: #94a3b8; font-size: 1.15rem; cursor: pointer; padding: 0; line-height: 1; }
.dom-close-btn:hover { color: #e2e8f0; }
.dom-view-tabs {
  display: flex; gap: 0.2rem; padding: 0.35rem 0.8rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.dom-vtab {
  background: rgba(255,255,255,0.04); border: 1px solid transparent; color: #64748b;
  padding: 0.2rem 0.6rem; border-radius: 4px; cursor: pointer; font-size: 0.7rem;
  transition: all 0.12s;
}
.dom-vtab:hover { color: #e2e8f0; }
.dom-vtab--active { color: var(--color-primary, #6366f1); border-color: var(--color-primary, #6366f1); background: rgba(99,102,241,0.1); }
.dom-canvas {
  flex: 1; width: 100%; background: rgba(0,0,0,0.15); display: block;
}
.dom-list-view {
  flex: 1; overflow-y: auto; padding: 0.4rem 0;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.dom-list-item {
  display: flex; align-items: center; gap: 0.4rem; padding: 0.3rem 0.5rem;
  cursor: pointer; font-size: 0.76rem; color: #c4c9d4; transition: background 0.1s;
}
.dom-list-item:hover { background: rgba(99,102,241,0.1); }
.dom-list-bullet { font-size: 0.5rem; flex-shrink: 0; }
.dom-list-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dom-list-line { font-size: 0.6rem; color: #475569; font-family: monospace; flex-shrink: 0; }
.dom-empty {
  text-align: center; padding: 1.5rem; font-size: 0.78rem; color: #64748b;
  background: rgba(255,255,255,0.03); border-radius: 8px; margin: 1rem;
}
.dom-actions {
  display: flex; gap: 0.35rem; padding: 0.5rem 0.8rem;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.dom-copy-btn, .dom-export-btn {
  flex: 1; padding: 0.38rem; border: none; border-radius: 6px;
  font-size: 0.72rem; cursor: pointer; transition: all 0.12s;
}
.dom-copy-btn { background: var(--color-primary, #6366f1); color: #fff; }
.dom-copy-btn:hover { opacity: 0.85; }
.dom-export-btn { background: rgba(255,255,255,0.08); color: #c4c9d4; }
.dom-export-btn:hover { background: rgba(255,255,255,0.12); }

/* Light theme */
[data-theme="light"] .dom-trigger-btn { color: #475569; border-color: #e2e8f0; }
[data-theme="light"] .dom-panel { background: #fff; border-color: #e2e8f0; box-shadow: -4px 0 24px rgba(0,0,0,0.1); }
[data-theme="light"] .dom-header { border-color: #e2e8f0; }
[data-theme="light"] .dom-header h3 { color: #1e293b; }
[data-theme="light"] .dom-zoom-btn, [data-theme="light"] .dom-refresh-btn { color: #64748b; border-color: #e2e8f0; background: #f8fafc; }
[data-theme="light"] .dom-vtab { color: #94a3b8; background: #f8fafc; }
[data-theme="light"] .dom-canvas { background: rgba(0,0,0,0.03); }
[data-theme="light"] .dom-list-item { color: #475569; }
[data-theme="light"] .dom-list-item:hover { background: rgba(99,102,241,0.06); }
[data-theme="light"] .dom-empty { background: #f8fafc; color: #94a3b8; }
[data-theme="light"] .dom-actions { border-color: #e2e8f0; }
[data-theme="light"] .dom-export-btn { background: #f1f5f9; color: #475569; }

@media (max-width: 640px) {
  .dom-panel { width: 100%; right: -100%; }
}

/* ── Paragraph Reorder ───────────────────────────────────── */
.pr-trigger-btn {
  background: transparent; border: 1px solid rgba(255,255,255,0.12); color: #c4c9d4;
  padding: 0.35rem 0.7rem; border-radius: 6px; cursor: pointer; font-size: 0.78rem;
  display: inline-flex; align-items: center; gap: 0.35rem; transition: all 0.15s;
}
.pr-trigger-btn:hover { border-color: rgba(255,255,255,0.25); color: #e2e8f0; }
.pr-trigger-btn.pr-active { border-color: var(--color-primary, #6366f1); color: var(--color-primary, #6366f1); background: rgba(99,102,241,0.08); }
.pr-icon { font-size: 0.9rem; }
.pr-panel {
  position: fixed; top: 0; right: -380px; width: 370px; height: 100vh;
  background: #1a1b2e; border-left: 1px solid rgba(255,255,255,0.08);
  box-shadow: -4px 0 24px rgba(0,0,0,0.35); z-index: var(--z-toast);
  display: flex; flex-direction: column; transition: right 0.25s cubic-bezier(0.4,0,0.2,1);
}
.pr-panel--open { right: 0; }
.pr-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.65rem 0.8rem; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.pr-header h3 { margin: 0; font-size: 0.92rem; font-weight: 600; color: #e2e8f0; }
.pr-header-actions { display: flex; align-items: center; gap: 0.25rem; }
.pr-undo-btn, .pr-refresh-btn {
  background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.08);
  color: #94a3b8; width: 1.6rem; height: 1.6rem; border-radius: 4px;
  cursor: pointer; font-size: 0.75rem; display: flex; align-items: center;
  justify-content: center; transition: all 0.1s;
}
.pr-undo-btn:hover:not(:disabled), .pr-refresh-btn:hover { color: #e2e8f0; border-color: rgba(255,255,255,0.2); }
.pr-undo-btn:disabled { opacity: 0.35; cursor: default; }
.pr-close-btn { background: none; border: none; color: #94a3b8; font-size: 1.15rem; cursor: pointer; padding: 0; line-height: 1; }
.pr-close-btn:hover { color: #e2e8f0; }
.pr-hint {
  padding: 0.4rem 0.8rem; font-size: 0.7rem; color: #64748b;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.pr-list {
  flex: 1; overflow-y: auto; padding: 0.4rem 0.5rem;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.pr-item {
  display: flex; align-items: flex-start; gap: 0.35rem; padding: 0.45rem 0.4rem;
  background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.06);
  border-radius: 7px; margin-bottom: 0.3rem; cursor: grab; transition: all 0.15s;
}
.pr-item:hover { background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.1); }
.pr-item.pr-dragging { opacity: 0.4; border-color: var(--color-primary, #6366f1); }
.pr-item.pr-drag-over { border-color: var(--color-primary, #6366f1); background: rgba(99,102,241,0.1); box-shadow: 0 0 0 2px rgba(99,102,241,0.2); }
.pr-handle {
  color: #475569; font-size: 0.85rem; cursor: grab; flex-shrink: 0;
  padding: 0.1rem; line-height: 1; user-select: none;
}
.pr-item-content { flex: 1; min-width: 0; }
.pr-item-num {
  display: inline-block; background: var(--color-primary, #6366f1); color: #fff;
  font-size: 0.6rem; font-weight: 700; width: 1.2rem; height: 1.2rem; border-radius: 50%;
  text-align: center; line-height: 1.2rem; margin-right: 0.3rem; vertical-align: middle;
}
.pr-item-text {
  font-size: 0.73rem; color: #c4c9d4; line-height: 1.35;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.pr-item-actions { display: flex; flex-direction: column; gap: 0.1rem; flex-shrink: 0; }
.pr-item-actions button {
  background: none; border: 1px solid rgba(255,255,255,0.06); color: #64748b;
  width: 1.3rem; height: 1.3rem; border-radius: 3px; cursor: pointer;
  font-size: 0.55rem; display: flex; align-items: center; justify-content: center;
  transition: all 0.1s;
}
.pr-item-actions button:hover:not(:disabled) { color: #e2e8f0; border-color: rgba(255,255,255,0.2); }
.pr-item-actions button:disabled { opacity: 0.25; cursor: default; }
.pr-empty {
  text-align: center; padding: 1.5rem; font-size: 0.78rem; color: #64748b;
  background: rgba(255,255,255,0.03); border-radius: 8px;
}
.pr-actions {
  display: flex; gap: 0.35rem; padding: 0.55rem 0.8rem;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.pr-apply-btn, .pr-cancel-btn {
  flex: 1; padding: 0.4rem; border: none; border-radius: 6px;
  font-size: 0.73rem; cursor: pointer; transition: all 0.12s;
}
.pr-apply-btn { background: var(--color-primary, #6366f1); color: #fff; }
.pr-apply-btn:hover { opacity: 0.85; }
.pr-cancel-btn { background: rgba(255,255,255,0.08); color: #c4c9d4; }
.pr-cancel-btn:hover { background: rgba(255,255,255,0.12); }

/* Light theme */
[data-theme="light"] .pr-trigger-btn { color: #475569; border-color: #e2e8f0; }
[data-theme="light"] .pr-panel { background: #fff; border-color: #e2e8f0; box-shadow: -4px 0 24px rgba(0,0,0,0.1); }
[data-theme="light"] .pr-header { border-color: #e2e8f0; }
[data-theme="light"] .pr-header h3 { color: #1e293b; }
[data-theme="light"] .pr-hint { color: #94a3b8; border-color: #f1f5f9; }
[data-theme="light"] .pr-item { background: #f8fafc; border-color: #e2e8f0; }
[data-theme="light"] .pr-item:hover { background: #f1f5f9; }
[data-theme="light"] .pr-item-text { color: #475569; }
[data-theme="light"] .pr-handle { color: #94a3b8; }
[data-theme="light"] .pr-empty { background: #f8fafc; color: #94a3b8; }
[data-theme="light"] .pr-actions { border-color: #e2e8f0; }
[data-theme="light"] .pr-cancel-btn { background: #f1f5f9; color: #475569; }
[data-theme="light"] .pr-undo-btn, [data-theme="light"] .pr-refresh-btn { color: #64748b; border-color: #e2e8f0; background: #f8fafc; }

@media (max-width: 640px) {
  .pr-panel { width: 100%; right: -100%; }
  .pr-item-text { -webkit-line-clamp: 1; }
}

/* ── Voice Recorder Notes ────────────────────────────────── */
.vr-trigger-btn {
  background: transparent; border: 1px solid rgba(255,255,255,0.12); color: #c4c9d4;
  padding: 0.35rem 0.7rem; border-radius: 6px; cursor: pointer; font-size: 0.78rem;
  display: inline-flex; align-items: center; gap: 0.35rem; transition: all 0.15s;
}
.vr-trigger-btn:hover { border-color: rgba(255,255,255,0.25); color: #e2e8f0; }
.vr-trigger-btn.vr-active { border-color: var(--color-primary, #6366f1); color: var(--color-primary, #6366f1); background: rgba(99,102,241,0.08); }
.vr-icon { font-size: 0.9rem; }
.vr-panel {
  position: fixed; top: 0; right: -380px; width: 370px; height: 100vh;
  background: #1a1b2e; border-left: 1px solid rgba(255,255,255,0.08);
  box-shadow: -4px 0 24px rgba(0,0,0,0.35); z-index: var(--z-toast);
  display: flex; flex-direction: column; transition: right 0.25s cubic-bezier(0.4,0,0.2,1);
}
.vr-panel--open { right: 0; }
.vr-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.65rem 0.8rem; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.vr-header h3 { margin: 0; font-size: 0.92rem; font-weight: 600; color: #e2e8f0; }
.vr-header-actions { display: flex; align-items: center; gap: 0.5rem; }
.vr-count {
  background: var(--color-primary, #6366f1); color: #fff; font-size: 0.6rem; font-weight: 700;
  padding: 0.1rem 0.35rem; border-radius: 10px; min-width: 1.1rem; text-align: center;
}
.vr-close-btn { background: none; border: none; color: #94a3b8; font-size: 1.15rem; cursor: pointer; padding: 0; line-height: 1; }
.vr-close-btn:hover { color: #e2e8f0; }
.vr-recorder {
  padding: 0.8rem; border-bottom: 1px solid rgba(255,255,255,0.06);
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
}
.vr-timer {
  font-size: 1.8rem; font-weight: 700; color: #e2e8f0; font-family: monospace;
  letter-spacing: 0.08em;
}
.vr-rec-controls { display: flex; gap: 0.6rem; }
.vr-rec-btn, .vr-stop-btn {
  width: 2.8rem; height: 2.8rem; border-radius: 50%; border: 2px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.05); color: #e2e8f0; font-size: 1.1rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.vr-rec-btn:hover:not(:disabled) { border-color: #ef4444; background: rgba(239,68,68,0.1); }
.vr-rec-btn.vr-recording { border-color: #ef4444; background: rgba(239,68,68,0.2); animation: vr-pulse 1s ease-in-out infinite; }
.vr-stop-btn:hover:not(:disabled) { border-color: #94a3b8; background: rgba(255,255,255,0.1); }
.vr-rec-btn:disabled, .vr-stop-btn:disabled { opacity: 0.3; cursor: default; }
@keyframes vr-pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.3); } 50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); } }
.vr-rec-status { font-size: 0.7rem; color: #64748b; }
.vr-tag-row { width: 100%; }
.vr-tag-input {
  width: 100%; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 5px; color: #e2e8f0; font-size: 0.73rem; padding: 0.3rem 0.5rem;
}
.vr-tag-input:focus { border-color: var(--color-primary, #6366f1); outline: none; }
.vr-tag-input::placeholder { color: #4a5068; }
.vr-notes-list {
  flex: 1; overflow-y: auto; padding: 0.4rem 0.6rem;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.vr-note-card {
  background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px; padding: 0.5rem; margin-bottom: 0.4rem;
}
.vr-note-card:hover { background: rgba(255,255,255,0.05); }
.vr-note-header {
  display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.3rem;
}
.vr-note-tag { font-size: 0.78rem; font-weight: 600; color: #e2e8f0; flex: 1; }
.vr-note-dur { font-size: 0.65rem; color: #64748b; font-family: monospace; }
.vr-note-del {
  background: none; border: none; color: #475569; cursor: pointer; font-size: 0.8rem;
  padding: 0 0.2rem; transition: color 0.1s;
}
.vr-note-del:hover { color: #ef4444; }
.vr-audio {
  width: 100%; height: 28px; margin: 0.25rem 0; border-radius: 4px;
}
.vr-note-meta {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.25rem;
}
.vr-note-date { font-size: 0.62rem; color: #475569; }
.vr-insert-btn {
  background: none; border: 1px solid rgba(255,255,255,0.08); color: #94a3b8;
  padding: 0.15rem 0.4rem; border-radius: 4px; cursor: pointer; font-size: 0.62rem;
  transition: all 0.1s;
}
.vr-insert-btn:hover { color: #e2e8f0; border-color: rgba(255,255,255,0.2); }
.vr-transcription {
  width: 100%; background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08);
  border-radius: 5px; color: #c4c9d4; font-size: 0.72rem; padding: 0.3rem 0.4rem;
  resize: vertical; min-height: 2rem; font-family: inherit; line-height: 1.35;
}
.vr-transcription:focus { border-color: var(--color-primary, #6366f1); outline: none; }
.vr-transcription::placeholder { color: #4a5068; }
.vr-empty {
  text-align: center; padding: 1.5rem; font-size: 0.78rem; color: #64748b;
  background: rgba(255,255,255,0.03); border-radius: 8px;
}
.vr-actions {
  display: flex; gap: 0.35rem; padding: 0.55rem 0.8rem;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.vr-export-btn, .vr-clear-btn {
  flex: 1; padding: 0.38rem; border: none; border-radius: 6px;
  font-size: 0.72rem; cursor: pointer; transition: all 0.12s;
}
.vr-export-btn { background: var(--color-primary, #6366f1); color: #fff; }
.vr-export-btn:hover { opacity: 0.85; }
.vr-clear-btn { background: rgba(239,68,68,0.1); color: #ef4444; }
.vr-clear-btn:hover { background: rgba(239,68,68,0.2); }

/* Light theme */
[data-theme="light"] .vr-trigger-btn { color: #475569; border-color: #e2e8f0; }
[data-theme="light"] .vr-panel { background: #fff; border-color: #e2e8f0; box-shadow: -4px 0 24px rgba(0,0,0,0.1); }
[data-theme="light"] .vr-header { border-color: #e2e8f0; }
[data-theme="light"] .vr-header h3 { color: #1e293b; }
[data-theme="light"] .vr-timer { color: #1e293b; }
[data-theme="light"] .vr-rec-btn, [data-theme="light"] .vr-stop-btn { border-color: #e2e8f0; background: #f8fafc; }
[data-theme="light"] .vr-tag-input { background: #f8fafc; border-color: #e2e8f0; color: #1e293b; }
[data-theme="light"] .vr-note-card { background: #f8fafc; border-color: #e2e8f0; }
[data-theme="light"] .vr-note-tag { color: #1e293b; }
[data-theme="light"] .vr-transcription { background: #fff; border-color: #e2e8f0; color: #1e293b; }
[data-theme="light"] .vr-empty { background: #f8fafc; color: #94a3b8; }
[data-theme="light"] .vr-actions { border-color: #e2e8f0; }

@media (max-width: 640px) {
  .vr-panel { width: 100%; right: -100%; }
}

/* ── Citation Preview Tooltip ─────────────────────────────────────── */

.cpt-tooltip {
  position: fixed;
  z-index: var(--z-tooltip);
  max-width: 380px;
  min-width: 240px;
  background: #1e1e2e;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.45);
  padding: 0;
  pointer-events: auto;
  animation: cpt-fadeIn 0.15s ease;
}
@keyframes cpt-fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.cpt-content { padding: 12px 14px; }

.cpt-formatted {
  font-size: 0.82rem;
  color: #e2e8f0;
  line-height: 1.55;
  margin-bottom: 6px;
}
.cpt-formatted em { color: #a5b4fc; font-style: italic; }

.cpt-abstract {
  font-size: 0.75rem;
  color: #94a3b8;
  line-height: 1.5;
  margin-bottom: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.cpt-doi {
  font-size: 0.72rem;
  color: #6366f1;
  margin-bottom: 8px;
  font-family: 'Fira Code', monospace;
}

.cpt-actions {
  display: flex;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.cpt-copy-btn, .cpt-goto-btn {
  padding: 4px 12px;
  border-radius: 5px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04);
  color: #94a3b8;
  font-size: 0.72rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.cpt-copy-btn:hover { background: rgba(99,102,241,0.15); color: #a5b4fc; border-color: rgba(99,102,241,0.3); }
.cpt-goto-btn:hover { background: rgba(16,185,129,0.15); color: #6ee7b7; border-color: rgba(16,185,129,0.3); }

.cpt-unknown {
  font-size: 0.82rem;
  color: #fbbf24;
  line-height: 1.5;
}
.cpt-unknown-icon { font-size: 1rem; }
.cpt-unknown strong { color: #f59e0b; }
.cpt-add-hint {
  font-size: 0.72rem;
  color: #64748b;
  margin-top: 4px;
}

/* Light theme */
[data-theme="light"] .cpt-tooltip { background: #ffffff; border-color: rgba(0,0,0,0.1); box-shadow: 0 12px 40px rgba(0,0,0,0.12); }
[data-theme="light"] .cpt-formatted { color: #1e293b; }
[data-theme="light"] .cpt-formatted em { color: #6366f1; }
[data-theme="light"] .cpt-abstract { color: #64748b; border-top-color: rgba(0,0,0,0.06); }
[data-theme="light"] .cpt-actions { border-top-color: rgba(0,0,0,0.06); }
[data-theme="light"] .cpt-copy-btn, [data-theme="light"] .cpt-goto-btn { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.1); color: #64748b; }
[data-theme="light"] .cpt-copy-btn:hover { background: rgba(99,102,241,0.08); color: #6366f1; }
[data-theme="light"] .cpt-goto-btn:hover { background: rgba(16,185,129,0.08); color: #059669; }
[data-theme="light"] .cpt-unknown { color: #d97706; }
[data-theme="light"] .cpt-add-hint { color: #94a3b8; }

@media (max-width: 640px) {
  .cpt-tooltip { max-width: 92vw; min-width: 200px; }
}

/* ── Auto-Complete Suggestions ────────────────────────────────────── */

.acs-dropdown {
  position: fixed;
  z-index: var(--z-max);
  min-width: 220px;
  max-width: 340px;
  max-height: 240px;
  overflow-y: auto;
  background: #1e1e2e;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  padding: 4px 0;
  animation: acs-fadeIn 0.12s ease;
}
@keyframes acs-fadeIn { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: translateY(0); } }

.acs-item {
  padding: 6px 12px;
  font-size: 0.82rem;
  color: #cbd5e1;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.1s;
  line-height: 1.4;
}
.acs-item strong { color: #a5b4fc; font-weight: 600; }
.acs-item.acs-active { background: rgba(99,102,241,0.18); color: #e2e8f0; }
.acs-item:hover { background: rgba(99,102,241,0.12); }

.acs-badge {
  margin-left: auto;
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 3px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}
.acs-badge-phrase {
  background: rgba(99,102,241,0.15);
  color: #818cf8;
  border: 1px solid rgba(99,102,241,0.25);
}

/* Light theme */
[data-theme="light"] .acs-dropdown { background: #ffffff; border-color: rgba(0,0,0,0.1); box-shadow: 0 8px 32px rgba(0,0,0,0.12); }
[data-theme="light"] .acs-item { color: #334155; }
[data-theme="light"] .acs-item strong { color: #6366f1; }
[data-theme="light"] .acs-item.acs-active { background: rgba(99,102,241,0.1); color: #1e293b; }
[data-theme="light"] .acs-item:hover { background: rgba(99,102,241,0.06); }
[data-theme="light"] .acs-badge-phrase { background: rgba(99,102,241,0.08); color: #6366f1; border-color: rgba(99,102,241,0.2); }

@media (max-width: 640px) {
  .acs-dropdown { max-width: 90vw; min-width: 180px; }
}

/* ── Document Compare ─────────────────────────────────────────────── */

.dc-trigger-btn {
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid rgba(99,102,241,0.3);
  background: rgba(99,102,241,0.08);
  color: #a5b4fc;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.dc-trigger-btn:hover { background: rgba(99,102,241,0.18); color: #c7d2fe; }

.dc-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: var(--z-popover);
  display: flex; align-items: center; justify-content: center;
  animation: dc-fadeIn 0.2s ease;
}
@keyframes dc-fadeIn { from { opacity: 0; } to { opacity: 1; } }

.dc-modal {
  background: #1e1e2e;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  width: 92vw; max-width: 1100px;
  max-height: 88vh;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  overflow: hidden;
}
.dc-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.dc-title { margin: 0; font-size: 1rem; color: #e2e8f0; font-weight: 600; }
.dc-stats-bar { display: flex; gap: 10px; margin-left: auto; }
.dc-stat { font-size: 0.72rem; padding: 2px 8px; border-radius: 4px; font-weight: 600; }
.dc-stat-added { color: #4ade80; background: rgba(74,222,128,0.1); }
.dc-stat-removed { color: #f87171; background: rgba(248,113,113,0.1); }
.dc-stat-changed { color: #fbbf24; background: rgba(251,191,36,0.1); }
.dc-stat-unchanged { color: #94a3b8; background: rgba(148,163,184,0.06); }
.dc-close-btn { background: none; border: none; color: #94a3b8; font-size: 1.1rem; cursor: pointer; padding: 4px 8px; border-radius: 4px; }
.dc-close-btn:hover { background: rgba(255,255,255,0.08); color: #e2e8f0; }

.dc-controls { padding: 10px 16px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.dc-version-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dc-label { font-size: 0.78rem; color: #94a3b8; font-weight: 600; }
.dc-select { padding: 4px 10px; border-radius: 5px; border: 1px solid rgba(255,255,255,0.1); background: rgba(0,0,0,0.3); color: #e2e8f0; font-size: 0.78rem; }
.dc-compare-btn { padding: 5px 16px; border-radius: 5px; border: none; background: #6366f1; color: #fff; font-size: 0.8rem; cursor: pointer; }
.dc-compare-btn:hover { background: #4f46e5; }
.dc-paste-row { display: flex; gap: 8px; margin-top: 8px; }
.dc-paste-area { flex: 1; min-height: 60px; padding: 8px; background: rgba(0,0,0,0.25); border: 1px solid rgba(255,255,255,0.06); border-radius: 6px; color: #e2e8f0; font-size: 0.78rem; font-family: 'Fira Code', monospace; resize: vertical; }

.dc-diff-area { display: flex; flex: 1; overflow: hidden; min-height: 0; }
.dc-diff-left, .dc-diff-right { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.dc-diff-left { border-right: 1px solid rgba(255,255,255,0.06); }
.dc-diff-header { padding: 6px 12px; font-size: 0.75rem; color: #94a3b8; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 1px solid rgba(255,255,255,0.04); background: rgba(0,0,0,0.15); }
.dc-diff-content { flex: 1; overflow-y: auto; font-family: 'Fira Code', monospace; font-size: 0.78rem; line-height: 1.6; }

.dc-line { display: flex; padding: 1px 8px; min-height: 1.6em; }
.dc-line-num { width: 36px; text-align: right; color: #475569; font-size: 0.7rem; padding-right: 8px; flex-shrink: 0; user-select: none; }
.dc-text { flex: 1; white-space: pre-wrap; word-break: break-word; }
.dc-unchanged { color: #94a3b8; }
.dc-removed { background: rgba(248,113,113,0.08); color: #fca5a5; }
.dc-added { background: rgba(74,222,128,0.08); color: #86efac; }
.dc-changed-old { background: rgba(251,191,36,0.06); color: #fde68a; text-decoration: line-through; text-decoration-color: rgba(251,191,36,0.3); }
.dc-changed-new { background: rgba(99,102,241,0.08); color: #c7d2fe; }
.dc-empty { color: transparent; }

.dc-footer { display: flex; gap: 8px; padding: 10px 16px; border-top: 1px solid rgba(255,255,255,0.06); }
.dc-export-btn, .dc-copy-btn { padding: 5px 14px; border-radius: 5px; border: 1px solid rgba(255,255,255,0.1); background: rgba(255,255,255,0.04); color: #94a3b8; font-size: 0.78rem; cursor: pointer; }
.dc-export-btn:hover, .dc-copy-btn:hover { background: rgba(255,255,255,0.08); color: #e2e8f0; }

/* Light theme */
[data-theme="light"] .dc-trigger-btn { color: #6366f1; background: rgba(99,102,241,0.06); border-color: rgba(99,102,241,0.2); }
[data-theme="light"] .dc-modal { background: #fff; border-color: rgba(0,0,0,0.08); box-shadow: 0 20px 60px rgba(0,0,0,0.12); }
[data-theme="light"] .dc-header, [data-theme="light"] .dc-controls, [data-theme="light"] .dc-footer { border-color: rgba(0,0,0,0.06); }
[data-theme="light"] .dc-title { color: #1e293b; }
[data-theme="light"] .dc-select { background: #f8fafc; border-color: rgba(0,0,0,0.1); color: #334155; }
[data-theme="light"] .dc-paste-area { background: #f8fafc; border-color: rgba(0,0,0,0.1); color: #334155; }
[data-theme="light"] .dc-diff-header { background: #f1f5f9; color: #64748b; }
[data-theme="light"] .dc-diff-left { border-right-color: rgba(0,0,0,0.06); }
[data-theme="light"] .dc-unchanged { color: #64748b; }
[data-theme="light"] .dc-removed { background: rgba(239,68,68,0.06); color: #dc2626; }
[data-theme="light"] .dc-added { background: rgba(34,197,94,0.06); color: #16a34a; }
[data-theme="light"] .dc-changed-old { background: rgba(234,179,8,0.06); color: #a16207; }
[data-theme="light"] .dc-changed-new { background: rgba(99,102,241,0.06); color: #4f46e5; }
[data-theme="light"] .dc-export-btn, [data-theme="light"] .dc-copy-btn { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.1); color: #64748b; }

@media (max-width: 768px) {
  .dc-modal { width: 98vw; max-height: 94vh; }
  .dc-diff-area { flex-direction: column; }
  .dc-diff-left { border-right: none; border-bottom: 1px solid rgba(255,255,255,0.06); max-height: 40%; }
  .dc-version-row { flex-direction: column; align-items: stretch; }
  .dc-paste-row { flex-direction: column; }
}

/* ── Word Frequency Analyzer ──────────────────────────────────────── */

.wfa-trigger-btn {
  padding: 5px 12px; border-radius: 6px;
  border: 1px solid rgba(99,102,241,0.3); background: rgba(99,102,241,0.08);
  color: #a5b4fc; font-size: 0.8rem; cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.wfa-trigger-btn:hover { background: rgba(99,102,241,0.18); color: #c7d2fe; }

.wfa-panel {
  position: fixed; top: 0; right: -380px; width: 370px; height: 100vh;
  background: #1a1b2e; border-left: 1px solid rgba(255,255,255,0.06);
  z-index: var(--z-overlay); display: flex; flex-direction: column;
  transition: right 0.3s ease; box-shadow: -4px 0 24px rgba(0,0,0,0.35);
}
.wfa-panel.wfa-panel-open { right: 0; }

.wfa-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid rgba(255,255,255,0.06);
}
.wfa-title { margin: 0; font-size: 0.95rem; color: #e2e8f0; font-weight: 600; }
.wfa-close-btn { background: none; border: none; color: #94a3b8; font-size: 1.1rem; cursor: pointer; padding: 4px 8px; border-radius: 4px; }
.wfa-close-btn:hover { background: rgba(255,255,255,0.08); color: #e2e8f0; }

.wfa-controls {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.04); flex-wrap: wrap;
}
.wfa-toggle-label, .wfa-top-label { font-size: 0.75rem; color: #94a3b8; display: flex; align-items: center; gap: 4px; }
.wfa-stop-toggle { accent-color: #6366f1; }
.wfa-top-input { width: 48px; padding: 2px 6px; border-radius: 4px; border: 1px solid rgba(255,255,255,0.1); background: rgba(0,0,0,0.3); color: #e2e8f0; font-size: 0.75rem; text-align: center; }
.wfa-refresh-btn { padding: 3px 10px; border-radius: 4px; border: 1px solid rgba(255,255,255,0.1); background: rgba(255,255,255,0.04); color: #94a3b8; font-size: 0.72rem; cursor: pointer; margin-left: auto; }
.wfa-refresh-btn:hover { background: rgba(255,255,255,0.08); color: #e2e8f0; }

.wfa-summary { display: flex; gap: 12px; padding: 8px 16px; border-bottom: 1px solid rgba(255,255,255,0.04); }
.wfa-stat { font-size: 0.75rem; color: #94a3b8; }
.wfa-stat strong { color: #e2e8f0; }

.wfa-chart { flex: 1; overflow-y: auto; padding: 8px 16px; }

.wfa-bar-row {
  display: flex; align-items: center; gap: 8px; padding: 3px 0;
  cursor: pointer; border-radius: 4px; transition: background 0.1s;
}
.wfa-bar-row:hover { background: rgba(99,102,241,0.06); }
.wfa-bar-row.wfa-bar-active { background: rgba(99,102,241,0.12); }
.wfa-bar-label { width: 80px; font-size: 0.75rem; color: #cbd5e1; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex-shrink: 0; }
.wfa-bar-track { flex: 1; height: 14px; background: rgba(255,255,255,0.04); border-radius: 3px; overflow: hidden; }
.wfa-bar-fill { height: 100%; background: linear-gradient(90deg, #6366f1, #818cf8); border-radius: 3px; transition: width 0.3s ease; }
.wfa-bar-count { width: 32px; font-size: 0.72rem; color: #94a3b8; text-align: left; flex-shrink: 0; }

.wfa-hl { background: rgba(99,102,241,0.25); border-radius: 2px; padding: 0 1px; }

.wfa-export-row { display: flex; gap: 8px; padding: 10px 16px; border-top: 1px solid rgba(255,255,255,0.06); }
.wfa-export-btn { padding: 5px 14px; border-radius: 5px; border: 1px solid rgba(255,255,255,0.1); background: rgba(255,255,255,0.04); color: #94a3b8; font-size: 0.75rem; cursor: pointer; }
.wfa-export-btn:hover { background: rgba(255,255,255,0.08); color: #e2e8f0; }

/* Light theme */
[data-theme="light"] .wfa-trigger-btn { color: #6366f1; background: rgba(99,102,241,0.06); border-color: rgba(99,102,241,0.2); }
[data-theme="light"] .wfa-panel { background: #fff; border-left-color: rgba(0,0,0,0.08); box-shadow: -4px 0 24px rgba(0,0,0,0.1); }
[data-theme="light"] .wfa-header, [data-theme="light"] .wfa-controls, [data-theme="light"] .wfa-summary { border-color: rgba(0,0,0,0.06); }
[data-theme="light"] .wfa-title { color: #1e293b; }
[data-theme="light"] .wfa-bar-label { color: #334155; }
[data-theme="light"] .wfa-bar-track { background: rgba(0,0,0,0.04); }
[data-theme="light"] .wfa-bar-count { color: #64748b; }
[data-theme="light"] .wfa-bar-row:hover { background: rgba(99,102,241,0.04); }
[data-theme="light"] .wfa-bar-row.wfa-bar-active { background: rgba(99,102,241,0.08); }
[data-theme="light"] .wfa-hl { background: rgba(99,102,241,0.15); }
[data-theme="light"] .wfa-top-input { background: #f8fafc; border-color: rgba(0,0,0,0.1); color: #334155; }
[data-theme="light"] .wfa-export-row { border-color: rgba(0,0,0,0.06); }
[data-theme="light"] .wfa-export-btn { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.1); color: #64748b; }

@media (max-width: 640px) {
  .wfa-panel { width: 100%; right: -100%; }
}

/* ── Sentence Complexity Scorer ───────────────────────────────────── */

.scs-trigger-btn {
  padding: 5px 12px; border-radius: 6px;
  border: 1px solid rgba(99,102,241,0.3); background: rgba(99,102,241,0.08);
  color: #a5b4fc; font-size: 0.8rem; cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.scs-trigger-btn:hover { background: rgba(99,102,241,0.18); color: #c7d2fe; }

.scs-panel {
  position: fixed; top: 0; right: -380px; width: 370px; height: 100vh;
  background: #1a1b2e; border-left: 1px solid rgba(255,255,255,0.06);
  z-index: var(--z-overlay); display: flex; flex-direction: column;
  transition: right 0.3s ease; box-shadow: -4px 0 24px rgba(0,0,0,0.35);
}
.scs-panel.scs-panel-open { right: 0; }

.scs-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid rgba(255,255,255,0.06);
}
.scs-title { margin: 0; font-size: 0.95rem; color: #e2e8f0; font-weight: 600; }
.scs-close-btn { background: none; border: none; color: #94a3b8; font-size: 1.1rem; cursor: pointer; padding: 4px 8px; border-radius: 4px; }
.scs-close-btn:hover { background: rgba(255,255,255,0.08); color: #e2e8f0; }

.scs-overview { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-bottom: 1px solid rgba(255,255,255,0.04); }
.scs-score-ring { flex-shrink: 0; }
.scs-overview-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.scs-ov-stat { display: flex; flex-direction: column; }
.scs-ov-stat strong { font-size: 0.85rem; color: #e2e8f0; }
.scs-ov-stat span { font-size: 0.68rem; color: #64748b; }

.scs-histogram { padding: 12px 16px; border-bottom: 1px solid rgba(255,255,255,0.04); }
.scs-hist-bars { display: flex; gap: 12px; align-items: flex-end; height: 60px; }
.scs-hist-col { flex: 1; display: flex; flex-direction: column; align-items: center; }
.scs-hist-bar-wrap { width: 100%; height: 50px; display: flex; align-items: flex-end; }
.scs-hist-bar { width: 100%; border-radius: 3px 3px 0 0; min-height: 2px; transition: height 0.3s; }
.scs-hist-easy { background: #4ade80; }
.scs-hist-medium { background: #fbbf24; }
.scs-hist-hard { background: #fb923c; }
.scs-hist-vhard { background: #f87171; }
.scs-hist-label { font-size: 0.7rem; color: #94a3b8; margin-top: 4px; }

.scs-legend { display: flex; gap: 10px; padding: 6px 16px; flex-wrap: wrap; border-bottom: 1px solid rgba(255,255,255,0.04); }
.scs-leg { font-size: 0.68rem; color: #94a3b8; }
.scs-leg-easy { color: #4ade80; }
.scs-leg-medium { color: #fbbf24; }
.scs-leg-hard { color: #fb923c; }
.scs-leg-vhard { color: #f87171; }

.scs-list { flex: 1; overflow-y: auto; padding: 8px 16px; }
.scs-list-header { font-size: 0.78rem; color: #94a3b8; font-weight: 600; margin-bottom: 6px; }
.scs-list-item { padding: 6px 8px; margin-bottom: 4px; border-radius: 6px; border-left: 3px solid; font-size: 0.78rem; line-height: 1.45; }
.scs-item-hard { border-color: #fb923c; background: rgba(251,146,60,0.06); }
.scs-item-vhard { border-color: #f87171; background: rgba(248,113,113,0.06); }
.scs-item-badge { display: inline-block; font-size: 0.65rem; padding: 1px 6px; border-radius: 3px; background: rgba(255,255,255,0.06); color: #94a3b8; margin-right: 6px; font-weight: 600; }
.scs-item-text { color: #cbd5e1; }
.scs-list-empty { font-size: 0.78rem; color: #4ade80; padding: 12px; text-align: center; }

.scs-hl { border-radius: 2px; padding: 0 1px; }
.scs-hl-medium { background: rgba(251,191,36,0.15); }
.scs-hl-hard { background: rgba(251,146,60,0.2); }
.scs-hl-vhard { background: rgba(248,113,113,0.25); }

.scs-footer { display: flex; gap: 8px; padding: 10px 16px; border-top: 1px solid rgba(255,255,255,0.06); }
.scs-highlight-btn, .scs-refresh-btn { padding: 5px 14px; border-radius: 5px; border: 1px solid rgba(255,255,255,0.1); background: rgba(255,255,255,0.04); color: #94a3b8; font-size: 0.75rem; cursor: pointer; }
.scs-highlight-btn:hover { background: rgba(99,102,241,0.15); color: #a5b4fc; border-color: rgba(99,102,241,0.3); }
.scs-refresh-btn:hover { background: rgba(255,255,255,0.08); color: #e2e8f0; }

/* Light theme */
[data-theme="light"] .scs-trigger-btn { color: #6366f1; background: rgba(99,102,241,0.06); border-color: rgba(99,102,241,0.2); }
[data-theme="light"] .scs-panel { background: #fff; border-left-color: rgba(0,0,0,0.08); box-shadow: -4px 0 24px rgba(0,0,0,0.1); }
[data-theme="light"] .scs-header, [data-theme="light"] .scs-overview, [data-theme="light"] .scs-histogram, [data-theme="light"] .scs-legend, [data-theme="light"] .scs-footer { border-color: rgba(0,0,0,0.06); }
[data-theme="light"] .scs-title { color: #1e293b; }
[data-theme="light"] .scs-ov-stat strong { color: #1e293b; }
[data-theme="light"] .scs-item-text { color: #334155; }
[data-theme="light"] .scs-item-badge { background: rgba(0,0,0,0.04); color: #64748b; }
[data-theme="light"] .scs-hl-medium { background: rgba(251,191,36,0.1); }
[data-theme="light"] .scs-hl-hard { background: rgba(251,146,60,0.12); }
[data-theme="light"] .scs-hl-vhard { background: rgba(248,113,113,0.15); }
[data-theme="light"] .scs-highlight-btn, [data-theme="light"] .scs-refresh-btn { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.1); color: #64748b; }

@media (max-width: 640px) {
  .scs-panel { width: 100%; right: -100%; }
  .scs-overview { flex-direction: column; align-items: center; }
}

/* ── Transition Word Helper ───────────────────────────────────────── */

.twh-trigger-btn {
  padding: 5px 12px; border-radius: 6px;
  border: 1px solid rgba(99,102,241,0.3); background: rgba(99,102,241,0.08);
  color: #a5b4fc; font-size: 0.8rem; cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.twh-trigger-btn:hover { background: rgba(99,102,241,0.18); color: #c7d2fe; }

.twh-panel {
  position: fixed; top: 0; right: -380px; width: 370px; height: 100vh;
  background: #1a1b2e; border-left: 1px solid rgba(255,255,255,0.06);
  z-index: var(--z-overlay); display: flex; flex-direction: column;
  transition: right 0.3s ease; box-shadow: -4px 0 24px rgba(0,0,0,0.35);
}
.twh-panel.twh-panel-open { right: 0; }

.twh-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid rgba(255,255,255,0.06);
}
.twh-title { margin: 0; font-size: 0.95rem; color: #e2e8f0; font-weight: 600; }
.twh-close-btn { background: none; border: none; color: #94a3b8; font-size: 1.1rem; cursor: pointer; padding: 4px 8px; border-radius: 4px; }
.twh-close-btn:hover { background: rgba(255,255,255,0.08); color: #e2e8f0; }

.twh-summary { display: flex; align-items: center; gap: 14px; padding: 12px 16px; border-bottom: 1px solid rgba(255,255,255,0.04); }
.twh-sum-ring { flex-shrink: 0; }
.twh-sum-stats { display: flex; flex-direction: column; gap: 3px; }
.twh-sum-stat { font-size: 0.78rem; color: #94a3b8; }
.twh-sum-stat strong { color: #e2e8f0; }
.twh-sum-gap strong { color: #fbbf24; }

.twh-gaps-list { flex: 1; overflow-y: auto; padding: 8px 16px; }
.twh-gaps-header { font-size: 0.78rem; color: #94a3b8; font-weight: 600; margin-bottom: 8px; }
.twh-no-gaps { text-align: center; padding: 18px; color: #4ade80; font-size: 0.82rem; }

.twh-gap-card {
  background: rgba(255,255,255,0.02); border: 1px solid rgba(255,255,255,0.04);
  border-radius: 8px; padding: 10px; margin-bottom: 8px;
}
.twh-gap-context { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.twh-gap-prev { font-size: 0.72rem; color: #64748b; font-style: italic; }
.twh-gap-arrow { text-align: center; color: #f87171; font-size: 0.9rem; }
.twh-gap-curr { font-size: 0.72rem; color: #94a3b8; }

.twh-gap-suggestions { display: flex; flex-wrap: wrap; gap: 4px; }
.twh-insert-btn {
  padding: 3px 10px; border-radius: 12px; border: 1px solid rgba(99,102,241,0.25);
  background: rgba(99,102,241,0.08); color: #a5b4fc; font-size: 0.72rem;
  cursor: pointer; transition: background 0.15s, color 0.15s;
}
.twh-insert-btn:hover { background: rgba(99,102,241,0.2); color: #c7d2fe; }

.twh-library { padding: 10px 16px; border-top: 1px solid rgba(255,255,255,0.04); }
.twh-lib-title { font-size: 0.78rem; color: #94a3b8; font-weight: 600; margin-bottom: 8px; }
.twh-lib-cat { margin-bottom: 8px; }
.twh-lib-cat-name { font-size: 0.72rem; font-weight: 600; margin-bottom: 4px; }
.twh-lib-words { display: flex; flex-wrap: wrap; gap: 3px; }
.twh-lib-word {
  padding: 2px 8px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.06);
  background: rgba(255,255,255,0.02); color: #cbd5e1; font-size: 0.68rem;
  cursor: pointer; transition: background 0.15s;
}
.twh-lib-word:hover { background: rgba(99,102,241,0.12); color: #e2e8f0; }

.twh-footer { padding: 10px 16px; border-top: 1px solid rgba(255,255,255,0.06); }
.twh-refresh-btn { padding: 5px 14px; border-radius: 5px; border: 1px solid rgba(255,255,255,0.1); background: rgba(255,255,255,0.04); color: #94a3b8; font-size: 0.75rem; cursor: pointer; }
.twh-refresh-btn:hover { background: rgba(255,255,255,0.08); color: #e2e8f0; }

/* Light theme */
[data-theme="light"] .twh-trigger-btn { color: #6366f1; background: rgba(99,102,241,0.06); border-color: rgba(99,102,241,0.2); }
[data-theme="light"] .twh-panel { background: #fff; border-left-color: rgba(0,0,0,0.08); box-shadow: -4px 0 24px rgba(0,0,0,0.1); }
[data-theme="light"] .twh-header, [data-theme="light"] .twh-library, [data-theme="light"] .twh-footer { border-color: rgba(0,0,0,0.06); }
[data-theme="light"] .twh-title { color: #1e293b; }
[data-theme="light"] .twh-sum-stat strong { color: #1e293b; }
[data-theme="light"] .twh-gap-card { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.06); }
[data-theme="light"] .twh-gap-prev { color: #94a3b8; }
[data-theme="light"] .twh-gap-curr { color: #64748b; }
[data-theme="light"] .twh-insert-btn { background: rgba(99,102,241,0.05); border-color: rgba(99,102,241,0.2); color: #6366f1; }
[data-theme="light"] .twh-lib-word { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.06); color: #334155; }
[data-theme="light"] .twh-refresh-btn { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.1); color: #64748b; }

@media (max-width: 640px) {
  .twh-panel { width: 100%; right: -100%; }
}

/* ══════════════════════════════════════════════════════════════════ */
/* Paragraph Metrics Panel                                          */
/* ══════════════════════════════════════════════════════════════════ */

.pmp-trigger-btn {
  position: fixed; bottom: 178px; right: 18px; z-index: var(--z-toast);
  padding: 6px 14px; border-radius: 6px; border: 1px solid rgba(255,255,255,0.1);
  background: rgba(16,185,129,0.1); color: #10b981; font-size: 0.78rem;
  cursor: pointer; transition: all 0.2s;
}
.pmp-trigger-btn:hover { background: rgba(16,185,129,0.2); color: #34d399; }

.pmp-panel {
  position: fixed; top: 0; right: -420px; width: 420px; height: 100vh;
  background: #1e1e2e; border-left: 1px solid rgba(255,255,255,0.06);
  z-index: var(--z-tooltip); display: flex; flex-direction: column;
  transition: right 0.3s ease; box-shadow: -4px 0 24px rgba(0,0,0,0.3);
}
.pmp-panel-open { right: 0; }

.pmp-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid rgba(255,255,255,0.06);
}
.pmp-title { font-size: 0.92rem; font-weight: 600; color: #e2e8f0; }
.pmp-close-btn {
  background: none; border: none; color: #94a3b8; font-size: 1.2rem;
  cursor: pointer; padding: 2px 6px;
}
.pmp-close-btn:hover { color: #f87171; }

.pmp-summary { padding: 12px 16px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.pmp-sum-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.pmp-sum-card {
  text-align: center; padding: 8px 4px; border-radius: 6px;
  background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.05);
}
.pmp-sum-val { font-size: 1.1rem; font-weight: 700; color: #e2e8f0; }
.pmp-sum-lbl { font-size: 0.65rem; color: #64748b; margin-top: 2px; }

.pmp-grade-easy { color: #10b981; }
.pmp-grade-medium { color: #f59e0b; }
.pmp-grade-hard { color: #f97316; }
.pmp-grade-vhard { color: #ef4444; }

.pmp-distribution { margin-top: 6px; }
.pmp-dist-label { font-size: 0.68rem; color: #64748b; margin-bottom: 6px; }
.pmp-dist-bar-wrap {
  display: flex; align-items: center; gap: 6px; margin-bottom: 3px;
}
.pmp-dist-num { font-size: 0.6rem; color: #64748b; min-width: 14px; }
.pmp-dist-bar {
  height: 6px; border-radius: 3px; min-width: 2px;
  transition: width 0.3s ease;
}
.pmp-dist-bar.pmp-grade-easy { background: #10b981; }
.pmp-dist-bar.pmp-grade-medium { background: #f59e0b; }
.pmp-dist-bar.pmp-grade-hard { background: #f97316; }
.pmp-dist-bar.pmp-grade-vhard { background: #ef4444; }

.pmp-list { flex: 1; overflow-y: auto; padding: 8px 16px; }
.pmp-empty { text-align: center; color: #64748b; font-size: 0.82rem; padding: 30px 0; }

.pmp-item {
  padding: 10px 12px; margin-bottom: 8px; border-radius: 6px;
  background: rgba(255,255,255,0.02); border: 1px solid rgba(255,255,255,0.05);
}
.pmp-item-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.pmp-item-num { font-size: 0.72rem; font-weight: 700; color: #10b981; }
.pmp-item-badge {
  font-size: 0.62rem; padding: 1px 8px; border-radius: 10px;
  background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08);
}
.pmp-item-preview { font-size: 0.72rem; color: #94a3b8; margin-bottom: 6px; line-height: 1.4; }
.pmp-item-stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.pmp-stat { font-size: 0.68rem; color: #64748b; }
.pmp-stat strong { color: #cbd5e1; }
.pmp-item-bar-wrap {
  height: 4px; border-radius: 2px; background: rgba(255,255,255,0.04); overflow: hidden;
}
.pmp-item-bar { height: 100%; border-radius: 2px; transition: width 0.3s; }
.pmp-item-bar.pmp-grade-easy { background: #10b981; }
.pmp-item-bar.pmp-grade-medium { background: #f59e0b; }
.pmp-item-bar.pmp-grade-hard { background: #f97316; }
.pmp-item-bar.pmp-grade-vhard { background: #ef4444; }

.pmp-footer {
  padding: 10px 16px; border-top: 1px solid rgba(255,255,255,0.06);
  display: flex; gap: 8px;
}
.pmp-refresh-btn, .pmp-export-btn {
  flex: 1; padding: 6px 12px; border-radius: 5px; border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04); color: #94a3b8; font-size: 0.75rem;
  cursor: pointer; text-align: center;
}
.pmp-refresh-btn:hover, .pmp-export-btn:hover { background: rgba(255,255,255,0.08); color: #e2e8f0; }

/* Light theme */
[data-theme="light"] .pmp-trigger-btn { color: #059669; background: rgba(16,185,129,0.06); border-color: rgba(16,185,129,0.2); }
[data-theme="light"] .pmp-panel { background: #fff; border-left-color: rgba(0,0,0,0.08); box-shadow: -4px 0 24px rgba(0,0,0,0.1); }
[data-theme="light"] .pmp-header, [data-theme="light"] .pmp-summary, [data-theme="light"] .pmp-footer { border-color: rgba(0,0,0,0.06); }
[data-theme="light"] .pmp-title { color: #1e293b; }
[data-theme="light"] .pmp-close-btn { color: #64748b; }
[data-theme="light"] .pmp-sum-card { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.06); }
[data-theme="light"] .pmp-sum-val { color: #1e293b; }
[data-theme="light"] .pmp-sum-lbl { color: #94a3b8; }
[data-theme="light"] .pmp-item { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.06); }
[data-theme="light"] .pmp-item-preview { color: #64748b; }
[data-theme="light"] .pmp-stat { color: #94a3b8; }
[data-theme="light"] .pmp-stat strong { color: #334155; }
[data-theme="light"] .pmp-item-bar-wrap { background: rgba(0,0,0,0.04); }
[data-theme="light"] .pmp-item-badge { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.08); }
[data-theme="light"] .pmp-refresh-btn, [data-theme="light"] .pmp-export-btn { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.1); color: #64748b; }
[data-theme="light"] .pmp-dist-bar-wrap { background: transparent; }

@media (max-width: 640px) {
  .pmp-panel { width: 100%; right: -100%; }
  .pmp-sum-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ══════════════════════════════════════════════════════════════════ */
/* Outline Drag Reorder                                             */
/* ══════════════════════════════════════════════════════════════════ */

.odr-trigger-btn {
  position: fixed; bottom: 214px; right: 18px; z-index: var(--z-toast);
  padding: 6px 14px; border-radius: 6px; border: 1px solid rgba(255,255,255,0.1);
  background: rgba(59,130,246,0.1); color: #3b82f6; font-size: 0.78rem;
  cursor: pointer; transition: all 0.2s;
}
.odr-trigger-btn:hover { background: rgba(59,130,246,0.2); color: #60a5fa; }

.odr-panel {
  position: fixed; top: 0; right: -380px; width: 380px; height: 100vh;
  background: #1e1e2e; border-left: 1px solid rgba(255,255,255,0.06);
  z-index: var(--z-tooltip); display: flex; flex-direction: column;
  transition: right 0.3s ease; box-shadow: -4px 0 24px rgba(0,0,0,0.3);
}
.odr-panel-open { right: 0; }

.odr-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid rgba(255,255,255,0.06);
}
.odr-title { font-size: 0.92rem; font-weight: 600; color: #e2e8f0; }
.odr-close-btn {
  background: none; border: none; color: #94a3b8; font-size: 1.2rem;
  cursor: pointer; padding: 2px 6px;
}
.odr-close-btn:hover { color: #f87171; }

.odr-hint {
  padding: 8px 16px; font-size: 0.7rem; color: #64748b;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.odr-list { flex: 1; overflow-y: auto; padding: 8px 12px; }
.odr-empty { text-align: center; color: #64748b; font-size: 0.82rem; padding: 30px 0; }

.odr-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  margin-bottom: 3px; border-radius: 6px; cursor: grab;
  background: rgba(255,255,255,0.02); border: 1px solid rgba(255,255,255,0.05);
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.odr-item:hover { background: rgba(255,255,255,0.05); }
.odr-item-dragging { opacity: 0.4; transform: scale(0.97); }
.odr-item-over {
  border-color: rgba(59,130,246,0.5);
  background: rgba(59,130,246,0.08);
  box-shadow: 0 0 0 2px rgba(59,130,246,0.15);
}

.odr-drag-handle { color: #64748b; font-size: 0.9rem; cursor: grab; user-select: none; }
.odr-item-tag {
  font-size: 0.58rem; font-weight: 700; color: #3b82f6; padding: 1px 5px;
  border-radius: 3px; background: rgba(59,130,246,0.1); min-width: 22px; text-align: center;
}
.odr-item-text {
  flex: 1; font-size: 0.76rem; color: #cbd5e1; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.odr-item-num { font-size: 0.6rem; color: #475569; min-width: 16px; text-align: right; }

.odr-footer {
  padding: 10px 16px; border-top: 1px solid rgba(255,255,255,0.06);
  display: flex; gap: 8px;
}
.odr-apply-btn, .odr-reset-btn {
  flex: 1; padding: 7px 12px; border-radius: 5px; font-size: 0.75rem;
  cursor: pointer; text-align: center; border: 1px solid rgba(255,255,255,0.1);
}
.odr-apply-btn { background: rgba(59,130,246,0.15); color: #3b82f6; }
.odr-apply-btn:hover { background: rgba(59,130,246,0.25); }
.odr-reset-btn { background: rgba(255,255,255,0.04); color: #94a3b8; }
.odr-reset-btn:hover { background: rgba(255,255,255,0.08); color: #e2e8f0; }

/* Light theme */
[data-theme="light"] .odr-trigger-btn { color: #2563eb; background: rgba(59,130,246,0.06); border-color: rgba(59,130,246,0.2); }
[data-theme="light"] .odr-panel { background: #fff; border-left-color: rgba(0,0,0,0.08); box-shadow: -4px 0 24px rgba(0,0,0,0.1); }
[data-theme="light"] .odr-header, [data-theme="light"] .odr-hint, [data-theme="light"] .odr-footer { border-color: rgba(0,0,0,0.06); }
[data-theme="light"] .odr-title { color: #1e293b; }
[data-theme="light"] .odr-item { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.06); }
[data-theme="light"] .odr-item:hover { background: rgba(0,0,0,0.04); }
[data-theme="light"] .odr-item-over { border-color: rgba(59,130,246,0.4); background: rgba(59,130,246,0.06); }
[data-theme="light"] .odr-item-text { color: #334155; }
[data-theme="light"] .odr-item-tag { background: rgba(59,130,246,0.08); }
[data-theme="light"] .odr-apply-btn { background: rgba(59,130,246,0.08); color: #2563eb; }
[data-theme="light"] .odr-reset-btn { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.1); color: #64748b; }

@media (max-width: 640px) {
  .odr-panel { width: 100%; right: -100%; }
}

/* ══════════════════════════════════════════════════════════════════ */
/* Heading Hierarchy Validator                                      */
/* ══════════════════════════════════════════════════════════════════ */

.hhv-trigger-btn {
  position: fixed; bottom: 250px; right: 18px; z-index: var(--z-toast);
  padding: 6px 14px; border-radius: 6px; border: 1px solid rgba(255,255,255,0.1);
  background: rgba(245,158,11,0.1); color: #f59e0b; font-size: 0.78rem;
  cursor: pointer; transition: all 0.2s;
}
.hhv-trigger-btn:hover { background: rgba(245,158,11,0.2); color: #fbbf24; }

.hhv-panel {
  position: fixed; top: 0; right: -400px; width: 400px; height: 100vh;
  background: #1e1e2e; border-left: 1px solid rgba(255,255,255,0.06);
  z-index: var(--z-tooltip); display: flex; flex-direction: column;
  transition: right 0.3s ease; box-shadow: -4px 0 24px rgba(0,0,0,0.3);
}
.hhv-panel-open { right: 0; }

.hhv-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid rgba(255,255,255,0.06);
}
.hhv-title { font-size: 0.92rem; font-weight: 600; color: #e2e8f0; }
.hhv-close-btn { background: none; border: none; color: #94a3b8; font-size: 1.2rem; cursor: pointer; }
.hhv-close-btn:hover { color: #f87171; }

.hhv-summary { padding: 12px 16px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.hhv-sum-row { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.hhv-sum-badge {
  font-size: 0.7rem; font-weight: 600; padding: 3px 10px; border-radius: 10px;
}
.hhv-status-ok { background: rgba(16,185,129,0.15); color: #10b981; }
.hhv-status-warn { background: rgba(245,158,11,0.15); color: #f59e0b; }
.hhv-status-error { background: rgba(239,68,68,0.15); color: #ef4444; }
.hhv-sum-count { font-size: 0.72rem; color: #64748b; }
.hhv-sum-counts { display: flex; gap: 12px; flex-wrap: wrap; }
.hhv-cnt-error { font-size: 0.68rem; color: #ef4444; }
.hhv-cnt-warn { font-size: 0.68rem; color: #f59e0b; }
.hhv-cnt-info { font-size: 0.68rem; color: #3b82f6; }
.hhv-cnt-ok { font-size: 0.68rem; color: #10b981; }

.hhv-tree { padding: 8px 12px; border-bottom: 1px solid rgba(255,255,255,0.06); max-height: 40vh; overflow-y: auto; }
.hhv-empty { text-align: center; color: #64748b; font-size: 0.82rem; padding: 24px 0; }
.hhv-tree-item {
  display: flex; align-items: center; gap: 6px; padding: 5px 8px;
  border-radius: 4px; cursor: pointer; transition: background 0.15s;
}
.hhv-tree-item:hover { background: rgba(255,255,255,0.04); }
.hhv-tree-issue { background: rgba(245,158,11,0.04); }
.hhv-tree-tag {
  font-size: 0.58rem; font-weight: 700; color: #f59e0b; padding: 1px 5px;
  border-radius: 3px; background: rgba(245,158,11,0.1); min-width: 22px; text-align: center;
}
.hhv-tree-text { flex: 1; font-size: 0.74rem; color: #cbd5e1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hhv-tree-icon { font-size: 0.7rem; }
.hhv-icon-error { color: #ef4444; }
.hhv-icon-warning { color: #f59e0b; }
.hhv-icon-info { color: #3b82f6; }

.hhv-issues { flex: 1; overflow-y: auto; padding: 8px 16px; }
.hhv-issues-title { font-size: 0.78rem; font-weight: 600; color: #94a3b8; margin-bottom: 8px; }
.hhv-issue {
  padding: 8px 12px; margin-bottom: 6px; border-radius: 6px;
  border-left: 3px solid transparent;
}
.hhv-issue-error { background: rgba(239,68,68,0.06); border-left-color: #ef4444; }
.hhv-issue-warning { background: rgba(245,158,11,0.06); border-left-color: #f59e0b; }
.hhv-issue-info { background: rgba(59,130,246,0.06); border-left-color: #3b82f6; }
.hhv-issue-msg { font-size: 0.74rem; color: #e2e8f0; margin-bottom: 4px; }
.hhv-issue-fix { font-size: 0.68rem; color: #94a3b8; }

.hhv-footer { padding: 10px 16px; border-top: 1px solid rgba(255,255,255,0.06); }
.hhv-refresh-btn {
  width: 100%; padding: 7px 12px; border-radius: 5px; border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04); color: #94a3b8; font-size: 0.75rem; cursor: pointer;
}
.hhv-refresh-btn:hover { background: rgba(255,255,255,0.08); color: #e2e8f0; }

/* Light theme */
[data-theme="light"] .hhv-trigger-btn { color: #d97706; background: rgba(245,158,11,0.06); border-color: rgba(245,158,11,0.2); }
[data-theme="light"] .hhv-panel { background: #fff; border-left-color: rgba(0,0,0,0.08); box-shadow: -4px 0 24px rgba(0,0,0,0.1); }
[data-theme="light"] .hhv-header, [data-theme="light"] .hhv-summary, [data-theme="light"] .hhv-tree, [data-theme="light"] .hhv-footer { border-color: rgba(0,0,0,0.06); }
[data-theme="light"] .hhv-title { color: #1e293b; }
[data-theme="light"] .hhv-tree-item:hover { background: rgba(0,0,0,0.03); }
[data-theme="light"] .hhv-tree-text { color: #334155; }
[data-theme="light"] .hhv-issue-msg { color: #1e293b; }
[data-theme="light"] .hhv-issue-fix { color: #64748b; }
[data-theme="light"] .hhv-issue-error { background: rgba(239,68,68,0.04); }
[data-theme="light"] .hhv-issue-warning { background: rgba(245,158,11,0.04); }
[data-theme="light"] .hhv-issue-info { background: rgba(59,130,246,0.04); }
[data-theme="light"] .hhv-refresh-btn { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.1); color: #64748b; }

@media (max-width: 640px) {
  .hhv-panel { width: 100%; right: -100%; }
  .hhv-tree { max-height: 30vh; }
}

/* ══════════════════════════════════════════════════════════════════ */
/* Citation Count Badge                                             */
/* ══════════════════════════════════════════════════════════════════ */

.ccb-badge {
  position: fixed; bottom: 286px; right: 18px; z-index: var(--z-toast);
  display: flex; align-items: center; gap: 5px; padding: 5px 12px;
  border-radius: 16px; border: 1px solid rgba(255,255,255,0.1);
  background: rgba(139,92,246,0.1); color: #a78bfa; font-size: 0.75rem;
  cursor: pointer; transition: all 0.2s;
}
.ccb-badge:hover { background: rgba(139,92,246,0.2); }
.ccb-badge-count { font-weight: 700; font-size: 0.85rem; }
.ccb-badge-label { font-size: 0.65rem; color: #94a3b8; }
.ccb-badge-ok { border-color: rgba(16,185,129,0.3); }
.ccb-badge-ok .ccb-badge-count { color: #10b981; }
.ccb-badge-warn { border-color: rgba(245,158,11,0.3); }
.ccb-badge-warn .ccb-badge-count { color: #f59e0b; }

.ccb-panel {
  position: fixed; top: 0; right: -390px; width: 390px; height: 100vh;
  background: #1e1e2e; border-left: 1px solid rgba(255,255,255,0.06);
  z-index: var(--z-tooltip); display: flex; flex-direction: column;
  transition: right 0.3s ease; box-shadow: -4px 0 24px rgba(0,0,0,0.3);
}
.ccb-panel-open { right: 0; }

.ccb-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid rgba(255,255,255,0.06);
}
.ccb-title { font-size: 0.92rem; font-weight: 600; color: #e2e8f0; }
.ccb-close-btn { background: none; border: none; color: #94a3b8; font-size: 1.2rem; cursor: pointer; }
.ccb-close-btn:hover { color: #f87171; }

.ccb-summary { padding: 12px 16px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.ccb-sum-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.ccb-sum-card {
  text-align: center; padding: 8px 4px; border-radius: 6px;
  background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.05);
}
.ccb-sum-val { font-size: 1.05rem; font-weight: 700; color: #e2e8f0; }
.ccb-sum-lbl { font-size: 0.58rem; color: #64748b; margin-top: 2px; }
.ccb-val-warn { color: #f59e0b; }
.ccb-val-ok { color: #10b981; }

.ccb-tabs {
  display: flex; border-bottom: 1px solid rgba(255,255,255,0.06);
}
.ccb-tab {
  flex: 1; padding: 8px 12px; background: none; border: none; border-bottom: 2px solid transparent;
  color: #64748b; font-size: 0.75rem; cursor: pointer; transition: all 0.15s;
}
.ccb-tab:hover { color: #cbd5e1; }
.ccb-tab-active { color: #a78bfa; border-bottom-color: #a78bfa; }

.ccb-list { flex: 1; overflow-y: auto; padding: 8px 16px; }
.ccb-empty { text-align: center; color: #64748b; font-size: 0.82rem; padding: 24px 0; }
.ccb-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px;
  margin-bottom: 4px; border-radius: 5px; background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.04);
}
.ccb-item-warn { border-left: 3px solid #f59e0b; }
.ccb-item-key { font-size: 0.72rem; font-weight: 600; color: #a78bfa; min-width: 50px; }
.ccb-item-freq { font-size: 0.68rem; color: #64748b; min-width: 28px; }
.ccb-item-text { flex: 1; font-size: 0.7rem; color: #94a3b8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ccb-item-bar-wrap { flex: 1; height: 4px; border-radius: 2px; background: rgba(255,255,255,0.04); }
.ccb-item-bar { height: 100%; border-radius: 2px; background: #a78bfa; transition: width 0.3s; }

/* Light theme */
[data-theme="light"] .ccb-badge { background: rgba(139,92,246,0.06); border-color: rgba(139,92,246,0.2); color: #7c3aed; }
[data-theme="light"] .ccb-panel { background: #fff; border-left-color: rgba(0,0,0,0.08); box-shadow: -4px 0 24px rgba(0,0,0,0.1); }
[data-theme="light"] .ccb-header, [data-theme="light"] .ccb-summary, [data-theme="light"] .ccb-tabs { border-color: rgba(0,0,0,0.06); }
[data-theme="light"] .ccb-title { color: #1e293b; }
[data-theme="light"] .ccb-sum-card { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.06); }
[data-theme="light"] .ccb-sum-val { color: #1e293b; }
[data-theme="light"] .ccb-tab { color: #94a3b8; }
[data-theme="light"] .ccb-tab-active { color: #7c3aed; border-bottom-color: #7c3aed; }
[data-theme="light"] .ccb-item { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.05); }
[data-theme="light"] .ccb-item-key { color: #7c3aed; }
[data-theme="light"] .ccb-item-bar-wrap { background: rgba(0,0,0,0.04); }
[data-theme="light"] .ccb-item-bar { background: #7c3aed; }

@media (max-width: 640px) {
  .ccb-panel { width: 100%; right: -100%; }
  .ccb-sum-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ══════════════════════════════════════════════════════════════════ */
/* Auto-Link Detector                                               */
/* ══════════════════════════════════════════════════════════════════ */

.ald-trigger-btn {
  position: fixed; bottom: 322px; right: 18px; z-index: var(--z-toast);
  padding: 6px 14px; border-radius: 6px; border: 1px solid rgba(255,255,255,0.1);
  background: rgba(14,165,233,0.1); color: #0ea5e9; font-size: 0.78rem;
  cursor: pointer; transition: all 0.2s;
}
.ald-trigger-btn:hover { background: rgba(14,165,233,0.2); color: #38bdf8; }

.ald-panel {
  position: fixed; top: 0; right: -390px; width: 390px; height: 100vh;
  background: #1e1e2e; border-left: 1px solid rgba(255,255,255,0.06);
  z-index: var(--z-tooltip); display: flex; flex-direction: column;
  transition: right 0.3s ease; box-shadow: -4px 0 24px rgba(0,0,0,0.3);
}
.ald-panel-open { right: 0; }

.ald-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid rgba(255,255,255,0.06);
}
.ald-title { font-size: 0.92rem; font-weight: 600; color: #e2e8f0; }
.ald-close-btn { background: none; border: none; color: #94a3b8; font-size: 1.2rem; cursor: pointer; }
.ald-close-btn:hover { color: #f87171; }

.ald-summary { padding: 12px 16px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.ald-sum-row { margin-bottom: 4px; }
.ald-sum-badge { font-size: 0.78rem; font-weight: 600; color: #0ea5e9; }
.ald-sum-counts { display: flex; gap: 14px; }
.ald-cnt-url { font-size: 0.7rem; color: #10b981; }
.ald-cnt-doi { font-size: 0.7rem; color: #f59e0b; }

.ald-tabs { display: flex; border-bottom: 1px solid rgba(255,255,255,0.06); }
.ald-tab {
  flex: 1; padding: 8px 12px; background: none; border: none; border-bottom: 2px solid transparent;
  color: #64748b; font-size: 0.75rem; cursor: pointer; transition: all 0.15s;
}
.ald-tab:hover { color: #cbd5e1; }
.ald-tab-active { color: #0ea5e9; border-bottom-color: #0ea5e9; }

.ald-list { flex: 1; overflow-y: auto; padding: 8px 16px; }
.ald-empty { text-align: center; color: #64748b; font-size: 0.82rem; padding: 24px 0; }

.ald-item {
  padding: 8px 10px; margin-bottom: 5px; border-radius: 6px;
  background: rgba(255,255,255,0.02); border: 1px solid rgba(255,255,255,0.05);
}
.ald-item-head { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.ald-type-badge {
  font-size: 0.55rem; font-weight: 700; padding: 1px 6px; border-radius: 3px;
  text-transform: uppercase;
}
.ald-type-url { background: rgba(16,185,129,0.12); color: #10b981; }
.ald-type-doi { background: rgba(245,158,11,0.12); color: #f59e0b; }
.ald-item-domain { flex: 1; font-size: 0.74rem; font-weight: 600; color: #cbd5e1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ald-item-copy, .ald-item-open {
  background: none; border: none; color: #64748b; font-size: 0.72rem;
  cursor: pointer; padding: 2px 4px; text-decoration: none;
}
.ald-item-copy:hover, .ald-item-open:hover { color: #0ea5e9; }
.ald-item-url { font-size: 0.66rem; color: #64748b; word-break: break-all; }

.ald-footer {
  padding: 10px 16px; border-top: 1px solid rgba(255,255,255,0.06);
  display: flex; gap: 8px;
}
.ald-rescan-btn, .ald-export-btn {
  flex: 1; padding: 6px 12px; border-radius: 5px; border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04); color: #94a3b8; font-size: 0.75rem;
  cursor: pointer; text-align: center;
}
.ald-rescan-btn:hover, .ald-export-btn:hover { background: rgba(255,255,255,0.08); color: #e2e8f0; }

/* Light theme */
[data-theme="light"] .ald-trigger-btn { color: #0284c7; background: rgba(14,165,233,0.06); border-color: rgba(14,165,233,0.2); }
[data-theme="light"] .ald-panel { background: #fff; border-left-color: rgba(0,0,0,0.08); box-shadow: -4px 0 24px rgba(0,0,0,0.1); }
[data-theme="light"] .ald-header, [data-theme="light"] .ald-summary, [data-theme="light"] .ald-tabs, [data-theme="light"] .ald-footer { border-color: rgba(0,0,0,0.06); }
[data-theme="light"] .ald-title { color: #1e293b; }
[data-theme="light"] .ald-tab { color: #94a3b8; }
[data-theme="light"] .ald-tab-active { color: #0284c7; border-bottom-color: #0284c7; }
[data-theme="light"] .ald-item { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.05); }
[data-theme="light"] .ald-item-domain { color: #1e293b; }
[data-theme="light"] .ald-item-url { color: #94a3b8; }
[data-theme="light"] .ald-rescan-btn, [data-theme="light"] .ald-export-btn { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.1); color: #64748b; }

@media (max-width: 640px) {
  .ald-panel { width: 100%; right: -100%; }
}

/* ══════════════════════════════════════════════════════════════════ */
/* Abbreviation Manager                                             */
/* ══════════════════════════════════════════════════════════════════ */

.abm-trigger-btn {
  position: fixed; bottom: 358px; right: 18px; z-index: var(--z-toast);
  padding: 6px 14px; border-radius: 6px; border: 1px solid rgba(255,255,255,0.1);
  background: rgba(236,72,153,0.1); color: #ec4899; font-size: 0.78rem;
  cursor: pointer; transition: all 0.2s;
}
.abm-trigger-btn:hover { background: rgba(236,72,153,0.2); color: #f472b6; }

.abm-panel {
  position: fixed; top: 0; right: -400px; width: 400px; height: 100vh;
  background: #1e1e2e; border-left: 1px solid rgba(255,255,255,0.06);
  z-index: var(--z-tooltip); display: flex; flex-direction: column;
  transition: right 0.3s ease; box-shadow: -4px 0 24px rgba(0,0,0,0.3);
}
.abm-panel-open { right: 0; }

.abm-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid rgba(255,255,255,0.06);
}
.abm-title { font-size: 0.92rem; font-weight: 600; color: #e2e8f0; }
.abm-close-btn { background: none; border: none; color: #94a3b8; font-size: 1.2rem; cursor: pointer; }
.abm-close-btn:hover { color: #f87171; }

.abm-summary { padding: 10px 16px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.abm-sum-row { display: flex; gap: 12px; flex-wrap: wrap; }
.abm-sum-stat { font-size: 0.7rem; color: #94a3b8; }
.abm-sum-stat strong { color: #e2e8f0; }
.abm-ok strong { color: #10b981; }
.abm-warn strong { color: #f59e0b; }
.abm-err strong { color: #ef4444; }

.abm-add-row {
  display: flex; gap: 6px; padding: 8px 16px; border-bottom: 1px solid rgba(255,255,255,0.06);
}
.abm-add-abbr, .abm-add-def {
  flex: 1; padding: 5px 8px; border-radius: 4px; border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04); color: #e2e8f0; font-size: 0.72rem;
}
.abm-add-abbr { max-width: 80px; }
.abm-add-btn {
  padding: 5px 10px; border-radius: 4px; border: 1px solid rgba(236,72,153,0.3);
  background: rgba(236,72,153,0.1); color: #ec4899; font-size: 0.8rem; cursor: pointer;
}
.abm-add-btn:hover { background: rgba(236,72,153,0.2); }

.abm-tabs { display: flex; border-bottom: 1px solid rgba(255,255,255,0.06); }
.abm-tab {
  flex: 1; padding: 8px 12px; background: none; border: none; border-bottom: 2px solid transparent;
  color: #64748b; font-size: 0.75rem; cursor: pointer;
}
.abm-tab:hover { color: #cbd5e1; }
.abm-tab-active { color: #ec4899; border-bottom-color: #ec4899; }

.abm-list { flex: 1; overflow-y: auto; padding: 8px 16px; }
.abm-empty { text-align: center; color: #64748b; font-size: 0.82rem; padding: 24px 0; }

.abm-item {
  padding: 8px 10px; margin-bottom: 5px; border-radius: 6px;
  background: rgba(255,255,255,0.02); border: 1px solid rgba(255,255,255,0.05);
}
.abm-no-def { border-left: 3px solid #f59e0b; }
.abm-has-def { border-left: 3px solid #10b981; }
.abm-item-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.abm-item-abbr { font-size: 0.78rem; font-weight: 700; color: #ec4899; }
.abm-item-count { font-size: 0.65rem; color: #64748b; }
.abm-item-del { margin-left: auto; background: none; border: none; color: #64748b; cursor: pointer; font-size: 0.8rem; }
.abm-item-del:hover { color: #f87171; }
.abm-item-def {
  width: 100%; padding: 4px 8px; border-radius: 4px; border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.03); color: #cbd5e1; font-size: 0.7rem;
}
.abm-item-def:focus { border-color: rgba(236,72,153,0.3); outline: none; }

.abm-issue {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px;
  margin-bottom: 4px; border-radius: 5px; border-left: 3px solid transparent;
}
.abm-issue-error { background: rgba(239,68,68,0.06); border-left-color: #ef4444; }
.abm-issue-warning { background: rgba(245,158,11,0.06); border-left-color: #f59e0b; }
.abm-issue-info { background: rgba(59,130,246,0.06); border-left-color: #3b82f6; }
.abm-issue-abbr { font-size: 0.72rem; font-weight: 700; color: #ec4899; min-width: 40px; }
.abm-issue-msg { font-size: 0.7rem; color: #94a3b8; }

.abm-footer {
  padding: 10px 16px; border-top: 1px solid rgba(255,255,255,0.06);
  display: flex; gap: 8px;
}
.abm-rescan-btn, .abm-export-btn {
  flex: 1; padding: 6px 12px; border-radius: 5px; border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04); color: #94a3b8; font-size: 0.75rem;
  cursor: pointer; text-align: center;
}
.abm-rescan-btn:hover, .abm-export-btn:hover { background: rgba(255,255,255,0.08); color: #e2e8f0; }

/* Light theme */
[data-theme="light"] .abm-trigger-btn { color: #db2777; background: rgba(236,72,153,0.06); border-color: rgba(236,72,153,0.2); }
[data-theme="light"] .abm-panel { background: #fff; border-left-color: rgba(0,0,0,0.08); box-shadow: -4px 0 24px rgba(0,0,0,0.1); }
[data-theme="light"] .abm-header, [data-theme="light"] .abm-summary, [data-theme="light"] .abm-add-row, [data-theme="light"] .abm-tabs, [data-theme="light"] .abm-footer { border-color: rgba(0,0,0,0.06); }
[data-theme="light"] .abm-title { color: #1e293b; }
[data-theme="light"] .abm-sum-stat strong { color: #1e293b; }
[data-theme="light"] .abm-tab { color: #94a3b8; }
[data-theme="light"] .abm-tab-active { color: #db2777; border-bottom-color: #db2777; }
[data-theme="light"] .abm-item { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.05); }
[data-theme="light"] .abm-item-def { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.08); color: #334155; }
[data-theme="light"] .abm-add-abbr, [data-theme="light"] .abm-add-def { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.1); color: #334155; }
[data-theme="light"] .abm-rescan-btn, [data-theme="light"] .abm-export-btn { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.1); color: #64748b; }

@media (max-width: 640px) {
  .abm-panel { width: 100%; right: -100%; }
  .abm-add-row { flex-wrap: wrap; }
}

/* ══════════════════════════════════════════════════════════════════ */
/* Table Inserter                                                   */
/* ══════════════════════════════════════════════════════════════════ */

.tbl-trigger-btn {
  position: fixed; bottom: 394px; right: 18px; z-index: var(--z-toast);
  padding: 6px 14px; border-radius: 6px; border: 1px solid rgba(255,255,255,0.1);
  background: rgba(34,197,94,0.1); color: #22c55e; font-size: 0.78rem;
  cursor: pointer; transition: all 0.2s;
}
.tbl-trigger-btn:hover { background: rgba(34,197,94,0.2); color: #4ade80; }

.tbl-overlay {
  position: fixed; inset: 0; z-index: var(--z-max); background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
}
.tbl-modal {
  width: 520px; max-height: 90vh; background: #1e1e2e; border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.08); display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}

.tbl-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid rgba(255,255,255,0.06);
}
.tbl-title { font-size: 0.92rem; font-weight: 600; color: #e2e8f0; }
.tbl-close-btn { background: none; border: none; color: #94a3b8; font-size: 1.2rem; cursor: pointer; }
.tbl-close-btn:hover { color: #f87171; }

.tbl-body { padding: 16px 18px; overflow-y: auto; flex: 1; }

.tbl-config { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.tbl-config-row { display: flex; align-items: center; gap: 6px; }
.tbl-label { font-size: 0.72rem; color: #94a3b8; min-width: 60px; }
.tbl-input {
  width: 60px; padding: 4px 8px; border-radius: 4px; border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04); color: #e2e8f0; font-size: 0.75rem;
}
.tbl-select {
  padding: 4px 8px; border-radius: 4px; border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04); color: #e2e8f0; font-size: 0.72rem;
}

.tbl-grid-picker { margin-bottom: 14px; }
.tbl-grid-label { font-size: 0.68rem; color: #64748b; margin-bottom: 6px; }
.tbl-grid {
  display: grid; grid-template-columns: repeat(10, 22px); gap: 2px; margin-bottom: 4px;
}
.tbl-grid-cell {
  width: 22px; height: 18px; border-radius: 2px; border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.02); cursor: pointer; transition: background 0.1s;
}
.tbl-grid-cell:hover, .tbl-grid-hl {
  background: rgba(34,197,94,0.25); border-color: rgba(34,197,94,0.4);
}
.tbl-grid-size { font-size: 0.65rem; color: #64748b; }

.tbl-preview-label { font-size: 0.68rem; color: #64748b; margin-bottom: 6px; }
.tbl-preview {
  max-height: 180px; overflow: auto; border-radius: 6px; padding: 8px;
  background: rgba(255,255,255,0.02); border: 1px solid rgba(255,255,255,0.06);
  font-size: 0.72rem; color: #cbd5e1;
}

.tbl-footer {
  padding: 12px 18px; border-top: 1px solid rgba(255,255,255,0.06);
  display: flex; gap: 8px; justify-content: flex-end;
}
.tbl-insert-btn {
  padding: 7px 18px; border-radius: 5px; border: 1px solid rgba(34,197,94,0.3);
  background: rgba(34,197,94,0.15); color: #22c55e; font-size: 0.78rem; cursor: pointer;
}
.tbl-insert-btn:hover { background: rgba(34,197,94,0.25); }
.tbl-cancel-btn {
  padding: 7px 14px; border-radius: 5px; border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04); color: #94a3b8; font-size: 0.78rem; cursor: pointer;
}
.tbl-cancel-btn:hover { background: rgba(255,255,255,0.08); }

/* Light theme */
[data-theme="light"] .tbl-trigger-btn { color: #16a34a; background: rgba(34,197,94,0.06); border-color: rgba(34,197,94,0.2); }
[data-theme="light"] .tbl-modal { background: #fff; border-color: rgba(0,0,0,0.08); box-shadow: 0 20px 60px rgba(0,0,0,0.15); }
[data-theme="light"] .tbl-header, [data-theme="light"] .tbl-footer { border-color: rgba(0,0,0,0.06); }
[data-theme="light"] .tbl-title { color: #1e293b; }
[data-theme="light"] .tbl-input, [data-theme="light"] .tbl-select { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.1); color: #334155; }
[data-theme="light"] .tbl-grid-cell { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.08); }
[data-theme="light"] .tbl-grid-cell:hover, [data-theme="light"] .tbl-grid-hl { background: rgba(34,197,94,0.2); border-color: rgba(34,197,94,0.4); }
[data-theme="light"] .tbl-preview { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.06); color: #334155; }
[data-theme="light"] .tbl-insert-btn { background: rgba(34,197,94,0.08); color: #16a34a; }
[data-theme="light"] .tbl-cancel-btn { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.1); color: #64748b; }

@media (max-width: 640px) {
  .tbl-modal { width: 95vw; max-height: 95vh; }
  .tbl-config { flex-direction: column; }
}

/* ── Image Inserter ── */
.img-trigger-btn {
  position: fixed; bottom: 20px; left: 380px; z-index: 900;
  background: rgba(168,85,247,0.12); color: #c084fc; border: 1px solid rgba(168,85,247,0.25);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600;
  transition: all 0.2s ease;
}
.img-trigger-btn:hover { background: rgba(168,85,247,0.2); color: #d8b4fe; }

.img-overlay {
  display: none; position: fixed; inset: 0; z-index: var(--z-tooltip);
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  justify-content: center; align-items: center;
}
.img-overlay.img-visible { display: flex; }

.img-modal {
  background: #1e1e2e; border: 1px solid rgba(255,255,255,0.06);
  border-radius: 16px; width: 520px; max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.img-header, .img-footer {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid rgba(255,255,255,0.06);
}
.img-footer { border-bottom: none; border-top: 1px solid rgba(255,255,255,0.06); gap: 8px; justify-content: flex-end; }
.img-title { font-size: 16px; font-weight: 700; color: #e2e8f0; }
.img-close { background: none; border: none; color: #94a3b8; font-size: 20px; cursor: pointer; }
.img-close:hover { color: #e2e8f0; }

.img-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }

.img-label { font-size: 12px; font-weight: 600; color: #94a3b8; margin-bottom: 4px; display: block; }
.img-input, .img-select {
  width: 100%; padding: 8px 12px; border-radius: 8px; font-size: 13px;
  background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.1); color: #e2e8f0;
  box-sizing: border-box;
}
.img-input:focus, .img-select:focus { outline: none; border-color: rgba(168,85,247,0.5); }

.img-dropzone {
  border: 2px dashed rgba(168,85,247,0.3); border-radius: 12px; padding: 24px;
  text-align: center; color: #94a3b8; font-size: 13px; cursor: pointer;
  transition: all 0.2s ease; min-height: 60px; display: flex; align-items: center; justify-content: center;
}
.img-dropzone:hover, .img-dropzone.img-dragover {
  border-color: rgba(168,85,247,0.6); background: rgba(168,85,247,0.06); color: #c084fc;
}

.img-row { display: flex; gap: 12px; }
.img-row > div { flex: 1; }

.img-preview-box {
  background: rgba(255,255,255,0.02); border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px; padding: 12px; min-height: 80px; display: flex; align-items: center; justify-content: center;
}
.img-preview-box img { max-width: 100%; max-height: 200px; border-radius: 6px; }
.img-preview-box .img-placeholder { color: #64748b; font-size: 12px; }

.img-insert-btn {
  padding: 8px 20px; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer;
  background: rgba(168,85,247,0.15); color: #c084fc; border: 1px solid rgba(168,85,247,0.3);
  transition: all 0.2s ease;
}
.img-insert-btn:hover { background: rgba(168,85,247,0.25); }
.img-cancel-btn {
  padding: 8px 16px; border-radius: 8px; font-size: 13px; cursor: pointer;
  background: rgba(255,255,255,0.04); color: #94a3b8; border: 1px solid rgba(255,255,255,0.1);
}
.img-cancel-btn:hover { background: rgba(255,255,255,0.08); }

/* Image Inserter – light theme */
[data-theme="light"] .img-trigger-btn { color: #7c3aed; background: rgba(168,85,247,0.06); border-color: rgba(168,85,247,0.2); }
[data-theme="light"] .img-modal { background: #fff; border-color: rgba(0,0,0,0.08); box-shadow: 0 20px 60px rgba(0,0,0,0.15); }
[data-theme="light"] .img-header, [data-theme="light"] .img-footer { border-color: rgba(0,0,0,0.06); }
[data-theme="light"] .img-title { color: #1e293b; }
[data-theme="light"] .img-input, [data-theme="light"] .img-select { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.1); color: #334155; }
[data-theme="light"] .img-dropzone { border-color: rgba(168,85,247,0.2); color: #64748b; }
[data-theme="light"] .img-dropzone:hover, [data-theme="light"] .img-dropzone.img-dragover { border-color: rgba(168,85,247,0.5); background: rgba(168,85,247,0.04); }
[data-theme="light"] .img-preview-box { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.06); }
[data-theme="light"] .img-insert-btn { background: rgba(168,85,247,0.08); color: #7c3aed; }
[data-theme="light"] .img-cancel-btn { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.1); color: #64748b; }

@media (max-width: 640px) {
  .img-modal { width: 95vw; max-height: 95vh; }
  .img-row { flex-direction: column; }
}

/* ── Footnote Preview Tooltip ── */
.fpt-tooltip {
  position: fixed; z-index: var(--z-max); width: 320px; max-height: 220px;
  background: #1e1e2e; border: 1px solid rgba(59,130,246,0.2);
  border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,0.4);
  opacity: 0; pointer-events: none; transition: opacity 0.2s ease, transform 0.2s ease;
  overflow: hidden;
}
.fpt-tooltip.fpt-visible { opacity: 1; pointer-events: auto; }

.fpt-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-bottom: 1px solid rgba(255,255,255,0.06);
  background: rgba(59,130,246,0.06);
}
.fpt-num {
  font-size: 13px; font-weight: 700; color: #60a5fa;
  background: rgba(59,130,246,0.15); padding: 2px 8px; border-radius: 6px;
}
.fpt-label { font-size: 11px; color: #94a3b8; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.fpt-goto {
  margin-left: auto; background: rgba(59,130,246,0.12); border: 1px solid rgba(59,130,246,0.25);
  color: #60a5fa; width: 26px; height: 26px; border-radius: 6px; cursor: pointer;
  font-size: 14px; display: flex; align-items: center; justify-content: center; transition: all 0.15s;
}
.fpt-goto:hover { background: rgba(59,130,246,0.25); color: #93c5fd; }

.fpt-body {
  padding: 10px 14px; font-size: 13px; line-height: 1.55; color: #cbd5e1;
  max-height: 150px; overflow-y: auto;
}
.fpt-body.fpt-empty { color: #64748b; font-style: italic; }

.fpt-body::-webkit-scrollbar { width: 4px; }
.fpt-body::-webkit-scrollbar-track { background: transparent; }
.fpt-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* Footnote Preview – light theme */
[data-theme="light"] .fpt-tooltip { background: #fff; border-color: rgba(59,130,246,0.15); box-shadow: 0 12px 40px rgba(0,0,0,0.12); }
[data-theme="light"] .fpt-header { background: rgba(59,130,246,0.04); border-color: rgba(0,0,0,0.06); }
[data-theme="light"] .fpt-num { color: #2563eb; background: rgba(59,130,246,0.1); }
[data-theme="light"] .fpt-label { color: #64748b; }
[data-theme="light"] .fpt-goto { background: rgba(59,130,246,0.06); border-color: rgba(59,130,246,0.2); color: #2563eb; }
[data-theme="light"] .fpt-body { color: #334155; }
[data-theme="light"] .fpt-body.fpt-empty { color: #94a3b8; }

@media (max-width: 640px) {
  .fpt-tooltip { width: 280px; }
}

/* ── Section Word Limit Enforcer ── */
.swl-trigger-btn {
  position: fixed; bottom: 20px; left: 460px; z-index: 900;
  background: rgba(249,115,22,0.12); color: #fb923c; border: 1px solid rgba(249,115,22,0.25);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600;
  transition: all 0.2s ease;
}
.swl-trigger-btn:hover { background: rgba(249,115,22,0.2); color: #fdba74; }

.swl-panel {
  position: fixed; top: 60px; right: -420px; width: 400px; bottom: 0; z-index: var(--z-popover);
  background: #1e1e2e; border-left: 1px solid rgba(255,255,255,0.06);
  box-shadow: -8px 0 30px rgba(0,0,0,0.3); transition: right 0.3s cubic-bezier(0.4,0,0.2,1);
  display: flex; flex-direction: column; overflow: hidden;
}
.swl-panel.swl-visible { right: 0; }

.swl-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid rgba(255,255,255,0.06);
}
.swl-title { font-size: 15px; font-weight: 700; color: #e2e8f0; }
.swl-close { background: none; border: none; color: #94a3b8; font-size: 20px; cursor: pointer; }
.swl-close:hover { color: #e2e8f0; }

.swl-body { flex: 1; overflow-y: auto; padding: 16px 20px; }

.swl-summary { display: flex; gap: 10px; margin-bottom: 16px; }
.swl-stat {
  flex: 1; text-align: center; background: rgba(255,255,255,0.03); border-radius: 10px; padding: 10px 6px;
  border: 1px solid rgba(255,255,255,0.06);
}
.swl-stat-val { display: block; font-size: 20px; font-weight: 800; color: #fb923c; }
.swl-stat-lbl { font-size: 11px; color: #94a3b8; }
.swl-stat-alert .swl-stat-val { color: #ef4444; }

.swl-list { display: flex; flex-direction: column; gap: 10px; }

.swl-item {
  background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px; padding: 12px 14px;
}
.swl-item.swl-over { border-color: rgba(239,68,68,0.3); background: rgba(239,68,68,0.04); }
.swl-item.swl-warn { border-color: rgba(245,158,11,0.3); background: rgba(245,158,11,0.04); }

.swl-item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.swl-item-name { font-size: 13px; font-weight: 600; color: #e2e8f0; }
.swl-item-count { font-size: 12px; color: #94a3b8; font-weight: 600; font-variant-numeric: tabular-nums; }

.swl-bar-track { height: 6px; background: rgba(255,255,255,0.06); border-radius: 3px; overflow: hidden; }
.swl-bar-fill { height: 100%; border-radius: 3px; transition: width 0.3s ease; }
.swl-bar-ok { background: linear-gradient(90deg, #059669, #34d399); }
.swl-bar-warn { background: linear-gradient(90deg, #d97706, #fbbf24); }
.swl-bar-over { background: linear-gradient(90deg, #dc2626, #ef4444); }

.swl-over-msg { font-size: 11px; color: #ef4444; margin-top: 4px; font-weight: 600; }

.swl-item-edit { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.swl-edit-label { font-size: 11px; color: #64748b; }
.swl-edit-input {
  width: 80px; padding: 4px 8px; border-radius: 6px; font-size: 12px;
  background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.1); color: #e2e8f0;
}
.swl-edit-input:focus { outline: none; border-color: rgba(249,115,22,0.5); }

.swl-empty { text-align: center; color: #64748b; font-size: 13px; padding: 40px 20px; }

.swl-footer {
  display: flex; gap: 8px; padding: 12px 20px; border-top: 1px solid rgba(255,255,255,0.06);
}
.swl-refresh-btn, .swl-reset-btn {
  flex: 1; padding: 8px; border-radius: 8px; font-size: 12px; font-weight: 600; cursor: pointer;
  border: 1px solid rgba(255,255,255,0.1); transition: all 0.15s;
}
.swl-refresh-btn { background: rgba(249,115,22,0.12); color: #fb923c; border-color: rgba(249,115,22,0.25); }
.swl-refresh-btn:hover { background: rgba(249,115,22,0.2); }
.swl-reset-btn { background: rgba(255,255,255,0.04); color: #94a3b8; }
.swl-reset-btn:hover { background: rgba(255,255,255,0.08); }

/* Section Word Limit – light theme */
[data-theme="light"] .swl-trigger-btn { color: #ea580c; background: rgba(249,115,22,0.06); border-color: rgba(249,115,22,0.2); }
[data-theme="light"] .swl-panel { background: #fff; border-color: rgba(0,0,0,0.08); box-shadow: -8px 0 30px rgba(0,0,0,0.1); }
[data-theme="light"] .swl-header { border-color: rgba(0,0,0,0.06); }
[data-theme="light"] .swl-title { color: #1e293b; }
[data-theme="light"] .swl-stat { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.06); }
[data-theme="light"] .swl-stat-val { color: #ea580c; }
[data-theme="light"] .swl-item { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.06); }
[data-theme="light"] .swl-item.swl-over { border-color: rgba(239,68,68,0.25); background: rgba(239,68,68,0.03); }
[data-theme="light"] .swl-item.swl-warn { border-color: rgba(245,158,11,0.25); background: rgba(245,158,11,0.03); }
[data-theme="light"] .swl-item-name { color: #1e293b; }
[data-theme="light"] .swl-item-count { color: #64748b; }
[data-theme="light"] .swl-edit-input { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.1); color: #334155; }
[data-theme="light"] .swl-footer { border-color: rgba(0,0,0,0.06); }
[data-theme="light"] .swl-refresh-btn { background: rgba(249,115,22,0.06); color: #ea580c; }
[data-theme="light"] .swl-reset-btn { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.1); color: #64748b; }

@media (max-width: 640px) {
  .swl-panel { width: 100vw; right: -100vw; }
  .swl-summary { flex-wrap: wrap; }
}

