/* =====================================================
 * TAONSA Tech — Chatbot IA (CSS additif)
 * Charge ce fichier APRÈS style.css. Préfixe .taonsa-chat-* pour ne rien casser.
 * ===================================================== */

/* État "caché" quand l'utilisateur a atteint le footer (anti-encombrement) */
.taonsa-chat-toggle.taonsa-chat-toggle-hidden {
    opacity: 0;
    transform: translateY(20px) scale(0.85);
    pointer-events: none;
}

/* ---------- Bouton flottant (toggle) ---------- */
/* Position : à droite, juste AU-DESSUS du bouton WhatsApp (qui est à bottom:24px) */
.taonsa-chat-toggle {
    position: fixed;
    bottom: max(96px, calc(96px + env(safe-area-inset-bottom))); /* 24px (WA) + 60px (WA height) + 12px gap = 96px */
    right: 24px;
    z-index: 36;
    width: 60px;
    height: 60px;
    border-radius: 30px;
    background: linear-gradient(135deg, #0d9488 0%, #0891b2 100%);
    color: #ffffff;
    border: 0;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(13, 148, 136, 0.45), 0 2px 8px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease, width 0.3s ease, border-radius 0.3s ease;
    overflow: hidden;
}
.taonsa-chat-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 12px 32px rgba(13, 148, 136, 0.55);
}
.taonsa-chat-toggle:focus-visible {
    outline: 3px solid #0d9488;
    outline-offset: 3px;
}
.taonsa-chat-toggle i {
    font-size: 1.375rem; /* FIX 2026-05-21 : unifie en rem Tailwind scale */
    line-height: 1;
}
.taonsa-chat-toggle-label {
    /* Label "Aide IA" toujours masque : on garde un cercle 60x60 comme le bouton WhatsApp,
       sur mobile ET desktop. */
    display: none;
}

/* Pulse halo */
.taonsa-chat-toggle-pulse {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: rgba(13, 148, 136, 0.4);
    animation: taonsa-chat-pulse 2.2s ease-out infinite;
    z-index: -1;
    pointer-events: none;
}
@keyframes taonsa-chat-pulse {
    0%   { transform: scale(0.85); opacity: 0.65; }
    70%  { transform: scale(1.55); opacity: 0; }
    100% { transform: scale(1.55); opacity: 0; }
}

/* ---------- Panel du chat ---------- */
/* IMPORTANT : display: none par defaut pour eviter qu'un ancetre avec
   transform (ex: body.fade-in) ne fasse echouer le masquage transform-based.
   Le panel n'apparait qu'avec la classe .open (ajoutee par le JS au clic). */
.taonsa-chat-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 60;
    background: #ffffff;
    box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    max-height: 90vh;
    height: 90vh;
    border-radius: 24px 24px 0 0;
    overflow: hidden;
}
.taonsa-chat-panel.open {
    display: flex;
    transform: translateY(0);
}
/* Desktop : panel à droite (cohérent avec position du toggle) */
@media (min-width: 768px) {
    .taonsa-chat-panel {
        bottom: 16px;
        right: 24px;
        left: auto;
        width: 400px;
        height: min(620px, 80vh);
        max-height: 80vh;
        border-radius: 24px;
        transform: translateY(120%) translateX(0);
    }
    .taonsa-chat-panel.open {
        display: flex;
        transform: translateY(0);
    }
}

/* ---------- Header ---------- */
.taonsa-chat-header {
    background: linear-gradient(135deg, #0d9488 0%, #0891b2 100%);
    color: #ffffff;
    padding: 14px 18px;
    flex-shrink: 0;
}
.taonsa-chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem; /* FIX 2026-05-21 : unifie en rem Tailwind scale */
    color: #ffffff;
    flex-shrink: 0;
}
.taonsa-chat-title {
    font-weight: 700;
    font-size: 0.9375rem; /* FIX 2026-05-21 : unifie en rem Tailwind scale */
    margin: 0;
    line-height: 1.2;
}
.taonsa-chat-status {
    font-size: 0.75rem; /* FIX 2026-05-21 : unifie en rem Tailwind scale */
    opacity: 0.85;
    margin: 2px 0 0;
    display: flex;
    align-items: center;
    gap: 6px;
}
.taonsa-chat-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 6px #4ade80;
    display: inline-block;
}
.taonsa-chat-close {
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    flex-shrink: 0;
}
.taonsa-chat-close:hover {
    background: rgba(255, 255, 255, 0.28);
}

