/* ==========================================================================
   Chatbot FAQ — Widget public premium
   Design system raffiné : moderne, minimal, cohérent, accessible
   ========================================================================== */

/* ==========================================================================
   1. Variables & Reset
   ========================================================================== */
#chatboxContainer {
    /* Couleurs principales (surchargées par JS) */
    --faq-color: var(--main-color, #4f6bff);
    --faq-color-secondary: var(--secondary-color, #6366f1);
    --faq-color-dark: #3a52d6;
    --faq-color-soft: #eef1ff;
    --faq-ring: rgba(79, 107, 255, .24);

    /* Neutres */
    --faq-text: #0f172a;
    --faq-muted: #64748b;
    --faq-border: #e7eaf1;
    --faq-border-strong: #dce2ec;
    --faq-surface: #ffffff;
    --faq-soft: #f7f8fc;
    --faq-soft-2: #fbfcfe;

    /* Bulles */
    --bot-bubble-color: var(--chat-bubble-color, #ffffff);
    --bot-text-color: var(--chat-text-color, #0f172a);
    --user-bubble-color: var(--chat-user-bubble-color, var(--faq-color));
    --user-text-color: var(--chat-user-text-color, #ffffff);

    /* Géométrie */
    --faq-radius-lg: 24px;
    --faq-radius-md: 18px;
    --faq-radius-sm: 12px;
    --faq-radius-full: 999px;

    /* Ombres */
    --faq-shadow-sm: 0 1px 2px rgba(15, 23, 42, .04);
    --faq-shadow-md: 0 4px 12px rgba(15, 23, 42, .08);
    --faq-shadow-lg: 0 10px 20px rgba(15, 23, 42, .06), 0 32px 64px rgba(15, 23, 42, .14);
    --faq-shadow-ring: 0 5px 14px var(--faq-ring), 0 14px 30px rgba(15, 23, 42, .18);

    /* Layout */
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 999999;

    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.55;
    color: var(--faq-text);

    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Dérivés automatiques via color-mix (navigateurs modernes) */
@supports (color: color-mix(in srgb, #000 50%, #fff)) {
    #chatboxContainer {
        --faq-color-dark: color-mix(in srgb, var(--faq-color) 78%, #111827);
        --faq-color-soft: color-mix(in srgb, var(--faq-color) 10%, #ffffff);
        --faq-ring: color-mix(in srgb, var(--faq-color) 24%, transparent);
    }
}

/* Reset scopé */
#chatboxContainer *,
#chatboxContainer *::before,
#chatboxContainer *::after {
    box-sizing: border-box;
}

#chatboxContainer button,
#chatboxContainer input {
    font: inherit;
    color: inherit;
}

#chatboxContainer button:focus-visible,
#chatboxContainer input:focus-visible {
    outline: 2px solid var(--faq-color);
    outline-offset: 2px;
}

/* ==========================================================================
   2. Launcher flottant
   ========================================================================== */
.my-faq-chatbot-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    padding: 0;
    color: #fff;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    background: linear-gradient(145deg, var(--faq-color), var(--faq-color-dark));
    box-shadow: var(--faq-shadow-ring);
    transition:
        transform .32s cubic-bezier(.34, 1.56, .64, 1),
        box-shadow .2s ease,
        filter .2s ease;
}

/* Anneau interne subtil */
.my-faq-chatbot-toggle::before {
    content: "";
    position: absolute;
    inset: -2px;
    border: 1px solid rgba(255, 255, 255, .45);
    border-radius: inherit;
    opacity: .65;
    pointer-events: none;
}

/* Halo animé */
.my-faq-chatbot-toggle::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: inherit;
    z-index: -1;
    animation: faq-launcher-halo 3s ease-out infinite;
}

.my-faq-chatbot-toggle:hover {
    transform: translateY(-3px) scale(1.05);
    filter: brightness(1.06);
    box-shadow: 0 7px 20px var(--faq-ring), 0 20px 42px rgba(15, 23, 42, .22);
}

.my-faq-chatbot-toggle:active {
    transform: scale(.96);
}

.my-faq-chatbot-toggle .dashicons {
    position: relative;
    z-index: 1;
    width: 28px;
    height: 28px;
    font-size: 28px;
    line-height: 1;
}

#chatboxContainer.show .my-faq-chatbot-toggle {
    opacity: 0;
    transform: scale(.4);
    pointer-events: none;
}

@keyframes faq-launcher-halo {
    0% {
        transform: scale(1);
        opacity: .28;
    }

    65%,
    100% {
        transform: scale(1.42);
        opacity: 0;
    }
}

/* ==========================================================================
   3. Fenêtre
   ========================================================================== */
.my-faq-chatbot-window {
    position: absolute;
    right: 0;
    bottom: 74px;
    display: flex;
    flex-direction: column;
    width: 400px;
    height: 600px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 120px);
    overflow: hidden;
    background: var(--faq-surface);
    border: 1px solid var(--faq-border);
    border-radius: var(--faq-radius-lg);
    box-shadow: var(--faq-shadow-lg);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(16px) scale(.94);
    transform-origin: bottom right;
    transition:
        opacity .28s ease,
        transform .36s cubic-bezier(.16, 1, .3, 1),
        visibility .28s ease;
}

