/* Conseiller IA — bouton flottant, amorce et panneau de conversation.
   Reprend les couleurs et formes du catalogue (encre, magenta, brume, rayons arrondis). */

.ai {
    --ai-offset: 1.25rem;
    position: fixed;
    right: var(--ai-offset);
    bottom: calc(var(--ai-offset) + env(safe-area-inset-bottom));
    z-index: 70;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.75rem;
    font-family: var(--font-body);
    pointer-events: none;
}
.ai > * { pointer-events: auto; }

/* ---------- Bouton ---------- */

.ai-launcher {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    min-height: 3.5rem;
    padding: 0.55rem 1.2rem 0.55rem 0.7rem;
    border: 0;
    border-radius: 999px;
    background: var(--encre);
    color: var(--blanc);
    box-shadow: 0 14px 34px -14px rgb(34 27 38 / 0.65);
    cursor: pointer;
    transition: transform 0.2s ease, background-color 0.2s ease;
}
.ai-launcher:hover { background: var(--magenta-fonce); transform: translateY(-2px); }
.ai-launcher:focus-visible { outline: 3px solid var(--magenta); outline-offset: 3px; }
.ai-spark {
    flex: none;
    width: 2.3rem;
    height: 2.3rem;
    padding: 0.5rem;
    border-radius: 50%;
    background: var(--magenta);
    color: var(--blanc);
}
.ai-launcher:hover .ai-spark { background: var(--blanc); color: var(--magenta-fonce); }
.ai-launcher-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; text-align: left; }
.ai-launcher-hint { font-size: 0.75rem; opacity: 0.75; }
.ai-launcher-label { font-family: var(--font-title); font-weight: 700; font-size: 1rem; }
.ai.is-open .ai-launcher { display: none; }

/* ---------- Amorce ---------- */

.ai-teaser {
    position: relative;
    display: flex;
    align-items: flex-start;
    max-width: 19rem;
    border-radius: 18px 18px 6px 18px;
    background: var(--blanc);
    box-shadow: 0 18px 40px -18px rgb(34 27 38 / 0.45), 0 0 0 1px var(--filet);
    animation: ai-pop 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.ai-teaser-text {
    flex: 1;
    padding: 0.9rem 0.4rem 0.9rem 1.05rem;
    border: 0;
    background: none;
    font-size: 0.95rem;
    line-height: 1.4;
    text-align: left;
    cursor: pointer;
}
.ai-teaser-text:hover { color: var(--magenta-fonce); }
.ai-teaser-close {
    flex: none;
    display: grid;
    place-items: center;
    width: 2.25rem;
    height: 2.25rem;
    margin: 0.35rem 0.35rem 0 0;
    border: 0;
    border-radius: 50%;
    background: none;
    color: var(--gris);
    cursor: pointer;
}
.ai-teaser-close:hover { background: var(--brume); color: var(--encre); }

@keyframes ai-pop {
    from { opacity: 0; transform: translateY(10px) scale(0.96); }
    to { opacity: 1; transform: none; }
}

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

.ai-panel {
    display: flex;
    flex-direction: column;
    width: min(26.5rem, calc(100vw - 2 * var(--ai-offset)));
    height: min(41rem, calc(100vh - 2 * var(--ai-offset) - 1rem));
    height: min(41rem, calc(100dvh - 2 * var(--ai-offset) - 1rem));
    overflow: hidden;
    border-radius: 24px;
    background: var(--blanc);
    box-shadow: 0 28px 70px -24px rgb(34 27 38 / 0.55), 0 0 0 1px var(--filet);
    animation: ai-pop 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}
.ai-head {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.85rem 0.7rem 0.85rem 1rem;
    background: var(--encre);
    color: var(--blanc);
}
.ai-avatar {
    flex: none;
    display: grid;
    place-items: center;
    width: 2.4rem;
    height: 2.4rem;
    border-radius: 50%;
    background: var(--magenta);
}
.ai-head-text { flex: 1; min-width: 0; }
.ai-title { margin: 0; font-family: var(--font-title); font-size: 1.05rem; font-weight: 700; line-height: 1.2; }
.ai-subtitle { margin: 0.1rem 0 0; font-size: 0.78rem; opacity: 0.75; }
.ai-icon-btn {
    flex: none;
    display: grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--blanc);
    cursor: pointer;
}
.ai-icon-btn:hover { background: rgb(255 255 255 / 0.12); }
.ai-icon-btn:focus-visible, .ai-chip:focus-visible, .ai-add:focus-visible, .ai-offer-btn:focus-visible, .ai-send:focus-visible {
    outline: 3px solid var(--magenta);
    outline-offset: 2px;
}

