:root {
  --bg: #f5f5f9;
  --panel: #ffffff;
  --ink: #1c2230;
  --ink-soft: #3d4657;
  --muted: #5f6775;   /* >=4.5:1 on white and --bg (WCAG AA body text) */
  --faint: #6b7280;   /* >=4.5:1 for dates and the star control */
  --decor: #cbd2dc;   /* purely decorative fills (empty-state icon) */
  --line: #eef0f4;
  --line-2: #e4e7ee;
  --accent: #7c3aed;
  --accent-600: #6d28d9;
  --accent-050: #f3efff;
  --accent-100: #e9e1fe;
  --danger: #dc2626;
  --danger-050: #fdecec;
  --spam: #b45309;
  --spam-050: #fdf1dd;
  --ok: #0f9d58;
  --ok-050: #e7f6ee;
  --star: #f5b301;
  --r: 10px;
  --r-lg: 16px;
  --r-pill: 999px;
  --shadow: 0 1px 2px rgba(20, 28, 48, .04), 0 6px 20px rgba(20, 28, 48, .05);
  --sidebar-w: 258px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14.5px/1.55 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.icon { width: 1.1em; height: 1.1em; flex-shrink: 0; }
.vh { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ============ app shell ============ */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--line-2);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 1.15rem; color: var(--ink);
  padding: 4px 6px 12px;
}
.brand:hover { text-decoration: none; }
.brand-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--accent); color: #fff;
}
.brand-badge .icon { width: 19px; height: 19px; }

