:root {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-sidebar: #0f172a;
    --bg-sidebar-hover: #1e293b;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-sidebar: #94a3b8;
    --text-sidebar-active: #f1f5f9;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.12);
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: rgba(99, 102, 241, 0.1);
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #22c55e;
    --success-hover: #16a34a;
    --ok-bg: #10b981;
    --editor-bg: #fafbfc;
}

body.dark-theme {
    --bg-primary: #0f1115;
    --bg-secondary: #1a1d24;
    --bg-card: #1e2229;
    --bg-sidebar: #0d0f14;
    --bg-sidebar-hover: #1a1d24;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-sidebar: #64748b;
    --text-sidebar-active: #f1f5f9;
    --border-color: #2d3139;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.4);
    --primary-light: rgba(99, 102, 241, 0.15);
    --editor-bg: #15171e;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Разрешить выделение в редакторах и полях ввода */
input,
textarea,
[contenteditable="true"],
.note-editor,
#noteEditor,
.input-full,
.color-input-full,
.search-box input,
.auth-card input,
.add-item-form input[type="text"] {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
}

/* Auth pages */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

body.dark-theme.auth-page {
    background: linear-gradient(135deg, #1a1c23 0%, #2d3436 100%);
}

.auth-container {
    width: 100%;
    max-width: 420px;
    padding: 20px;
}

.auth-card {
    background: var(--bg-card);
    padding: 45px 40px;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.auth-logo {
    display: flex;
    justify-content: center;
    margin-bottom: 15px;
}

.auth-logo-icon {
    width: 48px;
    height: 48px;
    filter: brightness(0) invert(0.4) sepia(1) hue-rotate(220deg) saturate(3);
}

.auth-card h1 {
    text-align: center;
    margin-bottom: 8px;
    font-size: 2.8rem;
}

.auth-card h2 {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 30px;
    font-weight: 400;
    font-size: 1.1rem;
}

.auth-card form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group-with-hint {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group-with-hint label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group-with-hint .hint {
    font-size: 11px;
    color: var(--text-secondary);
    font-style: italic;
}

.password-strength {
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 4px;
}

.password-strength .strength-bar {
    height: 100%;
    width: 0%;
    transition: all 0.3s;
    border-radius: 2px;
}

.password-strength .strength-bar.weak {
    width: 33%;
    background: var(--danger);
}

.password-strength .strength-bar.medium {
    width: 66%;
    background: #f59e0b;
}

.password-strength .strength-bar.strong {
    width: 100%;
    background: var(--success);
}

.auth-card input {
    padding: 14px 18px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-size: 15px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: all 0.2s;
}

.auth-card input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-light);
}

.auth-card button {
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.auth-card button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.auth-card .error {
    color: var(--danger);
    text-align: center;
    min-height: 20px;
    font-size: 14px;
}

.auth-card p {
    text-align: center;
    color: var(--text-secondary);
    margin-top: 24px;
    font-size: 14px;
}

.auth-card a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

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

/* App Container */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Mobile Menu Toggle */
.menu-toggle {
    display: none;
    position: fixed;
    top: 10px;
    left: 15px;
    z-index: 200;
    background: var(--bg-sidebar);
    border: none;
    border-radius: 10px;
    width: 44px;
    height: 44px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    box-shadow: var(--shadow-lg);
}

.menu-toggle span {
    color: white;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    z-index: 250;
    transition: transform 0.3s ease;
    font-family: 'JetBrains Mono', monospace;
}

.sidebar-header {
    padding: 17px 24px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 32px;
    height: 32px;
    filter: brightness(0) invert(1);
}

.sidebar-header h1 {
    color: white;
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin: 0;
}

.btn-create-note {
    margin: 20px 16px;
    padding: 14px 20px;
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.2s;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn-create-note .btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-create-note .btn-icon .menu-icon {
    width: 18px;
    height: 18px;
    filter: brightness(0) invert(1);
}

.btn-create-note:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.sidebar-nav {
    padding: 8px 12px;
}

.nav-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    background: transparent;
    border: none;
    border-radius: 10px;
    color: var(--text-sidebar);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
    text-align: left;
    margin-bottom: 4px;
}

.nav-btn:hover {
    background: var(--bg-sidebar-hover);
    color: var(--text-sidebar-active);
}

.nav-btn.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 500;
}

.nav-icon {
    font-size: 18px;
    width: 24px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-icon .menu-icon {
    width: 18px;
    height: 18px;
    filter: brightness(0) invert(0.6);
    transition: filter 0.2s;
}

.nav-btn:hover .menu-icon {
    filter: brightness(0) invert(1);
}

.nav-btn.active .menu-icon {
    filter: brightness(0) invert(0.4) sepia(1) hue-rotate(220deg) saturate(3);
}

/* Тёмная тема */
body.dark-theme .nav-icon .menu-icon {
    filter: brightness(0) invert(0.7);
}

body.dark-theme .nav-btn:hover .menu-icon {
    filter: brightness(0) invert(0.9);
}

body.dark-theme .nav-btn.active .menu-icon {
    filter: brightness(0) invert(0.7) sepia(1) hue-rotate(220deg) saturate(2);
}

.sidebar-section {
    padding: 20px 16px 10px;
    border-top: 1px solid rgba(255,255,255,0.08);
    margin-top: 10px;
}

.section-title {
    color: var(--text-sidebar);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 0 12px;
    margin-bottom: 8px;
    display: block;
    font-weight: 600;
}

.sidebar-categories {
    display: flex;
    flex-direction: column;
    max-height: 400px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 4px;
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
    transition: scrollbar-color 0.2s;
}

.sidebar-categories:hover {
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

/* Скроллбар для категорий - появляется только при наведении */
.sidebar-categories::-webkit-scrollbar {
    width: 4px;
}

.sidebar-categories::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-categories::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 2px;
    transition: background 0.2s;
}

.sidebar-categories:hover::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
}

.sidebar-categories::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

.sidebar-category {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-sidebar);
    font-size: 14px;
}

.sidebar-category:hover {
    background: var(--bg-sidebar-hover);
    color: var(--text-sidebar-active);
}

.sidebar-category.active {
    background: var(--primary-light);
    color: var(--primary);
}

.sidebar-category .cat-count {
    font-size: 11px;
    background: rgba(255,255,255,0.1);
    padding: 2px 8px;
    border-radius: 10px;
}

.sidebar-category-ghost {
    opacity: 0.4;
    background: var(--primary-light);
    border: 2px dashed var(--primary);
}

.sidebar-category-drag {
    background: var(--bg-sidebar-hover);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    cursor: grabbing;
}

.sidebar-footer {
    margin-top: auto;
    padding: 16px;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-footer-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.theme-btn {
    width: 40px;
    padding: 0;
    margin-top: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    cursor: pointer;
    border-radius: 10px;
}

.theme-btn:hover {
    background: transparent;
}

.theme-icon {
    width: 22px;
    height: 22px;
    filter: brightness(0) invert(0.7);
    transition: filter 0.2s;
}

.theme-btn:hover .theme-icon {
    filter: brightness(0) invert(1);
}

.user-logout-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.username {
    color: white;
    font-weight: 500;
    font-size: 14px;
}

.btn-logout {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: transparent;
    border-radius: 10px;
    transition: all 0.2s;
}

.btn-logout:hover {
    background: rgba(239, 68, 68, 0.1);
}

.logout-icon {
    width: 20px;
    height: 20px;
    filter: brightness(0) invert(0.3) sepia(1) hue-rotate(320deg) saturate(2);
    transition: filter 0.2s;
}

.btn-logout:hover .logout-icon {
    filter: brightness(0) invert(0.2) sepia(1) hue-rotate(320deg) saturate(3);
}

/* Main Content */
.main-content {
    margin-left: 280px;
    flex: 1;
    padding: 30px 40px;
    transition: margin-left 0.35s cubic-bezier(0.4, 0, 0.2, 1) 0.1s;
    will-change: margin-left;
}

.main-content.with-editor {
    margin-left: 0;
}

.top-header {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    margin-bottom: 30px;
    position: relative;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
    width: 100%;
    max-width: 500px;
}

.search-wrapper {
    width: 100%;
}

.search-box {
    position: relative;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    border: none;
    border-bottom: 1px solid var(--border-color);
    transition: all 0.2s;
    display: flex;
    align-items: center;
}

.search-box:focus-within {
    border-bottom-color: var(--primary);
}

.search-icon-img {
    width: 18px;
    height: 18px;
    margin-right: 10px;
    filter: brightness(0) invert(0.5);
    flex-shrink: 0;
}

.search-box input {
    width: 100%;
    padding: 10px 0;
    border: none;
    border-radius: 0;
    font-size: 14px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 400;
    background: transparent;
    color: var(--text-primary);
    letter-spacing: 0.3px;
}

.search-box input:focus {
    outline: none;
}

.search-box input::placeholder {
    color: var(--text-secondary);
}

/* Notes Grid */
.notes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: grid-template-columns;
}

.note-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1), border-color 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    max-height: 200px;
    border: 1px solid var(--border-color);
    position: relative;
    touch-action: none;
    will-change: transform, box-shadow, border-color;
}

