/* ---------- 主题变量 ---------- */
:root {
  --bg: #f2f4f8;
  --card: #ffffff;
  --text: #1a2233;
  --muted: #68738a;
  --border: #e3e7ef;
  --primary: #3565e0;
  --primary-weak: #e8eefc;
  --danger: #d64545;
  --danger-weak: #fdeeee;
  --ok: #2fa36b;
  --warn: #c77a00;
  --warn-weak: #fdf3dc;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 6px 20px rgba(16, 24, 40, 0.06);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f131b;
    --card: #171d29;
    --text: #e8ecf4;
    --muted: #97a1b8;
    --border: #27303f;
    --primary: #6f8df5;
    --primary-weak: #222b44;
    --danger: #e5636b;
    --danger-weak: #3a2426;
    --warn: #f0a74e;
    --warn-weak: #3a2f1c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
  }
}

/* ---------- 基础 ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
body.modal-open { overflow: hidden; }
button { font: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }
h2, h3 { margin: 0; font-weight: 650; }
.hidden { display: none !important; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 860px; margin: 0 auto; padding: 12px 20px;
  display: flex; align-items: center; justify-content: space-between;
}
.logo { font-size: 18px; font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.conn-status { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; }
.conn-status.online { background: var(--ok); }
.conn-status.offline { background: var(--danger); }
.admin-badge { font-size: 12px; padding: 3px 8px; border-radius: 999px; background: rgba(255, 180, 0, 0.18); color: #b07c00; border: 1px solid rgba(255, 180, 0, 0.4); }

/* ---------- 布局 ---------- */
.wrap { max-width: 860px; margin: 0 auto; padding: 20px; display: grid; gap: 16px; }
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}

/* ---------- 地址栏 ---------- */
.addr-card { padding: 18px 20px; }
.addr-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.addr-input {
  flex: 1 1 200px; min-width: 160px;
  font-family: var(--mono); font-size: 17px;
  padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--bg); outline: none;
}
.addr-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-weak); }
.addr-at { font-size: 17px; color: var(--muted); }
.addr-domain {
  padding: 10px 8px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); font-family: var(--mono); font-size: 15px; max-width: 220px;
}
.addr-hint { margin: 10px 2px 0; font-size: 13px; color: var(--muted); }

/* ---------- 收件箱 ---------- */
.inbox-card { overflow: hidden; }
.inbox-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; gap: 8px;
}
.badge {
  display: inline-block; min-width: 22px; text-align: center;
  background: var(--danger); color: #fff; font-size: 12px;
  border-radius: 999px; padding: 2px 7px; vertical-align: 2px;
}
.inbox-tools { display: flex; align-items: center; gap: 8px; }
.auto-label { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 5px; }

.email-list { list-style: none; margin: 0; padding: 0; }
.email-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 13px 20px; border-bottom: 1px solid var(--border); cursor: pointer;
  transition: background 0.12s;
}
.email-item:last-child { border-bottom: none; }
.email-item:hover { background: color-mix(in srgb, var(--primary-weak) 55%, transparent); }
.email-item.unread { box-shadow: inset 3px 0 0 var(--primary); }
.email-item.unread .email-subject { font-weight: 700; }

