:root {
  --bg: #f5f6f8;
  --panel: #fff;
  --line: #e3e5ea;
  --text: #1f2328;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --danger: #c0352b;
  --radius: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
input, textarea, button, select { font: inherit; color: inherit; }
input, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}
input:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; min-height: 240px; }
button, .btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
button:hover, .btn:hover { background: #f0f1f4; }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.primary:hover { background: #1d4fd0; }
.danger { color: var(--danger); }
.muted { color: var(--muted); }
.error-text { color: var(--danger); }
.center { padding: 48px 16px; text-align: center; }
.grow { flex: 1; }

/* 登录 / 初始化 */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.auth { max-width: 380px; margin: 10vh auto; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.auth h1 { margin: 0; font-size: 20px; }
.auth p { margin: 0; }
label { display: flex; flex-direction: column; gap: 4px; }
.addr { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.addr input { border: 0; outline: 0; }
.addr span { padding: 0 10px; color: var(--muted); white-space: nowrap; }

/* 主布局 */
.layout { display: flex; height: 100vh; }
.side {
  width: 220px; flex-shrink: 0; display: flex; flex-direction: column; gap: 12px;
  padding: 16px 12px; background: var(--panel); border-right: 1px solid var(--line);
}
.brand { font-weight: 600; font-size: 16px; padding: 0 8px; }
.compose { justify-content: center; padding: 8px; }
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
nav a { display: flex; justify-content: space-between; padding: 7px 10px; border-radius: 6px; color: var(--text); }
nav a:hover { background: #f0f1f4; }
nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.badge { background: var(--accent); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 12px; line-height: 20px; }
.me { font-size: 13px; color: var(--muted); padding: 0 8px; }
.me-addr { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.main { flex: 1; overflow: auto; padding: 16px 24px; min-width: 0; }

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar h2 { margin: 0 12px 0 0; font-size: 18px; }
.search { flex: 1; min-width: 160px; max-width: 360px; }

/* 列表 */
.list { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row {
  display: grid; grid-template-columns: 200px 1fr auto; gap: 12px; align-items: baseline;
  padding: 10px 14px; border-bottom: 1px solid var(--line); color: var(--text);
}
.row:last-child { border-bottom: 0; }
.row:hover { background: #f8f9fb; }
.row.unread { font-weight: 600; }
.row.unread .who::before { content: "●"; color: var(--accent); margin-right: 6px; font-size: 10px; }
.who, .subj { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.snip { color: var(--muted); font-weight: 400; margin-left: 8px; }
.date { color: var(--muted); font-size: 13px; font-weight: 400; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; padding: 12px; }

/* 阅读 */
.msg { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.msg h2 { margin: 0 0 12px; font-size: 20px; }
.meta { color: var(--text); font-size: 13px; display: grid; gap: 2px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.meta b { color: var(--muted); font-weight: 400; }
.atts { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.att { padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--text); }
.body { padding-top: 12px; }
.body iframe { width: 100%; height: 70vh; border: 0; background: #fff; }
.body pre { white-space: pre-wrap; word-wrap: break-word; font: inherit; margin: 0; }

/* 写信 */
.compose-form { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; display: flex; flex-direction: column; gap: 8px; }
.line { flex-direction: row; align-items: center; gap: 10px; }
.line span { width: 52px; color: var(--muted); flex-shrink: 0; }
.compose-bottom { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.warn { background: #fff7e6; border: 1px solid #f5d58a; border-radius: 6px; padding: 8px 12px; }

/* 设置 / 管理 */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; margin-bottom: 16px; }
.stack { display: flex; flex-direction: column; gap: 10px; max-width: 360px; }
.stack h3 { margin: 8px 0 0; font-size: 15px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-form > * { width: auto; flex: 1 1 160px; }
.inline-form .addr { flex: 2 1 240px; }
.inline-form button, .inline-form .check { flex: 0 0 auto; }
.check { flex-direction: row; align-items: center; gap: 6px; }
.check input { width: auto; }
.users { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.users th, .users td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.users th { color: var(--muted); font-weight: 500; font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.actions button { padding: 3px 8px; font-size: 13px; }
.tag { font-size: 12px; background: var(--accent-soft); color: var(--accent); padding: 1px 6px; border-radius: 4px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #1f2328; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 10;
  box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 90vw;
}
.toast.error { background: var(--danger); }

/* 手机 */
@media (max-width: 760px) {
  .layout { flex-direction: column; height: auto; min-height: 100vh; }
  .side { width: auto; border-right: 0; border-bottom: 1px solid var(--line); flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px; }
  nav { flex-direction: row; flex-wrap: wrap; flex: 1 1 100%; order: 3; }
  .me { order: 2; margin-left: auto; }
  .main { padding: 12px; }
  .row { grid-template-columns: 1fr auto; }
  .row .subj { grid-column: 1 / -1; }
  .users, .users tbody, .users tr, .users td { display: block; }
  .users thead { display: none; }
  .users td { border: 0; padding: 4px 12px; }
  .users tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
}
