/* ═══════════════════════════════════════════════════════════════
   WHITETAIL NOTES — app.css
   Design tokens → layout → components → dark mode → mobile
═══════════════════════════════════════════════════════════════ */

/* ── DESIGN TOKENS ─────────────────────────────────────────── */
:root {
    --bg:           #F6F3EC;
    --surface:      #FBF9F4;
    --surface-2:    #EFECE1;
    --text:         #33302A;
    --muted:        #A09A8C;
    --accent:       #6B7560;
    --accent-soft:  rgba(107, 117, 96, .10);
    --border:       #EBE7DB;
    --destructive:  #B4675A;
    --popover-bg:   #26241F;

    --panel-bg:         rgba(251, 249, 244, .92);
    --panel-border:     rgba(235, 231, 219, .85);
    --panel-shadow:     18px 0 50px rgba(40, 36, 24, .16);

    --rail-w:       52px;
    --rail-w-open:  176px;
    --panel-w:      320px;
    --col-max:      710px;

    --radius-pill:  999px;
    --radius-input: 9px;
    --radius-card:  16px;
    --radius-row:   8px;
    --radius-key:   5px;
    --radius-sheet: 24px;

    --font-serif: 'Lora', Georgia, serif;
    --font-sans:  'Inter', system-ui, sans-serif;
    --font-mono:  ui-monospace, Menlo, monospace;

    --font-size-body:  18px;
    --line-height-body: 1.78;

    --transition-rail: width .18s ease;
    --transition-panel: opacity .18s ease, transform .18s ease;
}

[data-theme="dark"] {
    --bg:           #1A1A17;
    --surface:      #1F1E1B;
    --surface-2:    #27261F;
    --text:         #E6E1D6;
    --muted:        #7E7A6E;
    --accent:       #99A384;
    --accent-soft:  rgba(153, 163, 132, .13);
    --border:       #2A2823;
    --panel-bg:         rgba(31, 30, 27, .92);
    --panel-border:     rgba(42, 40, 35, .9);
}

[data-theme="sepia"] {
    --bg:           #F5EFE0;
    --surface:      #FAF5E9;
    --surface-2:    #EDE5CE;
    --text:         #3B3020;
    --muted:        #9C8E71;
    --accent:       #8B6F47;
    --accent-soft:  rgba(139, 111, 71, .12);
    --border:       #DED4B8;
    --panel-bg:         rgba(250, 245, 233, .92);
    --panel-border:     rgba(222, 212, 184, .85);
}

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

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

button { cursor: pointer; border: none; background: none; color: inherit; font: inherit; -webkit-tap-highlight-color: transparent; }
a      { color: inherit; text-decoration: none; -webkit-tap-highlight-color: transparent; }
ul     { list-style: none; }
input  { font: inherit; color: inherit; background: none; border: none; outline: none; }

/* ── APP SHELL ──────────────────────────────────────────────── */
.app {
    display: flex;
    position: fixed;
    inset: 0;
    overflow: hidden;
}

/* ── RAIL ───────────────────────────────────────────────────── */
.rail {
    flex: 0 0 auto;
    width: var(--rail-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 14px 0;
    overflow: hidden;
    transition: var(--transition-rail);
    z-index: 20;
}

.rail:hover,
.rail.is-expanded {
    width: var(--rail-w-open);
}

.rail-top,
.rail-bottom {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.rail-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--rail-w);
    height: 44px;
    flex: 0 0 auto;
    color: var(--accent);
    transition: color .15s, width .18s ease;
    margin-bottom: 10px;
}

.rail-logo:hover { color: var(--text); }

.rail-logo svg {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    transition: width .18s ease, height .18s ease;
}

.rail:hover .rail-logo,
.rail.is-expanded .rail-logo {
    width: 100%;
}

.rail:hover .rail-logo svg,
.rail.is-expanded .rail-logo svg {
    width: 32px;
    height: 32px;
}

