:root {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  color-scheme: light;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
  --ink: #202020;
  --paper: #fff;
  --line: #c9c9c9;
  --muted: #555;
  --control: #f4f4f4;
  --hover: #e6e6e6;
  --border: #a5a5a5;
  --field-line: #999;
  --link: #174f8a;
  --primary: #285681;
  --primary-hover: #1d4265;
  --focus: #175a9c;
  --danger: #a51b1b;
  --muted-strong: #444;
  --header: #f2f2f2;
  --subtle: #f7f7f7;
  --label: #333;
  --dim: #666;
  --accent: #e4edf7;
  --accent-line: #b9c9da;
  --accent-ink: #153c65;
  --separator: #ddd;
  --active-line: #f0f4f8;
  --cursor: #111;
  --preview-back: #dedede;
  --panel: #fafafa;
  --avatar: #e0e0e0;
  --line-hover: #bbb;
  --border-strong: #aaa;
  --syntax-comment: #626262;
  --syntax-string: #87521b;
  --syntax-keyword: #704090;
  --syntax-number: #8f3b1d;
  --quote: #ededed;
  --comment: #fff1b8;
  --comment-active: #ffdc72;
  --comment-border: #947114;
  --warning: #fff7e6;
  --warning-line: #b9a269;
  --warning-ink: #743d00;
  --error: #fff3f3;
  --error-line: #b14a4a;
  --error-ink: #811414;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e3e5e8;
  --paper: #1c1e22;
  --line: #454950;
  --muted: #afb5be;
  --control: #30343a;
  --hover: #3c424a;
  --border: #68707b;
  --field-line: #737d89;
  --link: #91c5ff;
  --primary: #315f8c;
  --primary-hover: #3c719f;
  --focus: #8cc8ff;
  --danger: #ff9999;
  --muted-strong: #c1c6ce;
  --header: #25282c;
  --subtle: #24272c;
  --label: #d2d6dc;
  --dim: #a9b0ba;
  --accent: #263d54;
  --accent-line: #526e8a;
  --accent-ink: #c4dfff;
  --separator: #3e444c;
  --active-line: #29313b;
  --cursor: #f2f4f7;
  --preview-back: #131518;
  --panel: #22252a;
  --avatar: #3a3e45;
  --line-hover: #68707a;
  --border-strong: #747c87;
  --syntax-comment: #a9b0ba;
  --syntax-string: #e7b77c;
  --syntax-keyword: #c9a2e8;
  --syntax-number: #f0a98f;
  --quote: #30363e;
  --comment: #51451f;
  --comment-active: #70591d;
  --comment-border: #cfac48;
  --warning: #382f20;
  --warning-line: #8d7848;
  --warning-ink: #f3c782;
  --error: #3d2528;
  --error-line: #ca737b;
  --error-ink: #ffc0c6;
}
* { box-sizing: border-box; }
body { margin: 0; }
button, input, select, textarea { font: inherit; }
a { color: var(--link); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 5px 9px;
  min-height: 30px;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.3;
  color: var(--ink);
  background: var(--control);
  text-decoration: none;
}
button:hover, .button:hover { background: var(--hover); text-decoration: none; }
button:disabled { opacity: .55; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
input, select, textarea { padding: 6px; border: 1px solid var(--field-line); border-radius: 2px; background: var(--paper); color: var(--ink); }
.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.primary:hover { background: var(--primary-hover); }
.secondary { background: var(--control); }
.quiet { background: transparent; border-color: transparent; padding: 5px 7px; }
.quiet:hover { background: var(--hover); border-color: var(--line-hover); }
.danger { color: var(--danger); }
.small { padding: 5px 9px; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 24px; font-weight: 600; margin-bottom: 12px; }
h2 { font-size: 18px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
p { color: var(--muted-strong); font-size: 14px; line-height: 1.5; }
.wordmark { color: var(--ink); font-size: 18px; font-weight: 650; text-decoration: none; }
.wordmark.compact { font-size: 13px; font-weight: 400; text-decoration: underline; flex-shrink: 0; }
.dashboard-header { min-height: 48px; border-bottom: 1px solid var(--line); padding: 8px 20px; display: flex; align-items: center; justify-content: space-between; }
.account { display: flex; gap: 12px; align-items: center; font-size: 13px; }
.dashboard { max-width: 1100px; padding: 24px 20px; margin: auto; }
.section-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 12px; }
.section-title h1 { margin: 0; }
.create-project { display: flex; gap: 8px; margin-bottom: 20px; }
.create-project input { flex: 1; min-width: 0; max-width: 480px; }
.project-grid { display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.project-grid:empty { border: 0; }
.project-card { display: flex; align-items: center; gap: 16px; padding: 12px 8px; min-height: 48px; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.project-card:hover { background: var(--subtle); text-decoration: none; }
.project-card h2 { margin: 0; flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: 14px; font-weight: 500; color: var(--link); }
.card-meta { display: flex; gap: 24px; align-items: center; font-size: 12px; color: var(--muted); }
.card-meta span:first-child { text-transform: capitalize; }
.card-meta span:last-child { color: var(--link); text-decoration: underline; }
footer { border-top: 1px solid var(--line); padding: 12px 0; margin-top: 28px; display: flex; gap: 16px; font-size: 12px; }
.empty { padding: 24px 0; }
.empty h2 { font-size: 16px; margin-bottom: 8px; }
.welcome { max-width: 560px; margin: 48px auto; padding: 0 20px; }
.welcome .wordmark { display: inline-block; margin-bottom: 24px; }
.welcome h1 { font-size: 24px; }
.welcome p { margin-bottom: 20px; }
.welcome-note { font-size: 12px; margin-top: 24px; }
.loading { margin: 24px; color: var(--muted); }
.toast { position: fixed; left: 50%; top: 8px; transform: translateX(-50%); z-index: 50; background: var(--error); border: 1px solid var(--error-line); color: var(--error-ink); max-width: 90vw; padding: 8px 12px; display: flex; gap: 16px; align-items: center; font-size: 13px; }
.toast button { padding: 0 5px; background: transparent; font-size: 18px; }
.workspace { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.workspace-header { min-height: 44px; flex-shrink: 0; background: var(--header); border-bottom: 1px solid var(--line); display: flex; align-items: center; padding: 6px 10px; gap: 10px; }
.separator { color: var(--dim); }
.project-name { font-size: 13px; font-weight: 600; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; max-width: 25vw; }
.save-status { font-size: 12px; color: var(--muted-strong); margin-left: 4px; }
.toolbar { display: flex; gap: 4px; margin-left: auto; align-items: center; flex-wrap: wrap; }
.work-area { display: flex; min-height: 0; flex: 1; position: relative; }
.file-sidebar { width: 180px; flex-shrink: 0; border-right: 1px solid var(--line); display: flex; flex-direction: column; background: var(--subtle); }
.sidebar-heading { min-height: 36px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; padding: 4px 10px; border-bottom: 1px solid var(--line); font-size: 11px; font-weight: 600; color: var(--muted-strong); }
.sidebar-heading button { padding: 2px 6px; min-height: 26px; background: transparent; font-size: 16px; }
.sidebar-heading div { display: flex; gap: 2px; }
.file-sidebar nav { padding: 4px; overflow: auto; }
.file { display: flex; align-items: center; justify-content: flex-start; gap: 6px; width: 100%; text-align: left; border: 1px solid transparent; padding: 5px 6px; background: transparent; font-size: 13px; overflow-wrap: anywhere; }
.file.active { background: var(--accent); border-color: var(--accent-line); color: var(--accent-ink); }
.file-symbol { font-size: 13px; color: var(--dim); }
.sidebar-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 12px 10px; font-size: 12px; color: var(--muted); }
.sidebar-bottom .quiet { justify-content: flex-start; font-size: 12px; padding: 2px; }
.sidebar-bottom > span { font-size: 10px; color: var(--muted); }
.editor-pane, .preview-pane { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.editor-pane { background: var(--paper); border-right: 1px solid var(--line); }
.pane-heading { min-height: 36px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; padding: 5px 10px; border-bottom: 1px solid var(--line); font-size: 12px; color: var(--label); background: var(--subtle); gap: 8px; }
.pane-heading > span:last-child { font-size: 11px; color: var(--muted); text-align: right; }
.editor-host { flex: 1; min-height: 0; overflow: hidden; }
.editor-footer { min-height: 24px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; padding: 3px 10px; font-size: 11px; color: var(--muted); gap: 8px; }
.cm-editor { height: 100%; font-size: 14px; background: var(--paper); }
.cm-scroller { overflow: auto; font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace !important; line-height: 1.5; }
.cm-content { padding: 8px 0 !important; }
.cm-line { padding-left: 10px !important; padding-right: 10px !important; }
.cm-gutters { background: var(--subtle) !important; border-right: 1px solid var(--separator) !important; color: var(--dim) !important; }
.cm-gutterElement { padding-left: 8px !important; }
.cm-activeLine, .cm-activeLineGutter { background: var(--active-line) !important; }
.cm-focused { outline: none !important; }
.cm-cursor { border-left-color: var(--cursor) !important; }
.remote-cursor { position: relative; border-left: 2px solid; height: 1.3em; margin-left: -1px; }
.remote-cursor > span { position: absolute; bottom: 100%; left: -2px; white-space: nowrap; font: 11px system-ui; color: #fff; padding: 1px 4px; pointer-events: none; }
.preview-pane { background: var(--preview-back); }
.preview-pages { padding: 16px; overflow: auto; flex: 1; text-align: center; }
.preview-page { display: block; width: 100%; height: auto; border: 1px solid var(--border-strong); margin-bottom: 16px; background: #fff; }
.preview-empty { margin: 32px 16px; color: var(--muted); }
.preview-empty > span { display: none; }
.preview-empty h2 { font-size: 16px; }
.preview-empty p { font-size: 13px; }
.diagnostics { max-height: 180px; overflow: auto; background: var(--warning); border-top: 1px solid var(--warning-line); padding: 8px; }
.diagnostics button { display: block; text-align: left; background: transparent; color: var(--warning-ink); font-size: 12px; }
.detail-panel { width: 300px; flex-shrink: 0; border-left: 1px solid var(--line); background: var(--panel); overflow: auto; }
.panel-content { padding: 12px; }
.panel-content h2 { font-size: 18px; }
.panel-content h3 { font-size: 14px; margin-bottom: 10px; }
.panel-content p { font-size: 13px; }
.panel-content > button { margin-bottom: 8px; max-width: 100%; }
.panel-content label { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; font-size: 13px; color: var(--label); }
.panel-content input, .panel-content select { width: 100%; font-size: 13px; }
.panel-content hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.member { display: flex; align-items: center; gap: 8px; padding: 8px 0; }
.avatar { width: 26px; height: 26px; background: var(--avatar); border: 1px solid var(--line-hover); display: grid; place-items: center; font-size: 12px; color: var(--label); flex-shrink: 0; }
.member strong { font-size: 13px; font-weight: 600; display: block; }
.member small { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; }
.member button { font-size: 12px; margin-left: auto; }
.checkpoint { border-left: 2px solid var(--border-strong); padding: 0 0 12px 10px; margin-top: 16px; display: flex; flex-direction: column; gap: 6px; }
.checkpoint strong { font-size: 13px; font-weight: 600; }
.checkpoint small, .checkpoint > span { font-size: 12px; color: var(--muted); }
.checkpoint button { text-align: left; justify-content: flex-start; font-size: 12px; padding: 3px 5px; }
.syntax-comment { color: var(--syntax-comment); font-style: italic; }
.syntax-string { color: var(--syntax-string); }
.syntax-heading { color: var(--link); font-weight: 650; }
.syntax-keyword { color: var(--syntax-keyword); }
.syntax-number { color: var(--syntax-number); }
.syntax-punctuation { color: var(--muted); }
.syntax-raw { color: var(--muted-strong); }
.preview-page:has(canvas) { height: auto; overflow: hidden; }
.preview-page > canvas { display: block; width: 100%; height: 100%; }
.comments-panel { flex-direction: column; min-width: 300px; width: 340px; }
.comments-panel > .panel-content { overflow: auto; min-height: 0; }
.comment-controls { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.comment-controls select, .comment-composer textarea { width: 100%; }
.comment-thread { padding: 10px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.comment-thread.active { border-left: 2px solid var(--primary); padding-left: 8px; }
.comment-location { font-weight: 600; }
.comment-quote { display: block; width: 100%; text-align: left; white-space: pre-wrap; max-height: 100px; overflow: auto; margin: 6px 0; padding: 6px; border-left: 2px solid var(--border-strong); background: var(--quote); }
.comment-message { margin: 10px 0; }
.comment-message strong, .comment-message small { display: block; }
.comment-message small, .comment-detached, .comment-composer small { font-size: 12px; color: var(--muted); }
.comment-body { white-space: pre-wrap; margin: 5px 0; }
.comment-thread button.quiet { font-size: 12px; }
.comment-detached { display: block; font-style: italic; }
.comment-notice { font-size: 13px; overflow-wrap: anywhere; }
.comment-notice:empty { display: none; }
.comment-composer { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }
.comment-composer:empty { display: none; }
.comment-composer textarea { resize: vertical; min-height: 100px; padding: 6px; }
.comment-composer small { display: block; margin: 6px 0; }
.comment-composer button { margin: 4px 4px 4px 0; }
.comment-drafts button { display: block; text-align: left; overflow-wrap: anywhere; }
.comment-range { background: var(--comment); border-bottom: 1px solid var(--comment-border); cursor: pointer; }
.comment-range.active { background: var(--comment-active); }
@media (max-width: 1100px) {
  .file-sidebar { width: 150px; }
  .detail-panel { position: absolute; right: 0; top: 0; bottom: 0; z-index: 5; border-left: 2px solid var(--border-strong); }
  .save-status { max-width: 110px; overflow: hidden; white-space: nowrap; }
  .preview-pages { padding: 10px; }
}
@media (max-width: 760px) {
  .workspace-header { flex-wrap: wrap; gap: 6px; }
  .project-name { max-width: calc(100vw - 180px); }
  .save-status { margin-left: auto; }
  .toolbar { flex-basis: 100%; margin-left: 0; }
  .toolbar button { padding: 5px 7px; }
  .file-sidebar { width: 120px; height: 55%; }
  .sidebar-heading { padding: 4px 6px; font-size: 10px; }
  .file { padding: 5px 2px; font-size: 12px; }
  .file-symbol { display: none; }
  .work-area { flex-wrap: wrap; }
  .editor-pane { width: calc(100% - 120px); flex: initial; height: 55%; }
  .preview-pane { height: 45%; flex-basis: 100%; border-top: 1px solid var(--line); }
  .pane-heading { padding: 4px 8px; }
  .preview-page { max-width: 500px; margin: 0 auto 12px; }
  .detail-panel, .comments-panel { width: min(340px, 100%); min-width: 0; }
  .dashboard-header { padding: 8px 12px; }
  .dashboard { padding: 16px 12px; }
  .account { gap: 6px; font-size: 12px; }
  .card-meta { gap: 10px; }
  .welcome { margin-top: 24px; }
}

/* Writing assistance stays within the editor; documentation is plain text. */
.cm-tooltip { border: 1px solid var(--field-line) !important; background: var(--paper) !important; color: var(--ink); }
.language-documentation { max-width: min(520px, 85vw); max-height: 300px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; padding: 8px; font: 13px/1.45 system-ui, sans-serif; }
.language-signature { max-width: min(600px, 85vw); max-height: 220px; overflow: auto; padding: 8px; }
.language-signature code { display: block; font: 13px/1.5 "SFMono-Regular", Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.language-signature strong { background: var(--accent); text-decoration: underline; }
.language-signature .language-documentation { padding: 6px 0 0; }
.cm-tooltip-autocomplete > ul { font-size: 13px; }
.cm-tooltip-autocomplete > ul > li[aria-selected] { background: var(--primary) !important; color: #fff !important; }
.cm-completionDetail { color: inherit; opacity: .8; max-width: 260px; display: inline-block; vertical-align: bottom; overflow: hidden; text-overflow: ellipsis; }
.language-status { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-footer > span:last-child { flex-shrink: 0; }
@media (max-width: 1100px) { .editor-footer { flex-wrap: wrap; } .editor-footer > span:last-child { font-size: 10px; } }

/* The canvas supplies appearance; this transparent layer supplies selection. */
.preview-page { position: relative; text-align: left; }
.typst-html-semantics { position: absolute; left: 0; top: 0; --data-text-width: 1px; --data-text-height: 1px; transform-origin: left top; z-index: 2; color: transparent; white-space: pre; font-family: monospace; user-select: text; cursor: text; overflow: hidden; }
.typst-html-semantics span { left: 0; top: 0; position: absolute; display: inline-block; transform-origin: left top; color: transparent; font-family: monospace; }
.typst-html-semantics .typst-content-hint { width: 1px; height: 1px; overflow: hidden; }
.typst-html-semantics .typst-content-fallback { pointer-events: none; user-select: none; }
.typst-html-semantics ::selection { color: transparent; background: #3578c655; }
.preview-location { position: absolute; z-index: 3; pointer-events: none; background: #e8ad2855; outline: 2px solid #a77613; }

/* Discussions belong to the preview UI, separate from the exported document. */
.preview-comments { position: absolute; inset: 0; pointer-events: none; }
.preview-comment-range { position: absolute; background: #f0c34b66; box-shadow: inset 0 -1px #95700b; }
.preview-comment-range.active { background: #e9a52c88; box-shadow: inset 0 -2px #704800; }
.preview-comment-marker { position: absolute; right: 2px; z-index: 4; pointer-events: auto; min-width: 20px; height: 20px; padding: 0 3px; border: 1px solid #95700b; border-radius: 2px; color: #352900; background: #fff0b3; font: bold 11px/18px system-ui, sans-serif; cursor: pointer; }
.preview-comment-marker.active { border: 2px solid #704800; background: #ffd46e; }
.preview-comment-marker:focus-visible { outline: 2px solid #165ba0; outline-offset: 2px; }

/* Flat groups avoid zero-sized positioned ancestors trapping browser carets. */
.typst-html-semantics .typst-content-group { display: contents; }
.typst-html-semantics .typst-glyph-run { pointer-events: none; font-size: 0; line-height: 0; }
.typst-html-semantics .typst-content-glyph { pointer-events: auto; font-kerning: none; font-variant-ligatures: none; }

.theme-control { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; white-space: nowrap; }
.theme-control select { padding: 4px; font-size: 12px; }
.welcome > .theme-control { float: right; }
.cm-editor { color: var(--ink); }
.cm-selectionBackground, .cm-editor.cm-focused .cm-selectionBackground { background: var(--accent-line) !important; }
.cm-content ::selection { background: var(--accent-line); }
.cm-selectionMatch { background: var(--accent); outline: 1px solid var(--accent-line); }
.cm-searchMatch { background: var(--comment); outline: 1px solid var(--comment-border); }
.cm-searchMatch-selected { background: var(--comment-active); }
.cm-panels, .cm-panel.cm-search { background: var(--subtle); color: var(--ink); }
.cm-panel input, .cm-panel button { background: var(--control); color: var(--ink); border-color: var(--border); }

/* Navigation and review keep the live editor mounted to preserve collaboration. */
.project-navigation { display: flex; flex-direction: column; min-height: 0; overflow: auto; }
.project-navigation [hidden] { display: none !important; }
.navigation-tabs { display: flex; padding: 4px; gap: 2px; border-bottom: 1px solid var(--line); }
.navigation-tabs .file { flex: 1; justify-content: center; }
.navigation-tabs [aria-selected="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent-line); }
.navigation-notice { font-size: 11px; color: var(--muted); margin: 6px 8px; overflow-wrap: anywhere; }
.navigation-notice:empty { display: none; }
.tree-root { font-size: 11px; padding: 6px; color: var(--muted); border-bottom: 1px solid var(--line); }
.tree-file { display: flex; align-items: center; }
.tree-file .file { min-width: 0; flex: 1; word-break: break-word; }
.file-actions { padding: 2px 5px; background: transparent; flex-shrink: 0; }
.review-comment-navigation { display: flex; justify-content: space-between; align-items: center; gap: 4px; font-size: 12px; }
.review-comment-navigation button { font-size: 12px; }
.review-mode .editor-pane { display: none; }
.review-mode .comments-panel { width: 360px; }
.review-mode .preview-pane { flex: 1; height: auto; }
.review-mode .preview-pages { padding: 16px max(16px, calc((100% - 860px) / 2)); }
@media (max-width: 1100px) {
  .review-mode .comments-panel { position: static; width: 300px; border-left: 1px solid var(--line); }
}
@media (max-width: 650px) {
  .review-mode .file-sidebar { display: none; }
  .review-mode .preview-pane { height: 60%; flex: 1 0 100%; }
  .review-mode .comments-panel { height: 40%; flex: 1 0 100%; width: 100%; }
}

.app-dialog { color: var(--ink); background: var(--panel); border: 1px solid var(--border-strong); padding: 20px; width: min(440px, calc(100vw - 32px)); max-height: 85dvh; overflow: auto; }
.app-dialog::backdrop { background: rgb(0 0 0 / 45%); }
.app-dialog h2 { font-size: 18px; margin: 0 0 12px; }
.app-dialog p { font-size: 14px; white-space: pre-wrap; }
.app-dialog label { display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.app-dialog input, .app-dialog select { width: 100%; }
.app-dialog .dialog-input { font-size: 0; }
.app-dialog .dialog-input input { font-size: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.project-card > h2 { color: var(--link); }
.project-card > h2 a { color: inherit; }
.project-role { font-size: 12px; color: var(--muted); text-transform: capitalize; }
.project-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.project-actions .small { font-size: 12px; min-height: 28px; padding: 4px 8px; }
.template-manager { margin-top: 28px; border-top: 1px solid var(--line); padding-top: 12px; }
.template-manager summary { cursor: pointer; font-weight: 600; }
.template-manager > p { font-size: 13px; color: var(--muted); max-width: 720px; }
.template-row { display: flex; align-items: center; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.template-row > strong { flex: 1; }
.create-project select { max-width: 240px; }
@media (max-width: 760px) {
  .project-card { flex-wrap: wrap; gap: 8px; }
  .project-card > h2 { flex-basis: calc(100% - 90px); }
  .project-actions { width: 100%; }
  .create-project { flex-wrap: wrap; }
  .create-project input { flex-basis: 100%; max-width: none; }
  .template-row { flex-wrap: wrap; }
}

.project-overview-controls { display:flex; justify-content:space-between; align-items:center; gap:12px; margin:16px 0 10px; font-size:12px; color:var(--muted); }
.project-display-controls {display:flex;align-items:center;justify-content:flex-end;flex-wrap:wrap;gap:8px;}
.project-tag-filter-slot:empty {display:none;}
.project-view-switch { display:flex; gap:4px; }
.project-view-switch [aria-pressed="true"] { background:var(--accent); color:var(--accent-ink); border-color:var(--accent-line); }
.project-cover { display:none; }
.project-grid.project-tiles { display:grid; grid-template-columns:repeat(auto-fill,minmax(210px,1fr)); gap:16px; border-top:0; }
.project-tiles .project-card { flex-direction:column; align-items:stretch; gap:8px; padding:0 12px 12px; border:1px solid var(--line); min-width:0; }
.project-tiles .project-cover { display:flex; height:220px; justify-content:center; align-items:center; background:var(--preview-back); margin:0 -12px 4px; padding:12px; border-bottom:1px solid var(--line); overflow:hidden; text-decoration:none; }
.project-cover img { height:100%; max-width:100%; object-fit:contain; background:#fff; border:1px solid var(--line); }
.project-document-placeholder { height:100%; aspect-ratio:0.71; background:var(--paper); border:1px solid var(--line); display:flex; flex-direction:column; justify-content:center; align-items:center; gap:16px; color:var(--dim); font-size:11px; }
.project-document-placeholder svg { width:44px; height:55px; fill:none; stroke:currentColor; stroke-width:2; }
.project-tiles .project-card h2 { font-size:14px; flex:none; overflow-wrap:anywhere; }
.project-tiles .project-actions { margin-top:auto; gap:4px; }
.project-tiles .project-role { font-size:11px; }
.project-pagination { display:flex; justify-content:center; align-items:center; gap:16px; padding:20px 0 4px; font-size:12px; color:var(--muted); }
@media (max-width:520px) { .project-grid.project-tiles { grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; } .project-tiles .project-cover { height:170px; } .project-tiles .project-actions .small { padding:4px; } .project-pagination { gap:8px; } }

.dashboard-projects-layout {display:flex;gap:20px;align-items:flex-start;}
.dashboard-projects-content {flex:1;min-width:0;}
.project-folders {width:175px;flex-shrink:0;border-right:1px solid var(--line);padding-right:12px;font-size:12px;}
.folder-heading {display:flex;justify-content:space-between;align-items:center;min-height:36px;}
.folder-heading .quiet {padding:2px 6px;}
.project-folders nav {display:flex;flex-direction:column;gap:2px;}
.folder-link {display:block;background:transparent;border:1px solid transparent;text-align:left;padding:7px 6px;min-width:0;overflow-wrap:anywhere;font-size:12px;}
.folder-link.active {background:var(--accent);border-color:var(--accent-line);color:var(--accent-ink);}
.project-folder-row {display:flex;align-items:center;}
.project-folder-row .folder-link {flex:1;}
.folder-action {padding:2px 4px;font-size:13px;}
.project-search {display:flex;align-items:center;gap:6px;margin:12px 0;}
.project-search input {width:100%;min-width:0;}
.project-folder-select {max-width:150px;padding:3px;font-size:11px;}
.project-tiles .project-folder-select {max-width:none;width:100%;}
@media (max-width:760px) {.dashboard-projects-layout {flex-direction:column;gap:12px;} .project-folders {width:100%;border-right:0;border-bottom:1px solid var(--line);padding:0 0 10px;} .project-folders nav {flex-direction:row;flex-wrap:wrap;gap:4px;} .folder-heading {justify-content:flex-start;gap:8px;} }

.create-project {align-items:center;}
.create-project input,.create-project select,.create-project > button {height:36px;margin:0;}
.create-project > button {white-space:nowrap;}
.project-caption {display:flex;align-items:center;gap:8px;flex:1;min-width:0;width:100%;}
.project-title {flex:1;min-width:0;}
.project-title h2 {margin:0 0 3px;max-width:100%;}
.project-title .project-role {font-size:11px;}
.project-menu-trigger {flex-shrink:0;align-self:flex-start;font-size:22px;line-height:1;padding:3px 8px;min-height:28px;}
.project-menu {position:fixed;inset:auto;margin:0;padding:6px;width:210px;max-width:calc(100vw - 16px);max-height:calc(100dvh - 16px);overflow:auto;background:var(--panel);color:var(--ink);border:1px solid var(--border-strong);box-shadow:0 3px 10px rgb(0 0 0 / 15%);}
.project-menu .project-actions {display:flex;flex-direction:column;align-items:stretch;width:auto;margin:0;gap:2px;}
.project-menu .project-actions a,.project-menu .project-actions button,.project-menu > button {display:block;width:100%;padding:7px 8px;margin:0;text-align:left;justify-content:flex-start;border:0;background:transparent;font-size:13px;color:var(--ink);text-decoration:none;}
.project-menu .project-actions a:hover,.project-menu .project-actions button:hover,.project-menu > button:hover {background:var(--subtle);}
.project-menu > button.danger {color:var(--danger);}
.project-folder-label {display:flex;flex-direction:column;gap:5px;margin:6px 0;padding:8px;border-top:1px solid var(--line);border-bottom:1px solid var(--line);font-size:11px;color:var(--muted);}
.project-menu .project-folder-select {max-width:none;width:100%;font-size:12px;}
.project-tiles .project-card {gap:0;padding-bottom:10px;}
.project-tiles .project-cover {margin-bottom:10px;}
.project-tiles .project-card {flex-wrap:nowrap;}
.project-tiles .project-card > .project-caption {flex:0 0 auto;}
@media (max-width:760px) {.project-card > .project-caption {flex-basis:100%;} .create-project select {flex:1;min-width:120px;}}
@media (max-width:520px) {.create-project select {flex-basis:100%;max-width:none;}}

.project-create-actions {justify-content:flex-start;}
.new-project-dialog {width:min(680px,calc(100vw - 32px));}
.new-project-dialog form {display:flex;flex-direction:column;gap:14px;}
.new-project-dialog h2 {margin-bottom:0;}
.new-project-templates {border:0;padding:0;margin:0;min-width:0;}
.new-project-templates legend {font-size:13px;margin-bottom:8px;}
.template-choices {display:grid;grid-template-columns:repeat(auto-fill,minmax(135px,1fr));gap:10px;max-height:330px;overflow:auto;padding:2px;}
.new-project-dialog .template-choice {position:relative;display:flex;flex-direction:column;gap:0;cursor:pointer;border:1px solid var(--line);background:var(--subtle);}
.template-choice:has(input:checked) {border:2px solid var(--primary);}
.template-choice:has(input:focus-visible) {outline:2px solid var(--link);outline-offset:2px;}
.template-choice input {position:absolute;inset:0;opacity:0;width:100%;height:100%;cursor:pointer;z-index:1;}
.template-choice-cover {height:160px;display:flex;align-items:center;justify-content:center;padding:8px;}
.template-choice-cover img {height:100%;max-width:100%;object-fit:contain;background:#fff;}
.template-choice-name {padding:8px;font-size:12px;border-top:1px solid var(--line);text-align:center;overflow-wrap:anywhere;}
.template-placeholder {height:100%;aspect-ratio:0.71;background:var(--paper);border:1px solid var(--line);display:flex;align-items:center;justify-content:center;color:var(--dim);font-size:11px;}
.new-project-error {color:var(--danger);margin:0;}
.new-project-error:empty {display:none;}
.new-project-dialog .dialog-actions {margin-top:0;}
.template-row-preview {width:40px;height:55px;flex-shrink:0;display:flex;justify-content:center;align-items:center;background:var(--preview-back);}
.template-row-preview img {max-height:100%;max-width:100%;object-fit:contain;}
.template-row-preview .template-placeholder {font-size:8px;}
@media(max-width:520px){.template-choices {grid-template-columns:repeat(2,minmax(0,1fr));max-height:290px;}.template-choice-cover{height:140px;}.project-create-actions{justify-content:flex-start;}}
.feature-controls {display:flex;gap:6px;align-items:center;flex-wrap:wrap;}
.feature-dialog {width:min(760px,calc(100vw - 32px));max-height:90vh;overflow:auto;}
.feature-body {display:flex;flex-direction:column;gap:12px;margin-bottom:16px;}
.feature-body form {display:flex;flex-direction:column;gap:12px;}
.feature-body label {display:flex;flex-direction:column;gap:6px;}
.check-label,.feature-body .check-label {display:flex;flex-direction:row;align-items:center;gap:8px;margin:0;line-height:1.4;}
.check-label input {flex:0 0 auto;width:14px;height:14px;margin:0;padding:0;}
.feature-row {display:flex;gap:8px;align-items:center;flex-wrap:wrap;}
.feature-row>span:first-child {flex:1;}
.feature-error {color:var(--danger);}
.feature-error:empty {display:none;}
.inbox-entry {padding:12px 0;border-bottom:1px solid var(--line);overflow-wrap:anywhere;}
.inbox-entry.unread {border-left:3px solid var(--primary);padding-left:12px;}
.inbox-entry small {display:block;color:var(--muted);margin:6px 0;}
.inbox-entry blockquote {margin:8px 0;padding-left:10px;border-left:2px solid var(--line);white-space:pre-wrap;}
.inbox-entry p {white-space:pre-wrap;}
.inbox-entry button {margin:4px 6px 0 0;}
.project-tag-labels {display:flex;align-items:flex-start;gap:4px;flex-wrap:wrap;min-width:0;}
.project-tiles .project-tag-labels {margin-top:auto;padding-top:8px;}
.project-tag-labels:empty {display:none;}
.project-tag-labels span {max-width:100%;font-size:11px;line-height:1.4;padding:2px 5px;border:1px solid var(--line);color:var(--muted);overflow-wrap:anywhere;}
.tag-filter {position:relative;}
.tag-filter > summary {display:flex;align-items:center;gap:6px;list-style:none;cursor:pointer;padding:4px 8px;border:1px solid var(--field-line);border-radius:2px;background:var(--control);font-size:12px;line-height:1.3;}
.tag-filter > summary::-webkit-details-marker {display:none;}
.tag-filter > summary::after {content:"▾";}
.tag-filter > summary:hover {background:var(--hover);}
.tag-filter > summary:focus-visible {outline:2px solid var(--focus);outline-offset:2px;}
.tag-filter-options {position:absolute;top:calc(100% + 4px);right:0;z-index:10;display:flex;flex-direction:column;gap:10px;width:240px;max-width:calc(100vw - 32px);max-height:320px;overflow:auto;padding:12px;border:1px solid var(--line);background:var(--paper);text-align:left;}
.tag-filter-options .check-label {overflow-wrap:anywhere;}
.tag-filter-options > button {align-self:flex-start;}
.template-choice-description {padding:0 8px 8px;font-size:11px;color:var(--muted);}
.upload-status {font-size:12px;padding:5px 10px;color:var(--ink);background:var(--subtle);border-bottom:1px solid var(--line);}
.upload-status.error {color:var(--danger);}

.preview-stage {position:relative;display:flex;flex-direction:column;flex:1;min-height:0;min-width:0;}
.preview-loading {position:absolute;inset:0;display:flex;align-items:center;justify-content:center;gap:10px;pointer-events:none;z-index:2;color:var(--ink);font-size:13px;}
.preview-loading > span:last-child {background:var(--paper);padding:6px 8px;border:1px solid var(--line);}
.preview-spinner {width:24px;height:24px;border:3px solid var(--line);border-top-color:var(--primary);border-radius:50%;animation:preview-spin 0.8s linear infinite;background:var(--paper);}
@keyframes preview-spin {to {transform:rotate(360deg);}}
@media(prefers-reduced-motion:reduce) {.preview-spinner {animation:none;}}
.project-display-controls .tag-filter > summary,
.project-display-controls .project-view-switch > button {box-sizing:border-box;height:30px;padding:5px 9px;font-size:13px;line-height:1.3;}
.project-display-controls {position:relative;}
.project-display-controls .tag-filter {position:static;}

/* Panel dimensions must not invalidate styles on every selectable PDF glyph. */
@property --panel-navigation {syntax:"<length>";inherits:false;initial-value:180px;}
@property --panel-detail {syntax:"<length>";inherits:false;initial-value:300px;}
@property --panel-editor {syntax:"<number>";inherits:false;initial-value:0.5;}
@property --panel-preview {syntax:"<number>";inherits:false;initial-value:0.5;}
@property --panel-stack {syntax:"<length-percentage>";inherits:false;initial-value:55%;}
.workspace .file-sidebar {width:var(--panel-navigation,180px);min-width:0;}
.workspace.sidebar-hidden .file-sidebar {display:none;}
.workspace .editor-pane {flex:var(--panel-editor,0.5) 1 0%;}
.workspace .preview-pane {flex:var(--panel-preview,0.5) 1 0%;}
.workspace .detail-panel {width:var(--panel-detail,300px);}
.workspace.review-mode .preview-pane {flex:1;}
.panel-resizer {position:absolute;z-index:8;cursor:col-resize;touch-action:none;outline:none;}
.panel-resizer[hidden] {display:none;}
.panel-resizer.horizontal {cursor:row-resize;}
.panel-resizer::after {content:"";position:absolute;top:0;bottom:0;left:3px;width:2px;background:transparent;}
.panel-resizer.horizontal::after {top:3px;bottom:auto;left:0;right:0;width:auto;height:2px;}
.panel-resizer:hover::after,.panel-resizer:focus-visible::after {background:var(--primary);}
.resizing-panels,.resizing-panels * {user-select:none!important;cursor:inherit!important;}
@media(max-width:760px){
  .workspace .file-sidebar {height:var(--panel-stack,55%);}
  .workspace .editor-pane {flex:initial;width:calc(100% - var(--panel-navigation,120px));height:var(--panel-stack,55%);}
  .workspace.sidebar-hidden .editor-pane {width:100%;}
  .workspace.review-mode [data-sidebar-toggle] {display:none;}
  .workspace .preview-pane {flex:initial;width:100%;height:calc(100% - var(--panel-stack,55%));}
  .workspace.review-mode .preview-pane {flex:initial;height:var(--panel-stack,60%);}
  .workspace.review-mode .comments-panel {flex:initial;width:100%;height:calc(100% - var(--panel-stack,60%));}
}

/* Motion belongs to UI feedback, never editor or document layout. */
@keyframes ui-fade {from {opacity:0;} to {opacity:1;}}
@keyframes dialog-appear {from {opacity:0;transform:translateY(4px);} to {opacity:1;transform:translateY(0);}}
@keyframes menu-appear {from {opacity:0;transform:translateY(3px);} to {opacity:1;transform:translateY(0);}}
@keyframes discussion-highlight {from {background-color:var(--comment-active);} to {background-color:transparent;}}
@keyframes comment-focus {from {opacity:.4;} to {opacity:1;}}
@media (prefers-reduced-motion:no-preference) {
  button,.button,.file,.folder-link,.tag-filter > summary {
    transition:background-color 100ms ease-out,border-color 100ms ease-out,color 100ms ease-out;
  }
  .app-dialog[open] {animation:dialog-appear 140ms ease-out;}
  .app-dialog[open]::backdrop {animation:ui-fade 140ms ease-out;}
  .project-menu:popover-open,.tag-filter[open] .tag-filter-options {animation:menu-appear 110ms ease-out;}
  .detail-panel {animation:ui-fade 120ms ease-out;}
  .comment-thread.comment-reveal {animation:discussion-highlight 150ms ease-out;}
  .preview-comment-range.comment-reveal {animation:comment-focus 150ms ease-out;}
  .comment-range {transition:background-color 100ms ease-out;}
  .document-thumbnail {transition:opacity 150ms ease-out;}
  .document-thumbnail:not(.thumbnail-loaded) {opacity:0;}
}

/* Keep project, personal and file actions in their respective contexts. */
.workspace-mode {display:inline-flex;gap:0;}
.workspace-mode button + button {border-left:0;}
.workspace-mode [aria-pressed="true"] {background:var(--accent);border-color:var(--accent-line);color:var(--accent-ink);}
.account-menu,.export-menu {position:relative;flex-shrink:0;}
.account-menu > summary {cursor:pointer;font-size:13px;padding:5px 8px;max-width:180px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
.account-actions,.export-actions {position:absolute;right:0;top:calc(100% + 4px);z-index:20;min-width:210px;padding:6px;background:var(--panel);border:1px solid var(--border-strong);box-shadow:0 3px 10px rgb(0 0 0 / 15%);}
.account-actions > button,.export-actions > button,.export-actions > a {display:block;width:100%;text-align:left;padding:8px;border:0;font-size:13px;text-decoration:none;}
.account-actions > button,.export-actions > button {background:transparent;}
.export-actions > a:hover,.account-actions > button:hover,.export-actions > button:hover {background:var(--subtle);}
.account-actions > button:last-child {border-top:1px solid var(--line);}
.project-opened {display:block;font-size:11px;color:var(--muted);margin-top:4px;}
.project-tiles .project-opened {display:none;}
.active-project-filters {display:flex;align-items:center;gap:6px;flex-wrap:wrap;}
.active-project-filters:not(:empty) {margin:8px 0;}
.filter-chip {font-size:12px;min-height:26px;padding:3px 7px;}
.main-file-badge {font-size:10px;color:var(--muted);border:1px solid var(--line);padding:1px 3px;align-self:center;white-space:nowrap;}
.project-menu .file-delete {border-top:1px solid var(--line);margin-top:4px;}
.preview-controls {display:flex;align-items:center;gap:6px;padding:5px 10px;flex-shrink:0;border-bottom:1px solid var(--line);font-size:12px;flex-wrap:wrap;}
.preview-controls label {display:inline-flex;align-items:center;gap:4px;}
.preview-controls label:last-child {margin-left:auto;}
.preview-controls input {width:54px;font-size:12px;padding:3px;}
.preview-controls select {font-size:12px;padding:3px;}
.preview-help {display:flex;align-items:center;justify-content:space-between;gap:6px;font-size:11px;padding:4px 10px;border-bottom:1px solid var(--line);color:var(--muted);flex-shrink:0;}
.preview-help[hidden],[data-file-control][hidden] {display:none;}
.preview-help button {font-size:14px;min-height:22px;padding:0 4px;}
.comment-composer:not(:empty) {padding:10px 0;border-block:1px solid var(--line);margin:8px 0;}
.comment-tools {font-size:12px;color:var(--muted);margin:12px 0;}
.comment-tools summary {cursor:pointer;}
.comment-tools button {font-size:12px;margin-top:6px;}
@media(max-width:760px){
 .workspace-header .project-name {max-width:40vw;}
 .workspace-header .account-menu > summary {max-width:120px;}
 .workspace-header > .toolbar {gap:3px;}
 .workspace-header .workspace-share {margin-left:0;}
 .export-actions {right:0;max-width:calc(100vw - 20px);}
}
@media(prefers-reduced-motion:no-preference){.account-menu[open] .account-actions,.export-menu[open] .export-actions{animation:menu-appear 110ms ease-out;}}
.app-feedback {position:fixed;bottom:16px;left:50%;transform:translateX(-50%);z-index:100;padding:8px 12px;border:1px solid var(--border-strong);background:var(--panel);color:var(--ink);font-size:13px;max-width:calc(100vw - 24px);}
.preview-controls[hidden] {display:none;}
.export-actions > small {display:block;padding:8px;color:var(--muted);font-size:11px;border-top:1px solid var(--line);}

/* A single header row; less-used actions live in the Project menu. */
.workspace-header {flex-wrap:nowrap;gap:6px 10px;}
.workspace-header > .toolbar {order:initial;flex-basis:auto;margin-left:auto;flex-wrap:nowrap;flex-shrink:0;}
.workspace-header > .feature-controls {margin-left:0;}
.workspace-header .project-name {min-width:30px;flex-shrink:1;}
.workspace-header .connection-status {max-width:125px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:11px;}
.workspace-header .save-status {white-space:nowrap;font-size:11px;}
.workspace-share {margin-left:0;}
.project-tools {position:relative;flex-shrink:0;}
.export-actions > strong {display:block;padding:6px 8px;font-size:12px;overflow-wrap:anywhere;border-bottom:1px solid var(--line);}
.project-tools .compact-only,.compact-inbox {display:none;}
.sidebar-toggle {padding:5px;flex-shrink:0;}
@media(max-width:1100px){
 .workspace-header .workspace-share,.workspace-header .export-menu {display:none;}
 .project-tools .compact-only {display:block;}
 .workspace-header .connection-status {display:none;}
}
@media(max-width:760px){
 .workspace-header {gap:4px;padding:6px;}
 .workspace-header .project-name,.workspace-header .separator,.workspace-header .save-status,.workspace-header > .feature-controls {display:none;}
 .workspace-header .toolbar {flex-basis:auto;margin-left:auto;gap:3px;}
 .workspace-header .account-menu > summary {max-width:70px;padding:5px 3px;}
 .workspace-header .comments-label {display:none;}
 .project-tools > summary {font-size:0;min-width:28px;padding:5px;}
 .project-tools > summary::after {content:'⋮';font-size:18px;line-height:18px;}
 .project-tools .export-actions {right:-70px;}
 .compact-inbox {display:block;}
}
@media(max-width:760px){
 .workspace-header .save-status {display:inline;font-size:0;margin-left:0;}
 .workspace-header .save-status::before {content:'●';font-size:10px;color:var(--muted);}
 .workspace-header .save-status[data-state="Unsaved changes"]::before,.workspace-header .save-status[data-state="Saving…"]::before {color:var(--warning-ink);}
}
.format-badge {font-size:10px;margin-left:6px;padding:2px 4px;border:1px solid var(--line);color:var(--muted);}
.latex-page .pdf-text-layer {z-index:2;}
.latex-page .pdf-text-layer ::selection {background:#3578c655;}
.preview-controls [hidden] {display:none;}
