:root {
  --blue: #2f6bff;
  --blue-deep: #1e4fd8;
  --ink: #16181d;
  --muted: #8d8676;
  --bg: #f5f0e6;
  --card: #ffffff;
  --line: #ebe3d4;
  --danger: #d45743;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

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

button,
input {
  font-family: inherit;
}

/* ---------- buttons ---------- */

.btn {
  height: 38px;
  padding: 0 16px;
  border-radius: 9px;
  border: 1px solid #e7e0d2;
  background: #fff;
  color: #55503f;
  font-size: 13.5px;
  cursor: pointer;
  transition: all 0.16s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  border-color: #d3c9b6;
  background: #fbf8f2;
}

.btn.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.btn.primary:hover {
  background: var(--blue-deep);
  border-color: var(--blue-deep);
}

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

.btn.ghost {
  background: transparent;
}

.btn.small {
  height: 32px;
  padding: 0 12px;
  font-size: 12.5px;
  border-radius: 8px;
}

.btn.block {
  width: 100%;
  height: 44px;
  font-size: 14.5px;
}

.btn.danger-text {
  border: none;
  background: none;
  color: var(--danger);
  padding: 0 8px;
  height: 30px;
}

.btn.danger-text:hover {
  background: #fdf1ee;
  border-radius: 7px;
}

.icon-btn {
  width: 30px;
  height: 30px;
  border: none;
  background: none;
  border-radius: 8px;
  font-size: 20px;
  line-height: 1;
  color: #9a9488;
  cursor: pointer;
}

.icon-btn:hover {
  background: #f5f1e8;
  color: #55503f;
}

/* ---------- login ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(1100px 520px at 50% -10%, #d9e5ff 0%, transparent 62%), var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 34px 30px 26px;
  box-shadow: 0 20px 60px rgba(78, 63, 35, 0.1);
  display: flex;
  flex-direction: column;
}

.login-badge {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  background: linear-gradient(135deg, #3474ff, #1e4fd8);
  color: #fff;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.25);
}

.login-badge svg {
  width: 22px;
  height: 22px;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
  letter-spacing: 0.01em;
}

.login-sub {
  margin: 0 0 26px;
  font-size: 13px;
  color: var(--muted);
}

.field {
  display: block;
  margin-bottom: 16px;
}

.field > span {
  display: block;
  font-size: 13px;
  color: #5f5a4c;
  margin-bottom: 7px;
  font-weight: 500;
}

.field > span i {
  color: var(--danger);
  font-style: normal;
}

.field input[type="text"],
.field input[type="password"] {
  width: 100%;
  height: 42px;
  border: 1px solid #e4dccd;
  border-radius: 9px;
  padding: 0 13px;
  font-size: 14px;
  color: var(--ink);
  background: #fdfcf8;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.field input::placeholder {
  color: #b3ac9d;
}

.field input:focus {
  border-color: #9db9f7;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(47, 107, 255, 0.12);
}

.login-error,
.form-error {
  margin: 0 0 14px;
  padding: 9px 12px;
  border-radius: 8px;
  background: #fdf1ee;
  border: 1px solid #f4d8d1;
  color: #c0503d;
  font-size: 12.5px;
}

.back-link {
  margin-top: 18px;
  text-align: center;
  font-size: 12.5px;
  color: #9a9488;
  text-decoration: none;
}

.back-link:hover {
  color: var(--blue-deep);
}

/* ---------- topbar ---------- */

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

.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px;
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
}

.topbar-brand .logo {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, #3474ff, #1e4fd8);
  color: #fff;
  display: grid;
  place-items: center;
}

.topbar-brand .logo svg {
  width: 15px;
  height: 15px;
}

.topbar-brand em {
  font-style: normal;
  font-size: 12px;
  font-weight: 500;
  color: #a49c8c;
  padding-left: 10px;
  border-left: 1px solid #eee7d9;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar-actions a {
  font-size: 13px;
  color: #6f6a5e;
  text-decoration: none;
}

.topbar-actions a:hover {
  color: var(--blue-deep);
}

