/*
 * Styles du widget chatbot.
 * La couleur principale est injectée via la variable CSS --chatbot-color
 * (définie en inline par widget.js à partir de config.php).
 */

#chatbot-widget-root {
    --chatbot-color: #22c55e;
    --chatbot-color-dark: #16a34a;
    --chatbot-radius: 16px;
    --chatbot-font: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;

    position: fixed;
    bottom: 20px;
    z-index: 999999;
    font-family: var(--chatbot-font);
    font-size: 15px;
    line-height: 1.4;
}

#chatbot-widget-root[data-position="bottom-right"] {
    right: 20px;
}

#chatbot-widget-root[data-position="bottom-left"] {
    left: 20px;
}

/* ---------- Bulle flottante ---------- */

.chatbot-bubble {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chatbot-color) 0%, var(--chatbot-color-dark) 100%);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 28px;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.chatbot-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.35);
}

.chatbot-bubble:active {
    transform: scale(0.96);
}

.chatbot-bubble .chatbot-bubble-icon-open,
.chatbot-bubble .chatbot-bubble-icon-close {
    position: absolute;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.chatbot-bubble .chatbot-bubble-icon-close {
    opacity: 0;
    transform: rotate(-90deg) scale(0.6);
}

#chatbot-widget-root.chatbot-open .chatbot-bubble .chatbot-bubble-icon-open {
    opacity: 0;
    transform: rotate(90deg) scale(0.6);
}

#chatbot-widget-root.chatbot-open .chatbot-bubble .chatbot-bubble-icon-close {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

/* ---------- Fenêtre de chat ---------- */

.chatbot-window {
    position: absolute;
    bottom: 76px;
    width: 360px;
    max-width: calc(100vw - 40px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: #ffffff;
    border-radius: var(--chatbot-radius);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.97);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

#chatbot-widget-root[data-position="bottom-right"] .chatbot-window {
    right: 0;
}

#chatbot-widget-root[data-position="bottom-left"] .chatbot-window {
    left: 0;
}

#chatbot-widget-root.chatbot-open .chatbot-window {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.chatbot-header {
    background: linear-gradient(135deg, var(--chatbot-color) 0%, var(--chatbot-color-dark) 100%);
    color: #ffffff;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chatbot-header-info h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 2px;
}

.chatbot-header-info p {
    font-size: 0.78rem;
    opacity: 0.9;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 5px;
}

.chatbot-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.4);
    display: inline-block;
}

.chatbot-close-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #ffffff;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: none; /* fermeture via la bulle ; bouton visible seulement en plein écran mobile */
    align-items: center;
    justify-content: center;
}

/* ---------- Messages ---------- */

.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f7f8fa;
}

.chatbot-msg {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.9rem;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.chatbot-msg-assistant {
    align-self: flex-start;
    background: #ffffff;
    color: #1f2937;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.chatbot-msg-user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--chatbot-color) 0%, var(--chatbot-color-dark) 100%);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.chatbot-msg-error {
    align-self: center;
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
    font-size: 0.82rem;
    text-align: center;
}

/* Indicateur de frappe */
.chatbot-typing {
    align-self: flex-start;
    background: #ffffff;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    padding: 12px 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    display: flex;
    gap: 4px;
}

.chatbot-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #9ca3af;
    animation: chatbot-typing-bounce 1.2s infinite ease-in-out;
}

.chatbot-typing span:nth-child(2) { animation-delay: 0.15s; }
.chatbot-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chatbot-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.6; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ---------- Zone de saisie ---------- */

.chatbot-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid #e5e7eb;
    background: #ffffff;
    flex-shrink: 0;
}

.chatbot-input {
    flex: 1;
    resize: none;
    border: 1px solid #d1d5db;
    border-radius: 20px;
    padding: 10px 16px;
    font-family: var(--chatbot-font);
    font-size: 0.9rem;
    max-height: 90px;
    outline: none;
    transition: border-color 0.2s ease;
}

.chatbot-input:focus {
    border-color: var(--chatbot-color);
}

.chatbot-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--chatbot-color) 0%, var(--chatbot-color-dark) 100%);
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s ease, opacity 0.15s ease;
}

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

.chatbot-send-btn:disabled {
    opacity: 0.5;
    cursor: default;
    transform: none;
}

.chatbot-footer-note {
    text-align: center;
    font-size: 0.68rem;
    color: #9ca3af;
    padding: 4px 0 10px;
    background: #ffffff;
}

/* ---------- Mobile : plein écran ---------- */

@media (max-width: 480px) {
    #chatbot-widget-root {
        bottom: 16px;
    }

    #chatbot-widget-root[data-position="bottom-right"],
    #chatbot-widget-root[data-position="bottom-left"] {
        right: 16px;
        left: 16px;
    }

    .chatbot-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    .chatbot-close-btn {
        display: flex;
    }
}
