/* Feuille de style unique. Mobile d'abord : tout est dimensionne pour un iPhone tenu
   a une main, et l'ecran large n'est qu'un cas particulier traite a la fin.

   Les couleurs passent toutes par des variables. Le theme sombre n'est pas une
   surcouche : c'est le meme jeu de variables avec d'autres valeurs, ce qui evite
   les oublis de contraste. */

:root {
  --fond: #f6f6f8;
  --carte: #ffffff;
  --texte: #1a1a1f;
  --discret: #6a6a76;
  --bord: #e2e2ea;
  --accent: #f0782a;
  --accent-texte: #ffffff;
  --danger: #b3261e;
  --rayon: 14px;
  --ombre: 0 1px 3px rgba(0, 0, 0, .08);
  /* Marges de securite du materiel : encoche en haut, barre de geste en bas. */
  --haut: env(safe-area-inset-top, 0px);
  --bas: env(safe-area-inset-bottom, 0px);
}

[data-theme="sombre"] {
  --fond: #131316;
  --carte: #1e1e23;
  --texte: #f2f2f6;
  --discret: #9b9baa;
  --bord: #303038;
  --accent-texte: #ffffff;
  --danger: #f2b8b5;
  --ombre: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* Empeche Safari de grossir le texte en paysage. */
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(64px + var(--bas));
}

/* --- Entete ------------------------------------------------------------- */

.entete {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + var(--haut)) 16px 10px;
  background: color-mix(in srgb, var(--fond) 85%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--bord);
}

.entete h1 {
  flex: 1;
  margin: 0;
  font-size: 20px;
  font-weight: 650;
  /* Un titre qui passe a la ligne fait sauter la mise en page a chaque changement
     d'ecran. On le tronque plutot que de laisser l'entete respirer. */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Vue ---------------------------------------------------------------- */

.vue { padding: 16px; display: grid; gap: 12px; }

.carte {
  background: var(--carte);
  border: 1px solid var(--bord);
  border-radius: var(--rayon);
  box-shadow: var(--ombre);
  padding: 14px 16px;
}

.carte h2 { margin: 0 0 8px; font-size: 16px; font-weight: 650; }
.discret { color: var(--discret); font-size: 14px; }
.vide { text-align: center; color: var(--discret); padding: 32px 16px; }

.ligne { display: flex; align-items: center; gap: 12px; }
.ligne .titre { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* --- Controles ---------------------------------------------------------- */

/* 44px : c'est la taille minimale d'une cible tactile confortable sur iPhone.
   En dessous, on rate le bouton une fois sur cinq en marchant. */
button, .bouton {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--bord);
  border-radius: 10px;
  background: var(--carte);
  color: var(--texte);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  /* Supprime le surlignage bleu au tap, qui fait "page web" et pas "application". */
  -webkit-tap-highlight-color: transparent;
}

button.principal { background: var(--accent); color: var(--accent-texte); border-color: transparent; }
button.discret { background: none; border-color: transparent; color: var(--discret); }
button.danger { color: var(--danger); }
button:active { opacity: .7; }

button.icone {
  min-width: 44px;
  padding: 0;
  border-color: transparent;
  background: none;
  font-size: 20px;
}
button.icone.tourne { animation: tourner .8s linear infinite; }
@keyframes tourner { to { transform: rotate(360deg); } }

input, textarea, select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--bord);
  border-radius: 10px;
  background: var(--fond);
  color: var(--texte);
  font-family: inherit;
  /* 16px exactement, et jamais moins : en dessous, Safari zoome automatiquement a la
     mise au point et l'utilisateur se retrouve avec une page decalee.
     A ecrire en proprietes separees : `font: 16px/1.4 inherit` est invalide (le
     raccourci n'accepte pas `inherit` comme famille) et le navigateur retombe alors
     sur sa taille par defaut, autour de 13px. */
  font-size: 16px;
  line-height: 1.4;
}
textarea { min-height: 96px; resize: vertical; }

label { display: grid; gap: 6px; font-size: 14px; color: var(--discret); }

