/* ==========================================================================
   VARIABLES ET CONFIGURATION
   ========================================================================== */

:root {
    /* Font settings */
    --font-family: 'Helvetica Neue', Arial, sans-serif;
    --font-color: #2d3748;            /* Couleur principale de la police */
    --font-color-light: #4a5568;      /* Couleur secondaire plus claire pour la police */
    --font-color-muted: #718096;      /* Couleur tertiaire atténuée pour éléments moins importants */
    
    /* Core colors - Polaris Asso theme exactes du logo */
    --background-color: #f8fafb;      /* Fond légèrement gris bleuté */
    --text-color: var(--font-color);  /* Utilise la couleur de police principale */
    --header-background-color: #ffffff;  /* Fond blanc pour l'en-tête */
    
    /* Couleurs exactes du logo Polaris */
    --primary-purple: #2e0e45;        /* Violet foncé du logo "polaris" */
    --primary-purple-light: #2e0e4530; /* Version transparente pour messages */
    --accent-teal: #4ecdc4;           /* Turquoise de l'étoile */
    --accent-cyan: #42b4d6;           /* Cyan bleu pour "asso" */
    --secondary-purple: #3d2a72;      /* Violet secondaire plus clair que le principal */
    
    /* Message colors */
    --message-user-bg: var(--primary-purple-light); /* Fond violet transparent pour messages utilisateur */
    --message-bot-bg: #ffffff;        /* Blanc pour messages bot */
    --message-user-text: var(--font-color); /* Texte pour messages utilisateur */
    --message-bot-text: var(--font-color);  /* Texte pour messages bot */
    
    /* Accent colors */
    --accent-orange: #ff9d5c;         /* Accent orange pour notifications/alertes */
    --accent-green: #86c28e;          /* Accent vert pour les éléments de succès */
    
    /* Button colors */
    --button-bg: var(--accent-cyan);  /* Bouton cyan comme le mot "asso" */
    --button-hover-bg: #39a4c3;       /* Version légèrement plus foncée pour hover */
    --button-text-color: #ffffff;     /* Texte blanc sur boutons */
    
    /* Input colors */
    --input-border-color: #e2e8f0;    /* Bordure gris clair pour inputs */
    --input-bg-color: #ffffff;        /* Fond blanc pour inputs */
    --input-focus-color: var(--accent-cyan); /* Focus cyan pour inputs */
    --input-text-color: var(--font-color); /* Couleur du texte dans les inputs */
    --input-placeholder-color: #a0aec0; /* Couleur du placeholder */
    
    /* Container */
    --container-border-color: #e2e8f0; /* Bordure légère pour le conteneur */
    
    /* Typing indicator */
    --typing-indicator-color: #718096; /* Couleur pour les points animés */
    --typing-indicator-bg: #ffffff;    /* Fond pour l'indicateur de frappe */
    --typing-indicator-text: var(--font-color-muted); /* Texte pour l'indicateur de frappe */
    
    /* Markdown colors */
    --markdown-header-color: var(--primary-purple); /* Titres en violet */
    --markdown-bg-color: #f7fafc;      /* Fond légèrement gris pour blocs de code */
    --code-bg-color: #f7fafc;          /* Fond pour code inline */
    --link-color: var(--accent-cyan);  /* Couleur des liens */
    --link-hover-color: var(--primary-purple); /* Couleur des liens au survol */
    
    /* Decorative elements */
    --border-radius: 12px;             /* Radius général */
    --message-border-radius: 12px;     /* Radius messages */
    --message-shadow: 0 2px 8px rgba(0, 0, 0, 0.05); /* Ombre légère */
    
    /* Typography */
    --message-line-height: 1.5;
    --font-size: 1em;
    --font-size-small: 0.875em;
    --font-size-large: 1.125em;
    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-bold: 600;
}

/* ==========================================================================
   RÉINITIALISATION
   ========================================================================== */

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ==========================================================================
   BASE
   ========================================================================== */

body {
    font-family: var(--font-family);
    background-color: var(--background-color);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100); /* Pour la prise en charge mobile */
    margin: 0;
    line-height: var(--message-line-height);
    overflow: hidden; /* Évite les barres de défilement inutiles */
}

/* Styles focus améliorés pour l'accessibilité */
:focus {
    outline: var(--focus-outline-width) solid var(--focus-outline-color);
    outline-offset: 2px;
}

/* Masquer les éléments accessibles uniquement pour les 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;
}

/* ==========================================================================
   HEADER
   ========================================================================== */

