/* ══════════════════════════════════════════════════════
   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 — overlay palette */
#search-bar {
    position: fixed;
    top: 18%;
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--z-dropdown);
    width: 480px;
    max-width: calc(100vw - 32px);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    background: var(--paper-card);
    border-radius: var(--radius-lg);
    box-shadow: 0 12px 40px rgba(0,0,0,0.18);
    border: var(--border-width) solid var(--color-border);
}

.search-bar-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
}

#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;
    padding: var(--space-2) 0;
}

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

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

/* Search dropdown */
.search-dropdown {
    max-height: 360px;
    overflow-y: auto;
    background: var(--color-surface);
    border-top: var(--border-width) solid var(--color-border-light);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    margin: 0;
}

.search-overlay-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: calc(var(--z-dropdown) - 1);
    cursor: pointer;
}

#search-bar .search-bar-row {
    border-bottom: var(--border-width) solid transparent;
    transition: border-color 0.15s;
}

#search-bar.dropdown-visible .search-bar-row {
    border-bottom-color: var(--color-border-light);
}

.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: hidden;
    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: 0 var(--space-8) var(--space-6);
    background: var(--color-bg);
    animation: contentIn var(--transition) var(--ease-out);
}

#editor-toolbar-container {
    flex-shrink: 0;
    background: var(--color-bg);
}

/* ═══ 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);
    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: 0 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: var(--hl-keyword); }

.hljs-string,
.hljs-regexp,
.hljs-addition,
.hljs-attribute,
.hljs-meta .hljs-string { color: var(--hl-string); }

.hljs-number,
.hljs-literal,
.hljs-variable,
.hljs-template-variable,
.hljs-type { color: var(--hl-number); }

.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: var(--hl-function); }

.hljs-attr,
.hljs-params,
.hljs-symbol,
.hljs-bullet,
.hljs-link { color: var(--hl-attr); }

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

.hljs-tag { color: var(--hl-tag); }
.hljs-tag .hljs-name { color: var(--hl-tag-name); }
.hljs-tag .hljs-attr { color: var(--hl-tag-attr); }

.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: 20px;
    height: 20px;
    margin-top: 2px;
    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: var(--accent-text);
    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: var(--accent-text);
    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: var(--accent-text);
    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: var(--z-popover);
    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: 44px;
    height: 44px;
    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);
    min-height: 44px;
}

.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: var(--gold-text);
    font-weight: var(--font-weight-semibold);
}

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

/* ═══ 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;
    min-height: 44px;
}

.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;
    contain: layout style;
}

.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: 44px;
        height: 44px;
        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 {
    background: var(--gold-bg);
}

.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);
    padding: var(--space-4);
    margin-bottom: var(--space-3);
    background: var(--color-surface);
    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);
}

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

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

.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-sans);
}

.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;
    transition: opacity 150ms ease;
}

.editor-toolbar {
    display: flex;
    gap: var(--space-2);
    align-items: center;
    padding: var(--space-2) var(--space-4);
    border-bottom: var(--border-width) solid var(--color-border-light);
    margin-bottom: var(--space-4);
    flex-shrink: 0;
    z-index: 5;
    background: var(--color-bg);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.editor-toolbar::-webkit-scrollbar {
    display: none;
}

.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);
}

.note-date {
    font-size: var(--text-sm);
    color: var(--ink-muted);
    margin-bottom: var(--space-4);
}

.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: 32px;
    height: 32px;
    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);
}

.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;
    }
}

/* ── Skeleton variants ─────────────────────────────── */
.skeleton-folder-item {
    display: flex; align-items: center; gap: var(--space-2);
    padding: var(--space-1-5) var(--space-2); height: 34px;
}
.skeleton-folder-icon { width: 16px; height: 16px; border-radius: var(--radius-sm); }
.skeleton-folder-label { flex: 1; height: 12px; border-radius: var(--radius-sm); }

.skeleton-note-item {
    padding: var(--space-3);
    border-bottom: 1px solid var(--color-border);
    display: flex; flex-direction: column; gap: var(--space-1);
}
.skeleton-note-title { height: 14px; width: 75%; border-radius: var(--radius-sm); }
.skeleton-note-date { height: 10px; width: 40%; border-radius: var(--radius-sm); }
.skeleton-note-snippet { height: 10px; width: 55%; border-radius: var(--radius-sm); }

.skeleton-editor-header { height: 40px; width: 60%; margin-bottom: var(--space-4); border-radius: var(--radius-sm); }
.skeleton-editor-block { height: 16px; margin-bottom: var(--space-3); border-radius: var(--radius-sm); }

