:root {
  color-scheme: light;
  --bg-top: #dcecff;
  --bg-mid: #eef4fa;
  --bg-bottom: #f7f9fc;
  --panel: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(244, 248, 252, 0.76));
  --panel-strong: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(247, 250, 253, 0.88));
  --line: rgba(219, 229, 238, 0.92);
  --line-soft: rgba(255, 255, 255, 0.82);
  --text: #16202d;
  --muted: #718295;
  --accent: #2c90f1;
  --accent-soft: #e6f1ff;
  --accent-green: #17a45a;
  --accent-gold: #f2b63f;
  --danger: #d84e57;
  --danger-bg: #fff0f2;
  --shadow: 0 24px 64px rgba(92, 113, 141, 0.12);
  --shadow-soft: 0 14px 32px rgba(92, 113, 141, 0.09);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 0%, rgba(255, 255, 255, 0.92) 0, rgba(255, 255, 255, 0) 24%),
    radial-gradient(circle at 88% 6%, rgba(170, 212, 255, 0.36) 0, rgba(170, 212, 255, 0) 18%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-mid) 28%, var(--bg-bottom) 100%);
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

.hidden {
  display: none !important;
}

.page {
  width: min(1160px, calc(100% - 48px));
  margin: 0 auto;
  padding: 34px 0 52px;
}

.admin-tab-panel + .admin-tab-panel {
  margin-top: 0;
}

.auth-panel {
  min-height: calc(100vh - 86px);
  display: grid;
  place-items: center;
}

.auth-card,
.panel,
.stats-card,
.stats-detail-card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line-soft);
  border-radius: 28px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
}

.auth-card::before,
.panel::before,
.stats-card::before,
.stats-detail-card::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 42%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.54), rgba(255, 255, 255, 0));
  pointer-events: none;
}

.auth-card {
  width: min(480px, 100%);
  padding: 34px 32px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.18em;
}

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

h1 {
  font-size: 44px;
  line-height: 1.04;
  font-weight: 800;
}

.subtitle,
.muted {
  color: var(--muted);
}

.subtitle {
  margin-top: 14px;
  font-size: 15px;
  line-height: 1.75;
}

.muted {
  font-size: 13px;
  line-height: 1.6;
}

.muted[data-type="error"] {
  color: var(--danger);
}

.muted[data-type="success"] {
  color: var(--accent-green);
}

.login-form,
.generate-form {
  display: grid;
  gap: 14px;
}

.login-form {
  margin-top: 26px;
}

.generate-form {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding: 22px 24px 24px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.toggle-field {
  justify-content: flex-end;
}

.toggle-field input[type="checkbox"] {
  width: 22px;
  height: 22px;
  margin-top: 10px;
  accent-color: var(--accent);
}

input {
  height: 50px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.76);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

select {
  width: 100%;
  height: 50px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.76);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

select:focus {
  outline: none;
  border-color: rgba(44, 144, 241, 0.4);
  box-shadow: 0 0 0 4px rgba(44, 144, 241, 0.12);
}

input:focus {
  outline: none;
  border-color: rgba(44, 144, 241, 0.4);
  box-shadow: 0 0 0 4px rgba(44, 144, 241, 0.12);
}

.wide {
  grid-column: span 2;
}

.primary-button,
.ghost-button,
.delete-button,
.code-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 16px;
  cursor: pointer;
  transition: transform 180ms ease, opacity 180ms ease, box-shadow 180ms ease;
}

.primary-button:hover,
.ghost-button:hover,
.delete-button:hover,
.code-pill:hover,
.back-link:hover {
  transform: translateY(-1px);
}

.primary-button {
  border: 0;
  color: #ffffff;
  background: linear-gradient(180deg, #63bcff, #197ce0);
  box-shadow: 0 16px 30px rgba(25, 124, 224, 0.24);
  font-weight: 700;
}

.ghost-button,
.code-pill,
.back-link {
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel-strong);
  box-shadow: var(--shadow-soft);
}

.delete-button {
  border: 1px solid rgba(216, 78, 87, 0.18);
  color: var(--danger);
  background: var(--danger-bg);
}

.code-pill {
  min-height: 40px;
  align-items: flex-start;
  justify-content: flex-start;
}

