:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #e5e7eb;
  --line-strong: #d7dce5;
  --text: #111827;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --good: #16a34a;
  --good-soft: #ecfdf3;
  --warn: #ca8a04;
  --warn-soft: #fef9c3;
  --bad: #dc2626;
  --bad-soft: #fef2f2;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 12% 8%, rgba(37, 99, 235, 0.14), transparent 24rem),
    radial-gradient(circle at 88% 0%, rgba(14, 165, 233, 0.12), transparent 22rem),
    linear-gradient(180deg, #fbfdff 0%, var(--bg) 46%, #eef2f7 100%);
  color: var(--text);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(15, 23, 42, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 23, 42, 0.035) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(to bottom, black 0%, transparent 76%);
}

.shell {
  position: relative;
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 34px 0 60px;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  margin-bottom: 22px;
}

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

h1 {
  margin: 0;
  font-size: clamp(34px, 5.4vw, 62px);
  line-height: 1.02;
  letter-spacing: -.055em;
}

h2 {
  margin: 0 0 14px;
  font-size: 22px;
  letter-spacing: -.02em;
}

p { line-height: 1.7; }

.lead {
  max-width: 760px;
  color: var(--muted);
  font-size: 18px;
}

.panel,
.status-card,
.metric-grid article {
  border: 1px solid rgba(226, 232, 240, 0.95);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  border-radius: 26px;
  padding: 24px;
}

.status-card {
  min-width: 210px;
  text-align: center;
}

#sessionBadge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 8px 13px;
  border-radius: 999px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  font-weight: 800;
}

.login {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 28px;
  align-items: center;
}

.hidden { display: none !important; }

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

label {
  color: var(--muted);
  display: grid;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 13px 14px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

input[readonly] {
  color: var(--muted);
  background: var(--surface-soft);
}

input:focus,
textarea:focus {
  border-color: rgba(37, 99, 235, 0.55);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

textarea { resize: vertical; }

button,
a.secondary {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
  text-align: center;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  transition: transform .14s ease, box-shadow .14s ease, background .14s ease;
}

button:hover,
a.secondary:hover {
  transform: translateY(-1px);
}

.primary {
  color: #fff;
  background: linear-gradient(135deg, #3b82f6, var(--primary-dark));
  box-shadow: 0 12px 26px rgba(37, 99, 235, 0.22);
}

.secondary,
.ghost {
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line-strong);
}

.ghost {
  margin-top: 10px;
}

.danger {
  color: var(--bad);
  background: var(--bad-soft);
  border: 1px solid #fecaca;
}

.small {
  padding: 8px 12px;
  font-size: 13px;
}

.tabs {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 18px 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  width: fit-content;
  max-width: 100%;
}

.tab {
  color: var(--muted);
  background: transparent;
}

.tab.active {
  color: #fff;
  background: var(--primary);
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.2);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 18px;
}

.metric-grid article {
  background: linear-gradient(180deg, #fff, #f8fbff);
}

.metric-grid span {
  color: var(--muted);
  font-weight: 800;
}

.metric-grid strong {
  display: block;
  margin-top: 10px;
  font-size: 42px;
  color: var(--primary-dark);
  letter-spacing: -.04em;
}

.grid-2 {
  display: grid;
  grid-template-columns: minmax(320px, .9fr) minmax(420px, 1.1fr);
  gap: 18px;
}

.batch-list,
.ticket-list,
.timeline {
  display: grid;
  gap: 10px;
  max-height: 560px;
  overflow: auto;
  padding-right: 4px;
}

.ticket-panel {
  margin-top: 18px;
}

.batch-card,
.ticket,
.event {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  background: #fff;
}

.event {
  color: var(--muted);
}

.batch-card header,
.ticket header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-weight: 900;
}

.batch-card header strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 10px;
}

.section-head h2 {
  margin-bottom: 4px;
}

.check-all {
  display: inline-flex;
  align-items: center;
  grid-auto-flow: column;
  gap: 8px;
  white-space: nowrap;
  color: var(--text);
}

