/**
 * N8N Chatbot - Frontend Styles
 * Version: 1.0.0
 */

/* ==========================================================================
   Variables CSS et Configuration de Base
   ========================================================================== */

:root {
    /* === 15 COULEURS ESSENTIELLES - VRAIMENT INDÉPENDANTES === */

    /* Bouton chat flottant */
    --n8n-widget-btn: #0084ff;           /* Fond bouton widget UNIQUEMENT */
    --n8n-widget-icon: #ffffff;          /* Icône bouton widget UNIQUEMENT */

    /* Header */
    --n8n-header-bg: #0084ff;            /* Fond header UNIQUEMENT */
    --n8n-header-title: #ffffff;         /* Titre "Chat avec nous" UNIQUEMENT */
    --n8n-header-status: #ffffff;        /* Texte "En ligne" UNIQUEMENT */
    --n8n-header-btns: #ffffff;          /* Boutons minimize/close UNIQUEMENT */

    /* Body / Zone messages */
    --n8n-body-bg: #f5f5f5;              /* Fond zone messages UNIQUEMENT */

    /* Messages BOT */
    --n8n-bot-msg-bg: #f0f0f0;           /* Fond bulles bot UNIQUEMENT */
    --n8n-bot-msg-text: #000000;         /* Texte bulles bot UNIQUEMENT */

    /* Messages USER */
    --n8n-user-msg-bg: #0084ff;          /* Fond bulles user UNIQUEMENT */
    --n8n-user-msg-text: #ffffff;        /* Texte bulles user UNIQUEMENT */

    /* Input */
    --n8n-input-bg: #ffffff;             /* Fond input UNIQUEMENT */
    --n8n-input-text: #000000;           /* Texte input UNIQUEMENT */

    /* Bouton envoyer */
    --n8n-send-btn: #0084ff;             /* Fond bouton envoyer UNIQUEMENT */

    /* Footer */
    --n8n-footer-bg: #ffffff;            /* Fond footer UNIQUEMENT */

    /* Autres (ombres, transitions) */
    --n8n-shadow: 0 5px 40px rgba(0, 0, 0, 0.16);
    --n8n-shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.1);
    --n8n-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================================
   Container Principal
   ========================================================================== */

/* Par défaut, cache le container du chatbot jusqu'à ce que JS soit prêt */
#n8n-chatbot-container {
    position: fixed;
    z-index: 2147483647 !important; /* Valeur maximale pour être au-dessus de tout (Avada, etc.) */
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    display: none !important;
}

/* Quand JS est prêt, il ajoute cette classe pour afficher */
#n8n-chatbot-container.n8n-ready {
    display: block !important;
}

/* Positionnement du widget */
#n8n-chatbot-container.n8n-chatbot-bottom-right {
    bottom: 20px;
    right: 20px;
    width: 380px;
    height: 60px;
}

#n8n-chatbot-container.n8n-chatbot-bottom-left {
    bottom: 20px;
    left: 20px;
    width: 380px;
    height: 60px;
}

#n8n-chatbot-container.n8n-chatbot-top-right {
    top: 20px;
    right: 20px;
    width: 380px;
    height: 60px;
}

#n8n-chatbot-container.n8n-chatbot-top-left {
    top: 20px;
    left: 20px;
    width: 380px;
    height: 60px;
}

/* Bouton positionné selon le coin */
.n8n-chatbot-bottom-right .n8n-chatbot-button,
.n8n-chatbot-top-right .n8n-chatbot-button {
    right: 0;
}

.n8n-chatbot-bottom-left .n8n-chatbot-button,
.n8n-chatbot-top-left .n8n-chatbot-button {
    left: 0;
}

.n8n-chatbot-bottom-right .n8n-chatbot-button,
.n8n-chatbot-bottom-left .n8n-chatbot-button {
    bottom: 0;
}

.n8n-chatbot-top-right .n8n-chatbot-button,
.n8n-chatbot-top-left .n8n-chatbot-button {
    top: 0;
}

/* ==========================================================================
   Bouton Flottant
   ========================================================================== */

.n8n-chatbot-button {
    position: absolute;
    bottom: 0;
    right: 0;
    z-index: 10 !important; /* S'assurer que le bouton est au-dessus des autres éléments du container */
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--n8n-widget-btn);
    color: var(--n8n-widget-icon);
    border: none;
    cursor: pointer;
    box-shadow: var(--n8n-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--n8n-transition);
    overflow: hidden;
    pointer-events: auto !important; /* Forcer les événements de clic */
    /* Le widget flottant doit être visible immédiatement */
    opacity: 1 !important;
    visibility: visible !important;
}

