:root {
  color-scheme: light;
  --ink: #17201c;
  --muted: #637067;
  --line: #d8ded7;
  --paper: #f7f6f1;
  --panel: #ffffff;
  --accent: #1f7a5a;
  --accent-strong: #10583e;
  --accent-soft: #dcefe7;
  --danger: #a73535;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  padding-bottom: 36px;
  background: var(--paper);
  color: var(--ink);
}

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

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

button.secondary {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

button.ghost {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

button.danger {
  background: #f2dada;
  color: var(--danger);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
}

textarea {
  resize: vertical;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 32px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.brand-copy {
  display: grid;
  justify-items: start;
  min-width: 0;
  text-align: left;
}

.brand-lockup img {
  display: block;
  flex: 0 0 auto;
  width: 50px;
  height: 50px;
  object-fit: contain;
}

.logo-placeholder {
  display: grid;
  flex: 0 0 auto;
  width: 58px;
  height: 58px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbf8;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.topbar h1,
.section-head h2 {
  margin: 0;
  line-height: 1.05;
}

.topbar h1 {
  font-size: 1.75rem;
}

.section-head h2 {
  font-size: 1.45rem;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-strong);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.menu-toggle,
.nav-backdrop {
  display: none;
}

.menu-toggle {
  flex: 0 0 auto;
  width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0;
  border: 1px solid var(--line);
  background: #fff;
}

.menu-toggle:hover {
  background: var(--accent-soft);
}

.menu-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  border-radius: 99px;
  background: var(--ink);
}

.session-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border-radius: 999px;
  padding: 0 12px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 800;
}

.app-shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: calc(100vh - 93px - 36px);
}

.powered-by {
  display: grid;
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 36px;
  border-top: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.powered-center {
  display: flex;
  grid-column: 2;
  align-items: center;
  gap: 8px;
}

.powered-center img {
  display: block;
  height: 28px;
  width: auto;
}

.footer-links {
  display: flex;
  grid-column: 3;
  justify-self: end;
  gap: 14px;
  padding-right: 18px;
  font-size: 0.68rem;
}

.footer-links a {
  color: var(--muted);
  text-decoration: none;
}

.footer-links a:hover {
  color: var(--accent-strong);
  text-decoration: underline;
}

.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: #fff;
  padding: 20px 14px;
}

.nav-item {
  width: 100%;
  justify-content: flex-start;
  margin-bottom: 8px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.nav-session {
  display: grid;
  gap: 10px;
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  overflow-wrap: anywhere;
}

.session-name {
  color: var(--ink);
  font-weight: 800;
}

.session-name small {
  color: var(--muted);
  font-weight: 700;
}

.workspace {
  padding: 28px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.toolbar {
  display: flex;
  align-items: end;
  gap: 12px;
}

.compact-label {
  display: grid;
  gap: 6px;
  min-width: min(48vw, 520px);
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

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

.panel h3 {
  margin: 0 0 14px;
}

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

.scan-layout,
.admin-grid {
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
  gap: 18px;
}

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

.stack-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.full-width {
  width: 100%;
  margin-top: 12px;
}

.code-form {
  margin-top: 14px;
}

.code-hint {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbf8;
  color: var(--accent-strong);
  padding: 12px;
  font-weight: 800;
}

.admin-login-box {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.admin-login-box h4 {
  margin: 0 0 12px;
}

.logged-in-panel {
  display: grid;
  gap: 12px;
}

.logged-in-panel h3,
.logged-in-panel p {
  margin: 0;
}

.my-checkins {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.my-checkins h4 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  font-size: 0.95rem;
}

.my-checkins h4 span {
  color: var(--accent);
  font-weight: 900;
}

.my-checkins ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.my-checkins li {
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fbfcf8;
}

.my-checkins li span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.form-error {
  margin: -4px 0 0;
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 800;
}

.empty-state {
  display: grid;
  min-height: 220px;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  padding: 18px;
}

.checkpoint-success {
  display: grid;
  gap: 14px;
}

.success-badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 32px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  padding: 0 12px;
  font-weight: 800;
}

.route-list {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.route-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 18px;
}

.route-card header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.route-card h3,
.route-card p {
  margin: 0;
}

.checkpoint-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.checkpoint-chip {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfa;
}

.checkpoint-chip strong {
  display: block;
  margin-bottom: 4px;
}

.checkpoint-chip code,
.qr-human-code {
  color: var(--accent-strong);
  font-weight: 900;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
}

.analytics-board,
.leaderboard,
.checkpoint-results {
  display: grid;
  gap: 16px;
}

.analytics-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 18px;
}

.analytics-section > header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.analytics-section h3,
.checkpoint-result-card h4 {
  margin: 0;
}

.analytics-highlight {
  display: grid;
  min-width: 150px;
  justify-items: end;
  gap: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}

.analytics-highlight strong {
  color: var(--accent-strong);
  font-size: 1.35rem;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) minmax(170px, auto);
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfa;
}

.rank-badge {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
}

.leaderboard-main {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.leaderboard-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.leaderboard-title strong,
.leaderboard-title span {
  overflow-wrap: anywhere;
}

.leaderboard-title span,
.leaderboard-metrics span {
  color: var(--muted);
  font-size: 0.82rem;
}

.progress-track,
.time-bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8ede8;
}

.progress-track span,
.time-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.progress-track span {
  background: var(--accent);
}

.time-bar span {
  background: #96b9d8;
}

.leaderboard-metrics {
  display: grid;
  justify-items: end;
  gap: 3px;
  text-align: right;
}

.leaderboard-metrics strong {
  color: var(--ink);
}

.checkpoint-results {
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  margin-top: 18px;
}

.checkpoint-result-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.checkpoint-result-card p {
  margin: 4px 0 12px;
}

.arrival-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 30px;
  border-top: 1px solid var(--line);
}

.arrival-row span {
  color: var(--accent-strong);
  font-weight: 900;
}

.arrival-row strong {
  overflow-wrap: anywhere;
}

.arrival-row em {
  color: var(--muted);
  font-size: 0.78rem;
  font-style: normal;
}

.print-pages {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 420px));
  gap: 22px;
  justify-content: center;
}

