/* ============================================================
   Modale de paiement avant Stripe — MRAUK-U
   Pilote UX : confirmation avant ouverture de Stripe dans un
   nouvel onglet. Préfixe : pm- (payment modal)
   ============================================================ */

/* --- Overlay (voile léger + léger flou) --- */
.pm-overlay {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    background-color: rgba(10, 12, 20, 0.5);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}

.pm-overlay.is-open {
    display: flex;
}

/* --- Modale --- */
.pm-modal {
    position: relative;
    width: min(520px, 94vw);
    max-height: 92vh;
    max-height: 92dvh;
    overflow-y: auto;
    background-color: var(--surface-container-lowest, #ffffff);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-ambient);
    padding: 2rem;
}

.pm-modal:focus {
    outline: none;
}

/* --- Bouton fermer (×) --- */
.pm-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 5;
    width: 2.5rem;
    height: 2.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background-color: var(--surface-container-high, #f1f1f4);
    color: var(--on-surface);
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
}

.pm-close:hover {
    background-color: var(--outline-variant);
    transform: rotate(90deg);
}

.pm-close:focus-visible,
.pm-modal a:focus-visible,
.pm-modal button:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* --- En-tête --- */
.pm-head {
    text-align: center;
    margin-bottom: 1.25rem;
}

.pm-head .pm-icon {
    width: 3.25rem;
    height: 3.25rem;
    margin: 0 auto 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background-color: var(--primary-soft, rgba(176, 141, 87, 0.14));
    color: var(--primary);
}

.pm-head h3 {
    font-family: var(--font-display);
    font-size: 1.5rem;
    margin: 0 0 0.4rem;
    color: var(--secondary);
}

.pm-head p {
    font-size: 0.95rem;
    color: var(--on-surface-variant);
    margin: 0;
    line-height: 1.5;
}

/* --- Récapitulatif --- */
.pm-recap {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-bottom: 1.25rem;
    padding: 1rem 1.1rem;
    border: 1px solid var(--outline-variant);
    border-radius: var(--radius-md);
    background-color: var(--surface-container-low, #fafafa);
}

.pm-recap-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    font-size: 0.92rem;
}

.pm-recap-row__label {
    color: var(--on-surface-variant);
}

.pm-recap-row__value {
    font-weight: 600;
    color: var(--secondary);
    text-align: right;
}

.pm-recap-row--accent .pm-recap-row__value {
    color: var(--primary);
}

/* --- Sécurité Stripe --- */
.pm-secure {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1.25rem;
    padding: 0.75rem 0.9rem;
    border-radius: var(--radius-sm);
    background-color: var(--primary-soft, rgba(176, 141, 87, 0.12));
    color: var(--secondary);
    font-size: 0.9rem;
    font-weight: 600;
}

.pm-secure svg {
    flex-shrink: 0;
    color: #10B981;
}

/* --- Texte d'explication --- */
.pm-note {
    font-size: 0.9rem;
    color: var(--on-surface-variant);
    line-height: 1.55;
    margin-bottom: 1.5rem;
}

/* --- Actions --- */
.pm-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.pm-actions .btn {
    width: 100%;
    text-align: center;
    justify-content: center;
    padding: 0.85rem 1rem;
}

/* ============================================================
   PILOTE STRIPE CHECKOUT EMBEDDED — assis_fusion (TEST)
   Styles des conteneurs de paiement intégré (#pm-embedded-*)
   ============================================================ */

/* --- Zone de paiement intégré --- */
.pm-embedded-zone {
    position: relative;
    min-height: 320px;
    margin-bottom: 1.25rem;
}

/* --- État "chargement" : overlay premium discret (zone paiement uniquement) --- */
#pm-embedded-loading {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.9rem;
    padding: 1.5rem;
    text-align: center;
    border-radius: var(--radius-md);
    background-color: rgba(252, 251, 247, 0.94);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    color: var(--on-surface-variant);
    transition: opacity 0.2s ease;
}

#pm-embedded-loading.is-hidden {
    opacity: 0;
    pointer-events: none;
}

#pm-embedded-loading .pm-spinner {
    width: 2rem;
    height: 2rem;
    border: 2px solid rgba(10, 25, 47, 0.12);
    border-top-color: var(--primary, #b08d57);
    border-right-color: rgba(10, 25, 47, 0.28);
    border-radius: 50%;
    animation: pm-spin 0.8s linear infinite;
}

#pm-embedded-loading p {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--secondary, #0a192f);
    letter-spacing: 0.01em;
}

@media (prefers-reduced-motion: reduce) {

    #pm-embedded-loading .pm-spinner,
    .pm-spinner {
        animation: none;
        border-top-color: var(--primary, #b08d57);
        border-right-color: rgba(10, 25, 47, 0.12);
    }

    #pm-embedded-loading {
        transition: none;
    }
}

.pm-spinner {
    width: 2.75rem;
    height: 2.75rem;
    border: 3px solid var(--outline-variant, #e2e2e6);
    border-top-color: var(--primary, #b08d57);
    border-radius: 50%;
    animation: pm-spin 0.9s linear infinite;
}

@keyframes pm-spin {
    to {
        transform: rotate(360deg);
    }
}

/* --- Conteneur du Checkout Embedded Stripe --- */
#pm-embedded-container {
    min-height: 280px;
}

/* --- État "erreur / fallback TEST" --- */
#pm-embedded-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    min-height: 240px;
    padding: 1.5rem;
    text-align: center;
    color: var(--on-surface-variant);
    font-size: 0.95rem;
    line-height: 1.55;
}

