/* ══════════════════════════════════════════════════════
   Internet Notepad — Styles (Linen)
   Warm paper notebook aesthetic · Spectral + Rubik
   ══════════════════════════════════════════════════════ */

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: var(--leading);
    color: var(--color-text-primary);
    background: var(--color-bg);
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background var(--transition-slow), color var(--transition-slow);
}

noscript {
    display: none;
}

::selection {
    background: var(--color-accent-light);
    color: var(--color-text-primary);
}

:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

:focus:not(:focus-visible) {
    outline: none;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-muted);
}

@supports (scrollbar-width: thin) {
    * {
        scrollbar-width: thin;
        scrollbar-color: var(--color-border) transparent;
    }
}

/* ═══ ICONS ═══════════════════════════════════════════ */
.icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* ═══ LAYOUT ══════════════════════════════════════════ */
.skip-link {
    position: absolute;
    top: -9999px;
    left: var(--space-4);
    z-index: var(--z-toast);
    padding: var(--space-2) var(--space-4);
    background: var(--color-accent);
    color: var(--accent-text);
    border-radius: var(--radius);
    font-weight: var(--font-weight-semibold);
    text-decoration: none;
}

.skip-link:focus {
    top: var(--space-2);
}

/* Header */
#header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    height: var(--header-height);
    padding: 0 var(--space-4);
    background: var(--color-surface);
    border-bottom: var(--border-width) solid var(--color-border);
    flex-shrink: 0;
    position: relative;
    z-index: var(--z-header);
}

#logo {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: var(--font-weight-bold);
    color: var(--color-text-primary);
    text-decoration: none;
    margin-right: auto;
    letter-spacing: -0.01em;
}

#logo .icon {
    width: 22px;
    height: 22px;
    color: var(--gold);
}

/* Nav tabs */
#nav-tabs {
    display: flex;
    gap: var(--space-1);
}

#nav-tabs a {
    position: relative;
    text-decoration: none;
    color: var(--color-text-secondary);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius);
    font-size: var(--text-sm);
    font-weight: var(--font-weight-medium);
    transition: color var(--transition-fast);
}

#nav-tabs a:hover {
    color: var(--color-text-primary);
}

#nav-tabs a[aria-selected="true"] {
    color: var(--color-accent);
    background: var(--color-accent-subtle);
}

/* Theme toggle */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    background: var(--paper-hover);
    border: 1px solid var(--line);
    border-radius: var(--radius-full);
    padding: 3px;
    cursor: pointer;
}

.theme-option {
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: var(--font-weight-medium);
    color: var(--ink-secondary);
    transition: all var(--transition-fast);
    user-select: none;
}

.theme-option.active {
    background: var(--paper-card);
    box-shadow: var(--shadow-xs);
    color: var(--ink);
}

/* Search bar */
#search-bar {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border-bottom: var(--border-width) solid var(--color-border);
    background: var(--color-surface);
    flex-shrink: 0;
}

#search-bar .search-icon {
    flex-shrink: 0;
    color: var(--color-text-muted);
}

#search-input {
    flex: 1;
    border: none;
    background: transparent;
    font-family: var(--font-sans);
    font-size: var(--text-base);
    color: var(--color-text-primary);
    outline: none;
}

#search-input::placeholder {
    color: var(--color-text-muted);
}

#search-close {
    flex-shrink: 0;
}

/* Search dropdown */
#search-bar {
    position: relative;
}

.search-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 360px;
    overflow-y: auto;
    background: var(--color-surface);
    border: var(--border-width) solid var(--color-border);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 100;
    margin: 0;
}

.sr-item {
    display: block;
    padding: var(--space-2) var(--space-4);
    border-bottom: var(--border-width) solid var(--color-border);
    cursor: pointer;
    transition: background 0.1s;
}

.sr-item:last-child {
    border-bottom: none;
}

.sr-item:hover,
.sr-item.selected {
    background: var(--color-surface-hover);
}

.sr-title {
    font-size: var(--text-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sr-preview {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.sr-meta {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
}

/* Main layout */
main#app {
    display: flex;
    flex: 1;
    overflow: hidden;
}

#sidebar {
    width: var(--sidebar-width);
    min-width: 0;
    border-right: var(--border-width) solid var(--color-border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background: var(--color-surface);
    flex-shrink: 0;
    transition: width var(--transition) ease;
}

#sidebar.collapsed {
    width: 0;
    min-width: 0;
    padding: 0;
    overflow: hidden;
    border-right: none;
    transition: width var(--transition) ease;
}

#sidebar-toggle .icon {
    transition: transform var(--transition-fast);
}

body.collapsed #sidebar-toggle .icon {
    transform: rotate(180deg);
}

#editor-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

#content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: var(--space-6) var(--space-8);
    animation: contentIn var(--transition) var(--ease-out);
}

/* ═══ TAB BAR ══════════════════════════════════════════ */
#tab-bar {
    display: none;
}

.tab-bar {
    display: flex;
    align-items: stretch;
    gap: 2px;
    padding: var(--space-1) var(--space-2) 0;
    background: var(--color-surface);
    border-bottom: var(--border-width) solid var(--color-border);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    flex-shrink: 0;
    min-height: var(--tab-min-height);
}

.tab-bar::-webkit-scrollbar {
    display: none;
}

.tab-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius) var(--radius) 0 0;
    font-size: var(--text-xs);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-muted);
    cursor: pointer;
    white-space: nowrap;
    max-width: 180px;
    border: var(--border-width) solid transparent;
    border-bottom: none;
    transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
    user-select: none;
    flex-shrink: 0;
}

.tab-item:hover {
    background: var(--color-surface-hover);
    color: var(--color-text-secondary);
}

.tab-item.active {
    background: var(--color-bg);
    color: var(--color-text-primary);
    border-color: var(--color-border);
}

.tab-item .tab-title {
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}

.tab-item .tab-type-icon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.dirty-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-accent);
    display: inline-block;
    flex-shrink: 0;
    margin-left: 2px;
}

.tab-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 14px;
    line-height: 1;
    flex-shrink: 0;
    margin-left: var(--space-1);
}

.tab-close:hover {
    background: var(--color-surface-hover);
    color: var(--color-danger);
}

