/*
  Inventaire TC22 — direction visuelle

  Contexte : entrepôt alimentaire, écran 5" HD durci, opérateur ganté, éclairage
  néon ou chambre froide, lecture à bout de bras, une seule main libre.

  Parti pris :
  - Aucune police web. Le terminal doit démarrer en zone blanche wifi et rester
    lisible hors ligne : on n'utilise que la stack système Android (Roboto) et un
    monospace natif pour tout ce qui est chiffre ou code — les codes se lisent en
    colonnes, pas en prose.
  - La COULEUR EST LA DONNÉE. L'inventaire cherche justement à distinguer les
    encodages : chaque type d'étiquette a une couleur, portée par la bande verdict
    puis rappelée à l'identique dans le récapitulatif. Aucune couleur n'est décorative.
  - Cibles tactiles à 64 px minimum, aucune zone d'appui à moins de 8 px d'une autre.
*/

:root {
  --bg:        #0E1418;
  --surface:   #18222A;
  --surface-2: #1F2C36;
  --line:      #2C3A45;
  --ink:       #E6EDF2;
  --muted:     #8CA0AE;

  /* Légende des encodages — sémantique, pas décor */
  --c-ean13:   #F2B705;   /* ambre  : EAN13 simple, pas de quantité portée */
  --c-gs1:     #35C4FF;   /* cyan   : GS1/EAN128, données structurées */
  --c-none:    #FF6B4A;   /* corail : pas d'étiquette scannable */
  --c-unknown: #A78BFA;   /* violet : code lu mais hors référentiel */
  --c-idle:    #3A4A57;

  --mono: ui-monospace, "Roboto Mono", "Droid Sans Mono", monospace;
  --sys:  system-ui, Roboto, "Helvetica Neue", sans-serif;

  --tap: 64px;
  --r: 10px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Capteur douchette : reste focus en permanence, invisible mais toujours
   preneur de focus (display:none/visibility:hidden empechent le focus sur
   certains WebView Android). inputmode="none" masque le clavier virtuel. */
.scan-catch {
  position: fixed; top: -1px; left: -1px; width: 1px; height: 1px;
  opacity: .01; border: 0; padding: 0; z-index: -1; caret-color: transparent;
}

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: var(--sys);
  overscroll-behavior: none;
  user-select: none;
}
body {
  display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.eyebrow {
  display: block; font-size: 9px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted); line-height: 1.4;
}
[hidden] { display: none !important; }

