* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.5;
    color: var(--ink-2);
    background: var(--page);
    -webkit-font-smoothing: antialiased;
}

/* ============================================================
   Primitives
   ============================================================ */
.dc-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--dc-radius-lg);
    box-shadow: var(--dc-shadow-card);
}

.dc-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--dc-space-2);
    font: 700 14px/20px var(--font-body);
    border-radius: var(--dc-radius-md);
    padding: 10px 20px;
    border: 0;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--dc-dur-base) var(--dc-ease),
                opacity var(--dc-dur-base) var(--dc-ease);
}

.dc-btn--primary {
    background: var(--btn-primary-bg);
    color: var(--btn-primary-ink);
}

.dc-btn--primary:hover {
    background: var(--btn-primary-hover);
}

.dc-btn--ghost {
    background: transparent;
    color: var(--ink-2);
    border: 1px solid var(--border-strong);
}

.dc-btn--ghost:hover {
    background: var(--dc-surface-mute);
}

.dc-btn--danger {
    background: var(--danger);
    color: var(--danger-ink);
}

.dc-btn--danger:hover {
    background: var(--danger-hover);
}

.dc-btn--sm {
    padding: 6px 12px;
    font-size: 13px;
}

.dc-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.dc-btn[disabled] {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ============================================================
   App shell — dark navigation rail + content
   ============================================================ */
.app {
    display: flex;
    min-height: 100vh;
}

.rail {
    width: 240px;
    flex: none;
    display: flex;
    flex-direction: column;
    padding: 18px 0;
    background: var(--rail-bg);
    color: var(--rail-ink);
    overflow: hidden;
    white-space: nowrap;
    transition: width var(--dc-dur-base) var(--dc-ease);
}

.rail-head {
    display: flex;
    align-items: center;
    padding-bottom: 18px;
}

.rail-brand {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 0 8px 0 18px;
    text-decoration: none;
}

.rail-collapse {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    margin-right: 12px;
    border: 0;
    border-radius: var(--dc-radius-sm);
    background: var(--rail-field-bg);
    color: var(--rail-ink-2);
    cursor: pointer;
    transition: background var(--dc-dur-fast) var(--dc-ease),
                color var(--dc-dur-fast) var(--dc-ease);
}

.rail-collapse:hover {
    background: var(--rail-hover);
    color: var(--rail-accent);
}

.rail-collapse:focus-visible {
    outline: 2px solid var(--rail-accent);
    outline-offset: 2px;
}

/* ---- Collapsed state ---- */
html.sidebar-collapsed .rail {
    width: 0;
    padding-top: 0;
    padding-bottom: 0;
}

.sidebar-reopen {
    position: fixed;
    top: 16px;
    left: 14px;
    z-index: 50;
    display: none;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: var(--dc-radius-md);
    background: var(--card);
    color: var(--ink-3);
    cursor: pointer;
    box-shadow: var(--dc-shadow-card);
    transition: background var(--dc-dur-fast) var(--dc-ease),
                border-color var(--dc-dur-fast) var(--dc-ease),
                color var(--dc-dur-fast) var(--dc-ease);
}

.sidebar-reopen:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.sidebar-reopen:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

html.sidebar-collapsed .sidebar-reopen {
    display: inline-flex;
}

html.sidebar-collapsed .content {
    padding-left: 62px;
}

.rail-brand .brand-mark {
    width: 28px;
    height: 28px;
    border-radius: var(--dc-radius-sm);
    background: var(--brand-mark-bg);
    display: flex;
    align-items: center;
    justify-content: center;
}

.rail-brand .brand-mark::after {
    content: "";
    width: 12px;
    height: 12px;
    border-radius: 3px;
    background: var(--brand-mark-dot);
}

.rail-brand .brand-name {
    font: 700 16px var(--font-wordmark);
    color: var(--rail-ink);
}

.rail-search {
    display: flex;
    align-items: center;
    gap: 8px;
    width: calc(100% - 24px);
    height: 34px;
    margin: 0 12px 12px;
    padding: 0 11px;
    border: 0;
    border-radius: 9px;
    background: var(--rail-field-bg);
    color: var(--rail-muted);
    font: 400 12.5px var(--font-body);
    cursor: pointer;
    text-align: left;
}

.rail-search:hover {
    color: var(--rail-ink-2);
}

.rail-search .rail-search-label {
    flex: 1;
}

.rail-search .kbd {
    font: 600 10px var(--font-mono);
    background: var(--rail-kbd-bg);
    border-radius: 4px;
    padding: 1px 5px;
    color: var(--rail-kbd-ink);
}

.rail-search .kbd-slash {
    display: none;
}

[data-theme="clean-blue"] .rail-search .kbd-cmdk {
    display: none;
}

[data-theme="clean-blue"] .rail-search .kbd-slash {
    display: inline;
}

.rail-tree-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px 6px 18px;
}

.rail-section-label {
    font: 700 10px var(--font-body);
    letter-spacing: 0.7px;
    text-transform: uppercase;
    color: var(--rail-label);
}

