:root,
html[data-theme="blue"] {
    --bg: #0b1020;
    --bg-elevated: #141b2f;
    --bg-input: #0f1528;
    --bg-nav: rgba(11, 16, 32, 0.94);
    --bg-panel: rgba(20, 27, 47, 0.85);
    --bg-group: rgba(20, 27, 47, 0.72);
    --bg-group-folders: rgba(18, 24, 40, 0.9);
    --bg-code: #0a0e1a;
    --code-text: #d7e3ff;
    --border: rgba(255, 255, 255, 0.1);
    --border-folder: rgba(255, 255, 255, 0.1);
    --text: #e8eefc;
    --text-muted: #9aa8c7;
    --accent: #5b9fff;
    --accent-press: #3d82e8;
    --accent-soft: rgba(91, 159, 255, 0.1);
    --accent-soft-strong: rgba(91, 159, 255, 0.12);
    --accent-border: rgba(91, 159, 255, 0.45);
    --accent-inset: rgba(91, 159, 255, 0.12);
    --accent-row: rgba(91, 159, 255, 0.22);
    --btn-on-accent: #061018;
    --danger: #ff7b7b;
    --ok: #6ddea8;
    --warn: #f0c674;
    --glow-a: rgba(91, 159, 255, 0.18);
    --glow-b: rgba(109, 222, 168, 0.08);
    --nav-chip: rgba(255, 255, 255, 0.05);
    --preview-wash-a: rgba(20, 27, 47, 0.92);
    --preview-wash-b: rgba(15, 21, 40, 0.96);
    --edit-btn-bg: rgba(20, 27, 47, 0.65);
    --hairline: rgba(255, 255, 255, 0.06);
    --radius: 12px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --font: "Outfit", system-ui, sans-serif;
    --mono: "IBM Plex Mono", ui-monospace, monospace;
    color-scheme: dark;
}

html[data-theme="oled"] {
    --bg: #000000;
    --bg-elevated: #0a0a0a;
    --bg-input: #050505;
    --bg-nav: rgba(0, 0, 0, 0.96);
    --bg-panel: rgba(12, 12, 12, 0.96);
    --bg-group: rgba(14, 14, 14, 0.95);
    --bg-group-folders: rgba(10, 10, 10, 0.98);
    --bg-code: #000000;
    --code-text: #e6e6e6;
    --border: rgba(255, 255, 255, 0.12);
    --border-folder: rgba(255, 255, 255, 0.1);
    --text: #f2f2f2;
    --text-muted: #9a9a9a;
    --accent: #6aa8ff;
    --accent-press: #4d8ef0;
    --accent-soft: rgba(106, 168, 255, 0.12);
    --accent-soft-strong: rgba(106, 168, 255, 0.14);
    --accent-border: rgba(106, 168, 255, 0.4);
    --accent-inset: rgba(106, 168, 255, 0.1);
    --accent-row: rgba(106, 168, 255, 0.2);
    --btn-on-accent: #000000;
    --danger: #ff8a8a;
    --ok: #6ddea8;
    --warn: #f0c674;
    --glow-a: transparent;
    --glow-b: transparent;
    --nav-chip: rgba(255, 255, 255, 0.04);
    --preview-wash-a: rgba(8, 8, 8, 0.98);
    --preview-wash-b: rgba(0, 0, 0, 1);
    --edit-btn-bg: rgba(20, 20, 20, 0.9);
    --hairline: rgba(255, 255, 255, 0.08);
    color-scheme: dark;
}

