:root {
    --bg: #030303;
    --bg-elev: #0c0c10;
    --bg-elev-2: #14141a;
    --text: #EDEDED;
    --text-dim: #A0A0A0;
    --text-dimmer: #6E6E6E;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.16);
    --accent: #A855F7;
    --accent-soft: rgba(168, 85, 247, 0.12);
    --green: #22C55E;
    --orange: #F97316;
    --blue: #3B82F6;
    --red: #FF5F57;
    --surface-1: rgba(255, 255, 255, 0.03);
    --surface-2: rgba(255, 255, 255, 0.06);
}

:root[data-theme="light"] {
    --bg: #F5F4EE;
    --bg-elev: #FFFFFF;
    --bg-elev-2: #FAFAF7;
    --text: #1A1A1F;
    --text-dim: #5A5A60;
    --text-dimmer: #8E8E94;
    --border: rgba(0, 0, 0, 0.10);
    --border-strong: rgba(0, 0, 0, 0.18);
    --accent: #9333EA;
    --accent-soft: rgba(147, 51, 234, 0.10);
    --green: #16A34A;
    --orange: #EA580C;
    --blue: #2563EB;
    --red: #DC2626;
    --surface-1: rgba(0, 0, 0, 0.03);
    --surface-2: rgba(0, 0, 0, 0.06);
}

html { color-scheme: dark; }
html[data-theme="light"] { color-scheme: light; }
body { transition: background 0.2s ease, color 0.2s ease; }

/* Compact list density */
html[data-density="compact"] .message-row { padding: 7px 16px; }
html[data-density="compact"] .message-subject,
html[data-density="compact"] .message-from { font-size: 12px; }
html[data-density="compact"] .row-main { gap: 1px; }

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    line-height: 1.5;
    overflow: hidden;
}

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

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

/* ===== LOGIN ===== */

.login-body {
    display: flex; align-items: center; justify-content: center;
    min-height: 100dvh;
    padding: 24px;
    overflow: auto;
}
.login-card {
    width: 100%; max-width: 380px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px 32px;
    text-align: center;
    box-shadow: 0 40px 80px -20px rgba(0,0,0,0.6);
}
.login-glyph {
    font-size: 48px;
    color: var(--accent);
    margin-bottom: 8px;
}
.login-card h1 {
    font-family: 'Instrument Serif', serif;
    font-size: 36px; font-weight: 400;
    margin-bottom: 6px;
}
.login-sub {
    color: var(--text-dim);
    font-size: 13px;
    margin-bottom: 28px;
}
.field {
    text-align: left;
    margin-bottom: 14px;
}
.field label {
    display: block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-dimmer);
    margin-bottom: 6px;
}
.field input, .field textarea, .field select {
    width: 100%;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 11px 14px;
    font-size: 14px;
    transition: border-color 0.15s;
    color: var(--text);
}
.field select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23A0A0A0' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
    cursor: pointer;
}
.field input:focus, .field textarea:focus, .field select:focus {
    outline: none;
    border-color: var(--accent);
    background-color: var(--bg-elev-2);
}
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-1);
    cursor: pointer;
    font-size: 13px;
    transition: 0.15s;
    text-decoration: none;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn-primary {
    background: var(--text); color: var(--bg); border-color: var(--text);
    width: 100%; padding: 12px; font-weight: 500;
    margin-top: 4px;
}
.btn-primary:hover { background: #fff; }
.btn-icon {
    width: 32px; height: 32px; padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
}
.login-error {
    margin-top: 16px;
    padding: 10px 12px;
    background: rgba(255, 95, 87, 0.1);
    border: 1px solid rgba(255, 95, 87, 0.3);
    border-radius: 8px;
    font-size: 12px;
    color: #FCA5A5;
    text-align: left;
}

/* ===== APP LAYOUT ===== */

.app {
    display: grid;
    grid-template-columns: 240px 360px 1fr;
    height: 100dvh;
    background: var(--bg);
}

/* --- Sidebar --- */

.sidebar {
    background: var(--bg-elev);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    overflow: hidden;
}
.sidebar-header {
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.brand {
    font-family: 'Instrument Serif', serif;
    font-size: 22px; font-weight: 400;
    color: var(--text);
    display: flex; align-items: center; gap: 8px;
}
.brand-glyph { color: var(--accent); }
.user-menu {
    position: relative;
}
.user-button {
    background: transparent; border: none; cursor: pointer;
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--surface-2); color: var(--text);
    font-size: 11px; font-weight: 500;
    display: flex; align-items: center; justify-content: center;
}
.user-button:hover { background: var(--surface-1); border: 1px solid var(--border-strong); }
/* Theme toggle: show moon on dark, sun on light */
#themeBtn .icon-theme-light { display: none; }
:root[data-theme="light"] #themeBtn .icon-theme-dark { display: none; }
:root[data-theme="light"] #themeBtn .icon-theme-light { display: inline; }

.compose-btn {
    margin: 14px 14px 8px;
    padding: 10px 14px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    transition: 0.15s;
}
.compose-btn:hover { background: #9333EA; transform: translateY(-1px); }

.folder-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 8px 16px;
    list-style: none;
}
.folder-list li {
    padding: 0;
}
.folder-list button {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-dim);
    text-align: left;
    padding: 9px 12px;
    border-radius: 6px;
    cursor: pointer;
    display: flex; align-items: center; gap: 10px;
    font-size: 13px;
    transition: 0.1s;
}
.folder-list button:hover {
    background: var(--surface-1);
    color: var(--text);
}
.folder-list button.active {
    background: var(--accent-soft);
    color: var(--text);
}
.folder-list .folder-icon {
    width: 16px; text-align: center;
    flex-shrink: 0;
    color: inherit;
}
.folder-list .folder-name { flex: 1; }
.folder-list .folder-count {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--text-dimmer);
}
.folder-list button.active .folder-count { color: var(--accent); }

