/*
 * Feuille de style du chatbot.
 *
 * Tout est préfixé « ai-chatbot- » et rattaché aux deux racines (.ai-chatbot),
 * pour qu'aucune règle ne sorte du chatbot ni n'y entre par accident.
 * Les valeurs vivent dans les tokens ci-dessous : les règles n'écrivent
 * jamais une couleur, un espacement ou un rayon en dur.
 * Les trois tokens de marque sont surchargés par FrontHandler (ACF).
 */

.ai-chatbot {
    /* Marque */
    --ai-chatbot-primary: #4facfe;
    --ai-chatbot-secondary: #00f2fe;
    --ai-chatbot-primary-soft: #4facfe33;
    --ai-chatbot-brand-gradient: linear-gradient(135deg, var(--ai-chatbot-primary), var(--ai-chatbot-secondary));

    /* Surfaces */
    --ai-chatbot-surface: #ffffff;
    --ai-chatbot-surface-sunken: #f4f4f8;
    --ai-chatbot-surface-muted: #f8fafc;
    --ai-chatbot-surface-accent: #f1f5f9;
    --ai-chatbot-border: #e1e8ed;
    --ai-chatbot-border-soft: #e4e7ec;
    --ai-chatbot-border-strong: #cccccc;

    /* Texte */
    --ai-chatbot-text: #334155;
    --ai-chatbot-text-strong: #1e293b;
    --ai-chatbot-text-muted: #64748b;
    --ai-chatbot-text-faint: #7f8c8d;
    --ai-chatbot-text-on-brand: #ffffff;
    --ai-chatbot-link: #0a4b78;

    /* États */
    --ai-chatbot-danger-surface: #fef2f2;
    --ai-chatbot-danger-border: #fee2e2;
    --ai-chatbot-danger-text: #991b1b;

    /* Typographie */
    --ai-chatbot-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --ai-chatbot-font-chrome: Arial, sans-serif;
    --ai-chatbot-text-xs: 10px;
    --ai-chatbot-text-sm: 12px;
    --ai-chatbot-text-md: 14px;
    --ai-chatbot-text-lg: 15px;
    --ai-chatbot-text-xl: 20px;
    --ai-chatbot-leading: 1.5;

    /* Espacement */
    --ai-chatbot-space-1: 4px;
    --ai-chatbot-space-2: 6px;
    --ai-chatbot-space-3: 8px;
    --ai-chatbot-space-4: 10px;
    --ai-chatbot-space-5: 12px;
    --ai-chatbot-space-6: 16px;
    --ai-chatbot-space-7: 20px;
    --ai-chatbot-space-8: 25px;

    /* Rayons */
    --ai-chatbot-radius-sm: 8px;
    --ai-chatbot-radius-md: 12px;
    --ai-chatbot-radius-lg: 14px;
    --ai-chatbot-radius-pill: 20px;
    --ai-chatbot-radius-round: 50%;

    /* Ombres */
    --ai-chatbot-shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
    --ai-chatbot-shadow-sm: 0 2px 5px rgba(0, 0, 0, 0.02);
    --ai-chatbot-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --ai-chatbot-shadow-lg: 0 8px 20px rgba(0, 0, 0, 0.25);
    --ai-chatbot-shadow-input: 0 -5px 30px -10px #bbbbbb;

    /* Mouvement */
    --ai-chatbot-ease: cubic-bezier(0.4, 0, 0.2, 1);
    --ai-chatbot-duration: 200ms;
    --ai-chatbot-duration-slow: 250ms;

    /* Gabarit */
    --ai-chatbot-width: 350px;
    --ai-chatbot-height: 450px;
    --ai-chatbot-offset: 20px;
    --ai-chatbot-bubble-size: 60px;
    --ai-chatbot-action-size: 42px;
    --ai-chatbot-z: 9999999;
}

/* ---------------------------------------------------------------- Bulle */

#ai-chatbot-bubble {
    position: fixed;
    inset-block-end: var(--ai-chatbot-offset);
    inset-inline-end: var(--ai-chatbot-offset);
    z-index: var(--ai-chatbot-z);
    transition: transform var(--ai-chatbot-duration) ease, opacity var(--ai-chatbot-duration) ease;
    will-change: transform, opacity;
}

#ai-chatbot-bubble > button {
    border: none;
    border-radius: var(--ai-chatbot-radius-round);
    width: var(--ai-chatbot-bubble-size);
    height: var(--ai-chatbot-bubble-size);
    cursor: pointer;
    padding-block-start: var(--ai-chatbot-space-4);
    background: var(--ai-chatbot-brand-gradient);
}

