/*
 * Mentor IA du lecteur de cours (study-mentor.blade.php, course-mentor.js) :
 * un bouton dans le coin bas droit, une fenêtre de discussion au-dessus.
 * Les couleurs viennent des variables --st-* du lecteur : le thème sombre suit
 * sans règle de plus.
 *
 * Le coin est partagé. Sous 1200 px, le bouton « Programme » (.st-fab) y est
 * déjà ; sous 600 px, la barre précédent / suivant occupe le bas de l'écran.
 * Le bouton du mentor se pose au-dessus des deux.
 */

.mt-lanceur {
    position: fixed;
    z-index: 1039;
    right: max(24px, env(safe-area-inset-right));
    bottom: max(24px, env(safe-area-inset-bottom));
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 52px;
    padding: 0 20px 0 16px;
    border: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--st-brand), var(--st-brand2));
    color: #fff;
    font: inherit;
    font-size: 15px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 12px 28px -10px rgba(11, 59, 209, .8);
    transition: transform .15s ease;
}

.mt-lanceur:hover {
    transform: translateY(-2px);
}

/* Même raison que pour .st-fab : `[class^="ri-"]` du thème repeint le glyphe. */
.mt-lanceur i {
    color: inherit;
    font-size: 22px;
    line-height: 1;
}

.mt-lanceur[aria-expanded="true"] {
    padding: 0;
    width: 52px;
    justify-content: center;
}

.mt-lanceur[aria-expanded="true"] span {
    display: none;
}

.st-mentor {
    position: fixed;
    z-index: 1045;
    right: max(24px, env(safe-area-inset-right));
    bottom: calc(max(24px, env(safe-area-inset-bottom)) + 64px);
    width: min(400px, calc(100vw - 32px));
    /* Jamais sous l'en-tête du gabarit : 110 px libres au-dessus de la fenêtre. */
    height: min(640px, calc(100vh - 200px));
    display: flex;
    flex-direction: column;
    background: var(--st-surface);
    border: 1px solid var(--st-border);
    border-radius: 18px;
    box-shadow: 0 24px 60px -20px rgba(6, 12, 24, .55);
    overflow: hidden;
    transform-origin: bottom right;
    animation: mt-ouverture .18s ease-out;
}

@keyframes mt-ouverture {
    from {
        opacity: 0;
        transform: translateY(8px) scale(.98);
    }
}

/* Les règles display de ce fichier l'emporteraient sur l'attribut hidden. */
.st-mentor[hidden],
.st-mentor [hidden] {
    display: none !important;
}

@media (prefers-reduced-motion: reduce) {
    .st-mentor {
        animation: none;
    }
}

.mt-tete {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 10px 12px 14px;
    border-bottom: 1px solid var(--st-border);
}

.mt-avatar {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--st-brand), var(--st-brand2));
    color: #fff;
    font-size: 16px;
    font-weight: 800;
}

.mt-id {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}

.mt-id b {
    color: var(--st-text);
    font-size: 14.5px;
}

.mt-id span {
    color: var(--st-text3);
    font-size: 12.5px;
}

.mt-icone {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--st-text2);
    font-size: 19px;
    cursor: pointer;
}

.mt-icone i {
    color: inherit;
}

.mt-icone:hover {
    background: var(--st-surface2);
    color: var(--st-text);
}

.mt-chargement {
    color: var(--st-text3);
    font-size: 14px;
    padding: 16px;
}

.mt-vide {
    color: var(--st-text3);
    font-size: 14px;
    line-height: 1.55;
    padding: 4px 2px;
}

.mt-accord,
.mt-raison {
    margin: 14px;
    overflow-y: auto;
    border: 1px solid var(--st-border);
    background: var(--st-surface2);
    border-radius: var(--st-radius);
    padding: 14px 16px;
    font-size: 14px;
    color: var(--st-text2);
    line-height: 1.55;
}

.mt-accord ul {
    margin: 8px 0 14px;
    padding-left: 18px;
    list-style: disc;
}

.mt-accord li + li {
    margin-top: 6px;
}

.mt-accord b {
    color: var(--st-text);
}

.mt-raison {
    background: var(--st-warn-soft);
    border-color: transparent;
    color: var(--st-text);
}

