/* nBox design system foundation. The palette lives in CSS custom
   properties so the three-pane mail UI (milestone 2) composes from the
   same tokens, and dark mode is a token swap, not a rewrite. */

:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #eef0f3;
    --border: #d9dde3;
    --text: #1c2733;
    --text-muted: #5c6b7a;
    --accent: #2f6fed;
    --accent-contrast: #ffffff;
    --danger: #d64545;
    --star: #e8a013;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #12161c;
        --surface: #1a2028;
        --surface-2: #222a35;
        --border: #303a47;
        --text: #e6ebf2;
        --text-muted: #93a1b3;
        --accent: #5b8dff;
        --accent-contrast: #0d1320;
        --danger: #e5696e;
        --star: #f0b429;
        --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea {
    font: inherit;
    color: inherit;
}

/* ---------- landing (pre-login placeholder) ---------- */

.landing {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.landing-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 2.5rem 3rem;
    text-align: center;
}

.landing-logo {
    font-size: 2.25rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--accent);
    margin-bottom: 0.5rem;
}

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

/* ---------- shared controls ---------- */

.btn {
    display: inline-block;
    background: var(--accent);
    color: var(--accent-contrast);
    border: none;
    border-radius: var(--radius);
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-weight: 600;
}
.btn:hover { filter: brightness(1.05); }
.btn[disabled] { opacity: 0.6; cursor: default; }

.text-input {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
}
.text-input:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
    border-color: var(--accent);
}

.error {
    color: var(--danger);
    background: color-mix(in srgb, var(--danger) 10%, transparent);
    border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    margin: 0.5rem 0;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    text-align: left;
    margin-top: 1.5rem;
}

.login-form label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.login-form .btn {
    margin-top: 1rem;
}

.btn-primary { background: var(--accent); }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.875rem; }
.btn-danger { background: var(--danger); }

.link-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    font-size: 0.875rem;
}
.link-btn:hover { color: var(--text); text-decoration: underline; }

/* ---------- mail: three-pane shell ---------- */

.mail-shell {
    display: grid;
    grid-template-columns: var(--sidebar-w, 230px) 360px 1fr;
    height: 100vh;
    overflow: hidden;
    position: relative; /* anchors the resize divider */
}

/* draggable boundary between sidebar and list pane: an absolute
   overlay on the boundary line, NOT a grid child — a grid cell here
   shifts every pane over one column. */
.sidebar-resize {
    position: absolute;
    left: calc(var(--sidebar-w, 230px) - 3px);
    top: 0;
    width: 6px;
    height: 100vh;
    cursor: col-resize;
    z-index: 10;
    background: transparent;
}
.sidebar-resize:hover, .sidebar-resize.dragging {
    background: var(--accent);
    opacity: 0.5;
}

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--border);
}

.brand {
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--accent);
    font-size: 1.1rem;
}

#sidebar-inner { flex: 1; overflow-y: auto; padding: 0.5rem 0; }

.folder-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.folder a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.45rem 1rem;
    color: var(--text);
    text-decoration: none;
    border-left: 3px solid transparent;
}
.folder a:hover { background: var(--surface-2); }
.folder.current a {
    background: var(--surface-2);
    border-left-color: var(--accent);
    font-weight: 600;
}

.badge {
    background: var(--accent);
    color: var(--accent-contrast);
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.05rem 0.5rem;
}

.sidebar-foot {
    border-top: 1px solid var(--border);
    padding: 0.6rem 0.9rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    font-size: 0.875rem;
}
.sidebar-links {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.foot-link {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    background: none;
    border: none;
    padding: 0.3rem 0.4rem;
    margin-left: -0.4rem;
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.875rem;
}
.foot-link:hover { background: var(--surface-2); color: var(--text); }
.foot-link svg { flex-shrink: 0; }
.foot-session {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    border-top: 1px solid var(--border);
    padding-top: 0.5rem;
}
.whoami { overflow: hidden; text-overflow: ellipsis; }

/* ---------- message list ---------- */

.list-pane {
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--bg);
}

.message-list { display: flex; flex-direction: column; height: 100%; min-height: 0; }

.list-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.search-partial { font-size: 0.85rem; }
}
.list-title { font-weight: 700; }

.rows { flex: 1; overflow-y: auto; }

.row {
    display: flex;
    gap: 0.25rem;
    padding: 0.55rem 0.75rem 0.55rem 0.5rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    background: var(--surface);
}
.row:hover { background: var(--surface-2); }

