Outiref

Code source de l'URL : http://aptevia.fr

<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta name="robots" content="index,follow,max-image-preview:large,max-snippet:-1,max-video-preview:-1">

    <title>Cabinet APTEVIA – Tests psychotechniques agréés permis de conduire</title>

    <meta name="description" content="Cabinet agréé APTEVIA : tests psychotechniques obligatoires après suspension, annulation ou invalidation du permis. Interventions à Étampes, Angerville, Intréville et Pithiviers.">

    <link rel="canonical" href="https://aptevia.fr/">

    <script>
      window.BASE_URL = "https://aptevia.fr/";
      window.RDV_ONLINE_ENABLED = false;
    </script>

    <script type="application/ld+json">{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://aptevia.fr/#organization","name":"APTEVIA","url":"https://aptevia.fr","logo":"https://aptevia.fr/assets/img/logo.png","email":"contact@aptevia.fr","address":{"@type":"PostalAddress","streetAddress":"2 rue de Mérouville","postalCode":"28310","addressLocality":"Intréville","addressCountry":"FR"},"sameAs":[],"contactPoint":[{"@type":"ContactPoint","contactType":"customer support","email":"contact@aptevia.fr","availableLanguage":["fr-FR"]}]},{"@type":"LocalBusiness","@id":"https://aptevia.fr/#localbusiness","name":"APTEVIA","url":"https://aptevia.fr","image":"https://aptevia.fr/assets/img/logo.png","logo":"https://aptevia.fr/assets/img/logo.png","email":"contact@aptevia.fr","address":{"@type":"PostalAddress","streetAddress":"2 rue de Mérouville","postalCode":"28310","addressLocality":"Intréville","addressCountry":"FR"},"parentOrganization":{"@id":"https://aptevia.fr/#organization"},"areaServed":["Essonne (91)","Eure-et-Loir (28)","Loiret (45)","Étampes","Pithiviers","Angerville"],"availableLanguage":["fr-FR"],"knowsAbout":["Tests psychotechniques permis de conduire","Évaluation psychotechnique","Aptitude à la conduite","Suspension du permis","Annulation du permis","Invalidation du permis","Lettre 3F","Lettre 44","Lettre 48SI"]},{"@type":"WebSite","@id":"https://aptevia.fr/#website","url":"https://aptevia.fr","name":"APTEVIA","publisher":{"@id":"https://aptevia.fr/#organization"}},{"@type":"WebPage","@id":"https://aptevia.fr/#webpage","url":"https://aptevia.fr/","name":"Cabinet APTEVIA – Tests psychotechniques agréés permis de conduire","description":"Cabinet agréé APTEVIA : tests psychotechniques obligatoires après suspension, annulation ou invalidation du permis. Interventions à Étampes, Angerville, Intréville et Pithiviers.","inLanguage":"fr-FR","isPartOf":{"@id":"https://aptevia.fr/#website"},"publisher":{"@id":"https://aptevia.fr/#organization"}}]}</script>

    <!-- Favicons -->
    <link rel="icon" href="/favicon.ico" sizes="any">
    <link rel="icon" type="image/svg+xml" href="/favicon.svg">
    <link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96">
    <link rel="apple-touch-icon" href="/apple-touch-icon.png">
    <link rel="manifest" href="/site.webmanifest">
    <meta name="theme-color" content="#002F3F">

    <!-- CSS -->
    <link rel="stylesheet" href="/assets/css/theme_aptevia.css?v=1.6">
    <link rel="stylesheet" href="/assets/css/style.css?v=1.6">
    <link rel="stylesheet" href="/assets/css/aptevia.css?v=1.6">
    <link rel="stylesheet" href="/assets/css/ia.css?v=1.6">
    <link rel="stylesheet" href="/assets/css/ia_aptevia.css?v=1.6">
    <link rel="stylesheet" href="/assets/css/rdv_disabled.css?v=1.0">

    <!-- JS -->
    <script src="/assets/js/main.js?v=1.6" defer></script>
    <script src="/admin/assets/js/popup_login.js?v=1.1" defer></script>

    <script src="/assets/js/rdv_disabled.js?v=1.0" defer></script>



</head>

<body>
<header>
    <div class="header-container">

        <div class="logo">
            <a href="https://aptevia.fr/index_site.php">
                <img src="/assets/img/logo.png" alt="Cabinet APTEVIA">
            </a>
        </div>

        <nav class="main-nav">
            <ul>
                <li><a href="https://aptevia.fr/index_site.php">Accueil</a></li>
                <li><a href="https://aptevia.fr/pages/a-propos.php">À propos</a></li>
                <li><a href="https://aptevia.fr/pages/devis_pro.php">Offre Entreprises</a></li>
                <li><a href="https://aptevia.fr/pages/methode_evaluation.php">Méthode d'évaluation</a></li>
                <li><a href="https://aptevia.fr/pages/rendezvous/prendre_rdv.php">Prendre rendez-vous</a></li>
                <li><a href="https://aptevia.fr/pages/contact.php">Contact</a></li>
            </ul>
        </nav>

        <div class="header-right">
            <a href="https://aptevia.fr/pages/rendezvous/prendre_rdv.php" class="btn-header rdv">
                Prendre rendez-vous
            </a>

            
            <a href="https://aptevia.fr/admin/login.php"
               class="btn-header pro"
               id="btnEspacePro">
                Espace Pro
            </a>
        </div>

    </div>
</header>

<!-- Styles spécifiques à la popup (OK en page) -->
<style>
    /* Pour être sûr que la popup reste parfaite */
    #pro-login-overlay {
        display:none;
        position:fixed;
        inset:0;
        background:rgba(0,0,0,0.45);
        z-index:9999;
        align-items:center;
        justify-content:center;
    }
    .pro-popup {
        background:#f7f4ef;
        border-radius:10px;
        max-width:480px;
        width:90%;
        padding:25px;
        position:relative;
        box-shadow:0 10px 30px rgba(0,0,0,0.25);
    }
    .pro-login-title {
        color:#002f3f;
        text-align:center;
        margin-bottom:15px;
    }
    .pro-form-group {
        margin-bottom:15px;
    }
    .pro-input {
        width:100%;
        padding:12px;
        border-radius:8px;
        border:1px solid #ccc;
        background:#fff;
    }
    .btn-container {
        display:flex;
        gap:15px;
        justify-content:center;
        margin-top:15px;
    }
    .btn-pro-main {
        flex:1;
        background:#002f3f;
        color:white;
        padding:12px;
        border:none;
        border-radius:999px;
        cursor:pointer;
    }
    .btn-pro-secondary {
        flex:1;
        background:#c0b8ae;
        color:#002f3f;
        padding:12px;
        border:none;
        border-radius:999px;
        cursor:pointer;
    }
    #pro-login-close {
        position:absolute;
        top:8px;
        right:12px;
        border:none;
        background:transparent;
        font-size:26px;
        cursor:pointer;
    }
