:root {
  --bg: #eef1f8;
  --card: #ffffff;
  --text: #1b2030;
  --muted: #6b7280;
  --line: #e3e8f2;
  --primary: #2f6df6;
  --primary-d: #1f54c9;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .07);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--primary); text-decoration: none; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 22px;
  background: linear-gradient(120deg, #1d2b53, #2f6df6);
  color: #fff;
  position: sticky; top: 0; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 36px; height: 36px; border-radius: 11px; flex: none;
  display: grid; place-items: center;
  background: rgba(255,255,255,.16); font-size: 18px; font-weight: 700;
}
.brand h1 { margin: 0; font-size: 16px; font-weight: 650; white-space: nowrap; }
.brand .sub { margin: 0; font-size: 11.5px; opacity: .78; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.user-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px;
  background: rgba(255,255,255,.15); font-size: 12px; white-space: nowrap;
  max-width: 100%;
}
.user-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: #7ce38b; flex: none; }
.user-chip.warn .dot { background: #ffc65c; }
.user-chip.bad .dot { background: #ff8a8a; }

.icon-btn {
  border: 1px solid rgba(255,255,255,.35); background: transparent; color: #fff;
  padding: 6px 11px; border-radius: 9px; font: inherit; font-size: 12.5px; cursor: pointer;
}
.icon-btn:hover { background: rgba(255,255,255,.14); }

/* ---------- 通用 ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px;
}
.layout { display: grid; grid-template-columns: minmax(340px, 460px) 1fr; gap: 16px; padding: 16px 22px 32px; }
h2 { margin: 0 0 6px; font-size: 15px; }
h3 { margin: 0 0 8px; font-size: 14px; }
.hint { margin: 0 0 12px; color: var(--muted); font-size: 12.5px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.row > input[type=text], .row > input[type=password] { flex: 1 1 160px; min-width: 0; }

input[type=text], input[type=password], select {
  width: 100%;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--text); font: inherit; outline: none;
  transition: border-color .15s, box-shadow .15s;
  min-height: 42px;
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47,109,246,.13); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; color: var(--text); font: inherit; cursor: pointer;
  transition: all .15s; white-space: nowrap; min-height: 42px;
}
.btn:hover { border-color: #cfd6e6; background: #fafbff; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-d); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; min-height: 32px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px;
  background: #eef1f7; color: var(--muted); white-space: nowrap;
}
.badge.ok { background: #e6f6ec; color: var(--ok); }
.badge.warn { background: #fff4e0; color: var(--warn); }
.badge.bad { background: #fdeaea; color: var(--danger); }
.badge.info { background: #eef2ff; color: #3b5bdb; }

.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---------- 登录 / 注册 ---------- */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 10% -10%, #dfe9ff 0%, var(--bg) 55%);
}
.auth-card { width: min(430px, 100%); padding: 26px 24px; }
.auth-card h1 { margin: 0 0 4px; font-size: 22px; }
.auth-card .subtitle { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 6px; font-size: 12.5px; color: var(--muted); }
.actions { display: flex; gap: 10px; margin-top: 6px; }
.actions .btn { flex: 1; }
.switch-line { margin-top: 16px; text-align: center; font-size: 13px; color: var(--muted); }
.alert {
  padding: 10px 12px; border-radius: 10px; font-size: 12.5px; margin-bottom: 14px;
  background: #fff8e8; border: 1px solid #f3dfb6; color: #8a5300; white-space: pre-wrap;
}
.alert.bad { background: #fdeaea; border-color: #f6c9c9; color: #a11212; }
.alert.ok { background: #e9f8ee; border-color: #bfe8cd; color: #126b34; }

/* ---------- 来源栏 ---------- */
.source-bar {
  margin: 16px 22px 0; display: flex; flex-wrap: wrap; gap: 12px;
  align-items: center; justify-content: space-between;
}
.source-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.source-left label { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.source-left select { width: auto; min-width: 170px; }
.source-status { font-size: 12.5px; color: var(--muted); flex: 1 1 280px; min-width: 0; }
.source-status .ok { color: var(--ok); }
.source-status .bad { color: var(--danger); }

.banner {
  margin: 12px 22px 0; padding: 11px 14px; border-radius: 12px;
  background: #fff7e6; border: 1px solid #f5d9a8; color: #8a5300; font-size: 12.5px;
}
.banner.bad { background: #fdeaea; border-color: #f6c9c9; color: #a11212; }

/* ---------- 结果列表 ---------- */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.tabs { display: flex; gap: 3px; background: #f1f4fb; padding: 3px; border-radius: 10px; }
.tab {
  border: 0; background: transparent; padding: 6px 12px; border-radius: 8px;
  font: inherit; font-size: 12.5px; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.tab.active {
  background: #fff; color: var(--text); font-weight: 600;
  box-shadow: 0 1px 3px rgba(16, 24, 40, .09);
}

.searchbar {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 6px 5px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.searchbar:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47,109,246,.13); }
.searchbar-icon { font-size: 17px; color: var(--muted); line-height: 1; }
.searchbar input {
  flex: 1 1 auto; min-width: 0; border: 0; background: transparent;
  padding: 8px 4px; box-shadow: none !important;
}
.searchbar input:focus { border: 0; box-shadow: none; }
.searchbar .btn { min-height: 38px; border-radius: 9px; padding: 0 14px; }
.clear-btn {
  border: 0; background: #eef1f7; color: var(--muted); width: 24px; height: 24px;
  border-radius: 50%; cursor: pointer; line-height: 1; font-size: 14px; flex: none;
}
.clear-btn:hover { background: #e2e7f3; color: var(--text); }

.search-meta { min-height: 18px; margin: 8px 0 4px; font-size: 12.5px; color: var(--muted); }
.search-meta.bad { color: var(--danger); }

.result-list { display: grid; gap: 8px; max-height: 52vh; overflow: auto; padding-right: 2px; }
.result-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  background: #fff; transition: border-color .15s, background .15s, box-shadow .15s;
}
.result-item:hover { border-color: #cfd8ee; background: #fafbff; }
.result-item.selected { border-color: var(--primary); background: #f2f6ff; box-shadow: 0 0 0 2px rgba(47,109,246,.12); }
.result-main { min-width: 0; }
.result-title { font-weight: 650; word-break: break-word; }
.result-sub { display: flex; align-items: center; gap: 6px; margin-top: 2px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.result-extra { margin-top: 2px; font-size: 11.5px; color: var(--muted); }
.pick-btn { flex: none; }

.picker-bar {
  margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}
.pick-info { min-width: 0; flex: 1 1 180px; }
.pick-label { font-size: 11.5px; color: var(--muted); }
.pick-title { display: block; font-weight: 600; word-break: break-word; }
.pick-ops { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.fmt-select { width: auto; min-width: 96px; }
.title-input { flex: 1 1 140px; min-width: 0; width: auto; }

.input-row { display: flex; gap: 8px; align-items: stretch; }
.input-row input { flex: 1 1 auto; }
.field-hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); }

.results { list-style: none; margin: 8px 0 0; padding: 0; max-height: 320px; overflow: auto; }
.results li {
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
  padding: 10px 2px; border-bottom: 1px dashed var(--line);
}
.results .name { font-weight: 600; }
.results .meta { font-size: 12px; color: var(--muted); }

/* ---------- 队列 ---------- */
.queue-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.queue-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 12px;
  padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.check-col { width: 34px; }
.check-cell { width: 34px; text-align: center; }
.check-cell input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

.task-group-head, tr.group-row td { background: #f7f9ff; }
tr.group-row td { padding: 8px 10px; border-bottom: 1px solid var(--line); }
tr.group-row td strong { margin-right: 8px; }
tr.group-row td .badge { margin-right: 6px; }
tr.group-row td .btn { margin-left: auto; float: right; }
tbody td { padding: 10px; border-bottom: 1px solid #f1f4fa; vertical-align: middle; }
tbody td.source-cell { white-space: nowrap; }
tbody td.user-cell { white-space: nowrap; }
tbody td.title-cell { min-width: 210px; }
tbody tr:hover { background: #fafbff; }
.status-cell .tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; background: #eef1f7; color: var(--muted); white-space: nowrap; }
.tag.queued { background: #eef2ff; color: #3b5bdb; }
.tag.running { background: #e7f7ee; color: var(--ok); }
.tag.ready { background: #fff4e0; color: #b45309; }
.tag.paused { background: #f1f0ff; color: #6d5ce0; }
.tag.delivered { background: #e6f6ec; color: #15803d; }
.tag.expired { background: #f3f4f6; color: #9aa1ac; }
.tag.success { background: #e6f6ec; color: var(--ok); }
.tag.failed { background: #fdeaea; color: var(--danger); }
.tag.canceled { background: #f2f3f5; color: #868e96; }
.title-cell .t { font-weight: 600; word-break: break-word; }
.title-cell .m { font-size: 11.5px; color: var(--muted); margin-top: 2px; word-break: break-word; }
.title-cell .m.clamp {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.title-cell .warn-text { color: #b45309; }
.title-cell .t { word-break: break-word; }
.progress-cell { min-width: 140px; }
.bar { height: 7px; border-radius: 999px; background: #eef1f7; overflow: hidden; min-width: 80px; }
.bar > span { display: block; height: 100%; background: var(--primary); width: 0; transition: width .3s; }
.progress-cell .p { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.action-cell { white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 20px; font-size: 13px; }

/* ---------- 提示 ---------- */
.msg { margin: 6px 0 0; font-size: 12.5px; min-height: 18px; }
.msg.ok { color: var(--ok); }
.msg.bad { color: var(--danger); }

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; z-index: 60; padding: 16px; }
.modal-card { width: min(520px, 100%); max-height: 86vh; overflow: auto; background: #fff; border-radius: 16px; padding: 20px; box-shadow: 0 24px 64px rgba(15,23,42,.28); }
.modal-card h3 { margin: 0 0 8px; font-size: 16px; }
.modal-card p { margin: 0 0 16px; color: var(--muted); font-size: 13px; white-space: pre-wrap; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- 管理后台 ---------- */
.admin-wrap { padding: 16px 22px 40px; display: grid; gap: 16px; }
.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 16px; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .v { font-size: 22px; font-weight: 700; }
.stat .k { font-size: 12px; color: var(--muted); }
.key-box {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 10px 12px; border-radius: 10px; background: #f7f9ff; border: 1px dashed #cfd9f5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px; word-break: break-all;
}
.user-list { display: grid; gap: 10px; }
.user-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: #fff; }
.user-card .head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.user-card .name { font-weight: 650; }
.user-card .meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.user-card .ops { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.tag-row { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- 移动端 ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 14px 14px 28px; }
  .source-bar { margin: 14px 14px 0; }
  .banner { margin: 12px 14px 0; }
  .admin-wrap { padding: 14px; }
}

@media (max-width: 560px) {
  .topbar { flex-direction: column; align-items: stretch; gap: 8px; }
  .brand { order: 1; }
  .topbar-right { order: 2; justify-content: flex-start; }
  .user-chip { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .brand h1 { font-size: 15px; }
}

@media (max-width: 760px) {
  .check-col, .check-cell { width: 28px; }
  .result-list { max-height: 52vh; }
  .result-item { align-items: flex-start; }
  .pick-btn { min-height: 34px; }
  .picker-bar { align-items: stretch; }
  .pick-ops { width: 100%; }
  .pick-ops .btn { flex: 1 1 100%; }
  .title-input { flex: 1 1 100%; }
  .searchbar .btn { padding: 0 12px; }
  .topbar { padding: 10px 14px; }
  .brand h1 { font-size: 15px; }
  .brand .sub { display: none; }
  .user-chip { font-size: 11.5px; padding: 4px 8px; }
  .icon-btn { padding: 5px 9px; font-size: 12px; }

  /* 表格在窄屏折叠为卡片 */
  thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tbody tr {
    border: 1px solid var(--line); border-radius: 12px;
    padding: 8px 10px; margin-bottom: 10px; background: #fff;
  }
  tbody td { border: none; padding: 3px 0; }
  tbody td[data-label]::before {
    content: attr(data-label);
    display: inline-block;
    min-width: 62px;
    color: var(--muted);
    font-size: 11.5px;
  }
  .title-cell .t { display: inline-block; }
  .progress-cell { min-width: 0; margin-top: 4px; }
  .action-cell { margin-top: 6px; }
  .action-cell .btn, .action-cell a.btn { width: auto; }
  .queue-actions .btn { flex: 1; }
  .modal-actions .btn { flex: 1 1 45%; }
  .auth-card { padding: 22px 18px; }
}
