@import url('https://fonts.googleapis.com/css2?family=Google+Sans+Flex:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

/* ─── Finn-inspired blue-slate palette — Dark mode (default) ──── */
:root {
    /* Core hue — everything derives from this blue-slate base */
    --hue: 204deg;
    --sat: 15%;

    /* Background scale */
    --bg:             hsl(var(--hue), var(--sat), 12%);
    --sidebar-bg:     hsl(var(--hue), var(--sat), 14%);
    --surface:        hsl(var(--hue), var(--sat), 18%);
    --surface-hover:  hsl(var(--hue), var(--sat), 22%);

    /* Borders */
    --border:         hsl(var(--hue), var(--sat), 25%);
    --border-strong:  hsl(var(--hue), var(--sat), 35%);
    --sidebar-border: hsl(var(--hue), var(--sat), 22%);

    /* Text */
    --text:           hsl(var(--hue), var(--sat), 80%);
    --text-strong:    hsl(var(--hue), var(--sat), 95%);
    --text-muted:     hsl(var(--hue), var(--sat), 60%);
    --text-faint:     hsl(var(--hue), var(--sat), 45%);

    /* Accent — blue-slate primary */
    --primary:        hsl(204deg, 49%, 45%);
    --primary-hover:  hsl(204deg, 49%, 55%);

    /* Links — blue, matching the Finn link treatment */
    --link:           hsl(204deg, 60%, 65%);
    --link-hover:     hsl(204deg, 60%, 75%);

    /* Semantic colors */
    --red-600:        hsl(4deg, 65%, 45%);
    --red-500:        hsl(4deg, 75%, 55%);
    --red-400:        hsl(4deg, 75%, 65%);
    --yellow-muted:   hsl(45deg, 55%, 60%);
    --green-muted:    hsl(140deg, 40%, 50%);

    /* Code */
    --code-bg:        hsl(var(--hue), var(--sat), 18%);
    --code-color:     hsl(4deg, 75%, 60%);

    /* Shadows */
    --shadow-dropdown: 0 8px 24px rgba(0, 0, 0, 0.45);

    /* Highlight */
    --highlight-bg:   rgba(201, 168, 76, 0.2);
    --highlight-text: hsl(45deg, 55%, 65%);

    /* Selection */
    --selection-bg:   hsl(204deg, 49%, 35%);
    --selection-text:  #fff;

    /* Layout */
    --sidebar-width:  260px;
    --rsb-width:      380px;
    --topbar-height:  42px;
    --radius:         4px;

    /* Typography */
    --font-body:      'Google Sans Flex', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono:      'JetBrains Mono', monospace;
    --font-size:      17px;
}

/* ─── Light mode overrides ─────────────────────────────────────── */
[data-theme="light"] {
    --bg:             hsl(var(--hue), var(--sat), 98%);
    --sidebar-bg:     hsl(var(--hue), var(--sat), 95%);
    --surface:        hsl(var(--hue), var(--sat), 91%);
    --surface-hover:  hsl(var(--hue), var(--sat), 87%);

    --border:         hsl(var(--hue), var(--sat), 82%);
    --border-strong:  hsl(var(--hue), var(--sat), 70%);
    --sidebar-border: hsl(var(--hue), var(--sat), 85%);

    --text:           hsl(var(--hue), var(--sat), 25%);
    --text-strong:    hsl(var(--hue), var(--sat), 12%);
    --text-muted:     hsl(var(--hue), var(--sat), 45%);
    --text-faint:     hsl(var(--hue), var(--sat), 60%);

    --primary:        hsl(204deg, 49%, 27%);
    --primary-hover:  hsl(204deg, 49%, 35%);

    --link:           hsl(204deg, 60%, 38%);
    --link-hover:     hsl(204deg, 60%, 28%);

    --red-600:        hsl(4deg, 65%, 42%);
    --red-500:        hsl(4deg, 65%, 50%);
    --red-400:        hsl(4deg, 65%, 58%);
    --yellow-muted:   hsl(45deg, 55%, 42%);
    --green-muted:    hsl(140deg, 40%, 35%);

    --code-bg:        hsl(var(--hue), var(--sat), 93%);
    --code-color:     hsl(4deg, 65%, 48%);

    --shadow-dropdown: 0 8px 24px rgba(0, 0, 0, 0.12);

    --highlight-bg:   rgba(201, 168, 76, 0.18);
    --highlight-text: hsl(45deg, 60%, 35%);

    --selection-bg:   hsl(204deg, 49%, 27%);
    --selection-text:  #fff;
}

/* ─── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

::selection {
    background: var(--selection-bg);
    color: var(--selection-text);
}

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: var(--font-size);
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    transition: background 0.2s ease, color 0.2s ease;
}

a { color: var(--link); }

/* ─── Top navbar ─────────────────────────────────────────────── */
.topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topbar-height);
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.75rem;
    z-index: 200;
    gap: 0.5rem;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.topbar-left,
.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    flex-shrink: 0;
}

.topbar-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.15rem;
    cursor: pointer;
    padding: 0.2rem 0.45rem;
    border-radius: var(--radius);
    line-height: 1;
    transition: color 0.1s, background 0.1s;
}
.topbar-btn:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.topbar-rsb-toggle {
    font-size: 1.25rem;
    letter-spacing: -0.05em;
}
body.rsb-open .topbar-rsb-toggle {
    color: var(--primary);
}

/* ── Topbar search ── */
.topbar-center {
    flex: 1;
    max-width: 420px;
    position: relative;
}
.topbar-search {
    position: relative;
    display: flex;
    align-items: center;
}
.topbar-search-icon {
    position: absolute;
    left: 0.55rem;
    color: var(--text-faint);
    font-size: 0.85rem;
    pointer-events: none;
}
.topbar-search-input {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.78rem;
    padding: 0.3rem 0.55rem 0.3rem 1.7rem;
    outline: none;
    transition: border-color 0.15s, background 0.15s;
}
.topbar-search-input::placeholder { color: var(--text-faint); }
.topbar-search-input:focus { border-color: var(--primary); }