/* ---------- main ---------- */

.admin-main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 30px 24px 70px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.page-head h2 {
  margin: 0 0 6px;
  font-size: 22px;
}

.page-head p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.table-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}

.table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid #f1ebdf;
  font-size: 13px;
  color: #5f5a4c;
  background: #fcfaf5;
}

.table-head b {
  color: var(--ink);
}

.table-head .hint {
  font-size: 12px;
  color: #a49c8c;
}

.table-scroll {
  overflow-x: auto;
}

.merchant-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.merchant-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 500;
  color: #9a9488;
  padding: 11px 18px;
  border-bottom: 1px solid #f1ebdf;
  white-space: nowrap;
}

.merchant-table th.right {
  text-align: right;
}

.merchant-table td {
  padding: 13px 18px;
  border-bottom: 1px solid #f6f2e9;
  font-size: 13.5px;
  vertical-align: middle;
}

.merchant-table tr:last-child td {
  border-bottom: none;
}

.merchant-table tbody tr:hover {
  background: #fefcf8;
}

.cell-merchant {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.cell-avatar {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  flex: none;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
}

.cell-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cell-name {
  font-weight: 600;
  color: #1a1c21;
  white-space: nowrap;
}

.cell-code {
  color: #7d7668;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.cell-link {
  max-width: 300px;
}

.cell-link a,
.cell-link span {
  display: inline-block;
  max-width: 100%;
  color: #5a6c9e;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  font-size: 12.5px;
}

.cell-link span {
  color: #b3ac9d;
}

.cell-link a:hover {
  text-decoration: underline;
}

.cell-actions {
  text-align: right;
  white-space: nowrap;
}

.cell-actions .btn {
  height: 30px;
  padding: 0 12px;
  font-size: 12.5px;
  border-radius: 7px;
}

.table-empty {
  padding: 48px 20px;
  text-align: center;
  color: #a49c8c;
  font-size: 13.5px;
}

/* ---------- switch ---------- */

.switch {
  position: relative;
  display: inline-flex;
  width: 38px;
  height: 22px;
  flex: none;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #ddd6c8;
  cursor: pointer;
  transition: background 0.18s ease;
}

.slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
  transition: transform 0.18s ease;
}

.switch input:checked + .slider {
  background: var(--blue);
}

.switch input:checked + .slider::before {
  transform: translateX(16px);
}

/* ---------- modal ---------- */

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 17, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
  backdrop-filter: blur(2px);
}

.modal {
  width: 100%;
  max-width: 470px;
  max-height: 92vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 24px 70px rgba(28, 25, 17, 0.28);
  animation: modal-in 0.18s ease;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 12px;
}

.modal-head h3 {
  margin: 0;
  font-size: 17px;
}

.modal-body {
  padding: 6px 22px 8px;
}

.avatar-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 0 20px;
}

.avatar-preview {
  width: 62px;
  height: 62px;
  border-radius: 13px;
  background: var(--blue);
  color: #fff;
  font-size: 24px;
  font-weight: 600;
  display: grid;
  place-items: center;
  overflow: hidden;
  flex: none;
}

.avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.avatar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.avatar-tip {
  width: 100%;
  font-size: 11.5px;
  color: #b3ac9d;
}

.switch-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 13px 14px;
  border: 1px solid #f0e9dc;
  background: #fdfbf6;
  border-radius: 10px;
  margin-bottom: 16px;
}

.switch-field > div > span {
  font-size: 13px;
  color: #5f5a4c;
  font-weight: 500;
}

.switch-field > div > p {
  margin: 4px 0 0;
  font-size: 11.5px;
  color: #a49c8c;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 22px 20px;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translateX(-50%);
  background: #1f232b;
  color: #fff;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 9px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
  z-index: 80;
  animation: toast-in 0.2s ease;
}

.toast.error {
  background: #b8462f;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* ---------- admin tabs ---------- */

.admin-tabs {
  border-top: 1px solid #f4eee2;
}

.admin-tabs-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
}

