:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --text: #17202a;
  --muted: #667085;
  --line: #d9dee7;
  --blue: #2563eb;
  --blue-hover: #1d4ed8;
  --orange: #e67e22;
  --orange-hover: #ca6f1e;
  --red: #dc2626;
  --red-hover: #b91c1c;
  --gray: #5f6b7a;
  --gray-hover: #4b5563;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", sans-serif;
  font-size: 15px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand {
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
  text-decoration: none;
}

nav {
  display: flex;
  gap: 18px;
}

nav a {
  color: var(--muted);
  text-decoration: none;
}

nav a:hover {
  color: var(--text);
}

.page {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.hero,
.page-title,
.with-action {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 24px;
}

h1 {
  margin: 0 0 8px;
  font-size: 34px;
  line-height: 1.2;
}

h2 {
  margin: 0 0 14px;
  font-size: 20px;
}

p {
  margin: 0;
  color: var(--muted);
}

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

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

.stat.wide {
  grid-column: span 2;
}

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

.stat strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 20px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 26px;
}

.primary-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border: 0;
  border-radius: 6px;
  color: white;
  cursor: pointer;
  font: inherit;
  font-weight: 650;
  text-decoration: none;
  white-space: nowrap;
}

.button.blue { background: var(--blue); }
.button.blue:hover { background: var(--blue-hover); }
.button.orange { background: var(--orange); }
.button.orange:hover { background: var(--orange-hover); }
.button.red { background: var(--red); }
.button.red:hover { background: var(--red-hover); }
.button.gray { background: var(--gray); }
.button.gray:hover { background: var(--gray-hover); }

.button.large {
  min-height: 54px;
  width: 100%;
}

.button.small {
  min-height: 32px;
  padding: 0 12px;
  font-size: 13px;
}

.notice {
  margin-bottom: 18px;
  padding: 14px 16px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 8px;
}

.notice a {
  color: var(--blue);
  font-weight: 700;
}

.debug {
  margin-bottom: 26px;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.debug summary {
  cursor: pointer;
  font-weight: 700;
}

.debug-actions {
  margin: 16px 0 0;
}

.inline-message {
  color: var(--orange);
  font-weight: 700;
}

.result {
  margin-bottom: 20px;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.result.success {
  border-color: #9ad3ad;
}

.result.danger {
  border-color: #f2a0a0;
}

.result-head {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}

.result-head span {
  color: var(--muted);
}

pre {
  overflow: auto;
  margin: 0;
  padding: 12px;
  background: #111827;
  color: #f9fafb;
  border-radius: 6px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.table-section,
.guide {
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

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

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

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

td {
  overflow-wrap: anywhere;
}

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

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

.guide h2 {
  margin-top: 20px;
}

.guide h2:first-child {
  margin-top: 0;
}

.upload-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
}

.upload-panel {
  display: grid;
  gap: 14px;
  max-width: 680px;
}

.upload-status {
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fafb;
}

.upload-status strong {
  font-size: 17px;
}

.upload-status span {
  color: var(--muted);
}

.upload-status.active {
  border-color: #fdba74;
  background: #fff7ed;
}

.qr-upload-form input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.upload-choice {
  width: 100%;
  min-height: 92px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font: inherit;
}

.upload-choice strong,
.upload-choice span {
  display: block;
}

.upload-choice strong {
  margin-bottom: 8px;
  font-size: 20px;
}

.upload-choice span {
  color: var(--muted);
  line-height: 1.5;
}

.upload-choice.camera {
  border-color: #93c5fd;
  background: #eff6ff;
}

.upload-choice.album {
  border-color: #fdba74;
  background: #fff7ed;
}

.upload-choice:disabled {
  cursor: wait;
  opacity: 0.7;
}

.qr-progress-card {
  margin-bottom: 18px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.qr-progress-card.pending,
.qr-progress-card.running {
  border-color: #fdba74;
  background: #fff7ed;
}

.qr-progress-card.success {
  border-color: #86efac;
  background: #f0fdf4;
}

.qr-progress-card.failed,
.qr-progress-card.cancelled {
  border-color: #fca5a5;
  background: #fef2f2;
}

.qr-progress-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.qr-progress-head h2 {
  margin-bottom: 6px;
  font-size: 22px;
}

.qr-badge {
  flex: 0 0 auto;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--text);
  color: white;
  font-size: 13px;
  font-weight: 700;
}

.qr-steps {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  padding: 0;
  margin: 0 0 12px;
  list-style: none;
}

.qr-steps li {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.qr-steps li.done {
  border-color: #22c55e;
  background: #dcfce7;
  color: #166534;
}

.refresh-note {
  color: var(--orange);
  font-weight: 700;
}

@media (max-width: 820px) {
  .topbar,
  .hero,
  .page-title,
  .with-action {
    flex-direction: column;
    align-items: stretch;
  }

  nav {
    flex-wrap: wrap;
  }

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

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

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

  .button {
    width: 100%;
  }

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

  .qr-progress-head {
    flex-direction: column;
  }
}