#ai-chatbot-bubble.is-hidden {
    opacity: 0;
    transform: translateY(var(--ai-chatbot-space-3)) scale(0.98);
    pointer-events: none;
}

/* -------------------------------------------------------------- Fenêtre */

#ai-chatbot-window {
    position: fixed;
    inset-block-end: var(--ai-chatbot-offset);
    inset-inline-end: var(--ai-chatbot-offset);
    width: var(--ai-chatbot-width);
    height: var(--ai-chatbot-height);
    background-color: var(--ai-chatbot-surface);
    border-radius: var(--ai-chatbot-radius-md);
    box-shadow: var(--ai-chatbot-shadow-lg);
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: var(--ai-chatbot-font-chrome);
    z-index: var(--ai-chatbot-z);
    opacity: 0;
    transform: translateY(var(--ai-chatbot-space-5)) scale(0.98);
    transform-origin: bottom right;
    transition: opacity var(--ai-chatbot-duration) ease, transform var(--ai-chatbot-duration-slow) ease;
    will-change: opacity, transform;
    pointer-events: none;
}

#ai-chatbot-window.is-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

@media (prefers-reduced-motion: reduce) {
    #ai-chatbot-window,
    #ai-chatbot-bubble {
        transition: none !important;
    }
}

/* --------------------------------------------------------------- Entête */

#ai-chatbot-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--ai-chatbot-text-on-brand);
    padding: var(--ai-chatbot-space-4);
    background: var(--ai-chatbot-brand-gradient);
}

#ai-chatbot-header button {
    background: none;
    border: none;
    color: inherit;
    font-size: var(--ai-chatbot-text-xl);
    cursor: pointer;
}

#ai-chatbot-title {
    display: flex;
    align-items: center;
    font-weight: 700;
}

.ai-chatbot .ai-chatbot-btn-wrapper {
    display: flex;
}

.ai-chatbot .ai-chatbot-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    border: 0;
}

/* ----------------------------------------------- Pages (base commune) */

.ai-chatbot .ai-chatbot-page {
    display: none;
    flex-direction: column;
    font-family: var(--ai-chatbot-font);
    color: var(--ai-chatbot-text);
    padding: var(--ai-chatbot-space-8) var(--ai-chatbot-space-6);
    overflow-y: auto;
}

.ai-chatbot .ai-chatbot-page h3 {
    margin: 0 0 var(--ai-chatbot-space-3);
    font-size: var(--ai-chatbot-text-xl);
    font-weight: 700;
    color: var(--ai-chatbot-text-strong);
}

.ai-chatbot .ai-chatbot-description {
    display: block;
    margin-block-end: var(--ai-chatbot-space-8);
    line-height: var(--ai-chatbot-leading);
    font-size: var(--ai-chatbot-text-md);
    color: var(--ai-chatbot-text-muted);
}

/* Liste de boutons : accueil et liste de produits. */
.ai-chatbot .ai-chatbot-choice-list {
    display: flex;
    flex-direction: column;
    gap: var(--ai-chatbot-space-5);
}

.ai-chatbot .ai-chatbot-choice-list button {
    all: unset;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--ai-chatbot-space-5);
    padding: var(--ai-chatbot-space-5) var(--ai-chatbot-space-6);
    background-color: var(--ai-chatbot-surface);
    border: 1px solid var(--ai-chatbot-border);
    border-radius: var(--ai-chatbot-radius-md);
    cursor: pointer;
    font-weight: 500;
    transition: all var(--ai-chatbot-duration-slow) var(--ai-chatbot-ease);
    box-shadow: var(--ai-chatbot-shadow-sm);
}

.ai-chatbot .ai-chatbot-choice-list button:hover {
    border-color: var(--ai-chatbot-primary);
    color: var(--ai-chatbot-primary);
    box-shadow: var(--ai-chatbot-shadow-md);
}

.ai-chatbot .ai-chatbot-choice-list button svg {
    flex-shrink: 0;
}

.ai-chatbot .ai-chatbot-empty-state {
    font-size: var(--ai-chatbot-text-md);
    color: var(--ai-chatbot-text-muted);
}

/* ------------------------------------------------------ Page : accueil */

#ai-chatbot-page-home-choices {
    padding: var(--ai-chatbot-space-7);
}

#ai-chatbot-page-home-choices > p {
    margin: 0 0 var(--ai-chatbot-space-6);
    font-weight: 600;
    opacity: 0.8;
}

/* ------------------------------------------------ Page : question libre */

#ai-chatbot-page-open-question {
    flex: 1;
    padding: 0;
    overflow: visible;
    /* Laisse la zone de messages gérer son propre défilement. */
    min-height: 0;
}