.topbar-search-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0; right: 0;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow-dropdown);
    max-height: 320px;
    overflow-y: auto;
    z-index: 300;
}
.ts-item {
    padding: 0.45rem 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.82rem;
    color: var(--text);
    transition: background 0.08s;
}
.ts-item:hover,
.ts-item--active {
    background: var(--surface-hover);
}
.ts-item-icon {
    color: var(--text-faint);
    font-size: 0.75rem;
    flex-shrink: 0;
}
.ts-item-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ts-item--create {
    border-top: 1px solid var(--border);
    color: var(--primary);
}
.ts-item--create strong {
    color: var(--text-strong);
}
.ts-empty {
    padding: 0.6rem 0.75rem;
    color: var(--text-faint);
    font-size: 0.78rem;
    font-style: italic;
}

/* ─── Layout ────────────────────────────────────────────────────── */
.sidebar {
    position: fixed;
    top: var(--topbar-height); left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--topbar-height));
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    z-index: 100;
    padding: 1rem 0;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.content {
    position: fixed;
    top: var(--topbar-height);
    left: var(--sidebar-width);
    right: 0;
    bottom: 0;
    overflow-y: auto;
    padding: 2.5rem 3.5rem 6rem;
    transition: right 0.2s ease;
}

/* When right sidebar is open, shrink main content */
body.rsb-open .content {
    right: var(--rsb-width);
}

/* ─── Right sidebar ────────────────────────────────────────────── */
.right-sidebar {
    position: fixed;
    top: var(--topbar-height);
    right: 0;
    width: var(--rsb-width);
    height: calc(100vh - var(--topbar-height));
    background: var(--sidebar-bg);
    border-left: 1px solid var(--sidebar-border);
    z-index: 90;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.rsb-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.rsb-title {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-faint);
}
.rsb-close-all {
    background: none;
    border: none;
    color: var(--text-faint);
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0.15rem 0.35rem;
    border-radius: 2px;
    transition: color 0.12s, background 0.12s;
    line-height: 1;
}
.rsb-close-all:hover {
    color: var(--text);
    background: var(--surface);
}

.rsb-cards {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0;
}

/* ─── Right sidebar cards ──────────────────────────────────────── */
.rsb-card {
    border-bottom: 1px solid var(--border);
    padding: 0;
}

.rsb-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.55rem 1rem 0.35rem;
    position: sticky;
    top: 0;
    background: var(--sidebar-bg);
    z-index: 1;
}
.rsb-card-title {
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 400;
    font-style: italic;
    color: var(--link);
    text-decoration: none;
    transition: color 0.1s;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.rsb-card-title:hover { color: var(--link-hover); }

.rsb-card-close {
    background: none;
    border: none;
    color: var(--text-faint);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 0.1rem 0.3rem;
    border-radius: 2px;
    transition: color 0.12s, background 0.12s;
    flex-shrink: 0;
    line-height: 1;
}
.rsb-card-close:hover {
    color: var(--red-500);
    background: hsla(4deg, 75%, 55%, 0.1);
}

.rsb-card-blocks {
    padding: 0 0.75rem 0.6rem;
}

.rsb-block {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    padding: 0.05rem 0.15rem;
    border-radius: var(--radius);
    transition: background 0.08s;
}
.rsb-block:hover { background: var(--surface); }

.rsb-block-bullet {
    color: var(--text-faint);
    font-size: 0.4rem;
    padding-top: 0.45rem;
    flex-shrink: 0;
    user-select: none;
    width: 1rem;
    text-align: center;
}

.rsb-block-content {
    flex: 1;
    min-width: 0;
    font-family: var(--font-body);
    font-size: 0.85rem;
    line-height: 1.55;
    color: var(--text-muted);
    word-break: break-word;
    white-space: pre-wrap;
}

/* Wiki links inside sidebar cards */
.rsb-block-content a.wiki-link {
    color: var(--link);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: color 0.1s, border-color 0.1s;
    cursor: pointer;
}
.rsb-block-content a.wiki-link:hover {
    color: var(--link-hover);
    border-bottom-color: var(--link-hover);
}

/* Inline styles in sidebar blocks */
.rsb-block-content strong { font-weight: 600; color: var(--text-strong); }
.rsb-block-content em { font-style: italic; }
.rsb-block-content code {
    font-family: var(--font-mono);
    font-size: 0.8em;
    background: var(--code-bg);
    color: var(--code-color);
    padding: 0.1em 0.3em;
    border-radius: 2px;
}
.rsb-block-content del { opacity: 0.5; text-decoration: line-through; }
.rsb-block-content mark {
    background: var(--highlight-bg);
    color: var(--highlight-text);
    padding: 0.05em 0.15em;
    border-radius: 2px;
}
.rsb-block-content .todo-checkbox {
    display: inline-block;
    width: 0.75rem;
    height: 0.75rem;
    border: 1.5px solid var(--text-faint);
    border-radius: 2px;
    vertical-align: middle;
    margin-right: 0.25rem;
    position: relative;
    top: -1px;
}
.rsb-block-content .todo-checkbox.todo-checked {
    background: var(--primary);
    border-color: var(--primary);
}
.rsb-block-content .block-ref {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 2px;
    padding: 0.02em 0.3em;
    font-size: 0.85em;
    color: var(--text-muted);
}

/* Empty state */
.rsb-empty {
    padding: 1.5rem 1rem;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-faint);
    font-style: italic;
    text-align: center;
}

/* Add block input in sidebar cards */
.rsb-add-block {
    padding: 0.25rem 0.75rem 0.5rem;
}
.rsb-add-input {
    width: 100%;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.82rem;
    padding: 0.3rem 0.15rem;
    outline: none;
    transition: border-color 0.15s;
}
.rsb-add-input::placeholder {
    color: var(--text-faint);
    font-style: italic;
    font-size: 0.78rem;
}
.rsb-add-input:focus {
    border-bottom-color: var(--primary);
}
.rsb-add-input:disabled {
    opacity: 0.4;
}

