/* ==========================================================================
   Chatbot UI Modernisé - Trainizer
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Variables & Globales
   -------------------------------------------------------------------------- */
:root {
    /* Palette dégradé Logo Trainizer */
    --ai-gradient-start: #1b49b6;  /* Bleu profond */
    --ai-gradient-mid:   #25b8a5;  /* Turquoise / Cyan */
    --ai-gradient-end:   #eab308;  /* Jaune / Doré */
    
    --ai-gradient: linear-gradient(135deg, var(--ai-gradient-start), var(--ai-gradient-mid), var(--ai-gradient-end));

    /* Aurore du fond de conversation (mode IA) */
    --ai-glow-a-on: rgba(27, 73, 182, 0.08);
    --ai-glow-b-on: rgba(37, 184, 165, 0.07);
    --ai-glow-c-on: rgba(234, 179, 8, 0.05);
}

[data-theme="dark"] {
    --ai-glow-a-on: rgba(36, 76, 200, 0.35);
    --ai-glow-b-on: rgba(37, 184, 165, 0.11);
    --ai-glow-c-on: rgba(234, 179, 8, 0.06);
}

/* --------------------------------------------------------------------------
   2. Structure Principale & États
   -------------------------------------------------------------------------- */
#chatbot.main-card {
    position: fixed;
    right: 0;
    bottom: 50px;
    z-index: 1054;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: calc(100% - 170px);
    margin: 0;
    overflow: hidden;
    background: var(--coul-ternaire);
    color: var(--coul-foncee);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
    transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (min-width: 450px) {
    #chatbot.main-card {
        width: 380px;
        height: calc(100% - 90px) !important; /* Marge sous la navbar */
        max-height: 580px;
        margin: 16px !important;
        border-radius: 16px;
    }
}

[data-theme="dark"] #chatbot.main-card {
    background: #18191a !important;
    color: #e4e6eb !important;
    border-color: rgba(255, 255, 255, 0.08) !important;
}

/* Etat rétracté (Floating Action Button) */
#chatbot.collapsed {
    width: 52px !important;
    height: 52px !important;
    margin: 20px !important;
    overflow: hidden !important;
    border-radius: 26px !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

#chatbot.collapsed .main-title,
#chatbot.collapsed .chat-area,
#chatbot.collapsed .chatbot-attachment,
#chatbot.collapsed .ai-disclaimer,
#chatbot.collapsed .line,
#chatbot.collapsed .chatbot-suggestions,
#chatbot.collapsed .chatbot-composer,
#chatbot.collapsed .input-div {
    display: none !important;
}

/* --------------------------------------------------------------------------
   3. En-tête & Bouton de fermeture
   -------------------------------------------------------------------------- */
#chatbot .main-title {
    position: relative;
    display: flex;
    /* Sans cela, l'en-tête se comprimait à mesure que la conversation
       s'allongeait : titre et boutons finissaient écrasés l'un sur l'autre. */
    flex-shrink: 0;
    align-items: center;
    justify-content: space-between;
    height: 52px;
    padding: 0 52px 0 16px;
    background-color: var(--coul-principale);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    font-size: 1rem;
    font-weight: 600;
}

#chatbot .main-title span {
    color: #ffffff !important;
    letter-spacing: 0.3px;
}

/* Bouton principal (Positionné en haut à droite du header) */
#chatbot_toggle {
    position: absolute !important;
    top: 6px !important;
    right: 6px !important;
    z-index: 9999 !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: transparent;
    color: #ffffff !important;
    border: none;
    cursor: pointer;
    transform: none !important;
}

#chatbot_toggle i {
    font-size: 1.25rem;
    color: #ffffff !important;
}

/* Quand le chatbot est replié (FAB circulaire bas-droite) */
#chatbot.collapsed #chatbot_toggle {
    top: 0 !important;
    right: 0 !important;
    width: 52px !important;
    height: 52px !important;
    background: var(--coul-principale) !important;
    border-radius: 50% !important;
}

#chatbot.collapsed #chatbot_toggle i {
    color: var(--coul-ternaire) !important;
}

/* --------------------------------------------------------------------------
   4. Zone de Discussion & Messages
   -------------------------------------------------------------------------- */
#chatbot .chat-area {
    display: flex;
    flex-direction: column;
    /* min-height: 0 autorise le conteneur à devenir plus petit que son
       contenu, donc à défiler, au lieu de pousser sur ses voisins. */
    flex: 1 1 auto;
    min-height: 0;
    gap: 12px;
    padding: 16px;
    overflow-y: auto;
    background-color: var(--coul-ternaire);
    scroll-behavior: smooth;
}

[data-theme="dark"] #chatbot .chat-area {
    background-color: #0d1017 !important;
}

/* Mode IA activé : de la lumière qui monte du bas du panneau, comme une aurore,
   avec la teinte dorée qui affleure en haut. La voix de l'IA se distingue par
   l'ambiance, pas par un liseré. Hors mode IA, le fond reste uni. */
