:root {
    --bg: #1f2326;
    --panel: #171a1d;
    --panel-2: #24282c;
    --line: #343b42;
    --line-soft: #2b3035;
    --text: #f0f3f4;
    --muted: #9aa3aa;
    --faint: #687179;
    --accent: #ff4d5b;
    --accent-2: #38c7b5;
    --warn: #f0b65f;
    --radius: 6px;
    --sidebar-width: 320px;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: "Aptos", "Segoe UI Variable", "Segoe UI", sans-serif;
    letter-spacing: 0;
}

button,
input,
textarea,
[contenteditable="true"] {
    font: inherit;
}

button {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #262b30;
    color: var(--text);
    cursor: pointer;
}

button:hover,
.file-button:hover {
    border-color: var(--accent);
}

.hidden {
    display: none !important;
}

.login-body {
    display: grid;
    place-items: center;
    min-height: 100%;
    background:
        linear-gradient(145deg, rgba(56, 199, 181, .12), transparent 32%),
        linear-gradient(315deg, rgba(255, 77, 91, .12), transparent 35%),
        var(--bg);
}

.login-panel {
    width: min(380px, calc(100vw - 32px));
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(23, 26, 29, .94);
    padding: 28px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, .32);
}

.brand-mark,
.brand-icon {
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--accent);
    color: var(--accent);
    font-weight: 800;
}

.brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 8px;
}

.login-panel h1 {
    margin: 18px 0 22px;
    font-size: 32px;
}

.login-panel label {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 13px;
}

.login-panel input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #111416;
    color: var(--text);
    padding: 12px;
}

.login-panel button {
    width: 100%;
    margin-top: 14px;
    padding: 12px;
    background: var(--accent);
    border-color: var(--accent);
    color: white;
    font-weight: 700;
}

.login-error {
    color: #ff9ca5;
    margin: 10px 0 0;
}

.app-shell {
    height: 100vh;
    display: grid;
    grid-template-columns: var(--sidebar-width) 6px minmax(0, 1fr);
    grid-template-rows: 58px 1fr;
    overflow: hidden;
}

.topbar {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 240px minmax(220px, 520px) 1fr auto;
    align-items: center;
    gap: 16px;
    padding: 0 16px;
    background: #22262a;
    border-bottom: 1px solid #151719;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    width: 30px;
    height: 30px;
    border-radius: 7px;
    font-size: 12px;
}

.search-wrap {
    position: relative;
}

.search-wrap input {
    width: 100%;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: #171a1d;
    color: var(--text);
    padding: 10px 12px 10px 34px;
    outline: none;
}

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

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
}

.save-status {
    color: var(--muted);
    font-size: 13px;
    justify-self: end;
}

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

.save-status.saved {
    color: var(--accent-2);
}

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

.ghost-button {
    padding: 8px 12px;
    background: transparent;
}

.sidebar {
    grid-column: 1;
    grid-row: 2;
    min-width: 0;
    overflow: auto;
    background: var(--panel);
    border-right: 1px solid #151719;
}

.sidebar-resize-handle {
    grid-column: 2;
    grid-row: 2;
    position: relative;
    z-index: 4;
    background: #151719;
    cursor: col-resize;
    touch-action: none;
}

.sidebar-resize-handle::after {
    content: "";
    position: absolute;
    inset: 0 2px;
    border-radius: 999px;
    background: transparent;
}

.sidebar-resize-handle:hover::after,
.sidebar-resize-handle:focus-visible::after,
body.sidebar-resizing .sidebar-resize-handle::after {
    background: var(--accent-2);
}

body.sidebar-resizing {
    cursor: col-resize;
    user-select: none;
}

.sidebar-actions {
    position: sticky;
    top: 0;
    z-index: 2;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 12px;
    background: var(--panel);
    border-bottom: 1px solid var(--line-soft);
}

.sidebar-actions button,
.tree-action,
.note-action {
    padding: 8px;
    font-size: 13px;
}

.tree-view,
.search-results {
    padding: 8px;
}

.tree-row,
.note-row,
.result-row {
    display: grid;
    align-items: center;
    min-height: 34px;
    border-radius: var(--radius);
    color: var(--text);
}

.tree-row {
    grid-template-columns: 18px 1fr auto auto;
    gap: 4px;
    padding: 3px 4px;
    font-weight: 600;
}

.note-row {
    grid-template-columns: 1fr auto;
    gap: 4px;
    padding: 7px 8px;
    margin-left: 24px;
    color: #d9dddf;
}

.tree-row[draggable="true"],
.note-row[draggable="true"] {
    cursor: grab;
}

.tree-row.dragging,
.note-row.dragging {
    cursor: grabbing;
    opacity: .45;
}

.tree-row.drop-before,
.note-row.drop-before {
    box-shadow: inset 0 2px 0 var(--accent-2);
}

.tree-row.drop-after,
.note-row.drop-after {
    box-shadow: inset 0 -2px 0 var(--accent-2);
}

.tree-row.drop-inside {
    background: rgba(56, 199, 181, .14);
    box-shadow: inset 0 0 0 1px var(--accent-2);
}

.tree-view.drop-root {
    box-shadow: inset 0 0 0 1px var(--accent-2);
}