/* The row open in the reading pane: stronger than multi-select
   (.selected) and stable under hover, with an accent bar so it reads
   as "this is the one I'm looking at" at a glance. The server renders
   the class on every list refresh; app.js adds it instantly on click. */
.row.current {
    background: color-mix(in srgb, var(--accent) 16%, var(--surface));
    box-shadow: inset 3px 0 0 var(--accent);
}
.row.current:hover { background: color-mix(in srgb, var(--accent) 20%, var(--surface)); }

.row.unread .from, .row.unread .subject { font-weight: 700; }

.star {
    background: none;
    border: none;
    color: var(--border);
    cursor: pointer;
    font-size: 1rem;
    padding: 0.15rem 0.25rem;
    align-self: flex-start;
}
.star.lit { color: var(--star); }

.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.1rem; }

.row-top { display: flex; justify-content: space-between; gap: 0.5rem; }
.from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.date { color: var(--text-muted); font-size: 0.8125rem; flex-shrink: 0; }

.row-subject { display: flex; align-items: center; gap: 0.35rem; }
.subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clip { font-size: 0.85rem; }

.snippet {
    color: var(--text-muted);
    font-size: 0.8125rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    border-top: 1px solid var(--border);
    background: var(--surface);
    font-size: 0.875rem;
}

/* ---------- reader ---------- */

.reader-pane { overflow-y: auto; min-width: 0; background: var(--bg); }

.reader-empty {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.message-view { display: flex; flex-direction: column; height: 100%; min-height: 0; }

.view-head {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.view-head h2 { margin: 0 0 0.5rem; font-size: 1.25rem; }

.view-head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.view-meta { font-size: 0.875rem; color: var(--text-muted); display: flex; flex-direction: column; gap: 0.15rem; flex: 1; min-width: 16rem; }
.view-meta .label { display: inline-block; min-width: 3rem; font-weight: 600; color: var(--text-muted); }

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

.view-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem 1.5rem;
    background: var(--surface);
    line-height: 1.6;
}
.view-body img[data-remote-src] {
    display: inline-block;
    min-width: 3rem;
    min-height: 3rem;
    background: var(--surface-2) repeating-linear-gradient(45deg, transparent, transparent 6px, var(--border) 6px, var(--border) 12px);
    border-radius: 4px;
    vertical-align: middle;
}
.view-body img:not([src])::after { content: "🖼 remote image blocked"; font-size: 0.75rem; color: var(--text-muted); }

.body-text {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: inherit;
    margin: 0;
}

.attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-top: 1px solid var(--border);
    background: var(--surface);
}
.attachment {
    display: inline-flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.4rem 0.75rem;
    font-size: 0.875rem;
    background: var(--surface-2);
}
.attachment:hover { text-decoration: none; border-color: var(--accent); }
.attachment .filename { font-weight: 600; }

/* ---------- responsive ---------- */

@media (max-width: 1100px) {
    .mail-shell { grid-template-columns: minmax(160px, var(--sidebar-w, 200px)) 300px 1fr; }
}
@media (max-width: 860px) {
    .mail-shell { grid-template-columns: 200px 1fr; grid-template-rows: 1fr 1fr; }
    .list-pane { grid-column: 2; }
    .reader-pane { grid-column: 1 / span 2; grid-row: 2; }
}

.row.selected { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }

/* ---------- compose ---------- */

.compose { display: flex; flex-direction: column; height: 100%; min-height: 0; padding: 1.25rem 1.5rem; overflow-y: auto; }
.compose-head h2 { margin: 0 0 0.75rem; font-size: 1.25rem; }

.compose-form { display: flex; flex-direction: column; gap: 0.35rem; }
.compose-form label { font-size: 0.8125rem; font-weight: 600; color: var(--text-muted); margin-top: 0.5rem; }

.editor-wrap {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    margin-top: 0.5rem;
}
#editor-toolbar { border-bottom: 1px solid var(--border); }
#editor {
    min-height: 220px;
    max-height: 40vh;
    overflow-y: auto;
    font-size: 15px;
}
.editor-wrap .ql-editor { font-family: var(--font); }
.editor-wrap .ql-editor pre {
    background: var(--surface-2);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    white-space: pre-wrap;
}
.editor-wrap .ql-editor blockquote {
    border-left: 3px solid var(--border);
    margin: 0.5rem 0;
    padding: 0.1rem 0.9rem;
    color: var(--text-muted);
}
/* Paragraph spacing parity with the message view (.msg-html below):
   Quill zeroes .ql-editor p margins, so without this rule Enter looks
   tighter while composing than the sent mail does when read. Signature
   lines are letterhead — no gaps anywhere. */
