:root {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --text: #121826;
  --muted: #5b6475;
  --border: #d4d9e3;
  --primary: #3b4cca;
  --primary-press: #2f3da6;
  --focus: #8b9bff;
  --error: #c62828;
  --ok: #0b8a4a;
  --ko: #c62828;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.5; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* --- Page d'inscription --- */
.shell { max-width: 480px; margin: 0 auto; padding: 24px 16px calc(32px + env(safe-area-inset-bottom)); }
.brand { margin: 8px 4px 20px; }
.brand-kicker { margin: 0; font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--primary); }
.brand h1 { margin: 4px 0 6px; font-size: 1.75rem; line-height: 1.2; }
.brand-sub { margin: 0; color: var(--muted); }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 16px; }

.field { margin-bottom: 16px; }
.field > label { display: block; margin-bottom: 6px; font-weight: 600; }
.field input:not([type="checkbox"]) {
  width: 100%; min-height: 52px; padding: 12px 14px;
  font: inherit; font-size: 16px; color: var(--text);
  background: #fff; border: 1.5px solid var(--border); border-radius: 10px;
  -webkit-appearance: none; appearance: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:not([type="checkbox"]):focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(59, 76, 202, .18); }
.field.has-error input:not([type="checkbox"]) { border-color: var(--error); }
.field.has-error input:not([type="checkbox"]):focus { box-shadow: 0 0 0 4px rgba(198, 40, 40, .15); }
.field-error { margin: 6px 0 0; color: var(--error); font-size: .9rem; font-weight: 500; }
.field-error:empty { display: none; }
#f-ticket_number { font-family: ui-monospace, "SF Mono", Consolas, monospace; letter-spacing: .04em; }

.field-consent > label { display: flex; gap: 12px; align-items: flex-start; min-height: 48px; font-weight: 400; font-size: .92rem; color: var(--muted); cursor: pointer; }
.field-consent input { flex: none; width: 24px; height: 24px; margin: 1px 0 0; accent-color: var(--primary); }
.field-consent.has-error > label { color: var(--text); }

.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