.rail-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 0 9px 15px;
    border-radius: 0;
    color: var(--muted);
    transition: background .12s, color .12s;
    white-space: nowrap;
    min-height: 38px;
}

.rail-item:hover {
    background: var(--surface-2);
    color: var(--text);
}

.rail-item--danger:hover { color: var(--destructive); }

.rail-icon {
    width: 17px;
    height: 17px;
    flex-shrink: 0;
    stroke-width: 1.7;
}

.rail-label {
    font-size: 13px;
    font-family: var(--font-sans);
    opacity: 0;
    transition: opacity .12s ease;
}

.rail:hover .rail-label,
.rail.is-expanded .rail-label {
    opacity: 1;
}

/* Rail tag list */
.rail-tags {
    margin-top: 8px;
    padding: 0 0 0 15px;
    overflow: hidden;
}

.rail-eyebrow {
    display: block;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: .13em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 6px 0 4px;
    opacity: 0;
    transition: opacity .12s ease;
}

.rail:hover .rail-eyebrow,
.rail.is-expanded .rail-eyebrow {
    opacity: 1;
}

#rail-tag-list {
    opacity: 0;
    transition: opacity .12s ease;
    max-height: 280px;
    overflow-y: auto;
}

.rail:hover #rail-tag-list,
.rail.is-expanded #rail-tag-list {
    opacity: 1;
}

.rail-tag-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 0;
    color: var(--muted);
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    transition: color .12s;
}

.rail-tag-item:hover,
.rail-tag-item.is-active {
    color: var(--accent);
}

.rail-tag-remove {
    margin-left: auto;
    margin-right: 8px;
    font-size: 12px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .1s, color .1s, background .1s;
    padding: 2px 4px;
    border-radius: 4px;
}
.rail-tag-item:hover .rail-tag-remove { opacity: .6; pointer-events: auto; }
.rail-tag-item:hover .rail-tag-remove:hover { opacity: 1; color: var(--destructive); background: var(--surface-2); }

.rail-tag-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity .12s;
}

.rail-tag-item.is-active .rail-tag-dot { opacity: 1; }

/* ── FLOATING PANEL ─────────────────────────────────────────── */
.panel-scrim {
    position: absolute;
    inset: 0;
    background: rgba(28, 27, 24, .10);
    z-index: 29;
}

.floating-panel {
    position: absolute;
    top: 0;
    bottom: 0;
    left: var(--rail-w);
    width: var(--panel-w);
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-right: 1px solid var(--panel-border);
    box-shadow: var(--panel-shadow);
    display: flex;
    flex-direction: column;
    z-index: 30;
    transform: translateX(-8px);
    opacity: 0;
    transition: var(--transition-panel);
}

.floating-panel:not([hidden]) {
    transform: translateX(0);
    opacity: 1;
}

/* Override hidden display so transition works */
.floating-panel[hidden],
.panel-scrim[hidden] {
    display: flex !important;
    pointer-events: none;
}

.panel-scrim[hidden] { display: block !important; opacity: 0; pointer-events: none; }

.panel-search-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 22px 24px 14px;
    flex-shrink: 0;
}

.panel-search-icon {
    width: 15px;
    height: 15px;
    color: var(--muted);
    flex-shrink: 0;
    stroke-width: 1.7;
}

.panel-search {
    flex: 1;
    font-size: 13.5px;
    color: var(--text);
}

.panel-search::placeholder { color: var(--muted); }

.keycap {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-key);
    padding: 1px 5px;
    flex-shrink: 0;
}

.panel-section-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: .13em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 4px 24px 8px;
    flex-shrink: 0;
}

.panel-heading-clear {
    font-size: 14px;
    font-weight: 400;
    letter-spacing: 0;
    text-transform: none;
    color: var(--muted);
    line-height: 1;
    padding: 1px 5px;
    border-radius: 4px;
    transition: color .1s, background .1s;
    flex-shrink: 0;
}
.panel-heading-clear:hover { color: var(--destructive); background: var(--surface-2); }

