/* Chatbot ELYD - Style personnalisé */
#elyd-chatbot {
    position: fixed;
    bottom: 20px;
    right: 90px; /* Déplacé vers la gauche pour éviter le chevauchement avec back-to-top */
    z-index: 1000;
    font-family: 'Inter', system-ui, sans-serif;
}

/* Bouton du chatbot */
.chat-button {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #141414 0%, #1F1F25 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(20, 20, 20, 0.3);
    transition: all 0.3s ease;
    position: relative;
    color: #fff;
}

.chat-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 35px rgba(20, 20, 20, 0.4);
    background: linear-gradient(135deg, #1F1F25 0%, #141414 100%);
}

.chat-notification {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #faff69;
    color: #141414;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Fenêtre du chatbot */
.chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 390px;
    height: 590px;
    max-width: calc(100vw - 32px);
    max-height: calc(100dvh - 120px);
    background: #0d0d0d;
    border-radius: 16px;
    box-shadow: 0 22px 70px rgba(0, 0, 0, 0.42);
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #292929;
}

.chat-window.open {
    display: flex;
    animation: slideUp 0.3s ease-out;
}

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

/* Header du chat */
.chat-header {
    background: #141414;
    color: white;
    min-height: 58px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #292929;
}

.chat-header-content {
    display: flex;
    align-items: center;
    gap: 0;
    min-width: 0;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 12px;
    flex-shrink: 0;
}

.chat-avatar {
    display: none;
}

.chat-info {
    min-width: 0;
}

.chat-info h4 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.15;
    color: #fff !important;
}

.chat-status {
    display: block;
    margin-top: 4px;
    font-size: 11px;
    line-height: 1;
    color: #faff69;
    font-weight: 500;
}

.chat-fullscreen-toggle {
    background: rgba(250, 255, 105, 0.08);
    border: 1px solid rgba(250, 255, 105, 0.45);
    color: #faff69;
    cursor: pointer;
    padding: 7px;
    border-radius: 10px;
    transition: all 0.3s ease;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-fullscreen-toggle:hover,
.chat-fullscreen-toggle[aria-pressed="true"] {
    background: #faff69;
    border-color: #faff69;
    color: #141414;
    transform: translateY(-1px);
}

.chat-fullscreen-toggle:focus-visible {
    outline: 2px solid #faff69;
    outline-offset: 3px;
}

.chat-fullscreen-icon {
    width: 17px;
    height: 17px;
    display: block;
}

.chat-fullscreen-icon-collapse {
    display: none;
}

.chat-fullscreen-toggle[aria-pressed="true"] .chat-fullscreen-icon-expand {
    display: none;
}

.chat-fullscreen-toggle[aria-pressed="true"] .chat-fullscreen-icon-collapse {
    display: block;
}

.chat-close {
    background: #1d1d1d;
    border: 1px solid #292929;
    color: #f2f2f2;
    cursor: pointer;
    padding: 7px;
    border-radius: 50%;
    transition: all 0.3s ease;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-close:hover {
    background: #242424;
    border-color: rgba(250, 255, 105, 0.45);
    color: #faff69;
    transform: scale(1.1);
}

.chat-close svg {
    width: 17px;
    height: 17px;
}

html.elyd-chatbot-fullscreen-active,
body.elyd-chatbot-fullscreen-active {
    overflow: hidden !important;
}

body.elyd-chatbot-fullscreen-active #elyd-chatbot {
    inset: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: var(--elyd-chatbot-visual-height, 100dvh);
    z-index: 2147483000;
    pointer-events: none;
}

body.elyd-chatbot-fullscreen-active #chat-button {
    display: none;
}

.chat-window.chat-fullscreen {
    position: fixed;
    inset: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: var(--elyd-chatbot-visual-height, 100dvh);
    max-width: none;
    max-height: none;
    border: 0;
    border-radius: 0;
    background: #0d0d0d;
    z-index: 2147483001;
    box-shadow: none;
    pointer-events: auto;
    transform: translateY(var(--elyd-chatbot-visual-offset-top, 0px));
}