</style>

<main class="page">

<!-- =========================================================
     HERO
============================================================= -->
<section style="text-align:center; padding:80px 20px; background:#f7f4ef;">
    <h1 style="color:#002f3f; font-size:2.2rem;">
        Retrouvez votre capacité à conduire avec
        <span style="color:#A89E8F;">APTEVIA</span>
    </h1>

    <p style="max-width:800px; margin:20px auto; font-size:1.1rem; color:#333;">
        Cabinet agréé pour les <strong>tests psychotechniques</strong> obligatoires
        après suspension, annulation ou invalidation du permis de conduire.
    </p>

    <a href="https://aptevia.fr/pages/rendezvous/prendre_rdv.php" class="btn-header rdv">
        Prendre rendez-vous
    </a>
</section>

<!-- =========================================================
     SITUATIONS – ENVELOPPES
============================================================= -->
<section class="ap-enveloppes-section">

    <h2 class="ap-enveloppes-title">Quelle est votre situation&nbsp;?</h2>

    <p class="ap-enveloppes-intro">
        Vous avez normalement reçu un courrier des autorités indiquant une référence.
        Choisissez simplement celle qui apparaît sur votre document.
    </p>

    <div class="ap-enveloppes-row">

        <div class="ap-envelope" data-target="https://aptevia.fr/pages/lettres/lettre.php?code=3F">
            <div class="ap-env-wrap">
                <div class="env-flap-dark"></div>
                <div class="env-flap-light"></div>
                <div class="env-base"></div>
                <div class="ap-letter">Lettre 3F</div>
            </div>
        </div>

        <div class="ap-envelope" data-target="https://aptevia.fr/pages/lettres/lettre.php?code=7">
            <div class="ap-env-wrap">
                <div class="env-flap-dark"></div>
                <div class="env-flap-light"></div>
                <div class="env-base"></div>
                <div class="ap-letter">Lettre 7</div>
            </div>
        </div>

        <div class="ap-envelope" data-target="https://aptevia.fr/pages/lettres/lettre.php?code=44">
            <div class="ap-env-wrap">
                <div class="env-flap-dark"></div>
                <div class="env-flap-light"></div>
                <div class="env-base"></div>
                <div class="ap-letter">Lettre 44</div>
            </div>
        </div>

        <div class="ap-envelope" data-target="https://aptevia.fr/pages/lettres/lettre.php?code=48SI">
            <div class="ap-env-wrap">
                <div class="env-flap-dark"></div>
                <div class="env-flap-light"></div>
                <div class="env-base"></div>
                <div class="ap-letter">Lettre 48SI</div>
            </div>
        </div>
    </div>

    <div class="ap-no-mail">
        <a href="https://aptevia.fr/pages/lettres/lettre.php?code=NOCOURRIER" class="ap-no-mail-btn">
            Je n’ai pas reçu de courrier
        </a>
    </div>