.tab-bar .split-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    border-radius: var(--radius);
    font-size: 16px;
    margin-left: auto;
    flex-shrink: 0;
}

.tab-bar .split-btn:hover {
    background: var(--color-surface-hover);
    color: var(--color-text-primary);
}

.noscript-banner {
    text-align: center;
    padding: var(--space-10);
    color: var(--color-text-secondary);
    font-family: var(--font-sans);
}

/* ═══ LIVE EDITOR ══════════════════════════════════════ */
.live-editor {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    cursor: text;
}

.live-block {
    position: relative;
    padding: var(--space-2) 0;
    margin: 0 0 var(--space-1);
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
    min-height: 24px;
}

.live-block.viewing {
    cursor: pointer;
}

.live-block.viewing:hover {
    background: var(--color-surface-hover);
}

.live-block.editing {
    cursor: text;
}

.live-block.empty {
    min-height: 24px;
}

.live-textarea {
    width: 100%;
    border: none;
    margin: 0;
    padding: 4px 8px;
    font-family: var(--font-mono);
    font-size: var(--text-base);
    line-height: var(--leading-relaxed);
    color: var(--color-text-primary);
    resize: none;
    outline: none;
    background: transparent;
    overflow: hidden;
}

.live-textarea::placeholder {
    color: var(--color-text-muted);
}

.live-block.viewing h1 {
    font-family: var(--font-display);
    font-size: var(--text-2xl);
    margin: 0 0 var(--space-2);
    font-weight: var(--font-weight-bold);
    line-height: var(--leading-tight);
}

.live-block.viewing h2 {
    font-family: var(--font-display);
    font-size: var(--text-xl);
    margin: 0 0 var(--space-2);
    font-weight: var(--font-weight-semibold);
}

.live-block.viewing h3 {
    font-family: var(--font-display);
    font-size: var(--text-lg);
    margin: 0 0 var(--space-1);
    font-weight: var(--font-weight-semibold);
}

.live-block.viewing p {
    margin: 0;
    line-height: var(--leading-relaxed);
}

.live-block.viewing a {
    color: var(--color-accent);
    text-decoration: underline;
}

.live-block.viewing ul,
.live-block.viewing ol {
    padding-left: var(--space-6);
    margin: 0;
}

.live-block.viewing li {
    margin-bottom: var(--space-1);
}

.live-block.viewing code {
    background: var(--color-bg);
    color: var(--color-accent);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
}

/* Wikilinks */
.wikilink {
    color: var(--color-accent);
    text-decoration: none;
    border-bottom: 1px dashed var(--color-accent);
    cursor: pointer;
    transition: color var(--transition-fast), border-color var(--transition-fast);
}

.wikilink:hover {
    color: var(--color-accent-hover);
    border-bottom-style: solid;
}

.wikilink--missing {
    color: var(--color-text-muted);
    border-bottom-color: var(--color-text-muted);
    cursor: default;
}

.wikilink--missing:hover {
    color: var(--color-text-muted);
    border-bottom-style: dashed;
}

.live-block.viewing pre {
    background: var(--color-bg);
    border: var(--border-width) solid var(--color-border);
    padding: var(--space-4);
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 0;
}

.live-block.viewing pre code {
    background: transparent;
    color: var(--color-text-primary);
    padding: 0;
    font-size: var(--text-sm);
}

/* ── Code highlighting (highlight.js, paper-adaptive) ── */
.live-block.viewing pre code.hljs {
    color: var(--ink);
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-section,
.hljs-doctag { color: oklch(0.48 0.15 290); }

.hljs-string,
.hljs-regexp,
.hljs-addition,
.hljs-attribute,
.hljs-meta .hljs-string { color: oklch(0.48 0.1 145); }

.hljs-number,
.hljs-literal,
.hljs-variable,
.hljs-template-variable,
.hljs-type { color: oklch(0.48 0.14 40); }

.hljs-comment,
.hljs-quote,
.hljs-deletion,
.hljs-meta { color: var(--ink-muted); font-style: italic; }

.hljs-title,
.hljs-name,
.hljs-selector-id,
.hljs-selector-class,
.hljs-function,
.hljs-built_in { color: oklch(0.48 0.11 250); }

.hljs-attr,
.hljs-params,
.hljs-symbol,
.hljs-bullet,
.hljs-link { color: oklch(0.48 0.08 335); }

.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: var(--weight-bold); }

.hljs-tag { color: oklch(0.48 0.1 290); }
.hljs-tag .hljs-name { color: oklch(0.48 0.12 25); }
.hljs-tag .hljs-attr { color: oklch(0.48 0.08 100); }

.hljs-formula { color: var(--ink); background: var(--paper-hover); }

.live-block.viewing blockquote {
    border: 0;
    padding: var(--space-2) var(--space-4);
    color: var(--color-text-secondary);
    font-style: italic;
    margin: 0;
    background: var(--paper-hover);
    border-radius: var(--radius);
}

.live-block.viewing img {
    max-width: 100%;
    border-radius: var(--radius);
}

.live-block.viewing hr {
    border: none;
    border-top: var(--border-width) solid var(--color-border);
    margin: var(--space-4) 0;
}

.todo-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    padding: 2px 0;
}

.todo-checkbox {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    margin-top: 3px;
    accent-color: var(--color-accent);
    cursor: pointer;
}

.todo-text {
    line-height: var(--leading-relaxed);
    color: var(--color-text-primary);
}

.todo-text.checked {
    text-decoration: line-through;
    color: var(--color-text-muted);
}

.live-block[data-type="divider"].viewing {
    cursor: default;
    padding: var(--space-2) 0;
    position: relative;
}

.live-block[data-type="divider"].viewing .live-block-image-delete {
    position: absolute;
    top: 2px;
    right: 4px;
    width: 20px;
    height: 20px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.4);
    color: #fff;
    font-size: 14px;
    line-height: 20px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 2;
}

.live-block[data-type="divider"].viewing:hover .live-block-image-delete {
    opacity: 1;
}

.live-block[data-type="divider"].viewing .live-block-image-delete:hover {
    background: var(--color-danger);
}

.live-block[data-type="heading"] .live-textarea {
    font-family: var(--font-display);
    font-weight: var(--font-weight-bold);
    font-size: var(--text-xl);
}

