:root {
  color-scheme: light;
  --ink: #18243b;
  --muted: #58677d;
  --navy: #111c32;
  --accent: #244fc5;
  --accent-hover: #183da4;
  --tint: #edf2ff;
  --line: #dce3ee;
  --paper: #fff;
  --wash: #f5f7fb;
  --danger: #aa2c3c;
  font: 15px/1.5 system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--wash);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body, h1, h2, h3, p { margin: 0; }
button, input, textarea, select { font: inherit; }
button, summary { cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
:focus-visible { outline: 3px solid #7192f4; outline-offset: 3px; }
h1 { font-size: clamp(2rem, 4vw, 2.85rem); line-height: 1.12; letter-spacing: -.045em; }
h2 { font-size: 1.13rem; line-height: 1.35; letter-spacing: -.016em; }
a { color: inherit; }
button, select, summary {
  min-height: 2.5rem; padding: .48rem .8rem; border: 1px solid var(--line); border-radius: .55rem;
  color: var(--ink); background: var(--paper); font-weight: 650;
}
button:hover:not(:disabled), summary:hover { background: var(--wash); }
.primary { background: var(--accent); border-color: var(--accent); color: white; }
.primary:hover:not(:disabled) { background: var(--accent-hover); }
.quiet { background: transparent; border-color: transparent; }
.danger-text { color: var(--danger); }
.danger { background: var(--danger); border-color: var(--danger); color: white; }
.danger:hover:not(:disabled) { background: #862134; }
.muted, .hint { color: var(--muted); }
.actions, .between { display: flex; align-items: center; gap: .65rem; }
.between { justify-content: space-between; }
.app { display: grid; grid-template-columns: 15rem minmax(0, 1fr); min-height: 100dvh; }
.sidebar {
  position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column;
  padding: 1.7rem 1.15rem 1rem; background: var(--navy); color: #f8faff;
}
.brand { display: flex; align-items: center; gap: .68rem; font-size: 1.35rem; font-weight: 750; letter-spacing: -.03em; }
.mark {
  flex: 0 0 auto; display: grid; place-items: center; width: 2.35rem; height: 2.35rem;
  border-radius: .7rem; background: #bcd0ff; color: #172d69; font-size: 1.15rem;
}
.nav { display: grid; gap: .3rem; margin-top: 2.4rem; }
.nav a {
  display: flex; align-items: center; gap: .65rem; min-height: 2.65rem; padding: .45rem .7rem;
  color: #c4cfe4; border-radius: .55rem; text-decoration: none; font-weight: 630;
}
.nav a span { width: 1.25rem; text-align: center; color: #a9bff5; font-size: 1.05rem; }
.nav a:hover { background: #1e2c47; }
.nav a[aria-current] { background: #293e69; color: white; }
.profile {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: .65rem; align-items: center;
  margin-top: auto; padding-top: 1rem; border-top: 1px solid #33415c;
}
.profile strong, .profile small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile small { color: #b6c4de; font-size: .75rem; }
.profile button { min-width: 2.25rem; padding: .25rem; background: transparent; border-color: #475975; color: #e3ebfc; }
.profile button:hover { background: #293e69; }
#workspace-status:not(:empty) { color: #f9cad0; font-size: .8rem; margin-top: .65rem; }
main { width: 100%; max-width: 105rem; margin: 0 auto; padding: clamp(1.25rem, 4vw, 3.25rem); }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1.6rem; }
.page-head p { margin-top: .48rem; color: var(--muted); overflow-wrap: anywhere; }
.page-head button { flex-shrink: 0; }
.panel, .workspace, .onboarding {
  background: var(--paper); border: 1px solid var(--line); border-radius: .85rem;
  box-shadow: 0 4px 18px #1b2d5010;
}
.panel-bar { min-height: 4.5rem; padding: .85rem 1.25rem; display: flex; gap: .8rem; align-items: center; justify-content: space-between; }
.panel-bar h2 { display: flex; align-items: center; gap: .5rem; }
.count-pill, .badge {
  display: inline-block; border-radius: 2rem; padding: .15rem .55rem;
  background: #edf1f7; color: #475872; font-size: .77rem; font-weight: 700;
}
.badge.admin { background: var(--tint); color: var(--accent); }
.page-status:not(:empty) { padding: .65rem 1.25rem; border-top: 1px solid var(--line); color: var(--muted); }
.user-table { border-collapse: collapse; width: 100%; table-layout: fixed; }
.user-table th {
  text-align: left; font-size: .78rem; font-weight: 700; color: var(--muted); background: #f3f6fb; border-top: 1px solid var(--line);
}
.user-table th:first-child { width: 60%; }
.user-table th, .user-table td { padding: .75rem 1.25rem; }
.user-table td { border-top: 1px solid var(--line); }
.user-table tbody tr:hover { background: #fafbfe; }
.user-table .align-end { text-align: right; }
.identity { display: flex; gap: .7rem; align-items: center; overflow-wrap: anywhere; }
.identity small { display: block; color: var(--muted); }
.avatar {
  flex: 0 0 auto; display: grid; place-items: center; width: 2.4rem; height: 2.4rem;
  border-radius: .65rem; background: var(--tint); color: #2a4aab; font-weight: 750; font-size: .82rem;
}
.panel-empty { padding: 2rem 1.25rem; color: var(--muted); border-top: 1px solid var(--line); }
.account-row {
  display: flex; gap: .75rem; align-items: center; padding: .85rem 1.25rem; border-top: 1px solid var(--line);
}
.account-info { flex: 1; min-width: 0; }
.account-name { width: 100%; font-weight: 700; border: 1px solid transparent; background: transparent; border-radius: .45rem; padding: .18rem .3rem; }
.account-name:hover, .account-name:focus { border-color: var(--line); background: var(--wash); }
.account-info small { display: block; font-size: .78rem; color: var(--muted); padding-left: .3rem; overflow-wrap: anywhere; }
.account-info small[data-status="ok"] { color: #137352; }
.account-info small[data-status="error"] { color: var(--danger); }
.account-actions { display: flex; align-items: center; gap: .25rem; }
.account-actions button { font-size: .83rem; }
.mail-tools { display: flex; flex-wrap: wrap; gap: .65rem; align-items: center; margin-bottom: .75rem; }
.mail-tools .search { margin-left: auto; }
.search {
  display: flex; align-items: center; gap: .48rem; min-height: 2.5rem; width: min(100%, 19rem);
  padding: .3rem .6rem; background: white; border: 1px solid var(--line); border-radius: .55rem;
}
.search span { font-size: 1.25rem; color: var(--muted); }
.search input { min-width: 0; width: 100%; border: none; background: transparent; color: var(--ink); }
.folder { display: flex; align-items: center; gap: .45rem; color: var(--muted); font-size: .88rem; }
.folder select { font-size: .94rem; }
.mailbox-picker { position: relative; max-width: min(100%, 18rem); }
.mailbox-picker summary { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mailbox-picker summary > span:first-child { display: inline-block; margin-right: .25rem; color: var(--accent); }
.mailbox-options {
  position: absolute; z-index: 2; inset-inline-start: 0; top: calc(100% + .35rem);
  width: min(90vw, 21rem); padding: .85rem; background: var(--paper); border: 1px solid var(--line);
  border-radius: .7rem; box-shadow: 0 8px 30px #16233b25;
}
#account-select { max-height: 15rem; overflow: auto; margin-block: .4rem; }
#account-select label { display: flex; align-items: center; gap: .55rem; padding: .45rem .35rem; overflow-wrap: anywhere; }
input[type="checkbox"] { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); flex: 0 0 auto; }
.onboarding {
  display: grid; justify-items: center; align-content: center; gap: .7rem; min-height: min(59vh, 31rem);
  text-align: center; padding: 2rem 1.25rem;
}
.onboarding h2 { font-size: 1.5rem; }
.onboarding p { color: var(--muted); max-width: 34ch; }
.onboarding .actions { flex-wrap: wrap; justify-content: center; margin-top: .35rem; }
.empty-icon {
  display: grid; place-items: center; width: 3.3rem; height: 3.3rem; margin: 0 auto .25rem;
  border-radius: .85rem; background: var(--tint); color: var(--accent); font-size: 1.4rem;
}
.workspace { display: grid; grid-template-columns: minmax(16rem, .82fr) minmax(0, 1.5fr); min-height: 32rem; overflow: hidden; }
.list-pane { min-width: 0; border-right: 1px solid var(--line); }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: .55rem; padding: .65rem .85rem; border-bottom: 1px solid var(--line); }
.filters { display: flex; gap: .25rem; }
.filters button, .back { min-height: 2.2rem; border: 0; background: transparent; padding: .4rem .58rem; font-size: .85rem; }
.filters button[aria-pressed=true], .back { background: var(--tint); color: var(--accent); }
#count { color: var(--muted); font-size: .77rem; }
#status:not(:empty) { padding: 1rem; color: var(--muted); }
#messages { max-height: 64vh; overflow: auto; }
.message {
  position: relative; display: grid; grid-template-columns: 2.4rem minmax(0, 1fr); gap: .7rem;
  width: 100%; padding: .85rem; text-align: left; font-weight: 400; border: 0; border-bottom: 1px solid var(--line); border-radius: 0;
}
.message:hover, .message[aria-current=true] { background: #f2f5fe; }
.message[aria-current=true] { box-shadow: inset 3px 0 var(--accent); }
.message:focus-visible { outline-offset: -4px; }
.message-top { display: flex; align-items: center; justify-content: space-between; gap: .6rem; font-size: .85rem; }
.sender, .message-subject, .preview { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sender { font-weight: 700; }
.message time, .preview { color: var(--muted); font-size: .78rem; }
.message-subject { margin: .12rem 0; font-size: .94rem; }
.message[data-unread=true] .message-subject { font-weight: 750; }
.message[data-unread=true] .sender::before { content: ""; display: inline-block; width: 6px; height: 6px; background: var(--accent); border-radius: 50%; margin-right: .4rem; vertical-align: middle; }
.reader { padding: clamp(1.1rem, 3.5vw, 2.5rem); min-width: 0; }
.reader h2 { font-size: clamp(1.3rem, 3vw, 2rem); overflow-wrap: anywhere; }
.details { display: flex; align-items: center; gap: .7rem; margin: 1.25rem 0; padding-bottom: 1rem; border-bottom: 1px solid var(--line); }
.details div { min-width: 0; overflow-wrap: anywhere; }
.details small { display: block; color: var(--muted); }
.body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.75; }
.empty { display: grid; place-content: center; gap: .4rem; min-height: 26rem; text-align: center; color: var(--muted); }
.empty h2 { color: var(--ink); font-size: 1.2rem; }
.back { display: none; margin-bottom: 1rem; }
#load-more { margin: .75rem; }
.auth-shell {
  display: grid; grid-template-columns: 1fr 1fr; width: min(92vw, 52rem); min-height: 29rem;
  margin: max(5vh, calc((100dvh - 29rem)/2)) auto 1.5rem;
  border: 1px solid var(--line); border-radius: 1.15rem; overflow: hidden; background: white;
  box-shadow: 0 18px 60px #17284d1c;
}
.auth-brand {
  display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start; gap: 2rem;
  padding: clamp(1.55rem, 4vw, 3.2rem); color: white; background: radial-gradient(ellipse at 95% 100%, #2b50a3 0%, var(--navy) 73%);
}
.auth-brand p { max-width: 15ch; font-size: clamp(1.5rem, 3vw, 2.1rem); font-weight: 650; letter-spacing: -.035em; line-height: 1.18; }
.auth-panel { align-self: center; padding: clamp(1.55rem, 4vw, 3.2rem); }
.auth-panel > p { margin-top: .55rem; }
.form, .form-fields { display: grid; gap: .85rem; }
.form { margin-top: 1.2rem; }
.form label { display: block; font-weight: 650; }
.form input:not([type="checkbox"]), .form textarea {
  display: block; width: 100%; margin-top: .32rem; padding: .55rem .65rem;
  color: var(--ink); background: white; border: 1px solid #bac7da; border-radius: .48rem; font-weight: 400;
}
.form input::placeholder, .form textarea::placeholder { color: #687991; }
.form textarea { resize: vertical; }
.form .hint { font-weight: 400; font-size: .85rem; }
.form-status:empty { display: none; }
.form-status { color: var(--danger); font-size: .88rem; overflow-wrap: anywhere; }
dialog {
  width: min(31rem, calc(100% - 1.5rem)); max-height: calc(100dvh - 1.5rem); overflow: auto;
  padding: 1.35rem; border: 1px solid var(--line); border-radius: .8rem; color: var(--ink); box-shadow: 0 20px 60px #10192a55;
}
dialog::backdrop { background: #10192a8c; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: .8rem; }
.dialog-head h2 { font-size: 1.45rem; overflow-wrap: anywhere; }
.dialog-head p, dialog > p { color: var(--muted); margin-top: .32rem; }
.icon-button { min-height: 2.1rem; padding: 0 .5rem; font-size: 1.38rem; line-height: 1; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .55rem; }
.connect-tabs { align-self: start; }
.form .check-option {
  display: flex; gap: .55rem; align-items: flex-start; padding: .65rem; border: 1px solid var(--line); border-radius: .55rem;
}
.check-option small { display: block; font-weight: 400; color: var(--muted); }
.password-wrap { display: flex; gap: .35rem; align-items: center; margin: .32rem 0; }
.password-wrap input:not([type="checkbox"]) { margin: 0; }
@media (max-width: 970px) {
  .app { grid-template-columns: 11.5rem minmax(0, 1fr); }
  main { padding: 1.4rem; }
  .mail-tools .search { margin-left: 0; flex: 1 1 12rem; }
}
@media (max-width: 740px) {
  .app { display: block; }
  .sidebar { position: static; height: auto; display: grid; grid-template-columns: 1fr auto; padding: .7rem .9rem; gap: .7rem; }
  .sidebar .brand { font-size: 1.15rem; }
  .sidebar .mark { width: 1.9rem; height: 1.9rem; }
  .nav { grid-row: 2; grid-column: 1 / -1; display: flex; margin: 0; }
  .nav a { flex: 1; justify-content: center; font-size: .9rem; min-height: 2.25rem; padding: .3rem .4rem; }
  .profile { border: 0; padding: 0; }
  .profile .avatar, .profile small { display: none; }
  .profile { grid-template-columns: minmax(0, 6rem) auto; font-size: .83rem; }
  #workspace-status { grid-column: 1 / -1; }
  main { padding: 1.1rem .9rem; }
  .page-head { margin-bottom: 1rem; }
  .page-head p { font-size: .88rem; }
  .page-head button { padding-inline: .55rem; font-size: .84rem; }
  .workspace { display: block; min-height: 23rem; }
  .list-pane { border-right: 0; }
  .reader { display: none; }
  .workspace.open .reader { display: block; }
  .workspace.open .list-pane { display: none; }
  .back { display: inline-block; }
  #messages { max-height: none; }
  .panel-bar { padding: .75rem; }
  .user-table th, .user-table td { padding: .62rem .55rem; }
  .user-table th:first-child { width: 54%; }
  .user-table .avatar { display: none; }
  .user-table button { padding-inline: .35rem; }
  .account-row { flex-wrap: wrap; padding: .7rem; }
  .account-actions { width: 100%; justify-content: end; }
  .auth-shell { display: block; max-width: 26rem; margin-top: 5vh; }
  .auth-brand { gap: .8rem; }
  .auth-brand p { font-size: 1.05rem; max-width: none; }
}
@media (max-width: 400px) {
  .panel-bar:has(#user-search) { flex-wrap: wrap; }
  .panel-bar:has(#user-search) .search { width: 100%; }
}
