:root {
  --ink: #192522;
  --ink-soft: #52635e;
  --paper: #f3f7f5;
  --surface: #ffffff;
  --line: #dce6e1;
  --accent: #176b56;
  --accent-soft: #e6f2ec;
  --gold: #d8a34c;
  --green: #18734b;
  --red: #b3261e;

  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --radius: 16px;
  --step: 1rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(ellipse at 50% -18rem, #e0eee7 0, transparent 38rem),
    var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
}

h1,
h2 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.035em;
  line-height: 1.15;
}

h1 {
  font-size: clamp(1.9rem, 5vw, 2.6rem);
}

h2 {
  font-size: 1.2rem;
}

p {
  margin: 0 0 var(--step);
}

a {
  color: var(--accent);
  text-underline-offset: 2px;
}

.display {
  margin-bottom: 0.35rem;
}

.lede {
  color: var(--ink-soft);
  margin-bottom: 1.5rem;
}

.muted {
  color: var(--ink-soft);
  font-size: 0.9rem;
}

/* ---------- Navigation ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.5rem;
  padding: 0.85rem max(1.25rem, calc((100% - 72rem) / 2));
  background: #172923;
  color: var(--paper);
  border-bottom: 1px solid rgb(255 255 255 / 9%);
  box-shadow: 0 8px 24px rgb(23 41 35 / 10%);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--paper);
  text-decoration: none;
  margin-right: auto;
}

.brand::before {
  width: 0.55rem;
  height: 0.55rem;
  flex: none;
  border-radius: 50%;
  background: var(--gold);
  content: "";
}

.nav {
  display: flex;
  gap: 0.3rem;
}

.nav-icon {
  display: none;
}

.nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.4rem 0.8rem;
  border: 1px solid transparent;
  border-radius: 9px;
  color: #d5e0da;
  text-decoration: none;
  font-size: 0.95rem;
  transition: background-color 140ms ease, color 140ms ease;
}

.nav a:hover,
.nav a:focus-visible {
  background: rgb(255 255 255 / 8%);
  color: #fff;
}

.nav a[aria-current="page"] {
  background: rgb(255 255 255 / 12%);
  border-color: rgb(255 255 255 / 12%);
  color: #fff;
}

.signout {
  margin: 0;
}

.link-button {
  min-height: 44px;
  padding: 0.4rem 0.75rem;
  border: 1px solid rgb(255 255 255 / 18%);
  border-radius: 9px;
  background: transparent;
  color: #e4ece7;
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background-color 140ms ease;
}

.link-button:hover {
  background: rgb(255 255 255 / 8%);
}

/* ---------- Layout ---------- */

.page {
  width: min(100% - 2rem, 72rem);
  margin: 0 auto;
  padding: 2.5rem 0 4rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-top: 1.5rem;
  box-shadow: 0 8px 28px rgb(28 54 43 / 4%);
}

.panel-narrow {
  max-width: 34rem;
}

/* ---------- Flash ---------- */

.flash {
  width: min(100% - 2rem, 72rem);
  margin: 1rem auto 0;
  padding: 0.75rem 1rem;
  background: var(--accent-soft);
  border: 1px solid #c9e2d4;
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  font-size: 0.95rem;
}

/* ---------- Forms ---------- */

.stack {
  display: grid;
  gap: 1rem;
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink-soft);
}

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

input:focus-visible,
select:focus-visible {
  outline: 3px solid rgb(23 107 86 / 20%);
  outline-offset: 1px;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.65rem 1.15rem;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.button:hover {
  background: #105b47;
  border-color: #105b47;
  transform: translateY(-1px);
}

.button:disabled {
  cursor: wait;
  opacity: 0.65;
  transform: none;
}

.button-quiet {
  background: transparent;
  color: var(--accent);
}

.button-quiet:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #105b47;
}

.button:focus-visible,
.link-button:focus-visible,
.nav a:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.alert {
  padding: 0.7rem 0.9rem;
  margin-bottom: 1rem;
  border: 1px solid #e3b5b1;
  border-left: 4px solid var(--red);
  border-radius: 10px;
  background: #fcf1f0;
  color: #7a1d17;
  font-size: 0.95rem;
}

.hint {
  margin-top: 1.5rem;
  color: var(--ink-soft);
  font-size: 0.875rem;
}

/* ---------- Login ---------- */

.login {
  max-width: 26rem;
  margin: clamp(2rem, 10vh, 6rem) auto 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2.25rem;
  box-shadow: 0 20px 60px rgb(28 54 43 / 9%);
}

.login .button {
  width: 100%;
  margin-top: 0.25rem;
}

/* ---------- Dashboard stats ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 1rem;
  margin: 1.75rem 0 0;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.2rem 1.25rem;
  box-shadow: 0 8px 24px rgb(28 54 43 / 4%);
}

.stat dt {
  font-size: 0.85rem;
  color: var(--ink-soft);
  font-weight: 600;
}

.stat dd {
  margin: 0.25rem 0 0;
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: -0.05em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.plain {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--ink-soft);
}

.plain li + li {
  margin-top: 0.4rem;
}

/* ---------- People list ---------- */

