/**
 * ARIA Chat Widget - Styles
 * Inspiré du widget ARIA Chat Demo
 */

:root {
    --aria-primary: #6366f1;
    --aria-primary-dark: #4f46e5;
    --aria-bg: #ffffff;
    --aria-text: #1f2937;
    --aria-text-light: #6b7280;
    --aria-border: #e5e7eb;
    --aria-user-bg: #6366f1;
    --aria-bot-bg: #f3f4f6;
}

#aria-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    z-index: 99999;
    /* Comportement comme scroll-to-top : caché par défaut, apparaît après scroll */
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    /* Permettre les clics sur le bouton même quand le widget n'est pas visible */
    pointer-events: none;
}

#aria-widget.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

/* Permettre les clics sur le bouton toggle même quand le widget n'est pas visible */
#aria-toggle {
    width: 65px;
    height: 65px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--aria-primary), var(--aria-primary-dark));
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s, box-shadow 0.3s;
    position: relative;
    /* Améliorer la réactivité sur mobile */
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    /* Permettre les clics même quand le widget parent n'est pas visible */
    pointer-events: auto;
}

#aria-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(99, 102, 241, 0.5);
}

#aria-toggle:active {
    transform: scale(0.95);
}

/* Améliorer la visibilité sur mobile */
@media (hover: none) and (pointer: coarse) {
    #aria-toggle:active {
        transform: scale(0.9);
        box-shadow: 0 2px 15px rgba(99, 102, 241, 0.6);
    }
}

#aria-toggle svg {
    width: 30px;
    height: 30px;
    fill: white;
}

#aria-chat {
    /* IMPORTANT : Le chat doit être en position fixed et indépendant du widget parent */
    position: fixed !important;
    bottom: 100px !important;
    right: 24px !important;
    width: 400px;
    height: 600px;
    max-width: calc(100vw - 48px);
    max-height: calc(100vh - 140px);
    background: var(--aria-bg);
    border-radius: 20px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.2);
    display: none;
    flex-direction: column;
    overflow: hidden;
    /* S'assurer que le chat reste au-dessus de tout */
    z-index: 999999;
    /* Empêcher le scroll de la page quand on interagit avec le chat */
    touch-action: pan-y;
    /* S'assurer que le chat est caché par défaut */
    visibility: hidden;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0s 0.3s;
    /* S'assurer que le chat n'est jamais masqué */
    pointer-events: none;
    /* Forcer l'affichage au-dessus de tout */
    isolation: isolate;
}

/* État ouvert : toutes les propriétés dans une seule règle pour garantir l'affichage */
#aria-chat.open {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    transform: translateY(0) !important;
    will-change: transform, opacity;
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0s 0s;
    /* S'assurer que le chat est toujours visible quand ouvert, même si le widget parent n'est pas visible */
    pointer-events: auto !important;
    /* Forcer position fixed pour garantir la visibilité */
    position: fixed !important;
    bottom: 100px !important;
    right: 24px !important;
    top: auto !important;
    left: auto !important;
    width: 400px !important;
    height: 600px !important;
    max-width: calc(100vw - 48px) !important;
    max-height: calc(100vh - 140px) !important;
    /* S'assurer que le chat est au-dessus de tout */
    z-index: 999999 !important;
    /* Forcer l'affichage - aucune propriété ne doit masquer */
    clip: auto !important;
    clip-path: none !important;
    -webkit-clip-path: none !important;
    mask: none !important;
    -webkit-mask: none !important;
    /* S'assurer que le chat n'est pas affecté par le parent */
    contain: none !important;
}

/* Garantir que le widget parent est visible quand le chat est ouvert */
/* Solution de repli pour les navigateurs qui ne supportent pas :has() */
#aria-widget.visible #aria-chat.open {
    /* Le chat est déjà géré par #aria-chat.open, cette règle est pour la compatibilité */
}

/* Alternative avec classe supplémentaire pour compatibilité navigateurs */
#aria-widget.chat-open {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    transform: translateY(0) !important;
}

/* ⭐ NOUVEAU (Version 2.11.3) : Classes pour remplacer les styles inline JavaScript */
/* Ces classes permettent d'éviter les violations CSP tout en gardant le contrôle */
#aria-widget.force-visible {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    transform: translateY(0) !important;
}