.live-block[data-type="image"].viewing {
    cursor: default;
    padding: 4px 0;
    position: relative;
}

.live-block[data-type="image"].viewing .live-block-image-delete {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    font-size: 16px;
    line-height: 24px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 2;
}

.live-block[data-type="image"].viewing:hover .live-block-image-delete {
    opacity: 1;
}

.live-block[data-type="image"].viewing .live-block-image-delete:hover {
    background: var(--color-danger);
}

.live-block[data-type="image"].viewing img {
    display: block;
    margin: 0 auto;
    max-height: 600px;
    object-fit: contain;
}

.live-block[data-type="image"].editing .live-textarea {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
}

.live-block[data-type="code"].viewing pre {
    margin: 0;
}

.live-block.editing {
    outline: 1px solid var(--color-accent-subtle);
    outline-offset: -1px;
    border-radius: var(--radius-sm);
}

.live-editor-click-below {
    min-height: 200px;
    cursor: text;
    width: 100%;
}

.block-gap {
    position: relative;
    height: 2px;
    transition: height 0.15s ease;
    cursor: text;
}

.block-gap:hover {
    height: 26px;
}

.block-gap-btn {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 22px;
    height: 22px;
    padding: 0;
    border: 1px solid var(--color-border);
    border-radius: 50%;
    background: var(--color-surface);
    color: var(--color-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.block-gap:hover .block-gap-btn {
    opacity: 1;
}

.block-gap-btn:hover {
    background: var(--color-accent);
    color: var(--color-accent-text);
    border-color: var(--color-accent);
}

.block-drag-handle {
    position: absolute;
    left: -32px;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    color: var(--color-text-muted);
    font-size: 16px;
    letter-spacing: 0.5px;
    opacity: 0;
    transition: opacity 0.15s ease, color 0.15s ease;
    user-select: none;
    z-index: 2;
}

.live-block:hover .block-drag-handle {
    opacity: 1;
}

.live-block.dragging .block-drag-handle {
    opacity: 1;
    cursor: grabbing;
}

.block-drag-handle:hover {
    color: var(--color-accent);
}

.live-block.dragging {
    opacity: 0.5;
}

.live-block.drag-over::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--color-accent);
    border-radius: 1px;
    z-index: 3;
}

.live-block-delete-btn {
    position: absolute;
    right: 4px;
    top: 4px;
    width: 20px;
    height: 20px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.35);
    color: #fff;
    font-size: 14px;
    line-height: 20px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease, background 0.15s ease;
    z-index: 1;
}

.live-block:hover .live-block-delete-btn {
    opacity: 1;
}

.live-block-delete-btn:hover {
    background: var(--color-danger);
}

.slash-menu {
    position: fixed;
    z-index: 10000;
    width: 240px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    padding: 4px 0;
    max-height: 280px;
    overflow-y: auto;
    font-family: var(--font-sans);
}

.slash-menu-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 6px 12px;
    cursor: pointer;
    font-size: var(--text-sm);
}

.slash-menu-item.selected {
    background: var(--color-accent-subtle);
}

.slash-menu-item:hover {
    background: var(--color-surface-hover);
}

.slash-menu-item.selected:hover {
    background: var(--color-accent-subtle);
}

.slash-menu-icon {
    width: 24px;
    text-align: center;
    font-weight: var(--font-weight-bold);
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    flex-shrink: 0;
}

.slash-menu-label {
    color: var(--color-text-primary);
    flex: 1;
}

.slash-menu-desc {
    color: var(--color-text-muted);
    font-size: var(--text-xs);
}

/* ═══ BUTTONS ═════════════════════════════════════════ */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.btn-icon:hover {
    background: var(--color-surface-hover);
    color: var(--color-text-primary);
}

.btn-icon:active {
    background: var(--color-surface-active);
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text-primary);
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
    white-space: nowrap;
}

.btn:hover {
    background: var(--color-surface-hover);
}

.btn:active {
    background: var(--color-surface-active);
    transform: scale(0.97);
}

.btn-primary {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: var(--accent-text);
    font-weight: var(--font-weight-semibold);
}

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

.btn-primary:active {
    filter: brightness(0.9);
}

.btn-danger {
    color: var(--color-danger);
    border-color: var(--color-border);
}

.btn-danger:hover {
    background: var(--color-danger-light);
    border-color: var(--color-danger);
    color: var(--color-danger-hover);
}

.btn-ghost {
    border-color: transparent;
    background: transparent;
    color: var(--color-text-secondary);
}

.btn-ghost:hover {
    background: var(--color-surface-hover);
    color: var(--color-text-primary);
}

.btn-sm {
    padding: var(--space-1) var(--space-3);
    font-size: var(--text-xs);
}

.btn-lg {
    padding: var(--space-3) var(--space-6);
    font-size: var(--text-base);
}

.btn-gold {
    background: var(--gold-bg);
    border-color: var(--gold-bg);
    color: oklch(0.3 0.06 85);
    font-weight: var(--font-weight-semibold);
}

.btn-gold:hover {
    background: oklch(0.88 0.12 85);
    border-color: oklch(0.88 0.12 85);
}

/* ═══ SIDEBAR / NOTE LIST ════════════════════════════ */
#sidebar-header {
    flex-shrink: 0;
}

#note-list-container {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3);
    border-bottom: var(--border-width) solid var(--color-border);
    background: var(--color-surface);
    position: sticky;
    top: 0;
    z-index: var(--z-sidebar);
}

.sidebar-header .form-input {
    font-size: var(--text-xs);
    padding: var(--space-1) var(--space-3) var(--space-1) var(--space-8);
    flex: 1;
    min-width: 0;
}

.sidebar-header .btn-sm {
    flex-shrink: 0;
}

.note-item {
    padding: var(--space-3) var(--space-4);
    border-bottom: var(--border-width) solid var(--color-border-light);
    cursor: pointer;
    transition: background var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
    position: relative;
}

.drag-handle {
    position: absolute;
    left: var(--space-1);
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
    cursor: grab;
    opacity: 0;
    transition: opacity var(--transition-fast);
    border-radius: var(--radius-sm);
    user-select: none;
    font-size: 14px;
}

