/* =========================================
   1. CONFIGURATION & VARIABLES
   ========================================= */
:root {
    --ia-primary: #872D84;
    --ia-accent: #04C360;
    --ia-bg: #faf5f1;
    --ia-panel-bg: #f7f9fb;
    --ia-text: #2c3e50;
    --ia-muted: #6b7280;
    --ia-danger: #b00020;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --shadow-soft: 0 4px 15px rgba(0,0,0,0.05);
}

* { box-sizing: border-box; }

/* =========================================
   2. INTÉGRATION WIDGET (BASE.HTML)
   ========================================= */

#chatbot-toggler {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    background: var(--ia-panel-bg);
    border-radius: 50%;
    color: var(--ia-text);
    border: 1px solid rgba(152, 152, 152, 0.25);
    font-size: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(150, 150, 150, 0.4);
    z-index: 20000;
    transition: transform 0.3s ease;
}

#chatbot-toggler:hover { transform: scale(1.1); }
#chatbot-toggler.active { transform: rotate(90deg); background: #e74c3c; }

/* CONTENEUR DU WIDGET - TAILLE MAXIMALE */
#chatbot-widget-container {
    position: fixed;
    bottom: 100px;
    right: 30px;

    width: 500px;
    height: 85vh;
    max-height: 900px;

    background: var(--ia-bg);
    border-radius: 16px;
    box-shadow: var(--shadow-soft);
    z-index: 19999;
    overflow: hidden;

    opacity: 0;
    transform: translateY(20px) scale(0.95);
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

#chatbot-widget-container iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

/* =========================================
   3. INTERFACE INTERNE (CHATBOT.HTML)
   ========================================= */

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    background-color: var(--ia-panel-bg);
    overflow: hidden;
}

/* --- HEADER FIXE --- */
.chat-header {
    flex: 0 0 auto;
    background: linear-gradient(135deg, var(--ia-primary), var(--ia-accent));
    padding: 15px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #faf5f1;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 10;
}

.header-info h2 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* --- MESSAGES --- */
.messages-area {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: fadeIn 0.3s ease;
}

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

.message.utilisateur { align-self: flex-end; align-items: flex-end; }
.message.robot { align-self: flex-start; align-items: flex-start; }

.bubble {
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.5;
    font-size: 0.95rem;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.message.utilisateur .bubble { background: var(--ia-primary); color: #faf5f1; border-bottom-right-radius: 2px; }
.message.robot .bubble { background: var(--ia-bg); color: var(--ia-text); border-bottom-left-radius: 2px; }

.time { font-size: 0.7rem; color: var(--ia-muted); margin-top: 4px; }

.message-speaker-btn {
    background: none;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    padding: 2px;
    margin-top: 2px;
}
.message-speaker-btn:hover { color: var(--ia-primary); }

/* --- INPUT AREA (FIXE & ALIGNÉ) --- */
.input-area {
    flex: 0 0 auto; /* Fixe en hauteur */
    padding: 12px;
    background: #faf5f1;
    border-top: 1px solid #eee;

    /* Conteneur Flex pour centrer le formulaire */
    display: flex;
    align-items: center;
    justify-content: center;
}

#chatForm {
    /* Mise en page LIGNE stricte */
    display: flex;
    flex-direction: row;
    align-items: center;
    flex-wrap: nowrap; /* INTERDICTION de passer à la ligne */

    width: 100%;
    gap: 8px; /* Espace entre les éléments */
}

/* 1. Le Dictaphone */
.mic-btn {
    flex: 0 0 auto; /* Garde sa taille naturelle */
    font-size: 1.2rem;
    color: #9ca3af;
    padding: 8px;
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}
.mic-btn:hover { color: var(--ia-primary); }
.mic-btn.recording { color: #e74c3c; animation: pulse 1.5s infinite; }

/* 2. La Zone de Texte */
.input-wrapper {
    flex: 1 1 auto; /* Prend tout l'espace disponible */
    min-width: 0;   /* Empêche le débordement sur petit écran */

    display: flex;
    align-items: center;
    background: #f0f2f5;
    border-radius: 24px;
    padding: 8px 16px;
    height: 44px; /* Hauteur fixe pour alignement propre */
}

#userMessage {
    width: 100%;
    border: none;
    background: transparent;
    outline: none;
    font-size: 1rem;
    font-family: inherit;
    color: #333;
}

/* 3. Le Bouton Envoyer */
#sendBtn {
    flex: 0 0 auto; /* Garde sa taille fixe */
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ia-accent), #039e50);
    color: #faf5f1;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(4, 195, 96, 0.2);
    transition: transform 0.2s;
}
#sendBtn:hover { transform: scale(1.05); }

/* Animation écriture */
.typing span {
    display: inline-block; width: 6px; height: 6px; background: #9ca3af;
    border-radius: 50%; margin-right: 3px; animation: bounce 1.4s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* =========================================
   4. RESPONSIVE
   ========================================= */
@media (max-width: 768px) {
    #chatbot-widget-container {
        width: 100%;
        height: 100%;
        max-height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }
    #chatbot-toggler { bottom: 20px; right: 20px; width: 50px; height: 50px; }
}

/* ... (Garder tout le CSS précédent) ... */

/* Ajout pour le bouton fermer dans le header */
.close-chat-btn {
    background: transparent;
    border: none;
    color: #faf5f1;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: auto; /* Pousse le bouton à droite si besoin */
}

.close-chat-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ... (Le reste du CSS reste identique, notamment la section Responsive) ... */