.ticket-title {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.ticket-select,
#selectAllTickets {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

.badge {
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--warn);
  background: var(--warn-soft);
  white-space: nowrap;
}

.badge.USED {
  color: var(--good);
  background: var(--good-soft);
}

.badge.USED.OUTSIDE {
  color: #0369a1;
  background: #e0f2fe;
}

.badge.VOID {
  color: var(--bad);
  background: var(--bad-soft);
}

.meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
  margin-top: 8px;
}

.ticket-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.camera-stage {
  position: relative;
  overflow: hidden;
  border-radius: 22px;
  background: #0f172a;
  border: 1px solid var(--line);
  isolation: isolate;
}

.scanner video {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.camera-stage::before,
.camera-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
}

.camera-stage::before {
  border: 0 solid rgba(34, 197, 94, .75);
  box-shadow: inset 0 0 0 0 rgba(34, 197, 94, .25);
}

.camera-stage::after {
  height: 4px;
  top: 0;
  inset-inline: 10%;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, #86efac, #22c55e, #86efac, transparent);
  box-shadow: 0 0 28px rgba(34, 197, 94, .9);
}

.qr-detected-effect {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  pointer-events: none;
  color: #fff;
  opacity: 0;
  transform: scale(.98);
  background: radial-gradient(circle at center, rgba(34, 197, 94, .22), transparent 42%);
}

.qr-detected-effect strong {
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(15, 23, 42, .72);
  border: 1px solid rgba(255,255,255,.42);
  backdrop-filter: blur(10px);
  font-size: 20px;
  letter-spacing: .04em;
  box-shadow: 0 18px 55px rgba(0,0,0,.28);
}

.qr-target {
  position: relative;
  width: min(42%, 190px);
  aspect-ratio: 1;
  border-radius: 24px;
}

.qr-target span {
  position: absolute;
  width: 38px;
  height: 38px;
  border-color: #fff;
  filter: drop-shadow(0 0 10px rgba(34, 197, 94, .9));
}

.qr-target span:nth-child(1) {
  top: 0;
  left: 0;
  border-top: 5px solid;
  border-left: 5px solid;
  border-top-left-radius: 18px;
}

.qr-target span:nth-child(2) {
  top: 0;
  right: 0;
  border-top: 5px solid;
  border-right: 5px solid;
  border-top-right-radius: 18px;
}

.qr-target span:nth-child(3) {
  bottom: 0;
  left: 0;
  border-bottom: 5px solid;
  border-left: 5px solid;
  border-bottom-left-radius: 18px;
}

.qr-target span:nth-child(4) {
  right: 0;
  bottom: 0;
  border-right: 5px solid;
  border-bottom: 5px solid;
  border-bottom-right-radius: 18px;
}

.camera-stage.qr-detected::before {
  animation: detectedFrame .78s ease-out both;
}

.camera-stage.qr-detected::after {
  animation: detectedScanLine .72s cubic-bezier(.2, .8, .2, 1) both;
}

.camera-stage.qr-detected .qr-detected-effect {
  animation: detectedPop .78s cubic-bezier(.2, 1.25, .3, 1) both;
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 2px 0 14px;
}

.mode-switch label {
  cursor: pointer;
}

.mode-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-switch span {
  display: grid;
  place-items: center;
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--muted);
  font-weight: 900;
}

