@import url('https://fonts.googleapis.com/css2?family=DM+Sans:opsz,wght@9..40,300;9..40,400;9..40,500;9..40,600;9..40,700;9..40,800&display=swap');

/* ─── Dark Theme (Default) ───────────────────────────────── */
:root,
html[data-theme="dark"] {
    --bg: #1c1f27;
    --bg-surface: #141419;
    --bg-elevated: #1b1b22;
    --bg-hover: #23232d;
    --bg-active: #2a2a36;
    --sidebar-bg: #232630;
    --text: #e0ddf0;
    --text-muted: #6a667e;
    --text-dim: #3e3b52;
    --sidebar-text: #9996ac;
    --sidebar-active-text: #e0ddf0;
    --border: rgba(255, 255, 255, 0.065);
    --border-md: rgba(255, 255, 255, 0.11);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.6);
}

/* ─── Light Theme ─────────────────────────────────────────── */
html[data-theme="light"] {
    --bg: #f2f0eb;
    --bg-surface: #ffffff;
    --bg-elevated: #ffffff;
    --bg-hover: #ece9e3;
    --bg-active: #e4e0d8;
    --sidebar-bg: #f8f6f1;
    --text: #1a1820;
    --text-muted: #6b6880;
    --text-dim: #9896a8;
    --sidebar-text: #5a5870;
    --sidebar-active-text: #1a1820;
    --border: rgba(0, 0, 0, 0.08);
    --border-md: rgba(0, 0, 0, 0.13);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.15);
}

/* ─── Shared Tokens (same in both themes) ────────────────── */
:root {
    --accent: #c72535;
    --accent-hover: #a81f2c;
    --accent-glow: rgba(199, 37, 53, 0.18);
    --gold: #c9923c;
    --success: #3a9e6e;
    --radius: 8px;
    --radius-sm: 5px;
    --radius-lg: 12px;
    --sidebar-width: 300px;
}

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

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'DM Sans', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ─── Login Page ─────────────────────────────────────────── */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface);
    overflow: auto;
}

.login-card {
    width: 340px;
    background: var(--bg-elevated);
    border-radius: var(--radius-lg);
    border-top: 2px solid var(--accent);
    padding: 2.5rem 2rem 2rem;
    box-shadow: var(--shadow-lg);
}

.login-logo {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 2rem;
}


.login-logo h1 {
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: -0.01em;
    color: var(--text);
}

.login-error {
    background: rgba(199, 37, 53, 0.12);
    border: 1px solid rgba(199, 37, 53, 0.3);
    color: #d05060;
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.9rem;
    font-size: 0.85rem;
    margin-bottom: 1.2rem;
}

html[data-theme="dark"] .login-error { color: #f08090; }

.login-form-group { margin-bottom: 1.2rem; }

.login-form-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.45rem;
}

.login-form-group input {
    width: 100%;
    height: 46px;
    background: var(--bg-active);
    border: 1px solid var(--border-md);
    border-radius: 7px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    padding: 0 0.9rem;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

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

.login-form-group input::placeholder { color: var(--text-dim); }

.login-btn {
    width: 100%;
    height: 46px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    cursor: pointer;
    transition: background 0.15s;
    box-shadow: 0 2px 8px rgba(199, 37, 53, 0.3);
    margin-top: 0.5rem;
}

.login-btn:hover { background: var(--accent-hover); }

.login-version {
    margin-top: 1rem;
    text-align: center;
    font-size: 0.7rem;
    color: #888;
    user-select: none;
}

/* ─── App Logo Badge ─────────────────────────────────────── */
.app-logo-badge {
    width: 28px;
    height: 28px;
    background: var(--accent);
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.62rem;
    font-weight: 800;
    color: #fff;
    letter-spacing: 0.02em;
    flex-shrink: 0;
    user-select: none;
}

/* ─── Icon Sizes ─────────────────────────────────────────── */
.sidebar-icon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    opacity: 0.8;
}