.skeleton-calendar-grid {
    display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; max-width: 350px;
}
.skeleton-calendar-cell { aspect-ratio: 1; border-radius: var(--radius-sm); }

.skeleton-search-item {
    display: flex; flex-direction: column; gap: 4px;
    padding: var(--space-2) var(--space-3);
}

.skeleton-heatmap {
    display: grid; grid-template-columns: repeat(52, 10px);
    grid-template-rows: repeat(7, 10px); gap: 2px;
}

.skeleton-progress {
    position: fixed; top: 0; left: 0; height: 2px; z-index: var(--z-tooltip);
    background: var(--color-accent);
    animation: progress-indeterminate 2s ease-in-out infinite;
}

@keyframes progress-indeterminate {
    0% { width: 0; left: 0; }
    50% { width: 40%; left: 30%; }
    100% { width: 0; left: 100%; }
}

.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) var(--space-4);
    font-size: var(--text-base);
    margin-top: var(--space-4);
}

.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;
    margin-bottom: var(--space-4);
}

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

/* ═══ 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);
        padding-top: env(safe-area-inset-top, 0);
    }

    #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;
        padding-top: env(safe-area-inset-top, 0);
        padding-bottom: env(safe-area-inset-bottom, 0);
    }

    #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);
        padding-top: calc(var(--space-4) + env(safe-area-inset-top, 0));
        padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0));
        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;
    }

    #content.editor-hidden ~ #editor-toolbar-container {
        display: none;
    }

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

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

    .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);
    }

    .note-item .preview {
        font-size: var(--text-sm);
    }

    .note-item .meta {
        font-size: var(--text-xs);
    }

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

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

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

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

    /* Tab bar touch targets */
    .tab-close {
        width: 28px;
        height: 28px;
        margin-left: var(--space-2);
    }

    .tab-item {
        padding: var(--space-2) var(--space-3);
        font-size: var(--text-sm);
    }

    /* Folder tree touch targets */
    .folder-tree-item {
        padding: var(--space-2) var(--space-3);
        min-height: 44px;
    }

    .folder-note-item {
        padding: var(--space-2) var(--space-3);
        min-height: 44px;
        font-size: var(--text-sm);
    }

    .folder-toggle {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }

    .folder-tree-trash {
        padding: var(--space-3);
        min-height: 44px;
    }

    /* Reorder buttons touch */
    .reorder-btn {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }

    /* Context menu touch targets */
    .context-menu-item {
        padding: var(--space-4);
        min-height: 44px;
    }

    /* Slash menu touch targets */
    .slash-menu-item {
        padding: 10px 16px;
        min-height: 44px;
    }

    /* Tag remove button */
    .tag-remove {
        width: 24px;
        height: 24px;
        font-size: 18px;
    }

    /* Block add button enlargement */
    .block-gap-btn {
        width: 32px;
        height: 32px;
    }

    /* iOS zoom prevention — all inputs ≥ 16px */
    .form-input,
    .modal-input,
    .folder-rename-input,
    .entry-textarea {
        font-size: 16px;
    }
}

.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-evenly;
        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: 56px;
        min-height: 44px;
        justify-content: center;
        position: relative;
    }

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

    .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);
    }

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

    /* 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;
    /* единственный #modal-overlay — общий confirm/prompt. Он вызывается изнутри
       других модалок, поэтому обязан быть выше них: на --z-modal подтверждение
       восстановления версии оказывалось под оверлеем истории и не кликалось */
    z-index: var(--z-nested-modal);
}

.modal-card,
.modal {
    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);
    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);
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    contain: layout style;
}