.mt-corps {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 14px 10px;
}

.mt-fil {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: 2px;
}

.mt-msg {
    max-width: 92%;
    font-size: 14.5px;
    line-height: 1.6;
    overflow-wrap: anywhere;
}

.mt-msg.moi {
    align-self: flex-end;
    background: var(--st-brand);
    color: #fff;
    border-radius: 14px 14px 4px 14px;
    padding: 9px 13px;
    white-space: pre-wrap;
}

.mt-msg.ia {
    align-self: flex-start;
    background: var(--st-surface2);
    color: var(--st-text);
    border-radius: 14px 14px 14px 4px;
    padding: 10px 14px;
}

.mt-msg.ia > :first-child {
    margin-top: 0;
}

.mt-msg.ia > :last-child {
    margin-bottom: 0;
}

.mt-msg.ia p,
.mt-msg.ia ul,
.mt-msg.ia ol,
.mt-msg.ia pre,
.mt-msg.ia h4 {
    margin: 0 0 9px;
}

.mt-msg.ia ul,
.mt-msg.ia ol {
    padding-left: 20px;
}

.mt-msg.ia ul {
    list-style: disc;
}

.mt-msg.ia ol {
    list-style: decimal;
}

.mt-msg.ia h4 {
    font-size: 14.5px;
    font-weight: 700;
}

.mt-msg.ia code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9em;
    background: var(--st-surface3);
    border-radius: 5px;
    padding: 1px 5px;
}

.mt-msg.ia pre {
    background: #0e1a30;
    color: #e7ecf5;
    border-radius: var(--st-radius-sm);
    padding: 10px 12px;
    overflow-x: auto;
    font-size: 13px;
    line-height: 1.5;
}

.mt-msg.ia pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.mt-msg.ia .mt-ts {
    border: 0;
    background: var(--st-soft);
    color: var(--st-brand);
    border-radius: 5px;
    padding: 0 5px;
    font: inherit;
    font-size: 0.92em;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
}

.mt-msg.ia.erreur {
    background: var(--st-danger-soft);
}

.mt-curseur::after {
    content: "";
    display: inline-block;
    width: 7px;
    height: 1em;
    margin-left: 2px;
    vertical-align: -2px;
    background: var(--st-brand);
    animation: mt-clignote 1s steps(2) infinite;
}

@keyframes mt-clignote {
    50% {
        opacity: 0;
    }
}

.mt-outils {
    display: flex;
    gap: 4px;
    margin-top: -6px;
}

.mt-outils button {
    border: 0;
    background: transparent;
    color: var(--st-text3);
    border-radius: 6px;
    padding: 3px 7px;
    font: inherit;
    font-size: 12.5px;
    cursor: pointer;
}

.mt-outils button:hover,
.mt-outils button.on {
    color: var(--st-brand);
    background: var(--st-soft);
}

.mt-actions {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
}

.mt-actions::-webkit-scrollbar {
    display: none;
}

.mt-actions button {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1px solid var(--st-border);
    background: var(--st-surface);
    color: var(--st-text);
    border-radius: 99px;
    padding: 6px 12px;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}

.mt-actions button:hover {
    border-color: var(--st-brand);
    color: var(--st-brand);
}

.mt-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.mt-form textarea {
    flex: 1 1 auto;
    min-height: 44px;
    max-height: 160px;
    resize: none;
    border: 1px solid var(--st-border2);
    background: var(--st-surface);
    color: var(--st-text);
    border-radius: var(--st-radius-sm);
    padding: 10px 12px;
    font: inherit;
    font-size: 14.5px;
    line-height: 1.45;
}

.mt-form textarea:focus {
    outline: 2px solid var(--st-soft);
    border-color: var(--st-brand);
}

.mt-form .st-btn {
    height: 44px;
    width: 44px;
    justify-content: center;
    padding: 0;
}

.st-mentor.occupe .mt-actions button,
.st-mentor.occupe .mt-form .st-btn {
    opacity: 0.5;
    pointer-events: none;
}

.mt-pied {
    color: var(--st-text3);
    font-size: 12.5px;
}