/* ─── Right sidebar: backlinks section ──────────────────────────── */
.rsb-backlinks-section {
    border-top: 1px solid var(--border);
    margin-top: 0.5rem;
    padding-top: 0.5rem;
}

.rsb-section-heading {
    font-family: var(--font-mono);
    font-size: 0.55rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-faint);
    padding: 0 0.65rem 0.35rem;
}

.rsb-section-toggle {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.35rem 0.65rem;
    cursor: pointer;
    user-select: none;
    transition: color 0.1s;
}
.rsb-section-toggle:hover {
    color: var(--text-muted);
}
.rsb-section-toggle .rsb-section-heading {
    padding: 0;
}
.rsb-section-caret {
    font-size: 1.5rem;
    color: var(--text-faint);
    width: 1.1rem;
    text-align: center;
    flex-shrink: 0;
    line-height: 1;
}
.rsb-section-toggle:hover .rsb-section-caret {
    color: var(--text-muted);
}

.rsb-section-body {
    transition: max-height 0.15s ease;
}
.rsb-section-collapsed .rsb-section-body {
    display: none;
}

.rsb-backlink {
    padding: 0.25rem 0.65rem;
    border-left: 2px solid var(--border);
    margin: 0 0.65rem 0.35rem;
    transition: border-color 0.12s;
}

.rsb-backlink:hover {
    border-left-color: var(--primary);
}

.rsb-backlink-source {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.62rem;
    color: var(--text-faint);
    margin-bottom: 0.1rem;
    font-style: italic;
}

.rsb-backlink-source a.wiki-link {
    color: var(--link);
    text-decoration: none;
    transition: color 0.1s;
}

.rsb-backlink-source a.wiki-link:hover {
    color: var(--link-hover);
}

.rsb-backlink-content {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.5;
    word-break: break-word;
}

.rsb-backlink-content a.wiki-link {
    color: var(--link);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.1s, color 0.1s;
}

.rsb-backlink-content a.wiki-link:hover {
    color: var(--link-hover);
    border-bottom-color: var(--link-hover);
}

.rsb-backlink-content code {
    font-family: var(--font-mono);
    font-size: 0.85em;
    background: var(--code-bg);
    color: var(--code-color);
    padding: 0.1em 0.3em;
    border-radius: 2px;
}

.rsb-backlink-content .todo-checkbox {
    width: 0.75rem;
    height: 0.75rem;
    cursor: default;
}

/* ─── Sidebar ───────────────────────────────────────────────────── */
.sidebar-top {
    display: flex;
    flex-direction: column;
    padding: 0 0.85rem;
    gap: 0.1rem;
}

.nav-logo {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    letter-spacing: 0.18em;
    text-transform: lowercase;
    padding: 0.4rem 0.5rem;
    margin-bottom: 0.5rem;
    display: block;
    transition: color 0.1s;
}
.nav-logo:hover { color: var(--text); }

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
    font-family: var(--font-mono);
    padding: 0.35rem 0.5rem;
    border-radius: var(--radius);
    transition: color 0.1s, background 0.1s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.nav-link:hover { color: var(--text); background: var(--surface-hover); }

.sidebar-divider {
    height: 1px;
    background: var(--sidebar-border);
    margin: 0.6rem 0.85rem;
}

.sidebar-bottom {
    margin-top: auto;
    padding: 0.75rem 0.85rem 0;
    border-top: 1px solid var(--sidebar-border);
}
.nav-link--small { font-size: 0.75rem; }

/* ─── Sidebar bookmarks ────────────────────────────────────────── */
.sidebar-bookmarks {
    padding: 0 0.85rem;
}

.sidebar-section-label {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-faint);
    padding: 0.2rem 0.5rem 0.3rem;
}

.nav-link--bookmark {
    font-size: 0.78rem;
}

/* ─── Sidebar attributes panel ────────────────────────────────── */
.sidebar-attrs {
    padding: 0 0.85rem;
}

.attr-row {
    display: flex;
    align-items: baseline;
    gap: 0.35rem;
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius);
    transition: background 0.08s, opacity 0.12s;
}

.attr-row:hover {
    background: var(--surface-hover);
}

.attr-key {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.attr-key::after {
    content: '::';
    color: var(--text-faint);
    margin-left: 0.1rem;
}

.attr-value {
    font-family: var(--font-body);
    font-size: 0.82rem;
    color: var(--text);
    cursor: text;
    min-width: 2rem;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border-radius: 2px;
    padding: 0 0.2rem;
    transition: background 0.1s;
}

.attr-value:hover {
    background: var(--surface);
}

.attr-value--empty {
    color: var(--text-faint);
    font-style: italic;
    font-size: 0.72rem;
}

.attr-delete {
    background: none;
    border: none;
    color: var(--text-faint);
    font-size: 0.6rem;
    cursor: pointer;
    padding: 0 0.15rem;
    opacity: 0;
    transition: opacity 0.1s, color 0.1s;
    flex-shrink: 0;
}

.attr-row:hover .attr-delete {
    opacity: 1;
}

.attr-delete:hover {
    color: var(--red-500);
}

.attr-add-btn {
    display: block;
    width: 100%;
    background: none;
    border: none;
    color: var(--text-faint);
    font-family: var(--font-mono);
    font-size: 0.65rem;
    cursor: pointer;
    padding: 0.3rem 0.5rem;
    text-align: left;
    border-radius: var(--radius);
    transition: color 0.1s, background 0.1s;
}

.attr-add-btn:hover {
    color: var(--text-muted);
    background: var(--surface-hover);
}

.attr-add-form {
    padding: 0.3rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.attr-input {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    padding: 0.25rem 0.45rem;
    outline: none;
    transition: border-color 0.15s;
}

.attr-input:focus {
    border-color: var(--primary);
}

.attr-input::placeholder {
    color: var(--text-faint);
}

.attr-inline-edit {
    width: 100%;
    padding: 0 0.2rem;
    font-family: var(--font-body);
    font-size: 0.82rem;
    background: var(--surface);
    border: 1px solid var(--primary);
}

.attr-add-actions {
    display: flex;
    gap: 0.35rem;
}

.attr-save-btn,
.attr-cancel-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.62rem;
    padding: 0.2rem 0.5rem;
    cursor: pointer;
    transition: color 0.1s, border-color 0.1s;
}

.attr-save-btn:hover {
    color: var(--text);
    border-color: var(--border-strong);
}

.attr-cancel-btn:hover {
    color: var(--text-faint);
}

/* ─── Sidebar calendar ─────────────────────────────────────────── */
.sidebar-calendar {
    padding: 0 0.85rem;
}

.scal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.3rem;
}
.scal-title {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.04em;
}
.scal-nav {
    background: none;
    border: none;
    color: var(--text-faint);
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0 0.3rem;
    transition: color 0.1s;
    line-height: 1;
}
.scal-nav:hover { color: var(--text); }