.mode-switch input:checked + span {
  border-color: rgba(37, 99, 235, .28);
  background: linear-gradient(135deg, var(--primary), #0ea5e9);
  color: #fff;
  box-shadow: 0 14px 30px rgba(37, 99, 235, .18);
}

.scan-feedback {
  margin-top: 12px;
  border-radius: 22px;
  padding: 18px;
  display: grid;
  gap: 4px;
  text-align: center;
  border: 2px solid var(--line);
  background: var(--surface-soft);
}

.scan-feedback strong {
  font-size: 30px;
  letter-spacing: -.04em;
}

.scan-feedback span {
  color: var(--muted);
  font-weight: 800;
}

.scan-feedback.ok {
  color: #fff;
  background: linear-gradient(135deg, #16a34a, #15803d);
  border-color: #15803d;
  box-shadow: 0 18px 40px rgba(22, 163, 74, .24);
}

.scan-feedback.ok span {
  color: rgba(255, 255, 255, .9);
}

.scan-feedback.bad {
  color: #fff;
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  border-color: #b91c1c;
  box-shadow: 0 18px 40px rgba(220, 38, 38, .25);
}

.scan-feedback.bad span {
  color: rgba(255, 255, 255, .9);
}

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

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

code {
  padding: 2px 6px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.result-card {
  border-radius: 22px;
  padding: 18px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  min-height: 86px;
  color: var(--muted);
}

.result-card.ok {
  color: #166534;
  border-color: #bbf7d0;
  background: var(--good-soft);
}

.result-card.bad {
  color: #991b1b;
  border-color: #fecaca;
  background: var(--bad-soft);
}

#toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: 360px;
  display: grid;
  gap: 10px;
  z-index: 20;
}

.toast {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 20px 50px rgba(15, 23, 42, .16);
}

.checkin-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 18px;
  color: #fff;
  text-align: center;
  backdrop-filter: blur(12px);
  animation: overlayFadeIn .18s ease-out both;
}

.checkin-overlay.ok {
  background:
    radial-gradient(circle at center, rgba(255,255,255,.22), transparent 22rem),
    linear-gradient(135deg, rgba(22, 163, 74, .94), rgba(21, 128, 61, .94));
}

.checkin-overlay.bad {
  background:
    radial-gradient(circle at center, rgba(255,255,255,.18), transparent 22rem),
    linear-gradient(135deg, rgba(239, 68, 68, .95), rgba(153, 27, 27, .95));
}

.checkin-mark {
  width: 150px;
  height: 150px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  border: 5px solid rgba(255,255,255,.88);
  box-shadow: 0 24px 80px rgba(0,0,0,.22), inset 0 0 0 10px rgba(255,255,255,.14);
  font-size: 96px;
  font-weight: 900;
  line-height: 1;
  animation: markPop .42s cubic-bezier(.2, 1.4, .35, 1) both;
}

.checkin-overlay strong {
  font-size: clamp(48px, 9vw, 108px);
  line-height: .95;
  letter-spacing: -.07em;
  text-shadow: 0 12px 36px rgba(0,0,0,.2);
  animation: slideUp .36s ease-out .06s both;
}

.checkin-overlay span {
  max-width: min(820px, calc(100vw - 36px));
  font-size: clamp(18px, 3vw, 34px);
  font-weight: 800;
  opacity: .95;
  animation: slideUp .36s ease-out .12s both;
}

@keyframes overlayFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes markPop {
  0% { transform: scale(.65) rotate(-8deg); opacity: 0; }
  70% { transform: scale(1.08) rotate(0); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(18px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes detectedFrame {
  0% {
    opacity: 0;
    border-width: 0;
    box-shadow: inset 0 0 0 0 rgba(34, 197, 94, 0);
  }
  26% {
    opacity: 1;
    border-width: 5px;
    box-shadow: inset 0 0 0 999px rgba(34, 197, 94, .09);
  }
  100% {
    opacity: 0;
    border-width: 1px;
    box-shadow: inset 0 0 0 0 rgba(34, 197, 94, 0);
  }
}

@keyframes detectedScanLine {
  0% {
    opacity: 0;
    top: 0;
    transform: scaleX(.6);
  }
  18% {
    opacity: 1;
  }
  78% {
    opacity: 1;
    top: calc(100% - 4px);
    transform: scaleX(1);
  }
  100% {
    opacity: 0;
    top: calc(100% - 4px);
    transform: scaleX(.85);
  }
}

@keyframes detectedPop {
  0% {
    opacity: 0;
    transform: scale(.86);
  }
  28% {
    opacity: 1;
    transform: scale(1.03);
  }
  72% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(.98);
  }
}

@media (max-width: 860px) {
  .hero,
  .login,
  .grid-2 {
    grid-template-columns: 1fr;
    display: grid;
  }

  .tabs {
    border-radius: 22px;
    width: 100%;
  }

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

  h1 {
    font-size: 40px;
  }
}
