/*
 * La facturation d'un projet et la formule d'un client (API.md de la facturation, section 10) :
 * les composants web/facturation/payeur.js (la question d'un projet, posee dans les
 * formulaires de creation, web/suivi/creer.js et « Créer un projet » de l'agenda dans
 * web/suivi/ensemble.js, le bloc de la fiche projet et la section « Facturation à faire ») et
 * web/facturation/formule.js (le formulaire de la formule : dans la question, sur la fiche
 * client, dans « Facturation à faire »), et la section de web/facturation/tournages.js.
 *
 * Prefixes py- (la question, et ce que la formule partage avec elle) et fo- (la formule) ;
 * les lignes, boutons, etiquettes et nombres sont ceux du socle (web/suivi/socle.css : p-ligne,
 * p-btn, p-prim, p-tag, p-nombre, p-pastille, p-fi-err). Seulement les variables du theme
 * (commun/style.css) et du socle : jamais de rouge ni d'orange (tests/couleurs-refonte.test.js),
 * la priorite au contraste, le vert pour le choix coche et le geste principal ; une erreur est
 * un texte clair et gras, un filet a gauche.
 *
 * Les composants s'habillent eux-memes : ils vivent dans un .p-fi (l'agenda), un .c-form (le
 * bouton « + ») ou un .f-bloc (les fiches), qui ont chacun leurs regles de label et de champ.
 * Leurs regles portent deux classes (ou une classe et :is()) : elles passent devant celles-la,
 * et ce fichier est lie apres elles dans index.html.
 *
 * Telephone (700 px et moins) : chaque choix fait 44 px de haut, les champs aussi (16 px de
 * texte : l'iPhone n'agrandit pas la page au focus) ; aucun defilement horizontal a 375 px :
 * rien n'a de largeur fixe, tout passe a la ligne.
 *
 * Classes :
 *   .py-payeur                      la question : .py-question, .py-sa-formule (la formule du
 *                                   client), .py-options > .py-option (un choix, et son champ
 *                                   dans .py-detail), .py-choix (un bouton radio et son texte
 *                                   .py-choix-texte), .py-champ, .py-deux, .py-note, .py-err,
 *                                   .py-bas, .py-attente, .py-discret, .py-sous-formule (la
 *                                   formule, ouverte a la place de « Choisir sa formule »)
 *   .fo-formule                     la formule : .fo-titre, .fo-formules (les quatre formules,
 *                                   des .py-choix.fo-choix : .fo-nom, son nom et ses
 *                                   etiquettes, .fo-raison), .fo-sortes,
 *                                   .fo-sous-titre, .fo-liste > .fo-ligne > .fo-ligne-texte
 *                                   (un pack, un projet), .fo-suit, .fo-choix-projet ; et les
 *                                   classes de la question (.py-choix, .py-champ, .py-deux,
 *                                   .py-note, .py-err, .py-bas)
 *   .py-paye                        « Facturation : » (fiche projet), « Formule : » (fiche
 *                                   client) : .py-paye-haut, .py-paye-texte, .py-zone (la
 *                                   question ou la formule, ouverte dessous)
 *   .py-section                     « Facturation à faire » : .py-section-titre, .py-aide,
 *                                   .py-groupe > .py-groupe-titre ; dans une ligne du socle,
 *                                   .py-raison, .py-montant, .py-etat, .py-petit, .py-gestes,
 *                                   a.py-btn-lien, .py-sous (le choix ouvert dessous) ;
 *                                   .py-factures (le choix de la facture, comme .py-payeur)
 */

/* ---------- la question, la formule ---------- */

.py-payeur, .py-factures, .fo-formule {
  display: flex; flex-direction: column; gap: 9px; min-width: 0; margin: 0;
  padding: 11px; border: 1px solid var(--bord-haut); border-radius: 9px;
  background: var(--fond); overflow-wrap: anywhere;
}
/* Dans un formulaire de creation (l'agenda, le bouton « + »), la question en fait partie :
   pas de second cadre (la largeur compte sur telephone), un filet au-dessus. La formule
   ouverte dans la question n'a pas de cadre non plus. */
