/*
 * Lot D1 (2026-10-07) : composant « dialogue DRM » de la direction artistique v9.
 * Spécification : DESIGN-ECARTS-FRONT.md §2 et maquette dlg/maquette-dialogue-drm.html.
 *
 * Remplace à l'écran les fenêtres Bootstrap fabriquées par fonctions_global.js (modalConfirm, modalCenter),
 * les notifications toastr et le voile de chargement, qui n'avaient plus de style sur les pages redessinées.
 * Comportement : public/assets/js/dr-dialogue.js.
 *
 * Feuille AUTONOME : ses jetons sont posés sur .dr-dlg, .dr-toasts et .dr-voile. Elle ne dépend ni de
 * body.ds-page ni de drm-v9-compte.css (dc-btn et dc-alerte n'existent que sur Mon compte et le tunnel), car elle
 * sert aussi le catalogue et les pages non redessinées. Valeurs reprises de drm-v9.css (--dr-*) et de dc-alerte.
 */
.dr-dlg, .dr-toasts, .dr-voile {
    --dlg-texte: #1c1b1f; --dlg-texte-2: #6a6a6a; --dlg-bordure: #e3e3e8; --dlg-sep: #eeeff2; --dlg-hover: #f7f7f8;
    --dlg-danger: #b3261e; --dlg-danger-hover: #8f1d17;
    --dlg-r-md: 12px; --dlg-r-lg: 16px; --dlg-r-xl: 20px;
    --dlg-info-fond: #eef6ff; --dlg-info-bord: #c7defa; --dlg-info-texte: #00408f;
    --dlg-succes-fond: #f0fdf4; --dlg-succes-bord: #bbf7d0; --dlg-succes-texte: #166534;
    --dlg-attention-fond: #fffbeb; --dlg-attention-bord: #fde68a; --dlg-attention-texte: #92400e;
    --dlg-erreur-fond: #fef2f2; --dlg-erreur-bord: #fecaca; --dlg-erreur-texte: #b91c1c;
    font-family: var(--ds-font, "Inter", -apple-system, "Helvetica Neue", Arial, sans-serif);
    color: var(--dlg-texte);
    letter-spacing: normal;
    text-transform: none;
}
.dr-dlg *, .dr-dlg *::before, .dr-dlg *::after, .dr-toasts *, .dr-voile * { box-sizing: border-box; }

