:root {
  --ink: #0e1726;
  --ink-2: #3b4658;
  --muted: #7b8597;
  --line: #e3e7ee;
  --bg: #eef1f6;
  --card: #ffffff;
  --hero: #0d1b2a;
  --hero-2: #14304a;
  --accent: #ff5a36;
  --accent-soft: #fff0eb;
  --ok: #16a34a;
  --danger: #d1343e;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(14, 23, 38, .05), 0 12px 32px -12px rgba(14, 23, 38, .18);
  font-family: "Inter", "PingFang SC", "HarmonyOS Sans SC", "Noto Sans SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* 按角色显示：data-role 由服务端写在 <body> 上，首屏就生效；没有角色时一律隐藏 */
body:not([data-role="admin"]):not([data-role="super"]) [data-admin-only],
body:not([data-role="super"]) [data-super-only],
body:not([data-role="user"]) [data-user-only],
body[data-role="user"] .toolbar { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }

.ic {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- hero ---------- */
.hero {
  position: relative;
  background:
    radial-gradient(900px 320px at 85% -10%, rgba(255, 90, 54, .22), transparent 60%),
    radial-gradient(700px 300px at 0% 120%, rgba(80, 150, 255, .18), transparent 60%),
    linear-gradient(160deg, var(--hero), var(--hero-2));
  color: #fff;
  padding: 28px 20px 64px;
}
.hero-inner { max-width: 760px; margin: 0 auto; text-align: center; }
.brand {
  display: inline-flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .02em;
  padding: 6px 12px; border-radius: 999px; background: rgba(255, 255, 255, .08); font-size: 14px;
}
.hero h1 { font-size: clamp(28px, 5vw, 44px); line-height: 1.15; margin: 22px 0 10px; letter-spacing: -.01em; }
.hero h1 span { color: var(--accent); }
.lede { color: rgba(255, 255, 255, .72); margin: 0 auto 28px; max-width: 520px; line-height: 1.6; }

.address {
  background: var(--card); color: var(--ink); text-align: left;
  border-radius: 20px; padding: 18px 18px 14px; box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .5);
}
.address label { display: block; font-size: 12px; font-weight: 600; letter-spacing: .08em; color: var(--muted); margin: 0 4px 10px; }
.address-field {
  display: flex; align-items: center; gap: 8px;
  border: 1.5px solid var(--line); border-radius: 14px; padding: 6px 6px 6px 14px; background: #f8fafc;
  transition: border-color .15s, box-shadow .15s;
}
.address-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(255, 90, 54, .14); background: #fff; }
.address-field .lead { color: var(--muted); }
.address-field input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
  font-size: clamp(16px, 2.6vw, 21px); font-weight: 600; padding: 10px 2px;
  font-family: "JetBrains Mono", "SF Mono", ui-monospace, monospace;
}
.address-field input::placeholder { font-family: inherit; font-weight: 400; font-size: 15px; color: var(--muted); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 10px;
  padding: 10px 14px; background: transparent; color: var(--ink-2); font-weight: 600; white-space: nowrap;
}
.chip:hover { background: #eef2f7; }
.chip.solid { background: var(--accent); color: #fff; }
.chip.solid:hover { filter: brightness(1.05); }
.hint { margin: 10px 4px 0; font-size: 13px; color: var(--muted); text-align: center; }
.hint.error { color: var(--danger); }

/* ---------- toolbar ---------- */
.toolbar {
  display: flex; justify-content: center; flex-wrap: wrap; gap: 10px;
  max-width: 900px; margin: -26px auto 0; padding: 0 20px; position: relative;
}
.pill {
  display: inline-flex; align-items: center; gap: 8px; height: 46px; padding: 0 20px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font-weight: 600; box-shadow: var(--shadow); transition: transform .1s, border-color .15s;
}
.pill:hover:not(:disabled) { border-color: #c9d1dd; transform: translateY(-1px); }
.pill.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.pill.danger { color: var(--danger); }
/* 普通账号没有可见按钮时，工具栏不占位 */
.toolbar:not(:has(> :not([hidden]))) { display: none; }

/* ---------- panel ---------- */
main { max-width: 900px; margin: 24px auto 0; padding: 0 20px; }
.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; min-height: 440px; }
.panel-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 22px; border-bottom: 1px solid var(--line);
}
.panel-title { font-weight: 700; font-size: 17px; }
.count { color: var(--muted); font-weight: 500; font-size: 14px; margin-left: 4px; }
.live { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 rgba(22, 163, 74, .5); animation: pulse 2s infinite; }
.live.off i { background: var(--muted); animation: none; }
.live.err i { background: var(--danger); animation: none; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(22, 163, 74, 0); } 100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); } }