.btn-primary {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; min-height: 56px; margin-top: 8px; padding: 0 20px;
  font: inherit; font-size: 1.06rem; font-weight: 700; color: #fff;
  background: var(--primary); border: 0; border-radius: 12px; cursor: pointer;
  touch-action: manipulation; transition: background .15s, transform .1s;
}
.btn-primary:active { transform: scale(.98); background: var(--primary-press); }
.btn-primary:disabled { cursor: progress; opacity: .85; }
.spinner { display: none; width: 20px; height: 20px; border: 2.5px solid rgba(255, 255, 255, .4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
.is-busy .spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 16px; padding: 12px 14px; color: #7a4100; background: #fff4e5; border: 1px solid #ffd8a8; border-radius: 12px; font-weight: 500; }
.banner-btn { flex: none; min-height: 44px; padding: 0 16px; font: inherit; font-weight: 700; color: #fff; background: #7a4100; border: 0; border-radius: 10px; cursor: pointer; }
.foot { margin: 20px 4px 0; text-align: center; font-size: .82rem; color: var(--muted); }

/* --- Écrans résultat --- */
body.is-ok { background: var(--ok); }
body.is-refused { background: var(--ko); }
.result {
  position: fixed; inset: 0; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: 32px 24px calc(32px + env(safe-area-inset-bottom));
  text-align: center; color: #fff;
  opacity: 0; transform: scale(.96); transition: opacity .2s ease-out, transform .2s ease-out;
}
.result.is-in { opacity: 1; transform: none; }
.result-ok { background: var(--ok); }
.result-refused { background: var(--ko); }
.result-icon { display: grid; place-items: center; width: 96px; height: 96px; border-radius: 50%; background: rgba(255, 255, 255, .2); font-size: 56px; font-weight: 700; line-height: 1; }
.result-title { margin: 8px 0 0; font-size: 2.25rem; line-height: 1.1; outline: none; }
.result-name { margin: 0; font-size: 1.6rem; font-weight: 700; overflow-wrap: anywhere; }
.result-meta { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px 28px; margin: 8px 0 0; padding: 14px 22px; background: rgba(0, 0, 0, .16); border-radius: 14px; }
.result-meta div { display: flex; flex-direction: column; }
.result-meta dt { font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; opacity: .85; }
.result-meta dd { margin: 0; font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.result-note { max-width: 340px; margin: 8px 0 0; font-size: 1.02rem; opacity: .95; }
.result-reason { max-width: 340px; margin: 4px 0 0; font-size: 1.25rem; font-weight: 600; }
.btn-secondary { display: inline-flex; align-items: center; justify-content: center; min-height: 52px; margin-top: 16px; padding: 0 24px; font-weight: 700; color: var(--ko); background: #fff; border-radius: 12px; text-decoration: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .result { transform: none; }
}

/* --- Administration --- */
.page-admin { background: var(--bg); }
.admin { max-width: 1100px; margin: 0 auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); }
.admin-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.admin-title { margin: 2px 0 0; font-size: 1.35rem; line-height: 1.2; }
.admin-bar-right { display: flex; align-items: center; gap: 12px; }
.admin-bar-right form { margin: 0; }
.live { display: inline-flex; align-items: center; gap: 8px; font-size: .88rem; font-weight: 600; color: var(--muted); }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 rgba(11, 138, 74, .5); animation: pulse 2s infinite; }
.live[data-state="error"] .live-dot { background: #e08a00; animation: none; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(11, 138, 74, 0); } 100% { box-shadow: 0 0 0 0 rgba(11, 138, 74, 0); } }

.counter { display: flex; flex-wrap: wrap; align-items: baseline; gap: 12px 32px; margin-bottom: 16px; padding: 18px 20px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.counter-value { display: inline-block; font-size: 3rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; color: var(--primary); }
.counter-value.bump { animation: bump .35s ease-out; }
@keyframes bump { 50% { transform: scale(1.15); } }
.counter-label { font-size: 1.1rem; color: var(--muted); }
.counter-item { display: flex; align-items: baseline; gap: 10px; }
.counter-item-checked .counter-value { color: var(--ok); }

.admin-tools { margin-bottom: 12px; }
#search { width: 100%; min-height: 48px; padding: 10px 14px; font: inherit; font-size: 16px; background: #fff; border: 1.5px solid var(--border); border-radius: 10px; }
#search:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(59, 76, 202, .18); }

.list { margin: 0; padding: 0; list-style: none; }
.list-head { display: none; }
.row {
  display: grid; grid-template-columns: 44px 1fr auto;
  grid-template-areas: "check name time" "check email email" "check ticket mail" ". actions actions";
  gap: 2px 12px; align-items: center;
  margin-bottom: 8px; padding: 12px 14px;
  background: var(--surface); border-radius: 12px; box-shadow: 0 1px 2px rgba(16, 24, 40, .06);
}
.row.is-new { animation: flash 2s ease-out; }
@keyframes flash { 0%, 30% { background: #fff3b0; } 100% { background: var(--surface); } }
.cell { min-width: 0; }
.cell-check { grid-area: check; display: flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; cursor: pointer; }
.cell-check input { width: 26px; height: 26px; margin: 0; accent-color: var(--ok); cursor: pointer; }
.checked-at { display: block; font-size: .8rem; font-weight: 600; color: var(--ok); }
.checked-at:empty { display: none; }
.row.is-checked { background: #eceef3; box-shadow: none; }
.row.is-checked .cell:not(.cell-check):not(.cell-actions) { opacity: .5; }
.row.is-checked .name-text { text-decoration: line-through; }
.cell-name { grid-area: name; font-weight: 700; overflow-wrap: anywhere; }
.cell-time { grid-area: time; color: var(--muted); font-variant-numeric: tabular-nums; }
.cell-email { grid-area: email; color: var(--muted); font-size: .92rem; overflow-wrap: anywhere; }
.cell-ticket { grid-area: ticket; font-family: ui-monospace, "SF Mono", Consolas, monospace; overflow-wrap: anywhere; }
.cell-mail { grid-area: mail; display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.cell-actions { grid-area: actions; display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.mail { font-weight: 700; }
.mail-sent { color: var(--ok); }
.mail-failed { color: var(--ko); }
.mail-pending { color: var(--muted); }
.confirm-label { font-weight: 600; white-space: nowrap; }

.btn-small { min-height: 44px; padding: 0 14px; font: inherit; font-size: .9rem; font-weight: 600; color: var(--text); background: #fff; border: 1.5px solid var(--border); border-radius: 10px; cursor: pointer; }
.btn-small:disabled { opacity: .6; cursor: progress; }
.btn-danger { color: var(--ko); border-color: #f0c4c4; }
.btn-danger-solid { color: #fff; background: var(--ko); border-color: var(--ko); }
.empty { padding: 24px; text-align: center; color: var(--muted); }

@media (min-width: 760px) {
  .list-head, .row {
    grid-template-columns: 48px 64px 1.2fr 1.6fr 1fr 110px 220px;
    grid-template-areas: "check time name email ticket mail actions";
  }
  .list-head { display: grid; gap: 12px; padding: 0 14px 8px; font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
  .row { gap: 12px; }
  .cell-mail { justify-content: flex-start; }
  .cell-actions { margin-top: 0; }
}
