/*
 * Cadychat - feuille de style.
 *
 * Contraintes du cahier des charges prises au mot :
 *  - utilisable au pouce sur un telephone d'entree de gamme : cibles de
 *    44 px minimum ;
 *  - la navigation est EN HAUT sur un telephone et A GAUCHE sur un ecran
 *    large, jamais en bas : demande du maitre d'ouvrage, 2 novembre 2026 ;
 *  - textes simples, contrastes lisibles en plein soleil ;
 *  - aucune police distante, aucune image lourde : la page doit s'afficher
 *    en moins de 3 secondes sur une connexion 3G.
 */

:root {
  --vert: #0f766e;
  --vert-clair: #e6f4f1;
  --vert-fonce: #0b574f;
  --encre: #17191c;
  --encre-douce: #5b6168;
  --ligne: #e3e6e8;
  --fond: #f6f7f9;
  --blanc: #ffffff;
  --rouge: #b42318;
  --rouge-clair: #fdeaea;
  --orange: #9a5b00;
  --orange-clair: #fff4e5;
  --vert-ok: #17803d;
  --vert-ok-clair: #e7f6ec;
  --rayon: 14px;
  --ombre: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
  --barre-laterale: 236px;
  --hauteur-onglets: 52px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--encre);
  background: var(--fond);
  -webkit-text-size-adjust: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------------- Ecran de connexion ---------------- */

.ecran.plein {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.carte-centrale {
  background: var(--blanc);
  border-radius: var(--rayon);
  box-shadow: var(--ombre);
  padding: 28px 22px;
  width: 100%;
  max-width: 380px;
}

.logo {
  font-size: 30px;
  font-weight: 700;
  color: var(--vert);
  letter-spacing: -0.5px;
}

.sous-titre { color: var(--encre-douce); margin: 2px 0 24px; }

.forme { display: grid; gap: 6px; }
.forme label { font-size: 14px; font-weight: 600; margin-top: 10px; }

/* Une ligne de champs qui tient sur un telephone : elle passe a la ligne
   plutot que de deborder. */
.ligne-champs { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.ligne-champs label { font-size: 14px; font-weight: 600; display: grid; gap: 4px; flex: 1 1 180px; }

/* « input:not([type]) » n'est pas une coquetterie : un <input> sans
   attribut type EST un champ texte, mais il ne correspond a aucun des
   selecteurs ci-dessous. Sans cette ligne, dix-neuf champs de
   l'application — dont le nom de l'article — tombaient au style par
   defaut du navigateur : 29 px de haut, sans bordure, mal visibles et
   difficiles a viser sur un telephone. */
input:not([type]),
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="tel"], input[type="date"], select, textarea {
  width: 100%;
  min-height: 48px;
  padding: 11px 13px;
  border: 1.5px solid var(--ligne);
  border-radius: 10px;
  background: var(--blanc);
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--vert);
  outline-offset: 1px;
  border-color: var(--vert);
}

.secret {
  font-family: ui-monospace, monospace;
  font-size: 15px;
  letter-spacing: 1px;
  background: var(--vert-clair);
  color: var(--vert-fonce);
  padding: 12px;
  border-radius: 10px;
  word-break: break-all;
  margin: 8px 0;
}

/* ---------------- Boutons ---------------- */

.bouton {
  min-height: 48px;
  min-width: 48px;
  padding: 0 18px;
  border: 1.5px solid var(--ligne);
  border-radius: 10px;
  background: var(--blanc);
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.bouton:active { transform: translateY(1px); }
.bouton.principal { background: var(--vert); border-color: var(--vert); color: var(--blanc); }
.bouton.principal:active { background: var(--vert-fonce); }
.bouton.danger { background: var(--rouge); border-color: var(--rouge); color: var(--blanc); }
.bouton.grand { width: 100%; margin-top: 18px; }
.bouton.petit { min-height: 38px; padding: 0 12px; font-size: 14px; }
.bouton.icone { border: none; background: transparent; font-size: 22px; }
.bouton:disabled { opacity: 0.5; }

/* ---------------- Structure ---------------- */

/*
 * La navigation n'est jamais en bas de l'ecran.
 *
 * Sur un telephone, la barre reunit l'entete et les onglets, et reste
 * collee en haut. Sur un ecran large, la meme barre devient une colonne a
 * gauche, sur toute la hauteur, et le contenu se place a cote. Une seule
 * structure, deux presentations : rien a dupliquer dans le HTML.
 */

.cadre { min-height: 100vh; }

.rail {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--vert);
}

.entete {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: var(--vert);
  color: var(--blanc);
  padding-top: max(10px, env(safe-area-inset-top));
}