#aria-chat.force-open {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    transform: translateY(0) !important;
    z-index: 999999 !important;
    position: fixed !important;
    bottom: 85px !important;
    right: 20px !important;
    top: auto !important;
    left: auto !important;
    clip: auto !important;
    clip-path: none !important;
    contain: none !important;
    pointer-events: auto !important;
}

#aria-chat:not(.open) {
    will-change: auto;
}

@keyframes slideUp {
    from { 
        opacity: 0; 
        transform: translateY(20px); 
    }
    to { 
        opacity: 1; 
        transform: translateY(0); 
    }
}

/* Optimisation : contenant de composition pour les animations GPU */
/* DÉSACTIVÉ : contain peut masquer le chat qui est en position fixed */
/* #aria-widget {
    contain: layout style paint;
} */

#aria-messages {
    contain: layout style;
    /* Optimisation du scroll */
    transform: translateZ(0);
    -webkit-overflow-scrolling: touch;
}

#aria-header {
    background: linear-gradient(135deg, var(--aria-primary), var(--aria-primary-dark));
    color: white;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    position: relative;
}

#aria-close {
    position: absolute;
    right: 15px;
    top: 15px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    color: white;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

#aria-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

#aria-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

#aria-header-info h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 4px;
}

#aria-header-info span {
    font-size: 13px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
}

#aria-status {
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
    display: inline-block;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { 
        opacity: 1; 
    }
    50% { 
        opacity: 0.5; 
    }
}

#aria-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background: #fafafa;
}

.aria-message {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.6;
    animation: fadeIn 0.3s ease;
    word-wrap: break-word;
}

@keyframes fadeIn {
    from { 
        opacity: 0; 
        transform: scale(0.95); 
    }
    to { 
        opacity: 1; 
        transform: scale(1); 
    }
}

.aria-message.user {
    background: var(--aria-user-bg);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.aria-message.bot {
    background: white;
    color: var(--aria-text);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.aria-typing {
    display: flex;
    gap: 5px;
    padding: 18px;
    align-self: flex-start;
    background: white;
    border-radius: 18px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.aria-typing span {
    width: 10px;
    height: 10px;
    background: var(--aria-primary);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.aria-typing span:nth-child(2) { 
    animation-delay: 0.2s; 
}

.aria-typing span:nth-child(3) { 
    animation-delay: 0.4s; 
}

@keyframes typing {
    0%, 100% { 
        transform: translateY(0); 
        opacity: 0.5; 
    }
    50% { 
        transform: translateY(-8px); 
        opacity: 1; 
    }
}

#aria-input-area {
    padding: 18px;
    border-top: 1px solid var(--aria-border);
    display: flex;
    gap: 12px;
    background: white;
}

#aria-input {
    flex: 1;
    padding: 14px 20px;
    border: 2px solid var(--aria-border);
    border-radius: 25px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

#aria-input:focus {
    border-color: var(--aria-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

#aria-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

#aria-send {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--aria-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
    flex-shrink: 0;
}

#aria-send:hover { 
    background: var(--aria-primary-dark); 
    transform: scale(1.05);
}

#aria-send:disabled { 
    background: var(--aria-border); 
    cursor: not-allowed;
    transform: none;
}

#aria-send svg {
    width: 22px;
    height: 22px;
    fill: white;
}

#aria-powered {
    text-align: center;
    padding: 10px;
    font-size: 11px;
    color: var(--aria-text-light);
    background: white;
    border-top: 1px solid var(--aria-border);
}

#aria-powered a {
    color: var(--aria-primary);
    text-decoration: none;
}

#aria-powered a:hover {
    text-decoration: underline;
}