.chat-window.chat-fullscreen .chat-header {
    min-height: 72px;
    padding: 16px clamp(20px, 5vw, 72px);
    border-bottom: 1px solid rgba(250, 255, 105, 0.14);
    flex-shrink: 0;
}

.chat-window.chat-fullscreen .chat-info h4 {
    font-size: 18px;
}

.chat-window.chat-fullscreen .chat-status {
    font-size: 12px;
}

.chat-window.chat-fullscreen .chat-messages {
    align-items: center;
    min-height: 0;
    padding: clamp(22px, 4vw, 44px) clamp(18px, 8vw, 160px);
    background: #0d0d0d;
}

.chat-window.chat-fullscreen .message {
    width: 100%;
    max-width: min(860px, 100%);
}

.chat-window.chat-fullscreen .chat-input-container {
    padding: 14px clamp(20px, 5vw, 72px) 18px;
    background: #0d0d0d;
    flex-shrink: 0;
}

.chat-window.chat-fullscreen .message-content {
    max-width: min(680px, 100%);
}

.chat-window.chat-fullscreen .bot-message .message-content {
    margin-right: auto;
}

.chat-window.chat-fullscreen .user-message .message-content {
    margin-left: auto;
    max-width: min(680px, 88%);
}

.chat-window.chat-fullscreen .message-bubble {
    padding: 15px 18px;
    font-size: 15px;
}

.chat-window.chat-fullscreen .bot-message .message-bubble.has-speech-control {
    padding-right: 54px;
}

.chat-window.chat-fullscreen .chat-input-wrapper {
    width: 100%;
    max-width: 900px;
    margin-right: auto;
    margin-left: auto;
}

.chat-window.chat-fullscreen .chat-attachments-preview,
.chat-window.chat-fullscreen .chat-upload-error,
.chat-window.chat-fullscreen .typing-indicator {
    width: 100%;
    max-width: 900px;
    margin-right: auto;
    margin-left: auto;
}

/* Messages */
.chat-messages {
    flex: 1;
    padding: 16px 14px;
    overflow-y: auto;
    overflow-x: hidden; /* Empêcher le scroll horizontal */
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #0d0d0d;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(250, 255, 105, 0.28);
    border-radius: 2px;
}

.message {
    display: flex;
    gap: 0;
    width: 100%;
    max-width: 100%;
    animation: messageSlide 0.3s ease-out;
    word-wrap: break-word; /* Forcer le retour à la ligne */
}

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

.user-message {
    align-self: flex-end;
    justify-content: flex-end;
}

.bot-message {
    align-self: flex-start;
    justify-content: flex-start;
}

.message-avatar {
    display: none;
}

