:root {
    --bg: #1e1e24;
    --bg-side: #17171c;
    --bg-elev: #26262e;
    --bg-hover: #2e2e38;
    --border: #33333d;
    --text: #dcdce4;
    --muted: #8b8b98;
    --accent: #8b6cf6;
    --accent-soft: rgba(139, 108, 246, 0.18);
    --danger: #e5484d;
    --bg-code: #26262e;
    --radius: 6px;
    color-scheme: dark;
}

/* Light palette: chosen explicitly (data-theme="light") or following the OS when no choice was made. */
:root[data-theme="light"] {
    --bg: #ffffff;
    --bg-side: #f5f5f7;
    --bg-elev: #ffffff;
    --bg-hover: #ececf1;
    --border: #e0e0e6;
    --text: #1f1f24;
    --muted: #6e6e7a;
    --accent: #6d4fe0;
    --accent-soft: rgba(109, 79, 224, 0.12);
    --bg-code: #f2f2f5;
    color-scheme: light;
}

@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
        --bg: #ffffff;
        --bg-side: #f5f5f7;
        --bg-elev: #ffffff;
        --bg-hover: #ececf1;
        --border: #e0e0e6;
        --text: #1f1f24;
        --muted: #6e6e7a;
        --accent: #6d4fe0;
        --accent-soft: rgba(109, 79, 224, 0.12);
        --bg-code: #f2f2f5;
        color-scheme: light;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font: inherit; color: inherit; }

button {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.35rem 0.75rem;
    cursor: pointer;
}
button:hover:not(:disabled) { background: var(--bg-hover); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { filter: brightness(1.1); background: var(--accent); }
button.danger { color: var(--danger); }
button.icon { background: none; border: none; padding: 0.2rem 0.4rem; color: var(--muted); }
button.icon:hover, button.icon.active { color: var(--text); background: var(--bg-hover); }
button.link { background: none; border: none; color: var(--accent); padding: 0; }
button.wide { width: 100%; }

input, select, textarea {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.4rem 0.6rem;
    outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

.muted { color: var(--muted); }
.error { color: var(--danger); }
.center { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; }
.center-screen { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; }

/* ---------- Auth ---------- */
.auth-card {
    width: min(360px, 100% - 2rem);
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    padding: 2rem;
    background: var(--bg-side);
    border: 1px solid var(--border);
    border-radius: 12px;
}
.auth-card h1 { margin: 0; }
.auth-card p { margin: 0; }
.auth-card label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; }

/* ---------- App shell ---------- */
.app {
    display: grid;
    grid-template-columns: 250px 300px 1fr;
    height: 100vh;
    overflow: hidden;
}

.sidebar {
    background: var(--bg-side);
    border-right: 1px solid var(--border);
    padding: 0.9rem 0.6rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    overflow-y: auto;
}
.brand { font-weight: 700; font-size: 1.1rem; padding: 0 0.4rem 0.5rem; }
.search input { width: 100%; margin: 0.35rem 0; }
.nav-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius);
    color: var(--text);
}
.nav-item a { color: inherit; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item:hover { background: var(--bg-hover); text-decoration: none; }
.nav-item.active { background: var(--accent-soft); }
.nav-item .actions { display: none; }
.nav-item:hover .actions { display: flex; }
.section-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.9rem;
    padding: 0 0.4rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}
