/* Bare content styles — rendered inside iframe */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #fff;
    --bg-wash: #f7f8fa;
    --bg-hover: #f0f1f4;
    --text: #1b2733;
    --text-secondary: #5c6a79;
    --text-muted: #8f99a8;
    --border: #e8ebed;
    --border-light: #f0f1f3;
    --primary: #2b6cb0;
    --primary-hover: #2c5282;
    --primary-light: #ebf4ff;
    --danger: #d94848;
    --radius: 6px;
    --radius-lg: 10px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    --font-mono: "SF Mono", "Fira Code", "Consolas", monospace;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark mode */
[data-theme="dark"] {
    --bg: #191b1f;
    --bg-wash: #1e2024;
    --bg-hover: #2a2d32;
    --text: #e0e4e8;
    --text-secondary: #a0a8b4;
    --text-muted: #6b7280;
    --border: #2e3138;
    --border-light: #262930;
    --primary: #5b9bd5;
    --primary-hover: #4a8ac4;
    --primary-light: rgba(91,155,213,0.12);
    --danger: #e06060;
    --radius: 6px;
    --radius-lg: 10px;
    color-scheme: dark;
}

body {
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    line-height: 1.6;
    font-size: 15px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; border: none; background: none; cursor: pointer; color: inherit; }

/* Topbar */
.topbar {
    position: sticky;
    top: 0;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 24px;
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    z-index: 5;
}
[data-theme="dark"] .topbar { background: rgba(25,27,31,0.95); }
.topbar-toggle-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    margin-left: 8px;
}
.topbar-toggle-btn:hover { background: var(--bg-hover); color: var(--text); }
/* New doc button — small, outlined */
.btn-new-doc-sm {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 12px; font-size: 13px; font-weight: 500;
    border: 1px solid var(--border); border-radius: 6px;
    background: var(--bg); color: var(--text); text-decoration: none;
    cursor: pointer; white-space: nowrap; margin-left: 4px;
}
.btn-new-doc-sm:hover { background: var(--bg-hover); }
.btn-new-doc-sm svg { flex-shrink: 0; }
[data-theme="dark"] .btn-new-doc-sm { background: var(--bg-wash); }
/* Document context area in topbar: collection/title + TOC + star */
.topbar-doc-context {
    flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px;
}
.topbar-scroll-title {
    font-size: 14px; font-weight: 500; color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    opacity: 0; transition: opacity 0.15s;
}
.topbar-scroll-title.visible { opacity: 1; }
.topbar-scroll-icon { display: inline-flex; vertical-align: middle; margin-right: 4px; }
.topbar-scroll-icon svg { width: 16px; height: 16px; }
.breadcrumb-icon { display: inline-flex; vertical-align: middle; margin-right: 4px; }
.breadcrumb-icon svg { width: 16px; height: 16px; }
.topbar-sep { color: var(--text-muted); font-size: 14px; opacity: 0; transition: opacity 0.15s; }
.topbar-scroll-title.visible ~ .topbar-sep { opacity: 1; }
.topbar-icon-btn {
    background: none; border: none; cursor: pointer; color: var(--text-secondary);
    padding: 4px; border-radius: 4px; display: flex; align-items: center; flex-shrink: 0;
}
.topbar-icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.topbar-icon-btn.starred svg { fill: #f0b429; color: #f0b429; }
/* TOC sidebar */
.toc-sidebar {
    display: none;
    width: 100%;
    font-size: 13px; line-height: 1.5;
    position: sticky; top: 64px; align-self: start;
    max-height: calc(100vh - 80px); overflow-y: auto;
    min-width: 0;
}
.toc-sidebar.open { display: block; }
.page-container.page-document.toc-open {
    display: grid;
    grid-template-columns: minmax(170px, 220px) minmax(0, 800px);
    column-gap: 28px;
    max-width: 1100px;
    width: 100%;
}
.doc-content-wrap { min-width: 0; }
.page-document[data-document-page] > .doc-content-wrap > .breadcrumb { display: none; }
.toc-sidebar-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); padding: 0 0 8px; }
.toc-sidebar a {
    display: block; padding: 3px 0; color: var(--text-secondary); text-decoration: none;
    cursor: pointer;
}
.toc-sidebar a:hover { color: var(--primary); }
.toc-sidebar a.toc-active { color: var(--primary); font-weight: 500; }
.toc-sidebar a.toc-h2 { padding-left: 14px; }
.toc-sidebar a.toc-h3 { padding-left: 28px; }
.toc-sidebar a.toc-h4 { padding-left: 42px; }

/* Workspace */
.workspace { padding: 0; }

.page-container {
    max-width: 760px;
    margin: 0 auto;
    padding: 28px 32px;
    overflow-wrap: break-word;
    word-wrap: break-word;
}
.page-container.page-narrow { max-width: 560px; }
.page-container.page-editor { max-width: 960px; }
.page-container.page-document { max-width: 800px; position: relative; overflow: visible; }
.page-container.docs-page { max-width: 980px; }

.page-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 16px;
    line-height: 1.25;
}

.page-description { color: var(--text-secondary); margin-bottom: 24px; }

/* Docs page */
.docs-page { padding-top: 32px; padding-bottom: 40px; }
.docs-hero {
    position: relative;
    margin-bottom: 28px;
    padding: 28px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background:
        radial-gradient(circle at top right, rgba(59,130,246,0.12), transparent 32%),
        radial-gradient(circle at bottom left, rgba(16,185,129,0.10), transparent 28%),
        linear-gradient(180deg, var(--bg) 0%, var(--bg-wash) 100%);
    overflow: hidden;
}
.docs-kicker {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(59,130,246,0.10);
    color: var(--primary);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.docs-hero .page-title { margin-bottom: 10px; font-size: 36px; }
.docs-hero .page-description {
    max-width: 720px;
    margin-bottom: 0;
    font-size: 16px;
    line-height: 1.65;
}
.docs-summary-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-top: 22px;
}
.docs-summary-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: rgba(255,255,255,0.65);
    backdrop-filter: blur(8px);
}
.docs-summary-card strong {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
}
.docs-summary-card span {
    font-size: 13px;
    line-height: 1.55;
    color: var(--text-secondary);
}
.docs-markdown {
    padding: 28px 32px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--bg);
    box-shadow: 0 18px 44px rgba(15, 23, 42, 0.05);
}
.docs-markdown h2 {
    margin-top: 2.25em;
    padding-top: 0.15em;
}
.docs-markdown h2:first-child { margin-top: 0; }
.docs-markdown h3 { color: var(--text); }
.docs-markdown p,
.docs-markdown li { font-size: 15px; }
.docs-markdown blockquote {
    border-left-width: 4px;
    background: linear-gradient(180deg, var(--bg-wash) 0%, rgba(59,130,246,0.05) 100%);
}
.docs-markdown table { table-layout: auto; }
.docs-markdown td:first-child code,
.docs-markdown th:first-child { white-space: nowrap; }

