/* Pensé d'abord pour un petit téléphone (320 px de large). */

/* Polices de 26COMPTA, réduites aux caractères utiles (licence SIL Open Font). */
@font-face { font-family: Fraunces; src: url("../polices/fraunces-600.woff") format("woff"); font-weight: 600; font-display: swap; }
@font-face { font-family: Inter; src: url("../polices/inter-400.woff") format("woff"); font-weight: 400; font-display: swap; }
@font-face { font-family: Inter; src: url("../polices/inter-600.woff") format("woff"); font-weight: 600; font-display: swap; }
@font-face { font-family: Inter; src: url("../polices/inter-700.woff") format("woff"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Plex Mono"; src: url("../polices/plex-mono-500.woff") format("woff"); font-weight: 500; font-display: swap; }

/* Couleurs de 26COMPTA (ui/theme.py), maquette COFFRE_ACHATS/4-MAQUETTES/identite-26compta. */
:root {
  --bg: #F4F1EA; --carte: #FFFFFF; --ligne: #EBE3D5; --teinte: #F2EEE6; --separateur: #CBC2B2;
  --text: #1C2431; --muted: #6E6A61;
  --bleu: #1B4DD1; --bleu-encre: #182F63; --bleu-fond: #EEF2FE; --bleu-focus: #185FA5;
  --bouton: #122238; --bouton-appui: #0C1A2E;
  --vert: #2F8F5B;
  --ambre: #C0872B; --ambre-fond: #FBF0DC;
  --red: #C0492F; --red-pale: #FAEBE7; --red-encre: #993C1D;
  --champ-fond: #FBF9F5; --champ-bord: #E8E3D9;
  --blanc: #fff;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.35;
}

/* Dans l'appli installée, la page défile jusque sous l'heure et l'encoche : cette bande la cache. */
body::before {
  content: ""; position: fixed; top: 0; left: 0; right: 0; z-index: 90;
  height: env(safe-area-inset-top, 0px); background: var(--bg);
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right))
           calc(24px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left));
}

h1 {
  margin: 0;
  font-family: Fraunces, Georgia, "Times New Roman", serif;
  font-size: 25px;
  font-weight: 600;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: .55; cursor: default; }

/* --- Boutons --- */

.bouton {
  display: block; width: 100%; min-height: 54px; padding: 12px 14px;
  font-weight: 600; color: var(--blanc);
  background: var(--bouton); border: 1px solid var(--bouton); border-radius: 10px;
}
.bouton:active { background: var(--bouton-appui); }
.bouton.secondaire { color: var(--bleu); background: var(--carte); border-color: var(--ligne); }
.bouton.danger { color: var(--red); background: var(--blanc); border-color: var(--red); }
.bouton.danger-plein { color: var(--blanc); background: var(--red); border-color: var(--red); }

.retour {
  min-height: 48px; padding: 8px 8px 8px 0; margin-bottom: 4px;
  color: var(--bleu); font-weight: 600; background: none; border: 0;
}

/* --- Écran du code --- */

.ecran-code { padding-top: 32px; }
.ecran-code h1 { margin-bottom: 20px; }
.ecran-code .aide {
  padding: 12px; margin: 0 0 18px;
  background: var(--carte); border: 1px solid var(--ligne); border-left: 4px solid var(--bleu); border-radius: 8px;
}
.ecran-code input { letter-spacing: 2px; text-transform: uppercase; }

/* --- Accueil --- */

.prenom { margin: 3px 0 14px; color: var(--muted); overflow-wrap: anywhere; }

