/* ============ 基础 ============ */
:root {
  --bg: #f6f8fc;
  --surface: #ffffff;
  --surface-2: #f2f6fc;
  --primary: #0b57d0;
  --primary-soft: #d3e3fd;
  --text: #1f1f1f;
  --muted: #5f6368;
  --line: #e3e6ea;
  --danger: #d93025;
  --ok: #188038;
  --shadow-1: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
  --shadow-2: 0 4px 12px rgba(60, 64, 67, 0.22), 0 1px 3px rgba(60, 64, 67, 0.18);
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.43 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; }

.hidden { display: none !important; }

/* ============ 登录 / 注册 ============ */
.auth {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-x: hidden;
  background:
    radial-gradient(1200px 600px at 15% -10%, #e8f0fe 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 10%, #e6f4ea 0%, transparent 55%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  min-width: 0;
  flex: 0 1 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 32px;
  box-shadow: var(--shadow-2);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.auth-logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #0b57d0, #3b82f6);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 17px;
}

.auth-brand b { font-size: 19px; font-weight: 500; letter-spacing: 0.2px; }

.auth h2 {
  margin: 18px 0 6px;
  font-size: 24px;
  font-weight: 400;
  letter-spacing: -0.2px;
}

.auth p.sub { margin: 0 0 22px; color: var(--muted); font-size: 14px; }

.field {
  display: block;
  margin-bottom: 14px;
}

.field > span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.input {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid #c4c7c5;
  border-radius: 10px;
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(11, 87, 208, 0.12);
}

.input-row {
  display: flex;
  align-items: center;
  border: 1px solid #c4c7c5;
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input-row:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(11, 87, 208, 0.12);
}

.input-row input {
  flex: 1;
  border: 0;
  padding: 13px 14px;
  outline: none;
  min-width: 0;
}

.input-row .suffix {
  padding: 0 14px;
  color: var(--muted);
  background: var(--surface-2);
  align-self: stretch;
  display: grid;
  place-items: center;
  font-size: 13px;
  border-left: 1px solid var(--line);
}

.btn {
  width: 100%;
  padding: 13px 18px;
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-weight: 500;
  transition: filter 0.15s, box-shadow 0.15s;
}

.btn:hover { filter: brightness(1.06); box-shadow: var(--shadow-1); }
.btn:disabled { opacity: 0.55; cursor: default; box-shadow: none; filter: none; }

.btn.ghost {
  background: transparent;
  color: var(--primary);
  font-weight: 500;
}

.auth-foot {
  margin-top: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}

.link { color: var(--primary); cursor: pointer; background: none; border: 0; padding: 0; font-size: 13px; }
.link:hover { text-decoration: underline; }

.msg {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  background: #fce8e6;
  color: #b3261e;
}

.msg.ok { background: #e6f4ea; color: #137333; }

.verify-box {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 14px;
  background: var(--surface-2);
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 54px;
}

.verify-box.ok { border-color: #b7e1c4; background: #f0fbf3; color: var(--ok); }

/* ============ 主框架 ============ */
.app {
  height: 100%;
  display: grid;
  grid-template-rows: 64px 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 8px 8px;
  background: var(--bg);
  min-width: 0;
  overflow: hidden;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  display: grid;
  place-items: center;
  color: var(--muted);
  flex: 0 0 auto;
  transition: background 0.15s;
}

.icon-btn:hover { background: rgba(60, 64, 67, 0.08); }
.icon-btn svg { width: 20px; height: 20px; }

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 8px;
  flex: 0 0 auto;
}

.brand .mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, #0b57d0, #3b82f6);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 15px;
}

.brand span { font-size: 20px; color: var(--muted); letter-spacing: -0.2px; }

.searchbar {
  flex: 1 1 0;
  min-width: 0;
  max-width: 720px;
  height: 48px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px 0 6px;
  background: #eaf1fb;
  border-radius: 999px;
  transition: background 0.15s, box-shadow 0.15s;
}

.searchbar:focus-within {
  background: var(--surface);
  box-shadow: var(--shadow-1);
}

.searchbar input {
  flex: 1;
  border: 0;
  outline: none;
  background: transparent;
  font-size: 15px;
  min-width: 0;
}

.searchbar .icon-btn { width: 36px; height: 36px; }

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5b8def, #7b61ff);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 14px;
  flex: 0 0 auto;
  border: 0;
}

.body {
  display: grid;
  grid-template-columns: 256px 1fr;
  min-height: 0;
  padding-right: 16px;
}

