/* ===== Melissa Chat Widget — UI 2024 premium ===== */

#aam-chat-widget {
    --aam-primary: #8b5cf6;
    --aam-primary-dark: #6d28d9;
    --aam-accent: #fbbf24;
    --aam-bg: #ffffff;
    --aam-bg-soft: #fafafa;
    --aam-text: #18181b;
    --aam-text-soft: #52525b;
    --aam-text-faint: #a1a1aa;
    --aam-border: #f1f1f4;
    --aam-radius: 22px;
    --aam-radius-msg: 18px;
    --aam-shadow-lg: 0 24px 60px -12px rgba(0,0,0,0.16), 0 8px 20px -8px rgba(0,0,0,0.08);
    --aam-shadow-launcher: 0 12px 32px -8px rgba(139, 92, 246, 0.4), 0 4px 12px rgba(0,0,0,0.08);
    --aam-mobile-offset: 90px;
    --aam-z: 2147483000;
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "SF Pro Text", "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--aam-text);
    -webkit-font-smoothing: antialiased;
}
#aam-chat-widget *, #aam-chat-widget *::before, #aam-chat-widget *::after {
    box-sizing: border-box;
}

/* ============================================================
   LAUNCHER — pill avec avatar Melissa + texte (frosted glass)
   ============================================================ */
.aam-chat-launcher {
    position: fixed;
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    right: 20px;
    padding: 6px 18px 6px 6px;
    background: rgba(255, 255, 255, 0.78);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.6);
    box-shadow: var(--aam-shadow-launcher);
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    z-index: var(--aam-z);
    color: var(--aam-text);
    font-family: inherit;
    transition: transform 240ms cubic-bezier(0.34, 1.56, 0.64, 1),
                box-shadow 240ms ease,
                background 200ms ease;
    animation: aam-bounce-in 600ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
    animation-delay: 800ms;
}
@keyframes aam-bounce-in {
    0%   { opacity: 0; transform: scale(0.7) translateY(20px); }
    60%  { opacity: 1; transform: scale(1.08) translateY(0); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}
.aam-chat-launcher:hover  { transform: translateY(-2px) scale(1.02); box-shadow: 0 16px 40px -10px rgba(139,92,246,0.5); }
.aam-chat-launcher:active { transform: translateY(0) scale(0.98); }

/* Avatar pastille */
.aam-launcher-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--aam-primary) 0%, #ec4899 50%, var(--aam-accent) 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
    overflow: hidden;
    position: relative;
    box-shadow: 0 2px 6px rgba(139, 92, 246, 0.3);
}
.aam-launcher-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.aam-launcher-avatar svg { width: 28px; height: 28px; }
.aam-launcher-avatar::after {
    content: '';
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #22c55e;
    border: 2.5px solid #fff;
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.6);
}

