/**
 * mod_chatifs — bulle de chat flottante (BEM, tokens en tête)
 * (C) 2026 i-FormaSite
 */

.chatifs {
    /* Couleur principale d'ifs-Styles si présente, sinon bleu ; surchargeable par le module. */
    --chatifs-accent: var(--ifs-s-primary, #1d4ed8);
    --chatifs-accent-text: #ffffff;
    --chatifs-bg: #ffffff;
    --chatifs-fg: #1e293b;
    --chatifs-muted: #64748b;
    --chatifs-border: #e2e8f0;
    --chatifs-client-bg: var(--chatifs-accent);
    --chatifs-client-fg: var(--chatifs-accent-text);
    --chatifs-bot-bg: #f1f5f9;
    --chatifs-radius: 16px;
    --chatifs-shadow: 0 12px 40px rgba(15, 23, 42, 0.22);
    --chatifs-z: 9990;

    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: var(--chatifs-z);
    font-size: 15px;
    line-height: 1.45;
    color: var(--chatifs-fg);
}

.chatifs--left {
    right: auto;
    left: 24px;
}

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

.chatifs__bubble {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    border: 0;
    border-radius: 50%;
    background: var(--chatifs-accent);
    color: var(--chatifs-accent-text);
    cursor: pointer;
    box-shadow: var(--chatifs-shadow);
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.chatifs__bubble:hover,
.chatifs__bubble:focus-visible {
    transform: scale(1.06);
}

.chatifs__bubble:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--chatifs-accent) 40%, transparent);
    outline-offset: 2px;
}

.chatifs__bubble-close {
    display: none;
    font-size: 26px;
    line-height: 1;
}

.chatifs.is-open .chatifs__bubble-icon {
    display: none;
}

.chatifs.is-open .chatifs__bubble-close {
    display: block;
}

/* ---------- Panneau ---------- */

.chatifs__panel {
    position: absolute;
    right: 0;
    bottom: 72px;
    display: flex;
    flex-direction: column;
    width: min(370px, calc(100vw - 32px));
    height: min(520px, calc(100vh - 120px));
    overflow: hidden;
    background: var(--chatifs-bg);
    border: 1px solid var(--chatifs-border);
    border-radius: var(--chatifs-radius);
    box-shadow: var(--chatifs-shadow);
    opacity: 0;
    transform: translateY(12px);
    transition: transform 0.25s ease, opacity 0.25s ease;
}

.chatifs--left .chatifs__panel {
    right: auto;
    left: 0;
}

.chatifs__panel.is-visible {
    opacity: 1;
    transform: translateY(0);
}

/* ---------- En-tête ---------- */

.chatifs__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    background: var(--chatifs-accent);
    color: var(--chatifs-accent-text);
}

.chatifs__header-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.chatifs__title {
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chatifs__status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    opacity: 0.9;
}

.chatifs__status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
}

.chatifs__close {
    flex: none;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: inherit;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}

.chatifs__close:hover,
.chatifs__close:focus-visible {
    background: rgba(255, 255, 255, 0.18);
}

/* ---------- Messages ---------- */

.chatifs__messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
    scroll-behavior: smooth;
}

.chatifs__msg {
    max-width: 85%;
    padding: 9px 13px;
    border-radius: 14px;
    white-space: pre-wrap;
    overflow-wrap: break-word;
}

.chatifs__msg--client {
    align-self: flex-end;
    background: var(--chatifs-client-bg);
    color: var(--chatifs-client-fg);
    border-bottom-right-radius: 4px;
}

.chatifs__msg--bot {
    align-self: flex-start;
    background: var(--chatifs-bot-bg);
    border-bottom-left-radius: 4px;
}

.chatifs__msg--info {
    align-self: center;
    background: transparent;
    color: var(--chatifs-muted);
    font-size: 13px;
    text-align: center;
}

.chatifs__msg--error {
    align-self: flex-start;
    background: #fef2f2;
    color: #b91c1c;
}

.chatifs__msg--ack {
    align-self: flex-start;
    background: color-mix(in srgb, var(--chatifs-accent) 10%, var(--chatifs-bot-bg));
    color: var(--chatifs-fg);
    border-bottom-left-radius: 4px;
    font-size: 14px;
}

.chatifs__msg.is-pending {
    color: var(--chatifs-muted);
    font-style: italic;
}

