/* Page de saisie du vendeur.
   Pensée pour un stand en plein air : un seul écran à la fois, fort contraste (lisible en plein soleil),
   grosses cibles tactiles, chiffres larges. Aucun style en ligne : la CSP du serveur les interdit. */

:root {
  --encre: #0b1b3a;
  --ultramarine: #1747e0;
  --ultramarine-appuye: #0f35b0;
  --brume: #e8edf7;
  --papier: #ffffff;
  --etiquette: #ffc83d;
  --alerte: #c4161c;
  --gris: #4f5b78;
  --ombre-touche: #bfc9e0;
  --police: "Bahnschrift", "Avenir Next", "Segoe UI Variable Display", "Segoe UI", Roboto, "Helvetica Neue", system-ui, sans-serif;
  --police-iban: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, "Liberation Mono", monospace;
  --marge: max(0.75rem, 2.5vw);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  background: var(--brume);
  color: var(--encre);
  font-family: var(--police);
  font-size: 1rem;
  line-height: 1.3;
  -webkit-tap-highlight-color: transparent;
}

body[data-ecran="qr"] {
  background: var(--ultramarine);
  color: var(--papier);
}

body[data-ecran="indisponible"] {
  background: var(--papier);
}

main {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
}

.ecran {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: max(var(--marge), env(safe-area-inset-top)) max(var(--marge), env(safe-area-inset-right))
    max(var(--marge), env(safe-area-inset-bottom)) max(var(--marge), env(safe-area-inset-left));
}

h1,
p {
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

[tabindex="-1"]:focus {
  outline: none;
}

button:focus-visible {
  outline: 4px solid var(--ultramarine);
  outline-offset: 3px;
}

body[data-ecran="qr"] button:focus-visible {
  outline-color: var(--papier);
}

.lecteur-seulement {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- chargement / indisponible ---------- */

.ecran-message {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 1.5rem;
  font-size: 1.25rem;
}

.ecran-message h1 {
  max-width: 20ch;
  padding-left: 1rem;
  border-left: 0.5rem solid var(--alerte);
  text-align: left;
  text-wrap: balance;
  font-size: clamp(1.75rem, 7vw, 2.75rem);
  line-height: 1.15;
}

.bouton-discret {
  min-height: 3.5rem;
  padding: 0 2rem;
  border-radius: 0.875rem;
  background: var(--brume);
  font-size: 1.25rem;
  font-weight: 700;
}

/* ---------- saisie du montant ---------- */

.evenement {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  font-size: 1.125rem;
  font-weight: 700;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

/* La fenêtre du montant : elle rappelle l'afficheur d'une caisse. */
.affichage {
  container-type: inline-size;
  padding: 0.5rem 1rem 0.625rem;
  border: 3px solid var(--encre);
  border-radius: 1rem;
  background: var(--papier);
  box-shadow: 0 4px 0 var(--encre);
}

.montant {
  display: block;
  position: relative;
  text-align: right;
}

.montant-texte {
  display: block;
  font-size: min(5.5rem, calc(96cqw / (max(var(--n, 6), 6) * 0.62)));
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums lining-nums;
  white-space: nowrap;
}

.fantome {
  color: #8a96b5;
}

.limite {
  min-height: 1.3em;
  padding-inline: 0.25rem;
  color: var(--gris);
  font-size: 1rem;
}

/* Configuration affichée = copie gardée hors ligne : le vendeur doit le voir. */
.hors-ligne {
  padding: 0.375rem 0.75rem;
  border-radius: 0.5rem;
  background: var(--etiquette);
  color: var(--encre);
  font-size: 0.9375rem;
  font-weight: 600;
}

.limite[data-depasse] {
  color: var(--alerte);
  font-weight: 700;
}

.affichage[data-depasse] {
  border-color: var(--alerte);
  box-shadow: 0 4px 0 var(--alerte);
}

.affichage[data-depasse] .montant-texte {
  color: var(--alerte);
}

/* Montants rapides : des étiquettes de prix. */
.rapides {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.rapide {
  min-height: 3rem;
  padding: 0 1.125rem;
  border-radius: 0.75rem;
  background: var(--etiquette);
  color: var(--encre);
  font-size: 1.3125rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.rapide[data-choisi] {
  outline: 3px solid var(--encre);
  outline-offset: 2px;
}

.pave {
  flex: 1 1 auto;
  min-height: 14rem;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 1fr;
  gap: 0.625rem;
}

.touche {
  border-radius: 1rem;
  background: var(--papier);
  box-shadow: 0 4px 0 var(--ombre-touche);
  font-size: clamp(1.75rem, 8vw, 2.5rem);
  font-weight: 700;
  font-variant-numeric: lining-nums;
}

.touche-fonction {
  background: #d3dbee;
}

.touche:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--ombre-touche);
}

/* Collé en bas de l'écran : toujours atteignable, même avec beaucoup de montants rapides. */
.valider {
  position: sticky;
  bottom: max(var(--marge), env(safe-area-inset-bottom));
  min-height: 4.25rem;
  border-radius: 1rem;
  background: var(--ultramarine);
  color: var(--papier);
  box-shadow: 0 4px 0 var(--ultramarine-appuye);
  font-size: 1.5rem;
  font-weight: 700;
}

.valider:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--ultramarine-appuye);
}

.valider:disabled {
  background: #cdd5e8;
  color: var(--gris);
  box-shadow: none;
  cursor: not-allowed;
}

@media (prefers-reduced-motion: no-preference) {
  .touche,
  .valider {
    transition: transform 60ms ease-out, box-shadow 60ms ease-out;
  }
}

/* ---------- écran du QR code ---------- */

#ecran-qr {
  align-items: center;
  gap: 0.625rem;
  text-align: center;
}