.panel-notes {
    flex: 1;
    overflow-y: auto;
    padding: 0 12px;
}

.panel-note-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-row);
    cursor: pointer;
    transition: background .1s;
}

.panel-note-row:hover,
.panel-note-row.is-active {
    background: var(--surface-2);
}

.panel-note-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    flex-shrink: 0;
    opacity: 0;
    transition: opacity .1s;
}

.panel-note-row.is-active .panel-note-dot { opacity: 1; }

.panel-note-title {
    font-family: var(--font-serif);
    font-size: 14.5px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.panel-note-row.is-active .panel-note-title {
    font-weight: 600;
    color: var(--text);
}

.panel-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 13px 22px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.panel-footer-label {
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: .13em;
    text-transform: uppercase;
    color: var(--muted);
}

.panel-tag-pills {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.panel-tag-pill {
    font-size: 12px;
    font-family: var(--font-sans);
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    padding: 2px 9px;
    cursor: pointer;
    transition: color .1s, border-color .1s;
}

.panel-tag-pill:hover { color: var(--text); }

.panel-tag-pill.is-active {
    color: var(--accent);
    border-color: var(--accent);
}

.panel-tag-pill-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 3px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    font-size: 11px;
    line-height: 1;
    opacity: 0;
    transition: opacity .1s, background .1s;
    vertical-align: middle;
}
.panel-tag-pill:hover .panel-tag-pill-remove { opacity: 1; }
.panel-tag-pill-remove:hover { background: var(--destructive); color: #fff; opacity: 1; }

/* ── EDITOR AREA ────────────────────────────────────────────── */
.editor-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
}

.date-row {
    text-align: right;
    font-size: 11.5px;
    color: var(--muted);
    font-family: var(--font-sans);
    padding: 14px 48px 0;
    max-width: calc(var(--col-max) + 96px);
    width: 100%;
    margin: 0 auto;
    flex-shrink: 0;
}

.writing-surface {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 54px 48px 36px;
}

.text-column {
    max-width: var(--col-max);
    width: 100%;
    margin: 0 auto;
}

/* Quill body editor */
#body-editor {
    font-family: var(--font-serif);
    font-size: var(--font-size-body);
    line-height: var(--line-height-body);
    color: var(--text);
}

/* Override Quill internals */
.ql-container { border: none !important; font-family: var(--font-serif); }
.ql-editor {
    padding: 0 !important;
    font-size: var(--font-size-body);
    line-height: var(--line-height-body);
    color: var(--text);
    font-family: var(--font-serif);
    overflow-wrap: anywhere;
    word-break: break-word;
    width: 100%;
    box-sizing: border-box;
    -webkit-user-select: text;
    user-select: text;
}

/* First block = title */
.ql-editor > *:first-child {
    font-size: 31px !important;
    font-weight: 500 !important;
    line-height: 1.22 !important;
    letter-spacing: -0.015em !important;
    margin-bottom: 24px !important;
}

.ql-editor p { margin-bottom: 19px; }
.ql-editor ul,
.ql-editor ol {
    padding-left: 1.5em;
    margin-bottom: 19px;
}
.ql-editor li { margin-bottom: 7px; line-height: 1.7; }
/* Quill default: width 1.2em + margin-right 0.3em = 1.5em (net zero shift).
   Reduce width, increase gap so there's breathing room between bullet and text. */
.ql-editor li:not(.ql-direction-rtl)::before {
    width: 0.9em;
    margin-right: 0.6em;
}
.ql-container.ql-bubble:not(.ql-disabled) .ql-editor a {
    white-space: normal;
    word-break: break-all;
    overflow-wrap: anywhere;
}
/* Quill's ::before/::after link tooltip clips against overflow ancestors — replaced by #link-tooltip */
.ql-container.ql-bubble:not(.ql-disabled) .ql-editor a::before,
.ql-container.ql-bubble:not(.ql-disabled) .ql-editor a::after {
    display: none !important;
}
.ql-editor a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
[data-theme="dark"] .ql-editor.ql-blank::before { color: var(--muted) !important; }