.people {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
}

.person {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 0;
  border-top: 1px dashed var(--line);
}

.person:first-child {
  border-top: 0;
  padding-top: 0;
}

.person-id {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.person-name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.person-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.85rem;
}

.password-reset {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.password-reset input {
  width: 10rem;
  min-height: 40px;
  padding: 0.45rem 0.6rem;
}

.password-reset .button {
  min-height: 40px;
  padding: 0.4rem 0.7rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 1.55rem;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: capitalize;
}

.badge-admin {
  background: #f6e7c6;
  color: #6b4a0c;
}

.badge-ticketer {
  background: var(--accent-soft);
  color: #322a75;
}

.state {
  font-size: 0.85rem;
  color: var(--green);
}

.state-off {
  color: var(--red);
}

/* ---------- Page header, search ---------- */

.crumb {
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}

.crumb a {
  text-decoration: none;
}

.crumb a:hover {
  text-decoration: underline;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.page-head h1 {
  margin: 0;
}

.toolbar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.toolbar input {
  flex: 1;
  min-width: 0;
}

.toolbar .button {
  flex: none;
}

.empty {
  margin-top: 2rem;
  color: var(--ink-soft);
}

.errors {
  margin: 0;
  padding-left: 1.1rem;
}

/* ---------- Ticket rows ---------- */

.rows {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.ticket-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  text-decoration: none;
  color: inherit;
  transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.ticket-link:hover,
.ticket-link:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 5px 16px rgb(28 54 43 / 7%);
  transform: translateY(-1px);
}

.ticket-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.ticket-main {
  display: grid;
  gap: 0.15rem;
  min-width: 0;
}

.ticket-name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.ticket-meta {
  color: var(--ink-soft);
  font-size: 0.875rem;
}

/* ---------- Status pills ---------- */

.badge-valid,
.badge-email-sent {
  background: #e2f2e9;
  color: #14603b;
}

.badge-checked_in {
  background: var(--accent-soft);
  color: #322a75;
}

.badge-revoked,
.badge-email-failed {
  background: #fbe3e1;
  color: #8c1c15;
}

.badge-email-pending {
  background: #f6e7c6;
  color: #6b4a0c;
}

/* ---------- Ticket detail ---------- */

.detail-grid {
  display: grid;
  gap: 1.5rem;
}

.detail-grid .panel {
  margin-top: 0;
}

.facts {
  margin: 1rem 0 0;
  display: grid;
  gap: 0.65rem;
}

.fact {
  display: grid;
  gap: 0.1rem;
}

.fact dt {
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.fact dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.qr-panel {
  display: grid;
  justify-items: center;
  gap: 0.75rem;
  text-align: center;
}

.qr-panel h2 {
  justify-self: start;
}

.qr-panel img {
  width: min(240px, 100%);
  height: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 8px 24px rgb(28 54 43 / 7%);
}

.qr-panel form,
.qr-panel .button {
  width: 100%;
}

@media (min-width: 48rem) {
  .detail-grid {
    grid-template-columns: minmax(0, 1fr) 20rem;
    align-items: start;
  }

  .fact {
    grid-template-columns: 9rem minmax(0, 1fr);
    align-items: baseline;
  }
}

@media (max-width: 30rem) {
  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.25rem 0.75rem;
    padding: calc(0.5rem + env(safe-area-inset-top))
      calc(0.75rem + env(safe-area-inset-right)) 0.5rem
      calc(0.75rem + env(safe-area-inset-left));
  }

  .brand {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    overflow-wrap: anywhere;
  }

  .nav {
    grid-column: 1 / -1;
    grid-row: 2;
    flex-wrap: wrap;
    gap: 0.1rem 0.35rem;
    margin-inline: -0.25rem;
  }

  .nav a {
    padding-inline: 0.45rem;
    border-radius: 6px;
  }

  .nav a[aria-current="page"] {
    background: rgb(255 255 255 / 12%);
  }

  .signout {
    grid-column: 2;
    grid-row: 1;
  }

  .link-button {
    padding-inline: 0.4rem;
  }

  .page {
    width: min(100% - 1.25rem, 60rem);
    padding-top: 1.5rem;
    padding-bottom: calc(2rem + env(safe-area-inset-bottom));
  }

  .flash {
    width: min(100% - 1.25rem, 72rem);
  }

  .panel {
    padding: 1.1rem;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem;
    margin-top: 1.25rem;
  }

  .stat {
    min-width: 0;
    padding: 0.85rem;
  }

  .stat dd {
    font-size: clamp(1.65rem, 8vw, 2.2rem);
  }

  .stat dd.stat-money {
    font-size: clamp(1rem, 5vw, 1.3rem);
  }

  .person-actions .button {
    min-height: 44px;
    padding: 0.4rem 0.8rem;
  }

  .toolbar {
    flex-direction: column;
  }

  .toolbar .button,
  .page-actions .button,
  .stack > .button {
    width: 100%;
  }

  .page-head {
    align-items: flex-start;
  }

  .page-actions {
    width: 100%;
    flex-direction: column;
  }

  .ticket-link {
    align-items: flex-start;
    padding: 0.75rem;
  }

  .ticket-link > .badge,
  .ticket-side {
    flex: none;
    align-self: center;
  }

  .scan-actions {
    flex-direction: column;
  }

  .scan-actions .button {
    flex: none;
    width: 100%;
  }

  .table {
    min-width: 34rem;
  }

  .person {
    align-items: flex-start;
  }

  .person-actions {
    width: 100%;
    justify-content: space-between;
  }

  .person-actions form {
    flex: none;
  }

  .password-reset {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .password-reset input,
  .password-reset .button {
    width: 100%;
  }
}

@media (min-width: 30.001rem) and (max-width: 48rem) {
  .topbar {
    gap: 0.5rem 1rem;
  }

  .nav {
    gap: 0.5rem;
  }
}

@media (max-width: 48rem) {
  .nav {
    position: fixed;
    z-index: 20;
    inset-inline: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(4rem, 1fr));
    gap: 0.25rem;
    margin: 0;
    padding: 0.5rem max(0.75rem, env(safe-area-inset-right))
      calc(0.5rem + env(safe-area-inset-bottom))
      max(0.75rem, env(safe-area-inset-left));
    border-top: 1px solid var(--line);
    background: rgb(255 255 255 / 94%);
    box-shadow: 0 -8px 24px rgb(28 54 43 / 9%);
    backdrop-filter: blur(16px);
  }

  .nav a {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.2rem;
    min-width: 0;
    min-height: 3.5rem;
    padding: 0.35rem 0.2rem;
    border-radius: 11px;
    color: var(--ink-soft);
    font-size: 0.72rem;
    line-height: 1;
    transition: background-color 140ms ease, color 140ms ease;
  }

  .nav-icon {
    display: block;
    width: 1.2rem;
    height: 1.2rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .nav a:hover,
  .nav a:focus-visible {
    background: #f1f7f3;
    color: var(--accent);
  }

  .nav a[aria-current="page"] {
    background: var(--accent-soft);
    border-color: transparent;
    color: var(--accent);
  }

  .nav a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
  }

  .page {
    padding-bottom: calc(6rem + env(safe-area-inset-bottom));
  }
}

/* ---------- Scanner ---------- */

.scan-shell,
.scan-result {
  max-width: 34rem;
  margin-inline: auto;
}

.scan-shell {
  padding: 1rem;
}

.reader {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #101b17;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 10%);
}

.reader video,
.reader canvas {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
}

.scan-shell #camera-status {
  margin: 0.75rem 0 0;
}

.scan-shell .button {
  width: 100%;
  margin-top: 0.75rem;
}

.scan-result {
  margin-top: 1.25rem;
  margin-bottom: 1.25rem;
  padding: 1.1rem 1.25rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 4px solid var(--ink-soft);
  border-radius: var(--radius);
  box-shadow: 0 12px 30px rgb(28 54 43 / 8%);
}

.scan-result.is-valid {
  border-top-color: var(--green);
  background: #edf7f0;
}

.scan-result.is-danger {
  border-top-color: var(--red);
  background: #fdf0ef;
}

.scan-kicker {
  margin: 0;
  font-weight: 700;
  color: var(--green);
}

.scan-result.is-danger .scan-kicker {
  color: var(--red);
}

.scan-result h2 {
  margin: 0.2rem 0 0.15rem;
  font-size: 1.75rem;
  overflow-wrap: anywhere;
}

.scan-meta {
  margin: 0;
  color: var(--ink-soft);
}

.scan-note {
  margin: 0.6rem 0 0;
}

.scan-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1rem;
}

