:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --border: #e6e8ec;
  --border-strong: #d4d8de;
  --text: #14171c;
  --muted: #6b7280;
  --faint: #9aa1ac;
  --accent: #2563eb;
  --accent-soft: #eef4ff;
  --accent-line: #c7dbff;
  --green: #16a34a;
  --radius: 14px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

.hidden { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; }

.logo {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.5px;
}

.brand-name { font-weight: 600; letter-spacing: -0.2px; }

.brand-domain {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
}

.ttl { font-size: 12px; color: var(--faint); }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px 24px 24px;
  align-items: stretch;
  min-height: calc(100vh - 113px);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

/* ---------- side ---------- */
.side { padding: 18px; }

.side-block + .side-block { margin-top: 22px; }

.label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 8px;
}

.addr-row { display: flex; gap: 8px; }

.addr-input {
  flex: 1;
  min-width: 0;
  font-family: var(--mono);
  font-size: 13px;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.addr-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.addr-actions { display: flex; gap: 8px; margin-top: 10px; }

.btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  padding: 8px 14px;
  border-radius: 9px;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}

.btn:hover { background: #f9fafb; border-color: #c3c8d0; }
.btn:active { transform: translateY(0.5px); }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  flex: 1;
}

.btn.primary:hover { background: #1d4fd8; border-color: #1d4fd8; }

.btn.ghost { background: transparent; }
.btn.small { padding: 6px 11px; font-size: 12px; }
.btn.icon { padding: 8px 11px; font-size: 14px; line-height: 1; color: var(--muted); }

.link {
  appearance: none;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
}

.link:hover { color: var(--accent); }

.recent-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.recent-head .label { margin-bottom: 0; }

.recent-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 260px;
  overflow-y: auto;
}

.recent-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 7px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  transition: background .12s, color .12s;
}

.recent-item:hover { background: var(--bg); color: var(--text); }
.recent-item.active { background: var(--accent-soft); color: var(--accent); }

.recent-item .rname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.side-foot {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  color: var(--faint);
  font-size: 12px;
}

.side-foot p { margin: 0 0 4px; }
.side-foot strong { color: var(--muted); font-weight: 500; }

/* ---------- inbox ---------- */
.inbox {
  min-height: 460px;
  display: flex;
  flex-direction: column;
}

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

.inbox-title-wrap { min-width: 0; }

.inbox-head h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meta {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--faint);
}

.inbox-tools { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.live {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border-strong);
  display: inline-block;
  transition: background .2s;
}

.live.on {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, .12);
}

/* ---------- message list ---------- */
.msg-list { flex: 1; overflow-y: auto; }

.msg-row {
  display: flex;
  gap: 12px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .12s;
}

.msg-row:hover { background: #fafbfc; }
.msg-row:last-child { border-bottom: none; }

.msg-avatar {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  flex-shrink: 0;
  text-transform: uppercase;
}

.msg-body { flex: 1; min-width: 0; }

.msg-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.msg-from {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-time { font-size: 11px; color: var(--faint); flex-shrink: 0; font-variant-numeric: tabular-nums; }

.msg-subject {
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 1px;
}

.msg-code {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: 5px;
  padding: 1px 6px;
  margin-top: 4px;
  letter-spacing: 0.5px;
}

/* ---------- empty ---------- */
.empty {
  padding: 72px 24px;
  text-align: center;
  color: var(--faint);
}

.empty-mark {
  font-size: 30px;
  color: var(--border-strong);
  margin-bottom: 8px;
  line-height: 1;
}

.empty p { margin: 0; font-size: 13px; }

/* ---------- detail ---------- */
.msg-detail {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.msg-detail.hidden { display: none; }

.detail-head {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.back-btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: #fff;
  border-radius: 7px;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  cursor: pointer;
  color: var(--muted);
  flex-shrink: 0;
  font-size: 14px;
  line-height: 1;
}

.back-btn:hover { background: var(--bg); }

.detail-info { flex: 1; min-width: 0; }

.detail-subject {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 3px;
  word-break: break-word;
}

.detail-from {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
  word-break: break-all;
}

.detail-code-bar {
  padding: 10px 18px;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--accent-line);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--accent);
}

.detail-code-bar strong {
  font-family: var(--mono);
  font-size: 15px;
  letter-spacing: 1px;
}

.mail-frame {
  flex: 1;
  width: 100%;
  min-height: 380px;
  border: none;
  background: #fff;
}

.mail-text {
  flex: 1;
  margin: 0;
  padding: 18px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: auto;
  color: #333;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(8px);
  background: #14171c;
  color: #fff;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 9px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
  z-index: 100;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- turnstile ---------- */
.turnstile {
  margin-top: 12px;
  min-height: 0;
}

.turnstile:empty { display: none; }

.ts-fail {
  font-size: 12px;
  color: #b45309;
  margin-bottom: 6px;
}

/* ---------- attachment badge ---------- */
.msg-att {
  display: inline-block;
  font-size: 11px;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
  margin-top: 4px;
  margin-left: 6px;
}

/* ---------- attachment list ---------- */
.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}

.att-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-decoration: none;
  max-width: 100%;
  transition: border-color .15s, background .15s;
}

.att-item:hover { border-color: var(--accent); background: var(--accent-soft); }
.att-item.disabled { color: var(--faint); background: var(--bg); cursor: default; }
.att-item.disabled:hover { border-color: var(--border-strong); background: var(--bg); }

.att-name {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.att-size { color: var(--faint); font-variant-numeric: tabular-nums; }
.att-note { color: #b45309; font-size: 11px; }

/* ---------- responsive ---------- */
@media (max-width: 880px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 12px;
  }
  .topbar { padding: 12px 16px; }
  .brand-domain { display: none; }
  .inbox { min-height: 380px; }
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #d8dce2; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #c2c8d0; }
::-webkit-scrollbar-track { background: transparent; }
