/* ==========================================================================
   Ctrl-Data, site v2 : « le plan » (objets du bâtiment, côté Ctrl-Data BTP)
   Pages : btp/index.html (bon de commande, bordereau), btp/exemples.html
   (cotes et cartouche des planches).

   Trois objets de bureau d'études, en papier et encre :
   1. .bon        — un bon de commande arraché du carnet à souches, avec son
                    coup de tampon (texte réel du logiciel : « OK – envoyé par
                    Ctrl-Data »). Il monte du carnet et se pose de biais.
   2. .bordereau  — ce qui est inclus, présenté comme un bordereau de prix :
                    numéros 1.1, 2.1…, désignation, unité. Les lignes s'écrivent
                    l'une après l'autre (un voile de papier qui se retire, transform
                    seulement), puis le tampon tombe.
   3. .cotes / .cartouche — les captures des planches sont « cotées » comme un
                    plan (lignes de cote qui se tracent depuis le centre) et
                    portent un cartouche (projet, planche, objet, source).

   Jetons seulement (contexte .feuille / .encre). Animations : transform,
   opacity, clip-path courts. Sans JS : tout est posé (secours de
   [data-apparition] à 2,5 s). Mouvement réduit : rien ne bouge.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Bon de commande (chapitre Chantier)
   -------------------------------------------------------------------------- */
.bon { margin: 0; max-width: 36rem; }
.bon__feuille {
  --bon-rot: 1.2deg;
  position: relative;
  padding: clamp(20px, 3vw, 36px) clamp(18px, 3vw, 36px) clamp(22px, 3vw, 34px) clamp(34px, 4.4vw, 56px);
  border-radius: 2px;
  box-shadow: 0 30px 70px -34px var(--ombre-feuille), 0 2px 6px -2px var(--ombre-feuille);
  transform: rotate(var(--bon-rot));
}
/* la souche : bord gauche perforé, arraché du carnet */
.bon__feuille::before {
  content: "";
  position: absolute;
  top: 10px;
  bottom: 10px;
  left: clamp(12px, 1.8vw, 20px);
  width: 6px;
  background: radial-gradient(circle at 3px 3px, var(--filet-fort) 1.5px, transparent 2px) 0 0 / 6px 11px repeat-y;
}
.bon__tete {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--espace-4);
  padding-bottom: var(--espace-4);
  border-bottom: 2px solid var(--texte);
}
.bon__titre {
  font-family: var(--police-titre);
  font-weight: 700;
  font-size: var(--t-4);
  line-height: 1.05;
  letter-spacing: -.01em;
  text-transform: uppercase;
}
.bon__logo {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 4.6em;
  aspect-ratio: 1;
  border: 1px dashed var(--filet-fort);
  border-radius: 2px;
  font-family: var(--police-mono);
  font-size: var(--t-mono-petit);
  letter-spacing: var(--interlettrage-mono);
  line-height: 1.2;
  text-align: center;
  text-transform: uppercase;
  color: var(--texte-2);
}
.bon__champs {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px 14px;
  align-items: center;
  margin-top: var(--espace-4);
}
.bon__champs dd { margin: 0; }
.bon__barre {
  display: block;
  width: var(--l, 60%);
  height: .62em;
  border-radius: 1px;
  background-color: var(--filet-fort);
}
.bon__lignes {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 3.4em;
  gap: 0 14px;
  margin-top: var(--espace-5);
  border-top: 1px solid var(--filet-fort);
}
.bon__lignes > span { padding-block: 9px; border-bottom: 1px solid var(--filet); }
.bon__lignes > .etiquette { padding-block: 8px 6px; }
.bon__pied {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--espace-4);
  margin-top: var(--espace-6);
}
.bon__visa { display: grid; gap: 8px; min-width: 9em; }
.bon__tampon { --tampon-rotation: -6deg; --tampon-taille: clamp(.78rem, .62rem + .5vw, 1rem); white-space: normal; max-width: 13em; line-height: 1.15; text-align: center; }
.bon figcaption { margin-top: var(--espace-4); }

/* entrée : le bon monte du carnet et se pose de biais */
.js .bon[data-apparition] { transform: translateY(44px) rotate(-2deg); }
.js .bon[data-apparition].est-visible { transform: none; }

/* --------------------------------------------------------------------------
   2. Bordereau des inclus
   -------------------------------------------------------------------------- */
.bordereau-section__tete { display: grid; gap: var(--espace-6) clamp(16px, 2vw, 32px); align-items: end; margin-bottom: var(--espace-8); }
@media (min-width: 900px) { .bordereau-section__tete { grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); } }
.bordereau-section__tete .chapeau { max-width: 40ch; }