:is(.p-fi, .c-form) .py-payeur {
  padding: 10px 0 0; border: 0; border-top: 1px solid var(--bord-haut); border-radius: 0;
  background: none;
}
.py-payeur .fo-formule { padding: 0; border: 0; border-radius: 0; background: none; }
.py-question, .fo-titre { margin: 0; color: var(--texte); font-size: 13.5px; font-weight: 650; line-height: 1.35; }
.py-sa-formule { margin: 0; color: var(--doux); font-size: 12.5px; }
.py-sa-formule b { color: var(--texte); font-weight: 600; }
.py-options { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.py-option { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.py-liste { display: flex; flex-direction: column; gap: 6px; min-width: 0; }

/* Un bouton radio et son texte, sur toute la largeur : 44 px de haut, le coche en vert.
   Deux classes : passe devant les label de .p-fi (socle) et de commun/style.css. */
:is(.py-payeur, .py-factures, .fo-formule) .py-choix {
  display: flex; flex-direction: row; align-items: center; gap: 9px;
  min-width: 0; min-height: 44px; margin: 0; padding: 6px 10px;
  border: 1px solid var(--bord-haut); border-radius: 8px; background: var(--carte);
  color: var(--texte); font-size: 13.5px; line-height: 1.35; cursor: pointer;
}
:is(.py-payeur, .py-factures, .fo-formule) .py-choix:has(input:checked) { border-color: var(--accent); background: var(--p-accent-voile); }
:is(.py-payeur, .py-factures, .fo-formule) .py-choix:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }
/* Un pack plein : grise, il ne se choisit pas. */
:is(.py-payeur, .py-factures, .fo-formule) .py-choix:has(input:disabled) { color: var(--doux); cursor: not-allowed; opacity: .7; }
:is(.py-payeur, .py-factures, .fo-formule) .py-choix[hidden] { display: none; }
:is(.py-payeur, .py-factures, .fo-formule) .py-choix input[type="radio"] {
  flex: 0 0 auto; width: 18px; height: 18px; margin: 0; accent-color: var(--accent);
}
.py-choix-texte { display: flex; flex-direction: column; gap: 1px; flex: 1 1 auto; min-width: 0; }
.py-choix-texte b { font-weight: 650; }
.py-choix-texte small { color: var(--doux); font-size: 12px; line-height: 1.35; font-variant-numeric: tabular-nums; }
.py-choix .p-tag { flex: 0 0 auto; }

/* Le champ d'un choix, sous lui, aligne sur son texte (apres le bouton radio). */
.py-detail { display: flex; flex-direction: column; gap: 8px; min-width: 0; padding: 0 0 4px 12px; margin-left: 9px; border-left: 2px solid var(--bord-haut); }
.py-detail[hidden] { display: none; }
.py-deux { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); gap: 8px; }
.py-deux > * { min-width: 0; }

:is(.py-payeur, .py-factures, .fo-formule) .py-champ {
  display: flex; flex-direction: column; gap: 4px; min-width: 0; margin: 0;
  color: var(--doux); font-size: 12.5px;
}
/* :is() porte la specificite de son argument le plus fort : ces regles passent devant celles
   du socle (.p-fi), des fiches (.f-form), de la coquille (.c-form) et de commun/style.css. */