/* Bulle « Demander au mentor » sur un passage surligné de la leçon. */
.mt-bulle {
    position: absolute;
    z-index: 60;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 0;
    background: #0e1a30;
    color: #fff;
    border-radius: 99px;
    padding: 7px 12px;
    font: inherit;
    font-size: 13px;
    box-shadow: 0 6px 18px rgba(14, 26, 48, 0.25);
    cursor: pointer;
}

/* Point sur le bouton : Léo a proposé quelque chose. */
.mt-lanceur.signal::after {
    content: "";
    position: absolute;
    top: 4px;
    right: 6px;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: #ff5a5f;
    box-shadow: 0 0 0 2px #fff;
}

/* Bulle de relance, au-dessus du bouton (course-mentor.js, « Relances »). */
.mt-relance {
    position: fixed;
    z-index: 1039;
    right: max(24px, env(safe-area-inset-right));
    bottom: calc(max(24px, env(safe-area-inset-bottom)) + 66px);
    width: min(310px, calc(100vw - 28px));
    padding: 14px 14px 12px;
    background: var(--st-surface, #fff);
    color: var(--st-text, #0e1a30);
    border: 1px solid var(--st-border, #e2e8f2);
    border-radius: 16px 16px 4px 16px;
    box-shadow: 0 18px 40px -16px rgba(6, 12, 24, .45);
    animation: mt-relance-entree .25s ease-out;
}

.mt-relance.sortie {
    opacity: 0;
    transform: translateY(6px);
    transition: opacity .2s, transform .2s;
}

@keyframes mt-relance-entree {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
}

.mt-relance-tete {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding-right: 18px;
}

.mt-relance-tete .mt-avatar {
    width: 30px;
    height: 30px;
    font-size: 14px;
}

.mt-relance-tete p {
    margin: 0;
    font-size: 14.5px;
    line-height: 1.45;
}

.mt-relance-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    padding-left: 40px;
}

.mt-relance-x {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--st-text3, #8b98b2);
    font-size: 16px;
    cursor: pointer;
}

.mt-relance-x i {
    color: inherit;
}

.mt-relance-x:hover {
    background: var(--st-surface2, #f4f6fb);
}

@media (prefers-reduced-motion: reduce) {
    .mt-relance {
        animation: none;
    }
}

/* Tablette : le bouton « Programme » est dans le coin, on passe au-dessus. */
@media (max-width: 1200px) {
    .mt-lanceur {
        right: max(14px, env(safe-area-inset-right));
        bottom: calc(max(14px, env(safe-area-inset-bottom)) + 58px);
    }

    .mt-relance {
        right: max(14px, env(safe-area-inset-right));
        bottom: calc(max(14px, env(safe-area-inset-bottom)) + 120px);
    }

    .st-mentor {
        right: max(14px, env(safe-area-inset-right));
        bottom: calc(max(14px, env(safe-area-inset-bottom)) + 122px);
        height: min(620px, calc(100vh - 250px));
    }
}

/* Téléphone : la barre précédent / suivant est en bas, le bouton « Programme »
   au-dessus d'elle, le mentor encore au-dessus ; la fenêtre prend tout
   l'écran. */
@media (max-width: 600px) {
    .mt-lanceur {
        bottom: calc(max(14px, env(safe-area-inset-bottom)) + 142px);
        height: 48px;
        padding: 0 16px 0 14px;
    }

    .mt-relance {
        bottom: calc(max(14px, env(safe-area-inset-bottom)) + 214px);
    }

    /* Plein écran, au-dessus des en-têtes collants. */
    .st-mentor {
        inset: 0;
        width: auto;
        height: auto;
        z-index: 100000;
        border: 0;
        border-radius: 0;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .mt-msg {
        max-width: 100%;
    }
}

/* Lien vers un cours ou un parcours, dans une réponse de Léo. */
.mt-msg.ia .mt-lien {
    color: var(--st-brand);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

/*
 * Léo hors du lecteur (gabarit du tableau de bord, mode conseiller) : les
 * variables --st-* et le bouton .st-btn viennent normalement de la feuille du
 * lecteur (study-styles), absente ici. Mêmes valeurs, limitées à Léo.
 */
.leo-hors-cours {
    --st-surface: #fff;
    --st-surface2: #f4f6fb;
    --st-surface3: #e7ecf5;
    --st-border: #e2e8f2;
    --st-border2: #d3dbea;
    --st-text: #0e1a30;
    --st-text2: #56657f;
    --st-text3: #8b98b2;
    --st-brand: #0b3bd1;
    --st-brand2: #1c50e8;
    --st-soft: #e7edff;
    --st-warn-soft: #fbefd8;
    --st-danger-soft: #fbe9e9;
    --st-radius: 12px;
    --st-radius-sm: 9px;
    font-family: inherit;
}

.dark .leo-hors-cours {
    --st-surface: #111827;
    --st-surface2: #161f30;
    --st-surface3: #1c2740;
    --st-border: #25314a;
    --st-border2: #31405e;
    --st-text: #eaf0fa;
    --st-text2: #9fb0ce;
    --st-text3: #65759a;
    --st-brand: #5e86ff;
    --st-brand2: #7a9bff;
    --st-soft: #16223f;
    --st-warn-soft: #2a2110;
    --st-danger-soft: #2a1414;
}

.leo-hors-cours *,
.leo-hors-cours *::before,
.leo-hors-cours *::after {
    box-sizing: border-box;
}

.leo-hors-cours .st-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 1px solid var(--st-border2);
    background: var(--st-surface);
    color: var(--st-text);
    font: inherit;
    font-size: 13.5px;
    font-weight: 500;
    padding: 8px 15px;
    border-radius: var(--st-radius-sm);
    cursor: pointer;
}

.leo-hors-cours .st-btn.primary {
    background: var(--st-brand);
    border-color: var(--st-brand);
    color: #fff;
}

.leo-hors-cours .st-btn.primary:hover {
    background: var(--st-brand2);
}

.leo-hors-cours .st-btn.sm {
    padding: 6px 12px;
    font-size: 12.5px;
}

/* Pas de bouton « Programme » ni de barre précédent / suivant hors du
   lecteur : Léo reprend le coin, même sur tablette et téléphone. */
@media (max-width: 1200px) {
    .leo-hors-cours .mt-lanceur {
        bottom: max(16px, env(safe-area-inset-bottom));
    }

    .leo-hors-cours .st-mentor {
        bottom: calc(max(16px, env(safe-area-inset-bottom)) + 64px);
        height: min(620px, calc(100vh - 190px));
    }

    .leo-hors-cours .mt-relance {
        bottom: calc(max(16px, env(safe-area-inset-bottom)) + 66px);
    }
}

@media (max-width: 600px) {
    .leo-hors-cours .st-mentor {
        bottom: 0;
    }
}

/*
 * Page d'accueil : le bouton « Assistance » (assistance-widget, bottom-5
 * right-5, z-index 9998) tient déjà le coin. Léo se pose au-dessus de lui,
 * et sa fenêtre ouverte passe devant le panneau d'assistance.
 */
.leo-accueil .mt-lanceur {
    right: max(20px, env(safe-area-inset-right));
    bottom: calc(max(20px, env(safe-area-inset-bottom)) + 62px);
    z-index: 9997;
}

.leo-accueil .mt-relance {
    right: max(20px, env(safe-area-inset-right));
    bottom: calc(max(20px, env(safe-area-inset-bottom)) + 128px);
    z-index: 9997;
}

/* L'en-tête du site est collant (81 px, z-index 99999) : la fenêtre ne doit
   jamais remonter dessous. Elle descend jusqu'en bas, par-dessus les deux
   boutons (sa croix la ferme), et garde 110 px libres en haut. */
.leo-accueil .st-mentor {
    right: max(20px, env(safe-area-inset-right));
    bottom: max(20px, env(safe-area-inset-bottom));
    height: min(620px, calc(100vh - 130px));
    z-index: 10000;
}

/* Téléphone : plein écran, au-dessus de l'en-tête collant. */
@media (max-width: 600px) {
    .leo-accueil .st-mentor {
        inset: 0;
        height: auto;
        z-index: 100000;
    }
}

/* Accueil : à la place de l'écran d'accord, une mention discrète. */
.mt-mention {
    margin: -4px 0 0;
    color: var(--st-text3);
    font-size: 11.5px;
    line-height: 1.4;
}