.folder-tree-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    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-color-dot {
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.folder-color-picker {
    position: fixed;
    z-index: var(--z-popover);
    background: var(--paper-card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: var(--space-2);
    display: flex;
    gap: var(--space-1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}

.color-dot {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
    transition: transform 0.15s, border-color 0.15s;
}

.color-dot:hover {
    transform: scale(1.2);
}

.color-dot.active {
    border-color: var(--ink);
}

.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;
}

.note-share-icon {
    font-size: 11px;
    margin-left: 4px;
    opacity: 0.5;
}

.btn-ghost.has-shares {
    color: var(--accent);
}

/* ── Trash / Корзина ── */
.folder-tree-trash {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) 0;
    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: var(--z-dropdown);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    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: 767px) {
    .folder-tree {
        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: var(--z-toast);
    animation: toast-slide-in 0.3s ease;
    max-width: 400px;
    text-align: center;
}

.toast--error {
    border-top: 3px solid var(--color-danger);
}

.toast--success {
    border-top: 3px solid var(--color-success);
}

/* 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-sans);
    font-size: var(--text-sm);
    color: var(--color-text-primary);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    z-index: var(--z-toast);
    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: oklch(0 0 0 / 0.5);
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
}

.versions-modal {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    max-width: 800px;
    width: 95vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.versions-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: var(--border-width) solid var(--color-border);
    flex-shrink: 0;
}

.versions-modal-header h3 {
    margin: 0;
    font-size: var(--text-lg);
    font-weight: var(--font-weight-semibold);
}

.versions-modal-close {
    background: none;
    border: none;
    font-size: var(--text-xl);
    cursor: pointer;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    color: var(--color-text-secondary);
    line-height: 1;
}

.versions-modal-close:hover {
    background: var(--color-surface-hover);
}

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

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

.versions-list {
    padding: var(--space-2) 0;
}

.versions-item {
    padding: 10px 16px;
    cursor: pointer;
    background: transparent;
    transition: background 0.15s;
    min-height: 44px;
}

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

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

.versions-item-num {
    font-weight: var(--font-weight-semibold);
    font-size: var(--text-sm);
    color: var(--color-accent);
    margin-right: 6px;
}

.versions-item-date {
    font-size: var(--text-xs);
    color: var(--color-text-secondary);
    display: block;
    margin-top: 2px;
}

.versions-item-preview {
    font-size: var(--text-sm);
    color: var(--color-text-primary);
    display: block;
    margin-top: var(--space-1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}

.versions-empty,
.versions-error {
    padding: var(--space-5) var(--space-4);
    color: var(--color-text-secondary);
    text-align: center;
    font-size: var(--text-sm);
}

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

.versions-diff-toolbar {
    padding: var(--space-2) var(--space-4);
    border-bottom: var(--border-width) solid var(--color-border);
    display: flex;
    gap: var(--space-4);
}

.diff-mode-label {
    font-size: var(--text-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: var(--space-1);
    color: var(--color-text-secondary);
}

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

.versions-diff-content {
    flex: 1;
    overflow: auto;
    padding: var(--space-3) var(--space-4);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    line-height: 1.6;
}

.versions-diff-placeholder {
    color: var(--color-text-secondary);
    text-align: center;
    padding-top: var(--space-12);
}

.versions-modal-footer {
    padding: var(--space-3) var(--space-5);
    border-top: var(--border-width) solid var(--color-border);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
    flex-shrink: 0;
}

/* ── Versions modal mobile (≤600px) single column ── */
@media (max-width: 600px) {
    .versions-modal {
        width: 100vw;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
    }

    .versions-modal-body {
        flex-direction: column;
    }

    .versions-sidebar {
        width: 100%;
        max-height: 120px;
        border-right: none;
        border-bottom: var(--border-width) solid var(--color-border);
        overflow-x: auto;
        overflow-y: hidden;
        white-space: nowrap;
    }

    .versions-list {
        display: flex;
        padding: var(--space-2);
        gap: var(--space-2);
    }

    .versions-item {
        flex-shrink: 0;
        max-width: 160px;
        min-height: auto;
        padding: var(--space-2) var(--space-3);
    }

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

    .versions-item-preview {
        max-width: 140px;
        font-size: var(--text-xs);
    }

    .versions-diff {
        min-height: 200px;
    }

    .versions-modal-overlay {
        padding: 0;
    }
}

/* ═══════════════ 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: var(--diff-added-bg);
}

.diff-line.diff-removed {
    background: var(--diff-removed-bg);
}

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

.diff-line.diff-added .diff-prefix {
    color: var(--diff-added);
}

.diff-line.diff-removed .diff-prefix {
    color: var(--diff-removed);
}

.diff-text {
    flex: 1;
}

/* Side-by-side */

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

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

.diff-column--old {
    border-right: 1px solid var(--line);
}

.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: var(--diff-added-bg);
}

.diff-sbs-removed {
    background: var(--diff-removed-bg);
}

.diff-sbs-empty {
    background: var(--paper-hover);
}

/* Версии — режим «Рендер»: обе версии отрисованы, дифф по блокам.
   Одна сетка парами ячеек, а не две колонки: у отрендеренных блоков разная
   высота, и независимые колонки разъехались бы. */
.diff-rendered {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border: var(--border-width) solid var(--color-border);
    border-radius: 6px;
    overflow: hidden;
}

.diff-rendered-head {
    padding: var(--space-1) var(--space-3);
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    background: var(--color-surface);
    border-bottom: var(--border-width) solid var(--color-border);
}

.diff-rendered-cell {
    padding: var(--space-2) var(--space-3);
    min-width: 0;
    /* .versions-diff-content форсит моноширинный — рендеру нужен шрифт редактора */
    font-family: var(--font-editor);
    font-size: var(--text-base);
    line-height: var(--leading-relaxed);
}

.diff-rendered > :nth-child(odd) {
    border-right: var(--border-width) solid var(--color-border);
}

.diff-rendered-cell--added {
    background: var(--diff-added-bg);
}

.diff-rendered-cell--removed {
    background: var(--diff-removed-bg);
}

.diff-rendered-cell--empty {
    background: var(--color-bg);
}

/* блоки в диффе не редактируются — гасим интерактивность редактора */
.diff-rendered .live-block.viewing:hover {
    background: transparent;
    cursor: default;
}

.diff-rendered .live-block {
    padding: 0;
}

.diff-rendered img {
    max-width: 100%;
    height: auto;
}

/* Dark theme — diff colours handled by tokens */
@media (prefers-color-scheme: dark) {
    .diff-line.diff-added .diff-prefix { color: var(--diff-added); }
    .diff-line.diff-removed .diff-prefix { color: var(--diff-removed); }
}

/* ═══════════════ Admin panel ═══════════════ */
.admin-page { max-width: 1100px; margin: 0 auto; padding: var(--space-6); }
.admin-header { display: flex; align-items: center; gap: var(--space-4); margin-bottom: var(--space-6); }
.admin-title { font-family: var(--font-display); font-size: var(--text-xl); margin: 0; }
.admin-gate { text-align: center; padding: var(--space-8); }

.admin-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--space-4); margin-bottom: var(--space-6); }
.stat-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: var(--space-4); }
.stat-value { font-size: var(--text-xl); font-weight: 600; }
.stat-label { font-size: var(--text-sm); color: var(--color-text-muted); margin-top: var(--space-1); }

