:root {
  --bg: #f4f6fa; --panel: #ffffff; --side: #eef1f7; --line: #e2e6ee;
  --text: #1d2433; --muted: #6b7489; --accent: #3b6cf6; --accent-weak: #e6edff;
  --danger: #d64545; --unread: #1d2433;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c; --panel: #181c25; --side: #141821; --line: #262c38;
    --text: #e5e8ef; --muted: #8b93a7; --accent: #6b8fff; --accent-weak: #22305a;
    --danger: #ff6b6b; --unread: #ffffff;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.err { color: var(--danger); font-size: 13px; min-height: 1em; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; font-family: inherit; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  cursor: pointer; font: inherit; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.icon-btn { border: none; background: transparent; color: var(--muted); font-size: 18px; cursor: pointer;
  width: 32px; height: 32px; border-radius: 8px; }
.icon-btn:hover { background: var(--accent-weak); color: var(--accent); }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.end { justify-content: flex-end; }

/* login */
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 32px;
  width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0 0 8px; }
.logo { width: 52px; height: 52px; margin: 0 auto; border-radius: 14px; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 26px; }
.logo.sm { width: 26px; height: 26px; font-size: 14px; border-radius: 7px; margin: 0; display: inline-flex; }

/* layout */
.app { display: grid; grid-template-columns: 260px 360px 1fr; height: 100vh; }
.sidebar { background: var(--side); border-right: 1px solid var(--line); padding: 16px 12px; display: flex;
  flex-direction: column; gap: 10px; overflow-y: auto; }
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; padding: 0 4px 6px; }
.folders { display: flex; flex-direction: column; gap: 2px; }
.folder, .mb { text-align: left; border: none; background: transparent; color: var(--text); padding: 8px 10px;
  border-radius: 8px; cursor: pointer; font: inherit; display: flex; align-items: center; gap: 6px; width: 100%; }
.folder:hover, .mb:hover { background: var(--accent-weak); }
.folder.active, .mb.active { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.section-head { display: flex; align-items: center; justify-content: space-between; color: var(--muted);
  font-size: 12px; padding: 8px 4px 0; text-transform: uppercase; letter-spacing: .04em; }
.mailboxes { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.mb .addr { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mb .note { display: block; font-size: 11px; color: var(--muted); font-weight: 400; }
.mb .badge { background: var(--accent); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 7px; }
.mb .x { opacity: 0; color: var(--muted); border: none; background: none; cursor: pointer; font-size: 13px; padding: 0 2px; }
.mb .copy { opacity: 0; color: var(--muted); border: none; background: none; cursor: pointer; font-size: 12px; padding: 0 2px; }
.mb:hover .x, .mb:hover .copy { opacity: 1; }
.new-mb { display: flex; flex-direction: column; gap: 6px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px; }
.new-mb .at { color: var(--muted); padding-right: 6px; }

.list { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; background: var(--panel); }
.list-head { display: flex; align-items: center; gap: 6px; padding: 12px 12px 6px; }
.list-title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search { margin: 0 12px 8px; width: auto; }
.messages { overflow-y: auto; flex: 1; }
.item { padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.item:hover { background: var(--bg); }
.item.active { background: var(--accent-weak); }
.item .top { display: flex; gap: 8px; align-items: baseline; }
.item .from { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.item .subj, .item .prev { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .prev { color: var(--muted); font-size: 12px; }
.item .to { color: var(--accent); font-size: 11px; }
.item.unread .from, .item.unread .subj { font-weight: 700; color: var(--unread); }
.item.unread { border-left: 3px solid var(--accent); }
.more { padding: 12px; text-align: center; }
.list-empty { padding: 40px 16px; text-align: center; color: var(--muted); }

.reader { overflow-y: auto; min-width: 0; display: flex; flex-direction: column; }
.empty { margin: auto; color: var(--muted); }
.msg { padding: 16px 24px 24px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.msg-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.msg h2 { margin: 6px 0 0; font-size: 20px; word-break: break-word; }
.meta { display: flex; flex-direction: column; gap: 2px; padding-bottom: 10px; border-bottom: 1px solid var(--line); word-break: break-all; }
.atts { display: flex; flex-wrap: wrap; gap: 6px; }
.atts a { font-size: 12px; }
.body-frame { width: 100%; flex: 1; min-height: max(400px, calc(100vh - 260px)); border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.body-text { white-space: pre-wrap; word-break: break-word; font-family: inherit; margin: 0; }
.body-text a { color: var(--accent); }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.modal-card { background: var(--panel); border-radius: 14px; padding: 18px; width: 100%; max-width: 680px;
  max-height: 100%; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-card label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.modal-card label.inline { flex-direction: row; align-items: center; gap: 6px; }
.modal-card label.inline input { width: auto; }
.modal-card label.btn { flex-direction: row; color: var(--text); font-size: 13px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #222; color: #fff;
  padding: 10px 16px; border-radius: 10px; z-index: 20; max-width: calc(100% - 32px); }

.mobile-only { display: none; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .mobile-only { display: inline-block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 5; transform: translateX(-100%); transition: transform .2s; }
  .app.menu-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .reader { display: none; }
  .app.reading .list { display: none; }
  .app.reading .reader { display: flex; }
  .msg { padding: 12px 16px; }
}
