/* Mobile-first, sans dépendance. */
:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #16202a;
  --muted: #5d6b78;
  --line: #dfe5ea;
  --accent: #16607a;
  --error: #b3261e;
  --warn: #8a5300;
}

* { box-sizing: border-box; }

/* L'attribut hidden doit l'emporter : une regle d'auteur comme
   « canvas { display: block } » ecrase sinon le [hidden] du navigateur, et
   l'element reste visible alors que le code le croit masque. */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  padding: 1rem;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.card {
  max-width: 34rem;
  margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.25rem;
}

h1 {
  margin: 0 0 .25rem;
  font-size: 1.4rem;
  line-height: 1.25;
}

.sub { margin: 0 0 1rem; color: var(--muted); font-size: .95rem; }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* Bénéficiaire */
.benef {
  background: #f8fafb;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .75rem .9rem;
  margin-top: 1.5rem;
}
.benef dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .3rem .75rem;
  margin: 0;
  font-size: .95rem;
}
.benef dt { color: var(--muted); }
.benef dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

/* Formulaire : une colonne, y compris sur grand écran (2 champs seulement) */
.field { margin-bottom: 1rem; }
label {
  display: block;
  margin-bottom: .3rem;
  font-size: .9rem;
  font-weight: 600;
}
input[type="text"] {
  width: 100%;
  padding: .7rem .75rem;
  font-size: 1.05rem;
  color: inherit;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
input[type="text"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
input[aria-invalid="true"] { border-color: var(--error); }

.hint { margin: .35rem 0 0; font-size: .8rem; color: var(--muted); }
.error { margin: .35rem 0 0; font-size: .85rem; color: var(--error); }
.warn { margin: .35rem 0 0; font-size: .85rem; color: var(--warn); }

/* QR */
.qr { margin: 0 0 1.5rem; text-align: center; }
.qr-box {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 12rem;
  padding: .75rem;
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: 8px;
}
.qr-box:not(.empty) { border-style: solid; }
.placeholder { margin: 0; color: var(--muted); font-size: .9rem; }
canvas {
  display: block;
  width: 100%;
  max-width: 20rem;
  height: auto;
  image-rendering: pixelated;
}
.caption { margin: .6rem 0 0; font-size: .9rem; color: var(--muted); }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  justify-content: center;
  margin-top: 1rem;
}
button {
  flex: 1 1 10rem;
  padding: .65rem .9rem;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
button:hover { filter: brightness(1.08); }
button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* Payload */
.payload { margin-top: 1.5rem; border-top: 1px solid var(--line); padding-top: .75rem; }
summary { cursor: pointer; font-size: .9rem; color: var(--muted); }
pre {
  margin: .6rem 0 0;
  padding: .7rem;
  font-size: .8rem;
  background: #f8fafb;
  border: 1px solid var(--line);
  border-radius: 6px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (min-width: 30rem) {
  body { padding: 2rem 1rem; }
  .card { padding: 1.75rem; }
  h1 { font-size: 1.6rem; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131a20;
    --card: #1b242c;
    --ink: #e9eef2;
    --muted: #9fb0bd;
    --line: #2f3d47;
    --accent: #3d9ec0;
    --error: #ff8a80;
    --warn: #ffc46b;
  }
  .benef, pre { background: #161e25; }
  input[type="text"] { background: #101720; }
  button { color: #0d1418; }
  /* Le QR reste sur fond blanc : indispensable pour rester scannable. */
  .qr-box { background: #fff; }
  .placeholder { color: #5d6b78; }
}

/* ------------------------------------------------------------------ */
/* Choix du type de communication                                     */
/* ------------------------------------------------------------------ */
fieldset.choix {
  border: 0;
  padding: 0;
  margin: 0 0 1rem;
}
fieldset.choix legend {
  padding: 0;
  margin-bottom: .3rem;
  font-size: .9rem;
  font-weight: 600;
}
.radio, .case {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  margin-right: 1.2rem;
  font-size: .95rem;
  font-weight: 400;
  cursor: pointer;
}
.case { display: flex; margin: .5rem 0 0; font-size: .85rem; }

button.lien {
  flex: none;
  margin-top: .5rem;
  padding: 0;
  font-size: .85rem;
  font-weight: 600;
  color: var(--accent);
  background: none;
  text-decoration: underline;
  cursor: pointer;
}

/* ------------------------------------------------------------------ */
/* Administration                                                     */
/* ------------------------------------------------------------------ */
body.large .card { max-width: 60rem; }
.card.etroit { max-width: 24rem; }
.card.centre { text-align: center; }

.entete-admin {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.entete-admin h1 { margin: 0; }

h2 {
  margin: 2rem 0 .75rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
  font-size: 1.15rem;
}

p.bloc {
  padding: .6rem .8rem;
  border-radius: 8px;
  border: 1px solid currentColor;
}
.succes { color: #1c6b3a; }

.tableau { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
th, td {
  padding: .55rem .6rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
th { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
td a { color: var(--accent); }

.actions-ligne {
  display: flex;
  gap: .6rem;
  align-items: center;
}
.actions-ligne form { display: inline; }
.actions-ligne button {
  flex: none;
  padding: .3rem .6rem;
  font-size: .8rem;
}
button.danger { background: var(--error); }
button.discret {
  flex: none;
  padding: .4rem .7rem;
  font-size: .85rem;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
}
.bouton-secondaire {
  display: inline-flex;
  align-items: center;
  padding: .65rem .9rem;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 8px;
}

input[type="password"] {
  width: 100%;
  padding: .7rem .75rem;
  font-size: 1.05rem;
  color: inherit;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

@media (prefers-color-scheme: dark) {
  .succes { color: #7cd0a0; }
  input[type="password"] { background: #101720; }
  button.discret { color: var(--ink); }
}

/* ------------------------------------------------------------------ */
/* Page d'aide                                                        */
/* ------------------------------------------------------------------ */
.adresse {
  display: inline-block;
  padding: .5rem .7rem;
  font-size: .95rem;
  color: var(--accent);
  background: #f8fafb;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-wrap: anywhere;
}
a.exemple { color: var(--accent); overflow-wrap: anywhere; }
main ul { padding-left: 1.2rem; }
main li { margin-bottom: .4rem; }
main p { line-height: 1.6; }
.retour { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.retour a, .aide-lien a { color: var(--accent); font-weight: 600; text-decoration: none; }
.aide-lien { margin: 1.25rem 0 0; text-align: center; font-size: .9rem; }
.tableau td { white-space: normal; }
.tableau td.mono { white-space: nowrap; }

@media (prefers-color-scheme: dark) {
  .adresse { background: #161e25; }
}

/* ------------------------------------------------------------------ */
/* Agrandissement du QR (plein écran)                                 */
/* ------------------------------------------------------------------ */
.agrandir {
  margin: .3rem 0 0;
  font-size: .78rem;
  color: var(--muted);
}
#qr-canvas { cursor: zoom-in; }

.plein-ecran {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1rem;
  background: #fff;
  cursor: zoom-out;
}
.plein-ecran[hidden] { display: none; }
.plein-ecran img {
  width: min(92vw, 92vh);
  height: auto;
  image-rendering: pixelated;
}
.plein-ecran p {
  margin: 0;
  font-size: .85rem;
  color: #5d6b78;
}

/* ------------------------------------------------------------------ */
/* Mise en page compacte sur petit écran                              */
/* ------------------------------------------------------------------ */
@media (max-width: 40rem) {
  body { padding: .5rem; }
  .card { padding: .9rem; border-radius: 10px; }

  h1 { font-size: 1.15rem; }
  .sub { margin-bottom: .5rem; font-size: .82rem; }

  /* Le QR reste visible pendant la saisie des champs. */
  .qr {
    position: sticky;
    top: 0;
    z-index: 5;
    margin: 0 0 .6rem;
    padding: .35rem 0 .45rem;
    background: var(--card);
    box-shadow: 0 8px 8px -8px rgba(0, 0, 0, .3);
  }
  .qr-box { min-height: 0; padding: .35rem; }
  #qr-canvas { width: min(100%, 30vh); }
  .caption { margin-top: .3rem; font-size: .75rem; }

  .field { margin-bottom: .65rem; }
  fieldset.choix { margin-bottom: .65rem; }
  fieldset.choix legend { margin-bottom: .2rem; }
  input[type="text"] { padding: .55rem .65rem; font-size: 1rem; }
  .hint, .error, .warn { margin-top: .25rem; font-size: .78rem; }

  .benef { margin-top: 1rem; padding: .6rem .7rem; }
  .benef dl { gap: .25rem .6rem; font-size: .88rem; }
  .actions { margin-top: .75rem; }
  .aide-lien { margin-top: 1rem; }
  .payload { margin-top: 1rem; }
}

/* Écrans courts (mobile en paysage) : on rogne encore le QR. */
@media (max-width: 40rem) and (max-height: 34rem) {
  .sub { display: none; }
  #qr-canvas { width: min(100%, 22vh); }
}