.admin-tabs button {
  position: relative;
  height: 46px;
  padding: 0 14px;
  border: none;
  background: none;
  color: #7d7668;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color 0.16s ease;
}

.admin-tabs button:hover {
  color: var(--blue-deep);
}

.admin-tabs button.active {
  color: var(--blue);
  font-weight: 600;
}

.admin-tabs button.active::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 0;
  height: 2px;
  border-radius: 2px;
  background: var(--blue);
}

.badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #e05252;
  color: #fff;
  font-size: 11px;
  font-style: normal;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
}

/* ---------- extra form controls ---------- */

.field input[type="number"],
.field select {
  width: 100%;
  height: 42px;
  border: 1px solid #e4dccd;
  border-radius: 9px;
  padding: 0 13px;
  font-size: 14px;
  color: var(--ink);
  background: #fdfcf8;
  outline: none;
  font-family: inherit;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.field select {
  cursor: pointer;
}

.field input[type="number"]:focus,
.field select:focus {
  border-color: #9db9f7;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(47, 107, 255, 0.12);
}

/* ---------- keys ---------- */

.gen-card {
  padding: 18px;
  margin-bottom: 18px;
  overflow: visible;
}

.key-gen {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) auto;
  align-items: end;
  gap: 14px;
}

.key-gen .field {
  margin-bottom: 0;
}

.new-keys {
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px dashed #cfdcf7;
  border-radius: 10px;
  background: #f7faff;
}

.new-keys-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 12.5px;
  color: #5a6c9e;
}

.new-keys pre {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.8;
  color: #22305a;
  white-space: pre-wrap;
  word-break: break-all;
}

.key-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  color: #22305a;
  background: #f6f8fd;
  border: 1px solid #e4eaf8;
  border-radius: 6px;
  padding: 3px 7px;
  cursor: pointer;
  white-space: nowrap;
}

.key-code:hover {
  border-color: #9db9f7;
}

/* ---------- settings ---------- */

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.settings-card {
  padding: 20px;
  overflow: visible;
}

.settings-card h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.settings-desc {
  margin: 0 0 18px;
  font-size: 12.5px;
  color: #a49c8c;
  line-height: 1.6;
}

.settings-tip {
  margin: 4px 0 0;
  font-size: 12px;
  color: #8d8676;
  line-height: 1.7;
  word-break: break-all;
}

.settings-tip code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  color: #2c5bc4;
  background: #eef4ff;
  border-radius: 5px;
  padding: 2px 6px;
}

.settings-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  margin-top: 18px;
}

.settings-actions .form-error {
  margin: 0;
}

/* ---------- status pills ---------- */

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  background: #f1f4fd;
  color: #4a5c8f;
  font-size: 11.5px;
  line-height: 1.7;
  white-space: nowrap;
}

.pill.pending {
  background: #fff5e6;
  color: #b7791f;
}

.pill.rejected {
  background: #fdf0ee;
  color: #b94334;
}

.pill.used {
  background: #f1f4fd;
  color: #6b7ba6;
}

.owner-tag {
  margin-left: 8px;
  font-style: normal;
  font-size: 11px;
  font-weight: 500;
  color: #8d8676;
  background: #f6f2e9;
  border-radius: 999px;
  padding: 2px 7px;
}

.cell-time {
  color: #8d8676;
  font-size: 12.5px;
  white-space: nowrap;
}

.cell-done {
  color: #b3ac9d;
  font-size: 12.5px;
}

/* ---------- responsive ---------- */

@media (max-width: 860px) {
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar-inner,
  .admin-main,
  .admin-tabs-inner {
    padding-left: 16px;
    padding-right: 16px;
  }

  .topbar-inner {
    height: 56px;
  }

  .topbar-brand em {
    display: none;
  }

  .page-head {
    flex-direction: column;
    align-items: stretch;
  }

  .page-head .btn {
    align-self: flex-start;
  }

  .table-head .hint {
    display: none;
  }

  .login-card {
    padding: 28px 22px 22px;
  }

  .key-gen {
    grid-template-columns: 1fr;
  }
}