.ai-log {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 1rem 1rem 0.5rem;
    background: var(--brume);
    scroll-behavior: smooth;
}
.ai-msg { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 0.9rem; }
.ai-msg-user { align-items: flex-end; }
.ai-bubble {
    max-width: 88%;
    margin: 0;
    padding: 0.7rem 0.95rem;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.5;
    overflow-wrap: anywhere;
}
.ai-msg-user .ai-bubble { border-bottom-right-radius: 6px; background: var(--magenta-fonce); color: var(--blanc); }
.ai-msg-bot .ai-bubble { align-self: flex-start; border-bottom-left-radius: 6px; background: var(--blanc); box-shadow: 0 1px 0 var(--filet); }
.ai-msg-error .ai-bubble { background: #fdf0ef; color: var(--alerte); }
.ai-text p { margin: 0 0 0.5rem; }
.ai-text p:last-child, .ai-text ul:last-child { margin-bottom: 0; }
.ai-text ul { margin: 0 0 0.5rem; padding-left: 1.1rem; }
.ai-text li { margin-bottom: 0.3rem; }
.ai-text li::marker { color: var(--magenta); }
.ai-text strong { font-weight: 700; }

/* Indicateur de recherche */
.ai-typing .ai-bubble { display: inline-flex; align-items: center; gap: 0.6rem; color: var(--gris); }
.ai-dots { position: relative; width: 2rem; height: 0.5rem; }
.ai-dots, .ai-dots::before, .ai-dots::after { background: radial-gradient(circle, var(--magenta) 0.22rem, transparent 0.24rem) 0 50% / 0.66rem 0.5rem repeat-x; }
.ai-dots { animation: ai-blink 1.1s infinite ease-in-out; }
@keyframes ai-blink { 50% { opacity: 0.35; } }

/* Réponses rapides */
.ai-chips { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.ai-chip {
    min-height: 2.4rem;
    padding: 0.4rem 0.9rem;
    border: 1.5px solid var(--magenta-fonce);
    border-radius: 999px;
    background: var(--blanc);
    color: var(--magenta-fonce);
    font-size: 0.88rem;
    font-weight: 600;
    line-height: 1.25;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}
.ai-chip:hover { background: var(--magenta-fonce); color: var(--blanc); }

/* Cartes produits : défilement horizontal */
.ai-cards {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 10.5rem;
    gap: 0.6rem;
    margin: 0 -1rem;
    padding: 0.1rem 1rem 0.4rem;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-padding: 0 1rem;
}
.ai-card {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 16px;
    background: var(--blanc);
    box-shadow: 0 0 0 1px var(--filet);
    scroll-snap-align: start;
}
.ai-card-media { position: relative; display: block; aspect-ratio: 1; background: #fafafa; }
.ai-card-media img { width: 100%; height: 100%; object-fit: contain; padding: 0.6rem; }
.ai-card-media.is-missing img { visibility: hidden; }
.ai-badge {
    position: absolute;
    left: 0.45rem;
    top: 0.45rem;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: #e5f3ea;
    color: var(--vert);
    font-size: 0.7rem;
    font-weight: 700;
}
.ai-card-body { display: flex; flex: 1; flex-direction: column; gap: 0.2rem; padding: 0.6rem 0.7rem 0.7rem; }
.ai-card-title {
    display: -webkit-box;
    overflow: hidden;
    color: var(--encre);
    font-size: 0.86rem;
    font-weight: 600;
    line-height: 1.3;
    text-decoration: none;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}
.ai-card-title:hover { color: var(--magenta-fonce); text-decoration: underline; }
.ai-card-price { margin: 0; font-size: 0.82rem; font-weight: 700; color: var(--magenta-fonce); }
.ai-card-meta { margin: 0; font-size: 0.74rem; line-height: 1.35; color: var(--gris); }
.ai-card-add { display: flex; gap: 0.35rem; margin-top: auto; padding-top: 0.45rem; }
.ai-qty {
    width: 4.2rem;
    min-width: 0;
    min-height: 2.3rem;
    padding: 0.25rem 0.4rem;
    border: 1px solid var(--filet-fort);
    border-radius: 10px;
    background: var(--blanc);
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
}
.ai-add {
    flex: 1;
    min-height: 2.3rem;
    padding: 0.25rem 0.4rem;
    border: 0;
    border-radius: 10px;
    background: var(--encre);
    color: var(--blanc);
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
}
.ai-add:hover { background: var(--magenta-fonce); }
.ai-add.is-done { background: var(--vert); }

/* Offre */
.ai-offer {
    padding: 0.95rem 1rem 1rem;
    border-radius: 18px;
    background: var(--rose);
    box-shadow: inset 0 0 0 1px rgb(236 0 140 / 0.25);
}
.ai-offer-title { margin: 0 0 0.25rem; font-family: var(--font-title); font-size: 1rem; font-weight: 700; }
.ai-offer-text { margin: 0 0 0.75rem; font-size: 0.86rem; line-height: 1.45; color: var(--gris); }
.ai-offer-btn {
    width: 100%;
    min-height: 2.9rem;
    border: 0;
    border-radius: 999px;
    background: var(--magenta-fonce);
    color: var(--blanc);
    font-weight: 700;
    cursor: pointer;
}
.ai-offer-btn:hover { background: var(--encre); }

/* Saisie */
.ai-form {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.7rem 0.75rem 0.35rem;
    border-top: 1px solid var(--filet);
    background: var(--blanc);
}
.ai-input {
    flex: 1;
    min-height: 2.75rem;
    max-height: 140px;
    padding: 0.65rem 0.9rem;
    border: 1px solid var(--filet-fort);
    border-radius: 18px;
    background: var(--blanc);
    font-size: 1rem; /* 16 px : pas de zoom automatique sur iOS */
    line-height: 1.35;
    resize: none;
}
.ai-input:focus { outline: none; border-color: var(--magenta-fonce); box-shadow: 0 0 0 3px rgb(236 0 140 / 0.15); }
.ai-send {
    flex: none;
    display: grid;
    place-items: center;
    width: 2.75rem;
    height: 2.75rem;
    border: 0;
    border-radius: 50%;
    background: var(--magenta-fonce);
    color: var(--blanc);
    cursor: pointer;
}
.ai-send:hover { background: var(--encre); }
.ai-send[disabled] { opacity: 0.5; cursor: progress; }
.ai-disclaimer { margin: 0; padding: 0.2rem 1rem 0.65rem; background: var(--blanc); font-size: 0.68rem; line-height: 1.35; color: var(--gris); }

.ai-prefilled { margin-top: 0.35rem; color: var(--magenta-fonce); }

/* Fiche produit sur mobile : au-dessus de la barre de commande fixe. */
@media (max-width: 960px) {
    .page-product .ai:not(.is-open) { bottom: calc(5.75rem + env(safe-area-inset-bottom)); }
}

/* Mobile : panneau plein écran, bouton compact. */
@media (max-width: 47.99rem) {
    .ai { --ai-offset: 0.85rem; }
    .ai-launcher { min-height: 3.1rem; padding-right: 1rem; }
    .ai-launcher-hint { display: none; }
    .ai.is-open { inset: 0; gap: 0; }
    .ai.is-open .ai-teaser { display: none; }
    .ai-panel { width: 100%; height: 100%; border-radius: 0; animation: none; }
    .ai-head { padding-top: calc(0.85rem + env(safe-area-inset-top)); }
    .ai-disclaimer { padding-bottom: calc(0.65rem + env(safe-area-inset-bottom)); }
    .ai-teaser { max-width: min(19rem, calc(100vw - 2rem)); }
}

@media (prefers-reduced-motion: reduce) {
    .ai-teaser, .ai-panel { animation: none; }
    .ai-dots { animation: none; }
    .ai-log { scroll-behavior: auto; }
    .ai-launcher { transition: none; }
}

@media print {
    .ai { display: none; }
}