.editor-wrap .ql-editor p { margin: 0 0 .5em; }
.editor-wrap .ql-editor blockquote p { margin: 0; }
.editor-wrap .ql-editor .nbox-signature p { margin: 0; }
.sig-editor .ql-editor p { margin: 0; }
.editor-wrap .ql-toolbar.ql-snow, .editor-wrap .ql-container.ql-snow { border: none; }

.attach-label { display: block; }

.compose-actions { display: flex; gap: 0.5rem; margin-top: 1rem; }

.ql-snow.ql-toolbar button:hover,
.ql-snow.ql-toolbar button.ql-active {
    color: var(--accent);
}

/* ---------- search + bulk toolbar ---------- */

.search-form { margin-top: 0.4rem; }
.search-input { padding: 0.3rem 0.6rem; font-size: 0.875rem; }

.bulk-bar {
    display: none;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.75rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    font-size: 0.875rem;
}
.bulk-bar.active { display: flex; }
.bulk-bar .bulk-target { width: auto; padding: 0.25rem 0.4rem; font-size: 0.875rem; }
.select-all { display: inline-flex; align-items: center; gap: 0.3rem; color: var(--text-muted); }

.row-check { margin: 0.3rem 0.25rem 0 0.1rem; align-self: flex-start; }

.inline-form { display: inline-flex; gap: 0.35rem; align-items: center; }
.inline-form .text-input { width: auto; padding: 0.3rem 0.5rem; font-size: 0.875rem; }

/* ---------- folders panel ---------- */

.folders-panel { padding: 1.25rem 1.5rem; }
.folders-panel h2 { margin: 0 0 0.75rem; }
.folder-create { display: flex; gap: 0.5rem; margin-bottom: 1rem; max-width: 26rem; }
.folder-create .text-input { flex: 1; }

.folders-manage { list-style: none; margin: 0; padding: 0; }
.folders-manage li {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.folders-manage .folder-name { font-weight: 600; min-width: 8rem; }

.notice {
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
}

.sidebar-tools { padding: 0.5rem 1rem; border-top: 1px solid var(--border); }

/* explicit dark override for users who pick dark on a light system */
:root[data-theme="dark"] {
    --bg: #12161c;
    --surface: #1a2028;
    --surface-2: #222a35;
    --border: #303a47;
    --text: #e6ebf2;
    --text-muted: #93a1b3;
    --accent: #5b8dff;
    --accent-contrast: #0d1320;
    --danger: #e5696e;
    --star: #f0b429;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* ---------- settings panel ---------- */

.settings-panel { padding: 1.25rem 1.5rem; overflow-y: auto; }
.settings-panel h2 { margin: 0 0 0.75rem; }
.settings-section { border-top: 1px solid var(--border); padding: 1rem 0; }
.settings-section h3 { margin: 0 0 0.5rem; }

.settings-form { display: flex; flex-direction: column; gap: 0.35rem; max-width: 34rem; }
.settings-form label { font-size: 0.8125rem; font-weight: 600; color: var(--text-muted); margin-top: 0.4rem; }
.check-label { display: flex; align-items: center; gap: 0.5rem; font-weight: 400 !important; }
.settings-form textarea { resize: vertical; font-family: var(--mono); font-size: 0.85rem; }

.identity-form, .filter-form {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
    background: var(--surface);
}
.form-row { display: flex; gap: 0.5rem; margin-top: 0.5rem; }

.filter-grid {
    display: grid;
    grid-template-columns: minmax(9rem, auto) 1fr;
    gap: 0.35rem 0.75rem;
    align-items: center;
}
.filter-grid label { margin-top: 0 !important; }
.filter-when { display: flex; gap: 0.75rem; align-items: center; }
.filter-when .text-input { max-width: 16rem; }

details.new-identity, details.new-filter { margin-top: 0.5rem; }
details summary { cursor: pointer; color: var(--accent); font-weight: 600; }


/* ---------- contacts + autocomplete ---------- */

.ac-drop { position: relative; }
.ac-item {
    padding: 0.35rem 0.6rem;
    border: 1px solid var(--border);
    border-top: none;
    background: var(--surface);
    cursor: pointer;
    font-size: 0.875rem;
}
.ac-item:first-child { border-top: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius); }
.ac-item:hover { background: var(--surface-2); }

.contacts-panel { padding: 1.25rem 1.5rem; }
.contacts-panel h2 { margin: 0 0 0.75rem; }
.contacts-list { list-style: none; margin: 1rem 0 0; padding: 0; }
.contacts-list li {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}
code { background: var(--surface-2); border-radius: 4px; padding: 0.1rem 0.35rem; font-family: var(--mono); font-size: 0.85em; }

/* ---------- first-sync placeholder ---------- */

.sync-progress {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 2rem 1rem;
    text-align: center;
}

.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: nbox-spin 0.8s linear infinite;
    margin-bottom: 0.5rem;
}

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