.compose-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: #fff;
  padding: 11px 14px; border-radius: var(--r-pill);
  font-weight: 600; font-size: .95rem;
  box-shadow: 0 4px 12px rgba(124, 58, 237, .28);
  margin-bottom: 8px;
}
.compose-btn:hover { background: var(--accent-600); text-decoration: none; }
.compose-btn .icon { width: 17px; height: 17px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: var(--r);
  color: var(--ink-soft); font-weight: 500;
}
.nav-item:hover { background: #f4f5f8; text-decoration: none; color: var(--ink); }
.nav-item.active { background: var(--accent-050); color: var(--accent-600); font-weight: 600; }
.nav-item.active .icon { color: var(--accent); }
.nav-item .icon { width: 18px; height: 18px; color: var(--muted); }
.nav-label { flex: 1; }
.nav-item .count {
  background: var(--accent); color: #fff;
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: var(--r-pill);
  font-size: .72rem; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.nav-item.active .count { background: var(--accent); }
.nav-sep { height: 1px; background: var(--line); margin: 10px 6px; }

.sidebar-foot {
  margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px;
}
.acct { display: flex; align-items: center; gap: 9px; min-width: 0; flex: 1; }
.acct-email {
  font-size: .82rem; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.logout {
  background: none; border: 0; color: var(--muted); cursor: pointer;
  padding: 7px; border-radius: 8px; display: inline-flex;
}
.logout:hover { background: #f4f5f8; color: var(--danger); }
.logout .icon { width: 18px; height: 18px; }

.content { flex: 1; min-width: 0; padding: 26px 32px; }

/* ============ avatars ============ */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  font-size: .8rem; font-weight: 700; flex-shrink: 0;
  letter-spacing: .3px;
}
.avatar.sm { width: 28px; height: 28px; font-size: .72rem; }
.avatar.c0 { background: #ede9fe; color: #7c3aed; }
.avatar.c1 { background: #dbeafe; color: #2563eb; }
.avatar.c2 { background: #d1fae5; color: #059669; }
.avatar.c3 { background: #fee2e2; color: #dc2626; }
.avatar.c4 { background: #fef3c7; color: #d97706; }
.avatar.c5 { background: #fce7f3; color: #db2777; }
.avatar.c6 { background: #cffafe; color: #0891b2; }
.avatar.c7 { background: #e0e7ff; color: #4f46e5; }

/* ============ page heading ============ */
.pagehead { display: flex; align-items: center; gap: 12px; margin: 2px 2px 18px; }
.pagehead h1 { font-size: 1.35rem; margin: 0; letter-spacing: -.01em; }
.pagehead h1.cap { text-transform: capitalize; }
.pagehead .sub { color: var(--muted); font-size: .9rem; }
.pagehead .spacer { flex: 1; }

/* ============ message list ============ */
.msglist {
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.msg-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  position: relative;
  transition: background .12s;
}
.msg-row:last-child { border-bottom: 0; }
.msg-row:hover { background: #faf9fe; }
.msg-row .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); flex-shrink: 0; visibility: hidden;
}
.msg-row.unread .dot { visibility: visible; }
.msg-row.unread { background: #fbfaff; }

.star {
  display: inline-flex; margin: 0;
}
.star button {
  background: none; border: 0; cursor: pointer; padding: 3px;
  display: inline-flex; border-radius: 6px; color: var(--faint);
}
.star button:hover { background: #f0eefb; color: var(--star); }
.star .icon { width: 18px; height: 18px; fill: none; }
.star.on button { color: var(--star); }
.star.on .icon { fill: var(--star); stroke: var(--star); }

.msg-link {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 14px;
  color: inherit;
}
.msg-link:hover { text-decoration: none; }
.msg-sender {
  width: 168px; flex-shrink: 0;
  color: var(--ink-soft); font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg-row.unread .msg-sender { color: var(--ink); font-weight: 700; }
.msg-subject {
  flex: 1; min-width: 0;
  color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg-row.unread .msg-subject { color: var(--ink-soft); font-weight: 500; }
.msg-meta {
  flex-shrink: 0; display: flex; align-items: center; gap: 8px;
  color: var(--faint); font-size: .82rem; white-space: nowrap;
}

.msglist-foot { padding: 12px 16px; }
.empty {
  color: var(--muted); text-align: center; padding: 48px 16px;
}
.empty .icon { width: 40px; height: 40px; color: var(--decor); display: block; margin: 0 auto 10px; }

/* ============ badges ============ */
.badge {
  display: inline-flex; align-items: center;
  background: #eef1f5; color: var(--muted);
  border-radius: var(--r-pill); padding: 1px 9px;
  font-size: .74rem; font-weight: 600;
}
.badge.spam { background: var(--spam-050); color: var(--spam); }
.badge.sent { background: var(--ok-050); color: var(--ok); }
.badge.bounced { background: var(--danger-050); color: var(--danger); }
.badge.deferred { background: var(--spam-050); color: var(--spam); }
.badge.pending, .badge.sending { background: var(--accent-050); color: var(--accent-600); }

/* ============ cards & content ============ */
.card {
  background: var(--panel); border: 1px solid var(--line-2);
  border-radius: var(--r-lg); box-shadow: var(--shadow);
  padding: 24px 26px; margin-bottom: 18px;
}
.card h1 { font-size: 1.25rem; margin: 0 0 4px; }
.card.narrow { max-width: 480px; }
.card > h2:first-of-type { margin-top: 4px; }
h2 { font-size: 1.02rem; margin: 22px 0 10px; letter-spacing: -.01em; }
section { padding: 18px 0; }
section:first-of-type { padding-top: 4px; }
section + section { border-top: 1px solid var(--line); }
section h2:first-child { margin-top: 0; }

/* ============ forms ============ */
label { display: block; margin: 12px 0 0; color: var(--ink-soft); font-size: .86rem; font-weight: 600; }
input, textarea, select {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px;
  border: 1px solid var(--line-2); border-radius: var(--r); font: inherit;
  color: var(--ink); background: #fff; transition: border-color .12s, box-shadow .12s;
}
input:focus, textarea:focus, select:focus {
  outline: 0; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-050);
}
textarea { resize: vertical; min-height: 120px; }
label.chk, .chk { display: inline-flex; width: auto; align-items: center; gap: 7px; margin-top: 0; font-weight: 500; color: var(--ink-soft); }
label.chk input, .chk input { width: auto; display: inline; margin: 0; }

button, .btn {
  padding: 10px 18px; border: 0; border-radius: var(--r); font: inherit; font-weight: 600;
  background: var(--accent); color: #fff; cursor: pointer; transition: background .12s;
  display: inline-flex; align-items: center; gap: 8px;
}
button:hover, .btn:hover { background: var(--accent-600); text-decoration: none; }
button.ghost, .btn.ghost {
  background: #fff; color: var(--ink-soft); border: 1px solid var(--line-2);
}
button.ghost:hover, .btn.ghost:hover { background: #f7f8fb; }
button.danger { background: var(--danger); }
button.danger:hover { background: #b91c1c; }
button.linkbtn, .linkbtn { background: none; color: var(--accent); padding: 0; font-weight: 600; }
.linkbtn:hover { background: none; text-decoration: underline; }
button.linkbtn.danger, .linkbtn.danger { background: none; color: var(--danger); }
form.inline, .inline { display: inline; }
form.stack { margin-top: 14px; }
form.stack button { margin-top: 16px; }
form.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 12px; }
form.row input, form.row select { width: auto; margin-top: 0; flex: 1; min-width: 160px; }
form.row button { flex-shrink: 0; }

/* ============ banners ============ */
.banner {
  padding: 12px 16px; border-radius: var(--r); margin-bottom: 18px;
  font-size: .9rem; font-weight: 500;
  display: flex; align-items: center; gap: 8px;
}
.banner.ok { background: var(--accent-050); color: var(--accent-600); border: 1px solid var(--accent-100); }
.banner.err { background: var(--danger-050); color: var(--danger); border: 1px solid #f6c9c9; }
.notice { background: var(--accent-050); border: 1px solid var(--accent-100); color: var(--accent-600); padding: 12px 16px; border-radius: var(--r); margin-bottom: 16px; }
.notice.secret code { display: block; margin-top: 8px; word-break: break-all; font-size: .85rem; color: var(--ink); }
.error { background: var(--danger-050); border: 1px solid #f6c9c9; color: var(--danger); padding: 12px 16px; border-radius: var(--r); margin-bottom: 16px; }

/* ============ message view ============ */
.msg-actions { display: flex; gap: 8px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.msg-actions .spacer { flex: 1; }
.card h1.subject { font-size: 1.4rem; margin: 6px 0 16px; letter-spacing: -.01em; }
.msg-from { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.msg-from .who { min-width: 0; }
.msg-from .who .name { font-weight: 700; }
.msg-from .who .addr { color: var(--muted); font-size: .85rem; }
.headers { color: var(--muted); font-size: .86rem; margin: 4px 0 18px; }
.headers div { padding: 1px 0; }
.headers span.k { display: inline-block; width: 52px; color: var(--ink-soft); font-weight: 600; }
.attachments {
  background: #f8f9fb; border: 1px solid var(--line-2); border-radius: var(--r);
  padding: 12px 14px; margin-bottom: 18px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.att {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border: 1px solid var(--line-2); border-radius: var(--r-pill);
  padding: 4px 12px; font-size: .85rem; color: var(--ink-soft);
}
.att .icon { width: 15px; height: 15px; color: var(--muted); }
.text-body { white-space: pre-wrap; word-wrap: break-word; font: inherit; margin: 0; color: var(--ink-soft); }
.html-body { border-top: 1px solid var(--line); padding-top: 18px; }
.html-body img { max-width: 100%; }

/* ============ tables ============ */
.tbl { width: 100%; border-collapse: collapse; margin-top: 12px; }
.tbl th, .tbl td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: .88rem; vertical-align: middle; }
.tbl th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .err { color: var(--danger); font-size: .8rem; max-width: 260px; overflow: hidden; }
.dkim, pre.dkim { background: #f8f9fb; padding: 12px; border-radius: var(--r); overflow-x: auto; font-size: .8rem; border: 1px solid var(--line-2); }
.domain { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.domain h3 { margin: 0 0 8px; font-size: 1rem; }
.sub { margin: 6px 0; font-size: .88rem; color: var(--ink-soft); }
.mono, code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ============ auth (login / totp) ============ */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth { width: 100%; max-width: 400px; }
.auth .card { padding: 32px 30px; }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 22px; font-weight: 700; font-size: 1.3rem; }
.auth-brand .brand-badge { width: 38px; height: 38px; }
.qr { display: block; margin: 16px auto; border: 1px solid var(--line-2); border-radius: var(--r); }

/* ============ responsive ============ */
@media (max-width: 780px) {
  .sidebar {
    position: static; height: auto; width: 100%;
    flex-direction: row; flex-wrap: wrap; align-items: center;
    gap: 8px; padding: 10px 14px;
  }
  .brand { padding: 4px 6px; }
  .compose-btn { order: 3; margin: 0; padding: 9px 14px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav-sep { display: none; }
  .sidebar-foot { margin: 0; padding: 0; border: 0; width: auto; }
  .acct-email { display: none; }
  .content { padding: 18px 16px; }
  .msg-sender { width: 120px; }
}
@media (max-width: 520px) {
  .msg-sender { width: 92px; font-size: .9rem; }
  .msg-meta .badge { display: none; }
}