.champs { display: grid; gap: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* --- Onglets ------------------------------------------------------------ */

.onglets {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: flex;
  padding-bottom: var(--bas);
  background: color-mix(in srgb, var(--carte) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--bord);
}

.onglets a {
  flex: 1;
  padding: 12px 4px;
  text-align: center;
  text-decoration: none;
  color: var(--discret);
  font-size: 13px;
  font-weight: 550;
  -webkit-tap-highlight-color: transparent;
}
.onglets a.actif { color: var(--accent); }

/* --- Bandeaux ----------------------------------------------------------- */

.maj {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(8px + var(--haut)) 16px 8px;
  background: var(--accent);
  color: var(--accent-texte);
  font-size: 14px;
}
.maj span { flex: 1; }
.maj button { min-height: 36px; background: rgba(255, 255, 255, .18); border-color: transparent; color: inherit; }
/* Quand le bandeau est la, c'est lui qui absorbe l'encoche, plus l'entete. */
.maj:not([hidden]) ~ .entete { padding-top: 10px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + var(--bas));
  transform: translate(-50%, 12px);
  z-index: 20;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: #1a1a1f;
  color: #fff;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

/* ======================================================================== */
/* La carte, ecran Explorer                                                  */
/* ======================================================================== */

/* La carte occupe tout l'espace disponible et la page ne defile pas : c'est elle le
   contenu, pas une illustration posee au-dessus d'une liste. C'est le principal
   reproche fait a la V1, ou la carte etait une vignette.

   Elle est MASQUEE, jamais retiree du document : un conteneur Leaflet detache garde une
   animation de zoom inachevee et devient sourd a setView. */
.carte-hote { display: none; }

body.route-carte {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-bottom: 0;
  overflow: hidden;
}
body.route-carte .vue { display: none; }
body.route-carte .carte-hote {
  display: block;
  flex: 1;
  min-height: 0;
  position: relative;
  /* Les couches internes de Leaflet montent jusqu'a z-index 700 et recouvrent tout ce
     qui se dessine au-dessus de la carte. `isolation` les enferme dans leur propre
     contexte d'empilement : a conserver si la mise en page evolue. */
  isolation: isolate;
}
body.route-carte .onglets { position: relative; }

.carte-conteneur { height: 100%; width: 100%; background: var(--bord); }

.bandeau-hors-ligne {
  margin: 0;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--carte);
  color: var(--discret);
  font-size: 12px;
}

/* Les commandes flottent sur la carte plutot que de lui prendre de la place. */
.carte-commandes {
  position: absolute;
  top: 10px; left: 10px; right: 10px;
  z-index: 500;
  display: grid;
  gap: 8px;
  pointer-events: none;
}
.carte-commandes > * { pointer-events: auto; }

.recherche-champ {
  box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
  border-color: transparent;
  background: var(--carte);
}

.categories {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  /* La rangee defile horizontalement sans barre visible : sept categories ne tiennent
     pas sur la largeur d'un iPhone, et les replier les rendrait introuvables. */
  scrollbar-width: none;
}
.categories::-webkit-scrollbar { display: none; }

.categorie {
  flex: none;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .14);
}
.categorie-active { background: var(--accent); color: var(--accent-texte); border-color: transparent; }

.exploration-ligne { display: flex; }
.exploration-etat {
  font-size: 12px;
  color: var(--texte);
  background: color-mix(in srgb, var(--carte) 88%, transparent);
  border-radius: 999px;
  padding: 0 10px;
  line-height: 22px;
}
.exploration-etat:empty { display: none; }

.accueil-vide {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--carte) 92%, transparent);
  color: var(--texte);
  font-size: 13px;
  line-height: 1.4;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .14);
}

/* Le raccourci vers la reserve reste a portee du pouce, en bas, et non dans la grappe
   de commandes du haut : c'est le geste qui fait passer au second temps. */