.admin-controls { display: flex; gap: var(--space-3); margin-bottom: var(--space-4); flex-wrap: wrap; align-items: center; }
.admin-controls .form-input { max-width: 320px; }

.admin-table-wrap { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.admin-table th, .admin-table td { text-align: left; padding: var(--space-3); border-bottom: 1px solid var(--color-border); vertical-align: top; }
.admin-table th { font-weight: 600; color: var(--color-text-muted); white-space: nowrap; }
.admin-user-name { font-weight: 500; }
.admin-user-sub { font-size: var(--text-xs); color: var(--color-text-muted); }
.admin-muted { color: var(--color-text-muted); }
.admin-actions { display: flex; gap: var(--space-2); white-space: nowrap; }
.admin-loading { padding: var(--space-6); text-align: center; color: var(--color-text-muted); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: var(--text-xs); background: var(--color-border); }
.badge-admin { background: var(--color-accent); color: var(--accent-text); margin-left: var(--space-2); }

.admin-pagination { display: flex; align-items: center; gap: var(--space-4); justify-content: center; margin-top: var(--space-6); }
.admin-page-info { font-size: var(--text-sm); color: var(--color-text-muted); }

/* ── Compact list density ─────────────────────────────── */
body[data-density="compact"] .note-item,
body[data-density="compact"] .folder-note-item,
body[data-density="compact"] .folder-tree-item,
html[data-density="compact"] .note-item,
html[data-density="compact"] .folder-note-item,
html[data-density="compact"] .folder-tree-item {
    padding-top: var(--space-1);
    padding-bottom: var(--space-1);
}

.live-editor, .editor .live-editor { font-family: var(--font-editor); }

/* ── Settings modal ───────────────────────────────────── */
.settings-overlay {
    position: fixed; inset: 0; z-index: var(--z-modal);
    background: oklch(0 0 0 / 0.4); display: none;
    align-items: center; justify-content: center; padding: var(--space-4);
}
.settings-overlay.visible { display: flex; }
.settings-card {
    background: var(--color-surface); border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg); width: 100%; max-width: 520px;
    max-height: 85vh; display: flex; flex-direction: column; overflow: hidden;
}
.settings-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--space-4); border-bottom: 1px solid var(--color-border);
}
.settings-head h3 {
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: var(--font-weight-semibold);
    margin: 0;
}
.settings-tabs {
    display: flex; gap: var(--space-1); padding: var(--space-2) var(--space-4);
    border-bottom: 1px solid var(--color-border); flex-wrap: wrap;
}
.settings-tab {
    border: none; background: none; padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-full); cursor: pointer; color: var(--color-text-secondary);
    font-size: var(--text-sm);
}
.settings-tab.active { background: var(--color-accent-light); color: var(--color-accent); }
.settings-body { padding: var(--space-4); overflow-y: auto; }
.settings-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: var(--space-3); padding: var(--space-3) 0; flex-wrap: wrap;
    border-bottom: 1px solid var(--color-border-light);
}
.settings-row:last-child { border-bottom: none; }
.settings-label { color: var(--color-text-primary); font-size: var(--text-sm); }
.seg-control { display: inline-flex; border: 1px solid var(--color-border); border-radius: var(--radius); overflow: hidden; }
.seg-btn {
    border: none; background: var(--color-surface); padding: var(--space-1) var(--space-3);
    cursor: pointer; font-size: var(--text-sm); color: var(--color-text-secondary);
}
.seg-btn.active { background: var(--color-accent); color: var(--accent-text); }
.settings-hint { color: var(--color-text-muted); font-size: var(--text-xs); margin-top: var(--space-2); }
.pin-form { display: flex; gap: var(--space-2); margin: var(--space-2) 0; flex-wrap: wrap; }
.pin-form .form-input { max-width: 180px; }
.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
    position: absolute; inset: 0; background: var(--color-border);
    border-radius: var(--radius-full); transition: var(--transition-fast); cursor: pointer;
}
.switch .slider::before {
    content: ""; position: absolute; height: 16px; width: 16px; left: 3px; top: 3px;
    background: var(--color-surface); border-radius: 50%; transition: var(--transition-fast);
}
.switch input:checked + .slider { background: var(--color-accent); }
.switch input:checked + .slider::before { transform: translateX(18px); }
.switch input:disabled + .slider { opacity: 0.5; cursor: not-allowed; }