.bot-message .message-avatar {
    background: linear-gradient(135deg, #141414 0%, #1F1F25 100%);
    color: #faff69;
}

.user-message .message-avatar {
    background: #faff69;
    color: #141414;
}

.message-content {
    flex: 1;
    min-width: 0; /* Important pour éviter le débordement */
}

.message-bubble {
    position: relative;
    background: #141414;
    padding: 12px 16px;
    border: 1px solid #292929;
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.5;
    color: #f2f2f2 !important;
    box-shadow: none;
    word-wrap: break-word; /* Forcer le retour à la ligne */
    overflow-wrap: break-word; /* Support moderne */
    hyphens: auto; /* Césure automatique */
    max-width: 100%; /* Empêcher le débordement */
}

.message-bubble p {
    margin: 0;
    color: inherit !important;
    font: inherit;
    line-height: inherit;
}

.message-bubble p.is-typing-text {
    white-space: pre-wrap;
}

.bot-message .message-bubble {
    background: #141414;
    color: #f2f2f2 !important;
}

.bot-message .message-bubble.has-speech-control {
    padding-right: 52px;
}

.user-message .message-bubble {
    background: #faff69;
    border-color: #faff69;
    color: #141414 !important;
}

.message-content {
    display: flex;
    flex: 0 1 auto;
    flex-direction: column;
    align-items: flex-start;
    min-width: 0;
    max-width: 100%;
}

.bot-message .message-content {
    width: 100%;
}

.user-message .message-content {
    align-items: flex-end;
    max-width: 92%;
}

/* Styles pour les liens dans les messages */
.message-bubble p a {
    color: inherit;
    text-decoration: underline;
    word-break: break-all; /* Forcer la coupure des liens longs */
}

.bot-message .message-bubble p a {
    color: #faff69;
}

.user-message .message-bubble p a {
    color: #141414;
}

.message-attachments {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
    gap: 8px;
    margin-bottom: 8px;
}

.message-attachments img {
    width: 100%;
    max-width: 180px;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: 12px;
    border: 1px solid #292929;
    background: #141414;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.message-time {
    display: block;
    margin-top: 7px;
    font-size: 11px;
    color: #a0a0a0 !important;
    padding: 0 4px;
    line-height: 1.2;
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    margin-top: 7px;
    padding: 0 4px;
}

.message-meta .message-time {
    margin-top: 0;
    padding: 0;
}

.message-speech-toggle {
    position: absolute;
    right: 10px;
    bottom: 10px;
    width: 28px;
    height: 28px;
    border: 1px solid rgba(250, 255, 105, 0.28);
    border-radius: 999px;
    background: #0d0d0d;
    color: #faff69;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.message-speech-toggle svg,
.message-speech-toggle .speech-spinner {
    width: 16px;
    height: 16px;
    display: block;
}

.speech-spinner {
    border: 2px solid rgba(250, 255, 105, 0.24);
    border-top-color: currentColor;
    border-radius: 50%;
}

.message-speech-toggle:hover,
.message-speech-toggle:focus-visible {
    background: rgba(250, 255, 105, 0.1);
    border-color: rgba(250, 255, 105, 0.6);
    outline: none;
    transform: translateY(-1px);
}

.message-speech-toggle.loading {
    cursor: wait;
    opacity: 0.78;
}

.message-speech-toggle.loading .speech-spinner {
    animation: speechSpin 0.75s linear infinite;
}

.message-speech-toggle.speaking {
    background: #faff69;
    border-color: #faff69;
    color: #141414;
}

.message-speech-toggle.paused {
    background: rgba(250, 255, 105, 0.1);
    border-color: rgba(250, 255, 105, 0.5);
    color: #faff69;
}

.message-speech-toggle.error {
    border-color: rgba(255, 180, 180, 0.65);
    color: #ffb4b4;
}

@keyframes speechSpin {
    to {
        transform: rotate(360deg);
    }
}

/* Zone de saisie */
.chat-input-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 14px 12px;
    background: #0d0d0d;
    border-top: 1px solid #292929;
}

.chat-input-wrapper {
    display: flex;
    gap: 7px;
    align-items: flex-end;
}

.chat-ai-disclaimer {
    display: flex;
    justify-content: center;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 3px;
    width: 100%;
    margin: 0;
    color: rgba(160, 160, 160, 0.78);
    font-size: 10px;
    line-height: 1.2;
    text-align: center;
    text-wrap: balance;
}

.chat-privacy-link {
    color: rgba(250, 255, 105, 0.82);
    font: inherit;
    font-size: 10px;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.chat-privacy-link:hover,
.chat-privacy-link:focus-visible {
    color: #faff69;
}

.chat-text-input-shell {
    position: relative;
    display: flex;
    flex: 1;
    min-width: 0;
}

.chat-file-input {
    display: none;
}

.chat-attachments-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.chat-attachments-preview[hidden],
.chat-upload-error[hidden] {
    display: none;
}

.chat-attachment-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 100%;
    padding: 6px 8px;
    background: #141414;
    border: 1px solid #292929;
    border-radius: 10px;
    color: #f2f2f2;
    font-size: 12px;
}

.chat-attachment-chip img {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
}

.chat-attachment-chip span {
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-attachment-chip button {
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1d1d1d;
    color: #faff69;
    cursor: pointer;
    flex-shrink: 0;
}

.chat-upload-error {
    margin-bottom: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(215, 70, 70, 0.12);
    color: #ffb4b4;
    font-size: 12px;
    line-height: 1.4;
}

#chat-input {
    flex: 1;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    border: 1px solid #292929;
    border-radius: 10px;
    min-height: 42px;
    max-height: 118px;
    padding: 10px 38px 10px 14px;
    padding-right: 38px;
    font-size: 14px;
    line-height: 1.45;
    font-family: 'Inter', system-ui, sans-serif;
    transition: all 0.3s ease;
    background: #141414;
    color: #f2f2f2;
    resize: none;
    overflow-y: hidden;
    scrollbar-width: none; /* Firefox - Masquer completement la scrollbar */
    -ms-overflow-style: none; /* IE/Edge - Masquer completement la scrollbar */
}



/* Masquer completement la scrollbar pour Chrome, Safari, Edge */
#chat-input::-webkit-scrollbar {
    display: none;
}