.badge-reserve {
  position: fixed;
  left: 50%;
  bottom: calc(72px + var(--bas));
  transform: translateX(-50%);
  z-index: 500;
  min-height: 40px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-texte);
  border-color: transparent;
  font-size: 14px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
}

/* --- Reperes ------------------------------------------------------------- */

.pin {
  position: relative;
  width: 34px; height: 34px;
  border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  background: var(--pin-couleur, #94a3b8);
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
  display: grid;
  place-items: center;
}
.pin-symbole { transform: rotate(45deg); font-size: 16px; line-height: 1; }
.pin-attente { border-style: dashed; }
.pin-base { width: 40px; height: 40px; }

.pin-jour {
  position: absolute;
  top: -8px; right: -10px;
  transform: rotate(45deg);
  padding: 0 5px;
  border-radius: 999px;
  background: #fff;
  color: #1a1a1f;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
}

/* Les propositions d'exploration sont volontairement discretes : ce sont des
   suggestions, pas des decisions. */
.poi {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--carte);
  border: 2px solid var(--accent);
  display: grid;
  place-items: center;
  font-size: 13px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
}

.fleche { font-size: 14px; line-height: 1; text-align: center; }

/* ======================================================================== */
/* Feuille du bas                                                            */
/* ======================================================================== */

.feuille-fond {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, .35);
  opacity: 0;
  transition: opacity .18s;
  display: flex;
  align-items: flex-end;
}
.feuille-fond.ouverte { opacity: 1; }

.feuille {
  width: 100%;
  max-height: 82dvh;
  overflow-y: auto;
  padding: 8px 16px calc(20px + var(--bas));
  background: var(--carte);
  border-radius: 18px 18px 0 0;
  transform: translateY(100%);
  transition: transform .2s ease-out;
}
.feuille-fond.ouverte .feuille { transform: translateY(0); }

.feuille-poignee {
  width: 38px; height: 4px;
  margin: 0 auto 10px;
  border-radius: 999px;
  background: var(--bord);
}
.feuille-titre { margin: 0; font-size: 18px; font-weight: 650; }
.feuille-soustitre { margin: 2px 0 0; font-size: 13px; color: var(--discret); }
.feuille-note { margin: 12px 0 0; font-size: 14px; }
.feuille-corps { padding: 4px 0; }
.feuille-actions { display: grid; gap: 8px; margin-top: 16px; }
.feuille-statuts { display: flex; gap: 6px; }
.feuille-statuts .puce-statut { flex: 1; }

/* ======================================================================== */
/* Statuts                                                                   */
/* ======================================================================== */

:root {
  --st-peutetre: #8b5cf6;
  --st-afaire: #d97706;
  --st-confirme: #0d9488;
}
[data-theme="sombre"] {
  --st-peutetre: #a78bfa;
  --st-afaire: #fbbf24;
  --st-confirme: #2dd4bf;
}