.scal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0;
}
.scal-day-head {
    font-family: var(--font-mono);
    font-size: 0.52rem;
    font-weight: 500;
    color: var(--text-faint);
    text-align: center;
    padding: 0.1rem 0 0.2rem;
    letter-spacing: 0.02em;
}
.scal-day-head.scal-weekend { color: var(--text-faint); opacity: 0.6; }

.scal-cell {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    text-align: center;
    padding: 0.22rem 0;
    border-radius: 3px;
    cursor: pointer;
    color: var(--text-muted);
    text-decoration: none;
    transition: background 0.08s, color 0.08s;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    line-height: 1;
}
.scal-cell:hover { background: var(--surface-hover); color: var(--text); }
.scal-cell.scal-weekend { color: var(--text-faint); }
.scal-cell.scal-weekend:hover { color: var(--text-muted); }
.scal-cell.scal-empty { cursor: default; }
.scal-cell.scal-today {
    background: var(--primary);
    color: #fff;
    font-weight: 500;
}
.scal-cell.scal-today:hover { background: var(--primary-hover); }

/* Dot indicator for days with content */
.scal-cell.scal-has-content::after {
    content: '';
    position: absolute;
    bottom: 1px;
    left: 50%;
    transform: translateX(-50%);
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: var(--text-faint);
}
.scal-cell.scal-today.scal-has-content::after {
    background: rgba(255, 255, 255, 0.6);
}

/* ─── Page ──────────────────────────────────────────────────────── */
.page { max-width: 700px; }
.page--wide { max-width: 940px; }

.page-title {
    font-family: var(--font-body);
    font-size: 1.75rem;
    font-weight: 600;
    line-height: 1.25;
    color: var(--text-strong);
    margin-bottom: 0;
    letter-spacing: -0.01em;
    font-style: italic;
}

/* Editable title */
.page-title[contenteditable] {
    outline: none;
    border-bottom: 2px solid transparent;
    transition: border-color 0.15s;
    cursor: text;
    border-radius: 2px;
    padding: 0 0.1rem;
}
.page-title[contenteditable]:focus {
    border-bottom-color: var(--primary);
}
.page-title[contenteditable]:hover:not(:focus) {
    border-bottom-color: var(--border);
}

.page-header {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    margin-bottom: 1.75rem;
}

.btn-bookmark {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.1rem;
    line-height: 1;
    transition: opacity 0.12s;
}

.bookmark-icon {
    font-size: 1rem;
    color: var(--text-faint);
    transition: color 0.12s;
}

.btn-bookmark:hover .bookmark-icon {
    color: var(--yellow-muted);
}

.btn-bookmark.is-active .bookmark-icon {
    color: var(--yellow-muted);
}

/* ─── Editor ────────────────────────────────────────────────────── */
.editor {
    display: flex;
    flex-direction: column;
    margin-bottom: 2.5rem;
    width: 100%;
}

.block {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    padding: 0.1rem 0.25rem;
    border-radius: var(--radius);
    transition: background 0.08s;
    width: 100%;
    min-width: 0;
    cursor: text;
}
.block:hover { background: var(--surface); }

.block-bullet {
    color: var(--text-faint);
    font-size: 0.5rem;
    padding-top: 0.55rem;
    flex-shrink: 0;
    user-select: none;
    width: 1.25rem;
    text-align: center;
    transition: color 0.1s;
}
.block:hover .block-bullet { color: var(--text-muted); }

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

/* ── Display ── */
.block-display {
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.65;
    color: var(--text);
    min-height: 1.5rem;
    word-break: break-word;
    white-space: pre-wrap;
    cursor: text;
    padding: 1px 0;
}
.block-display--placeholder {
    color: var(--text-faint);
    font-style: italic;
}

/* Wiki links */
.block-display a.wiki-link,
.backlink-content a.wiki-link,
.todo-item a.wiki-link,
.todo-breadcrumbs a.wiki-link,
.search-result-content a.wiki-link {
    color: var(--link);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.1s, color 0.1s;
}
.block-display a.wiki-link:hover,
.backlink-content a.wiki-link:hover,
.todo-item a.wiki-link:hover,
.todo-breadcrumbs a.wiki-link:hover,
.search-result-content a.wiki-link:hover {
    color: var(--link-hover);
    border-bottom-color: var(--link-hover);
}

/* External links */
.block-display a.external-link,
.backlink-content a.external-link,
.todo-item a.external-link,
.search-result-content a.external-link {
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 1px dashed var(--text-faint);
    transition: color 0.1s, border-color 0.1s;
}
.block-display a.external-link:hover,
.backlink-content a.external-link:hover {
    color: var(--text);
    border-bottom-color: var(--text);
}

/* ── Markdown inline styles ── */
.block-display strong,
.backlink-content strong,
.todo-item strong { font-weight: 600; color: var(--text-strong); }

.block-display em,
.backlink-content em,
.todo-item em { font-style: italic; }

