.answer{
    background-color: var(--vp-c-bg);
    z-index: 9999;
    display: none;
    position: fixed;
    top: 110px;
    width: 600px;
    max-width: 87%;
    margin: 0 auto;
    padding: 20px;
    border: 1px solid #b9b9b9;
    border-radius: 5px;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
    transition: all 0.3s;
    right: 30px;
    margin-bottom: 10px;
    overflow-y: auto;
    max-height: 85vh;
}

/* VitePress remet à zéro les marges et puces hors de .vp-doc : on les rétablit dans le panneau */
#answerContent p, .chatMessage p {
    margin: 0.6em 0;
    line-height: 1.6;
}

#answerContent ul, #answerContent ol, .chatMessage ul, .chatMessage ol {
    margin: 0.6em 0;
    padding-left: 1.4em;
}

#answerContent ul, .chatMessage ul {
    list-style: disc;
}

#answerContent ol, .chatMessage ol {
    list-style: decimal;
}

#answerContent li + li, .chatMessage li + li {
    margin-top: 0.3em;
}

#answerContent :not(pre) > code, .chatMessage :not(pre) > code {
    padding: 2px 5px;
    border-radius: 4px;
    background-color: var(--vp-c-mute, rgba(127, 127, 127, 0.15));
    font-size: 0.875em;
}

#answerContent pre, .chatMessage pre {
    margin: 0.6em 0;
    padding: 10px 12px;
    border-radius: 6px;
    background-color: var(--vp-code-block-bg, rgba(127, 127, 127, 0.12));
    font-size: 0.85em;
    overflow-x: auto;
}

#answerContent h1, #answerContent h2, #answerContent h3, #answerContent h4,
.chatMessage h1, .chatMessage h2, .chatMessage h3, .chatMessage h4 {
    margin: 0.8em 0 0.4em;
    font-weight: 600;
}

#answerContent > :first-child {
    margin-top: 0;
}

.answerContentInfo{
    padding-top: 10px;
    font-size: 0.7em;
    line-height: 1;
    font-style: italic;
    text-align: center;
}

.answer.visible{
    display: block;
}

.answer > h3{
    margin-top: 0;
    font-size: 1.5em;
    margin-bottom: 10px;
}

.answer > .close {
    position: absolute; top: 10px; right: 10px; cursor: pointer;
}

#reformulateAction {
    z-index: 999;
    display: none;
    position: absolute;
    padding: 5px 10px;
    background-color: #fff;
    color: #000000;
    border: 1px solid #b9b9b9;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
    opacity: 0.2;
    transition: all 0.3s;
}

#reformulateAction:hover {
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
    opacity: 1;
}

.answer.animation {
    box-shadow: 0 0 10px #ff6ec4; /* Couleur initiale de l'ombre intérieure */
    transition: all 0.3s;
    animation: boxShadowRotate 5s infinite;
}

@keyframes boxShadowRotate {
    0% {
        box-shadow:  0 0 10px #ff6ec4;
    }
    25% {
        box-shadow:  0 0 30px #7873f5; 
    }
    50% {
        box-shadow:  0 0 10px #32a8a0; 
    }
    75% {
        box-shadow:  0 0 30px #ff6ec4; 
    }
    100% {
        box-shadow:  0 0 10px #ff6ec4;
    }
}
#chatStart {
    display: none;
    margin: 10px auto 0;
    padding: 6px 14px;
    border: 1px solid var(--vp-c-divider, #b9b9b9);
    border-radius: 20px;
    background-color: var(--vp-c-bg-soft);
    cursor: pointer;
}

#chatStart:hover {
    border-color: var(--vp-c-brand-1, #3e80af);
}

#chatForm {
    display: none;
}

/* Choix entre la reformulation par prompt et le résumé de Chrome */
#reformulationModes {
    display: none;
    gap: 4px;
    margin-bottom: 10px;
    padding: 3px;
    border-radius: 20px;
    background-color: var(--vp-c-bg-soft);
    width: fit-content;
}

#reformulationModes button {
    padding: 3px 12px;
    border-radius: 20px;
    font-size: 0.85em;
    color: var(--vp-c-text-2);
    cursor: pointer;
}

#reformulationModes button.active {
    background-color: var(--vp-c-bg);
    color: var(--vp-c-text-1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.answer.chat #reformulationModes {
    display: none !important;
}

/* Mode chat : panneau ancré à droite, sur toute la hauteur sous la barre de navigation */
:root {
    --reformulation-panel-width: 420px;
}

