/* ==========================================================
   Webmail Hub — UI
   ========================================================== */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --border: #e6e9f0;
  --border-strong: #d4d9e3;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #8a94a6;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --primary-ring: rgba(79, 70, 229, .22);
  --ok: #059669; --ok-soft: #ecfdf5;
  --err: #dc2626; --err-soft: #fef2f2;
  --warn: #d97706; --warn-soft: #fffbeb;
  --sidebar: #0c1324;
  --sidebar-2: #151d33;
  --sidebar-text: #a8b3c7;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 6px 24px -10px rgba(16, 24, 40, .12);
  --shadow-lg: 0 30px 60px -20px rgba(16, 24, 40, .35);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans Bengali", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0a0f1c;
  --surface: #111827;
  --surface-2: #0f1626;
  --surface-3: #1a2336;
  --border: #1f2a3d;
  --border-strong: #2c3a52;
  --text: #e6eaf2;
  --text-2: #a3aec2;
  --muted: #6b7890;
  --primary: #6366f1;
  --primary-hover: #7c7ff5;
  --primary-soft: rgba(99, 102, 241, .14);
  --primary-ring: rgba(99, 102, 241, .35);
  --ok-soft: rgba(5, 150, 105, .14);
  --err-soft: rgba(220, 38, 38, .14);
  --warn-soft: rgba(217, 119, 6, .14);
  --sidebar: #070b15;
  --sidebar-2: #111827;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -12px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); font-size: 14px; line-height: 1.5; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 19px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 600; }