button.st-peutetre { background: var(--st-peutetre); color: #fff; border-color: transparent; }
button.st-afaire { background: var(--st-afaire); color: #fff; border-color: transparent; }
button.st-confirme { background: var(--st-confirme); color: #fff; border-color: transparent; }

.statuts { display: flex; gap: 6px; }
.puce-statut {
  min-height: 38px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 13px;
  background: none;
  border: 1px solid var(--bord);
  color: var(--discret);
}
.puce-statut.st-peutetre { background: none; color: var(--st-peutetre); border-color: var(--st-peutetre); }
.puce-statut.st-afaire { background: none; color: var(--st-afaire); border-color: var(--st-afaire); }
.puce-statut.st-confirme { background: none; color: var(--st-confirme); border-color: var(--st-confirme); }
.puce-statut-active.st-peutetre { background: var(--st-peutetre); color: #fff; }
.puce-statut-active.st-afaire { background: var(--st-afaire); color: #fff; }
.puce-statut-active.st-confirme { background: var(--st-confirme); color: #fff; }

/* ======================================================================== */
/* Ecran Programme                                                           */
/* ======================================================================== */

.reserve {
  position: sticky;
  top: calc(52px + var(--haut));
  z-index: 5;
  padding: 10px 12px;
  background: var(--carte);
  border: 1px solid var(--bord);
  border-radius: var(--rayon);
  box-shadow: var(--ombre);
}
.reserve-entete { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.reserve-titre { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .4px; color: var(--discret); }
.reserve-compte {
  min-width: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-texte);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  line-height: 20px;
}
.reserve-vide { margin: 0; font-size: 13px; }

.aide-glisser { margin: -4px 4px 0; font-size: 12px; color: var(--discret); text-align: center; }

.journee {
  background: var(--carte);
  border: 1px solid var(--bord);
  border-left: 4px solid var(--couleur-jour, var(--bord));
  border-radius: var(--rayon);
  box-shadow: var(--ombre);
  padding: 12px 14px;
}
.journee-aujourdhui { border-color: var(--accent); border-left-color: var(--accent); }

.journee-entete { display: flex; align-items: baseline; gap: 8px; }
.journee-num { font-size: 15px; font-weight: 700; color: var(--couleur-jour, var(--texte)); }
.journee-date { flex: 1; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--discret); }
.journee-marque {
  padding: 0 8px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-texte);
  font-size: 11px;
  font-weight: 650;
  line-height: 18px;
}
.journee-meteo { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--discret); }
.journee-meteo .meteo-icone { font-size: 15px; }
.journee-base { margin: 8px 0 0; font-size: 12px; color: var(--discret); }

/* Un champ qui se lit comme du texte tant qu'on n'y touche pas : c'est ce qui permet a
   cet ecran d'etre un programme et non un formulaire. */
.champ-discret {
  min-height: 0;
  padding: 2px 0;
  border: none;
  background: none;
  overflow: hidden;
  resize: none;
}
.champ-discret:focus { outline: none; border-bottom: 1px solid var(--accent); }
.journee-titre { font-size: 17px; font-weight: 600; }
/* 16px et pas moins, meme pour un champ volontairement discret : en dessous, Safari
   zoome a la mise au point et la page se retrouve decalee sans que l'on comprenne
   pourquoi. La discretion passe par la couleur, pas par la taille. */
.journee-note { font-size: 16px; color: var(--discret); }

/* --- Cases et puces ------------------------------------------------------ */

.case {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-height: 34px;
  margin-top: 4px;
  padding: 3px 4px;
  border-radius: 8px;
  border: 1px dashed transparent;
}
.case-label {
  flex: none;
  width: 74px;
  padding-top: 6px;
  font-size: 12px;
  color: var(--discret);
}
.case-puces { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; min-height: 30px; }

/* Les cases vides ne sont montrees que pendant un glissement : quatre moments sur huit
   jours feraient trente-deux lignes vides au repos, alors qu'elles ne servent qu'a
   recevoir un lieu. */
.case-vide { display: none; }
body.cases-visibles .case-vide { display: flex; border-color: var(--bord); }

.puce-lieu {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 34px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--bord);
  border-left: 4px solid var(--couleur-jour, var(--bord));
  background: var(--fond);
  font-size: 14px;
  font-weight: 550;
  max-width: 100%;
  touch-action: manipulation;
}
.puce-icone { font-size: 13px; }
.puce-nom { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 46vw; }
.puce-heure { font-size: 12px; font-weight: 700; color: var(--accent); }

.puce-lieu.st-peutetre { border-style: dashed; color: var(--discret); }
.puce-lieu.st-confirme { border-color: var(--st-confirme); }

/* --- Glissement ---------------------------------------------------------- */

/* Le corps cesse de defiler tant que le doigt tient un element : c'est ce verrou qui
   rend le geste sans ambiguite. */
body.glissement-actif { overflow: hidden; touch-action: none; }
body.glissement-actif * { cursor: grabbing; }

.fantome {
  opacity: .95;
  transform: scale(1.06);
  box-shadow: 0 8px 22px rgba(0, 0, 0, .3);
  transition: none;
}
.en-deplacement { opacity: .3; }

.depot-vise {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border-color: var(--accent) !important;
  border-style: solid;
}

/* ======================================================================== */
/* Ecran A regler                                                            */
/* ======================================================================== */

.carte-resume { display: flex; gap: 8px; text-align: center; }
.resume-bloc { flex: 1; display: grid; gap: 2px; }
.resume-valeur { font-size: 20px; font-weight: 700; }
.resume-label { font-size: 11px; color: var(--discret); line-height: 1.3; }

.ligne-regler {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--bord);
  cursor: pointer;
}
.ligne-regler:first-of-type { border-top: none; }
.ligne-regler-corps { flex: 1; min-width: 0; display: grid; }
.ligne-regler-titre { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ligne-regler-detail { font-size: 12px; color: var(--discret); }

.bouton-mini {
  min-height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 13px;
  flex: none;
}

.taches { margin-top: 12px; display: grid; }
.ligne-tache {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--bord);
  font-size: 15px;
  color: var(--texte);
}
.ligne-tache input[type="checkbox"] { width: 22px; height: 22px; min-height: 22px; flex: none; margin: 0; accent-color: var(--accent); }
.tache-texte { flex: 1; min-width: 0; }
.tache-faite .tache-texte { text-decoration: line-through; color: var(--discret); }
.tache-qui, .tache-echeance { font-size: 12px; color: var(--discret); flex: none; }
.tache-echeance.en-retard { color: var(--danger); font-weight: 650; }

.budget { margin-top: 10px; display: grid; }
.budget-ligne {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-top: 1px solid var(--bord);
  font-size: 14px;
  cursor: pointer;
}
.budget-montant { font-weight: 650; color: var(--discret); }
.budget-confirme { color: var(--st-confirme); }

/* ======================================================================== */
/* Divers                                                                    */
/* ======================================================================== */

.ligne-champs { display: flex; gap: 10px; }
.ligne-champs > * { flex: 1; min-width: 0; }

.case-ligne { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--texte); }
.case-ligne input[type="checkbox"] { width: 22px; height: 22px; min-height: 22px; flex: none; margin: 0; accent-color: var(--accent); }