.block-display code,
.backlink-content code,
.todo-item code {
    font-family: var(--font-mono);
    font-size: 0.85em;
    background: var(--code-bg);
    color: var(--code-color);
    padding: 0.1em 0.35em;
    border-radius: 2px;
}

.block-display del,
.backlink-content del { opacity: 0.5; text-decoration: line-through; }

.block-display mark,
.backlink-content mark {
    background: var(--highlight-bg);
    color: var(--highlight-text);
    padding: 0.05em 0.2em;
    border-radius: 2px;
}

.block-display blockquote {
    border-left: 3px solid var(--border-strong);
    padding-left: 0.85rem;
    color: var(--text-muted);
    font-style: italic;
}

/* Block-level headings (rendered inside blocks) */
.block-heading {
    font-family: var(--font-body);
    font-weight: 600;
    color: var(--text-strong);
    line-height: 1.3;
    margin-top: 0.6rem;
    padding-bottom: 0.1rem;
}
.block-h2 { font-size: 1.4rem; margin-top: 1rem; }
.block-h3 { font-size: 1.2rem; margin-top: 0.75rem; }
.block-h4 { font-size: 1.05rem; letter-spacing: 0.01em; }

/* ── Textarea ── */
.block-textarea {
    display: none;
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    overflow: hidden;
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.65;
    color: var(--text-strong);
    caret-color: var(--primary);
    padding: 1px 0;
    min-height: 1.5rem;
}

/* ─── Todo checkboxes ───────────────────────────────────────────── */
.todo-checkbox {
    display: inline-block;
    width: 0.9rem;
    height: 0.9rem;
    border: 1.5px solid var(--text-faint);
    border-radius: 2px;
    cursor: pointer;
    vertical-align: middle;
    margin-right: 0.35rem;
    position: relative;
    top: -1px;
    transition: border-color 0.12s, background 0.12s;
}
.todo-checkbox:hover { border-color: var(--primary); }

.todo-checkbox.todo-checked {
    background: var(--primary);
    border-color: var(--primary);
}
.todo-checkbox.todo-checked::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    line-height: 1;
}

.backlink-content .todo-checkbox { cursor: default; }

/* ─── Sections ──────────────────────────────────────────────────── */
.section-heading {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-faint);
    margin-bottom: 0.75rem;
}

.backlinks, .lookahead {
    margin-top: 2.5rem;
    padding-top: 1.75rem;
    border-top: 1px solid var(--border);
}

.lookahead-day { margin-bottom: 1.25rem; }

.lookahead-date {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
    font-family: var(--font-mono);
}
.lookahead-date a { color: inherit; text-decoration: none; transition: color 0.1s; }
.lookahead-date a:hover { color: var(--link); }

.backlink-block {
    border-left: 2px solid var(--border);
    padding: 0.35rem 0 0.35rem 0.9rem;
    margin-bottom: 0.5rem;
    transition: border-color 0.12s;
}
.backlink-block:hover { border-left-color: var(--primary); }

.backlink-source {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-faint);
    margin-bottom: 0.15rem;
    font-style: italic;
}
.backlink-source a { color: var(--link); text-decoration: none; transition: color 0.1s; }
.backlink-source a:hover { color: var(--link-hover); }

.backlink-content {
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.5;
    white-space: pre-wrap;
}

/* ─── Autocomplete / Template picker dropdown ───────────────────── */
.ac-dropdown {
    position: fixed;
    z-index: 200;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    min-width: 260px;
    max-width: 400px;
    max-height: 240px;
    overflow-y: auto;
    box-shadow: var(--shadow-dropdown);
    padding: 0.25rem 0;
}
.ac-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.65rem;
    cursor: pointer;
    transition: background 0.06s;
}
.ac-item:hover, .ac-item--active { background: var(--surface-hover); }
.ac-icon { font-size: 0.75rem; flex-shrink: 0; }
.ac-title {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ac-item--active .ac-title { color: var(--text-strong); }
.ac-empty {
    padding: 0.45rem 0.65rem;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-faint);
    font-style: italic;
}
.ac-item--create .ac-icon {
    color: var(--primary);
    font-weight: 600;
}
.ac-item--create .ac-title {
    color: var(--text-muted);
}
.ac-item--create .ac-title strong {
    color: var(--text);
}

/* Block ref dropdown items */
.ac-block-ref {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}
.ac-block-content {
    font-family: var(--font-body);
    font-size: 0.78rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ac-block-page {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    color: var(--text-faint);
}

/* Inline block references */
.block-ref {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 2px;
    padding: 0.05em 0.4em;
    font-size: 0.9em;
    color: var(--text-muted);
    cursor: default;
    transition: border-color 0.1s;
}
.block-ref:hover { border-color: var(--border-strong); }
.block-ref--missing { color: var(--text-faint); font-style: italic; }

/* ─── Date picker ───────────────────────────────────────────────── */
.dp-dropdown {
    position: fixed;
    z-index: 200;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow-dropdown);
    padding: 0.6rem;
    width: 260px;
}

.dp-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}
.dp-title {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text);
}
.dp-nav {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1rem;
    cursor: pointer;
    padding: 0 0.4rem;
    transition: color 0.1s;
}
.dp-nav:hover { color: var(--text); }

.dp-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
}
.dp-day-head {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    font-weight: 500;
    color: var(--text-faint);
    text-align: center;
    padding: 0.2rem 0 0.35rem;
    letter-spacing: 0.03em;
}
.dp-day-head.dp-weekend { opacity: 0.6; }

.dp-cell {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    text-align: center;
    padding: 0.3rem 0;
    border-radius: 3px;
    cursor: pointer;
    color: var(--text-muted);
    transition: background 0.08s, color 0.08s;
}
.dp-cell:hover { background: var(--surface-hover); color: var(--text); }
.dp-cell.dp-weekend { color: var(--text-faint); }
.dp-cell.dp-weekend:hover { color: var(--text-muted); }
.dp-cell.dp-today {
    background: var(--primary);
    color: #fff;
    font-weight: 500;
}
.dp-cell.dp-today:hover { background: var(--primary-hover); }
.dp-cell.dp-empty { cursor: default; }