.small-button {
  min-height: 38px;
  padding: 0 12px;
  border-radius: 12px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.top-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.back-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 16px;
  color: var(--text);
  text-decoration: none;
}

.panel + .panel {
  margin-top: 20px;
}

.admin-tabs-panel {
  margin-bottom: 20px;
}

.admin-tabs {
  padding: 18px 20px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.admin-tab {
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background: var(--panel-strong);
  box-shadow: var(--shadow-soft);
  font-weight: 700;
  cursor: pointer;
  transition: transform 180ms ease, opacity 180ms ease, box-shadow 180ms ease;
}

.admin-tab:hover {
  transform: translateY(-1px);
}

.admin-tab.is-active {
  color: #ffffff;
  border-color: transparent;
  background: linear-gradient(180deg, #63bcff, #197ce0);
  box-shadow: 0 16px 30px rgba(25, 124, 224, 0.22);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 24px 24px 0;
  min-height: 96px;
}

.panel-head h2 {
  font-size: 23px;
}

.panel-head > div:first-child {
  min-height: 48px;
}

.stats-overview-grid {
  padding: 18px 24px 12px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}

.stats-card {
  padding: 18px 18px 20px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(244, 248, 252, 0.74));
}

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

.stats-value {
  margin-top: 10px;
  font-size: 30px;
  line-height: 1.1;
  font-weight: 800;
}

.tone-blue .stats-value { color: #2c90f1; }
.tone-green .stats-value { color: #19a15d; }
.tone-red .stats-value { color: #d84e57; }
.tone-cyan .stats-value { color: #1597b8; }
.tone-purple .stats-value { color: #7c61d7; }
.tone-gold .stats-value { color: #d99a18; }
.tone-slate .stats-value { color: #203145; }

.stats-detail-grid {
  padding: 8px 24px 24px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.stats-detail-card {
  padding: 18px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(244, 248, 252, 0.74));
}

.stats-detail-head {
  margin-bottom: 14px;
}

.stats-detail-head h3 {
  font-size: 18px;
}

.stats-bars {
  display: grid;
  gap: 12px;
}

.stats-bar-row {
  display: grid;
  gap: 8px;
}

.stats-bar-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
  font-size: 13px;
}

.stats-bar-meta b {
  font-size: 14px;
}

.stats-bar-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(214, 225, 235, 0.9);
}

.stats-bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #69c2ff 0%, #2c90f1 100%);
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.82fr);
  align-items: start;
  gap: 20px;
  margin-top: 20px;
}

.admin-user-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.04fr) minmax(0, 0.96fr);
  gap: 20px;
  margin-top: 0;
}

.grid > .panel,
.admin-user-grid > .panel {
  align-self: start;
}

.inner-panel {
  border-radius: 24px;
}

.toolbar-input {
  height: 46px;
  min-width: 240px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.76);
}

.compact {
  padding-bottom: 12px;
}

.detail-body {
  padding: 0 24px 24px;
  display: grid;
  gap: 18px;
}

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

.detail-chip {
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--text);
  background: rgba(235, 242, 249, 0.86);
  font-size: 12px;
}

.detail-form,
.detail-block {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.8), rgba(245, 249, 253, 0.72));
}

.detail-form h3,
.detail-block h3 {
  margin-bottom: 14px;
  font-size: 16px;
}

.detail-form {
  display: grid;
  gap: 14px;
}

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

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

.detail-list-row {
  padding: 12px 14px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  border-radius: 16px;
  background: rgba(240, 246, 251, 0.84);
}

.detail-list-row strong,
.detail-list-row span {
  display: block;
}

.detail-list-row p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.detail-list-side {
  text-align: right;
}

.empty-block {
  color: var(--muted);
  font-size: 13px;
}

.active-row td {
  background: rgba(217, 235, 255, 0.76);
}

