/**
 * Soterys Modal - composant réutilisable.
 * Utilisé par assets/js/modal.js (openPrompt / openConfirm / openAlert / openForm).
 */

.soterys-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: saturate(160%) blur(4px);
    -webkit-backdrop-filter: saturate(160%) blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.15s ease;
    padding: 1rem;
}
/* IMPORTANT : l'attribut HTML [hidden] doit forcer display:none.
   Sans ca, le display:flex ci-dessus override [hidden] -> la modal reste
   visible par-dessus toute la page et bloque tous les clicks (bug fatal). */
.soterys-modal-overlay[hidden] {
    display: none !important;
}
.soterys-modal-overlay.is-open { opacity: 1; }
.soterys-modal-overlay.is-closing { opacity: 0; }

/* Overlay « generation de document en cours » (pdf_download_controller) :
   affiche pendant la production du PDF, masque des reception du fichier. */
.pdf-gen {
    max-width: 340px;
    padding: 1.75rem 1.5rem;
    align-items: center;
    text-align: center;
    gap: 0;
}
.pdf-gen__spinner {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 3px solid #E2E8F0;
    border-top-color: #C8102E;
    animation: pdf-gen-spin 0.7s linear infinite;
    margin: 0 auto 0.9rem;
}
.pdf-gen__title { margin: 0; font-weight: 600; color: #1e293b; }
.pdf-gen__sub { margin: 0.3rem 0 0; min-height: 2.6em; font-size: 0.85rem; line-height: 1.3; color: #64748b; }
/* Messages d'attente qui defilent (pdf_download_controller) : fondu et leger glissement. */
.pdf-gen__sub.is-rotating { animation: pdf-gen-msg 3.6s ease-in-out both; }
@keyframes pdf-gen-msg {
    0% { opacity: 0; transform: translateY(6px); }
    12%, 86% { opacity: 1; transform: none; }
    100% { opacity: 0; transform: translateY(-6px); }
}
/* Proposition « Me prevenir » apres 30 s d'attente. */
.pdf-gen__later { margin-top: 1rem; padding-top: 0.9rem; border-top: 1px solid #e2e8f0; animation: pdf-gen-later .35s ease-out both; }
.pdf-gen__later-hint { margin: 0.45rem 0 0; font-size: 0.75rem; color: #94a3b8; }
@keyframes pdf-gen-later { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes pdf-gen-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
    .pdf-gen__spinner { animation-duration: 1.6s; }
    .pdf-gen__sub.is-rotating { animation: none; }
    .pdf-gen__later { animation: none; }
}

.soterys-modal {
    background: white;
    border-radius: 1rem;
    box-shadow: 0 20px 60px -10px rgba(0, 0, 0, 0.25), 0 8px 20px -5px rgba(0, 0, 0, 0.15);
    width: 100%;
    max-width: 480px;
    overflow: hidden;
    transform: translateY(10px) scale(0.98);
    transition: transform 0.18s cubic-bezier(0.16, 1, 0.3, 1);
    max-height: calc(100vh - 2rem);
    display: flex;
    flex-direction: column;
}
/* Popups de LECTURE (journal des versions, sommaire d'un ticket) : elles
   portent des paragraphes entiers, pas une question fermee. Les dialogues de
   confirmation gardent la largeur par defaut, plus adaptee a une phrase. */
.soterys-modal--wide { max-width: 660px; }

.soterys-modal-overlay.is-open .soterys-modal {
    transform: translateY(0) scale(1);
}

/* Variante danger - header rouge pour actions destructives */
.soterys-modal-overlay--danger .soterys-modal__header {
    background: linear-gradient(to bottom, #FEF2F2 0%, #FFFFFF 100%);
}
.soterys-modal-overlay--danger .soterys-modal__header h3 {
    color: #C8102E;
}

.soterys-modal__header {
    padding: 1.25rem 1.5rem 0.75rem;
    border-bottom: 1px solid #E2E8F0;
    flex-shrink: 0;
}
.soterys-modal__header h3 {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 700;
    color: #0F172A;
    letter-spacing: -0.01em;
}
.soterys-modal__subtitle {
    margin: 0.375rem 0 0;
    font-size: 0.85rem;
    color: #64748B;
    font-weight: 500;
}

.soterys-modal__body {
    padding: 1.25rem 1.5rem;
    overflow-y: auto;
    flex: 1 1 auto;
}

.soterys-modal__message {
    margin: 0 0 0.75rem;
    font-size: 0.95rem;
    color: #334155;
    line-height: 1.5;
}
.soterys-modal__message:last-child { margin-bottom: 0; }

/* Champs du formulaire */
.soterys-modal__field {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    margin-bottom: 0.875rem;
}
.soterys-modal__field:last-child { margin-bottom: 0; }
.soterys-modal__label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #334155;
    letter-spacing: 0.01em;
}

.soterys-modal__input {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 1rem;
    font-family: inherit;
    border: 1.5px solid #CBD5E1;
    border-radius: 0.5rem;
    background: white;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    color: #0F172A;
    box-sizing: border-box;
}
.soterys-modal__input:focus {
    outline: none;
    border-color: #C8102E;
    box-shadow: 0 0 0 3px rgba(200, 16, 46, 0.15);
}
.soterys-modal__input::placeholder { color: #94A3B8; }

.soterys-modal__textarea {
    resize: vertical;
    min-height: 5rem;
    font-family: inherit;
}

.soterys-modal__hint {
    margin: 0.625rem 0 0;
    font-size: 0.75rem;
    color: #94A3B8;
    font-style: italic;
}

.soterys-modal__footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.875rem 1.5rem;
    background: #F8FAFC;
    border-top: 1px solid #E2E8F0;
    flex-shrink: 0;
}

@media (max-width: 540px) {
    .soterys-modal {
        max-width: 100%;
        border-radius: 0.75rem;
    }
    .soterys-modal__header { padding: 1rem 1.125rem 0.625rem; }
    .soterys-modal__body { padding: 1rem 1.125rem; }
    .soterys-modal__footer { padding: 0.75rem 1.125rem; flex-direction: column-reverse; }
    .soterys-modal__footer .btn { width: 100%; justify-content: center; }
}

/* Bouton de telechargement d'un document en preparation (« Me prevenir ») :
   cercle qui tourne, inactif, puis bref halo quand il redevient cliquable. */
.btn.is-preparing { display: inline-flex; align-items: center; gap: .45rem; pointer-events: none; cursor: progress; opacity: .9; }
.btn-prep__spinner { width: .85em; height: .85em; flex: none; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: pdf-gen-spin .8s linear infinite; }
.btn.is-ready { animation: btn-ready 2.4s ease-out; }
@keyframes btn-ready { 0% { box-shadow: 0 0 0 0 rgba(5, 150, 105, .55); } 60% { box-shadow: 0 0 0 8px rgba(5, 150, 105, 0); } 100% { box-shadow: none; } }
@media (prefers-reduced-motion: reduce) {
    .btn-prep__spinner { animation-duration: 2s; }
    .btn.is-ready { animation: none; }
}