#chatboxContainer.show .my-faq-chatbot-window {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

/* ==========================================================================
   4. En-tête
   ========================================================================== */
.my-faq-chatbot-header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 72px;
    padding: 16px 18px;
    overflow: hidden;
    color: #fff;
    background: linear-gradient(145deg, var(--faq-color), var(--faq-color-dark));
}

/* Motif géométrique décoratif */
.my-faq-chatbot-header::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, .06) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, .06) 1px, transparent 1px);
    background-size: 24px 24px;
    -webkit-mask-image: radial-gradient(ellipse at top right, #000, transparent 70%);
    mask-image: radial-gradient(ellipse at top right, #000, transparent 70%);
    pointer-events: none;
}

.my-faq-chatbot-bot-name {
    position: relative;
    z-index: 1;
    max-width: 260px;
    overflow: hidden;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -.01em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Pastille de statut "en ligne" */
.my-faq-chatbot-bot-name::before {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    margin: 0 9px 1px 0;
    border-radius: 50%;
    background: #6ee7b7;
    box-shadow: 0 0 0 4px rgba(110, 231, 183, .16);
}

/* Actions du header — base commune aux 3 boutons */
.my-faq-chatbot-header-actions {
    position: relative;
    z-index: 1;
    display: flex;
    gap: 7px;
}

.my-faq-chatbot-header-actions button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    color: #fff;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .14);
    cursor: pointer;
    transition:
        background .2s ease,
        transform .2s ease,
        opacity .2s ease;
}

.my-faq-chatbot-header-actions button:hover {
    background: rgba(255, 255, 255, .28);
}

.my-faq-chatbot-header-actions button:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.my-faq-chatbot-header-actions .dashicons {
    width: 18px;
    height: 18px;
    font-size: 18px;
    line-height: 1;
}

/* Animations spécifiques par bouton */
.my-faq-chatbot-human-btn:hover {
    transform: translateY(-1px);
}

.my-faq-chatbot-new-btn:hover {
    transform: rotate(-30deg);
}

.my-faq-chatbot-close-btn:hover {
    transform: rotate(90deg);
}

/* ==========================================================================
   5. Zone des messages
   ========================================================================== */
.my-faq-chatbot-messages {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 14px;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 20px 16px;
    background: var(--faq-soft);
    scroll-behavior: smooth;
    scrollbar-color: rgba(0, 0, 0, .14) transparent;
    scrollbar-width: thin;
}

.my-faq-chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.my-faq-chatbot-messages::-webkit-scrollbar-thumb {
    border-radius: var(--faq-radius-full);
    background: rgba(0, 0, 0, .13);
}

/* ==========================================================================
   6. Bulles de message
   ========================================================================== */
.message-bubble {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 88%;
    animation: faq-message-in .3s cubic-bezier(.16, 1, .3, 1);
}

.bot-message {
    align-self: flex-start;
}

.user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}

@keyframes faq-message-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==========================================================================
   7. Avatars (SVG masqué + CSS variables)
   --avatar-url    : URL du SVG (passée par JS)
   --avatar-bg     : couleur de fond de la pastille
   --avatar-color  : couleur de l'icône
   ========================================================================== */
.message-avatar {
    position: relative;
    flex: 0 0 auto;
    display: inline-block;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--avatar-bg, #eaeaea);
    border: 1px solid rgba(15, 23, 42, .06);
    box-shadow: 0 2px 7px rgba(15, 23, 42, .10);
    overflow: hidden;
    transition: background-color .2s ease;
}