.scan-actions .button {
  flex: 1 1 9rem;
  min-height: 56px;
  font-size: 1.05rem;
}

button.ticket-link {
  width: 100%;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

button.ticket-link:hover,
button.ticket-link:focus-visible {
  border-color: var(--accent);
}

.ticket-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  background: #f7f6fb;
}

.ticket-side {
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- Dashboard table, export & revoke ---------- */

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.stat dd.stat-money {
  font-size: 1.35rem;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}

.table-wrap:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.table th,
.table td {
  padding: 0.55rem 0.4rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.table th {
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 600;
  background: #f7faf8;
}

.table tbody tr:hover {
  background: #f8fbf9;
}

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

.table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.table .badge {
  margin-left: 0.35rem;
  vertical-align: 1px;
}

.alert a {
  color: inherit;
}

.button-danger {
  background: transparent;
  color: var(--red);
  border-color: var(--red);
}

.button-danger:hover {
  background: #fcf1f0;
}

.revoke-form {
  margin-top: 0.9rem;
  padding-top: 0.9rem;
  border-top: 1px dashed var(--line);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  z-index: 10;
  top: 0.5rem;
  left: 0.5rem;
  padding: 0.65rem 0.9rem;
  border-radius: 9px;
  background: #fff;
  color: var(--accent);
  font-weight: 700;
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 30rem) {
  .scan-actions {
    flex-direction: column;
  }

  .scan-actions .button {
    flex: none;
    width: 100%;
  }
}
