:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --line: #d9e2ec;
  --line-soft: #eef2f6;
  --text: #17212f;
  --muted: #657386;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --blue-soft: #eff6ff;
  --danger: #dc2626;
  --danger-soft: #fff1f2;
  --success: #047857;
  --success-soft: #ecfdf5;
  --warning: #a16207;
  --warning-soft: #fffbeb;
  --shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

html,
body { min-height: 100%; }

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  font-size: 13px;
  line-height: 1.45;
}

h1,
h2,
p { margin: 0; }

h1 {
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: 0;
}

h2 {
  font-size: 16px;
  line-height: 1.3;
}

a { text-decoration: none; }

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

button { cursor: pointer; }

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

.app-shell {
  width: min(1440px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 32px;
}

.app-shell.narrow {
  width: min(960px, calc(100% - 28px));
  padding-top: 42px;
}

.login-wrap .app-shell.narrow,
main.app-shell.narrow:has(.login-panel) {
  width: min(960px, calc(100% - 28px));
  padding-top: 42px;
}

.topbar,
.panel,
.login-panel,
.tabs {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.glass-panel {
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.front-hero {
  align-items: stretch;
  padding: 18px;
}

.hero-copy {
  display: grid;
  align-content: center;
  gap: 6px;
  min-width: 280px;
}

.hero-copy h1 {
  font-size: 24px;
}

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

.front-hero-side {
  flex: 1;
  max-width: 760px;
  display: grid;
  grid-template-columns: 170px minmax(420px, 1fr);
  gap: 12px;
  align-items: stretch;
}

.business-card {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: linear-gradient(135deg, #eff6ff 0%, #ffffff 58%, #eef2ff 100%);
}

.business-title {
  color: #1e3a8a;
  font-size: 14px;
  font-weight: 800;
}

.business-desc {
  margin-top: 4px;
  color: #334155;
  font-weight: 600;
}

.support-note {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.wechat-box {
  min-width: 172px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding-left: 14px;
  border-left: 1px solid #c7d2fe;
}

.wechat-box span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.wechat-box strong {
  color: #1d4ed8;
  font-size: 15px;
  line-height: 1.2;
}

.muted {
  color: var(--muted);
  margin-top: 4px;
}

.stock-box {
  min-width: 160px;
  display: grid;
  gap: 2px;
  padding: 10px 14px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: var(--blue-soft);
}

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

.stock-box strong {
  color: #1d4ed8;
  font-size: 26px;
  line-height: 1;
}

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

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.form-grid {
  display: grid;
  gap: 10px;
  align-items: end;
}

.user-grid {
  grid-template-columns: minmax(260px, 1fr) 260px auto;
}

.card-generate-grid {
  grid-template-columns: 140px 140px minmax(240px, 1fr);
  margin-bottom: 10px;
}

.field {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.inline-field {
  min-width: 160px;
}

.inline-field.grow {
  flex: 1;
  min-width: 260px;
}

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

textarea {
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #93b4ff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.btn {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  color: #263445;
  background: #fff;
  white-space: nowrap;
  font-weight: 600;
}

.btn:hover { background: var(--panel-soft); }

.btn.full { width: 100%; }

.btn-primary {
  color: #fff;
  border-color: var(--primary);
  background: var(--primary);
}

.btn-primary:hover { background: var(--primary-hover); }

.btn-blue {
  color: var(--primary);
  border-color: #bcd0ff;
  background: var(--blue-soft);
}

.btn-blue:hover { background: #dbeafe; }

.btn-blue-soft {
  color: var(--primary);
  border-color: #bcd0ff;
  background: var(--blue-soft);
}

.btn-blue-soft:hover { background: #dbeafe; }

.btn-white {
  color: #334155;
  background: #fff;
}

.btn-danger-soft {
  color: var(--danger);
  border-color: #fecaca;
  background: var(--danger-soft);
}

.btn-danger-soft:hover { background: #ffe4e6; }

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

.button-row.end { justify-content: flex-end; }

.message-box {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  color: #1e3a8a;
  background: var(--blue-soft);
}

.message-box.error {
  color: #991b1b;
  border-color: #fecaca;
  background: #fef2f2;
}

.result-area {
  min-height: 320px;
}

.compact-area {
  min-height: 142px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  z-index: 60;
  max-width: min(520px, calc(100% - 32px));
  padding: 10px 14px;
  color: #fff;
  background: rgba(15, 23, 42, 0.92);
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.login-wrap {
  min-height: calc(100vh - 80px);
  display: grid;
  place-items: center;
}

.login-panel {
  width: min(380px, 100%);
  display: grid;
  gap: 14px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 6px;
  margin-bottom: 12px;
}

.tab {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  padding: 7px 14px;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
}

.tab.active {
  color: #fff;
  background: var(--primary);
}

.tab-view { margin-bottom: 12px; }

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

.stat-card {
  min-height: 88px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.stat-card span {
  color: var(--muted);
  font-weight: 600;
}

.stat-card strong {
  font-size: 24px;
  line-height: 1;
}

.toolbar {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: #475569;
  background: #f8fafc;
  font-size: 12px;
  font-weight: 800;
}

td {
  color: #263445;
  word-break: break-all;
}

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

.select-col input {
  width: auto;
  min-height: 0;
}

.token-cell {
  max-width: 190px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: normal;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.badge.available,
.badge.unused {
  color: var(--success);
  background: var(--success-soft);
}

.badge.extracted,
.badge.used {
  color: #1d4ed8;
  background: var(--blue-soft);
}

.badge.disabled {
  color: var(--danger);
  background: var(--danger-soft);
}

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

.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.45);
}

.modal {
  width: min(820px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

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

  .front-hero-side {
    width: 100%;
    max-width: none;
    grid-template-columns: 1fr;
  }

  .business-card {
    width: 100%;
    flex-direction: column;
  }

  .wechat-box {
    min-width: 0;
    padding-left: 0;
    padding-top: 10px;
    border-left: 0;
    border-top: 1px solid #c7d2fe;
  }

  .user-grid,
  .card-generate-grid {
    grid-template-columns: 1fr;
  }

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

  .stock-box {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .app-shell,
  .app-shell.narrow {
    width: calc(100% - 18px);
    padding-top: 12px;
  }

  .tabs {
    overflow-x: auto;
  }

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

  .button-row,
  .toolbar {
    width: 100%;
  }

  .btn {
    min-width: 0;
  }
}
