/* Marges & Prix de revient — styles (mobile d'abord, puis tablette et PC) */
:root {
  --bleu: #1f3a5f;
  --bleu-clair: #2c5282;
  --fond: #f4f6fa;
  --carte: #ffffff;
  --bordure: #e3e8ef;
  --texte: #1b2430;
  --texte-doux: #6b7785;
  --vert: #2fb36d;
  --vert-fond: #dcf5e7;
  --orange: #f2a33a;
  --orange-fond: #feefd9;
  --rouge: #e5484d;
  --rouge-fond: #fde4e4;
  --simule: #5b8def;
  --simule-fond: #e9f0fe;
  --hauteur-nav: 62px;
  --bs-primary: #1f3a5f;
  --bs-primary-rgb: 31, 58, 95;
  --bs-link-color: #2c5282;
  --bs-link-color-rgb: 44, 82, 130;
}
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--fond);
  color: var(--texte);
  font-size: 15px;
  padding-bottom: calc(var(--hauteur-nav) + env(safe-area-inset-bottom) + 12px);
}
a { text-decoration: none; }
.btn-primary { --bs-btn-bg: var(--bleu); --bs-btn-border-color: var(--bleu); --bs-btn-hover-bg: var(--bleu-clair); --bs-btn-hover-border-color: var(--bleu-clair); --bs-btn-active-bg: #172c48; --bs-btn-disabled-bg: #8aa0bb; --bs-btn-disabled-border-color: #8aa0bb; }
.btn-outline-primary { --bs-btn-color: var(--bleu); --bs-btn-border-color: var(--bleu); --bs-btn-hover-bg: var(--bleu); --bs-btn-hover-border-color: var(--bleu); }
.form-control, .form-select { font-size: 16px; } /* évite le zoom automatique sur iPhone */
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.texte-doux { color: var(--texte-doux); }
.petit { font-size: .78rem; }

/* ---- En-tête ---- */
.entete {
  position: sticky; top: 0; z-index: 1030;
  background: var(--bleu); color: #fff;
  padding-top: env(safe-area-inset-top);
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.entete-contenu { max-width: 1400px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .5rem .9rem; }
.marque { display: flex; align-items: center; gap: .55rem; color: #fff; flex: 0 0 auto; }
.marque span { display: flex; flex-direction: column; line-height: 1.1; }
.marque small { opacity: .7; font-size: .72rem; }
.maj { font-size: .75rem; background: rgba(255,255,255,.14); padding: .2rem .55rem; border-radius: 99px; white-space: nowrap; }
.btn-entete { color: #fff; font-size: 1.6rem; padding: 0 .25rem; border: 0; }
.btn-entete:hover, .btn-entete:focus { color: #dbe6f5; }
.nav-large { display: none; }
@media (min-width: 992px) {
  .nav-large { display: flex; gap: .2rem; flex: 1; }
  .nav-large a { color: rgba(255,255,255,.75); padding: .4rem .75rem; border-radius: 8px; font-size: .9rem; display: flex; gap: .4rem; align-items: center; }
  .nav-large a:hover { color: #fff; background: rgba(255,255,255,.08); }
  .nav-large a.actif { color: #fff; background: rgba(255,255,255,.16); font-weight: 600; }
}

.contenu { max-width: 1400px; margin: 0 auto; padding: .9rem .9rem 1rem; }
.contenu-etroit { max-width: 760px; }
.titre-page { font-size: 1.25rem; font-weight: 700; color: var(--bleu); margin-bottom: .8rem; }
.titre-bloc { font-size: .95rem; font-weight: 700; color: var(--bleu); margin: 0 0 .6rem; }
.lien-retour { display: inline-block; margin-bottom: .5rem; font-size: .9rem; }
.entete-page { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: space-between; margin-bottom: .8rem; }
.entete-page .titre-page { margin: 0; }

/* ---- Barre de navigation basse (téléphone) ---- */
.barre-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030;
  display: flex; justify-content: space-around;
  background: #fff; border-top: 1px solid var(--bordure);
  height: calc(var(--hauteur-nav) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 10px rgba(0,0,0,.05);
}
.barre-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--texte-doux); font-size: .68rem; gap: 2px; }
.barre-nav a i { font-size: 1.3rem; }
.barre-nav a.actif { color: var(--bleu); font-weight: 700; }
@media (min-width: 992px) {
  .barre-nav { display: none; }
  body { padding-bottom: 1.5rem; }
}

/* ---- Blocs ---- */
.carte-bloc { background: var(--carte); border: 1px solid var(--bordure); border-radius: 14px; padding: .9rem; margin-bottom: .9rem; }
.carte-bloc > .titre-bloc:first-child { margin-top: 0; }
.grille-2 { display: grid; gap: .9rem; }
@media (min-width: 992px) { .grille-2 { grid-template-columns: 1fr 1fr; align-items: start; } .grille-2-1 { grid-template-columns: 2fr 1fr; } }

.recherche { position: relative; }
.recherche i { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--texte-doux); }
.recherche input { padding-left: 2.3rem; border-radius: 12px; height: 44px; }

/* ---- Indicateurs ---- */
.grille-kpi { display: grid; grid-template-columns: repeat(2, 1fr); gap: .65rem; margin-bottom: .9rem; }
@media (min-width: 900px) { .grille-kpi { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--carte); border: 1px solid var(--bordure); border-radius: 14px; padding: .75rem .8rem; display: flex; flex-direction: column; min-width: 0; }
.kpi-libelle { font-size: .72rem; color: var(--texte-doux); text-transform: uppercase; letter-spacing: .02em; }
.kpi-valeur { font-size: 1.35rem; font-weight: 800; color: var(--bleu); line-height: 1.25; margin: .15rem 0; overflow-wrap: anywhere; }
.kpi-detail { font-size: .72rem; color: var(--texte-doux); }
.kpi.principal { background: linear-gradient(135deg, var(--bleu), var(--bleu-clair)); border: 0; }
.kpi.principal .kpi-libelle, .kpi.principal .kpi-detail { color: rgba(255,255,255,.8); }
.kpi.principal .kpi-valeur { color: #fff; }
.kpi.danger { border-left: 4px solid var(--rouge); }
.kpi.danger .kpi-valeur { color: var(--rouge); }

/* ---- Pastilles de statut ---- */
.pastille { display: inline-flex; align-items: center; gap: .35rem; font-size: .72rem; font-weight: 600; padding: .2rem .55rem; border-radius: 99px; white-space: nowrap; background: #eef1f5; color: var(--texte-doux); }
.pastille::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: #c3cad3; }
.pastille.vert { background: var(--vert-fond); color: #17663e; } .pastille.vert::before { background: var(--vert); }
.pastille.orange { background: var(--orange-fond); color: #8a5300; } .pastille.orange::before { background: var(--orange); }
.pastille.rouge { background: var(--rouge-fond); color: #a3171c; } .pastille.rouge::before { background: var(--rouge); }
.pastille.simule { background: var(--simule-fond); color: #2b56b5; } .pastille.simule::before { background: var(--simule); }
.source { font-size: .65rem; font-weight: 700; padding: .1rem .4rem; border-radius: 6px; text-transform: uppercase; letter-spacing: .03em; }
.source.AUTO { background: #e8eef6; color: var(--bleu); }
.source.MANUEL { background: #f1e8fb; color: #6b3fa0; }
.source.MODIFIE { background: var(--orange-fond); color: #8a5300; }
.valeur-negative { color: var(--rouge) !important; font-weight: 700; }

/* ---- Filtres et barre d'outils ---- */
.filtres { display: grid; grid-template-columns: 1fr 1fr; gap: .45rem; margin-bottom: .6rem; }
.filtres .recherche { grid-column: 1 / -1; }
@media (min-width: 900px) { .filtres { grid-template-columns: 2fr 1fr 1fr 1fr 1fr; } .filtres .recherche { grid-column: auto; } }
.filtres select { border-radius: 10px; }
.barre-outils { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .7rem; align-items: center; }
.barre-outils .espace { flex: 1; }
.bandeau-simulation { position: sticky; top: calc(56px + env(safe-area-inset-top)); z-index: 1020; background: var(--simule-fond); border: 1px solid #c9d8fb; color: #2b56b5; border-radius: 12px; padding: .5rem .75rem; margin-bottom: .7rem; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; font-size: .85rem; }
.bandeau-simulation .espace { flex: 1; }

/* ---- Tableau des marges : cartes sur téléphone, tableau sur PC ---- */
.table-marges { width: 100%; border-collapse: separate; border-spacing: 0; }
.table-marges thead { display: none; }
.table-marges tbody { display: flex; flex-direction: column; gap: .5rem; }
.table-marges tr.ligne {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .35rem .6rem;
  background: #fff; border: 1px solid var(--bordure); border-left: 4px solid var(--bordure); border-radius: 12px; padding: .6rem .7rem;
}
.table-marges tr.ligne.vert { border-left-color: var(--vert); }
.table-marges tr.ligne.orange { border-left-color: var(--orange); }
.table-marges tr.ligne.rouge { border-left-color: var(--rouge); }
.table-marges tr.ligne.est-simule { background: #fbfcff; box-shadow: inset 0 0 0 1px #c9d8fb; }
.table-marges td { display: block; min-width: 0; padding: 0; }
.table-marges td[data-libelle]::before { content: attr(data-libelle); display: block; font-size: .64rem; color: var(--texte-doux); text-transform: uppercase; letter-spacing: .02em; }
.table-marges td.col-produit { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: .5rem; align-items: flex-start; }
.table-marges td.col-produit a { color: inherit; min-width: 0; }
.table-marges td.col-produit strong { display: block; font-size: .9rem; line-height: 1.2; }
.table-marges td.col-produit small { color: var(--texte-doux); font-size: .72rem; }
.table-marges td.masque-mobile { display: none; }
.table-marges .ancien { display: block; font-size: .7rem; color: var(--texte-doux); text-decoration: line-through; }
.saisie-prix { width: 100%; max-width: 9.5rem; padding: .2rem .4rem; border: 1px solid #cbd5e1; border-radius: 8px; text-align: right; font-weight: 700; font-size: 16px; background: #fff; font-variant-numeric: tabular-nums; }
.saisie-prix:focus { outline: 2px solid var(--simule); border-color: var(--simule); }
.est-simule .saisie-prix { border-color: var(--simule); background: var(--simule-fond); color: #2b56b5; }
.marge-valeur { font-weight: 700; font-variant-numeric: tabular-nums; }
@media (min-width: 992px) {
  .table-marges { display: table; background: #fff; border: 1px solid var(--bordure); border-radius: 14px; overflow: hidden; font-size: .84rem; }
  .table-marges thead { display: table-header-group; }
  .table-marges tbody { display: table-row-group; }
  .table-marges tr.ligne { display: table-row; border: 0; border-radius: 0; padding: 0; }
  .table-marges th { position: sticky; top: calc(56px + env(safe-area-inset-top)); background: #eef2f8; color: var(--texte-doux); font-size: .7rem; text-transform: uppercase; letter-spacing: .02em; padding: .55rem .5rem; white-space: nowrap; cursor: pointer; user-select: none; z-index: 2; }
  .table-marges th.tri-asc::after { content: " ▲"; } .table-marges th.tri-desc::after { content: " ▼"; }
  .table-marges td { display: table-cell; padding: .45rem .5rem; border-top: 1px solid var(--bordure); vertical-align: middle; }
  .table-marges td[data-libelle]::before { display: none; }
  .table-marges td.col-produit { display: table-cell; }
  .table-marges td.col-produit .pastille { display: none; }
  .table-marges td.masque-mobile { display: table-cell; }
  .table-marges tr.ligne td:first-child { border-left: 4px solid transparent; }
  .table-marges tr.ligne.vert td:first-child { border-left-color: var(--vert); }
  .table-marges tr.ligne.orange td:first-child { border-left-color: var(--orange); }
  .table-marges tr.ligne.rouge td:first-child { border-left-color: var(--rouge); }
  .table-marges tr.ligne:hover td { background: #f8fafd; }
  .table-marges tr.ligne.est-simule td { background: #f7f9ff; }
}
.tri-mobile { display: flex; gap: .4rem; align-items: center; }
@media (min-width: 992px) { .tri-mobile { display: none; } }

/* ---- Listes simples ---- */
.liste-lignes { display: flex; flex-direction: column; gap: .45rem; }
.ligne-liste { display: flex; justify-content: space-between; align-items: center; gap: .6rem; background: #fff; border: 1px solid var(--bordure); border-radius: 12px; padding: .6rem .7rem; color: inherit; }
a.ligne-liste:active { background: #f0f4fa; }
.ligne-liste.inactif { opacity: .55; }
.ligne-nom { display: flex; flex-direction: column; min-width: 0; }
.ligne-nom strong { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; }
.ligne-nom small, .ligne-droite small { color: var(--texte-doux); font-size: .72rem; }
.ligne-droite { display: flex; flex-direction: column; align-items: flex-end; text-align: right; flex: 0 0 auto; }

/* ---- Tableaux compacts ---- */
.tableau-compact { font-size: .82rem; margin-bottom: 0; }
.tableau-compact th { font-weight: 600; color: var(--texte-doux); font-size: .7rem; text-transform: uppercase; white-space: nowrap; }
.tableau-compact td { vertical-align: middle; }
.defilement-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
details > summary { cursor: pointer; color: var(--bleu-clair); font-size: .88rem; }

/* ---- Fiche détail ---- */
.liste-detail { display: grid; grid-template-columns: auto 1fr; gap: .35rem 1rem; margin: 0; font-size: .88rem; }
.liste-detail dt { font-weight: 400; color: var(--texte-doux); }
.liste-detail dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.liste-detail dd.total { border-top: 1px solid var(--bordure); padding-top: .25rem; }
.etiquettes { display: flex; flex-wrap: wrap; gap: .35rem; }
.etiquette { background: #eef2f8; color: var(--bleu); border-radius: 99px; padding: .2rem .6rem; font-size: .75rem; }
.barre-decomposition { display: flex; height: 22px; border-radius: 8px; overflow: hidden; background: #eef2f8; margin: .3rem 0 .5rem; }
.barre-decomposition > div { height: 100%; }
.legende { display: flex; flex-wrap: wrap; gap: .4rem .9rem; font-size: .75rem; color: var(--texte-doux); }
.legende span { display: inline-flex; align-items: center; gap: .3rem; }
.puce { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: 0 0 10px; }
.graphique { position: relative; height: 230px; }
.graphique-haut { height: 320px; }

/* ---- Simulateur ---- */
.simu-grille { display: grid; gap: .8rem; }
@media (min-width: 992px) { .simu-grille { grid-template-columns: 1fr 1fr; } }
.champ-groupe { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.champ-groupe label { font-size: .75rem; color: var(--texte-doux); margin-bottom: .15rem; display: block; }
.champ-groupe .form-control { font-weight: 700; text-align: right; }
.resultat-grand { font-size: 1.9rem; font-weight: 800; color: var(--bleu); line-height: 1.1; font-variant-numeric: tabular-nums; }
.resultat-grand small { font-size: .9rem; font-weight: 600; color: var(--texte-doux); }
.curseur-prix { width: 100%; }
.message-alerte { border-radius: 10px; padding: .5rem .7rem; font-size: .85rem; background: var(--rouge-fond); color: #a3171c; }
.comparaison-cibles { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; text-align: center; }
.comparaison-cibles > div { background: #f6f8fb; border-radius: 10px; padding: .5rem .3rem; }
.comparaison-cibles span { display: block; font-size: .68rem; color: var(--texte-doux); text-transform: uppercase; }
.comparaison-cibles strong { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.comparaison-cibles em { display: block; font-style: normal; font-size: .72rem; color: var(--texte-doux); }

/* ---- Familles ---- */
.famille-carte { background: #fff; border: 1px solid var(--bordure); border-radius: 14px; padding: .75rem .8rem; }
.famille-carte .entete-famille { display: flex; justify-content: space-between; gap: .5rem; align-items: flex-start; }
.famille-carte .chiffres { display: grid; grid-template-columns: repeat(4, 1fr); gap: .3rem; margin-top: .5rem; text-align: center; }
.famille-carte .chiffres span { display: block; font-size: .64rem; color: var(--texte-doux); text-transform: uppercase; }
.famille-carte .chiffres strong { font-size: .95rem; font-variant-numeric: tabular-nums; }
.saisie-cible { width: 5.2rem; text-align: right; font-weight: 700; }
.liste-familles { display: grid; gap: .55rem; }
@media (min-width: 992px) { .liste-familles { grid-template-columns: 1fr 1fr; } }

/* ---- R&D ---- */
.cascade { width: 100%; font-size: .86rem; font-variant-numeric: tabular-nums; }
.cascade td { padding: .3rem .25rem; border-top: 1px solid var(--bordure); }
.cascade td.lettre { width: 1.6rem; color: var(--texte-doux); font-weight: 700; }
.cascade tr.important td { font-weight: 800; color: var(--bleu); background: #f4f7fb; }
.cascade tr.marge td { font-weight: 800; }
.intrant { background: #fff; border: 1px solid var(--bordure); border-radius: 12px; padding: .55rem .6rem; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .35rem .5rem; }
.intrant .designation { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: .4rem; align-items: flex-start; }
.intrant .designation strong { font-size: .86rem; }
.intrant label { font-size: .64rem; color: var(--texte-doux); text-transform: uppercase; display: block; }
.intrant input, .intrant select { font-size: 16px; padding: .2rem .4rem; text-align: right; }
.intrant .cout { font-weight: 700; text-align: right; align-self: end; font-variant-numeric: tabular-nums; }
.intrant .ancien { font-size: .68rem; color: var(--texte-doux); text-decoration: line-through; }
@media (min-width: 992px) { .intrant { grid-template-columns: 2.6fr 1fr 1fr 1fr .8fr 1fr auto; align-items: end; } .intrant .designation { grid-column: auto; } }
.groupe-intrants h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--texte-doux); margin: .8rem 0 .4rem; display: flex; justify-content: space-between; }
.resultats-recherche { position: absolute; left: 0; right: 0; top: 100%; z-index: 30; background: #fff; border: 1px solid var(--bordure); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 300px; overflow-y: auto; }
.resultats-recherche button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: .5rem .7rem; border-top: 1px solid var(--bordure); font-size: .85rem; }
.resultats-recherche button:hover, .resultats-recherche button:focus { background: #f0f4fa; }
.resultats-recherche small { color: var(--texte-doux); }
.zone-recherche { position: relative; }
.fil-ariane { font-size: .82rem; display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; margin-bottom: .6rem; }
.fil-ariane a { background: #e8eef6; border-radius: 99px; padding: .15rem .6rem; }
.fil-ariane .courant { font-weight: 700; }
.barre-actions { position: sticky; bottom: calc(var(--hauteur-nav) + env(safe-area-inset-bottom) + 6px); z-index: 1010; display: flex; gap: .5rem; background: rgba(255,255,255,.95); border: 1px solid var(--bordure); border-radius: 14px; padding: .5rem; box-shadow: 0 4px 18px rgba(0,0,0,.08); align-items: center; }
.barre-actions .etat { flex: 1; font-size: .78rem; color: var(--texte-doux); }
@media (min-width: 992px) { .barre-actions { bottom: 1rem; } }
.cas-tableau td, .cas-tableau th { text-align: right; } .cas-tableau td:first-child, .cas-tableau th:first-child { text-align: left; }

/* ---- Divers ---- */
.vide { text-align: center; padding: 3rem 1rem; color: var(--texte-doux); }
.vide i { font-size: 3rem; color: #b6c1cf; }
.cases-multiples { display: grid; grid-template-columns: 1fr 1fr; gap: .2rem .8rem; }
.choix-radio .form-check { background: #f6f8fb; border: 1px solid var(--bordure); border-radius: 10px; padding: .55rem .7rem .55rem 2.2rem; margin-bottom: .35rem; }
.zone-depot { border: 2px dashed #b6c1cf; border-radius: 14px; padding: 1rem; text-align: center; background: #fafbfd; transition: background .15s; }
.zone-depot.survol { background: var(--simule-fond); border-color: var(--simule); }
.anomalie { font-size: .82rem; padding: .3rem 0; border-top: 1px solid var(--bordure); }
.anomalie:first-child { border-top: 0; }
.chargement { opacity: .5; pointer-events: none; }

/* ---- Connexion ---- */
.page-connexion { padding-bottom: 0; background: linear-gradient(160deg, #1f3a5f 0%, #2c5282 55%, #f4f6fa 55%); min-height: 100vh; }
.boite-connexion { max-width: 400px; margin: 8vh auto 0; background: #fff; border-radius: 18px; padding: 2rem 1.5rem; box-shadow: 0 10px 40px rgba(0,0,0,.15); }

@media print {
  .entete, .barre-nav, .barre-outils, .barre-actions, .bandeau-simulation { display: none !important; }
  body { padding: 0; background: #fff; }
}