.note-item:hover .drag-handle {
    opacity: 0.5;
}

/* Mobile reorder buttons */
.reorder-btns {
    display: none;
}

@media (max-width: 767px) {
    .reorder-btns {
        display: flex;
        flex-direction: column;
        gap: 2px;
        margin-left: var(--space-2);
        flex-shrink: 0;
    }

    .reorder-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 28px;
        height: 20px;
        border: none;
        background: var(--color-surface-hover);
        color: var(--color-text-muted);
        border-radius: var(--radius-sm);
        cursor: pointer;
        font-size: 12px;
        line-height: 1;
        padding: 0;
    }

    .reorder-btn:active {
        background: var(--color-accent);
        color: var(--accent-text);
    }

    .note-item:first-child .reorder-up,
    .note-item:last-child .reorder-down {
        visibility: hidden;
    }
}

.note-item .drag-handle:hover,
.note-item .drag-handle:active {
    opacity: 1;
    color: var(--color-text-primary);
    background: var(--color-surface-hover);
}

.note-item.dragging {
    opacity: 0.5;
    box-shadow: var(--shadow-md);
}

.note-item.drag-over {
    border-top: 3px solid var(--color-accent);
}

.note-item:hover {
    background: var(--color-surface-hover);
    transform: translateX(2px);
}

.note-item:active {
    transform: translateX(0) scale(0.995);
}

.note-item.active {
    background: var(--color-accent-subtle);
}

.note-item.pinned::before {
    content: '';
    position: absolute;
    left: 0;
    top: var(--space-2);
    bottom: var(--space-2);
    width: 2px;
    background: var(--color-accent);
    border-radius: var(--radius-full);
}

.note-item .title {
    font-family: var(--font-display);
    font-weight: var(--font-weight-semibold);
    font-size: var(--text-sm);
    margin-bottom: 2px;
    line-height: var(--leading-tight);
}

.note-item .title.empty {
    color: var(--color-text-muted);
    font-weight: var(--font-weight-normal);
    font-style: italic;
}

.note-item .preview {
    font-size: var(--text-xs);
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.note-item .meta {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    margin-top: var(--space-1);
}

/* ═══ CALENDAR ════════════════════════════════════════ */
.calendar-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    padding: var(--space-4) 0;
}

.calendar-nav .month {
    font-family: var(--font-display);
    font-weight: var(--font-weight-semibold);
    font-size: var(--text-lg);
    min-width: 180px;
    text-align: center;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}

.calendar-grid .day-name {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    text-align: center;
    padding: var(--space-2) 0;
    font-weight: var(--font-weight-medium);
}

.calendar-grid .day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-sm);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: background var(--transition-fast);
    position: relative;
}

.calendar-grid .day:hover {
    background: var(--color-surface-hover);
}

.calendar-grid .day.empty {
    color: var(--color-text-muted);
    cursor: default;
    pointer-events: none;
}

.calendar-grid .day.today {
    color: var(--color-accent);
    font-weight: var(--font-weight-bold);
}

.calendar-grid .day.today::after {
    content: '';
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--color-accent);
}

.calendar-grid .day.selected {
    background: var(--color-accent);
    color: var(--accent-text);
}

.calendar-grid .day.has-entry {
    background: var(--color-accent-subtle);
    font-weight: var(--font-weight-semibold);
}

.calendar-grid .day.has-entry::after {
    content: '';
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
    width: 6px;
    height: 6px;
    border-radius: var(--radius-full);
    background: var(--color-accent);
}

.journal-editor {
    margin-top: var(--space-5);
}

.journal-date-heading {
    font-family: var(--font-display);
    font-size: var(--text-xl);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
}

/* Journal entry cards */
.journal-entry-card {
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    margin-bottom: var(--space-3);
    background: var(--color-surface-raised);
    transition: border-color var(--transition-fast);
}

.journal-entry-card:focus-within {
    border-color: var(--color-accent);
}

.journal-entry-card--new {
    border-style: dashed;
    border-color: var(--color-accent);
}

.entry-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}

.entry-header .title-input {
    flex: 1;
    border: none;
    background: transparent;
    font-family: var(--font-display);
    font-size: var(--text-base);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
    padding: 2px 0;
    outline: none;
    min-width: 0;
}

.entry-header .title-input::placeholder {
    color: var(--color-text-muted);
}

.entry-time {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    white-space: nowrap;
}

.entry-actions {
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.entry-save-indicator {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    gap: 2px;
    white-space: nowrap;
}

.entry-save-indicator.saved {
    color: var(--color-success, #22c55e);
}

.entry-save-indicator.saving {
    color: var(--color-text-muted);
}

.entry-save-indicator.error {
    color: var(--color-danger, #ef4444);
}

.entry-textarea {
    width: 100%;
    min-height: 60px;
    border: none;
    background: transparent;
    color: var(--color-text-primary);
    font-size: var(--text-sm);
    line-height: var(--leading-relaxed);
    resize: vertical;
    outline: none;
    padding: 0;
    font-family: var(--font-body);
}

.entry-textarea::placeholder {
    color: var(--color-text-muted);
}

/* Calendar: multiple entries indicator */
.calendar-grid .day.has-multiple::before {
    content: attr(data-count);
    position: absolute;
    top: 2px;
    right: 4px;
    font-size: 8px;
    font-weight: var(--font-weight-bold);
    color: var(--color-accent);
    line-height: 1;
}

.calendar-grid .day.has-multiple.has-entry::after {
    bottom: 5px;
    width: 4px;
    height: 4px;
}

.calendar-grid .day.selected.has-multiple::before {
    color: var(--accent-text);
}

/* ═══ EDITOR ══════════════════════════════════════════ */
.editor {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    animation: contentIn var(--transition-slow) ease;
}

.editor-toolbar {
    display: flex;
    gap: var(--space-2);
    align-items: center;
    padding: var(--space-2) 0;
    border-bottom: var(--border-width) solid var(--color-border-light);
    margin-bottom: var(--space-4);
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg-primary);
}

.editor-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-2) 0;
    border-top: var(--border-width) solid var(--color-border-light);
    margin-top: auto;
}

.editor-tags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
    align-items: center;
}

.tag-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border: none;
    background: none;
    color: var(--ink-muted);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    margin-left: 2px;
    border-radius: var(--radius-sm);
}

