/* Panier flottant (#17) : l'onglet en bas à droite et son panneau latéral.
   Chargé par vue/panier/zone-panier.php sur chaque page publique. Toutes les
   règles partent de #panier-flottant pour ne rien changer au reste de la
   page ; chaque couleur a sa valeur de secours si la page ne définit pas
   les variables. */

#panier-flottant {
  --pf-fond: var(--fond-clair, #161b22);
  --pf-carte: var(--fond-carte, #1c2128);
  --pf-bordure: var(--bordure, #30363d);
  --pf-texte: var(--texte, #e6edf3);
  --pf-attenue: var(--texte-attenue, #8b949e);
  --pf-accent: var(--accent, #ff8a00);
  --pf-accent-clair: var(--accent-clair, #ffb15c);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
  color: var(--pf-texte);
}

#panier-flottant .texte-masque {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ===== L'onglet ===== */
#panier-flottant .onglet-panier {
  position: fixed;
  right: 1.2rem;
  bottom: 1.2rem;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.65rem 1.05rem 0.65rem 0.9rem;
  border: 2px solid var(--pf-bordure);
  border-radius: 999px;
  background: rgba(22, 27, 34, 0.96);
  color: var(--pf-texte);
  font-size: 0.92rem;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease, padding 0.2s ease;
}

#panier-flottant .onglet-panier:hover,
#panier-flottant .onglet-panier:focus-visible {
  border-color: var(--pf-accent);
  transform: translateY(-2px);
}

#panier-flottant .onglet-panier:focus-visible {
  outline: 3px solid var(--pf-accent-clair);
  outline-offset: 3px;
}

#panier-flottant .onglet-panier-icone {
  width: 1.35rem;
  height: 1.35rem;
  color: var(--pf-accent);
  flex: none;
}

#panier-flottant .onglet-panier-nombre {
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--pf-accent);
  color: #1a1200;
  font-size: 0.78rem;
  line-height: 1.35rem;
  text-align: center;
}

#panier-flottant .onglet-panier-nombre[hidden] {
  display: none;
}

#panier-flottant .onglet-panier-total {
  color: var(--pf-accent-clair);
  font-weight: 700;
}

#panier-flottant .onglet-panier-depot {
  display: none;
}

/* Loi 3 : pendant un glisser, l'onglet s'allume, grandit et dit quoi faire */
#panier-flottant.zone-active .onglet-panier {
  border-style: dashed;
  border-color: var(--pf-accent);
  padding: 1.1rem 1.5rem;
  box-shadow: 0 0 0 6px rgba(255, 138, 0, 0.25), 0 12px 32px rgba(0, 0, 0, 0.55);
}

#panier-flottant.zone-active .onglet-panier-libelle,
#panier-flottant.zone-active .onglet-panier-total {
  display: none;
}

#panier-flottant.zone-active .onglet-panier-depot {
  display: inline;
  color: var(--pf-accent-clair);
}

/* Loi 5 : survol de l'onglet pendant le mouvement */
#panier-flottant.survol-depot .onglet-panier {
  background: #2a1d0f;
  transform: scale(1.06);
}

#panier-flottant[aria-busy="true"] .onglet-panier {
  opacity: 0.85;
}

/* Loi 6 : l'onglet rebondit quand un jeu y entre */
#panier-flottant.onglet-rebond .onglet-panier {
  animation: rebond-onglet 0.45s ease-out;
}

@keyframes rebond-onglet {
  0% { transform: scale(1); }
  40% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* ===== La bulle après un ajout ===== */
#panier-flottant .bulle-panier {
  position: fixed;
  right: 1.2rem;
  bottom: 4.9rem;
  z-index: 40;
  max-width: min(20rem, calc(100vw - 2.4rem));
  margin: 0;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--pf-accent);
  border-radius: 8px;
  background: var(--pf-carte);
  color: var(--pf-texte);
  font-size: 0.88rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  animation: entree-bulle 0.25s ease-out;
}

#panier-flottant .bulle-panier[hidden] {
  display: none;
}

@keyframes entree-bulle {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ===== Le panneau ===== */
/* Fermé : hors de l'écran et hors du clavier (visibility). Ouvert par
   panier.js (.tiroir-ouvert) ou, sans JavaScript, par l'ancre #zone-panier
   (:target). Avec JavaScript (.avec-js), :target ne compte plus : le
   navigateur le garde même après history.replaceState, et la croix ne
   refermerait pas le panneau. */
#panier-flottant .voile-panier {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgba(0, 0, 0, 0.5);
}

#panier-flottant.tiroir-ouvert .voile-panier,
#panier-flottant:not(.avec-js) .tiroir-panier:target + .voile-panier {
  display: block;
}

#panier-flottant .tiroir-panier {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  width: min(26rem, 100vw);
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  padding: 1.2rem 1.3rem;
  background: var(--pf-fond);
  border-left: 1px solid var(--pf-bordure);
  box-shadow: -16px 0 40px rgba(0, 0, 0, 0.5);
  visibility: hidden;
  transform: translateX(100%);
  transition: transform 0.25s ease-out, visibility 0s linear 0.25s;
}

#panier-flottant.tiroir-ouvert .tiroir-panier,
#panier-flottant:not(.avec-js) .tiroir-panier:target {
  visibility: visible;
  transform: none;
  transition: transform 0.25s ease-out;
}

/* Pendant un glisser, le panneau ouvert est lui aussi une zone de dépôt */
#panier-flottant.zone-active .tiroir-panier {
  box-shadow: inset 0 0 0 3px var(--pf-accent), -16px 0 40px rgba(0, 0, 0, 0.5);
}

