/* 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: 230px 360px 1fr;
    height: 100vh;
    overflow: hidden;
}

.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.75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.875rem;
}
.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);
}
.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); }

.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-meta { font-size: 0.875rem; color: var(--text-muted); display: flex; flex-direction: column; gap: 0.15rem; }
.view-meta .label { display: inline-block; min-width: 3rem; font-weight: 600; color: var(--text-muted); }

.view-actions { display: flex; gap: 0.5rem; margin-top: 0.9rem; align-items: center; }
.view-actions .spacer { flex: 1; }

.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: 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);
}
.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; }

.sidebar-tools { display: flex; flex-direction: column; gap: 0.25rem; align-items: flex-start; }

/* ---------- 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; }
