/**
 * app.css — Relevé GPS SIG
 *
 * Principes :
 *   - lisibilité plein soleil : fonds clairs très contrastés, encre quasi
 *     noire, aucune teinte pastel pour le texte ;
 *   - tactile : cibles ≥ 56 px, boutons pleine largeur en bas d'écran,
 *     utilisables d'une seule main ;
 *   - palette sobre : neutres froids + un unique accent « orange signal »
 *     réservé aux actions d'enregistrement ;
 *   - le bandeau instrument (mesures en chiffres tabulaires monospace)
 *     est l'élément signature de l'interface.
 */

/* L'attribut hidden doit toujours l'emporter sur les display des classes
   (.overlay, .fab, .panel…) — sans cette règle, les éléments masqués
   apparaissent au chargement. */
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ */
/* Jetons de design                                                    */
/* ------------------------------------------------------------------ */
:root {
  /* Couleurs */
  --ink: #14181c;            /* encre principale */
  --ink-soft: #4a565e;       /* texte secondaire */
  --paper: #ffffff;          /* fond des panneaux */
  --paper-dim: #f2f4f5;      /* fonds secondaires */
  --line: #ccd4d8;           /* bordures */
  --slate: #182226;          /* bandeau instrument */
  --slate-text: #e8edef;
  --accent: #e8590c;         /* orange signal : enregistrer / valider */
  --accent-ink: #ffffff;
  --ok: #1f8a4c;             /* GPS bon */
  --warn: #c9a227;           /* GPS moyen */
  --bad: #c62828;            /* GPS mauvais / erreurs */

  /* Typographie */
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;

  /* Dimensions */
  --touch: 56px;             /* hauteur minimale d'une cible tactile */
  --radius: 10px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;                 /* la carte occupe tout l'écran */
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--paper-dim);
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; cursor: pointer; }

/* ------------------------------------------------------------------ */
/* Carte                                                               */
/* ------------------------------------------------------------------ */
#map {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: #dfe6e9;
}

/* Boutons de zoom Leaflet agrandis pour le tactile et le plein soleil. */
.leaflet-control-zoom { margin-top: calc(var(--safe-top) + 92px) !important; }
.leaflet-control-zoom a {
  width: 48px !important;
  height: 48px !important;
  line-height: 48px !important;
  font-size: 26px !important;
  color: var(--ink) !important;
}

/* ------------------------------------------------------------------ */
/* Bandeau instrument (signature)                                      */
/* ------------------------------------------------------------------ */
.strip {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 20;
  padding: calc(var(--safe-top) + 8px) 12px 8px;
  background: var(--slate);
  color: var(--slate-text);
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.strip-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

/* Pastille d'état GPS : grise (inactif), verte, jaune ou rouge. */
.gps-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #6c7a83;
  flex: none;
}
.gps-dot.ok   { background: var(--ok);   box-shadow: 0 0 8px var(--ok); }
.gps-dot.warn { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.gps-dot.bad  { background: var(--bad);  box-shadow: 0 0 8px var(--bad); }

/*
 * Relevé rouvert depuis une archive. Le bandeau doit le dire sans
 * ambiguïté : sinon « GPS inactif » se lit comme une panne, alors que
 * c'est le mode qui veut ça.
 */
.strip-archive {
  margin: 0;
  padding: 4px 8px;
  border-left: 3px solid var(--warn);
  background: rgba(201, 162, 39, 0.16);
  border-radius: 4px;
  font-size: 13px;
  line-height: 1.35;
}
.strip-archive strong { letter-spacing: 0.02em; }

.strip-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 0;
}
.strip-metrics dt {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #9fb0b8;
}
.strip-metrics dd {
  margin: 0;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 17px;
  font-weight: 700;
  white-space: nowrap;
}

/* ------------------------------------------------------------------ */
/* Outils carte (droite)                                               */
/* ------------------------------------------------------------------ */
.map-tools {
  position: fixed;
  right: 10px;
  top: calc(var(--safe-top) + 96px);
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.tool {
  width: 52px; height: 52px;
  border-radius: var(--radius);
  border: 2px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
.tool[aria-pressed="true"] {
  background: var(--slate);
  color: var(--slate-text);
  border-color: var(--slate);
}

/* ------------------------------------------------------------------ */
/* Bouton flottant Observation                                         */
/* ------------------------------------------------------------------ */
.fab {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--safe-bottom) + 96px);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--touch);
  padding: 0 22px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 17px;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}
.fab:active { transform: translateX(-50%) scale(0.97); }

/*
 * Armé : le prochain toucher de la carte posera l'observation. L'armement
 * ne dure qu'un toucher — d'où un état visible, pour qu'on sache qu'il est
 * en cours et qu'on puisse le désarmer en repressant le bouton.
 */