.answer.chat {
    display: flex;
    flex-direction: column;
    top: var(--vp-nav-height, 64px);
    bottom: 0;
    right: 0;
    width: var(--reformulation-panel-width);
    max-width: 100%;
    max-height: none;
    margin: 0;
    overflow: hidden;
    border: none;
    border-left: 1px solid var(--vp-c-divider, #b9b9b9);
    border-radius: 0;
    box-shadow: none;
    z-index: 25; /* sous la barre de navigation (30) et ses menus déroulants */
}

/* Tablette : la barre VitePress n'est plus fixe (elle défile), le panneau part du haut de l'écran */
@media (min-width: 641px) and (max-width: 959px) {
    .answer.chat {
        top: 0;
    }
}

/* Pas de halo animé sur le panneau de chat pendant la génération */
.answer.chat.animation {
    animation: none;
    box-shadow: none;
}

/* Grand écran : le contenu se décale au lieu d'être masqué (le sommaire de droite laisse sa place au chat) */
@media (min-width: 1280px) {
    html.reformulation-docked .VPContent,
    html.reformulation-docked .VPFooter {
        padding-right: max(var(--reformulation-panel-width), calc((100vw - var(--vp-layout-max-width)) / 2)) !important;
    }

    html.reformulation-docked .VPDoc .aside {
        display: none !important;
    }
}

.answer.chat #chatThread {
    flex: 1;
    overflow-y: auto;
}

.answer.chat #chatForm {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding-top: 10px;
    border-top: 1px solid var(--vp-c-divider, #b9b9b9);
}

#modelChoice {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    font-size: 0.8em;
    color: var(--vp-c-text-2);
}

#modelSelect {
    flex: 1;
    min-width: 0;
    padding: 3px 6px;
    border: 1px solid var(--vp-c-divider, #b9b9b9);
    border-radius: 5px;
    background-color: var(--vp-c-bg-soft);
    color: var(--vp-c-text-1);
    font: inherit;
}

#modelDelete {
    display: flex;
    align-items: center;
    padding: 4px;
    border-radius: 5px;
    color: var(--vp-c-text-2);
    cursor: pointer;
}

#modelDelete:hover:not(:disabled) {
    color: var(--vp-c-danger-1, #c0392b);
    background-color: var(--vp-c-bg-soft);
}

#modelDelete:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* Passage sélectionné rappelé en tête du chat */
.chatSelection {
    margin: 0 0 10px;
    padding: 8px 12px;
    border-left: 3px solid var(--vp-c-brand-1, #3e80af);
    background-color: var(--vp-c-bg-soft);
    font-size: 0.9em;
    color: var(--vp-c-text-2);
}

.chatSelection p {
    margin: 0;
}

.chatSelection .chatSelectionTitle {
    margin-bottom: 4px;
    font-size: 0.8em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

#chatContext {
    width: 100%;
    margin: 0;
    font-size: 0.8em;
    color: var(--vp-c-text-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#chatInput {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid var(--vp-c-divider, #b9b9b9);
    border-radius: 5px;
    background-color: var(--vp-c-bg-soft);
    resize: none;
    font: inherit;
}

#chatForm > button {
    padding: 0 12px;
    border-radius: 5px;
    background-color: var(--vp-c-brand-1, #3e80af);
    color: #fff;
    cursor: pointer;
}

.chatMessage {
    margin-top: 10px;
    padding: 8px 12px;
    border-radius: 8px;
}

.chatMessage.user {
    margin-left: 15%;
    background-color: var(--vp-c-brand-soft, #e8f0f7);
}

.chatMessage.assistant {
    background-color: var(--vp-c-bg-soft);
}

.chatMessage.info {
    font-size: 0.8em;
    font-style: italic;
    text-align: center;
    color: var(--vp-c-text-2);
}

.chatMessage > :first-child {
    margin-top: 0;
}

.chatMessage > :last-child {
    margin-bottom: 0;
}

/* Mobile : panneau sur toute la largeur, et chat en tiroir en bas pour garder la page visible au-dessus */
@media (max-width: 640px) {
    .answer {
        top: calc(var(--vp-nav-height, 64px) + 16px);
        left: 16px;
        right: 16px;
        width: auto;
        max-width: none;
        max-height: 60vh;
    }

    .answer.chat {
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        width: auto;
        margin: 0;
        height: 55vh;
        height: 55dvh;
        padding: 16px;
        border: none;
        border-top: 1px solid var(--vp-c-divider, #b9b9b9);
        border-radius: 12px 12px 0 0;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    }

    .answer.chat.animation {
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    }

    .answer > h3 {
        font-size: 1.2em;
    }

    /* 16 px minimum : évite le zoom automatique du navigateur au focus du champ */
    #chatInput {
        font-size: 16px;
    }
}
