/* ===================== SelfMail 主题 ===================== */
:root {
  --primary: #6366f1;
  --primary-2: #8b5cf6;
  --primary-grad: linear-gradient(135deg, #6366f1, #8b5cf6);
  --bg: #f4f5fa;
  --surface: #ffffff;
  --surface-2: #f8f9fe;
  --text: #1a1d27;
  --muted: #6b7280;
  --border: #e6e8f0;
  --shadow: 0 4px 24px rgba(30, 34, 64, 0.08);
  --shadow-sm: 0 1px 3px rgba(30, 34, 64, 0.06);
  --danger: #ef4444;
  --success: #10b981;
  --radius: 16px;
  --radius-sm: 10px;
}
[data-theme="dark"] {
  --bg: #0e1017;
  --surface: #181b25;
  --surface-2: #1f2330;
  --text: #e8eaf2;
  --muted: #9aa0b0;
  --border: #2a2f3d;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
/* 关键：让 hidden 属性优先级最高，否则 .modal{display:flex} 会盖过 [hidden] 导致弹层一直显示 */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  font-family: 'Inter', 'Noto Sans SC', -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s, color 0.25s;
}
.muted { color: var(--muted); }

/* ---------- 按钮 / 输入 ---------- */
.btn {
  border: none; border-radius: var(--radius-sm); padding: 11px 18px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: transform 0.12s, box-shadow 0.2s, opacity 0.2s;
  font-family: inherit;
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn-primary { background: var(--primary-grad); color: #fff; box-shadow: 0 6px 18px rgba(99, 102, 241, 0.32); }
.btn-primary:hover { box-shadow: 0 10px 26px rgba(99, 102, 241, 0.42); }
.btn-ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--border); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 7px; color: var(--muted); }
input, select, textarea {
  width: 100%; padding: 11px 13px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 14px; background: var(--surface);
  color: var(--text); font-family: inherit; transition: border 0.2s, box-shadow 0.2s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.16);
}
.icon-btn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  width: 38px; height: 38px; border-radius: 10px; cursor: pointer; font-size: 16px;
  display: inline-flex; align-items: center; justify-content: center; transition: background 0.2s;
}
.icon-btn:hover { background: var(--border); }

/* ---------- 登录页 ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; }
.login-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(60% 60% at 20% 20%, rgba(139, 92, 246, 0.35), transparent 60%),
    radial-gradient(55% 55% at 85% 75%, rgba(99, 102, 241, 0.32), transparent 60%),
    var(--bg);
}
.login-card {
  position: relative; width: 380px; max-width: calc(100vw - 32px);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border); border-radius: 22px; padding: 38px 34px;
  box-shadow: var(--shadow);
}
.brand { text-align: center; margin-bottom: 28px; }
.brand-logo {
  width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 18px;
  background: var(--primary-grad); display: flex; align-items: center; justify-content: center;
  font-size: 30px; box-shadow: 0 10px 26px rgba(99, 102, 241, 0.4);
}
.brand-logo.small { width: 34px; height: 34px; font-size: 17px; border-radius: 10px; margin: 0; box-shadow: none; }
.brand h1 { font-size: 24px; letter-spacing: 0.5px; }
.brand .muted { font-size: 13px; margin-top: 6px; }
.error { color: var(--danger); font-size: 13px; margin-top: 12px; text-align: center; }

/* ---------- 主布局 ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  padding: 22px 16px; display: flex; flex-direction: column; gap: 8px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; }
.brand-name { font-weight: 700; font-size: 17px; }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 11px 13px; border: none;
  background: transparent; color: var(--muted); border-radius: 11px; cursor: pointer;
  font-size: 14px; font-weight: 500; width: 100%; text-align: left; transition: background 0.18s, color 0.18s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-grad); color: #fff; box-shadow: 0 6px 16px rgba(99, 102, 241, 0.28); }
.nav-item .ico { font-size: 17px; }
.sidebar-foot { display: flex; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.sidebar-foot .icon-btn { flex: 1; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 22px 32px 12px;
}
.topbar h2 { font-size: 22px; font-weight: 700; }
.content { padding: 8px 32px 40px; }

/* ---------- 卡片 / 统计 ---------- */
.grid { display: grid; gap: 18px; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow-sm); transition: transform 0.16s, box-shadow 0.2s;
}
.card.hover:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.stat-card { position: relative; overflow: hidden; }
.stat-card .stat-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.stat-card .stat-number { font-size: 34px; font-weight: 700; margin-top: 8px; letter-spacing: -0.5px; }
.stat-card .stat-ico {
  position: absolute; right: 18px; top: 18px; width: 42px; height: 42px; border-radius: 12px;
  background: var(--surface-2); display: flex; align-items: center; justify-content: center; font-size: 20px;
}