.fab[aria-pressed='true'] {
  background: var(--warn);
  color: var(--ink);
  animation: fab-armed 1.4s ease-in-out infinite;
}
@keyframes fab-armed {
  0%, 100% { box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35); }
  50%      { box-shadow: 0 4px 20px rgba(201, 162, 39, 0.85); }
}
@media (prefers-reduced-motion: reduce) {
  .fab[aria-pressed='true'] { animation: none; }
}
.fab-icon { font-size: 22px; }

/* Saisie libre : la note d'observation. Assez haute pour qu'on voie ce
   qu'on écrit, assez basse pour ne pas chasser les boutons de l'écran. */
.field-notes {
  width: 100%;
  min-height: 76px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;               /* < 16 px ferait zoomer iOS à la mise au point. */
  line-height: 1.35;
  resize: vertical;
}
.field-counter {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------ */
/* Barre de contrôle                                                   */
/* ------------------------------------------------------------------ */
.controls {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: flex;
  gap: 10px;
  padding: 10px 12px calc(var(--safe-bottom) + 10px);
  background: var(--paper);
  border-top: 2px solid var(--line);
}

.btn {
  flex: 1;
  min-height: var(--touch);
  padding: 0 14px;
  border-radius: var(--radius);
  border: 2px solid transparent;
  font-size: 17px;
  font-weight: 700;
}
.btn:active { transform: scale(0.98); }

.btn-primary   { background: var(--slate); color: var(--slate-text); }
.btn-record    { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--paper); color: var(--ink); border-color: var(--line); }
.btn-finish    { background: var(--paper); color: var(--accent); border-color: var(--accent); }
.btn-danger    { background: var(--bad); color: #fff; }

/* ------------------------------------------------------------------ */
/* Panneaux (Paramètres, Formulaire)                                   */
/* ------------------------------------------------------------------ */
.panel {
  position: fixed;
  inset: 0;
  z-index: 30;
  overflow-y: auto;
  padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 16px);
  background: var(--paper);
}
.panel h2 {
  margin: 0 0 16px;
  font-size: 22px;
}

.field { display: block; margin-bottom: 18px; border: none; padding: 0; }
.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
}
.field-hint { display: block; margin-top: 4px; font-size: 13px; color: var(--ink-soft); }

.field input[type="number"],
.field input[type="password"],
.field select {
  width: 100%;
  min-height: var(--touch);
  padding: 0 12px;
  font-size: 18px;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: var(--radius);
}
.field input:focus-visible,
.field select:focus-visible,
.btn:focus-visible,
.tool:focus-visible,
.fab:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Case à cocher unique, présentée comme une grosse case tactile : la
   cible est toute la ligne, pas le carré de 13 px du navigateur. */
.field-check {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--touch);
  padding: 0 12px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
}
.field-check input[type="checkbox"] {
  flex: none;
  width: 28px;
  height: 28px;
  margin: 0;
  accent-color: var(--accent);
}
.field-check .field-label { margin: 0; }
.field-check:has(input:checked) { border-color: var(--accent); }

/* Dictée (observation Audio, note des formulaires) : deux boutons côte à
   côte, le champ texte en dessous. */
.form-audio-actions { display: flex; gap: 10px; margin-top: 8px; }
.form-audio-actions .btn { flex: 1; }
#form-dictation .field-notes,
#parcel-dictation .field-notes,
#building-dictation .field-notes { margin-top: 8px; }

/* Boutons radio « à plat » : grosses cases tactiles. */
.radio-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}
.radio-row-wide { grid-template-columns: repeat(2, 1fr); }
.radio-row label {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  font-size: 18px;
  font-weight: 700;
  background: var(--paper);
}
.radio-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.radio-row input:checked + span { color: var(--accent-ink); }
.radio-row label:has(input:checked) {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.radio-row input:focus-visible ~ span { outline: 3px solid var(--accent); outline-offset: 6px; }

/* Menu de choix du type d'observation : grandes cibles empilées, chacune
   avec son pictogramme, son libellé et sa phrase d'explication. */
.type-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.type-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 76px;
  padding: 12px 16px;
  text-align: left;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
}
.type-btn:active { transform: scale(0.99); }
.type-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.type-icon { flex: none; font-size: 28px; line-height: 1; }
.type-text { display: flex; flex-direction: column; gap: 3px; }
.type-label { font-size: 18px; font-weight: 700; }
.type-hint { font-size: 13px; color: var(--ink-soft); }

.form-photo {
  display: block;
  width: 100%;
  max-height: 34vh;
  object-fit: contain;
  margin-bottom: 16px;
  border-radius: var(--radius);
  background: var(--paper-dim);
}

.panel-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

/* Zone de maintenance : nettement détachée du reste des Paramètres, pour
   qu'on n'y touche pas par inadvertance en réglant la fréquence GPS. */