#chat-input:focus {
    outline: none;
    border-color: #faff69;
    background: #171717;
}

#chat-input::placeholder {
    color: rgba(160, 160, 160, 0.58);
}

.chat-voice-toggle {
    position: absolute;
    bottom: 5px;
    right: 6px;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #a0a0a0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.chat-voice-toggle:hover {
    background: rgba(250, 255, 105, 0.1);
    color: #faff69;
}

.chat-voice-toggle:focus-visible {
    outline: 2px solid #faff69;
    outline-offset: 2px;
}

.chat-voice-toggle.listening {
    background: #faff69;
    color: #141414;
    animation: voicePulse 1.2s infinite;
}

.chat-voice-toggle.unsupported {
    display: none;
}

@keyframes voicePulse {
    0% {
        box-shadow: 0 0 0 0 rgba(250, 255, 105, 0.36);
    }
    100% {
        box-shadow: 0 0 0 10px rgba(250, 255, 105, 0);
    }
}

.chat-attach {
    background: #141414;
    border: 1px solid #292929;
    border-radius: 50%;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    color: #faff69;
    flex-shrink: 0;
}

.chat-attach:hover {
    background: #1d1d1d;
    border-color: rgba(250, 255, 105, 0.45);
    transform: scale(1.05);
}

.chat-attach:disabled {
    color: #74787C;
    cursor: not-allowed;
    transform: none;
}

.chat-send {
    background: #faff69;
    border: 1px solid #faff69;
    border-radius: 50%;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    color: #141414;
}

.chat-send:hover {
    background: #f4f692;
    transform: scale(1.05);
}

.chat-send:disabled {
    background: #292929;
    border-color: #292929;
    color: #74787C;
    cursor: not-allowed;
    transform: none;
}

/* Indicateur de frappe */
.typing-indicator {
    display: flex;
    align-self: flex-start;
    align-items: center;
    gap: 7px;
    width: fit-content;
    max-width: 100%;
    padding: 9px 12px;
    border: 1px solid #292929;
    border-radius: 10px;
    background: #141414;
    color: #a0a0a0;
    box-shadow: none;
}

.typing-indicator[hidden] {
    display: none;
}

.typing-label {
    font-size: 12px;
    line-height: 1.2;
    color: #a0a0a0;
}

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