.avatar {
  flex: none; width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 600; color: #fff;
  background: hsl(var(--h, 220) 62% 52%);
}
.email-main { flex: 1; min-width: 0; }
.email-top { display: flex; justify-content: space-between; gap: 10px; }
.email-from { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.email-item.unread .email-from { font-weight: 600; }
.email-time { flex: none; font-size: 12px; color: var(--muted); }
.email-subject { font-size: 14px; margin-top: 2px; }
.email-preview {
  font-size: 12.5px; color: var(--muted); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.att-badge { flex: none; font-size: 12px; color: var(--muted); align-self: center; }

/* ---------- 空状态 ---------- */
.empty { padding: 52px 20px; text-align: center; }
.empty-icon { font-size: 44px; }
.empty-title { margin-top: 10px; font-size: 16px; font-weight: 600; }
.empty-sub { margin-top: 6px; font-size: 13px; color: var(--muted); }

/* ---------- 按钮 ---------- */
.btn {
  padding: 8px 14px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--card); color: var(--text); font-size: 13.5px; line-height: 1.2;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--bg); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: color-mix(in srgb, var(--primary) 88%, #000); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-weak); border-color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-icon { padding: 6px 9px; font-size: 15px; }
.btn.loading { opacity: 0.6; pointer-events: none; }

/* ---------- 弹窗 ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 14, 22, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.modal {
  background: var(--card); border-radius: 14px; border: 1px solid var(--border);
  width: 100%; max-width: 760px; max-height: 92vh;
  display: flex; flex-direction: column; box-shadow: var(--shadow);
  animation: pop 0.16s ease-out;
}
.settings-modal { max-width: 460px; }
@keyframes pop { from { transform: scale(0.97); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-head { padding: 16px 20px 12px; border-bottom: 1px solid var(--border); }
.title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.title-row h3 { font-size: 16.5px; line-height: 1.45; word-break: break-word; }
.modal-body { padding: 16px 20px 20px; overflow-y: auto; }

.detail-meta { margin-top: 8px; display: grid; gap: 3px; font-size: 13px; color: var(--muted); }
.detail-meta b { color: var(--text); font-weight: 600; }
.meta-msgid { font-family: var(--mono); font-size: 11.5px; word-break: break-all; }
.detail-toolbar { margin-top: 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.seg-btn { border: none; background: transparent; padding: 6px 14px; font-size: 13px; color: var(--muted); }
.seg-btn.active { background: var(--primary-weak); color: var(--primary); font-weight: 600; }

.mail-frame {
  width: 100%; height: 58vh; border: 1px solid var(--border); border-radius: 10px;
  background: #fff; display: block;
}
.mail-text {
  margin: 0; padding: 14px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); font-family: var(--mono); font-size: 13px;
  white-space: pre-wrap; word-break: break-word; max-height: 58vh; overflow-y: auto;
}

.attachment-list { margin-top: 12px; display: grid; gap: 6px; }
.attachment-item { border: 1px solid var(--border); border-radius: 9px; }
.att-link {
  display: flex; align-items: center; gap: 8px; padding: 9px 12px;
  color: inherit; text-decoration: none; font-size: 13.5px;
}
.att-link:hover { background: var(--bg); }
.att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-size { margin-left: auto; flex: none; font-size: 12px; color: var(--muted); }

/* ---------- 设置 ---------- */
.settings-block { margin-bottom: 14px; }
.field-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.text-input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 9px; background: var(--bg); outline: none; font-family: var(--mono);
}
.text-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-weak); }
.field-hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); }
.settings-info { font-size: 13px; color: var(--muted); line-height: 1.9; border-top: 1px dashed var(--border); padding-top: 12px; }
.settings-info b { color: var(--text); font-weight: 600; }

/* ---------- Toast / 页脚 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%);
  background: var(--text); color: var(--card); font-size: 13.5px;
  padding: 9px 18px; border-radius: 999px; z-index: 99;
  box-shadow: var(--shadow); max-width: 86vw; word-break: break-all;
  transition: opacity 0.25s ease;
}
/* 警告主题：右上角 + 警告色背景 */
.toast.warn {
  left: auto; right: 16px; bottom: auto; top: 64px; transform: none;
  background: var(--warn-weak); color: var(--warn);
  border: 1px solid var(--warn); font-weight: 600;
  max-width: 320px; padding: 10px 16px; border-radius: 10px;
}
.foot { text-align: center; font-size: 12px; color: var(--muted); padding: 8px 0 26px; }

/* ---------- 移动端 ---------- */
@media (max-width: 620px) {
  .wrap { padding: 12px; gap: 12px; }
  .addr-row .btn { padding: 8px 10px; }
  .overlay { padding: 0; align-items: stretch; }
  .modal { max-width: none; border-radius: 0; max-height: 100vh; }
  .mail-frame, .mail-text { height: 62vh; max-height: 62vh; }
}
