:root {
  --ink: #12141a;
  --muted: #5c6570;
  --bg: #eef1f4;
  --card: #ffffff;
  --line: #e3e7ee;
  --red: #e10600;
  --red-dark: #b80500;
  --green: #0b7a43;
  --green-bg: #e8f7ef;
  --amber: #8a4d00;
  --amber-bg: #fff6e5;
  --shadow: 0 1px 2px rgba(18, 20, 26, .04), 0 12px 32px rgba(18, 20, 26, .06);
  --radius: 20px;
  --max: 1080px;
  color-scheme: light;
}

* { box-sizing: border-box; }

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

body {
  font-family: Manrope, system-ui, -apple-system, Segoe UI, sans-serif;
  background:
    radial-gradient(720px 280px at 100% 0, rgba(225, 6, 0, .08), transparent 70%),
    var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

img { max-width: 100%; height: auto; }

button, input { font: inherit; color: inherit; }

a { color: inherit; }

.shell {
  width: min(var(--max), calc(100% - 32px));
  margin: 0 auto;
  padding-bottom: calc(40px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: env(safe-area-inset-top);
  background: rgba(238, 241, 244, .88);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(227, 231, 238, .9);
}

.topbar-inner {
  width: min(var(--max), calc(100% - 32px));
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 0;
}

.brand {
  display: flex;
  align-items: center;
  text-decoration: none;
  min-width: 0;
}

.brand strong { display: block; font-size: 18px; letter-spacing: -.04em; }
.brand span { display: block; color: var(--muted); font-size: 12px; font-weight: 650; }

.nav {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
  gap: 6px;
}

.nav a {
  text-align: center;
  text-decoration: none;
  font-weight: 750;
  font-size: 14px;
  padding: 9px 14px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--line);
}

.nav a.on {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.nav a.logout {
  background: transparent;
  border-color: transparent;
}

.page { padding-top: 28px; }

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

.page-head h1 {
  margin: 0 0 8px;
  font-size: clamp(1.9rem, 4vw, 2.6rem);
  letter-spacing: -.045em;
  line-height: 1.05;
}

.lede { margin: 0 0 22px; color: var(--muted); max-width: 46rem; font-size: 1.02rem; }

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

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

.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.stat em {
  display: block;
  font-style: normal;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.stat b {
  display: block;
  margin-top: 4px;
  font-size: clamp(1.7rem, 4vw, 2.1rem);
  letter-spacing: -.04em;
  font-variant-numeric: tabular-nums;
}

.stat.good b { color: var(--green); }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.login-card { max-width: 420px; margin: 24px auto 0; padding: 28px 24px; }
.login-card .lede { margin-bottom: 18px; }
.share-card { margin-bottom: 16px; }
.share-card .btn { margin-top: 12px; }

.band-frame {
  overflow: hidden;
  border-radius: 14px;
  background: #f7f8fa;
  border: 1px solid var(--line);
}

.band-frame img, #previewImg { display: block; width: 100%; height: auto; }

.actions {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.field { display: grid; gap: 6px; }

.field span { font-size: 13px; font-weight: 750; color: var(--muted); }

input[type="number"],
input[type="text"],
input[type="search"],
input[type="password"],
input:not([type]) {
  width: 100%;
  border: 1px solid var(--line);
  background: #fbfcfd;
  border-radius: 14px;
  padding: 14px 14px;
  font-size: 16px;
  outline: none;
}

input:focus {
  border-color: var(--ink);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(18, 20, 26, .08);
}

.password-wrap { position: relative; }
.password-wrap input { padding-right: 52px; }
.eye {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.eye svg { width: 22px; height: 22px; display: block; }
.eye .eye-closed { display: none; }
.eye.on .eye-open { display: none; }
.eye.on .eye-closed { display: block; }

.btn-row, .quick-links { display: grid; gap: 10px; }

.quick-links { margin-top: 16px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid transparent;
  text-decoration: none;
  font-weight: 800;
  cursor: pointer;
  letter-spacing: -.02em;
}

.btn.primary { background: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-dark); }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn.dark { background: var(--ink); color: #fff; width: 100%; margin-top: 12px; }
.btn.stop { background: #8d2f39; color: #fff; }
.btn:disabled { opacity: .55; cursor: progress; }

.note, .warn { margin: 12px 0 0; color: var(--muted); font-size: 14px; }

.warn {
  color: #8f1d18;
  background: #fdecea;
  border-radius: 12px;
  padding: 10px 12px;
}

.alert {
  background: #fdecea;
  color: #8f1d18;
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
  font-weight: 700;
}

.hidden { display: none !important; }

.preview { margin-top: 16px; }

.preview figcaption {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.preview img {
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
}

.toolbar {
  display: grid;
  gap: 10px;
  margin: 0 0 16px;
}

.toolbar input { min-width: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 9px 14px;
  font-weight: 750;
  cursor: pointer;
}

.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }

.scan-method { margin: 0 0 14px; }

.method-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.method-switch button {
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  font-size: 15px;
  cursor: pointer;
}

.method-switch button.on {
  background: var(--ink);
  color: #fff;
}

.method-help {
  margin: 8px 2px 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

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

.row-card, .table-wrap {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.table-wrap { overflow: auto; max-height: 70vh; }

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

th, td {
  text-align: left;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: #fbfcfd;
  font-size: 12px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 800;
  background: #f3f5f8;
  color: var(--muted);
}

.pill.in { background: var(--green-bg); color: var(--green); }

.empty {
  background: var(--card);
  border: 1px dashed var(--line);
  border-radius: 16px;
  padding: 32px 18px;
  text-align: center;
  color: var(--muted);
}

.scan-live {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 0 14px;
  padding: 12px 16px;
  background: var(--ink);
  color: #fff;
  border-radius: 16px;
}

.scan-live b {
  font-size: 1.8rem;
  letter-spacing: -.04em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.scan-live span { color: rgba(255, 255, 255, .78); font-weight: 700; }

.camera {
  background: #12141a;
  border-radius: 18px;
  overflow: hidden;
  min-height: 200px;
}

#qr-reader, #qr-reader video {
  width: 100% !important;
  border-radius: 18px;
}

.result {
  margin-top: 14px;
  border-radius: 20px;
  padding: 22px 16px 18px;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.result .kicker { font-weight: 800; letter-spacing: .08em; text-transform: uppercase; font-size: 12px; }
.result .serial {
  font-size: clamp(2.8rem, 14vw, 4.6rem);
  font-weight: 800;
  letter-spacing: -.05em;
  line-height: .95;
  margin: 6px 0;
  font-variant-numeric: tabular-nums;
}
.result .serial:empty { display: none; }
.result .detail { color: inherit; opacity: .78; }
.result.welcome { background: var(--green-bg); color: var(--green); border-color: transparent; }
.result.already { background: #fde8e6; color: #9f2218; border-color: transparent; }
.result.unknown { background: var(--amber-bg); color: var(--amber); border-color: transparent; }

.manual { display: grid; gap: 10px; margin-top: 14px; }

.barcode-box input {
  min-height: 64px;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: .02em;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(18, 20, 26, .46);
  display: none;
  z-index: 40;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  overflow-y: auto;
}

.overlay[hidden] { display: none !important; }
.overlay.scan-open {
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.scan-dialog { text-align: left; }
.scan-dialog .kicker {
  margin: 0;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.scan-open.welcome .kicker,
.scan-open.welcome .dialog-serial { color: var(--green); }
.scan-open.already .kicker,
.scan-open.already .dialog-serial { color: #9f2218; }
.scan-open.invalid .kicker,
.scan-open.invalid .dialog-serial { color: var(--amber); }
.dialog-message {
  margin: 0 0 16px;
  font-weight: 750;
  color: var(--ink);
}
.scan-open.invalid .dialog-serial {
  font-size: clamp(1.4rem, 6vw, 2.2rem);
  overflow-wrap: anywhere;
}
.dialog-serial {
  margin: 4px 0 14px;
  font-size: clamp(2.4rem, 10vw, 3.4rem);
  letter-spacing: -.05em;
  line-height: 1;
}
.details { display: grid; gap: 10px; margin: 0 0 16px; }
.details div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  min-width: 0;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.details dt { flex: none; color: var(--muted); font-weight: 700; }
.details dd {
  min-width: 0;
  margin: 0;
  font-weight: 800;
  text-align: right;
  overflow-wrap: anywhere;
}
.scan-dialog .btn { width: 100%; }

.overlay .panel {
  width: min(460px, 100%);
  margin-top: auto;
  flex: 0 0 auto;
  background: #fff;
  color: var(--ink);
  border-radius: 20px;
  padding: 22px 18px 18px;
  box-shadow: var(--shadow);
}

.track {
  height: 8px;
  border-radius: 999px;
  background: #eef1f4;
  overflow: hidden;
  margin: 14px 0;
}

.track > div {
  height: 100%;
  width: 0;
  background: var(--red);
  border-radius: inherit;
}

@media (min-width: 720px) {
  .shell { width: min(var(--max), calc(100% - 48px)); }
  .topbar-inner { width: min(var(--max), calc(100% - 48px)); }
  .nav { width: auto; justify-content: flex-end; }
  .stats.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .actions { grid-template-columns: minmax(160px, 220px) 1fr; align-items: end; }
  .btn-row, .quick-links { grid-template-columns: 1fr 1fr; }
  .quick-links { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .toolbar { grid-template-columns: 1fr auto auto; align-items: center; }
  .panel { padding: 20px; }
  .overlay { align-items: center; }
  .camera { min-height: 300px; }
}

@media (max-width: 719px) {
  .table-wrap { display: none; }
  .cards { display: grid; }
  .nav { display: grid; grid-template-columns: 1fr 1fr; }
}

@media (max-height: 520px) {
  .overlay.scan-open { align-items: flex-start; }
  .overlay .panel { margin-top: 0; padding: 14px 14px 12px; }
  .dialog-serial { font-size: 2rem; margin: 0 0 8px; }
  .details { gap: 4px; margin-bottom: 10px; }
  .details div { padding-bottom: 4px; }
  .scan-dialog .btn { min-height: 44px; }
}

@media (min-width: 720px) {
  .cards { display: none; }
}

.cards { gap: 10px; }

.gallery { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }

.band-card {
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  box-shadow: var(--shadow);
}

.band-hint { display: none; margin: 0 0 12px; }

.band-scroll {
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  border-radius: 10px;
  background: #fff;
  -webkit-overflow-scrolling: touch;
}

.band-card img {
  display: block;
  width: auto;
  max-width: none;
  height: 120px;
  background: #fff;
}

@media (min-width: 1100px) {
  .band-card img {
    width: 100%;
    max-width: 100%;
    height: auto;
  }
}

@media (max-width: 1099px) {
  .band-hint { display: block; }
}

.band-card .band-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.band-card .serial {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -.03em;
}

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

@media (max-width: 520px) {
  .pager { display: grid; grid-template-columns: 1fr 1fr; }
  .pager .note { grid-column: 1 / -1; order: -1; margin: 0; text-align: center; }
}

.person {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  box-shadow: var(--shadow);
}

.person .serial {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
}

.person .meta { grid-column: 1 / -1; color: var(--muted); font-size: 13px; }