/* Responsive */
@media (max-width: 480px) {
    #aria-widget {
        bottom: 20px;
        right: 20px;
        z-index: 99999;
    }
    
    #aria-widget.visible {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
    }
    
    #aria-chat {
        width: calc(100vw - 40px);
        height: calc(100vh - 100px);
        bottom: 80px;
        right: -10px;
        /* S'assurer que le chat prend tout l'écran sur mobile */
        max-width: calc(100vw - 40px);
        max-height: calc(100vh - 100px);
        /* Z-index très élevé pour rester au-dessus de tout */
        z-index: 100000;
    }
    
    #aria-chat.open {
        /* Empêcher le scroll de la page quand le chat est ouvert */
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
    }
    
    #aria-toggle {
        width: 60px;
        height: 60px;
        position: relative;
        /* Augmenter l'ombre pour meilleure visibilité sur mobile */
        box-shadow: 0 6px 25px rgba(99, 102, 241, 0.6);
        /* Zone de touch plus grande sur mobile */
        min-width: 60px;
        min-height: 60px;
    }
}

/* Media query pour très petits écrans */
@media (max-width: 360px) {
    #aria-widget {
        bottom: 15px !important;
        right: 15px !important;
    }
    
    #aria-toggle {
        width: 56px;
        height: 56px;
        box-shadow: 0 4px 20px rgba(99, 102, 241, 0.7);
    }
}

/* Compatibilité avec le scroll-to-top */
.scroll-to-top {
    bottom: 100px !important;
}

@media (max-width: 768px) {
    .scroll-to-top {
        bottom: 90px !important;
    }
}

/* Garantir que le footer ne masque pas le widget */
.site-footer {
    position: relative;
    z-index: 1;
}

/* S'assurer que le widget reste au-dessus de tous les éléments */
#aria-widget {
    /* Éviter que d'autres éléments ne masquent le widget */
    /* DÉSACTIVÉ : isolation peut masquer le chat */
    /* isolation: isolate; */
    /* S'assurer que le widget ne masque pas le chat */
    overflow: visible !important;
}

/* Protection contre les masquages accidentels */
body:has(#aria-widget) {
    /* S'assurer que le body ne cache pas le widget */
    overflow-x: hidden;
}

/* S'assurer que le widget est visible quand la classe .visible est présente */
#aria-widget.visible #aria-toggle {
    pointer-events: auto;
}

/* Améliorer l'accessibilité tactile sur mobile */
#aria-toggle {
    /* Zone de touch minimale recommandée : 44x44px (WCAG 2.1 AA) */
    min-width: 44px;
    min-height: 44px;
}

/* Classe sr-only pour les éléments cachés visuellement mais accessibles aux lecteurs d'écran */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Améliorer le contraste pour WCAG 2.1 AA (ratio minimum 4.5:1 pour texte normal) */
#aria-header-info span {
    color: var(--aria-text-light);
    /* Contraste vérifié : #6b7280 sur blanc = 4.6:1 ✅ */
}

#aria-input {
    /* Contraste amélioré pour le placeholder */
    color: var(--aria-text);
}

#aria-input::placeholder {
    color: var(--aria-text-light);
    opacity: 1; /* Assurer le contraste même avec opacity */
}

/* Focus visible pour l'accessibilité clavier (WCAG 2.1 AA) */
#aria-toggle:focus,
#aria-close:focus,
#aria-send:focus,
#aria-input:focus {
    outline: 2px solid var(--aria-primary);
    outline-offset: 2px;
}

/* Améliorer le contraste du bouton send au focus */
#aria-send:focus {
    background: var(--aria-primary-dark);
}

/* Support prefers-reduced-motion pour l'accessibilité */
@media (prefers-reduced-motion: reduce) {
    #aria-widget,
    #aria-chat,
    #aria-toggle,
    .aria-message,
    .aria-typing {
        animation: none !important;
        transition: none !important;
    }
    
    #aria-chat {
        animation: none !important;
    }
}

/* Améliorer le contraste des messages bot (WCAG 2.1 AA) */
.aria-message.bot {
    color: var(--aria-text);
    background: white;
    /* Contraste vérifié : texte #1f2937 sur blanc = 12.6:1 ✅ */
}

.aria-message.user {
    /* Contraste vérifié : blanc sur #6366f1 = 8.6:1 ✅ */
    color: white;
    background: var(--aria-user-bg);
}

/* Améliorer la visibilité des liens */
#aria-powered a {
    color: var(--aria-primary);
    text-decoration: underline;
}

#aria-powered a:hover,
#aria-powered a:focus {
    color: var(--aria-primary-dark);
    text-decoration: underline;
    outline: 1px solid var(--aria-primary);
    outline-offset: 2px;
}

