/* ==========================================================================
   MESSAGES ET NAVIGATION ENTRE BRANCHES
   ========================================================================== */
.message {
    max-width: 800px;
    margin: 0 auto 16px;
    display: flex;
    gap: 12px;
    width: 100%;
    animation: messageSlideIn 0.4s ease-out;
    position: relative;
}

.message.masque {
    display: none !important;
}


.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--rayon);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 16px;
    position: relative;
    z-index: 10;
    transition: all 0.3s ease;
}
.message.utilisateur .message-avatar {
    background: var(--accent);
    color: white;
}
.message.assistant .message-avatar {
    background: var(--fond-tertiaire);
}
.message-contenu {
    flex: 1;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}
.message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    justify-content: space-between;
    position: relative;
}
.message-header>div:first-child {
    display: flex;
    align-items: center;
    gap: 8px;
}
.message-controls {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}
.message:hover .message-controls {
    opacity: 1;
}

/* Navigation entre branches alternatives */
.nav-branches {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--fond-tertiaire);
    padding: 4px 8px;
    border-radius: 16px;
    border: 1px solid var(--bordure);
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
}

.btn-nav-branche {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px solid var(--bordure);
    background: var(--fond-principal);
    color: var(--texte-secondaire);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
}

.btn-nav-branche:hover:not(:disabled) {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.btn-nav-branche:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.nav-branche-compteur {
    font-size: 12px;
    font-weight: 600;
    color: var(--texte-principal);
    white-space: nowrap;
    padding: 0 4px;
}

.message-auteur {
    font-weight: 500;
    font-size: 13px;
}
.message-date {
    font-size: 11px;
    color: var(--texte-tertiaire);
}

.message-texte {
    color: var(--texte-principal);
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
}
.message-edition {
    width: 100%;
    min-height: 80px;
    padding: 8px 12px;
    border: 1px solid var(--bordure);
    border-radius: var(--rayon);
    background: var(--fond-principal);
    color: var(--texte-principal);
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
}
.message.en-edition .message-actions {
    opacity: 1;
}
.message-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.2s ease;
    flex-wrap: wrap;
}
.message:hover .message-actions {
    opacity: 1;
}
.btn-action {
    padding: 4px 8px;
    background: transparent;
    border: 1px solid var(--bordure);
    color: var(--texte-secondaire);
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    transition: var(--transition);
}
.btn-action:hover {
    background: var(--fond-tertiaire);
    color: var(--texte-principal);
    border-color: var(--texte-secondaire);
}
.suggestions-container {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 12px;
    padding: 12px;
    background: var(--fond-tertiaire);
    border-radius: var(--rayon);
    opacity: 0;
    animation: fadeIn 0.3s forwards;
}
.btn-suggestion {
    padding: 8px 16px;
    background: var(--fond-principal);
    border: 1px solid var(--bordure);
    border-radius: var(--rayon);
    cursor: pointer;
    font-size: 12px;
    transition: var(--transition);
    color: var(--texte-principal);
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: relative;
}
.btn-suggestion:hover {
    background: var(--accent-leger);
    border-color: var(--accent);
    transform: translateY(-1px);
}
.btn-suggestion[title]:hover::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--fond-principal);
    border: 1px solid var(--bordure);
    border-radius: var(--rayon);
    padding: 8px 12px;
    white-space: normal;
    max-width: 300px;
    font-size: 11px;
    box-shadow: var(--ombre-moyenne);
    z-index: 1000;
    margin-bottom: 8px;
}

/* Navigation des messages avec triangles autour de l'avatar */
.message-avatar.navigation-active {
    position: relative;
}