#pm-embedded-error .btn {
    width: auto;
    min-width: 220px;
}

/* --- État "paiement en cours de confirmation" (moyen asynchrone) --- */
#pm-embedded-processing {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.9rem;
    min-height: 280px;
    padding: 1.5rem;
    text-align: center;
    color: var(--on-surface-variant);
    font-size: 0.95rem;
    line-height: 1.55;
}

/* --- Écran intermédiaire de finalisation post-paiement ---
   Affiché dès le signal réel Stripe (Checkout terminé), pendant la
   vérification serveur / le polling. L'écran final "Paiement enregistré"
   ne remplace cet écran qu'après validation serveur. Reprend les
   couleurs, la typographie et les dimensions de la modale existante. --- */
#pm-embedded-finalizing {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.9rem;
    min-height: 280px;
    padding: 1.5rem;
    text-align: center;
    color: var(--on-surface-variant);
    font-size: 0.95rem;
    line-height: 1.55;
}

#pm-embedded-finalizing .pm-finalizing-icon {
    width: 3.5rem;
    height: 3.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background-color: rgba(16, 185, 129, 0.14);
    color: #10B981;
}

#pm-embedded-finalizing h4 {
    font-family: var(--font-display);
    font-size: 1.35rem;
    margin: 0;
    color: var(--secondary);
}

#pm-embedded-finalizing .pm-finalizing-subtitle {
    margin: 0;
    font-size: 1rem;
    color: var(--on-surface-variant);
    line-height: 1.5;
}

#pm-embedded-finalizing .pm-spinner {
    width: 3rem;
    height: 3rem;
    border-width: 3px;
}

#pm-embedded-finalizing .pm-finalizing-note {
    margin: 0;
    font-size: 0.9rem;
    color: var(--on-surface-variant);
    line-height: 1.55;
    max-width: 400px;
}

/* --- Confirmation de paiement DANS la modale (aucune navigation) --- */
#pm-embedded-success {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.8rem;
    min-height: 280px;
    justify-content: center;
    padding: 1.5rem;
    text-align: center;
}

#pm-embedded-success h4 {
    font-family: var(--font-display);
    font-size: 1.35rem;
    margin: 0;
    color: var(--secondary);
}

#pm-embedded-success>p {
    margin: 0;
    font-size: 1rem;
    color: var(--on-surface-variant);
    line-height: 1.5;
}

.pm-success-icon {
    width: 4rem;
    height: 4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background-color: rgba(16, 185, 129, 0.14);
    color: #10B981;
}

.pm-success-recap {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    width: 100%;
    max-width: 420px;
    margin: 0.4rem 0;
    padding: 1rem 1.1rem;
    border: 1px solid var(--outline-variant);
    border-radius: var(--radius-md);
    background-color: var(--surface-container-low, #fafafa);
    text-align: left;
}

.pm-success-note {
    max-width: 460px;
}

#pm-embedded-success .btn {
    margin-top: 0.4rem;
    min-width: 220px;
    justify-content: center;
}

/* --- Mode Embedded : on masque récap, actions, notes et sécurité
   pour ne laisser place qu'au Checkout Embedded Stripe --- */
.pm-overlay.is-embedded .pm-recap,
.pm-overlay.is-embedded .pm-actions,
.pm-overlay.is-embedded .pm-note,
.pm-overlay.is-embedded .pm-secure {
    display: none;
}

/* --- Modale Embedded : un peu plus large pour le checkout --- */
.pm-overlay.is-embedded .pm-modal {
    width: min(620px, 94vw);
}

/* --- Responsive (mobile) --- */
@media (max-width: 480px) {

    /* Overlay : padding réduit pour laisser la modale occuper un maximum
       de la hauteur visible utile du téléphone. */
    .pm-overlay {
        padding: 0.5rem;
    }

    /* Modale : hauteur plafonnée à la zone visible du téléphone.
       Fallback vh (navigateurs anciens) puis dvh (iOS 16.4+) pour ne
       jamais dépasser sous la barre Safari / le home indicator.
       Marge de sécurité de 24 px en haut et en bas.
       overflow-x: hidden → aucun scroll horizontal possible. */
    .pm-modal {
        max-height: calc(100vh - 24px);
        max-height: calc(100dvh - 24px);
        padding: 1.5rem;
        padding-top: calc(1.5rem + env(safe-area-inset-top));
        padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
        overflow-x: hidden;
    }

    /* --- Mode Embedded : architecture "conteneur + zone scrollable" ---
       La modale devient une colonne flex :
         - l'en-tête (.pm-head) et la croix (.pm-close) restent fixes
           et toujours accessibles ;
         - la zone paiement (.pm-embedded-zone) gère le scroll vertical.
       L'iframe Stripe conserve sa hauteur naturelle : c'est le conteneur
       qui défile, jamais l'iframe elle-même ni la modale entière. */
    .pm-overlay.is-embedded .pm-modal {
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .pm-overlay.is-embedded .pm-head {
        flex-shrink: 0;
        margin-bottom: 0.85rem;
    }

    .pm-overlay.is-embedded .pm-embedded-zone {
        flex: 1 1 auto;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        margin-bottom: 0;
    }

    .pm-head h3 {
        font-size: 1.3rem;
    }
}