.note-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}

.note-card-ghost {
    opacity: 0.4;
    background: var(--bg-primary);
    border: 2px dashed var(--primary);
}

.note-card-drag {
    transform: scale(1.02);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    cursor: grabbing;
}

.note-card .note-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.note-card .note-favorite-icon {
    color: #fbbf24;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.note-card .note-favorite-icon svg {
    width: 14px;
    height: 14px;
    fill: #fbbf24;
}

.note-card .note-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.note-card .note-content {
    color: var(--text-secondary);
    font-size: 0.8rem;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    flex-grow: 1;
}

.note-card .note-meta {
    margin-top: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.note-card .note-category {
    background: var(--bg-primary);
    padding: 3px 8px;
    border-radius: 8px;
    font-size: 0.7rem;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.note-card .note-tag {
    padding: 3px 8px;
    border-radius: 8px;
    font-size: 0.7rem;
    color: white;
}

.note-card .note-date {
    font-size: 0.68rem;
    color: var(--text-secondary);
    margin-top: 8px;
}

.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-secondary);
    grid-column: 1 / -1;
}

.empty-state h2 {
    font-size: 1.4rem;
    margin-bottom: 10px;
}

/* Editor Panel */
.editor-panel {
    position: fixed;
    top: 0;
    right: -100%;
    width: calc(100% - 280px);
    max-width: 1000px;
    height: 100vh;
    background: var(--bg-card);
    box-shadow: -10px 0 50px rgba(0, 0, 0, 0.15);
    z-index: 600;
    transition: right 0.35s cubic-bezier(0.4, 0, 0.2, 1), width 0.35s cubic-bezier(0.4, 0, 0.2, 1), max-width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    will-change: right, width, max-width;
}

.editor-panel.active {
    right: 0;
}

/* Когда сайдбар открыт - редактор на всю оставшуюся ширину */
.editor-panel.with-sidebar {
    width: calc(100% - 280px);
    max-width: calc(100% - 280px);
}

/* Когда сайдбар скрыт (на мобильных или свёрнут) */
.editor-panel:not(.with-sidebar) {
    width: 100%;
    max-width: 100%;
}