/* ─── Link popup ────────────────────────────────────────────────── */
.link-popup {
    position: fixed;
    z-index: 200;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow-dropdown);
    padding: 0.5rem 0.6rem;
    width: 300px;
}
.link-popup-label {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    font-weight: 500;
    color: var(--text-faint);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    display: block;
    margin-bottom: 0.3rem;
}
.link-popup-input {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.78rem;
    padding: 0.35rem 0.55rem;
    outline: none;
    transition: border-color 0.15s;
}
.link-popup-input:focus { border-color: var(--primary); }

/* ─── Page sections ─────────────────────────────────────────────── */
.page-section { margin-bottom: 2.5rem; }
.page-section .section-heading { margin-bottom: 0.5rem; }

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.5rem;
}
.section-header .section-heading { margin-bottom: 0; }

.table-filter {
    position: relative;
    display: flex;
    align-items: center;
}
.table-filter-input {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    padding: 0.3rem 0.55rem;
    width: 180px;
    outline: none;
    transition: border-color 0.15s;
}
.table-filter-input::placeholder { color: var(--text-faint); }
.table-filter-input:focus { border-color: var(--primary); }
.table-filter-clear {
    position: absolute;
    right: 0.4rem;
    color: var(--text-faint);
    font-size: 0.7rem;
    text-decoration: none;
    line-height: 1;
    transition: color 0.1s;
}
.table-filter-clear:hover { color: var(--text); }

/* ─── Page table (All Pages) ────────────────────────────────────── */
.page-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-size: 0.78rem;
}
.page-table thead th {
    text-align: left;
    font-weight: 500;
    color: var(--text-faint);
    font-size: 0.62rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid var(--border);
}
.page-table tbody tr {
    transition: background 0.08s;
}
.page-table tbody tr:hover { background: var(--surface); }
.page-table tbody td {
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
    vertical-align: middle;
}
.page-table tbody td:first-child a {
    color: var(--link);
    text-decoration: none;
    transition: color 0.1s;
}
.page-table tbody td:first-child a:hover { color: var(--link-hover); }

.page-table-title { min-width: 180px; }
.page-table-meta { font-size: 0.7rem; white-space: nowrap; }
.page-table-num { font-size: 0.7rem; text-align: right !important; width: 60px; }
.page-table-action { width: 30px; text-align: center !important; }

.btn-delete-page {
    background: none;
    border: none;
    color: var(--text-faint);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0.15rem 0.3rem;
    border-radius: 2px;
    transition: color 0.12s, background 0.12s;
    line-height: 1;
}
.btn-delete-page:hover {
    color: var(--red-500);
    background: hsla(4deg, 75%, 55%, 0.1);
}

/* ── Sort links ── */
.sort-link {
    color: var(--text-faint);
    text-decoration: none;
    transition: color 0.1s;
    white-space: nowrap;
}
.sort-link:hover { color: var(--text); }
.sort-link.sort-active { color: var(--text-muted); }

/* ── Section count ── */
.section-count {
    font-weight: 400;
    color: var(--text-faint);
    font-size: 0.85em;
}

/* ── Pagination ── */
.pagination {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0.5rem 0;
    font-family: var(--font-mono);
    font-size: 0.72rem;
}
.page-link {
    color: var(--link);
    text-decoration: none;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius);
    transition: background 0.1s, color 0.1s;
}
.page-link:hover {
    background: var(--surface-hover);
    color: var(--link-hover);
}
.page-info {
    color: var(--text-faint);
}

/* ─── Todos page ────────────────────────────────────────────────── */
.todo-group { margin-bottom: 2rem; }

.todo-group-title {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    margin-bottom: 0.5rem;
}
.todo-group-title a { color: var(--link); text-decoration: none; transition: color 0.1s; }
.todo-group-title a:hover { color: var(--link-hover); }

.todo-item {
    padding: 0.3rem 0 0.3rem 0.25rem;
    font-size: 0.95rem;
    color: var(--text);
    line-height: 1.5;
    border-radius: var(--radius);
    transition: opacity 0.2s, transform 0.2s, background 0.08s;
}
.todo-item:hover { background: var(--surface); }

.todo-item-content { /* contains the checkbox + text */ }

.todo-breadcrumbs {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    color: var(--text-faint);
    margin-bottom: 0.15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ─── Page list (fallback) ──────────────────────────────────────── */
.page-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}
.page-list a {
    color: var(--link);
    text-decoration: none;
    font-size: 0.95rem;
    padding: 0.2rem 0;
    display: block;
    transition: color 0.1s;
}
.page-list a:hover { color: var(--link-hover); }
.page-list .empty { color: var(--text-faint); font-style: italic; }

/* ─── Template management ───────────────────────────────────────── */
.template-actions { margin-bottom: 1.5rem; }

.btn-new-template {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text-muted);
    text-decoration: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.35rem 0.75rem;
    transition: color 0.1s, background 0.1s, border-color 0.1s;
}
.btn-new-template:hover {
    color: var(--text);
    background: var(--surface);
    border-color: var(--border-strong);
}

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

.template-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.6rem 0.85rem;
    transition: border-color 0.1s;
}
.template-card:hover { border-color: var(--border-strong); }

.template-card-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.template-card-name {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--text);
}
.template-badge {
    font-family: var(--font-mono);
    font-size: 0.58rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--green-muted);
    border: 1px solid var(--green-muted);
    border-radius: 2px;
    padding: 0.1rem 0.35rem;
}

.template-card-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.template-link {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--text-faint);
    text-decoration: none;
    background: none;
    border: none;
    cursor: pointer;
    transition: color 0.1s;
}
.template-link:hover { color: var(--text); }
.template-link--danger:hover { color: var(--red-500); }

.inline-form { display: inline; }

