:root {
  --bg: #f6f7f9; --panel: #fff; --ink: #16181d; --muted: #6b7280; --line: #e3e6ea;
  --accent: #2563eb; --ok: #15803d; --bad: #b91c1c; --todo: #fff8e6; --done: #f2f7f2;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a; --panel: #1c1f25; --ink: #e6e8ec; --muted: #98a0ad; --line: #2b3038;
    --accent: #60a5fa; --ok: #4ade80; --bad: #f87171; --todo: #26231a; --done: #1a2320;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  padding-bottom: 88px;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: rgba(127,127,127,.15); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
main { max-width: 1240px; margin: 0 auto; padding: 16px; }
h1 { font-size: 20px; margin: 4px 0 12px; }
h2 { font-size: 15px; margin: 22px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.nowrap { white-space: nowrap; }
.ellipsis { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 顶栏 */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20; flex-wrap: wrap;
}
.topbar nav { display: flex; gap: 14px; flex-wrap: wrap; }
.topbar nav a { color: var(--muted); }
.topbar nav a.on { color: var(--ink); font-weight: 600; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 20px; }

.toast {
  background: #dbeafe; color: #1e3a8a; border: 1px solid #bfdbfe;
  padding: 8px 12px; border-radius: var(--radius); margin-bottom: 12px;
}
@media (prefers-color-scheme: dark) { .toast { background: #1e293b; color: #bfdbfe; border-color: #334155; } }

/* 登录 */
.login { max-width: 320px; margin: 15vh auto; text-align: center; }
.login h1 { font-size: 22px; margin-bottom: 2px; }
.login form { margin-top: 20px; display: grid; gap: 10px; }
.error { color: var(--bad); }

/* 表单控件 */
input[type=password], input[type=number], input[type=text], select, textarea {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--panel); color: var(--ink); width: 100%;
}
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
button {
  font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; cursor: pointer;
}
button:disabled { opacity: .5; cursor: default; }
button.danger { background: var(--bad); border-color: var(--bad); }
button.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.form { display: grid; gap: 14px; max-width: 620px; }
.form label { display: grid; gap: 5px; }
.form label.check { display: flex; align-items: center; gap: 7px; }
.form input[type=checkbox] { width: auto; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
legend { font-size: 12px; color: var(--muted); padding: 0 4px; }

/* 头部工具条 */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.head-tools { display: flex; gap: 8px; align-items: center; }
.inline { display: inline; }
.date { color: var(--muted); font-weight: 400; font-size: 15px; }

/* 账户卡片 */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 10px; margin: 12px 0 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.card-err { border-color: var(--bad); }
.card-top { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.card-mail { color: var(--muted); font-size: 12px; margin-bottom: 6px; word-break: break-all; }
.nums { display: flex; gap: 12px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.nums b { color: var(--ink); font-size: 15px; margin-right: 2px; }
.nums .hi b { color: var(--accent); }
.letter {
  display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 5px;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 700;
}

/* 筛选 */
.filters { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.chip {
  padding: 4px 10px; border: 1px solid var(--line); border-radius: 20px;
  background: var(--panel); color: var(--muted); font-size: 12px;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip:hover { text-decoration: none; }
.counts { margin-left: auto; font-size: 12px; }

/* 邮件表 */
.acct { margin-bottom: 18px; }
.acct h2 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pick-all { font-size: 12px; font-weight: 400; }
table.mails, table.grid {
  width: 100%; border-collapse: collapse; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
table.mails th, table.grid th {
  text-align: left; font-size: 12px; color: var(--muted); font-weight: 600;
  padding: 8px 10px; border-bottom: 1px solid var(--line); background: rgba(127,127,127,.05);
}
table.mails td, table.grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.mails tr:last-child td, table.grid tr:last-child td { border-bottom: 0; }
tr.todo { background: var(--todo); }
tr.done { background: var(--done); opacity: .72; }
td.c, th.c { width: 30px; }
td.ref { font-weight: 700; white-space: nowrap; }
td.from { max-width: 190px; }
.fname { font-weight: 600; }
.femail { font-size: 11px; word-break: break-all; }
td.subj { max-width: 520px; }
.stitle { font-weight: 500; }
.sprev { font-size: 12px; }
.unsub { font-size: 11px; }
td.sug { font-size: 12px; max-width: 170px; }
.auto { font-size: 11px; }

/* 底部动作条 */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--line);
}
.actionbar .sel { margin-right: auto; }
.actionbar button { padding: 7px 12px; font-size: 13px; }

.empty { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; text-align: center; }
.note { background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--accent);
        border-radius: var(--radius); padding: 10px 14px; margin-top: 16px; font-size: 13px; }

@media (max-width: 760px) {
  main { padding: 12px 10px; }
  /* 手机上四个账户卡片占满一屏，压成两列 */
  .cards { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .card { padding: 8px 10px; }
  .card-mail { font-size: 11px; }
  .nums { gap: 8px; font-size: 11px; }
  .nums b { font-size: 13px; }
  .actionbar { gap: 6px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
  .actionbar button { padding: 6px 10px; font-size: 12px; }
  .actionbar .sel { width: 100%; margin: 0 0 2px; font-size: 12px; }
  table.mails thead { display: none; }
  table.mails, table.mails tbody, table.mails tr, table.mails td { display: block; width: 100%; }
  table.mails tr { border-bottom: 1px solid var(--line); padding: 8px 4px; position: relative; }
  table.mails td { border: 0; padding: 2px 8px; }
  td.c { position: absolute; right: 4px; top: 8px; width: auto; }
  td.from { max-width: none; }
  .femail { display: inline; }
  .fname { display: inline; margin-right: 6px; }
  td.subj { max-width: none; }
  .counts { margin-left: 0; width: 100%; }
}
