/* Usine BPF — feuille de style unique, mobile d'abord. */
@font-face { font-family: "Atkinson"; src: url("fonts/atkinson-hyperlegible-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Atkinson"; src: url("fonts/atkinson-hyperlegible-latin-700-normal.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
  --paper: #f5f7f6;
  --surface: #ffffff;
  --ink: #1c2932;
  --ink-2: #51616b;
  --line: #d6dddb;
  --line-strong: #b5c1bd;
  --process: #0d6b6b;        /* action principale : vert d'eau de process */
  --process-ink: #ffffff;
  --process-soft: #e2f0ef;
  --amber: #a8650e;  --amber-bg: #fff4e0;   /* quarantaine, à surveiller */
  --green: #23744a;  --green-bg: #e5f4ea;   /* accepté, libéré, conforme */
  --red: #b0281f;    --red-bg: #fde9e7;     /* refusé, échu, bloqué */
  --blue: #2d5c9a;   --blue-bg: #e7eef8;    /* information */
  --radius: 6px;
  --gap: 16px;
  --font: "Atkinson", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 400 16px/1.5 var(--font); }
a { color: var(--process); text-underline-offset: 2px; }
:focus-visible { outline: 3px solid #f2b705; outline-offset: 2px; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; letter-spacing: -0.01em; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 1em; max-width: 72ch; }
.muted { color: var(--ink-2); }
.small { font-size: .875rem; }
.code { font-variant-numeric: tabular-nums; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }

/* ---------- Barre du haut ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--ink); color: #fff; }
.topbar-in { display: flex; align-items: center; gap: 12px; max-width: 1180px; margin: 0 auto; padding: 10px 16px; }
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.05rem; display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 26px; height: 26px; border: 2px solid #8fd1cc; border-radius: 4px; display: grid; place-items: center; font-size: .72rem; color: #8fd1cc; }
.topbar .spacer { flex: 1; }
.btn-scan { display: inline-flex; align-items: center; gap: 8px; background: #8fd1cc; color: var(--ink); font-weight: 700; text-decoration: none; padding: 8px 14px; border-radius: 999px; }
.btn-scan svg { width: 18px; height: 18px; }
.menu-toggle { background: none; border: 1px solid #47606d; color: #fff; border-radius: var(--radius); padding: 7px 10px; font: inherit; cursor: pointer; }
.who { color: #c8d4d9; font-size: .875rem; text-decoration: none; }

.nav { background: #24343e; display: none; }
.nav.open { display: block; }
.nav-in { max-width: 1180px; margin: 0 auto; padding: 8px 16px 14px; display: grid; gap: 4px; }
.nav a { color: #e3ebee; text-decoration: none; padding: 8px 10px; border-radius: var(--radius); }
.nav a:hover, .nav a[aria-current="page"] { background: #33495a; }
.nav .nav-group { color: #8ea4ae; font-size: .8rem; margin: 10px 10px 2px; }
.nav form { margin: 6px 0 0; }

@media (min-width: 900px) {
  .menu-toggle { display: none; }
  .nav { display: block; }
  .nav-in { display: flex; flex-wrap: wrap; align-items: center; gap: 0 2px; padding: 4px 16px; }
  .nav a { padding: 7px 9px; font-size: .95rem; white-space: nowrap; }
  .nav .btn-small { min-height: 32px; white-space: nowrap; }
  .nav .nav-group { display: none; }
  .nav form { margin: 0 0 0 auto; }
}

/* ---------- Page ---------- */
main { max-width: 1180px; margin: 0 auto; padding: 20px 16px 64px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head h1 { margin: 0; }
.page-head .lead { margin: 6px 0 0; color: var(--ink-2); }
.crumbs { font-size: .875rem; margin-bottom: 6px; }
.crumbs a { color: var(--ink-2); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: var(--gap); }
.panel > h2:first-child { margin-top: 0; }
.panel-title { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.help { background: var(--process-soft); border-left: 4px solid var(--process); padding: 10px 14px; border-radius: 0 var(--radius) var(--radius) 0; margin-bottom: var(--gap); color: #17403f; }

/* ---------- Boutons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 16px; border-radius: var(--radius); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font: 700 1rem var(--font); text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--ink-2); }
.btn-primary { background: var(--process); border-color: var(--process); color: var(--process-ink); }
.btn-primary:hover { background: #0a5858; }
.btn-danger { color: var(--red); border-color: #e2b4b0; }
.btn-small { min-height: 34px; padding: 4px 10px; font-size: .9rem; }
.linkbtn { background: none; border: 0; padding: 0; color: inherit; font: inherit; cursor: pointer; text-decoration: underline; }

/* ---------- Statuts : étiquettes comme en atelier ---------- */
.tag { display: inline-block; padding: 2px 9px; border: 2px solid currentColor; border-radius: 3px; font-size: .78rem; font-weight: 700; letter-spacing: .03em; line-height: 1.5; white-space: nowrap; background: var(--surface); }
.tag-green { color: var(--green); background: var(--green-bg); }
.tag-amber { color: var(--amber); background: var(--amber-bg); }
.tag-red   { color: var(--red);   background: var(--red-bg); }
.tag-blue  { color: var(--blue);  background: var(--blue-bg); }
.tag-grey  { color: var(--ink-2); background: #eef1f0; }

/* ---------- Messages ---------- */
.flash { padding: 12px 14px; border-radius: var(--radius); margin-bottom: var(--gap); border: 1px solid; }
.flash-ok   { background: var(--green-bg); border-color: #a6d3b6; color: #15452c; }
.flash-err  { background: var(--red-bg);   border-color: #efb6b0; color: #6f1812; }
.flash-info { background: var(--blue-bg);  border-color: #b5c8e3; color: #1c3a63; }
.errors { background: var(--red-bg); border: 1px solid #efb6b0; color: #6f1812; padding: 10px 14px; border-radius: var(--radius); margin-bottom: var(--gap); }
.errors ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .82rem; color: var(--ink-2); font-weight: 700; background: #eef2f1; position: sticky; top: 0; }
tbody tr:hover td { background: #f8faf9; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-link { color: inherit; text-decoration: none; }
.row-link:hover .code { text-decoration: underline; }
.empty { padding: 28px; text-align: center; color: var(--ink-2); }

/* Liste en cartes sur téléphone */
@media (max-width: 699px) {
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { border-bottom: 1px solid var(--line); padding: 10px 4px; }
  table.responsive td { border: 0; padding: 2px 8px; }
  table.responsive td[data-label]::before { content: attr(data-label) " : "; color: var(--ink-2); font-size: .85rem; }
  table.responsive td:first-child::before { content: none; }
}

/* ---------- Formulaires ---------- */
.form-grid { display: grid; gap: 14px 20px; }
@media (min-width: 760px) { .form-grid { grid-template-columns: 1fr 1fr; } .form-grid .full { grid-column: 1 / -1; } }
.field label, .field .label { display: block; font-weight: 700; margin-bottom: 4px; }
.field .req { color: var(--red); }
.field .hint { font-size: .85rem; color: var(--ink-2); margin-top: 4px; }
.field .err { font-size: .875rem; color: var(--red); margin-top: 4px; font-weight: 700; }
input[type=text], input[type=search], input[type=password], input[type=number], input[type=date], input[type=email], select, textarea {
  width: 100%; min-height: 44px; padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: #fff; color: var(--ink); font: 400 1rem var(--font);
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--process); outline: 3px solid #b8e0dd; outline-offset: 0; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--red); }
.check { display: flex; align-items: flex-start; gap: 10px; font-weight: 400; }
.check input { width: 22px; height: 22px; margin-top: 1px; accent-color: var(--process); }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.inline-form .field { min-width: 180px; flex: 1; }

/* Bloc de signature électronique */
.sign-box { border: 2px solid var(--process); border-radius: var(--radius); padding: 14px; background: var(--process-soft); }
.sign-box .label { color: #17403f; }
.sign-box input { max-width: 220px; letter-spacing: .3em; font-weight: 700; }
.motif-box { border-left: 4px solid var(--amber); background: var(--amber-bg); padding: 12px 14px; border-radius: 0 var(--radius) var(--radius) 0; }

/* ---------- Fiche ---------- */
.dl { display: grid; grid-template-columns: minmax(140px, 220px) 1fr; gap: 0; margin: 0; }
.dl dt, .dl dd { padding: 9px 0; border-bottom: 1px solid var(--line); margin: 0; }
.dl dt { color: var(--ink-2); padding-right: 14px; }
@media (max-width: 560px) { .dl { grid-template-columns: 1fr; } .dl dt { border: 0; padding-bottom: 0; } }
.cols { display: grid; gap: var(--gap); }
@media (min-width: 980px) { .cols { grid-template-columns: 3fr 2fr; } }

/* Historique (piste d'audit d'un enregistrement) */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 18px; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--line-strong); }
.timeline li.t-signature::before { background: var(--process); }
.timeline li.t-creation::before { background: var(--green); }
.timeline .when { font-size: .85rem; color: var(--ink-2); }
.changes { margin: 4px 0 0; padding: 0; list-style: none; font-size: .9rem; }
.changes li { border: 0; padding: 0; margin: 0; }
.changes li::before { content: none; }
.old { color: var(--red); text-decoration: line-through; }
.new { color: var(--green); font-weight: 700; }
.reason { font-size: .9rem; background: #f3f5f4; padding: 4px 8px; border-radius: 4px; display: inline-block; margin-top: 4px; }

/* ---------- Accueil ---------- */
.counts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.count { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; text-decoration: none; color: var(--ink); }
.count b { display: block; font-size: 1.7rem; font-variant-numeric: tabular-nums; }
.count span { color: var(--ink-2); font-size: .9rem; }
.alerts { list-style: none; margin: 0; padding: 0; }
.alerts li { border-bottom: 1px solid var(--line); }
.alerts a { display: flex; gap: 10px; align-items: baseline; padding: 10px 2px; color: var(--ink); text-decoration: none; }
.alerts a:hover { background: #f8faf9; }

/* ---------- Filtres et pagination ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.filters .field { min-width: 160px; }
.filters .grow { flex: 1; min-width: 220px; }
.pager { display: flex; gap: 8px; align-items: center; margin-top: 12px; }

/* Matrice des habilitations */
.matrix th.rot { white-space: normal; min-width: 110px; font-size: .78rem; }
.matrix td { text-align: center; white-space: nowrap; }
.matrix td:first-child { text-align: left; }

/* ---------- Connexion ---------- */
.public { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--ink); }
.login { width: 100%; max-width: 400px; background: var(--surface); border-radius: 10px; padding: 26px; }
.login .brand-mark { border-color: var(--process); color: var(--process); width: 34px; height: 34px; font-size: .85rem; }
.login h1 { margin: 14px 0 4px; }

/* ---------- Scanner ---------- */
#reader { width: 100%; max-width: 480px; margin: 0 auto 14px; border-radius: var(--radius); overflow: hidden; background: #000; }

/* ---------- Étiquette (aperçu écran) ---------- */
.label-preview { display: inline-block; border: 1px dashed var(--line-strong); padding: 10px; background: #fff; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
.sign-note { margin: 0 0 8px; }
.mt0 { margin-top: 0; }
.mb0 { margin-bottom: 0; }
.mt16 { margin-top: 16px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