/* ── Lock overlay ─────────────────────────────────────── */
.lock-overlay {
    position: fixed; inset: 0; z-index: var(--z-nested-modal);
    background: var(--color-bg); display: none;
    align-items: center; justify-content: center;
}
.lock-overlay.visible { display: flex; }
.lock-card { text-align: center; padding: var(--space-8); max-width: 320px; }
.lock-icon { width: 48px; height: 48px; color: var(--color-accent); margin-bottom: var(--space-4); }
.lock-card h2 { font-family: var(--font-display); margin-bottom: var(--space-2); }
.lock-card p { color: var(--color-text-secondary); margin-bottom: var(--space-6); }

.lock-dots {
    display: flex; justify-content: center; gap: var(--space-4);
    margin-bottom: var(--space-6);
}
.lock-dot {
    width: 14px; height: 14px;
    border-radius: 50%;
    border: 2px solid var(--color-border);
    background: transparent;
    transition: background var(--transition-fast), border-color var(--transition-fast);
}
.lock-dot.filled {
    background: var(--color-accent);
    border-color: var(--color-accent);
}

.lock-keypad {
    display: flex; flex-direction: column; align-items: center; gap: var(--space-2);
    margin-bottom: var(--space-5);
}
.lock-keypad-row {
    display: flex; gap: var(--space-2);
}
.lock-key {
    width: 56px; height: 48px;
    font-family: var(--font-mono); font-size: var(--text-xl);
    border: 1px solid var(--color-border); border-radius: var(--radius);
    background: var(--color-surface); color: var(--color-text-primary);
    cursor: pointer;
    transition: background var(--transition-fast), transform var(--transition-fast);
    user-select: none;
}
.lock-key:hover { background: var(--color-surface-hover); }
.lock-key:active { transform: scale(0.94); background: var(--color-surface-active); }
.lock-key:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }

.lock-key-del {
    font-size: var(--text-lg);
    color: var(--color-text-secondary);
}
.lock-key-enter {
    background: var(--color-accent);
    color: var(--color-accent-text);
    border-color: var(--color-accent);
    font-weight: 600;
}
.lock-key-enter:hover { background: var(--color-accent-hover); }
.lock-key-enter:disabled {
    opacity: 0.4; cursor: default;
    background: var(--color-accent);
}
.lock-key-enter:disabled:hover { background: var(--color-accent); }

.lock-error { color: var(--color-danger); min-height: 20px; margin-bottom: var(--space-2); font-size: var(--text-sm); }

.lock-card.shake { animation: lock-shake 0.4s; }
@keyframes lock-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    75% { transform: translateX(8px); }
}

