:root {
  --bg: #f5f6f8;
  --card: #fff;
  --text: #1d2129;
  --muted: #6b7280;
  --border: #e3e5e8;
  --accent: #2563eb;
  --accent-text: #fff;
  --danger: #c2410c;
  --info-bg: #eef4ff;
  --warn-bg: #fff7e6;
  --error-bg: #fdecec;
  --radius: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --card: #1e2125;
    --text: #e6e8eb;
    --muted: #9aa1ab;
    --border: #2f3338;
    --accent: #4f8cff;
    --info-bg: #1b2a44;
    --warn-bg: #3a2f17;
    --error-bg: #3d1f1f;
    --danger: #ff8a5c;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 12px; }
h2 { font-size: 17px; margin: 0 0 12px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 600; color: var(--text); }
.wrap { max-width: 900px; margin: 0 auto; padding: 20px 16px 60px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card.narrow { max-width: 440px; margin: 40px auto; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

input, textarea, button { font: inherit; color: inherit; }
input:not([type=checkbox]), textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
button {
  padding: 8px 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--card); cursor: pointer; white-space: nowrap;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.link, button.menu-button { border: 0; background: none; padding: 0; color: var(--accent); }
button.small-button { padding: 4px 10px; font-size: 13px; }
button.danger { color: var(--danger); }

.stack { display: grid; gap: 14px; margin: 16px 0; }
.stack label { display: grid; gap: 6px; font-weight: 500; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.inline-form { display: grid; grid-template-columns: 2fr 1.5fr auto; gap: 8px; }
@media (max-width: 640px) { .inline-form { grid-template-columns: 1fr; } }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; background: var(--info-bg); }
.flash-warn { background: var(--warn-bg); }
.flash-error { background: var(--error-bg); }

.switcher { position: relative; }
.switcher summary { cursor: pointer; list-style: none; color: var(--accent); max-width: 60vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.switcher summary::after { content: " ▾"; }
.switcher-menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 280px; display: grid; gap: 2px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px;
  box-shadow: 0 8px 24px rgb(0 0 0 / .12);
}
.switcher-menu a, .switcher-menu .menu-button { padding: 6px 8px; border-radius: 6px; text-align: left; overflow-wrap: anywhere; }
.switcher-menu a[aria-current] { font-weight: 600; background: var(--bg); }
.switcher-menu form { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; }
.switcher-menu .menu-button { color: var(--danger); width: 100%; }

.inbox-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.inbox-head h1 { margin: 0; overflow-wrap: anywhere; }
.address { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
h1.address { font-size: 19px; }
.search { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }

.mail-list { list-style: none; margin: 8px 0; padding: 0; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.mail-list li + li { border-top: 1px solid var(--border); }
.mail-list a { display: block; padding: 12px 16px; color: inherit; }
.mail-list a:hover { background: var(--bg); text-decoration: none; }
.mail-list .row1 { display: flex; justify-content: space-between; gap: 12px; }
.mail-list .from { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-list time { color: var(--muted); font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.mail-list .subject { overflow-wrap: anywhere; }
.mail-list .snippet { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-list .empty { padding: 28px 16px; color: var(--muted); text-align: center; }
.badge { display: inline-block; font-size: 12px; padding: 0 6px; border-radius: 4px; background: var(--bg); border: 1px solid var(--border); color: var(--muted); vertical-align: 1px; font-family: inherit; }
.pager { display: flex; justify-content: center; gap: 16px; margin-top: 12px; }

.message h1 { overflow-wrap: anywhere; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0 0 16px; font-size: 14px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; overflow-wrap: anywhere; }
.attachments { padding: 10px 14px; background: var(--bg); border-radius: 8px; margin-bottom: 16px; }
.attachments ul { margin: 6px 0 0; padding-left: 20px; }
.body-tools { color: var(--muted); margin-bottom: 8px; }
.body-tools .notice { margin: 0 0 6px; padding: 8px 12px; border-radius: 8px; background: var(--warn-bg); color: var(--text); }
.html-body { width: 100%; height: 75vh; border: 1px solid var(--border); border-radius: 8px; background: #fff; resize: vertical; }
.text-body { white-space: pre-wrap; overflow-wrap: anywhere; }

.table-wrap { overflow-x: auto; margin-bottom: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; white-space: nowrap; }
td.actions { white-space: nowrap; }
td.actions form { display: inline; }
.note-form { display: flex; gap: 6px; min-width: 200px; }
.note-form input { padding: 4px 8px; }
#alias-filter { max-width: 240px; }
code.code { white-space: nowrap; font-size: 17px; letter-spacing: 1px; padding: 2px 8px; border-radius: 6px; background: var(--bg); border: 1px solid var(--border); }
