:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1f2937;
  --text-sub: #6b7280;
  --line: #e5e9f2;
  --primary: #4f6ef7;
  --primary-dark: #3d59e0;
  --green: #16a34a;
  --red: #e5484d;
  --amber: #d97706;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---------- 登录遮罩 ---------- */
.login-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(15, 23, 42, .55);
  backdrop-filter: blur(3px);
  display: grid; place-items: center;
}
.login-box {
  width: 360px; max-width: calc(100vw - 40px);
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 28px;
}
.login-brand { display: flex; gap: 10px; align-items: center; margin-bottom: 22px; }
.login-brand .brand-title { color: var(--text); }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-sub); }
.login-form input {
  border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px;
  font-size: 14px; outline: none; transition: border .15s;
}
.login-form input:focus { border-color: var(--primary); }
.login-form .btn.block { width: 100%; padding: 11px; font-size: 14.5px; }

/* ---------- 布局 ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 248px;
  flex: 0 0 248px;
  background: linear-gradient(180deg, #1e293b 0%, #111827 100%);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; gap: 10px; align-items: center; padding: 4px 6px 20px; }
.brand-icon {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(135deg, #6172f3, #8b5cf6);
  display: grid; place-items: center; font-weight: 700; color: #fff; font-size: 17px;
}
.brand-title { font-weight: 600; font-size: 15px; }
.brand-sub { font-size: 11px; color: #94a3b8; letter-spacing: .3px; }

.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  color: #cbd5e1; text-decoration: none; cursor: pointer;
  font-size: 13.5px; transition: all .15s;
}
.nav-item span { font-size: 15px; width: 18px; text-align: center; }
.nav-item:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.nav-item.active { background: linear-gradient(135deg, #4f6ef7, #6172f3); color: #fff; box-shadow: 0 6px 16px rgba(79, 110, 247, .35); }

.sidebar-foot { border-top: 1px solid rgba(255, 255, 255, .09); padding-top: 12px; font-size: 12px; color: #94a3b8; }
.status-line { display: flex; align-items: center; gap: 7px; margin-bottom: 4px; color: #e2e8f0; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #64748b; }
.dot.on { background: #22c55e; box-shadow: 0 0 0 4px rgba(34, 197, 94, .18); }
.dot.busy { background: #f59e0b; box-shadow: 0 0 0 4px rgba(245, 158, 11, .18); }
.tiny { font-size: 11px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 20px 28px; background: rgba(255, 255, 255, .8);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { margin: 0; font-size: 19px; font-weight: 600; }
.sub { margin: 3px 0 0; color: var(--text-sub); font-size: 12.5px; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.content { padding: 22px 28px 60px; display: flex; flex-direction: column; gap: 18px; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; border: 1px solid var(--line);
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.hint { font-size: 12px; color: var(--text-sub); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.stat-label { color: var(--text-sub); font-size: 12.5px; }
.stat-value { font-size: 30px; font-weight: 650; margin: 6px 0 2px; letter-spacing: -.5px; }
.stat-foot { font-size: 12px; color: var(--text-sub); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 1080px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- 按钮 ---------- */
.btn {
  border: 1px solid transparent; border-radius: 9px; padding: 8px 14px;
  font-size: 13px; cursor: pointer; font-family: inherit; transition: all .15s;
  background: #eef1f8; color: var(--text);
}
.btn:hover { filter: brightness(.97); }
.btn.primary { background: linear-gradient(135deg, #4f6ef7, #6172f3); color: #fff; box-shadow: 0 4px 12px rgba(79, 110, 247, .3); }
.btn.primary:hover { background: linear-gradient(135deg, #3d59e0, #5468ee); }
.btn.ghost { background: #fff; border-color: var(--line); }
.btn.ghost:hover { background: #f7f9fc; }
.btn.danger { color: var(--red); border-color: #f6d5d5; }
.btn.danger:hover { background: #fef2f2; }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { border: none; background: transparent; font-size: 20px; line-height: 1; cursor: pointer; color: var(--text-sub); }

.row-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 14px; }

/* ---------- 表单 ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--text-sub); }
label.block { margin-top: 14px; }
label.span-2 { grid-column: span 2; }
@media (max-width: 700px) { label.span-2 { grid-column: span 1; } }

input[type="text"], input[type="password"], input[type="number"], input[type="time"], select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 11px; font-size: 13px; font-family: inherit; color: var(--text);
  background: #fbfcfe; outline: none; transition: border .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 110, 247, .12); background: #fff; }
textarea { resize: vertical; line-height: 1.6; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

.switch-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.switch { flex-direction: row; align-items: center; gap: 9px; color: var(--text); font-size: 13px; cursor: pointer; }
.switch input { width: 16px; height: 16px; accent-color: var(--primary); }
.checkbox { flex-direction: row; align-items: center; gap: 7px; font-size: 12.5px; }
.checkbox input { width: 15px; height: 15px; accent-color: var(--primary); }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; font-weight: 600; color: var(--text-sub); font-size: 12px;
  padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 10px; border-bottom: 1px solid #f1f4fa; vertical-align: middle; }
.table tbody tr:hover { background: #fafbfe; }
.table .muted { color: var(--text-sub); font-size: 12px; }
.table .subject-cell { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11.5px; font-weight: 500; }
.badge.green { background: #e8f7ee; color: #15803d; }
.badge.red { background: #fdecec; color: #b91c1c; }
.badge.gray { background: #eef1f6; color: #64748b; }
.badge.blue { background: #eaefff; color: #3d59e0; }
.badge.amber { background: #fef4e6; color: #b45309; }

.tip { font-size: 12.5px; color: var(--text-sub); margin: 8px 0 0; line-height: 1.6; }

/* ---------- 额度进度 ---------- */
.quota-list { display: flex; flex-direction: column; gap: 13px; }
.quota-item { display: flex; flex-direction: column; gap: 6px; }
.quota-top { display: flex; justify-content: space-between; font-size: 12.5px; }
.quota-top .email { font-weight: 500; }
.quota-top .num { color: var(--text-sub); }
.bar { height: 8px; border-radius: 6px; background: #eef1f8; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 6px; background: linear-gradient(90deg, #4f6ef7, #7c8cff); transition: width .4s; }
.bar.done > i { background: linear-gradient(90deg, #16a34a, #34d399); }

/* ---------- 图表 ---------- */
.chart { display: flex; align-items: flex-end; gap: 12px; height: 190px; padding-top: 10px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; }
.chart .bars { flex: 1; display: flex; align-items: flex-end; gap: 4px; width: 100%; justify-content: center; }
.chart .bars i { width: 12px; border-radius: 5px 5px 0 0; display: block; min-height: 2px; }
.chart .bars i.o { background: linear-gradient(180deg, #6172f3, #4f6ef7); }
.chart .bars i.r { background: linear-gradient(180deg, #34d399, #16a34a); }
.chart .lbl { font-size: 11px; color: var(--text-sub); }

/* ---------- 键值对 ---------- */
.kv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.kv { background: #fafbfe; border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; }
.kv .k { font-size: 11.5px; color: var(--text-sub); }
.kv .v { font-size: 14px; margin-top: 4px; font-weight: 500; word-break: break-all; }

.pair-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.pair { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: #fafbfe; font-size: 12.5px; }
.pair .from { font-weight: 600; margin-bottom: 6px; }
.pair .arrow { color: var(--primary); margin-right: 6px; }
.pair .to { color: var(--text-sub); line-height: 1.8; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters select { width: auto; min-width: 130px; }
.pager { display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 14px; font-size: 12.5px; color: var(--text-sub); }

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; z-index: 100; padding: 20px; }
.modal-box { background: #fff; border-radius: 16px; width: 100%; max-width: 720px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 24px 60px rgba(15, 23, 42, .3); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); }

.mail-view { white-space: pre-wrap; word-break: break-word; font-family: inherit; font-size: 13px; line-height: 1.7; margin: 0; background: #fafbfe; padding: 14px; border-radius: 10px; border: 1px solid var(--line); }

/* ---------- 邮件详情 ---------- */
.modal-box.wide { max-width: 880px; }
#viewMeta { margin-bottom: 14px; }
#viewMeta .kv { background: #fafbfe; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
#viewMeta .kv .k { margin-bottom: 3px; }
#viewMeta .kv .v { font-size: 13px; }

/* ---------- 接口诊断 ---------- */
.diag { margin-top: 14px; border-radius: 12px; padding: 14px 16px; font-size: 13px; line-height: 1.75; white-space: pre-wrap; word-break: break-word; border: 1px solid var(--line); background: #fafbfe; }
.diag.ok { border-color: #86efac; background: #f0fdf4; color: #15803d; }
.diag.err { border-color: #fca5a5; background: #fef2f2; color: #b91c1c; }
.diag .diag-meta { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 10px; padding-top: 10px; border-top: 1px dashed rgba(0, 0, 0, .12); font-size: 12px; color: #475569; }
.diag .diag-meta code { background: rgba(0, 0, 0, .06); padding: 1px 6px; border-radius: 5px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; right: 24px; bottom: 24px; z-index: 200;
  background: #1e293b; color: #fff; padding: 12px 18px; border-radius: 11px;
  font-size: 13px; max-width: 420px; box-shadow: 0 12px 30px rgba(15, 23, 42, .3);
  line-height: 1.5;
}
.toast.ok { background: linear-gradient(135deg, #15803d, #16a34a); }
.toast.err { background: linear-gradient(135deg, #b91c1c, #e5484d); }

.loading { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; flex-direction: column; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .content, .topbar { padding: 16px; }
}