.list { list-style: none; margin: 0; padding: 0; }
.item {
  display: grid; grid-template-columns: 40px 1fr auto; gap: 14px; align-items: center;
  padding: 14px 22px; border-bottom: 1px solid var(--line); cursor: pointer; transition: background .12s;
}
.item:hover { background: #f7f9fc; }
.avatar {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  font-weight: 700; color: #fff; background: var(--hero-2); text-transform: uppercase;
}
.item .main { min-width: 0; }
.item .from { font-size: 14px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .subject { margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.item .time { font-size: 12px; color: var(--muted); white-space: nowrap; }
.item.unread .from, .item.unread .subject { font-weight: 700; color: var(--ink); }
.item.unread .avatar { background: var(--accent); }
.item.fresh { animation: fresh 1.6s ease-out; }
@keyframes fresh { from { background: var(--accent-soft); } to { background: transparent; } }

.empty { text-align: center; padding: 56px 24px 48px; }
.empty-art {
  position: relative; width: 120px; height: 120px; margin: 0 auto 20px; border-radius: 50%;
  display: grid; place-items: center; background: radial-gradient(circle, #fff 55%, var(--accent-soft) 56%);
  color: var(--accent);
}
.empty-art .ic { width: 44px; height: 44px; stroke-width: 1.5; }
.dots { position: absolute; bottom: 14px; display: flex; gap: 4px; }
.dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); opacity: .3; animation: blink 1.4s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 40% { opacity: 1; } }
.empty h3 { margin: 0 0 6px; font-size: 19px; }
.empty p { margin: 0 0 20px; color: var(--muted); }
.tip {
  display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-2);
  background: #f3f5f9; padding: 10px 16px; border-radius: 10px;
}
.tip .ic { color: var(--accent); }

/* ---------- reader ---------- */
#view-reader { display: flex; flex-direction: column; min-height: 520px; }
.reader-bar { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.reader-head { padding: 18px 22px 16px; border-bottom: 1px solid var(--line); }
.reader-head h2 { margin: 0 0 10px; font-size: 20px; line-height: 1.35; word-break: break-word; }
.reader-head .sub { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 14px; color: var(--ink-2); }
.reader-head .sub .time { color: var(--muted); }
.otp {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px;
  background: var(--accent-soft); border: 1px dashed rgba(255, 90, 54, .4); border-radius: 12px; padding: 12px 16px;
}
.otp small { display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 2px; }
.otp code { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 26px; font-weight: 800; letter-spacing: .12em; color: var(--accent); }
.links { margin-top: 12px; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.links a { color: #2563eb; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#view-reader iframe { flex: 1; width: 100%; min-height: 480px; border: 0; background: #fff; }
#view-reader pre { flex: 1; margin: 0; padding: 22px; white-space: pre-wrap; word-break: break-word; font-family: inherit; line-height: 1.6; }

/* ---------- 全部邮箱 ---------- */
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; }
.all-tools { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 12px 22px; border-bottom: 1px solid var(--line); }
.search {
  display: flex; align-items: center; gap: 8px; flex: 1; max-width: 360px;
  border: 1.5px solid var(--line); border-radius: 10px; padding: 8px 12px; background: #f8fafc; color: var(--muted);
}
.search:focus-within { border-color: var(--accent); background: #fff; }
.search input { color: var(--ink); }
.all-stats { font-size: 13px; color: var(--muted); }
.box-item { grid-template-columns: 1fr auto auto; }
.box-item .email, .user-item .email { font-family: "JetBrains Mono", ui-monospace, monospace; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.box-item .created, .user-item .created { font-size: 12px; color: var(--muted); margin-top: 3px; }
.badge {
  font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  background: #f1f4f8; color: var(--muted); white-space: nowrap;
}
.badge.has { background: var(--accent-soft); color: var(--accent); }
.badge.cur { background: #e8f7ee; color: var(--ok); }
.box-item .owner { color: var(--ink-2); }
.create-form { padding: 22px; display: flex; flex-direction: column; gap: 16px; }
.create-row { display: flex; align-items: center; gap: 10px; }
.prefix-field { position: relative; flex: 1; min-width: 0; display: flex; }
.prefix-field input, .create-row select {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; background: #f8fafc; outline: 0;
  font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 16px; font-weight: 600;
}
.prefix-field input { padding-right: 112px; }
.prefix-field input:focus, .create-row select:focus { border-color: var(--accent); background: #fff; }
.prefix-field input:disabled { color: var(--muted); background: #f1f4f8; }
.prefix-field .chip { position: absolute; right: 5px; top: 50%; transform: translateY(-50%); padding: 7px 12px; }
.create-row .at { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 20px; font-weight: 700; color: var(--muted); }
.create-row select { flex: 0 1 280px; width: auto; cursor: pointer; }
.create-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.create-preview { font-family: "JetBrains Mono", ui-monospace, monospace; color: var(--ink-2); word-break: break-all; }
.create-rule { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.create-rule.error { color: var(--danger); }

.user-form {
  display: grid; grid-template-columns: auto 1fr 1.3fr auto; gap: 10px; padding: 14px 22px; border-bottom: 1px solid var(--line);
}
.user-form:has(#new-role[hidden]) { grid-template-columns: 1fr 1.3fr auto; }
.user-form select {
  border: 1.5px solid var(--line); border-radius: 10px; padding: 0 10px; background: #f8fafc; outline: 0; font-weight: 600;
}
.user-form input {
  width: 100%; border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #f8fafc; outline: 0;
}
.user-form input:focus { border-color: var(--accent); background: #fff; }
.pw-field { position: relative; display: flex; }
.pw-field input { padding-right: 76px; font-family: "JetBrains Mono", ui-monospace, monospace; }
.pw-field input::placeholder { font-family: "Inter", system-ui, sans-serif; }
.pw-field .chip { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); padding: 6px 10px; font-size: 13px; }
.user-item { grid-template-columns: 1fr auto auto; cursor: default; }
.user-item:hover { background: transparent; }
.user-actions { display: flex; gap: 4px; min-width: 190px; justify-content: flex-end; }
.chip.danger-text { color: var(--danger); }
.badge.role-super { background: var(--accent-soft); color: var(--accent); }
.badge.role-admin { background: #e8f0fe; color: #2563eb; }

.list .note { padding: 32px 22px; text-align: center; color: var(--muted); }

/* ---------- 账号 ---------- */
.userbar {
  position: absolute; top: 18px; right: 20px; display: flex; align-items: center; gap: 10px;
  font-size: 14px; color: rgba(255, 255, 255, .75);
}
.userbar button {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid rgba(255, 255, 255, .18);
  background: rgba(255, 255, 255, .06); color: #fff; border-radius: 999px; padding: 5px 12px; font-size: 13px;
}
.userbar button:hover { background: rgba(255, 255, 255, .14); }
.userbar .ic { width: 15px; height: 15px; }

.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background:
    radial-gradient(900px 400px at 85% -10%, rgba(255, 90, 54, .2), transparent 60%),
    linear-gradient(160deg, var(--hero), var(--hero-2));
}
.login-card {
  width: 100%; max-width: 360px; background: var(--card); border-radius: 20px; padding: 32px 28px 28px;
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .5); display: flex; flex-direction: column; gap: 16px;
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.login-card input {
  border: 1.5px solid var(--line); border-radius: 10px; padding: 11px 12px; background: #f8fafc; outline: 0; font-size: 15px;
}
.login-card input:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 4px rgba(255, 90, 54, .12); }
.login-card button[type=submit] {
  margin-top: 4px; border: 0; border-radius: 10px; padding: 12px; background: var(--accent); color: #fff; font-weight: 700; font-size: 15px;
}
.login-error { margin: 0; color: var(--danger); font-size: 13px; }

.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 28px 20px 40px; }

.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 10px; font-size: 14px;
  box-shadow: var(--shadow); z-index: 10;
}

@media (max-width: 640px) {
  .hero { padding-top: 60px; padding-bottom: 56px; }
  .address { padding: 14px 12px 12px; }
  .address-field { flex-wrap: wrap; padding: 6px; }
  .address-field .lead { display: none; }
  .address-field input { flex-basis: 100%; padding: 8px; }
  .chip { flex: 1; justify-content: center; background: #eef2f7; }
  .toolbar { gap: 8px; }
  .pill { height: 40px; padding: 0 14px; font-size: 14px; }
  .user-form { grid-template-columns: 1fr; padding: 14px 16px; }
  .create-form { padding: 16px; }
  .create-row { flex-wrap: wrap; }
  .create-row .at { display: none; }
  .create-row select { flex: 1 1 100%; }
  .user-item { grid-template-columns: 1fr auto; }
  .user-actions { grid-column: 1 / -1; justify-content: flex-start; min-width: 0; }
  .item { grid-template-columns: 34px 1fr auto; gap: 10px; padding: 12px 16px; }
  .avatar { width: 34px; height: 34px; border-radius: 10px; }
}
