:root {
  --primary: #0d9488;
  --primary-dark: #0f766e;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --paper: #f5f7f9;
  --white: #ffffff;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.05);
  --shadow: 0 1px 3px rgba(16,24,40,.06), 0 10px 30px rgba(16,24,40,.07);
  --font: "Inter","PingFang SC","Microsoft YaHei","Noto Sans SC",system-ui,-apple-system,"Segoe UI",sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font: 15px/1.6 var(--font);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

header {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 60px;
  padding: 0 max(24px, calc((100vw - 1200px) / 2));
  display: flex;
  align-items: center;
  gap: 18px;
  background: rgba(255,255,255,.85);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}

header .brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -.01em;
  text-decoration: none;
  flex-shrink: 0;
}

header .brand-mark {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), #14b8a6);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  box-shadow: 0 4px 10px rgba(13,148,136,.35);
}

header .crumb {
  color: var(--muted);
  font-size: 14px;
  padding-left: 18px;
  border-left: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

header .header-link {
  margin-left: auto;
  color: var(--primary);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

header .header-link:hover { text-decoration: underline; }

main {
  max-width: 1200px;
  margin: 30px auto;
  padding: 0 22px;
}

.grid {
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
  gap: 20px;
  align-items: start;
}

.panel {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px;
  box-shadow: var(--shadow-sm);
}

.narrow { max-width: 480px; margin: 7vh auto; }

h1 {
  margin: 0 0 18px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.01em;
  line-height: 1.3;
}

h2 { margin: 0; font-size: 17px; font-weight: 600; }

label {
  display: grid;
  gap: 6px;
  margin: 14px 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

input, select, textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  background: #fff;
  font: inherit;
  color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease;
}

textarea { min-height: 96px; resize: vertical; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13,148,136,.15);
}

input[disabled], select[disabled] {
  background: #f3f4f6;
  color: var(--muted);
  cursor: not-allowed;
}

input::placeholder, textarea::placeholder { color: #9ca3af; }

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 18px;
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease, transform .06s ease;
}

button:hover, .button:hover { background: var(--primary-dark); }

button:active, .button:active { transform: translateY(1px); }

button:disabled, .button:disabled {
  opacity: .5;
  cursor: not-allowed;
}

button:disabled:hover, .button:disabled:hover { background: var(--primary); }

.button.secondary:disabled:hover, button.secondary:disabled:hover {
  background: #fff;
  border-color: var(--line-strong);
}

button:focus-visible, .button:focus-visible, a:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.button.secondary, button.secondary {
  color: var(--ink);
  background: #fff;
  border-color: var(--line-strong);
}

.button.secondary:hover, button.secondary:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
}

.button.secondary.nav-active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.button.secondary.nav-active:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

table { width: 100%; border-collapse: collapse; }

th, td {
  padding: 12px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  background: #f9fafb;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}

tbody tr { transition: background .12s ease; }
tbody tr:hover { background: #f8fafc; }
tbody tr:last-child td { border-bottom: 0; }

code {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  background: #f3f4f6;
  border-radius: 6px;
  padding: 2px 7px;
}

.error {
  color: #b91c1c;
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
}

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.inline { display: inline-flex; align-items: center; gap: 6px; }

.spaced { margin-top: 22px; }

.muted { color: var(--muted); }

.eyebrow {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--primary);
}

.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.page-heading h1 { margin: 0; }

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 6px;
}

.section-heading h2 { font-size: 17px; font-weight: 600; }
.section-heading span { color: var(--muted); font-size: 13px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.stats.four { grid-template-columns: repeat(4, 1fr); }

.stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-top: 3px solid transparent;
  border-radius: var(--radius);
  text-decoration: none;
  box-shadow: var(--shadow-sm);
  transition: transform .12s ease, box-shadow .12s ease;
}