.folder-group-header {
    padding: 14px 12px 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-dimmer);
    display: flex; align-items: center; gap: 8px;
    pointer-events: none;
}
.account-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* --- Message list pane --- */

.list-pane {
    background: var(--bg-elev-2);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    overflow: hidden;
}
.list-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 10px;
}
.list-title {
    font-family: 'Instrument Serif', serif;
    font-size: 20px;
    flex: 1;
}
.search-box {
    flex: 1;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 7px 10px;
    font-size: 12px;
    transition: border-color 0.15s;
}
.search-box:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--bg-elev);
}

.message-list {
    flex: 1;
    overflow-y: auto;
    list-style: none;
}
.message-row {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.1s;
    display: flex; gap: 12px;
    position: relative;
}
.message-row:hover { background: var(--surface-1); }
.message-row.active { background: var(--accent-soft); }
.message-row.selected { background: rgba(168, 85, 247, 0.12); }
.message-row.selected.active { background: rgba(168, 85, 247, 0.22); }
.message-row.keyboard-cursor {
    box-shadow: inset 3px 0 0 var(--accent);
}

.row-main {
    flex: 1; min-width: 0;
    display: flex; flex-direction: column; gap: 4px;
}
.row-check {
    background: transparent; border: none; cursor: pointer;
    color: var(--text-dimmer);
    width: 22px; height: 22px;
    padding: 0; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    margin-top: 1px;
    opacity: 0.6;
    transition: opacity 0.15s, color 0.15s;
}
.row-check:hover { opacity: 1; }
.message-row.selected .row-check { color: var(--accent); opacity: 1; }
.row-check .icon { width: 14px; height: 14px; }

