:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: #eef3f8;
  color: #172033;
  --bg: #eef3f8;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --line: #d9e2ef;
  --line-strong: #bdc9da;
  --text: #172033;
  --muted: #66758c;
  --primary: #175cff;
  --primary-dark: #0f45d5;
  --danger: #d92d20;
  --danger-dark: #b42318;
  --shadow: 0 12px 32px rgba(26, 39, 68, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  background:
    linear-gradient(180deg, rgba(23, 92, 255, 0.07), rgba(255, 255, 255, 0) 340px),
    var(--bg);
  margin: 0;
  min-height: 100%;
}

body.modal-open {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.link-button {
  align-items: center;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  font-weight: 700;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  text-decoration: none;
  transition: background 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
  white-space: nowrap;
}

button {
  background: var(--primary);
  color: #fff;
}

button:hover:not(:disabled),
.link-button:hover {
  box-shadow: 0 9px 20px rgba(23, 92, 255, 0.18);
  transform: translateY(-1px);
}

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

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.secondary,
.link-button {
  background: #e9eef6;
  color: var(--text);
}

.secondary:hover:not(:disabled),
.link-button:hover {
  background: #dfe7f2;
}

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

.danger:hover:not(:disabled) {
  background: var(--danger-dark);
  box-shadow: 0 9px 20px rgba(217, 45, 32, 0.18);
}

.shell {
  margin: 0 auto;
  max-width: 1240px;
  padding: 24px 18px 44px;
}

.compact-shell {
  align-items: center;
  display: grid;
  max-width: 720px;
  min-height: 100vh;
}

.panel {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(217, 226, 239, 0.98);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.auth-panel,
.redeem-panel,
.admin-section {
  display: grid;
  gap: 16px;
}

.admin-grid .admin-section {
  grid-template-rows: auto auto minmax(0, 1fr);
  height: 640px;
  min-height: 640px;
}

.admin-grid .admin-section > div:last-child {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
}

.auth-panel {
  margin: 8vh auto 18px;
  max-width: 660px;
}

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

.page-header {
  background:
    linear-gradient(135deg, rgba(23, 92, 255, 0.08), rgba(255, 255, 255, 0) 62%),
    rgba(255, 255, 255, 0.98);
}

.page-heading {
  display: grid;
  gap: 7px;
}

.eyebrow {
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0;
  text-transform: uppercase;
}

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

h1 {
  color: var(--text);
  font-size: clamp(28px, 4vw, 40px);
  line-height: 1.1;
}

h2 {
  font-size: 19px;
  line-height: 1.25;
}

h3 {
  font-size: 14px;
  line-height: 1.35;
}

.page-subtitle {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.redeem-form {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr auto;
  padding: 10px;
}

input,
select,
textarea {
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text);
  outline: none;
  width: 100%;
}

input {
  min-height: 40px;
  padding: 0 12px;
}

select {
  min-height: 40px;
  padding: 0 34px 0 12px;
}

textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.55;
  min-height: 250px;
  padding: 14px;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: #8a97aa;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(23, 92, 255, 0.13);
}

.grid,
.admin-grid,
.tables {
  display: grid;
  gap: 16px;
}

.grid,
.admin-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.admin-grid {
  margin: 16px 0;
}

.tables {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 16px;
}

.panel-head,
.list-head {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  min-width: 0;
}

.panel-head {
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.panel-head span,
.row small {
  color: var(--muted);
  font-size: 13px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.admin-section > .actions button {
  min-width: 108px;
}

.compact-actions {
  gap: 8px;
}

.compact-actions button {
  min-height: 38px;
  min-width: 88px;
  padding: 0 14px;
}

.filters {
  align-items: center;
  display: flex;
  flex: 0 0 auto;
  flex-wrap: nowrap;
  gap: 10px;
  justify-content: flex-end;
}

.filters input {
  min-height: 38px;
  width: 230px;
}

.filters select {
  min-height: 38px;
  width: 150px;
}

.stats {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.stat {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 92px;
  padding: 14px;
}

.stat b {
  color: var(--text);
  display: block;
  font-size: clamp(24px, 3vw, 32px);
  line-height: 1.1;
}

.stat span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  margin-top: 8px;
}

.table {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  max-height: 360px;
  overflow: auto;
}

#cdkList,
#smsList {
  height: 100%;
  max-height: none;
  min-height: 0;
}

.exchange-table {
  margin-top: 14px;
}

.row {
  border-bottom: 1px solid #edf1f7;
  display: grid;
  gap: 7px;
  padding: 12px;
}

.row:hover {
  background: #fafcff;
}

.row:last-child {
  border-bottom: 0;
}

.row b,
.row code {
  overflow-wrap: anywhere;
}

.row code,
.code {
  background: #14213a;
  border-radius: 7px;
  color: #fff;
  display: inline-block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.45;
  padding: 5px 8px;
  width: fit-content;
}

.check-row {
  align-items: center;
  color: var(--text);
  display: flex;
  gap: 8px;
  min-width: 0;
}

.check-row input {
  min-height: auto;
  width: auto;
}

.cdk-code-row {
  flex-wrap: wrap;
}

.mini-button {
  border-radius: 6px;
  font-size: 12px;
  min-height: 26px;
  min-width: 44px;
  padding: 0 8px;
}

.tag {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  padding: 6px 9px;
  width: fit-content;
}

.available {
  background: #e8f7ee;
  color: #10733b;
}

.used {
  background: #fff3df;
  color: #9a5b00;
}

.cooldown {
  background: #e8f0ff;
  color: #1452b8;
}

.exhausted {
  background: #eef1f5;
  color: #596579;
}

.expired {
  background: #fbe9e8;
  color: #b42318;
}

.blacklisted {
  background: #1f2937;
  color: #fff;
}

.pager {
  align-items: center;
  color: var(--muted);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 10px;
}

.pager button {
  min-height: 38px;
  padding: 0 14px;
}

.result {
  background: #f8fbff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  padding: 16px;
}

.result strong {
  font-size: 24px;
}

.code-box {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.hidden {
  display: none;
}

.form-row {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(180px, 1fr) 130px auto auto;
}

.toast {
  background: #172033;
  border-radius: 8px;
  bottom: 20px;
  box-shadow: 0 16px 34px rgba(23, 32, 51, 0.22);
  color: #fff;
  left: 50%;
  max-width: calc(100vw - 32px);
  padding: 12px 16px;
  position: fixed;
  transform: translateX(-50%);
  z-index: 20;
}

.raw-record {
  background: #f6f8fb;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  margin: 4px 0 0;
  max-height: 170px;
  overflow: auto;
  padding: 10px;
  white-space: pre-wrap;
  word-break: break-word;
}

.modal {
  align-items: center;
  background: rgba(15, 23, 42, 0.48);
  display: grid;
  inset: 0;
  justify-items: center;
  padding: 18px;
  position: fixed;
  z-index: 40;
}

.modal.hidden {
  display: none;
}

.modal-card {
  background: #fff;
  border: 1px solid rgba(217, 226, 239, 0.98);
  border-radius: 8px;
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.28);
  max-height: min(82vh, 820px);
  overflow: hidden;
  width: min(920px, 100%);
}

.modal-head {
  align-items: flex-start;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 18px 18px 14px;
}

.modal-table {
  border: 0;
  border-radius: 0;
  max-height: min(70vh, 680px);
}

.modal-table .row:last-child {
  border-bottom: 0;
}

.icon-button {
  min-height: 38px;
  padding: 0 14px;
}

.import-page .admin-section {
  max-width: 900px;
}

@media (max-width: 1100px) {
  .stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .admin-grid,
  .tables {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .shell {
    padding: 16px 12px 32px;
  }

  .panel {
    padding: 16px;
  }

  .auth-panel {
    margin-top: 0;
  }

  .admin-title,
  .panel-head,
  .list-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .actions,
  .filters,
  .filters input,
  .filters select,
  .link-button,
  button {
    width: 100%;
  }

  .filters {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .admin-grid .admin-section {
    height: 620px;
    min-height: 620px;
  }

  .redeem-form,
  .grid,
  .stats,
  .form-row {
    grid-template-columns: 1fr;
  }

  .pager {
    align-items: stretch;
    flex-direction: column;
  }

  .pager button {
    width: 100%;
  }

  .modal {
    padding: 10px;
  }

  .modal-card {
    max-height: 90vh;
  }

  .modal-head {
    align-items: stretch;
    flex-direction: column;
  }

  .icon-button {
    width: 100%;
  }
}