@media (prefers-reduced-motion: reduce) {
  #panier-flottant .onglet-panier,
  #panier-flottant .tiroir-panier,
  #panier-flottant .bulle-panier,
  #panier-flottant.onglet-rebond .onglet-panier,
  #panier-flottant .liste-panier li.ligne-ajoutee {
    transition: none;
    animation: none;
  }
}

#panier-flottant .tiroir-entete {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#panier-flottant .tiroir-entete h2 {
  margin: 0;
  font-size: 1.25rem;
}

#panier-flottant .tiroir-entete h2:focus {
  outline: none;
}

#panier-flottant .tiroir-fermer {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  width: 2.2rem;
  height: 2.2rem;
  border: 1px solid var(--pf-bordure);
  border-radius: 6px;
  background: transparent;
  color: var(--pf-texte);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

#panier-flottant .tiroir-fermer:hover,
#panier-flottant .tiroir-fermer:focus-visible {
  border-color: var(--pf-accent);
  color: var(--pf-accent);
}

#panier-flottant .zone-panier-consigne {
  margin: 0;
  color: var(--pf-attenue);
  font-size: 0.82rem;
}

#panier-flottant.zone-active .zone-panier-consigne {
  color: var(--pf-accent-clair);
  font-weight: 700;
}

#panier-flottant .tiroir-vide {
  margin: 0;
  color: var(--pf-attenue);
}

#panier-flottant .tiroir-vide a {
  color: var(--pf-accent-clair);
  text-decoration: underline;
}

#panier-flottant .tiroir-vide[hidden],
#panier-flottant .tiroir-pied[hidden] {
  display: none;
}

/* Les jeux */
#panier-flottant .liste-panier {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  /* Place pour la barre de défilement : les prix ne sont pas rognés */
  padding-right: 0.4rem;
  scrollbar-gutter: stable;
  display: flex;
  flex-direction: column;
}

#panier-flottant .liste-panier li {
  display: grid;
  grid-template-columns: 4.5rem 1fr auto;
  align-items: start;
  gap: 0.8rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--pf-bordure);
}

#panier-flottant .liste-panier img {
  width: 4.5rem;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--pf-bordure);
}

#panier-flottant .liste-panier-texte {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

#panier-flottant .liste-panier-titre {
  color: var(--pf-texte);
  font-weight: 700;
  text-decoration: none;
}

#panier-flottant .liste-panier-titre:hover,
#panier-flottant .liste-panier-titre:focus-visible {
  color: var(--pf-accent);
}

#panier-flottant .liste-panier-resume {
  color: var(--pf-attenue);
  font-size: 0.8rem;
}

#panier-flottant .liste-panier-actions {
  display: flex;
  gap: 0.9rem;
  margin-top: 0.2rem;
  font-size: 0.82rem;
}

#panier-flottant .liste-panier-actions a,
#panier-flottant .bouton-retirer-ligne {
  padding: 0;
  border: none;
  background: none;
  color: var(--pf-accent-clair);
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

#panier-flottant .bouton-retirer-ligne {
  color: var(--pf-attenue);
}

#panier-flottant .bouton-retirer-ligne:hover,
#panier-flottant .bouton-retirer-ligne:focus-visible {
  color: #ffb3a7;
}

#panier-flottant .liste-panier-prix {
  color: var(--pf-accent-clair);
  font-weight: 700;
  white-space: nowrap;
}

#panier-flottant .ligne-indisponible img,
#panier-flottant .ligne-indisponible .liste-panier-titre {
  opacity: 0.5;
}

#panier-flottant .ligne-indisponible .liste-panier-resume {
  color: #ffb3a7;
}

/* Loi 6 : le jeu déposé apparaît en image, avec une courte animation */
#panier-flottant .liste-panier li.ligne-ajoutee {
  animation: arrivee-panier 0.45s ease-out;
}

@keyframes arrivee-panier {
  0% { transform: translateY(-12px) scale(0.92); opacity: 0; background: rgba(255, 138, 0, 0.3); }
  100% { transform: none; opacity: 1; background: transparent; }
}

/* Le pied : total et caisse */
#panier-flottant .tiroir-pied {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding-top: 0.4rem;
}

#panier-flottant .zone-panier-resume {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 0;
  color: var(--pf-attenue);
}

#panier-flottant .zone-panier-resume strong {
  color: var(--pf-accent);
  font-size: 1.3rem;
}

#panier-flottant .tiroir-caisse {
  display: block;
  padding: 0.8rem 1rem;
  border-radius: 4px;
  background: var(--pf-accent);
  color: #1a1200;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
}

#panier-flottant .tiroir-caisse:hover,
#panier-flottant .tiroir-caisse:focus-visible {
  background: var(--pf-accent-clair);
}

#panier-flottant .tiroir-note {
  margin: 0;
  color: var(--pf-attenue);
  font-size: 0.78rem;
}

/* Résultat d'un envoi sans JavaScript */
#panier-flottant .panier-message {
  margin: 0;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--pf-accent);
  border-radius: 6px;
  font-size: 0.88rem;
}

#panier-flottant .panier-message-erreur {
  border-color: #ffa198;
  color: #ffb3a7;
}

#panier-flottant .formulaire-retirer-ligne {
  display: inline;
  margin: 0;
}

#panier-flottant .zone-panier-erreur {
  margin: 0;
  color: #ffb3a7;
  font-size: 0.85rem;
}

#panier-flottant .zone-panier-erreur:empty {
  display: none;
}

/* Sur un téléphone : l'onglet se réduit à l'icône, au nombre et au total */
@media (max-width: 520px) {
  #panier-flottant .onglet-panier {
    right: 0.8rem;
    bottom: 0.8rem;
  }

  #panier-flottant .onglet-panier-libelle {
    display: none;
  }

  #panier-flottant .bulle-panier {
    right: 0.8rem;
    bottom: 4.3rem;
  }
}