.n8n-chatbot-button:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 50px rgba(0, 132, 255, 0.4);
}

.n8n-chatbot-button:active {
    transform: scale(0.95);
}

.n8n-chatbot-button svg {
    width: 28px;
    height: 28px;
    transition: var(--n8n-transition);
    pointer-events: none !important; /* Les SVG ne doivent pas capturer les clics */
}

.n8n-chatbot-button svg * {
    pointer-events: none !important; /* Les enfants des SVG non plus */
}

.n8n-chatbot-icon {
    display: block;
    pointer-events: none !important;
}

/* Custom widget icon (image) */
.n8n-chatbot-custom-icon {
    width: 60%;
    height: 60%;
    object-fit: contain;
    border-radius: 0;
}

.n8n-chatbot-close-icon {
    display: none;
    position: absolute;
    pointer-events: none !important;
}

#n8n-chatbot-container.n8n-chatbot-open .n8n-chatbot-icon {
    display: none;
}

#n8n-chatbot-container.n8n-chatbot-open .n8n-chatbot-close-icon {
    display: block;
}

/* Badge de notification */
.n8n-chatbot-notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff3b30;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    border: 2px solid white;
    animation: n8n-pulse 2s infinite;
}

@keyframes n8n-pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
}

/* ==========================================================================
   Fenêtre du Chat
   ========================================================================== */

.n8n-chatbot-window {
    position: absolute;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 600px;
    max-height: calc(100vh - 100px);
    background: var(--n8n-secondary);
    border-radius: 16px;
    box-shadow: var(--n8n-shadow);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: scale(0.8) translateY(20px);
    pointer-events: none;
    transition: var(--n8n-transition);
    overflow: hidden;
}

/* Positionnement de la fenêtre selon la position du bouton */
.n8n-chatbot-bottom-right .n8n-chatbot-window,
.n8n-chatbot-bottom-left .n8n-chatbot-window {
    bottom: 80px;
}

.n8n-chatbot-top-right .n8n-chatbot-window,
.n8n-chatbot-top-left .n8n-chatbot-window {
    top: 80px;
}

.n8n-chatbot-bottom-right .n8n-chatbot-window,
.n8n-chatbot-top-right .n8n-chatbot-window {
    right: 0;
}

.n8n-chatbot-bottom-left .n8n-chatbot-window,
.n8n-chatbot-top-left .n8n-chatbot-window {
    left: 0;
}

/* État ouvert */
#n8n-chatbot-container.n8n-chatbot-open .n8n-chatbot-window {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: all;
}

/* ==========================================================================
   Header du Chat
   ========================================================================== */

.n8n-chatbot-header {
    background: var(--n8n-header-bg);
    color: var(--n8n-header-title);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    flex-shrink: 0;
}

.n8n-chatbot-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

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

.n8n-chatbot-default-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.n8n-chatbot-default-avatar svg {
    width: 24px;
    height: 24px;
    color: white;
}

/* Logo du header */
.n8n-chatbot-header-logo {
    object-fit: contain !important;
    flex-shrink: 0;
    margin-right: 12px;
}

/* Tailles du logo - utilise les indices 0, 1, 2 */
.n8n-chatbot-header-logo.n8n-chatbot-logo-0 {
    max-height: 40px !important;
    width: auto !important;
    height: 40px !important;
}

.n8n-chatbot-header-logo.n8n-chatbot-logo-1 {
    max-height: 60px !important;
    width: auto !important;
    height: 60px !important;
}

.n8n-chatbot-header-logo.n8n-chatbot-logo-2 {
    max-height: 80px !important;
    width: auto !important;
    height: 80px !important;
}

/* Fallback pour les anciennes classes (small, medium, large) */
.n8n-chatbot-header-logo.n8n-chatbot-logo-small {
    max-height: 40px !important;
    width: auto !important;
    height: 40px !important;
}

.n8n-chatbot-header-logo.n8n-chatbot-logo-medium {
    max-height: 60px !important;
    width: auto !important;
    height: 60px !important;
}

.n8n-chatbot-header-logo.n8n-chatbot-logo-large {
    max-height: 80px !important;
    width: auto !important;
    height: 80px !important;
}

