/* ============================================================
   MailDeck — Modern minimal UI
   Violet accent · soft shadows · generous whitespace
   ============================================================ */

:root {
    --accent:        #6D5DF6;
    --accent-strong: #5B4BE0;
    --accent-soft:   #EEEBFE;
    --bg:            #F6F5FB;
    --surface:       #FFFFFF;
    --border:        #E9E7F4;
    --text:          #23213C;
    --muted:         #716E8A;
    --danger:        #E5484D;
    --ok:            #2FA96C;
    --warn:          #F5A623;
    --star:          #F5A623;
    --radius:        14px;
    --radius-sm:     9px;
    --shadow:        0 1px 2px rgba(28,25,60,.05), 0 10px 30px rgba(28,25,60,.07);
    --shadow-soft:   0 1px 3px rgba(28,25,60,.07);
    --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --topbar-h: 58px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14.5px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0 0 .35em; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--accent-soft); border-radius: 5px; padding: 1px 6px; font-size: .92em; }

.muted { color: var(--muted); }
.ic { width: 18px; height: 18px; vertical-align: -3px; }

/* ---------------- buttons & inputs ---------------- */
.btn {
    display: inline-flex; align-items: center; gap: 7px; justify-content: center;
    border: 1px solid transparent; border-radius: 10px;
    padding: 9px 16px; font: inherit; font-weight: 550; cursor: pointer;
    transition: background .15s, box-shadow .15s, transform .05s;
    white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 6px 16px rgba(109,93,246,.28); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); box-shadow: var(--shadow-soft); }
.btn-ghost:hover { background: #FAF9FE; }
.btn-ghost.danger, .icon-btn.danger { color: var(--danger); }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border-radius: 9px; border: none;
    background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent-strong); }