.moyens { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.moyen {
  min-height: 80px; padding: 8px 2px;
  font-size: 18px; font-weight: 700; color: var(--blanc);
  background: var(--bouton); border: 0; border-radius: 12px;
}
.moyen:active { background: var(--bouton-appui); }

.vide { margin: 22px 8px; color: var(--muted); text-align: center; }

.ticket {
  display: block; width: 100%; padding: 12px 14px; margin-bottom: 8px;
  text-align: left; background: var(--carte);
  border: 1px solid var(--ligne); border-radius: 12px;
  box-shadow: 0 2px 7px rgba(28, 36, 49, .05);
}
.ticket.alerte-normale { border: 2px solid var(--red); }
.ticket.alerte-forte { background: var(--red-pale); border: 2px solid var(--red); }
.ticket-titre { font-weight: 600; overflow-wrap: anywhere; }
.ticket-sous-titre { margin-top: 2px; font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }

.badge {
  display: inline-block; margin-top: 7px; padding: 2px 9px; font-size: 12px; font-weight: 600;
  color: var(--bleu-encre); background: var(--bleu-fond); border-radius: 11px;
}
.badge.A_COMPLETER { color: var(--red-encre); background: var(--red-pale); }
.badge.EN_LECTURE { color: var(--muted); background: var(--teinte); }

/* --- Messages --- */

.message {
  padding: 12px 14px; margin-bottom: 12px;
  font-weight: 600; border-radius: 10px; overflow-wrap: anywhere;
}
.message.ok { color: var(--text); background: var(--carte); border: 1px solid var(--ligne); border-left: 4px solid var(--vert); }
.message.info { background: var(--red-pale); color: var(--red-encre); }
.message.attente { color: var(--text); background: var(--ambre-fond); border: 1px solid var(--ambre); }

/* La zone reste en haut de l'écran pendant qu'on fait défiler : impossible à manquer. */
.bandeaux, #message-fiche:has(.message.erreur) {
  position: sticky; top: calc(8px + env(safe-area-inset-top)); z-index: 5;
}
.message.erreur {
  color: var(--blanc); background: var(--red);
  box-shadow: 0 2px 10px rgba(28, 36, 49, .35);
}

.erreur-code { min-height: 1.4em; margin: 12px 0 0; font-weight: 600; color: var(--red); }
.ecran-code .erreur-code:empty { display: none; }

/* --- Fiche du ticket --- */

.en-tete-fiche { margin-bottom: 12px; }

/* La photo en entier : on lit le ticket en faisant défiler, sans l'ouvrir à chaque case. */
/* La photo reste en haut pendant la saisie ; un long ticket se fait défiler dans sa zone. */
.photos {
  position: sticky; top: calc(8px + env(safe-area-inset-top)); z-index: 4;
  display: grid; grid-auto-rows: max-content; gap: 8px; margin-bottom: 14px;
  max-height: 38vh; overflow-y: auto; border-radius: 10px; background: var(--bg);
}
.photo {
  width: 100%; min-height: 150px; padding: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 15px;
  background: var(--carte); border: 1px solid var(--ligne); border-radius: 10px;
}
.photo img { display: block; width: 100%; height: auto; }

fieldset { min-width: 0; padding: 0; margin: 0; border: 0; }

.champ { display: block; margin-bottom: 12px; }
.champ-titre { display: block; margin-bottom: 3px; font-size: 14px; font-weight: 600; color: var(--muted); }
.a-verifier { margin-left: 6px; font-size: 14px; color: var(--red); }

input[type="text"], input[type="date"] {
  display: block; width: 100%; min-height: 50px; padding: 10px 12px;
  /* 16 px au moins : en dessous, l'iPhone zoome tout seul sur la case. */
  font-size: 17px;
  background: var(--champ-fond); border: 1px solid var(--champ-bord); border-radius: 9px;
  -webkit-appearance: none; appearance: none;
}
.en-defaut input { border: 2px solid var(--red); }
input:focus { border-color: var(--bleu-focus); outline: none; }
input:focus-visible, button:focus-visible { outline: 2px solid var(--bleu-focus); outline-offset: 1px; }

/* Montant lu automatiquement, pas encore confirmé (maquette identite-26compta, ajustement 4). */
.proposition input { color: var(--muted); font-style: italic; background: var(--red-pale); }
.note-proposition { margin: -6px 0 8px; font-size: 14px; font-weight: 600; color: var(--red-encre); }
.bouton.montant-bon { margin: 0 0 12px; color: var(--bleu); border-color: var(--bleu); }
input[name="montant_ttc"], input[name="montant_ht"], input[name="montant_tva"], input[type="date"] {
  font-family: "Plex Mono", Consolas, monospace;
}

