:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-soft: #f1f5f9;
  --surface: #ffffff;
  --sidebar: #0f172a;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-soft: #edf2f7;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --teal: #0891b2;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --gold: #f97316;
  --gold-soft: #ffedd5;
  --indigo: #4f46e5;
  --shadow: 0 12px 28px rgba(15, 23, 42, .08);
  --radius-l: 8px;
  --radius-m: 8px;
  --radius-s: 6px;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
}

a {
  color: inherit;
  text-decoration: none;
}

input,
select,
textarea,
button {
  font-family: inherit;
  font-size: 14px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line) !important;
  background: #fff !important;
  color: var(--text) !important;
  border-radius: var(--radius-m) !important;
  padding: 11px 12px !important;
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease;
}

input::placeholder,
textarea::placeholder {
  color: #94a3b8;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #93c5fd !important;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .14) !important;
}

label {
  display: block;
  color: #334155;
  font-size: 13px;
  font-weight: 700;
  margin: 14px 0 7px;
}

.shell {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 48px;
}

body.logged-out .shell {
  width: min(520px, calc(100% - 32px));
  padding-top: 26px;
}

body.logged-out .hero {
  align-items: flex-start;
}

body.logged-out .login-only .card {
  max-width: none !important;
}

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

.eyebrow {
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 5px;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.25;
  letter-spacing: 0;
}

h2,
h3 {
  color: var(--text);
  letter-spacing: 0;
}

.hero p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.65;
  max-width: 720px;
  font-size: 13px;
}

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

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

.who strong {
  color: var(--text);
}

.card {
  background: var(--panel) !important;
  border: 1px solid var(--line) !important;
  border-radius: var(--radius-l) !important;
  box-shadow: var(--shadow);
  padding: 18px;
  backdrop-filter: none;
}

.card + .card { margin-top: 14px; }

.card-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  color: var(--text);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0;
}

.hint {
  color: var(--muted) !important;
  font-size: 13px;
  line-height: 1.65;
}

.btn {
  min-height: 38px;
  border: 1px solid var(--line);
  cursor: pointer;
  border-radius: var(--radius-m);
  padding: 9px 12px;
  color: var(--text);
  font-weight: 700;
  background: var(--panel);
  transition: border-color .18s ease, background .18s ease, color .18s ease, transform .18s ease;
  box-shadow: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn:hover {
  border-color: #bfdbfe;
  color: var(--blue);
  transform: none;
  filter: none;
}

.btn:active {
  transform: none;
}

.btn:disabled {
  opacity: .55;
  cursor: not-allowed;
  filter: grayscale(.2);
  transform: none;
}

.btn.full { width: 100%; }

.btn:not(.ghost):not(.green):not(.warn):not(.red) {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.btn:not(.ghost):not(.green):not(.warn):not(.red):hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
  color: #fff;
}

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

.btn.green:hover {
  background: #15803d;
  border-color: #15803d;
  color: #fff;
}

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

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

.btn.red:hover {
  background: var(--red-soft);
  border-color: #fca5a5;
  color: #b91c1c;
}

.btn.ghost {
  background: var(--panel);
  color: var(--text) !important;
  border: 1px solid var(--line);
}

.btn.ghost:hover {
  color: var(--blue) !important;
}

.btn.sm {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 12px;
  border-radius: var(--radius-s);
}

.pill {
  border: 1px solid var(--line);
  background: var(--panel-soft);
  border-radius: 999px;
  padding: 7px 11px;
  color: var(--muted);
  white-space: nowrap;
  font-size: 12px;
  font-weight: 700;
}

.pill.green {
  color: #166534;
  border-color: #bbf7d0;
  background: var(--green-soft);
}

.pill.red {
  color: #991b1b;
  border-color: #fecaca;
  background: var(--red-soft);
}

.msg {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-m);
  font-size: 13px;
  line-height: 1.6;
  display: none;
  white-space: pre-wrap;
}

.msg.show { display: block; }

.msg.ok {
  background: var(--green-soft);
  border: 1px solid #bbf7d0;
  color: #166534;
}

.msg.err {
  background: var(--red-soft);
  border: 1px solid #fecaca;
  color: #991b1b;
}

.msg.info {
  background: var(--blue-soft);
  border: 1px solid #bfdbfe;
  color: #1e40af;
}

.kpi,
.stat-banner {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.kpi-item,
.stat-banner > * {
  border: 1px solid var(--line) !important;
  background: var(--panel) !important;
  border-radius: var(--radius-l) !important;
  padding: 14px;
  box-shadow: 0 1px 0 rgba(15, 23, 42, .03);
}

.kpi-label {
  color: var(--muted);
  font-size: 12px;
}

.kpi-value {
  margin-top: 6px;
  color: var(--text);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0;
}

.kpi-value.green { color: var(--green); }
.kpi-value.gold { color: var(--gold); }
.kpi-value.blue { color: var(--blue); }

.table-wrap,
div[style*="overflow-x:auto"] {
  overflow: auto;
  border: 1px solid var(--line) !important;
  border-radius: var(--radius-l) !important;
  background: var(--panel) !important;
}

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

th,
td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft) !important;
  color: var(--text);
  font-size: 13px;
  vertical-align: top;
}

th,
table.admins thead th {
  color: #475569 !important;
  background: #f8fafc !important;
  position: sticky;
  top: 0;
  z-index: 1;
  font-weight: 700;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 700;
}

.badge.unused,
.badge.active {
  color: #166534;
  background: var(--green-soft);
}

.badge.running {
  color: #9a3412;
  background: var(--gold-soft);
}

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

.badge.cancelled,
.badge.disabled {
  color: #991b1b;
  background: var(--red-soft);
}

