:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #18202b;
  --muted: #6c7785;
  --line: #d9dee7;
  --primary: #1f6feb;
  --primary-dark: #1557b8;
  --danger: #b42318;
  --ok: #137333;
  --warn: #9a6700;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

a {
  color: var(--primary);
  text-decoration: none;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.brand h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.brand span {
  color: var(--muted);
  font-size: 13px;
}

.grid {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

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

.create-type-panel {
  margin-bottom: 14px;
  padding: 12px 18px;
}

.stack {
  display: grid;
  gap: 12px;
}

.row {
  display: grid;
  gap: 6px;
}

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

label {
  font-size: 13px;
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  color: var(--text);
  background: #fff;
}

textarea {
  min-height: 74px;
  resize: vertical;
}

button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 12px;
  background: var(--primary);
  color: #fff;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}

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

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

button.secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
}

button.secondary:hover {
  background: #eef2f7;
}

button.danger {
  background: var(--danger);
}

.message {
  min-height: 22px;
  font-size: 13px;
  color: var(--muted);
}

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

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

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.tabs button {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
}

.tabs button.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

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

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

th {
  color: var(--muted);
  font-weight: 600;
  background: #fafbfc;
}

.badge {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  padding: 2px 9px;
  background: #eef2f7;
  color: #334155;
  font-size: 12px;
}

.badge.ok {
  color: var(--ok);
  background: #e9f6ec;
}

.badge.warn {
  color: var(--warn);
  background: #fff5d6;
}

.delivery-row {
  display: grid;
  grid-template-columns: 1fr 150px 1.5fr auto;
  gap: 8px;
  align-items: end;
}

.code {
  font-family: Consolas, monospace;
  word-break: break-all;
}

.totp-code {
  font-size: 22px;
  font-family: Consolas, monospace;
  font-weight: 700;
}

.hidden {
  display: none !important;
}

.stock-box {
  min-height: 220px;
  font-family: Consolas, monospace;
}

.toolbar input {
  max-width: 360px;
}

.toolbar select {
  max-width: 180px;
}

.table-wrap {
  overflow: auto;
}

.pager {
  margin-top: 12px;
}

.redeem-shell {
  min-height: 100vh;
  background: #f6f7f9;
}

.redeem-hero {
  background: #122033;
  color: #fff;
}

.hero-inner {
  width: min(1180px, calc(100% - 32px));
  min-height: 240px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.hero-inner h1 {
  margin: 0 0 10px;
  font-size: 44px;
  line-height: 1.05;
}

.hero-inner p {
  max-width: 640px;
  margin: 0;
  color: #d8e2ef;
}

.hero-inner a {
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 6px;
  padding: 9px 12px;
}

.eyebrow {
  margin-bottom: 10px !important;
  color: #8bc4ff !important;
  font-size: 13px;
  text-transform: uppercase;
}

.redeem-workspace {
  margin-top: -40px;
}

.compact-tabs {
  margin-bottom: 12px;
}

.result-panel {
  min-height: 360px;
}

.empty-state {
  min-height: 120px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  text-align: center;
}

.status-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  background: #fff;
}

.status-card.available {
  border-left: 4px solid var(--ok);
}

.status-card.used {
  border-left: 4px solid var(--warn);
}

.status-card h2 {
  margin: 10px 0 6px;
}

.meta-grid {
  display: grid;
  gap: 8px;
  min-width: 220px;
}

.meta-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.meta-grid strong {
  font-size: 13px;
}

.delivery-list {
  display: grid;
  gap: 10px;
}

.delivery-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

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

.delivery-card p {
  margin: 0;
}

.totp-box {
  display: grid;
  justify-items: end;
  gap: 6px;
}

.totp-box strong {
  font-family: Consolas, monospace;
  font-size: 24px;
}

.portal {
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(18, 32, 51, 0.96) 0, rgba(18, 32, 51, 0.96) 310px, transparent 310px),
    #f4f6f9;
}

.portal-hero {
  color: #fff;
}

.portal-hero__inner {
  width: min(1120px, calc(100% - 32px));
  min-height: 250px;
  margin: 0 auto;
  display: flex;
  align-items: center;
}

.portal-copy {
  max-width: 760px;
}

.portal-kicker {
  margin: 0 0 10px;
  color: #8bc4ff;
  font-size: 13px;
  text-transform: uppercase;
}

.portal-copy h1 {
  margin: 0 0 12px;
  font-size: 46px;
  line-height: 1.05;
}