.entete-titre { font-weight: 700; display: flex; align-items: center; gap: 8px; min-width: 0; }
.entete-titre > span:first-child {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.entete .bouton.icone { color: var(--blanc); }

.contenu {
  padding: 14px 14px 32px;
  max-width: 760px;
  margin: 0 auto;
}

.navigation {
  display: flex;
  gap: 2px;
  background: var(--vert-fonce);
  overflow-x: auto;
  scrollbar-width: none;
  padding: 0 6px;
}
.navigation::-webkit-scrollbar { display: none; }

.onglet {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 0 12px;
  min-height: var(--hauteur-onglets);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: rgba(255, 255, 255, 0.72);
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
}

.onglet .pictogramme { font-size: 17px; line-height: 1; }
.onglet .libelle { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.onglet.actif { color: var(--blanc); border-bottom-color: var(--blanc); }

.pastille {
  background: var(--rouge);
  color: var(--blanc);
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  padding: 0 5px;
}

/* Tres petit ecran : le mot compte plus que le pictogramme. */
@media (max-width: 420px) {
  .onglet { padding: 0 4px; gap: 0; }
  .onglet .pictogramme { display: none; }
  .onglet .libelle { font-size: 12.5px; }
}

/* Ecran large : la meme barre devient une colonne a gauche. */
@media (min-width: 900px) {
  .cadre {
    display: grid;
    grid-template-columns: var(--barre-laterale) 1fr;
    align-items: start;
  }
  .rail {
    height: 100vh;
    display: flex;
    flex-direction: column;
  }
  .entete { padding: 16px 16px 14px; }
  .navigation {
    flex-direction: column;
    padding: 8px;
    background: transparent;
    overflow: visible;
  }
  .onglet {
    flex: 0 0 auto;
    justify-content: flex-start;
    min-height: 46px;
    border-radius: 10px;
    border-bottom: none;
  }
  .onglet.actif { background: rgba(255, 255, 255, 0.16); border-bottom: none; }
  .onglet .pastille { margin-left: auto; }
  .contenu { padding: 22px 26px 48px; max-width: 920px; margin: 0; }
  .banniere { margin: 0; border-radius: 0; }
}

/* ---------------- Cartes et listes ---------------- */

.carte {
  background: var(--blanc);
  border-radius: var(--rayon);
  box-shadow: var(--ombre);
  padding: 14px;
  margin-bottom: 12px;
}

.carte h2 { font-size: 15px; margin: 0 0 10px; }
.carte h3 { font-size: 14px; margin: 14px 0 6px; color: var(--encre-douce); }

.grille-chiffres { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.chiffre {
  background: var(--blanc);
  border-radius: var(--rayon);
  box-shadow: var(--ombre);
  padding: 13px;
}

.chiffre .valeur { font-size: 21px; font-weight: 700; letter-spacing: -0.4px; }
.chiffre .etiquette { font-size: 12px; color: var(--encre-douce); }
.chiffre .detail { font-size: 12px; color: var(--encre-douce); margin-top: 3px; }
.chiffre.alerte .valeur { color: var(--rouge); }
/* Le reste a payer d un acompte. Le commercant doit le voir avant de
   remettre sa marchandise : c est la seule protection utile, puisque la
   plateforme ne lui interdit pas de livrer. */
.tableau tr.alerte th,
.tableau tr.alerte td { color: var(--rouge); }
.chiffre.bien .valeur { color: var(--vert-ok); }

.liste { list-style: none; margin: 0; padding: 0; }

.liste li {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--ligne);
}

.liste li:last-child { border-bottom: none; }
.liste .corps { flex: 1; min-width: 0; }
.liste .titre { font-weight: 600; }

.liste .note {
  font-size: 13px;
  color: var(--encre-douce);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.liste .droite { text-align: right; font-size: 13px; white-space: nowrap; }

.ligne-cliquable { cursor: pointer; }
.ligne-cliquable:active { background: var(--fond); }

/* ---------------- Badges et etats ---------------- */

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--fond);
  color: var(--encre-douce);
  white-space: nowrap;
}

.badge.test { background: var(--orange-clair); color: var(--orange); }
.badge.ok { background: var(--vert-ok-clair); color: var(--vert-ok); }
.badge.attention { background: var(--orange-clair); color: var(--orange); }
.badge.mauvais { background: var(--rouge-clair); color: var(--rouge); }
.badge.assistant { background: var(--vert-clair); color: var(--vert-fonce); }

.banniere {
  padding: 11px 14px;
  background: var(--orange-clair);
  color: var(--orange);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}

.banniere.mauvais { background: var(--rouge-clair); color: var(--rouge); }
.banniere.ok { background: var(--vert-ok-clair); color: var(--vert-ok); }

.erreur {
  background: var(--rouge-clair);
  color: var(--rouge);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  margin-top: 12px;
}

.info { color: var(--encre-douce); font-size: 14px; margin: 4px 0 0; }
.info.petit { font-size: 13px; }
.attente { text-align: center; color: var(--encre-douce); padding: 40px 0; }
.vide { text-align: center; color: var(--encre-douce); padding: 28px 10px; }

/* ---------------- Conversation ---------------- */

.fil { display: grid; gap: 8px; margin-bottom: 14px; }

.bulle {
  max-width: 85%;
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 15px;
  white-space: pre-wrap;
  word-break: break-word;
}

.bulle.entrant { background: var(--blanc); box-shadow: var(--ombre); justify-self: start; }
.bulle.sortant { background: var(--vert-clair); justify-self: end; }
.bulle .auteur { font-size: 11px; font-weight: 700; color: var(--encre-douce); display: block; }
.bulle .heure { font-size: 11px; color: var(--encre-douce); display: block; text-align: right; }

.zone-reponse { display: grid; gap: 8px; }
.zone-reponse textarea { min-height: 76px; resize: vertical; }

/* ---------------- Feuille coulissante ---------------- */

.feuille { position: fixed; inset: 0; z-index: 50; }
.feuille-fond { position: absolute; inset: 0; background: rgba(16, 24, 40, 0.45); }

.feuille-corps {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--blanc);
  border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(24px + env(safe-area-inset-bottom));
}