#chatbot:has(.input-message.ai-enabled) .chat-area {
    background-image:
        radial-gradient(120% 75% at 50% 115%, var(--ai-glow-a-on), transparent 70%),
        radial-gradient(70% 45% at 100% 0%, var(--ai-glow-b-on), transparent 70%),
        radial-gradient(60% 35% at 0% 0%, var(--ai-glow-c-on), transparent 70%);
}

#chatbot .chat-message-div {
    display: flex;
    width: 100%;
}

#chatbot .chat-message-sent {
    max-width: 82%;
    margin: 4px 0 4px auto;
    padding: 10px 14px;
    background-color: var(--coul-principale);
    color: #ffffff;
    border-radius: 16px 16px 4px 16px;
    font-size: 0.9rem;
    line-height: 1.4;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    animation: fadeIn 150ms ease-out;
}

#chatbot .chat-message-received {
    max-width: 85%;
    margin: 4px auto 4px 0;
    padding: 10px 14px;
    background-color: #f0f2f5;
    color: #212529;
    border-radius: 16px 16px 16px 4px;
    font-size: 0.9rem;
    line-height: 1.45;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
    animation: fadeIn 150ms ease-out;
}

[data-theme="dark"] #chatbot .chat-message-received {
    background-color: rgba(255, 255, 255, 0.07) !important;
    color: #e4e6eb !important;
}

/* --------------------------------------------------------------------------
   5. Mode IA, Animation Loading & Rendu Code
   -------------------------------------------------------------------------- */
/* Bulle de l'IA : verre dépoli posé sur l'aurore, sans liseré en dégradé. */
#chatbot .chat-message-received.ia {
    position: relative;
    background-color: rgba(255, 255, 255, 0.72) !important;
    border: 1px solid rgba(27, 73, 182, 0.14) !important;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}

[data-theme="dark"] #chatbot .chat-message-received.ia {
    background-color: rgba(255, 255, 255, 0.06) !important;
    border-color: rgba(255, 255, 255, 0.09) !important;
}

/* Loader IA (Typing) */
#chatbot .chat-message-received.ia.typing {
    display: flex;
    align-items: center;
    justify-content: center;
    width: fit-content;
    min-height: 42px;
    padding: 12px 18px;
}

#chatbot .ai-loading-dots {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

#chatbot .ai-loading-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    animation: aiBounce 1.4s infinite ease-in-out both;
}

#chatbot .ai-loading-dots span:nth-child(1) {
    background-color: var(--ai-gradient-start);
    animation-delay: -0.32s;
}

#chatbot .ai-loading-dots span:nth-child(2) {
    background-color: var(--ai-gradient-mid);
    animation-delay: -0.16s;
}

#chatbot .ai-loading-dots span:nth-child(3) {
    background-color: var(--ai-gradient-end);
    animation-delay: 0s;
}

@keyframes aiBounce {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    40% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* Code dans la réponse IA */
#chatbot .chat-message-received.ia pre {
    margin: 8px 0;
    padding: 10px;
    overflow-x: auto;
    background-color: #1e1e2e;
    color: #f8f8f2;
    border-radius: 8px;
    font-family: 'Fira Code', monospace;
    font-size: 0.8rem;
}

/* Liens des réponses : une adresse longue ne doit pas déborder de la bulle. */
#chatbot .chat-message-received.ia a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
    overflow-wrap: anywhere;
}

#chatbot .chat-message-received.ia a:hover {
    text-decoration-thickness: 2px;
}

#chatbot .chat-message-received.ia code {
    padding: 2px 5px;
    background-color: rgba(0, 0, 0, 0.06);
    border-radius: 4px;
}

/* Disclaimer IA */
#chatbot .ai-disclaimer {
    flex-shrink: 0;
    padding: 6px 12px;
    background-color: transparent;
    font-size: 0.73rem;
    line-height: 1.2;
    opacity: 0.75;
    user-select: none;
}

[data-theme="dark"] #chatbot .ai-disclaimer {
    flex-shrink: 0;
    color: #a0a6b0 !important;
}

/* --------------------------------------------------------------------------
   6. Formulaire, Saisie & Boutons
   -------------------------------------------------------------------------- */
#chatbot .input-div {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--coul-ternaire);
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] #chatbot .input-div {
    background: #0d1017;
    border-top-color: rgba(255, 255, 255, 0.06);
}

#chatbot .input-message {
    flex-grow: 1;
    height: 40px;
    padding: 0 14px;
    background: #f8f9fa;
    color: inherit;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 20px;
    font-size: 0.88rem;
    outline: none;
    transition: all 0.2s ease;
}

[data-theme="dark"] #chatbot .input-message {
    background: #242526;
    border-color: rgba(255, 255, 255, 0.15);
}

#chatbot .input-message:focus {
    border-color: var(--coul-principale);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

/* Input Focus Mode IA */
#chatbot .input-message.ai-enabled {
    border-color: rgba(37, 184, 165, 0.65);
    box-shadow: 0 0 0 3px rgba(37, 184, 165, 0.12);
}