.sidebar-item:hover .sidebar-icon,
.sidebar-item.active .sidebar-icon { opacity: 1; }

.footer-icon {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

.empty-icon {
    width: 44px;
    height: 44px;
    color: var(--text-dim);
    margin-bottom: 0.4rem;
    flex-shrink: 0;
}

/* ─── App Shell ──────────────────────────────────────────── */
.app-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ─── Sidebar ────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 1.1rem 1rem 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-new-note-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    flex-shrink: 0;
    margin-left: auto;
    transition: background 0.15s;
}

.sidebar-new-note-btn:hover { background: var(--accent-hover); }

.sidebar-logo { font-size: 1.2rem; }

.sidebar-brand {
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: 0.03em;
    color: var(--text);
    flex: 1;
}

.sidebar-search {
    padding: 0.7rem 0.75rem;
    flex-shrink: 0;
}

.sidebar-search input {
    width: 100%;
    height: 32px;
    background: var(--bg-active);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 0.82rem;
    padding: 0 0.7rem;
    outline: none;
    transition: border-color 0.15s;
}

.sidebar-search input:focus { border-color: var(--border-md); }
.sidebar-search input::placeholder { color: var(--text-dim); }

.sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 0.5rem;
}

.sidebar-body::-webkit-scrollbar { width: 4px; }
.sidebar-body::-webkit-scrollbar-track { background: transparent; }
.sidebar-body::-webkit-scrollbar-thumb { background: var(--border-md); border-radius: 2px; }

.sidebar-section { padding: 0.4rem 0; }

.sidebar-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.3rem 0.75rem 0.2rem;
}

.sidebar-section-label {
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.sidebar-section-add {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0.1rem 0.2rem;
    border-radius: 3px;
    transition: color 0.15s, background 0.15s;
}

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

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.45rem 0.75rem;
    font-size: 0.86rem;
    color: var(--sidebar-text);
    cursor: pointer;
    border-left: 2px solid transparent;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    user-select: none;
}

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

.sidebar-item.active {
    background: var(--accent-glow);
    border-left-color: var(--accent);
    color: var(--sidebar-active-text);
    font-weight: 500;
}

.sidebar-count {
    margin-left: auto;
    font-size: 0.7rem;
    color: var(--text-muted);
    background: var(--bg-active);
    padding: 0.05rem 0.35rem;
    border-radius: 9px;
}

.sidebar-tag-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.sidebar-input-row {
    display: flex;
    gap: 0.35rem;
    padding: 0.25rem 0.75rem 0.3rem;
}

.sidebar-input-row input {
    flex: 1;
    height: 28px;
    background: var(--bg-active);
    border: 1px solid var(--border-md);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 0.8rem;
    padding: 0 0.6rem;
    outline: none;
}

.sidebar-input-row input:focus { border-color: var(--accent); }

.sidebar-input-row button {
    height: 28px;
    padding: 0 0.6rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    cursor: pointer;
}

/* ─── Folder Tree ────────────────────────────────────────── */
.folder-tree-row {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding-top: 0.42rem;
    padding-bottom: 0.42rem;
    padding-right: 0.6rem;
    font-size: 0.86rem;
    color: var(--sidebar-text);
    cursor: pointer;
    border-left: 2px solid transparent;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    user-select: none;
}

.folder-tree-row:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.folder-tree-row:hover .folder-tree-actions { opacity: 1; }
.folder-tree-row:hover .sidebar-icon { opacity: 1; }

.folder-tree-row.active {
    background: var(--accent-glow);
    border-left-color: var(--accent);
    color: var(--sidebar-active-text);
    font-weight: 500;
}

.folder-tree-row.active .sidebar-icon { opacity: 1; }

.folder-tree-chevron-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    color: var(--text-muted);
    opacity: 0.65;
    transition: opacity 0.15s, transform 0.18s;
}

.folder-tree-chevron-btn.expanded { transform: rotate(90deg); }
.folder-tree-chevron-btn.invisible { visibility: hidden; cursor: default; }
.folder-tree-chevron-btn:hover { opacity: 1; }

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

