:root {
  color-scheme: light;
  --bg: #f4f7f6;
  --panel: #ffffff;
  --panel-soft: #eef5f1;
  --text: #14211c;
  --muted: #63746c;
  --line: #dce6e1;
  --primary: #0f7b63;
  --primary-dark: #0a5d4b;
  --accent: #d09b2c;
  --danger: #b23737;
  --success: #14724f;
  --shadow: 0 18px 50px rgba(28, 55, 47, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.page {
  min-height: 100vh;
}

.redeem-page {
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(circle at 18% 20%, rgba(15, 123, 99, 0.13), transparent 28%),
    linear-gradient(135deg, #f6faf7 0%, #edf4f2 48%, #f7f0df 100%);
}

.redeem-shell {
  width: min(1180px, 100%);
  display: grid;
  grid-template-columns: minmax(300px, 0.72fr) minmax(620px, 1.28fr);
  min-height: 520px;
  border: 1px solid rgba(15, 123, 99, 0.12);
  background: rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow);
  overflow: hidden;
  border-radius: 8px;
}

.brand-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(32px, 5vw, 64px);
  background:
    linear-gradient(135deg, rgba(15, 123, 99, 0.96), rgba(12, 68, 61, 0.94)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240' viewBox='0 0 240 240'%3E%3Cpath d='M0 40h240M0 100h240M0 160h240M40 0v240M100 0v240M160 0v240' stroke='rgba(255,255,255,.09)' stroke-width='2'/%3E%3C/svg%3E");
  color: #ffffff;
}

.brand-mark {
  width: 76px;
  height: 76px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.48);
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  border-radius: 8px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-mark.small {
  width: 48px;
  height: 48px;
  color: var(--primary);
  border-color: rgba(15, 123, 99, 0.22);
  background: #ecf6f2;
}

.brand-panel h1 {
  margin: 32px 0 12px;
  font-size: clamp(34px, 6vw, 58px);
  line-height: 1.08;
  letter-spacing: 0;
}

.brand-panel p,
.brand-line p,
.section-head p {
  margin: 0;
  color: var(--muted);
}

.brand-panel p {
  color: rgba(255, 255, 255, 0.78);
  font-size: 18px;
}

.brand-links {
  display: grid;
  gap: 10px;
  margin-top: 28px;
}

.brand-link {
  display: grid;
  gap: 4px;
  padding: 14px 16px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  color: #ffffff;
  text-decoration: none;
  background: rgba(255, 255, 255, 0.1);
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

.brand-link:hover,
.brand-link:focus-visible {
  border-color: rgba(255, 255, 255, 0.44);
  background: rgba(255, 255, 255, 0.16);
  transform: translateY(-1px);
}

.brand-link:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.28);
  outline-offset: 2px;
}

.brand-info {
  cursor: default;
}

.brand-info:hover {
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.1);
  transform: none;
}

.brand-link-title {
  font-weight: 800;
}

.brand-link-url {
  color: rgba(255, 255, 255, 0.72);
  font-size: 14px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.tool-panel,
.login-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(24px, 3.8vw, 42px);
  background: var(--panel);
}

.redeem-tool-stack {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.1fr);
  gap: 18px;
  align-items: stretch;
}

.redeem-card,
.history-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.redeem-card {
  padding: 18px;
}

.history-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  max-height: 620px;
  padding: 18px;
}

.panel-heading {
  display: grid;
  gap: 4px;
  margin-bottom: 2px;
}

.panel-heading h2 {
  margin: 0;
  font-size: 21px;
}

.panel-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.history-search-form {
  gap: 10px;
}

.history-results {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 0;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-gutter: stable;
}

.history-item,
.history-empty {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 12px;
}

