/* ==========================================================================
   Interface v2 — section « Devis & Factures » (25/08/2026)
   ==========================================================================
   Compagnon de ui-v2-facturation.js. Tout est scopé html.ui-v2 et préfixé
   v2fa- (fa comme facturation) : sans la v2, ce fichier ne change RIEN.
   Jetons de design-tokens.css (thème clair posé par la coquille) et
   variables de ui-v2.css (--v2-bordure-douce). Règles du cahier : cartes
   blanches radius 12, boutons/champs radius 8, pastilles radius 4, grille
   8 pt, cibles 44 px, un seul bouton primaire cuivre par écran, H1 PT Serif.

   Deux parties : le dessin v2 de l'écran Historique (tableau + panneau), et
   la peau v2fa-v1 qui éclaircit les sous-écrans restés en logique v1 —
   même patron que la peau v2ap-v1 des appels. Dans la peau, les couleurs
   des badges v1 sont reprises par SÉLECTEURS D'ATTRIBUT ([class*="signe"]…)
   et jamais par leur nom de classe complet : la sous-chaîne interdite ne
   doit apparaître nulle part dans ces deux fichiers.
   ========================================================================== */

/* ---------------------------------------------- onglets soulignés cuivre */
/* Dix onglets : la barre défile horizontalement plutôt que de replier —
   un onglet invisible est un écran perdu. */
html.ui-v2 .v2fa-onglets {
  display: flex;
  gap: 22px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--v2-bordure-douce);
  overflow-x: auto;
  scrollbar-width: thin;
}
html.ui-v2 .v2fa-onglets a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 2px;
  font-size: 14px;
  color: var(--texte-attenue);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  flex: none;
}
html.ui-v2 .v2fa-onglets a:hover { color: var(--sobria-nuit); }
html.ui-v2 .v2fa-onglets a.v2fa-onglet-actif {
  color: var(--sobria-nuit);
  font-weight: 600;
  border-bottom-color: var(--sobria-cuivre);
}

/* ------------------------------------------------------- en-tête d'écran */
html.ui-v2 .v2fa-entete {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
html.ui-v2 .v2fa-entete h1 {
  margin: 0;
  font-family: var(--font-head, "PT Serif", Georgia, serif);
  font-size: 28px;
  line-height: 1.2;
  color: var(--sobria-nuit);
}
html.ui-v2 .v2fa-sous-titre {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--texte-attenue);
  max-width: 64ch;
}
html.ui-v2 .v2fa-entete-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* ----------------------------------------------------------------- boutons */
/* Un seul primaire cuivre par écran (« + Nouveau devis ») ; les autres
   restent blancs bordés. */
html.ui-v2 .v2fa-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--v2-bordure-douce);
  border-radius: 8px;
  background: var(--fond-surface, #fff);
  color: var(--texte);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}