.typing-dots span {
    width: 6px;
    height: 6px;
    background: #faff69;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

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

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

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Responsive */
@media (max-width: 480px) {
    #elyd-chatbot {
        right: 15px; /* Même position horizontale que le bouton back-to-top */
        bottom: 15px; /* Chatbot en bas */
    }
    
    .chat-window {
        width: calc(100vw - 30px); /* Largeur adaptée avec plus de marge */
        height: min(72vh, 620px); /* Hauteur plus confortable sans couvrir tout l'ecran */
        right: 0;
        bottom: 85px; /* Position ajustée */
        border-radius: 12px;
        max-width: none;
        max-height: 620px;
        margin-right: 15px; /* Marge pour éviter de toucher le bord */
        overflow: hidden; /* Empêcher tout débordement */
    }
    
    .chat-header {
        padding: 12px 15px; /* Padding réduit */
    }
    
    .chat-header-content {
        gap: 10px;
    }
    
    .chat-info h4 {
        font-size: 14px;
    }
    
    .chat-close {
        width: 32px;
        height: 32px;
        padding: 6px;
    }
    
    .chat-close svg {
        width: 16px;
        height: 16px;
    }
    
    .chat-messages {
        padding: 12px; /* Padding réduit */
        flex: 1;
        min-height: 0; /* Important pour le scroll */
        overflow-x: hidden; /* Forcer pas de scroll horizontal */
    }
    
    .chat-input-container {
        padding: 12px 15px 18px; /* Padding réduit */
        flex-shrink: 0; /* Empêche la compression */
    }
    
    /* Messages spécifiques mobile */
    .message {
        max-width: 90%; /* Plus de place sur mobile */
    }
    
    .message-bubble {
        font-size: 13px; /* Texte légèrement plus petit */
        padding: 10px 12px; /* Padding réduit */
        word-break: break-word; /* Forcer la coupure des mots longs */
        overflow-wrap: anywhere; /* Coupure agressive si nécessaire */
    }
    
    .bot-message .message-bubble.has-speech-control {
        padding-right: 48px;
    }

    /* Liens sur mobile */
    .message-bubble p a {
        word-break: break-all; /* Forcer la coupure des liens */
        display: inline-block;
        max-width: 100%;
    }
    
    /* Zone de saisie mobile */
    #chat-input {
        font-size: 14px; /* Taille adaptée mobile */
        padding: 10px 48px 10px 14px;
    }
    
    /* Bouton back-to-top au-dessus du chatbot sur mobile */
    .progress-wrap {
        right: 15px !important;
        bottom: 85px !important; /* Au-dessus du chatbot */
        z-index: 10001 !important; /* Au-dessus du chatbot */
    }
}

/* Ajustement pour les écrans moyens */
@media (max-width: 768px) and (min-width: 481px) {
    #elyd-chatbot {
        right: 20px; /* Moins d'espace sur tablette */
        bottom: 20px;
    }
    
    .chat-window {
        width: 380px;
        height: 560px;
        max-width: calc(100vw - 40px);
        max-height: calc(100dvh - 120px);
    }
}

/* Animations d'entrée */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.new {
    animation: fadeInUp 0.4s ease-out;
}

@media (max-width: 480px) {
    .chat-window {
        width: calc(100vw - 24px);
        height: min(72vh, 620px);
        max-width: none;
        max-height: 620px;
        margin-right: 0;
    }

    .chat-window.open {
        position: fixed;
        inset: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        height: var(--elyd-chatbot-visual-height, 100dvh);
        max-width: none;
        max-height: none;
        border-radius: 0;
        margin-right: 0;
        transform: translateY(var(--elyd-chatbot-visual-offset-top, 0px));
    }

    .chat-header {
        min-height: 52px;
        padding: 9px 12px;
    }

    .chat-header-content {
        gap: 0;
    }

    .chat-messages {
        padding: 12px 10px;
    }

    .chat-input-container {
        padding: 10px 12px 16px;
    }

    #chat-input {
        max-height: 96px;
    }

    .message {
        width: 100%;
        max-width: 100%;
    }

    .user-message .message-content {
        max-width: 94%;
    }

    .chat-header-actions {
        gap: 6px;
        margin-left: 8px;
    }

    .chat-close {
        width: 32px;
        height: 32px;
        padding: 6px;
    }

    .chat-fullscreen-toggle {
        display: none;
    }

    .chat-window.chat-fullscreen {
        position: fixed;
        inset: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        height: var(--elyd-chatbot-visual-height, 100dvh);
        max-height: none;
        border-radius: 0;
        margin-right: 0;
        transform: translateY(var(--elyd-chatbot-visual-offset-top, 0px));
    }

    .chat-window.chat-fullscreen .chat-header {
        padding: 10px 12px;
    }

    .chat-window.chat-fullscreen .chat-messages {
        padding: 12px 10px;
    }

    .chat-window.chat-fullscreen .chat-input-container {
        gap: 6px;
        padding: 10px 12px 10px;
    }
}
