:root {
  color-scheme: light;
  --bg: #eef1f4;
  --bg-strong: #dfe5ea;
  --panel: #fbfcfd;
  --panel-strong: #ffffff;
  --text: #17202a;
  --muted: #687482;
  --subtle: #8a96a3;
  --line: #d4dbe3;
  --line-strong: #b8c3ce;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --accent-soft: #d9f3ee;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --ok: #067647;
  --ok-soft: #dcfae6;
  --warn: #a15c07;
  --warn-soft: #fff3d6;
  --shadow: 0 18px 45px rgb(31 42 55 / 9%);
  --radius: 8px;
  --mono: "SFMono-Regular", "Cascadia Code", "Liberation Mono", Menlo, Consolas, monospace;
  --sans: "Aptos", "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    linear-gradient(90deg, rgb(23 32 42 / 4%) 1px, transparent 1px),
    linear-gradient(rgb(23 32 42 / 4%) 1px, transparent 1px),
    var(--bg);
  background-size: 28px 28px;
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgb(15 118 110 / 14%), transparent 34rem),
    linear-gradient(180deg, rgb(255 255 255 / 62%), rgb(255 255 255 / 0) 22rem);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.32;
  background-image: linear-gradient(135deg, rgb(255 255 255 / 55%) 0 1px, transparent 1px 7px);
  z-index: -1;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 9px;
  padding: 9px clamp(12px, 2.4vw, 22px);
  border-bottom: 1px solid rgb(184 195 206 / 72%);
  background: rgb(251 252 253 / 90%);
  backdrop-filter: blur(16px);
  box-shadow: 0 10px 26px rgb(31 42 55 / 6%);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid #143c38;
  border-radius: var(--radius);
  background: #17202a;
  color: #e5fbf7;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  box-shadow: inset 0 -8px 14px rgb(15 118 110 / 26%);
  flex: 0 0 auto;
}

.brand-copy {
  min-width: 0;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 2px;
  font-size: clamp(17px, 2.2vw, 24px);
  line-height: 1.08;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

.token-control {
  display: grid;
  grid-template-columns: max-content max-content;
  align-items: center;
  gap: 6px;
}

.app-header input,
.app-header button {
  min-height: 32px;
  padding: 6px 9px;
  font-size: 12px;
}

.token-control button {
  min-width: 48px;
}

main {
  width: min(1240px, calc(100vw - 28px));
  margin: 22px auto 56px;
}

.admin-locked .header-tabs,
.admin-locked .header-actions {
  display: none;
}

.login-main {
  width: min(420px, calc(100vw - 28px));
  margin-top: 72px;
}

.login-panel {
  box-shadow: 0 22px 55px rgb(31 42 55 / 12%);
}

.redeem-main {
  width: min(980px, calc(100vw - 28px));
}

.grid {
  display: grid;
  grid-template-columns: minmax(270px, 0.8fr) minmax(0, 1.45fr);
  gap: 16px;
  align-items: start;
}

.full {
  grid-column: 1 / -1;
}

.panel {
  min-width: 0;
  border: 1px solid rgb(184 195 206 / 78%);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel-strong), var(--panel));
  box-shadow: var(--shadow);
  overflow: clip;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid rgb(212 219 227 / 76%);
}

.panel h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
}

