:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .06);
  --shadow: 0 4px 12px rgba(0, 0, 0, .08);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .12);
}

* { 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;
  font-size: 14px;
  line-height: 1.6;
  color: var(--gray-800);
  background: var(--gray-50);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------- 顶部导航 ---------------- */
.app-header {
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.app-header-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 60px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 16px;
  font-weight: 700;
  color: var(--gray-900);
  white-space: nowrap;
}

.brand-icon {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700;
}

.nav {
  display: flex;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
}

.nav a {
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  color: var(--gray-600);
  font-weight: 500;
  white-space: nowrap;
  transition: all .15s;
}

.nav a:hover { background: var(--gray-100); color: var(--gray-900); text-decoration: none; }
.nav a.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }

.header-user {
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
}

.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 12px;
  background: var(--gray-100);
  border-radius: 999px;
  font-size: 13px;
}

.user-role {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

/* ---------------- 布局 ---------------- */
.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.container.narrow { max-width: 780px; }
.container.mid { max-width: 1000px; }

.page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 4px;
}

.page-desc {
  color: var(--gray-500);
  margin-bottom: 20px;
  font-size: 13px;
}

.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 900px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .app-header-inner { gap: 12px; padding: 0 12px; }
  .header-user .user-chip span.uname { display: none; }
}

/* ---------------- 卡片 ---------------- */
.card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card + .card, .card + .grid, .grid + .card { margin-top: 18px; }

.card-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.card-title { font-size: 15px; font-weight: 600; color: var(--gray-900); }
.card-body { padding: 18px; }
.card-body.pad-0 { padding: 0; }

/* ---------------- 表单 ---------------- */
.form-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

@media (max-width: 700px) { .form-row { grid-template-columns: 1fr; } }

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 6px;
}

.field label .req { color: var(--danger); margin-left: 3px; }
.field .hint { font-size: 12px; color: var(--gray-400); margin-top: 4px; }

input[type="text"],
input[type="tel"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--gray-900);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

input:disabled, select:disabled {
  background: var(--gray-100);
  color: var(--gray-500);
  cursor: not-allowed;
}

textarea { resize: vertical; min-height: 70px; }

/* ---------------- 按钮 ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
  background: var(--gray-100);
  color: var(--gray-700);
}

.btn:hover { background: var(--gray-200); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #15803d; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }

.btn-outline { background: #fff; border-color: var(--gray-300); color: var(--gray-700); }
.btn-outline:hover:not(:disabled) { background: var(--gray-50); border-color: var(--gray-400); }

.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-lg { padding: 12px 22px; font-size: 15px; }
.btn-block { width: 100%; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------------- 表格 ---------------- */
.table-wrap { overflow-x: auto; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

table.data th {
  text-align: left;
  padding: 11px 14px;
  background: var(--gray-50);
  color: var(--gray-600);
  font-weight: 600;
  font-size: 12.5px;
  white-space: nowrap;
  border-bottom: 1px solid var(--gray-200);
}

table.data td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

table.data tbody tr:hover { background: var(--gray-50); }
table.data tbody tr:last-child td { border-bottom: none; }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.code-text { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 600; letter-spacing: .5px; color: var(--primary); }

/* ---------------- 徽标 ---------------- */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.7;
}

.badge-active { background: var(--primary-light); color: var(--primary); }
.badge-used { background: var(--success-light); color: var(--success); }
.badge-revoked { background: var(--gray-100); color: var(--gray-500); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-warning { background: var(--warning-light); color: var(--warning); }

/* ---------------- 统计卡 ---------------- */
.stat {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 18px;
}

.stat-label { font-size: 13px; color: var(--gray-500); margin-bottom: 6px; }
.stat-value { font-size: 26px; font-weight: 700; color: var(--gray-900); line-height: 1.2; }
.stat-value.primary { color: var(--primary); }
.stat-value.success { color: var(--success); }
.stat-value.warning { color: var(--warning); }
.stat-sub { font-size: 12px; color: var(--gray-400); margin-top: 4px; }

/* ---------------- 券码展示 ---------------- */
.coupon-result {
  text-align: center;
  padding: 30px 20px;
  background: linear-gradient(135deg, #eff6ff, #f5f3ff);
  border: 1px dashed var(--primary);
  border-radius: var(--radius);
  margin-bottom: 18px;
}

.coupon-code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: 4px;
  color: var(--primary-dark);
  margin: 10px 0;
  word-break: break-all;
}

/* ---------------- 提示条 ---------------- */
.alert {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}

.alert-info { background: var(--primary-light); color: var(--primary-dark); border-color: #bfdbfe; }
.alert-success { background: var(--success-light); color: #15803d; border-color: #bbf7d0; }
.alert-warning { background: var(--warning-light); color: #b45309; border-color: #fde68a; }
.alert-danger { background: var(--danger-light); color: #b91c1c; border-color: #fecaca; }

/* ---------------- 空状态 / 加载 ---------------- */
.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--gray-400);
}

.empty-icon { font-size: 36px; margin-bottom: 10px; opacity: .5; }

.loading { text-align: center; padding: 40px; color: var(--gray-400); }

.spinner {
  display: inline-block;
  width: 22px; height: 22px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- 分页 ---------------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-top: 1px solid var(--gray-200);
  flex-wrap: wrap;
}

.pagination .info { font-size: 13px; color: var(--gray-500); }
.pagination .controls { display: flex; gap: 6px; align-items: center; }

/* ---------------- 登录页 ---------------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a8a, #4c1d95 60%, #6d28d9);
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
}

.login-logo {
  width: 52px; height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 700;
  margin: 0 auto 16px;
}

.login-title { text-align: center; font-size: 20px; font-weight: 700; color: var(--gray-900); }
.login-sub { text-align: center; color: var(--gray-500); font-size: 13px; margin-bottom: 26px; }

/* ---------------- Toast ---------------- */
#toast-wrap {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  pointer-events: none;
}

.toast {
  padding: 11px 20px;
  border-radius: 999px;
  background: var(--gray-900);
  color: #fff;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn .25s ease;
  max-width: 90vw;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.danger { background: var(--danger); }
.toast.warning { background: var(--warning); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------------- 模态框 ---------------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
  animation: fadeIn .15s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow: auto;
  animation: modalIn .2s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(.96); }
  to { opacity: 1; transform: scale(1); }
}

.modal-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  font-weight: 700;
  font-size: 15px;
}

.modal-body { padding: 20px; }
.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--gray-200);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ---------------- 详情列表 ---------------- */
.detail-grid {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 10px 16px;
  font-size: 14px;
}

