:root {
  --primary: #1a73e8;
  --primary-d: #1559b8;
  --ink: #1f2329;
  --ink-2: #5b6470;
  --muted: #9098a3;
  --line: #ececf0;
  --bg: #ffffff;
  --bg-soft: #f4f5f7;
  --unread: #1a73e8;
  --danger: #e0483d;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg-soft);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.45;
}
#app { max-width: 560px; margin: 0 auto; min-height: 100%; background: var(--bg); position: relative; }
.view { min-height: 100vh; }
[hidden] { display: none !important; }
b { font-weight: 600; }
button { font-family: inherit; }

/* ===================== Login ===================== */
.view-login {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
  background: linear-gradient(160deg, #1a73e8 0%, #155ec0 48%, #0d3f86 100%);
}
.login-wrap { width: 100%; max-width: 360px; text-align: center; color: #fff; }
.login-logo {
  width: 72px; height: 72px; margin: 0 auto 16px; border-radius: 20px;
  background: rgba(255,255,255,.16); backdrop-filter: blur(8px);
  display: grid; place-items: center; font-size: 36px;
  box-shadow: 0 8px 30px rgba(0,0,0,.18);
}
.login-title { font-size: 27px; font-weight: 700; margin: 0; letter-spacing: .5px; }
.login-sub { margin: 6px 0 28px; opacity: .85; font-size: 14px; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.field {
  display: flex; align-items: center; background: #fff; border-radius: 14px;
  overflow: hidden; box-shadow: 0 4px 18px rgba(0,0,0,.12);
}
.field-input {
  flex: 1; min-width: 0; border: 0; outline: none; background: transparent;
  padding: 15px 16px; font-size: 16px; color: var(--ink);
}
.field-suffix { padding: 0 14px 0 0; color: var(--muted); font-size: 14px; white-space: nowrap; }
.login-btn {
  margin-top: 8px; border: 0; border-radius: 14px; padding: 15px;
  background: #fff; color: var(--primary); font-size: 17px; font-weight: 700;
  letter-spacing: 4px; cursor: pointer; box-shadow: 0 4px 18px rgba(0,0,0,.12);
  transition: transform .05s ease, opacity .15s;
}
.login-btn:active { transform: scale(.99); }
.login-btn:disabled { opacity: .6; }
.login-error { margin: 4px 0 0; color: #ffd7d2; font-size: 13.5px; min-height: 1em; }
.login-foot { margin-top: 26px; font-size: 12.5px; opacity: .8; line-height: 1.6; }
.login-foot b { font-weight: 700; }

/* ===================== App bar ===================== */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(var(--safe-top) + 10px) 14px 10px;
  background: rgba(255,255,255,.86);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.appbar-lead { flex: 1; min-width: 0; }
.appbar-title { margin: 0; font-size: 21px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.title-badge {
  font-size: 12px; font-weight: 700; color: #fff; background: var(--unread);
  border-radius: 999px; padding: 1px 8px; min-width: 20px; text-align: center;
}
.appbar-addr {
  font-size: 12.5px; color: var(--muted); margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.appbar-actions { display: flex; align-items: center; gap: 6px; }
.iconbtn {
  width: 38px; height: 38px; border: 0; background: transparent; color: var(--ink-2);
  border-radius: 50%; display: grid; place-items: center; cursor: pointer;
}
.iconbtn:active { background: var(--bg-soft); }
.iconbtn.back { margin-left: -8px; color: var(--primary); }
.avatarbtn { border: 0; background: transparent; padding: 0; cursor: pointer; }
#me-avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--primary); color: #fff; font-weight: 700; font-size: 15px;
}
.appbar-detail { gap: 6px; }
.appbar-title-sm { flex: 1; text-align: center; margin: 0; font-size: 16px; font-weight: 600; }
.appbar-spacer { width: 38px; }

/* account popover */
.popover {
  position: absolute; top: calc(var(--safe-top) + 54px); right: 12px; z-index: 30;
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 10px 36px rgba(16,24,40,.16); width: 240px; overflow: hidden;
  animation: pop .12s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(-6px); } }
.popover-head { display: flex; align-items: center; gap: 10px; padding: 14px; border-bottom: 1px solid var(--line); }
.popover-addr { font-size: 13.5px; font-weight: 600; word-break: break-all; }
.popover-item {
  width: 100%; text-align: left; border: 0; background: #fff; padding: 14px;
  font-size: 15px; color: var(--danger); cursor: pointer;
}
.popover-item:active { background: var(--bg-soft); }

/* ===================== Search ===================== */
.searchbar { position: relative; padding: 8px 14px 10px; background: #fff; border-bottom: 1px solid var(--line); }
.search-ic { position: absolute; left: 26px; top: 50%; transform: translateY(-50%); color: var(--muted); display: grid; }
.search-input {
  width: 100%; border: 0; background: var(--bg-soft); border-radius: 11px;
  padding: 10px 12px 10px 38px; font-size: 15px; outline: none; color: var(--ink);
}
.search-input::placeholder { color: var(--muted); }

/* ===================== Message list ===================== */
.mlist { list-style: none; margin: 0; padding: 0; }
.mitem {
  display: flex; gap: 12px; padding: 13px 14px; border-bottom: 1px solid var(--line);
  cursor: pointer; align-items: flex-start;
}
.mitem:active { background: var(--bg-soft); }
.avatar {
  flex-shrink: 0; width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 17px;
  text-transform: uppercase;
}
.avatar.lg { width: 46px; height: 46px; font-size: 19px; }
.mitem-body { flex: 1; min-width: 0; }
.mitem-top { display: flex; align-items: baseline; gap: 8px; }
.mitem-from { flex: 1; min-width: 0; font-size: 15.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.mitem-time { flex-shrink: 0; font-size: 12px; color: var(--muted); }
.mitem-subj {
  margin-top: 2px; font-size: 14px; color: var(--ink-2);
  overflow: hidden; white-space: nowrap; display: flex; align-items: center; gap: 6px;
}
.mitem-subj .ell { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mitem-prev {
  margin-top: 2px; font-size: 13px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mitem .dot { flex-shrink: 0; width: 9px; height: 9px; border-radius: 50%; background: var(--unread); }
.mitem .clip { flex-shrink: 0; color: var(--muted); font-size: 12px; }
.mitem.unread .mitem-from { font-weight: 700; }
.mitem.unread .mitem-subj { color: var(--ink); font-weight: 600; }

/* states */
.state { text-align: center; padding: 70px 30px; color: var(--muted); }
.empty-ic { font-size: 48px; }
.empty-title { font-size: 16px; color: var(--ink-2); margin: 14px 0 6px; font-weight: 600; }
.empty-sub { font-size: 13px; line-height: 1.7; }
.spinner {
  display: inline-block; width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--primary); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===================== Detail ===================== */
.detail { padding: 16px 16px calc(var(--safe-bottom) + 40px); }
.detail-subject { font-size: 21px; line-height: 1.35; font-weight: 700; margin: 6px 0 18px; }
.sender-row { display: flex; align-items: center; gap: 12px; }
.sender-info { flex: 1; min-width: 0; }
.sender-name { font-size: 15.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sender-addr { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-time { flex-shrink: 0; font-size: 12.5px; color: var(--muted); align-self: flex-start; padding-top: 2px; }
.detail-to { margin: 14px 0 0; font-size: 13px; color: var(--muted); }
.detail-to b { color: var(--ink-2); font-weight: 600; }

.attachments { margin-top: 16px; display: flex; flex-wrap: wrap; gap: 8px; }
.att {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%;
  padding: 9px 12px; background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 11px; text-decoration: none; color: var(--ink);
}
.att-ic { font-size: 16px; }
.att-name { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.att-size { font-size: 11.5px; color: var(--muted); flex-shrink: 0; }

.mbody {
  margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line);
}
.text-body { white-space: pre-wrap; word-break: break-word; font-family: inherit; font-size: 15px; line-height: 1.6; margin: 0; color: var(--ink); }
.html-frame { width: 100%; min-height: 200px; border: 0; background: #fff; }