html[data-theme="light"] {
    --bg: #e8ecf4;
    --bg-elevated: #ffffff;
    --bg-input: #f7f9fc;
    --bg-nav: rgba(255, 255, 255, 0.94);
    --bg-panel: rgba(255, 255, 255, 0.92);
    --bg-group: rgba(255, 255, 255, 0.88);
    --bg-group-folders: rgba(246, 248, 252, 0.96);
    --bg-code: #e8ecf2;
    --code-text: #152033;
    --border: rgba(20, 32, 56, 0.12);
    --border-folder: rgba(20, 32, 56, 0.1);
    --text: #152033;
    --text-muted: #5c6b86;
    --accent: #2f6fdb;
    --accent-press: #245bb8;
    --accent-soft: rgba(47, 111, 219, 0.1);
    --accent-soft-strong: rgba(47, 111, 219, 0.12);
    --accent-border: rgba(47, 111, 219, 0.35);
    --accent-inset: rgba(47, 111, 219, 0.1);
    --accent-row: rgba(47, 111, 219, 0.16);
    --btn-on-accent: #ffffff;
    --danger: #d64545;
    --ok: #1f9d66;
    --warn: #b7791f;
    --glow-a: rgba(47, 111, 219, 0.12);
    --glow-b: rgba(31, 157, 102, 0.06);
    --nav-chip: rgba(20, 32, 56, 0.04);
    --preview-wash-a: rgba(255, 255, 255, 0.96);
    --preview-wash-b: rgba(247, 249, 252, 0.98);
    --edit-btn-bg: rgba(247, 249, 252, 0.95);
    --hairline: rgba(20, 32, 56, 0.08);
    color-scheme: light;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    background:
        radial-gradient(1200px 600px at 10% -10%, var(--glow-a), transparent 60%),
        radial-gradient(900px 500px at 100% 0%, var(--glow-b), transparent 55%),
        var(--bg);
    color: var(--text);
    font-family: var(--font);
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100dvh;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.app {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    height: 100dvh;
    max-width: 720px;
    margin: 0 auto;
    padding: calc(12px + var(--safe-top)) 14px 0;
    /* Leave room for fixed bottom nav (+ mobile path dock) */
    padding-bottom: calc(var(--nav-offset, 88px) + var(--path-dock-offset, 0px) + 12px);
    overflow: hidden;
}

.context-strip {
    margin-bottom: 10px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.context-strip-main {
    min-width: 0;
}

.view-title {
    margin: 0 0 4px;
    font-size: 1.05rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.01em;
}

.view-title--doc {
    font-size: clamp(1.2rem, 4.2vw, 1.55rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.2;
    color: var(--text);
    max-width: 100%;
}

.loading-file-name {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 650;
    letter-spacing: -0.02em;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.status {
    margin: 0;
    min-height: 1.25rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.status.is-error {
    color: var(--danger);
}

.status.is-ok {
    color: var(--ok);
}

.status.is-warn {
    color: var(--warn);
}

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* ——— Nav bar: bottom tabs on mobile, top on desktop ——— */
.nav-bar {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 0;
    top: auto;
    z-index: 30;
    width: 100%;
    max-width: 720px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px 12px calc(8px + var(--safe-bottom));
    background: var(--bg-nav);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.nav-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px;
    border-radius: 14px;
    background: var(--nav-chip);
    border: 1px solid var(--border);
}

.nav-actions-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-actions-editor {
    flex-direction: row;
    align-items: stretch;
    gap: 6px;
}

.nav-actions-editor .btn {
    flex: 1 1 0;
    min-width: 0;
    border-radius: 8px;
    min-height: 36px;
    padding: 0.35rem 0.45rem;
    font-size: 0.78rem;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-actions-editor .btn-save {
    flex: 1.65 1 0;
    min-height: 36px;
    font-size: 0.85rem;
    font-weight: 700;
    padding: 0.35rem 0.55rem;
}

.btn-save.is-flashing:not(:disabled) {
    animation: save-flash 1.1s ease-in-out infinite;
}

@keyframes save-flash {
    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(91, 159, 255, 0);
        filter: brightness(1);
    }
    50% {
        box-shadow: 0 0 0 4px rgba(91, 159, 255, 0.35);
        filter: brightness(1.12);
    }
}

html[data-theme="light"] .btn-save.is-flashing:not(:disabled) {
    animation-name: save-flash-light;
}

@keyframes save-flash-light {
    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(47, 111, 219, 0);
        filter: brightness(1);
    }
    50% {
        box-shadow: 0 0 0 4px rgba(47, 111, 219, 0.28);
        filter: brightness(1.06);
    }
}

@media (prefers-reduced-motion: reduce) {
    .btn-save.is-flashing:not(:disabled) {
        animation: none;
        box-shadow: 0 0 0 3px rgba(91, 159, 255, 0.4);
    }
}

.nav-bar-inner {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    padding: 4px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
}

.nav-tab {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--text-muted);
    border-radius: 10px;
    min-height: 48px;
    padding: 0.55rem 0.4rem;
    font: inherit;
    font-weight: 600;
    font-size: 0.92rem;
    cursor: pointer;
    touch-action: manipulation;
    transition: background 0.15s ease, color 0.15s ease;
}

.nav-tab-label {
    display: block;
}

.nav-tab.is-active {
    background: rgba(91, 159, 255, 0.22);
    color: var(--text);
    box-shadow: inset 0 0 0 1px rgba(91, 159, 255, 0.45);
}

.nav-tab:not(.is-active):active {
    background: rgba(255, 255, 255, 0.06);
}

.finder-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.finder-actions .create-actions {
    flex: 1 1 auto;
}

.finder-path-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    padding: 6px 8px 6px 6px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg-panel);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02);
}

/* Mobile: dock path + Up above the bottom nav for easier reach */
@media (max-width: 767.98px) {
    .finder-path-bar:not([hidden]) {
        position: fixed;
        left: 50%;
        transform: translateX(-50%);
        z-index: 29;
        width: calc(100% - 28px);
        max-width: 692px;
        bottom: calc(var(--nav-offset, 88px) + 6px);
        margin: 0;
        background: var(--bg-nav);
        backdrop-filter: blur(14px);
        -webkit-backdrop-filter: blur(14px);
        box-shadow:
            0 -8px 28px rgba(0, 0, 0, 0.28),
            inset 0 0 0 1px rgba(255, 255, 255, 0.04);
    }
}

.finder-up-btn {
    flex: 0 0 auto;
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-input);
    color: var(--text);
    cursor: pointer;
    touch-action: manipulation;
}

.finder-up-btn:not(:disabled):active {
    transform: scale(0.96);
}

.finder-up-btn:not(:disabled):hover,
.finder-up-btn:not(:disabled):focus-visible {
    color: var(--accent);
    border-color: var(--accent-border);
}

.finder-up-icon {
    width: 18px;
    height: 18px;
    display: block;
    background: currentColor;
    -webkit-mask: url('./Assets/SVGs/Up-ArrowIcons.svg') center / contain no-repeat;
    mask: url('./Assets/SVGs/Up-ArrowIcons.svg') center / contain no-repeat;
}

.folder-path {
    flex: 1;
    min-width: 0;
    margin: 0;
    color: var(--text-muted);
    font-size: 0.88rem;
    line-height: 1.35;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.folder-path::-webkit-scrollbar {
    display: none;
}

.folder-path--crumbs {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 4px 6px;
    white-space: nowrap;
}

.folder-path--plain {
    padding: 0 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.folder-path-crumb {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--accent);
    font: inherit;
    font-size: inherit;
    font-weight: 600;
    padding: 6px 4px;
    min-height: 32px;
    cursor: pointer;
    border-radius: 8px;
}

.folder-path-crumb:hover,
.folder-path-crumb:focus-visible {
    background: var(--accent-soft);
}

.folder-path-sep {
    color: var(--text-muted);
    opacity: 0.55;
    flex: 0 0 auto;
}

.folder-path-current {
    color: var(--text);
    font-weight: 700;
    padding: 6px 4px;
}

@media (min-width: 768px) {
    .app {
        padding: calc(16px + var(--safe-top)) 18px calc(20px + var(--safe-bottom));
        gap: 0;
        --path-dock-offset: 0px;
    }

    .nav-bar {
        position: sticky;
        top: 0;
        bottom: auto;
        transform: none;
        left: auto;
        order: -1;
        margin: 0 0 12px;
        padding: 0;
        background: transparent;
        border: 0;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        gap: 10px;
        /* Tabs first at top; action strip sits under the mode tabs */
        flex-direction: column-reverse;
    }

    .nav-actions {
        background: var(--bg-panel);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
    }

    .nav-bar-inner {
        padding: 6px;
        background: var(--bg-panel);
        border: 1px solid var(--border);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
    }
}

.view {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.view[hidden],
[hidden] {
    display: none !important;
}

.empty-panel {
    margin: auto 0;
    padding: 28px 20px;
    text-align: center;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) + 4px);
    background: var(--bg-panel);
}

