:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #4f46e5;
  --primary-soft: #eef2ff;
  --green: #10b981;
  --green-soft: #ecfdf5;
  --amber: #f59e0b;
  --amber-soft: #fffbeb;
  --red: #ef4444;
  --red-soft: #fef2f2;
  --gray-soft: #f3f4f6;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255,255,255,.85);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto;
  padding: 14px 24px;
  display: flex; align-items: center; gap: 16px;
}
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.topbar .spacer { flex: 1; }
.topbar .meta { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 13px; }
.live-dot { display: inline-flex; align-items: center; gap: 6px; }
.live-dot::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--green); animation: pulse 1.6s infinite; }
.live-dot.off::before { background: var(--red); animation: none; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 7px 14px; border-radius: 8px; font-size: 13px; cursor: pointer;
  transition: all .15s; font-family: inherit;
}
.btn:hover { border-color: #c7cbd4; background: #fafafa; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #4338ca; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--gray-soft); color: var(--text); }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: var(--red-soft); border-color: #fecaca; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { padding: 4px 10px; font-size: 12px; }

/* ---------- 容器 ---------- */
.container { max-width: 1200px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 18px; }
.page-head h1 { font-size: 22px; margin: 0; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ---------- 统计条 ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat-card .label { color: var(--muted); font-size: 12px; }
.stat-card .value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.stat-card .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- 任务卡片 ---------- */
.task-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.task-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s;
  display: flex; flex-direction: column; gap: 10px;
}
.task-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.task-card .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.task-card .name { font-weight: 600; font-size: 15px; line-height: 1.35; }
.task-card .kind { font-size: 11px; color: var(--muted); }
.status-chip {
  font-size: 11px; padding: 2px 10px; border-radius: 999px; font-weight: 600; white-space: nowrap;
  background: var(--gray-soft); color: var(--muted);
}
.status-chip.ACTIVE { background: var(--green-soft); color: #047857; }
.status-chip.PAUSED { background: var(--amber-soft); color: #b45309; }
.status-chip.EXPIRED, .status-chip.OFFLINE, .status-chip.FULL { background: var(--gray-soft); color: var(--muted); }
.status-chip.DRAFT { background: var(--gray-soft); color: var(--muted); }

.task-card .commission { font-size: 22px; font-weight: 700; color: var(--text); }
.task-card .commission .cur { font-size: 13px; color: var(--muted); font-weight: 500; margin-right: 2px; }
.task-card .meta-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.task-card .meta-row strong { color: var(--text); font-weight: 600; }
.task-card .progress { height: 6px; background: var(--gray-soft); border-radius: 999px; overflow: hidden; }
.task-card .progress > div { height: 100%; background: var(--primary); border-radius: 999px; }
.task-card .deadline { font-size: 11px; color: var(--muted); }

/* ---------- 空态 / 加载 ---------- */
.empty, .loading { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty .big { font-size: 40px; margin-bottom: 8px; }
.toast-wrap { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #111827; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 13px;
  box-shadow: var(--shadow-lg); animation: toastIn .2s ease;
}
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- 后台 ---------- */
.admin-wrap { max-width: 1000px; margin: 0 auto; padding: 24px; }
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 22px; }
.tab {
  padding: 10px 16px; cursor: pointer; font-size: 14px; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -2px; font-weight: 500;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab:hover { color: var(--text); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.card h3 { margin: 0 0 14px; font-size: 15px; }
.card h3 .desc { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 8px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 500; }
.field input, .field select, .field textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 13px; font-family: inherit; background: #fff; color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.field textarea { min-height: 120px; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.field .hint { font-size: 11px; color: var(--muted); margin-top: 4px; }
.form-actions { display: flex; gap: 10px; margin-top: 16px; align-items: center; }
.form-actions .spacer { flex: 1; }

/* token 展示 */
.token-box {
  background: #0f172a; color: #a5f3fc; padding: 12px 14px; border-radius: 8px;
  font-family: ui-monospace, Consolas, monospace; font-size: 12px; word-break: break-all;
  display: flex; gap: 10px; align-items: center;
}
.token-box .copy { margin-left: auto; }

/* 收件人列表 */
.recipient-list { list-style: none; padding: 0; margin: 0; }
.recipient-list li {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; background: #fff;
}
.recipient-list li .email { flex: 1; font-size: 13px; }
.recipient-list li .time { font-size: 11px; color: var(--muted); }

/* 开关 */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider-sw { position: absolute; cursor: pointer; inset: 0; background: #d1d5db; border-radius: 22px; transition: .2s; }
.slider-sw::before { content: ''; position: absolute; height: 16px; width: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider-sw { background: var(--primary); }
.switch input:checked + .slider-sw::before { transform: translateX(16px); }

/* 事件日志 */
.event-log { max-height: 320px; overflow-y: auto; }
.event-log .ev { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.event-log .ev .tag { font-weight: 600; min-width: 64px; }
.event-log .ev .tag.new { color: var(--green); }
.event-log .ev .tag.status { color: var(--primary); }
.event-log .ev .tag.error { color: var(--red); }
.event-log .ev .tag.login { color: var(--amber); }
.event-log .ev .ts { color: var(--muted); margin-left: auto; white-space: nowrap; }

/* 滑块验证码 */
.slider-modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.slider-box { background: #fff; border-radius: 12px; padding: 18px; width: 340px; box-shadow: var(--shadow-lg); }
.slider-box h4 { margin: 0 0 12px; font-size: 14px; }
.slider-surface { position: relative; width: 300px; margin: 0 auto; user-select: none; }
.slider-surface img.bg { display: block; width: 300px; border-radius: 6px; }
.slider-surface img.piece { position: absolute; left: 0; cursor: grab; filter: drop-shadow(0 2px 3px rgba(0,0,0,.4)); }
.slider-surface img.piece.dragging { cursor: grabbing; }
.slider-track { margin-top: 12px; height: 38px; background: var(--gray-soft); border-radius: 8px; position: relative; overflow: hidden; }
.slider-track .fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--primary-soft); }
.slider-track .handle {
  position: absolute; top: 2px; left: 2px; width: 34px; height: 34px; border-radius: 6px;
  background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 18px; cursor: grab; box-shadow: var(--shadow);
}
.slider-track .text { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--muted); pointer-events: none; }
.captcha-img { height: 40px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; vertical-align: middle; }

/* 登录态卡片 */
.auth-status { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 8px; background: var(--green-soft); color: #065f46; font-size: 13px; }
.auth-status.off { background: var(--gray-soft); color: var(--muted); }
.auth-status .who { font-weight: 600; }

.var-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.var-chip { font-size: 11px; background: var(--primary-soft); color: var(--primary); padding: 2px 8px; border-radius: 999px; font-family: ui-monospace, monospace; cursor: pointer; }

@media (max-width: 720px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .topbar-inner { padding: 12px 16px; }
  .container, .admin-wrap { padding: 16px; }
}