/* ============ 侧栏 ============ */
.side {
  padding: 0 8px 16px 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.compose-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 56px;
  padding: 0 22px 0 16px;
  margin: 4px 0 12px 8px;
  border: 0;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-1);
  color: #001d35;
  font-size: 14px;
  font-weight: 500;
  width: fit-content;
  transition: box-shadow 0.15s, background 0.15s;
}

.compose-btn:hover { box-shadow: var(--shadow-2); background: #edf3fe; }
.compose-btn svg { width: 20px; height: 20px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 34px;
  padding: 0 26px 0 26px;
  border: 0;
  border-radius: 0 17px 17px 0;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  text-align: left;
  white-space: nowrap;
  width: 100%;
}

.nav-item:hover { background: #eaebef; }
.nav-item.active { background: var(--primary-soft); font-weight: 700; color: #041e49; }
.nav-item .n { margin-left: auto; font-size: 12px; color: var(--muted); }
.nav-item.active .n { color: #041e49; }

.nav-title {
  padding: 14px 26px 6px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.3px;
}

.side hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 10px 16px;
}

/* ============ 列表 ============ */
.main {
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-bottom: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  min-height: 48px;
}

.toolbar .spacer { flex: 1; }

.chip {
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 13px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chip:hover { background: var(--surface-2); }

.list { flex: 1; overflow-y: auto; }

.mail {
  display: grid;
  grid-template-columns: 32px 32px minmax(120px, 200px) 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 0 16px 0 8px;
  height: 40px;
  border-bottom: 1px solid #f1f3f4;
  cursor: pointer;
  font-size: 14px;
  position: relative;
}

.mail:hover { background: var(--surface-2); box-shadow: inset 1px 0 0 #dadce0, inset -1px 0 0 #dadce0; z-index: 1; }
.mail.unread { background: #fff; font-weight: 700; }
.mail.unread:hover { background: var(--surface-2); }

.mail .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail .subj { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.mail.unread .subj { color: var(--text); }
.mail .subj .snip { color: var(--muted); font-weight: 400; }

.mail .when {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  padding-left: 12px;
}

.mail .star, .mail .check {
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: none;
  display: grid;
  place-items: center;
  color: #c4c7c5;
}

.mail .star:hover, .mail .check:hover { background: rgba(60, 64, 67, 0.1); }
.mail .star.on { color: #f9ab00; }

.empty-state {
  margin: 64px auto;
  max-width: 340px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.empty-state .big { font-size: 40px; margin-bottom: 12px; opacity: 0.5; }

/* ============ 阅读页 ============ */
.reader {
  position: fixed;
  inset: 64px 16px 0 272px;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  border: 1px solid var(--line);
  border-bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 20;
  overflow: hidden;
}

.reader-head {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}

.reader-title {
  padding: 18px 32px 0;
  font-size: 22px;
  font-weight: 400;
  line-height: 1.3;
}

.reader-meta {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 32px;
  border-bottom: 1px solid #f1f3f4;
}

.reader-meta .who-line { flex: 1; min-width: 0; }
.reader-meta .who-line b { font-weight: 700; }
.reader-meta .who-line .addr { color: var(--muted); font-size: 13px; }
.reader-meta .date { color: var(--muted); font-size: 12px; white-space: nowrap; }

.reader-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 32px 32px;
  line-height: 1.65;
  word-break: break-word;
}

.reader-body pre {
  white-space: pre-wrap;
  font: inherit;
  margin: 0;
}

.otp-card {
  margin: 16px 0;
  padding: 16px 20px;
  border: 1px solid #c6dafc;
  background: #f3f8ff;
  border-radius: 14px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.otp-card .code {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 6px;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.reader-actions {
  display: flex;
  gap: 10px;
  padding: 16px 32px 24px;
}

.btn2 {
  height: 38px;
  padding: 0 20px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn2:hover { background: var(--surface-2); }
.btn2.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn2.primary:hover { filter: brightness(1.06); }
.btn2.danger { color: var(--danger); }

/* ============ 写信 ============ */
.compose {
  position: fixed;
  right: 24px;
  bottom: 0;
  width: 560px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 100px);
  background: var(--surface);
  border-radius: 12px 12px 0 0;
  box-shadow: var(--shadow-2);
  display: flex;
  flex-direction: column;
  z-index: 40;
  overflow: hidden;
}

.compose-head {
  height: 44px;
  background: #f2f6fc;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 0 16px;
  font-weight: 500;
  font-size: 14px;
  color: #041e49;
}

.compose .row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  min-height: 46px;
}

.compose .row input {
  flex: 1;
  border: 0;
  outline: none;
  background: none;
  font-size: 14px;
  min-width: 0;
}

.compose textarea {
  flex: 1;
  border: 0;
  outline: none;
  resize: none;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.6;
}

.compose-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}

.compose-foot .send {
  height: 36px;
  padding: 0 24px;
  border-radius: 999px;
  border: 0;
  background: var(--primary);
  color: #fff;
  font-weight: 500;
}

.compose-foot .send:disabled { opacity: 0.55; }
.compose-foot .hint { font-size: 12px; color: var(--muted); }

/* ============ 设置 ============ */
.sheet {
  position: fixed;
  inset: 0;
  background: rgba(32, 33, 36, 0.5);
  display: grid;
  place-items: center;
  z-index: 60;
  padding: 24px;
}

.sheet-card {
  width: 100%;
  max-width: 560px;
  max-height: 82vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 24px;
  padding: 24px 28px 28px;
  box-shadow: var(--shadow-2);
}

.sheet-card h3 { margin: 0 0 4px; font-size: 20px; font-weight: 500; }
.sheet-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }

.kv {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #f1f3f4;
  font-size: 14px;
}

.kv span:first-child { color: var(--muted); }
.kv b { font-weight: 500; }

.addr-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid #f1f3f4;
  font-size: 14px;
}

.addr-item .tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: #041e49;
  margin-left: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  background: #202124;
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 100;
  box-shadow: var(--shadow-2);
  max-width: 90vw;
}

/* ============ 响应式 ============ */
@media (max-width: 1000px) {
  .body { grid-template-columns: 72px 1fr; padding-right: 8px; }
  .side { padding-left: 4px; }
  .compose-btn { width: 56px; padding: 0; justify-content: center; margin-left: 4px; }
  .compose-btn span { display: none; }
  .nav-item { padding: 0 0 0 18px; gap: 10px; font-size: 13px; }
  .nav-item .txt, .nav-item .n { display: none; }
  .nav-title { display: none; }
  .reader { inset: 64px 8px 0 80px; }
}

@media (max-width: 720px) {
  .app { grid-template-rows: 56px 1fr; }
  .body { grid-template-columns: 1fr; padding: 0; }
  .side { display: none; }
  .topbar { padding: 4px 8px; gap: 2px; }
  .brand span { display: none; }
  .searchbar { height: 42px; }
  .main { border-radius: 0; border: 0; }
  .mail {
    grid-template-columns: 32px 1fr auto;
    height: auto;
    min-height: 64px;
    padding: 8px 12px 8px 4px;
    gap: 4px 8px;
  }
  .mail .check { display: none; }
  .mail .who { grid-column: 2; grid-row: 1; }
  .mail .subj { grid-column: 2; grid-row: 2; }
  .mail .when { grid-column: 3; grid-row: 1; padding-left: 4px; font-size: 11px; }
  .mail .star { grid-column: 1; grid-row: 1 / span 2; }
  .reader { inset: 0; border-radius: 0; border: 0; }
  .reader-title { padding: 12px 20px 0; font-size: 19px; }
  .reader-meta { padding: 12px 20px; }
  .reader-body { padding: 4px 20px 24px; }
  .reader-actions { padding: 12px 20px 20px; }
  .compose { right: 0; bottom: 0; width: 100%; height: 100%; max-height: 100%; border-radius: 0; }
  .otp-card .code { font-size: 24px; letter-spacing: 4px; }
}

/* 悬浮按钮（移动端写信） */
.fab {
  position: fixed;
  right: 18px;
  bottom: 22px;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  border: 0;
  background: var(--primary);
  color: #fff;
  display: none;
  place-items: center;
  box-shadow: var(--shadow-2);
  z-index: 30;
}

.fab svg { width: 24px; height: 24px; }

@media (max-width: 720px) {
  .fab { display: grid; }
}

@media (max-width: 480px) {
  .auth { padding: 16px; }
  .auth-card { padding: 24px 20px; border-radius: 22px; }
  .auth h2 { font-size: 22px; }
  .input-row .suffix { padding: 0 10px; font-size: 12px; }
}
@media (max-width: 430px) {
  .brand .mark { width: 26px; height: 26px; font-size: 13px; border-radius: 8px; }
  .topbar { gap: 4px; padding: 4px 6px; }
  .searchbar { padding: 0 4px 0 2px; gap: 2px; }
  .searchbar input { font-size: 14px; }
  #btn-settings { display: none; }
}