.user-cell {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.user-cell strong {
  font-size: 13px;
}

.user-cell span {
  color: var(--muted);
  font-size: 12px;
}

.positive-text {
  color: var(--accent-green);
}

.negative-text {
  color: var(--danger);
}

.table-wrap {
  padding: 18px 24px 24px;
  overflow-x: hidden;
  overflow-y: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  padding: 14px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
  word-break: break-word;
}

th:first-child,
td:first-child {
  padding-left: 18px;
}

th:last-child,
td:last-child {
  padding-right: 18px;
}

th {
  color: #7a8da0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

td {
  font-size: 14px;
  color: var(--text);
}

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

.actions-cell {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.status-unused,
.status-active {
  color: #125238;
  background: #dff9ec;
}

.status-used,
.status-expired {
  color: #7a2e32;
  background: #ffe4e7;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 28px 12px;
}

.code-pill {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  text-align: left;
  white-space: normal;
  line-height: 1.45;
  word-break: break-all;
}

.table-wrap table th:nth-child(1),
.table-wrap table td:nth-child(1) {
  width: 22%;
}

.grid > .panel:first-child .table-wrap table th:nth-child(2),
.grid > .panel:first-child .table-wrap table td:nth-child(2) {
  width: 10%;
}

.grid > .panel:first-child .table-wrap table th:nth-child(3),
.grid > .panel:first-child .table-wrap table td:nth-child(3) {
  width: 10%;
}

.grid > .panel:first-child .table-wrap table th:nth-child(4),
.grid > .panel:first-child .table-wrap table td:nth-child(4) {
  width: 12%;
}

.grid > .panel:first-child .table-wrap table th:nth-child(5),
.grid > .panel:first-child .table-wrap table td:nth-child(5) {
  width: 24%;
}

.grid > .panel:first-child .table-wrap table th:nth-child(6),
.grid > .panel:first-child .table-wrap table td:nth-child(6) {
  width: 10%;
}

.grid > .panel:last-child .table-wrap table th:nth-child(1),
.grid > .panel:last-child .table-wrap table td:nth-child(1) {
  width: 32%;
}

.grid > .panel:last-child .table-wrap table th:nth-child(2),
.grid > .panel:last-child .table-wrap table td:nth-child(2) {
  width: 10%;
}

.grid > .panel:last-child .table-wrap table th:nth-child(3),
.grid > .panel:last-child .table-wrap table td:nth-child(3) {
  width: 18%;
}

.grid > .panel:last-child .table-wrap table th:nth-child(4),
.grid > .panel:last-child .table-wrap table td:nth-child(4) {
  width: 8%;
}

.grid > .panel:last-child .table-wrap table th:nth-child(5),
.grid > .panel:last-child .table-wrap table td:nth-child(5) {
  width: 12%;
}

.admin-user-grid > .panel:first-child .table-wrap table th:nth-child(1),
.admin-user-grid > .panel:first-child .table-wrap table td:nth-child(1) {
  width: 28%;
}

.admin-user-grid > .panel:first-child .table-wrap table th:nth-child(2),
.admin-user-grid > .panel:first-child .table-wrap table td:nth-child(2) {
  width: 10%;
}

.admin-user-grid > .panel:first-child .table-wrap table th:nth-child(3),
.admin-user-grid > .panel:first-child .table-wrap table td:nth-child(3) {
  width: 18%;
}

.admin-user-grid > .panel:first-child .table-wrap table th:nth-child(4),
.admin-user-grid > .panel:first-child .table-wrap table td:nth-child(4) {
  width: 10%;
}

.admin-user-grid > .panel:first-child .table-wrap table th:nth-child(5),
.admin-user-grid > .panel:first-child .table-wrap table td:nth-child(5) {
  width: 12%;
}

.admin-user-grid > .panel:first-child .table-wrap table th:nth-child(6),
.admin-user-grid > .panel:first-child .table-wrap table td:nth-child(6) {
  width: 10%;
}

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

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

@media (max-width: 920px) {
  .topbar {
    flex-direction: column;
  }

  h1 {
    font-size: 36px;
  }

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

  .wide {
    grid-column: span 2;
  }

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

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

@media (max-width: 640px) {
  .page {
    width: min(100% - 24px, 1200px);
  }

  .auth-card {
    padding: 24px;
  }

  .generate-form,
  .stats-overview-grid {
    grid-template-columns: 1fr;
  }

  .toolbar-input {
    min-width: 0;
    width: 100%;
  }

  .wide {
    grid-column: span 1;
  }
}