.danger-zone {
  margin-top: 32px;
  padding: 16px;
  border: 2px solid var(--bad);
  border-radius: var(--radius);
  background: #fff6f6;
}
.danger-zone h3 {
  margin: 0 0 8px;
  font-size: 16px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--bad);
}
.danger-zone .field { margin-top: 16px; margin-bottom: 0; }
.danger-zone .panel-actions { margin-top: 16px; }

/* ------------------------------------------------------------------ */
/* Confirmation et messages                                            */
/* ------------------------------------------------------------------ */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(20, 24, 28, 0.55);
}
.confirm {
  width: 100%;
  max-width: 420px;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}
/* `pre-line` rend les sauts de ligne du message : la boîte est remplie
   par textContent — jamais innerHTML — donc c'est au CSS de les honorer. */
.confirm p {
  margin: 0;
  font-size: 17px;
  line-height: 1.45;
  white-space: pre-line;
}

.toasts {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(var(--safe-bottom) + 170px);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--slate);
  color: var(--slate-text);
  font-size: 15px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  animation: toast-in 0.2s ease-out;
}
.toast.error { background: var(--bad); color: #fff; }
.toast.success { background: var(--ok); color: #fff; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
  .btn:active, .fab:active, .type-btn:active { transform: none; }
}

/* Écrans plus larges : la barre de contrôle ne s'étire pas à l'infini. */
@media (min-width: 700px) {
  .controls { justify-content: center; }
  .btn { max-width: 260px; }
  .panel { max-width: 560px; left: 50%; transform: translateX(-50%); }
}

/* ------------------------------------------------------------------ */
/* Mode parcelles                                                      */
/* ------------------------------------------------------------------ */

/* Numéro de la parcelle sélectionnée, mis en évidence. */
.parcel-label {
  margin: 0;
  font: 700 26px/1.2 ui-monospace, "Cascadia Mono", "Roboto Mono", monospace;
  color: var(--accent, #e8590c);
  letter-spacing: 0.02em;
}

/* Attributs relevés sur la parcelle : numéro officiel et surface. Deux
   lignes libellé/valeur, lisibles d'un coup d'œil en plein soleil. */
.parcel-facts {
  /* Marge basse : le bloc qui suit (autorité compétente) doit respirer
     par rapport à la dernière ligne filetée. */
  margin: 14px 0 22px;
  display: grid;
  gap: 10px;
}

.parcel-facts div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
}

.parcel-facts dt {
  font-size: 14px;
  color: var(--ink-soft, #666);
}

.parcel-facts dd {
  margin: 0;
  font: 600 16px/1.3 ui-monospace, "Cascadia Mono", "Roboto Mono", monospace;
  text-align: right;
  /* Un identifiant cadastral peut être long : il se coupe plutôt que de
     déborder du panneau. */
  overflow-wrap: anywhere;
}

/* Bouton de recherche du contact : posé dans le flux du champ, pas dans
   une barre d'actions. */
.btn-inline {
  align-self: flex-start;
  margin: 4px 0;
  padding: 8px 14px;
  font-size: 15px;
}

/* ------------------------------------------------------------------ */
/* Pastille de disponibilité des outils cartographiques                */
/* ------------------------------------------------------------------ */

/* Un point en haut à droite de l'outil indique si le zoom courant est
   suffisant pour que la couche se charge : vert = prête, rouge = zoom
   insuffisant. Le liseré blanc garantit le contraste sur les deux
   fonds du bouton (clair au repos, ardoise quand la couche est active). */
.tool { position: relative; }

.tool[data-ready]::after {
  content: '';
  position: absolute;
  top: 5px;
  right: 5px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  background: var(--bad);
}

.tool[data-ready="true"]::after { background: var(--ok); }

/* ------------------------------------------------------------------ */
/* Enregistrement sonore                                               */
/* ------------------------------------------------------------------ */

/* Le chronomètre est l'information centrale du panneau : gros, tabulaire
   pour que les chiffres ne dansent pas d'une seconde à l'autre, et lisible
   à bout de bras pendant qu'on parle. */
.audio-timer {
  margin: 8px 0 4px;
  font-size: 48px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--ink);
}

.audio-controls { display: flex; margin: 16px 0; }

/* Bouton unique — enregistrer, arrêter, refaire —, haut et pleine largeur :
   c'est celui qu'on cherche du pouce sans regarder. */
.btn-audio-toggle { min-height: 64px; font-size: 19px; }

.audio-preview {
  display: block;
  width: 100%;
  margin-top: 12px;
}

/* Un bouton de validation grisé dit mieux qu'un message qu'il n'y a encore
   rien à enregistrer. */
.panel-actions .btn:disabled {
  opacity: 0.45;
  pointer-events: none;
}