@media (max-width: 900px) {
    .editor-panel {
        width: 100%;
        max-width: 100%;
    }
    
    .editor-panel.with-sidebar {
        width: 100%;
        max-width: 100%;
    }
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.editor-title {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.btn-back {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    width: 38px;
    height: 38px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    transition: all 0.2s;
}

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

.editor-title-input {
    flex: 1;
    border: none;
    font-size: 20px;
    font-weight: 600;
    background: transparent;
    color: var(--text-primary);
    padding: 8px 0;
}

.editor-title-input:focus {
    outline: none;
}

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

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

.favorite-checkbox-label {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-secondary);
    position: relative;
}

.favorite-checkbox-label:hover {
    border-color: #fbbf24;
    color: #fbbf24;
}

.favorite-checkbox {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.favorite-checkbox:checked + svg {
    fill: #fbbf24;
    stroke: #fbbf24;
}

.favorite-checkbox-label:hover svg {
    fill: #fbbf24;
    stroke: #fbbf24;
}

.btn-delete-small {
    background: transparent;
    border: 1px solid var(--border-color);
    width: 38px;
    height: 38px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.btn-delete-small:hover {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.btn-ok {
    background: linear-gradient(135deg, var(--success), var(--success-hover));
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-ok:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
}

/* Editor Toolbar - Minimalist Design */
.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 0;
    padding: 10px 15px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    flex-wrap: nowrap;
    overflow-x: auto;
}

.toolbar-group {
    display: flex;
    gap: 2px;
    padding: 0 8px;
    border-right: 1px solid var(--border-color);
}

.toolbar-group:last-child {
    border-right: none;
}

.toolbar-btn {
    width: 32px;
    height: 32px;
    border: 1px solid transparent;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.toolbar-btn:hover {
    background: var(--bg-secondary);
    color: var(--primary);
    border-color: var(--border-color);
}

.toolbar-btn:active {
    transform: scale(0.95);
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background: var(--border-color);
    margin: 0 4px;
    flex-shrink: 0;
}

.toolbar-btn:hover {
    background: var(--bg-secondary);
    color: var(--primary);
    border-color: var(--border-color);
}

.toolbar-btn:active {
    transform: scale(0.95);
}

/* Editor Body */

.color-picker-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
}

.color-picker-wrapper input[type="color"] {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    padding: 0;
    background: none;
    transition: transform 0.2s;
}

.color-picker-wrapper input[type="color"]:hover {
    transform: scale(1.05);
}

.color-picker-label {
    position: absolute;
    top: 50%;
    left: 12px;
    transform: translateY(-50%);
    font-size: 16px;
    font-weight: 700;
    pointer-events: none;
    color: var(--text-primary);
    z-index: 2;
}

.color-picker-label.highlight {
    font-size: 14px;
    left: 13px;
}

.color-apply-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: var(--success);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.3);
}

.color-apply-btn:hover {
    background: var(--success-hover);
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(34, 197, 94, 0.4);
}

/* Modal for editing */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    border-radius: 16px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.modal-small {
    max-width: 450px;
}

.modal-content.modal-small {
    max-width: 450px;
}

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

.modal-header h2 {
    font-size: 1.3rem;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s;
}

.close-btn:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.modal-body {
    padding: 25px;
}

.modal-footer {
    padding: 20px 25px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.modal-actions {
    display: flex;
    gap: 10px;
}

/* Modal form styles */
.modal-body .form-group-with-hint {
    margin-bottom: 20px;
}

.modal-body .form-group-with-hint:last-child {
    margin-bottom: 0;
}

.modal-body .form-group-with-hint label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.modal-body .input-full {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: all 0.2s;
    font-family: inherit;
}

.modal-body .input-full:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.modal-body .input-full::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

.modal-body .input-full[type="password"] {
    letter-spacing: 2px;
}

.modal-body textarea.input-full {
    resize: vertical;
    min-height: 150px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    line-height: 1.6;
}

/* Trash modal styles */
.trash-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.trash-info {
    color: var(--text-secondary);
    font-size: 14px;
    margin: 0;
}

.btn-clear-trash {
    background: var(--danger);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-clear-trash:hover {
    background: var(--danger-hover);
    transform: translateY(-1px);
}

.trash-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 500px;
    overflow-y: auto;
}

.trash-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: var(--bg-primary);
    border-radius: 10px;
    border: 1px solid var(--border-color);
    transition: all 0.2s;
}

.trash-item:hover {
    background: var(--bg-secondary);
    box-shadow: var(--shadow);
}

.trash-item-content {
    flex: 1;
}

.trash-item-title {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 5px;
}

.trash-item-meta {
    display: flex;
    gap: 10px;
    align-items: center;
    font-size: 12px;
    color: var(--text-secondary);
}

.trash-item-category {
    background: var(--bg-secondary);
    padding: 3px 8px;
    border-radius: 6px;
}

.trash-item-tags {
    display: flex;
    gap: 5px;
}

.trash-item-tag {
    padding: 2px 6px;
    border-radius: 6px;
    font-size: 11px;
    color: white;
}

.trash-item-date {
    color: var(--danger);
    font-size: 12px;
}

.trash-item-actions {
    display: flex;
    gap: 8px;
}

.trash-item-actions button {
    padding: 8px 12px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
}

.btn-restore {
    background: var(--success);
    color: white;
}

.btn-restore:hover {
    background: var(--success-hover);
    transform: translateY(-1px);
}

.btn-delete-permanent {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-delete-permanent:hover {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.empty-trash {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.empty-trash svg {
    width: 64px;
    height: 64px;
    margin-bottom: 15px;
    opacity: 0.3;
}

/* Edit form styles */
.edit-form-row {
    display: flex;
    gap: 15px;
    align-items: flex-start;
}

.edit-form-group {
    display: flex;
    flex-direction: column;
}

.edit-form-group:first-child {
    flex: 4;
}

.edit-form-group:last-child {
    flex: 1;
}

.edit-form-group .color-input-full {
    width: 100%;
    height: 44px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    padding: 4px;
    background: var(--bg-secondary);
    transition: border-color 0.2s;
}

.edit-form-group .color-input-full:focus {
    outline: none;
    border-color: var(--primary);
}

/* Modal buttons */
.btn-modal-secondary {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

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

.btn-modal-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s;
    box-shadow: 0 2px 10px rgba(99, 102, 241, 0.3);
}

.btn-modal-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

#editItemModal .modal-content {
    max-width: 450px;
}

/* Editor Body */
.editor-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    order: 2;
}

.editor-header {
    order: 1;
}

.editor-meta {
    order: 3;
}

.note-editor {
    flex: 1;
    padding: 30px 40px;
    background: var(--editor-bg);
    color: var(--text-primary);
    font-size: 16px;
    line-height: 1.7;
    overflow-y: auto;
    font-family: 'Inter', sans-serif;
}

.note-editor:focus {
    outline: none;
}

.note-editor:empty:before {
    content: attr(placeholder);
    color: var(--text-secondary);
    opacity: 0.5;
}

.note-editor h1, .note-editor h2, .note-editor h3 {
    margin: 24px 0 12px 0;
    color: var(--text-primary);
    font-weight: 600;
}

.note-editor h1 { font-size: 2em; }
.note-editor h2 { font-size: 1.6em; }
.note-editor h3 { font-size: 1.3em; }

.note-editor p {
    margin: 12px 0;
}

.note-editor pre {
    background: var(--bg-sidebar);
    color: #e2e8f0;
    padding: 18px;
    padding-top: 35px;
    border-radius: 10px;
    overflow-x: auto;
    font-family: 'JetBrains Mono', 'Consolas', monospace;
    font-size: 13px;
    border: 1px solid var(--border-color);
    margin: 15px 0;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    word-break: break-all;
    position: relative;
}

.note-editor pre .code-copy-btn {
    pointer-events: auto;
    position: absolute;
    top: 8px;
    right: 8px;
}

.note-editor pre code {
    pointer-events: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.note-editor pre::before {
    content: attr(data-language);
    position: absolute;
    top: 5px;
    right: 50px;
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.6;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
}

.note-editor pre .code-copy-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    padding: 4px 6px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    user-select: none;
    -webkit-user-select: none;
}

.note-editor pre .code-copy-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border-color: rgba(255, 255, 255, 0.4);
}

.note-editor pre .code-copy-btn:active {
    transform: scale(0.95);
}

.note-editor pre code {
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Уведомление о копировании */
.copy-toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: var(--success);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 15px rgba(34, 197, 94, 0.4);
    z-index: 2000;
    animation: toastSlideIn 0.3s ease;
}

@keyframes toastSlideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.note-editor code {
    background: var(--bg-sidebar);
    color: #e2e8f0;
    padding: 3px 8px;
    border-radius: 5px;
    font-family: 'JetBrains Mono', 'Consolas', monospace;
    font-size: 0.9em;
}

.note-editor hr {
    border: none;
    margin: 20px 0;
    opacity: 0.5;
}

.note-editor blockquote {
    border-left: 4px solid var(--primary);
    padding-left: 16px;
    margin: 15px 0;
    color: var(--text-secondary);
    font-style: italic;
    background: var(--bg-primary);
    padding: 12px 16px;
    border-radius: 0 8px 8px 0;
}

.note-editor ul, .note-editor ol {
    margin: 12px 0;
    padding-left: 25px;
}

.note-editor a {
    color: var(--primary);
    text-decoration: underline;
    pointer-events: auto !important;
    cursor: pointer !important;
    user-select: text !important;
    -webkit-user-select: text !important;
    display: inline-block;
    position: relative;
    z-index: 1;
}

.note-editor a:hover {
    opacity: 0.8;
    text-decoration: none;
}

.note-editor a:active {
    opacity: 0.6;
}

.note-editor img {
    max-width: 100%;
    border-radius: 8px;
    margin: 10px 0;
}

/* Editor Meta */
.editor-meta {
    padding: 16px 24px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 30px;
    flex-wrap: wrap;
}

.meta-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.meta-group label {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Custom Select */
.custom-select {
    position: relative;
    min-width: 180px;
}

.custom-select-selected {
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s;
}

.custom-select-selected:hover {
    border-color: var(--primary);
}

.custom-select-selected .select-arrow {
    transition: transform 0.2s;
}

.custom-select.open .select-arrow {
    transform: rotate(180deg);
}

.custom-select-options {
    position: absolute;
    bottom: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    max-height: 200px;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1000;
    display: none;
}

.custom-select.open .custom-select-options {
    display: block;
}

.custom-select-option {
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 13px;
    color: var(--text-primary);
}

.custom-select-option:hover {
    background: var(--bg-primary);
}

.custom-select-option.active {
    background: var(--primary-light);
    color: var(--primary);
}

/* Скроллбар для custom select */
.custom-select-options::-webkit-scrollbar {
    width: 6px;
}

.custom-select-options::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 3px;
}

.custom-select-options::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
    transition: background 0.2s;
}