header {
    background-color: var(--header-background-color);
    text-align: center;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--input-border-color);
    box-shadow: 0 2px 4px rgba(128, 90, 213, 0.05);
    z-index: 10; /* Assurer que l'en-tête reste au-dessus */
}

.logo {
    width: 150px;
    height: auto;
    max-width: 100%;
    will-change: transform; /* Optimisation de performance pour les animations */
}

.text-entete {
    font-size: 1.2em;
    line-height: var(--message-line-height);
    max-width: 80%;
    margin: 0 auto;
    display: none;
    color: var(--text-color);
}

/* ==========================================================================
   ZONE DE CHAT
   ========================================================================== */

main {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    position: relative;
}

#chatbox {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin: 0 auto;
    width: 100%;
    background: var(--background-color);
    /* Optimisation des performances de défilement */
    will-change: scroll-position;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--accent-secondary) var(--background-color);
    contain: content; /* Optimisation du renderLayerCompositing */
}

/* Style personnalisé pour la barre de défilement */
#chatbox::-webkit-scrollbar {
    width: 8px;
}

#chatbox::-webkit-scrollbar-track {
    background: var(--background-color);
}

#chatbox::-webkit-scrollbar-thumb {
    background-color: var(--accent-secondary);
    border-radius: 20px;
    border: 2px solid var(--background-color);
}

#chatbox a {
    color: var(--accent-secondary);
    text-decoration: underline;
    transition: color 0.2s ease;
}

#chatbox a:hover {
    color: var(--accent-primary);
    text-decoration: underline;
}

#chatbox a:focus {
    outline: var(--focus-outline-width) solid var(--focus-outline-color);
    outline-offset: 2px;
}

/* ==========================================================================
   MESSAGES
   ========================================================================== */

.message {
    max-width: 80%;
    padding: 15px 20px;
    font-size: var(--font-size);
    line-height: var(--message-line-height);
    word-wrap: break-word;
    border-radius: var(--message-border-radius);
    box-shadow: var(--message-shadow);
    transform: translateZ(0); /* Force l'accélération GPU */
    will-change: transform, opacity; /* Optimisation pour les animations */
    animation: message-appear 0.3s ease-out forwards;
}

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

/* Messages de l'utilisateur */
.message.user {
    align-self: flex-end;
    background-color: var(--message-user-bg);
    color: var(--text-color);
    border-radius: var(--border-radius) var(--border-radius) 0 var(--border-radius);
}

/* Messages du chatbot */
.message.bot {
    align-self: flex-start;
    background-color: var(--message-bot-bg);
    color: var(--text-color);
    border-radius: var(--border-radius) var(--border-radius) var(--border-radius) 0;
    border: 1px solid var(--input-border-color);
}

/* Message d'erreur */
.message.error {
    background-color: rgba(255, 0, 0, 0.1);
    border: 1px solid rgba(255, 0, 0, 0.3);
    color: #ff6b6b;
}

/* ==========================================================================
   MARKDOWN DANS LES MESSAGES
   ========================================================================== */

.message.bot h1, 
.message.bot h2, 
.message.bot h3 {
    color: var(--markdown-header-color);
    margin-top: 15px;
    margin-bottom: 10px;
    font-weight: 600;
    line-height: 1.3;
}

.message.bot h1 {
    font-size: 1.5em;
    border-bottom: 1px solid var(--input-border-color);
    padding-bottom: 5px;
}

.message.bot h2 {
    font-size: 1.3em;
}

.message.bot h3 {
    font-size: 1.1em;
}

.message.bot ul,
.message.bot ol {
    padding-left: 20px;
    margin: 10px 0;
}

.message.bot ul {
    list-style-type: disc;
}

.message.bot ol {
    list-style-type: decimal;
}

.message.bot li {
    margin-bottom: 5px;
}

.message.bot pre {
    background: var(--markdown-bg-color);
    padding: 15px;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    overflow-x: auto;
    margin: 10px 0;
    border: 1px solid var(--input-border-color);
    white-space: pre-wrap;
}

.message.bot code {
    background: var(--code-bg-color);
    padding: 2px 5px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.message.bot a {
    color: var(--accent-primary);
    text-decoration: underline;
    transition: color 0.2s ease;
}

.message.bot a:hover {
    color: var(--accent-tertiary);
}

.message.bot blockquote {
    border-left: 4px solid var(--accent-secondary);
    padding-left: 10px;
    margin: 10px 0;
    color: rgba(230, 230, 230, 0.8);
    font-style: italic;
}

.message.bot table {
    border-collapse: collapse;
    margin: 15px 0;
    width: 100%;
}

.message.bot th,
.message.bot td {
    border: 1px solid var(--input-border-color);
    padding: 8px 12px;
    text-align: left;
}

.message.bot th {
    background-color: rgba(58, 80, 107, 0.3);
}

.message.bot img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 10px 0;
}