/* JS-positioned link hover tooltip — fixed so it escapes overflow clipping */
#link-tooltip {
    position: fixed;
    background: var(--popover-bg);
    color: #fff;
    border-radius: var(--radius-input);
    padding: 5px 12px;
    font-size: 12px;
    font-family: var(--font-sans);
    white-space: nowrap;
    pointer-events: none;
    z-index: 9999;
    box-shadow: 0 4px 12px rgba(0,0,0,.25);
    display: none;
}

/* Quill bubble popover */
.ql-bubble .ql-tooltip {
    background: var(--popover-bg) !important;
    border-radius: var(--radius-input) !important;
    box-shadow: 0 8px 24px rgba(0,0,0,.28) !important;
    border: none !important;
    max-width: min(90vw, 480px) !important;
    z-index: 9999 !important;
}
.ql-bubble .ql-tooltip-editor input[type=text] { min-width: 0; width: 100%; }

.ql-bubble .ql-toolbar button { color: rgba(255,255,255,.75) !important; }
.ql-bubble .ql-toolbar button:hover { color: #fff !important; background: rgba(255,255,255,.10) !important; border-radius: 4px; }
.ql-bubble .ql-toolbar button.ql-active { color: #fff !important; }
.ql-bubble .ql-tooltip-arrow { border-bottom-color: var(--popover-bg) !important; border-top-color: var(--popover-bg) !important; }

/* ── TAG BAR ────────────────────────────────────────────────── */
.tag-bar {
    flex-shrink: 0;
    background: var(--bg);
    padding: 10px 48px 16px;
}

.tag-bar-inner {
    max-width: var(--col-max);
    margin: 0 auto;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.tag-chips { display: flex; gap: 6px; flex-wrap: wrap; }

.tag-chip {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-family: var(--font-sans);
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    padding: 2px 8px;
    cursor: default;
    transition: border-color .1s, color .1s;
}

.tag-chip:hover { color: var(--text); border-color: var(--muted); }

.tag-chip-remove {
    display: none;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 10px;
    cursor: pointer;
    transition: background .1s, color .1s;
    border: none;
    padding: 0;
}

.tag-chip:hover .tag-chip-remove { display: flex; }
.tag-chip-remove:hover { background: var(--destructive); color: #fff; }

.tag-add-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-family: var(--font-sans);
    color: var(--muted);
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    border: 1px solid transparent;
    transition: color .1s, border-color .1s;
}

.tag-add-btn:hover {
    color: var(--accent);
    border-color: var(--border);
}

.tag-add-input {
    display: none;
    font-size: 12px;
    font-family: var(--font-sans);
    color: var(--text);
    border: 1px solid var(--accent);
    border-radius: var(--radius-pill);
    padding: 2px 10px;
    background: var(--surface);
    outline: none;
    width: 120px;
}

.tag-add-input.is-open { display: block; }

.tag-add { position: relative; }

.tag-suggestions {
    position: absolute;
    bottom: calc(100% + 4px);
    left: 0;
    min-width: 150px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-input);
    box-shadow: 0 4px 16px rgba(0,0,0,.10);
    z-index: 200;
    overflow: hidden;
}
.tag-suggestions[hidden] { display: none; }
.tag-suggestion-item {
    padding: 7px 12px;
    font-size: 13px;
    font-family: var(--font-sans);
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
}
.tag-suggestion-item:hover,
.tag-suggestion-item.is-highlighted { background: var(--accent-soft); color: var(--accent); }

.word-count {
    margin-left: auto;
    font-size: 11.5px;
    font-family: var(--font-sans);
    color: var(--muted);
}

/* ── DELETE DIALOG ──────────────────────────────────────────── */
.dialog-scrim {
    position: fixed;
    inset: 0;
    background: rgba(28, 27, 24, .30);
    z-index: 49;
}

.dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 50;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 28px 32px 24px;
    width: 320px;
    box-shadow: 0 14px 44px rgba(40,36,24,.12);
}

.dialog[hidden],
.dialog-scrim[hidden] { display: none; }

.dialog p { font-size: 15px; font-family: var(--font-serif); color: var(--text); margin-bottom: 6px; }
.dialog-sub { font-size: 13px !important; font-family: var(--font-sans) !important; color: var(--muted) !important; margin-bottom: 20px !important; }

.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; }

