﻿/* ============================================================
   Chatbot Sigmund — Assistant contextuel intégré à main.aspx
   Z-index ≥ 9000 : passe devant les RadWindows Telerik (5000-7000)
   Aucune dépendance externe.
   ============================================================ */

.chatbot-container {
    position: fixed;
    top: 25vh;       /* 1/4 écran depuis le haut — évite la superposition avec Zoping en bas */
    right: 20px;
    width: 80px;
    height: 80px;
    transition: all 0.3s ease;
    cursor: pointer;
    z-index: 9000; /* Devant les RadWindows Telerik */
    font-family: 'Poppins', 'Segoe UI', sans-serif;
}

.chatbot-container.visible {
    right: 20px;
}

/* Pendant le drag : pas de transition (suivi instantané du curseur) */
.chatbot-container.dragging {
    transition: none;
}

.chatbot-container.expanded {
    width: 420px;
    height: 600px;
    cursor: default;
    right: 20px;
}

.chatbot-container.mini {
    width: 80px;
    height: 80px;
    right: 20px;
}

/* --- Icône flottante (avatar) --- */
.chatbot-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
    border: 2px solid rgb(243, 156, 18);
    position: relative;
    transition: all 0.3s ease;
}

.chatbot-icon:hover {
    transform: scale(1.06);
}

.chatbot-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* --- Bulle d'accroche (à gauche de l'icône) --- */

/* DÉMO (demande Laurent 07/09) : les 3 boutons de mode (Discussion /
   Guide-moi / Fais pour moi) n'existent qu'en FORMATION. En démo,
   l'interface est verrouillée et l'agent pilote en auto. */
.chatbot-container.chatbot-demo .chatbot-mode-switch {
    display: none !important;
}

.chatbot-bubble {
    display: none;
    position: absolute;
    top: 50%;
    right: calc(100% + 12px);
    transform: translateY(-50%);
    background: rgb(221 224 227);
    padding: 10px 15px;
    border-radius: 18px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    font-size: 14px;
    white-space: normal;
    z-index: 9001;
    color: black;
    width: 250px;
    padding-right: 25px;
    cursor: pointer;
    /* Demande Laurent 07/09 : la bulle repliée montre TOUS les textes du
       chat ouvert — élargie et scrollable si la conversation est longue. */
    max-width: 340px;
    max-height: 60vh;
    overflow-y: auto;
}

/* Messages concaténés dans la bulle repliée (collapseForGuidance) */
.chatbot-bubble .bubble-msg {
    padding: 4px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    font-size: 13px;
    line-height: 1.35;
}
.chatbot-bubble .bubble-msg:last-child {
    border-bottom: none;
}
.chatbot-bubble .bubble-msg-current {
    font-weight: 600;
    color: #1a3a4a;
}

.chatbot-bubble::before {
    content: '';
    position: absolute;
    right: -10px;
    top: 50%;
    transform: translateY(-50%);
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-left: 10px solid rgb(221 224 227);
}

.chatbot-container.show-bubble .chatbot-bubble {
    display: block;
}

.bubble-close-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    cursor: pointer;
    background: transparent;
    border: none;
    font-size: 16px;
    color: #333;
    z-index: 9002;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.bubble-close-btn:hover {
    color: #666;
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 50%;
}

/* --- Contenu déplié --- */
.chatbot-content {
    display: none;
    flex-direction: column;
    height: 100%;
    width: 100%;
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}

.chatbot-container.expanded .chatbot-content {
    display: flex;
}

.chatbot-container.expanded .chatbot-icon,
.chatbot-container.expanded .chatbot-bubble {
    display: none;
}

/* --- En-tête = poignée de déplacement --- */
.chatbot-header {
    background: linear-gradient(135deg, #1565C0, #0D47A1);
    color: #fff;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: grab;
    user-select: none; /* Empêche la sélection de texte pendant le drag */
    -webkit-user-select: none;
    touch-action: none;
}

.chatbot-header:active {
    cursor: grabbing;
}

.chatbot-header h3 {
    font-weight: 500;
    font-size: 1.1rem;
    margin: 0;
    pointer-events: none; /* le drag passe à travers le titre */
}

.chatbot-header .close-btn {
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    color: #fff;
    background: transparent;
    border: none;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chatbot-header .close-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
}

.chatbot-header .newchat-btn {
    cursor: pointer;
    color: #fff;
    background: transparent;
    border: none;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-right: 6px;
}

.chatbot-header .newchat-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
}

/* --- Sélecteur de mode (Discussion / Guide-moi / Fais pour moi) --- */
.chatbot-mode-switch {
    display: flex;
    gap: 4px;
    padding: 8px 12px 0;
    background: #fff;
}

.chatbot-mode-switch .mode-option {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    border: 1px solid #d0d7de;
    border-radius: 14px;
    padding: 4px 6px;
    font-size: 0.72rem;
    color: #555;
    transition: all 0.2s ease;
    user-select: none;
    white-space: nowrap;
}

.chatbot-mode-switch .mode-option input {
    accent-color: #1565C0;
    margin: 0;
    cursor: pointer;
}