.tag-remove:hover {
    color: var(--color-danger);
    background: var(--color-danger-light);
}

.title-input {
    border: none;
    font-family: var(--font-display);
    font-size: var(--text-2xl);
    font-weight: var(--font-weight-bold);
    padding: var(--space-2) 0;
    outline: none;
    margin-bottom: var(--space-3);
    background: transparent;
    color: var(--color-text-primary);
    letter-spacing: -0.01em;
}

.title-input::placeholder {
    color: var(--color-text-muted);
}

.live-editor .live-block.viewing {
    font-family: var(--font-display);
    font-size: var(--text-base);
    line-height: var(--leading-relaxed);
    color: var(--color-text-primary);
}

/* Markdown toolbar */
.md-toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: var(--space-1) var(--space-3);
    border-bottom: var(--border-width) solid var(--color-border-light);
    background: var(--paper-hover);
    border-radius: var(--radius) var(--radius) 0 0;
}

.md-toolbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.md-toolbar-btn:hover {
    background: var(--color-surface);
    color: var(--color-text-primary);
}

.md-toolbar-btn:active {
    background: var(--color-surface-active);
}

.md-toolbar-divider {
    width: 1px;
    height: 18px;
    background: var(--color-border);
    margin: 0 var(--space-1);
}

.editor-toolbar .toolbar-spacer {
    flex: 1;
}

.md-help-btn {
    color: var(--color-accent);
}

/* Markdown help/cheatsheet panel */
.md-help-panel {
    background: var(--color-surface);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-3);
    margin-bottom: var(--space-4);
}

.md-help-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-2);
}

.md-help-title {
    font-size: var(--text-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
}

.md-help-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-xs);
    font-family: var(--font-sans);
}

.md-help-table td {
    padding: var(--space-1) var(--space-2);
    border-bottom: var(--border-width) solid var(--color-border-light);
    color: var(--color-text-secondary);
}

.md-help-table td:first-child {
    color: var(--color-text-primary);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    white-space: nowrap;
}

.md-help-table td code {
    background: transparent;
    color: var(--ink);
    font-family: var(--font-mono);
}

.md-help-table strong,
.md-help-table em,
.md-help-table s {
    color: var(--color-text-primary);
}

.search-result-preview {
    margin-top: var(--space-4);
}

.highlight {
    background: var(--gold-bg);
    color: oklch(0.3 0.06 85);
    padding: 0 2px;
    border-radius: 2px;
    font-weight: var(--font-weight-medium);
}

/* ═══ STATES ══════════════════════════════════════════ */
.skeleton {
    background: linear-gradient(90deg,
        var(--color-surface-hover) 25%,
        var(--color-border) 50%,
        var(--color-surface-hover) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}

.skeleton-line {
    height: 14px;
    margin-bottom: var(--space-2);
}

.skeleton-line.short {
    width: 60%;
}

.skeleton-line.medium {
    width: 80%;
}

.skeleton-block {
    height: 60px;
    margin-bottom: var(--space-3);
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-16) var(--space-6);
    text-align: center;
    gap: var(--space-4);
    animation: fadeIn var(--transition-slow) ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes contentIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.empty-state-icon {
    width: 64px;
    height: 64px;
    border-radius: var(--radius-full);
    background: var(--paper-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ink-muted);
    margin-bottom: var(--space-2);
}

.empty-state-icon svg {
    width: 28px;
    height: 28px;
}

.empty-state-title {
    font-family: var(--font-display);
    font-size: var(--text-xl);
    font-weight: var(--font-weight-semibold);
    color: var(--ink);
}

.empty-state-text {
    font-size: var(--text-base);
    color: var(--ink-secondary);
    max-width: 320px;
    line-height: var(--leading-relaxed);
}

.empty-state p {
    margin-bottom: var(--space-4);
}

.empty-state--compact {
    padding: var(--space-4) var(--space-4);
    gap: var(--space-2);
}

.empty-state--compact .empty-state-icon {
    width: 40px;
    height: 40px;
    margin-bottom: var(--space-1);
}

.empty-state--compact .empty-state-icon svg {
    width: 20px;
    height: 20px;
}

.empty-state--compact .empty-state-title {
    font-size: var(--text-sm);
}

.empty-state--compact .empty-state-text {
    font-size: var(--text-xs);
}

.empty-state-actions {
    margin-top: var(--space-3);
    display: flex;
    gap: var(--space-2);
}

.error-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--color-danger-light);
    border: var(--border-width) solid var(--color-danger);
    border-radius: var(--radius);
    color: var(--color-danger);
    margin-bottom: var(--space-4);
    font-size: var(--text-sm);
}

.save-indicator {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-2) 0;
    transition: color var(--transition-fast);
}

.save-indicator.saved {
    color: var(--color-success);
}

.save-indicator.saving {
    color: var(--color-text-muted);
}

.word-counter {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    padding: var(--space-2) 0;
    white-space: nowrap;
    user-select: none;
}

.hidden {
    display: none !important;
}

.offline-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    background: var(--gold-bg);
    color: oklch(0.3 0.06 85);
    font-size: var(--text-xs);
    font-weight: var(--font-weight-medium);
    text-align: center;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: calc(var(--z-header) + 1);
}

.offline-banner .icon {
    width: 14px;
    height: 14px;
}

/* ═══ AUTH SCREEN ═════════════════════════════════════ */
.login-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--color-bg);
    padding: var(--space-6);
    overflow-y: auto;
}

.login-card {
    max-width: 380px;
    width: 100%;
    margin: var(--space-10) auto;
    padding: var(--space-10) var(--space-8);
    background: var(--paper-card);
    border: var(--border-width) solid var(--line);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    text-align: center;
}

.login-card h2 {
    font-family: var(--font-display);
    font-size: var(--text-2xl);
    font-weight: var(--font-weight-bold);
    color: var(--color-text-primary);
    margin-bottom: var(--space-2);
}

.login-subtitle {
    color: var(--color-text-secondary);
    font-size: var(--text-sm);
    margin-bottom: var(--space-8);
}

.login-field {
    text-align: left;
    margin-bottom: var(--space-4);
}

