/**
 * Chatbot IA - CSS Complet avec Messages Riches - Repousse les Limites
 * Fichier : /wp-content/themes/astra-child/chatbotIA/chatbot.css
 * Version : 1.2.0 - Support formatage HTML sécurisé
 */

:root {
    /* Charte Repousse les Limites */
    --primary: #bf360c;
    --accent: #e65100;
    --white: #ffffff;
    --text: #1c1c1c;
    --border: #eaeaea;
    --background: #fafafa;
    --placeholder: #9CA3AF;
    
    /* Avatar Miguel Termet - Variable corrigée pour correspondre au JavaScript */
    --chatbot-avatar-url: url('https://repousseleslimites.com/wp-content/uploads/2025/08/MiguelTermetIA.webp');
    
    /* Variables pour safe areas mobiles */
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
    
    /* Variables pour messages riches */
    --chatbot-rich-bg: rgba(191, 54, 12, 0.05);
    --chatbot-rich-border: rgba(191, 54, 12, 0.2);
    --chatbot-code-bg: rgba(191, 54, 12, 0.1);
    --chatbot-quote-border: var(--primary);
}

/* Correction viewport pour mobiles problématiques */
@-webkit-viewport { width: device-width; }
@-moz-viewport { width: device-width; }
@-ms-viewport { width: device-width; }
@-o-viewport { width: device-width; }
@viewport { width: device-width; }

/* Reset simple */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* ================================
   BULLE FLOTTANTE
   ================================ */

