:root {
  --green: #143a2e;
  --green-2: #0f6b46;
  --gold: #c4a46b;
  --gold-soft: #e9dcc3;
  --cream: #f6f2ea;
  --paper: #ffffff;
  --ink: #1b1b1b;
  --muted: #5f655f;
  --line: #e2dccf;
  --ok: #17794a;
  --warn: #b26a00;
  --bad: #b3261e;
  --radius: 10px;
  --sidebar-w: 264px;
  --sidebar: #0f2e25;
  --sidebar-ink: #dbe7e0;
  --sidebar-muted: #8fae9f;
  --sidebar-line: rgba(255,255,255,.09);
  --sidebar-hover: rgba(255,255,255,.07);
  --sidebar-active: rgba(255,255,255,.12);
  --serif: "Source Serif 4", "Source Serif Pro", Georgia, "Times New Roman", serif;
  --sans: "Source Sans 3", "Source Sans Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; color: var(--green); line-height: 1.2; letter-spacing: -0.01em; margin: 0 0 .5em; text-wrap: balance; }
h1 { font-size: clamp(1.7rem, 4vw, 2.3rem); }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; }
p { margin: 0 0 1em; }
a { color: var(--green-2); }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .06em; }
.wrap { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.wrap.narrow { max-width: 720px; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.eyebrow { font-size: .76rem; letter-spacing: .14em; text-transform: uppercase; color: var(--gold); font-weight: 600; }

/* Public header + hero */
.crest { background: var(--paper); text-align: center; padding: 18px 16px 14px; }
.crest img { display: block; margin: 0 auto; max-width: 100%; height: auto; }
.crest .coat { height: 64px; width: auto; }
.crest .logos { height: 46px; width: auto; margin-top: 10px; }
.hero { background: var(--green); color: #fff; text-align: center; padding: 28px 16px 30px; border-bottom: 4px solid var(--gold); }
.hero h1 { color: #fff; margin: 6px 0 8px; }
.hero h1 { font-weight: 700; letter-spacing: 0; }
.hero h1 em { color: var(--gold); font-style: italic; font-weight: 400; }
.hero .meta { color: var(--gold-soft); font-size: 1rem; margin: 0; }
.site-footer { text-align: center; padding: 22px 16px; color: var(--muted); font-size: .8rem; }

/* Cards and forms */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card + .card { margin-top: 16px; }
.section { padding: 24px 0 40px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label, .field-label { font-weight: 600; font-size: .9rem; color: var(--green); }
.field .hint { font-size: .84rem; color: var(--muted); }
input[type=text], input[type=tel], input[type=email], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: #fff;
  border: 1px solid #cfc8b8; border-radius: 8px; padding: 10px 12px; min-height: 44px;
}
/* Selects and single-line inputs share one height, so a row of fields lines up. */
input[type=text], input[type=tel], input[type=email], input[type=password], input[type=number], input[type=search], select { height: 44px; padding-top: 0; padding-bottom: 0; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; border-color: var(--green); }
input[readonly] { background: #f3efe6; color: var(--muted); }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .grid, .grid.three { grid-template-columns: 1fr; } }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: .9rem; }
.check input { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--green); }
/* A tick box that sits in a form grid like any other field: same height and border as an input. */
.field label.check { font-weight: 400; font-size: inherit; color: var(--ink); }
.check.boxed { align-items: center; gap: 10px; min-height: 44px; padding: 8px 12px; background: #fff; border: 1px solid #cfc8b8; border-radius: 8px; cursor: pointer; }
.check.boxed input { margin: 0; flex: 0 0 auto; }
.check.boxed:has(input:checked) { border-color: var(--green); background: #f4f8f5; }
.check.boxed:has(input:focus-visible) { outline: 2px solid var(--gold); outline-offset: 1px; }
.field-validation-error, .validation-summary-errors { color: var(--bad); font-size: .82rem; }
.validation-summary-errors ul { margin: 0; padding-left: 18px; }
.validation-summary-valid { display: none; }
.input-validation-error { border-color: var(--bad) !important; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  background: var(--green); color: #fff; border: 1px solid var(--green);
  border-radius: 8px; padding: 10px 18px; min-height: 44px;
}
.btn:hover { background: #0d2a21; }
.btn.gold { background: var(--gold); border-color: var(--gold); color: #231a08; }
.btn.gold:hover { background: #b39258; }
.btn.outline { background: transparent; color: var(--green); }
.btn.outline:hover { background: #eef2ee; }
.btn.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
.btn.danger:hover { background: #fbeceb; }
.btn.sm { min-height: 34px; padding: 5px 12px; font-size: .9rem; }
.btn.block { width: 100%; }

.alert { border-radius: 8px; padding: 12px 14px; border: 1px solid; font-size: .96rem; }
.alert.ok { background: #e9f5ee; border-color: #b7dcc6; color: #0f5132; }
.alert.warn { background: #fff5e2; border-color: #f0d49b; color: #6b4300; }
.alert.bad { background: #fbeceb; border-color: #efbcb8; color: #7d1a15; }

.badge { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: .8rem; letter-spacing: .02em; font-weight: 700; color: #fff; background: var(--green); white-space: nowrap; }
.badge.plain { background: #ece7db; color: var(--ink); }
.badge.ok { background: var(--ok); }
.badge.warn { background: var(--warn); }

/* Registration rows */
.person { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; background: #fffdf8; }
.person + .person { margin-top: 14px; }
.person-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.person-head strong { font-family: var(--serif); font-weight: 600; font-size: 1.05rem; color: var(--green); }

/* Ticket */
.ticket { max-width: 420px; margin: 16px auto 0; background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; text-align: center; }
.ticket-top { background: var(--green); color: #fff; padding: 16px; border-bottom: 3px solid var(--gold); }
.ticket-top .t { font-family: var(--serif); font-weight: 600; font-size: 1.2rem; }
.ticket-body { padding: 18px 18px 6px; }
.ticket-name { font-family: var(--serif); font-size: 1.5rem; color: var(--green); font-weight: 700; overflow-wrap: anywhere; }
.ticket-qr { width: 230px; max-width: 80%; height: auto; margin: 12px auto 4px; display: block; image-rendering: pixelated; }
.ticket-band { color: #fff; font-weight: 700; letter-spacing: .12em; padding: 9px; margin-top: 12px; }
.ticket-info { text-align: left; padding: 14px 18px 18px; font-size: .94rem; border-top: 1px dashed var(--line); }
.ticket-info p { margin: 0 0 6px; }

/* ---------- Signed-in shell: sidebar, top bar, account menu ---------- */
.icon { width: 20px; height: 20px; flex: 0 0 auto; }
.skip-link { position: fixed; left: 12px; top: -60px; z-index: 60; background: #fff; color: var(--green); padding: 8px 14px; border-radius: 8px; font-weight: 600; }
.skip-link:focus { top: 12px; outline: 2px solid var(--gold); }

body.app { display: block; background: var(--cream); }
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 40; width: var(--sidebar-w);
  display: flex; flex-direction: column; background: var(--sidebar); color: var(--sidebar-ink);
  border-right: 1px solid var(--sidebar-line); transition: transform .2s ease;
}
.sb-brand { display: flex; align-items: center; gap: 12px; padding: 16px 16px 14px; color: #fff; text-decoration: none; border-bottom: 1px solid var(--sidebar-line); }
.sb-logo { width: 40px; height: 40px; flex: 0 0 auto; background: #fff; border-radius: 10px; display: grid; place-items: center; }
.sb-logo img { width: 32px; height: 28px; object-fit: contain; }
.sb-name { min-width: 0; line-height: 1.25; }
.sb-name strong { display: block; font-family: var(--serif); font-weight: 600; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-name small { display: block; font-size: .78rem; color: var(--sidebar-muted); }
.sidebar nav { flex: 1; overflow-y: auto; padding: 10px 10px 16px; }
.sb-group + .sb-group { margin-top: 14px; }
.sb-group h2 { font-family: var(--sans); font-size: .7rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--sidebar-muted); margin: 0; padding: 8px 10px 6px; }
.sb-group ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.sb-group a {
  display: flex; align-items: center; gap: 11px; min-height: 40px; padding: 8px 10px; border-radius: 8px;
  color: var(--sidebar-ink); text-decoration: none; font-weight: 600; font-size: .96rem;
}
.sb-group a .icon { color: var(--sidebar-muted); }
.sb-group a:hover { background: var(--sidebar-hover); color: #fff; }
.sb-group a:focus-visible, .sb-brand:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }
.sb-group a[aria-current="page"] { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 var(--gold); }
.sb-group a[aria-current="page"] .icon, .sb-group a:hover .icon { color: var(--gold); }
.sb-foot { margin: 0; padding: 12px 20px 16px; font-size: .78rem; color: var(--sidebar-muted); border-top: 1px solid var(--sidebar-line); }
.sb-backdrop { display: none; }

.app-main { margin-left: var(--sidebar-w); min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; min-width: 0; transition: margin-left .2s ease; }
.topbar { position: sticky; top: 0; z-index: 30; height: 56px; flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: 0 20px 0 12px; background: rgba(255,255,255,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 8px; background: none; color: var(--green); cursor: pointer; }
.icon-btn:hover { background: #eef2ee; }
.icon-btn:focus-visible, .user-menu summary:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
.topbar-brand { display: none; font-family: var(--serif); font-weight: 600; color: var(--green); text-decoration: none; white-space: nowrap; }
.user-menu { position: relative; margin-left: auto; }
.user-menu summary { list-style: none; display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 8px 0 4px; border-radius: 8px; cursor: pointer; color: var(--ink); font-weight: 600; }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover, .user-menu[open] summary { background: #eef2ee; }
.user-menu summary .icon { width: 16px; height: 16px; color: var(--muted); transition: transform .15s; }
.user-menu[open] summary .icon { transform: rotate(180deg); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--green); color: #fff; display: grid; place-items: center; font-size: .85rem; font-weight: 700; }
.user-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 32px rgba(20,58,46,.16); padding: 6px; }
.menu-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; line-height: 1.3; }
.menu-head strong { display: block; overflow-wrap: anywhere; }
.menu-head span { font-size: .82rem; color: var(--muted); }
.menu button { width: 100%; display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 8px 10px; border: 0; border-radius: 6px; background: none; font: inherit; font-weight: 600; color: var(--ink); cursor: pointer; text-align: left; }
.menu button:hover, .menu button:focus-visible { background: #f3efe6; outline: none; }
.menu button .icon { width: 18px; height: 18px; color: var(--muted); }
.app-content { flex: 1; padding: 28px 32px 40px; }
.app-content .wrap { max-width: 1160px; padding: 0; margin: 0 auto; }
.app-footer { border-top: 1px solid var(--line); padding: 14px 32px; font-size: .8rem; color: var(--muted); }

/* Wide screens: the toggle folds the sidebar away. */
@media (min-width: 1024px) {
  .sidebar-collapsed .sidebar { transform: translateX(-100%); }
  .sidebar-collapsed .app-main { margin-left: 0; }
  .sidebar-collapsed .topbar-brand { display: block; }
}
/* Smaller screens: the sidebar is a drawer over the page. */
@media (max-width: 1023px) {
  .sidebar { transform: translateX(-100%); width: min(var(--sidebar-w), 86vw); box-shadow: none; }
  .sidebar-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.35); }
  .sidebar-open .sb-backdrop { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(15,30,25,.5); }
  .app-main { margin-left: 0; }
  .topbar-brand { display: block; }
  .topbar { padding: 0 12px 0 6px; }
  .app-content { padding: 18px 14px 32px; }
  .app-footer { padding: 14px; }
}
@media (max-width: 480px) { .user-name { display: none; } }
@media (prefers-reduced-motion: reduce) { .sidebar, .app-main { transition: none; } }

/* Sign-in page */
body.auth { display: block; background: var(--cream); }
.auth-main { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; padding: 24px 16px 48px; }
.auth-main > * { width: 100%; max-width: 420px; }
.auth-brand { text-align: center; }
.auth-brand img { display: block; margin: 0 auto; }
.auth-brand .coat { height: 64px; width: auto; }
.auth-brand .logos { height: 42px; width: auto; margin-top: 10px; }
.auth-brand .eyebrow { margin: 18px 0 2px; }
.auth-brand h1 { font-size: 1.6rem; margin: 0; }

.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .n { font-family: var(--serif); font-weight: 600; font-size: 2.1rem; color: var(--green); line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .l { font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table.table { width: 100%; border-collapse: collapse; font-size: .94rem; }
.table th, .table td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: .76rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); background: #faf7f0; white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 6px; background: #ece7db; border-radius: 3px; overflow: hidden; min-width: 70px; }
.bar > i { display: block; height: 100%; background: var(--green-2); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: baseline; }

/* Scanner */
.scan-shell { max-width: 520px; margin: 0 auto; }
#reader { width: 100%; border-radius: var(--radius); overflow: hidden; background: #000; min-height: 240px; }
.scan-result { border-radius: var(--radius); padding: 18px; color: #fff; text-align: center; }
.scan-result.admitted { background: var(--ok); }
.scan-result.duplicate { background: var(--warn); }
.scan-result.invalid { background: var(--bad); }
.scan-result.idle { background: #fff; color: var(--muted); border: 1px dashed #cfc8b8; }
.scan-result .verdict { font-size: .8rem; letter-spacing: .16em; text-transform: uppercase; font-weight: 700; }
.scan-result .who { font-family: var(--serif); font-size: 1.6rem; font-weight: 700; margin: 6px 0 2px; overflow-wrap: anywhere; }
.scan-result .tagno { display: inline-block; background: rgba(255,255,255,.18); border-radius: 6px; padding: 3px 12px; font-weight: 700; letter-spacing: .1em; margin-top: 8px; }
.scan-result .cat { display: inline-block; border-radius: 6px; padding: 3px 12px; font-weight: 700; margin-top: 8px; border: 2px solid #fff; }
.hit { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.hit:last-child { border-bottom: 0; }

@media print { .sidebar, .topbar, .app-footer, .site-footer, .no-print { display: none !important; } .app-main { margin-left: 0; } body { background: #fff; } }

/* ---------- Phones and small tablets ---------- */
img, video { max-width: 100%; }
input, select, textarea { min-width: 0; }

@media (max-width: 820px) {
  body { font-size: 16px; }
  .section { padding: 16px 0 32px; }
  .wrap { padding: 0 14px; }
  .card { padding: 16px; }
  h1 { font-size: 1.6rem; }
  h2 { font-size: 1.25rem; }

  /* Public header */
  .crest { padding: 12px 14px 10px; }
  .crest .coat { height: 50px; }
  .crest .logos { height: 36px; margin-top: 8px; }
  .hero { padding: 18px 14px 20px; }
  .hero .eyebrow { font-size: .66rem; letter-spacing: .1em; }
  .hero h1 { font-size: 1.5rem; margin: 4px 0 6px; }
  .hero .meta { font-size: .92rem; }

  /* Buttons fill the row so they are easy to tap */
  .row > .btn, .row > form > .btn { flex: 1 1 auto; }
  .row > form { display: flex; flex: 1 1 auto; }
  .row.between > h1, .row.between > h2 { flex: 1 1 100%; }
  .card.row.between > span { flex: 1 1 100%; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px 14px; }
  .stat .n { font-size: 1.7rem; }
  .check { padding: 4px 0; }
  .check input { width: 22px; height: 22px; margin-top: 2px; flex: 0 0 auto; }

  /* Tables become a list of cards, one per row, with the column name beside each value */
  .table-wrap { border: 0; background: none; overflow: visible; border-radius: 0; }
  table.table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .table tr { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 14px; }
  .table tr + tr { margin-top: 10px; }
  .table td, .table td.num { position: relative; border: 0; padding: 5px 0 5px 42%; min-height: 2em; text-align: left; overflow-wrap: anywhere; white-space: normal; }
  .table td::before {
    content: attr(data-label); position: absolute; left: 0; top: 8px; width: 40%;
    font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); line-height: 1.3;
  }
  .table td:not([data-label]) { padding-left: 0; }
  .table td:not([data-label])::before { content: none; }
  .table td:empty { display: none; }
  .table td.cell-wide { padding-left: 0; }
  .table td.cell-wide::before { position: static; display: block; width: auto; margin-bottom: 4px; }
  .table td .bar { margin-top: 8px; }
  .table td form.row { flex-wrap: nowrap; }
  .table td form.row input { flex: 1 1 auto; }
  .table td form.row .btn, .table td > form > .btn { flex: 0 0 auto; }

  /* The main cell of each row (a name or title) leads the card */
  .table tr { display: flex; flex-direction: column; }
  .table td.cell-title { order: -1; padding: 2px 0 6px; font-size: 1.05rem; min-height: 0; }
  .table td.cell-title::before { content: none; }
  .table td.cell-empty { display: none; }

  /* Dashboard tables: title, then the three counts side by side, then the progress bar */
  .table.summary tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px 10px; padding: 12px 14px; }
  .table.summary td, .table.summary td.num { padding: 0; min-height: 0; width: auto; }
  .table.summary td:first-child, .table.summary td:last-child { grid-column: 1 / -1; }
  .table.summary td:first-child { padding-bottom: 4px; font-size: 1.02rem; }
  .table.summary td:first-child::before, .table.summary td:last-child::before { content: none; }
  .table.summary td.num { font-family: var(--serif); font-weight: 600; font-size: 1.25rem; color: var(--green); }
  .table.summary td.num::before { position: static; display: block; width: auto; font-family: var(--sans); }
  .table.summary td .bar { margin-top: 6px; }

  /* Lone action buttons span the card */
  form.stack > div > .btn, .card > form > .btn { width: 100%; }
  .stats:has(> .stat:nth-child(3):last-child) { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stats:has(> .stat:nth-child(3):last-child) .stat { padding: 10px; }
  .stats:has(> .stat:nth-child(3):last-child) .stat .l { font-size: .68rem; letter-spacing: .04em; }
  #camMsg:empty { display: none; }

  .ticket-name { font-size: 1.35rem; }
  .scan-result .who { font-size: 1.4rem; }
  #reader { min-height: 200px; }
  .hit { flex-wrap: wrap; }
}

@media (max-width: 380px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .hero h1 { font-size: 1.35rem; }
  .table:not(.summary) td, .table:not(.summary) td.num { padding-left: 0; }
  .table:not(.summary) td::before { position: static; display: block; width: auto; margin-bottom: 2px; }
}