.dialog-cancel {
    font-size: 13.5px;
    padding: 9px 18px;
    border-radius: var(--radius-input);
    border: 1px solid var(--border);
    color: var(--muted);
    background: transparent;
    transition: color .1s, border-color .1s;
}
.dialog-cancel:hover { color: var(--text); border-color: var(--muted); }

.dialog-confirm {
    font-size: 13.5px;
    font-weight: 600;
    padding: 9px 18px;
    border-radius: var(--radius-input);
    background: var(--destructive);
    color: #fff;
    transition: opacity .1s;
}
.dialog-confirm:hover { opacity: .85; }

/* ── MOBILE — hidden by default ─────────────────────────────── */
.mobile-bottomnav,
.bottom-sheet,
.sheet-scrim { display: none; }

/* ═══════════════════════════════════════════════════════════════
   MOBILE  (<= 768px)
═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

    .rail,
    .floating-panel,
    .panel-scrim { display: none !important; }

    .app {
        flex-direction: column;
    }

    /* Mobile bottom nav — flex child, not fixed, so it reflows with the app container */
    .mobile-bottomnav {
        display: block;
        position: relative;
        flex-shrink: 0;
        height: 80px;
        z-index: 10;
    }

    .mobile-nav-list {
        position: absolute;
        bottom: 18px;
        left: 18px;
        width: 44px;
        height: 44px;
        background: var(--surface);
        border-radius: 999px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--muted);
        box-shadow: 0 0 0 1px var(--border), 0 2px 10px rgba(0,0,0,.08);
        transition: color .12s;
    }
    .mobile-nav-list:active { color: var(--accent); }
    .mobile-nav-list svg { width: 18px; height: 18px; stroke-width: 1.7; }

    .mobile-nav-new {
        position: absolute;
        bottom: 18px;
        right: 18px;
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 0 18px;
        height: 44px;
        background: var(--surface);
        border-radius: 999px;
        color: var(--muted);
        font-size: 13px;
        font-weight: 500;
        font-family: var(--font-sans);
        box-shadow: 0 0 0 1px var(--border), 0 2px 10px rgba(0,0,0,.08);
        transition: color .12s;
    }
    .mobile-nav-new:active { color: var(--accent); }
    .mobile-nav-new svg { width: 15px; height: 15px; stroke-width: 2; }

    /* Editor adjustments */
    .writing-surface { padding: 16px 24px 24px; }
    .date-row        { padding: 10px 24px 0; }
    .tag-bar         { padding: 8px 24px 12px; }

    .ql-editor > *:first-child { font-size: 25px !important; margin-bottom: 16px !important; }

    /* Keyboard open — hide tag bar, collapse nav so buttons float over the editor */
    .keyboard-open .tag-bar { display: none; }
    .keyboard-open .mobile-bottomnav { height: 0; }

    /* Bottom sheet */
    .sheet-scrim {
        display: block;
        position: fixed; inset: 0;
        background: rgba(28, 27, 24, .34);
        z-index: 39;
    }
    .sheet-scrim[hidden] { display: none; }

    .bottom-sheet {
        display: flex;
        flex-direction: column;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        height: 660px;
        background: rgba(251, 249, 244, .97);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
        box-shadow: 0 -12px 40px rgba(40, 36, 24, .20);
        z-index: 40;
        transform: translateY(100%);
        transition: transform .22s ease;
    }

    [data-theme="dark"] .bottom-sheet {
        background: rgba(31, 30, 27, .97);
    }

    .bottom-sheet:not([hidden]) { transform: translateY(0); }
    .bottom-sheet[hidden] { display: flex; pointer-events: none; box-shadow: none; }

    .sheet-handle {
        width: 38px; height: 4px;
        background: #D8D2C3;
        border-radius: var(--radius-pill);
        margin: 12px auto 8px;
        flex-shrink: 0;
    }

    .sheet-search-row {
        display: flex;
        align-items: center;
        gap: 8px;
        margin: 8px 16px 12px;
        background: var(--surface-2);
        border: 1px solid var(--border);
        border-radius: 11px;
        padding: 10px 14px;
        flex-shrink: 0;
    }

    .sheet-settings-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        width: 28px;
        height: 28px;
        color: var(--muted);
        border-radius: var(--radius-input);
        transition: color .1s;
    }
    .sheet-settings-btn:hover,
    .sheet-settings-btn:active { color: var(--text); }
    .sheet-settings-btn svg { width: 17px; height: 17px; }

    .swipe-wrap {
        position: relative;
        overflow: hidden;
        border-radius: var(--radius-row);
        isolation: isolate;
    }
    .swipe-wrap .panel-note-row {
        position: relative;
        background: var(--surface);
        border-radius: 0;
    }
    .swipe-wrap .panel-note-row:hover,
    .swipe-wrap .panel-note-row.is-active,
    .swipe-wrap .panel-note-row.is-swiping { background: var(--surface-2); }
    .swipe-delete-btn {
        position: absolute;
        right: 0; top: 0; bottom: 0;
        width: 76px;
        background: var(--destructive);
        color: #fff;
        font-size: 12.5px;
        font-weight: 600;
        font-family: var(--font-sans);
        display: flex;
        align-items: center;
        justify-content: center;
        transform: translateX(76px);
        z-index: 1;
    }
}

