:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-2: #f1f3f8;
  --line: #e4e7ef;
  --text: #171a21;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --danger: #dc2626;
  --shadow: 0 10px 30px rgba(20, 30, 60, .12);
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --panel: #181b22;
    --panel-2: #20242d;
    --line: #2a2f3a;
    --text: #e8eaf0;
    --muted: #9097a5;
    --accent: #6d9bff;
    --accent-soft: #1d2a47;
    --danger: #f87171;
    --shadow: 0 10px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.err { color: var(--danger); font-size: 13px; margin: 8px 0 0; white-space: pre-wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; text-decoration: none; color: var(--text);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: default; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 0; background: transparent;
  display: inline-grid; place-items: center; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn.spin svg { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

input:not([type=checkbox]) {
  width: 100%; height: 42px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); outline: none;
}
select {
  width: 100%; height: 42px; padding: 0 10px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); outline: none;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- 登录 ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 340px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 32px 24px; text-align: center; box-shadow: var(--shadow);
  display: grid; gap: 12px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0 0 8px; }
.login-logo { width: 64px; height: 64px; border-radius: 16px; margin: 0 auto; }

/* ---------- 布局 ---------- */
.app {
  height: 100%;
  display: grid;
  grid-template-columns: 232px minmax(320px, 400px) 1fr;
}
.sidebar {
  border-right: 1px solid var(--line); background: var(--panel-2);
  display: flex; flex-direction: column; min-height: 0; padding: 14px 10px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 4px 8px 14px; }