.volet summary { cursor: pointer; font-weight: 600; font-size: 15px; padding: 4px 0; }
.volet[open] summary { margin-bottom: 12px; }

.qui { display: grid; gap: 8px; }

.personnes { display: grid; margin-bottom: 12px; }
.ligne-personne { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--bord); }
.personne-nom { flex: 1; font-weight: 550; }

.ligne-piste { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; border-top: 1px solid var(--bord); }
.ligne-piste:first-child { border-top: none; }
.ligne-piste input[type="checkbox"] { width: 22px; height: 22px; min-height: 22px; flex: none; margin: 2px 0 0; accent-color: var(--accent); }
.piste-texte { flex: 1; font-size: 15px; }
.piste-faite .piste-texte { text-decoration: line-through; color: var(--discret); }

.gps { display: flex; gap: 14px; margin-top: 10px; }
.gps-lien { font-size: 14px; color: var(--accent); text-decoration: none; font-weight: 550; }

.carte-base { background: color-mix(in srgb, var(--accent) 10%, var(--carte)); }
.carte-base p { margin: 0; font-size: 15px; }

/* L'icone des pistes est un lien, pas un bouton : sans cette regle elle heritait de la
   hauteur du texte (24px) et devenait difficile a viser en marchant. */
.entete .icone {
  text-decoration: none;
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  font-size: 20px;
  -webkit-tap-highlight-color: transparent;
}

/* --- Ecran large -------------------------------------------------------- */

@media (min-width: 760px) {
  .entete, .vue, .onglets { max-width: 720px; margin-inline: auto; }
  .onglets { position: static; border-top: none; border-radius: 0; }
  body { padding-bottom: 24px; }
  body.route-carte .vue { max-width: none; }
  .puce-nom { max-width: 260px; }
}

/* Respecte le reglage systeme d'animations reduites : sur une app qu'on ouvre
   vingt fois par jour, les animations decoratives finissent par lasser. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