.create-actions {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.create-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border: 0;
    border-radius: var(--dc-radius-sm);
    background: transparent;
    color: var(--rail-muted);
    cursor: pointer;
    transition: background var(--dc-dur-fast) var(--dc-ease),
                color var(--dc-dur-fast) var(--dc-ease);
}

.create-action:hover {
    background: var(--rail-hover);
    color: var(--rail-accent);
}

.create-action:focus-visible {
    outline: 2px solid var(--rail-accent);
    outline-offset: 1px;
    color: var(--rail-ink);
}

.create-actions--row {
    flex: none;
    gap: 0;
    opacity: 0;
    transition: opacity var(--dc-dur-fast) var(--dc-ease);
}

.tree-summary:hover .create-actions--row,
.create-actions--row:focus-within {
    opacity: 1;
}

.create-actions--row .create-action {
    width: 22px;
    height: 22px;
}

.rail .tree {
    flex: 1;
    overflow-y: auto;
    padding: 0 10px;
    font: 500 13px var(--font-body);
}

.rail-user {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-top: auto;
    padding: 12px 16px 0;
    border-top: 1px solid var(--rail-border);
}

.rail-user .avatar {
    width: 30px;
    height: 30px;
    flex: none;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font: 700 12px var(--font-body);
    display: flex;
    align-items: center;
    justify-content: center;
    text-transform: uppercase;
}

.rail-user .user-name {
    font: 600 13px var(--font-body);
    color: var(--rail-ink);
}

.rail-user .user-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 2px;
}

.rail-user a,
.rail-user .logout-btn {
    font: 400 11px var(--font-body);
    color: var(--rail-muted);
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
    text-decoration: none;
}

.rail-user a:hover,
.rail-user .logout-btn:hover {
    color: var(--rail-ink-2);
}

.theme-switch {
    display: flex;
    gap: 4px;
    margin-top: 8px;
}

.theme-switch form {
    margin: 0;
}

.theme-opt {
    font: 600 10px var(--font-body);
    padding: 3px 9px;
    border-radius: var(--dc-radius-pill);
    border: 1px solid var(--rail-border);
    background: var(--rail-field-bg);
    color: var(--rail-muted);
    cursor: pointer;
}

.theme-opt:hover {
    color: var(--rail-ink-2);
}

.theme-opt.active {
    background: var(--rail-active-bg);
    color: var(--rail-active-ink);
    border-color: transparent;
}

.content {
    flex: 1;
    min-width: 0;
    padding: 24px 30px;
}

/* ============================================================
   Tree
   ============================================================ */
.tree-list {
    list-style: none;
    margin: 0;
    padding-left: 12px;
}

.tree > .tree-list {
    padding-left: 0;
}

.tree-node.file a {
    display: block;
    padding: 5px 8px;
    border-radius: var(--dc-radius-sm);
    color: var(--rail-ink-2);
    text-decoration: none;
}

.tree-node.file a:hover {
    background: var(--rail-hover);
    color: var(--rail-ink);
}

.tree-node.file a.active {
    position: relative;
    background: var(--rail-active-bg);
    color: var(--rail-active-ink);
    font-weight: 600;
}

.tree-node.file a.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    border-radius: 3px;
    background: var(--rail-accent);
}

.tree-node summary {
    cursor: pointer;
    padding: 6px 8px;
    color: var(--rail-ink-2);
    font-weight: 600;
}

.tree-summary {
    display: flex;
    align-items: center;
    gap: 4px;
    list-style: none;
}

.tree-summary::-webkit-details-marker {
    display: none;
}

.tree-chevron {
    flex: none;
    width: 14px;
    height: 14px;
    background: currentColor;
    color: var(--rail-muted);
    -webkit-mask: no-repeat center / 12px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5'%3E%3Cpath d='M9 6l6 6-6 6'/%3E%3C/svg%3E");
    mask: no-repeat center / 12px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5'%3E%3Cpath d='M9 6l6 6-6 6'/%3E%3C/svg%3E");
    transition: transform 0.12s ease;
}

.tree-node.dir > details[open] > .tree-summary > .tree-chevron {
    transform: rotate(90deg);
}

.tree-chevron--empty {
    visibility: hidden;
}

.tree-summary--leaf {
    padding: 6px 8px;
    font-weight: 600;
}

.tree-folder {
    flex: 1;
    min-width: 0;
    color: inherit;
    text-decoration: none;
    border-radius: var(--dc-radius-sm);
    padding: 0 4px;
}

.tree-folder:hover {
    color: var(--rail-ink);
}

.tree-folder.active {
    color: var(--rail-active-ink);
    font-weight: 700;
}

.rail .empty {
    padding: 6px 18px;
    color: var(--rail-muted);
}

.tree-cta {
    padding: 20px 14px;
    text-align: center;
}

.tree-cta-text {
    margin: 0 0 12px;
    font: 400 13px var(--font-body);
    color: var(--rail-muted);
}

.tree-cta-btn {
    width: 100%;
}

/* ============================================================
   Home / recent
   ============================================================ */
.recent {
    list-style: none;
    padding: 0;
    margin: 0;
}