/* ═══ Touch device hover alternatives ════════════════ */
@media (pointer: coarse) {
    .touch-device .live-block.viewing:hover {
        background: transparent;
    }

    .touch-device .note-item:hover {
        transform: none;
    }

    .touch-device .note-item:hover .drag-handle {
        opacity: 0;
    }

    .touch-device .live-block:hover .block-drag-handle {
        opacity: 0;
    }

    .touch-device .live-block:hover .live-block-delete-btn {
        opacity: 0;
    }

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

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

    .touch-device .block-gap:hover {
        height: 2px;
    }

    .touch-device .block-gap:hover .block-gap-btn {
        opacity: 0;
    }

    .touch-device .tab-close:hover {
        background: transparent;
        color: var(--color-text-muted);
    }
}

/* ── Tab bar scroll indicator ── */
@media (max-width: 767px) {
    .tab-bar {
        position: relative;
    }

    .tab-bar::after {
        content: '';
        position: sticky;
        right: 0;
        top: 0;
        bottom: 0;
        width: 24px;
        background: linear-gradient(to right, transparent, var(--color-surface));
        flex-shrink: 0;
        pointer-events: none;
        z-index: 1;
    }
}

/* ── Overscroll behavior for modals ── */
.modal-overlay,
.settings-overlay,
.versions-modal-overlay,
.lock-overlay {
    overscroll-behavior: contain;
}

/* ═══ FOCUS MODE ══════════════════════════════════════ */
body.focus-mode #sidebar {
    display: none;
}

body.focus-mode #header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
}

body.focus-mode #header:hover,
body.focus-mode #header:focus-within {
    transform: translateY(0);
}

.focus-exit-btn {
    display: none;
}

body.focus-mode .focus-exit-btn {
    display: inline-flex;
    position: fixed;
    top: 8px;
    right: 8px;
    z-index: var(--z-overlay);
    background: var(--paper-card);
    border-radius: var(--radius);
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

body.focus-mode #app {
    justify-content: center;
}

body.focus-mode #editor-area {
    max-width: 720px;
    transition: max-width 0.3s ease;
}

body.focus-mode #content {
    max-width: none;
}

body.focus-mode #tab-bar {
    max-width: 720px;
    margin: 0 auto;
}

body.focus-mode #editor-toolbar-container {
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
}

/* ═══ QUICK CAPTURE ══════════════════════════════════════ */
#quick-capture-fab {
    position: fixed;
    bottom: var(--space-6);
    right: var(--space-6);
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-text);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0,0,0,0.18);
    z-index: var(--z-overlay);
    transition: transform 0.2s, box-shadow 0.2s;
}

#quick-capture-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}

#quick-capture-fab.hidden {
    display: none;
}

@media (max-width: 767px) {
    #quick-capture-fab {
        display: none;
    }
}

.quick-capture-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: qc-fade-in 0.15s ease;
}

@keyframes qc-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.quick-capture-card {
    background: var(--paper-card);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    width: 480px;
    max-width: calc(100vw - var(--space-8));
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    box-shadow: 0 12px 36px rgba(0,0,0,0.2);
}

.quick-capture-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.quick-capture-head h3 {
    margin: 0;
    font-size: var(--text-lg);
    font-weight: var(--font-weight-semibold);
}

.quick-capture-textarea {
    resize: vertical;
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: 1.6;
    min-height: 120px;
}

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

body.qc-open #quick-capture-fab {
    display: none;
}

/* ═══ FORMAT TOOLBAR ══════════════════════════════════════ */
.format-toolbar {
    position: fixed;
    z-index: var(--z-dropdown);
    background: var(--paper-card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: var(--space-1);
    display: flex;
    align-items: center;
    gap: 2px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.14);
    opacity: 0;
    transform: translateY(4px);
    pointer-events: none;
    transition: opacity 0.15s, transform 0.15s;
}

.format-toolbar.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.fmt-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink);
    font-size: var(--text-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.1s;
}

.fmt-btn:hover {
    background: var(--paper-hover);
}

.fmt-sep {
    width: 1px;
    height: 20px;
    background: var(--line);
    margin: 0 var(--space-1);
}

.admin-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--color-border);
    margin-bottom: var(--space-6);
}
.admin-tab {
    padding: var(--space-3) var(--space-5);
    border: none;
    background: none;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--color-text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s, border-color 0.15s;
}
.admin-tab:hover { color: var(--ink); }
.admin-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}
.admin-tab-panel { display: none; }
.admin-tab-panel.active { display: block; }

.error-type-badge {
    display: inline-flex;
    padding: 2px var(--space-2);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    font-weight: 500;
    white-space: nowrap;
}
.error-type-badge.error { background: var(--danger); color: var(--paper); }
.error-type-badge.rejection { background: var(--gold); color: var(--ink); }
.error-type-badge.api_error { background: var(--accent); color: var(--paper); }