.form-label {
    display: block;
    font-size: var(--text-sm);
    font-weight: var(--font-weight-medium);
    color: var(--ink);
    margin-bottom: var(--space-1);
}

.form-input {
    width: 100%;
    font-family: var(--font-sans);
    font-size: var(--text-base);
    color: var(--color-text-primary);
    background: var(--paper-card);
    border: var(--border-width) solid var(--line);
    border-radius: var(--radius);
    padding: var(--space-3) var(--space-4);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    outline: none;
}

.form-input::placeholder {
    color: var(--ink-placeholder);
}

.form-input:hover {
    border-color: var(--ink-muted);
}

.form-input:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-light);
}

.form-input:disabled {
    opacity: 0.5;
    background: var(--paper-hover);
}

.input-search {
    padding-left: var(--space-8);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238B8478' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 12px center;
}

.form-input[aria-invalid="true"] {
    border-color: var(--color-danger);
    box-shadow: 0 0 0 3px var(--color-danger-light);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 0;
    width: 100%;
}

.auth-submit {
    width: 100%;
    padding: var(--space-3) 0;
    font-size: var(--text-base);
    margin-top: var(--space-2);
}

.auth-switch {
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    margin-top: var(--space-6);
}

.auth-switch a {
    color: var(--color-accent);
    font-weight: var(--font-weight-semibold);
    text-decoration: none;
}

.auth-switch a:hover {
    text-decoration: underline;
}

.auth-divider {
    display: flex;
    align-items: center;
    width: 100%;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    margin: var(--space-6) 0;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    border-bottom: var(--border-width) solid var(--color-border);
}

.auth-divider span {
    padding: 0 var(--space-4);
}

.auth-error {
    background: var(--color-danger-light);
    border: var(--border-width) solid var(--color-danger);
    border-radius: var(--radius);
    color: var(--color-danger);
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-sm);
    width: 100%;
    text-align: center;
}

.validation-msg {
    font-size: var(--text-xs);
    color: var(--color-danger);
    min-height: 16px;
    padding-left: var(--space-1);
}

/* ═══ TAGS ════════════════════════════════════════════ */
.tags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
    margin-top: var(--space-2);
}

.tag {
    display: inline-flex;
    align-items: center;
    font-size: var(--text-xs);
    font-weight: var(--font-weight-medium);
    padding: 2px var(--space-2);
    border-radius: var(--radius-sm);
    background: var(--paper-hover);
    color: var(--color-text-secondary);
    border: 1px solid var(--line-light);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.tag:hover {
    background: var(--color-accent-light);
    color: var(--color-accent);
}

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

/* ═══ RESPONSIVE ══════════════════════════════════════ */

/* ── Tablet (768–1023px) — sidebar hidden by default, toggles out ── */
@media (max-width: 1023px) {
    #sidebar {
        width: var(--sidebar-width-tablet);
    }

    #content {
        padding: var(--space-4) var(--space-5);
        max-width: calc(100% - var(--sidebar-width-tablet));
    }
}

@media (max-width: 767px) {
    #header {
        padding: 0 var(--space-3);
    }

    #nav-tabs {
        gap: 0;
    }

    #nav-tabs a {
        padding: var(--space-1) var(--space-2);
        font-size: var(--text-xs);
    }

    #logo span {
        display: none;
    }

    #logo .icon {
        width: 22px;
        height: 22px;
    }

    /* Sidebar becomes fullscreen overlay on mobile */
    #sidebar {
        position: fixed;
        inset: 0;
        top: var(--header-height);
        width: 100%;
        max-height: none;
        z-index: calc(var(--z-sidebar) + 5);
        border-right: none;
        transform: translateX(0);
        transition: transform var(--transition) ease;
    }

    #sidebar.sidebar-hidden {
        transform: translateX(-100%);
        opacity: 0;
    }

    /* Editor becomes full screen, slides in from right */
    #content {
        position: fixed;
        inset: 0;
        top: var(--header-height);
        max-width: 100%;
        padding: var(--space-4);
        z-index: calc(var(--z-sidebar) + 5);
        background: var(--color-bg);
        transform: translateX(0);
        transition: transform var(--transition) ease;
    }

    #content.editor-hidden {
        transform: translateX(100%);
        opacity: 0;
    }

    main#app {
        position: relative;
        overflow: hidden;
    }
}

.mobile-bottom-nav {
    display: none;
}

/* ── Small mobile (≤480px) — bottom nav ── */
@media (max-width: 480px) {
    #header {
        height: 44px;
        padding: 0 var(--space-2);
        gap: var(--space-1);
    }

    /* Hide top nav, show bottom nav */
    #nav-tabs {
        display: none;
    }

    #sidebar-toggle {
        display: none;
    }

    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--color-surface);
        border-top: var(--border-width) solid var(--color-border);
        justify-content: space-around;
        align-items: center;
        height: var(--bottom-nav-height);
        padding: 0 var(--space-2);
        padding-bottom: env(safe-area-inset-bottom, 0);
        z-index: var(--z-header);
    }

    .mobile-bottom-nav a {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        padding: var(--space-1) var(--space-2);
        border-radius: var(--radius);
        text-decoration: none;
        color: var(--color-text-muted);
        font-size: 10px;
        font-weight: var(--font-weight-medium);
        transition: color var(--transition-fast);
        min-width: 48px;
        min-height: 44px;
        justify-content: center;
    }

    .mobile-bottom-nav a .icon {
        width: 20px;
        height: 20px;
    }

    .mobile-bottom-nav a.active {
        color: var(--color-accent);
    }

    .mobile-bottom-nav a.active::after {
        content: '';
        position: absolute;
        bottom: 0;
        width: 16px;
        height: 3px;
        background: var(--color-accent);
        border-radius: var(--radius-full) var(--radius-full) 0 0;
    }

    main#app {
        padding-bottom: var(--bottom-nav-height);
    }

    #sidebar,
    #content {
        top: var(--header-height);
        bottom: var(--bottom-nav-height);
    }

    /* Back button in mobile editor */
    .mobile-back-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        border: none;
        background: transparent;
        color: var(--color-text-secondary);
        cursor: pointer;
        border-radius: var(--radius);
        margin-right: var(--space-2);
    }

    .mobile-back-btn:hover {
        background: var(--color-surface-hover);
    }

    /* Touch-friendly: enlarge interactive elements */
    .btn-icon {
        min-width: 44px;
        min-height: 44px;
    }

    .note-item {
        padding: var(--space-4);
    }

    .note-item .title {
        font-size: var(--text-base);
    }

    .calendar-grid .day {
        font-size: var(--text-xs);
        min-width: 36px;
        min-height: 36px;
    }

    .calendar-nav .month {
        font-size: var(--text-base);
        min-width: 140px;
    }

    .editor-toolbar .note-type-select {
        display: none;
    }

    /* Toast above bottom nav */
    .toast,
    .image-toast {
        bottom: calc(var(--bottom-nav-height) + var(--space-3));
    }

    /* Sidebar search — prevent iOS zoom */
    #sidebar-search {
        font-size: var(--text-base);
    }

    /* Login card — reduce padding on small screens */
    .login-card {
        padding: var(--space-6) var(--space-5);
        margin: var(--space-6) auto;
    }
}