/* ── SETTINGS MODAL ─────────────────────────────────────────── */
.settings-scrim {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.35);
    z-index: 100;
    opacity: 0;
    transition: opacity .18s ease;
}
.settings-scrim:not([hidden]) { opacity: 1; }
.settings-scrim[hidden] { display: block !important; pointer-events: none; }

.settings-modal {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -48%) scale(.97);
    z-index: 101;
    display: flex;
    width: min(860px, calc(100vw - 48px));
    height: min(620px, calc(100vh - 80px));
    border-radius: var(--radius-card);
    box-shadow: 0 24px 80px rgba(0,0,0,.22), 0 4px 16px rgba(0,0,0,.10);
    background: var(--surface);
    color: var(--text);
    opacity: 0;
    transition: opacity .18s ease, transform .18s ease;
    overflow: hidden;
}
.settings-modal:not([hidden]) { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.settings-modal[hidden] { display: flex !important; pointer-events: none; }

/* ── Nav sidebar */
.settings-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 180px;
    flex-shrink: 0;
    padding: 28px 12px 20px;
    background: var(--bg);
    border-right: 1px solid var(--border);
    overflow-y: auto;
}

.settings-nav-title {
    font-family: var(--font-sans);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 0 10px 14px;
}

.settings-tab {
    all: unset;
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 500;
    color: var(--muted);
    padding: 9px 14px;
    border-radius: var(--radius-row);
    cursor: pointer;
    transition: background .12s, color .12s;
}
.settings-tab:hover { background: var(--surface-2); color: var(--text); }
.settings-tab.is-active { background: var(--accent-soft); color: var(--accent); }

/* ── Body area */
.settings-body {
    flex: 1;
    position: relative;
    overflow-y: auto;
    padding: 40px 48px;
}