.log-row { cursor: pointer; }
.log-row:hover { background: var(--paper-hover); }
.log-msg { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.log-detail td { padding: 0; }
.log-detail-content {
    padding: var(--space-4);
    background: var(--paper-hover);
    border-radius: var(--radius-sm);
    margin: var(--space-2) 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}
.log-detail-section { font-size: var(--text-sm); }
.stack-trace {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    white-space: pre-wrap;
    overflow-x: auto;
    background: var(--paper);
    padding: var(--space-3);
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    margin-top: var(--space-1);
    max-height: 300px;
    overflow-y: auto;
}
.log-sub { margin-top: var(--space-1); }
.log-sub th { padding: var(--space-1) var(--space-3); }
.log-sub td { padding: var(--space-1) var(--space-3); border-bottom: none; }

/* ── Sync indicator ─────────────────────────────────── */
.sync-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
}
.sync-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.sync-dot.online { background: var(--success); }
.sync-dot.offline { background: var(--gold); }
.sync-dot.error { background: var(--danger); }

.sync-pending {
    font-size: var(--text-xs);
    background: var(--accent);
    color: var(--paper);
    border-radius: 50%;
    min-width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.sync-pending.hidden { display: none; }

/* ═══ IMPORT MODAL ══════════════════════════════════════ */
.import-overlay {
    position: fixed; inset: 0; z-index: var(--z-modal);
    background: rgba(0,0,0,0.4); display: flex;
    align-items: center; justify-content: center; padding: var(--space-4);
}
.import-card {
    background: var(--paper-card); border-radius: var(--radius-lg);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-lg); width: 100%; max-width: 500px;
    max-height: 85vh; display: flex; flex-direction: column; overflow: hidden;
}
.import-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--space-4); border-bottom: 1px solid var(--line);
}
.import-head h3 { margin: 0; font-size: var(--text-lg); }
.import-dropzone {
    margin: var(--space-4); padding: var(--space-8);
    border: 2px dashed var(--line); border-radius: var(--radius-md);
    text-align: center; color: var(--ink-muted); transition: border-color 0.2s;
}
.import-dropzone.dragover { border-color: var(--accent); background: var(--accent-bg); }
.import-bar-bg {
    margin: var(--space-3) var(--space-4); height: 6px;
    background: var(--paper-hover); border-radius: 3px; overflow: hidden;
}
.import-bar-fill {
    height: 100%; background: var(--accent); border-radius: 3px;
    transition: width 0.3s;
}
.import-errors { margin: 0 var(--space-4); font-size: var(--text-xs); color: var(--danger); list-style: none; padding: 0; }
.import-errors li { margin-bottom: 2px; }
.import-actions { padding: var(--space-4); display: flex; justify-content: flex-end; }

.sort-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: var(--color-surface);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-popover);
    min-width: 180px;
    padding: var(--space-1);
}

.sort-dropdown-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: var(--text-xs);
    color: var(--color-text);
    white-space: nowrap;
    transition: background var(--transition-fast);
}

.sort-dropdown-item:hover {
    background: var(--color-surface-hover);
}

.sort-dropdown-item.active {
    color: var(--color-accent);
    font-weight: var(--font-weight-medium);
}

.sort-dropdown-item .sort-check {
    font-size: 12px;
    margin-right: var(--space-2);
}

.sort-dropdown-item .sort-dir {
    font-size: 11px;
    color: var(--color-text-muted);
    margin-left: var(--space-2);
}

.sort-dropdown-item.active .sort-dir {
    color: var(--color-accent);
}

.sidebar-header {
    position: relative;
}

body[data-sort-mode]:not([data-sort-mode="manual"]) .drag-handle {
    display: none;
}
body[data-sort-mode]:not([data-sort-mode="manual"]) .reorder-btns {
    display: none;
}