/* ==========================================================================
   INDICATEUR DE FRAPPE
   ========================================================================== */

.typing-indicator {
    display: flex;
    color: #2d3748 !important;
    align-items: center;
    gap: 8px;
    font-style: italic;
    color: #fff;
    align-self: flex-start;
    padding: 10px;
    border-radius: 10px;
    background: var(--message-bot-bg);
    font-size: 0.9em;
    animation: fade-in 0.3s ease-in-out;
    will-change: opacity, transform; /* Optimisation pour l'animation */
}

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

.typing-icon {
    width: 20px;
    height: 20px;
    transform: translateZ(0); /* Force l'accélération GPU */
}

.dot-container .dot {
    display: inline-block;
    width: 5px;
    height: 5px;
    margin-right: 3px;
    background-color: var(--typing-indicator-color);
    border-radius: 50%;
    animation: blink 1.5s infinite;
    will-change: opacity; /* Optimisation pour l'animation */
}

.dot-container .dot:nth-child(1) { animation-delay: 0s; }
.dot-container .dot:nth-child(2) { animation-delay: 0.2s; }
.dot-container .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
    0% { opacity: 0.3; }
    50% { opacity: 1; }
    100% { opacity: 0.3; }
}

/* ==========================================================================
   FORMULAIRE DE CHAT
   ========================================================================== */

#chatForm {
    display: flex;
    padding: 15px;
    background-color: var(--input-bg-color);
    border-top: 1px solid var(--input-border-color);
    position: relative;
    margin: 0 auto;
    width: 100%;
    z-index: 5; /* Assurer que le formulaire reste au-dessus */
}

#userInput {
    flex: 1;
    padding: 12px 15px;
    border: 1px solid var(--input-border-color);
    border-radius: var(--border-radius);
    font-size: var(--font-size);
    outline: none;
    background-color: var(--input-bg-color);
    color: var(--text-color);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

#userInput:focus {
    border-color: var(--button-bg);
    box-shadow: 0 0 0 2px rgba(255, 215, 0, 0.25);
}

#userInput::placeholder {
    color: rgba(230, 230, 230, 0.5);
}

#chatForm button {
    background-color: var(--button-bg);
    color: var(--button-text-color);
    border: none;
    border-radius: var(--border-radius);
    padding: 12px 25px;
    margin-left: 10px;
    font-size: var(--font-size);
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.1s ease;
    position: relative;
    overflow: hidden;
}

#chatForm button:hover {
    background-color: var(--button-hover-bg);
}

#chatForm button:active {
    transform: scale(0.98);
}

#chatForm button::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 5px;
    height: 5px;
    background: rgba(255, 255, 255, 0.5);
    opacity: 0;
    border-radius: 100%;
    transform: scale(1, 1) translate(-50%, -50%);
    transform-origin: 50% 50%;
}

#chatForm button:focus:not(:active)::after {
    animation: ripple 0.6s ease-out;
}

@keyframes ripple {
    0% {
        transform: scale(0, 0);
        opacity: 0.5;
    }
    100% {
        transform: scale(20, 20);
        opacity: 0;
    }
}

/* ==========================================================================
   PLACEHOLDER DE BIENVENUE
   ========================================================================== */

#welcome-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 30px;
    border-radius: var(--message-border-radius);
    background-color: var(--message-bot-bg);
    box-shadow: var(--message-shadow);
    max-width: 80%;
    transition: opacity 0.5s ease, transform 0.5s ease;
    z-index: 1;
    border: 1px solid var(--input-border-color);
    will-change: opacity, transform; /* Optimisation pour l'animation */
}

#welcome-placeholder h1 {
    color: var(--accent-primary);
    margin: 15px 0;
    font-size: 1.8em;
    line-height: 1.3;
}

#welcome-placeholder p {
    color: var(--text-color);
    margin: 10px 0 20px;
    line-height: 1.6;
    font-size: 1.1em;
}

.placeholder-logo {
    width: 120px;
    height: auto;
    margin-bottom: 10px;
    will-change: transform; /* Optimisation pour l'animation */
}

.placeholder-stars {
    display: flex;
    justify-content: center;
    margin-top: 20px;
    width: 100%;
}