.chatbot-mode-switch .mode-option:has(input:checked) {
    background: #E3F2FD;
    border-color: #1565C0;
    color: #0D47A1;
    font-weight: 500;
}

.chatbot-mode-switch .mode-option:hover {
    border-color: #1565C0;
}

/* --- Zone des messages --- */
.chatbox {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px;
    background: white;
}

.chat-message {
    margin-bottom: 15px;
    display: flex;
    align-items: flex-start;
}

.chat-message.incoming {
    justify-content: flex-start;
}

.chat-message.outgoing {
    justify-content: flex-end;
}

.chat-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    margin-right: 10px;
    object-fit: cover;
    flex-shrink: 0;
}

.chat-bubble {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.chat-message.incoming .chat-bubble {
    background: #F1F0F0;
    color: #333;
}

.chat-message.outgoing .chat-bubble {
    background: #E3F2FD;
    color: #1565C0;
}

.chat-bubble a {
    color: #1565C0;
    text-decoration: underline;
}

/* --- Zone de saisie --- */
.chat-input {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    background: white;
    border-top: 1px solid #e0e0e0;
    gap: 6px;
    flex-wrap: nowrap;
    min-width: 0;
}

.chat-input input {
    flex: 1 1 auto;
    min-width: 40px;
    border: none;
    outline: none;
    padding: 8px 12px;
    font-size: 0.9rem;
    border-radius: 20px;
    background: #f5f5f5;
    font-family: inherit;
}

.chat-input button {
    background: #1976D2;
    color: #fff;
    border: none;
    padding: 0;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.3s ease;
    height: 38px;
    width: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    flex-shrink: 0;
}

/* Bouton d'envoi : le RadFormDecorator Telerik (skin Default) enveloppe le
   bouton dans un <a class="rfdSkinnedButton"> et applique un sprite d'image
   carré (ButtonSprites.gif) qui écrase le rond bleu. On force le style rond
   avec !important (même technique que .eleven-btn) et on neutralise le
   wrapper. */
#chatInputContainer .rfdSkinnedButton {
    background-image: none !important;
    background: none !important;
    padding: 0 !important;
    border: none !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    height: 38px;
    width: 38px;
}

#sendChatBtn {
    background: #1976D2 !important;
    background-image: none !important;
    color: #fff !important;
    border: none !important;
    padding: 0 !important;
    border-radius: 50% !important;
    height: 38px !important;
    width: 38px !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    line-height: 1;
    flex-shrink: 0;
}

#sendChatBtn:hover {
    background: #1565C0 !important;
}

/* --- Boutons vocaux (micro + haut-parleur) --- */
.eleven-btn {
    background: #546e7a !important;
    color: #fff !important;
    border: none;
    padding: 0;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.3s ease, opacity 0.3s ease;
    height: 36px;
    width: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
    opacity: 1;
    flex-shrink: 0;
}

.eleven-btn:hover:not(:disabled) {
    background: #37474f !important;
}

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

.eleven-btn.recording {
    background: #c62828 !important;
    animation: chatbot-pulse-red 1s infinite;
    box-shadow: 0 0 0 3px #c62828, 0 0 15px rgba(198, 40, 40, 0.5);
    transform: scale(1.05);
}

@keyframes chatbot-pulse-red {
    0%, 100% { box-shadow: 0 0 0 0 rgba(198, 40, 40, 0.5); }
    50% { box-shadow: 0 0 0 8px rgba(198, 40, 40, 0); }
}

.eleven-btn.playing {
    background: #1565C0 !important;
    animation: chatbot-pulse-blue 0.8s infinite;
}

@keyframes chatbot-pulse-blue {
    0%, 100% { box-shadow: 0 0 0 0 rgba(21, 101, 192, 0.5); transform: scale(1); }
    50% { box-shadow: 0 0 0 10px rgba(21, 101, 192, 0); transform: scale(1.15); }
}

/* Speaker OFF */
.eleven-btn:not(.active) {
    background: #546e7a !important;
}

/* Speaker ON (toggle actif) */
.eleven-btn.active {
    background: #1565C0 !important;
    box-shadow: 0 0 0 3px #1565C0, 0 0 12px rgba(21, 101, 192, 0.5);
    transform: scale(1.05);
}

.eleven-btn.active.playing {
    animation: chatbot-pulse-blue 0.8s infinite;
    box-shadow: 0 0 0 3px #1565C0, 0 0 20px rgba(21, 101, 192, 0.6);
}

/* --- Visage animé (SigmundFace) --- */
.chatbot-face {
    display: block;
    width: 100%;
    height: 100%;
}

.chat-avatar-face {
    display: block;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    margin-right: 10px;
    flex-shrink: 0;
    overflow: hidden;
}

.chatbot-icon .chatbot-face {
    border-radius: 50%;
}

/* Tête : léger balancement naturel (vie) */
.face-head {
    transform-box: fill-box;
    transform-origin: 50% 85%;
    animation: chatbot-face-sway 7s ease-in-out infinite;
}

@keyframes chatbot-face-sway {
    0%, 100% { transform: rotate(-1.1deg); }
    50% { transform: rotate(1.1deg); }
}