.recent-item {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.recent-item .meta {
    color: var(--muted);
    font-size: 0.85rem;
}

.empty {
    color: var(--muted);
}

/* ============================================================
   Document view
   ============================================================ */
.document {
    max-width: 820px;
    margin: 0 auto;
}

.doc-hero {
    position: relative;
    overflow: hidden;
    border-radius: var(--dc-radius-lg);
    background: var(--hero-bg);
    padding: 30px 34px;
    color: var(--hero-ink);
}

.doc-hero-glow {
    position: absolute;
    width: 280px;
    height: 280px;
    border-radius: 50%;
    background: var(--hero-glow);
    top: -140px;
    right: -60px;
    filter: blur(6px);
}

.doc-hero-inner {
    position: relative;
}

.doc-breadcrumb {
    font: 400 12px var(--font-body);
    color: var(--hero-ink-soft);
    margin-bottom: 10px;
}

.doc-hero-top {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
}

.doc-title {
    margin: 0;
    font: 500 40px/1.05 var(--font-display);
    letter-spacing: 0.01em;
    color: var(--hero-ink);
}

.doc-actions {
    flex: none;
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-edit {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 40px;
    padding: 0 20px;
    border: 0;
    border-radius: 10px;
    background: var(--hero-btn-bg);
    color: var(--hero-btn-ink);
    text-decoration: none;
    white-space: nowrap;
    font: 700 14px var(--font-body);
}

.btn-export,
.btn-copylink {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 40px;
    padding: 0 18px;
    border: 1px solid var(--hero-pill-bg);
    border-radius: 10px;
    background: var(--hero-pill-bg);
    color: var(--hero-ink);
    cursor: pointer;
    white-space: nowrap;
    font: 700 14px var(--font-body);
}

.doc-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
}

.doc-hero .status-pill,
.doc-hero .hero-tag {
    font: 600 12px var(--font-body);
    color: var(--hero-ink);
    background: var(--hero-pill-bg);
    padding: 5px 11px;
    border-radius: var(--dc-radius-pill);
}

.doc-hero .status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.doc-hero .status-pill .status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--hero-dot);
}

.doc-byline {
    font: 400 12px var(--font-body);
    color: var(--hero-ink-soft);
    margin-left: 4px;
}

.doc-body {
    line-height: 1.6;
    padding: 26px 4px 0;
}

.doc-body h1,
.doc-body h2,
.doc-body h3 {
    font-family: var(--font-display);
    font-weight: 500;
    color: var(--ink-1);
}

.doc-body table {
    border-collapse: collapse;
    margin: 1rem 0;
}

.doc-body th,
.doc-body td {
    border: 1px solid var(--border);
    padding: 0.4rem 0.7rem;
    text-align: left;
}

.doc-body blockquote {
    margin: 1rem 0;
    padding: 0.25rem 1rem;
    border-left: 3px solid var(--border-strong);
    color: var(--muted);
}

.doc-body pre {
    padding: 0.75rem 1rem;
    border-radius: var(--dc-radius-sm);
    background: var(--dc-surface-mute);
    overflow-x: auto;
}

.doc-body pre.mermaid {
    background: transparent;
    padding: 0.5rem 0;
    text-align: center;
    line-height: normal;
}

.doc-body code {
    font-family: var(--font-mono);
    font-size: 0.9em;
}

.doc-body :not(pre) > code {
    padding: 0.1rem 0.35rem;
    border-radius: var(--dc-radius-xs);
    background: var(--code-chip-bg);
    color: var(--code-chip-ink);
}

.doc-body .contains-task-list {
    list-style: none;
    padding-left: 0.2rem;
}

.doc-body .task-list-item {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}

.doc-body .task-list-item-checkbox {
    margin: 0;
    width: 1rem;
    height: 1rem;
    accent-color: var(--accent);
    flex: none;
    transform: translateY(0.15rem);
    cursor: default;
}

.doc-body a.wikilink {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px solid var(--accent-tint);
}

.doc-body a.wikilink:hover {
    border-bottom-color: var(--accent);
}

.doc-body .broken-link {
    color: var(--muted);
    background: var(--accent-tint);
    border-radius: var(--dc-radius-xs);
    padding: 0.1rem 0.35rem;
    text-decoration: line-through;
    cursor: help;
}

.app-toast {
    position: fixed;
    bottom: 22px;
    left: 50%;
    transform: translate(-50%, 12px);
    z-index: 200;
    padding: 10px 18px;
    border-radius: var(--dc-radius-sm);
    background: var(--ink-1);
    color: #fff;
    font: 600 13px var(--font-body);
    box-shadow: var(--dc-shadow-card);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dc-dur-base) var(--dc-ease), transform var(--dc-dur-base) var(--dc-ease);
}

.app-toast.visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

.doc-history {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.btn-history {
    font: inherit;
    padding: 0.35rem 0.9rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--dc-radius-sm);
    background: var(--card);
    cursor: pointer;
}

.history .commits {
    list-style: none;
    margin: 0.75rem 0 0;
    padding: 0;
}

