/**
 * Scanner de code-barres : le bouton de la barre de recherche et sa fenêtre.
 *
 * Couleurs du thème : texte #2c463a, turquoise #39c3a8.
 */

/* ===== Le bouton, à côté du champ de recherche =====
   L'enveloppe est à nous. #mobile-searchbox est forcé en display:block par
   header.css sur mobile, on ne pouvait donc pas le passer en flex. */
.pdc-recherche {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* L'extension de recherche impose width:100% !important à son conteneur :
   min-width:0 lui permet de rétrécir malgré ça, sans pousser le bouton hors
   de l'écran. */
.pdc-recherche .aws-container {
  flex: 1 1 auto;
  min-width: 0;
}

.pdc-scan-ouvrir {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 6px 10px;
  border: 1px solid #d6e3dd;
  border-radius: 8px;
  background: #fff;
  color: #2c463a;
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}

.pdc-scan-ouvrir:hover,
.pdc-scan-ouvrir:focus-visible {
  border-color: #39c3a8;
  color: #1f7a66;
}

.pdc-scan-ouvrir svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

/* Le bouton prend exactement la hauteur du champ de recherche : la cible est
   confortable au doigt sans chiffre en dur, et l'alignement suit le champ s'il
   change de taille. */
.pdc-recherche .pdc-scan-ouvrir {
  align-self: stretch;
  min-width: 44px;
  justify-content: center;
}

/* ===== Le bouton GLISSÉ DANS la barre, juste avant la loupe =====
   Il reprend la largeur et le comportement du bouton loupe du thème
   (header.css, .searchbox .aws-search-form .aws-search-btn), pour que les deux
   icônes soient de même gabarit. Les !important répondent à ceux de l'extension
   de recherche, qui met sa propre mise en page sur tout ce que contient le
   formulaire. */
.searchbox .aws-search-form .pdc-scan-ouvrir,
.aws-search-form .pdc-scan-ouvrir {
  flex: 0 0 auto !important;
  align-self: stretch !important;
  /* 42 px au minimum : sur téléphone, le clamp tomberait à la borne basse et
     la cible deviendrait trop étroite pour un doigt. */
  width: clamp(42px, 3.2vw, 46px) !important;
  min-width: 42px !important;
  padding: 0 !important;
  border: 0 !important;
  border-right: 1px solid #e4ebe8 !important;
  border-radius: 0 !important;
  background: transparent !important;
  color: #2c463a !important;
}

.searchbox .aws-search-form .pdc-scan-ouvrir:hover,
.aws-search-form .pdc-scan-ouvrir:hover {
  color: #e62ca1 !important;
}

/* Dans la barre, le mot ne tient pas : l'icône porte le sens, et le libellé
   reste lu par les lecteurs d'écran grâce à l'aria-label du bouton. */
.aws-search-form .pdc-scan-ouvrir__texte {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.aws-search-form .pdc-scan-ouvrir svg {
  width: 20px;
  height: 20px;
}

/* Sous 480 px, le mot prend la place du champ de recherche : l'icône suffit,
   le libellé reste lisible par les lecteurs d'écran via aria-label. */
@media (max-width: 480px) {
  .pdc-scan-ouvrir__texte {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .pdc-scan-ouvrir {
    padding: 6px 8px;
  }
}

/* ===== La fenêtre ===== */
.pdc-scan {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(20, 35, 29, 0.72);
}

.pdc-scan.is-ouvert {
  display: flex;
}

body.pdc-scan-ouvert {
  overflow: hidden;
}

.pdc-scan__boite {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 20px;
  border-radius: 16px;
  background: #fff;
  color: #2c463a;
}

.pdc-scan__fermer {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 36px;
  height: 36px;
  border: 0;
  background: none;
  color: #4a6257;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}

.pdc-scan__titre {
  margin: 0 36px 4px 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.pdc-scan__aide {
  margin: 0 0 12px;
  font-size: 0.875rem;
  color: #4a6257;
}

/* Le cadre de la caméra. Le ratio évite le saut de mise en page entre le
   moment où la fenêtre s'ouvre et celui où la vidéo arrive. */
.pdc-scan__cadre {
  position: relative;
  aspect-ratio: 4 / 3;
  margin-bottom: 10px;
  border-radius: 12px;
  overflow: hidden;
  background: #142321;
}

.pdc-scan__cadre[hidden] {
  display: none;
}

.pdc-scan__video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Le viseur : une bande horizontale, parce qu'un code-barres se présente dans
   le sens de la largeur. */
.pdc-scan__viseur {
  position: absolute;
  top: 50%;
  left: 8%;
  width: 84%;
  height: 28%;
  transform: translateY(-50%);
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  box-shadow: 0 0 0 9999px rgba(20, 35, 29, 0.35);
}

.pdc-scan__etat {
  min-height: 1.3em;
  margin: 0 0 10px;
  font-size: 0.875rem;
  color: #4a6257;
}

.pdc-scan__etat.is-erreur {
  color: #a8321f;
}

.pdc-scan__resultat {
  margin-bottom: 12px;
  padding: 12px 14px;
  border: 1px solid #f5c26b;
  border-radius: 10px;
  background: #fff8eb;
  color: #5c3d00;
  font-size: 0.875rem;
  line-height: 1.45;
}

.pdc-scan__resultat p {
  margin: 0 0 6px;
}

.pdc-scan__resultat p:last-child {
  margin-bottom: 0;
}

.pdc-scan__resultat code {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.06);
  font-size: 0.8125rem;
}

/* ===== La saisie à la main ===== */
.pdc-scan__manuel label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.8125rem;
  font-weight: 600;
}

.pdc-scan__manuel-ligne {
  display: flex;
  gap: 8px;
}

.pdc-scan__manuel input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid #d6e3dd;
  border-radius: 8px;
  /* 16 px minimum : en dessous, iOS zoome sur le champ à la saisie. */
  font-size: 1rem;
}

.pdc-scan__manuel button {
  flex: 0 0 auto;
  padding: 9px 16px;
  border: 0;
  border-radius: 8px;
  background: #39c3a8;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.pdc-scan__vie-privee {
  margin: 12px 0 0;
  font-size: 0.75rem;
  color: #7b8f86;
}