.message-avatar::before {
    content: "";
    position: absolute;
    inset: 5px;
    background-color: var(--avatar-color, #6a82fb);
    -webkit-mask-image: var(--avatar-url);
    mask-image: var(--avatar-url);
    -webkit-mask-position: center;
    mask-position: center;
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    transition: background-color .2s ease;
}

/* ==========================================================================
   8. Corps du message
   ========================================================================== */
.message-body {
    display: flex;
    min-width: 0;
    flex-direction: column;
    align-items: flex-start;
}

.user-message .message-body {
    align-items: flex-end;
}

.message-content {
    padding: 11px 15px;
    color: var(--bot-text-color, #0f172a);
    border: 1px solid var(--faq-border);
    border-radius: var(--faq-radius-md);
    background: var(--bot-bubble-color, #ffffff);
    box-shadow: var(--faq-shadow-sm);
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.bot-message .message-content {
    border-bottom-left-radius: 6px;
}

.user-message .message-content {
    color: var(--user-text-color, #fff);
    border: 0;
    border-bottom-right-radius: 6px;
    background: linear-gradient(145deg, var(--user-bubble-color, var(--faq-color)), var(--faq-color-dark));
    box-shadow: 0 2px 8px var(--faq-ring);
}

.message-time {
    display: block;
    margin: 5px 4px 0;
    color: var(--faq-muted);
    font-size: 10px;
    font-weight: 600;
    line-height: 1;
    letter-spacing: .02em;
    opacity: .82;
}

.user-message .message-time {
    color: var(--faq-muted);
}

/* ==========================================================================
   9. Feedback (👍 / 👎)
   ========================================================================== */
.my-faq-chatbot-feedback {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: -7px 0 0 40px;
    color: var(--faq-muted);
    font-size: 11px;
}

.my-faq-chatbot-feedback button {
    width: 26px;
    height: 26px;
    padding: 0;
    border: 1px solid var(--faq-border);
    border-radius: 50%;
    background: var(--faq-surface);
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    opacity: .75;
    transition: opacity .2s ease, transform .2s ease, box-shadow .2s ease;
}

.my-faq-chatbot-feedback button:hover {
    opacity: 1;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(15, 23, 42, .12);
}

.my-faq-chatbot-feedback.is-sent button {
    display: none;
}

/* ==========================================================================
   10. Indicateur de saisie
   ========================================================================== */
.my-faq-chatbot-typing-indicator .message-content {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 24px;
    padding: 12px 16px;
    color: var(--faq-muted) !important;
    font-style: normal;
}

.my-faq-chatbot-typing-indicator .message-content span {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: .4;
    animation: faq-typing-bounce 1.2s infinite ease-in-out;
}

.my-faq-chatbot-typing-indicator .message-content span:nth-child(2) {
    animation-delay: .15s;
}

.my-faq-chatbot-typing-indicator .message-content span:nth-child(3) {
    animation-delay: .3s;
}

@keyframes faq-typing-bounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: .4;
    }

    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* ==========================================================================
   11. Réponses rapides
   ========================================================================== */
.my-faq-chatbot-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 11px 15px;
    border-top: 1px solid var(--faq-border);
    background: var(--faq-surface);
}

.quick-reply-button {
    padding: 7px 12px;
    color: #fff;
    border: 0;
    border-radius: var(--faq-radius-full);
    background: var(--faq-color-secondary);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: transform .2s ease, filter .2s ease;
}

.quick-reply-button:hover {
    filter: brightness(1.08);
    transform: translateY(-1px);
}

/* ==========================================================================
   12. Zone de saisie
   ========================================================================== */
.my-faq-chatbot-input-area {
    display: flex;
    gap: 9px;
    padding: 13px 15px 15px;
    border-top: 1px solid var(--faq-border);
    background: var(--faq-surface);
}

#messageInput {
    flex: 1 1 auto;
    min-width: 0;
    height: 43px;
    padding: 10px 14px;
    color: var(--faq-text);
    border: 1px solid var(--faq-border-strong);
    border-radius: var(--faq-radius-sm);
    outline: 0;
    background: var(--faq-soft-2);
    transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
}

#messageInput::placeholder {
    color: #94a3b8;
}

#messageInput:focus {
    border-color: var(--faq-color);
    box-shadow: 0 0 0 3px var(--faq-ring);
    background: var(--faq-surface);
}