.chatifs__msg.is-pending::after {
    content: '…';
    animation: chatifs-dots 1.2s steps(4, end) infinite;
}

@keyframes chatifs-dots {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
}

/* ---------- Formulaire ---------- */

.chatifs__form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--chatifs-border);
    background: var(--chatifs-bg);
}

.chatifs__input {
    flex: 1;
    max-height: 110px;
    padding: 9px 12px;
    border: 1px solid var(--chatifs-border);
    border-radius: 10px;
    background: var(--chatifs-bg);
    color: var(--chatifs-fg);
    font: inherit;
    resize: none;
    /* Neutralise les styles de formulaire génériques des templates (hauteur, ombre, marges). */
    width: auto;
    min-width: 0;
    height: auto;
    min-height: 40px;
    margin: 0;
    box-shadow: none;
    line-height: 1.4;
    overflow-y: hidden;
}

.chatifs__input:focus-visible {
    outline: 2px solid var(--chatifs-accent);
    outline-offset: 0;
    border-color: var(--chatifs-accent);
}

.chatifs__send {
    flex: none;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 10px;
    background: var(--chatifs-accent);
    color: var(--chatifs-accent-text);
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.chatifs__send:hover,
.chatifs__send:focus-visible {
    transform: scale(1.05);
}

.chatifs__send:disabled {
    opacity: 0.5;
    cursor: default;
    transform: none;
}

.chatifs__sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ---------- Mode sombre ---------- */

@media (prefers-color-scheme: dark) {
    .chatifs {
        --chatifs-bg: #0f172a;
        --chatifs-fg: #e2e8f0;
        --chatifs-muted: #94a3b8;
        --chatifs-border: #1e293b;
        --chatifs-bot-bg: #1e293b;
    }

    .chatifs__msg--error {
        background: #450a0a;
        color: #fca5a5;
    }
}

/* ---------- Accessibilité mouvement ---------- */

@media (prefers-reduced-motion: reduce) {
    .chatifs__bubble,
    .chatifs__panel,
    .chatifs__send {
        transition: none;
    }

    .chatifs__messages {
        scroll-behavior: auto;
    }

    .chatifs__msg.is-pending::after {
        animation: none;
        content: '…';
    }
}

/* ---------- Assistant du site (0.3.0) ---------- */

.chatifs__msg a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
    overflow-wrap: anywhere;
}

.chatifs__msg--bot a {
    color: var(--chatifs-accent);
}

.chatifs__notice {
    margin: 0;
    padding: 0 14px 10px;
    font-size: 12px;
    line-height: 1.35;
    color: var(--chatifs-muted);
    background: var(--chatifs-bg);
}

/* ---------- Questions de base (0.3.2) ---------- */

.chatifs__suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 4px 0 2px;
}

.chatifs .chatifs__suggestion {
    margin: 0;
    padding: 6px 12px;
    border: 1px solid var(--chatifs-accent);
    border-radius: 999px;
    background: var(--chatifs-bg);
    color: var(--chatifs-accent);
    font: inherit;
    font-size: 13px;
    line-height: 1.3;
    text-align: left;
    cursor: pointer;
    box-shadow: none;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.chatifs .chatifs__suggestion:hover,
.chatifs .chatifs__suggestion:focus-visible {
    background: var(--chatifs-accent);
    color: var(--chatifs-accent-text);
}

.chatifs .chatifs__suggestion:focus-visible {
    outline: 2px solid var(--chatifs-accent);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .chatifs .chatifs__suggestion {
        transition: none;
    }
}

/* ---------- Effacer la conversation (0.3.3) ---------- */

.chatifs .chatifs__purge {
    flex: none;
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    margin: 0 0 0 auto;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: inherit;
    cursor: pointer;
    box-shadow: none;
    opacity: 0.85;
}

.chatifs .chatifs__purge:hover,
.chatifs .chatifs__purge:focus-visible {
    background: rgba(255, 255, 255, 0.18);
    opacity: 1;
}

.chatifs__header .chatifs__close {
    margin-left: 0;
}

.chatifs__confirm {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    border: 1px solid var(--chatifs-border);
    border-radius: 12px;
    background: var(--chatifs-bot-bg);
}

.chatifs__confirm p {
    flex: 1 1 100%;
    margin: 0 0 4px;
    font-size: 14px;
}

.chatifs .chatifs__confirm-yes {
    background: var(--chatifs-accent);
    color: var(--chatifs-accent-text);
}