.history .commit {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.history .commit-subject {
    display: block;
    color: var(--accent);
    text-decoration: none;
}

.history .commit-meta {
    display: flex;
    gap: 0.75rem;
    font-size: 0.8rem;
    color: var(--muted);
}

.diff {
    margin-top: 1.5rem;
}

.diff-body {
    padding: 0.75rem 1rem;
    border-radius: var(--dc-radius-sm);
    background: var(--dc-surface-mute);
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.85rem;
}

.diff-line {
    display: block;
    white-space: pre;
}

.diff-add {
    background: #e6ffec;
    color: #116329;
}

.diff-del {
    background: #ffebe9;
    color: #82071e;
}

.diff-hunk {
    color: var(--muted);
}

/* ============================================================
   Folder page (section listing)
   ============================================================ */
.folder-create {
    margin: 0;
}

.section-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.section-item a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--dc-radius-sm);
    background: var(--card);
    color: var(--ink-1);
    text-decoration: none;
}

.section-item a:hover {
    border-color: var(--border-strong);
    background: var(--dc-surface-mute);
}

.section-dir a {
    color: var(--accent);
    font-weight: 600;
}

.section-title {
    flex: 1;
    min-width: 0;
}

.section-doc .status-dot {
    flex: none;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
}

.section-status {
    flex: none;
    font: 600 11px var(--font-body);
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ============================================================
   Editor
   ============================================================ */
.editor {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.editor-topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border: 1px solid var(--lock-border);
    background: var(--lock-bg);
    border-radius: var(--dc-radius-sm);
    color: var(--lock-ink);
    font: 600 13px var(--font-body);
}

.editor-topbar-icon {
    flex: none;
}

.lock-heartbeat {
    font: 600 11px var(--font-body);
    background: #fff;
    border: 1px solid var(--lock-border);
    border-radius: 6px;
    padding: 2px 8px;
}

.editor-topbar .save-status {
    margin-left: auto;
}

.lock-banner {
    padding: 0.6rem 0.9rem;
    border: 1px solid var(--lock-border);
    background: var(--lock-bg);
    border-radius: var(--dc-radius-sm);
    color: var(--lock-ink);
    font-weight: 600;
}

.lock-banner .lock-remaining {
    margin-left: 0.5rem;
    color: var(--lock-ink);
}

.lock-countdown {
    font-size: 0.85rem;
    color: var(--muted);
}

.lock-countdown.expired {
    color: #b91c1c;
}

.save-status {
    font-size: 0.85rem;
    color: var(--muted);
}

.save-status.saved {
    color: #116329;
}

.save-status.error {
    color: #b91c1c;
}

.frontmatter-form {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--dc-radius-md);
    background: var(--card);
}

.frontmatter-form label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.85rem;
    color: var(--muted);
}

.frontmatter-form input[type="text"],
.frontmatter-form select {
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--dc-radius-sm);
    font: inherit;
    color: var(--ink-2);
}

.tags-input {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.4rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--dc-radius-sm);
    background: var(--card);
    min-width: 16rem;
}

.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 3px 8px;
    border-radius: 6px;
    background: var(--tag-solid-bg);
    color: var(--tag-solid-ink);
    font: 600 12px var(--font-body);
}

.tag-remove {
    border: none;
    background: none;
    color: inherit;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0;
}

.tags-input #tag-entry {
    border: none;
    outline: none;
    flex: 1;
    min-width: 6rem;
    font: inherit;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    border-radius: var(--dc-radius-sm);
    background: var(--toolbar-bg);
    border: 1px solid var(--toolbar-border);
}

.editor-toolbar button {
    font: 500 12px var(--font-body);
    padding: 0.3rem 0.6rem;
    border: 0;
    border-radius: 7px;
    background: var(--toolbar-btn-bg);
    color: var(--toolbar-ink);
    cursor: pointer;
}

.editor-toolbar button:hover {
    background: var(--toolbar-btn-hover);
}

.editor-modes {
    margin-left: auto;
    display: inline-flex;
    gap: 4px;
    padding: 3px;
    background: var(--dc-surface-mute);
    border-radius: var(--dc-radius-sm);
}

.editor-mode {
    border: 0;
    background: transparent;
    color: var(--ink-3);
    font: 600 12px var(--font-body);
    padding: 4px 12px;
    border-radius: var(--dc-radius-xs);
    cursor: pointer;
    transition: background var(--dc-dur-fast) var(--dc-ease),
                color var(--dc-dur-fast) var(--dc-ease);
}

.editor-mode.active {
    background: var(--card);
    color: var(--ink-1);
    box-shadow: var(--dc-shadow-button);
}

.editor-mode:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.editor-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    height: 60vh;
    min-height: 20rem;
}

.editor-split.editor-source-only {
    grid-template-columns: 1fr;
}

.editor-split.editor-source-only .editor-preview {
    display: none;
}

.editor-pane {
    border: 1px solid var(--border-strong);
    border-radius: var(--dc-radius-sm);
    overflow: auto;
}

.editor-source-pane {
    background: var(--source-bg);
    border-color: var(--source-gutter);
}