.qr-card {
  display: grid;
  grid-template-rows: auto auto;
  gap: 18px;
  aspect-ratio: 210 / 297;
  border: 2px solid #111;
  border-radius: 8px;
  background: #fff;
  padding: 24px;
  align-content: center;
  justify-items: center;
  text-align: center;
  break-inside: avoid;
  page-break-inside: avoid;
}

.qr-code svg {
  display: block;
  width: clamp(190px, 52vw, 280px);
  height: clamp(190px, 52vw, 280px);
}

.qr-meta {
  min-width: 0;
}

.qr-route,
.qr-location,
.qr-human-code,
.qr-backup-link {
  margin: 0 0 8px;
}

.qr-route {
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
}

.qr-title {
  margin: 0 0 8px;
  font-size: 1.25rem;
  overflow-wrap: anywhere;
}

.qr-human-code {
  font-size: 1rem;
}

.qr-backup-link {
  max-width: 100%;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.small-button {
  min-height: 34px;
  padding: 8px 12px;
  font-size: 0.85rem;
}

@media (max-width: 860px) {
  .section-head,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  body.nav-open {
    overflow: hidden;
  }

  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    padding: 14px 16px;
  }

  .brand-lockup {
    gap: 10px;
  }

  .brand-lockup img {
    width: 40px;
    height: 40px;
  }

  .topbar h1 {
    font-size: 1.22rem;
    line-height: 1.08;
  }

  .eyebrow {
    margin-bottom: 4px;
    font-size: 0.64rem;
  }

  .menu-toggle {
    display: flex;
    flex-direction: column;
  }

  .app-shell,
  .scan-layout,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .app-shell {
    min-height: calc(100vh - 120px - 36px);
  }

  .analytics-section > header,
  .leaderboard-row {
    grid-template-columns: 1fr;
  }

  .analytics-section > header {
    flex-direction: column;
  }

  .analytics-highlight,
  .leaderboard-metrics {
    justify-items: start;
    text-align: left;
  }

  .leaderboard-title {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 36px;
    left: 0;
    z-index: 40;
    width: min(78vw, 300px);
    border-right: 1px solid var(--line);
    box-shadow: 18px 0 42px rgba(23, 32, 28, 0.18);
    transform: translateX(-105%);
    transition: transform 180ms ease;
    overflow-y: auto;
  }

  body.nav-open .sidebar {
    transform: translateX(0);
  }

  .nav-backdrop {
    position: fixed;
    inset: 0 0 36px;
    z-index: 35;
    min-height: 0;
    border-radius: 0;
    padding: 0;
    background: rgba(23, 32, 28, 0.32);
  }

  body.nav-open .nav-backdrop {
    display: block;
  }

  .nav-item {
    width: 100%;
    min-height: 48px;
    white-space: nowrap;
  }

  .workspace {
    padding: 18px;
  }

  .brand-lockup {
    align-items: flex-start;
  }

  .compact-label {
    min-width: 0;
  }

  .powered-by {
    grid-template-columns: auto 1fr;
    justify-content: stretch;
    padding: 0 10px;
  }

  .powered-center {
    grid-column: 1;
  }

  .footer-links {
    grid-column: 2;
    gap: 8px;
    padding-right: 0;
  }
}

@page {
  size: A4;
  margin: 12mm;
}

@media print {
  body {
    padding-bottom: 0;
    background: #fff;
  }

  .topbar,
  .sidebar,
  .menu-toggle,
  .nav-backdrop,
  .no-print,
  .view:not(#view-print) {
    display: none !important;
  }

  .powered-by {
    display: grid !important;
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    grid-template-columns: 1fr auto 1fr;
    height: 8mm;
    border-top: 0.3mm solid #cfd6cf;
    background: #fff;
    font-size: 8pt;
  }

  .powered-center img {
    height: 6mm;
  }

  .footer-links {
    gap: 5mm;
    padding-right: 4mm;
    font-size: 6.5pt;
  }

  .app-shell,
  .workspace,
  #view-print {
    display: block;
    min-height: auto;
    padding: 0;
  }

  .print-pages {
    display: block;
  }

  .qr-card {
    width: 100%;
    min-height: calc(297mm - 24mm - 10mm);
    aspect-ratio: auto;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    gap: 14mm;
    border: 1mm solid #000;
    border-radius: 4mm;
    padding: 16mm 12mm;
    break-after: page;
    page-break-after: always;
  }

  .qr-card:last-child {
    break-after: auto;
    page-break-after: auto;
  }

  .qr-code svg {
    width: 132mm;
    height: 132mm;
  }

  .qr-title {
    font-size: 34pt;
    line-height: 1.05;
  }

  .qr-route,
  .qr-location,
  .qr-human-code {
    font-size: 18pt;
    line-height: 1.2;
  }

  .qr-human-code {
    font-size: 22pt;
  }

  .qr-backup-link {
    font-size: 8pt;
  }
}