/* Coque : dialog natif (couche supérieure ; piège du focus, inertie du fond et Échap fournis par le navigateur). */
.dr-dlg {
    border: 0; padding: 0; margin: auto; background: transparent; color: var(--dlg-texte);
    width: min(440px, calc(100vw - 32px)); max-width: none; max-height: none; overflow: visible;
    font-size: 15px; line-height: 1.5; text-align: left;
}
.dr-dlg--fenetre { width: min(720px, calc(100vw - 32px)); }
.dr-dlg--large { width: min(960px, calc(100vw - 32px)); }
.dr-dlg::backdrop { background: rgba(28, 27, 31, .48); }
.dr-dlg[open] { animation: dr-dlg-entree .2s cubic-bezier(.22, .61, .36, 1); }
.dr-dlg[open]::backdrop { animation: dr-dlg-fond .2s ease-out; }
@keyframes dr-dlg-entree { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes dr-dlg-fond { from { opacity: 0; } to { opacity: 1; } }
/* Fond figé tant qu'une fenêtre est ouverte, sans état JavaScript à tenir (une fenêtre retirée du DOM le libère). */
html:has(dialog.dr-dlg[open]), body:has(dialog.dr-dlg[open]) { overflow: hidden; }

.dr-dlg__carte {
    display: flex; flex-direction: column; gap: 24px; margin: 0; padding: 24px;
    background: #fff; border-radius: var(--dlg-r-lg); max-height: calc(100dvh - 48px);
    box-shadow: 0 24px 64px rgba(17, 24, 39, .24), 0 2px 8px rgba(17, 24, 39, .08);
}
.dr-dlg__corps { display: flex; flex-direction: column; gap: 8px; min-height: 0; overflow: auto; }
.dr-dlg__titre { margin: 0; font-size: 18px; line-height: 1.35; font-weight: 600; letter-spacing: -.01em; color: var(--dlg-texte); font-family: inherit; text-transform: none; }
.dr-dlg__texte { margin: 0; font-size: 15px; line-height: 1.5; color: var(--dlg-texte-2); }
.dr-dlg__texte p { margin: 0 0 8px; }
.dr-dlg__texte p:last-child { margin-bottom: 0; }
/* Le titre reçoit le focus initial d'une fenêtre de contenu (tabindex -1, hors de l'ordre de tabulation) : pas de
   halo, ce n'est pas une commande. Les commandes gardent leur contour. */
.dr-dlg__titre:focus, .dr-dlg__titre:focus-visible { outline: none; }
.dr-dlg__texte strong { color: var(--dlg-texte); font-weight: 600; }

/* Champ et choix (devis : libellé ; suppression de paniers : portée) */
.dr-dlg__champ { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.dr-dlg__etiquette { margin: 0; font-size: 14px; font-weight: 600; color: var(--dlg-texte); }
.dr-dlg__saisie {
    width: 100%; height: 44px; padding: 0 14px; border: 1px solid #8a8a91; border-radius: var(--dlg-r-md);
    font: inherit; font-size: 15px; color: var(--dlg-texte); background: #fff;
}
.dr-dlg__saisie:focus-visible { outline: 2px solid var(--dlg-texte); outline-offset: 2px; border-color: var(--dlg-texte); }
.dr-dlg__choix { border: 0; margin: 8px 0 0; padding: 0; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.dr-dlg__legende { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.dr-dlg__option {
    display: flex; align-items: center; gap: 12px; min-height: 44px; margin: 0; padding: 8px 14px;
    border: 1px solid var(--dlg-bordure); border-radius: var(--dlg-r-md);
    font-size: 15px; font-weight: 400; line-height: 1.35; color: var(--dlg-texte); cursor: pointer;
}
.dr-dlg__option:hover { background: var(--dlg-hover); }
.dr-dlg__option input { flex: none; width: 18px; height: 18px; margin: 0; accent-color: var(--dlg-texte); }
.dr-dlg__option:has(input:checked) { border-color: var(--dlg-texte); }
.dr-dlg__option:has(input:focus-visible) { outline: 2px solid var(--dlg-texte); outline-offset: 2px; }

/* Actions : DOM = principale puis secondaire ; au bureau à droite, principale en dernier. */
.dr-dlg__actions { display: flex; flex-direction: row-reverse; justify-content: flex-start; gap: 12px; }
.dr-dlg__btn {
    display: inline-flex; align-items: center; justify-content: center; min-height: 44px; margin: 0; padding: 0 20px;
    border-radius: var(--dlg-r-md); border: 1px solid var(--dlg-bordure); background: #fff; color: var(--dlg-texte);
    font: inherit; font-size: 14.5px; font-weight: 600; line-height: 1.2; text-align: center; text-decoration: none;
    cursor: pointer; box-shadow: none; text-transform: none;
    transition: background-color .14s, border-color .14s, color .14s;
}
.dr-dlg__btn:hover { background: var(--dlg-hover); border-color: #cfcfd6; color: var(--dlg-texte); text-decoration: none; }
.dr-dlg__btn:focus-visible { outline: 2px solid var(--dlg-texte); outline-offset: 2px; }
.dr-dlg__btn--principal { background: var(--dlg-texte); border-color: var(--dlg-texte); color: #fff; }
.dr-dlg__btn--principal:hover { background: #000; border-color: #000; color: #fff; }
.dr-dlg__btn--danger { background: var(--dlg-danger); border-color: var(--dlg-danger); color: #fff; }
.dr-dlg__btn--danger:hover { background: var(--dlg-danger-hover); border-color: var(--dlg-danger-hover); color: #fff; }

/* Variante fenêtre : en-tête fixe, corps qui défile, pied fixe. */
.dr-dlg--fenetre .dr-dlg__carte, .dr-dlg--large .dr-dlg__carte { padding: 0; gap: 0; }
.dr-dlg__entete { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 24px; border-bottom: 1px solid var(--dlg-sep); }
.dr-dlg__fermer {
    flex: none; display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; margin: -8px -12px -8px 0; padding: 0;
    border: 0; border-radius: var(--dlg-r-md); background: transparent; color: var(--dlg-texte); cursor: pointer;
}
.dr-dlg__fermer:hover { background: var(--dlg-hover); }
.dr-dlg__fermer:focus-visible { outline: 2px solid var(--dlg-texte); outline-offset: 2px; }
.dr-dlg__defile { padding: 24px; overflow: auto; min-height: 0; flex: 1 1 auto; font-size: 15px; line-height: 1.6; color: var(--dlg-texte); }
/* Contenu historique injecté dans la fenêtre (gabarits serveur) : la grille Bootstrap « row » ne doit pas déborder. */
.dr-dlg__defile.row { display: block; margin: 0; }
.dr-dlg__pied { display: flex; flex-direction: row-reverse; justify-content: flex-start; gap: 12px; padding: 16px 24px; border-top: 1px solid var(--dlg-sep); }
.dr-dlg__pied:empty { display: none; }

/* Mobile : feuille basse. */
@media (max-width: 640px) {
    .dr-dlg, .dr-dlg--fenetre, .dr-dlg--large { width: 100%; max-width: 100%; margin: auto 0 0; }
    .dr-dlg[open] { animation-name: dr-dlg-feuille; animation-duration: .25s; }
    .dr-dlg__carte { border-radius: var(--dlg-r-xl) var(--dlg-r-xl) 0 0; padding: 24px 16px calc(16px + env(safe-area-inset-bottom)); max-height: calc(100dvh - 24px); }
    .dr-dlg--fenetre .dr-dlg__carte, .dr-dlg--large .dr-dlg__carte { padding: 0; }
    .dr-dlg__actions { flex-direction: column; }
    .dr-dlg__btn { min-height: 48px; width: 100%; }
    .dr-dlg__entete { padding: 16px; }
    .dr-dlg__defile { padding: 16px; }
    .dr-dlg__pied { flex-direction: column; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
}
@keyframes dr-dlg-feuille { from { transform: translateY(100%); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) { .dr-dlg[open], .dr-dlg[open]::backdrop { animation: none; } }
@media (forced-colors: active) {
    .dr-dlg__carte { border: 1px solid CanvasText; }
    .dr-dlg__btn--principal, .dr-dlg__btn--danger { border: 2px solid ButtonText; }
}

/* Notifications : même anatomie que dc-alerte (v9), en haut à droite sous l'en-tête. Conteneur en popover manuel :
   il passe dans la couche supérieure et reste visible au-dessus d'une fenêtre modale ouverte. */
.dr-toasts {
    position: fixed; inset: auto; top: 72px; right: 16px; left: auto; bottom: auto; margin: 0; padding: 0; border: 0; background: none; overflow: visible;
    width: min(400px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 8px; z-index: 1300; pointer-events: none;
}
.dr-toasts:not(:has(.dr-toast)) { display: none; }
.dr-toast {
    pointer-events: auto; display: flex; align-items: flex-start; gap: 12px; padding: 14px 12px 14px 16px;
    border: 1px solid var(--dlg-bordure); border-radius: var(--dlg-r-md); background: #fff; color: var(--dlg-texte);
    box-shadow: 0 8px 28px rgba(0, 30, 60, .12); animation: dr-dlg-entree .2s cubic-bezier(.22, .61, .36, 1);
}
.dr-toast__icone { flex: none; width: 20px; height: 20px; margin-top: 1px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.dr-toast__corps { flex: 1; min-width: 0; font-size: 14.5px; line-height: 1.45; white-space: pre-line; overflow-wrap: anywhere; }
.dr-toast__titre { display: block; font-weight: 700; }
.dr-toast__action { display: inline-block; margin-top: 6px; font-weight: 600; color: inherit; text-decoration: underline; text-underline-offset: 3px; }
.dr-toast__action:hover { color: inherit; text-decoration-thickness: 2px; }
.dr-toast__action:focus-visible, .dr-toast__x:focus-visible { outline: 2px solid var(--dlg-texte); outline-offset: 2px; border-radius: 6px; }
.dr-toast__x {
    flex: none; display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; margin: -8px 0; padding: 0;
    border: 0; border-radius: 8px; background: transparent; color: inherit; cursor: pointer; opacity: .75;
}
.dr-toast__x:hover { opacity: 1; background: rgba(0, 0, 0, .05); }
.dr-toast--succes { background: var(--dlg-succes-fond); border-color: var(--dlg-succes-bord); color: #0d3b1e; }
.dr-toast--succes .dr-toast__icone { color: var(--dlg-succes-texte); }
.dr-toast--info { background: var(--dlg-info-fond); border-color: var(--dlg-info-bord); color: #0b2a52; }
.dr-toast--info .dr-toast__icone { color: var(--dlg-info-texte); }
.dr-toast--attention { background: var(--dlg-attention-fond); border-color: var(--dlg-attention-bord); color: #4a2205; }
.dr-toast--attention .dr-toast__icone { color: var(--dlg-attention-texte); }
.dr-toast--erreur { background: var(--dlg-erreur-fond); border-color: var(--dlg-erreur-bord); color: #4c0a0a; }
.dr-toast--erreur .dr-toast__icone { color: var(--dlg-erreur-texte); }
@media (max-width: 640px) { .dr-toasts { left: 12px; right: 12px; width: auto; top: 64px; } }
@media (prefers-reduced-motion: reduce) { .dr-toast { animation: none; } }

/* Voile de chargement (remplace #spinner-overlay de l'ancien thème, sans style sur les pages redessinées).
   Il bloque les clics tout de suite (pas de double envoi) ; l'assombrissement et l'anneau n'apparaissent qu'après
   un court délai pour ne pas faire clignoter l'écran sur une réponse rapide. Message lu après 2 s. */
.dr-voile {
    position: fixed; inset: 0; width: auto; height: auto; max-width: none; max-height: none; margin: 0; padding: 16px; border: 0;
    display: flex; align-items: center; justify-content: center; z-index: 1400;
    background: transparent; cursor: progress; overflow: hidden;
}
.dr-voile[popover]:not(:popover-open) { display: none; }
.dr-voile__fond {
    position: absolute; inset: 0; background: rgba(28, 27, 31, .32);
    opacity: 0; animation: dr-voile-apparait .2s ease-out .35s forwards;
}
.dr-voile__boite {
    position: relative; display: flex; align-items: center; gap: 12px; padding: 14px 20px; min-height: 52px;
    background: #fff; border-radius: var(--dlg-r-md); box-shadow: 0 8px 28px rgba(0, 30, 60, .16);
    font-size: 14.5px; font-weight: 500; color: var(--dlg-texte);
    opacity: 0; animation: dr-voile-apparait .2s ease-out .35s forwards;
}
.dr-voile__anneau {
    flex: none; width: 22px; height: 22px; border-radius: 50%;
    border: 3px solid var(--dlg-bordure); border-top-color: var(--dlg-texte);
    animation: dr-voile-tourne .8s linear infinite;
}
.dr-voile__texte:empty { display: none; }
@keyframes dr-voile-apparait { to { opacity: 1; } }
@keyframes dr-voile-tourne { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
    .dr-voile__anneau { animation-duration: 2.4s; }
    .dr-voile__fond, .dr-voile__boite { animation-duration: 0s; }
}
@media (forced-colors: active) { .dr-voile__boite { border: 1px solid CanvasText; } }
