/* Habillage « terrain » : l'application sur un téléphone, d'une main, souvent avec des gants et en plein jour.
   Chargé en dernier, il ne fait que surcharger style.css, ia.css, fournitures.css et reference.css.
   Règles : cibles de 48 px au moins, texte des champs à 17 px (pas de zoom automatique sous iOS),
   l'action principale à portée du pouce, la vue 3D lisible et agrandissable en plein écran. */

:root {
  --cible: 48px;
  --barre-bas: calc(76px + env(safe-area-inset-bottom));
  --hauteur-3d: clamp(200px, 34vh, 330px);
}

/* ------------------------------------------------------------------ partout */
.bouton { min-height: var(--cible); }
.bouton:active, .type:active, .releve:active, .ref-article:active { translate: 0 1px; filter: brightness(0.97); }
button, a, label, summary, input[type='range'] { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
input[type='text'], input[type='password'], input[type='search'], input:not([type]), select, textarea { min-height: 52px; font-size: 17px; }
.segments span { min-height: 52px; font-size: 16px; }
.menu summary { min-height: var(--cible); min-width: var(--cible); justify-content: center; }
.menu > div a, .menu > div button { min-height: var(--cible); display: flex; align-items: center; font-size: 16px; }
.pastille { min-height: 40px; }
.lien.discret { min-height: var(--cible); }
.retour { min-height: 40px; }

/* ------------------------------------------------------------------ liste : actions, sélection, annonce */
.releve-case { position: relative; }
.releve-case .releve { padding-right: 60px; }
.plus-actions {
  position: absolute; top: 6px; right: 6px; width: 48px; height: 48px; border: 0; border-radius: 10px;
  background: none; color: var(--texte-doux); font-size: 26px; line-height: 1; font-weight: 700;
}
.plus-actions:hover, .plus-actions:focus-visible { background: var(--papier2); color: var(--encre); }
.releve.choisi { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.releve.hors-choix { opacity: 0.45; }
.releve .coche {
  position: absolute; top: 14px; right: 14px; width: 30px; height: 30px; border-radius: 8px;
  border: 2px solid var(--trait-fort); background: var(--papier); display: grid; place-items: center;
}
.releve.choisi .coche { background: var(--accent); border-color: var(--accent); color: #fff; }
.releve.choisi .coche svg { width: 20px; height: 20px; stroke-width: 3; }
.outils-liste { display: flex; gap: 8px; align-items: stretch; }
.outils-liste .recherche { flex: 1; max-width: 520px; }
.outils-liste .choisir { flex: none; min-width: 96px; }
.outils-liste .choisir.actif { background: var(--encre); border-color: var(--encre); color: #fff; }
.aide-choix { font-weight: 600; color: var(--encre); }
.barre-choix { display: flex; gap: 10px; }
.barre-choix .bouton { min-height: 56px; font-size: 17px; }
.barre-choix .principal { flex: 1; }

.annonce {
  position: fixed; z-index: 80; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); translate: -50% 20px;
  width: min(520px, calc(100% - 24px)); display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 16px;
  background: var(--encre); color: #fff; border-radius: 12px; box-shadow: 0 12px 30px -10px rgba(0, 0, 0, 0.5);
  font-weight: 600; opacity: 0; pointer-events: none; transition: opacity 0.18s, translate 0.18s;
}
.annonce.visible { opacity: 1; translate: -50% 0; pointer-events: auto; }
.annonce span { flex: 1; overflow-wrap: anywhere; }
.annonce button { min-height: 44px; padding: 0 16px; border: 0; border-radius: 8px; background: #fff; color: var(--encre); font-weight: 700; }

.voile { position: fixed; inset: 0; z-index: 70; background: rgba(28, 28, 31, 0.45); display: grid; align-items: end; justify-items: center; }
.feuille {
  width: min(520px, 100%); background: var(--papier); border-radius: 16px 16px 0 0; display: grid; gap: 4px;
  padding: 16px 12px calc(12px + env(safe-area-inset-bottom)); box-shadow: 0 -10px 30px -10px rgba(0, 0, 0, 0.4);
  animation: feuille-monte 0.18s ease-out;
}
@keyframes feuille-monte { from { translate: 0 30px; opacity: 0.6; } }
@media (prefers-reduced-motion: reduce) { .feuille { animation: none; } .annonce { transition: none; } }
.feuille-tete { padding: 0 8px 10px; border-bottom: 1px solid var(--trait); margin-bottom: 4px; display: grid; gap: 2px; }
.feuille-tete strong { color: var(--encre); font-size: 17px; }
.feuille-tete .lieu { font-size: 14px; color: var(--texte-doux); }
.feuille-choix { display: flex; align-items: center; gap: 14px; min-height: 56px; padding: 0 12px; border: 0; border-radius: 10px; background: none; font-size: 17px; font-weight: 600; color: var(--encre); text-align: left; }
.feuille-choix:hover, .feuille-choix:focus-visible { background: var(--papier2); }
.feuille-choix svg { width: 22px; height: 22px; }
.feuille-choix.ouvrir svg { rotate: 180deg; }
.feuille-choix.danger { color: var(--accent-sombre); }
.feuille-fermer { margin-top: 6px; min-height: 52px; }

.intervention-reprise { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px; background: var(--info-clair); color: #1d3f61; }
.intervention-reprise > div { flex: 1; display: grid; gap: 2px; }
.intervention-reprise strong { color: var(--encre); font-size: 16px; }
.intervention-reprise .bouton { flex: none; min-height: 44px; padding: 6px 12px; font-size: 14px; }

@media (max-width: 940px) {
  .barre-choix { position: fixed; z-index: 30; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); }
  .barre-choix .bouton { min-height: 60px; border-radius: 14px; box-shadow: 0 6px 18px -8px rgba(0, 0, 0, 0.4); }
  .releve-case .releve { padding-right: 56px; }
}

@media (max-width: 940px) {
  body { font-size: 17px; }
  .page { padding: 14px 14px calc(var(--barre-bas) + 24px); }
  .entete { gap: 8px; padding: 6px 10px; padding-top: max(6px, env(safe-area-inset-top)); min-height: 56px; }
  .marque img { height: 32px; }
  .pastille { padding: 6px 10px; font-size: 13px; }
  h1 { font-size: 24px; }
  h2 { font-size: 13px; }

  /* -------------------------------------------------------------- accueil */
  /* « Nouveau relevé » : en bas de l'écran, sous le pouce, quel que soit le défilement. */
  .accueil > .bouton.geant {
    position: fixed; z-index: 30; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom));
    width: auto; min-height: 60px; font-size: 18px; border-radius: 14px;
    box-shadow: 0 10px 24px -8px rgba(236, 27, 36, 0.55), 0 2px 6px rgba(0, 0, 0, 0.18);
  }
  .accueil { gap: 22px; }
  .accueil .recherche { max-width: none; }
  .releve { padding: 14px 16px; border-radius: 12px; }
  .releve h3 { font-size: 17px; }
  .etat { width: 100%; justify-content: space-between; }

  /* -------------------------------------------------------------- « Que relevez-vous ? » */
  .nouveau { gap: 16px; }
  .ref-bloc { padding: 14px; background: var(--papier); border: 1px solid var(--trait); border-radius: 12px; }
  .ref-saisie label { font-size: 16px; }
  .ref-champ { min-height: 56px; font-size: 18px; }
  .ref-ligne .bouton { min-height: 52px; font-size: 17px; }
  .nouveau > .recherche { max-width: none; }
  /* Les domaines : une seule ligne qui défile au doigt, collée sous l'en-tête. */
  .domaines {
    position: sticky; top: 56px; z-index: 6; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
    margin: 0 -14px; padding: 8px 14px; background: var(--papier2); scroll-snap-type: x proximity;
  }
  .domaines::-webkit-scrollbar { display: none; }
  .domaines a { flex: none; min-height: 44px; display: inline-flex; align-items: center; scroll-snap-align: start; }
  .domaine { scroll-margin-top: 124px; }
  /* Deux composants par ligne : l'image et le nom suffisent pour reconnaître la pièce. */
  .choix-types { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .type { padding: 0 12px 12px; gap: 2px; border-radius: 12px; align-content: start; }
  .type img { width: calc(100% + 24px); margin: 0 -12px 8px; aspect-ratio: 4 / 3; }
  .type .sur-titre { font-size: 11px; letter-spacing: 0.04em; }
  .type h3 { font-size: 15.5px; line-height: 1.25; }
  .type p:last-child:not(.sur-titre) { display: none; }

  /* -------------------------------------------------------------- fiche */
  .fiche { gap: 14px; }
  .tete-fiche h1 { font-size: 21px; }
  .colonnes { gap: 14px; }
  .groupe { padding: 16px 14px 18px; border-radius: 12px; }
  .grille-champs { grid-template-columns: 1fr; gap: 16px; }
  .champ label { font-size: 16px; }
  .aide { font-size: 14px; }
  .avec-unite input { font-size: 19px; padding-right: 70px; }
  .avec-unite span { font-size: 15px; font-weight: 600; }
  .photos { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .retirer { width: 44px; height: 44px; }
  .ajouter-photo { min-height: 120px; font-size: 16px; }
  .ajouter-photo svg { width: 34px; height: 34px; }
  .bloc { padding: 12px 14px; border-radius: 12px; }
  .bloc ul { font-size: 15px; gap: 2px; }
  .bloc li .lien { min-height: 40px; padding: 8px 0; }
  .documents { display: grid; grid-template-columns: 1fr 1fr; }
  .documents .bouton { min-height: 52px; font-size: 15px; }
  .documents > :last-child:nth-child(odd) { grid-column: 1 / -1; }
  .transmettre .bouton.principal { width: 100%; min-height: 60px; font-size: 18px; border-radius: 14px; }
  .transmettre { justify-items: stretch; }
  .decision .boutons { display: grid; }
  .decision .bouton { min-height: 56px; }

  /* La vue 3D, collée en haut pendant la saisie. Ses commandes sont de vraies cibles pour le doigt. */
  .carte-3d { top: 56px; border-radius: 0 0 14px 14px; margin: 0 -14px; border-left: 0; border-right: 0; border-top: 0; }
  .vue-3d { height: var(--hauteur-3d); min-height: 0; }
  .barre-vue { top: 8px; left: 8px; right: 8px; }
  .modes-vue, .agrandir { border-radius: 10px; background: rgba(255, 255, 255, 0.96); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12); }
  .modes-vue button, .agrandir { min-height: 44px; font-size: 14px; }
  .modes-vue button { min-width: 48px; padding: 0 12px; }
  .agrandir { padding: 0 12px; }
  .curseur { min-height: 44px; padding: 2px 14px; font-size: 14px; }
  .curseur input[type='range'] { height: 32px; }
  .projections-vue button { min-height: 44px; font-size: 14px; }
  /* La légende tient sur deux lignes pendant la saisie ; en plein écran elle est entière. */
  .legende-3d { padding: 6px 14px 8px; font-size: 13px; line-height: 1.35; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }

  /* Plein écran : toute la hauteur, au-dessus de l'en-tête, pour lire les cotes et tourner la pièce. */
  .carte-3d.agrandie {
    inset: 0; margin: 0; z-index: 60; background: var(--papier);
    padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
  }
  .carte-3d.agrandie .barre-vue { top: calc(10px + env(safe-area-inset-top)); left: 10px; right: 10px; }
  .carte-3d.agrandie .modes-vue button, .carte-3d.agrandie .agrandir { min-height: 50px; font-size: 15px; }
  .carte-3d.agrandie .legende-3d { display: block; font-size: 14px; }
  body:has(.carte-3d.agrandie) { overflow: hidden; }

  .ia-panneau, .ia-bloc, .ref-bloc { scroll-margin-top: calc(var(--hauteur-3d) + 150px); }
  .champ { scroll-margin-top: calc(var(--hauteur-3d) + 150px); }
}

/* Petits téléphones ou clavier ouvert : la vue 3D se fait plus petite pour laisser voir le champ. */
@media (max-width: 940px) and (max-height: 700px) {
  :root { --hauteur-3d: clamp(170px, 30vh, 240px); }
  .curseur { min-height: 40px; }
}
/* Téléphone en paysage : pas de place pour une vue collée, elle défile avec la fiche. */
@media (max-width: 940px) and (max-height: 500px) and (orientation: landscape) {
  .carte-3d:not(.agrandie) { position: relative; top: auto; }
  :root { --hauteur-3d: 70vh; }
  .ia-panneau, .ia-bloc, .ref-bloc, .champ { scroll-margin-top: 70px; }
}

/* Très petits écrans : l'en-tête ne garde que l'essentiel. */
@media (max-width: 380px) {
  .pastille { font-size: 12px; padding: 6px 8px; }
  .modes-vue button { min-width: 44px; padding: 0 9px; }
  .agrandir { padding: 0 10px; }
}