.folder-tree-count {
    font-size: 0.7rem;
    color: var(--text-muted);
    background: var(--bg-active);
    padding: 0.05rem 0.35rem;
    border-radius: 9px;
    flex-shrink: 0;
}

.folder-tree-actions {
    display: flex;
    gap: 0.1rem;
    opacity: 0;
    transition: opacity 0.12s;
    flex-shrink: 0;
}

.folder-tree-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 3px;
    font-size: 0.82rem;
    line-height: 1;
    transition: background 0.1s, color 0.1s;
}

.folder-tree-action-btn:hover {
    background: var(--bg-active);
    color: var(--text);
}

.folder-tree-action-btn.danger:hover { color: var(--accent); }

.folder-tree-note-row {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding-top: 0.36rem;
    padding-bottom: 0.36rem;
    padding-right: 0.6rem;
    font-size: 0.84rem;
    color: var(--sidebar-text);
    cursor: pointer;
    border-left: 2px solid transparent;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    user-select: none;
}

.folder-tree-note-row:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.folder-tree-note-row:hover .sidebar-icon { opacity: 1; }

.folder-tree-note-row.active {
    background: var(--accent-glow);
    border-left-color: var(--accent);
    color: var(--sidebar-active-text);
    font-weight: 500;
}

.folder-tree-note-row.active .sidebar-icon { opacity: 1; }

.folder-tree-note-spacer {
    width: 14px;
    flex-shrink: 0;
}

/* ─── Sidebar Footer ─────────────────────────────────────── */
.sidebar-footer {
    flex-shrink: 0;
    padding: 0.5rem 0.6rem;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.sidebar-footer-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.42rem 0.55rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.82rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background 0.12s, color 0.12s;
    white-space: nowrap;
}

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

.sidebar-footer-btn.active {
    color: var(--accent);
    background: var(--accent-glow);
}

.sidebar-footer-spacer { flex: 1; }

.sidebar-version {
    font-size: 0.68rem;
    color: #888;
    user-select: none;
    padding: 0 0.25rem;
}

/* ─── Note List Panel ────────────────────────────────────── */
.note-list-panel {
    width: var(--notelist-width);
    min-width: var(--notelist-width);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: var(--bg);
    overflow: hidden;
}

.note-list-header {
    padding: 0.9rem 1rem 0.6rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.note-list-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.55rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-new-note {
    width: 100%;
    height: 32px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-new-note:hover { background: var(--accent-hover); }

.note-list-items {
    flex: 1;
    overflow-y: auto;
    padding: 0.3rem 0;
}

.note-list-items::-webkit-scrollbar { width: 4px; }
.note-list-items::-webkit-scrollbar-track { background: transparent; }
.note-list-items::-webkit-scrollbar-thumb { background: var(--border-md); border-radius: 2px; }

.note-card {
    padding: 0.65rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.12s;
    border-left: 2px solid transparent;
}

.note-card:hover { background: var(--bg-hover); }

.note-card.active {
    background: var(--bg-active);
    border-left-color: var(--accent);
}

.note-card-title {
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.18rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.note-card-preview {
    font-size: 0.76rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.25rem;
}

.note-card-meta {
    font-size: 0.7rem;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.note-tag {
    display: inline-block;
    padding: 0.04rem 0.38rem;
    border-radius: 9px;
    font-size: 0.66rem;
    font-weight: 500;
}

.note-list-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-dim);
    font-size: 0.83rem;
    gap: 0.4rem;
    padding: 2rem;
    text-align: center;
}

/* ─── Editor Panel ───────────────────────────────────────── */
.editor-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
}

.editor-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    gap: 0.5rem;
    font-size: 0.88rem;
}

.editor-empty-icon {
    font-size: 2.5rem;
    opacity: 0.35;
    margin-bottom: 0.3rem;
}

.editor-header {
    padding: 0.65rem 1.2rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-shrink: 0;
}