#ai-chatbot-messages {
    flex: 1;
    min-height: 0;
    padding: var(--ai-chatbot-space-4);
    overflow-y: auto;
    background: var(--ai-chatbot-surface-sunken);
}

.ai-chatbot .ai-chatbot-msg {
    display: flex;
    margin-block-end: var(--ai-chatbot-space-4);
    align-items: flex-end;
}

.ai-chatbot .ai-chatbot-msg.bot {
    justify-content: flex-start;
}

.ai-chatbot .ai-chatbot-msg.user {
    justify-content: flex-end;
}

.ai-chatbot .ai-chatbot-msg-content {
    max-width: 90%;
    padding: var(--ai-chatbot-space-4) var(--ai-chatbot-space-5);
    border-radius: var(--ai-chatbot-radius-lg);
    font-size: var(--ai-chatbot-text-md);
    line-height: var(--ai-chatbot-leading);
    text-align: start;
    overflow-wrap: anywhere;
}

.ai-chatbot .ai-chatbot-msg.bot .ai-chatbot-msg-content {
    background-color: var(--ai-chatbot-surface);
    border: 1px solid var(--ai-chatbot-border-soft);
    box-shadow: var(--ai-chatbot-shadow-xs);
    color: var(--ai-chatbot-text-strong);
}

.ai-chatbot .ai-chatbot-msg.user .ai-chatbot-msg-content {
    background-color: var(--ai-chatbot-primary);
    color: var(--ai-chatbot-text-on-brand);
}

/*
 * Neutralise la typographie héritée du thème à l'intérieur des bulles.
 * Les !important sont nécessaires : certains thèmes ciblent p/ul/li avec une
 * spécificité supérieure à la nôtre.
 */
.ai-chatbot .ai-chatbot-msg-content p,
.ai-chatbot .ai-chatbot-msg-content ul,
.ai-chatbot .ai-chatbot-msg-content ol,
.ai-chatbot .ai-chatbot-msg-content li {
    font-size: inherit !important;
    line-height: inherit !important;
    font-family: inherit !important;
    letter-spacing: normal !important;
    color: inherit !important;
    text-align: start !important;
}

.ai-chatbot .ai-chatbot-msg-content p {
    margin: 0 0 var(--ai-chatbot-space-3) !important;
    padding: 0 !important;
}

.ai-chatbot .ai-chatbot-msg-content ul,
.ai-chatbot .ai-chatbot-msg-content ol {
    margin: 0 0 var(--ai-chatbot-space-3) !important;
    padding-inline-start: var(--ai-chatbot-space-7) !important;
    list-style-position: outside !important;
}

.ai-chatbot .ai-chatbot-msg-content ul {
    list-style-type: disc !important;
}

.ai-chatbot .ai-chatbot-msg-content ol {
    list-style-type: decimal !important;
}

.ai-chatbot .ai-chatbot-msg-content li {
    margin: 0 0 var(--ai-chatbot-space-1) !important;
    padding: 0 !important;
}

.ai-chatbot .ai-chatbot-msg-content ul ul,
.ai-chatbot .ai-chatbot-msg-content ul ol,
.ai-chatbot .ai-chatbot-msg-content ol ul,
.ai-chatbot .ai-chatbot-msg-content ol ol {
    margin: var(--ai-chatbot-space-1) 0 0 !important;
}

.ai-chatbot .ai-chatbot-msg-content > *:first-child {
    margin-block-start: 0 !important;
}

.ai-chatbot .ai-chatbot-msg-content > *:last-child,
.ai-chatbot .ai-chatbot-msg-content li:last-child {
    margin-block-end: 0 !important;
}

.ai-chatbot .ai-chatbot-msg-content strong {
    font-weight: 600;
}

.ai-chatbot .ai-chatbot-msg-content a {
    font-weight: 600 !important;
    text-decoration: underline !important;
    text-underline-offset: 2px;
}

.ai-chatbot .ai-chatbot-msg.bot .ai-chatbot-msg-content a {
    color: var(--ai-chatbot-link) !important;
}

.ai-chatbot .ai-chatbot-msg.user .ai-chatbot-msg-content a {
    color: var(--ai-chatbot-text-on-brand) !important;
}

.ai-chatbot .ai-chatbot-msg.loading .ai-chatbot-msg-content {
    display: flex;
    align-items: center;
    gap: var(--ai-chatbot-space-2);
    padding: var(--ai-chatbot-space-1) var(--ai-chatbot-space-4);
}

.ai-chatbot .ai-chatbot-loading-status {
    font-size: var(--ai-chatbot-text-sm);
    font-style: italic;
    color: var(--ai-chatbot-text-muted);
}

