:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --bg: #f2f5f9;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --success: #16a34a;
  --success-light: #dcfce7;
  --border: #e5e7eb;
  --radius: 14px;
  --shadow: 0 4px 16px rgba(17, 24, 39, 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100%;
}

.container-wide {
  max-width: 1200px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 16px;
}

/* ---------- 通用组件 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 12px;
  padding: 12px 20px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  user-select: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  width: 100%;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-ghost {
  background: var(--primary-light);
  color: var(--primary-dark);
  width: 100%;
}

.btn-danger {
  background: var(--danger-light);
  color: var(--danger);
}

.btn-sm {
  padding: 7px 12px;
  font-size: 13px;
  border-radius: 8px;
  width: auto;
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  font-size: 16px;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color 0.15s;
}

.input:focus {
  border-color: var(--primary);
}

.input::placeholder {
  color: #9ca3af;
}

label.field-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin: 14px 0 6px;
}

label.field-label .req {
  color: var(--danger);
  margin-left: 2px;
}

.note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  margin: 18px 0;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ---------- 客户登记页 ---------- */

.hero-card {
  text-align: center;
  margin-top: 24px;
}

.hero-icon {
  width: 76px;
  height: 76px;
  border-radius: 22px;
  background: linear-gradient(135deg, #2563eb, #60a5fa);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 18px;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.3);
}

.hero-icon svg {
  width: 40px;
  height: 40px;
}

.hero-card h1 {
  font-size: 24px;
  margin-bottom: 8px;
}

.hero-card .desc {
  color: var(--muted);
  font-size: 15px;
  margin-bottom: 26px;
}

.btn-lg {
  padding: 16px 20px;
  font-size: 18px;
  border-radius: 14px;
}

.manual-row {
  display: flex;
  gap: 10px;
}

.manual-row .input {
  flex: 1;
  min-width: 0;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.manual-row .btn {
  width: auto;
  flex-shrink: 0;
  white-space: nowrap;
}

.scan-title {
  text-align: center;
  font-size: 17px;
  margin-bottom: 14px;
}

#scanner {
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: #111827;
  min-height: 260px;
}

#scanner video {
  width: 100%;
  object-fit: cover;
}

.scan-hint {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin: 12px 0 4px;
}

.barcode-chip {
  background: var(--primary-light);
  color: var(--primary-dark);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 15px;
  text-align: center;
  word-break: break-all;
}

.barcode-chip b {
  letter-spacing: 2px;
}

.form-actions {
  margin-top: 22px;
}

.state-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  font-size: 36px;
}

.state-icon.error {
  background: var(--danger-light);
}

.state-icon.success {
  background: var(--success-light);
}

.state-title {
  text-align: center;
  font-size: 21px;
  margin-bottom: 10px;
}

.state-desc {
  text-align: center;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.7;
  margin-bottom: 22px;
  word-break: break-all;
}

.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  background: #111827;
  color: #fff;
  padding: 12px 22px;
  border-radius: 10px;
  font-size: 14px;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(4px);
}

.warn-box {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  color: #92400e;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.7;
  margin-bottom: 12px;
}

/* ---------- 管理后台 ---------- */

.admin-header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.admin-header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.admin-title {
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-title .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--success);
  display: inline-block;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.stat-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.stat-card .num {
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
}

.stat-card .label {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  border-bottom: 2px solid var(--border);
}