.editor-source-pane .cm-editor {
    height: 100%;
    background: var(--source-bg);
    color: var(--source-ink);
}

.editor-source-pane .cm-content {
    caret-color: var(--accent);
    color: var(--source-ink);
}

.editor-source-pane .cm-gutters {
    background: var(--source-bg);
    color: var(--source-line);
    border: 0;
}

.editor-source-pane .cm-activeLine,
.editor-source-pane .cm-activeLineGutter {
    background: var(--source-active-line);
}

.editor-source-pane .cm-cursor {
    border-left-color: var(--accent);
}

.editor-body {
    width: 100%;
    height: 100%;
    border: none;
    padding: 0.75rem;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    resize: none;
}

.editor-preview {
    padding: 0.75rem 1rem;
    line-height: 1.6;
}

.conflict-prompt {
    padding: 0.75rem 1rem;
    border: 1px solid #fca5a5;
    background: #fef2f2;
    border-radius: var(--dc-radius-sm);
    color: #991b1b;
}

.conflict-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.conflict-actions button {
    font: inherit;
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--dc-radius-sm);
    background: var(--card);
    cursor: pointer;
}

.editor-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.editor-ifmatch {
    margin-left: auto;
    font: 400 12px var(--font-body);
    color: var(--muted);
}

.editor-ifmatch code {
    font-family: var(--font-mono);
    color: var(--ink-3);
}

.editor-actions button {
    font: 700 14px var(--font-body);
    padding: 0.45rem 1.1rem;
    border-radius: var(--dc-radius-md);
    cursor: pointer;
}

#editor-save {
    border: 0;
    background: var(--btn-primary-bg);
    color: var(--btn-primary-ink);
}

#editor-save:hover {
    background: var(--btn-primary-hover);
}

#editor-close {
    border: 1px solid var(--border-strong);
    background: var(--card);
    color: var(--ink-2);
}

/* ============================================================
   Auth pages — login split panel + change password
   ============================================================ */
.login-split {
    display: flex;
    min-height: 100vh;
    background: var(--card);
}

.login-panel {
    position: relative;
    overflow: hidden;
    width: 46%;
    flex: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 44px;
    background: var(--login-panel-bg);
    color: #fff;
}

.login-glow {
    position: absolute;
    border-radius: 50%;
}

.login-glow-1 {
    width: 360px;
    height: 360px;
    background: var(--login-glow-1);
    top: -120px;
    right: -120px;
    filter: blur(8px);
}

.login-glow-2 {
    width: 280px;
    height: 280px;
    background: var(--login-glow-2);
    bottom: -90px;
    left: -70px;
    filter: blur(6px);
}

.login-panel-brand {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
}

.login-panel-brand .brand-name {
    font: 700 18px var(--font-wordmark);
    color: #fff;
}

.login-panel-copy {
    position: relative;
}

.login-headline {
    margin: 0;
    font: 500 42px/1.05 var(--font-display);
    letter-spacing: 0.01em;
    color: #fff;
}

.login-tagline {
    margin: 18px 0 0;
    max-width: 340px;
    font: 400 15px/24px var(--font-body);
    color: rgba(255, 255, 255, 0.85);
}

.login-panel-note {
    position: relative;
    font: 400 12px var(--font-body);
    color: rgba(255, 255, 255, 0.7);
}

.login-form-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 56px;
}

.login-form {
    width: 100%;
    max-width: 340px;
}

.login-form-title {
    margin: 0;
    font: 500 30px/1.1 var(--font-display);
    color: var(--ink-1);
}

.login-form-sub {
    margin: 8px 0 0;
    font: 400 14px var(--font-body);
    color: var(--muted);
}

.login-form form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 28px;
}

.login-form label {
    display: flex;
    flex-direction: column;
    gap: 7px;
    font: 600 12px var(--font-body);
    color: var(--ink-3);
}

.login-form input {
    height: 46px;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    padding: 0 14px;
    font: 400 15px var(--font-body);
    color: var(--ink-1);
}

.login-submit {
    height: 48px;
    background: var(--btn-primary-bg);
    color: var(--btn-primary-ink);
    border: 0;
    border-radius: 10px;
    font: 700 15px var(--font-body);
    cursor: pointer;
}

.login-hint {
    margin: 16px 0 0;
    font: 400 12px/17px var(--font-body);
    color: var(--dc-ink-5);
}

.login-error {
    margin: 16px 0 0;
    color: #b91c1c;
    font-size: 0.9rem;
}

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--page);
}

.auth-standalone {
    padding: 40px;
    border-radius: var(--dc-radius-lg);
    background: var(--card);
    border: 1px solid var(--border);
    box-shadow: var(--dc-shadow-card);
}

/* ============================================================
   Command palette (⌘K)
   ============================================================ */
.cmd-palette[hidden] {
    display: none;
}

.cmd-palette {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.cmd-palette-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
}

.cmd-palette-modal {
    position: relative;
    width: 640px;
    max-width: calc(100vw - 32px);
    margin-top: 80px;
    background: #fff;
    border-radius: var(--dc-radius-lg);
    box-shadow: 0 24px 80px -12px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

.cmd-palette-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
}