.settings-close {
    all: unset;
    position: absolute;
    top: 18px; right: 20px;
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    color: var(--muted);
    border-radius: var(--radius-row);
    cursor: pointer;
    transition: color .12s, background .12s;
}
.settings-close:hover { color: var(--text); background: var(--surface-2); }
.settings-close svg { width: 18px; height: 18px; }

/* ── Panels */
.settings-panel { display: none; max-width: 540px; }
.settings-panel.is-active { display: block; }

.settings-heading {
    font-family: var(--font-sans);
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 28px;
}

.settings-subhead {
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 14px;
}
.settings-subhead--danger { color: var(--destructive); }

.settings-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px 0;
    border-bottom: 1px solid var(--border);
}
.settings-row:last-child { border-bottom: none; }

.settings-row--toggle {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}

.settings-label {
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.settings-value {
    font-size: 13px;
    font-weight: 400;
    color: var(--muted);
}

.settings-desc {
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--muted);
    margin-top: 3px;
}

/* ── Sliders */
.settings-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    border-radius: var(--radius-pill);
    background: var(--border);
    outline: none;
    cursor: pointer;
}
.settings-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px; height: 18px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 1px 4px rgba(0,0,0,.2);
    cursor: pointer;
    transition: transform .1s;
}
.settings-slider::-webkit-slider-thumb:active { transform: scale(1.18); }
.settings-slider::-moz-range-thumb {
    width: 18px; height: 18px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    cursor: pointer;
}

/* ── Font buttons */
.settings-font-btns { display: flex; gap: 8px; }
.settings-font-btn {
    flex: 1;
    padding: 10px 0;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-row);
    background: none;
    font-size: 15px;
    color: var(--muted);
    cursor: pointer;
    transition: border-color .12s, color .12s, background .12s;
}
.settings-font-btn:hover { border-color: var(--accent); color: var(--text); }
.settings-font-btn.is-active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* ── Theme buttons */
.settings-theme-btns { display: flex; gap: 8px; }
.settings-theme-btn {
    flex: 1;
    padding: 10px 0;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-row);
    background: none;
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    color: var(--muted);
    cursor: pointer;
    transition: border-color .12s, color .12s, background .12s;
}
.settings-theme-btn:hover { border-color: var(--accent); color: var(--text); }
.settings-theme-btn.is-active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* ── Accent swatches */
.settings-accents { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 2px; }
.settings-accent-swatch {
    width: 30px; height: 30px;
    border-radius: 50%;
    border: 2.5px solid transparent;
    cursor: pointer;
    transition: transform .12s, border-color .12s;
    outline-offset: 3px;
}
.settings-accent-swatch:hover { transform: scale(1.12); }
.settings-accent-swatch.is-active { border-color: var(--text); }

/* ── Toggle switch */
.toggle-switch {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    flex-shrink: 0;
}
.toggle-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-track {
    width: 42px; height: 24px;
    background: var(--border);
    border-radius: var(--radius-pill);
    position: relative;
    transition: background .15s;
}
.toggle-switch input:checked + .toggle-track { background: var(--accent); }
.toggle-thumb {
    position: absolute;
    top: 3px; left: 3px;
    width: 18px; height: 18px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
    transition: left .15s;
}
.toggle-switch input:checked + .toggle-track .toggle-thumb { left: 21px; }

/* ── Tags panel */
.settings-tag-create {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.settings-input {
    flex: 1;
    padding: 9px 13px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-row);
    background: var(--surface-2);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 14px;
    outline: none;
    transition: border-color .12s;
}
.settings-input:focus { border-color: var(--accent); }
.settings-input::placeholder { color: var(--muted); }

.settings-tag-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.settings-tag-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    border-radius: var(--radius-row);
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.settings-tag-name {
    flex: 1;
    font-family: var(--font-sans);
    font-size: 14px;
    color: var(--text);
}

.settings-tag-rename-input {
    flex: 1;
    border: none;
    outline: none;
    background: none;
    font-family: var(--font-sans);
    font-size: 14px;
    color: var(--text);
    padding: 0;
}