.star {
    width: 15px;
    height: 15px;
    background-color: var(--accent-primary);
    clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
    margin: 0 10px;
    animation: twinkle 2s infinite;
    will-change: opacity, transform; /* Optimisation pour l'animation */
    background-color: #4fb5d7;
}

/* Fallback pour les navigateurs qui ne supportent pas clip-path */
@supports not (clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%)) {
    .star {
        border-radius: 50%;
        transform: rotate(45deg);
    }
}

.star:nth-child(1) { animation-delay: 0s; }
.star:nth-child(2) { animation-delay: 0.4s; }
.star:nth-child(3) { animation-delay: 0.8s; }

@keyframes twinkle {
    0% { opacity: 0.3; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1.2); }
    100% { opacity: 0.3; transform: scale(0.8); }
}

/* ==========================================================================
   PIED DE PAGE
   ========================================================================== */

.privacy-notice {
    background-color: var(--header-background-color);
    text-align: center;
    padding: 10px;
    font-size: 0.8em;
    border-top: 1px solid var(--input-border-color);
}

.privacy-notice a {
    color: var(--accent-secondary);
    text-decoration: underline;
}

.privacy-notice a:hover {
    color: var(--accent-primary);
}

/* ==========================================================================
   RESPONSIVE DESIGN
   ========================================================================== */

@media (max-width: 768px) {
    .text-entete {
        font-size: 1em;
        padding: 10px;
    }
    
    #welcome-placeholder {
        max-width: 90%;
        padding: 20px;
    }
    
    #welcome-placeholder h1 {
        font-size: 1.5em;
    }
    
    .message {
        max-width: 85%;
    }

    .placeholder-logo {
        display: none;
    }
}

@media (max-width: 480px) {
    header {
        padding: 15px 10px;
    }

    .logo {
        width: 120px;
    }
    
    #chatbox {
        padding: 10px;
    }
    
    #chatForm {
        padding: 10px;
    }
    
    #chatForm button {
        padding: 10px 15px;
        margin-left: 5px;
    }
    
    .message {
        max-width: 90%;
        padding: 12px 15px;
        font-size: 0.95em;
    }

    #welcome-placeholder {
        width: 90%; /* Force exactement 90% de largeur sur mobile */
        padding: 15px; /* Vous pourriez réduire légèrement le padding pour les très petits écrans */
    }
    
    #welcome-placeholder h1 {
        font-size: 1.3em;
    }
    
    #welcome-placeholder p {
        font-size: 1em;
    }
}

/* Fix pour iOS Safari - hauteur de viewport */
@supports (-webkit-touch-callout: none) {
    body {
        height: -webkit-fill-available;
    }
}

/* Préfixes vendeurs pour les propriétés CSS avancées */
@supports (-ms-ime-align: auto) {
    /* Fixes pour Microsoft Edge */
    .message {
        box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
    }
}



/* Styles pour les liens de formulaires et QR codes */
a[data-form-link="true"],
a[data-qr-link="true"] {
    position: relative;
    padding-right: 1.5em;
    text-decoration: underline;
    transition: color 0.2s ease;
}

/* Icône de formulaire */
a[data-form-link="true"]::after {
    content: "📝";
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.9em;
}

/* Icône de QR code */
a[data-qr-link="true"]::after {
    content: "📱";
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.9em;
}

/* Animation de pulsation pour attirer l'attention */
@keyframes pulse {
    0% { transform: translateY(-50%) scale(1); }
    50% { transform: translateY(-50%) scale(1.1); }
    100% { transform: translateY(-50%) scale(1); }
}

/* Appliquer l'animation aux icônes */
a[data-form-link="true"]::after,
a[data-qr-link="true"]::after {
    animation: pulse 2s infinite;
}

/* Effet de survol pour les liens spéciaux */
a[data-form-link="true"]:hover,
a[data-qr-link="true"]:hover {
    color: var(--accent-primary);
}

/* Overlay pour les QR codes sur mobile */
.popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(10, 17, 40, 0.9);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

.popup-content {
    width: 90%;
    max-width: 500px;
    background-color: #1c2541;
    border-radius: 12px;
    padding: 20px;
    max-height: 80vh;
    overflow-y: auto;
    border: 2px solid #ffd700;
    color: #e6e6e6;
    text-align: center;
}

.popup-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background-color: #ffd700;
    color: #0a1128;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.popup-close:hover {
    background-color: #f8c537;
}

/* Empêcher le défilement quand l'overlay est actif */
body.overflow-hidden {
    overflow: hidden;
    height: 100%;
    position: fixed;
    width: 100%;
}