#ai-chatbot-input-wrapper {
    display: flex;
    padding: var(--ai-chatbot-space-4);
    border-block-start: 1px solid var(--ai-chatbot-border-strong);
    background: var(--ai-chatbot-surface);
    box-shadow: var(--ai-chatbot-shadow-input);
}

#ai-chatbot-input-wrapper input {
    flex: 1;
    padding: var(--ai-chatbot-space-3);
    border-radius: var(--ai-chatbot-radius-pill);
    border: 1px solid var(--ai-chatbot-border-strong);
    outline: none;
    font-size: var(--ai-chatbot-text-md);
}

#ai-chatbot-input-wrapper button {
    margin-inline-start: var(--ai-chatbot-space-1);
    padding: var(--ai-chatbot-space-3) var(--ai-chatbot-space-5);
    background-color: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    color: var(--ai-chatbot-primary);
}

/* ------------------------------------------- Page : suivi de réclamation */

#ai-chatbot-page-track-support {
    padding: var(--ai-chatbot-space-7);
}

#ai-chatbot-page-track-support .ai-chatbot-description {
    margin-block-end: var(--ai-chatbot-space-6);
}

.ai-chatbot .ai-chatbot-field-group {
    display: flex;
    flex-direction: column;
    gap: var(--ai-chatbot-space-4);
}

.ai-chatbot .ai-chatbot-field-group label {
    font-weight: 600;
    font-size: var(--ai-chatbot-text-xs);
    color: var(--ai-chatbot-text-faint);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-inline-start: 2px;
}

.ai-chatbot .ai-chatbot-field-wrapper {
    display: flex;
    gap: var(--ai-chatbot-space-5);
    align-items: center;
    background: var(--ai-chatbot-surface-muted);
    padding: var(--ai-chatbot-space-2);
    border-radius: var(--ai-chatbot-radius-lg) var(--ai-chatbot-radius-pill) var(--ai-chatbot-radius-pill) var(--ai-chatbot-radius-lg);
    border: 1px solid var(--ai-chatbot-border);
    transition: border-color var(--ai-chatbot-duration) ease, box-shadow var(--ai-chatbot-duration) ease;
}

.ai-chatbot .ai-chatbot-field-wrapper:focus-within {
    border-color: var(--ai-chatbot-primary);
    box-shadow: 0 0 0 3px var(--ai-chatbot-primary-soft);
    background: var(--ai-chatbot-surface);
}

.ai-chatbot .ai-chatbot-field-wrapper input {
    flex-grow: 1;
    border: none;
    background: transparent;
    padding: var(--ai-chatbot-space-4) var(--ai-chatbot-space-5);
    outline: none;
    color: var(--ai-chatbot-text);
}

.ai-chatbot .ai-chatbot-field-wrapper button {
    all: unset;
    cursor: pointer;
    background: var(--ai-chatbot-primary);
    width: var(--ai-chatbot-action-size);
    height: var(--ai-chatbot-action-size);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--ai-chatbot-radius-round);
    transition: all var(--ai-chatbot-duration) ease;
    flex-shrink: 0;
}

.ai-chatbot .ai-chatbot-field-wrapper button svg {
    fill: var(--ai-chatbot-text-on-brand);
}

#ai-chatbot-status-box {
    display: none;
    margin-block-end: var(--ai-chatbot-space-7);
    padding: var(--ai-chatbot-space-5) var(--ai-chatbot-space-6);
    border-radius: var(--ai-chatbot-radius-md);
    background: var(--ai-chatbot-surface-accent);
    border-inline-start: 4px solid var(--ai-chatbot-primary);
    animation: ai-chatbot-fade-in var(--ai-chatbot-duration-slow) ease;
}

@keyframes ai-chatbot-fade-in {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

#ai-chatbot-status-box .ai-chatbot-status-label {
    display: block;
    font-size: var(--ai-chatbot-text-sm);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
    color: var(--ai-chatbot-text-muted);
    margin-block-end: var(--ai-chatbot-space-1);
}

#ai-chatbot-status-box .ai-chatbot-status-value {
    font-size: var(--ai-chatbot-text-lg);
    font-weight: 600;
    color: var(--ai-chatbot-text-strong);
}

#ai-chatbot-response-msg {
    display: none;
    font-size: var(--ai-chatbot-text-sm);
    margin-block: var(--ai-chatbot-space-4) var(--ai-chatbot-space-7);
    padding: var(--ai-chatbot-space-3) var(--ai-chatbot-space-5);
    border-radius: var(--ai-chatbot-radius-sm);
    line-height: 1.4;
    background: var(--ai-chatbot-danger-surface);
    color: var(--ai-chatbot-danger-text);
    border: 1px solid var(--ai-chatbot-danger-border);
}