.settings-tag-actions { display: flex; gap: 4px; }
.settings-tag-btn {
    all: unset;
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 500;
    padding: 3px 8px;
    border-radius: 5px;
    cursor: pointer;
    color: var(--muted);
    transition: color .12s, background .12s;
}
.settings-tag-btn:hover { color: var(--text); background: var(--surface); }
.settings-tag-btn--danger:hover { color: var(--destructive); }
.settings-tag-btn--save { color: var(--accent); }
.settings-tag-btn--save:hover { color: var(--accent); background: var(--accent-soft); }

.settings-tag-list--pick .settings-tag-item { cursor: pointer; }
.settings-tag-list--pick .settings-tag-item:hover { border-color: var(--accent); background: var(--accent-soft); }

.settings-merge-ui {
    margin-top: 20px;
    padding: 16px;
    border: 1.5px dashed var(--border);
    border-radius: var(--radius-row);
}
.settings-merge-ui p {
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 12px;
}
.settings-merge-ui p strong { color: var(--text); }

/* ── Account forms */
.settings-form { display: flex; flex-direction: column; gap: 14px; }
.settings-field { display: flex; flex-direction: column; gap: 5px; }
.settings-field label {
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}
.settings-field input {
    padding: 10px 13px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-row);
    background: var(--surface-2);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 14px;
    outline: none;
    transition: border-color .12s;
}
.settings-field input:focus { border-color: var(--accent); }

.settings-form-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.settings-msg {
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--muted);
    flex: 1;
}
.settings-msg.is-error { color: var(--destructive); }
.settings-msg.is-ok { color: var(--accent); }

.settings-hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 24px 0;
}

.settings-danger { padding-top: 4px; }

/* ── Shared buttons */
.settings-btn-primary {
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 600;
    padding: 9px 18px;
    border-radius: var(--radius-row);
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    transition: opacity .12s;
    white-space: nowrap;
    flex-shrink: 0;
}
.settings-btn-primary:hover { opacity: .88; }

.settings-btn-ghost {
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    padding: 9px 18px;
    border-radius: var(--radius-row);
    background: var(--surface-2);
    color: var(--text);
    border: 1.5px solid var(--border);
    cursor: pointer;
    transition: background .12s;
}
.settings-btn-ghost:hover { background: var(--border); }

.settings-btn-danger {
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 600;
    padding: 9px 18px;
    border-radius: var(--radius-row);
    background: var(--destructive);
    color: #fff;
    border: none;
    cursor: pointer;
    transition: opacity .12s;
    white-space: nowrap;
    flex-shrink: 0;
}
.settings-btn-danger:hover { opacity: .88; }

/* ── Mobile settings modal */
@media (max-width: 768px) {
    .settings-modal {
        top: 0; left: 0;
        width: 100%; height: 100%;
        border-radius: 0;
        flex-direction: column;
        transform: scale(.97);
    }
    .settings-modal:not([hidden]) { transform: scale(1); }

    .settings-nav {
        width: 100%;
        flex-direction: row;
        align-items: center;
        padding: 12px 16px 0;
        gap: 0;
        border-right: none;
        border-bottom: 1px solid var(--border);
        overflow-x: auto;
        overflow-y: hidden;
        scrollbar-width: none;
    }
    .settings-nav::-webkit-scrollbar { display: none; }

    .settings-nav-title { display: none; }

    .settings-tab {
        white-space: nowrap;
        padding: 8px 14px 10px;
        border-radius: 0;
        border-bottom: 2px solid transparent;
        font-size: 13px;
    }
    .settings-tab.is-active {
        background: none;
        border-bottom-color: var(--accent);
        color: var(--accent);
    }

    .settings-body {
        padding: 24px 20px;
        flex: 1;
        overflow-y: auto;
    }

    .settings-close {
        top: 10px; right: 8px;
    }
}