.detail-grid dt { color: var(--gray-500); }
.detail-grid dd { color: var(--gray-900); font-weight: 500; word-break: break-all; }

.divider { height: 1px; background: var(--gray-200); margin: 16px 0; }

.text-muted { color: var(--gray-500); }
.muted { color: var(--gray-500); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { margin-bottom: 0; min-width: 140px; }
.hidden { display: none !important; }

/* ---------------- 券码项目选择卡片 ---------------- */
.project-list { display: flex; flex-direction: column; gap: 10px; }

.project-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all .15s;
  background: #fff;
}

.project-option:hover { border-color: var(--primary); background: var(--primary-light); }
.project-option.selected { border-color: var(--primary); background: var(--primary-light); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.project-option input[type="radio"] { width: 17px; height: 17px; margin: 0; flex: none; accent-color: var(--primary); cursor: pointer; }
.project-option .po-main { flex: 1; min-width: 0; }
.project-option .po-name { font-weight: 600; color: var(--gray-900); }
.project-option .po-desc { font-size: 12px; color: var(--gray-500); margin-top: 2px; }
.project-option .po-amount { font-weight: 700; color: var(--primary); font-size: 17px; white-space: nowrap; }

/* ---------------- 大输入框（核销页） ---------------- */
.code-input {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 6px;
  text-align: center;
  text-transform: uppercase;
  padding: 16px 12px !important;
}

/* ---------------- 客户档案页 ---------------- */
.search-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.search-row .field { margin-bottom: 0; flex: 1; min-width: 220px; }

.subtitle {
  color: var(--gray-500);
  font-size: 13px;
  margin-top: 4px;
}

.customer-profile { padding: 22px 22px 18px; }

.profile-head {
  display: flex;
  gap: 18px;
  align-items: center;
  flex-wrap: wrap;
}

.profile-avatar {
  width: 60px; height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 700;
  flex: none;
}

.profile-main { flex: 1; min-width: 200px; }
.profile-name { font-size: 22px; font-weight: 700; color: var(--gray-900); }
.profile-phone {
  margin-top: 6px;
  font-size: 15px;
  color: var(--gray-700);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.profile-phone .phone-text {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: 1px;
}
.profile-phone a { font-size: 13px; }
.phone-tag {
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--warning-light);
  color: var(--warning);
  font-weight: 600;
}

.profile-stat {
  display: flex;
  gap: 22px;
  flex-wrap: wrap;
}
.profile-stat .stat-item { text-align: center; min-width: 60px; }
.profile-stat .stat-num {
  font-size: 22px;
  font-weight: 700;
  color: var(--gray-900);
  line-height: 1.1;
}
.profile-stat .stat-num.stat-used    { color: var(--success); }
.profile-stat .stat-num.stat-active  { color: var(--primary); }
.profile-stat .stat-num.stat-revoked { color: var(--gray-500); }
.profile-stat .stat-label {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 2px;
}

.profile-meta {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px dashed var(--gray-200);
  display: flex;
  gap: 22px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--gray-500);
}
.profile-meta b { color: var(--gray-800); font-weight: 600; }

.code-cell {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-weight: 700;
  color: var(--primary-dark);
  letter-spacing: 1px;
  font-size: 13.5px;
}

.recent-list { padding: 8px 18px 18px; }

.recent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.recent-item {
  padding: 12px 14px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all .15s;
  background: #fff;
}
.recent-item:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.recent-name { font-size: 14px; font-weight: 600; color: var(--gray-900); }
.recent-phone {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12.5px;
  color: var(--gray-500);
  margin-top: 2px;
  letter-spacing: 1px;
}
.recent-stats { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 8px; }
.recent-stats .badge { font-size: 11px; padding: 1px 7px; }
.recent-time { font-size: 11.5px; margin-top: 6px; }

.empty-state { text-align: center; padding: 48px 20px; color: var(--gray-500); }
.empty-state .empty-icon { font-size: 36px; margin-bottom: 10px; opacity: .55; }
.empty-state .empty-text { font-size: 14px; }

@media (max-width: 720px) {
  .profile-head { gap: 12px; }
  .profile-avatar { width: 48px; height: 48px; font-size: 20px; }
  .profile-name { font-size: 18px; }
  .profile-stat { gap: 14px; width: 100%; }
  .profile-meta { gap: 12px; font-size: 12.5px; }
}

/* ---------------- 打印 ---------------- */
@media print {
  .app-header, .no-print { display: none !important; }
  body { background: #fff; }
  .coupon-code { font-size: 42px; }
}