.custom-select-options::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.4);
}

/* Firefox */
.custom-select-options {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

.meta-group select {
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 13px;
    min-width: 180px;
    cursor: pointer;
}

.meta-group select:focus {
    outline: none;
    border-color: var(--primary);
}

.editor-meta .tags-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.editor-meta .tag-option {
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 12px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
    color: white;
    font-weight: 500;
}

.editor-meta .tag-option:hover {
    opacity: 0.85;
    transform: scale(1.02);
}

.editor-meta .tag-option.selected {
    border-color: var(--text-primary);
    box-shadow: 0 0 0 2px var(--bg-secondary);
}

/* Side Panel */
.side-panel {
    position: fixed;
    top: 0;
    right: -360px;
    width: 340px;
    height: 100vh;
    background: var(--bg-card);
    box-shadow: -5px 0 25px rgba(0, 0, 0, 0.12);
    z-index: 500;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

.side-panel.active {
    right: 0;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border-color);
}

.panel-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.close-btn {
    background: none;
    border: none;
    font-size: 26px;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
    padding: 4px;
}

.close-btn:hover {
    color: var(--text-primary);
}

.panel-body {
    padding: 18px 22px;
    flex: 1;
    overflow-y: auto;
}

.add-item-form {
    display: flex;
    gap: 8px;
    margin-bottom: 18px;
    align-items: center;
}

.add-item-form input[type="text"] {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 13px;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.add-item-form input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
}

.add-item-form input[type="color"] {
    width: 29px;
    height: 32px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    padding: 0;
    background: none;
    overflow: hidden;
    flex-shrink: 0;
}

.add-item-form input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 50%;
    padding: 0;
}