.empty-panel-title {
    margin: 0 0 8px;
    font-size: 1.2rem;
    font-weight: 650;
}

.empty-panel-copy {
    margin: 0 0 18px;
    color: var(--text-muted);
    line-height: 1.45;
}

.editor-loading {
    margin: auto 0;
    padding: 36px 24px;
    text-align: center;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) + 4px);
    background: var(--bg-panel);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 3px solid rgba(91, 159, 255, 0.2);
    border-top-color: var(--accent);
    animation: loading-spin 0.8s linear infinite;
}

.loading-title {
    margin: 6px 0 0;
    font-size: 1.1rem;
    font-weight: 650;
}

.loading-bar {
    margin-top: 10px;
    width: min(100%, 260px);
    height: 6px;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(91, 159, 255, 0.15);
}

.loading-bar-fill {
    width: 40%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    animation: loading-bar-slide 1.1s ease-in-out infinite;
}

@keyframes loading-spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes loading-bar-slide {
    0% {
        transform: translateX(-120%);
    }
    100% {
        transform: translateX(320%);
    }
}

.editor-active {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
}

.view-settings {
    justify-content: flex-start;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.settings-card {
    padding: 22px 18px;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) + 4px);
    background: var(--bg-panel);
}

.settings-heading {
    margin: 0 0 6px;
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.settings-lede {
    margin: 0 0 20px;
    color: var(--text-muted);
    line-height: 1.45;
}

.settings-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 18px;
}

.settings-prefs {
    margin: 4px 0 18px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.settings-subheading {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 650;
}

.settings-prefs-lede {
    margin: 0;
    font-size: 0.85rem;
    line-height: 1.4;
    color: var(--text-muted);
}

.settings-prefs-lede--tight {
    margin-top: -4px;
}

.settings-pref {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.settings-pref--toggle {
    min-height: 44px;
}

.settings-pref-label {
    font-size: 0.92rem;
    font-weight: 550;
}

.settings-toggle {
    width: 1.25rem;
    height: 1.25rem;
    accent-color: var(--accent);
    flex: 0 0 auto;
}

.settings-select {
    min-width: 11.5rem;
    max-width: 60%;
    height: 40px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text);
    padding: 0 10px;
    font: inherit;
    font-size: 0.9rem;
}

.settings-hint {
    margin-top: 4px;
}

.btn {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text);
    border-radius: 999px;
    padding: 0.7rem 1rem;
    font: inherit;
    font-weight: 600;
    font-size: 0.95rem;
    min-height: 44px;
    cursor: pointer;
    touch-action: manipulation;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    border-color: transparent;
    color: var(--btn-on-accent);
}

.btn-primary:not(:disabled):active {
    background: var(--accent-press);
}

.btn-ghost {
    background: transparent;
}

.btn-danger {
    background: var(--danger);
    border-color: transparent;
    color: #1a0a0a;
}

.btn-danger:not(:disabled):active {
    filter: brightness(0.92);
}

html[data-theme="light"] .btn-danger {
    color: #fff;
}

.btn-large {
    width: 100%;
    min-height: 52px;
    font-size: 1.05rem;
}

.btn-block {
    width: 100%;
    margin-top: 10px;
}

.login-card {
    margin: auto 0;
    padding: 28px 20px;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) + 4px);
    background: var(--bg-panel);
    backdrop-filter: blur(10px);
}

.brand {
    margin: 0 0 8px;
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.lede {
    margin: 0 0 22px;
    color: var(--text-muted);
    line-height: 1.45;
}

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

.error-text {
    margin: 14px 0 0;
    color: var(--danger);
    font-size: 0.9rem;
}

.settings-tips {
    margin: 16px 0 0;
    padding-left: 1.1rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    line-height: 1.45;
}

.settings-tips kbd {
    font-family: var(--mono);
    font-size: 0.8em;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0 4px;
    background: rgba(255, 255, 255, 0.04);
}

.nav-tab.has-dirty .nav-tab-label {
    color: var(--warn);
}

.create-actions {
    display: flex;
    gap: 8px;
    margin: 0;
}

.create-actions .btn {
    flex: 1;
}

.browse-mode-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn-mode {
    flex: 1 1 auto;
    min-width: 30%;
    border-radius: 999px;
}

.browse-hint a {
    color: var(--accent);
}

.btn-mode.is-active {
    background: rgba(91, 159, 255, 0.2);
    border-color: rgba(91, 159, 255, 0.55);
    color: var(--text);
}

.search-form {
    display: flex;
    gap: 8px;
}

.search-input {
    flex: 1;
    min-height: 44px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text);
    padding: 0 14px;
    font: inherit;
    font-size: 16px;
}

.browse-hint {
    margin: 0;
    font-size: 0.8rem;
    line-height: 1.4;
    color: var(--text-muted);
}

.file-list {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
}

/* Mobile defaults / prefs: markdown section order relative to folders */
.file-list[data-md-mobile="bottom"] .file-group--folders {
    order: 1;
}

.file-list[data-md-mobile="bottom"] .file-group--markdown {
    order: 2;
}

.file-list[data-md-mobile="top"] .file-group--folders {
    order: 2;
}

.file-list[data-md-mobile="top"] .file-group--markdown {
    order: 1;
}

.file-group--recent {
    order: -1;
    background: rgba(109, 222, 168, 0.08);
    border-color: rgba(109, 222, 168, 0.4);
    box-shadow: inset 0 0 0 1px rgba(109, 222, 168, 0.1);
}

html[data-theme="light"] .file-group--recent {
    background: rgba(31, 157, 102, 0.08);
    border-color: rgba(31, 157, 102, 0.28);
    box-shadow: inset 0 0 0 1px rgba(31, 157, 102, 0.08);
}

html[data-theme="oled"] .file-group--recent {
    background: rgba(109, 222, 168, 0.1);
    border-color: rgba(109, 222, 168, 0.35);
}

