/* Variables CSS pour la cohérence */
:root {
    --primary-color: #667eea;
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --secondary-color: #f093fb;
    --success-color: #4caf50;
    --warning-color: #ff9800;
    --error-color: #f44336;
    --text-primary: #2c3e50;
    --text-secondary: #7f8c8d;
    --background-light: #ffffff;
    --background-gray: #f8f9fa;
    --border-color: #e9ecef;
    --shadow-light: 0 2px 10px rgba(0, 0, 0, 0.1);
    --shadow-medium: 0 4px 20px rgba(0, 0, 0, 0.15);
    --shadow-heavy: 0 8px 30px rgba(0, 0, 0, 0.2);
    --border-radius: 12px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Thème sombre */
body.dark-theme {
    --text-primary: #ffffff;
    --text-secondary: #b0bec5;
    --background-light: #2c3e50;
    --background-gray: #34495e;
    --border-color: #455a64;
    --shadow-light: 0 2px 10px rgba(0, 0, 0, 0.3);
    --shadow-medium: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-heavy: 0 8px 30px rgba(0, 0, 0, 0.5);
}

/* Bouton flottant moderne */
.modern-chatbot-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: var(--primary-gradient);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: var(--shadow-medium);
    z-index: 1000;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.modern-chatbot-toggle:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-heavy);
}

.modern-chatbot-toggle.active {
    background: var(--error-color);
}

.toggle-icon {
    position: relative;
    width: 24px;
    height: 24px;
    color: white;
}

.toggle-icon svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transition: var(--transition);
}

.close-icon {
    opacity: 0;
    transform: rotate(90deg);
}

.modern-chatbot-toggle.active .chat-icon {
    opacity: 0;
    transform: rotate(-90deg);
}

.modern-chatbot-toggle.active .close-icon {
    opacity: 1;
    transform: rotate(0deg);
}

/* Animation de pulsation */
.pulse-ring {
    position: absolute;
    top: -10px;
    left: -10px;
    right: -10px;
    bottom: -10px;
    border: 2px solid var(--primary-color);
    border-radius: 50%;
    animation: pulse 2s infinite;
    opacity: 0;
}

.modern-chatbot-toggle.has-notification .pulse-ring {
    opacity: 1;
}

@keyframes pulse {
    0% {
        transform: scale(0.8);
        opacity: 1;
    }
    100% {
        transform: scale(1.4);
        opacity: 0;
    }
}

/* Badge de notification */
.notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--error-color);
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    animation: bounce 0.5s ease-out;
}

@keyframes bounce {
    0%, 20%, 53%, 80%, 100% {
        transform: translate3d(0, 0, 0);
    }
    40%, 43% {
        transform: translate3d(0, -8px, 0);
    }
    70% {
        transform: translate3d(0, -4px, 0);
    }
    90% {
        transform: translate3d(0, -2px, 0);
    }
}

/* Container principal */
.modern-chatbot-container {
    position: fixed;
    bottom: 100px;
    right: 20px;
    width: 380px;
    height: 600px;
    background: var(--background-light);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-heavy);
    z-index: 1001; /* Augmenté de 999 à 1001 pour être au-dessus de la navigation */
    transform: translateY(100%) scale(0.8);
    opacity: 0;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modern-chatbot-container.open {
    transform: translateY(0) scale(1);
    opacity: 1;
}

.modern-chatbot-container.minimized {
    transform: translateY(100%) scale(0.8);
    opacity: 0;
}

/* Header du chatbot */
.chatbot-header {
    background: var(--primary-gradient);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: var(--border-radius) var(--border-radius) 0 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.bot-avatar {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.bot-avatar img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: contain; /* Changé de 'cover' à 'contain' pour éviter de couper le logo */
    border: 2px solid var(--primary-color);
    background: white;
    padding: 4px; /* Augmenté de 2px à 4px pour plus d'espace */
    box-shadow: var(--shadow-light);
    /* Nouveaux styles pour améliorer la visibilité */
    filter: brightness(1.1) contrast(1.1);
    transition: var(--transition);
}

.bot-avatar img:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-medium);
}

.bot-avatar-small img {
    width: 100%;
    height: 100%;
    object-fit: contain; /* Changé de 'cover' à 'contain' */
    padding: 2px; /* Ajouté du padding */
    background: white; /* Ajouté un fond blanc */
    border-radius: 50%;
}

.message.bot .message-avatar img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--primary-color);
    background: white;
    padding: 1px;
    box-shadow: var(--shadow-light);
}

.status-indicator {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid white;
}

.status-indicator.online {
    background: var(--success-color);
}

.bot-info h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.status-text {
    font-size: 12px;
    opacity: 0.9;
}

.header-controls {
    display: flex;
    gap: 8px;
}

.control-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.control-btn svg {
    width: 16px;
    height: 16px;
}

.control-btn.muted {
    opacity: 0.5;
}

/* Zone de messages */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    background: var(--background-gray);
}

.messages-container {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Messages */
.message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: messageSlideIn 0.3s ease-out;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.bot-message {
    align-self: flex-start;
}

.message-avatar {
    flex-shrink: 0;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
}

.bot-avatar-small {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--background-light);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-light);
    overflow: hidden;
}

.bot-avatar-small img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message-content {
    flex: 1;
}

.message-text {
    background: var(--background-light);
    padding: 12px 16px;
    border-radius: 18px;
    color: var(--text-primary);
    line-height: 1.4;
    box-shadow: var(--shadow-light);
    word-wrap: break-word;
}