/* Texte du launcher */
.aam-launcher-label {
    display: flex;
    flex-direction: column;
    gap: 2px;
    line-height: 1.2;
    max-width: 180px;
}
.aam-launcher-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--aam-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.aam-launcher-sub {
    font-size: 11px;
    color: var(--aam-text-soft);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* WOW effect : aura dorée pulsante autour du launcher */
.aam-wow .aam-chat-launcher::before {
    content: '';
    position: absolute;
    inset: -8px;
    border-radius: 999px;
    background: conic-gradient(from 0deg, var(--aam-primary), var(--aam-accent), #ec4899, var(--aam-primary));
    z-index: -1;
    opacity: 0.5;
    filter: blur(10px);
    animation: aam-conic 6s linear infinite;
}
@keyframes aam-conic {
    to { transform: rotate(360deg); }
}
.aam-wow .aam-launcher-avatar::before {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    background: var(--aam-primary);
    opacity: 0;
    animation: aam-pulse 2.4s ease-out infinite;
    z-index: -1;
}
@keyframes aam-pulse {
    0%   { transform: scale(0.85); opacity: 0.55; }
    100% { transform: scale(1.5);  opacity: 0; }
}

/* Notification dot */
.aam-chat-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: 2px solid #fff;
}

/* Quand panel ouvert → cache launcher */
#aam-chat-widget.aam-is-open .aam-chat-launcher,
#aam-chat-widget.aam-is-open .aam-launcher-mini { display: none; }

/* MINI BUTTON — bouton rétractation */
.aam-launcher-mini {
    position: fixed;
    bottom: calc(70px + env(safe-area-inset-bottom, 0px));
    right: 18px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(255,255,255,0.96);
    border: 1px solid rgba(0,0,0,0.08);
    color: #52525b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    z-index: 2147483001;
    transition: transform 200ms ease, background 150ms ease;
}
.aam-launcher-mini:hover { transform: scale(1.08); background: #fff; }
.aam-launcher-mini svg { width: 14px; height: 14px; }
.aam-launcher-mini .aam-mini-expand { display: none; }
#aam-chat-widget.aam-launcher-compact .aam-launcher-mini .aam-mini-collapse { display: none; }
#aam-chat-widget.aam-launcher-compact .aam-launcher-mini .aam-mini-expand { display: block; }

/* Icône minimaliste bulle chat (visible uniquement en compact) */
.aam-launcher-bubble { display: none; width: 22px; height: 22px; color: var(--aam-primary); }

/* COMPACT — icône minimaliste seule, plus d'avatar, plus de label, plus d'effet wow */
#aam-chat-widget.aam-launcher-compact .aam-launcher-label,
#aam-chat-widget.aam-launcher-compact .aam-launcher-avatar { display: none; }
#aam-chat-widget.aam-launcher-compact .aam-launcher-bubble { display: block; }
#aam-chat-widget.aam-launcher-compact .aam-chat-launcher {
    padding: 11px;
    gap: 0;
    background: rgba(255,255,255,0.94);
    box-shadow: 0 6px 16px -4px rgba(139,92,246,0.18), 0 2px 6px rgba(0,0,0,0.08);
    border: 1px solid rgba(0,0,0,0.06);
}
#aam-chat-widget.aam-launcher-compact .aam-chat-launcher::before { display: none; }

/* ============================================================
   PANEL
   ============================================================ */
.aam-chat-panel {
    position: fixed;
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    right: 20px;
    width: 380px;
    height: 620px;
    max-height: calc(100vh - 48px);
    background: var(--aam-bg);
    border-radius: var(--aam-radius);
    box-shadow: var(--aam-shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.96);
    transform-origin: bottom right;
    pointer-events: none;
    transition: opacity 240ms ease, transform 360ms cubic-bezier(0.32, 0.72, 0, 1);
    z-index: var(--aam-z);
}
.aam-chat-panel.aam-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Position bottom-left */
.aam-pos-bottom-left .aam-chat-launcher { right: auto; left: 20px; }
.aam-pos-bottom-left .aam-chat-panel    { right: auto; left: 20px; transform-origin: bottom left; }

/* ============================================================
   HEADER glassmorphism
   ============================================================ */
.aam-chat-header {
    background: linear-gradient(135deg, var(--aam-primary) 0%, #6366f1 50%, #ec4899 100%);
    color: #fff;
    padding: 18px 18px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}
.aam-chat-header::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 20% 30%, rgba(255,255,255,0.18), transparent 40%),
        radial-gradient(circle at 80% 70%, rgba(251,191,36,0.2), transparent 40%);
    pointer-events: none;
}

.aam-chat-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
    overflow: hidden;
    position: relative;
    z-index: 1;
    border: 2px solid rgba(255,255,255,0.3);
}
.aam-chat-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.aam-chat-avatar svg { width: 28px; height: 28px; }
.aam-chat-avatar::after {
    content: '';
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #22c55e;
    border: 2px solid var(--aam-primary);
}

.aam-chat-title { flex: 1; min-width: 0; position: relative; z-index: 1; }
.aam-chat-name { font-weight: 600; font-size: 15px; line-height: 1.2; margin-bottom: 2px; }
.aam-chat-status {
    font-size: 12px;
    opacity: 0.95;
    line-height: 1.2;
    display: flex;
    align-items: center;
    gap: 4px;
}