/* ═══════════════ Help page ═══════════════ */
.help-page {
    max-width: 1060px;
    margin: 0 auto;
    padding: var(--space-6);
}
.help-header {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}
.help-title {
    font-family: var(--font-display);
    font-size: var(--text-xl);
    margin: 0;
}
.help-layout {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: var(--space-8);
    align-items: start;
}
.help-toc {
    position: sticky;
    top: var(--space-6);
}
.help-toc ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.help-toc-link {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius);
    border-left: 2px solid transparent;
    color: var(--color-text-muted);
    font-size: var(--text-sm);
    text-decoration: none;
    transition: color var(--transition-fast), background var(--transition-fast);
}
.help-toc-link:hover {
    color: var(--color-text-primary);
    background: var(--color-surface-hover);
}
.help-toc-link.active {
    color: var(--color-accent);
    border-left-color: var(--color-accent);
    font-weight: var(--font-weight-medium);
    background: var(--color-surface);
}
.help-content {
    max-width: var(--content-max-width);
    min-width: 0;
}
.help-section {
    scroll-margin-top: var(--space-6);
    padding: var(--space-6);
    margin-bottom: var(--space-6);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    content-visibility: auto;
    contain-intrinsic-size: auto 300px;
}
.help-section h2 {
    font-family: var(--font-display);
    font-size: var(--text-lg);
    margin: 0 0 var(--space-4);
    padding-bottom: var(--space-3);
    border-bottom: 1px solid var(--color-border);
}
.help-section h3 {
    font-size: var(--text-base);
    font-weight: var(--font-weight-semibold);
    margin: var(--space-5) 0 var(--space-2);
}
.help-section p {
    margin: 0 0 var(--space-3);
    line-height: 1.65;
    color: var(--color-text-primary);
}
.help-section ul {
    margin: 0 0 var(--space-3);
    padding-left: var(--space-5);
    line-height: 1.65;
}
.help-section li {
    margin-bottom: var(--space-1);
}
.help-section code {
    font-family: var(--font-mono);
    font-size: 0.85em;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 1px 5px;
    white-space: nowrap;
}
.help-section kbd {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 0.8em;
    line-height: 1.4;
    padding: 1px 6px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-bottom-width: 2px;
    border-radius: var(--radius-sm);
    white-space: nowrap;
}
.help-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
    margin: 0 0 var(--space-3);
}
.help-table th,
.help-table td {
    text-align: left;
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--color-border);
    vertical-align: top;
}
.help-table th {
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-muted);
    white-space: nowrap;
}
.help-note {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
}

@media (max-width: 900px) {
    .help-page {
        padding: var(--space-4);
    }
    .help-layout {
        display: block;
    }
    .help-toc {
        position: sticky;
        top: 0;
        z-index: var(--z-header);
        margin: 0 calc(-1 * var(--space-4)) var(--space-4);
        padding: var(--space-2) var(--space-4);
        background: var(--color-bg);
        border-bottom: 1px solid var(--color-border);
    }
    .help-toc ul {
        flex-direction: row;
        gap: var(--space-2);
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .help-toc ul::-webkit-scrollbar {
        display: none;
    }
    .help-toc-link {
        flex: 0 0 auto;
        border: 1px solid var(--color-border);
        border-radius: 999px;
        padding: var(--space-2) var(--space-4);
        background: var(--color-surface);
        white-space: nowrap;
    }
    .help-toc-link.active {
        border-color: var(--color-accent);
        background: var(--color-surface);
    }
    .help-section {
        padding: var(--space-4);
        scroll-margin-top: 72px;
    }
    .help-table th,
    .help-table td {
        padding: var(--space-2);
    }
    .help-section code {
        white-space: normal;
        word-break: break-word;
    }
}

/* Медиа-блоки: аудио, видео и фасад эмбеда */
.media-audio,
.media-video,
.media-embed-box {
    margin: var(--space-3) 0;
    padding: var(--space-2);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

.media-audio audio,
.media-video video {
    width: 100%;
    display: block;
    /* браузер сам перекрашивает нативные контролы под тему */
    color-scheme: light dark;
}

.media-video video,
.media-iframe {
    aspect-ratio: 16 / 9;
    width: 100%;
    border: 0;
    border-radius: var(--radius-sm);
}

.media-facade {
    width: 100%;
    aspect-ratio: 16 / 9;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    color: var(--color-text-primary);
    background: var(--color-surface-hover);
    border: 1px dashed var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    /* минимальная кликабельная область — требование мобильной вёрстки проекта */
    min-height: 44px;
}

.media-facade:hover {
    background: var(--color-surface-active);
}

.media-caption {
    display: flex;
    justify-content: space-between;
    gap: var(--space-2);
    margin-top: var(--space-1);
    font-size: 0.85em;
    color: var(--color-text-secondary);
}

/* домен-источник: читатель должен видеть, на какой хост уйдёт запрос */
.media-host {
    font-family: var(--font-mono);
    opacity: 0.75;
}

/* Блок в состоянии загрузки аудио: полоса прогресса по --upload-pct */
.live-block[data-uploading]::after {
    content: 'Загрузка аудио…';
    display: block;
    padding: var(--space-2);
    font-size: 0.85em;
    color: var(--color-text-secondary);
    background: linear-gradient(to right,
        var(--color-surface-hover) var(--upload-pct, 0%),
        var(--color-surface) var(--upload-pct, 0%));
    border: 1px dashed var(--color-border);
    border-radius: var(--radius-sm);
}