.portal-copy p {
  margin: 0;
  color: #d8e2ef;
  font-size: 16px;
  line-height: 1.7;
}

.portal-main {
  width: min(1120px, calc(100% - 32px));
  margin: -44px auto 0;
  padding-bottom: 42px;
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 18px;
  align-items: start;
}

.redeem-card,
.result-stage {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.12);
}

.redeem-card {
  padding: 20px;
}

.redeem-card__header,
.result-stage__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.redeem-card__header h2,
.result-stage__header h2 {
  margin: 10px 0 0;
  font-size: 20px;
}

.result-stage__header {
  padding: 20px 20px 0;
}

.result-stage__header span {
  color: var(--muted);
  font-size: 13px;
}

.portal-form {
  display: grid;
  gap: 12px;
}

.input-action {
  display: grid;
  grid-template-columns: 1fr 92px;
  gap: 8px;
}

.input-action input {
  min-height: 46px;
  font-size: 16px;
}

.portal-form > button {
  min-height: 46px;
  font-weight: 700;
}

.state-dot {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 3px 10px;
  background: #eef2f7;
  color: #475569;
  font-size: 12px;
  white-space: nowrap;
}

.state-dot--ok {
  background: #e9f6ec;
  color: var(--ok);
}

.state-dot--warn {
  background: #fff5d6;
  color: var(--warn);
}

.result-stage > .empty-state,
.result-content {
  margin: 0 20px 20px;
}

.section-title {
  margin: 16px 0 10px;
  font-size: 17px;
}

.compact-empty {
  min-height: 88px;
}

.fade-in {
  animation: fadeInUp 180ms ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 60;
  transform: translate(-50%, 18px);
  min-width: 220px;
  max-width: min(420px, calc(100% - 32px));
  border-radius: 8px;
  padding: 11px 14px;
  background: #122033;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.2);
  transition: opacity 160ms ease, transform 160ms ease;
  text-align: center;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast--error {
  background: var(--danger);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.modal.is-open {
  opacity: 1;
  pointer-events: auto;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.54);
}

.modal__panel {
  position: relative;
  width: min(720px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 28px 70px rgba(15, 23, 42, 0.3);
  transform: translateY(12px) scale(0.98);
  transition: transform 180ms ease;
}

.modal.is-open .modal__panel {
  transform: translateY(0) scale(1);
}

.modal__header,
.modal__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
}

.modal__header {
  border-bottom: 1px solid var(--line);
}

.modal__header h2 {
  margin: 8px 0 0;
}

.modal__body {
  padding: 18px;
}

.modal__footer {
  border-top: 1px solid var(--line);
  justify-content: flex-end;
}

.icon-button {
  width: 38px;
  min-height: 38px;
  padding: 0;
  border-radius: 50%;
  background: #eef2f7;
  color: var(--text);
  font-size: 22px;
  line-height: 1;
}

.icon-button:hover {
  background: #dfe6ef;
}

body.modal-open {
  overflow: hidden;
}

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

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .hero-inner,
  .status-card,
  .delivery-card {
    grid-template-columns: 1fr;
  }

  .hero-inner {
    align-items: flex-start;
    justify-content: center;
    padding: 32px 0 70px;
  }

  .hero-inner h1 {
    font-size: 34px;
  }

  .totp-box {
    justify-items: start;
  }

  .portal {
    background:
      linear-gradient(180deg, rgba(18, 32, 51, 0.96) 0, rgba(18, 32, 51, 0.96) 270px, transparent 270px),
      #f4f6f9;
  }

  .portal-hero__inner {
    min-height: 220px;
  }

  .portal-copy h1 {
    font-size: 34px;
  }

  .portal-copy p {
    font-size: 14px;
  }

  .portal-main {
    grid-template-columns: 1fr;
    margin-top: -34px;
  }

  .redeem-card__header,
  .result-stage__header {
    align-items: flex-start;
  }

  .modal {
    align-items: end;
    padding: 0;
  }

  .modal__panel {
    width: 100%;
    max-height: 86vh;
    border-radius: 8px 8px 0 0;
  }

  .modal__footer {
    position: sticky;
    bottom: 0;
    background: #fff;
  }
}

@media (max-width: 520px) {
  .portal-hero__inner,
  .portal-main {
    width: min(100% - 20px, 1120px);
  }

  .input-action {
    grid-template-columns: 1fr;
  }

  .redeem-card,
  .result-stage {
    border-radius: 8px;
  }

  .modal__footer {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .modal__footer button {
    width: 100%;
  }
}
