/* Borne du self — écran d'une personne debout, tablette sur un comptoir,
 * salle peu éclairée. Fond sombre, très gros caractères, cibles tactiles
 * larges, aucune dépendance externe. */

:root {
  --bg: #0d1117;
  --panel: #161b22;
  --line: #30363d;
  --txt: #f0f6fc;
  --muted: #9aa7b4;
  --ok: #1a7f37;
  --ok-bright: #2ea043;
  --ko: #b91c1c;
  --ko-bright: #ef4444;
  --accent: #1f6feb;
  --pad: max(12px, env(safe-area-inset-left));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--txt);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; user-select: none;
}

body { display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* --- écrans ------------------------------------------------------------- */
.screen { display: none; flex: 1; min-height: 0; flex-direction: column; }
body[data-screen="start"] #screen-start,
body[data-screen="code"]  #screen-code,
body[data-screen="scan"]  #screen-scan { display: flex; }

#screen-start, #screen-code {
  align-items: center; justify-content: center; gap: 28px;
  padding: var(--pad) var(--pad) calc(var(--pad) + env(safe-area-inset-bottom));
}

.brand { font-size: clamp(32px, 7vw, 64px); font-weight: 800; letter-spacing: .02em; }
.brand.small { font-size: clamp(22px, 4vw, 34px); color: var(--muted); font-weight: 600; }

.huge {
  font-size: clamp(26px, 5vw, 44px); font-weight: 800;
  padding: 32px 48px; min-width: min(90vw, 620px); min-height: 140px;
  color: #fff; background: var(--accent); border: none; border-radius: 20px;
  cursor: pointer;
}
.huge:active { transform: scale(.98); }

.hint { color: var(--muted); font-size: clamp(14px, 2.2vw, 20px); margin: 0; text-align: center; }