.bulk-bar {
    display: flex; align-items: center; gap: 6px;
    padding: 8px 14px;
    background: rgba(168, 85, 247, 0.08);
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    color: var(--text);
}
.bulk-bar .bulk-count {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    color: var(--accent);
    margin-right: 4px;
}
.bulk-bar .spacer { flex: 1; }
.bulk-bar .btn-icon {
    width: 28px; height: 28px;
}
.message-row.unseen { font-weight: 500; }
.message-row.unseen::before {
    content: '';
    position: absolute;
    left: 4px; top: 50%;
    width: 4px; height: 4px;
    background: var(--accent);
    border-radius: 50%;
    transform: translateY(-50%);
}
.message-row-top {
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.account-badge {
    display: inline-block;
    width: 6px; height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}
.account-chip {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid;
    letter-spacing: 0.03em;
    margin-right: 8px;
}
.thread-count {
    background: var(--surface-2);
    color: var(--text-dim);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1px 7px;
    font-size: 10px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    line-height: 1.4;
    flex-shrink: 0;
}
.message-row.unseen .thread-count {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: rgba(168, 85, 247, 0.3);
}
.message-from {
    font-size: 13px;
    color: var(--text);
    flex: 1;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.message-row.seen .message-from { color: var(--text-dim); }
.message-date {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: var(--text-dimmer);
    flex-shrink: 0;
}
.message-subject {
    font-size: 13px;
    color: var(--text-dim);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.message-row.unseen .message-subject { color: var(--text); }
.message-meta {
    display: flex; gap: 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 9px;
    color: var(--text-dimmer);
}
/* --- Settings modal --- */
.settings-backdrop {
    position: fixed; inset: 0; z-index: 120;
    background: rgba(0,0,0,0.6);
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
}
.settings-backdrop[hidden] { display: none !important; }
.settings-modal {
    background: var(--bg-elev);
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    width: 100%; max-width: 560px;
    max-height: 85vh;
    display: flex; flex-direction: column;
    box-shadow: 0 40px 100px -20px rgba(0,0,0,0.7);
}
.settings-header {
    display: flex; align-items: center;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.settings-header h2 { flex: 1; font-family: 'Instrument Serif', serif; font-weight: 400; font-size: 22px; }
.settings-body { padding: 12px 20px; overflow-y: auto; }
.settings-section { padding: 12px 0; border-bottom: 1px solid var(--border); }
.settings-section:last-child { border-bottom: none; }
.settings-section h3 {
    font-family: 'JetBrains Mono', monospace; font-size: 11px;
    letter-spacing: 0.1em; text-transform: uppercase;
    color: var(--text-dimmer); margin-bottom: 12px;
}
.settings-sig { margin-bottom: 14px; }
.settings-sig label {
    display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 4px;
    font-family: 'JetBrains Mono', monospace;
}
.settings-sig textarea {
    width: 100%; min-height: 70px; resize: vertical;
    background: var(--bg-elev-2); border: 1px solid var(--border);
    border-radius: 8px; padding: 10px 12px; color: var(--text);
    font-family: inherit; font-size: 13px; line-height: 1.5;
}
.settings-sig textarea:focus { outline: none; border-color: var(--accent); }
.settings-field {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin-bottom: 12px; font-size: 14px;
}
.settings-field select {
    background: var(--bg-elev-2); border: 1px solid var(--border);
    border-radius: 8px; padding: 8px 12px; color: var(--text); font-size: 13px;
    min-width: 160px;
}
.settings-footer {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 20px; border-top: 1px solid var(--border);
}
.settings-footer .spacer { flex: 1; }
.settings-status { font-size: 12px; color: var(--green); }

/* --- Conversation (thread) view --- */
.conversation-count {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 4px;
}
.conversation {
    flex: 1;
    overflow-y: auto;
    padding: 12px 20px 60px;
    display: flex; flex-direction: column; gap: 10px;
}
.conv-msg {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-1);
    overflow: hidden;
}
.conv-msg.expanded { background: var(--bg-elev); }
.conv-msg-head {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 16px;
    cursor: pointer;
    user-select: none;
}
.conv-msg-head:hover { background: var(--surface-2); }
.conv-from { display: flex; flex-direction: column; gap: 1px; flex: 1; min-width: 0; }
.conv-from-name { font-size: 13px; font-weight: 500; color: var(--text); }
.conv-from-addr { font-size: 11px; color: var(--text-dim); font-family: 'JetBrains Mono', monospace; }
.conv-date { font-size: 11px; color: var(--text-dimmer); font-family: 'JetBrains Mono', monospace; flex-shrink: 0; }
.conv-preview {
    padding: 0 16px 10px;
    font-size: 12px; color: var(--text-dim);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv-msg.expanded .conv-preview { display: none; }
.conv-body { padding: 0 16px 8px; }
.conv-msg.collapsed .conv-body { display: none; }

/* --- Loading skeletons --- */
@keyframes skeleton-shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}
.skeleton {
    background: linear-gradient(90deg,
        var(--surface-1) 25%,
        var(--surface-2) 50%,
        var(--surface-1) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.4s ease-in-out infinite;
    border-radius: 4px;
}
@media (prefers-reduced-motion: reduce) {
    .skeleton { animation: none; }
}
.skeleton-row {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 8px;
}
.skeleton-row .sk-line-1 { height: 12px; width: 45%; }
.skeleton-row .sk-line-2 { height: 11px; width: 80%; }
.skeleton-reader { padding: 24px 28px; display: flex; flex-direction: column; gap: 14px; }
.skeleton-reader .sk-subject { height: 22px; width: 60%; }
.skeleton-reader .sk-meta { height: 11px; width: 40%; }
.skeleton-reader .sk-body { height: 12px; }
.skeleton-reader .sk-body.short { width: 70%; }

.empty-state {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-dimmer);
    font-size: 13px;
    font-family: 'JetBrains Mono', monospace;
}

.pagination-bar {
    display: flex; align-items: center; justify-content: center; gap: 12px;
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    background: var(--bg-elev);
}
.pagination-bar .page-info {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--text-dim);
}
.pagination-bar button { width: 32px; height: 32px; font-size: 16px; line-height: 1; }
.pagination-bar button:disabled { opacity: 0.3; cursor: not-allowed; }

/* --- Reader pane --- */

.reader-pane {
    background: var(--bg);
    display: flex; flex-direction: column;
    overflow: hidden;
}
.reader-empty {
    flex: 1;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-dimmer);
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
}
.reader-toolbar {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 8px;
    position: relative;
}
.reader-toolbar .spacer { flex: 1; }
/* Overflow toggle is mobile-only; on desktop every action is shown inline. */
.toolbar-more { display: none; }

.reader-header {
    padding: 20px 28px 16px;
    border-bottom: 1px solid var(--border);
}
.reader-subject {
    font-family: 'Instrument Serif', serif;
    font-size: 26px;
    font-weight: 400;
    line-height: 1.2;
    margin-bottom: 10px;
}
.reader-meta {
    font-size: 12px;
    color: var(--text-dim);
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 4px 12px;
    align-items: baseline;
}
.reader-meta .label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    letter-spacing: 0.05em;
    color: var(--text-dimmer);
    text-transform: uppercase;
}
.reader-attachments {
    margin-top: 12px;
    display: flex; flex-wrap: wrap; gap: 8px;
}
.attachment-chip {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 11px;
    color: var(--text-dim);
    text-decoration: none;
}
.attachment-chip:hover {
    background: var(--surface-2);
    color: var(--text);
    text-decoration: none;
}