.user-message .message-text {
    background: var(--primary-gradient);
    color: white;
    border-bottom-right-radius: 6px;
}

.bot-message .message-text {
    border-bottom-left-radius: 6px;
}

.message-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 4px;
    padding: 0 4px;
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary);
}

.action-btn {
    width: 24px;
    height: 24px;
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-btn:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.action-btn svg {
    width: 14px;
    height: 14px;
}

/* Indicateur de frappe */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: var(--background-light);
    border-top: 1px solid var(--border-color);
    opacity: 0;
    transform: translateY(10px);
    transition: var(--transition);
}

.typing-indicator.visible {
    opacity: 1;
    transform: translateY(0);
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary-color);
    animation: typingDot 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typingDot {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.typing-text {
    font-size: 12px;
    color: var(--text-secondary);
    font-style: italic;
}

/* Zone de saisie */
.chatbot-input-area {
    background: var(--background-light);
    border-top: 1px solid var(--border-color);
    padding: 16px 20px;
}

.quick-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    overflow-x: auto;
    padding-bottom: 4px;
}

.quick-action {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--background-gray);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    font-size: 12px;
    color: var(--text-primary);
}

.quick-action:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.quick-action .emoji {
    font-size: 14px;
}

.input-container {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.input-wrapper {
    flex: 1;
    position: relative;
    background: var(--background-gray);
    border: 2px solid var(--border-color);
    border-radius: 24px;
    transition: var(--transition);
    display: flex;
    align-items: flex-end;
}

.input-wrapper:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#chatbot-input {
    flex: 1;
    border: none;
    background: none;
    padding: 12px 16px;
    font-size: 14px;
    line-height: 1.4;
    resize: none;
    outline: none;
    color: var(--text-primary);
    min-height: 20px;
    max-height: 100px;
}

#chatbot-input::placeholder {
    color: var(--text-secondary);
}

.input-actions {
    display: flex;
    gap: 4px;
    padding: 8px;
}

.send-button {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--border-color);
    color: var(--text-secondary);
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.send-button:not(:disabled):hover,
.send-button.active {
    background: var(--primary-gradient);
    color: white;
    transform: scale(1.05);
}

.send-button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.send-button svg {
    width: 18px;
    height: 18px;
}

.character-count {
    text-align: right;
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
    transition: var(--transition);
}

.character-count.warning {
    color: var(--warning-color);
}

/* Suggestions intelligentes */
.smart-suggestions {
    padding: 0 20px 16px;
    background: var(--background-light);
    opacity: 0;
    transform: translateY(-10px);
    transition: var(--transition);
    max-height: 0;
    overflow: hidden;
}

.smart-suggestions.visible {
    opacity: 1;
    transform: translateY(0);
    max-height: 100px;
    padding: 12px 20px 16px;
}

.suggestion-btn {
    display: inline-block;
    margin: 4px 8px 4px 0;
    padding: 6px 12px;
    background: var(--background-gray);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    font-size: 12px;
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
}

.suggestion-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Panneau d'émojis */
.emoji-panel {
    position: fixed;
    bottom: 160px;
    right: 20px;
    width: 300px;
    height: 250px;
    background: var(--background-light);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-heavy);
    z-index: 1001;
    transform: translateY(20px) scale(0.9);
    opacity: 0;
    transition: var(--transition);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.emoji-panel.open {
    transform: translateY(0) scale(1);
    opacity: 1;
}

.emoji-categories {
    display: flex;
    background: var(--background-gray);
    border-bottom: 1px solid var(--border-color);
}

.emoji-category {
    flex: 1;
    padding: 12px;
    border: none;
    background: none;
    font-size: 16px;
    cursor: pointer;
    transition: var(--transition);
}

.emoji-category:hover,
.emoji-category.active {
    background: var(--primary-color);
    color: white;
}

.emoji-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    padding: 16px;
    overflow-y: auto;
}

.emoji-item {
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    font-size: 20px;
    cursor: pointer;
    border-radius: 8px;
    transition: var(--transition);
}

.emoji-item:hover {
    background: var(--background-gray);
    transform: scale(1.1);
}

/* Toast notifications */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 8px;
    color: white;
    font-size: 14px;
    font-weight: 500;
    z-index: 10000;
    transform: translateX(100%);
    transition: var(--transition);
}

.toast.show {
    transform: translateX(0);
}

.toast-success {
    background: var(--success-color);
}

.toast-error {
    background: var(--error-color);
}

.toast-info {
    background: var(--primary-color);
}

/* Responsive */
@media (max-width: 480px) {
    .modern-chatbot-container {
        width: calc(100vw - 20px);
        height: calc(100vh - 120px);
        right: 10px;
        bottom: 90px;
    }
    
    .modern-chatbot-toggle {
        right: 15px;
        bottom: 15px;
    }
    
    .emoji-panel {
        width: calc(100vw - 40px);
        right: 10px;
    }
    
    .message {
        max-width: 90%;
    }
    
    .quick-actions {
        flex-wrap: wrap;
    }
}

/* Scrollbar personnalisée */
.chatbot-messages::-webkit-scrollbar,
.emoji-grid::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track,
.emoji-grid::-webkit-scrollbar-track {
    background: var(--background-gray);
}

.chatbot-messages::-webkit-scrollbar-thumb,
.emoji-grid::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover,
.emoji-grid::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}