</section>

<!-- =========================================================
     PROCESSUS
============================================================= -->
<section style="padding:60px 20px; background:#f7f4ef;">
    <div style="max-width:1100px; margin:0 auto; text-align:center;">
        <h2 style="color:#002f3f;">Comment se déroule votre démarche ?</h2>

        <div class="processus-row">

            <div class="consultant-card">
                <h3>1. Prise de rendez-vous</h3>
                <p>Choisissez la ville, la date et l’heure selon les créneaux disponibles.</p>
            </div>

            <div class="consultant-card">
                <h3>2. Tests psychotechniques</h3>
                <p>Effectués dans un centre agréé, par un psychologue habilité.</p>
            </div>

            <div class="consultant-card">
                <h3>3. Attestation immédiate</h3>
                <p>Remise de l’attestation pour votre visite médicale en préfecture.</p>
            </div>

        </div>
    </div>
</section>

<!-- =========================================================
     FAQ IA
============================================================= -->
<section class="faq-section">
    <div class="faq-container">
        <h2>FAQ - Vos questions fréquentes</h2>
        <p class="faq-subtitle">
            Posez une question sur votre situation
            (ex : « J’ai reçu une lettre 3F, que faire ? »)
        </p>

        <div id="faq-box">
            <input type="text" id="faq-input" placeholder="Saisissez votre question...">
            <button id="faq-send">Envoyer</button>

            <div id="faq-status"></div>

            <div id="psy-loader">
                <div class="psy-circle"><span>PSY</span></div>
            </div>

            <div id="faq-response"></div>

            <div id="faq-progress">
                <div id="faq-progress-bar"></div>
            </div>

            <div id="faq-share">
                <button data-type="copy">📋 Copier</button>
                <button data-type="email">📧 Email</button>
                <button data-type="facebook">📘 Facebook</button>
                <button data-type="whatsapp">💬 WhatsApp</button>
            </div>
        </div>
    </div>
</section>

</main>

<!-- Script IA APTEVIA (spécifique accueil) -->
<script defer src="https://aptevia.fr/assets/js/ia_aptevia_v23.js"></script>

<!-- #########################################################
     POPUP CONNEXION ESPACE PRO
########################################################## -->