.retour {
  align-self: flex-start;
  min-height: 3.25rem;
  padding: 0 1.25rem;
  border-radius: 0.875rem;
  background: rgba(255, 255, 255, 0.18);
  color: var(--papier);
  font-size: 1.1875rem;
  font-weight: 700;
}

.retour:active {
  background: rgba(255, 255, 255, 0.32);
}

.qr-montant {
  font-size: clamp(2.5rem, 12vw, 4rem);
  font-weight: 700;
  line-height: 1.05;
  font-variant-numeric: tabular-nums lining-nums;
  overflow-wrap: anywhere;
}

.qr-consigne {
  font-size: 1.0625rem;
  opacity: 0.92;
}

/* Le QR occupe au moins 70 % de la largeur (et plus encore si la hauteur le permet). */
.qr-code {
  width: max(70vw, min(100%, calc(100dvh - 19rem)));
  max-width: 100%;
  aspect-ratio: 1;
  flex: none;
  overflow: hidden;
  border-radius: 1rem;
  background: var(--papier);
}

.qr-code svg {
  display: block;
  width: 100%;
  height: 100%;
}

.qr-details {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-width: 34rem;
}

.qr-beneficiaire {
  font-size: 1.1875rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.qr-iban {
  font-family: var(--police-iban);
  font-size: clamp(1.125rem, 5vw, 1.5rem);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.qr-communication {
  font-size: 1.0625rem;
  overflow-wrap: anywhere;
}

.qr-veille {
  max-width: 30rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  background: var(--etiquette);
  color: var(--encre);
  font-size: 0.9375rem;
  font-weight: 600;
}

/* ---------- paysage (téléphone ou tablette couchés, ordinateur) : deux colonnes ---------- */

@media (orientation: landscape) {
  #ecran-saisie {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto auto auto auto auto 1fr;
    grid-template-areas:
      "evenement pave"
      "affichage pave"
      "limite pave"
      "horsligne pave"
      "rapides pave"
      "valider pave";
    column-gap: 1rem;
    row-gap: 0.5rem;
    align-content: stretch;
  }

  #ecran-saisie .evenement { grid-area: evenement; }
  #ecran-saisie .affichage { grid-area: affichage; }
  #ecran-saisie .limite { grid-area: limite; }
  #ecran-saisie .hors-ligne { grid-area: horsligne; }
  #ecran-saisie .rapides { grid-area: rapides; }
  #ecran-saisie .pave { grid-area: pave; min-height: 0; }
  #ecran-saisie .valider { grid-area: valider; align-self: end; }

  .montant-texte {
    font-size: min(3.5rem, calc(96cqw / (max(var(--n, 6), 6) * 0.62)));
  }

  #ecran-qr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto auto 1fr auto;
    grid-template-areas:
      "retour qr"
      "montant qr"
      "consigne qr"
      "details qr"
      "veille qr";
    column-gap: 1.25rem;
    align-items: start;
    text-align: left;
  }

  #ecran-qr .retour { grid-area: retour; justify-self: start; }
  #ecran-qr .qr-montant { grid-area: montant; font-size: 2.75rem; }
  #ecran-qr .qr-consigne { grid-area: consigne; }
  #ecran-qr .qr-details { grid-area: details; }
  #ecran-qr .qr-veille { grid-area: veille; }
  #ecran-qr .qr-code {
    grid-area: qr;
    width: calc(100dvh - 2 * var(--marge));
    max-width: 55vw;
  }
}