/* ─── Template form ─────────────────────────────────────────────── */
.template-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-width: 520px;
}
.form-label {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-faint);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
}
.form-hint {
    font-size: 0.6rem;
    font-weight: 400;
    color: var(--text-faint);
    text-transform: none;
    letter-spacing: 0;
}
.form-input {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.82rem;
    padding: 0.45rem 0.65rem;
    outline: none;
    transition: border-color 0.15s;
}
.form-input:focus { border-color: var(--primary); }

.form-textarea {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.78rem;
    line-height: 1.55;
    padding: 0.55rem 0.65rem;
    outline: none;
    resize: vertical;
    tab-size: 2;
    transition: border-color 0.15s;
}
.form-textarea:focus { border-color: var(--primary); }

.form-checkbox-label {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}
.form-checkbox-label input[type="checkbox"] {
    accent-color: var(--primary);
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.25rem;
}
.btn-save {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    padding: 0.45rem 1rem;
    cursor: pointer;
    transition: background 0.15s;
    letter-spacing: 0.03em;
}
.btn-save:hover { background: var(--primary-hover); }
.btn-cancel {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text-faint);
    text-decoration: none;
    padding: 0.45rem 0.75rem;
    transition: color 0.1s;
}
.btn-cancel:hover { color: var(--text); }

/* ─── Search ────────────────────────────────────────────────────── */
.search-form { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; }
.search-form input {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 0.45rem 0.75rem;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    outline: none;
    transition: border-color 0.15s;
}
.search-form input:focus { border-color: var(--primary); }
.search-form button {
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.45rem 1rem;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
}
.search-form button:hover { background: var(--surface-hover); color: var(--text); }

.search-results { list-style: none; }
.search-result { padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.search-result-page {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--link);
    text-decoration: none;
    margin-bottom: 0.2rem;
    font-weight: 500;
    transition: color 0.1s;
}
.search-result-page:hover { color: var(--link-hover); }
.search-result-content { font-size: 0.9rem; color: var(--text-muted); }

.empty { color: var(--text-faint); font-style: italic; }

/* ─── Login ─────────────────────────────────────────────────────── */
body.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}
body.login-body .topbar,
body.login-body .sidebar,
body.login-body .right-sidebar,
body.login-body .ctx-menu { display: none; }
body.login-body .content {
    position: static;
    padding: 0;
}
.login-box {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 2rem 1.75rem;
    border-radius: 6px;
    width: 100%;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}
.login-logo {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-faint);
    letter-spacing: 0.18em;
    text-align: center;
    margin-bottom: 0.5rem;
}
.login-error { color: var(--red-400); font-size: 0.78rem; font-family: var(--font-mono); }
.login-box input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 0.5rem 0.7rem;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    outline: none;
    transition: border-color 0.15s;
}
.login-box input:focus { border-color: var(--primary); }
.login-box button {
    width: 100%;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    padding: 0.55rem;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    cursor: pointer;
    transition: background 0.15s;
    margin-top: 0.25rem;
    letter-spacing: 0.04em;
}
.login-box button:hover { background: var(--primary-hover); }

/* ─── Tiptap / ProseMirror editor ──────────────────────────────── */
.editor .ProseMirror {
    outline: none;
    min-height: 3rem;
}

.editor .ProseMirror > .block {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    padding: 0.1rem 0.25rem;
    border-radius: var(--radius);
    transition: background 0.08s;
    width: 100%;
    min-width: 0;
    cursor: text;
}

.editor .ProseMirror > .block:hover {
    background: var(--surface);
}

.editor .block .block-bullet {
    color: var(--text-faint);
    font-size: 0.5rem;
    padding-top: 0.55rem;
    flex-shrink: 0;
    user-select: none;
    width: 1.25rem;
    text-align: center;
    transition: color 0.1s;
}

.editor .block:hover .block-bullet {
    color: var(--text-muted);
}

/* Drag handle — appears on hover, initiates block drag */
.editor .block .block-handle {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 1rem;
    color: transparent;
    font-size: 0.7rem;
    text-align: center;
    cursor: grab;
    user-select: none;
    transition: color 0.12s;
    line-height: 1;
    padding: 0.2rem 0;
}
.editor .block {
    position: relative;
}
.editor .block:hover .block-handle {
    color: var(--text-faint);
}
.editor .block .block-handle:hover {
    color: var(--text-muted);
}
.editor .block .block-handle:active {
    cursor: grabbing;
    color: var(--primary);
}

/* ProseMirror drop cursor — styled line between blocks */
.ProseMirror-dropcursor {
    background: var(--primary) !important;
    height: 2px !important;
    opacity: 1 !important;
}

/* ── Custom drag ghost ── */
.drag-ghost {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    background: var(--surface);
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    padding: 0.3rem 0.65rem;
    font-family: var(--font-body);
    font-size: 0.82rem;
    color: var(--text);
    max-width: 350px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    opacity: 0.92;
}

/* Source blocks while dragging */
.editor .block.block-dragging {
    opacity: 0.25;
    pointer-events: none;
}

/* Drop indicator line — fixed positioned in viewport */
.drop-indicator {
    position: fixed;
    height: 2px;
    background: var(--primary);
    border-radius: 1px;
    z-index: 9998;
    pointer-events: none;
    display: none;
}
.drop-indicator::before {
    content: '';
    position: absolute;
    left: -3px;
    top: -3px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
}

/* ── Block collapse/expand ── */
/* Blocks with children: bullet becomes a toggle caret */
.editor .block.block-has-children .block-bullet {
    cursor: pointer;
    font-size: 0;
    line-height: 0;
    transition: color 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: 0;
    min-height: 1.65rem;
}
.editor .block.block-has-children .block-bullet::before {
    content: '▾';
    font-size: 1.5rem;
    line-height: 1;
    display: inline-block;
}

/* Collapsed state: toggle points right */
.editor .block.block-collapsed .block-bullet::before {
    content: '▸';
}

/* Child count indicator for collapsed blocks */
.editor .block.block-collapsed .block-bullet {
    color: var(--primary);
}

/* Hidden children */
.editor .block.block-hidden {
    display: none !important;
}