<div id="pro-login-overlay">

    <div class="pro-popup">

        <button type="button" id="pro-login-close">&times;</button>

        <div class="pro-login-box">

            <h2 class="pro-login-title">Connexion espace pro</h2>
            <div class="pro-login-sub">Accès réservé aux centres agréés et administrateurs APTEVIA.</div>

            <!-- =======================
                 ÉTAPE 1 : LOGIN
            ======================== -->
            <div id="login-step">

                <form id="pro-login-form" method="POST">
                    <input type="hidden" name="from_popup" value="1">

                    <div class="pro-form-group">
                        <label for="pro-login-email">Adresse e-mail</label>
                        <input type="email" id="pro-login-email" name="email" class="pro-input" required>
                    </div>

                    <div class="pro-form-group">
                        <label for="pro-login-password">Mot de passe</label>
                        <input type="password" id="pro-login-password" name="password" class="pro-input" required>
                    </div>

                    <p class="otp-info">
                        Après validation, un code à usage unique (OTP) vous sera envoyé par e-mail.
                    </p>

                    <div class="btn-container">
                        <button type="submit" class="btn-pro-main">Continuer</button>
                        <button type="button" class="btn-pro-secondary" id="pro-login-cancel">Annuler</button>
                    </div>

                    <div style="text-align:center; margin-top:12px;">
                        <a href="#" id="pro-forgot-open" style="color:#002f3f; text-decoration:none;">Mot de passe oublié ?</a>
                    </div>

                </form>
            </div>

            <!-- =======================
                 ÉTAPE 2 : OTP
            ======================== -->
            <div id="otp-step" style="display:none;">

                <h3 class="pro-login-title">Vérification du code</h3>

                <p id="otp-info-message">Un code à 6 chiffres vous a été envoyé.</p>

                <input type="text" id="otp-code" maxlength="6" class="pro-input"
                       style="font-size:28px; text-align:center; letter-spacing:8px;">

                <div class="btn-container">
                    <button class="btn-pro-main" type="button" id="btnValidateOTP">Valider le code</button>
                    <button class="btn-pro-secondary" type="button" id="cancel-otp">Annuler</button>
                </div>

            </div>

            <!-- =======================
                 ÉTAPE 3 : MOT DE PASSE OUBLIÉ
            ======================== -->
            <div id="forgot-step" style="display:none;">

                <h3 class="pro-login-title">Réinitialisation du mot de passe</h3>

                <p id="forgot-info-message">
                    Saisissez votre adresse email.<br>
                    Vous recevrez un lien de réinitialisation.
                </p>

                <input type="email" id="forgot-email" class="pro-input" placeholder="Votre adresse e-mail">

                <div class="btn-container">
                    <button class="btn-pro-main" type="button" id="btnSendForgot">Envoyer</button>
                    <button class="btn-pro-secondary" type="button" id="cancel-forgot">Annuler</button>
                </div>

            </div>

        </div>
    </div>
</div>

<!-- =========================================================
     JS POPUP