.editor-title-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text);
    font-family: inherit;
    font-size: 1.05rem;
    font-weight: 700;
    outline: none;
    min-width: 0;
}

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

.editor-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
}

.unsaved-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--gold);
    flex-shrink: 0;
}

.btn-save {
    height: 30px;
    padding: 0 0.85rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-save:hover { background: var(--accent-hover); }

.btn-icon {
    height: 30px;
    width: 30px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-md);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.btn-icon:hover { background: var(--bg-hover); color: var(--text); }
.btn-icon.danger:hover { color: var(--accent); border-color: var(--accent); }

.editor-meta-bar {
    padding: 0.35rem 1.2rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
    flex-wrap: wrap;
    min-height: 36px;
    position: relative;
}

.editor-meta-label {
    font-size: 0.7rem;
    color: var(--text-dim);
}

.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.08rem 0.45rem;
    border-radius: 9px;
    font-size: 0.7rem;
    font-weight: 500;
    cursor: default;
}

.tag-chip-remove {
    font-size: 0.7rem;
    opacity: 0.6;
    cursor: pointer;
    margin-left: 0.1rem;
    line-height: 1;
}

.tag-chip-remove:hover { opacity: 1; }

.meta-separator {
    width: 1px;
    height: 14px;
    background: var(--border-md);
    flex-shrink: 0;
    align-self: center;
    margin: 0 0.25rem;
}

.folder-selector-wrap {
    position: relative;
    flex-shrink: 0;
}

.folder-select-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    height: 22px;
    padding: 0 0.5rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border-md);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.72rem;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
    white-space: nowrap;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.folder-select-btn:hover { color: var(--text); border-color: var(--border-md); }

.folder-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border-md);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    min-width: 180px;
    z-index: 200;
    padding: 0.3rem 0;
}

.folder-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.38rem 0.75rem;
    font-size: 0.82rem;
    cursor: pointer;
    transition: background 0.1s;
    color: var(--text);
}

.folder-dropdown-item:hover { background: var(--bg-hover); }
.folder-dropdown-item.selected { color: var(--accent); }

.tag-add-btn {
    height: 22px;
    padding: 0 0.5rem;
    background: var(--bg-elevated);
    border: 1px dashed var(--border-md);
    border-radius: 9px;
    color: var(--text-dim);
    font-family: inherit;
    font-size: 0.7rem;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}

.tag-add-btn:hover { color: var(--text-muted); }

.tag-dropdown {
    position: absolute;
    top: calc(100% + 2px);
    left: 1.2rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border-md);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    min-width: 160px;
    z-index: 200;
    padding: 0.3rem 0;
}

.tag-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.38rem 0.75rem;
    font-size: 0.82rem;
    cursor: pointer;
    transition: background 0.1s;
    color: var(--text);
}

.tag-dropdown-item:hover { background: var(--bg-hover); }
.tag-dropdown-item.selected { color: var(--accent); }

.tag-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.editor-body {
    flex: 1;
    overflow: hidden;
    position: relative;
}

#editor-container {
    height: 100%;
    width: 100%;
}

/* ─── Fullscreen Editor ──────────────────────────────────── */
.editor-panel-inner {
    display: contents; /* transparent wrapper by default */
}

.editor-panel-inner.fullscreen {
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0;
    z-index: 500;
    background: var(--bg);
}

/* ─── Settings Panel ─────────────────────────────────────── */
.settings-panel {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 2.5rem;
}

.settings-panel h2 {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 2rem;
    letter-spacing: -0.01em;
}

.settings-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border-md);
    border-radius: var(--radius);
    padding: 1.5rem;
    max-width: 420px;
    margin-bottom: 1.5rem;
}

.settings-card h3 {
    font-size: 0.9rem;
    font-weight: 700;
    margin-bottom: 1.2rem;
    color: var(--text);
}

.settings-form-group { margin-bottom: 1rem; }

.settings-form-group label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

