:root {
  --encre: #16324f;
  --encre-2: #234a70;
  --fond: #f4f7f9;
  --surface: #ffffff;
  --froid: #1b7f9e;
  --froid-sombre: #136179;
  --trait: #d5dee5;
  --texte: #1c2733;
  --texte-doux: #5a6b7b;

  --actif: #2e7d4f;
  --proche: #a86a12;
  --perime: #b42318;
  --quarantaine: #6b4fa0;
  --rejete: #5b6470;
  --surstock: #1b7f9e;
  --neutre: #8796a5;

  --police: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --police-chiffres: "Barlow Semi Condensed", "Arial Narrow", "Segoe UI", sans-serif;
  --rayon: 6px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--police);
  font-size: 15px;
  line-height: 1.5;
  color: var(--texte);
  background: var(--fond);
}
h1, h2, h3 { font-family: var(--police-chiffres); font-weight: 600; color: var(--encre); line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.3rem; margin-top: 1.75rem; }
h3 { font-size: 1.1rem; }
p { max-width: 75ch; }
a { color: var(--froid-sombre); }
:focus-visible { outline: 3px solid var(--froid); outline-offset: 2px; }
.chargement { padding: 2rem; color: var(--texte-doux); }

/* ---------- Structure ---------- */
.coque { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.barre-laterale { background: var(--encre); color: #e8eef4; display: flex; flex-direction: column; padding: 1.25rem 0; position: sticky; top: 0; height: 100vh; }
.marque { padding: 0 1.25rem 1.25rem; border-bottom: 1px solid var(--encre-2); }
.marque strong { display: block; font-family: var(--police-chiffres); font-size: 1.15rem; font-weight: 600; line-height: 1.2; color: #fff; }
.marque span { font-size: .85rem; color: #a9bccd; }
.nav { list-style: none; margin: 1rem 0; padding: 0; flex: 1; }
.nav a { display: block; padding: .6rem 1.25rem; color: #d7e2ec; text-decoration: none; border-left: 4px solid transparent; }
.nav a:hover { background: var(--encre-2); }
.nav a[aria-current="page"] { border-left-color: #6fc3dc; background: var(--encre-2); color: #fff; font-weight: 700; }
.nav .compteur { float: right; background: var(--quarantaine); color: #fff; border-radius: 999px; font-size: .75rem; padding: 0 .5rem; }
.utilisateur { padding: 1rem 1.25rem 0; border-top: 1px solid var(--encre-2); font-size: .85rem; color: #a9bccd; }
.utilisateur strong { color: #fff; display: block; }

.principal { min-width: 0; }
.entete { display: flex; align-items: center; gap: 1rem; justify-content: space-between; padding: .9rem 2rem; background: var(--surface); border-bottom: 1px solid var(--trait); position: sticky; top: 0; z-index: 5; }
.entete > div { min-width: 0; }
.entete label { font-size: .85rem; color: var(--texte-doux); margin-right: .5rem; }
.contenu { padding: 1.5rem 2rem 4rem; max-width: 1400px; }
.menu-mobile { display: none; }
.entete-gauche { display: flex; align-items: center; gap: 1rem; min-width: 0; }
/* Compte utilisateur (en haut à droite) */
.compte { position: relative; flex-shrink: 0; }
.compte summary { list-style: none; display: flex; align-items: center; gap: .6rem; cursor: pointer; padding: .3rem .5rem; border-radius: 999px; border: 1px solid transparent; }
.compte summary::-webkit-details-marker { display: none; }
.compte summary:hover, .compte[open] summary { border-color: var(--trait); background: var(--fond); }
.compte summary:focus-visible { outline: 2px solid var(--froid-sombre); outline-offset: 2px; }
.avatar { width: 2.1rem; height: 2.1rem; border-radius: 50%; background: var(--encre); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: .85rem; flex-shrink: 0; }
.compte-texte { display: flex; flex-direction: column; line-height: 1.15; text-align: left; }
.compte-texte strong { font-size: .9rem; }
.compte-texte small { color: var(--texte-doux); font-size: .78rem; }
.chevron { color: var(--texte-doux); font-size: .8rem; }
.compte-menu { position: absolute; right: 0; top: calc(100% + .4rem); min-width: 250px; background: var(--surface); border: 1px solid var(--trait); border-radius: 10px; box-shadow: 0 10px 30px rgba(15, 35, 55, .15); padding: .4rem; z-index: 30; display: flex; flex-direction: column; }
.compte-entete { padding: .6rem .7rem .7rem; border-bottom: 1px solid var(--trait); margin-bottom: .3rem; display: flex; flex-direction: column; gap: .1rem; }
.compte-entete small { color: var(--texte-doux); font-size: .8rem; overflow-wrap: anywhere; }
.compte-menu a, .compte-menu button { display: block; width: 100%; text-align: left; padding: .55rem .7rem; border-radius: 6px; color: var(--texte, inherit); text-decoration: none; background: none; border: none; font: inherit; cursor: pointer; }
.compte-menu a:hover, .compte-menu button:hover, .compte-menu a:focus-visible, .compte-menu button:focus-visible { background: var(--fond); }
.compte-menu #deconnexion { color: #9b2c1f; border-top: 1px solid var(--trait); border-radius: 0 0 6px 6px; margin-top: .3rem; }

/* ---------- Éléments ---------- */
.btn { font: inherit; font-weight: 700; border: 1px solid var(--froid); background: var(--froid); color: #fff; padding: .55rem 1rem; border-radius: var(--rayon); cursor: pointer; }
.btn:hover { background: var(--froid-sombre); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondaire { background: transparent; color: var(--froid-sombre); }
.btn.secondaire:hover { background: #e7f2f6; }
.btn.danger { background: var(--perime); border-color: var(--perime); }
.btn.petit { padding: .25rem .6rem; font-size: .85rem; }
.btn.lien { background: none; border: none; color: #a9bccd; padding: 0; font-weight: 400; text-decoration: underline; }

input, select, textarea { font: inherit; color: var(--texte); background: #fff; border: 1px solid #b9c6d1; border-radius: var(--rayon); padding: .5rem .6rem; width: 100%; }
textarea { min-height: 5rem; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: auto; }
.champ { display: flex; flex-direction: column; gap: .3rem; }
.champ > span { font-weight: 700; font-size: .9rem; }
.champ small { color: var(--texte-doux); }
.champ.erreur input, .champ.erreur select, .champ.erreur textarea { border-color: var(--perime); background: #fff6f5; }
.grille { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem 1.25rem; }
.groupe { background: var(--surface); border: 1px solid var(--trait); border-radius: var(--rayon); padding: 1.25rem; margin-bottom: 1.25rem; }
.groupe > legend { font-family: var(--police-chiffres); font-weight: 600; color: var(--encre); padding: 0 .4rem; font-size: 1.05rem; }
.groupe.froid { border-left: 5px solid var(--froid); }
.groupe.alerte { border-left: 5px solid var(--quarantaine); background: #f8f5fc; }
.ligne-actions { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; margin-top: 1rem; }
.bascule { display: inline-flex; flex-wrap: wrap; max-width: 100%; border: 1px solid #b9c6d1; border-radius: var(--rayon); overflow: hidden; }
.bascule button { white-space: nowrap; font: inherit; border: none; background: #fff; padding: .45rem .8rem; cursor: pointer; color: var(--texte-doux); }
.bascule button[aria-pressed="true"] { background: var(--encre); color: #fff; }
.aide { color: var(--texte-doux); font-size: .9rem; }
.message { border-radius: var(--rayon); padding: .8rem 1rem; margin: 1rem 0; }
.message.erreur { background: #fdecea; color: #7a1a12; border: 1px solid #f4c4be; }
.message.ok { background: #e8f4ec; color: #1d5234; border: 1px solid #bcdcc7; }
.message.info { background: #e7f2f6; color: #134a5c; border: 1px solid #bfdde7; }

/* ---------- Tableaux ---------- */
.tableau-conteneur { overflow-x: auto; background: var(--surface); border: 1px solid var(--trait); border-radius: var(--rayon); }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { padding: .55rem .75rem; text-align: left; border-bottom: 1px solid #e6ecf0; vertical-align: middle; }
th { background: #eef3f6; color: var(--encre); font-weight: 700; position: sticky; top: 0; white-space: nowrap; }
tbody tr:hover { background: #f7fafb; }
td.nb, th.nb { text-align: right; font-family: var(--police-chiffres); font-size: 1rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.vide { padding: 2rem; text-align: center; color: var(--texte-doux); }
.filtres { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; margin: 1rem 0; }
.filtres .champ { min-width: 180px; }

/* ---------- Statuts ---------- */
.badge { display: inline-block; border-radius: 999px; padding: .05rem .6rem; font-size: .8rem; font-weight: 700; color: #fff; white-space: nowrap; }
.b-actif, .b-normal { background: var(--actif); }
.b-proche_peremption, .b-sous_stock { background: var(--proche); }
.b-perime, .b-rupture { background: var(--perime); }
.b-quarantaine { background: var(--quarantaine); }
.b-rejete { background: var(--rejete); }
.b-surstock { background: var(--surstock); }
.b-non_consomme { background: var(--neutre); }

/* Jauge de péremption (12 mois = pleine) */
.jauge { display: flex; align-items: center; gap: .5rem; min-width: 150px; }
.jauge-piste { flex: 1; height: 8px; background: #e6ecf0; border-radius: 4px; overflow: hidden; }
.jauge-niveau { height: 100%; border-radius: 4px; }
.jauge small { font-family: var(--police-chiffres); font-size: .95rem; white-space: nowrap; min-width: 4.5rem; text-align: right; }

/* ---------- Tableau de bord ---------- */
.situation { background: var(--surface); border: 1px solid var(--trait); border-radius: var(--rayon); padding: 1.25rem 1.5rem; }
.situation-titre { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: .5rem; }
.repartition { display: flex; height: 44px; border-radius: var(--rayon); overflow: hidden; margin: 1rem 0 .75rem; }
.repartition button { border: none; color: #fff; font-family: var(--police-chiffres); font-size: 1.1rem; font-weight: 600; cursor: pointer; min-width: 2.25rem; }
.repartition button[aria-pressed="true"] { box-shadow: inset 0 -5px 0 rgba(255,255,255,.85); }
.legende { display: flex; flex-wrap: wrap; gap: .4rem 1.25rem; font-size: .9rem; }
.legende i { display: inline-block; width: .8rem; height: .8rem; border-radius: 2px; margin-right: .35rem; vertical-align: -1px; }
.chiffres { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); border-top: 1px solid #e6ecf0; margin-top: 1.25rem; padding-top: 1rem; gap: 1rem; }
.chiffres div { font-size: .9rem; color: var(--texte-doux); }
.chiffres strong { display: block; font-family: var(--police-chiffres); font-weight: 600; font-size: 1.6rem; color: var(--encre); line-height: 1.15; }
.chiffres .alerte strong { color: var(--perime); }

/* ---------- Sortie FEFO : file des lots ---------- */
.file-fefo { display: flex; flex-direction: column; gap: .5rem; margin-top: 1rem; }
.etiquette { display: grid; grid-template-columns: 1.6fr 1fr 1fr 1.2fr; gap: .75rem; align-items: center; background: var(--surface); border: 1px solid var(--trait); border-left: 6px solid var(--actif); border-radius: var(--rayon); padding: .65rem 1rem; }
.etiquette.proche_peremption { border-left-color: var(--proche); }
.etiquette .lot { font-family: var(--police-chiffres); font-size: 1.15rem; font-weight: 600; color: var(--encre); }
.etiquette .prelevement { font-family: var(--police-chiffres); font-size: 1.15rem; text-align: right; }
.etiquette.preleve { background: #eaf5f8; border-color: #a9d4e1; }
.etiquette.preleve .prelevement { color: var(--froid-sombre); font-weight: 700; }
.etiquette.intact { opacity: .6; }
.reste { font-size: .85rem; color: var(--texte-doux); text-align: right; }

/* ---------- Connexion ---------- */
.connexion { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: linear-gradient(180deg, var(--encre) 0 38%, var(--fond) 38%); }
.connexion form { background: var(--surface); width: min(420px, 100%); padding: 2rem; border-radius: 10px; border: 1px solid var(--trait); display: flex; flex-direction: column; gap: 1rem; }
.connexion h1 { font-size: 1.5rem; }

/* ---------- Onglets, dialogue, toasts ---------- */
.onglets { display: flex; gap: .25rem; border-bottom: 2px solid var(--trait); margin: 1rem 0; flex-wrap: wrap; }
.onglets button { font: inherit; background: none; border: none; padding: .6rem 1rem; cursor: pointer; color: var(--texte-doux); border-bottom: 3px solid transparent; margin-bottom: -2px; }
.onglets button[aria-selected="true"] { color: var(--encre); border-bottom-color: var(--froid); font-weight: 700; }
dialog { border: none; border-radius: 10px; padding: 1.5rem; width: min(520px, 94vw); box-shadow: 0 10px 40px rgba(22, 50, 79, .25); }
dialog::backdrop { background: rgba(22, 50, 79, .45); }
#toasts { position: fixed; bottom: 1rem; right: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 50; }
.toast { background: var(--encre); color: #fff; padding: .75rem 1rem; border-radius: var(--rayon); max-width: 420px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.erreur { background: var(--perime); }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .coque { grid-template-columns: 1fr; }
  .barre-laterale { position: fixed; inset: 0 auto 0 0; width: 260px; transform: translateX(-100%); transition: transform .2s; z-index: 20; }
  .barre-laterale.ouverte { transform: none; }
  .menu-mobile { display: inline-block; }
  .entete { padding: .75rem 1rem; }
  .compte-texte, .chevron { display: none; }
  .contenu { padding: 1rem; }
  .etiquette { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.liste-mouvements { margin-top: 2.5rem; padding-top: 1.5rem; border-top: 1px solid var(--trait); }
.liste-mouvements td strong { white-space: nowrap; }

.inventaire-chiffres { border-top: none; padding-top: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin: 1rem 0; }
.inventaire-chiffres > div { background: var(--surface); border: 1px solid var(--trait); border-radius: 8px; padding: .75rem 1rem; font-size: .85rem; color: var(--texte-doux); }
.inventaire-chiffres strong { display: block; font-size: 1.3rem; color: var(--texte); }
.inventaire-chiffres .alerte strong { color: #9b2c1f; }
.lien-detail { background: none; border: none; padding: 0; font: inherit; color: var(--froid-sombre); text-decoration: underline; cursor: pointer; text-align: left; }
.ligne-detail > td { background: var(--fond); padding: .75rem 1rem 1rem; }
td .pos { color: var(--actif); }
td .neg { color: var(--perime); }
#resultats-inv > .tableau-conteneur > table > tbody > tr > td:first-child { min-width: 210px; }

/* Scan code-barres / QR code */
.scan-zone { background: var(--surface); border: 1px dashed var(--froid-sombre); border-radius: 10px; padding: .9rem 1rem; margin-bottom: 1rem; }
.scan-zone .message { margin: .6rem 0 0; }
.scan-ligne { display: flex; gap: .5rem; align-items: stretch; }
.scan-ligne input { flex: 1; min-width: 0; }
.bouton-camera { align-self: flex-start; margin-top: .35rem; }
.scan-camera { width: min(520px, 90vw); }
.scan-video { position: relative; background: #000; border-radius: 8px; overflow: hidden; aspect-ratio: 4 / 3; }
.scan-video video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-cadre { position: absolute; inset: 18% 12%; border: 3px solid rgba(255, 255, 255, .85); border-radius: 10px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, .25); }

.recherche-produits { margin: 0 0 1rem; max-width: 36rem; }
.recherche-produits .champ { margin-bottom: .25rem; }

/* Transferts entre laboratoires */
.b-brouillon { background: var(--neutre); }
.b-expedie   { background: var(--proche); }
.b-recu      { background: var(--actif); }
.b-annule    { background: var(--rejete); }