.bordereau {
  position: relative;
  padding: clamp(20px, 3.4vw, 48px) clamp(16px, 3.4vw, 48px);
  border-radius: 2px;
  box-shadow: 0 30px 80px -30px var(--ombre-feuille), 0 2px 6px -2px var(--ombre-feuille);
}
.bordereau__entete {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px var(--espace-5);
  padding-bottom: var(--espace-4);
  border-bottom: 3px double var(--texte);
}
.bordereau__titre {
  font-family: var(--police-titre);
  font-weight: 700;
  font-size: var(--t-3);
  line-height: 1;
  letter-spacing: -.02em;
  text-transform: uppercase;
}
/* grille commune : N° | désignation | unité */
.bordereau__colonnes,
.bordereau__ligne {
  display: grid;
  grid-template-columns: 3.2em minmax(0, 1fr) auto;
  gap: 0 clamp(10px, 2vw, 28px);
  align-items: baseline;
}
.bordereau__colonnes { padding-block: 10px 8px; border-bottom: 1px solid var(--filet-fort); }
.bordereau__colonnes span:last-child { text-align: right; }
.bordereau__lot { margin-top: var(--espace-5); }
.bordereau__lot-titre {
  padding-block: 6px;
  font-family: var(--police-mono);
  font-size: var(--t-mono-petit);
  font-weight: 500;
  letter-spacing: var(--interlettrage-mono);
  text-transform: uppercase;
  color: var(--accent-texte);
}
.bordereau__lignes { list-style: none; padding: 0; }
.bordereau__ligne {
  position: relative;
  padding-block: 12px 11px;
  border-bottom: 1px solid var(--filet);
}
.bordereau__num { font-family: var(--police-mono); font-size: var(--t-mono); color: var(--texte-2); }
.bordereau__designation { display: flex; align-items: baseline; gap: 12px; max-width: none; font-size: var(--t-petit); line-height: 1.45; }
/* points de conduite, comme sur un bordereau de prix */
.bordereau__designation::after { content: ""; flex: 1 1 2em; min-width: 2em; border-bottom: 1px dotted var(--filet-fort); transform: translateY(-.28em); }
.bordereau__designation b { font-family: var(--police-titre); font-weight: 600; font-size: var(--t-4); letter-spacing: -.01em; }
.bordereau__designation a { text-decoration: none; }
/* toute la ligne est cliquable */
.bordereau__designation a::after { content: ""; position: absolute; inset: 0; }
.bordereau__designation a:focus-visible { outline: none; }
.bordereau__ligne:has(a:focus-visible) { outline: 2px solid var(--accent-texte); outline-offset: 2px; }
.bordereau__unite {
  font-family: var(--police-mono);
  font-size: var(--t-mono-petit);
  font-weight: 500;
  letter-spacing: var(--interlettrage-mono);
  text-transform: uppercase;
  text-align: right;
  white-space: nowrap;
  color: var(--texte-2);
}
.bordereau__unite .fleche { width: 11px; height: 11px; margin-left: 4px; vertical-align: -1px; transition: transform .6s var(--sortie); }
@media (hover: hover) {
  .bordereau__ligne { transition: background-color var(--duree-courte) ease; }
  .bordereau__ligne:hover { background-color: var(--fond-2); }
  .bordereau__ligne:hover .bordereau__unite { color: var(--accent-texte); }
  .bordereau__ligne:hover .fleche { transform: translateX(4px); }
}
.bordereau__total {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--espace-4);
  margin-top: var(--espace-5);
  padding-top: var(--espace-4);
  border-top: 3px double var(--texte);
}
.bordereau__total-texte { display: flex; align-items: baseline; gap: var(--espace-4); font-family: var(--police-titre); font-weight: 700; font-size: var(--t-4); }
.bordereau__total .tampon-seul { --tampon-rotation: -7deg; --tampon-taille: clamp(1rem, .8rem + .6vw, 1.35rem); margin-right: var(--espace-3); }
.bordereau-section .boutons { margin-top: var(--espace-7); }
@media (max-width: 599px) {
  .bordereau__colonnes, .bordereau__ligne { grid-template-columns: 2.6em minmax(0, 1fr) auto; }
  .bordereau__designation::after { display: none; }
}

/* entrée : les lignes s'écrivent l'une après l'autre, de gauche à droite.
   Un voile couleur papier couvre chaque ligne et se retire vers la droite
   (transform seulement : un clip-path par ligne coûtait des images au téléphone). */
.js .bordereau[data-apparition] .bordereau__ligne::before {
  content: "";
  position: absolute;
  inset: 0 0 -1px 0;
  z-index: 1;
  background-color: var(--fond);
  transform-origin: 100% 50%;
  pointer-events: none;
  animation: plan-voile-secours 0s linear 2.5s forwards;   /* secours si commun.js ne charge pas */
}
.js.apparition-prete .bordereau[data-apparition] .bordereau__ligne::before { animation: none; }
.js .bordereau[data-apparition].est-visible .bordereau__ligne::before {
  transform: scaleX(0);
  transition: transform .7s cubic-bezier(.65, 0, .35, 1) calc(.25s + var(--i, 0) * 90ms);
}
@keyframes plan-voile-secours { to { transform: scaleX(0); } }

/* --------------------------------------------------------------------------
   3. Cotes et cartouche (planches de btp/exemples.html)
   La capture est entourée de deux lignes de cote (largeur au-dessus,
   hauteur à droite) qui se tracent depuis leur milieu.
   -------------------------------------------------------------------------- */