.editor .block .block-content {
    flex: 1;
    min-width: 0;
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.65;
    color: var(--text);
    word-break: break-word;
    white-space: pre-wrap;
    caret-color: var(--primary);
    min-height: 1.5rem;
    padding: 1px 0;
}

.editor .block .block-content:focus {
    outline: none;
}

/* ProseMirror selection */
.editor .ProseMirror .ProseMirror-selectednode {
    outline: 2px solid var(--primary);
    outline-offset: 1px;
    border-radius: 2px;
}

/* ProseMirror gapcursor */
.editor .ProseMirror .ProseMirror-gapcursor::after {
    border-color: var(--primary);
}

/* ProseMirror dropcursor */
.editor .ProseMirror .ProseMirror-dropcursor {
    color: var(--primary);
}

/* Placeholder for empty editor */
.editor .ProseMirror > .block:first-child:last-child .block-content:empty::before {
    content: 'Start writing\2026';
    color: var(--text-faint);
    font-style: italic;
    pointer-events: none;
}

/* Inline marks inside the editor */
.editor .block-content strong { font-weight: 600; color: var(--text-strong); }
.editor .block-content em { font-style: italic; }
.editor .block-content code {
    font-family: var(--font-mono);
    font-size: 0.85em;
    background: var(--code-bg);
    color: var(--code-color);
    padding: 0.1em 0.35em;
    border-radius: 2px;
}
.editor .block-content del { opacity: 0.5; text-decoration: line-through; }
.editor .block-content mark {
    background: var(--highlight-bg);
    color: var(--highlight-text);
    padding: 0.05em 0.2em;
    border-radius: 2px;
}

/* Wiki links and external links inside editor */
.editor .block-content a.wiki-link {
    color: var(--link);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.1s, color 0.1s;
    cursor: pointer;
}
.editor .block-content a.wiki-link:hover {
    color: var(--link-hover);
    border-bottom-color: var(--link-hover);
}

.editor .block-content a.external-link {
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 1px dashed var(--text-faint);
    transition: color 0.1s, border-color 0.1s;
}
.editor .block-content a.external-link:hover {
    color: var(--text);
    border-bottom-color: var(--text);
}

/* ── Block-level styling (headings, blockquotes) via decorations ── */
.editor .block.block-heading {
    margin-top: 0.6rem;
    padding-bottom: 0.1rem;
}
.editor .ProseMirror > .block.block-heading:first-child {
    margin-top: 0;
}
.editor .block.block-heading .block-content {
    font-family: var(--font-body);
    font-weight: 600;
    color: var(--text-strong);
    line-height: 1.3;
}
.editor .block.block-h2 { margin-top: 1rem; }
.editor .block.block-h2 .block-content { font-size: 1.4rem; }
.editor .block.block-h3 { margin-top: 0.75rem; }
.editor .block.block-h3 .block-content { font-size: 1.2rem; }
.editor .block.block-h4 .block-content { font-size: 1.05rem; letter-spacing: 0.01em; }

.editor .block.block-blockquote .block-content {
    border-left: 3px solid var(--border-strong);
    padding-left: 0.85rem;
    color: var(--text-muted);
    font-style: italic;
}

/* Dim the prefix characters (# , ## , > ) so they fade into the background */
.editor .block-prefix {
    font-size: 0.6em;
    color: var(--text-faint);
    font-weight: 400;
    letter-spacing: -0.02em;
    vertical-align: middle;
    user-select: text;
}

/* ─── Merge dialog ─────────────────────────────────────────────── */
.merge-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
}

.merge-dialog {
    background: var(--sidebar-bg);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    padding: 1.5rem 1.75rem;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

.merge-dialog-title {
    font-family: var(--font-body);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-strong);
    margin-bottom: 0.65rem;
}

.merge-dialog-text {
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.55;
    margin-bottom: 1.25rem;
}
.merge-dialog-text strong {
    color: var(--text);
}

.merge-dialog-actions {
    display: flex;
    gap: 0.65rem;
    justify-content: flex-end;
}

.merge-btn {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    border: none;
    border-radius: var(--radius);
    padding: 0.45rem 1rem;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.merge-btn--confirm {
    background: var(--primary);
    color: #fff;
}
.merge-btn--confirm:hover {
    background: var(--primary-hover);
}
.merge-btn--cancel {
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.merge-btn--cancel:hover {
    color: var(--text);
    background: var(--surface-hover);
}

/* ─── Context menu ─────────────────────────────────────────────── */
.ctx-menu {
    position: fixed;
    z-index: 9000;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    box-shadow: var(--shadow-dropdown);
    min-width: 220px;
    padding: 0.3rem 0;
    font-family: var(--font-body);
    font-size: 0.82rem;
}

.ctx-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0.85rem;
    color: var(--text);
    cursor: pointer;
    transition: background 0.08s;
    user-select: none;
}
.ctx-item:hover {
    background: var(--surface-hover);
}
.ctx-item--danger:hover {
    background: hsla(4, 75%, 55%, 0.12);
    color: var(--red-400);
}

.ctx-hint {
    font-size: 0.7rem;
    color: var(--text-faint);
    margin-left: 1.5rem;
}

.ctx-separator {
    height: 1px;
    background: var(--border);
    margin: 0.25rem 0;
}

.ctx-submenu {
    position: relative;
}
.ctx-submenu-arrow::after {
    content: '▸';
    font-size: 0.65rem;
    color: var(--text-faint);
    margin-left: 0.5rem;
}

/* ─── View as Document mode ────────────────────────────────────── */
.page.view-document .block-bullet {
    visibility: hidden;
    width: 0;
    padding: 0;
    margin: 0;
}

.page.view-document .block-drag-handle {
    display: none;
}

.page.view-document .block {
    padding-left: 0;
}

.page.view-document .block:hover {
    background: transparent;
}

.page.view-document .block-content {
    padding-left: 0;
}

/* Collapse carets hidden in doc mode */
.page.view-document .block-caret {
    display: none;
}