.tree-row:hover,
.note-row:hover,
.result-row:hover,
.tree-row.active,
.note-row.active,
.result-row.active {
    background: #24282c;
}

.tree-toggle {
    color: var(--muted);
    text-align: center;
}

.tree-name,
.note-title,
.result-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tree-action,
.note-action {
    opacity: .72;
    min-width: 26px;
    padding: 4px 6px;
    border-color: transparent;
    background: transparent;
}

.tree-action:hover,
.note-action:hover {
    opacity: 1;
    background: #30363c;
}

.tree-children {
    margin-left: 14px;
}

.tree-item {
    position: relative;
}

.tree-item.menu-open {
    z-index: 20;
}

.category-menu {
    position: absolute;
    top: 32px;
    right: 8px;
    z-index: 24;
    display: grid;
    gap: 2px;
    width: 172px;
    margin: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #111416;
    padding: 4px;
    box-shadow: 0 12px 34px rgba(0, 0, 0, .32);
}

.category-menu button {
    width: 100%;
    border-color: transparent;
    background: transparent;
    padding: 8px 10px;
    text-align: left;
}

.category-menu button:hover {
    background: #24282c;
}

.category-menu .danger {
    color: #ff8d97;
}

.note-menu {
    right: 0;
}

.result-row {
    gap: 4px;
    width: 100%;
    border: 0;
    background: transparent;
    padding: 10px;
    margin-bottom: 4px;
    text-align: left;
    text-decoration: none;
}

.result-meta {
    color: var(--faint);
    font-size: 12px;
}

.result-excerpt {
    color: var(--muted);
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.workspace {
    grid-column: 3;
    grid-row: 2;
    min-width: 0;
    overflow: hidden;
    background:
        linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px),
        var(--bg);
    background-size: 34px 34px;
}

.empty-state {
    height: 100%;
    display: grid;
    place-content: center;
    text-align: center;
    color: var(--muted);
}

.empty-state h1 {
    margin: 0 0 8px;
    color: var(--text);
    font-size: 44px;
}

.editor-pane {
    height: 100%;
    display: grid;
    grid-template-rows: auto 1fr;
    min-width: 0;
}

.editor-head {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 16px;
    align-items: end;
    padding: 26px 34px 18px;
    border-bottom: 1px solid var(--line-soft);
    background: rgba(31, 35, 38, .92);
}

.breadcrumb {
    min-height: 18px;
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 8px;
}

.title-input {
    width: 100%;
    border: 0;
    border-bottom: 1px solid transparent;
    background: transparent;
    color: var(--text);
    outline: none;
    font-size: clamp(28px, 4vw, 46px);
    font-weight: 800;
}

.title-input:focus {
    border-bottom-color: var(--line);
}

.editor-tools {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    max-width: 560px;
}

.format-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--line-soft);
    border-radius: var(--radius);
    background: rgba(17, 20, 22, .62);
}

.format-toolbar button {
    min-width: 32px;
    height: 30px;
    border-color: transparent;
    background: transparent;
    padding: 0 8px;
}

.format-toolbar button:hover {
    background: #30363c;
    border-color: var(--line);
}

.file-button {
    display: inline-flex;
    align-items: center;
    height: 36px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0 12px;
    background: #262b30;
    cursor: pointer;
}

.editor-scroll {
    min-height: 0;
    overflow: auto;
}

.rich-editor {
    width: 100%;
    max-width: 980px;
    min-height: 100%;
    margin: 0 auto;
    border: 0;
    outline: none;
    background: rgba(18, 21, 23, .38);
    color: var(--text);
    padding: 34px 42px 110px;
    line-height: 1.68;
    font-size: 16px;
}

.rich-editor:empty::before {
    content: attr(data-placeholder);
    color: var(--faint);
}

.rich-editor.drop-ready {
    box-shadow: inset 0 0 0 2px var(--accent-2);
}

.rich-editor h1,
.rich-editor h2,
.rich-editor h3 {
    line-height: 1.2;
    margin: 1em 0 .45em;
}

.rich-editor h1 {
    font-size: 34px;
}

.rich-editor h2 {
    font-size: 24px;
}

.rich-editor p {
    color: #d9dddf;
}

.rich-editor pre {
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #141719;
    padding: 16px;
    white-space: pre-wrap;
}

.rich-editor code,
.rich-editor pre {
    color: #f5d491;
    font-family: "Cascadia Mono", "Consolas", monospace;
}

.rich-editor img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 14px 0;
    border-radius: var(--radius);
    border: 1px solid var(--line);
}

.rich-editor a {
    color: var(--accent-2);
}

@media (max-width: 920px) {
    .app-shell {
        grid-template-columns: 1fr;
        grid-template-rows: auto 220px 1fr;
    }

    .topbar {
        grid-column: 1;
        grid-template-columns: 1fr;
        padding: 12px;
    }

    .sidebar {
        grid-column: 1;
        grid-row: 2;
        border-right: 0;
        border-bottom: 1px solid #151719;
    }

    .sidebar-resize-handle {
        display: none;
    }

    .workspace {
        grid-column: 1;
        grid-row: 3;
    }

    .editor-head {
        grid-template-columns: 1fr;
    }

    .editor-tools {
        justify-content: flex-start;
    }

    .rich-editor {
        min-height: 280px;
        padding: 24px 18px 80px;
    }
}