.chatbot-bubble {
    position: fixed;
    bottom: clamp(1rem, 3vh, 2rem);
    right: clamp(1rem, 3vw, 2rem);
    width: clamp(3.5rem, 10vw, 4.5rem);
    height: clamp(3.5rem, 10vw, 4.5rem);
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 50%;
    box-shadow: 0 0.25rem 1rem rgba(191, 54, 12, 0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999999;
    transition: all 0.3s ease;
    padding: 0.25rem;
    overflow: hidden;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Positions flexibles */
.chatbot-bubble.bottom-left {
    left: clamp(1rem, 3vw, 2rem);
    right: auto;
}

.chatbot-bubble.top-right {
    top: clamp(1rem, 3vh, 2rem);
    bottom: auto;
}

.chatbot-bubble.top-left {
    top: clamp(1rem, 3vh, 2rem);
    left: clamp(1rem, 3vw, 2rem);
    bottom: auto;
    right: auto;
}

/* Tailles */
.chatbot-bubble.small {
    width: clamp(3rem, 8vw, 3.5rem);
    height: clamp(3rem, 8vw, 3.5rem);
}

.chatbot-bubble.large {
    width: clamp(4rem, 12vw, 5rem);
    height: clamp(4rem, 12vw, 5rem);
}

/* États */
.chatbot-bubble:hover {
    transform: scale(1.05);
    box-shadow: 0 0.375rem 1.25rem rgba(191, 54, 12, 0.4);
}

.chatbot-bubble.minimized {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
}

.chatbot-bubble.pulse {
    animation: pulse 2s infinite;
}

/* Avatar Miguel - Variable corrigée */
.chatbot-bubble::before {
    content: '';
    position: absolute;
    inset: 0.25rem;
    background-image: var(--chatbot-avatar-url);
    background-size: cover;
    background-position: center;
    border-radius: 50%;
}

.chatbot-bubble svg {
    display: none;
}

/* Badge notification */
.chatbot-notification-badge {
    position: absolute;
    top: -0.3rem;
    right: -0.3rem;
    background: var(--accent);
    color: var(--white);
    border-radius: 50%;
    width: 1.25rem;
    height: 1.25rem;
    font-size: 0.7rem;
    display: none;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    animation: bounce 2s infinite;
    border: 2px solid var(--white);
}

/* ================================
   MODAL DU CHAT
   ================================ */

.chatbot-modal {
    position: fixed;
    bottom: clamp(1rem, 5vh, 6rem);
    right: clamp(1rem, 3vw, 2rem);
    width: min(90vw, 24rem);
    height: min(80vh, 35rem);
    background: var(--white);
    border-radius: clamp(0.5rem, 2vw, 1rem);
    box-shadow: 0 0.5rem 2rem rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    z-index: 999998;
    font-family: system-ui, -apple-system, sans-serif;
    overflow: hidden;
    border: 1px solid rgba(191, 54, 12, 0.1);
}

/* Positions */
.chatbot-modal.bottom-left {
    left: clamp(1rem, 3vw, 2rem);
    right: auto;
}

.chatbot-modal.top-right {
    top: clamp(1rem, 5vh, 6rem);
    bottom: auto;
}

.chatbot-modal.top-left {
    top: clamp(1rem, 5vh, 6rem);
    left: clamp(1rem, 3vw, 2rem);
    bottom: auto;
    right: auto;
}

.chatbot-modal.open {
    display: flex;
    animation: slideUp 0.3s ease;
}

/* Mobile plein écran - Correction Huawei/Android */
@media (max-width: 30rem) {
    .chatbot-modal {
        position: fixed !important;
        /* Utilisation des safe areas avec fallback */
        top: max(var(--safe-top), 0px) !important;
        left: env(safe-area-inset-left, 0px) !important;
        right: env(safe-area-inset-right, 0px) !important;
        bottom: max(var(--safe-bottom), 2rem) !important; /* 2rem minimum pour barres Android */
        
        width: calc(100vw - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)) !important;
        /* Hauteur calculée pour éviter les barres système */
        height: calc(
            100vh 
            - max(var(--safe-top), 0px) 
            - max(var(--safe-bottom), 2rem) 
            - 1rem
        ) !important;
        
        border-radius: 0 !important;
        animation: slideUpMobile 0.3s ease;
        
        /* Sécurité supplémentaire */
        max-height: calc(100vh - 3rem);
        min-height: 20rem;
    }
    
    /* Zone de saisie avec marge renforcée */
    .chatbot-input-container {
        padding-bottom: max(
            1.5rem,
            calc(var(--safe-bottom) + 1rem),
            2.5rem
        ) !important;
        /* Arrière-plan étendu pour éviter les transparences */
        background: linear-gradient(to bottom, var(--white) 80%, var(--white) 100%);
        box-shadow: 0 -0.5rem 1rem rgba(0, 0, 0, 0.1);
    }
    
    /* Messages ajustés */
    .chatbot-messages {
        /* Padding bottom réduit pour compenser la marge de l'input */
        padding-bottom: 0.5rem;
    }
}

/* ================================
   HEADER
   ================================ */

.chatbot-header {
    padding: clamp(0.75rem, 2vh, 1rem);
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: var(--white);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    flex-shrink: 0;
}

.chatbot-header::before {
    content: '';
    position: absolute;
    left: clamp(0.75rem, 2vh, 1rem);
    top: 50%;
    transform: translateY(-50%);
    width: clamp(1.5rem, 4vw, 2rem);
    height: clamp(1.5rem, 4vw, 2rem);
    background-image: var(--chatbot-avatar-url);
    background-size: cover;
    background-position: center;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.chatbot-title {
    font-size: clamp(0.875rem, 3vw, 1rem);
    font-weight: 600;
    margin-left: clamp(2.5rem, 6vw, 3rem);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chatbot-quota {
    font-size: clamp(0.6875rem, 2.5vw, 0.75rem);
    opacity: 0.9;
    margin-top: 0.125rem;
    margin-left: clamp(2.5rem, 6vw, 3rem);
}

.chatbot-close {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--white);
    font-size: 1.125rem;
    cursor: pointer;
    padding: 0.25rem;
    width: 1.75rem;
    height: 1.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.375rem;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chatbot-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

/* ================================
   MESSAGES
   ================================ */

.chatbot-messages {
    flex: 1;
    padding: clamp(0.75rem, 2vh, 1rem);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: clamp(0.5rem, 1.5vh, 0.75rem);
    background: var(--background);
    min-height: 0;
}

.chatbot-messages::-webkit-scrollbar {
    width: 0.375rem;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: rgba(191, 54, 12, 0.3);
    border-radius: 0.1875rem;
}

.chatbot-message {
    max-width: 85%;
    padding: clamp(0.5rem, 1.5vh, 0.75rem) clamp(0.75rem, 2vw, 1rem);
    border-radius: 0.75rem;
    font-size: clamp(0.8125rem, 3vw, 0.875rem);
    line-height: 1.5;
    word-wrap: break-word;
    position: relative;
    flex-shrink: 0;
    overflow-wrap: break-word;
}

.chatbot-message.user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: var(--white);
    border-bottom-right-radius: 0.25rem;
    margin-left: auto;
}

.chatbot-message.assistant {
    align-self: flex-start;
    background: var(--white);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 0.25rem;
    padding-left: clamp(2rem, 5vw, 2.5rem);
    margin-right: auto;
}

.chatbot-message.assistant::before {
    content: '';
    position: absolute;
    left: clamp(0.5rem, 1.5vw, 0.75rem);
    top: clamp(0.5rem, 1.5vh, 0.75rem);
    width: clamp(1.25rem, 3vw, 1.5rem);
    height: clamp(1.25rem, 3vw, 1.5rem);
    background-image: var(--chatbot-avatar-url);
    background-size: cover;
    background-position: center;
    border-radius: 50%;
    border: 1px solid var(--border);
}

.chatbot-message.system {
    align-self: center;
    background: var(--accent);
    color: var(--white);
    font-size: clamp(0.75rem, 2.5vw, 0.8125rem);
    text-align: center;
    opacity: 0.9;
    margin: 0 auto;
}

/* ================================
   STYLES POUR MESSAGES RICHES
   ================================ */

/* Paragraphes dans les messages */
.chatbot-message p {
    margin: 0 0 clamp(0.5rem, 1vh, 0.75rem) 0;
    line-height: 1.5;
}

.chatbot-message p:last-child {
    margin-bottom: 0;
}

.chatbot-message p:first-child {
    margin-top: 0;
}

/* Texte en gras */
.chatbot-message strong,
.chatbot-message b {
    font-weight: 600;
    color: var(--primary);
}

/* Messages utilisateur - gras en blanc */
.chatbot-message.user strong,
.chatbot-message.user b {
    color: var(--white);
    font-weight: 700;
}

/* Texte en italique */
.chatbot-message em,
.chatbot-message i {
    font-style: italic;
    color: var(--text);
}

.chatbot-message.user em,
.chatbot-message.user i {
    color: var(--white);
}

/* Titres dans les messages */
.chatbot-message h3,
.chatbot-message h4,
.chatbot-message h5,
.chatbot-message h6 {
    font-weight: 600;
    color: var(--primary);
    margin: clamp(0.75rem, 2vh, 1rem) 0 clamp(0.375rem, 1vh, 0.5rem) 0;
    line-height: 1.3;
}

.chatbot-message h3:first-child,
.chatbot-message h4:first-child,
.chatbot-message h5:first-child,
.chatbot-message h6:first-child {
    margin-top: 0;
}

.chatbot-message h3 {
    font-size: clamp(0.9375rem, 3.5vw, 1rem);
}

.chatbot-message h4 {
    font-size: clamp(0.875rem, 3vw, 0.9375rem);
}

.chatbot-message h5,
.chatbot-message h6 {
    font-size: clamp(0.8125rem, 2.5vw, 0.875rem);
}

/* Messages utilisateur - titres en blanc */
.chatbot-message.user h3,
.chatbot-message.user h4,
.chatbot-message.user h5,
.chatbot-message.user h6 {
    color: var(--white);
}

/* Listes */
.chatbot-message ul,
.chatbot-message ol {
    margin: clamp(0.5rem, 1.5vh, 0.75rem) 0;
    padding-left: clamp(1rem, 3vw, 1.25rem);
    line-height: 1.4;
}

.chatbot-message ul:first-child,
.chatbot-message ol:first-child {
    margin-top: 0;
}

.chatbot-message ul:last-child,
.chatbot-message ol:last-child {
    margin-bottom: 0;
}

.chatbot-message ul {
    list-style-type: none;
    position: relative;
}

.chatbot-message ol {
    list-style-type: decimal;
    list-style-position: outside;
}

.chatbot-message li {
    margin-bottom: clamp(0.25rem, 1vh, 0.375rem);
    position: relative;
}

.chatbot-message li:last-child {
    margin-bottom: 0;
}

/* Puces personnalisées pour les listes */
.chatbot-message ul li::before {
    content: '•';
    color: var(--primary);
    font-weight: bold;
    position: absolute;
    left: -clamp(0.75rem, 2vw, 1rem);
    top: 0;
}

/* Messages utilisateur - puces en blanc */
.chatbot-message.user ul li::before {
    color: var(--white);
}

/* Code inline */
.chatbot-message code {
    background: var(--chatbot-code-bg);
    color: var(--primary);
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-size: 0.85em;
    font-weight: 500;
}

/* Messages utilisateur - code avec fond blanc transparent */
.chatbot-message.user code {
    background: rgba(255, 255, 255, 0.2);
    color: var(--white);
}

/* Blocs de code */
.chatbot-message pre {
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    padding: clamp(0.5rem, 1.5vh, 0.75rem);
    margin: clamp(0.5rem, 1.5vh, 0.75rem) 0;
    overflow-x: auto;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-size: 0.8125rem;
    line-height: 1.4;
}

.chatbot-message pre:first-child {
    margin-top: 0;
}

.chatbot-message pre:last-child {
    margin-bottom: 0;
}

.chatbot-message pre code {
    background: none;
    padding: 0;
    color: var(--text);
}

/* Citations */
.chatbot-message blockquote {
    border-left: 0.25rem solid var(--primary);
    margin: clamp(0.5rem, 1.5vh, 0.75rem) 0;
    padding-left: clamp(0.75rem, 2vw, 1rem);
    font-style: italic;
    color: var(--text);
    opacity: 0.9;
    background: var(--chatbot-rich-bg);
    border-radius: 0 0.25rem 0.25rem 0;
}

.chatbot-message blockquote:first-child {
    margin-top: 0;
}

.chatbot-message blockquote:last-child {
    margin-bottom: 0;
}

/* Messages utilisateur - citations */
.chatbot-message.user blockquote {
    border-left-color: var(--white);
    background: rgba(255, 255, 255, 0.1);
    color: var(--white);
}

/* Mise en évidence */
.chatbot-message mark {
    background: rgba(230, 81, 0, 0.2);
    color: var(--text);
    padding: 0.0625rem 0.125rem;
    border-radius: 0.125rem;
}

.chatbot-message.user mark {
    background: rgba(255, 255, 255, 0.3);
    color: var(--white);
}

/* Texte petit */
.chatbot-message small {
    font-size: 0.75em;
    opacity: 0.8;
}

/* Indices et exposants */
.chatbot-message sub,
.chatbot-message sup {
    font-size: 0.6875em;
    line-height: 0;
}

/* Texte barré */
.chatbot-message del {
    text-decoration: line-through;
    opacity: 0.7;
}

/* Texte inséré */
.chatbot-message ins {
    text-decoration: underline;
    text-decoration-color: var(--accent);
    background: rgba(230, 81, 0, 0.1);
}

.chatbot-message.user ins {
    background: rgba(255, 255, 255, 0.2);
}

/* Classes CSS ajoutées dynamiquement */
.chatbot-message .chatbot-list {
    /* Styles déjà définis ci-dessus */
}

.chatbot-message .chatbot-list.numbered {
    /* Styles déjà définis ci-dessus */
}

.chatbot-message .chatbot-list-item {
    /* Styles déjà définis ci-dessus */
}

.chatbot-message .chatbot-code {
    /* Styles déjà définis ci-dessus */
}

.chatbot-message .chatbot-heading {
    /* Styles déjà définis ci-dessus */
}

.chatbot-message .chatbot-quote {
    /* Styles déjà définis ci-dessus */
}

/* ================================
   INDICATEUR DE FRAPPE
   ================================ */

.chatbot-typing {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: clamp(0.5rem, 1.5vh, 0.75rem) clamp(0.75rem, 2vw, 1rem) clamp(0.5rem, 1.5vh, 0.75rem) clamp(2rem, 5vw, 2.5rem);
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    border-bottom-left-radius: 0.25rem;
    max-width: 85%;
    font-size: clamp(0.8125rem, 3vw, 0.875rem);
    color: var(--text);
    position: relative;
    margin-right: auto;
}

.chatbot-typing::before {
    content: '';
    position: absolute;
    left: clamp(0.5rem, 1.5vw, 0.75rem);
    top: 50%;
    transform: translateY(-50%);
    width: clamp(1.25rem, 3vw, 1.5rem);
    height: clamp(1.25rem, 3vw, 1.5rem);
    background-image: var(--chatbot-avatar-url);
    background-size: cover;
    background-position: center;
    border-radius: 50%;
    border: 1px solid var(--border);
}

.chatbot-typing-dots {
    display: flex;
    gap: 0.125rem;
    align-items: center;
}

.chatbot-typing-dot {
    width: 0.375rem;
    height: 0.375rem;
    background: var(--primary);
    border-radius: 50%;
    animation: typingDot 1.4s infinite ease-in-out;
}

.chatbot-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.chatbot-typing-dot:nth-child(2) { animation-delay: -0.16s; }
.chatbot-typing-dot:nth-child(3) { animation-delay: 0s; }

/* ================================
   ZONE DE SAISIE - ALIGNEMENT + SAFE AREA ROBUSTE
   ================================ */

.chatbot-input-container {
    padding: clamp(0.75rem, 2vh, 1rem);
    background: var(--white);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    /* Protection robuste pour barres système mobiles */
    padding-bottom: max(
        clamp(0.75rem, 2vh, 1rem), 
        calc(var(--safe-bottom) + 0.5rem),
        1.5rem
    );
}

.chatbot-input-group {
    display: flex;
    gap: clamp(0.5rem, 1.5vw, 0.75rem);
    align-items: stretch; /* Alignement parfait */
    height: clamp(2.75rem, 6vh, 3rem); /* Hauteur fixe */
    position: relative;
    z-index: 10; /* Au-dessus des barres système */
}

.chatbot-input {
    flex: 1;
    min-width: 0;
    padding: clamp(0.75rem, 2vh, 1rem);
    border: 2px solid var(--border);
    border-radius: 0.625rem;
    font-size: clamp(1rem, 3.5vw, 1rem);
    font-family: inherit;
    resize: none;
    background: var(--white);
    color: var(--text);
    line-height: 1.4;
    transition: all 0.3s ease;
    overflow-y: auto;
    overflow-x: hidden;
    /* Hauteur fixe pour maintenir l'alignement avec le bouton */
    height: 100%;
    /* Désactiver le redimensionnement automatique pour garder l'alignement */
    min-height: unset;
    max-height: unset;
}

.chatbot-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 0.1875rem rgba(191, 54, 12, 0.1);
}

.chatbot-input::placeholder {
    color: var(--placeholder);
    font-style: italic;
}

.chatbot-send {
    width: clamp(2.75rem, 6vh, 3rem);
    height: 100%; /* Prend la hauteur du conteneur pour parfait alignement */
    padding: 0;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: var(--white);
    border: none;
    border-radius: 0.625rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.chatbot-send:hover:not(:disabled) {
    transform: translateY(-0.0625rem);
    box-shadow: 0 0.25rem 0.75rem rgba(191, 54, 12, 0.3);
}

.chatbot-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.chatbot-send svg {
    width: clamp(1rem, 3vw, 1.125rem);
    height: clamp(1rem, 3vw, 1.125rem);
    fill: currentColor;
}

/* ================================
   LOADING SPINNER
   ================================ */

.chatbot-spinner {
    width: clamp(1rem, 3vw, 1.125rem);
    height: clamp(1rem, 3vw, 1.125rem);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid var(--white);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* ================================
   OVERLAY
   ================================ */

.chatbot-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    display: none;
    z-index: 999997;
    backdrop-filter: blur(0.125rem);
}

.chatbot-overlay.active {
    display: block;
}

/* ================================
   ANIMATIONS
   ================================ */

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(1.25rem) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes slideUpMobile {
    from {
        opacity: 0;
        transform: translateY(100%);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0%, 100% { 
        transform: scale(1);
        box-shadow: 0 0.25rem 1rem rgba(191, 54, 12, 0.3);
    }
    50% { 
        transform: scale(1.05);
        box-shadow: 0 0.375rem 1.25rem rgba(191, 54, 12, 0.5);
    }
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-0.5rem); }
    60% { transform: translateY(-0.25rem); }
}

@keyframes typingDot {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Animation pour les nouveaux éléments formatés */
.chatbot-message.assistant ul,
.chatbot-message.assistant ol,
.chatbot-message.assistant h3,
.chatbot-message.assistant h4,
.chatbot-message.assistant h5,
.chatbot-message.assistant h6,
.chatbot-message.assistant blockquote {
    animation: fadeInUp 0.3s ease-out;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(0.5rem);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ================================
   CORRECTIONS SPÉCIFIQUES HUAWEI/ANDROID
   ================================ */

/* Classe ajoutée dynamiquement par JS sur appareils problématiques */
.chatbot-modal.force-safe-mobile {
    bottom: 4rem !important;
    height: calc(100vh - 6rem) !important;
    max-height: calc(100vh - 6rem) !important;
}

.chatbot-modal.force-safe-mobile .chatbot-input-container {
    padding-bottom: 3rem !important;
    margin-bottom: 0 !important;
    box-shadow: 0 -1rem 2rem rgba(0, 0, 0, 0.15);
}

/* Détection User-Agent pour Huawei (fallback CSS) */
@media (max-width: 30rem) {
    /* Sécurité maximale pour tous les Android */
    .chatbot-modal {
        /* Ajout d'une marge de sécurité de 64px en bas */
        padding-bottom: 2rem;
    }
    
    .chatbot-input-container {
        /* Position relative avec z-index élevé */
        position: relative;
        z-index: 1000;
        background: var(--white);
        border-top: 2px solid var(--border);
    }
}

/* ================================
   RESPONSIVE SUPPLÉMENTAIRE + CORRECTIONS MOBILES
   ================================ */

/* Ajustements pour très petits écrans */
@media (max-width: 20rem) {
    .chatbot-input-group {
        height: clamp(2.5rem, 8vw, 2.75rem);
        gap: 0.5rem;
    }
    
    .chatbot-input {
        font-size: 1rem; /* Taille fixe pour éviter le zoom sur iOS */
        padding: 0.625rem;
    }
    
    .chatbot-send {
        width: clamp(2.5rem, 8vw, 2.75rem);
    }
    
    /* Messages riches sur petits écrans */
    .chatbot-message ul,
    .chatbot-message ol {
        padding-left: clamp(0.75rem, 4vw, 1rem);
    }
    
    .chatbot-message li {
        font-size: clamp(0.8125rem, 3.5vw, 0.875rem);
    }
    
    .chatbot-message h3,
    .chatbot-message h4,
    .chatbot-message h5,
    .chatbot-message h6 {
        margin: clamp(0.5rem, 2vh, 0.75rem) 0 clamp(0.25rem, 1vh, 0.375rem) 0;
    }
    
    .chatbot-message code {
        font-size: 0.8em;
        padding: 0.1rem 0.2rem;
    }
}

/* Mode paysage mobile */
@media (max-height: 30rem) and (orientation: landscape) {
    .chatbot-modal {
        height: 85vh !important;
    }
    
    .chatbot-input-group {
        height: 2.5rem;
    }
    
    .chatbot-input-container {
        padding-bottom: 1rem;
    }
    
    /* Ajustements pour messages riches en mode paysage */
    .chatbot-message {
        padding: 0.5rem 0.75rem;
    }
    
    .chatbot-message h3,
    .chatbot-message h4,
    .chatbot-message h5,
    .chatbot-message h6 {
        margin: 0.5rem 0 0.25rem 0;
    }
    
    .chatbot-message ul,
    .chatbot-message ol {
        margin: 0.375rem 0;
    }
}

/* Espacement entre les éléments formatés */
.chatbot-message > *:not(:last-child) {
    margin-bottom: clamp(0.375rem, 1vh, 0.5rem);
}

.chatbot-message > ul:not(:last-child),
.chatbot-message > ol:not(:last-child),
.chatbot-message > blockquote:not(:last-child),
.chatbot-message > pre:not(:last-child),
.chatbot-message > h3:not(:last-child),
.chatbot-message > h4:not(:last-child),
.chatbot-message > h5:not(:last-child),
.chatbot-message > h6:not(:last-child) {
    margin-bottom: clamp(0.5rem, 1.5vh, 0.75rem);
}

/* Amélioration de la lisibilité */
.chatbot-message.assistant {
    line-height: 1.5;
}

/* États de focus pour accessibilité */
.chatbot-message:focus-within {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Print styles */
@media print {
    .chatbot-bubble,
    .chatbot-modal,
    .chatbot-overlay {
        display: none !important;
    }
}