/*
 * Boîtes de dialogue ONARP (assets/js/dialogue.js). Remplacent alert(), confirm() et prompt(),
 * qui sont interdits sur le site. Contrastes consignés dans docs/design/contrastes.md.
 */

.dlg {
  --dlg-accent: #0B1A2F;
  --dlg-accent-fond: #E8EDF4;
  width: min(540px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);   /* navigateurs sans dvh */
  max-height: calc(100dvh - 48px);
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: #FFFFFF;
  color: #1A2A42;
  box-shadow: 0 24px 60px rgba(11, 26, 47, .28), 0 2px 8px rgba(11, 26, 47, .12);
  font: 400 16px/1.6 Inter, "Segoe UI", Arial, sans-serif;
  overflow: hidden;
  overscroll-behavior: contain;
}
.dlg[open] { display: flex; flex-direction: column; animation: dlg-entree .26s cubic-bezier(.2, .8, .2, 1) both; }
.dlg::backdrop { background: rgba(11, 26, 47, .55); backdrop-filter: blur(3px); animation: dlg-voile-entree .26s ease both; }
.dlg.dlg--sortie { animation: dlg-sortie .18s cubic-bezier(.4, 0, 1, 1) both; }
.dlg.dlg--sortie::backdrop { animation: dlg-voile-sortie .18s ease both; }

