/* ============================================================
   Facturation électronique et formulaires en sections (refonte UI)
   S'appuie uniquement sur les jetons de generic/base.html
   (--brand-*, --gray-*, --color-*, --font-technical, --font-mono).
   Un état n'est jamais porté par la seule couleur : pictogramme + texte.
   ============================================================ */

/* --- Pastille d'état ------------------------------------------------ */
.fe-etat {
    display: inline-flex; align-items: center; gap: .35rem;
    padding: .2rem .6rem .2rem .45rem; border: 1px solid; border-radius: 999px;
    font-size: .78rem; font-weight: 600; line-height: 1.3; vertical-align: middle;
}
.fe-etat svg { width: 14px; height: 14px; flex: none; stroke-width: 2.2; }
.fe-etat--neutre { background: var(--gray-100); color: var(--gray-700); border-color: var(--gray-200); }
.fe-etat--actif  { background: var(--color-actif-bg); color: var(--color-actif); border-color: #b6d9f0; }
.fe-etat--info   { background: var(--color-info-bg); color: var(--color-info); border-color: #bae6fd; }
.fe-etat--succes { background: var(--color-success-bg); color: var(--color-success); border-color: #bbf7d0; }
.fe-etat--alerte { background: var(--color-warning-bg); color: var(--color-warning); border-color: #fde68a; }
.fe-etat--danger { background: var(--color-danger-bg); color: var(--color-danger); border-color: #fecaca; }

/* --- Rappel « mode préparation » (cadre pointillé .plan-frame) ------- */
.fe-hors-ligne {
    display: flex; gap: .7rem; align-items: flex-start;
    padding: .95rem 1rem .8rem; margin: .75rem 0 1rem;
    border-radius: var(--radius); font-size: .875rem; color: var(--gray-700);
}
.fe-hors-ligne > svg { flex: none; color: var(--brand-600); margin-top: .1rem; }
.fe-hors-ligne strong { display: block; color: var(--gray-900); font-weight: 600; }
/* L'étiquette du cadre prend le fond du conteneur (carte blanche ou page). */
.card .fe-hors-ligne.plan-frame::before, .fe-carte .fe-hors-ligne.plan-frame::before { background: #fff; }

/* --- Onglets facturation / file / e-reporting ------------------------ */
.fe-onglets {
    display: flex; gap: 1.5rem; margin: -.25rem 0 1.5rem;
    border-bottom: 1px solid var(--gray-200); overflow-x: auto; scrollbar-width: none;
}
.fe-onglets a {
    padding: .55rem 0; margin-bottom: -1px; white-space: nowrap;
    color: var(--gray-600); font-weight: 500; font-size: .9rem; text-decoration: none;
    border-bottom: 2px solid transparent;
}
.fe-onglets a:hover { color: var(--brand-700); border-bottom-color: var(--brand-200); }
.fe-onglets a[aria-current="page"] { color: var(--brand-700); font-weight: 600; border-bottom-color: var(--brand-600); }

/* --- En-tête de page -------------------------------------------------- */
.fe-entete { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: .75rem 1.5rem; margin-bottom: 1rem; }
.fe-entete h1 { margin: 0; }
.fe-entete__sous-titre { margin: .25rem 0 0; color: var(--gray-600); max-width: 68ch; }
.fe-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.fe-actions form { margin: 0; }

/* --- Cartes de section ------------------------------------------------ */
.fe-carte { background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 1.25rem 1.5rem; margin-bottom: 1.5rem; }
.fe-carte__entete { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem 1rem; margin-bottom: 1rem; }
.fe-carte__titre { font-family: var(--font-technical); font-size: 1.3rem; font-weight: 700; margin: 0; }
.fe-carte__sous-titre { font-size: 1rem; font-weight: 600; margin: 1.25rem 0 .5rem; }
@media (max-width: 575.98px) { .fe-carte { padding: 1rem; } }

/* Paires libellé / valeur */
.fe-dl { display: grid; grid-template-columns: minmax(8.5rem, max-content) 1fr; gap: .45rem 1.25rem; margin: 0; }
.fe-dl dt { font-weight: 500; color: var(--gray-600); font-size: .875rem; }
.fe-dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 575.98px) {
    .fe-dl { grid-template-columns: 1fr; gap: 0; }
    .fe-dl dd { margin-bottom: .6rem; }
}
.fe-code { font-family: var(--font-mono); font-size: .85em; font-variant-numeric: tabular-nums; }
.fe-montant { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* Liste de points à compléter / vérifications */
.fe-verifs { list-style: none; padding: 0; margin: .25rem 0 0; }
.fe-verifs li { display: flex; gap: .5rem; align-items: flex-start; padding: .3rem 0; font-size: .9rem; }
.fe-verifs li svg { flex: none; width: 16px; height: 16px; margin-top: .15rem; color: var(--color-warning); stroke-width: 2; }
.fe-verifs--ok li svg { color: var(--color-success); }

/* --- Parcours façon ligne de cote (élément signature) ---------------- */
.fe-parcours {
    list-style: none; margin: .25rem 0 1.25rem; padding: 0 0 0 8px;
    display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
}
.fe-parcours__etape { position: relative; display: flex; flex-direction: column; gap: .5rem; padding-right: .75rem; }
/* Segment de cote vers l'étape suivante : plein si l'étape est franchie, pointillé sinon. */
.fe-parcours__etape::before {
    content: ""; position: absolute; top: 10px; left: 22px; right: 0;
    border-top: 2px dashed var(--gray-300);
}
.fe-parcours__etape--fait::before { border-top-style: solid; border-top-color: var(--brand-600); }
.fe-parcours__etape:last-child::before { content: none; }
/* Traits d'extrémité, comme les bornes d'une cote de plan. */
.fe-parcours__etape:first-child .fe-parcours__repere::before,
.fe-parcours__etape:last-child .fe-parcours__repere::after {
    content: ""; position: absolute; top: -6px; height: 30px; border-left: 1.5px solid var(--gray-400);
}
.fe-parcours__etape:first-child .fe-parcours__repere::before { left: -8px; }
.fe-parcours__etape:last-child .fe-parcours__repere::after { right: -8px; }
.fe-parcours__repere {
    position: relative; z-index: 1; width: 22px; height: 22px; border-radius: 50%; flex: none;
    display: inline-flex; align-items: center; justify-content: center;
    border: 2px dashed var(--gray-400); background: #fff;
    font-weight: 800; font-size: .8rem; line-height: 1;
}
.fe-parcours__repere svg { width: 13px; height: 13px; stroke-width: 3; }
.fe-parcours__etape--fait .fe-parcours__repere { border: 2px solid var(--brand-600); background: var(--brand-600); color: #fff; }
.fe-parcours__etape--actuel .fe-parcours__repere { border: 2px solid var(--brand-600); background: var(--brand-600); box-shadow: inset 0 0 0 4px #fff; }
.fe-parcours__etape--bloque .fe-parcours__repere { border: 2px solid var(--color-warning); background: var(--color-warning-bg); color: var(--color-warning); }
.fe-parcours__texte { display: flex; flex-direction: column; gap: .1rem; min-width: 0; }
.fe-parcours__libelle { font-size: .84rem; font-weight: 600; color: var(--gray-700); line-height: 1.25; }
.fe-parcours__etape--a_venir .fe-parcours__libelle { color: var(--gray-label); font-weight: 500; }
.fe-parcours__etape--actuel .fe-parcours__libelle { color: var(--gray-900); }
.fe-parcours__etape--bloque .fe-parcours__libelle { color: var(--color-warning); }
.fe-parcours__detail { font-family: var(--font-mono); font-size: .72rem; color: var(--gray-label); line-height: 1.3; }
/* Mobile : la cote devient verticale, chaque étape sur une ligne. */
@media (max-width: 575.98px) {
    .fe-parcours { grid-auto-flow: row; padding: 8px 0 0; }
    .fe-parcours__etape { flex-direction: row; gap: .75rem; padding: 0 0 .9rem; }
    .fe-parcours__etape::before { top: 22px; bottom: 0; left: 10px; right: auto; border-top: 0; border-left: 2px dashed var(--gray-300); }
    .fe-parcours__etape--fait::before { border-left-style: solid; border-left-color: var(--brand-600); }
    .fe-parcours__etape:first-child .fe-parcours__repere::before,
    .fe-parcours__etape:last-child .fe-parcours__repere::after {
        left: -5px; right: auto; height: 0; width: 28px; border-left: 0; border-top: 1.5px solid var(--gray-400);
    }
    .fe-parcours__etape:first-child .fe-parcours__repere::before { top: -8px; }
    .fe-parcours__etape:last-child .fe-parcours__repere::after { top: auto; bottom: -8px; }
    .fe-parcours__texte { padding-top: .1rem; }
}

/* --- Transmissions et journal ---------------------------------------- */
.fe-envois { list-style: none; padding: 0; margin: 0; }
.fe-envois > li { padding: .75rem 0; border-top: 1px solid var(--gray-100); }
.fe-envois > li:first-child { border-top: 0; padding-top: 0; }
.fe-meta { display: flex; flex-wrap: wrap; gap: .15rem 1rem; margin-top: .35rem; font-size: .82rem; color: var(--gray-600); }
.fe-erreur {
    margin-top: .5rem; padding: .5rem .75rem; border-left: 3px solid var(--color-danger);
    background: var(--color-danger-bg); color: var(--color-danger); font-size: .85rem;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.fe-erreur--alerte { border-left-color: var(--color-warning); background: var(--color-warning-bg); color: var(--color-warning); }

.fe-journal { list-style: none; padding: 0; margin: .5rem 0 0 .35rem; border-left: 2px solid var(--gray-200); }
.fe-journal li { position: relative; padding: 0 0 .85rem 1rem; font-size: .875rem; }
.fe-journal li::before {
    content: ""; position: absolute; left: -6px; top: .3rem; width: 10px; height: 10px;
    border-radius: 50%; background: #fff; border: 2px solid var(--brand-500);
}
.fe-journal time { font-family: var(--font-mono); font-size: .75rem; color: var(--gray-label); display: block; }

/* Blocs repliables (journal, saisie manuelle) */
.fe-repli { border-top: 1px solid var(--gray-100); margin-top: 1rem; padding-top: .75rem; }
.fe-repli > summary { cursor: pointer; font-weight: 600; color: var(--brand-700); }
.fe-repli > summary .text-muted { font-weight: 400; }
.fe-repli[open] > summary { margin-bottom: .5rem; }

/* --- Compteurs de la file -------------------------------------------- */
.fe-compteurs { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1.5rem; padding: 0; list-style: none; }
.fe-compteur {
    display: flex; flex-direction: column; gap: .35rem; height: 100%;
    background: #fff; border: 1px solid var(--gray-200); border-top: 3px solid var(--gray-300);
    border-radius: var(--radius); padding: .75rem .9rem;
}
.fe-compteur__nombre { font-family: var(--font-mono); font-size: 1.5rem; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; color: var(--gray-900); }
.fe-compteur__libelle { display: flex; gap: .35rem; align-items: flex-start; font-size: .8rem; color: var(--gray-600); line-height: 1.3; }
.fe-compteur__libelle svg { width: 14px; height: 14px; flex: none; margin-top: .05rem; }
.fe-compteur--alerte { border-top-color: var(--color-warning); }
.fe-compteur--danger { border-top-color: var(--color-danger); }
.fe-compteur--info { border-top-color: var(--color-info); }
.fe-compteur--succes { border-top-color: var(--color-success); }
.fe-compteur--vide .fe-compteur__nombre { color: var(--gray-label); }

/* --- Tableaux qui deviennent des cartes sur mobile ------------------- */
.fe-table { background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius); overflow: hidden; margin-bottom: 1.5rem; }
.fe-table .table { margin: 0; }
.fe-table .table > :not(caption) > * > * { padding: .7rem .9rem; }
.fe-table .table > thead { background: var(--gray-50); }
.fe-table .table > tfoot td { font-weight: 600; border-top: 2px solid var(--gray-200); border-bottom: 0; }
.fe-table .etat-vide { padding: 2rem 1rem; }
@media (max-width: 767.98px) {
    table.table.fe-table-cartes, table.table.fe-table-cartes > tbody, table.table.fe-table-cartes > tfoot,
    table.table.fe-table-cartes tr, table.table.fe-table-cartes td { display: block; white-space: normal; overflow: visible; }
    table.table.fe-table-cartes > thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    table.table.fe-table-cartes > tbody > tr, table.table.fe-table-cartes > tfoot > tr { padding: .75rem .9rem; border-bottom: 1px solid var(--gray-200); }
    table.table.fe-table-cartes > tbody > tr > td, table.table.fe-table-cartes > tfoot > tr > td { border: 0; padding: .2rem 0; }
    table.table.fe-table-cartes td[data-label]::before {
        content: attr(data-label); display: block; font-size: .72rem; font-weight: 600; color: var(--gray-label);
    }
    table.table.fe-table-cartes td.fe-montant { text-align: left; }
    table.table.fe-table-cartes td:empty { display: none; }
}

/* --- Formulaires en sections ------------------------------------------ */
.formulaire-sections fieldset { margin: 1.5rem 0 0; padding: 1.5rem 0 0; border-top: 1px solid var(--gray-200); }
.formulaire-sections fieldset:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.formulaire-sections legend {
    font-family: var(--font-technical); font-size: 1.2rem; font-weight: 700; color: var(--gray-900);
    margin-bottom: .25rem; float: none; width: auto;
}
.formulaire-sections .fieldset-aide { color: var(--gray-600); font-size: .875rem; margin: 0 0 1rem; max-width: 72ch; }
.formulaire-sections .form-text { max-width: 72ch; }
.formulaire-legende-requis { font-size: .82rem; color: var(--gray-600); margin-bottom: 1.25rem; }
.formulaire-actions {
    display: flex; flex-wrap: wrap; gap: .5rem; align-items: center;
    margin-top: 1.75rem; padding-top: 1.25rem; border-top: 1px solid var(--gray-200);
}
/* Section conditionnelle repliable (ex. secteur public) : toujours accessible, jamais supprimée. */
.formulaire-sections details.section-conditionnelle { margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid var(--gray-200); }
.formulaire-sections details.section-conditionnelle > summary {
    cursor: pointer; display: flex; flex-wrap: wrap; align-items: baseline; gap: .25rem .6rem; list-style: none;
}
.formulaire-sections details.section-conditionnelle > summary::-webkit-details-marker { display: none; }
.formulaire-sections details.section-conditionnelle > summary::before {
    content: "+"; font-family: var(--font-mono); font-weight: 600; color: var(--brand-600); width: 1rem;
}
.formulaire-sections details.section-conditionnelle[open] > summary::before { content: "−"; }
.formulaire-sections details.section-conditionnelle .section-titre {
    font-family: var(--font-technical); font-size: 1.2rem; font-weight: 700; color: var(--gray-900);
}
.formulaire-sections details.section-conditionnelle .section-condition { font-size: .85rem; color: var(--gray-600); }
.formulaire-sections details.section-conditionnelle[open] > summary { margin-bottom: .75rem; }
.formulaire-sections details.section-conditionnelle > fieldset { margin-top: 0; padding-top: 0; border-top: 0; }
.note-conditionnelle {
    display: flex; gap: .5rem; align-items: flex-start; font-size: .875rem; color: var(--gray-600);
    background: var(--gray-50); border: 1px dashed var(--gray-300); border-radius: var(--radius-sm);
    padding: .6rem .75rem; margin-bottom: 1rem;
}
.note-conditionnelle svg { flex: none; width: 16px; height: 16px; margin-top: .1rem; color: var(--brand-600); }

/* Résumé des erreurs */
.resume-erreurs { border-left: 3px solid var(--color-danger); }
.resume-erreurs:focus { outline: 2px solid var(--color-danger); outline-offset: 2px; }
.resume-erreurs ul { margin: .35rem 0 0; padding-left: 1.1rem; }
.resume-erreurs a { color: var(--color-danger); font-weight: 600; }

/* Formulaires en ligne (saisie de statut, rattachement, période) */
.fe-form-ligne { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; align-items: end; }
.fe-form-ligne .form-label { margin-bottom: .25rem; }
.fe-form-ligne__large { grid-column: 1 / -1; }

/* --- Liste d'actions « À compléter » (fiche entreprise) -------------- */
.fe-actions-liste { list-style: none; padding: 0; margin: .5rem 0 0; border: 1px solid var(--gray-200); border-radius: var(--radius); }
.fe-action-ligne {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem 1rem;
    padding: .75rem 1rem; border-top: 1px solid var(--gray-200); font-size: .9rem;
}
.fe-action-ligne:first-child { border-top: 0; }
.fe-action-ligne__texte { display: flex; gap: .55rem; align-items: flex-start; flex: 1 1 22rem; min-width: 0; color: var(--gray-700); }
.fe-action-ligne__texte svg { flex: none; width: 17px; height: 17px; margin-top: .15rem; color: var(--color-warning); stroke-width: 2; }
.fe-action-ligne__bouton { flex: none; }
.fe-action-ligne__note { display: inline-flex; gap: .35rem; align-items: center; font-size: .82rem; color: var(--gray-600); }
.fe-action-ligne__note svg { width: 14px; height: 14px; }
/* Saisie sur place : le formulaire occupe toute la largeur sous le texte. */
.fe-action-ligne--saisie { background: var(--color-warning-bg); }
.fe-action-ligne__saisie {
    flex: 1 1 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 12rem)) auto; gap: .75rem; align-items: start;
    padding-left: 1.6rem;
}
.fe-action-ligne__saisie .form-label { margin-bottom: .2rem; }
.fe-action-ligne__saisie > div:last-child { align-self: end; }
@media (max-width: 575.98px) {
    .fe-action-ligne__saisie { grid-template-columns: 1fr 1fr; padding-left: 0; }
    .fe-action-ligne__saisie > div:last-child { grid-column: 1 / -1; }
}