.add-item-form input[type="color"]::-moz-color-swatch {
    border: none;
    border-radius: 50%;
    padding: 0;
}

.btn-add {
    width: 40px;
    height: 40px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 20px;
    transition: background 0.2s;
}

.btn-add:hover {
    background: var(--primary-hover);
}

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

.item-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    background: var(--bg-primary);
    border-radius: 8px;
    transition: all 0.2s;
}

.item-row:hover {
    background: var(--bg-secondary);
    box-shadow: var(--shadow);
}

.item-row .item-name {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    flex: 1;
}

.item-color {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    flex-shrink: 0;
}

.item-row .item-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.item-row .item-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.item-row .item-btn.edit-btn {
    color: var(--text-secondary);
}

.item-row .item-btn.edit-btn:hover {
    background: var(--primary);
    color: white;
}

.item-row .item-btn.delete-btn {
    color: var(--text-secondary);
}

.item-row .item-btn.delete-btn:hover {
    background: var(--danger);
    color: white;
}

.item-row .item-btn svg {
    width: 16px;
    height: 16px;
}

/* Плавающая кнопка для мобильных */
.fab-add {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
    z-index: 150;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all 0.2s;
}

.fab-add .fab-icon {
    width: 24px;
    height: 24px;
    filter: brightness(0) invert(1);
}

.fab-add:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(99, 102, 241, 0.5);
}

.fab-add:active {
    transform: scale(0.95);
}

/* Responsive */
@media (max-width: 900px) {
    .menu-toggle {
        display: flex;
        position: fixed;
        top: 10px;
        left: 15px;
        z-index: 200;
    }

    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        padding: 60px 15px 15px;
    }

    .top-header {
        position: fixed;
        top: 15px;
        left: 70px;
        right: 15px;
        z-index: 150;
        margin-bottom: 0;
    }

    .header-left {
        width: 100%;
        max-width: none;
    }

    .search-box {
        border-bottom-width: 1px;
    }

    .search-box input {
        padding: 8px 0;
        font-size: 13px;
    }

    .search-icon-img {
        width: 16px;
        height: 16px;
        margin-right: 8px;
    }

    .editor-panel {
        max-width: 100%;
        width: 100%;
    }

    .notes-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 10px;
        transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* Показываем кнопку в сайдбаре на мобильных */
    .btn-create-note {
        display: flex !important;
        margin: 15px 16px !important;
    }

    /* Блок категорий больше в мобильном меню */
    .sidebar-categories {
        max-height: 400px !important;
    }

    /* Плавающая кнопка для мобильных */
    .fab-add {
        display: flex;
        position: fixed;
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
        background: linear-gradient(135deg, var(--primary), var(--primary-hover));
        border: none;
        border-radius: 50%;
        cursor: pointer;
        box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
        z-index: 150;
        align-items: center;
        justify-content: center;
        padding: 0;
        transition: all 0.2s;
    }

    .fab-add .fab-icon {
        width: 24px;
        height: 24px;
        filter: brightness(0) invert(1);
    }

    .fab-add:hover {
        transform: scale(1.1);
        box-shadow: 0 6px 25px rgba(99, 102, 241, 0.5);
    }

    .fab-add:active {
        transform: scale(0.95);
    }

    .note-card {
        max-height: 170px;
        padding: 12px;
    }

    .note-card .note-title {
        font-size: 0.85rem;
    }

    .note-card .note-content {
        -webkit-line-clamp: 2;
        font-size: 0.75rem;
    }

    .note-card .note-header {
        margin-bottom: 6px;
    }

    .note-card .note-favorite-icon svg {
        width: 12px;
        height: 12px;
    }

    .toolbar-label {
        display: none;
    }

    .toolbar-section {
        padding: 0 4px;
    }

    .toolbar-btn {
        width: 32px;
        height: 32px;
    }

    .toolbar-select {
        min-width: 100px;
        padding: 6px 8px;
        font-size: 12px;
    }

    .editor-title-input {
        font-size: 18px;
    }

    .editor-header {
        padding: 15.5px 15px;
    }

    .editor-toolbar {
        padding: 10px 12px;
        gap: 2px;
    }

    .editor-meta {
        padding: 12px 15px;
        gap: 15px;
    }

    .meta-group select {
        min-width: 140px;
        font-size: 12px;
        padding: 8px 10px;
    }

    .side-panel {
        width: 320px;
        right: -320px;
    }
}