.feuille-fermer {
  position: absolute;
  top: 10px;
  right: 10px;
  border: none;
  background: var(--fond);
  width: 38px;
  height: 38px;
  border-radius: 19px;
  font-size: 16px;
  cursor: pointer;
}

.feuille-corps h2 { margin: 0 32px 14px 0; font-size: 18px; }

/* ---------------- Messages eclair ---------------- */

.messages-eclair {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--barre-basse) + 14px);
  z-index: 60;
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.eclair {
  background: var(--encre);
  color: var(--blanc);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: var(--ombre);
}

.eclair.mauvais { background: var(--rouge); }
.eclair.ok { background: var(--vert-ok); }

/* ---------------- Tableaux et details ---------------- */

.tableau { width: 100%; border-collapse: collapse; font-size: 13px; }
.tableau th, .tableau td { padding: 8px 6px; text-align: left; border-bottom: 1px solid var(--ligne); }
.tableau th { color: var(--encre-douce); font-weight: 600; }
.nombre { text-align: right; font-variant-numeric: tabular-nums; }

.barre { height: 7px; background: var(--ligne); border-radius: 4px; overflow: hidden; margin-top: 5px; }
.barre > span { display: block; height: 100%; background: var(--vert); }
.barre.attention > span { background: var(--orange); }
.barre.mauvais > span { background: var(--rouge); }

.recu {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  background: var(--fond);
  padding: 12px;
  border-radius: 10px;
  line-height: 1.6;
}

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.actions .bouton { flex: 1 1 auto; }

.separateur { height: 1px; background: var(--ligne); margin: 16px 0; }

.pile { display: grid; gap: 10px; }
.deux-colonnes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

@media (min-width: 620px) {
  .grille-chiffres { grid-template-columns: repeat(4, 1fr); }
  .feuille-corps { left: 50%; right: auto; transform: translateX(-50%); width: 560px;
    border-radius: 18px; bottom: 5vh; max-height: 90vh; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Une case a cocher et une quantite, assez grandes pour le pouce.
   La case fait 22 px parce qu'une case de 44 px est laide ; c'est son
   etiquette qui porte la zone touchable, et elle fait 44 px de haut.
   Mesure prise a 375 px de large : une rangee de quinze droits se coche
   au pouce sans attraper la ligne d'a cote. */
.choix {
  display: flex; align-items: center; gap: 8px; font-size: 13px;
  justify-content: flex-end; min-height: 44px; cursor: pointer;
}
.choix input[type="checkbox"] { width: 22px; height: 22px; flex: none; }
.droite input[type="number"] { width: 92px; min-height: 42px; text-align: right; margin-top: 6px; }
.info.petit { font-size: 13px; }

/* Une carte de suggestion : presente, mais qui ne crie pas. */
.carte.douce { background: #f6f7f8; border: 1px dashed var(--ligne); box-shadow: none; }

/* Un lien qui est un bouton : meme apparence qu un lien, meme sobriete. */
.lien { background: none; border: 0; color: var(--vert); font: inherit;
  text-decoration: underline; cursor: pointer; padding: 0; min-height: 0; }