.cotes { position: relative; padding: 30px 30px 0 0; }
.cote {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--texte-2);
  font-family: var(--police-mono);
  font-size: var(--t-mono-petit);
  font-weight: 500;
  letter-spacing: var(--interlettrage-mono);
  pointer-events: none;
}
/* la ligne de cote et ses deux traits d'attache (obliques, comme sur un plan) */
.cote::before {
  content: "";
  position: absolute;
  background-color: currentColor;
  opacity: .7;
  transition: transform .9s cubic-bezier(.65, 0, .35, 1);
}
.cote--largeur { top: 6px; left: 14px; right: 44px; height: 14px; }
.cote--largeur::before { left: 0; right: 0; top: 50%; height: 1px; }
.cote--hauteur { top: 44px; bottom: 14px; right: 6px; width: 14px; }
.cote--hauteur::before { top: 0; bottom: 0; left: 50%; width: 1px; }
.cote__bout { position: absolute; width: 9px; height: 1px; background-color: currentColor; transform: rotate(-45deg); }
.cote--largeur .cote__bout { top: 50%; }
.cote--largeur .cote__bout:first-child { left: -4px; }
.cote--largeur .cote__bout:last-of-type { right: -4px; }
.cote--hauteur .cote__bout { left: 2px; }
.cote--hauteur .cote__bout:first-child { top: -1px; }
.cote--hauteur .cote__bout:last-of-type { bottom: -1px; }
.cote__valeur { position: relative; padding: 0 8px; background-color: var(--fond); }
.cote--hauteur .cote__valeur { padding: 8px 0; writing-mode: vertical-rl; transform: rotate(180deg); }

/* le cartouche, en bas de la planche */
.cartouche {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: var(--espace-5);
  border: 1px solid var(--filet-fort);
  font-family: var(--police-mono);
  font-size: var(--t-mono-petit);
  letter-spacing: var(--interlettrage-mono);
  text-transform: uppercase;
}
.cartouche > div { display: grid; gap: 3px; padding: 8px 10px 7px; border-top: 1px solid var(--filet); border-left: 1px solid var(--filet); }
.cartouche > div:nth-child(-n + 2) { border-top: 0; }
.cartouche > div:nth-child(odd) { border-left: 0; }
.cartouche dt { color: var(--texte-2); }
.cartouche dd { margin: 0; color: var(--texte); font-weight: 500; }
@media (min-width: 640px) {
  .cartouche { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .cartouche > div:nth-child(-n + 4) { border-top: 0; }
  .cartouche > div:nth-child(odd) { border-left: 1px solid var(--filet); }
  .cartouche > div:first-child { border-left: 0; }
}

/* entrée : les cotes se tracent depuis le milieu, puis les valeurs s'écrivent.
   .cotes ne sert que de déclencheur : il ne s'efface pas lui-même (la capture a son rideau). */
.js .cotes[data-apparition] { opacity: 1; transform: none; animation: none; }
.js .cotes[data-apparition] .cote--largeur::before { transform: scaleX(0); }
.js .cotes[data-apparition] .cote--hauteur::before { transform: scaleY(0); }
.js .cotes[data-apparition] .cote__valeur,
.js .cotes[data-apparition] .cote__bout { opacity: 0; transition: opacity .4s var(--sortie-douce) .8s; }
.js .cotes[data-apparition].est-visible .cote::before { transform: none; transition-delay: .35s; }
.js .cotes[data-apparition].est-visible .cote__valeur,
.js .cotes[data-apparition].est-visible .cote__bout { opacity: 1; }
.js .cotes[data-apparition] .cote::before,
.js .cotes[data-apparition] .cote__valeur,
.js .cotes[data-apparition] .cote__bout { animation: plan-secours 0s linear 2.5s forwards; }
.js.apparition-prete .cotes[data-apparition] .cote::before,
.js.apparition-prete .cotes[data-apparition] .cote__valeur,
.js.apparition-prete .cotes[data-apparition] .cote__bout { animation: none; }
@media (max-width: 639px) {
  .cotes { padding: 26px 0 0; }
  .cote--hauteur { display: none; }
  .cote--largeur { right: 14px; }
}

@keyframes plan-secours { to { opacity: 1; transform: none; clip-path: inset(0 0 0 0); } }

/* --------------------------------------------------------------------------
   Mouvement réduit : tout est posé d'emblée
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .js .bon[data-apparition],
  .js .bon[data-apparition].est-visible { transform: none; }
  .js .bordereau[data-apparition] .bordereau__ligne::before { display: none; }
  .js .cotes[data-apparition] .cote::before { transform: none; transition: none; }
  .js .cotes[data-apparition] .cote__valeur,
  .js .cotes[data-apparition] .cote__bout { opacity: 1; transition: none; }
}
.mouvement-reduit .bon[data-apparition] { transform: none !important; }
.mouvement-reduit .bordereau .bordereau__ligne::before { display: none !important; }
.mouvement-reduit .cotes .cote::before { transform: none !important; transition: none; }
.mouvement-reduit .cotes .cote__valeur,
.mouvement-reduit .cotes .cote__bout { opacity: 1 !important; transition: none; }