/* ---------- Body (messages) ---------- */
.taonsa-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

/* ---------- Bulles ---------- */
.taonsa-chat-msg {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    max-width: 100%;
    animation: taonsa-chat-fadein 0.3s ease;
}
@keyframes taonsa-chat-fadein {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.taonsa-chat-msg-user {
    flex-direction: row-reverse;
    align-self: flex-end;
}
.taonsa-chat-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0d9488, #0891b2);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8125rem; /* FIX 2026-05-21 : unifie en rem Tailwind scale */
    flex-shrink: 0;
}
.taonsa-chat-bubble {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    padding: 10px 14px;
    font-size: 0.875rem; /* FIX 2026-05-21 : unifie en rem Tailwind scale */
    line-height: 1.5;
    color: #1f2937;
    max-width: 80%;
    word-wrap: break-word;
}
.taonsa-chat-msg-user .taonsa-chat-bubble {
    background: #0d9488;
    color: #ffffff;
    border-color: #0d9488;
    border-bottom-right-radius: 4px;
}
.taonsa-chat-msg-assistant .taonsa-chat-bubble {
    border-bottom-left-radius: 4px;
}

/* Liens dans les bulles */
.taonsa-chat-link {
    display: inline-block;
    background: #f0fdfa;
    color: #0f766e !important;
    padding: 3px 10px;
    border-radius: 8px;
    font-size: 0.75rem; /* FIX 2026-05-21 : unifie en rem Tailwind scale */
    font-weight: 600;
    text-decoration: none;
    margin: 2px 2px 2px 0;
    border: 1px solid #ccfbf1;
    white-space: nowrap;
}
.taonsa-chat-link:hover {
    background: #ccfbf1;
}
.taonsa-chat-msg-user .taonsa-chat-link {
    background: rgba(255, 255, 255, 0.18);
    color: #ffffff !important;
    border-color: rgba(255, 255, 255, 0.3);
}

/* Badge "Vérifié" / "Incertain" (anti-hallucination) */
.taonsa-chat-trust {
    margin-top: 8px;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 0.75rem; /* FIX 2026-05-21 : unifie en rem Tailwind scale */
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}
.taonsa-chat-trust-ok {
    background: #f0fdf4;
    color: #15803d;
    border: 1px solid #bbf7d0;
}
.taonsa-chat-trust-warn {
    background: #fef3c7;
    color: #b45309;
    border: 1px solid #fde68a;
}

/* Boutons feedback 👍 / 👎 */
.taonsa-chat-feedback {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed #e2e8f0;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem; /* FIX 2026-05-21 : unifie en rem Tailwind scale */
    color: #64748b;
}
.taonsa-chat-feedback-label {
    flex: 1;
}
.taonsa-chat-feedback-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid #e2e8f0;
    background: #ffffff;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    font-size: 0.75rem; /* FIX 2026-05-21 : unifie en rem Tailwind scale */
}
.taonsa-chat-feedback-btn:hover:not(:disabled) {
    border-color: #0d9488;
    color: #0d9488;
    transform: scale(1.05);
}
.taonsa-chat-feedback-btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}
.taonsa-chat-feedback-active-up {
    background: #f0fdf4 !important;
    border-color: #16a34a !important;
    color: #16a34a !important;
    opacity: 1 !important;
}
.taonsa-chat-feedback-active-down {
    background: #fef2f2 !important;
    border-color: #ef4444 !important;
    color: #ef4444 !important;
    opacity: 1 !important;
}
.taonsa-chat-msg-user .taonsa-chat-trust,
.taonsa-chat-msg-user .taonsa-chat-feedback { display: none; }

/* Tags d'outils utilisés par l'agent (mode autonome) */
.taonsa-chat-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed #e2e8f0;
}
.taonsa-chat-tool-tag {
    background: #f0f9ff;
    color: #075985;
    border: 1px solid #bae6fd;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.75rem; /* FIX 2026-05-21 : 10px sub-WCAG bumped a 12px (0.75rem) */
    font-weight: 600;
    white-space: nowrap;
}
.taonsa-chat-msg-user .taonsa-chat-tools { display: none; }

