:root {
  --bg: #f6f5f0; --card: #ffffff; --ink: #1c1917; --muted: #57534e; --line: #e2dfd6;
  --brand: #14532d; --brand-ink: #ffffff; --accent: #b45309;
  --ok: #15803d; --used: #c2410c; --pending: #facc15; --bad: #b91c1c; --undecided: #4338ca;
  --radius: 14px; --tap: 48px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
a { color: var(--brand); }
.muted { color: var(--muted); } .small { font-size: .85rem; }

/* ---------- shell ---------- */
.boot { display: grid; place-items: center; gap: .5rem; min-height: 60vh; color: var(--muted); }
.spinner {
  width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--brand);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(.6rem + var(--safe-t)) 1rem .6rem; background: var(--brand); color: var(--brand-ink);
}
.view { padding: 1rem 1rem calc(88px + var(--safe-b)); max-width: 720px; margin: 0 auto; outline: none; }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
}
.tabs button {
  flex: 1; min-height: 60px; border: 0; background: none; font: inherit; font-size: .78rem; color: var(--muted);
  display: grid; place-items: center; gap: 2px; padding: 6px 2px; cursor: pointer;
}
.tabs button .ico { font-size: 1.35rem; line-height: 1; }
.tabs button[aria-current="page"] { color: var(--brand); font-weight: 700; box-shadow: inset 0 3px 0 var(--brand); }
.pill {
  font-size: .78rem; padding: .15rem .6rem; border-radius: 999px; background: rgba(255,255,255,.2); white-space: nowrap;
}
.pill.off { background: #fde68a; color: #422006; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: .9rem; }
.card > :last-child { margin-bottom: 0; }

/* ---------- forms and buttons ---------- */
label { display: block; font-weight: 600; margin: .8rem 0 .25rem; }
input, select, textarea {
  width: 100%; min-height: var(--tap); padding: .6rem .75rem; font: inherit; color: inherit;
  background: #fff; border: 1.5px solid #a8a29e; border-radius: 10px;
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 3px solid #86efac; outline-offset: 1px; }
textarea { min-height: 80px; resize: vertical; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: var(--tap);
  padding: .6rem 1.1rem; border-radius: 10px; border: 1.5px solid var(--brand); background: var(--brand);
  color: #fff; font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
}
.btn.secondary { background: #fff; color: var(--brand); }
.btn.danger { background: #fff; color: var(--bad); border-color: var(--bad); }
.btn.wa { background: #128c4a; border-color: #128c4a; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.row > * { flex: 1 1 auto; }
.stack > * + * { margin-top: .6rem; }
.error { color: var(--bad); font-weight: 600; }
.notice { background: #fef9c3; border: 1px solid #facc15; border-radius: 10px; padding: .6rem .8rem; }
.notice.bad { background: #fee2e2; border-color: #fca5a5; }

/* ---------- login ---------- */
.login { max-width: 420px; margin: 8vh auto 0; }

/* ---------- dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; margin-bottom: .9rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; }
.stat b { display: block; font-size: 1.9rem; line-height: 1.1; }
.stat span { color: var(--muted); font-size: .85rem; }
.stat.hot b { color: var(--bad); }
.bar { height: 14px; border-radius: 999px; background: var(--line); overflow: hidden; margin: .4rem 0; }
.bar > i { display: block; height: 100%; width: var(--pct, 0%); background: var(--ok); }
.list { list-style: none; padding: 0; margin: 0; }
.list li { padding: .55rem 0; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: .75rem; }
.list li:first-child { border-top: 0; }

/* ---------- people ---------- */
.chips { display: flex; gap: .4rem; overflow-x: auto; padding: .1rem 0 .6rem; }
.chip {
  flex: none; border: 1.5px solid var(--line); background: #fff; border-radius: 999px; padding: .35rem .85rem;
  font: inherit; font-size: .9rem; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--brand); color: #fff; border-color: var(--brand); }
.person {
  display: flex; width: 100%; text-align: left; gap: .75rem; align-items: center; justify-content: space-between;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem .9rem;
  margin-bottom: .5rem; font: inherit; color: inherit; cursor: pointer; min-height: 58px;
}
.person .nm { font-weight: 700; } .person .ph { color: var(--muted); font-size: .88rem; }
.badges { display: flex; gap: .3rem; flex-wrap: wrap; justify-content: flex-end; }
.badge { font-size: .72rem; font-weight: 700; padding: .12rem .5rem; border-radius: 999px; background: var(--line); white-space: nowrap; }
.badge.paid { background: #dcfce7; color: #14532d; }
.badge.pending { background: #fef08a; color: #713f12; }
.badge.complimentary { background: #dbeafe; color: #1e3a8a; }
.badge.in { background: #14532d; color: #fff; }
.badge.void { background: #fee2e2; color: #7f1d1d; }

/* ---------- sheet ---------- */
.sheet {
  width: min(560px, 100%); max-height: 92vh; margin: auto auto 0; padding: 1rem 1rem calc(1rem + var(--safe-b));
  border: 0; border-radius: 18px 18px 0 0; overflow: auto;
}
.sheet::backdrop { background: rgba(0,0,0,.5); }
.qrbox { width: min(280px, 100%); margin: .5rem auto; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
.qrbox svg { display: block; width: 100%; height: auto; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(76px + var(--safe-b)); z-index: 20;
  background: #1c1917; color: #fff; padding: .65rem 1rem; border-radius: 10px; max-width: 92vw; text-align: center;
}
.toast.err { background: var(--bad); }

/* ---------- scanner ---------- */
.cam { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 4 / 3; }
.cam video { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam.live::after { /* aiming guide: the scanner reads the centre ~2/3 of the frame */
  content: ''; position: absolute; inset: 0; margin: auto; height: 68%; aspect-ratio: 1;
  border: 3px solid rgba(255,255,255,.9); border-radius: 14px; pointer-events: none; box-shadow: 0 0 0 9999px rgba(0,0,0,.25);
}
.cam .cam-msg { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; text-align: center; padding: 1rem; }
.result {
  margin: .9rem 0; border-radius: var(--radius); padding: 1rem; text-align: center; min-height: 168px;
  display: grid; align-content: center; gap: .2rem; background: #e7e5e4; color: var(--ink);
}
.result .glyph { font-size: 2.6rem; line-height: 1; }
.result .big { font-size: clamp(1.9rem, 9vw, 2.8rem); font-weight: 900; letter-spacing: .02em; line-height: 1.05; }
.result .who { font-size: 1.35rem; font-weight: 700; }
.result .sub { font-size: .95rem; opacity: .95; }
.result.VALID { background: var(--ok); color: #fff; }
.result.USED { background: var(--used); color: #fff; }
.result.PENDING { background: var(--pending); color: #1c1917; }
.result.INVALID { background: var(--bad); color: #fff; }
.result.UNDECIDED { background: var(--undecided); color: #fff; }
.result.busy { background: #d6d3d1; }
.gate-status { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem .8rem; font-size: .9rem; }
.gate-status dt { color: var(--muted); } .gate-status dd { margin: 0; font-weight: 600; }

/* ---------- ticket page ---------- */
.ticket-body { background: var(--brand); min-height: 100vh; }
.ticket-wrap { max-width: 420px; margin: 0 auto; padding: 1.2rem 1rem 2rem; }
.ticket { background: #fff; border-radius: 22px; padding: 1.4rem 1.2rem; text-align: center; box-shadow: 0 8px 30px rgba(0,0,0,.25); }
.ticket-kicker { letter-spacing: .18em; text-transform: uppercase; font-size: .8rem; color: var(--brand); font-weight: 800; margin-bottom: .3rem; }
.ticket-name { font-size: 1.7rem; margin-bottom: .2rem; overflow-wrap: anywhere; }
.ticket-date { color: var(--muted); }
.ticket-qr { width: min(300px, 100%); margin: .8rem auto; border: 1px solid var(--line); border-radius: 12px; padding: 4px; min-height: 40px; }
.ticket-qr svg { display: block; width: 100%; height: auto; }
.ticket-badge { display: inline-block; padding: .35rem .9rem; border-radius: 999px; font-weight: 800; }
.ticket-badge.ok { background: #dcfce7; color: #14532d; }
.ticket-badge.warn { background: #fef08a; color: #713f12; }
.ticket-badge.bad { background: #fee2e2; color: #7f1d1d; }
.ticket-note { color: var(--muted); font-size: .9rem; margin-top: .6rem; }
.ticket-help { color: #dcfce7; font-size: .9rem; text-align: center; padding: 1rem .5rem 0; }