.file-group--recent .file-group-title {
    color: var(--ok);
}

.file-group--recent .file-group-list > .file-row:nth-child(n + 4) {
    display: none;
}

@media (min-width: 768px) {
    .file-list[data-md-desktop="bottom"] .file-group--folders {
        order: 1;
    }

    .file-list[data-md-desktop="bottom"] .file-group--markdown {
        order: 2;
    }

    .file-list[data-md-desktop="top"] .file-group--folders {
        order: 2;
    }

    .file-list[data-md-desktop="top"] .file-group--markdown {
        order: 1;
    }

    .file-group--recent {
        order: -1;
    }

    .file-group--recent .file-group-list > .file-row:nth-child(n + 4) {
        display: flex;
    }

    .file-group--recent .file-group-list > .file-row:nth-child(n + 6) {
        display: none;
    }
}

.file-group {
    flex-shrink: 0;
    border-radius: calc(var(--radius) + 4px);
    border: 1px solid var(--border);
    overflow: hidden;
    background: var(--bg-group);
}

.file-group--folders {
    background: var(--bg-group-folders);
    border-color: var(--border-folder);
}

.file-group--markdown {
    background: var(--accent-soft);
    border-color: var(--accent-border);
    box-shadow: inset 0 0 0 1px var(--accent-inset);
}

.file-group-title {
    margin: 0;
    padding: 10px 14px 8px;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.file-group--markdown .file-group-title {
    color: var(--accent);
}

.file-group-list {
    display: flex;
    flex-direction: column;
}

.file-row {
    display: flex;
    align-items: stretch;
    gap: 8px;
    width: 100%;
    border: 0;
    background: transparent;
    color: inherit;
    border-radius: 0;
    min-height: 52px;
    overflow: hidden;
}

.file-group-list .file-row + .file-row {
    border-top: 1px solid var(--border);
}

.file-group--folders .file-group-list .file-row + .file-row {
    border-top-color: var(--hairline);
}

.file-group--markdown .file-group-list .file-row + .file-row {
    border-top-color: var(--accent-row);
}

.file-row-main {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    border: 0;
    background: transparent;
    color: inherit;
    padding: 14px 8px 14px 14px;
    font: inherit;
    cursor: pointer;
    touch-action: manipulation;
}

.file-row-menu {
    flex: 0 0 auto;
    align-self: center;
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    margin-right: 10px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--edit-btn-bg);
    color: var(--text-muted);
    cursor: pointer;
    touch-action: manipulation;
}

.file-row-menu:hover,
.file-row-menu:focus-visible {
    color: var(--accent);
    border-color: var(--accent-border);
}

.file-row-menu:active {
    transform: scale(0.96);
}

.file-row--folder {
    border-color: transparent;
    background: transparent;
}

.file-row--markdown {
    border: 0;
    background: transparent;
    box-shadow: none;
}

.file-row--markdown .file-row-name {
    font-weight: 600;
}

.file-row-main:active {
    background: rgba(255, 255, 255, 0.04);
}

.file-group--markdown .file-row-main:active {
    background: rgba(91, 159, 255, 0.14);
}

.btn-small {
    min-height: 32px;
    padding: 0.25rem 0.7rem;
    font-size: 0.8rem;
    line-height: 1.2;
    border-radius: 6px;
    white-space: nowrap;
    flex-shrink: 0;
}

.dialog-hint {
    margin: 0 0 12px !important;
    font-size: 0.9rem;
}

.name-input {
    width: 100%;
    min-height: 48px;
    margin: 0 0 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text);
    padding: 0 14px;
    font: inherit;
    font-size: 16px;
}

.name-input:focus {
    outline: none;
    border-color: rgba(91, 159, 255, 0.55);
}

.file-row-icon {
    flex: 0 0 auto;
    width: 2rem;
    height: 2rem;
    display: grid;
    place-items: center;
}

.file-row-icon img {
    width: 28px;
    height: 28px;
    object-fit: contain;
    display: block;
}

.file-row--folder .file-row-icon img {
    filter: invert(0.88) brightness(0.95);
    opacity: 0.9;
}

.file-row--markdown .file-row-icon img {
    filter: invert(58%) sepia(55%) saturate(1200%) hue-rotate(185deg) brightness(1.05);
}

html[data-theme="light"] .file-row--folder .file-row-icon img,
html[data-theme="light"] .move-folder-list .file-row-icon img {
    filter: none;
    opacity: 0.92;
}

html[data-theme="light"] .file-row--markdown .file-row-icon img {
    /* Dark blue so markdown icons read clearly on light surfaces */
    filter: invert(28%) sepia(70%) saturate(1400%) hue-rotate(200deg) brightness(0.85);
    opacity: 1;
}

.file-row-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

.empty-state {
    margin: 24px 0;
    text-align: center;
    color: var(--text-muted);
}

.view-editor {
    gap: 8px;
}

.editor-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 36px;
}

.editor-meta-main {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.editor-search-toggle {
    flex: 0 0 auto;
    min-height: 36px;
    padding: 0 12px;
}

.editor-search-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-elevated);
}

.editor-search-bar[hidden] {
    display: none !important;
}

.editor-search-input {
    flex: 1 1 12rem;
    min-width: 0;
    min-height: 40px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-input);
    color: var(--text);
    padding: 0 12px;
    font: inherit;
    font-size: 0.95rem;
    outline: none;
}

.editor-search-input:focus {
    border-color: var(--accent-border);
}

.editor-search-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