/* ---------- barre haute ---------- */
.bar {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px; background: var(--surface); border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.bar__id {
  background: none; border: 0; color: var(--ink); text-align: left; padding: 2px 4px;
  font-size: 13px;
}
.bar__stats { margin-left: auto; font-size: 12px; color: var(--muted); }
/* Bandeau "session terminée" : visible seulement en lecture seule. */
.bar__fin {
  display: none; margin-left: 8px; padding: 1px 7px; border-radius: 999px;
  font-size: 10px; font-weight: 600; letter-spacing: .02em;
  color: var(--c-none); border: 1px solid color-mix(in srgb, var(--c-none) 45%, transparent);
  background: color-mix(in srgb, var(--c-none) 12%, transparent);
}
body.termine .bar__fin { display: inline-block; }
/* Comptage désactivé quand la session est terminée. */
body.termine [data-add],
body.termine [data-action="edit-qty"] { opacity: .4; pointer-events: none; }
.sync { display: flex; align-items: center; gap: 5px; font-size: 10px; color: var(--muted); }
.sync__dot { width: 8px; height: 8px; border-radius: 50%; background: #4ADE80; }
.sync[data-state="pending"] .sync__dot { background: var(--c-ean13); animation: pulse 1s infinite; }
.sync[data-state="offline"] .sync__dot { background: var(--c-none); }
.sync[data-state="offline"] .sync__txt { color: var(--c-none); }
@keyframes pulse { 50% { opacity: .25; } }

/* ---------- SIGNATURE : bande verdict ---------- */
.verdict {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 12px;
  background: var(--c-idle); color: #0B1015;
  font-weight: 700; letter-spacing: .1em; text-transform: uppercase; font-size: 13px;
  transition: background-color .12s linear;
}
.verdict[data-type="EAN13"], .verdict[data-type="EAN8"], .verdict[data-type="UPC-A"],
.verdict[data-type="ITF-14"] { background: var(--c-ean13); }
.verdict[data-type="GS1-128"], .verdict[data-type="GS1-DATAMATRIX"],
.verdict[data-type="GS1-QRCODE"], .verdict[data-type="GS1-DATABAR"] { background: var(--c-gs1); }
.verdict[data-type="AUCUN"] { background: var(--c-none); }
.verdict[data-type="INCONNU"], .verdict[data-type="CODE128"] { background: var(--c-unknown); }
.verdict[data-type="idle"] { background: var(--c-idle); color: var(--muted); }
/* Vert uniquement quand le capteur douchette a effectivement le focus clavier :
   sinon rien n'arrive au scan malgre le bip (voir #view-focus). */
.verdict[data-type="idle"].verdict--focus { background: #4ADE80; color: #0B1015; }
.verdict__side { font-size: 11px; letter-spacing: 0; text-transform: none; opacity: .75; }
.verdict.flash { animation: flash .18s ease-out; }
@keyframes flash { from { filter: brightness(2.2); } }
@media (prefers-reduced-motion: reduce) {
  .verdict, .verdict.flash, .sync__dot { transition: none; animation: none; }
}

/* ---------- vues ---------- */
.view { flex: 1 1 auto; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 14px;
  /* La carte occupe toute la hauteur : le pavé de comptage tombe dans la zone
     du pouce, en bas, et le gros chiffre juste au-dessus. On lit de bas en haut,
     dans l'ordre où la main travaille. */
  flex: 1 1 auto; display: flex; flex-direction: column;
}
.card--alert { border-color: var(--c-unknown); }

.hint { margin: 0 0 6px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.hint--dim { font-size: 12px; }
.link { background: none; border: 0; color: var(--c-gs1); font: inherit; text-decoration: underline; padding: 4px; }

.code { margin: 0; font-size: 17px; letter-spacing: .06em; color: var(--ink); word-break: break-all; }
.designation {
  margin: 4px 0 5px; font-size: 20px; line-height: 1.2; font-weight: 600;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.meta { margin: 0; font-size: 12px; color: var(--muted); }
.sep { margin: 0 6px; opacity: .5; }
.ais { margin: 8px 0 0; font-size: 11px; color: var(--c-gs1); line-height: 1.6; word-break: break-all; }
.eans { margin: 4px 0 0; font-size: 11px; color: var(--c-ean13); line-height: 1.6; word-break: break-all; }
.details { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.note {
  margin: 8px 0 0; padding: 8px 10px; font-size: 13px; line-height: 1.4;
  color: var(--ink); background: var(--surface-2); border-radius: var(--r);
  border-left: 3px solid var(--c-gs1); white-space: pre-wrap; word-break: break-word;
}

.qty { display: flex; align-items: baseline; gap: 8px; margin: 14px 0 12px; }
.card--article .qty { margin-top: auto; }
.qty__num {
  font-size: 60px; font-weight: 700; line-height: .95; letter-spacing: -.03em;
  background: none; border: 1px dashed transparent; border-radius: 8px; color: var(--ink);
  font-family: var(--mono); padding: 0 4px; margin: 0 -4px;
}
.qty__num:active { border-color: var(--muted); }
.qty__unit { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
.qty__delta { margin-left: auto; font-size: 15px; font-weight: 700; color: #4ADE80; }
.qty__edit {
  font-size: 44px; font-weight: 700; width: 5ch; border-radius: 8px;
  border: 1px solid var(--c-gs1); background: var(--surface-2); color: var(--ink);
  font-family: var(--mono); padding: 0 6px;
}

.qtypcb { display: flex; align-items: baseline; gap: 6px; margin: -6px 0 12px; }
.qtypcb__n {
  font-size: 22px; font-weight: 700; color: var(--c-gs1); font-family: var(--mono);
  background: none; border: 1px dashed transparent; border-radius: 6px;
  padding: 0 4px; margin: 0 -4px; line-height: 1;
}
.qtypcb__n:active { border-color: var(--c-gs1); }
.qtypcb__lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
.qtypcb__op { font-size: 18px; font-weight: 700; color: var(--muted); }
.qtypcb__edit {
  font-size: 22px; font-weight: 700; width: 4ch; border-radius: 6px;
  border: 1px solid var(--c-gs1); background: var(--surface-2); color: var(--ink);
  font-family: var(--mono); padding: 0 4px; line-height: 1;
}

.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pad--sec { grid-template-columns: repeat(3, 1fr); margin-top: 8px; }
.pad--sec1 { grid-template-columns: 1fr; }
.pad--counter { display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: var(--tap); gap: 8px; }
.key {
  min-height: var(--tap); border-radius: var(--r); border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink);
  font-family: var(--mono); font-size: 21px; font-weight: 700;
}
.key:active { background: var(--ink); color: var(--bg); }
.key--ghost { font-family: var(--sys); font-size: 13px; font-weight: 600; min-height: 48px; background: transparent; }
.key--warn, .key--warn:active { font-family: var(--sys); font-size: 13px; }
.key--warn { color: var(--c-none); border-color: color-mix(in srgb, var(--c-none) 40%, var(--line)); }
.key--pcb { color: var(--c-gs1); border-color: color-mix(in srgb, var(--c-gs1) 45%, var(--line)); }
.key--plus { color: #4ADE80; border-color: color-mix(in srgb, #4ADE80 40%, var(--line)); }
.key--minus { color: var(--c-none); border-color: color-mix(in srgb, var(--c-none) 40%, var(--line)); }
.key:focus-visible, .link:focus-visible, .dock__btn:focus-visible, .bar__id:focus-visible {
  outline: 3px solid var(--c-gs1); outline-offset: 2px;
}
.alert__msg { margin: 6px 0 10px; font-size: 15px; line-height: 1.4; }

/* Page d'accueil récapitulatif : recherche en haut, liste scrollable, export en bas.
   min-height:0 pour que la LISTE défile à l'intérieur de la carte (sinon la carte
   déborde et pousse les boutons d'export sous le dock). */
.card--recap { padding: 10px; min-height: 0; }
.recap__head { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin-bottom: 6px; flex: 0 0 auto; }
.card--recap .legend { padding: 8px 2px 10px; flex: 0 0 auto; }
.card--recap .recap { border-top: 1px solid var(--line); flex: 1 1 auto; min-height: 0; }
.pad--exports { grid-template-columns: 1fr 1fr; margin-top: 8px; flex: 0 0 auto; }
.manual-code__row { display: flex; gap: 8px; min-width: 0; }
.manual-code__row .q { flex: 1 1 auto; min-width: 0; }
.manual-code__row .key { flex: 0 0 auto; padding: 0 16px; }

/* ---------- feuilles (recherche / récap) ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 20; background: var(--bg);
  display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet__head {
  display: flex; gap: 8px; align-items: center;
  padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.sheet__foot { padding: 8px 10px; border-top: 1px solid var(--line); background: var(--surface); }
.sheet__foot.pad { grid-template-columns: 1fr 1fr; }
.q {
  flex: 1; min-height: 48px; border-radius: var(--r); border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink); padding: 0 12px; font-size: 16px;
  font-family: var(--sys); user-select: text;
}
.q--area { min-height: 96px; padding: 10px 12px; line-height: 1.4; resize: vertical; width: 100%; }

.picklist, .recap { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; }
.picklist li, .recap li { border-bottom: 1px solid var(--line); }
.row {
  width: 100%; display: block; text-align: left; background: none; border: 0;
  color: var(--ink); padding: 11px 12px; min-height: var(--tap);
  border-left: 4px solid transparent;
}
.row:active { background: var(--surface-2); }
.row__t { display: block; font-size: 15px; line-height: 1.25; }
.row__m { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }
.row__q { float: right; font-size: 18px; font-weight: 700; margin-left: 8px; }
.histrow { padding: 11px 12px; }
.histrow .row__q { color: var(--ink); }
.row[data-type="EAN13"], .row[data-type="EAN8"], .row[data-type="ITF-14"] { border-left-color: var(--c-ean13); }
.row[data-type^="GS1"] { border-left-color: var(--c-gs1); }
.row[data-type="AUCUN"] { border-left-color: var(--c-none); }
.row[data-type="INCONNU"] { border-left-color: var(--c-unknown); }

.legend { display: flex; gap: 12px; list-style: none; margin: 0; padding: 8px 12px;
  font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em;
  border-bottom: 1px solid var(--line); }
.legend li { display: flex; align-items: center; gap: 5px; }
.legend i { width: 9px; height: 9px; border-radius: 2px; display: block; }
.legend [data-type="EAN13"] i { background: var(--c-ean13); }
.legend [data-type="GS1-128"] i { background: var(--c-gs1); }
.legend [data-type="AUCUN"] i { background: var(--c-none); }
.legend [data-type="INCONNU"] i { background: var(--c-unknown); }

/* ---------- petites modales (code manuel / creation article) ---------- */
.modal {
  position: fixed; inset: 0; z-index: 30; background: rgba(4,7,9,.72);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal__box {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 10px;
}
.modal__title { margin: 0; font-size: 16px; font-weight: 700; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field-label { font-size: 12px; color: var(--muted); padding: 0 2px; }

/* ---------- dock ---------- */
.dock {
  flex: 0 0 auto; display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  padding: 8px 10px; background: var(--surface); border-top: 1px solid var(--line);
}
.dock__btn {
  min-height: 48px; border-radius: var(--r); border: 1px solid var(--line);
  background: transparent; color: var(--ink); font-size: 13px; font-weight: 600;
}
.dock__btn--main { background: var(--surface-2); }

.toast {
  position: fixed; left: 10px; right: 10px; bottom: 70px; z-index: 40;
  background: var(--ink); color: var(--bg); border-radius: var(--r);
  padding: 11px 13px; font-size: 13px; font-weight: 600; text-align: center;
}
