.chatbot {
    position: fixed;
    right: 20px;
    bottom: 120px;
    z-index: 99999;
    font-family: 'Poppins', sans-serif;
}

.chatbot__toggle {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 3px solid #1e5f8e;
    background: #ffffff;
    color: #fff;
    font-size: 1.4rem;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0,0,0,0.18), 0 0 0 4px rgba(27, 108, 168, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .2s cubic-bezier(.2,.8,.2,1), box-shadow .2s ease, background .2s ease, border-color .2s ease;
    position: relative;
    z-index: 100000;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    animation: chatbotIdlePulse 3s infinite;
}

.chatbot__toggle:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 14px 32px rgba(0,0,0,0.22), 0 0 0 8px rgba(27, 108, 168, 0.12);
    background: #f8fafb;
    border-color: #1e5f8e;
}

.chatbot__toggle:active {
    transform: translateY(0) scale(0.95);
    box-shadow: 0 4px 12px rgba(0,0,0,0.18), 0 0 0 2px rgba(27, 108, 168, 0.15);
    background: #f0fdf4;
}

@keyframes chatbotIdlePulse {
    0%, 100% {
        box-shadow: 0 8px 24px rgba(0,0,0,0.18), 0 0 0 4px rgba(27, 108, 168, 0.08);
    }
    50% {
        box-shadow: 0 8px 24px rgba(0,0,0,0.18), 0 0 0 10px rgba(27, 108, 168, 0.18);
    }
}

.chatbot__toggle-img {
    width: 38px;
    height: 38px;
    object-fit: contain;
    pointer-events: none;
    display: block;
}

.chatbot__chat-badge {
    position: absolute;
    bottom: -8px;
    right: -8px;
    width: 30px;
    height: 30px;
    background: #ffffff;
    border: 2px solid #1e5f8e;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #1e5f8e;
    font-size: 0.85rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.18);
    pointer-events: none;
    animation: chatbotPulse 2.2s infinite;
}

.chatbot__badge {
    position: absolute;
    top: 2px;
    right: 2px;
    background: #dc3545;
    color: #fff;
    font-size: 0.7rem;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    border: 2px solid #fff;
}

@keyframes chatbotPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(27, 108, 168, 0.45);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(27, 108, 168, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(27, 108, 168, 0);
    }
}

.chatbot__window {
    position: absolute;
    right: 0;
    bottom: 76px;
    width: 370px;
    max-width: calc(100vw - 40px);
    height: 540px;
    max-height: calc(100vh - 120px);
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 24px 60px rgba(16, 35, 63, 0.18), 0 0 0 1px rgba(16, 35, 63, 0.06);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transform: scale(0.92);
    opacity: 0;
    pointer-events: none;
    transition: transform .28s cubic-bezier(.2,.8,.2,1), opacity .22s ease;
    will-change: transform, opacity;
    z-index: 99998;
}

.chatbot__window--open {
    transform: scale(1);
    opacity: 1;
    pointer-events: auto;
    animation: chatbotBounceIn .35s cubic-bezier(.2,.8,.2,1);
}