.url-cell {
  max-width: 320px;
  word-break: break-all;
  color: var(--blue);
}

.copy-line {
  display: flex;
  gap: 8px;
  align-items: center;
}

.copy-line input { flex: 1; }

.tab-row {
  display: flex;
  gap: 4px;
  background: var(--panel-soft) !important;
  border: 1px solid var(--line);
  padding: 4px;
  border-radius: var(--radius-l);
  margin-bottom: 16px;
}

.tab-row .tab {
  flex: 1;
  text-align: center;
  padding: 9px 10px;
  border-radius: var(--radius-s);
  cursor: pointer;
  color: #475569;
  font-weight: 700;
  font-size: 13px;
  transition: background .15s ease, color .15s ease;
}

.tab-row .tab:hover {
  color: var(--blue);
}

.tab-row .tab.active {
  color: #fff;
  background: var(--blue);
  box-shadow: none;
}

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

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

.drag-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(219, 234, 254, .82);
  z-index: 9999;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  gap: 12px;
  border: 4px dashed var(--blue);
  pointer-events: none;
}

.drag-overlay.visible { display: flex; }

.drag-overlay-icon {
  font-size: 72px;
  animation: none;
}

.drag-overlay-text {
  font-size: 22px;
  color: #1e40af;
  font-weight: 700;
}

.drag-overlay-hint {
  font-size: 14px;
  color: #475569;
}

.upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  background: var(--panel);
  border: 1px dashed #cbd5e1;
  border-radius: var(--radius-m);
  color: #475569;
  font-size: 13px;
  cursor: pointer;
  transition: border-color .18s ease, color .18s ease, background .18s ease;
}

.upload-btn:hover {
  border-color: var(--blue);
  color: var(--blue);
  background: #eff6ff;
}

.cdk-modal {
  background: rgba(15, 23, 42, .46) !important;
}

.cdk-modal .box {
  background: var(--panel) !important;
  border: 1px solid var(--line) !important;
  border-radius: var(--radius-l) !important;
  box-shadow: var(--shadow);
}

pre,
textarea,
div[style*="background:#060a14"],
div[style*="background: #060a14"],
input[style*="background:#060a14"],
input[style*="background: #060a14"] {
  background: #f8fafc !important;
  border-color: var(--line) !important;
  color: var(--text) !important;
}

div[style*="border: 2px dashed #303b52"] {
  border-color: #cbd5e1 !important;
  background: #f8fafc !important;
  color: #475569 !important;
}

section[style*="rgba(255,92,122"] {
  border-color: #fecaca !important;
  background: #fff7f7 !important;
}

section[style*="rgba(255,92,122"] h3 {
  color: #991b1b !important;
}

@media (max-width: 980px) {
  .grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .shell {
    width: min(100% - 24px, 1240px);
    padding: 16px 0 34px;
  }

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

  .tab-row {
    overflow-x: auto;
  }

  .tab-row .tab {
    min-width: 96px;
  }

  table {
    min-width: 680px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}

body.logged-in .shell:has(.admin-console) {
  width: 100%;
  min-height: 100vh;
  padding: 0;
}

body.logged-in .shell:has(.admin-console) > .hero {
  display: none;
}

body.logged-in .admin-console {
  display: grid !important;
  grid-template-columns: 254px minmax(0, 1fr);
  min-height: 100vh;
  background: var(--bg);
}

.admin-sidebar {
  background: var(--sidebar);
  color: #e2e8f0;
  min-height: 100vh;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  overflow-y: auto;
}

.side-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 10px 18px;
  border-bottom: 1px solid rgba(226, 232, 240, .12);
  margin-bottom: 16px;
}

.side-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--blue);
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  flex: 0 0 auto;
}

.side-brand strong {
  display: block;
  color: #fff;
  font-size: 17px;
  line-height: 1.2;
}

.side-brand span {
  display: block;
  margin-top: 4px;
  color: #94a3b8;
  font-size: 12px;
}

.side-group {
  margin-top: 18px;
}

.side-title {
  color: #94a3b8;
  font-size: 12px;
  padding: 0 10px 8px;
}

.side-tabs.tab-row {
  display: grid;
  gap: 4px;
  background: transparent !important;
  border: 0;
  padding: 0;
  margin: 0;
}

.side-tabs .tab {
  text-align: left;
  flex: none;
  color: #cbd5e1;
  border-radius: 8px;
  padding: 11px 10px;
  min-width: 0;
}

.side-tabs .tab:hover,
.side-tabs .tab.active {
  background: rgba(37, 99, 235, .22);
  color: #fff;
}

.side-note {
  margin: 22px 8px 0;
  padding: 12px;
  border-radius: 8px;
  background: rgba(15, 23, 42, .48);
  border: 1px solid rgba(226, 232, 240, .12);
  color: #94a3b8;
  font-size: 12px;
  line-height: 1.7;
}

.side-actions {
  display: grid;
  gap: 8px;
  margin: 22px 8px 0;
}

.side-actions .btn {
  width: 100%;
  justify-content: center;
}

.admin-main {
  min-width: 0;
  padding: 22px;
}

.admin-main::before {
  content: "卡密系统后台";
  display: block;
  margin: 0 0 16px;
  color: var(--text);
  font-size: 24px;
  font-weight: 800;
  line-height: 1.25;
}

.super-main::before {
  content: "超级管理后台";
}

@media (max-width: 900px) {
  body.logged-in .admin-console {
    grid-template-columns: 1fr;
  }

  .admin-sidebar {
    position: static;
    min-height: auto;
  }

  .side-tabs.tab-row {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }

  .admin-main {
    padding: 16px;
  }
}