.n8n-chatbot-header-info {
    flex: 1;
    min-width: 0;
}

.n8n-chatbot-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 4px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--n8n-header-title);
}

.n8n-chatbot-status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--n8n-header-status);
}

.n8n-chatbot-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4cd964;
    display: inline-block;
    animation: n8n-blink 2s infinite;
}

@keyframes n8n-blink {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.4;
    }
}

.n8n-chatbot-header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.n8n-chatbot-minimize,
.n8n-chatbot-close {
    background: transparent;
    border: none;
    color: var(--n8n-header-btns);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--n8n-transition);
    width: 32px;
    height: 32px;
}

.n8n-chatbot-minimize:hover,
.n8n-chatbot-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.n8n-chatbot-minimize svg,
.n8n-chatbot-close svg {
    width: 18px;
    height: 18px;
}

/* ==========================================================================
   Corps du Chat (Messages)
   ========================================================================== */

.n8n-chatbot-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--n8n-body-bg);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Scrollbar personnalisée */
.n8n-chatbot-body::-webkit-scrollbar {
    width: 6px;
}

.n8n-chatbot-body::-webkit-scrollbar-track {
    background: transparent;
}

.n8n-chatbot-body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.n8n-chatbot-body::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* Message */
.n8n-chatbot-message {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    animation: n8n-message-appear 0.3s ease;
}

@keyframes n8n-message-appear {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.n8n-chatbot-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.n8n-chatbot-message .n8n-chatbot-default-avatar {
    width: 32px;
    height: 32px;
    background: var(--n8n-primary);
}

.n8n-chatbot-message .n8n-chatbot-default-avatar svg {
    width: 18px;
    height: 18px;
}

.n8n-chatbot-message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 70%;
}

.n8n-chatbot-message-text {
    background: var(--n8n-bot-msg-bg);
    color: var(--n8n-bot-msg-text);
    padding: 12px 16px;
    border-radius: 18px;
    box-shadow: var(--n8n-shadow-sm);
    word-wrap: break-word;
    line-height: 1.5;
}

.n8n-chatbot-message-time {
    font-size: 11px;
    color: #999;
    padding: 0 8px;
}

/* Message de l'utilisateur */
.n8n-chatbot-message-user {
    flex-direction: row-reverse;
    align-self: flex-end;
}

.n8n-chatbot-message-user .n8n-chatbot-message-content {
    align-items: flex-end;
}

.n8n-chatbot-message-user .n8n-chatbot-message-text {
    background: var(--n8n-user-msg-bg);
    color: var(--n8n-user-msg-text);
}

/* Indicateur de frappe */
.n8n-chatbot-typing {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 0 20px 10px;
    animation: n8n-message-appear 0.3s ease;
}

.n8n-chatbot-typing-dots {
    background: white;
    padding: 12px 16px;
    border-radius: 18px;
    box-shadow: var(--n8n-shadow-sm);
    display: flex;
    gap: 4px;
}

.n8n-chatbot-typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #999;
    animation: n8n-typing 1.4s infinite;
}

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

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

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

/* ==========================================================================
   Footer du Chat (Input)
   ========================================================================== */

.n8n-chatbot-footer {
    padding: 16px 20px;
    background: var(--n8n-footer-bg);
    border-top: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.n8n-chatbot-form {
    margin-bottom: 8px;
}

/* ==========================================================================
   Formulaires HTML Interactifs - Support Complet et Responsive
   ========================================================================== */

.chatbot-form-container {
    width: 100%;
    padding: 15px;
    background: #f9f9f9;
    border-radius: 12px;
    margin: 10px 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.chatbot-form {
    width: 100%;
}

.form-row {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.form-field {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-field label {
    font-size: 13px;
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
}

.form-field input,
.form-field select,
.form-field textarea {
    padding: 10px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    color: #333;
    background: white;
    transition: all 0.2s ease;
    outline: none;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
    border-color: var(--n8n-send-btn);
    box-shadow: 0 0 0 3px rgba(0, 132, 255, 0.1);
}

.form-field input::placeholder,
.form-field textarea::placeholder {
    color: #999;
}

.form-field input[required] + label::after,
.form-field label:has(+ input[required])::after {
    content: ' *';
    color: #ff4444;
}

.form-submit-btn {
    width: 100%;
    padding: 12px 24px;
    background: var(--n8n-send-btn);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 8px;
}

.form-submit-btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 132, 255, 0.3);
}

.form-submit-btn:active {
    transform: translateY(0);
}

.form-submit-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    opacity: 0.6;
}

/* Responsive - Mobile */
@media (max-width: 600px) {
    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .chatbot-form-container {
        padding: 12px;
    }

    .form-field {
        margin-bottom: 12px;
    }
}

/* Formulaire soumis (désactivé) */
.chatbot-form.submitted {
    opacity: 0.6;
    pointer-events: none;
}

.chatbot-form.submitted::after {
    content: '✓ Formulaire envoyé';
    display: block;
    text-align: center;
    padding: 8px;
    background: #4caf50;
    color: white;
    border-radius: 6px;
    margin-top: 8px;
    font-weight: 600;
}

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

.n8n-chatbot-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 24px;
    font-size: 14px;
    outline: none;
    transition: var(--n8n-transition);
    font-family: inherit;
    background: var(--n8n-input-bg);
    color: var(--n8n-input-text);
}

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