#messageInput:disabled {
    opacity: .65;
    cursor: not-allowed;
}

/* Bouton Envoyer — icône SVG + texte */
#sendMessageBtn {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 43px;
    padding: 0 16px;
    color: #fff;
    border: 0;
    border-radius: var(--faq-radius-sm);
    background: linear-gradient(145deg, var(--faq-color), var(--faq-color-dark));
    cursor: pointer;
    font-weight: 700;
    box-shadow: 0 4px 10px var(--faq-ring);
    transition: transform .2s ease, filter .2s ease, box-shadow .2s ease;
}

#sendMessageBtn:hover:not(:disabled) {
    filter: brightness(1.07);
    transform: translateY(-1px);
    box-shadow: 0 6px 14px var(--faq-ring);
}

#sendMessageBtn:disabled {
    opacity: .55;
    cursor: not-allowed;
    box-shadow: none;
}

#sendMessageBtn .my-faq-chatbot-send-icon {
    flex: 0 0 auto;
    display: block;
    width: 18px;
    height: 18px;
    transform: translateX(-1px);
}

#sendMessageBtn .my-faq-chatbot-send-label {
    line-height: 1;
}

/* ==========================================================================
   13. Responsive
   ========================================================================== */
@media (max-width: 480px) {
    #chatboxContainer {
        right: 12px;
        bottom: 12px;
    }

    .my-faq-chatbot-toggle {
        width: 54px;
        height: 54px;
    }

    .my-faq-chatbot-toggle .dashicons {
        width: 24px;
        height: 24px;
        font-size: 24px;
    }

    .my-faq-chatbot-window {
        right: -2px;
        bottom: 64px;
        width: calc(100vw - 24px);
        height: calc(100vh - 96px);
        max-height: none;
        border-radius: 20px;
    }

    .my-faq-chatbot-input-area {
        padding: 10px;
        gap: 7px;
    }

    /* Bouton envoyer compact : icône seule sur mobile */
    #sendMessageBtn {
        width: 43px;
        padding: 0;
    }

    #sendMessageBtn .my-faq-chatbot-send-label {
        display: none;
    }

    .my-faq-chatbot-header-actions button {
        width: 32px;
        height: 32px;
    }

    .my-faq-chatbot-header-actions .dashicons {
        width: 16px;
        height: 16px;
        font-size: 16px;
    }
}

/* Très petits écrans (iPhone SE, etc.) */
@media (max-width: 360px) {
    .my-faq-chatbot-window {
        width: calc(100vw - 16px);
        height: calc(100vh - 80px);
        border-radius: 16px;
    }

    .my-faq-chatbot-bot-name {
        max-width: 180px;
        font-size: 14px;
    }
}

/* ==========================================================================
   14. Reduced motion
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {

    #chatboxContainer *,
    #chatboxContainer *::before,
    #chatboxContainer *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ==========================================================================
   15. Dark mode
   ========================================================================== */
@media (prefers-color-scheme: dark) {
    #chatboxContainer {
        --faq-text: #e5e7eb;
        --faq-muted: #94a3b8;
        --faq-border: #293246;
        --faq-border-strong: #354158;
        --faq-surface: #111827;
        --faq-soft: #182131;
        --faq-soft-2: #111827;

        --bot-bubble-color: #1f2937;
        --bot-text-color: #e5e7eb;
    }

    .my-faq-chatbot-messages,
    .my-faq-chatbot-quick-replies,
    .my-faq-chatbot-input-area {
        background: var(--faq-soft);
    }

    .my-faq-chatbot-quick-replies,
    .my-faq-chatbot-input-area {
        border-color: var(--faq-border);
    }

    .message-content {
        border-color: var(--faq-border);
    }

    .message-avatar {
        border-color: rgba(255, 255, 255, .08);
        box-shadow: 0 2px 8px rgba(0, 0, 0, .35);
    }

    #messageInput {
        color: #e5e7eb;
        border-color: var(--faq-border-strong);
        background: var(--faq-soft-2);
    }

    #messageInput:focus {
        background: #0b1220;
    }

    .my-faq-chatbot-feedback button {
        background: #1f2937;
        border-color: var(--faq-border);
    }

    .my-faq-chatbot-window {
        box-shadow:
            0 10px 20px rgba(0, 0, 0, .3),
            0 32px 64px rgba(0, 0, 0, .5);
    }
}