============================================================= -->
<script>
document.addEventListener("DOMContentLoaded", function () {

    const overlay      = document.getElementById('pro-login-overlay');
    const btnOpen      = document.getElementById('btnEspacePro');
    const btnClose     = document.getElementById('pro-login-close');
    const btnCancel    = document.getElementById('pro-login-cancel');
    const loginForm    = document.getElementById('pro-login-form');

    const loginStep    = document.getElementById('login-step');
    const otpStep      = document.getElementById('otp-step');
    const forgotStep   = document.getElementById('forgot-step');

    const otpInput     = document.getElementById('otp-code');
    const otpBtn       = document.getElementById('btnValidateOTP');
    const otpCancelBtn = document.getElementById('cancel-otp');

    const forgotOpen   = document.getElementById('pro-forgot-open');
    const forgotInput  = document.getElementById('forgot-email');
    const forgotSend   = document.getElementById('btnSendForgot');
    const forgotCancel = document.getElementById('cancel-forgot');

    function openPopup() {
        overlay.style.display = "flex";
    }
    function closePopup() {
        overlay.style.display = "none";
        loginStep.style.display  = "block";
        otpStep.style.display    = "none";
        forgotStep.style.display = "none";
    }

    if (btnOpen) {
        btnOpen.addEventListener("click", (e) => {
            if (overlay) {
                e.preventDefault();
                openPopup();
            }
        });
    }

    if (btnClose)  btnClose.addEventListener("click", closePopup);
    if (btnCancel) btnCancel.addEventListener("click", closePopup);

    overlay.addEventListener("click", (e) => {
        if (e.target === overlay) closePopup();
    });

    // LOGIN → OTP
    loginForm.addEventListener("submit", (e) => {
        e.preventDefault();

        const fd = new FormData(loginForm);
        fd.set("from_popup", "1");

        fetch("https://aptevia.fr/admin/auth/login_process.php", {
            method: "POST",
            body: fd
        })
        .then(r => r.json())
        .then(data => {
            if (!data.ok) {
                alert(data.message || "Identifiants incorrects.");
                return;
            }
            loginStep.style.display  = "none";
            otpStep.style.display    = "block";
            otpInput.value = "";
            otpInput.focus();
        })
        .catch(err => alert("Erreur : " + err));
    });

    // MOT DE PASSE OUBLIÉ
    if (forgotOpen) {
        forgotOpen.addEventListener("click", (e) => {
            e.preventDefault();
            loginStep.style.display  = "none";
            otpStep.style.display    = "none";
            forgotStep.style.display = "block";
            forgotInput.focus();
        });
    }

    forgotCancel.addEventListener("click", () => {
        forgotStep.style.display = "none";
        loginStep.style.display  = "block";
    });

    forgotSend.addEventListener("click", () => {

        const email = forgotInput.value.trim();
        if (!email) {
            alert("Veuillez indiquer votre email.");
            return;
        }

        const fd = new FormData();
        fd.append("email", email);
        fd.append("from_popup", "1");

        fetch("https://aptevia.fr/admin/auth/forgot_process.php", {
            method: "POST",
            body: fd
        })
        .then(r => r.text())
        .then(txt => {
            let data;
            try { data = JSON.parse(txt); }
            catch (e) {
                alert("Réponse inattendue du serveur :\n\n" + txt);
                return;
            }

            if (!data.ok) {
                alert(data.message || "Erreur lors de la demande.");
                return;
            }

            alert(data.message || "Un e-mail de réinitialisation vient d'être envoyé.\nVérifiez votre boîte de réception.");
            forgotStep.style.display = "none";
            loginStep.style.display  = "block";
        })
        .catch(err => alert("Erreur : " + err));
    });

    // VALIDATION OTP
    otpBtn.addEventListener("click", () => {
        const code = otpInput.value.trim();

        if (code.length !== 6) {
            alert("Veuillez saisir un code à 6 chiffres.");
            return;
        }

        const fd = new FormData();
        fd.append("otp", code);
        fd.append("from_popup", "1");

        fetch("https://aptevia.fr/admin/auth/otp_process.php", {
            method: "POST",
            body: fd
        })
        .then(r => r.json())
        .then(data => {
            if (!data.ok) {
                alert(data.message || "Code incorrect.");
                return;
            }

            if (data.redirect_url) window.location.href = data.redirect_url;
            else window.location.href = "https://aptevia.fr/admin/index.php";
        })
        .catch(err => alert("Erreur serveur : " + err));
    });

    otpCancelBtn.addEventListener("click", () => {
        otpStep.style.display   = "none";
        loginStep.style.display = "block";
    });

});
</script>

<script>
document.addEventListener("DOMContentLoaded", function() {
    const url = new URL(window.location.href);

    if (url.searchParams.get("reset_ok") === "1") {
        const overlay = document.getElementById("pro-login-overlay");
        if (overlay) overlay.style.display = "flex";

        const login = document.getElementById("login-step");
        const otp   = document.getElementById("otp-step");
        const forgot= document.getElementById("forgot-step");

        if (login)  login.style.display  = "block";
        if (otp)    otp.style.display    = "none";
        if (forgot) forgot.style.display = "none";

        setTimeout(() => {
            alert("Votre mot de passe a été réinitialisé avec succès.\nVous pouvez maintenant vous connecter.");
        }, 300);
    }
});
</script>