.editor-search-count {
    min-width: 4.5rem;
    text-align: right;
    font-size: 0.78rem;
    font-weight: 650;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.editor-search-count[data-empty="true"] {
    color: var(--warn);
}

.editor-search-opt {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    min-width: 36px;
    min-height: 36px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    user-select: none;
}

.editor-search-opt input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.editor-search-opt:has(input:checked),
.editor-search-opt.is-active {
    border-color: var(--accent-border);
    background: var(--accent-soft);
    color: var(--accent);
}

.editor-search-opt:has(input:focus-visible) {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.editor-search-nav,
.editor-search-close {
    min-width: 36px;
    min-height: 36px;
    padding: 0;
}

.dirty-label {
    margin: 0;
    color: var(--warn);
    font-size: 0.85rem;
    font-weight: 600;
    flex-shrink: 0;
}

.editor {
    flex: 1;
    width: 100%;
    min-height: 0;
    resize: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text);
    padding: 14px;
    font-family: var(--mono);
    font-size: 16px;
    line-height: 1.5;
    outline: none;
}

.editor:focus {
    border-color: rgba(91, 159, 255, 0.55);
}

.editor::selection {
    background: rgba(255, 186, 73, 0.55);
    color: inherit;
}

/* Find highlights in Preview / List */
mark.search-hit {
    background: rgba(255, 214, 10, 0.42);
    color: inherit;
    border-radius: 3px;
    padding: 0 0.06em;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

mark.search-hit--current {
    background: rgba(255, 153, 0, 0.72);
    box-shadow: 0 0 0 1px rgba(255, 140, 0, 0.85);
}

html[data-theme="light"] mark.search-hit {
    background: rgba(255, 196, 0, 0.45);
}

html[data-theme="light"] mark.search-hit--current {
    background: rgba(255, 152, 0, 0.7);
    box-shadow: 0 0 0 1px rgba(210, 110, 0, 0.75);
}

html[data-theme="light"] .editor::selection {
    background: rgba(255, 186, 73, 0.65);
}

.view-mode-bar {
    position: sticky;
    top: 0;
    z-index: 6;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    padding: 4px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg);
    box-shadow: 0 10px 18px -14px rgba(0, 0, 0, 0.55);
    flex: 0 0 auto;
}

.view-mode-btn {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--text-muted);
    border-radius: 6px;
    min-height: 34px;
    font: inherit;
    font-weight: 600;
    font-size: 0.8rem;
    line-height: 1.2;
    cursor: pointer;
    touch-action: manipulation;
    padding: 0 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.view-mode-btn.is-active {
    background: rgba(91, 159, 255, 0.22);
    color: var(--text);
    box-shadow: inset 0 0 0 1px rgba(91, 159, 255, 0.45);
}

.lists-status {
    margin: 0;
    font-size: 0.85rem;
    color: var(--warn);
}

.lists-status.is-error {
    color: var(--danger);
}

.lists-root {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
}

.lists-root--placing .md-preview--placing > [data-md-line] {
    cursor: pointer;
    border-radius: 8px;
    transition: background-color 0.12s ease, box-shadow 0.12s ease;
}

.lists-root--placing .md-preview--placing > [data-md-line]:hover {
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 1px var(--accent-border);
}

.lists-root--click-edit .md-preview--click-edit > [data-md-line] {
    cursor: text;
    border-radius: 8px;
    transition: background-color 0.12s ease, box-shadow 0.12s ease;
}

.lists-root--click-edit .md-preview--click-edit > [data-md-line]:hover {
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 1px var(--accent-border);
}

.lists-root--click-edit .mdlist-stack--click-edit {
    cursor: text;
}

.lists-root--click-edit .mdlist-stack--click-edit:hover .mdlist-block {
    box-shadow: inset 0 0 0 1px var(--accent-border);
}

.btn-click-edit--active,
.btn-insert-list--cancel {
    background: rgba(91, 159, 255, 0.18);
    border-color: rgba(91, 159, 255, 0.55);
    color: var(--text);
}

.lists-root--placing .mdlist-stack--placing {
    cursor: pointer;
}

.lists-root--placing .mdlist-stack--placing .mdlist-block,
.lists-root--placing .mdlist-stack--placing .mdlist-agent-note {
    pointer-events: none;
}

.lists-root--placing .mdlist-stack--placing:hover .mdlist-block {
    box-shadow: inset 0 0 0 1px var(--accent-border);
}

.is-place-target {
    background: var(--accent-soft) !important;
    box-shadow: inset 0 0 0 2px var(--accent) !important;
    border-radius: 8px;
}

.list-place-picker {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 4px 0 10px;
    padding: 10px 12px;
    border: 1px solid var(--accent-border);
    border-radius: var(--radius);
    background: var(--bg-elevated);
}

.list-place-picker-label {
    margin: 0;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text);
}

.list-place-picker-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.list-place-empty {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-panel);
}

.list-place-empty p {
    margin: 0;
    color: var(--text-muted);
    line-height: 1.4;
}

.lists-warning,
.lists-empty-hint {
    margin: 0;
    color: var(--warn);
    font-size: 0.9rem;
    line-height: 1.4;
}

.preview-toc-mount {
    position: relative;
    z-index: 1;
}

.preview-toc-mount--sticky {
    position: sticky;
    top: 0;
    z-index: 3;
}

.preview-toc {
    margin: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-elevated);
    overflow: hidden;
}

.preview-toc-summary {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 8px 12px;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

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

.preview-toc-summary::before {
    content: '';
    width: 0.45em;
    height: 0.45em;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(-45deg);
    flex: 0 0 auto;
    opacity: 0.7;
    transition: transform 0.15s ease;
}

.preview-toc[open] .preview-toc-summary::before {
    transform: rotate(45deg);
}

.preview-toc-title {
    font-weight: 700;
    font-size: 0.92rem;
    color: var(--text);
}

.preview-toc-meta {
    font-size: 0.75rem;
    font-weight: 650;
    color: var(--text-muted);
}

.preview-toc-hint {
    margin-left: auto;
    font-size: 0.72rem;
    font-weight: 650;
    color: var(--accent);
}

.preview-toc-nav {
    border-top: 1px solid var(--border);
    max-height: min(40vh, 18rem);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 6px 0 8px;
}

.preview-toc-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.preview-toc-item {
    margin: 0;
}

.preview-toc-link {
    display: block;
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 0.9rem;
    line-height: 1.35;
    padding: 8px 12px 8px calc(12px + (var(--toc-level, 0) * 0.85rem));
    cursor: pointer;
    overflow-wrap: anywhere;
}

.preview-toc-link:hover,
.preview-toc-link:focus-visible {
    background: var(--accent-soft);
    color: var(--accent);
    outline: none;
}

.preview-toc-link--list {
    color: var(--accent);
    font-weight: 650;
}

.toc-flash {
    animation: toc-flash-pulse 1.25s ease;
}

@keyframes toc-flash-pulse {
    0% {
        box-shadow: inset 0 0 0 0 transparent;
        background-color: transparent;
    }
    20% {
        box-shadow: inset 0 0 0 2px var(--accent);
        background-color: var(--accent-soft);
    }
    100% {
        box-shadow: inset 0 0 0 0 transparent;
        background-color: transparent;
    }
}

.md-preview > h1.toc-flash,
.md-preview > h2.toc-flash,
.md-preview > h3.toc-flash,
.md-preview > h4.toc-flash,
.md-preview > h5.toc-flash,
.md-preview > h6.toc-flash,
.mdlist-stack.toc-flash .mdlist-block {
    border-radius: 8px;
}

.lists-empty {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-panel);
}