@media (max-width: 720px) {
    .docs-page { padding-top: 20px; }
    .docs-hero { padding: 22px 18px; border-radius: 14px; }
    .docs-hero .page-title { font-size: 30px; }
    .docs-summary-grid { grid-template-columns: 1fr; }
    .docs-markdown { padding: 20px 18px; border-radius: 14px; }
}

[data-theme="dark"] .docs-kicker { background: rgba(96,165,250,0.15); }
[data-theme="dark"] .docs-summary-card { background: rgba(15,23,42,0.55); }
[data-theme="dark"] .docs-markdown { box-shadow: none; }

/* Page header */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}
.page-header h1 { margin-bottom: 0; }
.page-header-left { display: flex; align-items: center; gap: 12px; }
.page-header-actions { display: flex; gap: 8px; flex-shrink: 0; padding-top: 4px; }

.collection-dot-lg { width: 14px; height: 14px; border-radius: 4px; flex-shrink: 0; }

/* Tab bar */
.tab-bar { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 20px; gap: 0; }
.tab {
    padding: 8px 10px; font-size: 13px; font-weight: 500; color: var(--text-muted);
    border-bottom: 2px solid transparent; cursor: pointer; background: none;
    transition: color var(--transition), border-color var(--transition);
    text-decoration: none; white-space: nowrap;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--text); border-bottom-color: var(--primary); }