.brand img { width: 28px; height: 28px; border-radius: 7px; }
.acc-nav { flex: 1; overflow-y: auto; display: grid; align-content: start; gap: 2px; }
.acc-nav button {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 9px 10px; border: 0; border-radius: 9px; background: transparent; cursor: pointer;
}
.acc-nav button:hover { background: var(--panel); }
.acc-nav button.active { background: var(--panel); box-shadow: 0 1px 0 var(--line); font-weight: 600; }
.acc-nav .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-nav .sub { display: block; font-size: 11px; color: var(--muted); font-weight: 400; overflow: hidden; text-overflow: ellipsis; }
.count { font-size: 12px; color: var(--accent); font-weight: 600; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.sidebar-foot { padding-top: 10px; }

.list-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; border-right: 1px solid var(--line); background: var(--panel); }
.topbar {
  display: flex; align-items: center; gap: 8px; padding: calc(12px + var(--safe-top)) 12px 8px 16px;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h2 { margin: 0; font-size: 19px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; gap: 2px; }
.search-wrap { padding: 4px 12px 8px; }
.search-wrap input { height: 36px; background: var(--panel-2); border-color: transparent; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 12px 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button {
  flex: none; display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-size: 13px;
}
.chips button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.errors { padding: 0 12px; display: grid; gap: 6px; }
.errors div {
  font-size: 12px; padding: 8px 10px; border-radius: 8px; color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
}

.msg-list { list-style: none; margin: 0; padding: 0 0 calc(16px + var(--safe-bottom)); overflow-y: auto; flex: 1; }
.msg {
  position: relative; display: grid; grid-template-columns: 4px 1fr; gap: 10px;
  padding: 11px 14px 11px 10px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.msg:hover { background: var(--panel-2); }
.msg.active { background: var(--accent-soft); }
.msg .bar { border-radius: 2px; }
.msg .body { min-width: 0; }
.msg .row1 { display: flex; align-items: baseline; gap: 8px; }
.msg .from { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .time { font-size: 12px; color: var(--muted); flex: none; }
.msg .subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.msg .preview { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .tags { display: flex; gap: 6px; align-items: center; margin-top: 2px; font-size: 11px; color: var(--muted); }
.msg.unread .from, .msg.unread .subject { font-weight: 700; }
.msg.unread .from::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); margin-right: 6px; vertical-align: 2px;
}
.empty { padding: 48px 24px; text-align: center; color: var(--muted); }
.empty .btn { margin-top: 14px; }

/* ---------- 阅读 ---------- */
.reader { min-width: 0; min-height: 0; overflow-y: auto; background: var(--panel); }
.reader-empty { height: 100%; display: grid; place-items: center; }
.reader-head { padding: calc(16px + var(--safe-top)) 24px 14px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 1; }
.reader-head h1 { font-size: 20px; margin: 4px 0 10px; line-height: 1.35; word-break: break-word; }
.reader-nav { display: none; align-items: center; gap: 4px; margin: -6px 0 2px -10px; }
.meta { display: grid; gap: 2px; font-size: 13px; color: var(--muted); }
.meta b { color: var(--text); font-weight: 600; }
.acc-tag { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); }
.atts { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 24px 0; }
.atts a {
  display: inline-flex; gap: 6px; align-items: center; max-width: 100%; padding: 6px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text); text-decoration: none; font-size: 13px;
}
.atts a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-frame { display: block; width: 100%; border: 0; min-height: 200px; background: #fff; }
.frame-wrap { padding: 12px 12px calc(24px + var(--safe-bottom)); }
.frame-wrap .mail-frame { border-radius: 10px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- 账号弹窗 ---------- */
.sheet {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0;
  border: 1px solid var(--line); border-radius: 18px; background: var(--panel); color: var(--text); box-shadow: var(--shadow);
}
.sheet::backdrop { background: rgba(10, 14, 25, .45); }
.sheet > * { margin-left: 20px; margin-right: 20px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; }
.sheet-head h3 { margin: 0; font-size: 18px; }
.sheet h4 { margin: 22px 20px 10px; font-size: 14px; color: var(--muted); font-weight: 600; }
.acc-list { list-style: none; padding: 0; margin-top: 10px; display: grid; gap: 8px; }
.acc-list li {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px;
}
.acc-list .info { flex: 1; min-width: 0; }
.acc-list .info b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.acc-list .info span { font-size: 12px; color: var(--muted); }
.acc-list .none { justify-content: center; color: var(--muted); border-style: dashed; }
.link-btn { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 4px 6px; border-radius: 6px; }
.link-btn:hover { background: var(--panel-2); color: var(--text); }
.link-btn.danger:hover { color: var(--danger); }
.type-tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.type-tabs button {
  height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-size: 13px;
}
.type-tabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.add-pane { display: grid; gap: 10px; margin-top: 12px; }
.add-pane label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.hint { margin: 0; font-size: 13px; color: var(--muted); background: var(--panel-2); padding: 10px 12px; border-radius: 10px; line-height: 1.6; }
.hint a { color: var(--accent); }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 8px; font-size: 13px; line-height: 1.6; }
.steps a { color: var(--accent); }
.steps code, .copy-row code {
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--panel-2);
  padding: 2px 6px; border-radius: 6px; word-break: break-all;
}
.copy-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.copy-row code { flex: 1; padding: 8px 10px; }
.copy-row .btn { height: 34px; padding: 0 12px; flex: none; }
#msEditBtn { justify-self: center; }
.sheet-foot { display: flex; justify-content: flex-end; padding: 18px 0 18px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px;
  box-shadow: var(--shadow); z-index: 100; max-width: calc(100vw - 32px);
}

.mobile-only { display: none !important; }

/* 平板：收起侧栏 */
@media (max-width: 1100px) {
  .app { grid-template-columns: minmax(300px, 380px) 1fr; }
  .sidebar { display: none; }
  .mobile-only { display: flex !important; }
  .icon-btn.mobile-only { display: inline-grid !important; }
}

/* 手机：列表全屏，阅读页覆盖 */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .list-pane { border-right: 0; }
  .reader {
    position: fixed; inset: 0; z-index: 20; transform: translateX(100%); visibility: hidden;
    transition: transform .22s ease, visibility 0s linear .22s;
  }
  .app.reading .reader { transform: none; visibility: visible; transition: transform .22s ease; }
  .reader-nav { display: flex; }
  .reader-head { padding-left: 16px; padding-right: 16px; }
  .atts { padding-left: 16px; padding-right: 16px; }
  .frame-wrap { padding: 8px 0 calc(24px + var(--safe-bottom)); }
  .frame-wrap .mail-frame { border-radius: 0; }
  .sheet { width: 100vw; max-width: 100vw; max-height: 92vh; margin: auto 0 0; border-radius: 18px 18px 0 0; }
  .sheet > * { margin-left: 16px; margin-right: 16px; }
  .sheet h4 { margin-left: 16px; }
  .sheet-foot { padding-bottom: calc(18px + var(--safe-bottom)); }
}