.mdlist-stack {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.mdlist-agent-note {
    margin: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-panel);
    color: var(--text-muted);
    font-size: 0.72rem;
    line-height: 1.35;
}

.mdlist-agent-note-summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    font-weight: 650;
    letter-spacing: 0.02em;
    user-select: none;
}

.mdlist-agent-note-summary::-webkit-details-marker {
    display: none;
}

.mdlist-agent-note-summary::before {
    content: '';
    width: 0.45em;
    height: 0.45em;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(-45deg);
    flex: 0 0 auto;
    opacity: 0.75;
    transition: transform 0.15s ease;
}

.mdlist-agent-note[open] .mdlist-agent-note-summary::before {
    transform: rotate(45deg);
}

.mdlist-agent-note-summary:hover,
.mdlist-agent-note-summary:focus-visible {
    color: var(--text);
}

.mdlist-agent-note-body {
    margin: 0;
    padding: 0 10px 8px;
    max-width: 72ch;
}

.mdlist-block {
    border: 1px solid rgba(91, 159, 255, 0.35);
    border-radius: var(--radius);
    background: var(--accent-soft);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Keep Done / + Item chrome visible; only the item list scrolls. */
.mdlist-block--editing {
    max-height: calc(
        100dvh - var(--safe-top) - var(--nav-offset, 88px) - var(--path-dock-offset, 0px) - 10.5rem
    );
    min-height: 0;
}

.mdlist-block--editing > .mdlist-header {
    flex: 0 0 auto;
    position: sticky;
    top: 0;
    z-index: 3;
    margin: -12px -12px 0;
    padding: 12px 12px 8px;
    background: linear-gradient(var(--accent-soft), var(--accent-soft)), var(--bg-elevated);
    border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: 0 1px 0 var(--hairline);
}

.mdlist-block--editing > .mdlist-filter-note {
    flex: 0 0 auto;
}

.mdlist-block--editing > .mdlist-items {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.mdlist-block--editing > .mdlist-actions {
    flex: 0 0 auto;
    position: sticky;
    bottom: 0;
    z-index: 3;
    margin: 0 -12px -12px;
    padding: 8px 12px 12px;
    background: linear-gradient(var(--accent-soft), var(--accent-soft)), var(--bg-elevated);
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: 0 -1px 0 var(--hairline);
}

.mdlist-header {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mdlist-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.mdlist-title-row .btn {
    flex-shrink: 0;
    border-radius: 6px;
    min-height: 32px;
    padding: 0.25rem 0.7rem;
    white-space: nowrap;
}

.mdlist-title-input {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text);
    font: inherit;
    font-size: 1.05rem;
    font-weight: 700;
    padding: 0 12px;
}

.mdlist-count {
    flex: 0 0 auto;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
}

.mdlist-filter {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 8px;
}

.mdlist-filter-note {
    margin: 0;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.mdlist-rank {
    flex: 0 0 auto;
    align-self: center;
    min-width: 2rem;
    text-align: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--accent);
}

.mdlist-title {
    margin: 0;
    flex: 1;
    min-width: 0;
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.mdlist-edit-btn {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--edit-btn-bg);
    color: var(--text-muted);
    cursor: pointer;
    touch-action: manipulation;
}

.mdlist-edit-btn:hover,
.mdlist-edit-btn:focus-visible {
    color: var(--accent);
    border-color: var(--accent-border);
}

.mdlist-edit-btn:active {
    transform: scale(0.96);
}

.mdlist-block--view {
    gap: 8px;
}

.mdlist-items--view {
    gap: 0;
}

.mdlist-view-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 4px;
    border-top: 1px solid var(--hairline);
}

.mdlist-view-item:first-child {
    border-top: 0;
    padding-top: 2px;
}

.mdlist-view-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.mdlist-view-text {
    font-size: 1rem;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.mdlist-view-tags {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.3;
}

.mdlist-filter-label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.mdlist-filter-select {
    min-height: 44px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text);
    font: inherit;
    font-size: 16px;
    padding: 0 10px;
}

.mdlist-items {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.mdlist-empty-item {
    color: var(--text-muted);
    font-size: 0.9rem;
    padding: 8px 0;
}

.mdlist-item {
    display: flex;
    gap: 8px;
    align-items: stretch;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-elevated);
    padding: 8px;
    touch-action: manipulation;
}

.mdlist-item.is-dragging {
    opacity: 0.92;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    z-index: 5;
}

.mdlist-handle {
    flex: 0 0 auto;
    width: 44px;
    min-height: 44px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    cursor: grab;
    touch-action: none;
}

.mdlist-handle:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.mdlist-item-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mdlist-text,
.mdlist-score,
.mdlist-tags {
    width: 100%;
    min-height: 44px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text);
    font: inherit;
    font-size: 16px;
    padding: 0 12px;
    box-sizing: border-box;
}

.mdlist-text {
    display: block;
    resize: none;
    overflow: hidden;
    height: 44px;
    max-height: 44px;
    line-height: 1.35;
    padding-top: 10px;
    padding-bottom: 10px;
    white-space: pre-wrap;
    word-break: break-word;
}

.mdlist-text.is-expanded {
    overflow-y: auto;
    max-height: min(45vh, 20rem);
}