:is(.py-payeur, .py-factures, .fo-formule) :is(input:not([type="radio"]):not([type="checkbox"]), select) {
  width: 100%; min-width: 0; min-height: 38px; margin: 0; padding: 8px 10px;
  border: 1px solid var(--bord-haut); border-radius: 7px;
  background: var(--fond); color: var(--texte);
  font: inherit; font-size: 14px; line-height: 1.3;
}
:is(.py-payeur, .py-factures) input[type="search"] { -webkit-appearance: none; appearance: none; }
:is(.py-payeur, .py-factures, .fo-formule) :is(input, select):focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Les devis d'un pack, par groupe : de ce client, probablement ce client, les autres. */
.py-groupe-devis { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.py-groupe-devis[hidden] { display: none; }
.py-sous-titre, .fo-sous-titre { margin: 2px 0 0; color: var(--doux); font-size: 12px; font-weight: 600; }

.py-note, .py-compte { margin: 0; color: var(--doux); font-size: 12.5px; }
.py-compte[hidden] { display: none; }
.py-attente, .py-discret { margin: 0; color: var(--doux); font-size: 12.5px; }

/* L'erreur (la notre ou celle du serveur) : texte clair et gras, un filet a gauche. */
.py-err {
  margin: 0; padding-left: 8px; border-left: 2px solid var(--alerte);
  color: var(--alerte-texte); font-size: 12.5px; font-weight: 600; overflow-wrap: anywhere;
}
.py-err[hidden], .py-err:empty { display: none; }
.py-bas { display: flex; flex-wrap: wrap; gap: 6px; }
.py-bas[hidden] { display: none; }
.py-sous-formule { min-width: 0; }
.py-sous-formule:empty { display: none; }

/* ---------- la formule ---------- */

/* Les quatre formules : deux par rangee sur ordinateur, une sur telephone. */
.fo-formules { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); gap: 6px; }
.fo-formules > * { min-width: 0; }
.fo-nom { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; min-width: 0; }
.fo-choix .fo-raison { color: var(--texte); }
.fo-sortes { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
/* Un pack, un projet : son texte, et ce qu'il suit (ou son choix) a droite, dessous sur telephone. */
.fo-liste { display: flex; flex-direction: column; gap: 6px; min-width: 0; margin: 0; padding: 0; list-style: none; }
.fo-ligne {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; min-width: 0;
  padding: 7px 10px; border: 1px solid var(--bord-haut); border-radius: 8px; background: var(--carte);
}
.fo-ligne-texte { display: flex; flex-direction: column; gap: 1px; flex: 1 1 14em; min-width: 0; font-size: 13.5px; }
.fo-ligne-texte b { font-weight: 650; }
.fo-ligne-texte small, .fo-suit { color: var(--doux); font-size: 12px; line-height: 1.35; font-variant-numeric: tabular-nums; }
.fo-suit { flex: 0 1 auto; }
.fo-formule .fo-choix-projet { flex: 1 1 14em; }

/* ---------- « Facturation : » et « Formule : » sur les fiches ---------- */

.py-paye { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.py-paye-haut { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; min-width: 0; }
.py-paye-texte { flex: 1 1 14em; min-width: 0; margin: 0; font-size: 14px; overflow-wrap: anywhere; }
.py-paye-texte b { font-weight: 650; }
.py-paye-texte small { display: block; color: var(--doux); font-size: 12.5px; }
.py-zone { min-width: 0; }
.py-zone:empty { display: none; }

/* ---------- « Facturation à faire » ---------- */

.py-section { display: flex; flex-direction: column; gap: 10px; min-width: 0; margin-top: 22px; overflow-wrap: anywhere; }
/* Deux classes : passe devant le h3 de commun/style.css. Il ne prend le focus que par le
   code (apres une ecriture) : pas de cadre. */
.py-section .py-section-titre {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0;
  color: var(--doux); font-size: 12px; font-weight: 600; line-height: 1.4;
  text-transform: uppercase; letter-spacing: .09em;
}
.py-section .py-section-titre:focus { outline: none; }
.py-groupe { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.py-groupe + .py-groupe { margin-top: 6px; }
.py-section .py-groupe-titre {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0;
  color: var(--texte); font-size: 13px; font-weight: 650; line-height: 1.4;
  text-transform: none; letter-spacing: 0;
}
.py-aide { margin: 0; max-width: 80ch; color: var(--doux); font-size: 13px; }

/* Dans une ligne du socle : la raison, le montant a droite, l'etat, les gestes. */
.py-raison { margin: 0; color: var(--texte); font-size: 13px; overflow-wrap: anywhere; }
.py-montant {
  display: flex; flex-direction: column; align-items: flex-end; flex: 0 0 auto;
  margin: 0; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.py-montant b { font-size: 15px; font-weight: 700; line-height: 1.3; }
.py-montant small { color: var(--doux); font-size: 11.5px; line-height: 1.3; }
.py-etat { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; min-width: 0; }
.py-petit { color: var(--doux); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.py-gestes { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; }
/* « Voir le pack » : un lien habille comme les boutons voisins. */
a.py-btn-lien { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
a.py-btn-lien:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.py-sous { min-width: 0; }
.py-sous:empty { display: none; }

/* ---------- telephone ---------- */

@media (max-width: 700px) {
  .py-deux, .fo-formules { grid-template-columns: 1fr; }
  /* 16 px : sous cette taille, l'iPhone agrandit la page quand le champ prend le focus. */
  :is(.py-payeur, .py-factures, .fo-formule) :is(input:not([type="radio"]):not([type="checkbox"]), select) { font-size: 16px; }
  .py-detail { padding-left: 10px; margin-left: 4px; }
  .fo-formule .fo-choix-projet { flex-basis: 100%; }
}

/* Au doigt, une cible de moins de 44 px se rate : champs et liens-boutons (les choix y sont deja). */
@media (max-width: 700px), (pointer: coarse) {
  :is(.py-payeur, .py-factures, .fo-formule) :is(input:not([type="radio"]):not([type="checkbox"]), select) { min-height: 44px; }
  a.py-btn-lien { min-height: 44px; }
}