.panel-subtitle {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.panel-body {
  padding: 16px 18px 18px;
}

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

.field-group {
  display: grid;
  gap: 6px;
}

label {
  display: block;
  color: #4c5967;
  font-size: 12px;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 9px 11px;
  background: #fff;
  color: var(--text);
  font: inherit;
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(15 118 110 / 14%);
}

textarea {
  min-height: 168px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
}

input[type="file"] {
  min-height: auto;
  padding: 8px;
  background: #f7f9fb;
  font-size: 13px;
}

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

button {
  min-height: 38px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 8px 12px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 760;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
  white-space: nowrap;
}

button:hover:not(:disabled) {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
  box-shadow: 0 8px 18px rgb(15 118 110 / 17%);
  transform: translateY(-1px);
}

button:focus-visible {
  outline: 3px solid rgb(15 118 110 / 18%);
  outline-offset: 2px;
}

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

button.secondary:hover:not(:disabled) {
  border-color: #9aa8b6;
  background: #f4f7f8;
  box-shadow: 0 6px 14px rgb(31 42 55 / 8%);
}

button.secondary.danger {
  border-color: #f5b7b1;
  background: #fffafa;
  color: var(--danger);
}

button.secondary.danger:hover:not(:disabled) {
  border-color: var(--danger);
  background: var(--danger-soft);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
  box-shadow: none;
}

.copy-email {
  width: auto;
  max-width: 100%;
  min-height: 0;
  border: 0;
  background: transparent;
  color: #2563eb;
  padding: 0;
  font: inherit;
  font-weight: 760;
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
}

.copy-email:hover,
.copy-email:focus-visible {
  background: transparent !important;
  box-shadow: none !important;
  text-decoration: underline;
  transform: none !important;
}

.copy-email.copied {
  color: #067647;
}

.email-copy-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.email-value {
  overflow-wrap: anywhere;
}

.copy-email-button {
  width: auto;
  min-height: 30px;
  padding: 5px 10px;
  font-size: 12px;
  line-height: 1;
  flex: 0 0 auto;
}

.copy-email-button.copied {
  border-color: #86d7ad;
  background: #ecfdf3;
  color: #067647;
}

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

.notice {
  border: 1px solid #c7eadf;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #f1fffb, #e7f7f3);
  color: #24413d;
  padding: 12px 14px;
}

.muted {
  color: var(--subtle);
  font-size: 12px;
  line-height: 1.45;
  margin-top: 4px;
}

.tab-list {
  display: inline-flex;
  gap: 4px;
  margin: 18px 0;
  padding: 4px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: rgb(255 255 255 / 72%);
  box-shadow: 0 10px 22px rgb(31 42 55 / 7%);
}

.header-tabs {
  flex: 0 0 auto;
  gap: 3px;
  margin: 0;
  padding: 3px;
  background: rgb(255 255 255 / 64%);
  box-shadow: none;
}

.tab-button {
  min-width: 76px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.tab-button:hover:not(:disabled) {
  border-color: transparent;
  background: #eef4f3;
  box-shadow: none;
}

.tab-button.active {
  border-color: #9fcac3;
  background: var(--accent-soft);
  color: #123c38;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 50%);
}

.tab-panel[hidden] {
  display: none;
}

.table-actions {
  margin-bottom: 12px;
}

#runtimeStatus {
  flex: 1 1 260px;
}

button.compact-danger {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 720;
}

.account-pool-actions {
  position: sticky;
  top: calc(var(--app-header-height, 64px) + 10px);
  z-index: 18;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgb(247 250 249 / 96%);
  backdrop-filter: blur(12px);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 80%),
    0 12px 28px rgb(31 42 55 / 10%);
}

.bulk-account-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.account-pool-actions button {
  min-height: 30px;
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 720;
}

#accountSummary {
  width: auto;
  min-height: 0;
  margin-left: 4px;
  color: #40505f;
  font-size: 12px;
  font-weight: 720;
  line-height: 1.35;
  white-space: nowrap;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid #e4e9ee;
  padding: 10px 10px;
  vertical-align: top;
}

td button.secondary {
  min-height: 28px;
  padding: 4px 7px;
  font-size: 12px;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f3f7f8;
  color: #536171;
  font-size: 12px;
  font-weight: 800;
}

tbody tr {
  background: #fff;
}

tbody tr:hover {
  background: #f8fbfb;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.select-col {
  width: 42px;
  text-align: center;
}

.quota-col {
  width: 132px;
  min-width: 112px;
  max-width: 132px;
  overflow-wrap: anywhere;
}

.status-select {
  min-width: 96px;
  min-height: 34px;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 800;
}

select:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.status-valid,
.status-success,
.status-confirmed,
.status-available {
  color: var(--ok);
}

.status-invalid,
.status-failed,
.status-used,
.status-expired,
.status-partially_confirmed_expired {
  color: var(--danger);
}

.status-unchecked,
.status-running,
.status-pending_confirmation,
.status-disabled,
.status-reserved {
  color: var(--warn);
}

.stats-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.stat {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  background: #fff;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.pagination-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.pagination button {
  min-height: 32px;
  padding: 5px 9px;
  font-size: 12px;
}

.pagination-page {
  min-width: 34px;
}

.pagination-page.active {
  border-color: #9fcac3;
  background: var(--accent-soft);
  color: #123c38;
  opacity: 1;
}

.pagination-gap {
  padding: 0 2px;
  color: var(--subtle);
}

.empty-cell {
  color: var(--subtle);
  text-align: center;
}

.upload-group-row td {
  padding: 0;
  background: #edf3f3;
  border-bottom-color: #d6e0e1;
}

.upload-group-row:hover {
  background: #edf3f3;
}

.upload-group-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  padding: 10px 12px;
  text-align: left;
  font-size: 13px;
  white-space: normal;
}

.upload-group-toggle:hover:not(:disabled) {
  background: #e2eeee;
  box-shadow: none;
  transform: none;
}

.upload-group-caret {
  width: 14px;
  color: var(--muted);
  font-family: var(--mono);
}

.upload-group-title {
  font-weight: 820;
}

.upload-group-meta {
  color: var(--muted);
}

code {
  border: 1px solid #dce4e8;
  border-radius: 6px;
  background: #f6f8f9;
  color: #26323f;
  padding: 2px 5px;
  font-family: var(--mono);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.codes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 8px;
}

.generated-code-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.code-pill {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 10px;
  background: #fff;
  font-family: var(--mono);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.countdown {
  display: inline-flex;
  align-items: center;
  border: 1px solid #f3c98b;
  border-radius: var(--radius);
  background: var(--warn-soft);
  color: var(--warn);
  font-weight: 800;
  padding: 9px 11px;
  margin: 0 0 12px;
}

.redeem-hero {
  display: grid;
  gap: 14px;
}

.step-list {
  display: grid;
  gap: 9px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.step-list li {
  display: grid;
  grid-template-columns: 26px 1fr;
  gap: 10px;
  align-items: start;
  color: #40505f;
  font-size: 13px;
  line-height: 1.5;
}

.step-list span {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: #17202a;
  color: #e5fbf7;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 800;
}

@media (max-width: 900px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions,
  .header-tabs,
  .token-control {
    width: 100%;
  }

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

  .account-pool-actions {
    align-items: flex-start;
  }
}

@media (max-width: 620px) {
  main,
  .redeem-main {
    width: min(100vw - 18px, 1240px);
    margin-top: 12px;
  }

  .app-header {
    padding: 13px 12px;
  }

  .brand-mark {
    width: 30px;
    height: 30px;
  }

  .panel-header,
  .panel-body {
    padding-left: 13px;
    padding-right: 13px;
  }

  .row,
  .bulk-account-actions {
    width: 100%;
  }

  .account-pool-actions {
    gap: 5px;
  }

  button,
  .row > input {
    width: 100%;
  }

  button.compact-danger {
    width: auto;
  }

  .account-pool-actions button {
    width: auto;
  }

  #accountSummary {
    flex-basis: 100%;
    margin-left: 0;
    white-space: normal;
  }

  .token-control {
    grid-template-columns: minmax(0, 1fr) max-content max-content;
    gap: 6px;
  }

  .token-control button {
    width: auto;
    min-width: 44px;
    padding-left: 10px;
    padding-right: 10px;
  }

  .tab-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    width: 100%;
  }

  .tab-button {
    min-width: 0;
  }

  table {
    min-width: 680px;
  }
}