.tags { display: flex; flex-wrap: wrap; gap: 0.3rem; padding: 0 0.4rem; }
.tag {
    font-size: 0.8rem;
    padding: 0.05rem 0.45rem;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
}
.tag.active { background: var(--accent); color: #fff; }
.user {
    align-items: center;
    margin-top: auto;
    padding: 0.8rem 0.4rem 0;
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
}
.user span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Note list ---------- */
.note-list { border-right: 1px solid var(--border); overflow-y: auto; }
.note-list header {
    position: sticky;
    top: 0;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.9rem 1rem;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.note-list h2 { margin: 0; font-size: 1rem; }
.note-list ul { list-style: none; margin: 0; padding: 0; }
.note-list li a {
    display: block;
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}
.note-list li a:hover { background: var(--bg-hover); text-decoration: none; }
.note-list li.selected a { background: var(--accent-soft); }
.note-list .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-list .excerpt {
    color: var(--muted);
    font-size: 0.85rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.note-list .meta { display: flex; gap: 0.4rem; margin-top: 0.3rem; font-size: 0.75rem; color: var(--muted); }
.note-list .empty { padding: 1rem; }
.note-list header { flex-wrap: wrap; gap: 0.4rem; }
.note-list header h2 { flex: 1; }
.select-bar { display: flex; justify-content: space-between; align-items: center; width: 100%; }
.check-all { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; cursor: pointer; }
.bulk-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; width: 100%; }
.bulk-actions button, .bulk-actions select { font-size: 0.85rem; padding: 0.25rem 0.6rem; }
.note-list.selecting li a { display: grid; grid-template-columns: auto 1fr; column-gap: 0.6rem; }
.note-list.selecting li a > :not(.item-check) { grid-column: 2; }
.note-list .item-check { grid-row: 1 / span 3; margin-top: 0.3rem; pointer-events: none; }
.note-list li.checked a { background: var(--accent-soft); }
button.link.danger { color: var(--danger); }

/* ---------- Editor ---------- */
.editor-pane { overflow: hidden; }
.editor { height: 100%; display: flex; flex-direction: column; }
.banner {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    padding: 0.5rem 1rem;
    background: var(--accent-soft);
}
.toolbar { padding: 0.8rem 1.2rem 0.5rem; border-bottom: 1px solid var(--border); }
.title-input {
    width: 100%;
    border: none;
    background: none;
    padding: 0;
    font-size: 1.6rem;
    font-weight: 700;
}
.toolbar-row { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.5rem; flex-wrap: wrap; }
.toolbar-row .status { margin-left: auto; font-size: 0.8rem; }
.segmented { display: flex; }
.segmented button { border-radius: 0; margin-left: -1px; font-size: 0.85rem; }
.segmented button:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.segmented button:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.segmented button.active { background: var(--accent-soft); color: var(--accent); }


.markdown { max-width: 52rem; }
.markdown h1, .markdown h2, .markdown h3 { line-height: 1.25; }
.markdown pre, .markdown code { font-family: ui-monospace, Consolas, monospace; background: var(--bg-code); border-radius: 4px; }
.markdown code { padding: 0.1em 0.3em; }
.markdown pre { padding: 0.8rem; overflow-x: auto; }
.markdown pre code { padding: 0; background: none; }
.markdown blockquote { margin: 0; padding-left: 1rem; border-left: 3px solid var(--accent); color: var(--muted); }
.markdown table { border-collapse: collapse; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 0.3rem 0.6rem; }
.markdown img { max-width: 100%; }
.markdown mark { background: rgba(255, 208, 0, 0.35); color: inherit; }
.markdown ul.contains-task-list { list-style: none; padding-left: 1rem; }

.backlinks { border-top: 1px solid var(--border); padding: 0.6rem 1.4rem; max-height: 30%; overflow-y: auto; font-size: 0.9rem; }
.backlinks h4 { margin: 0 0 0.4rem; }
.backlinks ul { margin: 0; padding-left: 1.2rem; }
.backlinks p { margin: 0; }

/* ---------- Search highlights ---------- */
mark { background: var(--accent-soft); color: var(--accent); border-radius: 2px; padding: 0 1px; }

/* ---------- Editor (CodeMirror) ---------- */
.editor-body { flex: 1; min-height: 0; display: flex; }
.editor-body > .preview { flex: 1; overflow-y: auto; padding: 1rem 1.4rem; }
.cm-host { flex: 1; min-width: 0; display: flex; }
.cm-host .cm-editor { flex: 1; height: 100%; background: var(--bg); color: var(--text); font-size: 1rem; position: relative; }
.cm-host .cm-editor.cm-focused { outline: none; }
.cm-host .cm-scroller { font-family: inherit; line-height: 1.65; }
.cm-host .cm-content { padding: 1rem 0 40vh; max-width: 52rem; caret-color: var(--accent); }
.cm-host .cm-line { padding: 0 1.4rem; }
.cm-host .cm-cursor { border-left-color: var(--accent); border-left-width: 2px; }
.cm-host .cm-selectionBackground, .cm-host .cm-focused .cm-selectionBackground { background: var(--accent-soft) !important; }
.cm-host .cm-selectionMatch { background: rgba(255, 200, 0, 0.18); }
.cm-host .cm-placeholder { color: var(--muted); }
.cm-host .cm-editor.cm-source .cm-scroller { font-family: ui-monospace, "JetBrains Mono", Consolas, monospace; font-size: 0.92rem; }

/* Syntax colours (both modes) */
.cmt-heading { font-weight: 700; }
.cmt-strong { font-weight: 700; }
.cmt-em { font-style: italic; }
.cmt-strike { text-decoration: line-through; color: var(--muted); }
.cmt-link, .cmt-url { color: var(--accent); }
.cmt-code { font-family: ui-monospace, Consolas, monospace; font-size: 0.9em; }
.cmt-quote { color: var(--muted); }
.cmt-mark { color: var(--muted); opacity: 0.7; }

/* Live preview */
.cm-live .cm-h { font-weight: 700; line-height: 1.3; }
.cm-live .cm-h1 { font-size: 1.85em; padding-top: 0.5em; }
.cm-live .cm-h2 { font-size: 1.5em; padding-top: 0.4em; }
.cm-live .cm-h3 { font-size: 1.25em; padding-top: 0.3em; }
.cm-live .cm-h4, .cm-live .cm-h5, .cm-live .cm-h6 { font-size: 1.05em; }
.cm-live .cm-line:not(.cm-codeblock) .cmt-code { background: var(--bg-code); border-radius: 4px; padding: 0.1em 0.3em; }
.cm-host .cm-codeblock { background: var(--bg-code); font-family: ui-monospace, Consolas, monospace; font-size: 0.9em; }
.cm-host .cm-codeblock-first { border-radius: 6px 6px 0 0; }
.cm-host .cm-codeblock-last { border-radius: 0 0 6px 6px; }
.cm-host .cm-quote { border-left: 3px solid var(--accent); padding-left: calc(1.4rem - 3px + 0.8rem); color: var(--muted); }
.cm-host .cm-wikilink { color: var(--accent); text-decoration: underline; text-decoration-color: var(--accent-soft); text-underline-offset: 3px; cursor: pointer; }
.cm-host .cm-link { color: var(--accent); cursor: pointer; }
.cm-host .cm-hashtag { color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 0 0.35em; }
.cm-host .cm-list-marker { display: inline-block; text-indent: 0; color: var(--accent); font-variant-numeric: tabular-nums; }
.cm-host .cm-list-bullet { font-weight: 700; text-align: center; }
.cm-host .cm-list-ordered { text-align: right; padding-right: 0.45em; box-sizing: border-box; }
.cm-host .cm-list-number { color: var(--accent); font-variant-numeric: tabular-nums; }
.cm-host .cm-list-indent { display: inline-block; }
.cm-host .cm-task-box { margin: 0; padding: 0; height: 1em; vertical-align: -0.12em; accent-color: var(--accent); cursor: pointer; }
.cm-host .cm-nolink .cmt-link, .cm-host .cm-nolink .cmt-mark { color: inherit; opacity: 1; }
.cm-host .cm-highlight { background: rgba(255, 208, 0, 0.35); border-radius: 3px; padding: 0 0.1em; }
.cm-host .cm-codeblock-first { position: relative; }
.cm-host .cm-code-label { float: right; font-size: 0.75em; color: var(--muted); font-family: system-ui, sans-serif; }
.cm-host .cm-table-wrap { overflow-x: auto; padding: 0.4rem 1.4rem; cursor: text; }
.cm-host .cm-table { border-collapse: collapse; font-size: 0.95em; }
.cm-host .cm-table th, .cm-host .cm-table td { border: 1px solid var(--border); padding: 0.3rem 0.7rem; }
.cm-host .cm-table th { background: var(--bg-code); font-weight: 600; }
.cm-host .cm-table mark { background: rgba(255, 208, 0, 0.35); color: inherit; }
.cm-host .cm-table code { background: var(--bg-code); border-radius: 3px; padding: 0 0.25em; font-size: 0.9em; }
.cm-host .cm-task-done { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 60%, transparent); }
.cm-host .cm-rule { display: inline-block; width: 100%; border-top: 1px solid var(--border); vertical-align: middle; }
.cm-host .cm-image { display: block; max-width: min(100%, 640px); max-height: 480px; margin: 0.4rem 0; border-radius: 6px; }
.cm-host .cm-tooltip { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25); color: var(--text); }
.cm-host .cm-tooltip-autocomplete > ul > li { padding: 0.25rem 0.6rem; }
.cm-host .cm-tooltip-autocomplete > ul > li[aria-selected] { background: var(--accent-soft); color: var(--text); }
.cm-host .cm-completionDetail { color: var(--muted); font-style: normal; margin-left: 0.6em; }
.cm-host .cm-panels { background: var(--bg-side); color: var(--text); border-color: var(--border); }
.cm-host .cm-panels input, .cm-host .cm-panels button { font-size: 0.85rem; }
.cm-host .cm-searchMatch { background: rgba(255, 200, 0, 0.3); }