.tab {
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.toolbar .input {
  width: 260px;
}

.toolbar .input.small {
  width: 130px;
}

.toolbar .spacer {
  flex: 1;
}

.table-wrap {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 860px;
}

.data-table th {
  background: #f8fafc;
  text-align: left;
  padding: 12px 14px;
  font-weight: 700;
  color: #374151;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
  word-break: break-all;
}

.data-table tr:hover td {
  background: #f8fafc;
}

.mono {
  font-family: "SF Mono", Consolas, "Courier New", monospace;
  letter-spacing: 1px;
  font-weight: 600;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge.bound {
  background: var(--success-light);
  color: var(--success);
}

.badge.unbound {
  background: #fef3c7;
  color: #b45309;
}

.empty-row {
  text-align: center;
  color: var(--muted);
  padding: 36px 0 !important;
}

/* ---------- 收集字段配置 ---------- */

.field-table .input {
  padding: 8px 10px;
  font-size: 13px;
  border-radius: 8px;
}

.field-table .input.small {
  width: 100%;
  min-width: 120px;
}

.field-table .f-type {
  width: 120px !important;
  min-width: 120px;
  cursor: pointer;
}

.field-table .f-options {
  min-width: 220px;
}

.field-table .row-actions {
  display: flex;
  gap: 4px;
}

.field-table .row-actions .note {
  margin-left: 4px;
}

.icon-btn {
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  line-height: 1;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: #f8fafc;
  color: var(--primary);
  border-color: var(--primary);
}

/* ---------- 选项编辑弹窗 ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, 0.45);
}

.modal-box {
  position: relative;
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 460px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding: 22px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.22);
}

.modal-box.modal-lg {
  max-width: 600px;
}

.modal-box h3 {
  font-size: 17px;
  margin-bottom: 6px;
}

.modal-box .input {
  margin-top: 12px;
  resize: vertical;
  min-height: 180px;
  line-height: 1.7;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}

.modal-actions .btn {
  width: auto;
}

/* ---------- 登记详情卡片 ---------- */

.detail-box {
  max-width: 520px;
}

.detail-barcode {
  background: var(--primary-light);
  color: var(--primary-dark);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 17px;
  text-align: center;
  letter-spacing: 2px;
  margin: 14px 0 4px;
  word-break: break-all;
}

.detail-list {
  margin-top: 6px;
}

.detail-row {
  padding: 10px 2px;
  border-bottom: 1px solid #f1f5f9;
}

.detail-row:last-child {
  border-bottom: none;
}

.detail-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 3px;
}

.detail-value {
  display: block;
  font-size: 15px;
  font-weight: 600;
  word-break: break-all;
}

.row-actions-cell {
  display: flex;
  gap: 6px;
  white-space: nowrap;
}

.pager {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}

/* ---------- 客户表单：单选 / 多选 ---------- */

.option-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 6px 0 2px;
}

.option-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
}

.option-item input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  flex-shrink: 0;
}

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  text-align: center;
}

.login-card h1 {
  font-size: 22px;
  margin-bottom: 6px;
}

.login-card .sub {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 24px;
}

.login-card .input {
  margin-bottom: 14px;
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 20px 0 30px;
}

@media (max-width: 640px) {
  .container {
    padding: 12px;
  }
  .card {
    padding: 20px 16px;
  }
  .toolbar .input {
    width: 100%;
  }
  .table-wrap {
    border-radius: 10px;
  }
}

/* 手机端：客户信息列表改为卡片式 */
@media (max-width: 640px) {
  #tabRecords .table-wrap {
    background: transparent;
    box-shadow: none;
    overflow: visible;
  }
  #tabRecords table.data-table {
    min-width: 0;
  }
  #recordsHead {
    display: none;
  }
  #recordsBody tr {
    display: block;
    background: #fff;
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 10px 14px;
    margin-bottom: 10px;
  }
  #recordsBody tr:hover td {
    background: transparent;
  }
  #recordsBody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 7px 0;
    border-bottom: 1px solid #f1f5f9;
  }
  #recordsBody tr td:last-child {
    border-bottom: none;
  }
  #recordsBody td[data-label]::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 13px;
    flex-shrink: 0;
  }
  #recordsBody td.cell-check {
    justify-content: flex-start;
    padding-top: 0;
  }
  #recordsBody td.row-actions-cell {
    justify-content: flex-end;
    gap: 8px;
  }
  #recordsBody td.row-actions-cell .btn {
    padding: 9px 18px;
  }
  #recordsBody td.empty-row {
    display: block;
    text-align: center;
    border-bottom: none;
  }
  #recordsBody td.empty-row::before {
    content: none;
  }
  .pager {
    justify-content: center;
  }
}

#scanner {
  height: 300px;
  min-height: 0;
}
#scanner video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
}
