* { box-sizing: border-box; }
body { margin: 0; background: #f2f5f4; color: #18362e; font: 16px/1.6 system-ui, sans-serif; }
main { max-width: 1100px; margin: auto; padding: 24px 20px 80px; }
h1 { font-size: clamp(1.9rem, 5vw, 3rem); line-height: 1.15; }
h2 { font-size: 1.25rem; line-height: 1.3; } h3 { font-size: 1rem; margin: 0; }
.eyebrow { letter-spacing: .1em; font-weight: 700; font-size: .8rem; }
section { background: white; border: 1px solid #c5d3cd; border-radius: 12px; padding: 24px; margin: 20px 0; }
label { display: block; font-weight: 600; }
input, select, button { font: inherit; max-width: 100%; }
input, select { display: block; width: 100%; margin: 8px 0; padding: 12px; border: 1px solid #67877a; border-radius: 6px; background: white; color: #18362e; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; align-items: end; }
.actions { display: flex; gap: 12px; }
button { background: #175342; color: white; border: 0; border-radius: 6px; padding: 12px 18px; margin: 8px 0; cursor: pointer; }
button:disabled { background: #d3ddd8; color: #465b52; cursor: default; }
:focus-visible { outline: 3px solid #ad6610; outline-offset: 4px; }
.invoice { background: white; border: 1px solid #8ea69b; border-radius: 8px; padding: 24px; margin: 20px 0; }
.invoice-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 16px; }
.invoice-head p { margin: 2px 0; }
.table-wrap { overflow-x: auto; margin: 12px 0; }
table { border-collapse: collapse; width: 100%; min-width: 28rem; }
th, td { border: 1px solid #8ea69b; padding: 6px 8px; text-align: left; vertical-align: top; }
td.amount, th.amount { text-align: right; white-space: nowrap; }
dl > div { display: flex; justify-content: space-between; gap: 16px; border-bottom: 1px solid #c5d3cd; padding: 4px 0; }
dt { font-weight: 600; } dd { margin: 0; text-align: right; }
.totals { max-width: 26rem; margin-left: auto; }
.totals > div:last-child { font-weight: 700; border-bottom: 2px solid #18362e; }
.notice { font-size: .9rem; color: #533d12; background: #fff4d8; padding: 8px; }
#status { position: sticky; bottom: 10px; padding: 12px; background: #18362e; color: white; border-radius: 6px; }
#status.error { background: #822e23; }
@page { size: A4; margin: 15mm; }
/* Pied de facture : conditions de paiement puis mentions légales du déménageur (avant les règles d’impression, qui l’emportent). */
.payment-terms { margin: 12px 0 0; font-weight: 600; }
.mentions { margin-top: 12px; padding-top: 6px; border-top: 1px solid #c5d3cd; font-size: .85rem; overflow-wrap: anywhere; }
.mentions p { margin: 0; }
@media print {
  html, body { background: white; color: black; font-size: 10pt; }
  main { max-width: none; margin: 0; padding: 0; }
  .controls { display: none !important; }
  .invoice { border: 0; border-radius: 0; padding: 0; margin: 0; break-after: page; page-break-after: always; }
  .invoice:last-of-type { break-after: auto; page-break-after: auto; }
  .table-wrap { overflow: visible; }
  table { min-width: 0; }
  th, td { border-color: black; }
  tr, dl > div { break-inside: avoid; page-break-inside: avoid; }
  .rappel-mentions { display: none !important; }
  .mentions { font-size: 7.5pt; }
}
.settlement { margin: .4rem 0; font-weight: 600; }
.settlement.settled { color: #245438; }
.line-detail { display: block; font-size: .85rem; color: #4b5f55; }
@media screen and (max-width: 700px) { table { min-width: 0; } }

/* Export comptable : bloc resserré, le mois et ce qu'il contient côte à côte. */
#invoice-accounting { max-width: 44rem; }
.accounting-fields { align-items: center; }
.accounting-scope { margin: 0; color: var(--encre-2, #44566b); }
.accounting-actions { flex-wrap: wrap; gap: 8px; }
@media (max-width: 600px) { .accounting-fields { grid-template-columns: 1fr; } .accounting-scope { margin-top: 6px; } }
/* Champs et rappels propres à une édition : masqués dans l’autre, malgré la grille des champs. */
#form [hidden], #facture-manques-bloc[hidden] { display: none !important; }
.invoice-terms { list-style: none; padding: 0; margin: .75rem 0 0; }
.invoice-terms li { margin: .15rem 0; }
.settlement.settled strong { color: var(--vert, #1b7a3a); }
/* Lien du solde : il passe à la ligne au téléphone plutôt que de déborder. */
.mx .invoice .record-balance, .invoice .record-balance { white-space: normal; max-width: 100%; text-align: center; line-height: 1.25; padding-top: 8px; padding-bottom: 8px; }
/* Date de la prestation : d’où elle vient (bon de fin signé, ou planning à confirmer). */
.service-note { grid-column: 1 / -1; margin: 0 0 8px; font-size: .9rem; color: #4b5f55; }
.cancellation { margin-top: 8px; }

/* ---- Recette UI (phase 1) : le registre d'abord, une seule action principale, des replis homogènes ---- */
/* Registre : le titre et « Établir une nouvelle facture » (seul bouton plein) sur la même ligne, la liste des pièces juste dessous. */
.registre-tete { display: flex; align-items: center; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; }
.registre-tete h2 { margin: 0; }
.mx .registre-nouvelle, .registre-nouvelle { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 22px; border-radius: var(--r-s, 8px); background: var(--route, #0b3a82); color: #fff; font: 800 17px/1.1 var(--large, inherit); font-stretch: 85%; text-decoration: none; text-align: center; }
.mx .registre-nouvelle:hover { background: var(--route-fonce, #082c63); }
.mx #saved { margin: 6px 0 0; color: var(--encre-2, #44566b); font-size: 15px; }
.registre-filtre { margin-top: 8px; }
.mx main .actions button { font-size: 16px; }
/* Une ligne par pièce : n°, client et date à gauche ; état et montant à droite. */
.invoice-list { list-style: none; margin: 14px 0 4px; padding: 0; border-top: 1px solid var(--trait, #d5dde8); }
.invoice-list[hidden] { display: none; }
.invoice-list li { margin: 0; border-bottom: 1px solid var(--trait, #d5dde8); }
.mx .invoice-list .invoice-row, .invoice-list .invoice-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; width: 100%; min-height: 60px; margin: 0; padding: 10px 10px; border: 0; border-radius: 0; background: #fff; color: var(--encre, #0f1c2e); text-align: left; font: 400 16px/1.35 var(--texte, inherit); white-space: normal; cursor: pointer; }
.mx .invoice-list .invoice-row:hover:not(:disabled) { background: var(--route-pale, #e8eef8); border: 0; color: var(--encre, #0f1c2e); }
.mx .invoice-list .invoice-row[aria-pressed="true"] { background: var(--route-pale, #e8eef8); box-shadow: inset 4px 0 0 var(--route, #0b3a82); }
.invoice-row-qui { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.invoice-row-qui strong { font: 800 19px/1.1 var(--large, inherit); font-stretch: 80%; color: var(--encre, #0f1c2e); }
.invoice-row-qui span { color: var(--encre-2, #44566b); }
.invoice-row-etat { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.piece-montant { font-weight: 700; font-variant-numeric: tabular-nums; }
.invoice-row-etat .piece-montant { font: 800 20px/1.1 var(--large, inherit); font-stretch: 80%; }
/* Pastille d'état, dans les couleurs des autres écrans : orange à encaisser, vert réglée, gris annulée ou avoir. */
.pastille-etat { display: inline-flex; align-items: center; height: 26px; padding: 0 10px; border-radius: 13px; font: 700 14px/1 var(--large, inherit); font-stretch: 85%; white-space: nowrap; color: #fff; background: var(--gris, #5b6676); }
.pastille-etat.orange { background: var(--orange, #a4510b); }
.pastille-etat.vert { background: var(--vert, #1b7a3a); }
/* En-tête de la pièce : son état et le montant dû en haut à droite, à l'écran seulement. */
.piece-tete { display: flex; align-items: center; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; }
.piece-etat { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0; font-size: 18px; }
.invoice-row-qui, .piece-etat { overflow-wrap: anywhere; }
.impression-seule, .mx .mentions-toggle, .mentions-toggle { display: none; }
.mentions-texte { display: contents; }
/* Totaux : le montant reste sur la ligne de son libellé, aligné à droite, même au téléphone. */
@media screen {
  .mx .invoice .totals > div, .invoice .totals > div { flex-wrap: nowrap; align-items: baseline; }
  .invoice .totals dd { white-space: nowrap; flex: none; }
}
/* Replis (relance, export, registre, nouvelle facture) : un seul style, une rangée de 48 px avec chevron. */
.mx main details > summary, main details > summary { list-style: none; display: flex; align-items: center; gap: 10px; min-height: 48px; cursor: pointer; font-weight: 700; color: var(--route, #0b3a82); }
main details > summary::-webkit-details-marker { display: none; }
main details > summary::before { content: ""; flex: none; width: 8px; height: 8px; margin: 0 4px 0 2px; border-right: 2.5px solid currentColor; border-bottom: 2.5px solid currentColor; transform: rotate(-45deg); transition: transform .15s; }
main details[open] > summary::before { transform: rotate(45deg); }
.mx main section.controls:has(> details) { padding-top: 6px; padding-bottom: 6px; }
/* La saisie d'une nouvelle facture s'ouvre par le bouton du registre : fermée, elle ne double pas l'action. */
#invoice-prepare:not([open]) { display: none; }
#invoice-prepare { background: #fff; border: 1px solid var(--trait, #c5d3cd); border-radius: var(--r, 12px); padding: 6px 24px 20px; margin: 20px 0; }
@media screen and (max-width: 700px) {
  .mx main > header > p { display: none; }
  .mx .registre .registre-filtre .actions { margin-block: 0; }
  .mx .registre #print { margin-block: 0; }
  .registre-tete .registre-nouvelle { width: 100%; }
  .invoice-row-etat { width: 100%; justify-content: space-between; gap: 8px; }
  .invoice-row-etat .piece-montant { white-space: nowrap; }
  .mx main .mentions-toggle, .mentions-toggle { display: inline-flex; align-items: center; min-height: 44px; margin: 0; }
  .mentions-toggle[aria-expanded="false"] + .mentions-texte { display: none; }
  .mentions-toggle[aria-expanded="true"] { margin-bottom: 8px; }
  #invoice-prepare { padding: 6px 16px 16px; }
}
@media print {
  .piece-tete { display: contents; }
  .piece-etat, .invoice-list, .ecran-seul, .mentions-toggle { display: none !important; }
  .impression-seule { display: inline; }
}
/* Bureau : la barre de recherche de la coquille se pose après le premier affichage ; sa place est gardée pour que la page ne saute pas (CLS). */
@media screen and (min-width: 1024px) { .mx body:not(:has(> .mx-barre)) { padding-top: 62px; } }
.mx body:not([data-registre-pret]) main > section.controls:has(> details) { display: none; }
/* Un seul bouton plein sur l'écran (« Établir une nouvelle facture ») : l'avoir, geste de correction, est en contour. */
.mx main button.credit-open:not(:disabled) { background: #fff; border-color: var(--route); color: var(--route); }
.mx main button.credit-open:hover:not(:disabled) { background: var(--route-pale); }

/* ---- Recette UI (tour 1b) : titre et sous-titre chiffré, outils avant la liste, un geste principal près du net ---- */
/* Titre au gabarit des autres écrans ; dessous, le registre en chiffres (ou l'alerte d'une sauvegarde illisible). */
.mx main > header h1 { font-size: 34px; margin-bottom: 6px; }
.mx main > header > p.resume-registre { display: block; margin: 0; font-size: 17px; color: var(--encre-2, #44566b); }
.mx main > header > p.resume-registre.alert { color: var(--rouge, #a3271b); font-weight: 700; }
.lecteur-seul { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.sans-coupure { white-space: nowrap; }
/* Filtre et impression en tête de la liste, sur une ligne. */
.registre-outils { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin: 14px 0 0; }
.mx .registre-outils .registre-filtre { display: flex; align-items: center; gap: 10px; margin: 0; font-weight: 600; }
.mx .registre-outils select { width: 16rem; min-width: 0; min-height: 44px; margin: 0; padding: 8px 12px; }
.mx main .registre-outils #print { margin: 0; min-height: 44px; padding: 0 18px; font-size: 16px; }
/* Une pièce attend un geste : « Établir une nouvelle facture » passe en contour, le geste de la pièce reste le seul bouton plein. */
.mx .registre-nouvelle.registre-nouvelle-second { background: #fff; color: var(--route, #0b3a82); border: 2px solid var(--route, #0b3a82); }
.mx .registre-nouvelle.registre-nouvelle-second:hover { background: var(--route-pale, #e2ebf7); }
/* En tête de la pièce : le montant dans le style des montants du registre. */
.mx .piece-etat { align-items: baseline; gap: 8px; }
.piece-etat .piece-libelle { color: var(--encre-2, #44566b); font-weight: 600; font-size: 17px; }
.mx .piece-etat .piece-montant { font: 800 20px/1.1 var(--large, inherit); font-stretch: 80%; color: var(--encre, #0f1c2e); }
/* Gestes de la pièce : une barre sous le montant, un seul style de bouton secondaire (contour), le principal plein et à droite. */
.piece-actions { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: flex-end; gap: 10px; margin: 12px 0 8px; }
.mx main .piece-actions > *, .mx main .piece-actions .actions, .mx main .piece-actions button { margin: 0; }
.piece-actions > .piece-principale { order: 2; }
.piece-actions > details[open], .piece-actions > .credit-form { order: 3; flex-basis: 100%; }
.mx main .piece-actions details > summary { display: inline-flex; justify-content: center; min-height: 44px; padding: 0 18px; border: 2px solid var(--route, #0b3a82); border-radius: var(--r-s, 8px); background: #fff; color: var(--route, #0b3a82); font: 800 16px/1.1 var(--large, inherit); font-stretch: 85%; }
.mx main .piece-actions details > summary:hover { background: var(--route-pale, #e2ebf7); }
.piece-actions > details[open] > summary { float: right; margin-bottom: 8px; }
.piece-actions > details[open] > :not(summary) { clear: both; }
.mx main .piece-actions details.piece-principale > summary, .mx .invoice .piece-actions .record-balance.piece-principale { background: var(--route, #0b3a82); border-color: var(--route, #0b3a82); color: #fff; }
.mx main .piece-actions details.piece-principale > summary:hover, .mx .invoice .piece-actions .record-balance.piece-principale:hover { background: var(--route-fonce, #072a61); }
.mx .invoice .piece-actions .record-balance { min-height: 44px; }
/* Export et sauvegarde : une seule carte, deux replis du même style. */
.registre-plus > details + details { border-top: 1px solid var(--trait, #d5dde8); }
@media screen and (max-width: 700px) {
  .mx main > header h1 { font-size: 27px; }
  .mx main > header > p.resume-registre { font-size: 16px; }
  /* Une seule marge au téléphone : la carte garde 16 px, le contenu tient sans coupure. */
  .mx main > section.controls, .mx main .invoice, #invoice-prepare { padding-left: 16px; padding-right: 16px; }
  .mx .registre-outils { flex-wrap: nowrap; }
  .mx .registre-outils .registre-filtre { flex: 1; min-width: 0; }
  .registre-outils .registre-filtre-titre { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .mx .registre-outils select { min-width: 0; width: 100%; }
  /* « Imprimer » à côté du filtre : sa place est fixée par flex-basis (largeur pleine gardée hors de cette rangée). */
  .mx main .registre-outils #print { flex: 0 0 6.5rem; padding: 0 10px; }
  .mx .registre-outils select { padding-left: 10px; padding-right: 28px; }
  .mx .registre-outils .registre-filtre select { flex: 1; }
  /* Totaux : laisser le libellé revenir à la ligne si le montant prend davantage de place. */
  .mx .invoice .totals { font-size: 15px; }
  .mx .invoice .totals > div { gap: 6px; }
  .mx .invoice .totals dt { min-width: 0; overflow-wrap: anywhere; }
}
@media screen and (min-width: 370px) and (max-width: 700px) {
  /* Gestes en colonne, pleine largeur, le principal en premier. */
  .piece-actions { flex-direction: column; align-items: stretch; }
  .piece-actions > .piece-principale { order: -1; }
  .mx main .piece-actions details > summary, .mx main .piece-actions button, .mx .invoice .piece-actions .record-balance { width: 100%; min-height: 48px; }
  .piece-actions > details[open] > summary { float: none; }
  /* « Mentions légales » : un repli comme les autres (chevron), pas un bouton. */
  .mx main .invoice button.mentions-toggle { justify-content: flex-start; gap: 10px; width: 100%; min-height: 48px; padding: 0; border: 0; border-radius: 0; background: transparent; color: var(--route, #0b3a82); font: 700 16px/1.3 var(--texte, inherit); font-stretch: 100%; }
  .mx main .invoice button.mentions-toggle:hover:not(:disabled) { background: transparent; border: 0; color: var(--route, #0b3a82); }
  .mx main .invoice button.mentions-toggle::before { content: ""; flex: none; width: 8px; height: 8px; margin: 0 4px 0 2px; border-right: 2.5px solid currentColor; border-bottom: 2.5px solid currentColor; transform: rotate(-45deg); transition: transform .15s; }
  .mx main .invoice button.mentions-toggle[aria-expanded="true"]::before { transform: rotate(45deg); }
}
@media print { .piece-actions, .registre-outils { display: none !important; } }

.invoice-head .logo-entreprise {
  display: block;
  max-width: min(150px, 100%);
  max-height: 60px;
  margin-bottom: 8px;
}