.mdlist-item-meta {
    display: grid;
    grid-template-columns: minmax(5rem, 7rem) 1fr;
    gap: 8px;
}

.mdlist-score-label,
.mdlist-tags-label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.mdlist-move {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.mdlist-move-btn {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--edit-btn-bg);
    color: var(--text-muted);
    cursor: pointer;
    touch-action: manipulation;
    flex-shrink: 0;
}

.mdlist-move-btn:hover:not(:disabled),
.mdlist-move-btn:focus-visible:not(:disabled) {
    color: var(--accent);
    border-color: var(--accent-border);
}

.mdlist-move-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.mdlist-arrow {
    width: 16px;
    height: 16px;
    display: block;
    background: currentColor;
}

.mdlist-arrow--up {
    -webkit-mask: url('./Assets/SVGs/Up-ArrowIcons.svg') center / contain no-repeat;
    mask: url('./Assets/SVGs/Up-ArrowIcons.svg') center / contain no-repeat;
}

.mdlist-arrow--down {
    -webkit-mask: url('./Assets/SVGs/Down-ArrowIcons.svg') center / contain no-repeat;
    mask: url('./Assets/SVGs/Down-ArrowIcons.svg') center / contain no-repeat;
}

.mdlist-delete {
    margin-left: auto;
    color: var(--danger);
    flex-shrink: 0;
    border-radius: 6px;
    min-height: 32px;
    padding: 0.25rem 0.7rem;
    white-space: nowrap;
}

.mdlist-delete-list {
    color: var(--danger);
    border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
}

.mdlist-delete-list:hover,
.mdlist-delete-list:focus-visible {
    background: color-mix(in srgb, var(--danger) 14%, transparent);
    border-color: var(--danger);
}

.mdlist-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.mdlist-actions .btn {
    flex-shrink: 0;
    border-radius: 6px;
    min-height: 32px;
    padding: 0.25rem 0.7rem;
    white-space: nowrap;
}

.mdlist-actions .mdlist-delete-list {
    margin-left: auto;
}