.aam-chat-actions { display: flex; gap: 4px; position: relative; z-index: 2; }
.aam-chat-actions .aam-chat-close {
    background: rgba(255,255,255,0.95);
    border: 2px solid rgba(255,255,255,1);
    color: #1f0a26;
    height: 36px;
    padding: 0 14px 0 10px;
    border-radius: 999px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: inherit;
    font-weight: 700;
    font-size: 13px;
    line-height: 1;
    transition: all 160ms ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.18);
}
.aam-chat-actions .aam-chat-close:hover  { background: #fff; transform: scale(1.04); box-shadow: 0 6px 16px rgba(0,0,0,0.22); }
.aam-chat-actions .aam-chat-close:active { transform: scale(0.96); }
.aam-chat-actions .aam-chat-close svg    { width: 16px; height: 16px; stroke-width: 3; flex-shrink: 0; }
.aam-close-text { display: inline-block; }

/* ============================================================
   TOPIC SELECTOR (sélecteur Général / NovaCanvas)
   ============================================================ */
.aam-chat-topics {
    display: flex;
    gap: 6px;
    padding: 10px;
    background: #fff;
    border-bottom: 1px solid var(--aam-border);
    overflow-x: auto;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 2;
    scrollbar-width: none;
}
.aam-chat-topics::-webkit-scrollbar { display: none; }

.aam-topic {
    flex: 1 1 0;
    min-width: 0;
    padding: 9px 10px;
    border-radius: 12px;
    background: var(--aam-bg-soft);
    border: 1.5px solid transparent;
    cursor: pointer;
    transition: all 180ms ease;
    text-align: left;
    font-family: inherit;
    display: flex;
    flex-direction: column;
    gap: 1px;
}
.aam-topic:hover { background: #f4f4f5; }
.aam-topic.aam-active {
    background: rgba(139, 92, 246, 0.08);
    border-color: var(--aam-primary);
}
.aam-topic-icon { font-size: 16px; line-height: 1; margin-bottom: 1px; }
.aam-topic-label {
    font-weight: 600;
    font-size: 12.5px;
    color: var(--aam-text);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.aam-topic-desc {
    font-size: 10px;
    color: var(--aam-text-soft);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================================
   BODY / MESSAGES
   ============================================================ */
.aam-chat-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    background: var(--aam-bg-soft);
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}
.aam-chat-body::-webkit-scrollbar { width: 5px; }
.aam-chat-body::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }

.aam-msg {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    max-width: 88%;
    animation: aam-msg-in 320ms cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes aam-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.aam-msg-agent { align-self: flex-start; }
.aam-msg-user  { align-self: flex-end; flex-direction: row-reverse; }

.aam-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--aam-primary), #ec4899);
    color: #fff;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    overflow: hidden;
}
.aam-msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.aam-msg-user .aam-msg-avatar { display: none; }

.aam-msg-bubble {
    padding: 10px 14px;
    border-radius: var(--aam-radius-msg);
    line-height: 1.5;
    word-wrap: break-word;
    word-break: break-word;
    white-space: pre-wrap;
    font-size: 14px;
    max-width: 100%;
}
.aam-msg-agent .aam-msg-bubble {
    background: #fff;
    color: var(--aam-text);
    border-bottom-left-radius: 6px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.aam-msg-user .aam-msg-bubble {
    background: linear-gradient(135deg, var(--aam-primary) 0%, #6366f1 100%);
    color: #fff;
    border-bottom-right-radius: 6px;
}
.aam-msg-bubble a {
    color: inherit;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

/* Typing */
.aam-typing { display: inline-flex; align-items: center; gap: 3px; padding: 4px 0; }
.aam-typing span {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--aam-primary);
    animation: aam-bounce 1.3s ease-in-out infinite;
}
.aam-typing span:nth-child(2) { animation-delay: 0.15s; }
.aam-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes aam-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30%           { transform: translateY(-5px); opacity: 1; }
}

/* Quick replies */
.aam-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 4px 0 8px 38px;
    animation: aam-msg-in 320ms ease;
}
.aam-quick-reply {
    background: #fff;
    border: 1.5px solid var(--aam-primary);
    color: var(--aam-primary);
    padding: 7px 14px;
    border-radius: 18px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    transition: all 150ms ease;
    line-height: 1.2;
}
.aam-quick-reply:hover {
    background: var(--aam-primary);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(139,92,246,0.25);
}

/* Product cards */
.aam-products {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 4px 0 8px 38px;
}
.aam-product-card {
    display: flex;
    gap: 12px;
    padding: 10px;
    background: #fff;
    border: 1px solid var(--aam-border);
    border-radius: 14px;
    text-decoration: none;
    color: inherit;
    align-items: center;
    transition: all 180ms ease;
    cursor: pointer;
}
.aam-product-card:hover {
    border-color: var(--aam-primary);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px -6px rgba(139,92,246,0.18);
}
.aam-product-img {
    width: 60px;
    height: 60px;
    border-radius: 10px;
    object-fit: cover;
    flex-shrink: 0;
    background: #f1f1f4;
}
.aam-product-info { flex: 1; min-width: 0; }
.aam-product-name { font-weight: 600; font-size: 13px; line-height: 1.3; margin-bottom: 4px; }
.aam-product-meta { font-size: 12px; color: var(--aam-text-soft); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.aam-product-price { font-weight: 700; color: var(--aam-text); font-size: 13px; }
.aam-product-stock {
    background: #f1f1f4;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 500;
    color: var(--aam-text-soft);
}
.aam-product-stock.aam-in { background: #d1fae5; color: #047857; }
.aam-product-cta {
    background: var(--aam-primary);
    color: #fff;
    padding: 6px 12px;
    border-radius: 14px;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
    white-space: nowrap;
}

/* Footer / Input */
.aam-chat-footer {
    padding: 10px 12px;
    background: #fff;
    border-top: 1px solid var(--aam-border);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
}
.aam-chat-input {
    flex: 1;
    border: none;
    background: var(--aam-bg-soft);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
    resize: none;
    outline: none;
    max-height: 120px;
    color: var(--aam-text);
    transition: background 150ms ease;
}
.aam-chat-input:focus { background: #f4f4f5; box-shadow: 0 0 0 2px rgba(139,92,246,0.15); }
.aam-chat-input::placeholder { color: var(--aam-text-faint); }

.aam-chat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--aam-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 150ms ease;
}
.aam-chat-send:hover:not(:disabled)  { background: var(--aam-primary-dark); transform: scale(1.05); }
.aam-chat-send:active:not(:disabled) { transform: scale(0.95); }
.aam-chat-send:disabled              { opacity: 0.3; cursor: not-allowed; }
.aam-chat-send svg                   { width: 18px; height: 18px; }

.aam-chat-foot-note {
    text-align: center;
    font-size: 10px;
    color: var(--aam-text-faint);
    padding: 5px 10px 8px;
    background: #fff;
}

/* ============================================================
   MOBILE — au-dessus du dock (configurable)
   ============================================================ */
@media (max-width: 768px) {
    .aam-chat-launcher {
        bottom: calc(var(--aam-mobile-offset) + env(safe-area-inset-bottom, 0px));
        right: 16px;
        padding: 5px 14px 5px 5px;
    }
    .aam-launcher-avatar { width: 36px; height: 36px; }
    .aam-launcher-name { font-size: 13px; }
    .aam-launcher-sub  { font-size: 10px; }

    /* Panel flottant moderne — PLUS jamais plein écran */
    .aam-chat-panel {
        bottom: calc(var(--aam-mobile-offset) + 8px + env(safe-area-inset-bottom, 0px));
        right: 8px;
        left: 8px;
        top: auto;
        width: auto;
        height: min(78vh, 580px);
        max-height: calc(100vh - var(--aam-mobile-offset) - 40px);
        border-radius: 20px;
    }
    .aam-pos-bottom-left .aam-chat-panel { left: 8px; right: 8px; }
    .aam-pos-bottom-left .aam-chat-launcher { left: 12px; right: auto; }

    /* Header plus généreux + close vraiment évident */
    .aam-chat-header { padding-top: max(18px, env(safe-area-inset-top)); }
    .aam-chat-actions .aam-chat-close {
        height: 40px;
        padding: 0 16px 0 12px;
        font-size: 14px;
    }
    .aam-chat-actions .aam-chat-close svg { width: 18px; height: 18px; }

    /* Topics : compact 2 colonnes égales, sticky */
    .aam-chat-topics {
        padding: 8px;
        gap: 6px;
    }
    .aam-topic { padding: 8px 10px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    #aam-chat-widget *, #aam-chat-widget *::before, #aam-chat-widget *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 100ms !important;
    }
    .aam-chat-launcher::before, .aam-launcher-avatar::before { display: none; }
}
