/**
 * 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); }

.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); }
.fab-icon { font-size: 22px; }

/* ------------------------------------------------------------------ */
/* 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); }

/* ------------------------------------------------------------------ */
/* 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 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;
}

/* 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; }

.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;
}

/* ------------------------------------------------------------------ */
/* 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);
}
.confirm p { margin: 0; font-size: 17px; line-height: 1.45; }

.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 { 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;
}

/* ------------------------------------------------------------------ */
/* 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); }