/* ——— Plain markdown lists (interactive in Preview) ——— */
.mdplain-block {
    border: 1px solid rgba(109, 222, 168, 0.28);
    border-radius: var(--radius);
    background: rgba(109, 222, 168, 0.06);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.mdplain-block--editing {
    max-height: calc(
        100dvh - var(--safe-top) - var(--nav-offset, 88px) - var(--path-dock-offset, 0px) - 10.5rem
    );
    min-height: 0;
}

.mdplain-block--editing > .mdplain-header {
    flex: 0 0 auto;
    position: sticky;
    top: 0;
    z-index: 3;
    margin: -12px -12px 0;
    padding: 12px 12px 8px;
    background: linear-gradient(rgba(109, 222, 168, 0.06), rgba(109, 222, 168, 0.06)), var(--bg-elevated);
    border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: 0 1px 0 var(--hairline);
}

.mdplain-block--editing > .mdplain-items,
.mdplain-block--editing > .mdlist-items {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.mdplain-block--editing > .mdlist-actions {
    flex: 0 0 auto;
    position: sticky;
    bottom: 0;
    z-index: 3;
    margin: 0 -12px -12px;
    padding: 8px 12px 12px;
    background: linear-gradient(rgba(109, 222, 168, 0.06), rgba(109, 222, 168, 0.06)), var(--bg-elevated);
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: 0 -1px 0 var(--hairline);
}

.mdplain-header {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.mdplain-title {
    margin: 0;
    flex: 1;
    min-width: 0;
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.3;
    color: var(--ok);
}

.mdplain-hint {
    margin: 0;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.mdplain-view-items {
    margin: 0;
    padding: 0 0 0 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.mdplain-view-items--task {
    list-style: none;
    padding-left: 0;
}

.mdplain-view-item {
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.mdplain-view-text {
    color: var(--text);
}

.mdplain-task-label {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    cursor: default;
}

.mdplain-task-label input {
    margin-top: 0.3em;
    flex: 0 0 auto;
}

.mdplain-check-row {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.mdplain-check {
    width: 18px;
    height: 18px;
}

.md-preview--prose-chunk {
    margin: 0;
}

.mixed-markdown-wrap > .mdplain-block {
    margin: 4px 0;
}

.mixed-markdown-wrap {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mixed-md-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.mixed-md-toolbar .btn {
    flex-shrink: 0;
    border-radius: 6px;
    min-height: 32px;
    padding: 0.25rem 0.7rem;
    white-space: nowrap;
}

.mixed-md-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.mixed-markdown-editor {
    width: 100%;
    min-height: 6rem;
    resize: vertical;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text);
    padding: 12px;
    font-family: var(--mono);
    font-size: 16px;
    line-height: 1.45;
}

.mixed-markdown--error {
    margin: 0;
    padding: 12px;
    border-radius: var(--radius);
    border: 1px solid rgba(255, 123, 123, 0.45);
    background: rgba(255, 123, 123, 0.08);
    color: var(--danger);
    white-space: pre-wrap;
    font-family: var(--mono);
    font-size: 0.85rem;
}

/* ——— Markdown preview ——— */
.md-preview {
    flex: 1;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 18px 16px 28px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background:
        linear-gradient(180deg, var(--preview-wash-a), var(--preview-wash-b)),
        var(--bg-elevated);
    color: var(--text);
    line-height: 1.65;
    font-size: 1.02rem;
}

.md-preview--segment {
    flex: 0 0 auto;
    overflow: visible;
    padding: 14px 14px 16px;
    background: var(--bg-panel);
}

.md-preview > *:first-child {
    margin-top: 0;
}

.md-preview > *:last-child {
    margin-bottom: 0;
}

.md-preview .md-empty {
    color: var(--text-muted);
    font-style: italic;
}

.md-preview h1,
.md-preview h2,
.md-preview h3,
.md-preview h4,
.md-preview h5,
.md-preview h6 {
    line-height: 1.25;
    letter-spacing: -0.02em;
    font-weight: 700;
    margin: 1.35em 0 0.55em;
}

.md-preview h1 {
    font-size: 1.85rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.35em;
}

.md-preview h2 {
    font-size: 1.45rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    padding-bottom: 0.3em;
}

.md-preview h3 { font-size: 1.2rem; }
.md-preview h4 { font-size: 1.08rem; }
.md-preview h5,
.md-preview h6 {
    font-size: 0.98rem;
    color: var(--text-muted);
}

.md-preview p {
    margin: 0.85em 0;
}

.md-preview a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.md-preview strong {
    font-weight: 700;
    color: var(--text);
}

.md-preview em {
    font-style: italic;
}

.md-preview del {
    color: var(--text-muted);
}

.md-preview code {
    font-family: var(--mono);
    font-size: 0.9em;
    background: var(--accent-soft-strong);
    border: 1px solid var(--accent-inset);
    border-radius: 6px;
    padding: 0.1em 0.35em;
    color: var(--text);
}

.md-preview pre.md-code {
    margin: 1em 0;
    padding: 14px 14px;
    overflow-x: auto;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-code);
    -webkit-overflow-scrolling: touch;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.md-preview pre.md-code code {
    background: transparent;
    border: 0;
    padding: 0;
    font-size: 0.88rem;
    line-height: 1.5;
    color: var(--code-text);
    white-space: inherit;
    overflow-wrap: inherit;
    word-break: inherit;
}

.md-preview pre.md-code--mdlist {
    border-color: var(--accent-border);
    background: var(--accent-soft);
}

.md-preview pre.md-code--mdlist::before {
    content: "mdlist";
    display: block;
    font-family: var(--font);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 8px;
}

.md-preview blockquote {
    margin: 1em 0;
    padding: 0.35em 0 0.35em 1em;
    border-left: 3px solid var(--accent);
    color: var(--text-muted);
    background: rgba(91, 159, 255, 0.06);
    border-radius: 0 10px 10px 0;
}

html[data-theme="light"] .md-preview strong {
    color: #0b1220;
}

html[data-theme="light"] .md-preview blockquote {
    background: #e6eaef;
    color: #152033;
}

html[data-theme="light"] .md-preview blockquote strong {
    color: #0b1220;
}

html[data-theme="light"] .md-preview pre.md-code {
    background: #e6eaef;
    border-color: rgba(20, 32, 56, 0.12);
}

html[data-theme="light"] .md-preview pre.md-code code {
    color: #152033;
}

html[data-theme="light"] .md-preview h2 {
    border-bottom-color: rgba(20, 32, 56, 0.1);
}

.md-preview blockquote > *:first-child { margin-top: 0.4em; }
.md-preview blockquote > *:last-child { margin-bottom: 0.4em; }

.md-preview ul,
.md-preview ol {
    margin: 0.85em 0;
    padding-left: 1.4em;
}

.md-preview li {
    margin: 0.35em 0;
}

.md-preview ul.md-task-list {
    list-style: none;
    padding-left: 0;
}

.md-preview li.md-task {
    display: block;
}

.md-preview li.md-task label {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    cursor: default;
}

.md-preview li.md-task input {
    margin-top: 0.35em;
    width: 1.05rem;
    height: 1.05rem;
    accent-color: var(--accent);
}

.md-preview hr {
    border: 0;
    border-top: 1px solid var(--border);
    margin: 1.6em 0;
}

.md-preview img {
    max-width: 100%;
    height: auto;
    border-radius: 10px;
    border: 1px solid var(--border);
    display: block;
    margin: 1em 0;
}

.md-preview .md-table-wrap {
    overflow: auto;
    margin: 1em 0;
    border-radius: 12px;
    border: 1px solid var(--border);
    -webkit-overflow-scrolling: touch;
}

.md-preview table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
    min-width: 280px;
}

.md-preview th,
.md-preview td {
    padding: 0.65em 0.85em;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

.md-preview thead th {
    background: var(--accent-soft-strong);
    font-weight: 700;
}

.md-preview tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

.dialog {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-elevated);
    color: var(--text);
    padding: 0;
    max-width: min(92vw, 420px);
}

.dialog--danger {
    border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
}

.dialog--danger .dialog-body h2 {
    color: var(--danger);
}

.dialog-emphasis {
    margin: -8px 0 18px !important;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text) !important;
    font-weight: 650;
    overflow-wrap: anywhere;
}

.dialog::backdrop {
    background: rgba(4, 8, 18, 0.65);
}

.dialog-body {
    margin: 0;
    padding: 20px;
}

.dialog-body h2 {
    margin: 0 0 8px;
    font-size: 1.15rem;
}

.dialog-body p {
    margin: 0 0 18px;
    color: var(--text-muted);
    line-height: 1.4;
}

.dialog-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.dialog-actions--triple {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.dialog-actions--triple .btn-primary {
    grid-column: 1 / -1;
}

@media (min-width: 420px) {
    .dialog-actions--triple {
        grid-template-columns: auto auto 1fr;
    }

    .dialog-actions--triple .btn-primary {
        grid-column: auto;
        justify-self: end;
    }
}

.item-actions-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.item-action-btn {
    justify-content: flex-start;
    border-radius: 12px;
}

.dialog--move {
    max-width: min(96vw, 480px);
    width: 100%;
}

.dialog--move .dialog-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: min(84dvh, 640px);
}

.move-path-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    padding: 6px 8px 6px 6px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-input);
}

.move-folder-list {
    flex: 1;
    min-height: 12rem;
    max-height: min(42dvh, 320px);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-group);
}

.move-folder-row {
    appearance: none;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    border: 0;
    border-bottom: 1px solid var(--hairline);
    background: transparent;
    color: inherit;
    text-align: left;
    padding: 14px 12px;
    font: inherit;
    cursor: pointer;
    touch-action: manipulation;
}

.move-folder-row:last-child {
    border-bottom: 0;
}

.move-folder-row:active {
    background: var(--accent-soft);
}

.move-folder-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 560;
}

.move-loading {
    margin: 0;
    padding: 18px 14px;
    color: var(--text-muted);
}

.move-folder-list .file-row-icon img {
    filter: invert(0.88) brightness(0.95);
    opacity: 0.9;
}

@media (min-width: 640px) {
    .editor-active {
        gap: 10px;
    }
}