.history-code {
  margin-bottom: 6px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.history-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.history-empty {
  padding: 16px;
  color: var(--muted);
  text-align: center;
}

.form-stack {
  display: grid;
  gap: 12px;
}

label {
  color: #29443a;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: #ffffff;
  color: var(--text);
  outline: none;
}

input:focus,
select:focus {
  border-color: rgba(15, 123, 99, 0.65);
  box-shadow: 0 0 0 4px rgba(15, 123, 99, 0.12);
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

.primary-button {
  color: #ffffff;
  background: var(--primary);
}

.primary-button:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.primary-button:disabled,
.secondary-button:disabled,
.ghost-button:disabled,
.danger-button:disabled {
  opacity: 0.58;
  cursor: not-allowed;
  transform: none;
}

.secondary-button {
  color: var(--primary-dark);
  background: #e5f3ee;
  border: 1px solid rgba(15, 123, 99, 0.16);
}

.ghost-button {
  color: #29443a;
  background: transparent;
  border: 1px solid var(--line);
}

.danger-button {
  color: #ffffff;
  background: var(--danger);
}

.danger-button:not(:disabled):hover {
  background: #922c2c;
  transform: translateY(-1px);
}

.compact {
  min-height: 40px;
}

.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  min-width: 150px;
}

.message {
  min-height: 24px;
  margin: 2px 0 0;
  color: var(--muted);
}

.message.success {
  color: var(--success);
}

.message.error {
  color: var(--danger);
}

.message.muted {
  color: var(--muted);
}

.login-page {
  display: grid;
  place-items: center;
  padding: 28px;
  background: linear-gradient(135deg, #eef6f2, #fbf7eb);
}

.login-shell {
  width: min(440px, 100%);
}

.login-panel {
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.brand-line {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
}

.brand-line h1 {
  margin: 0 0 4px;
  font-size: 24px;
}

.admin-page {
  background: #f4f7f6;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(18px, 4vw, 44px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(14px);
}

.topbar .brand-line {
  margin-bottom: 0;
}

.admin-shell {
  width: min(1220px, calc(100% - 32px));
  margin: 28px auto 56px;
  display: grid;
  gap: 22px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.stat-box {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.stat-box span {
  display: block;
  color: var(--muted);
  margin-bottom: 10px;
}

.stat-box strong {
  font-size: 34px;
  line-height: 1;
}

.admin-band {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 22px;
  border-bottom: 1px solid var(--line);
}

.section-head h2 {
  margin: 0 0 6px;
  font-size: 22px;
}

.inline-form {
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(520px, 100%);
}

.toolbar,
.action-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.toolbar input {
  max-width: 340px;
}

.toolbar select {
  max-width: 160px;
}

.action-row {
  justify-content: space-between;
  background: #ffffff;
}

.action-buttons {
  display: flex;
  align-items: center;
  gap: 10px;
}

.table-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 210px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  background: #fbfdfc;
}

.pagination-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
}

th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: #3b5149;
  font-size: 14px;
  background: #fbfdfc;
}

tr:last-child td {
  border-bottom: 0;
}

.check-cell {
  width: 54px;
}

.check-cell input {
  width: 18px;
  min-height: 18px;
  height: 18px;
  padding: 0;
}

.mono {
  font-family: "Cascadia Mono", "Consolas", monospace;
  font-size: 13px;
}

.strong {
  font-weight: 800;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
}

.badge.available {
  color: #0b6b4c;
  background: #ddf4ea;
}

.badge.bound {
  color: #8a5a08;
  background: #fff1cb;
}

.badge.redeemed {
  color: #8d3434;
  background: #fbe1df;
}

.empty-cell {
  height: 92px;
  text-align: center;
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100% - 44px));
  padding: 14px 16px;
  border-radius: 8px;
  color: #ffffff;
  background: #263b34;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  background: var(--danger);
}

.toast.success {
  background: var(--success);
}

@media (max-width: 900px) {
  .redeem-shell {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .redeem-tool-stack {
    grid-template-columns: 1fr;
  }

  .brand-panel {
    min-height: 300px;
  }

  .history-card {
    max-height: none;
  }

  .history-results {
    max-height: 280px;
  }

  .history-item {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 780px) {

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .section-head,
  .inline-form,
  .toolbar,
  .action-row,
  .pagination,
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .pagination-actions {
    width: 100%;
  }

  .action-buttons {
    width: 100%;
  }

  .action-buttons button {
    flex: 1;
  }

  .pagination-actions button {
    flex: 1;
  }

  .toolbar input,
  .toolbar select {
    max-width: none;
  }
}

@media (max-width: 520px) {
  .redeem-page,
  .login-page {
    padding: 16px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .admin-shell {
    width: calc(100% - 20px);
    margin-top: 14px;
  }

  .brand-panel h1 {
    font-size: 34px;
  }
}