<footer>
    <div class="footer-container">
        <p>&copy; 2026 APTEVIA — Tests psychotechniques agréés.</p>

        <ul class="footer-links">
            <li><a href="https://aptevia.fr/pages/mentions-legales.php">Mentions légales</a></li>
            <li><a href="https://aptevia.fr/pages/politique-confidentialite.php">Confidentialité</a></li>
            <li><a href="https://aptevia.fr/pages/cgv.php">CGV</a></li>
            <li><a href="https://aptevia.fr/pages/cgu.php">CGU</a></li>
            <li><a href="https://aptevia.fr/pages/contact.php">Contact</a></li>
        </ul>
    </div>
</footer>

<!-- ============================================================
     SCRIPTS JAVASCRIPT (communs)
============================================================ -->
<script src="/assets/js/faq_ai.js?v=1.6" defer></script>


<!-- #########################################################
     POPUP CONNEXION ESPACE PRO (injectée globalement)
########################################################## -->
<div id="pro-login-overlay" aria-hidden="true">
  <div class="pro-popup" role="dialog" aria-modal="true" aria-labelledby="pro-login-title">

    <button type="button" id="pro-login-close" aria-label="Fermer">&times;</button>

    <div class="pro-login-box">
      <h2 class="pro-login-title" id="pro-login-title">Connexion espace pro</h2>
      <div class="pro-login-sub">Accès réservé aux centres agréés et administrateurs APTEVIA.</div>

      <!-- =======================
           ÉTAPE 1 : LOGIN
      ======================== -->
      <div id="login-step">
        <form id="pro-login-form" method="POST" autocomplete="on">
          <input type="hidden" name="from_popup" value="1">

          <div class="pro-form-group">
            <label for="pro-login-email">Adresse e-mail</label>
            <input type="email" id="pro-login-email" name="email" class="pro-input" required autocomplete="username">
          </div>

          <div class="pro-form-group">
            <label for="pro-login-password">Mot de passe</label>
            <input type="password" id="pro-login-password" name="password" class="pro-input" required autocomplete="current-password">
          </div>

          <p class="otp-info">
            Après validation, un code à usage unique (OTP) vous sera envoyé par e-mail.
          </p>

          <div class="btn-container">
            <button type="submit" class="btn-pro-main">Continuer</button>
            <button type="button" class="btn-pro-secondary" id="pro-login-cancel">Annuler</button>
          </div>

          <div style="text-align:center; margin-top:12px;">
            <a href="#" id="pro-forgot-open" style="color:#002f3f; text-decoration:none;">Mot de passe oublié ?</a>
          </div>
        </form>
      </div>

      <!-- =======================
           ÉTAPE 2 : OTP
      ======================== -->
      <div id="otp-step" style="display:none;">
        <h3 class="pro-login-title">Vérification du code</h3>
        <p id="otp-info-message">Un code à 6 chiffres vous a été envoyé.</p>

        <input type="text" id="otp-code" maxlength="6" inputmode="numeric"
               class="pro-input" style="font-size:28px; text-align:center; letter-spacing:8px;">

        <div class="btn-container">
          <button class="btn-pro-main" type="button" id="btnValidateOTP">Valider le code</button>
          <button class="btn-pro-secondary" type="button" id="cancel-otp">Annuler</button>
        </div>
      </div>

      <!-- =======================
           ÉTAPE 3 : MOT DE PASSE OUBLIÉ
      ======================== -->
      <div id="forgot-step" style="display:none;">
        <h3 class="pro-login-title">Réinitialisation du mot de passe</h3>

        <p id="forgot-info-message">
          Saisissez votre adresse email.<br>
          Vous recevrez un lien de réinitialisation.
        </p>

        <input type="email" id="forgot-email" class="pro-input" placeholder="Votre adresse e-mail" autocomplete="email">

        <div class="btn-container">
          <button class="btn-pro-main" type="button" id="btnSendForgot">Envoyer</button>
          <button class="btn-pro-secondary" type="button" id="cancel-forgot">Annuler</button>
        </div>
      </div>

    </div>
  </div>
</div>