/* Yeux : clignement + écoute */
.face-eye {
    transform-box: fill-box;
    transform-origin: center;
    transition: transform 70ms ease-out;
}

.chatbot-face.is-blinking .face-eye {
    transform: scaleY(0.06);
}

.chatbot-face.is-listening .face-eye {
    transform: scaleY(1.14);
}

/* Sourcils : levés en écoute, froncés en réflexion */
.face-brow {
    transform-box: fill-box;
    transform-origin: center;
    transition: transform 160ms ease;
}

.chatbot-face.is-listening .face-brow {
    transform: translateY(-2.6px);
}

.chatbot-face.is-thinking .face-brow {
    transform: translateY(1.2px) rotate(-3deg);
}

.chatbot-face.is-thinking .face-brow:last-of-type {
    transform: translateY(1.2px) rotate(3deg);
}

/* Réflexion : balancement plus marqué */
.chatbot-face.is-thinking .face-head {
    animation: chatbot-face-think 3.2s ease-in-out infinite;
}

@keyframes chatbot-face-think {
    0%, 100% { transform: rotate(-2.4deg) translateY(0.6px); }
    50% { transform: rotate(2deg) translateY(-0.6px); }
}

@media (prefers-reduced-motion: reduce) {
    .face-head,
    .chatbot-face.is-thinking .face-head {
        animation: none;
    }
}

/* --- Photo réaliste (Luc) : micro-animations de vie --- */

/* Icône : respiration subtile (l'avatar semble vivant) */
.chatbot-icon img {
    animation: chatbot-avatar-breathe 5s ease-in-out infinite;
}

@keyframes chatbot-avatar-breathe {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.045); }
}

/* Pendant que l'assistant parle (TTS) : anneau orange pulsant
   sur les avatars photo des messages + l'icône */
.chatbot-container.bot-speaking .chat-avatar,
.chatbot-container.bot-speaking .chatbot-icon {
    animation: chatbot-avatar-speak 1.1s ease-in-out infinite;
}

@keyframes chatbot-avatar-speak {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(243, 156, 18, 0.55);
    }
    50% {
        box-shadow: 0 0 0 7px rgba(243, 156, 18, 0);
    }
}

@media (prefers-reduced-motion: reduce) {
    .chatbot-icon img,
    .chatbot-container.bot-speaking .chat-avatar,
    .chatbot-container.bot-speaking .chatbot-icon {
        animation: none;
    }
}

/* --- Indicateur de réflexion dans la bulle (attente agent) --- */
.chatbot-thinking span {
    animation: chatbot-thinking-dots 1.4s infinite;
    opacity: 0;
    font-weight: bold;
}

.chatbot-thinking span:nth-of-type(1) { animation-delay: 0.2s; }
.chatbot-thinking span:nth-of-type(2) { animation-delay: 0.4s; }
.chatbot-thinking span:nth-of-type(3) { animation-delay: 0.6s; }

@keyframes chatbot-thinking-dots {
    0% { opacity: 0; }
    40% { opacity: 1; }
    80%, 100% { opacity: 0; }
}

/* --- Indicateur de frappe --- */
.typing-indicator {
    display: flex;
    align-items: center;
    margin-top: 5px;
}

.typing-indicator span {
    height: 8px;
    width: 8px;
    float: left;
    margin: 0 1px;
    background-color: #9E9EA1;
    display: block;
    border-radius: 50%;
    opacity: 0.4;
}

.typing-indicator span:nth-of-type(1) {
    animation: chatbot-blink 1s infinite 0.3333s;
}

.typing-indicator span:nth-of-type(2) {
    animation: chatbot-blink 1s infinite 0.6666s;
}

.typing-indicator span:nth-of-type(3) {
    animation: chatbot-blink 1s infinite 0.9999s;
}

@keyframes chatbot-blink {
    50% {
        opacity: 1;
    }
}

/* --- Responsive mobile --- */
@media (max-width: 480px) {
    .chatbot-container.expanded {
        width: 96%;
        height: 85%;
        right: 2%;
        top: 8%;
        border-radius: 12px;
    }

    .chatbot-header {
        padding: 8px 10px;
    }

    .chatbox {
        padding: 10px;
    }

    .chat-input {
        padding: 6px 8px;
        gap: 4px;
    }

    .chat-input input {
        font-size: 0.85rem;
        padding: 6px 10px;
        min-width: 30px;
    }

    .chat-input button {
        height: 34px;
        width: 34px;
        font-size: 13px;
    }

    .eleven-btn {
        height: 32px;
        width: 32px;
        font-size: 12px;
    }

    .chatbot-bubble {
        width: 180px;
        font-size: 12px;
    }

    .chat-message .chat-bubble {
        max-width: 90%;
        font-size: 0.85rem;
        padding: 8px 12px;
    }
}

/* Petits écrans très étroits (<360px) */
@media (max-width: 360px) {
    .chat-input button {
        height: 30px;
        width: 30px;
        font-size: 11px;
    }

    .eleven-btn {
        height: 28px;
        width: 28px;
        font-size: 10px;
    }
}