.cmd-palette-input {
    flex: 1;
    border: 0;
    outline: none;
    font: 400 18px var(--font-body);
    color: var(--ink-1);
    background: transparent;
}

.cmd-palette-count {
    font: 400 12px var(--font-body);
    color: var(--muted);
}

.cmd-palette-tags {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
}

.cmd-palette-tags:empty {
    display: none;
}

.cmd-tags-label {
    font: 600 11px var(--font-body);
    color: var(--muted);
}

.cmd-tag {
    font: 500 11px var(--font-body);
    color: var(--ink-3);
    background: transparent;
    border: 1px solid var(--border-strong);
    border-radius: var(--dc-radius-pill);
    padding: 3px 10px;
    cursor: pointer;
}

.cmd-tag.selected {
    color: var(--tag-solid-ink);
    background: var(--tag-solid-bg);
    border-color: var(--tag-solid-bg);
}

.cmd-palette-results {
    padding: 8px 8px 12px;
    max-height: 50vh;
    overflow-y: auto;
}

.cmd-result {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 10px;
    text-decoration: none;
    color: inherit;
}

.cmd-result.active {
    background: var(--accent-tint);
}

.cmd-result-icon {
    flex: none;
    color: var(--muted);
}

.cmd-result.active .cmd-result-icon {
    color: var(--accent);
}

.cmd-result-body {
    flex: 1;
    min-width: 0;
}

.cmd-result-title {
    display: block;
    font: 600 15px var(--font-body);
    color: var(--ink-1);
}

.cmd-result-title mark {
    background: var(--dc-blue-50);
    color: var(--ink-1);
    border-radius: 3px;
    padding: 0 2px;
}

.cmd-result-path {
    display: block;
    font: 400 12px var(--font-body);
    color: var(--muted);
}

.cmd-result-enter,
.cmd-palette-footer kbd {
    font: 600 10px var(--font-mono);
    color: var(--muted);
    background: #fff;
    border: 1px solid var(--border-strong);
    border-radius: 5px;
    padding: 2px 6px;
}

.cmd-empty {
    padding: 20px 14px;
    color: var(--muted);
}

.cmd-palette-footer {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 20px;
    border-top: 1px solid var(--border);
    background: var(--dc-surface-mute);
    font: 500 11px var(--font-body);
    color: var(--muted);
}

.cmd-palette-engine {
    margin-left: auto;
}

/* ============================================================
   Create dialog (new document / folder)
   ============================================================ */
.create-modal {
    width: 520px;
    background: var(--card);
}

.create-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px 0;
}

.create-title {
    margin: 0;
    font: 500 22px var(--font-display);
    color: var(--ink-1);
}

.create-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: var(--dc-radius-sm);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.create-close:hover {
    background: var(--dc-surface-mute);
    color: var(--ink-1);
}

.create-close:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.create-modes {
    display: inline-flex;
    gap: 4px;
    margin: 16px 20px 0;
    padding: 3px;
    background: var(--dc-surface-mute);
    border-radius: var(--dc-radius-sm);
}

.create-mode {
    border: 0;
    background: transparent;
    color: var(--ink-3);
    font: 600 13px var(--font-body);
    padding: 6px 16px;
    border-radius: var(--dc-radius-xs);
    cursor: pointer;
    transition: background var(--dc-dur-fast) var(--dc-ease),
                color var(--dc-dur-fast) var(--dc-ease);
}

.create-mode.active {
    background: var(--card);
    color: var(--ink-1);
    box-shadow: var(--dc-shadow-button);
}

.create-mode:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

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

.create-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0;
}

.create-label {
    font: 600 12px var(--font-body);
    color: var(--muted);
}

.create-field input[type="text"] {
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--dc-radius-sm);
    font: 400 14px var(--font-body);
    color: var(--ink-1);
    background: var(--card);
}

.create-field input[type="text"]:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-tint);
}

.create-field .tags-input {
    min-width: 0;
}

.create-field .tags-input:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-tint);
}

.create-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: var(--dc-surface-mute);
    border-radius: var(--dc-radius-sm);
}

.create-preview-label {
    flex: none;
    font: 600 11px var(--font-body);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

#create-path-preview {
    font: 400 13px var(--font-mono);
    color: var(--code-chip-ink);
    word-break: break-all;
}

.create-error {
    margin: 0;
    padding: 10px 12px;
    border-radius: var(--dc-radius-sm);
    background: var(--lock-bg);
    border: 1px solid var(--lock-border);
    color: var(--lock-ink);
    font: 500 13px var(--font-body);
}

.create-error[hidden] {
    display: none;
}

.create-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 0 20px 20px;
}

#create-submit[aria-busy="true"] {
    opacity: 0.6;
    pointer-events: none;
}

/* ============================================================
   Admin — permissions matrix
   ============================================================ */
.perm-section {
    max-width: 900px;
}

.perm-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
}

.perm-title {
    margin: 0;
    font: 500 26px var(--font-display);
    color: var(--ink-1);
}