.icon-btn.danger:hover { background: #FDECEC; color: var(--danger); }

.link-btn { background: none; border: none; color: var(--accent); font: inherit; font-size: 12.5px; cursor: pointer; padding: 0 4px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12.5px; font-weight: 550; color: var(--muted); margin-bottom: 5px; }
.field em.muted { font-weight: 400; font-style: normal; }
input, select, textarea {
    width: 100%; font: inherit; color: var(--text);
    border: 1.5px solid var(--border); border-radius: 10px;
    padding: 9px 12px; background: var(--surface);
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(109,93,246,.15);
}
input[disabled] { background: #F3F2F9; color: var(--muted); }
textarea { resize: vertical; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; min-width: 0; }
.field-row .field.slim { flex: 0 0 110px; }
.check { display: flex; gap: 9px; align-items: flex-start; font-size: 13.5px; margin: 8px 0; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); margin-top: 2px; }
.check-inline { display: inline-flex; align-items: center; margin-top: 22px; }

/* ---------------- topbar ---------------- */
.topbar {
    position: sticky; top: 0; z-index: 40;
    height: var(--topbar-h);
    display: flex; align-items: center; gap: 18px;
    padding: 0 18px;
    background: rgba(255,255,255,.82);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: 9px; font-weight: 700; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; border-radius: 9px;
    background: linear-gradient(135deg, var(--accent), #8F7BFF);
    color: #fff; font-weight: 800; font-size: 16px;
}
.brand-name { font-size: 16.5px; }
.brand-tag { font-size: 11px; color: var(--muted); border: 1px solid var(--border); padding: 2px 8px; border-radius: 999px; }

.topbar-search { flex: 1; max-width: 520px; position: relative; }
.topbar-search .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.topbar-search input { padding: 9px 12px 9px 38px; border-radius: 999px; background: #F3F2F9; border-color: transparent; }
.topbar-search input:focus { background: #fff; }

.topbar-nav { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.topbar-nav a {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border-radius: 10px; color: var(--muted);
}
.topbar-nav a:hover, .topbar-nav a.active { background: var(--accent-soft); color: var(--accent-strong); text-decoration: none; }
.logout-link { margin-left: 4px; }
.user-chip { margin-left: 6px; }
.avatar {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border-radius: 50%;
    color: #fff; font-weight: 650; font-size: 14px; flex: none;
    user-select: none;
}

/* ---------------- workspace: 3 panes ---------------- */
.workspace {
    display: grid;
    grid-template-columns: 268px minmax(330px, 420px) 1fr;
    height: calc(100vh - var(--topbar-h));
}

/* sidebar */
.sidebar {
    border-right: 1px solid var(--border);
    background: #FBFAFE;
    display: flex; flex-direction: column; min-height: 0;
}
.sidebar-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 14px 8px;
}
.sidebar-title { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.sidebar-body { flex: 1; overflow-y: auto; padding: 4px 10px 12px; }
.side-loading { color: var(--muted); padding: 14px; font-size: 13px; }

.acct-block { margin-top: 8px; }
.acct-row {
    display: flex; align-items: center; gap: 9px;
    padding: 8px 8px; border-radius: 10px; cursor: pointer;
}
.acct-row:hover { background: #F1EFFB; }
.acct-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: 0 0 0 3px rgba(0,0,0,.04); }
.acct-label { font-weight: 600; font-size: 13.5px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-caret { color: var(--muted); transition: transform .15s; font-size: 11px; }
.acct-block.open .acct-caret { transform: rotate(90deg); }
.acct-folders { display: none; padding: 2px 0 6px 16px; }
.acct-block.open .acct-folders { display: block; }

.folder-row {
    display: flex; align-items: center; gap: 9px;
    padding: 7px 10px; border-radius: 9px; cursor: pointer;
    color: var(--text); font-size: 13.5px;
}
.folder-row:hover { background: #F1EFFB; text-decoration: none; }
.folder-row.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.folder-row .ic { width: 16px; height: 16px; color: var(--muted); }
.folder-row.active .ic { color: var(--accent-strong); }
.folder-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge-unread {
    background: var(--accent); color: #fff; border-radius: 999px;
    font-size: 11px; font-weight: 700; padding: 1px 8px; min-width: 22px; text-align: center;
}
.badge-count { color: var(--muted); font-size: 11.5px; }

.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); }
.sidebar-foot .btn .ic { width: 16px; height: 16px; }

/* message list */
.msglist { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; background: var(--surface); }
.msglist-head {
    display: flex; align-items: center; gap: 10px;
    padding: 13px 16px; border-bottom: 1px solid var(--border);
}
.msglist-head h2 { font-size: 16.5px; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { font-size: 12px; color: var(--muted); background: #F3F2F9; border-radius: 999px; padding: 3px 10px; }

.bulkbar {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    padding: 8px 14px; background: var(--accent-soft);
    border-bottom: 1px solid var(--border); font-size: 13px;
}
.bulkbar #bulk-count { font-weight: 600; color: var(--accent-strong); margin-right: 4px; }

.msglist-body { flex: 1; overflow-y: auto; }
.msg-row {
    display: flex; gap: 12px; align-items: flex-start;
    padding: 12px 16px; border-bottom: 1px solid #F1F0F8;
    cursor: pointer; position: relative; transition: background .12s;
}
.msg-row:hover { background: #FAF9FE; }
.msg-row.active { background: var(--accent-soft); }
.msg-row.unread { background: #FFFFFF; }
.msg-row.unread .msg-subject { font-weight: 700; }
.msg-row.unread::before {
    content: ""; position: absolute; left: 0; top: 0; bottom: 0;
    width: 3px; background: var(--accent); border-radius: 0 3px 3px 0;
}
.msg-check { margin-top: 4px; width: 16px; height: 16px; accent-color: var(--accent); flex: none; }
.msg-main { flex: 1; min-width: 0; }
.msg-top { display: flex; align-items: baseline; gap: 8px; }
.msg-from { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.msg-date { color: var(--muted); font-size: 12px; flex: none; }
.msg-subject { font-size: 13.5px; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-snippet { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.msg-side { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; flex: none; }
.msg-flags { display: flex; gap: 4px; font-size: 12px; color: var(--muted); }
.msg-star { color: var(--warn); }
.msg-attach-ic { width: 14px; height: 14px; }
.star-btn { background: none; border: none; cursor: pointer; font-size: 15px; color: #C9C6DD; padding: 0; line-height: 1; }
.star-btn.on { color: var(--star); }
.star-btn:hover { transform: scale(1.15); }

.empty-state { text-align: center; padding: 60px 20px; }
.empty-art { font-size: 40px; margin-bottom: 10px; filter: grayscale(.2); }
.loading-note { color: var(--muted); padding: 18px; text-align: center; font-size: 13px; }
.msglist-foot { padding: 10px 14px; border-top: 1px solid var(--border); background: var(--surface); }

/* reader */
.reader { overflow-y: auto; min-height: 0; background: var(--bg); }
.reader-empty, .reader-msg { max-width: 860px; margin: 0 auto; }
.reader-empty { text-align: center; padding: 90px 30px; }
.reader-msg { background: var(--surface); margin: 18px; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.reader-head { padding: 20px 26px 14px; border-bottom: 1px solid var(--border); }
.reader-subject-row { display: flex; align-items: flex-start; gap: 10px; }
.reader-subject-row h1 { flex: 1; font-size: 19px; margin: 0; }
.reader-actions { display: flex; gap: 2px; flex: none; }
.reader-meta { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.reader-people { flex: 1; min-width: 0; }
.reader-from { font-size: 14px; }
.reader-people .muted { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; }
.reader-date { flex: none; font-size: 12.5px; }
.reader-buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

.reader-body { padding: 22px 26px 30px; overflow-wrap: break-word; }
.reader-attach { padding: 16px 26px 22px; border-top: 1px solid var(--border); }
.reader-attach h4 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 10px; }
.attach-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.attach-chip {
    display: inline-flex; align-items: center; gap: 8px;
    background: #F6F5FB; border: 1px solid var(--border);
    border-radius: 10px; padding: 7px 12px; font-size: 12.5px; max-width: 260px;
}
.attach-chip .f-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.attach-chip .f-size { color: var(--muted); flex: none; }
.attach-chip a { color: var(--accent); flex: none; font-weight: 600; }
.attach-chip .rm-btn { color: var(--muted); cursor: pointer; border: none; background: none; font-size: 13px; }

/* mail content rendered inside reader / quotes */
.md-mail { font-size: 14px; }
.md-mail img { max-width: 100%; height: auto; border-radius: 8px; }
.md-mail blockquote {
    margin: 12px 0; padding: 10px 16px;
    border-left: 3px solid var(--accent); background: #FAF9FE;
    border-radius: 0 10px 10px 0;
}
.md-mail .md-quote-header { color: var(--muted); font-size: 12.5px; margin-bottom: 8px; }
.md-mail .md-plaintext { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; white-space: pre-wrap; }
.md-mail .md-signature { margin-top: 22px; padding-top: 12px; border-top: 1px dashed var(--border); color: var(--muted); font-size: 13px; }
.md-mail .md-blocked-img {
    display: inline-block; min-width: 120px; min-height: 60px;
    background: repeating-linear-gradient(45deg, #F1EFFB, #F1EFFB 8px, #E9E7F4 8px, #E9E7F4 16px);
    border: 1px dashed var(--border); border-radius: 8px;
}
.md-mail a.md-blocked-link { color: var(--muted); }

/* ---------------- modal & compose ---------------- */
.modal {
    position: fixed; inset: 0; z-index: 60;
    background: rgba(30,27,58,.45); backdrop-filter: blur(3px);
    display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal[hidden] { display: none; }
.compose-card {
    width: 100%; max-width: 760px; max-height: 92vh;
    background: var(--surface); border-radius: 16px; box-shadow: var(--shadow);
    display: flex; flex-direction: column; overflow: hidden;
}
.compose-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.compose-head h3 { margin: 0; font-size: 16px; }
.compose-fields { padding: 10px 18px 0; }
.compose-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid #F3F2F9; }
.compose-row label { width: 62px; flex: none; font-size: 13px; font-weight: 600; color: var(--muted); }
.compose-row .input { border: none; box-shadow: none; padding: 7px 8px; border-radius: 8px; }
.compose-row .input:focus { box-shadow: none; }
.compose-toolbar {
    display: flex; align-items: center; gap: 2px;
    padding: 8px 18px; border-bottom: 1px solid var(--border);
}
.tool-btn {
    border: none; background: none; cursor: pointer; color: var(--muted);
    width: 30px; height: 30px; border-radius: 7px; font-size: 13.5px;
}
.tool-btn:hover { background: var(--accent-soft); color: var(--accent-strong); }
.tool-sep { width: 1px; height: 18px; background: var(--border); margin: 0 6px; }
.autosave-note { margin-left: auto; font-size: 12px; }
.compose-editor {
    flex: 1; min-height: 180px; max-height: 42vh; overflow-y: auto;
    padding: 14px 18px; outline: none;
}
.compose-editor:empty:before { content: attr(data-ph); color: var(--muted); }
.compose-attach { padding: 8px 18px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.attach-pick { margin-left: auto; }
.compose-foot {
    display: flex; justify-content: flex-end; gap: 10px;
    padding: 12px 18px; border-top: 1px solid var(--border); background: #FBFAFE;
}

/* ---------------- pages (accounts/settings) ---------------- */
.page-wrap { max-width: 980px; margin: 0 auto; padding: 28px 22px 60px; }
.page-wrap.narrow { max-width: 720px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.page-head p { margin: 2px 0 0; }

.account-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.account-card {
    background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-soft);
    padding: 18px; border: 1px solid var(--border); position: relative;
}
.account-card .acct-color-bar { position: absolute; inset: 0 auto 0 0; width: 5px; border-radius: var(--radius) 0 0 var(--radius); }
.account-card h3 { display: flex; align-items: center; gap: 9px; font-size: 15.5px; padding-left: 8px; }
.account-card .acct-email { color: var(--muted); font-size: 13px; padding-left: 8px; overflow: hidden; text-overflow: ellipsis; }
.acct-stats { display: flex; gap: 14px; margin: 12px 0 0 8px; font-size: 12.5px; color: var(--muted); }
.acct-card-actions { display: flex; gap: 8px; margin-top: 14px; padding-left: 8px; }
.add-card {
    display: flex; align-items: center; justify-content: center; min-height: 150px;
    border: 2px dashed var(--border); border-radius: var(--radius); color: var(--muted);
    cursor: pointer; font-weight: 550; background: transparent;
}
.add-card:hover { border-color: var(--accent); color: var(--accent-strong); background: #FBFAFE; }

.form-card {
    background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 22px 24px; width: 100%; max-width: 640px;
}
.form-card.flat { box-shadow: var(--shadow-soft); }
.form-section { margin: 18px 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.form-section:first-child { margin-top: 0; }
.form-section em { text-transform: none; letter-spacing: 0; font-weight: 500; }
.modal-foot { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 18px; }
.test-result { font-size: 13px; margin-right: auto; }
.test-result.ok { color: var(--ok); font-weight: 600; }
.test-result.bad { color: var(--danger); font-weight: 600; }

.preset-row { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 0 2px; }
.chip {
    border: 1.5px solid var(--border); background: #FBFAFE; border-radius: 999px;
    padding: 5px 14px; font: inherit; font-size: 12.5px; font-weight: 550; cursor: pointer; color: var(--text);
}
.chip:hover, .chip.active { border-color: var(--accent); color: var(--accent-strong); background: var(--accent-soft); }

/* ---------------- auth & installer ---------------- */
.auth-body {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 24px;
    background:
        radial-gradient(900px 500px at 85% -10%, rgba(109,93,246,.14), transparent 60%),
        radial-gradient(700px 420px at -10% 110%, rgba(47,169,108,.10), transparent 60%),
        var(--bg);
}
.auth-card {
    width: 100%; max-width: 420px;
    background: var(--surface); border-radius: 18px; box-shadow: var(--shadow);
    padding: 30px 30px 26px;
}
.auth-card h1 { margin-top: 18px; }
.auth-card > .muted { margin-top: 0; }
.auth-alt { text-align: center; font-size: 13.5px; color: var(--muted); margin: 16px 0 0; }
.installer-card { max-width: 520px; }
.installer-card h1 { margin-top: 16px; }
.req-list { list-style: none; padding: 0; margin: 14px 0 18px; }
.req-list li { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 14px; }
.req-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.req-list li.ok .req-dot { background: var(--ok); }
.req-list li.bad .req-dot { background: var(--danger); }
.req-list li.bad { color: var(--danger); }
.config-ta { width: 100%; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; margin-bottom: 12px; }
.brand-row { display: flex; align-items: center; gap: 10px; }
.brand-row .brand-name { font-weight: 700; font-size: 17px; }

/* ---------------- alerts & toasts ---------------- */
.alert { border-radius: 10px; padding: 10px 14px; font-size: 13.5px; margin: 10px 0; }
.alert-error { background: #FDECEC; color: #B3323A; border: 1px solid #F5CFCF; }
.alert-ok { background: #E8F6EE; color: #1F7A4D; border: 1px solid #CBEED9; }
.toast-zone { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
    background: #26233F; color: #fff; border-radius: 12px;
    padding: 10px 18px; font-size: 13.5px; box-shadow: var(--shadow);
    animation: toast-in .18s ease-out; max-width: 480px;
}
.toast.err { background: #8E2E33; }
.toast.ok { background: #1F6B45; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------------- responsive ---------------- */
.only-mobile { display: none; }
@media (max-width: 1080px) {
    .workspace { grid-template-columns: 240px 1fr; }
    .reader {
        position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 30;
        display: none; overflow-y: auto;
    }
    .reader.open { display: block; }
    .only-mobile { display: inline-flex; }
}
@media (max-width: 760px) {
    .workspace { grid-template-columns: 1fr; }
    .sidebar { position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 35; display: none; }
    .sidebar.open { display: flex; }
    .msglist { border-right: none; }
    .topbar-search { display: none; }
    .brand-name { display: none; }
}
