:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #d9dee7;
  --primary: #1677ff;
  --primary-dark: #0958d9;
  --danger: #c2410c;
  --success: #15803d;
  font-family: Inter, "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

.shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
}

.public-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 0;
}

.panel {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 18px 45px rgba(31, 41, 55, 0.08);
}

.redeem-panel {
  max-width: 460px;
  padding: 28px;
}

.brand-row {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 24px;
}

.public-brand-row {
  justify-content: space-between;
  align-items: flex-start;
}

.brand-title-group {
  display: flex;
  gap: 14px;
  align-items: center;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #e7f0ff;
  color: var(--primary-dark);
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.25;
}

p {
  margin: 6px 0 0;
  color: var(--muted);
}

.form-stack {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
}

input,
button,
select {
  width: 100%;
  min-height: 44px;
  border-radius: 6px;
  font: inherit;
}

input,
select {
  border: 1px solid var(--border);
  padding: 0 12px;
  background: #fff;
  color: var(--text);
}

input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
  padding: 0;
  accent-color: var(--primary);
}

.input-action-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.upload-button {
  white-space: nowrap;
}

.support-button {
  width: 100%;
}

.guide-button {
  width: auto;
  min-height: 34px;
  padding: 0 12px;
  white-space: nowrap;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

button {
  border: 0;
  padding: 0 16px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

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

button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.pending-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  place-items: center;
  padding: 24px;
  background: rgba(31, 41, 55, 0.42);
}

.pending-overlay.is-visible {
  display: grid;
}

.pending-dialog {
  width: min(380px, 100%);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: flex-start;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 20px 60px rgba(31, 41, 55, 0.2);
}

.pending-dialog strong {
  display: block;
  line-height: 1.4;
}

.pending-dialog p {
  margin-top: 6px;
  font-size: 14px;
  line-height: 1.55;
}

.pending-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid #dbeafe;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.support-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 110;
  place-items: center;
  padding: 24px;
  background: rgba(31, 41, 55, 0.44);
}

.support-overlay.is-visible {
  display: grid;
}

.guide-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 112;
  place-items: center;
  padding: 24px;
  background: rgba(31, 41, 55, 0.44);
}

.guide-overlay.is-visible {
  display: grid;
}

.support-dialog {
  position: relative;
  width: min(360px, 100%);
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 20px 60px rgba(31, 41, 55, 0.2);
  text-align: center;
}

.support-dialog h2 {
  margin-right: 28px;
  text-align: left;
}

.support-dialog p {
  text-align: left;
}

.guide-dialog {
  position: relative;
  width: min(560px, 100%);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 20px 60px rgba(31, 41, 55, 0.2);
}

.guide-dialog h2 {
  margin-right: 28px;
}

.guide-image {
  display: block;
  width: 100%;
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.support-close-button {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  min-height: 32px;
  padding: 0;
  border-radius: 50%;
  background: #eef2f7;
  color: var(--text);
  font-size: 20px;
  line-height: 1;
}

.support-close-button:hover {
  background: #e2e8f0;
}

.support-qr-image {
  width: min(240px, 100%);
  aspect-ratio: 1;
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  object-fit: contain;
}

.message {
  min-height: 22px;
  margin: 0;
  font-size: 14px;
}

.message.error {
  color: var(--danger);
}

.message.success {
  color: var(--success);
}

.admin-shell {
  padding: 28px 0;
}

.admin-header,
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.admin-header {
  margin-bottom: 20px;
}

.admin-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.password-modal {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(31, 41, 55, 0.44);
}

.password-dialog {
  position: relative;
  width: min(420px, 100%);
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 20px 60px rgba(31, 41, 55, 0.2);
}

.password-modal[hidden] {
  display: none;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  gap: 18px;
  align-items: start;
}

.admin-side {
  display: grid;
  gap: 18px;
}

.admin-main {
  display: grid;
  gap: 18px;
}

.table-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 14px;
}

.codes-toolbar {
  grid-template-columns: minmax(0, 1fr) auto auto;
}

.admin-panel {
  padding: 20px;
}

.upstream-ranking-card {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
}

.upstream-ranking-card .secondary-button {
  grid-column: 1 / -1;
}

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

h2 {
  margin: 0;
  font-size: 18px;
}

textarea {
  width: 100%;
  min-height: 160px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  resize: vertical;
  font: 14px/1.5 Consolas, monospace;
}

.secondary-button,
.small-button {
  width: auto;
  min-height: 36px;
  background: #eef2f7;
  color: var(--text);
}

.secondary-button:hover,
.small-button:hover {
  background: #e2e8f0;
}

.small-button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 13px;
}

.danger-button {
  background: #fff1f2;
  color: #be123c;
}

.danger-button:hover {
  background: #ffe4e6;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  margin-top: 14px;
}

.pagination-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

.page-info {
  min-width: 130px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 700;
}

.select-column {
  width: 44px;
  text-align: center;
  vertical-align: middle;
}

.table-checkbox {
  display: block;
  margin: 0 auto;
}

.link-cell {
  max-width: 280px;
  word-break: break-all;
}

.code-cell {
  font-weight: 700;
  letter-spacing: 0.02em;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  background: #eef2f7;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.status-badge.unused {
  background: #e0f2fe;
  color: #075985;
}

.status-badge.partially_used {
  background: #fef3c7;
  color: #92400e;
}

.status-badge.used {
  background: #dcfce7;
  color: #166534;
}

.status-badge.expired,
.status-badge.voided {
  background: #fee2e2;
  color: #991b1b;
}

.support-preview-wrap {
  display: grid;
  place-items: center;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: #f8fafc;
}

.support-qr-preview {
  width: min(180px, 100%);
  aspect-ratio: 1;
  object-fit: contain;
}

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

  .admin-header,
  .section-header,
  .pagination-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .admin-actions {
    width: 100%;
  }

  .table-toolbar {
    grid-template-columns: 1fr;
  }

  .codes-toolbar {
    grid-template-columns: 1fr;
  }

  .public-brand-row {
    gap: 12px;
  }

  .guide-button {
    min-height: 32px;
    padding: 0 10px;
    font-size: 13px;
  }
}