/* Breadcrumb */
.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb-sep { color: var(--border); }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px;
    border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px;
    font-weight: 500; cursor: pointer; text-decoration: none; background: var(--bg);
    color: var(--text); transition: all var(--transition); white-space: nowrap;
}
.btn:hover { text-decoration: none; background: var(--bg-hover); }
.btn svg { flex-shrink: 0; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-danger-text { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 13px; padding: 4px 0; }
.btn-danger-text:hover { text-decoration: underline; }
.btn-icon-sm {
    display: inline-flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; border-radius: 4px; color: var(--text-muted);
    opacity: 0; transition: opacity var(--transition);
}
.btn-icon-sm:hover { background: var(--bg-hover); color: var(--text); }

/* Doc card list */
.doc-card-list { display: flex; flex-direction: column; }
.doc-card-row { display: flex; align-items: center; }
.doc-card-row:hover .btn-icon-sm { opacity: 1; }
.doc-card {
    display: flex; align-items: flex-start; gap: 14px; padding: 14px 4px;
    border-bottom: 1px solid var(--border-light); text-decoration: none;
    color: var(--text); transition: background var(--transition); flex: 1; min-width: 0;
}
.doc-card:hover { text-decoration: none; background: var(--bg-wash); }
.doc-card-icon { color: var(--text-muted); padding-top: 1px; flex-shrink: 0; }
.doc-card-content { min-width: 0; flex: 1; }
.doc-card-title { font-size: 15px; font-weight: 600; color: var(--text); line-height: 1.35; margin-bottom: 3px; }
.doc-card-meta { font-size: 13px; color: var(--text-muted); }
.doc-card-author { color: var(--text-secondary); }
.doc-card-collection { color: var(--primary); }
.btn-use-template { white-space: nowrap; margin-right: 8px; }

/* Collection doc list (Outline-style) */
.doc-list { display: flex; flex-direction: column; }
.doc-list-item {
    display: flex; align-items: flex-start; gap: 12px; padding: 12px 0;
    text-decoration: none; color: var(--text);
}
.doc-list-item:hover { text-decoration: none; }
.doc-list-item:hover .doc-list-title { color: var(--primary); }
.doc-list-icon { color: var(--text-muted); padding-top: 2px; flex-shrink: 0; }
.doc-list-content { min-width: 0; flex: 1; }
.doc-list-title { font-size: 16px; font-weight: 600; color: var(--text); line-height: 1.35; transition: color var(--transition); }
.doc-list-meta { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* Document content */
.doc-meta { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); margin-bottom: 28px; flex-wrap: wrap; }
.doc-meta-sep { color: var(--border); }
.doc-content { line-height: 1.7; font-size: 15px; overflow-wrap: anywhere; }

/* Markdown typography */
.doc-content h1 { font-size: 1.75em; font-weight: 700; margin: 1.5em 0 0.5em; padding-bottom: 0.3em; border-bottom: 1px solid var(--border, #e8ebed); }
.doc-content h2 { font-size: 1.4em; font-weight: 600; margin: 1.4em 0 0.4em; padding-bottom: 0.25em; border-bottom: 1px solid var(--border, #e8ebed); }
.doc-content h3 { font-size: 1.15em; font-weight: 600; margin: 1.3em 0 0.3em; }
.doc-content h4, .doc-content h5, .doc-content h6 { font-size: 1em; font-weight: 600; margin: 1.2em 0 0.3em; }
.doc-content h1:first-child, .doc-content h2:first-child, .doc-content h3:first-child { margin-top: 0; }
.doc-content p { margin: 0 0 1em; }
.doc-content ul, .doc-content ol { margin: 0 0 1em; padding-left: 1.8em; }
.doc-content li { margin: 0.25em 0; }
.doc-content li > ul, .doc-content li > ol { margin: 0.25em 0 0.25em; }
.doc-content blockquote { margin: 0 0 1em; padding: 0.5em 1em; border-left: 3px solid var(--primary, #2b6cb0); background: var(--bg-wash, #f7f8fa); border-radius: 0 4px 4px 0; color: var(--text-secondary, #5c6a79); }
.doc-content blockquote p:last-child { margin-bottom: 0; }
.doc-content code { font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; font-size: 0.875em; padding: 0.15em 0.35em; background: var(--bg-hover, #f0f1f4); border-radius: 3px; }
.doc-content pre { margin: 0 0 1em; padding: 1em; background: #1b2733; color: #e8ebed; border-radius: 6px; overflow-x: auto; line-height: 1.5; }
.doc-content pre code { padding: 0; background: none; border-radius: 0; color: inherit; font-size: 0.85em; }
.doc-content table { border-collapse: collapse; margin: 0 0 1em; width: 100%; table-layout: fixed; }
.doc-content th, .doc-content td { padding: 8px 12px; border: 1px solid var(--border, #e8ebed); text-align: left; white-space: normal; word-break: break-word; overflow-wrap: anywhere; }
.doc-content th { background: var(--bg-wash, #f7f8fa); font-weight: 600; }
.doc-content tr:nth-child(even) { background: #fafbfc; }
.doc-content img { max-width: 100%; border-radius: 4px; }
.video-embed {
    position: relative;
    width: 100%;
    margin: 0 0 1.25em;
    padding-top: 56.25%;
    border: 1px solid var(--border, #e8ebed);
    border-radius: 12px;
    overflow: hidden;
    background:
        radial-gradient(circle at top right, rgba(59,130,246,0.12), transparent 32%),
        linear-gradient(180deg, #101923 0%, #0b1118 100%);
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
}
.video-embed iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}
.video-embed-card { margin: 0 0 1.25em; }
.video-embed-card .video-embed { margin-bottom: 0.65em; }
.video-embed-link-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.video-embed-link {
    display: inline-flex;
    max-width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--border, #e8ebed);
    border-radius: 999px;
    background: var(--bg-wash, #f7f8fa);
    color: var(--text-secondary, #5c6a79);
    font-size: 13px;
    line-height: 1.4;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.video-embed-link:hover {
    color: var(--primary, #2b6cb0);
    text-decoration: none;
}
.media-previews {
    display: none;
    margin-top: 18px;
    padding: 18px 18px 4px;
    border: 1px solid var(--border, #e8ebed);
    border-radius: 16px;
    background:
        linear-gradient(180deg, rgba(255,255,255,0.92) 0%, rgba(247,248,250,0.96) 100%);
}
.media-previews[hidden] { display: none !important; }
.media-previews-title {
    margin: 0 0 14px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-secondary, #5c6a79);
}
.media-preview-card { margin: 0 0 18px; }
.media-preview-card:last-child { margin-bottom: 0; }
.media-preview-copy { white-space: nowrap; }
.doc-content hr { border: none; border-top: 1px solid var(--border, #e8ebed); margin: 1.5em 0; }
.doc-content a { color: var(--primary, #2b6cb0); text-decoration: none; }
.doc-content a:hover { text-decoration: underline; }
.doc-content input[type="checkbox"] { margin-right: 0.4em; }

/* Mermaid diagrams */
.doc-content pre:has(> code.language-mermaid),
.doc-content pre:has(> code.language-mermaidjs) { visibility: hidden; max-height: 0; overflow: hidden; margin: 0; padding: 0; }
.mermaid-container { position: relative; border: 1px solid var(--border, #e8ebed); border-radius: 8px; margin: 0 0 1em; padding: 24px 16px; background: #fff; }
.mermaid-container .mermaid { display: flex; justify-content: center; }
.mermaid-container .mermaid svg { max-width: 100%; height: auto; }
.mermaid-toolbar { position: absolute; top: 8px; right: 8px; display: flex; gap: 4px; opacity: 0; transition: opacity 0.15s; }
.mermaid-container:hover .mermaid-toolbar { opacity: 1; }
.mermaid-toolbar button { padding: 4px 8px; border: 1px solid var(--border, #e8ebed); border-radius: 4px; background: var(--bg, #fff); color: var(--text-secondary, #5c6a79); font-size: 12px; cursor: pointer; display: flex; align-items: center; gap: 4px; }
.mermaid-toolbar button:hover { background: var(--bg-hover, #f0f1f4); }
.mermaid-source { display: none; margin-top: 12px; padding: 12px; background: #1b2733; color: #e8ebed; border-radius: 6px; font-family: "SFMono-Regular", Consolas, monospace; font-size: 13px; line-height: 1.5; white-space: pre-wrap; overflow-x: auto; }
.mermaid-source.visible { display: block; }

/* Diagram lightbox */
.diagram-lightbox { display: none; position: fixed; inset: 0; z-index: 1000; background: rgba(255,255,255,0.98); }
.diagram-lightbox.visible { display: block; }
.lightbox-controls { position: fixed; top: 16px; right: 16px; display: flex; gap: 4px; z-index: 1002; }
.lightbox-controls button { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border-radius: 8px; color: var(--text-secondary, #5c6a79); background: var(--bg, #fff); border: 1px solid var(--border, #e8ebed); cursor: pointer; transition: background 0.15s; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.lightbox-controls button:hover { background: var(--bg-hover, #f0f1f4); color: var(--text, #1b2733); }
.lightbox-nav { position: fixed; top: 50%; transform: translateY(-50%); z-index: 1002; width: 48px; height: 48px; display: flex; align-items: center; justify-content: center; border-radius: 50%; color: var(--text-muted, #8f99a8); background: var(--bg, #fff); border: 1px solid var(--border, #e8ebed); box-shadow: 0 1px 3px rgba(0,0,0,0.08); cursor: pointer; transition: color 0.15s; }
.lightbox-nav:hover { color: var(--text, #1b2733); background: var(--bg-hover, #f0f1f4); }
.lightbox-prev { left: 16px; }
.lightbox-next { right: 16px; }
.lightbox-content { position: absolute; inset: 0; overflow: auto; display: flex; align-items: center; justify-content: center; padding: 60px 80px; }
.lightbox-content svg { width: auto; height: auto; }

/* Collapsible headings */
.doc-content h1, .doc-content h2, .doc-content h3, .doc-content h4 { position: relative; cursor: default; scroll-margin-top: 64px; }
.heading-toggle { position: absolute; left: -24px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; color: var(--text-muted, #8f99a8); cursor: pointer; opacity: 0; transition: opacity 0.15s; border-radius: 3px; }
.heading-toggle:hover { background: var(--bg-hover, #f0f1f4); color: var(--text, #1b2733); }
.doc-content h1:hover .heading-toggle,
.doc-content h2:hover .heading-toggle,
.doc-content h3:hover .heading-toggle { opacity: 1; }
.heading-toggle.collapsed svg { transform: rotate(-90deg); }
.heading-collapsed { display: none; }

/* Selection toolbar */
.selection-toolbar { position: absolute; display: none; background: #1b2733; border-radius: 6px; padding: 4px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); z-index: 100; white-space: nowrap; }
.selection-toolbar.visible { display: flex; }
.selection-toolbar button { padding: 5px 8px; color: #fff; border-radius: 4px; font-size: 13px; cursor: pointer; display: flex; align-items: center; line-height: 1; }
.selection-toolbar button:hover { background: rgba(255,255,255,0.15); }
.selection-toolbar button.active { background: rgba(255,255,255,0.2); outline: 1px solid rgba(255,255,255,0.3); }
.selection-toolbar .sep { width: 1px; background: rgba(255,255,255,0.2); margin: 2px 2px; }
.selection-toolbar.link-bar { padding: 4px 6px; gap: 4px; }
.selection-toolbar.link-bar input { background: rgba(255,255,255,0.1); border: none; color: #fff; font-size: 13px; padding: 4px 8px; border-radius: 4px; outline: none; width: 200px; font-family: var(--font); }
.selection-toolbar.link-bar input::placeholder { color: rgba(255,255,255,0.4); }
.selection-toolbar.link-bar input:focus { background: rgba(255,255,255,0.15); }
.selection-toolbar.link-bar.visible { display: flex; align-items: center; }

/* Star button */
.star-btn { padding: 4px; border-radius: 4px; color: var(--text-muted); fill: none; cursor: pointer; transition: color var(--transition); flex-shrink: 0; }
.star-btn:hover { color: #f0b429; }
.star-btn.starred { color: #f0b429; fill: #f0b429; }
.star-btn svg { display: block; fill: inherit; }

/* Home sections */
.home-section { margin-bottom: 32px; }
.home-section-title { font-size: 14px; font-weight: 600; color: var(--text-secondary); margin-bottom: 12px; display: flex; align-items: center; gap: 6px; }

/* Icon picker */
.icon-picker-row { display: flex; align-items: center; gap: 8px; }
.icon-preview { width: 44px; height: 44px; border: 2px dashed var(--border); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 24px; cursor: pointer; background: var(--bg-wash); transition: border-color 0.15s; }
.icon-preview:hover { border-color: var(--primary); }
.icon-preview svg { display: block; }
.icon-display-empty { color: var(--text-muted); font-size: 20px; }
.icon-picker { margin-top: 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); box-shadow: 0 4px 16px rgba(0,0,0,0.08); max-height: min(420px, 60vh); overflow: hidden; display: flex; flex-direction: column; }
.icon-picker-tabs { display: flex; border-bottom: 1px solid var(--border); padding: 0 8px; flex-shrink: 0; }
.icon-tab { padding: 8px 14px; font-size: 13px; font-weight: 600; color: var(--text-secondary); border-bottom: 2px solid transparent; cursor: pointer; }
.icon-tab:hover { color: var(--text); }
.icon-tab.active { color: var(--primary); border-color: var(--primary); }
.icon-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.icon-color-row { display: flex; align-items: center; gap: 6px; padding: 10px 10px 2px; flex-wrap: wrap; flex-shrink: 0; }
.icon-color-dot { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; transition: transform 0.1s, border-color 0.1s; flex-shrink: 0; }
.icon-color-dot:hover { transform: scale(1.15); }
.icon-color-dot.active { border-color: var(--text); transform: scale(1.15); }
.icon-picker-search { padding: 8px; flex-shrink: 0; }
.icon-picker-search input { width: 100%; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 13px; outline: none; box-sizing: border-box; }
.icon-picker-search input:focus { border-color: var(--primary); }
.icon-picker-grid { padding: 0 8px 8px; overflow-y: scroll; flex: 1; min-height: 0; }
.icon-picker-grid::-webkit-scrollbar { width: 8px; }
.icon-picker-grid::-webkit-scrollbar-track { background: transparent; }
.icon-picker-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.icon-picker-grid::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
.icon-category-label { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; padding: 8px 0 4px; }
.icon-category-items { display: flex; flex-wrap: wrap; gap: 2px; }
.icon-item { width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; font-size: 18px; border-radius: 6px; cursor: pointer; transition: background 0.1s; }
.icon-item:hover { background: var(--bg-hover); }
.icon-item svg { display: block; }

/* Draft badge */
.draft-badge { display: inline-block; font-size: 11px; font-weight: 600; color: #b45309; background: #fef3c7; padding: 2px 8px; border-radius: 10px; text-transform: uppercase; letter-spacing: 0.04em; vertical-align: middle; margin-left: 4px; }

/* Drafts page */
.drafts-toolbar { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.drafts-toolbar-label { font-size: 14px; font-weight: 600; color: var(--text); }
.drafts-filters { display: flex; gap: 8px; }
.filter-select {
    appearance: none; -webkit-appearance: none;
    background: var(--bg) url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%235c6a79' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 8px center;
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 5px 26px 5px 10px; font-size: 13px; font-family: var(--font);
    color: var(--text-secondary); cursor: pointer; outline: none;
}
.filter-select:hover { border-color: var(--text-muted); }
.filter-select:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(43,108,176,0.12); }
.drafts-divider { border: none; border-top: 1px solid var(--border); margin: 8px 0 0; }
.drafts-empty { color: var(--text-muted); font-size: 15px; padding: 24px 0; }

/* Collection icon in header */
.collection-icon-lg { display: flex; align-items: center; flex-shrink: 0; }
.collection-icon-lg svg { display: block; }
.collection-icon-lg span { line-height: 1; }

/* Templates page */
.templates-ideas { margin-bottom: 20px; }
.templates-hint { font-size: 14px; color: var(--text-secondary); }
.templates-hint summary { cursor: pointer; font-weight: 600; color: var(--text-secondary); padding: 8px 0; }
.templates-hint summary:hover { color: var(--text); }
.templates-hint ul { margin: 8px 0 12px; padding-left: 1.5em; }
.templates-hint li { margin: 6px 0; line-height: 1.5; }
.templates-hint p { margin: 8px 0 0; line-height: 1.5; }

/* Template picker */
.template-picker { margin-bottom: 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.template-picker-label { font-size: 13px; color: var(--text-muted); }

/* Share popover */
.doc-actions-row { position: relative; }
.share-popover { position: absolute; right: 0; top: 100%; margin-top: 4px; z-index: 50; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: 0 4px 16px rgba(0,0,0,0.1); min-width: 320px; }
.share-popover-content { padding: 16px; }
.share-popover p { font-size: 13px; color: var(--text-secondary); margin-bottom: 10px; }
.share-link-row { display: flex; gap: 6px; }
.share-url-input { flex: 1; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 13px; font-family: var(--font-mono); background: var(--bg-wash); }

/* Document "···" menu */
.doc-menu-wrap { position: absolute; right: 0; top: 0; z-index: 10; }
.doc-menu-trigger {
    background: none; border: 1px solid var(--border); border-radius: 6px; cursor: pointer;
    color: var(--text-secondary); padding: 4px 8px; display: flex; align-items: center;
}
.doc-menu-trigger:hover { background: var(--bg-hover); color: var(--text); }
.doc-menu-trigger svg { display: block; }
.doc-menu {
    z-index: 100; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-lg);
    box-shadow: 0 4px 16px rgba(0,0,0,0.12); min-width: 200px; padding: 4px 0;
}
.doc-menu-item {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 14px;
    font-size: 14px; color: var(--text); background: none; border: none; cursor: pointer;
    text-decoration: none; font-family: inherit; text-align: left;
}
.doc-menu-item:hover { background: var(--bg-hover); }
.doc-menu-item svg { flex-shrink: 0; color: var(--text-secondary); }
.doc-menu-danger { color: var(--danger); }
.doc-menu-danger svg { color: var(--danger); }
.doc-menu-sep { height: 1px; background: var(--border); margin: 4px 0; }

/* Comments sidebar */
.comments-sidebar {
    position: fixed; top: 0; right: -380px; width: 380px; height: 100vh; z-index: 60;
    background: var(--bg); border-left: 1px solid var(--border);
    box-shadow: -4px 0 16px rgba(0,0,0,0.08);
    display: flex; flex-direction: column;
    transition: right 0.2s ease;
}
.comments-sidebar.open { right: 0; }
.comments-sidebar-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.comments-sidebar-header h3 { margin: 0; font-size: 15px; font-weight: 600; }
.comments-sidebar-close {
    background: none; border: none; font-size: 22px; cursor: pointer;
    color: var(--text-muted); padding: 0 4px; line-height: 1;
}
.comments-sidebar-close:hover { color: var(--text); }
.comments-sidebar-body { flex: 1; overflow-y: auto; padding: 16px 20px; }
.comments-sidebar-footer { padding: 12px 20px; border-top: 1px solid var(--border); flex-shrink: 0; }
.comments-sidebar-footer textarea {
    width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius);
    font-size: 14px; font-family: var(--font); resize: none; outline: none; margin-bottom: 8px;
    overflow-y: hidden; min-height: 38px; max-height: 220px;
}
.comments-sidebar-footer textarea:focus { border-color: var(--primary); }
.comment-compose-meta {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    color: var(--text-muted); font-size: 12px;
}
.comments-sidebar-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 59;
    background: rgba(0,0,0,0.15); opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.comments-sidebar-overlay.open { opacity: 1; pointer-events: auto; }

/* Comment items (shared between inline and sidebar) */
.comment { display: flex; gap: 10px; margin-bottom: 16px; }
.comment-avatar { width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; object-fit: cover; }
.comment-body { flex: 1; min-width: 0; }
.comment-header { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.comment-author { font-size: 13px; font-weight: 600; }
.comment-time { font-size: 12px; color: var(--text-muted); }
.comment-delete { font-size: 16px; color: var(--text-muted); cursor: pointer; padding: 0 4px; line-height: 1; margin-left: auto; }
.comment-delete:hover { color: var(--danger); }
.comment-text { font-size: 14px; line-height: 1.5; white-space: pre-wrap; }

.doc-actions-bottom { margin-top: 48px; padding-top: 16px; border-top: 1px solid var(--border-light); }
.doc-status-banner { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-radius: 6px; font-size: 14px; margin-bottom: 16px; }
.banner-archive { background: #fef3cd; color: #856404; }
.banner-trash { background: #f8d7da; color: #721c24; }
.sub-documents, .backlinks-section { margin-top: 36px; padding-top: 20px; border-top: 1px solid var(--border-light); }
.sub-documents h3, .backlinks-section h3 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin-bottom: 8px; }

/* Forms */
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-secondary); }
.optional { font-weight: 400; color: var(--text-muted); }
.form-group input[type="text"], .form-group input[type="search"], .form-group textarea {
    width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius);
    font-size: 15px; font-family: var(--font); outline: none; background: var(--bg);
}
.form-group input:focus, .form-group textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(43,108,176,0.12); }
.form-actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.form-danger-zone { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--border-light); }
.title-input { width: 100%; padding: 8px 0; border: none; border-bottom: 2px solid transparent; font-size: 28px; font-weight: 700; outline: none; background: transparent; margin-bottom: 16px; }
.title-input:focus { border-bottom-color: var(--primary); }

/* Editor */
.editor-form { max-width: 100%; }
.editor-container { border: 1px solid var(--border); border-radius: var(--radius-lg); margin-bottom: 16px; overflow: hidden; }
.editor-toolbar { display: flex; align-items: center; gap: 1px; padding: 6px 8px; background: var(--bg-wash); border-bottom: 1px solid var(--border); }
.editor-toolbar button { padding: 5px 8px; border-radius: 4px; font-size: 13px; color: var(--text-secondary); }
.editor-toolbar button:hover { background: var(--bg-hover); color: var(--text); }
.toolbar-spacer { flex: 1; }
.btn-preview { font-size: 13px; color: var(--text-muted) !important; }
.btn-preview.active { color: var(--primary) !important; background: var(--primary-light); }
.draft-recovery {
    display: flex; align-items: center; gap: 8px; margin: 0 0 12px; padding: 8px 10px;
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-wash);
    color: var(--text-secondary); font-size: 13px;
}
.draft-recovery[hidden] { display: none; }
.save-conflict {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 0 12px; padding: 8px 10px;
    border: 1px solid #f59e0b; border-radius: var(--radius); background: #fffbeb;
    color: #92400e; font-size: 13px;
}
.save-conflict[hidden] { display: none; }
[data-theme="dark"] .save-conflict { background: rgba(245,158,11,0.12); color: #fbbf24; border-color: rgba(245,158,11,0.35); }
.editor-body { display: flex; min-height: 500px; }
.editor-textarea { flex: 1; padding: 20px; border: none; outline: none; resize: vertical; font-family: var(--font-mono); font-size: 14px; line-height: 1.7; min-height: 500px; tab-size: 4; transition: border-color 0.15s; }
.editor-textarea.drag-over { background: var(--primary-light); }
.editor-preview { flex: 1; padding: 20px; border-left: 1px solid var(--border); overflow-y: auto; display: none; }
.editor-preview.visible { display: block; }

/* Search */
.search-form-main { display: flex; gap: 8px; margin-bottom: 24px; }
.search-input-lg { flex: 1; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 15px; outline: none; }
.search-input-lg:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(43,108,176,0.12); }
.result-count { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
.search-result { display: block; padding: 14px 0; border-bottom: 1px solid var(--border-light); text-decoration: none; color: var(--text); }
.search-result:hover { text-decoration: none; }
.search-result-title { font-size: 16px; font-weight: 600; color: var(--primary); margin-bottom: 2px; }
.search-result-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.search-result-snippet { font-size: 14px; color: var(--text-secondary); }
.search-result-snippet mark { background: #fef3c7; padding: 1px 3px; border-radius: 2px; }
.no-results { color: var(--text-muted); font-style: italic; }

/* Revisions */
.revision-list { display: flex; flex-direction: column; }
.revision-item { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--border-light); }
.revision-title { font-weight: 600; font-size: 14px; }
.revision-meta { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* Diff view */
.diff-pre { white-space: pre-wrap; word-wrap: break-word; font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace; font-size: 13px; line-height: 1.6; padding: 16px; background: var(--bg-wash); border-radius: 8px; }
.diff-added { background: #d4edda; color: #155724; text-decoration: none; }
.diff-removed { background: #f8d7da; color: #721c24; text-decoration: line-through; }

/* Empty state */
.empty-state { text-align: center; padding: 48px 0; color: var(--text-muted); }
.empty-state svg { margin-bottom: 12px; opacity: 0.4; }
.empty-state p { margin-bottom: 16px; }
.muted { color: var(--text-muted); font-weight: 400; }

/* ========== Dark mode overrides for hardcoded colors ========== */
[data-theme="dark"] .doc-content pre { background: #0d1117; color: #c9d1d9; }
[data-theme="dark"] .doc-content pre code { color: inherit; }
[data-theme="dark"] .video-embed { box-shadow: none; }
[data-theme="dark"] .doc-content tr:nth-child(even) { background: var(--bg-wash); }
[data-theme="dark"] .mermaid-container { background: var(--bg); }
[data-theme="dark"] .mermaid-source { background: #0d1117; color: #c9d1d9; }
[data-theme="dark"] .diagram-lightbox { background: rgba(25,27,31,0.98); }
[data-theme="dark"] .selection-toolbar { background: #0d1117; }
[data-theme="dark"] .selection-toolbar button { color: #c9d1d9; }
[data-theme="dark"] .selection-toolbar button:hover { background: rgba(255,255,255,0.1); }
[data-theme="dark"] .selection-toolbar.link-bar input { background: rgba(255,255,255,0.08); color: #c9d1d9; }
[data-theme="dark"] .selection-toolbar.link-bar input::placeholder { color: rgba(255,255,255,0.3); }
[data-theme="dark"] .draft-badge { color: #fbbf24; background: rgba(251,191,36,0.15); }
[data-theme="dark"] .banner-archive { background: rgba(251,191,36,0.12); color: #fbbf24; }
[data-theme="dark"] .banner-trash { background: rgba(224,96,96,0.12); color: #e06060; }
[data-theme="dark"] .diff-added { background: rgba(46,160,67,0.2); color: #7ee787; text-decoration: none; }
[data-theme="dark"] .diff-removed { background: rgba(248,81,73,0.2); color: #ffa198; }
[data-theme="dark"] .search-result-snippet mark { background: rgba(251,191,36,0.25); color: #fbbf24; }
[data-theme="dark"] .btn-google { background: #2a2d32; border-color: var(--border); color: var(--text); }
[data-theme="dark"] .btn-google:hover { background: var(--bg-hover); }
[data-theme="dark"] .filter-select {
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-color: var(--bg);
}
[data-theme="dark"] .editor-textarea { color: var(--text); background: var(--bg); }

/* ========== SETTINGS PAGE ========== */
.settings-nav { display: flex; gap: 4px; margin-bottom: 24px; border-bottom: 1px solid var(--border); padding-bottom: 0; }
.settings-nav a { padding: 8px 16px; font-size: 14px; font-weight: 500; color: var(--text-secondary); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.settings-nav a:hover { color: var(--text); }
.settings-nav a.active { color: var(--primary); border-color: var(--primary); }
.settings-page { max-width: 800px; margin: 0 auto; padding: 2rem; }
.settings-page .page-header { margin-bottom: 2rem; }
.settings-page .page-header h1 { margin: 0 0 0.25rem; font-size: 1.5rem; }
.settings-page .page-subtitle { color: var(--text-secondary); margin: 0; }
.settings-section { margin-bottom: 2.5rem; }
.settings-section h2 { font-size: 1.15rem; margin: 0 0 0.5rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--border); }
.settings-section h3 { font-size: 0.95rem; margin: 1.25rem 0 0.5rem; }
.settings-section h4 { font-size: 0.85rem; margin: 0.75rem 0 0.25rem; color: var(--text-secondary); }
.settings-section p { color: var(--text-secondary); font-size: 0.9rem; margin: 0 0 0.75rem; line-height: 1.5; }
.settings-section ul { margin: 0 0 0.5rem; padding-left: 1.25rem; font-size: 0.85rem; }
.settings-section li { margin-bottom: 0.2rem; color: var(--text-secondary); }
.settings-section li code { font-size: 0.8rem; font-weight: 600; color: var(--text); }

.settings-alert { padding: 1rem 1.25rem; border-radius: 8px; margin-bottom: 1.5rem; }
.settings-alert-success { background: #ecfdf5; border: 1px solid #a7f3d0; }
.settings-alert-header { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; color: #065f46; }
.settings-alert p { color: #065f46; font-size: 0.875rem; margin: 0 0 0.75rem; }
.settings-token-display { display: flex; align-items: center; gap: 0.75rem; background: #fff; border: 1px solid #d1fae5; border-radius: 6px; padding: 0.5rem 0.75rem; }
.settings-token-display code { flex: 1; font-size: 0.8rem; word-break: break-all; color: #065f46; }
[data-theme="dark"] .settings-alert-success { background: rgba(16,185,129,0.1); border-color: rgba(16,185,129,0.25); }
[data-theme="dark"] .settings-alert-header { color: #6ee7b7; }
[data-theme="dark"] .settings-alert p { color: #a7f3d0; }
[data-theme="dark"] .settings-token-display { background: var(--bg-alt); border-color: rgba(16,185,129,0.2); }
[data-theme="dark"] .settings-token-display code { color: #6ee7b7; }

.settings-create-form { display: flex; gap: 0.75rem; margin-bottom: 1.25rem; }
.settings-create-form .form-input { flex: 1; padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.9rem; background: var(--bg); color: var(--text); }
.settings-create-form .form-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(59,130,246,0.15); }

.settings-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.settings-table th { text-align: left; padding: 0.5rem 0.75rem; color: var(--text-secondary); font-weight: 500; border-bottom: 1px solid var(--border); }
.settings-table td { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); }
.settings-table code.token-prefix { font-size: 0.8rem; color: var(--text-secondary); background: var(--bg-alt); padding: 0.15rem 0.4rem; border-radius: 4px; }

.settings-empty { padding: 2rem; text-align: center; color: var(--text-secondary); background: var(--bg-alt); border-radius: 8px; }
.settings-empty p { color: var(--text-secondary); }

.settings-code-block { position: relative; background: var(--bg-alt); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 1rem; }
.settings-code-block pre { margin: 0; padding: 1rem; overflow-x: auto; }
.settings-code-block code { font-size: 0.8rem; line-height: 1.6; color: var(--text); white-space: pre; }
.settings-copy-btn { position: absolute; top: 0.5rem; right: 0.5rem; font-size: 0.75rem; }

.settings-tools-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 640px) { .settings-tools-grid { grid-template-columns: 1fr; } }

.btn-danger { color: #dc2626; border: 1px solid #fecaca; background: #fef2f2; }
.btn-danger:hover { background: #fee2e2; }
[data-theme="dark"] .btn-danger { color: #fca5a5; border-color: rgba(252,165,165,0.2); background: rgba(220,38,38,0.1); }
[data-theme="dark"] .btn-danger:hover { background: rgba(220,38,38,0.2); }

.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.75rem; border-radius: 4px; cursor: pointer; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.btn-sm:hover { background: var(--bg-hover); }

/* ========== WYSIWYG EDITOR (Tiptap/ProseMirror) ========== */

/* Editor container */
.wysiwyg-wrap { position: relative; min-height: 300px; }
.wysiwyg-wrap .ProseMirror { outline: none; padding: 0; line-height: 1.7; font-size: 15px; overflow-wrap: anywhere; min-height: 300px; }
.wysiwyg-wrap .ProseMirror:focus { outline: none; }

/* Inherit doc-content typography */
.wysiwyg-wrap .ProseMirror h1 { font-size: 1.75em; font-weight: 700; margin: 1.5em 0 0.5em; padding-bottom: 0.3em; border-bottom: 1px solid var(--border); }
.wysiwyg-wrap .ProseMirror h2 { font-size: 1.4em; font-weight: 600; margin: 1.4em 0 0.4em; padding-bottom: 0.25em; border-bottom: 1px solid var(--border); }
.wysiwyg-wrap .ProseMirror h3 { font-size: 1.15em; font-weight: 600; margin: 1.3em 0 0.3em; }
.wysiwyg-wrap .ProseMirror h4,
.wysiwyg-wrap .ProseMirror h5,
.wysiwyg-wrap .ProseMirror h6 { font-size: 1em; font-weight: 600; margin: 1.2em 0 0.3em; }
.wysiwyg-wrap .ProseMirror h1:first-child,
.wysiwyg-wrap .ProseMirror h2:first-child,
.wysiwyg-wrap .ProseMirror h3:first-child { margin-top: 0; }
.wysiwyg-wrap .ProseMirror h1,
.wysiwyg-wrap .ProseMirror h2,
.wysiwyg-wrap .ProseMirror h3,
.wysiwyg-wrap .ProseMirror h4 { scroll-margin-top: 64px; }
.wysiwyg-wrap .ProseMirror p { margin: 0 0 1em; }
.wysiwyg-wrap .ProseMirror ul,
.wysiwyg-wrap .ProseMirror ol { margin: 0 0 1em; padding-left: 1.8em; }
.wysiwyg-wrap .ProseMirror li { margin: 0.125em 0; }
.wysiwyg-wrap .ProseMirror li p { margin: 0; }
.wysiwyg-wrap .ProseMirror li > ul,
.wysiwyg-wrap .ProseMirror li > ol { margin: 0.125em 0 0.125em; }
.wysiwyg-wrap .ProseMirror blockquote { margin: 0 0 1em; padding: 0.5em 1em; border-left: 3px solid var(--primary); background: var(--bg-wash); border-radius: 0 4px 4px 0; color: var(--text-secondary); }
.wysiwyg-wrap .ProseMirror blockquote p:last-child { margin-bottom: 0; }
.wysiwyg-wrap .ProseMirror code { font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; font-size: 0.875em; padding: 0.15em 0.35em; background: var(--bg-hover); border-radius: 3px; }
.wysiwyg-wrap .ProseMirror pre { margin: 0 0 1em; padding: 1em; background: #1b2733; color: #e8ebed; border-radius: 6px; overflow-x: auto; line-height: 1.5; }
.wysiwyg-wrap .ProseMirror pre code { padding: 0; background: none; border-radius: 0; color: inherit; font-size: 0.85em; }
.wysiwyg-wrap .ProseMirror img { max-width: 100%; border-radius: 4px; }
.wysiwyg-wrap .ProseMirror .video-embed { margin: 0 0 1.25em; }
.wysiwyg-wrap .ProseMirror hr { border: none; border-top: 1px solid var(--border); margin: 1.5em 0; }
.wysiwyg-wrap .ProseMirror a { color: var(--primary); text-decoration: none; }
.wysiwyg-wrap .ProseMirror a:hover { text-decoration: underline; }

/* Tables */
.wysiwyg-wrap .ProseMirror table { border-collapse: collapse; margin: 0 0 1em; width: 100%; table-layout: fixed; }
.wysiwyg-wrap .ProseMirror th,
.wysiwyg-wrap .ProseMirror td { padding: 8px 12px; border: 1px solid var(--border); text-align: left; word-break: break-word; overflow-wrap: anywhere; }
.wysiwyg-wrap .ProseMirror th { background: var(--bg-wash); font-weight: 600; }
.wysiwyg-wrap .ProseMirror .selectedCell { background: var(--primary-light); }

/* Task lists */
.wysiwyg-wrap .ProseMirror ul[data-type="taskList"] { list-style: none; padding-left: 0; }
.wysiwyg-wrap .ProseMirror ul[data-type="taskList"] li { display: flex; align-items: flex-start; gap: 8px; }
.wysiwyg-wrap .ProseMirror ul[data-type="taskList"] li label { flex-shrink: 0; margin-top: 3px; }
.wysiwyg-wrap .ProseMirror ul[data-type="taskList"] li > div { flex: 1; }

/* Placeholder */
.wysiwyg-wrap .ProseMirror p.is-editor-empty:first-child::before {
    content: attr(data-placeholder);
    float: left;
    color: var(--text-muted);
    pointer-events: none;
    height: 0;
}

/* Dark mode overrides for ProseMirror */
[data-theme="dark"] .wysiwyg-wrap .ProseMirror pre { background: #0d1117; color: #c9d1d9; }
[data-theme="dark"] .wysiwyg-wrap .ProseMirror pre code { color: inherit; }

/* WYSIWYG toolbar */
.wysiwyg-toolbar {
    display: flex; align-items: center; gap: 1px; padding: 6px 8px;
    background: var(--bg-wash); border: 1px solid var(--border); border-radius: var(--radius);
    margin-bottom: 12px; flex-wrap: wrap;
}
.wysiwyg-toolbar button {
    padding: 5px 8px; border-radius: 4px; font-size: 13px; color: var(--text-secondary);
    display: inline-flex; align-items: center; justify-content: center; min-width: 28px;
}
.wysiwyg-toolbar button:hover { background: var(--bg-hover); color: var(--text); }
.wysiwyg-toolbar button.is-active { background: var(--bg-hover); color: var(--primary); }
.wysiwyg-toolbar .toolbar-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.wysiwyg-toolbar .toolbar-spacer { flex: 1; }

/* Mode toggle */
.mode-toggle {
    display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px;
    font-size: 13px; color: var(--text-muted); border-radius: 4px; cursor: pointer;
}
.mode-toggle:hover { background: var(--bg-hover); color: var(--text); }
.mode-toggle.active { color: var(--primary); background: var(--primary-light); }

/* Save status */
.save-status { font-size: 12px; color: var(--text-muted); min-height: 20px; white-space: nowrap; text-align: right; }
.save-status-failed, .save-status-conflict { color: var(--danger); }
.save-status-saved { color: var(--primary); }

/* Source editor container (CodeMirror) */
.source-editor-wrap { display: none; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; min-height: 400px; }
.source-editor-wrap.visible { display: block; }

/* Document view/edit mode switching */
.doc-rendered-content { display: block; }
.wysiwyg-wrap { display: none; }
html[data-edit-mode="true"] [data-document-page]:not([data-readonly="true"]) .doc-rendered-content { display: none; }
html[data-edit-mode="true"] [data-document-page]:not([data-readonly="true"]) .wysiwyg-wrap { display: block; }
html[data-edit-mode="true"] [data-document-page]:not([data-readonly="true"]) .media-previews { display: block; }
html:not([data-edit-mode="true"]) [data-document-page]:not([data-readonly="true"]) .wysiwyg-toolbar,
html:not([data-edit-mode="true"]) [data-document-page]:not([data-readonly="true"]) .source-editor-wrap,
html:not([data-edit-mode="true"]) [data-document-page]:not([data-readonly="true"]) .media-previews,
html:not([data-edit-mode="true"]) [data-document-page]:not([data-readonly="true"]) .save-status,
html:not([data-edit-mode="true"]) [data-document-page]:not([data-readonly="true"]) .draft-recovery,
html:not([data-edit-mode="true"]) [data-document-page]:not([data-readonly="true"]) .save-conflict {
    display: none;
}
[data-document-page][data-readonly="true"] .wysiwyg-toolbar,
[data-document-page][data-readonly="true"] .wysiwyg-wrap,
[data-document-page][data-readonly="true"] .source-editor-wrap,
[data-document-page][data-readonly="true"] .media-previews,
[data-document-page][data-readonly="true"] .save-status,
[data-document-page][data-readonly="true"] .draft-recovery,
[data-document-page][data-readonly="true"] .save-conflict {
    display: none !important;
}

/* Title input (borderless, matches h1) */
/* Document title row — star left, title fills remaining width */
.doc-title-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 4px;
}
.doc-title-row .star-btn { flex-shrink: 0; margin-top: 6px; }
.doc-title-input {
    flex: 1; min-width: 0; padding: 0; border: none; font-size: 28px; font-weight: 700;
    outline: none; background: transparent; color: var(--text); line-height: 1.25;
    resize: none; overflow: hidden; font-family: inherit;
}
/* Document actions row */
.doc-actions-row {
    display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px;
}
.doc-title-input::placeholder { color: var(--text-muted); }
.doc-title-input:disabled { opacity: 0.6; cursor: not-allowed; }

/* View mode (edit-mode off): hide toolbar, make title non-editable */
html:not([data-edit-mode="true"]) .wysiwyg-toolbar { display: none; }
html:not([data-edit-mode="true"]) .doc-title-input { pointer-events: none; }
html:not([data-edit-mode="true"]) .draft-recovery { display: none; }
html:not([data-edit-mode="true"]) .save-conflict { display: none; }
html:not([data-edit-mode="true"]) .save-status { display: none; }
