:root {
  --marine: #12305a;
  --bleu: #1d5fbf;
  --bleu-fonce: #174c99;
  --ciel: #e8f0fb;
  --fond: #f3f6fa;
  --texte: #16202e;
  --gris: #5b6675;
  --trait: #d5dde8;
  --rouge: #b3261e;
  --rouge-fond: #fdecea;
  --vert-fond: #e7f5ec;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--fond); color: var(--texte);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--bleu); }
h1 { font-size: 1.5rem; line-height: 1.25; margin: 0 0 .5rem; }
h2 { font-size: 1.1rem; margin: 0 0 .25rem; }
p { margin: 0 0 1rem; }

.bandeau {
  background: var(--marine); color: #fff; padding: .75rem 1rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
}
.marque { color: #fff; text-decoration: none; font-weight: 700; letter-spacing: .02em; }
.marque span { font-weight: 400; opacity: .85; }
.session { display: flex; align-items: center; gap: .75rem; margin: 0; }
.qui { font-size: .9rem; opacity: .9; }

.page { max-width: 68rem; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.page.etroite { max-width: 26rem; }
.carte {
  background: #fff; border: 1px solid var(--trait); border-radius: 10px; padding: 1.25rem;
}
.note { color: var(--gris); font-size: .92rem; }

label { display: block; font-weight: 600; margin: 0 0 .3rem; }
input[type=text], input[type=password] {
  width: 100%; min-height: 48px; padding: .6rem .75rem; font: inherit;
  border: 1px solid #9aa7b8; border-radius: 8px; background: #fff; color: var(--texte);
}
input:focus-visible, button:focus-visible, a:focus-visible { outline: 3px solid #7fb0f5; outline-offset: 2px; }
.champ { margin-bottom: 1rem; }
.code input { font-size: 1.5rem; letter-spacing: .3em; text-align: center; }

.bouton {
  display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: .6rem 1.1rem;
  font: inherit; font-weight: 600; border-radius: 8px; border: 1px solid var(--bleu);
  background: var(--bleu); color: #fff; cursor: pointer; text-decoration: none;
}
.bouton:hover { background: var(--bleu-fonce); }
.bouton.large { width: 100%; }
.bouton.discret { min-height: 40px; background: transparent; border-color: rgba(255,255,255,.55); color: #fff; }
.bouton.discret:hover { background: rgba(255,255,255,.12); }

.alerte { border-radius: 8px; padding: .75rem .9rem; margin-bottom: 1rem; }
.alerte.erreur { background: var(--rouge-fond); color: var(--rouge); border: 1px solid #f3b6b1; }
.alerte.ok { background: var(--vert-fond); color: #17603a; border: 1px solid #b4dcc3; }

.grille { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 1rem; margin-top: 1rem; }
.module { display: flex; flex-direction: column; gap: .35rem; }
.etiquette {
  align-self: flex-start; font-size: .78rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px;
  background: var(--ciel); color: var(--bleu-fonce);
}
.qr { display: flex; justify-content: center; margin: 1rem 0; }
.qr svg { width: 13rem; height: 13rem; }
.cle { font-family: ui-monospace, Menlo, Consolas, monospace; word-break: break-all; background: var(--ciel);
  padding: .5rem .65rem; border-radius: 6px; }
.codes { list-style: none; padding: 0; margin: 1rem 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; }
.codes li { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.1rem; text-align: center;
  background: var(--ciel); border-radius: 6px; padding: .5rem; }
ol.etapes { padding-left: 1.2rem; margin: 0 0 1rem; }
ol.etapes li { margin-bottom: .4rem; }

/* ----- pages, listes et formulaires (étape 1b) ----- */
.page.moyenne { max-width: 44rem; }
.fil { font-size: .9rem; margin-bottom: .5rem; }
.entete { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.entete h1 { margin: 0; }
.titre-section { margin: 1.5rem 0 .5rem; }
.lien-carte { text-decoration: none; color: inherit; }
.lien-carte:hover { border-color: var(--bleu); }
.etiquette.ouvert { background: var(--bleu); color: #fff; }
.chiffre { font-size: 1.4rem; font-weight: 700; }
.deux-colonnes { display: grid; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); gap: 1rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin: 1rem 0; }

input[type=email], input[type=number], input[type=date], input[type=search], input[type=tel], input[type=url],
input[type=file], select, textarea {
  width: 100%; min-height: 48px; padding: .6rem .75rem; font: inherit;
  border: 1px solid #9aa7b8; border-radius: 8px; background: #fff; color: var(--texte);
}
textarea { min-height: 5.5rem; resize: vertical; }
select:focus-visible, textarea:focus-visible { outline: 3px solid #7fb0f5; outline-offset: 2px; }
fieldset.sans-cadre, fieldset.groupe { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset.groupe legend { font-weight: 600; padding: 0; margin-bottom: .3rem; }
.cases { display: flex; flex-wrap: wrap; gap: .5rem .9rem; margin: 0 0 .5rem; }
.case { display: inline-flex; align-items: center; gap: .5rem; font-weight: 400; min-height: 44px; margin: 0; cursor: pointer; }
.case input { width: 1.35rem; height: 1.35rem; accent-color: var(--bleu); flex: none; }
.champ:has(> .case) { margin-bottom: .1rem; }
.aide { color: var(--gris); font-size: .85rem; margin: .25rem 0 0; }
.erreur-champ { color: var(--rouge); font-size: .9rem; margin: .25rem 0 0; }
.en-erreur input, .en-erreur select, .en-erreur textarea { border-color: var(--rouge); }
.bouton.secondaire { background: #fff; color: var(--bleu-fonce); }
.bouton.secondaire:hover { background: var(--ciel); }
.bouton:disabled { opacity: .6; cursor: progress; }

.recherche { margin-bottom: 1rem; }
.filtres { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-top: .6rem; }
.puce { margin: 0; cursor: pointer; }
.puce input { position: absolute; opacity: 0; }
.puce span { display: inline-flex; align-items: center; min-height: 40px; padding: .3rem .9rem; border-radius: 999px;
  border: 1px solid var(--trait); background: #fff; font-weight: 600; font-size: .92rem; }
.puce input:checked + span { background: var(--bleu); border-color: var(--bleu); color: #fff; }
.puce input:focus-visible + span { outline: 3px solid #7fb0f5; outline-offset: 2px; }

.fiches, .liste { list-style: none; margin: 0; padding: 0; }
.fiches li + li { margin-top: .5rem; }
.fiches a { display: block; padding: .8rem 1rem; background: #fff; border: 1px solid var(--trait); border-radius: 10px;
  color: inherit; text-decoration: none; }
.fiches a:hover { border-color: var(--bleu); }
.fiches .note, .lien-carte .note { display: block; }
.liste li { padding: .55rem 0; border-bottom: 1px solid var(--trait); }
.liste li .note { display: block; }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 1rem; }
.pieces { margin-top: 1rem; }
.ajout-piece { margin-top: .75rem; display: grid; gap: .5rem; }

/* ----- discussions avec les agents IA ----- */
.discussion { display: flex; flex-direction: column; gap: .75rem; margin: 1rem 0; }
.bulle { max-width: 46rem; padding: .75rem 1rem; border-radius: 12px; background: #fff; border: 1px solid var(--trait); }
.bulle.utilisateur { align-self: flex-end; background: var(--ciel); border-color: #c5d8f3; }
.bulle .auteur { font-size: .8rem; color: var(--gris); margin-bottom: .25rem; }
.bulle .texte { overflow-wrap: anywhere; }
.bulle .sources { font-size: .8rem; color: var(--gris); margin-top: .5rem; border-top: 1px dashed var(--trait); padding-top: .4rem; }
.question { display: grid; gap: .5rem; }
.attente { display: none; font-weight: 400; }
.htmx-request .attente { display: inline; }

/* ----- commercial : CRM et devis (étape 2a) ----- */
.bloc { margin-top: 1rem; }
.bloc > h2 { margin-bottom: .5rem; }
.alerte.info { background: var(--ciel); color: var(--marine); border: 1px solid #c5d8f3; }
.bouton.danger { border-color: var(--rouge); color: var(--rouge); }
.bouton.danger:hover { background: var(--rouge-fond); }
.actions form { margin: 0; }
form.suite { margin-top: .75rem; }
details > summary { cursor: pointer; font-weight: 600; color: var(--bleu-fonce); min-height: 44px; display: flex; align-items: center; }
details > summary::before { content: "▸"; margin-right: .5rem; }
details[open] > summary::before { content: "▾"; }
details > summary::-webkit-details-marker { display: none; }
details[open] > summary { margin-bottom: .5rem; }
.liens { display: flex; flex-wrap: wrap; gap: .25rem 1rem; margin-top: .2rem; }
.liens a { min-height: 32px; display: inline-flex; align-items: center; }
.texte-long { display: block; overflow-wrap: anywhere; }
.invisible { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.defilant { overflow-x: auto; }
.tableau { width: 100%; border-collapse: collapse; font-size: .95rem; }
.tableau th { text-align: left; font-size: .82rem; color: var(--gris); font-weight: 600; padding: .4rem .6rem; border-bottom: 2px solid var(--trait); white-space: nowrap; }
.tableau td { padding: .55rem .6rem; border-bottom: 1px solid var(--trait); vertical-align: top; }
.tableau .nombre { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tableau td .note { display: block; }
.tableau.large { min-width: 36rem; }
.tableau .fixe { white-space: nowrap; }
.totaux-document { margin: .75rem 0 .5rem auto; max-width: 21rem; }
.totaux-document div { display: flex; justify-content: space-between; gap: 1rem; padding: .25rem .6rem; }
.totaux-document dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.totaux-document .total { border-top: 2px solid var(--trait); font-size: 1.05rem; padding-top: .45rem; margin-top: .2rem; }
.tableau tr.en-cours td { background: var(--ciel); }
.resume { margin: 0 0 1rem; display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: .6rem 1.5rem; }
.resume dt { font-size: .82rem; color: var(--gris); font-weight: 600; }
.resume dd { margin: 0; overflow-wrap: anywhere; }
.etiquette.grande { font-size: .95rem; padding: .3rem .8rem; align-self: center; }
.etiquette.etat-brouillon { background: #eceff3; color: #444e5c; }
.etiquette.etat-a_valider { background: #fff1d6; color: #7a4b00; }
.etiquette.etat-valide { background: var(--ciel); color: var(--marine); }
.etiquette.etat-envoye { background: var(--ciel); color: var(--bleu-fonce); }
.etiquette.etat-relance { background: #fff1d6; color: #7a4b00; }
.etiquette.etat-accepte { background: var(--vert-fond); color: #17603a; }
.etiquette.etat-refuse { background: var(--rouge-fond); color: var(--rouge); }
.etiquette.etat-expire { background: #e3e6ea; color: #3b4450; }
.indicateurs { grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); margin: 0 0 1rem; }
.indicateurs .carte { display: flex; flex-direction: column; gap: .1rem; }
select.court { width: auto; min-width: 6.5rem; }
.en-ligne { display: inline-flex; align-items: center; gap: .5rem; white-space: nowrap; }
.en-ligne label { margin: 0; }
.deux-colonnes.serre { gap: 0 1rem; }

/* ----- tableaux, états et chiffres clés (étape 3a) ----- */
.defile { overflow-x: auto; background: #fff; border: 1px solid var(--trait); border-radius: 10px; }
.tableau { width: 100%; border-collapse: collapse; font-size: .95rem; }
.tableau th, .tableau td { padding: .6rem .75rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--trait); }
.tableau thead th { background: var(--ciel); font-size: .82rem; white-space: nowrap; }
.tableau tbody tr:last-child td, .tableau tfoot tr:last-child td { border-bottom: 0; }
.tableau .nombre { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tableau tfoot td { font-weight: 600; }
.tableau input, .tableau select { min-height: 42px; min-width: 6rem; }
.etat { display: inline-block; font-size: .8rem; font-weight: 600; padding: .15rem .6rem; border-radius: 999px;
  background: #e9edf2; color: #3c4756; white-space: nowrap; }
.etat.bon { background: var(--vert-fond); color: #17603a; }
.etat.attente { background: #fff3d6; color: #7a5200; }
.etat.manque { background: var(--rouge-fond); color: var(--rouge); }
.etat.cours { background: var(--ciel); color: var(--bleu-fonce); }
.faits { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: .75rem 1.25rem; margin: 0; }
.faits dt { color: var(--gris); font-size: .82rem; }
.faits dd { margin: 0; font-weight: 600; }
.bouton.petit { min-height: 40px; padding: .35rem .8rem; font-size: .92rem; }
.bouton.danger { background: #fff; border-color: var(--rouge); color: var(--rouge); }
.bouton.danger:hover { background: var(--rouge-fond); }
.form-ligne { display: inline; margin: 0; }
.carte > h2 { margin-bottom: .75rem; }
details.pli > summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
details.pli[open] > summary { margin-bottom: .5rem; }
.grille-champs { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 0 1rem; }
.grille-champs .entier { grid-column: 1 / -1; }
.etat.large { display: block; white-space: normal; border-radius: 8px; padding: .5rem .75rem; font-size: .9rem; }
.entete .etat, h1 .etat { vertical-align: middle; }

/* Au téléphone, un tableau « empile » devient une suite de fiches : chaque cellule porte son titre (data-titre). */
@media (max-width: 640px) {
  .tableau.empile thead, .tableau.empile .masque-tel { display: none; }
  .tableau.empile, .tableau.empile tbody, .tableau.empile tfoot, .tableau.empile tr, .tableau.empile td { display: block; width: 100%; }
  .tableau.empile tr { padding: .6rem .75rem; border-bottom: 1px solid var(--trait); }
  .tableau.empile tbody tr:last-child, .tableau.empile tfoot tr:last-child { border-bottom: 0; }
  .tableau.empile td { padding: .15rem 0; border: 0; }
  .tableau.empile td[data-titre] { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; text-align: right; }
  .tableau.empile td[data-titre]::before { content: attr(data-titre); color: var(--gris); font-size: .85rem; text-align: left; flex: none; }
  .tableau.empile td[data-titre]:empty { display: none; }
  .tableau.empile td[data-titre] input { max-width: 11rem; text-align: right; }
  .tableau.empile tfoot tr { padding-top: .2rem; padding-bottom: .2rem; }
}

/* Étape 2b : états des bons de commande, des marchés et des factures */
.etiquette.etat-confirme, .etiquette.etat-notifie, .etiquette.etat-validee { background: var(--ciel); color: var(--bleu-fonce); }
.etiquette.etat-en_production, .etiquette.etat-en_cours, .etiquette.etat-livre_partiel { background: #fff1d6; color: #7a4b00; }
.etiquette.etat-livre, .etiquette.etat-facture, .etiquette.etat-solde, .etiquette.etat-reception_provisoire,
.etiquette.etat-reception_definitive { background: var(--vert-fond); color: #17603a; }
.etiquette.etat-annule, .etiquette.etat-annulee, .etiquette.etat-resilie { background: #e3e6ea; color: #3b4450; }
.tableau input.court { min-width: 4.5rem; width: 6rem; text-align: right; }

/* Étape 2b, partie 2 : étapes des appels d'offres, listes de contrôle */
.etiquette.etat-veille, .etiquette.etat-abandonne, .etiquette.etat-infructueux { background: #e3e6ea; color: #3b4450; }
.etiquette.etat-etude, .etiquette.etat-depose { background: var(--ciel); color: var(--bleu-fonce); }
.etiquette.etat-preparation, .etiquette.etat-ouverture { background: #fff1d6; color: #7a4b00; }
.etiquette.etat-gagne { background: var(--vert-fond); color: #17603a; }
.etiquette.etat-perdu { background: var(--rouge-fond); color: var(--rouge); }
.texte-alerte { color: var(--rouge); }
.sous-titre { font-size: 1rem; margin: 1rem 0 .4rem; }
.sous-titre .note { font-weight: 400; }
.controles li { display: flex; gap: .6rem; align-items: baseline; }
.controles .etat { flex: none; min-width: 5.5rem; text-align: center; }
.pieces-dossier .ligne-piece { margin: 0; }
details.pli.discret > summary { font-weight: 400; font-size: .88rem; color: var(--gris); min-height: 32px; }
.version-ao p { margin: .25rem 0; }