/* Filet doré en tête, rappel de la charte. */
.dlg::before { content: ""; display: block; flex: none; height: 4px; background: linear-gradient(90deg, #C4983E, #E4CB8A 60%, #C4983E); }

.dlg--attention { --dlg-accent: #7A5A12; --dlg-accent-fond: #FAF5E6; }
.dlg--alerte    { --dlg-accent: #A4161A; --dlg-accent-fond: #FCEDEE; }
.dlg--succes    { --dlg-accent: #1E6B3A; --dlg-accent-fond: #EAF5EE; }

.dlg__corps { display: flex; gap: 16px; padding: 28px 28px 8px; overflow-y: auto; }
.dlg__icone {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--dlg-accent-fond);
  color: var(--dlg-accent);
  animation: dlg-icone .4s .08s cubic-bezier(.2, .8, .2, 1) both;
}
.dlg__icone svg { width: 22px; height: 22px; }
.dlg__texte { min-width: 0; }
.dlg__titre { margin: 8px 0 8px; font-size: 20px; font-weight: 600; line-height: 1.35; color: #0B1A2F; }
.dlg__message { margin: 0 0 12px; color: #374151; }
.dlg__details { margin: 0 0 12px; padding-left: 20px; color: #374151; }
.dlg__details li + li { margin-top: 4px; }

.dlg__actions {
  display: flex;
  flex: none;   /* boutons toujours visibles : c'est le corps qui défile */
  flex-wrap: wrap-reverse;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 28px 24px;
}
.dlg__bouton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 22px;
  border: 1px solid transparent;
  border-radius: 8px;
  font: 600 15px/1 Inter, "Segoe UI", Arial, sans-serif;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, transform .1s ease;
}
.dlg__bouton:active { transform: translateY(1px); }
.dlg__bouton:focus-visible { outline: 3px solid #1D4E89; outline-offset: 2px; }
.dlg__bouton--primaire   { background: #0B1A2F; border-color: #C4983E; color: #FFFFFF; }
.dlg__bouton--primaire:hover { background: #1D3A5F; }
.dlg__bouton--secondaire { background: #FFFFFF; border-color: #6B7280; color: #1A2A42; }
.dlg__bouton--secondaire:hover { background: #F3F4F6; }
.dlg__bouton--alerte     { background: #A4161A; color: #FFFFFF; }
.dlg__bouton--alerte:hover { background: #7A1013; }

@keyframes dlg-entree       { from { opacity: 0; transform: translateY(14px) scale(.965); } to { opacity: 1; transform: none; } }
@keyframes dlg-sortie       { to   { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes dlg-voile-entree { from { opacity: 0; } }
@keyframes dlg-voile-sortie { to   { opacity: 0; } }
@keyframes dlg-icone        { from { opacity: 0; transform: scale(.6); } }
@keyframes dlg-feuille      { from { transform: translateY(100%); } to { transform: none; } }
@keyframes dlg-feuille-sortie { to { transform: translateY(100%); } }

/* Mobile : feuille montant du bas, boutons pleine largeur. */
@media (max-width: 560px) {
  .dlg { width: 100%; max-width: none; margin: auto 0 0; border-radius: 16px 16px 0 0; }
  .dlg[open] { animation-name: dlg-feuille; animation-duration: .3s; }
  .dlg.dlg--sortie { animation-name: dlg-feuille-sortie; animation-duration: .22s; }
  .dlg__corps { padding: 24px 20px 4px; }
  .dlg__actions { flex-direction: column-reverse; padding: 12px 20px max(20px, env(safe-area-inset-bottom)); }
  .dlg__bouton { width: 100%; }
}
/* Très petits écrans : pictogramme au-dessus du texte pour garder toute la largeur au message. */
@media (max-width: 400px) {
  .dlg__corps { flex-direction: column; gap: 4px; }
  .dlg__titre { font-size: 19px; }
}

@media (prefers-reduced-motion: reduce) {
  .dlg[open], .dlg.dlg--sortie, .dlg__icone, .dlg::backdrop, .dlg.dlg--sortie::backdrop {
    animation-duration: .01ms;
  }
}

/* ------------------------------------------------------------ modale à onglets (mentions, confidentialité) */

.dlg--document { width: min(760px, calc(100vw - 32px)); height: min(720px, calc(100vh - 48px)); height: min(720px, calc(100dvh - 48px)); }
.dlg--document[open] { display: flex; flex-direction: column; }
.dlg--formulaire { height: auto; max-height: calc(100vh - 48px); max-height: calc(100dvh - 48px); }
.dlg__tete { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 22px 20px 6px 28px; }
.dlg__tete .dlg__titre { margin: 0; }
.dlg__fermer {
  flex: none; display: grid; place-items: center; width: 44px; height: 44px; padding: 0;
  border: 0; border-radius: 50%; background: transparent; color: #374151; cursor: pointer;
  transition: background-color .3s ease, color .3s ease, transform .4s cubic-bezier(.34, 1.4, .64, 1);
}
.dlg__fermer svg { width: 20px; height: 20px; }
.dlg__fermer:hover { background: #EEF3FA; color: #0B1A2F; transform: rotate(90deg); }
.dlg__fermer:focus-visible { outline: 3px solid #1D4E89; outline-offset: 2px; }
.dlg__onglets { position: relative; display: flex; gap: 4px; padding: 0 28px; border-bottom: 1px solid #D9DDE3; overflow-x: auto; scrollbar-width: none; }
.dlg__onglet {
  flex: none; min-height: 48px; padding: 0 14px; border: 0; background: none;
  color: #374151; font: 500 15px/1.2 Inter, "Segoe UI", Arial, sans-serif; cursor: pointer;
  transition: color .3s ease;
}
.dlg__onglet:hover { color: #0B1A2F; }
.dlg__onglet[aria-selected="true"] { color: #0B1A2F; font-weight: 600; }
.dlg__onglet:focus-visible { outline: 3px solid #1D4E89; outline-offset: -3px; border-radius: 6px; }
.dlg__marqueur {
  position: absolute; left: 0; bottom: -1px; height: 3px; width: 0; border-radius: 2px 2px 0 0;
  background: #C4983E; transition: transform .45s cubic-bezier(.2, .7, .2, 1), width .45s cubic-bezier(.2, .7, .2, 1);
}
.dlg__panneaux { flex: 1; min-height: 0; position: relative; }
.dlg__panneau { height: 100%; overflow-y: auto; overscroll-behavior: contain; padding: 22px 28px 28px; }
.dlg__panneau:focus-visible { outline: 3px solid #1D4E89; outline-offset: -3px; }
.dlg__panneau--entree { animation: dlg-panneau .4s cubic-bezier(.2, .7, .2, 1) both; }
@keyframes dlg-panneau { from { opacity: 0; transform: translateY(8px); } }
@media (max-width: 560px) {
  .dlg--document { height: calc(100vh - 24px); height: calc(100dvh - 24px); }
  .dlg__tete { padding: 18px 12px 4px 20px; }
  .dlg__onglets { padding: 0 20px; }
  .dlg__panneau { padding: 18px 20px max(24px, env(safe-area-inset-bottom)); }
}

/* ------------------------------------------------------------ modale de chiffrement et d'envoi
 * Scène : document (lignes qui se chiffrent) -> trajet (paquets) -> coffre (cadenas puis coche).
 * data-temps sur .chiffre : 1 chiffrement, 2 transmission, 3 enregistrement, fini.
 */

.dlg:focus-visible { outline: none; }
.dlg--chiffrement { width: min(500px, calc(100vw - 32px)); text-align: center; }
.dlg--chiffrement::before { background: linear-gradient(90deg, #13294A, #C4983E 40%, #E4CB8A 60%, #13294A); background-size: 200% 100%; animation: chiffre-lisere 1.6s linear infinite; }
.dlg--chiffre-ok::before { animation: none; background: linear-gradient(90deg, #1E6B3A, #3E9B63 50%, #1E6B3A); }
@keyframes chiffre-lisere { to { background-position: -200% 0; } }
.chiffre__corps-modale { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 30px 28px 30px; }
.dlg--chiffre-ok .chiffre__corps-modale { padding-bottom: 6px; }

.chiffre {
  position: relative; display: grid; grid-template-columns: 1fr 76px auto; align-items: center; gap: 0;
  margin: 0 auto 22px; padding: 18px 18px; max-width: 400px;
  border-radius: 16px; background: linear-gradient(160deg, #13294A, #0B1A2F); overflow: hidden;
}
.chiffre::before {
  /* Fin quadrillage, comme un papier sécurisé */
  content: ""; position: absolute; inset: 0; opacity: .08;
  background-image: linear-gradient(#E4CB8A 1px, transparent 1px), linear-gradient(90deg, #E4CB8A 1px, transparent 1px);
  background-size: 14px 14px;
}

/* Document */
.chiffre__doc {
  position: relative; display: grid; gap: 7px; padding: 14px 14px 14px 12px;
  border-radius: 10px; background: #FFFFFF; text-align: left;
  box-shadow: 0 10px 22px -10px rgba(0, 0, 0, .6);
  transition: transform .6s cubic-bezier(.2, .7, .2, 1), box-shadow .6s ease;
}
.chiffre__ligne {
  display: block; overflow: hidden; white-space: nowrap; text-overflow: clip;
  color: #1A2A42; font: 500 11px/1.3 Inter, "Segoe UI", Arial, sans-serif;
  transition: color .4s ease;
}
.chiffre__ligne--chiffree { color: #8A6A1F; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .04em; }
.chiffre__sceau {
  position: absolute; right: -10px; bottom: -10px; display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 50%; background: #C4983E; color: #FFFFFF;
  box-shadow: 0 0 0 3px #13294A; transform: scale(0); transition: transform .5s cubic-bezier(.34, 1.56, .64, 1);
}
.chiffre__sceau svg { width: 15px; height: 15px; }
.chiffre:not([data-temps="1"]) .chiffre__sceau { transform: scale(1); }
.chiffre[data-temps="2"] .chiffre__doc, .chiffre[data-temps="3"] .chiffre__doc { transform: scale(.94); }

/* Trajet : paquets qui voyagent pendant la transmission */
.chiffre__trajet { position: relative; height: 2px; margin: 0 6px; background-image: linear-gradient(90deg, rgba(228, 203, 138, .5) 50%, transparent 50%); background-size: 8px 2px; }
.chiffre__paquet {
  position: absolute; top: -3px; left: 0; width: 8px; height: 8px; border-radius: 2px;
  background: #E4CB8A; box-shadow: 0 0 8px rgba(228, 203, 138, .9); opacity: 0;
}
.chiffre[data-temps="2"] .chiffre__paquet, .chiffre[data-temps="3"] .chiffre__paquet { animation: chiffre-paquet 1.1s ease-in-out infinite; }
.chiffre__paquet:nth-child(2) { animation-delay: .35s !important; }
.chiffre__paquet:nth-child(3) { animation-delay: .7s !important; }
@keyframes chiffre-paquet { 0% { left: 0; opacity: 0; } 15% { opacity: 1; } 85% { opacity: 1; } 100% { left: calc(100% - 8px); opacity: 0; } }
.chiffre[data-temps="fini"] .chiffre__paquet { animation: none; opacity: 0; }

/* Coffre */
.chiffre__coffre {
  position: relative; width: 84px; height: 84px; border-radius: 50%;
  background: #0B1A2F; color: #E4CB8A; box-shadow: inset 0 0 0 2px rgba(228, 203, 138, .45);
  transition: background-color .6s ease, color .6s ease, box-shadow .6s ease;
}
.chiffre__coffre::after {
  content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 1.5px solid rgba(228, 203, 138, .5);
  animation: chiffre-halo 1.8s ease-in-out infinite;
}
@keyframes chiffre-halo { 50% { transform: scale(1.08); opacity: .35; } }
.chiffre__coffre svg { position: absolute; inset: 12px; width: 60px; height: 60px; }
.chiffre__anse { transform: translateY(-6px); transition: transform .5s cubic-bezier(.34, 1.56, .64, 1); }
.chiffre[data-temps="3"] .chiffre__anse, .chiffre[data-temps="fini"] .chiffre__anse { transform: none; }
.chiffre[data-temps="3"] .chiffre__coffre { box-shadow: inset 0 0 0 2px #E4CB8A, 0 0 22px rgba(228, 203, 138, .35); }
.chiffre__trou { animation: chiffre-trou 1.2s ease-in-out infinite; }
@keyframes chiffre-trou { 50% { opacity: .3; } }
.chiffre__coche { opacity: 0; }
.chiffre__coche * { stroke-dasharray: 1; stroke-dashoffset: 1; }

/* Réussite : le coffre devient une coche verte, le document s'apaise */
.dlg--chiffre-ok .chiffre__coffre { background: #1E6B3A; color: #FFFFFF; box-shadow: 0 0 0 6px rgba(30, 107, 58, .25); }
.dlg--chiffre-ok .chiffre__coffre::after { animation: chiffre-onde 1.2s .3s ease-out both; border-color: #3E9B63; }
@keyframes chiffre-onde { from { transform: scale(1); opacity: .7; } to { transform: scale(1.6); opacity: 0; } }
.dlg--chiffre-ok .chiffre__cadenas { animation: chiffre-sortie .35s ease both; }
@keyframes chiffre-sortie { to { opacity: 0; transform: scale(.6) rotate(-10deg); } }
.dlg--chiffre-ok .chiffre__coche { opacity: 1; transition: opacity .2s .25s; }
.dlg--chiffre-ok .chiffre__coche circle { animation: chiffre-trace .6s .3s cubic-bezier(.2, .7, .2, 1) forwards; }
.dlg--chiffre-ok .chiffre__coche path { animation: chiffre-trace .45s .8s cubic-bezier(.2, .7, .2, 1) forwards; }
@keyframes chiffre-trace { to { stroke-dashoffset: 0; } }
.dlg--chiffre-ok .chiffre__doc { transform: scale(.9); box-shadow: 0 0 0 2px #3E9B63, 0 10px 22px -10px rgba(0, 0, 0, .6); }

.chiffre__titre { margin: 0 0 6px; }
.chiffre__etat { margin: 0 0 16px; color: #374151; }
.chiffre__barre { height: 4px; margin: 0 auto 18px; max-width: 300px; border-radius: 2px; background: #E4E7EC; overflow: hidden; }
.chiffre__barre span { display: block; width: 0; height: 100%; border-radius: 2px; background: linear-gradient(90deg, #0B1A2F, #C4983E); transition: width .8s cubic-bezier(.2, .7, .2, 1); }
.dlg--chiffre-ok .chiffre__barre span { background: linear-gradient(90deg, #1E6B3A, #3E9B63); }

.chiffre__etapes { display: grid; gap: 8px; margin: 0 auto; padding: 0; max-width: 300px; list-style: none; text-align: left; }
.chiffre__etape { display: flex; align-items: center; gap: 10px; color: #6B7280; font-size: 15px; transition: color .4s ease; }
.chiffre__puce { flex: none; position: relative; width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid #9CA3AF; transition: border-color .4s ease, background-color .4s ease; }
.chiffre__etape--en-cours { color: #0B1A2F; font-weight: 500; }
.chiffre__etape--en-cours .chiffre__puce { border-color: #C4983E; border-top-color: transparent; animation: tourne-dlg .9s linear infinite; }
@keyframes tourne-dlg { to { transform: rotate(360deg); } }
.chiffre__etape--faite { color: #1A2A42; }
.chiffre__etape--faite .chiffre__puce { border-color: #1E6B3A; background: #1E6B3A; animation: chiffre-puce .35s cubic-bezier(.34, 1.56, .64, 1); }
@keyframes chiffre-puce { from { transform: scale(.6); } }
.chiffre__etape--faite .chiffre__puce::after {
  content: ""; position: absolute; left: 5px; top: 2px; width: 4px; height: 8px;
  border: solid #FFFFFF; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.chiffre__actions { justify-content: center; }
.chiffre__actions:not([hidden]) { animation: dlg-panneau .45s 1s cubic-bezier(.2, .7, .2, 1) both; }
@media (max-width: 400px) {
  .chiffre { grid-template-columns: 1fr 40px auto; padding: 14px; }
  .chiffre__coffre { width: 68px; height: 68px; }
  .chiffre__coffre svg { inset: 10px; width: 48px; height: 48px; }
}
@media (prefers-reduced-motion: reduce) {
  .dlg--chiffrement::before, .chiffre__coffre::after, .chiffre__trou, .chiffre__etape--en-cours .chiffre__puce, .chiffre__paquet { animation: none !important; }
  .dlg--chiffre-ok .chiffre__coche * { stroke-dashoffset: 0; animation: none; }
}

/* Mobile : les modales larges (documents, chiffrement) deviennent aussi des feuilles pleine largeur */
@media (max-width: 560px) {
  .dlg--document, .dlg--chiffrement { width: 100%; max-width: none; }
  .dlg__onglets { padding: 0 12px; }
  .dlg__onglet { padding: 0 10px; }
  .chiffre__corps-modale { padding: 26px 18px 24px; }
}

/* Écrans peu hauts (téléphone en paysage) : marges réduites, le contenu défile au lieu d'être coupé */
@media (max-height: 520px) {
  .dlg { max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); }
  .dlg--document { height: calc(100vh - 16px); height: calc(100dvh - 16px); }
  .dlg__corps { padding-top: 18px; }
  .dlg__tete { padding-top: 12px; }
  .dlg__onglet { min-height: 40px; }
  .chiffre__corps-modale { padding: 16px 20px; }
  .dlg__actions { padding-top: 8px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
}
/* Fond de page figé derrière une modale ouverte (évite le défilement de la page sous la feuille) */
html:has(dialog[open]) { overflow: hidden; }