.perm-subtitle {
    margin: 4px 0 0;
    font: 400 13px var(--font-body);
    color: var(--muted);
}

.perm-matrix-card {
    margin-top: 20px;
    overflow: hidden;
}

.perm-matrix {
    width: 100%;
    border-collapse: collapse;
    font: 400 14px var(--font-body);
}

.perm-matrix thead tr {
    background: var(--perm-header-bg);
}

.perm-matrix thead th {
    padding: 13px 12px;
    font: 600 13px var(--font-body);
    color: var(--perm-header-ink);
    text-align: center;
}

.perm-matrix thead th.perm-corner {
    text-align: left;
    font-size: 12px;
    color: var(--rail-muted);
}

.perm-matrix tbody td {
    padding: 14px 12px;
    border-bottom: 1px solid var(--border);
    text-align: center;
}

.perm-matrix tbody tr:last-child td {
    border-bottom: 0;
}

.perm-dir {
    text-align: left !important;
    font: 400 13px var(--font-mono);
    color: var(--code-chip-ink);
}

.perm-pill {
    border: 0;
    cursor: pointer;
    font: 600 11px var(--font-body);
    border-radius: 6px;
    padding: 3px 9px;
}

.perm-rw {
    background: var(--perm-rw-bg);
    color: var(--perm-rw-ink);
}

.perm-r {
    background: var(--perm-r-bg);
    color: var(--perm-r-ink);
}

.perm-none {
    color: var(--perm-none-ink);
}

.perm-legend {
    display: flex;
    gap: 16px;
    margin-top: 16px;
    font: 500 12px var(--font-body);
    color: var(--ink-3);
}

.perm-legend span {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 4px;
}

.legend-rw {
    background: var(--perm-rw-bg);
}

.legend-r {
    background: var(--perm-r-bg);
}

.legend-none {
    background: var(--dc-surface-border);
}

.perm-form {
    margin-top: 24px;
    padding: 20px 24px;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 16px;
}

.perm-form h2 {
    width: 100%;
    margin: 0;
    font: 500 18px var(--font-display);
    color: var(--ink-1);
}

.perm-form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font: 600 12px var(--font-body);
    color: var(--ink-3);
}

.perm-form input[type="text"],
.perm-form select {
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--dc-radius-sm);
    font: inherit;
    color: var(--ink-2);
}

.perm-form .perm-check {
    flex-direction: row;
    align-items: center;
    gap: 8px;
}

.perm-form-hint {
    width: 100%;
    margin: -6px 0 0;
    font: 400 13px var(--font-body);
    color: var(--muted);
}

.perm-form-controls {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 16px;
}

.perm-picker {
    width: 100%;
    margin: 0;
    max-height: 340px;
    overflow-y: auto;
    padding: 12px 16px;
    border: 1px solid var(--border-strong);
    border-radius: var(--dc-radius-sm);
    background: var(--dc-surface-mute);
}

.perm-picker legend {
    padding: 0 6px;
    font: 600 12px var(--font-body);
    color: var(--ink-3);
}

.perm-picker-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.perm-picker-list .perm-picker-list {
    padding-left: 18px;
}

.perm-picker-node {
    margin: 0;
}

.perm-picker-summary {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    list-style: none;
}

.perm-picker-summary::-webkit-details-marker {
    display: none;
}

.perm-picker-chevron {
    width: 0;
    height: 0;
    border-left: 5px solid var(--ink-3);
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    transition: transform 0.12s ease;
}

details[open] > .perm-picker-summary > .perm-picker-chevron {
    transform: rotate(90deg);
}

.perm-picker-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px;
    border-radius: var(--dc-radius-sm);
    font: 400 13px var(--font-mono);
    color: var(--ink-2);
    cursor: pointer;
}

.perm-picker-item--leaf {
    margin-left: 9px;
}

.perm-picker-item:hover {
    background: var(--accent-tint);
}

.perm-picker-item input[type="checkbox"] {
    accent-color: var(--accent);
}

.perm-picker-root {
    font-family: var(--font-body);
    font-weight: 600;
    color: var(--ink-1);
}

/* ============================================================
   Admin — navigation rail
   ============================================================ */
.admin-rail-head {
    padding: 12px 18px 6px;
}

.admin-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    padding: 0 10px;
    overflow-y: auto;
}

.admin-nav-item {
    position: relative;
    display: block;
    padding: 8px 12px;
    border-radius: var(--dc-radius-sm);
    color: var(--rail-ink-2);
    text-decoration: none;
    font: 500 13px var(--font-body);
}

.admin-nav-item:hover {
    background: var(--rail-hover);
    color: var(--rail-ink);
}

.admin-nav-item.active {
    background: var(--rail-active-bg);
    color: var(--rail-active-ink);
    font-weight: 600;
}

.admin-nav-item.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    border-radius: 3px;
    background: var(--rail-accent);
}

/* ============================================================
   Admin — content (pages, tables, forms)
   ============================================================ */
.admin-page {
    max-width: 960px;
}

.admin-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 20px;
}

