:root {
  --bg: #0c0f14;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-strong: rgba(255, 255, 255, 0.1);
  --line: rgba(255, 255, 255, 0.12);
  --fg: #eef2f7;
  --dim: #9aa6b2;
  --accent: #6ea8fe;
  --danger: #ff7a7a;
  --ok: #6ee7a8;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1000px 600px at 15% -10%, rgba(110, 168, 254, 0.22), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(160, 120, 255, 0.16), transparent 55%),
    var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", system-ui, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px calc(14px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand { font-weight: 700; letter-spacing: 0.02em; }
.topbar a { color: var(--dim); text-decoration: none; font-size: 14px; }
.topbar a:hover { color: var(--fg); }

.app {
  display: grid;
  gap: 14px;
  padding: 14px;
  max-width: 1180px;
  margin: 0 auto;
}

@media (min-width: 900px) {
  .app { grid-template-columns: 300px minmax(0, 1fr); padding: 18px; align-items: start; }
  .inboxes { position: sticky; top: 76px; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  backdrop-filter: blur(14px);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.panel-head h2 { font-size: 15px; margin: 0; color: var(--dim); font-weight: 600; }

h2, h3 { margin: 0; }

button {
  font: inherit;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--fg);
  padding: 8px 12px;
  cursor: pointer;
  transition: transform 0.06s ease, background 0.15s ease;
}

button:hover { background: rgba(255, 255, 255, 0.16); }
button:active { transform: scale(0.98); }
button.primary { background: rgba(110, 168, 254, 0.22); border-color: rgba(110, 168, 254, 0.5); }
button.ghost { background: transparent; }
button.danger { color: var(--danger); border-color: rgba(255, 122, 122, 0.4); background: transparent; }

input {
  font: inherit;
  width: 100%;
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
  color: var(--fg);
}

input:focus { outline: 2px solid rgba(110, 168, 254, 0.55); outline-offset: 1px; }

.row { display: flex; gap: 8px; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.create { display: grid; gap: 8px; margin-bottom: 12px; }

.inbox-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }

.inbox-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 11px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  font-size: 14px;
}

.inbox-item:hover { border-color: var(--line); }
.inbox-item.active { background: rgba(110, 168, 254, 0.16); border-color: rgba(110, 168, 254, 0.45); }
.inbox-item .lp { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  min-width: 22px;
  text-align: center;
  font-size: 12px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(110, 168, 254, 0.3);
  color: #fff;
}

.inbox-head {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}

.address { font-size: clamp(15px, 3.4vw, 20px); font-weight: 650; word-break: break-all; }
.meta { color: var(--dim); font-size: 12.5px; margin: 4px 0 0; }
.hint { color: var(--dim); font-size: 13px; margin: 8px 0 0; }
.empty { padding: 26px 6px; text-align: center; }
.empty h2 { font-size: 17px; margin-bottom: 6px; }
.empty p { color: var(--dim); font-size: 14px; margin: 0; }

.split { display: grid; gap: 12px; }

@media (min-width: 760px) {
  .split { grid-template-columns: 310px minmax(0, 1fr); align-items: start; }
}

.msg-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  max-height: 62vh;
  overflow: auto;
}

.msg-item {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 11px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
}

.msg-item:hover { border-color: var(--line); }
.msg-item.active { background: rgba(110, 168, 254, 0.16); border-color: rgba(110, 168, 254, 0.45); }
.msg-item .from { font-size: 12.5px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-item .subject { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-item .time { font-size: 11.5px; color: var(--dim); }

.msg-detail {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  background: rgba(0, 0, 0, 0.22);
  min-height: 220px;
}

.detail-head h3 { font-size: 16px; margin-bottom: 4px; word-break: break-word; }

.text-body {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  margin: 12px 0 0;
  max-height: 58vh;
  overflow: auto;
}

.html-body {
  width: 100%;
  height: 56vh;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-top: 12px;
  background: #fff;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(20, 24, 32, 0.92);
  border: 1px solid var(--line);
  font-size: 13.5px;
  z-index: 20;
  max-width: min(92vw, 460px);
  text-align: center;
}

.toast[data-kind="ok"] { border-color: rgba(110, 231, 168, 0.5); color: var(--ok); }
.toast[data-kind="error"] { border-color: rgba(255, 122, 122, 0.5); color: var(--danger); }

/* legacy pages: gate.html / login.html / admin */
.layout { display: grid; gap: 14px; padding: 18px; max-width: 780px; margin: 0 auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.err { color: var(--danger); font-size: 13px; }
#messages { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
#messages li button { width: 100%; text-align: left; }
pre { overflow: auto; }
