/*
  Noren : feuilles du bas, voile et toasts (CSS seul, aucun JavaScript ici).
  Variables de main.css. Mobile : panneau collé en bas (coins 24 en haut).
  À partir de 768 px : modale centrée de 480 px (coins 24 partout).

  HTML À COPIER

  Feuille (le .voile contient la .feuille ; l'attribut hidden le cache) :
  <div class="voile" hidden>
    <section class="feuille" role="dialog" aria-modal="true" aria-labelledby="feuille-titre-1">
      <header class="feuille__entete">
        <h2 class="feuille__titre" id="feuille-titre-1">Titre de la feuille</h2>
        <button class="feuille__fermer" type="button" aria-label="Fermer">
          <svg class="icone" aria-hidden="true"><use href="/assets/icons.svg#x"></use></svg>
        </button>
      </header>
      <div class="feuille__corps">Contenu défilable</div>
      <footer class="feuille__pied">
        <button class="btn btn--principal btn--bloc" type="button">Action principale</button>
      </footer>
    </section>
  </div>

  Toast (région « polie » : annoncée par les lecteurs d'écran) :
  <div class="toast" role="status" aria-live="polite">Numéro copié.</div>

  Pour le JS (plus tard) :
  - Ouvrir : retirer l'attribut hidden du .voile et ajouter la classe
    feuille-ouverte sur <body> (bloque le défilement de la page).
  - Fermer en douceur : ajouter .voile--sortie, attendre animationend sur le
    .voile, puis remettre hidden et retirer les classes. Avec « réduire les
    animations », animationend n'a jamais lieu : fermer tout de suite.
  - Toast : ajouter / retirer la classe est-visible.
*/

/* ---------- Voile ---------- */
.voile {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;   /* mobile : feuille collée en bas */
  justify-content: center;
  background: rgba(7, 26, 51, .45); /* navy-900 à 40 % */
  overscroll-behavior: contain;
  animation: voile-entree .2s ease-out both;
}

.voile[hidden] {
  display: none;
}

/* Pendant que la feuille est ouverte, la page dessous ne défile plus */
body.feuille-ouverte {
  overflow: hidden;
}

/* ---------- Feuille ---------- */
.feuille {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: 90vh;  /* repli */
  max-height: 90dvh;
  overflow: hidden;
  border-radius: var(--rayon-feuille); /* 24 en haut */
  background: var(--surface);
  box-shadow: none;
  border: 1px solid var(--bordure);
  animation: feuille-montee .28s cubic-bezier(.2, .8, .2, 1) both;
}

/* Poignée grise (décorative, mobile seulement) */
.feuille::before {
  content: "";
  flex-shrink: 0;
  width: 40px;
  height: 4px;
  margin: 12px auto 0;
  border-radius: var(--rayon-pilule);
  background: var(--slate-400);
}

/* En-tête : titre + bouton fermer */
.feuille__entete {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  gap: var(--espace-2);
  padding: var(--espace-1) var(--espace-1) var(--espace-1) var(--marge-laterale);
}

.feuille__titre {
  flex: 1 1 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.feuille__fermer {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: var(--zone-tactile);
  height: var(--zone-tactile);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: var(--rayon-pilule);
  background: transparent;
  color: var(--navy-900);
  -webkit-tap-highlight-color: transparent;
}
.feuille__fermer:hover {
  background: var(--slate-50);
}
.feuille__fermer:active {
  background: var(--bordure);
}

/* Corps : seule zone qui défile */
.feuille__corps {
  flex: 1 1 auto;
  min-height: 0;
  padding: var(--espace-1) var(--marge-laterale) var(--espace-2);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* Pied collant : le bouton principal reste visible, au-dessus de la zone sûre */
.feuille__pied {
  flex-shrink: 0;
  padding: var(--espace-2) var(--marge-laterale);
  padding-bottom: calc(var(--espace-2) + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--bordure);
  background: var(--surface);
}

/* ---------- Ordinateur et tablette : modale centrée ---------- */
@media (min-width: 768px) {
  .voile {
    align-items: center;
    padding: var(--marge-laterale);
  }

  .feuille {
    width: 480px;
    max-width: 100%;
    border-radius: 4px; /* coins arrondis partout */
    animation-name: feuille-fondu;
    animation-duration: .2s;
    animation-timing-function: ease-out;
  }

  .feuille::before {
    display: none; /* pas de poignée sur une modale */
  }

  .feuille__entete {
    padding-top: var(--espace-2);
  }

  .feuille__pied {
    padding-bottom: var(--espace-2);
  }
}

/* ---------- Fermeture douce (classe posée par le JS) ---------- */
.voile--sortie {
  animation: voile-sortie .2s ease-in both;
  pointer-events: none;
}
.voile--sortie .feuille {
  animation: feuille-descente .2s ease-in both;
}
@media (min-width: 768px) {
  .voile--sortie .feuille {
    animation-name: feuille-fondu-sortie;
  }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--espace-3) + env(safe-area-inset-bottom, 0px));
  z-index: 110; /* au-dessus du voile */
  width: max-content;
  max-width: calc(100% - 2 * var(--marge-laterale));
  padding: 12px var(--espace-2);
  border-radius: var(--rayon-bouton);
  background: var(--navy-900);
  box-shadow: none;
  border: 1px solid var(--bordure);
  color: #fff;
  font-size: var(--texte-s);
  line-height: var(--interligne-s);
  text-align: center;
  overflow-wrap: anywhere;
  /* caché par défaut */
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity .2s ease, transform .2s ease, visibility 0s linear .2s;
}

.toast.est-visible {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
  transition: opacity .2s ease, transform .2s ease, visibility 0s;
}

/* Page avec barre d'onglets (mobile) : le toast se pose au-dessus d'elle */
body.avec-onglets .toast {
  bottom: calc(var(--hauteur-onglets, 64px) + 1px + var(--espace-2) + env(safe-area-inset-bottom, 0px));
}
@media (min-width: 1024px) {
  body.avec-onglets .toast {
    bottom: calc(var(--espace-3) + env(safe-area-inset-bottom, 0px));
  }
}

/* ---------- Animations ---------- */
@keyframes voile-entree { from { opacity: 0; } to { opacity: 1; } }
@keyframes voile-sortie { from { opacity: 1; } to { opacity: 0; } }
@keyframes feuille-montee {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
@keyframes feuille-descente {
  from { transform: translateY(0); }
  to   { transform: translateY(100%); }
}
@keyframes feuille-fondu {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes feuille-fondu-sortie {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(8px); }
}

/* Respect du réglage « réduire les animations » : tout apparaît d'un coup */
@media (prefers-reduced-motion: reduce) {
  .voile,
  .feuille,
  .voile--sortie,
  .voile--sortie .feuille {
    animation: none !important;
  }

  .toast,
  .toast.est-visible {
    transform: translate(-50%, 0);
    transition: none !important;
  }
}