/* ── Large desktop (≥1440px) — wider sidebar ── */
@media (min-width: 1440px) {
    #sidebar {
        width: 340px;
    }

    #content {
        max-width: calc(100% - 340px);
        padding: var(--space-6) var(--space-10);
    }
}

/* ═══ CONTEXT MENU ═════════════════════════════════════ */
.context-menu {
    position: fixed;
    z-index: var(--z-modal);
    background: var(--color-surface);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: var(--space-1);
    min-width: 180px;
}

.context-menu-item {
    display: block;
    width: 100%;
    padding: var(--space-3) var(--space-4);
    border: none;
    background: transparent;
    color: var(--color-text-primary);
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    text-align: left;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}

.context-menu-item:hover {
    background: var(--color-surface-hover);
}

.context-menu-item.danger {
    color: var(--color-danger);
}

.context-menu-item.danger:hover {
    background: var(--color-danger-light);
}

.context-menu-separator {
    height: 1px;
    background: var(--color-border-light);
    margin: var(--space-1) 0;
}

/* ═══ MODAL ═══════════════════════════════════════════ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: oklch(0 0 0 / 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
}

.modal-card {
    background: var(--color-surface);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-xl);
    padding: var(--space-6);
    max-width: 380px;
    width: calc(100% - var(--space-8));
    box-shadow: var(--shadow-lg);
}

.modal-title {
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
    margin-bottom: var(--space-2);
}

.modal-message {
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-6);
    line-height: var(--leading-relaxed);
}

.modal-input {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-4);
    font-size: var(--text-sm);
    font-family: var(--font-sans);
    color: var(--color-text-primary);
    background: var(--color-bg);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-md);
    outline: none;
    transition: border-color 0.15s;
}

.modal-input:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-light);
}

.modal-input::placeholder {
    color: var(--color-text-muted);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
}

/* ═══ FOLDER TREE ══════════════════════════════════════ */
.folder-tree {
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--color-border);
    max-height: 40vh;
    overflow-y: auto;
    flex-shrink: 0;
}

.folder-tree-item {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: var(--text-sm);
    color: var(--color-text-primary);
    user-select: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.folder-tree-item:hover {
    background: var(--color-surface-hover);
}

.folder-tree-item.selected {
    background: var(--color-accent-light);
    color: var(--color-accent);
    font-weight: var(--font-weight-medium);
}

.folder-toggle {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: var(--color-text-muted);
    transition: transform 0.15s;
}

.folder-tree-item.expanded > .folder-toggle {
    transform: rotate(90deg);
}

.folder-children {
    overflow: hidden;
}

.folder-tree-item:not(.expanded) + .folder-children {
    display: none;
}

.folder-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.folder-count {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    flex-shrink: 0;
}

.folder-tree-all {
    font-style: italic;
    color: var(--color-text-muted);
}

.folder-tree-all.selected {
    font-style: italic;
    color: var(--color-accent);
}

.folder-error {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
    color: var(--color-danger);
}

.folder-rename-input {
    flex: 1;
    font-size: var(--text-sm);
    border: 1px solid var(--color-accent);
    border-radius: var(--radius-sm);
    padding: 2px var(--space-1);
    background: var(--color-surface);
    color: var(--color-text-primary);
    outline: none;
}

.folder-tree-item.drag-over {
    background: var(--color-accent-light);
    outline: 2px dashed var(--color-accent);
    outline-offset: -2px;
}


/* Folder note items (inside tree) */
.folder-note-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) var(--space-2);
    padding-right: var(--space-3);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: var(--text-xs);
    color: var(--color-text-secondary);
    user-select: none;
    white-space: nowrap;
    overflow: hidden;
    transition: background var(--transition-fast);
}

.folder-note-item:hover {
    background: var(--color-surface-hover);
}

.folder-note-item.active {
    background: var(--color-accent-subtle);
    color: var(--color-accent);
}

.folder-note-item.active .folder-note-title {
    font-weight: var(--font-weight-medium);
}

.folder-note-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.folder-note-title.empty {
    color: var(--color-text-muted);
    font-style: italic;
}

/* ── Trash / Корзина ── */
.folder-tree-trash {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    margin-top: var(--space-2);
    border-top: 1px solid var(--color-border-light);
    color: var(--color-text-muted);
    font-size: var(--text-sm);
    cursor: pointer;
    transition: color var(--transition-fast);
}

.folder-tree-trash:hover {
    color: var(--color-danger);
}

.trash-view {
    padding: var(--space-4) 0;
}

.trash-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: var(--space-3);
    border-bottom: var(--border-width) solid var(--color-border-light);
    margin-bottom: var(--space-3);
}

.trash-header h3 {
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: var(--font-weight-semibold);
}

.trash-count {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
}

.trash-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    border-bottom: 1px solid var(--color-border-light);
}

.trash-item-info {
    flex: 1;
    min-width: 0;
}

.trash-item-title {
    font-weight: var(--font-weight-medium);
    font-size: var(--text-sm);
    margin-bottom: 2px;
}