.image-prompt {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    padding: 0.5rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    font-size: 0.875rem;
}

.badge-static {
    font-size: 0.75rem;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.05rem 0.5rem;
}
.muted-row .folder-name { color: var(--text-muted); }

/* ---------- context menu ---------- */

.ctx-menu {
    position: fixed;
    z-index: 1000;
    min-width: 200px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
    padding: 0.3rem 0;
    font-size: 0.875rem;
}
.ctx-menu hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 0.25rem 0;
}
.ctx-item, .ctx-header {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 0.4rem 1rem;
    cursor: pointer;
    color: var(--text);
    font-size: 0.875rem;
}
.ctx-item:hover { background: var(--surface-2); }
.ctx-danger { color: var(--danger); }
.ctx-header {
    color: var(--text-muted);
    font-weight: 600;
    cursor: default;
    pointer-events: none;
}

.ctx-submenu { position: relative; }
.ctx-submenu > .ctx-item::after { content: ""; }
.ctx-sub {
    display: none;
    position: absolute;
    left: 100%;
    top: 0;
    min-width: 180px;
    max-height: 320px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
    padding: 0.3rem 0;
}
.ctx-submenu:hover .ctx-sub { display: block; }

.standalone-message { max-width: 60rem; margin: 0 auto; padding: 1rem; }
.standalone-message .message-view { height: auto; }

/* ---------- spell dialog ---------- */

.spell-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.spell-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
    width: min(40rem, 100%);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}
.spell-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.9rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.spell-head h3 { margin: 0; font-size: 1.05rem; }
.spell-list { overflow-y: auto; padding: 0.5rem 1.25rem; }
.spell-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.spell-row:last-child { border-bottom: none; }
.spell-row-done { opacity: 0.55; }
.spell-word { font-weight: 600; min-width: 7rem; }
.spell-choice { width: auto; min-width: 9rem; padding: 0.3rem 0.4rem; }
.spell-custom { width: 8rem; padding: 0.3rem 0.5rem; }
.spell-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 0 0 var(--radius) var(--radius);
}

.ctx-divider {
    border-top: 1px solid var(--border);
    margin: 0.25rem 0;
    height: 0;
}

/* submenu opening upward (menu near the viewport bottom) */
.ctx-sub-up {
    top: auto;
    bottom: 0;
}

/* nested folders */
.folder-sub {
    list-style: none;
    margin: 0;
    padding-left: 0.9rem;
    border-left: 1px solid var(--border);
    margin-left: 1.1rem;
}

/* collapse/expand carets */
.folder-caret {
    flex-shrink: 0;
    background: none;
    border: none;
    padding: 0.2rem;
    margin-left: 0.3rem;
    cursor: pointer;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    border-radius: 4px;
}
.folder-caret:hover { color: var(--text); background: var(--surface-2); }
.folder-caret svg { transition: transform 0.15s ease; }
li.folder.collapsed > .folder-caret svg { transform: rotate(-90deg); }
li.folder.collapsed > .folder-sub { display: none; }
.folder-caret-spacer { width: 12px; margin-left: 0.3rem; flex-shrink: 0; }
li.folder { display: flex; align-items: center; flex-wrap: wrap; }
li.folder > a {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    min-width: 0;
}
li.folder > .folder-sub { flex-basis: 100%; }
.folder-caret { align-self: center; }
.folder[style*="--depth"] > a { padding-left: calc(1rem); }
.folder.display-only > a .folder-name { color: var(--text-muted); font-style: italic; }

.folders-manage .folder-row { margin-left: calc(var(--depth, 0) * 1.4rem); }

.spinner-sm { width: 13px; height: 13px; border-width: 2px; margin: 0; }
.sync-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* search in-flight indicator (htmx toggles .htmx-request on it) */
.search-indicator {
    display: none;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.78rem;
    color: var(--text-muted);
    padding: 0 0.4rem;
}
.search-indicator.htmx-request { display: inline-flex; }