/* --- pavé numérique ----------------------------------------------------- */
.code-display {
  font-size: 44px; letter-spacing: 14px; min-height: 60px; font-weight: 700;
  border-bottom: 3px solid var(--line); padding: 0 10px 6px; min-width: 260px;
  text-align: center;
}
.code-display.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 30px; letter-spacing: 4px; }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; width: min(92vw, 420px); }
.keypad.small { width: min(88vw, 340px); gap: 10px; }
.key {
  font-size: 32px; font-weight: 700; padding: 22px 0; color: var(--txt);
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; cursor: pointer;
}
.keypad.small .key { font-size: 26px; padding: 16px 0; }
.key:active { background: #21262d; }
.key.alt { color: var(--muted); }
.key.go { background: var(--ok); border-color: var(--ok-bright); color: #fff; }

/* --- barre d'état ------------------------------------------------------- */
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(var(--pad) + env(safe-area-inset-top)) var(--pad) 8px;
  flex-wrap: wrap;
}
.status { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
}
.chip.up { color: #7ee787; border-color: #2ea04355; }
.chip.down { color: #ffa198; border-color: #f8514955; background: #2d1214; }
.bar-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.mini {
  font-size: 15px; font-weight: 600; padding: 12px 16px; min-height: 46px;
  background: var(--panel); color: var(--txt);
  border: 1px solid var(--line); border-radius: 12px; cursor: pointer;
}
.mini[aria-pressed="true"] { background: #3d2f00; border-color: #9e6a03; color: #f2cc60; }
.mini.wide { width: 100%; margin-top: 12px; }

.banner {
  margin: 6px var(--pad); padding: 12px 16px; border-radius: 12px;
  font-size: 16px; font-weight: 600;
}
.banner.error { background: #2d1214; color: #ffa198; border: 1px solid #f8514955; }

/* --- sélecteur de service ---------------------------------------------- */
.services { display: flex; gap: 10px; padding: 4px var(--pad) 10px; }
.svc {
  flex: 1; padding: 16px 10px; min-height: 88px; cursor: pointer;
  background: var(--panel); color: var(--txt);
  border: 2px solid var(--line); border-radius: 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.svc .lbl { font-size: clamp(17px, 2.6vw, 24px); font-weight: 700; }
.svc .prc { font-size: clamp(15px, 2.2vw, 20px); color: var(--muted); font-weight: 600; }
.svc[aria-pressed="true"] { background: #0d2d55; border-color: var(--accent); }
.svc[aria-pressed="true"] .prc { color: #cae0ff; }
.svc .win { font-size: 12px; color: var(--muted); }

/* --- caméra ------------------------------------------------------------- */
.stage { flex: 1; min-height: 0; display: flex; flex-direction: column;
  align-items: center; gap: 10px; padding: 0 var(--pad); }
.viewport {
  position: relative; flex: 1; min-height: 160px; width: 100%;
  container-type: size;
  background: #000; border-radius: 18px; overflow: hidden; border: 1px solid var(--line);
}
#video { width: 100%; height: 100%; object-fit: cover; display: block; }
/* Caméra frontale : miroir pour viser (posé par scan.js, sans effet sur la lecture). */
video.miroir { transform: scaleX(-1); }
.reticle {
  position: absolute; inset: 50% auto auto 50%; transform: translate(-50%, -50%);
  width: 80%; width: min(92cqw, 92cqh); aspect-ratio: 1; border: 3px solid #ffffff88; border-radius: 20px;
  box-shadow: 0 0 0 100vmax #00000055;
}

/* --- panneau de contrôle ------------------------------------------------ */
.panel { border-top: 1px solid var(--line); background: var(--panel);
  padding-bottom: env(safe-area-inset-bottom); }
.panel-toggle {
  width: 100%; display: flex; align-items: center; gap: 12px;
  padding: 16px var(--pad); min-height: 60px; cursor: pointer;
  background: none; border: none; color: var(--txt); font-size: 17px; font-weight: 600;
}
.panel-toggle strong {
  background: var(--accent); border-radius: 999px; padding: 3px 12px; font-size: 16px;
}
.panel-toggle .caret { margin-left: auto; color: var(--muted); }
.panel-toggle[aria-expanded="true"] .caret { transform: rotate(180deg); }
.panel-body { max-height: 42vh; overflow-y: auto; padding: 0 var(--pad) 14px; }
.meals { list-style: none; margin: 0; padding: 0; }
.meals li {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 16px;
}
.meals .h { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; }
.meals .n { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meals .b { font-variant-numeric: tabular-nums; color: var(--muted); }
.meals button {
  padding: 10px 14px; min-height: 44px; border-radius: 10px; cursor: pointer;
  background: #2d1214; color: #ffa198; border: 1px solid #f8514955; font-weight: 600;
}
.meals li.off { opacity: .55; }
.meals li.off .n { text-decoration: line-through; }
.meals .tag {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: #ffa198; border: 1px solid #f8514955; border-radius: 999px; padding: 3px 9px;
}
.panel-note {
  margin: 10px 0; padding: 12px 14px; border-radius: 12px; font-size: 15px;
  font-weight: 600; background: #0d2818; color: #7ee787; border: 1px solid #2ea04355;
}
.panel-note.warn { background: #2d1214; color: #ffa198; border-color: #f8514955; }
.meals button.arm { background: var(--ko); color: #fff; border-color: var(--ko-bright); }

/* --- éclairage par la dalle (caméra frontale) --------------------------- */
/* Blanc pur : c'est une lampe, pas un fond de page. Tout le reste de l'écran
 * passe dessous, sauf la barre d'outils (qui reste utilisable) et la petite
 * vidéo (qui sert à viser). */
.glow {
  display: none;
  position: fixed; inset: 0; z-index: 40; background: #fff;
  flex-direction: column; align-items: center; justify-content: flex-end; gap: 14px;
  padding: 24px var(--pad) calc(24px + env(safe-area-inset-bottom));
}
body[data-glow="1"] .glow { display: flex; }

.glow-hint { margin: 0; text-align: center; font-size: 15px; font-weight: 600; color: #6b7684; }
.glow-off {
  font-size: 18px; font-weight: 700; padding: 16px 28px; min-height: 60px;
  color: #111418; background: #eef1f4; border: 2px solid #c3cbd4;
  border-radius: 14px; cursor: pointer;
}
.glow-off:active { background: #dfe4ea; }

/* La barre reste au-dessus du blanc : on peut rebasculer la caméra, saisir un
 * numéro ou quitter sans avoir à éteindre l'éclairage d'abord. */
body[data-glow="1"] .bar {
  position: relative; z-index: 41; background: var(--bg); border-radius: 0 0 16px 16px;
}
/* Vignette de visée au centre du blanc. Position fixe : indépendante de
 * l'orientation et du repli de la barre. */
body[data-glow="1"] .viewport {
  position: fixed; z-index: 41; flex: none;
  left: 50%; top: 46%; transform: translate(-50%, -50%);
  /* bornée aussi en hauteur : en paysage sur un téléphone, elle viendrait
     sinon buter sur le bouton d'extinction. */
  width: min(46vw, 32vh, 220px); height: min(46vw, 32vh, 220px); min-height: 0;
  border-color: #c3cbd4;
}

/* --- retour plein écran ------------------------------------------------- */
.flash {
  position: fixed; inset: 0; z-index: 50; display: flex;
  align-items: center; justify-content: center; text-align: center;
  padding: 24px; color: #fff;
}
.flash.ok { background: var(--ok); }
.flash.ko { background: var(--ko); }
/* Servi par dérogation : ni le vert d'un service ordinaire, ni le rouge d'un
   refus. Le repas est parti, la situation reste à régler à l'accueil. */
.flash.warn { background: #8a5a00; }
.flash-inner { max-width: 96vw; }
.flash-title {
  font-size: clamp(46px, 13vw, 150px); font-weight: 900; line-height: 1;
  text-transform: uppercase; letter-spacing: -.01em;
}
.flash-name { font-size: clamp(24px, 5.5vw, 60px); font-weight: 700; margin-top: 14px; }
.flash-sub { font-size: clamp(20px, 4.5vw, 46px); font-weight: 600; margin-top: 10px; opacity: .92; }
.flash-close { margin-top: 26px; font-size: 17px; opacity: .8; }
.flash.ok .flash-close,
.flash.warn .flash-close { display: none; }   /* ces deux-là se referment seules */

/* --- dérogation à un blocage (sur l'écran rouge, et nulle part ailleurs) - */
.flash-override { margin-top: 30px; }
.override-btn {
  font-size: clamp(19px, 3.4vw, 28px); font-weight: 700; padding: 18px 28px;
  min-height: 66px; cursor: pointer; border-radius: 14px;
  background: #ffffff1a; color: #fff; border: 2px solid #ffffff88;
}
/* Armé : la couleur du geste qu'on est sur le point de faire, pas celle du refus. */
.override-btn.arm { background: #8a5a00; border-color: #ffd9a8; color: #fff; }
.override-btn:disabled { opacity: .6; }
.override-note {
  margin: 10px 0 0; font-size: clamp(13px, 2vw, 17px); opacity: .85; font-weight: 600;
}

/* --- modale ------------------------------------------------------------- */
.modal {
  position: fixed; inset: 0; z-index: 60; background: #000000cc;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-box {
  background: var(--bg); border: 1px solid var(--line); border-radius: 20px;
  padding: 20px; display: flex; flex-direction: column; align-items: center; gap: 14px;
  max-height: 96vh; overflow-y: auto;
}
.modal-box h2 { margin: 0; font-size: 22px; }
/* La saisie manuelle peut s'ouvrir depuis le dépannage : elle passe au-dessus. */
#manual { z-index: 70; }

/* --- dépannage d'un code oublié (mode secondaire, couleur distincte) --- */
.enroll .enroll-box {
  background: #2a1a4d; border: 2px solid #7c5cd6; border-radius: 20px;
  padding: 22px; width: min(96vw, 620px); text-align: center;
  display: flex; flex-direction: column; gap: 14px; max-height: 96vh; overflow-y: auto;
}
.enroll-head { font-size: 18px; font-weight: 700; color: #d6c7ff; letter-spacing: .04em;
  text-transform: uppercase; }
.enroll-ask { font-size: clamp(22px, 4.5vw, 34px); font-weight: 700; margin: 6px 0; }
.enroll-name { font-size: clamp(20px, 4vw, 30px); font-weight: 700; }
.enroll-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: clamp(52px, 16vw, 120px); font-weight: 900; letter-spacing: .1em;
  line-height: 1.05; margin: 6px 0;
}
.enroll-valid { font-size: clamp(17px, 3vw, 24px); font-weight: 600; color: #d6c7ff; }
/* Pourquoi cet écran existe, et pourquoi c'est la personne qui sert qui le tient :
   sans ces deux phrases, elle lira le code à n'importe qui de bonne foi. */
.enroll-why { font-size: clamp(15px, 2.4vw, 20px); color: #d6c7ff; margin: 0;
  line-height: 1.35; }
.enroll-warn {
  font-size: clamp(15px, 2.4vw, 20px); font-weight: 600; color: #ffd9a8; margin: 0;
  line-height: 1.35; background: #3a2a12; border: 1px solid #b4761f;
  border-radius: 12px; padding: 10px 12px;
}
/* Aperçu caméra du dépannage : la modale est au-dessus de la caméra de l'écran
   de scan, il faut donc réafficher le flux ici pour que la carte soit cadrable. */
.enroll-cam {
  position: relative; width: min(74vw, 300px); aspect-ratio: 1; margin: 0 auto;
  background: #000; border-radius: 16px; overflow: hidden; border: 2px solid #7c5cd6;
}
#enroll-video { width: 100%; height: 100%; object-fit: cover; display: block; }
.enroll-cam .reticle { width: 90%; border-width: 2px; }
.enroll-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.mini.go { background: var(--ok); border-color: var(--ok-bright); color: #fff; }

/* --- repas réservés ------------------------------------------------------ */
.resa-box { width: min(96vw, 640px); align-items: stretch; }
.resa-box h2, .resa-box > .hint { text-align: center; }
.resa-head { margin: 14px 0 0; font-size: 17px; color: var(--muted); }
.meals .tag.resa { color: #79c0ff; border-color: #388bfd66; }
.meals li.done .n { color: var(--muted); }
.meals button.hand { background: #0d2818; color: #7ee787; border-color: #2ea04355; }
.resa-print { display: flex; gap: 10px; flex-wrap: wrap; }
.resa-print .mini { flex: 1; min-width: 45%; }
.meals button.hand.arm { background: var(--ok); color: #fff; border-color: var(--ok-bright); }

/* --- paysage : caméra et panneau côte à côte --------------------------- */
@media (orientation: landscape) and (min-width: 700px) {
  .services { max-width: 620px; }
  .stage { flex-direction: row; align-items: stretch; }
  .stage .viewport { flex: 2; }
  #scan-hint { align-self: center; max-width: 240px; }
}