.trash-item-preview {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.trash-item-date {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    margin-top: var(--space-1);
}

.trash-item-actions {
    display: flex;
    gap: var(--space-1);
    flex-shrink: 0;
}

.folder-note-date {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    flex-shrink: 0;
}

.folder-note-item.dragging {
    opacity: 0.5;
}

.folder-notes-section {
}
.folder-picker {
    position: fixed;
    z-index: 60;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    max-height: 300px;
    overflow-y: auto;
    padding: var(--space-1) 0;
}

.folder-picker-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: var(--space-1) var(--space-3);
    border: none;
    background: none;
    font-size: var(--text-sm);
    color: var(--color-text-primary);
    cursor: pointer;
}

.folder-picker-item:hover {
    background: var(--color-surface-hover);
}

@media (max-width: 768px) {
    .folder-tree {
        max-height: none;
        padding: var(--space-1) var(--space-2);
    }
}

/* Toast notifications */
.toast {
    position: fixed;
    bottom: var(--space-6);
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-3) var(--space-5);
    font-size: var(--text-sm);
    color: var(--color-text-primary);
    box-shadow: var(--shadow-lg);
    z-index: 10010;
    animation: toast-slide-in 0.3s ease;
    max-width: 400px;
    text-align: center;
}

.toast--error {
    border-left: 3px solid var(--color-danger, #ef4444);
}

.toast--success {
    border-left: 3px solid var(--color-success, #22c55e);
}

/* Image upload toast */
.image-toast {
    position: fixed;
    bottom: var(--space-6);
    right: var(--space-6);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-3) var(--space-4);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    color: var(--color-text-primary);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    z-index: 9999;
    animation: toast-slide-in 0.3s ease;
}

@keyframes toast-slide-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Drag-over indicator for image drop */
.editor.drag-over {
    outline: 2px dashed var(--color-accent);
    outline-offset: -4px;
    border-radius: var(--radius);
}

/* Processing spinner on button */
.btn.processing {
    position: relative;
    color: transparent !important;
}

.btn.processing::after {
    content: '';
    position: absolute;
    inset: 50% auto auto 50%;
    width: 12px;
    height: 12px;
    margin: -6px 0 0 -6px;
    border: 2px solid var(--color-accent);
    border-top-color: transparent;
    border-radius: 50%;
    animation: btn-spin 0.6s linear infinite;
}

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

/* ═══════════════ Version History Modal ═══════════════ */

.versions-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.versions-modal {
    background: var(--bg-primary, #fff);
    border-radius: 12px;
    max-width: 800px;
    width: 90vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.versions-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color, #e0e0e0);
}

.versions-modal-header h3 {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
}

.versions-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    color: var(--text-secondary, #666);
    line-height: 1;
}

.versions-modal-close:hover {
    background: var(--bg-hover, #f0f0f0);
}

.versions-modal-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.versions-sidebar {
    width: 260px;
    flex-shrink: 0;
    border-right: 1px solid var(--border-color, #e0e0e0);
    overflow-y: auto;
}

.versions-list {
    padding: 8px 0;
}

.versions-item {
    padding: 10px 16px;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: background 0.15s;
}

.versions-item:hover {
    background: var(--bg-hover, #f5f5f5);
}

.versions-item.active {
    background: var(--bg-active, #e8f0fe);
    border-left-color: var(--accent, #1a73e8);
}

.versions-item-num {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--accent, #1a73e8);
    margin-right: 6px;
}

.versions-item-date {
    font-size: 0.75rem;
    color: var(--text-secondary, #888);
    display: block;
    margin-top: 2px;
}

.versions-item-preview {
    font-size: 0.8rem;
    color: var(--text-primary, #333);
    display: block;
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}

.versions-empty,
.versions-error {
    padding: 20px 16px;
    color: var(--text-secondary, #888);
    text-align: center;
    font-size: 0.875rem;
}

.versions-diff {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.versions-diff-toolbar {
    padding: 8px 16px;
    border-bottom: 1px solid var(--border-color, #e0e0e0);
    display: flex;
    gap: 16px;
}

.diff-mode-label {
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--text-secondary, #666);
}

.diff-mode-label input {
    margin: 0;
}

.versions-diff-content {
    flex: 1;
    overflow: auto;
    padding: 12px 16px;
    font-family: var(--font-mono, 'JetBrains Mono', monospace);
    font-size: 0.8rem;
    line-height: 1.6;
}

.versions-diff-placeholder {
    color: var(--text-secondary, #999);
    text-align: center;
    padding-top: 60px;
}

.versions-modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border-color, #e0e0e0);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ═══════════════ Diff Styles ═══════════════ */

.diff-unified {
    white-space: pre-wrap;
    word-break: break-word;
}

.diff-line {
    display: flex;
    min-height: 1.5em;
    padding: 0 8px;
}

.diff-line.diff-added {
    background: rgba(0, 200, 100, 0.12);
}

.diff-line.diff-removed {
    background: rgba(255, 80, 80, 0.12);
}

.diff-prefix {
    width: 16px;
    flex-shrink: 0;
    user-select: none;
}

.diff-line.diff-added .diff-prefix {
    color: #0a0;
}

.diff-line.diff-removed .diff-prefix {
    color: #d00;
}

.diff-text {
    flex: 1;
}

/* Side-by-side */

.diff-side-by-side {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 6px;
    overflow: hidden;
}

.diff-column {
    min-width: 0;
}

.diff-column--old {
    border-right: 1px solid var(--border-color, #e0e0e0);
}

.diff-sbs-line {
    padding: 1px 8px;
    min-height: 1.5em;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.75rem;
    line-height: 1.6;
}

.diff-sbs-added {
    background: rgba(0, 200, 100, 0.15);
}

.diff-sbs-removed {
    background: rgba(255, 80, 80, 0.15);
}

.diff-sbs-empty {
    background: var(--bg-secondary, #f9f9f9);
}

/* Dark theme overrides */
@media (prefers-color-scheme: dark) {
    .diff-line.diff-added {
        background: rgba(0, 200, 100, 0.2);
    }
    .diff-line.diff-removed {
        background: rgba(255, 80, 80, 0.2);
    }
    .diff-line.diff-added .diff-prefix { color: #4c4; }
    .diff-line.diff-removed .diff-prefix { color: #f44; }
    .diff-sbs-added { background: rgba(0, 200, 100, 0.2); }
    .diff-sbs-removed { background: rgba(255, 80, 80, 0.2); }
}