[data-theme="dark"] #chatbot .input-message.ai-enabled {
    border-color: rgba(95, 211, 195, 0.55);
    box-shadow: 0 0 0 3px rgba(37, 184, 165, 0.14);
}

/* Boutons d'action */
#chatbot .input-send,
#chatbot .input-attach,
#chatbot .input-activate-ia {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    background: transparent;
    color: var(--coul-principale);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
}

#chatbot .input-send:hover,
#chatbot .input-attach:hover,
#chatbot .input-activate-ia:hover:not(:disabled) {
    background: rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] #chatbot .input-send:hover,
[data-theme="dark"] #chatbot .input-attach:hover,
[data-theme="dark"] #chatbot .input-activate-ia:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
}

#chatbot .input-activate-ia.active {
    background: rgba(37, 184, 165, 0.12);
    color: var(--ai-gradient-mid);
}

#chatbot .input-activate-ia:disabled {
    cursor: not-allowed;
    opacity: 0.35;
}

#chatbot .input-send svg,
#chatbot .input-attach svg,
#chatbot .input-activate-ia svg {
    margin: 0 !important;
}

#chatbot .input-attach[hidden] {
    display: none;
}

/* Image en attente d'envoi */
#chatbot .chatbot-attachment {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 8px;
    padding: 6px 12px 0;
}

#chatbot .chatbot-attachment[hidden] {
    display: none;
}

#chatbot .chatbot-attachment img {
    max-width: 96px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

#chatbot .chatbot-attachment button {
    width: 24px;
    height: 24px;
    padding: 0;
    background: rgba(0, 0, 0, 0.08);
    color: inherit;
    border: none;
    border-radius: 50%;
    cursor: pointer;
}

[data-theme="dark"] #chatbot .chatbot-attachment button {
    background: rgba(255, 255, 255, 0.15);
}

/* --------------------------------------------------------------------------
   7. Utilitaires & Animations
   -------------------------------------------------------------------------- */
@keyframes fadeIn {
    from {
        transform: translateY(4px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

#chatbot .chat-area::-webkit-scrollbar {
    width: 6px;
}

#chatbot .chat-area::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

[data-theme="dark"] #chatbot .chat-area::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
}
/* --------------------------------------------------------------------------
   8. Autocomplétion des commandes
   -------------------------------------------------------------------------- */
#chatbot .chatbot-composer {
    position: relative;
    flex-shrink: 0;
}

#chatbot .chatbot-suggestions {
    position: absolute;
    right: 0;
    bottom: 100%;
    left: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    max-height: 220px;
    overflow-y: auto;
    padding: 6px;
    background: var(--coul-ternaire);
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.18);
}

#chatbot .chatbot-suggestions[hidden] {
    display: none;
}

[data-theme="dark"] #chatbot .chatbot-suggestions {
    background: #18191a;
    border-top-color: rgba(255, 255, 255, 0.06);
}

#chatbot .chatbot-suggestion {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    gap: 2px;
    width: 100%;
    padding: 6px 10px;
    background: transparent;
    color: inherit;
    text-align: left;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

#chatbot .chatbot-suggestion code,
#chatbot .chatbot-suggestion strong {
    color: var(--coul-principale);
    font-size: 0.85rem;
    font-weight: 600;
    background: none;
    padding: 0;
}

/* Une valeur proposée est un libellé saisi en back-office : elle peut être
   longue, et ne doit pas élargir le panneau. */
#chatbot .chatbot-suggestion strong,
#chatbot .chatbot-suggestion small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#chatbot .chatbot-suggestion small {
    opacity: 0.7;
    font-size: 0.75rem;
}

#chatbot .chatbot-suggestion:hover,
#chatbot .chatbot-suggestion.is-active {
    background: rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] #chatbot .chatbot-suggestion:hover,
[data-theme="dark"] #chatbot .chatbot-suggestion.is-active {
    background: rgba(255, 255, 255, 0.1);
}

/* --------------------------------------------------------------------------
   9. Boutons ajoutés : effacer la conversation, arrêter la génération
   -------------------------------------------------------------------------- */
#chatbot .chatbot-clear {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: transparent;
    color: #ffffff;
    border: none;
    border-radius: 50%;
    opacity: 0.8;
    cursor: pointer;
    transition: background 0.2s ease, opacity 0.2s ease;
}

#chatbot .chatbot-clear:hover {
    background: rgba(255, 255, 255, 0.15);
    opacity: 1;
}

#chatbot .input-stop {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    background: transparent;
    color: #d33a2c;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s ease;
}

#chatbot .input-stop[hidden] {
    display: none;
}

#chatbot .input-stop:hover {
    background: rgba(211, 58, 44, 0.12);
}

/* --------------------------------------------------------------------------
   10. Liste de l'aide (/aide)
   -------------------------------------------------------------------------- */
#chatbot .chatbot-help {
    margin: 0;
    padding-left: 1.1rem;
}

#chatbot .chatbot-help li + li {
    margin-top: 6px;
}

#chatbot .chatbot-help p {
    margin: 0;
}
