:root {
  --side: #16171b;
  --side-2: #1f2026;
  --side-text: #c9cad1;
  --side-dim: #7d7f8a;
  --bg: #ffffff;
  --bg-2: #f6f6f8;
  --line: #e7e7ec;
  --text: #17181c;
  --dim: #6b6d78;
  --accent: #f5b301;
  --accent-ink: #1a1400;
  --sel: #fff6d9;
  --unread: #2f6bff;
  --danger: #d33a2c;
  --code-bg: #111216;
  --code-text: #ffd34d;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #1b1c21;
    --bg-2: #222329;
    --line: #2e3038;
    --text: #ececf1;
    --dim: #9496a1;
    --sel: #3a3220;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #1b1c21;
  --bg-2: #222329;
  --line: #2e3038;
  --text: #ececf1;
  --dim: #9496a1;
  --sel: #3a3220;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--dim); }
.small { font-size: 12px; }
[hidden] { display: none !important; }

.app { display: grid; grid-template-columns: 236px 380px 1fr; height: 100vh; }

/* Sidebar */
.sidebar { background: var(--side); color: var(--side-text); display: flex; flex-direction: column; padding: 16px 12px; gap: 4px; min-height: 0; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: #fff; padding: 2px 8px 14px; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); position: relative; }
.logo::after { content: ''; position: absolute; inset: 6px 4px; border: 2px solid #111; border-top-color: transparent; border-radius: 1px; }
.compose-btn { background: var(--accent); color: var(--accent-ink); font-weight: 650; border-radius: 9px; padding: 9px 12px; margin-bottom: 12px; }
.compose-btn:hover { filter: brightness(1.06); }
.views button, .accounts button { display: flex; justify-content: space-between; align-items: center; width: 100%; text-align: left; padding: 7px 10px; border-radius: 7px; color: var(--side-text); }
.views button:hover, .accounts button:hover { background: var(--side-2); }
.views button.active, .accounts button.active { background: #2a2b33; color: #fff; }
.views b, .accounts b { font-weight: 600; font-size: 12px; color: var(--side-dim); }
.views b.hot:not(:empty) { background: var(--accent); color: var(--accent-ink); border-radius: 10px; padding: 0 7px; }
.section-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--side-dim); padding: 16px 10px 6px; }
.accounts .acct { display: flex; align-items: center; gap: 8px; min-width: 0; }
.accounts .acct span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--side-dim); }
.dot.live { background: #3ccf6e; }
.dot.error { background: var(--danger); }
.dot.connecting, .dot.reconnecting { background: var(--accent); }
.acct-err { font-size: 11px; color: #ff8a7f; padding: 0 10px 6px 25px; }
.ghost { color: var(--side-dim); text-align: left; padding: 7px 10px; border-radius: 7px; }
.ghost:hover { background: var(--side-2); color: var(--side-text); }
.spacer { flex: 1; }
.recent-codes { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.recent-codes .rc { background: var(--side-2); border-radius: 9px; padding: 8px 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.rc .who { font-size: 11px; color: var(--side-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rc .val { font: 600 15px ui-monospace, 'SF Mono', Menlo, monospace; color: var(--code-text); letter-spacing: .04em; }
.rc button { font-size: 11px; background: #33343d; color: #fff; padding: 3px 8px; border-radius: 6px; }

/* List */
.list-pane { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.list-head { padding: 12px 14px 6px; }
#search { width: 100%; padding: 8px 11px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg-2); outline: none; }
#search:focus { border-color: var(--accent); }
.list-title { display: flex; justify-content: space-between; padding: 6px 16px 8px; font-weight: 650; }
.list { overflow-y: auto; flex: 1; }
.row { display: grid; grid-template-columns: 34px 1fr; gap: 10px; padding: 10px 14px 10px 12px; border-bottom: 1px solid var(--line); cursor: default; position: relative; }
.row:hover { background: var(--bg-2); }
.row.sel { background: var(--sel); }
.row.unread::before { content: ''; position: absolute; left: 4px; top: 22px; width: 6px; height: 6px; border-radius: 50%; background: var(--unread); }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 650; color: #fff; font-size: 14px; }
.row .top { display: flex; justify-content: space-between; gap: 8px; }
.row .who { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.unread .who, .row.unread .subj { font-weight: 700; }
.row .when { color: var(--dim); font-size: 12px; white-space: nowrap; }
.row .subj { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .snip { color: var(--dim); font-size: 12.5px; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.row .meta { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--code-bg); color: var(--code-text); border-radius: 6px; padding: 2px 4px 2px 8px; font: 600 12.5px ui-monospace, 'SF Mono', Menlo, monospace; }
.chip button { background: #2c2d35; color: #fff; font: 600 11px -apple-system, system-ui, sans-serif; padding: 2px 7px; border-radius: 4px; }
.chip.link { font-family: inherit; padding-right: 8px; }
.tag { font-size: 11px; color: var(--dim); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; }
.star-on { color: var(--accent); }
.list-empty { padding: 40px 20px; text-align: center; color: var(--dim); }

/* Reader */
.reader { display: flex; flex-direction: column; min-height: 0; overflow-y: auto; background: var(--bg-2); }
.empty { margin: auto; text-align: center; color: var(--dim); }
.empty-mark { width: 54px; height: 54px; border-radius: 14px; background: var(--line); margin: 0 auto 12px; }
.toolbar { position: sticky; top: 0; z-index: 2; display: flex; gap: 4px; padding: 10px 18px; background: var(--bg-2); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.toolbar button { padding: 6px 11px; border-radius: 7px; color: var(--text); }
.toolbar button:hover { background: var(--line); }
.toolbar .ai { margin-left: auto; }
.toolbar .sep { width: 1px; background: var(--line); margin: 4px 4px; }
.msg { padding: 20px 24px 40px; max-width: 920px; width: 100%; }
.msg h1 { font-size: 21px; margin: 0 0 14px; line-height: 1.3; }
.from-line { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; }
.from-line .names { flex: 1; min-width: 0; }
.from-line .addr { color: var(--dim); font-size: 12.5px; }
.from-line .when { color: var(--dim); font-size: 12.5px; text-align: right; }
.code-banner { display: flex; align-items: center; gap: 14px; background: var(--code-bg); color: #fff; border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.code-banner .big { font: 700 26px ui-monospace, 'SF Mono', Menlo, monospace; letter-spacing: .08em; color: var(--code-text); }
.code-banner .lbl { font-size: 12px; color: #aaa; }
.code-banner .grow { flex: 1; }
.code-banner button, .code-banner a { background: var(--accent); color: var(--accent-ink); font-weight: 650; padding: 7px 13px; border-radius: 7px; text-decoration: none; }
.code-banner a.sec { background: #2c2d35; color: #fff; }
.summary { background: var(--bg); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; white-space: pre-wrap; }
.summary .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); margin-bottom: 4px; }
.notice { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 12.5px; color: var(--dim); background: var(--bg); border: 1px dashed var(--line); border-radius: 8px; padding: 7px 12px; margin-bottom: 10px; }
.notice button { color: var(--unread); font-weight: 600; }
.body-card { background: #fff; color: #111; border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; }
.body-card iframe { width: 100%; border: 0; display: block; min-height: 120px; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.attachments span { background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 5px 10px; font-size: 12.5px; }

/* Compose */
.compose { position: fixed; right: 24px; bottom: 0; width: min(640px, calc(100vw - 32px)); height: min(620px, 86vh); background: var(--bg); border: 1px solid var(--line); border-bottom: 0; border-radius: 12px 12px 0 0; box-shadow: 0 18px 60px rgba(0,0,0,.28); display: flex; flex-direction: column; z-index: 20; }
.compose-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; background: var(--side); color: #fff; border-radius: 12px 12px 0 0; font-weight: 600; }
.icon { color: inherit; padding: 2px 6px; border-radius: 5px; }
.compose-row { display: flex; align-items: center; border-bottom: 1px solid var(--line); padding: 0 14px; }
.compose-row label { width: 62px; color: var(--dim); font-size: 13px; }
.compose-row input, .compose-row select { flex: 1; border: 0; outline: none; padding: 9px 0; background: transparent; }
.ai-bar { display: flex; gap: 8px; padding: 10px 14px; background: var(--bg-2); border-bottom: 1px solid var(--line); }
.ai-bar input { flex: 1; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: var(--bg); outline: none; }
.ai-bar input:focus { border-color: var(--accent); }
button.ai { background: var(--side); color: var(--code-text); padding: 7px 12px; border-radius: 8px; font-weight: 600; white-space: nowrap; }
.toolbar button.ai { background: transparent; color: var(--text); }
textarea#cBody { flex: 1; border: 0; outline: none; resize: none; padding: 14px; background: transparent; line-height: 1.55; }
.compose-foot { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line); }
.primary { background: var(--accent); color: var(--accent-ink); font-weight: 650; padding: 8px 18px; border-radius: 8px; }
.primary:disabled { opacity: .5; cursor: default; }

/* Dialogs */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(480px, calc(100vw - 32px)); background: var(--bg); color: var(--text); box-shadow: 0 24px 80px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(10,10,14,.45); }
dialog form { padding: 22px; display: flex; flex-direction: column; gap: 12px; }
dialog h2 { margin: 0 0 4px; font-size: 18px; }
dialog label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--dim); }
dialog input:not([type='checkbox']) { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-2); color: var(--text); outline: none; }
dialog input:focus { border-color: var(--accent); }
dialog label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
dialog .ghost { color: var(--dim); }
dialog .ghost:hover { background: var(--bg-2); color: var(--text); }
.grid2 { display: grid; grid-template-columns: 1fr 90px; gap: 10px; margin-top: 10px; }
details summary { cursor: pointer; color: var(--dim); font-size: 13px; }
.hint { font-size: 12.5px; background: var(--bg-2); border-radius: 8px; padding: 9px 11px; color: var(--text); }
.hint:empty { display: none; }
.hint a { color: var(--unread); }
.error { color: var(--danger); font-size: 13px; }
.error:empty { display: none; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* Toasts */
.toasts { position: fixed; top: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 30; }
.toast { background: var(--code-bg); color: #fff; border-radius: 12px; padding: 12px 14px; box-shadow: 0 12px 40px rgba(0,0,0,.35); display: flex; align-items: center; gap: 14px; min-width: 280px; animation: drop .25s ease-out; }
.toast .t-who { font-size: 12px; color: #aaa; }
.toast .t-code { font: 700 20px ui-monospace, 'SF Mono', Menlo, monospace; letter-spacing: .06em; color: var(--code-text); }
.toast .grow { flex: 1; }
.toast button { background: var(--accent); color: var(--accent-ink); font-weight: 650; padding: 6px 12px; border-radius: 7px; }
.toast.plain { background: var(--side); }
@keyframes drop { from { transform: translateY(-8px); opacity: 0; } }

@media (max-width: 1100px) { .app { grid-template-columns: 200px 320px 1fr; } }
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .reader { display: none; }
  .app.reading .list-pane { display: none; }
  .app.reading .reader { display: flex; }
}

/* Folders under each account */
.folders { display: flex; flex-direction: column; margin: 0 0 6px 14px; border-left: 1px solid #2a2b33; }
.folders button { padding: 5px 10px; font-size: 13px; color: var(--side-dim); border-radius: 0 7px 7px 0; text-align: left; display: flex; justify-content: space-between; }
.folders button:hover { background: var(--side-2); color: var(--side-text); }
.folders button.active { background: #2a2b33; color: #fff; }
.caret { font-size: 10px; color: var(--side-dim); width: 10px; display: inline-block; }

/* Thread rows */
.count { font-size: 11px; font-weight: 600; color: var(--dim); background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; padding: 0 6px; margin-left: 6px; }
.clip { color: var(--dim); font-size: 12px; }

/* Conversation cards */
.mcard { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.mcard-head { display: flex; gap: 12px; align-items: center; padding: 12px 14px; cursor: pointer; }
.mcard-head .names { flex: 1; min-width: 0; }
.mcard-head .addr, .mcard-head .when { color: var(--dim); font-size: 12.5px; }
.mcard-head .when { text-align: right; white-space: nowrap; }
.mcard.collapsed .mcard-head .addr { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mcard .avatar { width: 30px; height: 30px; font-size: 13px; }
.mcard-body { padding: 0 14px 14px; }
.mcard-body .body-card { border: 0; border-top: 1px solid var(--line); border-radius: 0; margin: 0 -14px; }
.mcard.collapsed .mcard-body { display: none; }
.me-tag { font-size: 11px; color: var(--dim); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; margin-left: 6px; font-weight: 500; }

/* Attachments */
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.att { display: inline-flex; align-items: center; gap: 0; background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; font-size: 12.5px; overflow: hidden; max-width: 100%; }
.att .open { padding: 6px 10px; text-align: left; display: flex; gap: 8px; align-items: center; min-width: 0; }
.att .open:hover { background: var(--line); }
.att .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.att .ext { font: 700 10px ui-monospace, Menlo, monospace; background: var(--side); color: var(--code-text); border-radius: 4px; padding: 2px 5px; text-transform: uppercase; }
.att a.dl { padding: 6px 9px; border-left: 1px solid var(--line); color: var(--dim); text-decoration: none; }
.att a.dl:hover { background: var(--line); color: var(--text); }

/* Compose files */
.files { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px; }
.files:empty { display: none; }
.files .f { display: inline-flex; gap: 6px; align-items: center; background: var(--bg-2); border: 1px solid var(--line); border-radius: 7px; padding: 3px 4px 3px 9px; font-size: 12.5px; margin-bottom: 8px; }
.files .f button { color: var(--dim); padding: 0 5px; }
.compose-foot { gap: 10px; }
.compose-foot .grow { flex: 1; }
.attach { border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; }
.attach:hover { background: var(--bg-2); }
.drop-hint { display: none; position: absolute; inset: 44px 0 0; background: rgba(245,179,1,.12); border: 2px dashed var(--accent); border-radius: 0 0 12px 12px; place-items: center; font-weight: 600; pointer-events: none; }
.compose.dragging .drop-hint { display: grid; }

/* Preview dialog */
dialog.preview { width: min(1000px, calc(100vw - 32px)); height: min(860px, calc(100vh - 40px)); display: none; flex-direction: column; }
dialog.preview[open] { display: flex; }
.preview-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); font-weight: 600; }
.preview-head .grow { flex: 1; }
.preview-head a.primary { text-decoration: none; font-size: 13px; padding: 6px 14px; }
.preview-body { flex: 1; min-height: 0; background: var(--bg-2); display: grid; place-items: center; overflow: auto; }
.preview-body iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.preview-body img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* Settings, per account */
.acct-set { border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.acct-set .acct-email { font-weight: 600; color: var(--text); font-size: 13px; }
.acct-set textarea { min-height: 84px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-2); color: var(--text); outline: none; resize: vertical; font-size: 13px; }
#sAccounts { display: flex; flex-direction: column; gap: 10px; }
dialog#settingsDlg { width: min(560px, calc(100vw - 32px)); }
.preview-body:has(.pdf-pages) { display: block; }
.pdf-pages { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 16px; }
.pdf-pages canvas { background: #fff; box-shadow: 0 2px 12px rgba(0,0,0,.25); border-radius: 2px; }

/* Search */
.index-status { font-size: 11.5px; color: var(--dim); padding: 6px 2px 0; }
.index-status:empty { display: none; }
.snip.hit { -webkit-line-clamp: 2; }
.snip mark { background: var(--sel); color: var(--text); border-radius: 3px; padding: 0 2px; font-weight: 600; }
.mcard-body > .attachments { margin: 0 0 12px; }

/* Quoted original under the composer */
.quote-box { border-top: 1px solid var(--line); padding: 8px 14px; font-size: 12.5px; color: var(--dim); }
.quote-box summary { cursor: pointer; }
.quote-box iframe { width: 100%; height: 240px; border: 1px solid var(--line); border-radius: 8px; margin-top: 8px; background: #fff; }
textarea#cBody { min-height: 150px; }
.compose { overflow-y: auto; }
.quote-box iframe { height: 200px; }

/* Rich text editor (signature) */
.sig-label { font-size: 13px; color: var(--dim); }
.rte { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.rte-bar { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding: 6px; background: var(--bg-2); border-bottom: 1px solid var(--line); }
.rte-bar button, .rte-bar select, .rte-color { font-size: 12.5px; padding: 3px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--text); cursor: pointer; }
.rte-bar button:hover { background: var(--line); }
.rte-color { position: relative; font-weight: 700; display: inline-flex; align-items: center; gap: 4px; flex-direction: row !important; }
.rte-color input { width: 18px; height: 18px; padding: 0; border: 0; background: none; cursor: pointer; }
.rte-img { display: inline-flex; gap: 4px; align-items: center; font-size: 12px; color: var(--dim); margin-left: 4px; }
.rte-img[hidden] { display: none; }
.rte-area { min-height: 130px; max-height: 320px; overflow: auto; padding: 12px; background: #fff; color: #000; font: 11pt Calibri, Aptos, Arial, sans-serif; outline: none; }
.rte-area img { max-width: 100%; cursor: pointer; }
.rte-area img.picked { outline: 2px solid var(--accent); }
.rte-area a { color: #0563c1; }

/* Signature in the composer */
.sig-row { border-top: 1px dashed var(--line); padding: 8px 14px; display: flex; gap: 12px; align-items: flex-start; }
.sig-toggle { font-size: 12px; color: var(--dim); white-space: nowrap; display: flex; gap: 5px; align-items: center; }
.sig-preview { flex: 1; background: #fff; color: #000; border-radius: 6px; padding: 8px 10px; font: 10pt Calibri, Aptos, Arial, sans-serif; max-height: 140px; overflow: auto; }
.sig-preview img { max-width: 100%; }
.sig-row:has(#cSigOn:not(:checked)) .sig-preview { opacity: .35; }

/* Undo send */
.toast.undo { gap: 10px; }
.toast.undo button { background: var(--accent); color: var(--accent-ink); }
.toast.undo .ghost-btn { background: transparent; color: #ccc; border: 1px solid #44464f; }
.inline-set select { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-2); color: var(--text); }
#noSubjectDlg p { margin: 0; font-size: 13.5px; }

/* Rich composer body */
.compose-editor { flex: 1; min-height: 190px; display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.compose-editor .rte { border: 0; border-radius: 0; flex: 1; display: flex; flex-direction: column; }
.compose-editor .rte-area { flex: 1; max-height: none; min-height: 150px; }
.rte-area:empty::before { content: attr(data-placeholder); color: #999; }
.rte-area ul, .rte-area ol { margin: 0 0 0 1.2em; padding: 0; }