.settings-form-group input {
    width: 100%;
    height: 40px;
    background: var(--bg-active);
    border: 1px solid var(--border-md);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 0.88rem;
    padding: 0 0.8rem;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

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

.settings-msg {
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    margin-bottom: 0.8rem;
}

.settings-msg.success {
    background: rgba(58, 158, 110, 0.15);
    border: 1px solid rgba(58, 158, 110, 0.3);
    color: var(--success);
}

.settings-msg.error {
    background: rgba(199, 37, 53, 0.12);
    border: 1px solid rgba(199, 37, 53, 0.3);
    color: var(--accent);
}

.settings-divider {
    height: 1px;
    background: var(--border);
    margin: 1rem 0;
}

.btn-settings-save {
    height: 36px;
    padding: 0 1.2rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-settings-save:hover { background: var(--accent-hover); }

/* ─── Theme Toggle ───────────────────────────────────────── */
.theme-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.theme-toggle-label {
    font-size: 0.88rem;
    color: var(--text);
}

.toggle-switch {
    position: relative;
    width: 42px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-switch input { display: none; }

.toggle-track {
    position: absolute;
    inset: 0;
    background: var(--bg-active);
    border: 1px solid var(--border-md);
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s;
}

.toggle-switch input:checked + .toggle-track { background: var(--accent); border-color: var(--accent); }

.toggle-track::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: transform 0.2s, background 0.2s;
}

.toggle-switch input:checked + .toggle-track::after {
    transform: translateX(18px);
    background: #fff;
}

/* ─── Toast UI Editor — Layout & Sizing ─────────────────── */
/* These must always apply regardless of theme */
.toastui-editor-defaultUI {
    border: none !important;
    height: 100% !important;
}

.toastui-editor-main { height: 100% !important; }

#editor-container { height: 100%; width: 100%; }

/* ─── ProseMirror: Font & Spacing (both themes) ──────────── */
.ProseMirror {
    padding: 1.5rem 2rem !important;
    font-family: 'DM Sans', sans-serif !important;
    font-size: 0.95rem !important;
    line-height: 1.75 !important;
    min-height: 100% !important;
}

.ProseMirror:focus { outline: none !important; }
.ProseMirror a { color: var(--accent) !important; }

.ProseMirror blockquote {
    border-left: 3px solid var(--accent) !important;
}

/* ─── Dark Mode: Color overrides on top of CDN dark CSS ─── */
/* CDN dark CSS uses .toastui-editor-dark — we load after it, so we win */
.toastui-editor-dark .toastui-editor-toolbar {
    background: var(--bg-elevated) !important;
    border-bottom: 1px solid var(--border) !important;
}

.toastui-editor-dark .toastui-editor-toolbar-group button:hover,
.toastui-editor-dark .toastui-editor-toolbar-item button:hover {
    background: var(--bg-active) !important;
}

.toastui-editor-dark .toastui-editor-toolbar-divider {
    background: var(--border) !important;
}

.toastui-editor-dark .toastui-editor-ww-container,
.toastui-editor-dark .toastui-editor-md-container {
    background: var(--bg) !important;
}

.toastui-editor-dark .ProseMirror {
    background: var(--bg) !important;
    color: var(--text) !important;
}

.toastui-editor-dark .ProseMirror h1,
.toastui-editor-dark .ProseMirror h2,
.toastui-editor-dark .ProseMirror h3 {
    color: var(--text) !important;
}

.toastui-editor-dark .ProseMirror blockquote {
    color: var(--text-muted) !important;
    background: transparent !important;
}

.toastui-editor-dark .ProseMirror code {
    background: var(--bg-active) !important;
    color: var(--gold) !important;
}

.toastui-editor-dark .ProseMirror pre {
    background: var(--bg-elevated) !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius) !important;
}

.toastui-editor-dark .toastui-editor-mode-switch {
    background: var(--bg-elevated) !important;
    border-top: 1px solid var(--border) !important;
}

.toastui-editor-dark .toastui-editor-mode-switch .tab-item {
    border: none !important;
}

.toastui-editor-dark .toastui-editor-mode-switch .tab-item.active {
    background: var(--bg-active) !important;
}

.toastui-editor-dark .toastui-editor-popup,
.toastui-editor-dark .toastui-editor-dropdown-toolbar {
    background: var(--bg-elevated) !important;
    border: 1px solid var(--border-md) !important;
    box-shadow: var(--shadow-md) !important;
}

/* CodeMirror in dark mode */
.toastui-editor-dark .CodeMirror {
    background: var(--bg) !important;
    color: var(--text) !important;
    font-size: 0.93rem !important;
}

.toastui-editor-dark .CodeMirror-cursor { border-left-color: var(--text) !important; }
.toastui-editor-dark .CodeMirror-selected { background: var(--bg-active) !important; }

/* ─── Light Mode: subtle adjustments to CDN light defaults ─ */
/* CDN light theme already looks good; just align bg/font */
html[data-theme="light"] .toastui-editor-defaultUI {
    background: var(--bg) !important;
}

html[data-theme="light"] .ProseMirror {
    background: var(--bg) !important;
    color: var(--text) !important;
}

html[data-theme="light"] .toastui-editor-toolbar {
    background: var(--bg-elevated) !important;
    border-bottom: 1px solid var(--border) !important;
}

html[data-theme="light"] .toastui-editor-ww-container,
html[data-theme="light"] .toastui-editor-md-container {
    background: var(--bg) !important;
}

html[data-theme="light"] .toastui-editor-mode-switch {
    background: var(--bg-elevated) !important;
    border-top: 1px solid var(--border) !important;
}

html[data-theme="light"] .CodeMirror {
    background: var(--bg) !important;
    color: var(--text) !important;
}

/* ─── Note Window (standalone) ───────────────────────────── */
.note-window {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--bg);
    color: var(--text);
}

