/* Chatbot Widget Styles */

/* Animation pulse pour attirer l'attention */
@keyframes chatbotPulse {
    0% { box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3); }
    50% { box-shadow: 0 4px 30px rgba(30, 41, 59, 0.6), 0 0 0 8px rgba(30, 41, 59, 0.15); }
    100% { box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3); }
}

@keyframes chatbotBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

@keyframes notificationSlide {
    0% { opacity: 0; transform: translateX(20px); }
    100% { opacity: 1; transform: translateX(0); }
}

@keyframes notificationPop {
    0% { transform: scale(0); }
    70% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Bouton flottant */
.chatbot-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

/* Animation d'attention au chargement */
.chatbot-toggle.attention {
    animation: chatbotPulse 2s ease-in-out 3, chatbotBounce 0.6s ease-in-out 2;
}

.chatbot-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.4);
    animation: none;
}

.chatbot-toggle i {
    font-size: 24px;
    color: white;
    transition: transform 0.3s ease;
}

.chatbot-toggle.active {
    animation: none;
}

.chatbot-toggle.active i {
    transform: rotate(90deg);
}

/* Badge notification */
.chatbot-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid white;
    animation: notificationPop 0.4s ease-out;
}

/* Bulle de notification / teaser */
.chatbot-teaser {
    position: fixed;
    bottom: 92px;
    right: 24px;
    background: white;
    padding: 12px 16px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 9997;
    max-width: 220px;
    font-size: 14px;
    color: #1e293b;
    line-height: 1.4;
    animation: notificationSlide 0.4s ease-out;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chatbot-teaser:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.2);
}

.chatbot-teaser::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 24px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid white;
}

.chatbot-teaser-close {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 22px;
    height: 22px;
    background: #64748b;
    border: 2px solid white;
    border-radius: 50%;
    color: white;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}

.chatbot-teaser-close:hover {
    background: #475569;
}

/* Fenêtre de chat */
.chatbot-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 500px;
    max-height: calc(100vh - 150px);
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s ease;
}

.chatbot-window.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Header */
.chatbot-header {
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chatbot-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chatbot-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.3);
    flex-shrink: 0;
}

.chatbot-header-text h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.chatbot-header-text p {
    margin: 2px 0 0;
    font-size: 12px;
    opacity: 0.8;
}

.chatbot-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 8px;
    opacity: 0.8;
    transition: opacity 0.2s;
    flex-shrink: 0;
}

.chatbot-close:hover {
    opacity: 1;
}

/* Messages */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
}

.chatbot-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    animation: messageSlide 0.3s ease;
    word-wrap: break-word;
}

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

.chatbot-message.bot {
    background: #f1f5f9;
    color: #1e293b;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.chatbot-message.user {
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.chatbot-message.typing {
    display: flex;
    gap: 4px;
    padding: 16px;
}

.chatbot-message.typing span {
    width: 8px;
    height: 8px;
    background: #94a3b8;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.chatbot-message.typing span:nth-child(1) { animation-delay: 0s; }
.chatbot-message.typing span:nth-child(2) { animation-delay: 0.2s; }
.chatbot-message.typing span:nth-child(3) { animation-delay: 0.4s; }

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

/* Input */
.chatbot-input-container {
    padding: 12px 16px;
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
    flex-shrink: 0;
}

.chatbot-turns-info {
    font-size: 12px;
    color: #64748b;
    margin-bottom: 8px;
    text-align: center;
}

.chatbot-turns-info.warning {
    color: #f59e0b;
}

.chatbot-turns-info.exhausted {
    color: #ef4444;
}

.chatbot-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

.chatbot-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #e2e8f0;
    border-radius: 24px;
    font-size: 16px; /* 16px minimum pour éviter zoom iOS */
    outline: none;
    transition: border-color 0.2s;
    -webkit-appearance: none;
    appearance: none;
}

.chatbot-input:focus {
    border-color: #1e293b;
}

.chatbot-input:disabled {
    background: #f1f5f9;
    cursor: not-allowed;
}

.chatbot-send {
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, opacity 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.chatbot-send:hover:not(:disabled) {
    transform: scale(1.05);
}

.chatbot-send:active:not(:disabled) {
    transform: scale(0.95);
}

.chatbot-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Message de fin */
.chatbot-limit-message {
    text-align: center;
    padding: 16px;
    background: #fef3c7;
    color: #92400e;
    font-size: 13px;
}

.chatbot-limit-message a {
    color: #1e293b;
    font-weight: 600;
}

/* ==================== RESPONSIVE MOBILE ==================== */

/* Tablettes */
@media (max-width: 768px) {
    .chatbot-teaser {
        max-width: 200px;
        font-size: 13px;
        padding: 10px 14px;
        bottom: 88px;
        right: 20px;
    }

    .chatbot-toggle {
        bottom: 20px;
        right: 20px;
    }

    .chatbot-window {
        right: 16px;
        bottom: 90px;
        width: calc(100vw - 32px);
        max-width: 400px;
        height: calc(100vh - 120px);
        max-height: 550px;
    }
}

/* Mobiles */
@media (max-width: 480px) {
    .chatbot-toggle {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }

    .chatbot-toggle i {
        font-size: 22px;
    }

    .chatbot-teaser {
        bottom: 80px;
        right: 16px;
        left: 16px;
        max-width: none;
        text-align: center;
    }

    .chatbot-teaser::after {
        right: 28px;
    }

    /* Plein écran sur mobile */
    .chatbot-window {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        z-index: 10000;
    }

    .chatbot-header {
        padding: 16px;
        padding-top: max(16px, env(safe-area-inset-top));
    }

    .chatbot-messages {
        padding: 12px;
    }

    .chatbot-message {
        max-width: 90%;
        font-size: 15px;
    }

    .chatbot-input-container {
        padding: 12px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .chatbot-input {
        padding: 10px 14px;
    }

    .chatbot-send {
        width: 42px;
        height: 42px;
        min-width: 42px;
    }
}

/* Gestion du clavier virtuel sur mobile */
@media (max-height: 500px) and (max-width: 480px) {
    .chatbot-window {
        height: 100%;
    }

    .chatbot-messages {
        flex: 1;
        min-height: 100px;
    }
}

/* Dark mode support (si le site l'utilise) */
@media (prefers-color-scheme: dark) {
    .chatbot-teaser {
        background: #1e293b;
        color: white;
    }

    .chatbot-teaser::after {
        border-top-color: #1e293b;
    }
}