/* filter quick form + legend */
.filter-quick { padding: 1.25rem 1.5rem; overflow-y: auto; }
.filter-quick h2 { margin: 0 0 0.5rem; }
.filter-legend { margin: 0.5rem 0 1rem; font-size: 0.875rem; }
.filter-legend summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.legend-list { margin: 0.5rem 0 0; padding-left: 1.2rem; color: var(--text-muted); display: flex; flex-direction: column; gap: 0.3rem; }
.legend-list code { background: var(--surface-2); border-radius: 4px; padding: 0 0.3rem; font-family: var(--mono); font-size: 0.85em; }

/* bulk-operation working state */
.row-busy { opacity: 0.45; pointer-events: none; transition: opacity 0.15s; }
.bulk-busy {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin: 0.25rem 0.5rem;
    padding: 0.3rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    box-shadow: var(--shadow);
    font-size: 0.8rem;
    color: var(--text-muted);
    width: fit-content;
}

/* Dark theme: invert hard-coded light-UI email colors so dark text
   stays readable. Symmetric — dark-themed mail becomes light but also
   readable. Images are re-inverted so photos don't turn negative. */
:root[data-theme="dark"] .msg-html {
    /* Force a light palette before inversion: color-less HTML (our own
       sent mail from the editor) inherits the page's light text, which
       the filter would turn dark-on-dark. Black-on-white inverts to
       white-on-black consistently with explicit-color mail. */
    background: #ffffff;
    color: #000000;
    filter: invert(1) hue-rotate(180deg);
    padding: 0.75rem;
    border-radius: 6px;
}
:root[data-theme="dark"] .msg-html img,
:root[data-theme="dark"] .msg-html video {
    filter: invert(1) hue-rotate(180deg);
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .msg-html {
        background: #ffffff;
        color: #000000;
        filter: invert(1) hue-rotate(180deg);
        padding: 0.75rem;
        border-radius: 6px;
    }
    :root:not([data-theme="light"]) .msg-html img,
    :root:not([data-theme="light"]) .msg-html video {
        filter: invert(1) hue-rotate(180deg);
    }
}

/* drag & drop: index rows → folders */
.row.drag-ghost-src { opacity: 0.4; }
.folder.drop-target > a {
    background: color-mix(in srgb, var(--accent) 18%, var(--surface));
    outline: 2px dashed var(--accent);
    outline-offset: -2px;
    border-radius: 4px;
}

/* rows are drag sources; suppress accidental text selection during drag */
.message-list .row { -webkit-user-select: none; user-select: none; }

/* password-style masking for inputs that must not trigger browser
   password managers (Chrome ignores autocomplete=off on password
   fields, but never masks or saves plain text inputs) */
.pw-mask {
    -webkit-text-security: disc;
}

.folder-create label { font-size: 0.8125rem; }

/* quoted original preview (outside the editor, sent raw) */
.reply-quote {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 0.5rem;
    font-size: 0.875rem;
}
.reply-quote > summary {
    cursor: pointer;
    padding: 0.4rem 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
}
.reply-quote-body {
    max-height: 280px;
    overflow-y: auto;
    padding: 0.75rem;
    border-top: 1px solid var(--border);
}

/* Message view paragraph spacing: mail bodies are HTML fragments with
   no stylesheet of their own, so every <p> would take the browser's
   ~1em default and a single Enter would read as a double gap. The .5em
   gap matches the composer; quoted originals keep their own inline
   styling and signature lines stack tight. Outgoing mail gets the same
   spacing inline (mailparse.InlineParagraphSpacing) so external
   clients match what is shown here. */
.msg-html p,
.reply-quote-body p { margin: 0 0 .5em; }
.msg-html blockquote p,
.msg-html .nbox-signature p,
.reply-quote-body blockquote p,
.reply-quote-body .nbox-signature p { margin: 0; }

/* rich signature editor in settings */
.sig-editor {
    min-height: 70px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}
.sig-editor .ql-editor { min-height: 70px; font-size: 0.9rem; }

/* visual breathing room above the signature block */
.nbox-signature { margin-top: 0.75rem; }

/* calendar invite card above the message body */
.invite-card {
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
}
.invite-card .invite-banner {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--accent);
}
.invite-card .invite-banner.cancelled { color: var(--danger, #b3261e); }
.invite-card .invite-summary { font-weight: 600; margin-top: 0.15rem; }
.invite-card .invite-desc {
    white-space: pre-wrap;
    font-size: 0.9rem;
    margin-top: 0.35rem;
}
.invite-card .invite-actions { display: flex; gap: 0.5rem; margin-top: 0.6rem; }