.reader-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px 24px 80px;
    line-height: 1.65;
    font-size: 14.5px;
}
.reader-body > pre {
    white-space: pre-wrap;
    font-family: 'Inter', sans-serif;
    font-size: inherit;
    line-height: 1.65;
    padding: 16px 4px;
    margin: 0;
}
.mail-iframe {
    width: 100%;
    border: none;
    background: transparent;
    display: block;
    min-height: 200px;
}
.remote-banner[hidden] { display: none !important; }
.remote-banner {
    display: flex; align-items: center; gap: 10px;
    margin: 0 0 12px;
    padding: 9px 12px;
    background: rgba(249, 115, 22, 0.08);
    border: 1px solid rgba(249, 115, 22, 0.25);
    border-radius: 8px;
    font-size: 12px;
    color: var(--text-dim);
}
.remote-banner .icon { color: var(--orange); flex-shrink: 0; }
.remote-banner span { flex: 1; }
.remote-load-btn {
    background: transparent;
    border: 1px solid var(--orange);
    color: var(--orange);
    padding: 5px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    transition: 0.15s;
}
.remote-load-btn:hover { background: rgba(249, 115, 22, 0.15); }

/* ===== COMPOSE MODAL ===== */

/* --- Gmail-style compose dock --- */
.compose-dock {
    position: fixed;
    right: 24px; bottom: 0;
    width: 540px; max-width: calc(100vw - 48px);
    height: 560px; max-height: calc(100vh - 40px);
    background: var(--bg-elev);
    border: 1px solid var(--border-strong);
    border-bottom: none;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 24px 60px -12px rgba(0,0,0,0.7);
    z-index: 100;
    display: flex; flex-direction: column;
    overflow: hidden;
    animation: composeIn 0.18s ease-out;
}
.compose-dock[hidden] { display: none !important; }
@keyframes composeIn {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
.compose-dock.minimized { height: auto; }
.compose-dock.minimized .compose-form { display: none; }

.compose-titlebar {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 14px;
    background: var(--bg-elev-2);
    border-bottom: 1px solid var(--border);
    cursor: pointer;            /* click to toggle minimize */
    user-select: none;
}
.compose-title {
    flex: 1;
    font-size: 13px; font-weight: 500;
    color: var(--text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.compose-titlebar-actions { display: flex; gap: 2px; }
.compose-tb-btn {
    background: transparent; border: none; cursor: pointer;
    color: var(--text-dim);
    width: 28px; height: 28px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
}
.compose-tb-btn:hover { background: var(--surface-2); color: var(--text); }
.compose-tb-btn .icon { width: 15px; height: 15px; }

.compose-form {
    display: flex; flex-direction: column;
    flex: 1; min-height: 0;
}
.compose-fields {
    padding: 4px 14px;
    border-bottom: 1px solid var(--border);
}
.compose-row {
    display: flex; align-items: center; gap: 8px;
    border-bottom: 1px solid var(--border);
    position: relative;
}
.compose-row:last-child { border-bottom: none; }
.compose-row[hidden] { display: none; }
.compose-row input,
.compose-row .compose-from {
    flex: 1;
    background: transparent;
    border: none;
    padding: 10px 2px;
    font-size: 13px;
    color: var(--text);
    outline: none;
}
.compose-row .compose-from { color: var(--text-dim); cursor: pointer; }
.compose-cc-toggle {
    background: transparent; border: none; cursor: pointer;
    color: var(--text-dim); font-size: 12px; padding: 4px 6px;
}
.compose-cc-toggle:hover { color: var(--text); }

.compose-toolbar {
    display: flex; align-items: center; gap: 2px;
    padding: 6px 12px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.fmt-btn {
    background: transparent; border: none; cursor: pointer;
    color: var(--text-dim);
    min-width: 28px; height: 28px; border-radius: 6px;
    font-size: 14px; line-height: 1;
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0 6px;
}
.fmt-btn:hover { background: var(--surface-2); color: var(--text); }
.fmt-btn.active { background: var(--accent-soft); color: var(--accent); }
.fmt-sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }
.compose-toolbar { gap: 1px; }
.fmt-select {
    background: transparent; border: 1px solid transparent;
    color: var(--text-dim); cursor: pointer;
    height: 28px; border-radius: 6px; padding: 0 4px;
    font-size: 12px; max-width: 110px;
}
.fmt-select:hover { background: var(--surface-2); color: var(--text); }
.fmt-select:focus { outline: none; border-color: var(--border); }
.fmt-color { position: relative; overflow: hidden; }
.fmt-color input[type="color"] {
    position: absolute; inset: 0; opacity: 0; cursor: pointer; border: none; padding: 0;
}
.fmt-highlight { color: var(--text-dim); }

.emoji-picker {
    position: fixed;
    z-index: 130;
    background: var(--bg-elev);
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    box-shadow: 0 16px 40px -10px rgba(0,0,0,0.6);
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    max-width: 300px;
    max-height: 220px;
    overflow-y: auto;
}
.emoji-picker[hidden] { display: none !important; }
.emoji-picker button {
    background: transparent; border: none; cursor: pointer;
    font-size: 18px; width: 32px; height: 32px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
}
.emoji-picker button:hover { background: var(--surface-2); }

/* Editor content styles */
.compose-editor h1 { font-size: 1.6em; font-weight: 600; margin: 8px 0; }
.compose-editor h2 { font-size: 1.35em; font-weight: 600; margin: 8px 0; }
.compose-editor h3 { font-size: 1.15em; font-weight: 600; margin: 6px 0; }
.compose-editor pre {
    background: var(--surface-1); border: 1px solid var(--border);
    border-radius: 6px; padding: 10px 12px; overflow-x: auto;
    font-family: 'JetBrains Mono', monospace; font-size: 0.9em;
    white-space: pre-wrap;
}
.compose-editor table { border-collapse: collapse; margin: 8px 0; }
.compose-editor td, .compose-editor th { border: 1px solid var(--border-strong); padding: 6px 10px; min-width: 40px; }
.compose-editor img { max-width: 100%; height: auto; border-radius: 4px; }
.compose-editor hr { border: none; border-top: 1px solid var(--border-strong); margin: 12px 0; }
.compose-editor.drag-over { outline: 2px dashed var(--accent); outline-offset: -4px; }

.compose-editor {
    flex: 1; min-height: 0;
    overflow-y: auto;
    padding: 14px;
    font-size: 14px; line-height: 1.6;
    color: var(--text);
    outline: none;
}
.compose-editor:empty::before {
    content: attr(data-placeholder);
    color: var(--text-dimmer);
    pointer-events: none;
}
.compose-editor blockquote {
    border-left: 3px solid var(--border-strong);
    margin: 8px 0; padding-left: 12px; color: var(--text-dim);
}
/* The global `* { padding:0 }` reset strips list indentation — restore it so
   list markers (1., •) stay inside the editor instead of spilling left. */
.compose-editor ul, .compose-editor ol { padding-left: 24px; margin: 4px 0; }
.compose-editor li { margin: 2px 0; }
.compose-editor p { margin: 0 0 8px; }
.compose-editor a { color: var(--accent); }

/* legacy field positioning kept for autocomplete anchoring */
.compose-row { }

.autocomplete-list {
    position: absolute;
    top: 100%; left: 0; right: 0;
    margin-top: 2px;
    background: var(--bg-elev-2);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    box-shadow: 0 10px 30px -10px rgba(0,0,0,0.6);
    overflow: hidden;
    z-index: 50;
    max-height: 280px;
    overflow-y: auto;
}
.autocomplete-item {
    padding: 8px 12px;
    cursor: pointer;
    display: flex; flex-direction: column; gap: 2px;
    font-size: 13px;
    transition: background 0.1s;
}
.autocomplete-item:hover, .autocomplete-item.active {
    background: var(--accent-soft);
}
.autocomplete-item .ac-name { color: var(--text); }
.autocomplete-item .ac-addr {
    color: var(--text-dim);
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
}
.autocomplete-item.active .ac-addr { color: var(--accent); }
.compose-footer {
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    display: flex; align-items: center; gap: 8px;
    flex-shrink: 0;
}
.compose-footer .spacer { flex: 1; }
.compose-send { width: auto; padding: 9px 20px; }
.attach-list {
    display: flex; flex-wrap: wrap; gap: 6px;
    margin-top: 6px;
}
.attach-pill {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 11px;
    color: var(--text-dim);
    display: inline-flex; align-items: center; gap: 6px;
}
.attach-pill button {
    background: transparent; border: none; color: var(--text-dimmer); cursor: pointer;
    font-size: 14px; line-height: 1;
    padding: 0; margin: 0;
}
.attach-pill button:hover { color: var(--red); }

/* Status banner */
.toast {
    position: fixed; bottom: 24px; right: 24px;
    padding: 12px 16px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    box-shadow: 0 20px 40px -10px rgba(0,0,0,0.6);
    z-index: 200;
    transition: opacity 0.2s, transform 0.2s;
}
.toast.error { border-color: rgba(255, 95, 87, 0.4); color: #FCA5A5; }
.toast.success { border-color: rgba(34, 197, 94, 0.4); color: #86EFAC; }
.toast.hidden { opacity: 0; transform: translateY(8px); pointer-events: none; }

.undo-toast {
    position: fixed; bottom: 24px; left: 50%;
    transform: translateX(-50%);
    background: var(--bg-elev);
    border: 1px solid var(--border-strong);
    padding: 10px 14px;
    border-radius: 8px;
    display: flex; align-items: center; gap: 12px;
    box-shadow: 0 20px 40px -10px rgba(0,0,0,0.6);
    z-index: 250;
    font-size: 13px;
}
.undo-toast.hidden { display: none; }
.undo-progress {
    width: 60px; height: 3px;
    background: var(--surface-2);
    border-radius: 2px; overflow: hidden;
}
.undo-progress-bar {
    height: 100%;
    background: var(--accent);
    animation: undo-progress 5s linear forwards;
    transform-origin: left;
}
@keyframes undo-progress {
    from { transform: scaleX(0); }
    to { transform: scaleX(1); }
}
.undo-btn {
    background: transparent;
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 4px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: 0.15s;
}
.undo-btn:hover { background: var(--accent-soft); }

/* Image preview modal */
.image-preview {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.92);
    z-index: 300;
    display: flex; align-items: center; justify-content: center;
    padding: 40px;
}
.image-preview.hidden { display: none; }
.image-preview img {
    max-width: 100%; max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 40px 80px -20px rgba(0,0,0,0.6);
}
.image-preview-close {
    position: absolute; top: 20px; right: 20px;
    width: 40px; height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.image-preview-close:hover { background: rgba(255, 255, 255, 0.2); }

/* ===== ICONS ===== */

.icon {
    width: 16px; height: 16px;
    flex-shrink: 0;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ===== MOBILE ===== */

@media (max-width: 900px) {
    .app {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        height: 100dvh;
    }
    .sidebar {
        grid-row: 1; grid-column: 1;
        flex-direction: row;
        align-items: center;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
        overflow-x: auto;
        overflow-y: hidden;
        padding-top: env(safe-area-inset-top);
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .sidebar::-webkit-scrollbar { display: none; }

    /* Keep a compact header chip (logout) visible on mobile instead of hiding it. */
    .sidebar-header {
        display: flex;
        flex-direction: column;
        padding: 0 8px;
        border-bottom: none;
        flex-shrink: 0;
    }
    .sidebar-header .brand { display: none; }
    .user-button { width: 36px; height: 36px; }

    .compose-btn {
        margin: 8px 4px;
        padding: 10px 14px;
        flex-shrink: 0;
        min-height: 40px;
    }
    .compose-btn span, .compose-btn .label { display: none; }   /* icon-only on mobile */

    .folder-list {
        display: flex;
        gap: 4px;
        padding: 8px 4px;
        flex: 1;
        align-items: center;
    }
    .folder-list li { flex-shrink: 0; }
    .folder-list button {
        padding: 9px 14px;
        font-size: 13px;
        white-space: nowrap;
        min-height: 40px;
    }
    .folder-list .folder-count { display: none; }
    .folder-group-header { display: none; }   /* account grouping headers clutter the strip */

    .list-pane {
        grid-row: 2; grid-column: 1;
        border-right: none;
        min-height: 0;
    }

    /* Bigger tap targets in the message list */
    .message-row { padding: 14px 14px; }
    .row-check { width: 28px; height: 28px; }
    .row-check .icon { width: 18px; height: 18px; }
    .list-header { padding: 10px 12px; }
    .search-box { font-size: 16px; }   /* >=16px stops iOS zoom-on-focus */
    .bulk-bar { padding: 10px 12px; }
    .bulk-bar .btn-icon { width: 36px; height: 36px; }

    /* Reader as a full-screen slide-over */
    .reader-pane {
        position: fixed;
        inset: 0;
        z-index: 50;
        background: var(--bg);
        transform: translateX(100%);
        transition: transform 0.25s;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
    .reader-pane.open { transform: translateX(0); }
    .reader-toolbar { padding: 10px 12px; gap: 6px; flex-wrap: nowrap; }
    .reader-toolbar .btn { padding: 9px 12px; min-height: 42px; min-width: 42px; }
    .reader-toolbar .btn span { display: none; }   /* icon-only: Reply, Back, Delete */

    /* On mobile, secondary actions collapse into an overflow popover.
       JS moves the .toolbar-secondary buttons into a .toolbar-overflow wrapper. */
    .toolbar-more { display: inline-flex; }
    .reader-toolbar > .toolbar-secondary { display: none; }   /* hidden in the main bar */

    .toolbar-overflow {
        display: none;
        position: absolute; top: 100%; right: 8px;
        margin-top: 4px; z-index: 20;
        background: var(--bg-elev);
        border: 1px solid var(--border); border-radius: 12px;
        box-shadow: 0 20px 50px -12px rgba(0,0,0,0.7);
        padding: 6px; flex-direction: column; gap: 2px; min-width: 190px;
    }
    .reader-toolbar.show-more .toolbar-overflow { display: flex; }
    .toolbar-overflow .toolbar-secondary {
        display: flex !important;
        position: static; width: 100%;
        justify-content: flex-start; gap: 12px;
        min-height: 46px; padding: 10px 14px;
        background: transparent; border: none; border-radius: 8px;
    }
    .toolbar-overflow .toolbar-secondary span { display: inline; }
    .toolbar-overflow .toolbar-secondary:hover { background: var(--surface-2); }
    .reader-header { padding: 16px 16px 12px; }
    .reader-subject { font-size: 21px; }
    .reader-body { padding: 8px 14px 64px; }

    /* Compose dock becomes a full-screen sheet on mobile */
    .compose-dock {
        right: 0; bottom: 0; left: 0; top: 0;
        width: 100%; max-width: 100%;
        height: 100dvh; max-height: 100dvh;
        border: none; border-radius: 0;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
    .compose-dock.minimized { height: 100dvh; }   /* no minimize on mobile */
    .compose-dock.minimized .compose-form { display: flex; }
    .compose-minimize { display: none; }
    .compose-row input, .compose-row .compose-from { font-size: 16px; }  /* no iOS zoom */
    .compose-editor { font-size: 16px; }
    .compose-footer .btn { min-height: 44px; }

    .toast { left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); text-align: center; }

    /* --- Swipe gestures on message rows --- */
    .message-row {
        position: relative;
        overflow: hidden;
        touch-action: pan-y;       /* allow vertical scroll, capture horizontal */
    }
    .message-row .row-main,
    .message-row .row-check {
        transition: transform 0.18s ease;
        will-change: transform;
    }
    .message-row.swiping .row-main,
    .message-row.swiping .row-check { transition: none; }
    /* action labels revealed behind the sliding content */
    .swipe-action {
        position: absolute; top: 0; bottom: 0;
        display: flex; align-items: center;
        font-family: 'JetBrains Mono', monospace; font-size: 12px;
        font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase;
        color: #fff; padding: 0 18px;
        pointer-events: none;
        z-index: 0;
    }
    .swipe-action.left  { left: 0;  background: var(--green);  }   /* swipe right → archive */
    .swipe-action.right { right: 0; background: var(--red); justify-content: flex-end; }  /* swipe left → delete */
    /* Solid backdrop so the colored action panels stay hidden until you swipe. */
    .message-row { background: var(--bg-elev-2); }
    .message-row.active, .message-row.selected { background: var(--bg-elev-2); }
    .message-row .row-main, .message-row .row-check { position: relative; z-index: 1; background: var(--bg-elev-2); }
    .message-row.active .row-main, .message-row.active .row-check { background: var(--accent-soft); }
    .message-row.selected .row-main, .message-row.selected .row-check { background: rgba(168, 85, 247, 0.12); }
}