/* Cards produits dans les bulles */
.taonsa-chat-products {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-top: 10px;
}
.taonsa-chat-product-card {
    background: #f0fdfa;
    border: 1px solid #ccfbf1;
    border-radius: 10px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    text-decoration: none;
    transition: background 0.15s ease;
}
.taonsa-chat-product-card:hover {
    background: #ccfbf1;
}
.taonsa-chat-product-name {
    font-size: 0.75rem; /* FIX 2026-05-21 : unifie en rem Tailwind scale */
    font-weight: 600;
    color: #134e4a;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.3;
}
.taonsa-chat-product-price {
    font-size: 0.75rem; /* FIX 2026-05-21 : unifie en rem Tailwind scale */
    font-weight: 700;
    color: #0d9488;
}

/* Indicateur "en train de taper" */
.taonsa-chat-dots {
    display: inline-flex;
    gap: 4px;
    padding: 2px 0;
}
.taonsa-chat-dots span {
    width: 7px;
    height: 7px;
    background: #94a3b8;
    border-radius: 50%;
    animation: taonsa-chat-dot 1.4s ease-in-out infinite;
}
.taonsa-chat-dots span:nth-child(2) { animation-delay: 0.2s; }
.taonsa-chat-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes taonsa-chat-dot {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
}

/* ---------- Suggestions chips ---------- */
.taonsa-chat-suggestions {
    padding: 8px 12px;
    display: flex;
    gap: 6px;
    overflow-x: auto;
    border-top: 1px solid #e2e8f0;
    background: #ffffff;
    flex-shrink: 0;
    transition: opacity 0.3s ease, max-height 0.3s ease;
    max-height: 60px;
}
.taonsa-chat-suggestions-fade {
    opacity: 0;
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    pointer-events: none;
}
.taonsa-chat-suggestions::-webkit-scrollbar {
    height: 4px;
}
.taonsa-chat-suggestions::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}
.taonsa-chat-chip {
    background: #f0fdfa;
    color: #0f766e;
    border: 1px solid #ccfbf1;
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 0.75rem; /* FIX 2026-05-21 : unifie en rem Tailwind scale */
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.15s ease, transform 0.1s ease;
}
.taonsa-chat-chip:hover {
    background: #ccfbf1;
}
.taonsa-chat-chip:active {
    transform: scale(0.97);
}

/* ---------- Form / input ---------- */
.taonsa-chat-form {
    display: flex;
    gap: 8px;
    padding: 12px;
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
    align-items: flex-end;
}
.taonsa-chat-form textarea {
    flex: 1;
    border: 1px solid #cbd5e1;
    border-radius: 18px;
    padding: 10px 14px;
    font-size: 0.875rem; /* FIX 2026-05-21 : unifie en rem Tailwind scale */
    line-height: 1.4;
    resize: none;
    outline: none;
    background: #f8fafc;
    color: #1f2937;
    font-family: inherit;
    min-height: 40px;
    max-height: 120px;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.taonsa-chat-form textarea:focus {
    border-color: #0d9488;
    background: #ffffff;
}
.taonsa-chat-send {
    background: #0d9488;
    color: #ffffff;
    border: 0;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s ease, transform 0.1s ease;
}
.taonsa-chat-send:hover {
    background: #0f766e;
}
.taonsa-chat-send:active {
    transform: scale(0.95);
}
.taonsa-chat-send:disabled {
    background: #94a3b8;
    cursor: not-allowed;
    transform: none;
}

/* ---------- Mobile : repositionner au-dessus de la bottom-nav (64px) + WhatsApp (60+24) ---------- */
@media (max-width: 1023px) {
    body.has-bottom-nav .taonsa-chat-toggle {
        /* bottom-nav 64px + WhatsApp 60px + gap 16px = 140px */
        bottom: max(150px, calc(150px + env(safe-area-inset-bottom)));
    }
    /* WhatsApp float doit aussi se relever au-dessus de la bottom-nav */
    body.has-bottom-nav .whatsapp-float {
        bottom: max(80px, calc(80px + env(safe-area-inset-bottom))) !important;
    }
}

/* iOS no-zoom sur input */
@media (max-width: 640px) {
    .taonsa-chat-form textarea {
        font-size: 16px !important;
    }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
    .taonsa-chat-toggle-pulse,
    .taonsa-chat-dots span,
    .taonsa-chat-msg {
        animation: none;
    }
    .taonsa-chat-panel {
        transition: none;
    }
}