.n8n-chatbot-input::placeholder {
    color: #999;
}

.n8n-chatbot-send-button {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    max-width: 44px !important;
    border-radius: 50%;
    background: var(--n8n-send-btn);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--n8n-transition);
    flex-shrink: 0;
}

.n8n-chatbot-send-button:hover {
    opacity: 0.9;
    transform: scale(1.05);
    /* PAS de width ni height modifiés au hover */
}

.n8n-chatbot-send-button:active {
    opacity: 0.8;
}

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

.n8n-chatbot-send-button svg {
    width: 20px !important;
    height: 20px !important;
    flex-shrink: 0;
}

.n8n-chatbot-powered {
    text-align: center;
    font-size: 11px;
    color: #999;
    margin-top: 8px;
}

.n8n-chatbot-powered a {
    color: var(--n8n-primary);
    text-decoration: none;
}

.n8n-chatbot-powered a:hover {
    text-decoration: underline;
}

/* ==========================================================================
   Responsive Mobile
   ========================================================================== */

@media (max-width: 480px) {
    #n8n-chatbot-container {
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        top: auto !important;
    }

    .n8n-chatbot-button {
        position: fixed;
        bottom: 20px;
        right: 20px;
    }

    .n8n-chatbot-window {
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100vh !important;
        max-height: 100vh !important;
        bottom: 0 !important;
        top: auto !important;
        left: 0 !important;
        right: 0 !important;
        border-radius: 0;
        transform: translateY(100%);
    }

    #n8n-chatbot-container.n8n-chatbot-open .n8n-chatbot-window {
        transform: translateY(0);
    }

    .n8n-chatbot-header {
        border-radius: 0;
    }
}

/* ==========================================================================
   États et Animations
   ========================================================================== */

/* État de chargement */
.n8n-chatbot-loading {
    pointer-events: none;
    opacity: 0.6;
}

/* Animation shake pour les erreurs */
@keyframes n8n-shake {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-5px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(5px);
    }
}

.n8n-chatbot-error {
    animation: n8n-shake 0.5s;
}

/* Message d'erreur */
.n8n-chatbot-error-message {
    background: #ff3b30 !important;
    color: white !important;
}

/* ==========================================================================
   Accessibilité
   ========================================================================== */

.n8n-chatbot-button:focus,
.n8n-chatbot-minimize:focus,
.n8n-chatbot-close:focus,
.n8n-chatbot-send-button:focus {
    outline: 2px solid var(--n8n-primary);
    outline-offset: 2px;
}

.n8n-chatbot-input:focus {
    box-shadow: 0 0 0 3px rgba(0, 132, 255, 0.1);
}

/* Réduction des animations pour les préférences utilisateur */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Mode sombre (support basique) */
@media (prefers-color-scheme: dark) {
    :root {
        --n8n-bg-light: #1c1c1e;
        --n8n-secondary: #2c2c2e;
    }

    .n8n-chatbot-message-text {
        background: #3a3a3c;
        color: white;
    }

    .n8n-chatbot-input {
        background: #3a3a3c;
        border-color: #48484a;
        color: white;
    }

    .n8n-chatbot-footer {
        background: #2c2c2e;
        border-top-color: #48484a;
    }

    .n8n-chatbot-typing-dots {
        background: #3a3a3c;
    }
}