.choix-moyen { margin: 0 0 12px; }
.choix-moyen-boutons { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.choix-moyen label { display: block; }
.choix-moyen input { position: absolute; opacity: 0; width: 0; height: 0; }
.choix-moyen-boutons span {
  display: flex; align-items: center; justify-content: center; min-height: 50px;
  font-weight: 600; color: var(--bleu);
  background: var(--carte); border: 1px solid var(--ligne); border-radius: 9px;
}
.choix-moyen input:checked + span { color: var(--blanc); background: var(--bouton); border-color: var(--bouton); }
.choix-moyen input:focus-visible + span { outline: 2px solid var(--bleu-focus); outline-offset: 1px; }

details { margin-bottom: 14px; }
summary { min-height: 44px; padding: 10px 0; font-weight: 600; color: var(--bleu); cursor: pointer; }

.actions { display: grid; gap: 10px; margin-top: 8px; }

fieldset:disabled input, fieldset:disabled span { opacity: .55; }
.lecture-en-cours { margin: 0 0 12px; font-weight: 600; color: var(--muted); }

/* --- Fenêtres --- */

.voile {
  position: fixed; inset: 0; z-index: 20; padding: 16px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(28, 36, 49, .55);
}
.boite { width: 100%; max-width: 360px; padding: 18px; background: var(--carte); border-radius: 14px; }
.boite p { margin: 0 0 16px; }
.boite-boutons { display: grid; gap: 8px; }

.plein-ecran { position: fixed; inset: 0; z-index: 30; overflow: auto; background: #000; }
.plein-ecran img { display: block; width: 100%; height: auto; }
.plein-ecran .fermer {
  position: fixed; right: 12px; top: calc(12px + env(safe-area-inset-top));
  min-height: 48px; padding: 8px 14px; font-weight: 600;
  color: var(--text); background: var(--blanc); border: 0; border-radius: 10px;
}

/* --- File d'envoi --- */

.compteur {
  display: block; width: 100%; min-height: 48px; padding: 10px 14px; margin-bottom: 8px;
  text-align: left; font-weight: 600; color: var(--bleu-encre);
  background: var(--carte); border: 1px solid var(--ligne); border-radius: 10px;
}
.compteur.attente { color: var(--text); background: var(--ambre-fond); border-color: var(--ambre); }
.compteur.action { color: var(--blanc); background: var(--red); border-color: var(--red); }
/* Sans réseau : les photos qui partiront toutes seules, bloc gris distinct de l'action nécessaire. */
.compteur.partiront { color: var(--text); background: var(--teinte); border-color: var(--separateur); }
.compteur.partiront strong { display: block; font-weight: 600; }
.compteur.partiront span { font-size: 14px; font-weight: 400; color: var(--muted); }

.calme { margin: 0 0 10px; font-size: 14px; color: var(--muted); background: var(--bg); }
.conseil { margin: 0 0 10px; font-size: 14px; color: var(--muted); }
.autres { margin: 0 0 10px; font-size: 14px; font-weight: 600; color: var(--muted); }

.deuxieme {
  min-height: 44px; padding: 8px 12px; font-size: 14px; font-weight: 600; color: var(--bleu);
  background: var(--bleu-fond); border: 0; border-radius: 8px;
}
/* Sur une seule ligne : un message ne doit pas prendre la place des tickets. */
.message:has(.deuxieme) { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.message .deuxieme { flex: none; }
.bandeaux { max-height: 55vh; overflow-y: auto; }
.alerte-ligne { margin-top: 4px; font-weight: 400; }

.element {
  display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 10px;
  padding: 10px; margin-bottom: 10px; background: var(--carte); border: 1px solid var(--ligne); border-radius: 12px;
}
.element img { display: block; width: 76px; height: 96px; object-fit: cover; border-radius: 8px; background: var(--bg); }
.element-etat { font-weight: 600; }
.element-message { margin-top: 4px; font-size: 15px; color: var(--red-encre); overflow-wrap: anywhere; }
.element-details { margin-top: 2px; font-size: 14px; color: var(--muted); }
.element .actions { grid-column: 1 / -1; margin-top: 0; }
.element-photos { display: grid; gap: 6px; align-content: start; }
.voile-perte { z-index: 110; }   /* au-dessus du masque : l'alerte ne montre aucune donnée */
/* Stockage plein : reste visible sur tous les écrans, sans gêner les boutons. */
#perte-non-ecrite {
  position: fixed; left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); z-index: 105;
  padding: 10px 12px; font-size: 15px; font-weight: 600; color: var(--blanc); background: var(--red);
  border-radius: 10px; pointer-events: none;
}
/* Recouvre tout en arrière-plan : au-dessus de tout le reste, sans aucune donnée. */
.masque {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 24px; text-align: center; color: var(--muted); background: var(--bg);
}