.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat span { color: var(--muted); font-size: 13px; font-weight: 500; }
.stat strong { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.stat.active, .stat.confirmed, .stat.activated { border-top-color: var(--primary); }
.stat.pending, .stat.unused { border-top-color: var(--warn); }
.stat.expired { border-top-color: #9ca3af; }

.filters {
  display: grid;
  grid-template-columns: 150px minmax(200px, 1fr) minmax(220px, 1.3fr) 110px auto;
  gap: 14px;
  align-items: end;
}

.filters label { margin: 0; }
.filter-actions { display: flex; gap: 8px; }

.code-list { padding: 0; overflow: hidden; }
.code-list .section-heading { padding: 22px 24px 0; }
.code-list table { min-width: 1040px; }
.code-list td { vertical-align: top; }
.code-list small { display: block; margin-top: 4px; color: var(--muted); white-space: nowrap; }

.table-scroll { overflow-x: auto; }

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.status.active, .status.confirmed, .status.activated { color: #047857; background: #d1fae5; }
.status.pending, .status.unused { color: #b45309; background: var(--warn-soft); }
.status.rejected, .status.void { color: #b91c1c; background: var(--danger-soft); }
.status.expired, .status.cancelled { color: #4b5563; background: #f3f4f6; }

.empty { padding: 18px 24px 26px; color: var(--muted); text-align: center; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 18px 24px;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}

.pagination span { color: var(--muted); font-size: 13px; }
.pagination .button { min-height: 34px; padding: 6px 14px; }

dl { display: grid; grid-template-columns: 96px 1fr; margin: 14px 0; }

dt, dd { margin: 0; padding: 9px 0; border-bottom: 1px solid var(--line); }
dt { color: var(--muted); font-size: 13px; }
dd { font-weight: 500; }

dd small { display: block; margin-top: 4px; color: var(--muted); }

.thumbnails { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.thumbnails img {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.register-qr { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.register-qr img { border: 1px solid var(--line); border-radius: var(--radius-sm); }

.product-thumb {
  width: 64px;
  height: 64px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
  background: #f3f4f6;
}

.product-thumb img { width: 100%; height: 100%; object-fit: cover; }

.store-logo {
  width: 72px;
  height: 72px;
  flex-shrink: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f3f4f6;
  object-fit: cover;
}

.store-logo.small { width: 34px; height: 34px; border-radius: 9px; }

.store-logo.placeholder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 24px;
  font-weight: 700;
}

.store-logo.small.placeholder { font-size: 15px; }

.store-logo-row {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.logo-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.logo-form input[type="file"] { min-height: 38px; padding: 6px 10px; font-size: 12px; }
.logo-form button { min-height: 38px; padding: 6px 14px; }

.merchant-cell { display: flex; align-items: center; gap: 12px; }

.clerk-form { display: grid; grid-template-columns: 1fr 1.4fr 96px; gap: 8px; margin-top: 14px; }
.clerk-form input { min-height: 38px; }
.clerk-form button { min-height: 38px; padding: 6px 12px; }

.merchant-table { min-width: 980px; }
.merchant-table td { vertical-align: top; }
.merchant-table small { display: block; margin-top: 4px; color: var(--muted); }
.merchant-table .actions { flex-wrap: nowrap; }

.row-form { display: grid; grid-template-columns: 150px 92px; gap: 6px; }
.row-form input { min-height: 38px; }
.row-form button { min-height: 38px; padding: 6px 12px; }

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(17,24,39,.45);
}

.modal-overlay[hidden] { display: none; }

.modal {
  width: min(420px, 100%);
  padding: 26px;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(16,24,40,.28);
  animation: modal-in .18s ease;
}

.modal h2 { margin: 0 0 8px; font-size: 19px; font-weight: 700; }
.modal .muted { margin: 0 0 6px; }

@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 900px) {
  .filters { grid-template-columns: 1fr 1fr; }
  .stats.four { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 760px) {
  .grid, .stats, .stats.four { grid-template-columns: 1fr; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .filters { grid-template-columns: 1fr; }
  main { margin: 18px auto; }
  .panel { padding: 18px; }
  .code-list { padding: 0; }
  header .crumb { display: none; }
}