/* ---------- 邮箱卡片 ---------- */
.mailbox-card { display: flex; align-items: center; gap: 16px; }
.mailbox-avatar {
  width: 50px; height: 50px; flex-shrink: 0; border-radius: 14px; color: #fff;
  background: var(--primary-grad); display: flex; align-items: center; justify-content: center;
  font-size: 21px; font-weight: 700;
}
.mailbox-info { flex: 1; min-width: 0; }
.mailbox-info .name { font-weight: 600; font-size: 15px; }
.mailbox-info .addr { color: var(--muted); font-size: 13px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mailbox-actions { display: flex; gap: 8px; flex-shrink: 0; }
.tag { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.tag.ok { background: rgba(16, 185, 129, 0.14); color: var(--success); }
.tag.bad { background: rgba(239, 68, 68, 0.14); color: var(--danger); }
.tag.idle { background: var(--surface-2); color: var(--muted); }

/* ---------- 表单弹层 ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(12, 14, 24, 0.5); backdrop-filter: blur(3px); }
.modal-card {
  position: relative; width: 620px; max-width: 100%; max-height: 86vh; overflow: auto;
  background: var(--surface); border-radius: 20px; box-shadow: var(--shadow);
  animation: pop 0.18s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 22px 26px 6px; }
.modal-head h3 { font-size: 19px; }
.modal-meta { padding: 6px 26px 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
.modal-body { padding: 18px 26px 26px; }
.mail-render {
  border: 1px solid var(--border); border-radius: 12px; padding: 20px; background: var(--surface-2);
  font-size: 14px; line-height: 1.75; white-space: pre-wrap; word-break: break-word;
}
.mail-frame { width: 100%; min-height: 320px; border: 1px solid var(--border); border-radius: 12px; background: #fff; }

/* ---------- 邮件列表 ---------- */
.msg-list { display: flex; flex-direction: column; gap: 10px; }
.msg-item {
  display: flex; align-items: center; gap: 14px; padding: 15px 18px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: 13px; transition: border 0.16s, transform 0.14s;
}
.msg-item:hover { border-color: var(--primary); transform: translateX(3px); }
.msg-avatar {
  width: 42px; height: 42px; flex-shrink: 0; border-radius: 12px; color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
}
.msg-main { flex: 1; min-width: 0; }
.msg-from { font-weight: 600; font-size: 14px; }
.msg-subject { font-size: 13px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-snippet { font-size: 12px; color: var(--muted); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: 0.85; }
.msg-date { font-size: 12px; color: var(--muted); flex-shrink: 0; white-space: nowrap; }

/* ---------- 空状态 / 提示 ---------- */
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty .empty-ico { font-size: 52px; margin-bottom: 14px; opacity: 0.7; }
.empty h3 { font-size: 17px; color: var(--text); margin-bottom: 8px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 26px 0 16px; }
.section-head h3 { font-size: 17px; }
.toast {
  position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%) translateY(10px);
  background: var(--text); color: var(--bg); padding: 12px 22px; border-radius: 12px; font-size: 14px;
  box-shadow: var(--shadow); z-index: 100; opacity: 0; transition: opacity 0.22s, transform 0.22s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.spinner {
  width: 20px; height: 20px; border: 2.5px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 0.7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-row { display: flex; align-items: center; gap: 12px; justify-content: center; padding: 46px; color: var(--muted); }

/* ---------- 响应式 ---------- */
@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 40; height: 100vh; transform: translateX(-100%); transition: transform 0.24s; }
  .sidebar.open { transform: none; }
  .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
  .topbar, .content { padding-left: 18px; padding-right: 18px; }
  .menu-btn { display: inline-flex !important; }
}
.menu-btn { display: none; }