/* Folding: arrows appear on hover, like in Obsidian */
.cm-host .cm-gutters { background: transparent; border: none; }
.cm-host .cm-foldGutter .cm-gutterElement { padding: 0 0.15rem; }
.cm-host .cm-fold-marker { display: inline-block; color: var(--muted); cursor: pointer; font-size: 1.1em; line-height: 1; transition: transform 0.15s, opacity 0.15s; }
.cm-host .cm-fold-marker.open { transform: rotate(90deg); opacity: 0; }
.cm-host .cm-gutters:hover .cm-fold-marker.open, .cm-host .cm-fold-marker.open:hover { opacity: 1; }
.cm-host .cm-foldPlaceholder { background: var(--accent-soft); border: none; color: var(--accent); border-radius: 4px; padding: 0 0.4em; margin-left: 0.3em; }

/* Formatting toolbar */
.format-bar { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.5rem; }
.format-group { display: flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.format-group .fmt { border: none; border-radius: 0; background: none; min-width: 2rem; padding: 0.2rem 0.45rem; font-size: 0.85rem; color: var(--muted); }
.format-group .fmt + .fmt { border-left: 1px solid var(--border); }
.format-group .fmt:hover { color: var(--text); background: var(--bg-hover); }
.fmt-bold { font-weight: 800; }
.fmt-italic { font-style: italic; font-family: Georgia, serif; }
.fmt-strike { text-decoration: line-through; }
.fmt-code, .fmt-codeblock, .fmt-wikilink { font-family: ui-monospace, monospace; }

/* ---------- Attachments ---------- */
.cm-editor.cm-dragging::after {
    content: "Отпустите, чтобы прикрепить файл";
    position: absolute;
    inset: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--accent);
    border-radius: var(--radius);
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
    pointer-events: none;
}
.attachments { list-style: none; padding: 0 !important; margin: 0 0 0.6rem !important; }
.attachments li { display: flex; align-items: center; gap: 0.5rem; }
.attachments a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }
.markdown img { border-radius: 4px; }