.note-window-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
    flex-shrink: 0;
}

.note-window-title {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 1.05rem;
    font-weight: 600;
    font-family: inherit;
}

.note-window-title::placeholder { color: var(--text-dim); }

.note-window-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.note-window-body #editor-container {
    flex: 1;
    height: 100%;
}

.note-window-body .toastui-editor-defaultUI {
    height: 100% !important;
}

/* ─── Blazor Validation ──────────────────────────────────── */
.valid.modified:not([type=checkbox]) { outline: 1px solid #26b050; }
.invalid { outline: 1px solid #e50000; }
.validation-message { color: #e50000; }

/* ─── Mobile ─────────────────────────────────────────────── */
.sidebar-backdrop { display: none; }
.mobile-topbar    { display: none; }
.mobile-menu-btn  { display: none; }

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        z-index: 400;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        min-width: 0;
        width: 82vw;
        max-width: 300px;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.45);
        z-index: 399;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s;
    }

    .sidebar-backdrop.visible {
        opacity: 1;
        pointer-events: auto;
    }

    .mobile-topbar {
        display: flex;
        align-items: center;
        gap: 0.6rem;
        padding: 0.7rem 1rem;
        border-bottom: 1px solid var(--border);
        background: var(--bg-elevated);
        flex-shrink: 0;
    }

    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 34px;
        height: 34px;
        background: none;
        border: none;
        color: var(--text-muted);
        cursor: pointer;
        border-radius: var(--radius-sm);
        flex-shrink: 0;
    }

    .mobile-menu-btn:hover { background: var(--bg-hover); color: var(--text); }

    .mobile-topbar-title {
        font-size: 0.95rem;
        font-weight: 700;
        flex: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        color: var(--text);
    }

    .editor-header { padding: 0.55rem 0.75rem; gap: 0.4rem; }
    .editor-title-input { font-size: 0.95rem; }
    .editor-meta-bar { padding: 0.3rem 0.75rem; gap: 0.3rem; }

    .ProseMirror { padding: 1rem 1.25rem !important; }

    .login-card { width: calc(100% - 2rem); max-width: 360px; }

    .settings-panel { padding: 1.2rem 1rem; }
    .settings-card { max-width: 100%; }
}