@media (max-width: 600px) {
    .notes-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .note-card {
        max-height: 150px;
        padding: 10px;
        border-radius: 8px;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .note-card .note-title {
        font-size: 0.8rem;
        transition: font-size 0.3s;
    }

    .note-card .note-content {
        font-size: 0.7rem;
        -webkit-line-clamp: 2;
        transition: font-size 0.3s;
    }

    .note-card .note-meta {
        gap: 4px;
        transition: gap 0.3s;
    }

    .note-card .note-category,
    .note-card .note-tag {
        font-size: 0.65rem;
        padding: 2px 6px;
        transition: font-size 0.3s, padding 0.3s;
    }

    .side-panel {
        width: 100%;
        max-width: 320px;
        right: -320px;
    }

    .editor-toolbar {
        justify-content: flex-start;
        overflow-x: auto;
        flex-wrap: nowrap;
        padding: 10px;
    }

    .toolbar-divider {
        display: none;
    }

    .toolbar-section {
        flex-shrink: 0;
    }

    .auth-card {
        padding: 35px 25px;
    }

    .auth-card h1 {
        font-size: 2.2rem;
    }

    .editor-meta {
        flex-direction: column;
        gap: 12px;
    }

    .meta-group select {
        min-width: 100%;
        width: 100%;
    }

    .editor-title-input {
        font-size: 16px;
    }

    .btn-ok span {
        display: none;
    }

    .color-picker-wrapper {
        gap: 4px;
    }

    .color-picker-wrapper input[type="color"] {
        width: 36px;
        height: 36px;
    }

    .color-apply-btn {
        width: 24px;
        height: 24px;
        font-size: 14px;
    }

    .search-box input {
        padding: 12px 15px;
        font-size: 14px;
    }

    .top-header {
        margin-bottom: 20px;
    }

    .main-content {
        padding: 65px 12px 12px;
    }

    .note-editor {
        padding: 20px 15px;
        font-size: 15px;
    }

    .editor-header {
        padding: 10px 12px !important;
    }

    /* === Мобильная адаптация редактора === */
    
    /* Перемещаем meta (категории и теги) наверх, сразу под заголовок */
    .editor-meta {
        order: 2 !important;
        padding: 10px 16px !important;
        background: var(--bg-primary) !important;
        border-bottom: 1px solid var(--border-color) !important;
        border-top: none !important;
        gap: 12px !important;
    }

    .editor-body {
        order: 3 !important;
    }

    /* Уменьшаем кнопку сохранения - делаем как остальные кнопки */
    .btn-ok {
        padding: 0 !important;
        min-width: auto !important;
        width: 40px !important;
        height: 40px !important;
        border-radius: 10px !important;
        background: linear-gradient(135deg, var(--success), var(--success-hover)) !important;
        box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3) !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    .btn-ok span {
        display: none !important;
    }

    .btn-ok svg {
        width: 20px !important;
        height: 20px !important;
    }

    .btn-ok:hover {
        transform: translateY(-2px) !important;
        box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4) !important;
    }

    /* Уменьшаем все кнопки в хедере редактора */
    .editor-actions {
        gap: 6px !important;
    }

    .favorite-checkbox-label,
    .btn-delete-small,
    .btn-back {
        width: 40px !important;
        height: 40px !important;
    }

    .favorite-checkbox-label svg,
    .btn-delete-small svg,
    .btn-back svg {
        width: 20px !important;
        height: 20px !important;
    }

    /* Компактные категории и теги */
    .meta-group {
        gap: 6px !important;
        flex: 1 !important;
    }

    .meta-group label {
        font-size: 10px !important;
        gap: 4px !important;
    }

    .meta-group label svg {
        width: 12px !important;
        height: 12px !important;
    }

    .custom-select {
        min-width: 140px !important;
        position: relative !important;
    }

    .custom-select-selected {
        padding: 8px 12px !important;
        font-size: 12px !important;
    }

    /* Выпадающий список категорий вниз на мобильных */
    .custom-select-options {
        bottom: auto !important;
        top: calc(100% + 4px) !important;
        position: absolute !important;
        max-height: 250px !important;
    }

    .editor-meta .tags-selector {
        gap: 4px !important;
    }

    .editor-meta .tag-option {
        padding: 5px 10px !important;
        font-size: 11px !important;
        border-radius: 12px !important;
    }

    /* Адаптация тулбара - уменьшаем иконки и убираем разделители */
    .custom-toolbar {
        padding: 6px 8px !important;
        gap: 2px !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .custom-btn {
        width: 32px !important;
        height: 32px !important;
        flex-shrink: 0 !important;
        border-radius: 6px !important;
    }

    .custom-btn img {
        width: 14px !important;
        height: 14px !important;
    }

    .custom-separator {
        display: none !important;
    }

    .custom-btn-heading {
        font-size: 14px !important;
    }

    /* Увеличиваем область редактора для текста */
    .custom-editor {
        padding: 16px !important;
        font-size: 16px !important;
        line-height: 1.5 !important;
    }

    /* Уменьшаем заголовки в редакторе */
    .custom-editor h1 { font-size: 1.6em !important; }
    .custom-editor h2 { font-size: 1.4em !important; }
    .custom-editor h3 { font-size: 1.2em !important; }
    .custom-editor h4 { font-size: 1.1em !important; }
    .custom-editor h5 { font-size: 1em !important; }
    .custom-editor h6 { font-size: 0.9em !important; }

    /* Уменьшаем отступы у элементов редактора */
    .custom-editor blockquote,
    .custom-editor pre {
        margin: 0.8em 0 !important;
    }

    /* Скрываем кнопку "Добавить заметку" в сайдбаре - есть FAB внизу */
    .btn-create-note {
        display: none !important;
    }

    /* Возвращаем подписи в навигации */
    .nav-btn span:not(.nav-icon) {
        display: inline !important;
    }

    .nav-btn {
        justify-content: flex-start !important;
        padding: 12px 16px !important;
        width: auto !important;
        height: auto !important;
        gap: 14px !important;
    }

    .section-title {
        text-align: left !important;
    }

    .sidebar-category {
        justify-content: space-between !important;
    }

    .sidebar-category .cat-count {
        display: inline-block !important;
    }

    /* Уменьшаем шрифт в сайдбаре */
    .sidebar-header h1 {
        font-size: 1.4rem !important;
    }

    .logo-icon {
        width: 28px !important;
        height: 28px !important;
    }
}

@media (max-width: 400px) {
    .notes-grid {
        grid-template-columns: 1fr;
        transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .note-card {
        max-height: none;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .btn-create-note {
        padding: 12px !important;
        width: 44px !important;
        height: 44px !important;
    }

    .sidebar-header h1 {
        font-size: 1.3rem !important;
    }

    .nav-btn {
        padding: 10px 14px !important;
        gap: 12px !important;
    }

    .nav-icon .menu-icon {
        width: 18px !important;
        height: 18px !important;
    }

    .section-title {
        text-align: left !important;
        font-size: 10px !important;
    }

    .sidebar-category {
        justify-content: space-between !important;
        padding: 8px 12px !important;
    }

    .sidebar-category .cat-count {
        display: inline-block !important;
        font-size: 10px !important;
    }

    .logo-icon {
        width: 24px !important;
        height: 24px !important;
    }

    .custom-btn {
        width: 36px !important;
        height: 36px !important;
    }

    .custom-btn img {
        width: 18px !important;
        height: 18px !important;
    }

    .custom-editor {
        padding: 12px !important;
        font-size: 15px !important;
    }

    .custom-editor h1 { font-size: 1.4em !important; }
    .custom-editor h2 { font-size: 1.3em !important; }
    .custom-editor h3 { font-size: 1.1em !important; }
}

/* EasyMDE Markdown Editor Styles */
.editor-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 400px;
}

.editor-body .EasyMDEContainer {
    flex: 1;
    display: flex;
    flex-direction: column;
    border: none !important;
}

.editor-body .CodeMirror {
    flex: 1;
    min-height: 400px !important;
    height: auto !important;
    border: none !important;
    border-radius: 0 !important;
    font-family: 'JetBrains Mono', monospace !important;
    font-size: 14px !important;
    line-height: 1.6 !important;
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    padding: 20px !important;
}

.editor-body .editor-toolbar {
    border: none !important;
    border-bottom: 1px solid var(--border-color) !important;
    background: var(--bg-primary) !important;
    padding: 8px !important;
}

.editor-body .editor-toolbar button {
    color: var(--text-secondary) !important;
    background: transparent !important;
    border: 1px solid transparent !important;
}

.editor-body .editor-toolbar button:hover {
    color: var(--primary) !important;
    background: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
}

.editor-body .editor-toolbar button.active {
    color: var(--primary) !important;
    background: var(--bg-secondary) !important;
}

.editor-body .CodeMirror-fullscreen {
    z-index: 1000 !important;
}

.editor-body .editor-preview {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    padding: 20px !important;
    font-family: 'Inter', sans-serif !important;
    font-size: 14px !important;
    line-height: 1.6 !important;
}

.editor-body .editor-preview h1,
.editor-body .editor-preview h2,
.editor-body .editor-preview h3,
.editor-body .editor-preview h4,
.editor-body .editor-preview h5,
.editor-body .editor-preview h6 {
    color: var(--text-primary) !important;
    margin-top: 24px !important;
    margin-bottom: 16px !important;
    font-weight: 600 !important;
    line-height: 1.25 !important;
}

.editor-body .editor-preview h1 { font-size: 2em !important; }
.editor-body .editor-preview h2 { font-size: 1.5em !important; }
.editor-body .editor-preview h3 { font-size: 1.25em !important; }

.editor-body .editor-preview p {
    margin-bottom: 16px !important;
    color: var(--text-primary) !important;
}

.editor-body .editor-preview a {
    color: var(--primary) !important;
    text-decoration: underline !important;
}

.editor-body .editor-preview strong {
    color: var(--text-primary) !important;
    font-weight: 600 !important;
}

.editor-body .editor-preview em {
    color: var(--text-primary) !important;
}

.editor-body .editor-preview code {
    background: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    padding: 3px 8px !important;
    border-radius: 5px !important;
    font-family: 'JetBrains Mono', monospace !important;
    font-size: 0.9em !important;
}

.editor-body .editor-preview pre {
    background: var(--bg-sidebar) !important;
    color: #e2e8f0 !important;
    padding: 16px !important;
    border-radius: 8px !important;
    overflow-x: auto !important;
    font-family: 'JetBrains Mono', monospace !important;
    font-size: 13px !important;
    line-height: 1.5 !important;
    margin-bottom: 16px !important;
}

.editor-body .editor-preview pre code {
    background: transparent !important;
    color: inherit !important;
    padding: 0 !important;
}

.editor-body .editor-preview blockquote {
    border-left: 4px solid var(--primary) !important;
    padding-left: 16px !important;
    margin: 16px 0 !important;
    color: var(--text-secondary) !important;
    font-style: italic !important;
    background: var(--bg-primary) !important;
    padding: 12px 16px !important;
    border-radius: 0 8px 8px 0 !important;
}

.editor-body .editor-preview ul,
.editor-body .editor-preview ol {
    margin-bottom: 16px !important;
    padding-left: 24px !important;
    color: var(--text-primary) !important;
}

.editor-body .editor-preview li {
    margin-bottom: 8px !important;
    color: var(--text-primary) !important;
}

.editor-body .editor-preview table {
    border-collapse: collapse !important;
    width: 100% !important;
    margin-bottom: 16px !important;
}

.editor-body .editor-preview th,
.editor-body .editor-preview td {
    border: 1px solid var(--border-color) !important;
    padding: 10px 14px !important;
    color: var(--text-primary) !important;
}

.editor-body .editor-preview th {
    background: var(--bg-primary) !important;
    font-weight: 600 !important;
}

.editor-body .editor-preview tr:nth-child(even) {
    background: var(--bg-primary) !important;
}

.editor-body .editor-preview hr {
    border: none !important;
    border-top: 2px solid var(--border-color) !important;
    margin: 24px 0 !important;
    opacity: 0.5 !important;
}

.editor-body .editor-preview img {
    max-width: 100% !important;
    border-radius: 8px !important;
    margin: 16px 0 !important;
}

.editor-body .editor-preview-side {
    border-color: var(--border-color) !important;
}

.editor-body .CodeMirror-cursor {
    border-color: var(--primary) !important;
}

.editor-body .CodeMirror-selected {
    background: var(--primary-light) !important;
}

.editor-body .CodeMirror-gutters {
    background: var(--bg-primary) !important;
    border-color: var(--border-color) !important;
}

.editor-body .CodeMirror-linenumber {
    color: var(--text-secondary) !important;
}

.editor-body .CodeMirror-activeline-background {
    background: var(--bg-primary) !important;
}

/* Dark theme for EasyMDE */
body.dark-theme .CodeMirror {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}

body.dark-theme .CodeMirror-gutters {
    background: var(--bg-primary) !important;
    border-color: var(--border-color) !important;
}

body.dark-theme .CodeMirror-linenumber {
    color: var(--text-secondary) !important;
}

body.dark-theme .editor-toolbar {
    background: var(--bg-primary) !important;
    border-color: var(--border-color) !important;
}

body.dark-theme .editor-toolbar button {
    color: var(--text-secondary) !important;
}

body.dark-theme .editor-toolbar button:hover {
    color: var(--primary) !important;
}

body.dark-theme .editor-preview {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}

/* Custom Editor Styles */
.editor-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.custom-editor-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
}

.custom-toolbar {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    padding: 8px 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    user-select: none;
}

.custom-btn {
    background: none;
    border: 1px solid transparent;
    color: var(--text-primary);
    width: 36px;
    height: 36px;
    border-radius: 6px;
    font-size: 18px;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: all 0.13s;
    position: relative;
}

.custom-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--border-color);
}