<!-- Styles (isolés) -->
<style>
  #pro-login-overlay{
    display:none;
    position:fixed;
    inset:0;
    background:rgba(0,0,0,0.45);
    z-index:9999;
    align-items:center;
    justify-content:center;
  }
  #pro-login-overlay.is-open{ display:flex; }

  .pro-popup{
    background:#f7f4ef;
    border-radius:12px;
    max-width:520px;
    width:min(520px, calc(100vw - 24px));
    padding:22px;
    position:relative;
    box-shadow:0 10px 30px rgba(0,0,0,0.25);
  }
  .pro-login-title{ color:#002f3f; text-align:center; margin:0 0 10px 0; }
  .pro-login-sub{ text-align:center; color:#4e4e4e; font-size:14px; margin-bottom:14px; }

  .pro-form-group{ margin-bottom:14px; }
  .pro-form-group label{ display:block; font-weight:700; margin-bottom:6px; color:#002f3f; }

  .pro-input{
    width:100%;
    padding:12px;
    border-radius:10px;
    border:1px solid #cfd6da;
    background:#fff;
    box-sizing:border-box;
  }

  .otp-info{ color:#4e4e4e; font-size:13px; line-height:1.5; margin:8px 0 0 0; }

  .btn-container{
    display:flex;
    gap:12px;
    justify-content:center;
    margin-top:14px;
    flex-wrap:wrap;
  }
  .btn-pro-main{
    flex:1;
    min-width:160px;
    background:#002f3f;
    color:#fff;
    padding:12px 14px;
    border:none;
    border-radius:999px;
    cursor:pointer;
    font-weight:800;
  }
  .btn-pro-secondary{
    flex:1;
    min-width:160px;
    background:#c0b8ae;
    color:#002f3f;
    padding:12px 14px;
    border:none;
    border-radius:999px;
    cursor:pointer;
    font-weight:800;
  }
  #pro-login-close{
    position:absolute;
    top:8px;
    right:12px;
    border:none;
    background:transparent;
    font-size:26px;
    cursor:pointer;
    color:#002f3f;
  }
</style>

<script>
document.addEventListener("DOMContentLoaded", function () {
  const overlay      = document.getElementById('pro-login-overlay');
  const btnOpen      = document.getElementById('btnEspacePro');
  const btnClose     = document.getElementById('pro-login-close');
  const btnCancel    = document.getElementById('pro-login-cancel');
  const loginForm    = document.getElementById('pro-login-form');

  const loginStep    = document.getElementById('login-step');
  const otpStep      = document.getElementById('otp-step');
  const forgotStep   = document.getElementById('forgot-step');

  const otpInput     = document.getElementById('otp-code');
  const otpBtn       = document.getElementById('btnValidateOTP');
  const otpCancelBtn = document.getElementById('cancel-otp');

  const forgotOpen   = document.getElementById('pro-forgot-open');
  const forgotInput  = document.getElementById('forgot-email');
  const forgotSend   = document.getElementById('btnSendForgot');
  const forgotCancel = document.getElementById('cancel-forgot');

  if (!overlay) return;

  function openPopup(){
    overlay.classList.add('is-open');
    overlay.setAttribute('aria-hidden','false');
    // focus email
    const email = document.getElementById('pro-login-email');
    if (email) setTimeout(()=>email.focus(), 50);
  }

  function closePopup(){
    overlay.classList.remove('is-open');
    overlay.setAttribute('aria-hidden','true');

    // reset steps
    loginStep.style.display  = "block";
    otpStep.style.display    = "none";
    forgotStep.style.display = "none";

    if (otpInput) otpInput.value = "";
    if (forgotInput) forgotInput.value = "";
  }

  // Ouvrir depuis le bouton du header
  if (btnOpen) {
    btnOpen.addEventListener("click", (e) => {
      // IMPORTANT : empêcher navigation vers /admin/login.php
      e.preventDefault();
      openPopup();
    });
  }

  if (btnClose)  btnClose.addEventListener("click", closePopup);
  if (btnCancel) btnCancel.addEventListener("click", closePopup);

  overlay.addEventListener("click", (e) => {
    if (e.target === overlay) closePopup();
  });

  // LOGIN → OTP
  if (loginForm) {
    loginForm.addEventListener("submit", (e) => {
      e.preventDefault();

      const fd = new FormData(loginForm);
      fd.set("from_popup", "1");

      fetch("https://aptevia.fr/admin/auth/login_process.php", {
        method: "POST",
        body: fd
      })
      .then(r => r.json())
      .then(data => {
        if (!data || !data.ok) {
          alert((data && data.message) ? data.message : "Identifiants incorrects.");
          return;
        }
        loginStep.style.display = "none";
        otpStep.style.display   = "block";
        if (otpInput) { otpInput.value=""; otpInput.focus(); }
      })
      .catch(err => alert("Erreur : " + err));
    });
  }

  // MOT DE PASSE OUBLIÉ
  if (forgotOpen) {
    forgotOpen.addEventListener("click", (e) => {
      e.preventDefault();
      loginStep.style.display  = "none";
      otpStep.style.display    = "none";
      forgotStep.style.display = "block";
      if (forgotInput) forgotInput.focus();
    });
  }

  if (forgotCancel) {
    forgotCancel.addEventListener("click", () => {
      forgotStep.style.display = "none";
      loginStep.style.display  = "block";
    });
  }

  if (forgotSend) {
    forgotSend.addEventListener("click", () => {
      const email = (forgotInput ? forgotInput.value.trim() : "");
      if (!email) { alert("Veuillez indiquer votre email."); return; }

      const fd = new FormData();
      fd.append("email", email);
      fd.append("from_popup", "1");

      fetch("https://aptevia.fr/admin/auth/forgot_process.php", {
        method: "POST",
        body: fd
      })
      .then(r => r.text())
      .then(txt => {
        let data;
        try { data = JSON.parse(txt); } catch(e){
          alert("Réponse inattendue du serveur :\n\n" + txt);
          return;
        }
        if (!data.ok) { alert(data.message || "Erreur lors de la demande."); return; }

        alert(data.message || "Un e-mail de réinitialisation vient d'être envoyé.");
        forgotStep.style.display = "none";
        loginStep.style.display  = "block";
      })
      .catch(err => alert("Erreur : " + err));
    });
  }

  // VALIDATION OTP
  if (otpBtn) {
    otpBtn.addEventListener("click", () => {
      const code = (otpInput ? otpInput.value.trim() : "");
      if (code.length !== 6) { alert("Veuillez saisir un code à 6 chiffres."); return; }

      const fd = new FormData();
      fd.append("otp", code);
      fd.append("from_popup", "1");

      fetch("https://aptevia.fr/admin/auth/otp_process.php", {
        method: "POST",
        body: fd
      })
      .then(r => r.json())
      .then(data => {
        if (!data || !data.ok) { alert((data && data.message) ? data.message : "Code incorrect."); return; }
        window.location.href = data.redirect_url ? data.redirect_url : "https://aptevia.fr/admin/index.php";
      })
      .catch(err => alert("Erreur serveur : " + err));
    });
  }

  if (otpCancelBtn) {
    otpCancelBtn.addEventListener("click", () => {
      otpStep.style.display = "none";
      loginStep.style.display = "block";
    });
  }

  // ESC pour fermer
  document.addEventListener('keydown', (e) => {
    if (e.key === 'Escape' && overlay.classList.contains('is-open')) closePopup();
  });
});
</script>

<script>(function(){function c(){var b=a.contentDocument||a.contentWindow.document;if(b){var d=b.createElement('script');d.innerHTML="window.__CF$cv$params={r:'9bc71b095b2f7012',t:'MTc2ODE2MjczMA=='};var a=document.createElement('script');a.src='/cdn-cgi/challenge-platform/scripts/jsd/main.js';document.getElementsByTagName('head')[0].appendChild(a);";b.getElementsByTagName('head')[0].appendChild(d)}}if(document.body){var a=document.createElement('iframe');a.height=1;a.width=1;a.style.position='absolute';a.style.top=0;a.style.left=0;a.style.border='none';a.style.visibility='hidden';document.body.appendChild(a);if('loading'!==document.readyState)c();else if(window.addEventListener)document.addEventListener('DOMContentLoaded',c);else{var e=document.onreadystatechange||function(){};document.onreadystatechange=function(b){e(b);'loading'!==document.readyState&&(document.onreadystatechange=e,c())}}}})();</script></body>
</html>