:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #104490;
  --primary-soft: #e8f0fb;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.55;
}
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ---------- 登录页 ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #104490 0%, #0b5aa8 100%); padding: 16px;
}
.login-card {
  width: 100%; max-width: 380px; background: #fff; border-radius: 14px;
  padding: 32px 28px; box-shadow: 0 10px 40px rgba(0,0,0,.18);
}
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; background: #fff; color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--primary); border-color: transparent; }
.field textarea { resize: vertical; min-height: 80px; }
.btn {
  padding: 9px 16px; border-radius: 8px; border: none; font-size: 14px;
  background: var(--primary); color: #fff; transition: opacity .15s;
}
.btn:hover { opacity: .88; }
.btn.secondary { background: #e2e8f0; color: var(--text); }
.btn.danger { background: var(--red); }
.btn.green { background: var(--green); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- 布局 ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 210px; background: #0b2d5c; color: #cbd5e1; flex-shrink: 0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { padding: 18px 16px; font-size: 16px; font-weight: 700; color: #fff; border-bottom: 1px solid rgba(255,255,255,.12); }
.sidebar .brand small { display: block; font-size: 11px; font-weight: 400; color: #8ba7cc; margin-top: 2px; }
.nav { flex: 1; padding: 10px 8px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 9px; padding: 10px 12px; border-radius: 8px;
  color: #cbd5e1; cursor: pointer; margin-bottom: 2px; font-size: 14px;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item .badge { margin-left: auto; background: var(--red); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; }
.sidebar .userbox { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.12); font-size: 13px; }
.sidebar .userbox .name { color: #fff; }
.sidebar .userbox .logout { color: #8ba7cc; cursor: pointer; font-size: 12px; margin-top: 3px; display: inline-block; }
.main { flex: 1; padding: 22px 26px; overflow-x: hidden; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }
.page-head h2 { font-size: 19px; }

/* ---------- 卡片 / 表格 ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 16px 18px; }
.grid { display: grid; gap: 14px; }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stat { padding: 16px 18px; }
.stat .num { font-size: 26px; font-weight: 700; margin-top: 2px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 7px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; background: #f8fafc; white-space: nowrap; }
tr:hover td { background: #f8fafc; }
.tag {
  display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px;
  color: #fff; margin: 1px 3px 1px 0; white-space: nowrap;
}
.pill { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.status-pill { color: #fff; }
.wa-link { color: var(--green); font-weight: 600; }
.muted { color: var(--muted); }
.flex { display: flex; align-items: center; gap: 8px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.grow { flex: 1; }

/* ---------- 筛选条 ---------- */
.filterbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.filterbar input, .filterbar select {
  padding: 8px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 13.5px; background: #fff;
}
.filterbar input.search { min-width: 220px; }

/* ---------- 分页 ---------- */
.pagination { display: flex; align-items: center; gap: 6px; margin-top: 14px; justify-content: flex-end; }
.pagination button { border: 1px solid var(--border); background: #fff; border-radius: 6px; padding: 5px 11px; }
.pagination button:disabled { opacity: .4; }
.pagination .info { color: var(--muted); font-size: 13px; margin-right: 6px; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.modal {
  background: #fff; border-radius: 12px; width: 100%; max-width: 560px;
  max-height: 88vh; overflow-y: auto; box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.modal.wide { max-width: 720px; }
.modal .m-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal .m-head h3 { font-size: 16px; }
.modal .m-body { padding: 18px 20px; }
.modal .m-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.close-x { border: none; background: none; font-size: 20px; color: var(--muted); cursor: pointer; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-row .field:last-child:nth-child(odd) { grid-column: 1 / -1; }

/* ---------- 详情 ---------- */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px 20px; margin: 14px 0; }
.detail-item .k { color: var(--muted); font-size: 12.5px; }
.detail-item .v { font-size: 14px; margin-top: 2px; word-break: break-all; }

/* ---------- 邮件模板卡片 ---------- */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.tpl-card { padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.tpl-card .subject { font-size: 13px; color: var(--muted); border-left: 3px solid var(--primary); padding-left: 8px; }
.tpl-card .body-prev { font-size: 12.5px; color: var(--muted); white-space: pre-wrap; max-height: 120px; overflow: hidden; background: #f8fafc; padding: 8px; border-radius: 6px; }
.tpl-card .ops { margin-top: auto; display: flex; gap: 8px; }

/* ---------- 空态 ---------- */
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.empty .big { font-size: 34px; margin-bottom: 8px; }

/* ---------- 消息 ---------- */
.msg { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-size: 13.5px; }
.msg.err { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.msg.ok { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }

/* 移动端适配 */
@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .nav { display: flex; overflow-x: auto; }
  .nav-item { white-space: nowrap; }
  .main { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .filterbar input.search { min-width: 100%; }
  .table-scroll { overflow-x: auto; }
}