/* ---------- Notebook colours ---------- */
.nb-dot { display: inline-block; width: 0.6em; height: 0.6em; border-radius: 50%; margin-right: 0.45em; background: var(--nb-color, transparent); border: 1px solid var(--nb-color, var(--muted)); flex-shrink: 0; }
.note-list li[style*="--nb-color"] > a, .note-tree li[style*="--nb-color"] > .tree-row { box-shadow: inset 3px 0 0 var(--nb-color); }
.editor[style*="--nb-color"] .toolbar { box-shadow: inset 0 3px 0 var(--nb-color); }
.color-picker { display: flex; flex-wrap: wrap; gap: 0.3rem; padding: 0.35rem 0.4rem; }
.swatch { width: 1.3rem; height: 1.3rem; padding: 0; border-radius: 50%; border: 2px solid transparent; font-size: 0.7rem; line-height: 1; }
.swatch.selected { border-color: var(--text); }
.swatch.none { background: var(--bg-elev); color: var(--muted); border-color: var(--border); }

/* ---------- Tree of links ---------- */
.view-toggle button { padding: 0.1rem 0.45rem; font-size: 0.8rem; }
.note-tree, .note-tree ul { list-style: none; margin: 0; padding: 0; }
.tree-row { display: flex; align-items: center; gap: 0.3rem; padding: 0.35rem 0.6rem; border-bottom: 1px solid var(--border); }
.note-list .tree-row a { display: block; padding: 0; border: none; color: var(--text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-list .tree-row a:hover { background: none; text-decoration: none; }
.tree-row:hover { background: var(--bg-hover); }
.tree-item.selected > .tree-row { background: var(--accent-soft); }
.tree-toggle { width: 1.3rem; height: 1.3rem; padding: 0; border: none; background: none; color: var(--muted); font-size: 1rem; line-height: 1; transition: transform 0.15s; flex-shrink: 0; }
.tree-toggle.open { transform: rotate(90deg); }
.tree-toggle.empty { display: inline-block; }

/* ---------- Sharing & templates ---------- */
.share-panel { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; padding: 0.5rem 1.2rem; border-bottom: 1px solid var(--border); background: var(--bg-side); font-size: 0.9rem; }
.share-url { flex: 1; min-width: 240px; font-family: ui-monospace, monospace; font-size: 0.85rem; }
.banner.template { font-size: 0.85rem; flex-wrap: wrap; }
.banner.template code { background: var(--bg-elev); padding: 0 0.3rem; border-radius: 3px; }
.new-note { display: flex; }
.new-note button:first-child { flex: 1; border-radius: var(--radius) 0 0 var(--radius); }
.new-note .more { border-radius: 0 var(--radius) var(--radius) 0; border-left: 1px solid rgba(255, 255, 255, 0.3); padding: 0 0.6rem; }
.template-menu { display: flex; flex-direction: column; gap: 0.15rem; padding: 0.4rem; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); font-size: 0.9rem; }
.template-menu a { color: var(--text); padding: 0.25rem 0.4rem; border-radius: 4px; }
.template-menu a:hover { background: var(--bg-hover); text-decoration: none; }
.template-menu p { margin: 0; font-size: 0.85rem; }
.shared { max-width: 52rem; margin: 0 auto; padding: 2rem 1rem 3rem; }
.shared h1 { margin-bottom: 0.2rem; }
.shared footer { margin-top: 3rem; font-size: 0.8rem; text-align: center; }

/* ---------- Settings ---------- */
.settings { max-width: 720px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.settings header { display: flex; align-items: baseline; gap: 1rem; }
.settings section { margin-top: 1.5rem; padding: 1rem 1.2rem; background: var(--bg-side); border: 1px solid var(--border); border-radius: 10px; }
.settings h3 { margin-top: 0; }
.settings .row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin-top: 0.5rem; }
.settings .stack { display: flex; flex-direction: column; gap: 0.6rem; max-width: 320px; }
.settings .stack label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }
.settings .steps li { margin-bottom: 1rem; }
.settings .qr img { display: block; margin: 0.6rem 0; width: 200px; height: 200px; image-rendering: pixelated; background: #fff; padding: 6px; border-radius: 6px; }
.settings .key { font-size: 1rem; letter-spacing: 0.05em; user-select: all; }
.settings .codes { background: var(--bg-elev); padding: 0.6rem 0.8rem; border-radius: 6px; columns: 2; font-size: 0.95rem; }
.callout { padding: 0.8rem 1rem; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 6px; }
.ok { color: #2f9e5b; }

/* ---------- Attachment viewer ---------- */
.viewer {
    width: min(1100px, 100% - 2rem);
    height: min(88vh, 900px);
    display: flex;
    flex-direction: column;
    background: var(--bg-side);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}
.viewer header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.5rem 1rem; border-bottom: 1px solid var(--border); }
.viewer header strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer .actions { display: flex; align-items: center; gap: 1rem; flex-shrink: 0; font-size: 0.9rem; }
.viewer iframe { flex: 1; width: 100%; border: none; background: #fff; }
.viewer-image { flex: 1; display: flex; align-items: center; justify-content: center; overflow: auto; padding: 1rem; }
.viewer-image img { max-width: 100%; max-height: 100%; }
a.icon { color: var(--muted); padding: 0.2rem 0.4rem; }
a.icon:hover { color: var(--text); text-decoration: none; }

/* ---------- Sync, conflicts, history ---------- */
.sync { padding: 0.5rem 0.4rem 0; font-size: 0.8rem; color: var(--muted); }
.sync.online { color: #2f9e5b; }
.banner.conflict { flex-wrap: wrap; background: rgba(229, 72, 77, 0.12); }
.conflict-diff { max-height: 40vh; overflow: auto; padding: 0.5rem 1rem; border-bottom: 1px solid var(--border); }
.legend { margin: 0 0 0.4rem; font-size: 0.8rem; }
.legend .removed { color: var(--danger); margin-right: 1rem; }
.legend .added { color: #2f9e5b; }
.diff { font: 0.85rem/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
.diff-line { padding: 0 0.4rem; }
.diff-line .sign { display: inline-block; width: 1.2em; color: var(--muted); }
.diff-line.added { background: rgba(47, 158, 91, 0.15); }
.diff-line.removed { background: rgba(229, 72, 77, 0.15); text-decoration: line-through; text-decoration-color: rgba(229, 72, 77, 0.5); }
.diff-gap { padding: 0.15rem 0.4rem; font-size: 0.8rem; font-style: italic; }
.history {
    width: min(1100px, 100% - 2rem);
    height: min(80vh, 760px);
    display: flex;
    flex-direction: column;
    background: var(--bg-side);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    overflow: hidden;
}
.history header { display: flex; justify-content: space-between; align-items: center; padding: 0.6rem 1rem; border-bottom: 1px solid var(--border); }
.history h3 { margin: 0; }
.history-body { flex: 1; display: grid; grid-template-columns: 240px 1fr; min-height: 0; }
.history-list { list-style: none; margin: 0; padding: 0.35rem; overflow-y: auto; border-right: 1px solid var(--border); }
.history-list li { padding: 0.45rem 0.6rem; border-radius: var(--radius); cursor: pointer; }
.history-list li.selected { background: var(--accent-soft); }
.history-view { overflow-y: auto; padding: 0.8rem 1rem; }
.history-view .toolbar-row { margin: 0 0 0.6rem; }
.history-view .restore { margin-left: auto; }

/* ---------- Command palette ---------- */
.palette-hint {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    color: var(--muted);
    background: none;
}
kbd { font: 0.75rem ui-monospace, monospace; padding: 0 0.3rem; border: 1px solid var(--border); border-radius: 4px; }
.palette-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 12vh;
    background: rgba(0, 0, 0, 0.45);
}
.palette {
    width: min(640px, 100% - 2rem);
    background: var(--bg-side);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    overflow: hidden;
}
.palette-input { width: 100%; border: none; border-bottom: 1px solid var(--border); border-radius: 0; padding: 0.9rem 1rem; font-size: 1.05rem; background: none; }
.palette ul { list-style: none; margin: 0; padding: 0.35rem; max-height: 55vh; overflow-y: auto; }
.palette li { display: flex; align-items: baseline; gap: 0.6rem; padding: 0.45rem 0.65rem; border-radius: var(--radius); cursor: pointer; }
.palette li.selected { background: var(--accent-soft); }
.palette li .label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-shrink: 0; max-width: 45%; }
.palette li .hint { color: var(--muted); font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.palette li.empty { cursor: default; }
.palette footer { padding: 0.45rem 1rem; border-top: 1px solid var(--border); font-size: 0.75rem; }

/* ---------- Mobile: one column at a time, sidebar as a drawer ---------- */
.mobile-bar { display: none; }

@media (max-width: 800px) {
    .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
    .mobile-bar {
        display: flex;
        align-items: center;
        gap: 0.4rem;
        padding: 0.4rem 0.6rem;
        background: var(--bg-side);
        border-bottom: 1px solid var(--border);
    }
    .mobile-bar .brand { flex: 1; padding: 0; }
    .mobile-bar .icon { font-size: 1.2rem; color: var(--text); padding: 0.3rem 0.5rem; }
    .app .sidebar { display: none; }
    .app.menu-open .sidebar { display: flex; position: fixed; inset: 3rem 0 0 0; z-index: 50; }
    .app.has-note .note-list { display: none; }
    .app:not(.has-note) .editor-pane { display: none; }
    .history-body { grid-template-columns: 1fr; grid-template-rows: 30% 1fr; }
    .history-list { border-right: none; border-bottom: 1px solid var(--border); }
}

/* ---------- Blazor template: error bar and loading spinner ---------- */
#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

    #blazor-error-ui .dismiss {
        cursor: pointer;
        position: absolute;
        right: 0.75rem;
        top: 0.5rem;
    }

.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

    .blazor-error-boundary::after {
        content: "An error has occurred."
    }

.loading-progress {
    position: absolute;
    display: block;
    width: 8rem;
    height: 8rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto 0 auto;
}

    .loading-progress circle {
        fill: none;
        stroke: #e0e0e0;
        stroke-width: 0.6rem;
        transform-origin: 50% 50%;
        transform: rotate(-90deg);
    }

        .loading-progress circle:last-child {
            stroke: #1b6ec2;
            stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
            transition: stroke-dasharray 0.05s ease-in-out;
        }

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}

    .loading-progress-text:after {
        content: var(--blazor-load-percentage-text, "Loading");
    }