.custom-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.custom-btn-code {
    font-size: 20px;
    font-weight: bold;
    letter-spacing: -1px;
}

.custom-btn img {
    width: 20px;
    height: 20px;
    filter: invert(0.5) sepia(0) saturate(0) hue-rotate(0deg);
    transition: filter 0.13s;
}

body.dark-theme .custom-btn img {
    filter: invert(1);
}

.custom-btn.active img {
    filter: invert(1) brightness(2);
}

.custom-separator {
    width: 1px;
    background: var(--border-color);
    margin: 0 8px;
    align-self: stretch;
}

.custom-heading-dropdown {
    position: absolute;
    top: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 0;
    display: none;
    flex-direction: column;
    gap: 2px;
    z-index: 100;
    box-shadow: var(--shadow-lg);
}

.custom-btn-heading:hover .custom-heading-dropdown {
    display: flex;
}

.custom-heading-item {
    padding: 6px 16px;
    cursor: pointer;
    font-size: 14px;
    white-space: nowrap;
    color: var(--text-primary);
}

.custom-heading-item:hover {
    background: var(--bg-secondary);
}

.custom-editor {
    flex: 1;
    padding: 32px 40px;
    outline: none;
    font-size: 17px;
    line-height: 1.65;
    overflow-y: auto;
    caret-color: var(--primary);
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.custom-editor:empty:before {
    content: "Начните писать...";
    color: var(--text-secondary);
    pointer-events: none;
}

.custom-editor.has-content:empty:before {
    content: none;
}

.custom-editor h1 { font-size: 2.6em; margin: 0.4em 0; font-weight: 700; color: var(--text-primary); }
.custom-editor h2 { font-size: 2.1em; margin: 0.4em 0; font-weight: 700; color: var(--text-primary); }
.custom-editor h3 { font-size: 1.7em; margin: 0.4em 0; font-weight: 600; color: var(--text-primary); }
.custom-editor h4 { font-size: 1.4em; margin: 0.4em 0; font-weight: 600; color: var(--text-primary); }
.custom-editor h5 { font-size: 1.25em; margin: 0.4em 0; font-weight: 600; color: var(--text-secondary); }
.custom-editor h6 { font-size: 1.1em; margin: 0.4em 0; font-weight: 600; color: var(--text-secondary); }

.custom-editor blockquote {
    border-left: 4px solid var(--primary);
    padding-left: 1.2em;
    color: var(--text-secondary);
    margin: 1.4em 0;
    font-style: italic;
    min-height: 1.2em;
}

.custom-editor pre {
    background: var(--bg-sidebar);
    padding: 1em;
    border-radius: 8px;
    margin: 1.4em 0;
    overflow-x: auto;
}

.custom-editor pre code {
    background: none;
    padding: 0;
    display: block;
    font-family: 'Consolas', 'Courier New', monospace;
    white-space: pre;
    min-height: 1.2em;
    color: var(--text-primary);
}

.custom-editor hr.dashed {
    border: none;
    border-top: 1px dashed var(--border-color);
    margin: 0.8em 0;
}

.custom-editor a {
    color: var(--primary);
    text-decoration: underline;
    cursor: text;
}

@media (max-width: 600px) {
    .custom-editor {
        padding: 20px 16px;
        font-size: 16px;
    }
    
    .custom-btn {
        font-size: 16px;
    }
    
    .custom-btn-code {
        font-size: 18px;
    }
    
    .custom-btn img {
        width: 18px;
        height: 18px;
    }
    
    .custom-heading-dropdown {
        min-width: 80px;
        left: 0;
        transform: none;
    }
    
    .custom-editor hr.dashed {
        margin: 0.5em 0;
    }
}