@keyframes chatbotBounceIn {
    0% {
        transform: scale(0.92) translateY(10px);
        opacity: 0;
    }
    60% {
        transform: scale(1.02) translateY(-2px);
        opacity: 1;
    }
    100% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

.chatbot__header {
    background: linear-gradient(135deg, #1e5f8e, #164c7a);
    color: #fff;
    padding: 18px 18px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.chatbot__title {
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: 0.01em;
}

.chatbot__subtitle {
    font-size: 0.78rem;
    opacity: 0.92;
    margin-top: 2px;
}

.chatbot__close {
    background: rgba(255,255,255,0.18);
    border: none;
    color: #fff;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .2s ease, transform .2s ease;
    backdrop-filter: blur(4px);
}

.chatbot__close:hover {
    background: rgba(255,255,255,0.32);
    transform: rotate(90deg);
}

.chatbot__messages {
    flex: 1;
    padding: 18px;
    overflow-y: auto;
    background: linear-gradient(180deg, #f8f9fa 0%, #ffffff 100%);
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.chatbot__message {
    max-width: 88%;
}

.chatbot__message--bot {
    align-self: flex-start;
}

.chatbot__message--user {
    align-self: flex-end;
}

.chatbot__bubble {
    padding: 13px 15px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.5;
    word-break: break-word;
}

.chatbot__message--bot .chatbot__bubble {
    background: #ffffff;
    color: #10233F;
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 10px rgba(16, 35, 63, 0.06);
    border: 1px solid rgba(16, 35, 63, 0.06);
}

.chatbot__message--user .chatbot__bubble {
    background: linear-gradient(135deg, #1e5f8e, #164c7a);
    color: #fff;
    border-bottom-right-radius: 6px;
    box-shadow: 0 4px 14px rgba(27, 108, 168, 0.25);
}

.chatbot__bubble a {
    color: #1e5f8e;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.chatbot__bubble ul {
    margin: 10px 0 0 18px;
    padding: 0;
}

.chatbot__bubble li {
    margin-bottom: 6px;
}

.chatbot__bubble h4,
.chatbot__bubble h5 {
    margin: 12px 0 6px;
    font-weight: 700;
    line-height: 1.3;
    color: inherit;
}
.chatbot__bubble h4 { font-size: 1rem; }
.chatbot__bubble h5 { font-size: 0.95rem; }

.chatbot__bubble hr {
    margin: 10px 0;
    border: none;
    border-top: 1px solid rgba(16, 35, 63, 0.12);
}
.chatbot__message--user .chatbot__bubble hr {
    border-top-color: rgba(255, 255, 255, 0.3);
}

/* Tableau — enveloppe défilable : une bulle de chat est étroite, un
   tableau à plusieurs colonnes déborderait sinon de la fenêtre. */
.chatbot__bubble .chatbot__table-wrap {
    margin: 10px 0;
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid rgba(16, 35, 63, 0.1);
}

.chatbot__bubble table {
    border-collapse: collapse;
    width: 100%;
    font-size: 0.85rem;
}

.chatbot__bubble th,
.chatbot__bubble td {
    padding: 6px 10px;
    text-align: left;
    border-bottom: 1px solid rgba(16, 35, 63, 0.08);
    white-space: normal;
}

.chatbot__bubble thead th {
    background: rgba(30, 95, 142, 0.06);
    font-weight: 700;
    white-space: nowrap;
}

.chatbot__bubble tbody tr:last-child td {
    border-bottom: none;
}

.chatbot__form {
    display: flex;
    gap: 10px;
    padding: 14px 16px;
    border-top: 1px solid #e5e7eb;
    background: #ffffff;
}

.chatbot__input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 24px;
    padding: 11px 16px;
    font-size: 0.95rem;
    outline: none;
    background: #f9fafb;
    transition: border-color .2s ease, background .2s ease, box-shadow .2s ease;
}

.chatbot__input:focus {
    border-color: #1e5f8e;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(27, 108, 168, 0.12);
}

.chatbot__send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #1e5f8e, #164c7a);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .2s ease, box-shadow .2s ease;
    box-shadow: 0 4px 12px rgba(27, 108, 168, 0.25);
}

.chatbot__send:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(27, 108, 168, 0.35);
}

.chatbot__typing {
    display: inline-flex;
    gap: 5px;
    padding: 10px 12px;
}

.chatbot__typing span {
    width: 8px;
    height: 8px;
    background: #9ca3af;
    border-radius: 50%;
    animation: chatbotBounce .7s infinite alternate;
}

.chatbot__typing span:nth-child(2) {
    animation-delay: .18s;
}

.chatbot__typing span:nth-child(3) {
    animation-delay: .36s;
}

@keyframes chatbotBounce {
    to {
        transform: translateY(-5px);
        background: #1e5f8e;
    }
}

/* Téléphone : bouton plus discret, fenêtre en plein écran.
   La fenêtre flottante (370px, calée à droite) débordait de l'écran sur les
   petits téléphones : le bouton d'envoi sortait à droite. */
@media (max-width: 767.98px) {
    .chatbot {
        right: 16px;
        bottom: calc(84px + env(safe-area-inset-bottom, 0px));
    }

    .chatbot__toggle {
        width: 54px;
        height: 54px;
        border-width: 2px;
        animation: none;
    }

    .chatbot__toggle-img {
        width: 30px;
        height: 30px;
    }

    .chatbot__chat-badge {
        width: 24px;
        height: 24px;
        bottom: -5px;
        right: -5px;
        font-size: .7rem;
        animation: none;
    }

    .chatbot__window {
        position: fixed;
        inset: 0;
        width: 100%;
        max-width: none;
        height: 100%;
        max-height: none;
        border-radius: 0;
        transform: translateY(16px);
        transform-origin: bottom center;
    }

    .chatbot__window--open {
        transform: none;
        animation: none;
    }

    .chatbot__header {
        padding: calc(14px + env(safe-area-inset-top, 0px)) 16px 14px 20px;
    }

    .chatbot__close {
        width: 42px;
        height: 42px;
        flex-shrink: 0;
    }

    .chatbot__messages {
        padding: 16px;
    }

    .chatbot__form {
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
        gap: 8px;
    }

    .chatbot__input {
        min-width: 0;
        /* 16px minimum : en dessous, iOS zoome sur le champ à la saisie */
        font-size: 16px;
    }

    .chatbot__send {
        flex-shrink: 0;
    }

    /* Fenêtre ouverte : rien ne doit passer par-dessus ni défiler derrière */
    body.assistant-ouvert {
        overflow: hidden;
    }

    body.assistant-ouvert .chatbot__toggle,
    body.assistant-ouvert .visite-guidee-bouton,
    body.assistant-ouvert .grecaptcha-badge {
        visibility: hidden !important;
    }
}