.admin-title {
    margin: 0;
    font: 500 26px var(--font-display);
    color: var(--ink-1);
}

.admin-table-card {
    overflow: hidden;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font: 400 14px var(--font-body);
}

.admin-table thead tr {
    background: var(--perm-header-bg);
}

.admin-table thead th {
    padding: 13px 16px;
    font: 600 13px var(--font-body);
    color: var(--perm-header-ink);
    text-align: left;
    white-space: nowrap;
}

.admin-table tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--ink-2);
    vertical-align: top;
}

.admin-table tbody tr:last-child td {
    border-bottom: 0;
}

.admin-mono {
    font: 400 12.5px var(--font-mono);
    color: var(--ink-3);
}

.admin-badge {
    display: inline-block;
    font: 600 11px var(--font-body);
    padding: 2px 9px;
    border-radius: var(--dc-radius-pill);
    background: var(--dc-surface-mute);
    color: var(--muted);
}

.admin-badge--on {
    background: var(--perm-r-bg);
    color: var(--perm-r-ink);
}

.admin-badge--off {
    background: var(--lock-bg);
    color: var(--lock-ink);
}

.admin-row-actions {
    text-align: right;
}

.admin-edit summary {
    list-style: none;
    display: inline-flex;
    cursor: pointer;
}

.admin-edit summary::-webkit-details-marker {
    display: none;
}

.admin-edit-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 10px;
    padding: 16px;
    text-align: left;
}

.admin-form {
    margin-top: 24px;
    padding: 20px 24px;
}

.admin-form-title {
    margin: 0 0 16px;
    font: 500 18px var(--font-display);
    color: var(--ink-1);
}

.admin-form-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.admin-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 200px;
    flex: 1;
}

.admin-label {
    font: 600 12px var(--font-body);
    color: var(--ink-3);
}

.admin-field input[type="text"],
.admin-field input[type="password"],
.admin-select {
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--dc-radius-sm);
    font: 400 14px var(--font-body);
    color: var(--ink-1);
    background: var(--card);
}

.admin-field input:focus-visible,
.admin-select:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-tint);
}

.admin-check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font: 500 13px var(--font-body);
    color: var(--ink-2);
    cursor: pointer;
}

.admin-check input {
    width: 15px;
    height: 15px;
    accent-color: var(--accent);
}

.admin-form-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 16px;
}

/* ---- Groups ---- */
.admin-group-card {
    margin-bottom: 16px;
    padding: 20px 24px;
}

.admin-group-head {
    margin-bottom: 12px;
}

.admin-group-name {
    margin: 0;
    font: 500 18px var(--font-display);
    color: var(--ink-1);
}

.admin-group-desc {
    margin: 4px 0 0;
    font: 400 13px var(--font-body);
    color: var(--muted);
}

.admin-member-list {
    list-style: none;
    margin: 0 0 14px;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.admin-member {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--dc-radius-sm);
    font: 500 13px var(--font-body);
    color: var(--ink-2);
}

.admin-inline-form {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ============================================================
   Print — export a document to PDF (browser print-to-PDF).
   Strips app chrome; forces light content in both themes.
   ============================================================ */
@page {
    margin: 18mm 16mm;
}

@media print {
    /* Force light content regardless of the on-screen theme. */
    :root {
        --page: #ffffff;
        --card: #ffffff;
        --border: #e2e8f0;
        --border-strong: #cbd5e1;
        --ink-1: #0f172a;
        --ink-2: #1e293b;
        --ink-3: #475569;
        --muted: #475569;
        --accent: #0d6ea8;
        --hero-bg: transparent;
        --hero-glow: transparent;
        --hero-ink: #0f172a;
        --hero-ink-soft: #475569;
        --hero-pill-bg: #f1f5f9;
        --hero-dot: #0f172a;
        --code-chip-bg: #f1f5f9;
        --code-chip-ink: #0d6ea8;
        --dc-surface-mute: #f4f4f5;
    }

    html,
    body {
        background: #ffffff;
        color: #0f172a;
    }

    /* Hide every piece of app chrome — only the document prints. */
    .rail,
    .sidebar-reopen,
    #command-palette,
    #create-dialog,
    .doc-actions,
    .doc-history {
        display: none !important;
    }

    .app {
        display: block;
        min-height: 0;
    }

    .content {
        padding: 0;
    }

    .document {
        max-width: none;
        margin: 0;
    }

    .doc-hero {
        overflow: visible;
        padding: 0 0 12px;
        border-radius: 0;
        color: #0f172a;
    }

    .doc-title {
        font-size: 28pt;
    }

    .doc-body {
        padding-top: 14px;
        font-size: 11pt;
    }

    /* Keep atomic blocks from splitting awkwardly across pages. */
    .doc-body pre,
    .doc-body table,
    .doc-body blockquote,
    .doc-body pre.mermaid,
    .doc-body img {
        break-inside: avoid;
    }

    .doc-body h1,
    .doc-body h2,
    .doc-body h3 {
        break-after: avoid;
    }

    .doc-body a {
        color: var(--accent);
    }
}
