:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --border: #e5e9f0;
  --border-strong: #d5dce6;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff5ff;
  --accent: #0891b2;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .05), 0 1px 2px rgba(16, 24, 40, .03);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.app { max-width: 1320px; margin: 0 auto; padding: 24px 28px 60px; }

/* ---------- 顶部 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px; margin-bottom: 20px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 46px; height: 46px; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(140deg, #2563eb, #0ea5e9);
  color: #fff; font-size: 22px; font-weight: 700;
  border-radius: 12px; box-shadow: 0 6px 16px rgba(37, 99, 235, .22);
}
.brand-text h1 { margin: 0; font-size: 21px; letter-spacing: -.3px; }
.brand-text p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.stat-chips { display: flex; gap: 10px; }
.chip {
  background: var(--card); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 999px; color: var(--muted);
  font-size: 13px; box-shadow: var(--shadow); white-space: nowrap;
}
.chip b { color: var(--text); font-size: 15px; margin-left: 4px; }
.chip-accent { border-color: #bfdbfe; background: var(--primary-soft); }
.chip-accent b { color: var(--primary); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: 4px; border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.tab {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  padding: 11px 20px 13px; font-size: 14px; color: var(--muted);
  font-weight: 600; border-bottom: 2px solid transparent;
  margin-bottom: -1px; transition: .15s;
}
.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- 卡片 ---------- */
.panel { display: none; }
.panel.active { display: block; }
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 22px; margin-bottom: 18px;
}
.card.narrow { max-width: 720px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; margin-bottom: 16px; flex-wrap: wrap;
}
.card-head h2 { margin: 0; font-size: 16px; font-weight: 700; }
.hint { color: var(--muted); font-size: 12.5px; }
.badge {
  display: inline-block; margin-left: 6px; padding: 1px 9px;
  background: var(--primary-soft); color: var(--primary);
  border-radius: 999px; font-size: 12px; font-weight: 600; vertical-align: 1px;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- 表单 ---------- */
textarea, input[type="text"], input[type="number"], input[type="search"], select {
  width: 100%; border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 9px 11px; font: inherit; color: var(--text); background: #fff;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; line-height: 1.6; }
textarea:focus, input:focus, select:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .1);
}
textarea::placeholder, input::placeholder { color: #aab2c0; }
.form-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px 18px;
}
@media (max-width: 1050px) { .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 620px) { .form-grid { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 12.5px; font-weight: 600; color: #475569; }
.field i { color: var(--danger); font-style: normal; font-size: 11px; }

.row { display: flex; align-items: center; }
.row.gap { gap: 10px; margin-top: 12px; }
.row.end { justify-content: flex-end; gap: 10px; margin-top: 16px; }
.row.between { justify-content: space-between; }
.tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tools .search { width: 260px; }

.btn {
  appearance: none; border: 1px solid transparent; cursor: pointer;
  padding: 9px 16px; border-radius: 8px; font: inherit; font-weight: 600;
  font-size: 13px; transition: .15s; white-space: nowrap;
}
.btn.primary { background: var(--primary); color: #fff; box-shadow: 0 2px 6px rgba(37,99,235,.2); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost { background: #fff; color: #475569; border-color: var(--border-strong); }
.btn.ghost:hover { background: #f8fafc; border-color: #bcc7d6; }
.btn.danger { background: var(--danger-soft); color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: #fee2e2; }
.btn.copy-btn { background: #ecfeff; color: #0e7490; border-color: #a5e3ec; }
.btn.copy-btn:hover { background: #cffafe; border-color: #67e8f9; }
.btn.small { padding: 6px 12px; font-size: 12.5px; }
.btn.large { padding: 11px 24px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.tip { margin: 12px 0 0; color: var(--muted); font-size: 12.5px; line-height: 1.6; }
.inbox-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-top: 12px; padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.inbox-bar .hint { color: #0e7490; font-weight: 600; }
.inbox-bar .hint.pending { color: var(--warn); }
.inbox-bar .hint.offline { color: #9aa3b2; font-weight: 400; }
.steps { margin: 0; padding-left: 22px; color: #475569; }
.steps li { margin-bottom: 8px; font-size: 13px; }
.steps b { color: var(--text); }
.notice {
  margin-top: 16px; padding: 12px 14px; border-radius: 8px;
  background: var(--primary-soft); border: 1px solid #dbeafe;
  display: flex; flex-direction: column; gap: 2px; font-size: 12.5px;
}
.notice strong { color: #1e40af; }
.notice span { color: #475569; }

/* ---------- 表格 ---------- */
.sort-hint { color: #0e7490; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.letter-index {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-bottom: 12px; padding: 10px 12px;
  background: #f8fafc; border: 1px solid var(--border); border-radius: 8px;
}
.letter-btn {
  appearance: none; cursor: pointer; border: 1px solid var(--border-strong);
  background: #fff; color: #475569; border-radius: 6px;
  padding: 3px 9px; font: inherit; font-size: 12px; font-weight: 700;
  transition: .15s;
}
.letter-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.letter-btn small { font-weight: 400; color: #9aa3b2; margin-left: 2px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th {
  text-align: left; background: #f8fafc; color: #475569; font-weight: 700;
  padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.grid td {
  padding: 9px 12px; border-bottom: 1px solid #eef1f5; vertical-align: middle;
}
table.grid tbody tr:last-child td { border-bottom: 0; }
table.grid tbody tr:hover { background: #fafcff; }
table.grid tbody tr.group-row { background: #eff6ff; }
table.grid tbody tr.group-row:hover { background: #eff6ff; }
table.grid tbody tr.group-row td {
  padding: 6px 12px; color: var(--primary); font-weight: 800;
  font-size: 12.5px; letter-spacing: .5px; border-bottom: 1px solid #dbeafe;
}
table.grid tbody tr.match-sep td {
  padding: 8px 12px; background: #fffbeb; color: var(--warn);
  font-weight: 700; font-size: 12.5px; border-bottom: 1px solid #fde68a;
}
.col-check { width: 54px; text-align: center !important; }
.col-name { width: 110px; }
.col-phone { width: 140px; }
.col-status { width: 150px; }
.col-note { width: 190px; }
table.grid th.col-note { background: #d1fae5; color: #047857; }
table.grid td.note-cell { background: #f0fdf4; }
.col-op { width: 110px; }
.col-idx { width: 56px; }
.col-code { width: 72px; }
.code-cell { color: var(--primary); font-weight: 700; font-variant-numeric: tabular-nums; font-size: 12.5px; }
table.grid tbody tr.row-locked { background: #f3f4f6; }
table.grid tbody tr.row-locked td { color: #9aa3b2; }
table.grid tbody tr.row-locked td.name-cell,
table.grid tbody tr.row-locked td.phone-cell,
table.grid tbody tr.row-locked td.code-cell { color: #9aa3b2; }
.lock-tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  background: #e5e7eb; color: #6b7280; font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
table.grid td.cell-check { text-align: center; }
table.grid td input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); }
table.grid td input[type="text"] { padding: 5px 8px; font-size: 13px; }
table.grid td.name-cell { font-weight: 600; }
table.grid td.phone-cell { font-variant-numeric: tabular-nums; color: #374151; }
table.grid td.addr-cell { color: #475569; word-break: break-all; }
table.grid td input.note-inline,
table.grid td input.note-input {
  min-width: 120px; background: #ecfdf5; border-color: #a7f3d0; color: #065f46;
}
table.grid td input.note-inline:focus,
table.grid td input.note-input:focus { background: #fff; border-color: var(--success); }
.wx-nick {
  display: inline-block; max-width: 100%; padding: 2px 9px; border-radius: 999px;
  background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7;
  font-size: 12.5px; font-weight: 700; word-break: break-all;
}
.th-tip { font-weight: 400; color: #9aa3b2; font-size: 11px; }
.link-btn {
  appearance: none; border: 0; background: none; cursor: pointer;
  color: var(--primary); font-size: 12.5px; padding: 3px 6px; font-weight: 600;
}
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--danger); }
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
}
.tag.ok { background: #ecfdf5; color: var(--success); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.dup { background: #fef2f2; color: var(--danger); }
/* 地址自动补全省份标记 */
.addr-edit-wrap { display: flex; flex-direction: column; gap: 3px; min-width: 180px; }
.addr-edit-wrap input[type="text"] { width: 100%; }
.addr-edit-wrap input.auto-fixed { border-color: #93c5fd; background: #f0f7ff; }
.addr-fix-tip {
  display: inline-block; align-self: flex-start;
  font-size: 11px; color: #2563eb; background: #eff6ff;
  border: 1px solid #dbeafe; border-radius: 4px; padding: 1px 6px;
  cursor: help;
}
.empty {
  text-align: center; padding: 34px 16px; color: #9aa3b2; font-size: 13px;
}
.footer-row { margin-top: 14px; }
.generate-row { margin-top: 18px; flex-wrap: wrap; }

/* ---------- 备份 ---------- */
.rule-list {
  display: grid; gap: 10px;
}
.rule-list > div {
  display: flex; gap: 16px; align-items: baseline;
  padding: 10px 14px; background: #f8fafc;
  border: 1px solid var(--border); border-radius: 8px; font-size: 13px;
}
.rule-list b {
  flex: none; width: 64px; color: var(--primary); font-weight: 700;
}
.rule-list span { color: #475569; }
.rule-list span.rule-hl { color: #0e7490; font-weight: 600; }
.col-goods { width: 90px; }

.section-desc { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.backup-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.danger-zone {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  margin-top: 24px; padding: 16px; border: 1px solid #fecaca;
  background: var(--danger-soft); border-radius: 10px;
}
.danger-zone div { display: flex; flex-direction: column; }
.danger-zone strong { color: #991b1b; font-size: 13.5px; }
.danger-zone span { color: #b91c1c; font-size: 12px; opacity: .85; }
.version-note { margin-top: 20px; color: #9aa3b2; font-size: 12px; }

/* ---------- 弹层 / 提示 ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .38);
  display: grid; place-items: center; z-index: 50; padding: 20px;
}
.modal[hidden] { display: none; }
.modal-box {
  background: #fff; border-radius: 14px; width: min(520px, 100%);
  box-shadow: 0 20px 60px rgba(15, 23, 42, .2); overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 16px; }
.icon-btn {
  appearance: none; border: 0; background: none; cursor: pointer;
  font-size: 24px; line-height: 1; color: var(--muted); padding: 0 4px;
}
.modal-body { padding: 20px; display: grid; gap: 14px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--border); background: #fafcff;
}
.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translate(-50%, 20px);
  background: #111827; color: #fff; padding: 11px 20px; border-radius: 9px;
  font-size: 13.5px; box-shadow: 0 10px 30px rgba(0,0,0,.2);
  opacity: 0; pointer-events: none; transition: .25s; z-index: 100;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #b91c1c; }
.toast.success { background: #15803d; }