p { margin: .4em 0; }
code { font-family: var(--mono); font-size: 12px; background: var(--surface-3); padding: 2px 6px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.block { display: block; }
.mono { font-family: var(--mono); font-size: 13px; }
.nowrap { white-space: nowrap; }
.ta-r { text-align: right; }
.mt { margin-top: 14px; }
.center { justify-content: center; }
.row-gap { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.trunc { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ic { width: 18px; height: 18px; flex: none; }
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; padding: 18px 14px; z-index: 40; }
.brand { display: flex; align-items: center; gap: 11px; padding: 6px 8px 22px; color: #fff; text-decoration: none !important; }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, #6366f1, #4f46e5 45%, #0ea5e9); box-shadow: 0 6px 18px -6px rgba(79, 70, 229, .7); }
.brand-mark .ic { width: 19px; height: 19px; }
.brand-mark.lg { width: 52px; height: 52px; border-radius: 15px; }
.brand-mark.lg .ic { width: 28px; height: 28px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #5c6a84; padding: 8px 10px; font-weight: 600; }
.nav-item { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 10px; color: var(--sidebar-text); font-weight: 500; text-decoration: none !important; transition: background .15s, color .15s; }
.nav-item:hover { background: var(--sidebar-2); color: #fff; }
.nav-item.active { background: linear-gradient(90deg, rgba(99, 102, 241, .25), rgba(99, 102, 241, .08)); color: #fff; box-shadow: inset 2px 0 0 #818cf8; }
.sidebar-foot { margin-top: auto; }
.me { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 12px; background: var(--sidebar-2); }
.me-avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: #334155; color: #fff; font-weight: 600; }
.me-info { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.me-info strong { color: #fff; font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.me-info small { color: #64748b; font-size: 11px; }
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 30; height: 60px; display: flex; align-items: center; gap: 12px; padding: 0 28px; background: color-mix(in srgb, var(--surface) 85%, transparent); backdrop-filter: saturate(180%) blur(10px); border-bottom: 1px solid var(--border); }
.topbar-title { font-weight: 600; color: var(--text-2); }
.topbar-actions { margin-left: auto; display: flex; gap: 6px; }
.content { padding: 28px; width: 100%; max-width: 1440px; margin: 0 auto; }
.content.full { padding: 0; max-width: none; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.content.full > .alert { margin: 12px 16px 0; }
.content-pad { padding: 28px; }
body.is-full .main { height: 100vh; }
.only-mobile, .only-narrow { display: none; }
.sidebar-backdrop { display: none; }
[data-theme="dark"] .when-light, :root:not([data-theme="dark"]) .when-dark { display: none; }
.when-light, .when-dark { display: inline-flex; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; padding: 0 15px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; text-decoration: none !important; white-space: nowrap; transition: background .15s, border-color .15s, box-shadow .15s, transform .05s; box-shadow: var(--shadow-sm); }
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--primary-ring); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn .ic { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(79, 70, 229, .3), inset 0 1px 0 rgba(255, 255, 255, .12); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn-ghost:hover { background: var(--surface-3); border-color: transparent; }
.btn-danger-soft { background: var(--err-soft); color: var(--err); border-color: transparent; }
.btn-sm { height: 32px; padding: 0 11px; font-size: 13px; }
.btn-lg { height: 44px; padding: 0 20px; font-size: 15px; }
.btn-block { width: 100%; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; border: 0; background: transparent; color: var(--text-2); cursor: pointer; transition: background .15s, color .15s; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.danger:hover { background: var(--err-soft); color: var(--err); }
.icon-btn.ghost-dark { color: #7c8aa5; }
.icon-btn.ghost-dark:hover { background: #1e293b; color: #fff; }
.icon-btn.spin .ic { animation: spin .8s linear infinite; }
.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; }
form.inline { display: inline; }

/* ---------- Cards & page ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head .actions { display: flex; gap: 10px; flex-wrap: wrap; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat { display: flex; align-items: center; gap: 14px; padding: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.stat small { color: var(--muted); font-weight: 500; display: block; }
.stat strong { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.stat-ic { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; }
.stat-ic .ic { width: 21px; height: 21px; }
.stat-ic.indigo { background: #eef2ff; color: #4f46e5; }
.stat-ic.sky { background: #e0f2fe; color: #0284c7; }
.stat-ic.green { background: #dcfce7; color: #16a34a; }
.stat-ic.rose { background: #ffe4e6; color: #e11d48; }
[data-theme="dark"] .stat-ic { background: var(--surface-3); }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; }
.search { position: relative; flex: 1; max-width: 420px; }
.search .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 16px; height: 16px; pointer-events: none; }
.search input { padding-left: 38px !important; }

/* ---------- Mailbox cards ---------- */
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.mbox { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; overflow: hidden; transition: transform .15s, box-shadow .15s, border-color .15s; }
.mbox::before { content: ""; position: absolute; inset: 0 0 auto; height: 3px; background: var(--c); opacity: .9; }
.mbox:hover { transform: translateY(-2px); box-shadow: 0 14px 30px -14px rgba(16, 24, 40, .25); border-color: var(--border-strong); }
.mbox.has-error { border-color: color-mix(in srgb, var(--err) 35%, var(--border)); }
.mbox-top { display: flex; align-items: center; gap: 12px; }
.mbox-meta { flex: 1; min-width: 0; }
.mbox-title { font-weight: 650; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mbox-sub { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mbox-status { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-2); min-height: 18px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.mbox.has-error .mbox-status { color: var(--err); white-space: normal; }
.mbox-actions { display: flex; gap: 8px; align-items: center; }
.mbox-actions .btn { flex: 1; }
.avatar { --c: var(--primary); width: 42px; height: 42px; flex: none; border-radius: 12px; display: grid; place-items: center; font-weight: 700; font-size: 16px; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); }
.avatar.sm { width: 34px; height: 34px; border-radius: 10px; font-size: 14px; }
.avatar.lg { width: 64px; height: 64px; border-radius: 18px; font-size: 26px; margin: 0 auto 10px; }
.unread-badge { min-width: 34px; height: 28px; padding: 0 9px; border-radius: 999px; display: inline-grid; place-items: center; font-weight: 700; font-size: 13px; background: var(--surface-3); color: var(--muted); }
.unread-badge.has { background: var(--primary); color: #fff; box-shadow: 0 4px 12px -4px var(--primary); }
.unread-badge.err { background: var(--err-soft); color: var(--err); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); flex: none; }
.dot.ok { background: #10b981; box-shadow: 0 0 0 3px rgba(16, 185, 129, .15); }
.dot.err { background: var(--err); box-shadow: 0 0 0 3px rgba(220, 38, 38, .15); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field-end { justify-content: flex-end; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], input:not([type]), select, textarea {
  width: 100%; height: 40px; padding: 0 12px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit; transition: border-color .15s, box-shadow .15s; }
textarea { height: auto; padding: 10px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-ring); }
input[type=color] { width: 100%; height: 40px; padding: 4px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.hint { font-size: 12px; color: var(--muted); }
.input-icon { position: relative; }
.input-icon .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 17px; height: 17px; }
.input-icon input { padding-left: 40px; height: 44px; }
.input-reveal { position: relative; }
.input-reveal input { padding-right: 40px; }
.reveal { position: absolute; right: 4px; top: 4px; width: 32px; height: 32px; border: 0; background: none; color: var(--muted); cursor: pointer; border-radius: 7px; display: grid; place-items: center; }
.reveal:hover { background: var(--surface-3); }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; font-weight: 500; color: var(--text); margin: 4px 0; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch > span { width: 38px; height: 22px; border-radius: 999px; background: var(--border-strong); position: relative; flex: none; transition: background .2s; }
.switch > span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { box-shadow: 0 0 0 4px var(--primary-ring); }
.switch.sm > span { width: 32px; height: 18px; }
.switch.sm > span::after { width: 12px; height: 12px; }
.switch.sm input:checked + span::after { transform: translateX(14px); }
.switch.sm { font-size: 13px; white-space: nowrap; }
.field .switch { display: flex; }
.test-result { margin-top: 12px; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; display: flex; gap: 8px; align-items: flex-start; }
.test-result.ok { background: var(--ok-soft); color: var(--ok); }
.test-result.err { background: var(--err-soft); color: var(--err); }
.test-result.wait { background: var(--surface-3); color: var(--text-2); }

/* ---------- Alerts, pills, tags ---------- */
.alert { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: 12px; margin-bottom: 16px; font-size: 13.5px; border: 1px solid transparent; }
.alert > div { flex: 1; }
.alert-success { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 20%, transparent); }
.alert-error { background: var(--err-soft); color: var(--err); border-color: color-mix(in srgb, var(--err) 20%, transparent); }
.alert-warning { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 20%, transparent); }
.alert-x { background: none; border: 0; color: inherit; opacity: .6; cursor: pointer; padding: 0; }
.alert-x .ic { width: 16px; height: 16px; }
.pill { display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-err { background: var(--err-soft); color: var(--err); cursor: help; }
.pill-muted { background: var(--surface-3); color: var(--muted); }
.tag { display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: .03em; padding: 2px 7px; border-radius: 6px; background: var(--surface-3); color: var(--text-2); }
.tag-soft { background: var(--primary-soft); color: var(--primary); }

/* ---------- Table ---------- */
.table-card { overflow: hidden; }
.table-tools { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 11px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table tr.is-off { opacity: .55; }
.cell-acc { display: flex; align-items: center; gap: 11px; }
.cell-acc strong { display: block; }
.cell-acc small { color: var(--muted); }
.table .ta-r .icon-btn { width: 32px; height: 32px; }

/* ---------- Modal ---------- */
dialog.modal { width: min(760px, calc(100vw - 24px)); max-height: calc(100vh - 40px); padding: 0; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
dialog.modal[open] { animation: pop .18s ease-out; display: flex; flex-direction: column; }
dialog.modal > form { display: flex; flex-direction: column; max-height: calc(100vh - 40px); min-height: 0; }
dialog::backdrop { background: rgba(10, 15, 28, .55); backdrop-filter: blur(3px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 8px 22px 22px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 18px 18px; }
.form-section { padding: 16px 0; border-bottom: 1px dashed var(--border); }
.form-section:last-child { border-bottom: 0; }
.form-section-title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; color: var(--text-2); margin-bottom: 12px; }
.form-section-title .ic { width: 16px; height: 16px; color: var(--primary); }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------- Empty, toast, spinner ---------- */
.empty { text-align: center; padding: 56px 24px; }
.empty-ic { width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 18px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.empty-ic .ic { width: 30px; height: 30px; }
.empty h3 { font-size: 17px; margin-bottom: 4px; }
.empty .row-gap { margin-top: 18px; }
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast { min-width: 260px; max-width: 380px; padding: 12px 16px; border-radius: 12px; background: #0f172a; color: #fff; box-shadow: var(--shadow-lg); font-size: 13.5px; animation: pop .2s ease-out; display: flex; gap: 10px; align-items: center; }
.toast.ok { background: #065f46; }
.toast.err { background: #991b1b; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; opacity: .7; }
.spinner.lg { width: 34px; height: 34px; border-width: 3px; color: var(--primary); margin: 10px auto; display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Unified inbox ---------- */
.mail-app { flex: 1; min-height: 0; display: grid; grid-template-columns: 270px 400px minmax(0, 1fr); background: var(--surface); }
.mail-folders, .mail-list { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.mail-folders { background: var(--surface-2); }
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); min-height: 58px; }
.list-head .search { max-width: none; }
.list-head .search input { height: 36px; }
.progress { height: 2px; background: transparent; overflow: hidden; }
.progress .bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), #0ea5e9); transition: width .3s; }
.folder-list { overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.folder { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; cursor: pointer; border: 0; background: none; font: inherit; color: var(--text); text-align: left; width: 100%; }
.folder:hover { background: var(--surface-3); }
.folder.active { background: var(--primary-soft); color: var(--primary); }
.folder .fdot { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.folder .fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.folder .fname small { display: block; color: var(--muted); font-weight: 400; font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; }
.folder .fcount { font-size: 12px; font-weight: 700; color: var(--muted); }
.folder .fcount.has { color: #fff; background: var(--primary); padding: 1px 8px; border-radius: 999px; }
.folder .ferr { color: var(--err); display: inline-flex; }
.folder .ferr .ic { width: 15px; height: 15px; }
.folder.all { font-weight: 600; margin-bottom: 6px; padding: 10px; }
.folder.all .ic { width: 17px; height: 17px; }
.list-meta { padding: 8px 16px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 8px; }
.list-meta .warn { color: var(--err); cursor: help; }
.messages { overflow-y: auto; flex: 1; }
.msg { display: flex; gap: 12px; width: 100%; padding: 13px 16px; border: 0; border-bottom: 1px solid var(--border); background: var(--surface); color: var(--text); text-align: left; font: inherit; cursor: pointer; position: relative; }
.msg:hover { background: var(--surface-2); }
.msg.active { background: var(--primary-soft); }
.msg.active::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--primary); }
.msg-avatar { width: 36px; height: 36px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 600; font-size: 13px; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); }
.msg-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.msg-row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.msg-from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.msg-date { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.msg-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); font-size: 13.5px; }
.msg.unread .msg-from, .msg.unread .msg-subject { color: var(--text); font-weight: 650; }
.msg.unread .msg-date { color: var(--primary); font-weight: 600; }
.msg.unread::after { content: ""; position: absolute; right: 16px; bottom: 16px; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.msg-row2 { display: flex; align-items: center; gap: 8px; margin-top: 3px; }
.acc-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; color: var(--text-2); background: var(--surface-3); padding: 1px 8px 1px 6px; border-radius: 999px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-chip i { width: 7px; height: 7px; border-radius: 2px; flex: none; }
.msg-row2 .ic { width: 14px; height: 14px; color: var(--muted); }
.list-empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.mail-reader { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); }
.reader-empty { margin: auto; text-align: center; color: var(--text-2); }
.reader-head { padding: 18px 24px 14px; border-bottom: 1px solid var(--border); }
.reader-subject { font-size: 19px; font-weight: 700; line-height: 1.3; margin: 0 0 14px; word-break: break-word; }
.reader-meta { display: flex; gap: 12px; align-items: flex-start; }
.reader-meta .msg-avatar { width: 42px; height: 42px; font-size: 15px; }
.reader-from { flex: 1; min-width: 0; }
.reader-from strong { font-size: 14px; }
.reader-from .addr { color: var(--muted); font-size: 12.5px; }
.reader-from .to { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-date { font-size: 12px; color: var(--muted); white-space: nowrap; text-align: right; }
.reader-tools { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; align-items: center; }
.reader-tools .acc-chip { margin-right: auto; font-size: 11.5px; padding: 3px 10px 3px 8px; }
.atts { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 24px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.att { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); font-size: 12.5px; text-decoration: none !important; max-width: 280px; }
.att:hover { border-color: var(--primary); }
.att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att small { color: var(--muted); }
.att .ic { width: 15px; height: 15px; color: var(--primary); }
.img-blocked { display: flex; align-items: center; gap: 10px; padding: 8px 24px; background: var(--warn-soft); color: var(--warn); font-size: 12.5px; }
.reader-frame { flex: 1; border: 0; width: 100%; background: #fff; min-height: 0; }
.reader-loading { margin: auto; }
.back-btn { display: none; }

/* ---------- Auth & installer ---------- */
body.auth { min-height: 100vh; }
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px 16px; position: relative; overflow: hidden; }
.auth-bg { position: fixed; inset: 0; z-index: -1; background: radial-gradient(1000px 520px at 15% -10%, rgba(99, 102, 241, .22), transparent 60%), radial-gradient(800px 500px at 110% 110%, rgba(14, 165, 233, .18), transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 420px; padding: 34px; }
.auth-head { text-align: center; margin-bottom: 24px; }
.auth-head .brand-mark { margin: 0 auto 14px; }
.auth-foot { margin-top: 18px; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.auth-foot .ic { width: 14px; height: 14px; }
.autologin { text-align: center; }
.autologin p { margin: 6px 0; }
.copy-row { display: flex; gap: 8px; margin: 10px 0; }
.installer { width: 100%; max-width: 720px; padding: 30px 34px; }
.installer-head { display: flex; align-items: center; gap: 16px; margin-bottom: 26px; }
.steps { list-style: none; padding: 0; margin: 0 0 24px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; counter-reset: s; }
.steps li { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600; color: var(--muted); padding-top: 10px; border-top: 3px solid var(--border); }
.steps li span { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; background: var(--surface-3); color: var(--muted); }
.steps li.active, .steps li.done { color: var(--text); border-top-color: var(--primary); }
.steps li.active span, .steps li.done span { background: var(--primary); color: #fff; }
.step-panel { display: none; }
.step-panel.active { display: block; animation: pop .2s ease-out; }
.step-panel h3 { margin-bottom: 14px; font-size: 16px; }
.step-panel .form-grid { margin-bottom: 14px; }
.step-actions { display: flex; justify-content: space-between; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
.checklist { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.checklist li { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.checklist li:last-child { border-bottom: 0; }
.checklist li span:nth-child(2) { flex: 1; }
.checklist small { color: var(--muted); }
.ck { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; }
.ck .ic { width: 14px; height: 14px; }
.checklist .ok .ck { background: var(--ok-soft); color: var(--ok); }
.checklist .bad .ck { background: var(--err-soft); color: var(--err); }
.checklist .warn .ck { background: var(--warn-soft); color: var(--warn); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: flex; align-items: center; gap: 9px; justify-content: center; padding: 12px; border: 1.5px solid var(--border-strong); border-radius: 12px; font-weight: 600; transition: all .15s; }
.seg input:checked + span { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.seg input:disabled + span { opacity: .4; cursor: not-allowed; }
.summary { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.summary li { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.summary .ic { color: var(--primary); }
.install-done { text-align: center; padding: 10px 0; }
.done-icon { width: 68px; height: 68px; margin: 0 auto 14px; border-radius: 50%; display: grid; place-items: center; background: var(--ok-soft); color: var(--ok); }
.done-icon .ic { width: 34px; height: 34px; }
.install-done .row-gap { margin-top: 22px; }

/* ---------- Settings ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-bottom: 18px; }
.settings-card { padding: 22px; }
.settings-card h3 { display: flex; align-items: center; gap: 9px; margin-bottom: 14px; }
.settings-card h3 .ic { color: var(--primary); }
.settings-card .hint { margin: -6px 0 12px; }
.settings-card .switch { display: flex; }
.settings-save { grid-column: 1 / -1; display: flex; justify-content: flex-end; }
.sysinfo { display: grid; grid-template-columns: 110px 1fr; gap: 10px; margin: 0; }
.sysinfo dt { color: var(--muted); }
.sysinfo dd { margin: 0; font-weight: 500; }

/* ---------- Responsive ---------- */
@media (max-width: 1280px) {
  .mail-app { grid-template-columns: 230px 360px minmax(0, 1fr); }
}
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-grid { grid-template-columns: 1fr; }
  .mail-app { grid-template-columns: 340px minmax(0, 1fr); }
  .mail-folders { display: none; }
  .only-narrow { display: block; }
  #folderSelect { width: 150px; height: 36px; flex: none; }
}
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 264px; transform: translateX(-100%); transition: transform .25s; box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(10, 15, 28, .5); z-index: 35; }
  .only-mobile { display: inline-grid; }
  .topbar { padding: 0 14px; }
  .content { padding: 18px; }
}
@media (max-width: 760px) {
  .mail-app { grid-template-columns: 1fr; }
  .mail-reader { display: none; }
  .mail-app.show-reader .mail-list { display: none; }
  .mail-app.show-reader .mail-reader { display: flex; }
  .back-btn { display: inline-grid; }
  .form-grid, .form-grid.cols-4 { grid-template-columns: 1fr; }
  .span-2, .span-3 { grid-column: auto; }
  .stats { gap: 10px; }
  .stat { padding: 14px; }
  .page-head h1 { font-size: 19px; }
  .steps li { font-size: 0; gap: 0; }
  .installer { padding: 22px; }
  .reader-head { padding: 14px 16px; }
  .list-head { flex-wrap: wrap; }
  #folderSelect { width: 100%; }
}