html.ui-v2 .v2fa-btn:hover { background: #faf8f3; }
html.ui-v2 .v2fa-btn svg { width: 18px; height: 18px; flex: none; }
html.ui-v2 .v2fa-btn-primaire {
  border: 0;
  background: var(--sobria-cuivre);
  color: #fff;
  font-weight: 600;
}
html.ui-v2 .v2fa-btn-primaire:hover { background: #b06c33; }
html.ui-v2 .v2fa-btn-sm { min-height: 36px; padding: 0 10px; font-size: 13px; }
html.ui-v2 .v2fa-btn-sm svg { width: 15px; height: 15px; }

/* ---------------------------------------------------------------- cartes */
html.ui-v2 .v2fa-carte {
  background: var(--fond-surface, #fff);
  border: 1px solid var(--v2-bordure-douce);
  border-radius: 12px;
  box-shadow: var(--ombre-1, 0 1px 2px rgba(20, 33, 59, .06));
  overflow: hidden;
}
html.ui-v2 .v2fa-vide {
  padding: 32px 24px;
  text-align: center;
  color: var(--texte-attenue);
  font-size: 14px;
  line-height: 1.6;
}

/* ------------------------------------------------------------------ texte */
html.ui-v2 .v2fa-meta { font-size: 12.5px; color: var(--texte-attenue); }
html.ui-v2 p.v2fa-meta { margin: 4px 0; }
html.ui-v2 .v2fa-attenue { color: var(--texte-attenue); }

/* -------------------------------------------------------------- pastilles */
/* Radius 4, pastel — toujours un mot, jamais un pictogramme seul. */
html.ui-v2 .v2fa-pastille {
  display: inline-block;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  padding: 4px 8px;
  white-space: nowrap;
}
html.ui-v2 .v2fa-pastille-vert   { background: #eaf5ee; color: #3f8f5f; }
html.ui-v2 .v2fa-pastille-ambre  { background: #fdf3e3; color: #9a6b1a; }
html.ui-v2 .v2fa-pastille-bleu   { background: #eef3fb; color: #2f5fa8; }
html.ui-v2 .v2fa-pastille-rouge  { background: #fbeeec; color: #a3392b; }
html.ui-v2 .v2fa-pastille-neutre { background: #efeeec; color: #676d7c; }

/* ------------------------------------------------------------------ tableau */
html.ui-v2 .v2fa-tableau {
  width: 100%;
  border-collapse: collapse;
}
html.ui-v2 .v2fa-tableau th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--texte-attenue);
  padding: 12px;
  border-bottom: 1px solid var(--v2-bordure-douce);
  white-space: nowrap;
}
html.ui-v2 .v2fa-tableau td {
  padding: 10px 12px;
  border-top: 1px solid var(--v2-bordure-douce);
  font-size: 14px;
  vertical-align: middle;
}
html.ui-v2 .v2fa-tableau tbody tr:first-child td { border-top: 0; }
html.ui-v2 .v2fa-tableau tbody tr.v2fa-ligne { cursor: pointer; }
html.ui-v2 .v2fa-tableau tbody tr.v2fa-ligne:hover { background: #faf8f3; }
html.ui-v2 .v2fa-tableau tbody tr:focus-visible {
  outline: 2px solid var(--sobria-cuivre);
  outline-offset: -2px;
}
html.ui-v2 .v2fa-tableau a { color: var(--cuivre-clair, #a05f27); }
html.ui-v2 .v2fa-c-numero { white-space: nowrap; font-weight: 600; color: var(--sobria-nuit); }
html.ui-v2 .v2fa-c-num { text-align: right; white-space: nowrap; font-weight: 600; }
html.ui-v2 .v2fa-c-date { white-space: nowrap; }
html.ui-v2 .v2fa-c-objet {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--texte-attenue);
}
html.ui-v2 .v2fa-c-actions {
  white-space: nowrap;
  text-align: right;
}
html.ui-v2 .v2fa-c-actions .v2fa-btn { margin-left: 6px; }

/* -------------------------------------------------------- panneau latéral */
html.ui-v2 .v2fa-panneau {
  position: fixed;
  top: calc(var(--banniere-env-h, 0px) + var(--v2-topbar-hauteur, 64px));
  right: 0;
  bottom: 0;
  width: 440px;
  max-width: 100vw;
  background: var(--fond-surface, #fff);
  border-left: 1px solid var(--v2-bordure-douce);
  box-shadow: -12px 0 32px rgba(20, 33, 59, .12);
  transform: translateX(105%);
  transition: transform var(--duree-moyenne, 200ms) var(--courbe, ease-out);
  z-index: 70;                       /* sous les modales, sur le contenu */
  overflow-y: auto;
  padding: 24px;
}
html.ui-v2 .v2fa-panneau.v2fa-ouvert { transform: none; }
html.ui-v2 .v2fa-panneau-fermer {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--texte);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
html.ui-v2 .v2fa-panneau-fermer:hover { background: var(--fond-survol, #efeade); }
html.ui-v2 .v2fa-panneau-fermer svg { width: 20px; height: 20px; }
html.ui-v2 .v2fa-panneau h2 {
  margin: 0 44px 2px 0;
  font-size: 20px;
  font-family: var(--font-head, "PT Serif", Georgia, serif);
  color: var(--sobria-nuit);
}
html.ui-v2 .v2fa-panneau-sous {
  font-size: 13px;
  color: var(--texte-attenue);
  margin-bottom: 10px;
}
html.ui-v2 .v2fa-panneau-sous a { color: var(--cuivre-clair, #a05f27); }
html.ui-v2 .v2fa-panneau-pastilles {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
html.ui-v2 .v2fa-panneau-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
html.ui-v2 .v2fa-panneau-bloc {
  border-top: 1px solid var(--v2-bordure-douce);
  padding: 14px 0;
}
html.ui-v2 .v2fa-panneau-bloc h3 {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--texte-attenue);
}
html.ui-v2 .v2fa-dl {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(110px, auto) 1fr;
  gap: 6px 12px;
  font-size: 13px;
}
html.ui-v2 .v2fa-dl dt { color: var(--texte-attenue); }
html.ui-v2 .v2fa-dl dd { margin: 0; color: var(--texte); overflow-wrap: anywhere; }
html.ui-v2 .v2fa-prestation { padding: 6px 0; }
html.ui-v2 .v2fa-prestation + .v2fa-prestation { border-top: 1px dashed var(--v2-bordure-douce); }
html.ui-v2 .v2fa-prestation-nom { font-size: 13.5px; font-weight: 600; color: var(--sobria-nuit); }
html.ui-v2 .v2fa-panneau-lien {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  font-size: 13px;
  font-weight: 600;
  color: var(--cuivre-clair, #a05f27);
  text-decoration: none;
}
html.ui-v2 .v2fa-panneau-lien:hover { text-decoration: underline; }
html.ui-v2 .v2fa-panneau-lien svg { width: 14px; height: 14px; }

/* --------------------------------------------------------- accessibilité */
html.ui-v2 .v2fa-btn:focus-visible,
html.ui-v2 .v2fa-onglets a:focus-visible,
html.ui-v2 .v2fa-panneau-fermer:focus-visible {
  outline: 2px solid var(--sobria-cuivre);
  outline-offset: 2px;
}

/* ==========================================================================
   Peau v2fa-v1 — restyle LÉGER des sous-écrans restés en logique v1
   (Honoraires, Dépenses, Objectifs, Mandats, Récurrents, Envois programmés,
   Catalogue, Facturation électronique, Réglages société). Les variables
   inversées de ui-v2.css rendent déjà ces écrans clairs ; ici on aligne
   seulement titres, cartes, tableaux, champs et badges sur le dessin v2 —
   la logique et la structure v1 ne bougent pas. Patron : v2ap-v1 (appels).
   ========================================================================== */
html.ui-v2 #main.v2fa-v1 .page-head h1 {
  font-family: var(--font-head, "PT Serif", Georgia, serif);
  font-size: 28px;
  color: var(--sobria-nuit);
}
html.ui-v2 #main.v2fa-v1 .card,
html.ui-v2 #main.v2fa-v1 .stat-card {
  background: var(--fond-surface, #fff);
  border: 1px solid var(--v2-bordure-douce);
  border-radius: 12px;
  box-shadow: var(--ombre-1, 0 1px 2px rgba(20, 33, 59, .06));
}
html.ui-v2 #main.v2fa-v1 .card h2 { color: var(--sobria-nuit); font-size: 16px; }
html.ui-v2 #main.v2fa-v1 .stat-card .num {
  font-family: var(--font-head, "PT Serif", Georgia, serif);
  color: var(--sobria-nuit);
}
/* Les accents chiffrés reprennent les encres lisibles sur blanc (mesure du
   07/08 : les jetons sombres ne tiennent pas 4,5:1 ici). */
html.ui-v2 #main.v2fa-v1 .stat-card.accent .num { color: #a05f27; }
html.ui-v2 #main.v2fa-v1 .stat-card.danger .num { color: #a3392b; }
html.ui-v2 #main.v2fa-v1 .stat-card.warn .num { color: #9a6b1a; }

html.ui-v2 #main.v2fa-v1 .list-table {
  background: var(--fond-surface, #fff);
  border: 1px solid var(--v2-bordure-douce);
  border-radius: 12px;
}
html.ui-v2 #main.v2fa-v1 .list-table th,
html.ui-v2 #main.v2fa-v1 .list-table td { border-bottom-color: var(--v2-bordure-douce); }
/* Le survol v1 (blanc translucide) est invisible sur fond blanc. */
html.ui-v2 #main.v2fa-v1 .list-row:hover { background: rgba(20, 33, 59, .04); }
html.ui-v2 #main.v2fa-v1 .picker-row:hover { background: rgba(20, 33, 59, .04); }

html.ui-v2 #main.v2fa-v1 .toolbar select,
html.ui-v2 #main.v2fa-v1 .toolbar input {
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--v2-bordure-douce);
  border-radius: 8px;
  background: var(--fond-surface, #fff);
  color: var(--texte);
}
html.ui-v2 #main.v2fa-v1 .btn {
  min-height: 36px;
  border-radius: 8px;
  border: 1px solid var(--v2-bordure-douce);
  background: var(--fond-surface, #fff);
  color: var(--texte);
}
html.ui-v2 #main.v2fa-v1 .btn:hover { background: #faf8f3; filter: none; }
html.ui-v2 #main.v2fa-v1 .btn-primary {
  border: 0;
  background: var(--sobria-cuivre);
  color: #fff;
  font-weight: 600;
}
html.ui-v2 #main.v2fa-v1 .btn-primary:hover { background: #b06c33; }
html.ui-v2 #main.v2fa-v1 .btn-danger {
  background: transparent;
  border-color: #d8b6b0;
  color: #a3392b;
}
html.ui-v2 #main.v2fa-v1 .btn-danger:hover { background: #fbeeec; }

/* Badges v1 → pastilles pastel. Sélecteurs d'attribut à dessein : la
   sous-chaîne interdite (voir l'en-tête) ne doit pas s'écrire ici, et ces
   classes appartiennent au balisage v1, qu'on ne modifie pas. */
html.ui-v2 #main.v2fa-v1 .badge {
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
  background: #efeeec;
  color: #676d7c;
}
html.ui-v2 #main.v2fa-v1 .badge[class*="signe"],
html.ui-v2 #main.v2fa-v1 .badge[class*="-ok"] { background: #eaf5ee; color: #3f8f5f; }
html.ui-v2 #main.v2fa-v1 .badge[class*="envoye"],
html.ui-v2 #main.v2fa-v1 .badge[class*="warn"] { background: #fdf3e3; color: #9a6b1a; }
html.ui-v2 #main.v2fa-v1 .badge[class*="info"] { background: #eef3fb; color: #2f5fa8; }
html.ui-v2 #main.v2fa-v1 .badge[class*="urgente"],
html.ui-v2 #main.v2fa-v1 .badge[class*="danger"] { background: #fbeeec; color: #a3392b; }
html.ui-v2 #main.v2fa-v1 .badge[class*="brouillon"] { background: #efeeec; color: #676d7c; }

/* Jauges et graphiques v1 : rails clairs, barres cuivre inchangées. */
html.ui-v2 #main.v2fa-v1 .obj-bar {
  background: var(--sobria-creme, #F4F1E9);
  border: 1px solid var(--v2-bordure-douce);
}
html.ui-v2 #main.v2fa-v1 .obj-fill.done { background: #3f8f5f; }
html.ui-v2 #main.v2fa-v1 .pf-col.empty .pf-bar-wrap { border-bottom-color: var(--v2-bordure-douce); }
html.ui-v2 #main.v2fa-v1 .empty,
html.ui-v2 #main.v2fa-v1 .loading { color: var(--texte-attenue); }

/* ---------------------------------------------------------------- mobile */
@media (max-width: 767px) {
  html.ui-v2 .v2fa-entete { align-items: flex-start; flex-direction: column; }
  html.ui-v2 .v2fa-entete h1 { font-size: 24px; }
  html.ui-v2 .v2fa-onglets { gap: 16px; }

  /* Tableau → cartes empilées : chaque ligne devient une fiche, les
     cellules chiffrées annoncent leur libellé (data-th), les actions
     restent des cibles de 44 px. */
  html.ui-v2 .v2fa-tableau thead { display: none; }
  html.ui-v2 .v2fa-tableau,
  html.ui-v2 .v2fa-tableau tbody,
  html.ui-v2 .v2fa-tableau tr,
  html.ui-v2 .v2fa-tableau td { display: block; }
  html.ui-v2 .v2fa-tableau tbody tr {
    padding: 12px 16px;
    border-top: 1px solid var(--v2-bordure-douce);
  }
  html.ui-v2 .v2fa-tableau tbody tr:first-child { border-top: 0; }
  html.ui-v2 .v2fa-tableau td { padding: 2px 0; border: 0; }
  html.ui-v2 .v2fa-c-num, html.ui-v2 .v2fa-c-actions { text-align: left; }
  html.ui-v2 .v2fa-c-objet { max-width: none; white-space: normal; }
  html.ui-v2 .v2fa-c-num::before,
  html.ui-v2 .v2fa-c-date::before {
    content: attr(data-th) " : ";
    font-size: 12px;
    font-weight: 400;
    color: var(--texte-attenue);
  }
  html.ui-v2 .v2fa-c-type, html.ui-v2 .v2fa-c-statut { display: inline-block; margin-right: 6px; }
  html.ui-v2 .v2fa-c-actions { margin-top: 8px; }
  html.ui-v2 .v2fa-c-actions .v2fa-btn { margin: 0 6px 6px 0; min-height: 44px; }

  /* Le panneau devient une feuille plein écran. */
  html.ui-v2 .v2fa-panneau {
    top: var(--banniere-env-h, 0px);
    width: 100vw;
    border-left: 0;
    z-index: 80;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  }
}
