:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f9fbfd;
  --text: #152033;
  --muted: #657386;
  --line: #dce3eb;
  --line-strong: #c6d0dc;
  --primary: #1f5f99;
  --primary-strong: #174975;
  --green: #16643f;
  --green-bg: #e8f6ef;
  --amber: #825314;
  --amber-bg: #fff4d8;
  --red: #aa3244;
  --red-strong: #872535;
  --shadow: 0 10px 28px rgba(24, 36, 56, .08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: 14px 28px;
  background: rgba(255, 255, 255, .94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: #18324d;
  color: #fff;
  font-weight: 850;
  font-size: 13px;
}

.brand strong { display: block; font-size: 17px; }
.brand small { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }

nav {
  display: flex;
  align-items: center;
  gap: 10px;
}

nav a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 10px;
  border-radius: 6px;
  color: #243b55;
  text-decoration: none;
  font-weight: 750;
}

nav a:hover { background: #eef3f8; }
nav form { display: inline-flex; }

main {
  width: min(1240px, calc(100% - 36px));
  margin: 0 auto;
  padding: 26px 0 48px;
}

h1, h2, h3, p { margin-top: 0; }
h2 { margin-bottom: 0; font-size: 22px; letter-spacing: 0; }
h3 { margin-bottom: 6px; font-size: 15px; }
a { color: var(--primary); }

button {
  min-height: 40px;
  border: 0;
  border-radius: 7px;
  padding: 8px 14px;
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

button:hover { background: var(--primary-strong); }
button.secondary {
  background: #eef3f8;
  color: #214462;
  border: 1px solid #d7e0ea;
}
button.secondary:hover { background: #e3ebf4; }
button.danger { background: var(--red); }
button.danger:hover { background: var(--red-strong); }

form { display: grid; gap: 12px; margin: 0; }
form.inline,
form.toolbar {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  color: #4b5b6e;
  font-size: 13px;
  font-weight: 750;
}

input, select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 9px 11px;
  background: #fff;
  color: var(--text);
  font: inherit;
  outline: none;
}

input:focus, select:focus {
  border-color: #4e8cc4;
  box-shadow: 0 0 0 3px rgba(31, 95, 153, .12);
}

code {
  display: inline-flex;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
  color: #385066;
  background: #eef3f8;
  border: 1px solid #d8e1ea;
  border-radius: 5px;
  padding: 4px 6px;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}

th, td {
  padding: 13px 12px;
  border-bottom: 1px solid #e4e9ef;
  text-align: left;
  vertical-align: middle;
}

th {
  color: #667589;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  background: var(--surface-2);
}

td span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

tr:last-child td { border-bottom: 0; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  display: inline-flex;
  margin-bottom: 6px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.status-pill,
.user-chip,
.role {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  border: 1px solid #d5e0ea;
  border-radius: 999px;
  padding: 4px 10px;
  background: #fff;
  color: #2d4057;
  font-size: 12px;
  font-weight: 800;
}

.mailbox-head-actions {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
}

.settings-menu {
  position: relative;
}

.settings-menu summary {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid #d5e0ea;
  border-radius: 999px;
  padding: 0 12px;
  background: #fff;
  color: #2d4057;
  font-size: 12px;
  font-weight: 850;
  cursor: pointer;
  list-style: none;
}

.settings-menu summary::-webkit-details-marker { display: none; }
.settings-menu summary:hover { background: #eef3f8; }

.settings-popover {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 20;
  width: min(360px, calc(100vw - 32px));
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(20, 31, 48, .18);
}

.settings-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid #e5ebf1;
}

.settings-meta span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.user-chip small {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: .05em;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metrics div,
.stat-stack div {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 15px;
}

.metrics strong,
.stat-stack strong {
  display: block;
  font-size: 26px;
  line-height: 1;
}

.metrics span,
.stat-stack span {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.grid {
  display: grid;
  gap: 18px;
}

.grid.two {
  grid-template-columns: minmax(340px, .72fr) minmax(0, 1.28fr);
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 15px;
}

.panel-head h2 { font-size: 17px; }
.panel-head span,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.actions.compact button { min-height: 34px; padding: 6px 10px; font-size: 13px; }
.actions form { display: inline-flex; }
.actions.stacked { display: grid; grid-template-columns: 1fr 1fr; margin-bottom: 14px; }
.actions.stacked form, .actions.stacked button { width: 100%; }

.badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 850;
  background: #edf2f7;
  color: #475569;
}

.badge.verified { background: var(--green-bg); color: var(--green); }
.badge.pending { background: var(--amber-bg); color: var(--amber); }
.badge.disabled { background: #f1f5f9; color: #64748b; }

.mail-link {
  display: inline-flex;
  color: #142236;
  font-weight: 850;
  text-decoration: none;
}

.mail-link:hover { color: var(--primary); }

.auth-shell {
  min-height: calc(100vh - 140px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 430px;
  align-items: center;
  gap: 32px;
}

.auth-copy {
  padding: 12px;
}

.auth-copy h2 {
  max-width: 660px;
  font-size: 48px;
  line-height: 1.04;
}

.auth-copy p {
  max-width: 560px;
  color: var(--muted);
  font-size: 17px;
}

.auth {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.error {
  color: #991b2e;
  background: #fff1f3;
  border: 1px solid #ffc6cf;
  border-radius: 7px;
  padding: 10px;
}

.notice {
  margin-bottom: 16px;
  padding: 12px 14px;
  background: var(--amber-bg);
  border: 1px solid #f0d08b;
  border-radius: 8px;
  color: var(--amber);
  font-weight: 750;
}

.password-cell {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto;
  gap: 8px;
  align-items: center;
  max-width: 260px;
}

.password-cell input {
  min-height: 34px;
  padding: 6px 8px;
  font-size: 13px;
}

.password-cell button {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 13px;
}

.mailbox-layout {
  display: block;
}

.stat-stack {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.inbox-workspace {
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  gap: 0;
  min-height: calc(100vh - 190px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.message-list {
  border-right: 1px solid var(--line);
  background: #fbfcfe;
  overflow: auto;
  max-height: calc(100vh - 190px);
}

.list-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: #f7f9fc;
}

.list-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.inbox-row {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 13px 14px;
  border: 0;
  border-bottom: 1px solid #e7ecf2;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  text-decoration: none;
  text-align: left;
  font: inherit;
  font-weight: inherit;
  white-space: normal;
}

.inbox-row:hover {
  background: #eef5fb;
}

.inbox-row.active,
.inbox-row:focus {
  background: #e6f0fa;
  box-shadow: inset 3px 0 0 var(--primary);
  outline: none;
}

.row-sender {
  color: #20334c;
  font-size: 13px;
  font-weight: 850;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inbox-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.row-snippet {
  display: -webkit-box;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.inbox-row time {
  color: #7a8797;
  font-size: 11px;
}

.reader-pane {
  display: grid;
  gap: 14px;
  align-content: start;
  padding: 16px;
  max-height: calc(100vh - 190px);
  overflow: auto;
}

.message {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: none;
}

.reader-message {
  min-height: 540px;
}

.message-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  padding: 15px 16px;
  border-bottom: 1px solid #e4e9ef;
  background: var(--surface-2);
}

.message-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.message-head time {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.message-body {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: #fff;
  padding: 26px 28px;
  max-height: none;
  overflow: auto;
  color: #253244;
  font: 15px/1.62 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.empty {
  padding: 28px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
}

.empty.mini {
  padding: 14px;
  border-radius: 6px;
  box-shadow: none;
}

@media (max-width: 900px) {
  header { align-items: flex-start; flex-direction: column; }
  nav { width: 100%; flex-wrap: wrap; }
  main { width: min(100% - 24px, 1240px); padding-top: 18px; }
  .auth-shell,
  .grid.two,
  .inbox-workspace {
    grid-template-columns: 1fr;
  }
  .auth-copy h2 { font-size: 34px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .message-list,
  .reader-pane { max-height: none; }
  .message-list { border-right: 0; border-bottom: 1px solid var(--line); }
  table { display: block; overflow-x: auto; }
}

@media (max-width: 560px) {
  .page-head { align-items: flex-start; flex-direction: column; }
  .mailbox-head-actions { width: 100%; align-items: flex-start; flex-direction: column; }
  .settings-menu, .settings-menu summary { width: 100%; }
  .settings-popover { left: 0; right: auto; width: 100%; }
  .metrics { grid-template-columns: 1fr; }
  .actions.stacked { grid-template-columns: 1fr; }
  form.inline, form.toolbar { display: grid; }
  .form-row, .password-cell { grid-template-columns: 1fr; }
  button { width: 100%; }
}