.navigation-triangles {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.triangle-nav {
    position: absolute;
    width: 0;
    height: 0;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.3s ease, transform 0.2s ease;
    pointer-events: auto;
    z-index: 30;
}

.triangle-nav:hover {
    opacity: 1;
    transform: scale(1.3);
}

.triangle-haut {
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 10px solid var(--accent);
    top: -15px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 30;
}

.triangle-bas {
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 10px solid var(--accent);
    bottom: -14px;
    left: 50%;
    transform: translateX(-50%);
}

.triangle-gauche {
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-right: 10px solid #2196F3;
    left: -14px;
    top: 50%;
    transform: translateY(-50%);
}

.triangle-droite {
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: 10px solid #2196F3;
    right: -14px;
    top: 50%;
    transform: translateY(-50%);
}

.triangle-nav.desactive {
    opacity: 0.15;
    cursor: not-allowed;
}

.triangle-nav.desactive:hover {
    transform: none;
    opacity: 0.15;
}

.triangle-haut.desactive {
    border-bottom-color: var(--texte-tertiaire);
}

.triangle-bas.desactive {
    border-top-color: var(--texte-tertiaire);
}

.triangle-gauche.desactive {
    border-right-color: var(--texte-tertiaire);
}

.triangle-droite.desactive {
    border-left-color: var(--texte-tertiaire);
}

.triangle-nav.actif {
    opacity: 1 !important;
}

.triangle-haut.actif {
    animation: couleurFlecheHaut 0.8s ease-in-out;
}

.triangle-bas.actif {
    animation: couleurFlecheBas 0.8s ease-in-out;
}

.triangle-gauche.actif {
    animation: couleurFlecheGauche 0.8s ease-in-out;
}

.triangle-droite.actif {
    animation: couleurFlecheDroite 0.8s ease-in-out;
}

@keyframes couleurFlecheHaut {
    0% { border-bottom-color: #f44336; }
    100% { border-bottom-color: var(--accent); }
}

@keyframes couleurFlecheBas {
    0% { border-top-color: #f44336; }
    100% { border-top-color: var(--accent); }
}

@keyframes couleurFlecheGauche {
    0% { border-right-color: #f44336; }
    100% { border-right-color: #2196F3; }
}

@keyframes couleurFlecheDroite {
    0% { border-left-color: #f44336; }
    100% { border-left-color: #2196F3; }
}

/* Styles pour l'animation de frappe */
.typing-indicator .message-texte {
    padding: 8px 0;
}

.typing-animation {
    display: flex;
    gap: 4px;
    align-items: center;
}

.typing-animation span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--texte-tertiaire);
    animation: typingDot 1.4s infinite ease-in-out;
}

.typing-animation span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-animation span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingDot {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(15px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==========================================================================
   ANIMATIONS D'INDICATEURS DE LIMITE
   ========================================================================== */

/* Animation de pulsation */
.message-avatar.animation-pulsation {
    animation: animationPulsation 1s ease-in-out;
}

@keyframes animationPulsation {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.7; }
}

/* Animation de rebond */
.message-avatar.animation-rebond.animation-limite-haut {
    animation: animationRebondHaut 1s ease-out;
}

.message-avatar.animation-rebond.animation-limite-bas {
    animation: animationRebondBas 1s ease-out;
}

@keyframes animationRebondHaut {
    0% { transform: translateY(0); }
    30% { transform: translateY(-8px); }
    60% { transform: translateY(-4px); }
    100% { transform: translateY(0); }
}

@keyframes animationRebondBas {
    0% { transform: translateY(0); }
    30% { transform: translateY(8px); }
    60% { transform: translateY(4px); }
    100% { transform: translateY(0); }
}

/* Animation de changement de couleur */
.message-avatar.animation-couleur {
    animation: animationCouleur 1s ease-in-out;
}

@keyframes animationCouleur {
    0%, 100% {
        background-color: var(--fond-tertiaire);
        box-shadow: none;
    }
    50% {
        background-color: var(--accent);
        box-shadow: 0 0 15px rgba(var(--accent-rgb), 0.5);
    }
}

/* Animation de barre de progression */
.message-avatar.animation-barre::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    height: 2px;
    background: var(--accent);
    border-radius: 1px;
    animation: animationBarre 1s ease-out;
}

.message-avatar.animation-barre.animation-limite-haut::after {
    top: -4px;
    bottom: auto;
    animation: animationBarreVide 1s ease-out;
}

@keyframes animationBarre {
    0% { width: 0%; }
    100% { width: 100%; }
}

@keyframes animationBarreVide {
    0% { width: 100%; }
    100% { width: 0%; }
}

/* Animation de vague */
.message-avatar.animation-vague {
    animation: animationVague 1s ease-in-out;
}

@keyframes animationVague {
    0%, 100% {
        border-radius: var(--rayon);
        transform: scale(1);
    }
    25% {
        border-radius: 50% 30% 50% 30%;
        transform: scale(1.05);
    }
    50% {
        border-radius: 30% 50% 30% 50%;
        transform: scale(1.1);
    }
    75% {
        border-radius: 50% 30% 50% 30%;
        transform: scale(1.05);
    }
}

/* Animation de vibration */
.message-avatar.animation-vibration {
    animation: animationVibration 1s ease-in-out;
}

@keyframes animationVibration {
    0%, 100% { transform: translateX(0); }
    10% { transform: translateX(-2px); }
    20% { transform: translateX(2px); }
    30% { transform: translateX(-2px); }
    40% { transform: translateX(2px); }
    50% { transform: translateX(-1px); }
    60% { transform: translateX(1px); }
    70% { transform: translateX(-1px); }
    80% { transform: translateX(1px); }
    90% { transform: translateX(0); }
}

/* Styles pour les messages humains non lus */
.message.message-non-lu {
    position: relative;
    padding-left: 8px;
}

.message.message-non-lu::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--accent);
    border-radius: 2px;
    animation: pulseNonLu 2s infinite ease-in-out;
}

.message.message-non-lu .message-contenu {
    background: var(--accent-bg, rgba(0, 123, 255, 0.05));
    padding: 8px;
    border-radius: 8px;
}

.message.message-non-lu .message-auteur {
    color: var(--accent);
    font-weight: 600;
}

@keyframes pulseNonLu {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* ==========================================================================
   RESPONSIVE MOBILE - Text wrap autour avatar
   ========================================================================== */
@media (max-width: 768px) {
    /* Message: block au lieu de flex pour permettre float */
    .message {
        display: block;
        margin: 0 auto 8px;
        padding: 4px 4px 4px 4px;
        gap: 0;
        max-width: 100%;
    }

    /* Avatar + zone flèches = bloc flottant pour text-wrap */
    .message-avatar {
        float: left;
        /* Padding pour espace des flèches potentielles */
        margin: 12px 12px 12px 12px;
        width: 28px;
        height: 28px;
        font-size: 12px;
        /* Zone cliquable inclut les flèches */
        position: relative;
    }

    /* Triangles de navigation plus petits sur mobile */
    .triangle-haut {
        border-left: 5px solid transparent;
        border-right: 5px solid transparent;
        border-bottom: 8px solid var(--accent);
        top: -10px;
    }

    .triangle-bas {
        border-left: 5px solid transparent;
        border-right: 5px solid transparent;
        border-top: 8px solid var(--accent);
        bottom: -10px;
    }

    .triangle-gauche {
        border-top: 5px solid transparent;
        border-bottom: 5px solid transparent;
        border-right: 8px solid var(--accent);
        left: -10px;
    }

    .triangle-droite {
        border-top: 5px solid transparent;
        border-bottom: 5px solid transparent;
        border-left: 8px solid var(--accent);
        right: -10px;
    }

    /* Contenu s'adapte */
    .message-contenu {
        overflow: visible;
    }

    /* Header message avec boutons sur même ligne */
    .message-header {
        margin-bottom: 2px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-wrap: nowrap;
    }

    .message-auteur {
        font-size: 12px;
    }

    .message-date {
        font-size: 10px;
    }

    /* Boutons d'action: icônes seules sur mobile */
    .message-actions .btn-action {
        padding: 4px 6px;
        font-size: 12px;
    }

    .message-actions .btn-action i {
        margin-right: 0;
    }

    /* Cacher le texte des boutons sur mobile */
    .message-actions .btn-action .btn-texte {
        display: none;
    }

    /* Afficher texte au survol/focus sur mobile */
    .message-actions .btn-action:hover .btn-texte,
    .message-actions .btn-action:focus .btn-texte {
        display: inline;
        margin-left: 4px;
    }

    /* Texte du message */
    .message-texte {
        font-size: 14px;
        line-height: 1.5;
    }

    .message-texte p {
        margin: 0 0 6px 0;
    }

    /* Blocs de code: pleine largeur, clear float */
    .message-texte pre,
    .message-texte .code-block,
    .code-block-wrapper {
        clear: both;
        width: 100%;
        margin-left: 0;
        margin-right: 0;
    }

    /* Clear float après le message */
    .message::after {
        content: '';
        display: table;
        clear: both;
    }
}

/* ==========================================================================
   BOUTONS D'ACTION - Position absolute, non-cliquables si cachés
   ========================================================================== */
.message-actions {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    gap: 4px;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s, visibility 0.2s;
    background: linear-gradient(90deg, transparent, var(--fond-principal) 30%);
    padding: 2px 0 2px 16px;
    border-radius: 4px;
    z-index: 20;
    flex-wrap: wrap;
}

.message:hover .message-actions {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Texte des boutons (visible par défaut sur desktop) */
.message-actions .btn-action .btn-texte {
    margin-left: 4px;
}

/* Affichage au clic sur avatar */
.message.actions-visibles .message-actions {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}