/* ============================================================================
   Cockpit — assistant.css
   Widget « Une question ? » (public/assets/js/assistant.js), commun à la vitrine
   et aux trois espaces connectés. Uniquement des tokens du design system (avec
   valeurs de repli) : clair / sombre suivent la page hôte. Préfixe .cka-.
   Dans l'application, le bouton se range AU-DESSUS du bouton de messagerie
   (.msg-fab, 56 px puis 48 px sous 560 px) ; sur la vitrine mobile, au-dessus de
   la barre « Offre Pionnier » quand elle est visible.
   ============================================================================ */

.cka {
    --cka-gap: var(--space-5, 1.25rem);
    --cka-bg: var(--bg-elevated, var(--bg, #fff));
    --cka-line: var(--border-subtle, #e4e4e7);
    --cka-radius: var(--radius-lg, 14px);
    position: fixed;
    right: calc(var(--cka-gap) + env(safe-area-inset-right, 0px));
    bottom: calc(var(--cka-gap) + env(safe-area-inset-bottom, 0px));
    z-index: 91;
    font-family: var(--font-sans, system-ui, sans-serif);
    color: var(--text, #18181b);
}
.cka--app { bottom: calc(var(--cka-gap) + 56px + var(--space-3, 0.75rem) + env(safe-area-inset-bottom, 0px)); }
.cka--app.cka--alone { bottom: calc(var(--cka-gap) + env(safe-area-inset-bottom, 0px)); }

/* — Bouton d'ouverture — */
.cka__launcher {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 48px;
    padding: 0 1.1rem 0 0.9rem;
    border-radius: var(--radius-full, 9999px);
    border: 1px solid var(--accent, #c2410c);
    background: var(--accent, #c2410c);
    color: var(--on-accent, #fff);
    font: inherit;
    font-size: var(--text-sm, 0.9rem);
    font-weight: 500;
    box-shadow: var(--shadow-lg, 0 12px 24px rgba(10, 10, 11, 0.08));
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.cka__launcher:hover { transform: translateY(-1px); box-shadow: var(--shadow-xl, 0 24px 48px rgba(10, 10, 11, 0.12)); }
.cka__launcher:focus-visible { outline: 2px solid var(--accent, #c2410c); outline-offset: 3px; }
.cka__launcher svg { flex: none; }
/* Dans l'application : pastille ronde, plus discrète que la messagerie. */
.cka--app .cka__launcher {
    width: 48px;
    padding: 0;
    justify-content: center;
    background: var(--cka-bg);
    color: var(--accent-text, var(--accent, #c2410c));
    border-color: var(--border, #d4d4d8);
}
.cka--app .cka__launcher-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.cka.is-open .cka__launcher { display: none; }

/* — Panneau — */
.cka__panel {
    position: absolute;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    width: min(400px, calc(100vw - 2 * var(--cka-gap)));
    height: min(600px, calc(100vh - 7rem));
    height: min(600px, calc(100dvh - 7rem));
    background: var(--cka-bg);
    border: 1px solid var(--cka-line);
    border-radius: var(--cka-radius);
    box-shadow: var(--shadow-xl, 0 24px 48px rgba(10, 10, 11, 0.12));
    overflow: hidden;
}
.cka__panel[hidden] { display: none; }

.cka__head {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.9rem 0.9rem 0.8rem 1.1rem;
    border-bottom: 1px solid var(--cka-line);
}
.cka__title { margin: 0; font-size: var(--text-base, 1rem); font-weight: 600; line-height: 1.3; }
.cka__subtitle { margin: 0.15rem 0 0; font-size: var(--text-xs, 0.8rem); color: var(--text-dim, #5e5e63); line-height: 1.35; }
.cka__head-text { flex: 1; min-width: 0; }
.cka__icon-btn {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: var(--radius, 6px);
    background: transparent;
    color: var(--text-soft, #3f3f46);
    cursor: pointer;
}
.cka__icon-btn:hover { background: var(--bg-sunken, #f5f5f4); }
.cka__icon-btn:focus-visible { outline: 2px solid var(--accent, #c2410c); outline-offset: 1px; }

.cka__log {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 1rem 1.1rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.cka__msg {
    max-width: 92%;
    font-size: var(--text-sm, 0.9rem);
    line-height: 1.5;
    overflow-wrap: anywhere;
}
.cka__msg p { margin: 0; }
.cka__msg p + p, .cka__msg p + ul, .cka__msg p + ol, .cka__msg ul + p, .cka__msg ol + p { margin-top: 0.5rem; }
.cka__msg ul, .cka__msg ol { margin: 0.35rem 0 0; padding-left: 1.2rem; }
.cka__msg li + li { margin-top: 0.2rem; }
.cka__msg a { color: var(--accent-text, var(--accent, #c2410c)); text-decoration: underline; text-underline-offset: 2px; }
.cka__msg--bot { align-self: flex-start; }
.cka__msg--user {
    align-self: flex-end;
    padding: 0.55rem 0.8rem;
    border-radius: 12px 12px 4px 12px;
    background: var(--accent-soft, #ffedd5);
    color: var(--text, #18181b);
}
.cka__msg--error { color: var(--danger, #b91c1c); }
.cka__typing { display: inline-flex; gap: 4px; padding: 0.35rem 0; }
.cka__typing span {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--text-mute, #737378);
    animation: cka-blink 1.2s infinite ease-in-out;
}
.cka__typing span:nth-child(2) { animation-delay: 0.15s; }
.cka__typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes cka-blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* — Suggestions — */
.cka__chips { display: flex; flex-wrap: wrap; gap: 0.4rem; padding: 0.25rem 1.1rem 0.6rem; }
.cka__chips:empty { display: none; }
.cka__chip {
    padding: 0.4rem 0.7rem;
    border: 1px solid var(--border, #d4d4d8);
    border-radius: var(--radius-full, 9999px);
    background: transparent;
    color: var(--text-soft, #3f3f46);
    font: inherit;
    font-size: var(--text-xs, 0.8rem);
    line-height: 1.3;
    text-align: left;
    cursor: pointer;
}
.cka__chip:hover { border-color: var(--accent, #c2410c); color: var(--accent-text, #9a3412); }
.cka__chip:focus-visible { outline: 2px solid var(--accent, #c2410c); outline-offset: 1px; }
.cka__chip--cta { border-color: var(--accent, #c2410c); color: var(--accent-text, #9a3412); font-weight: 500; }

/* — Saisie — */
.cka__form {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.7rem 0.9rem 0.5rem 1.1rem;
    border-top: 1px solid var(--cka-line);
}
.cka__input {
    flex: 1;
    min-height: 40px;
    max-height: 120px;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border, #d4d4d8);
    border-radius: var(--radius-md, 10px);
    background: var(--bg, #fff);
    color: var(--text, #18181b);
    font: inherit;
    font-size: 16px; /* évite le zoom automatique d'iOS */
    line-height: 1.4;
    resize: none;
}
.cka__input:focus-visible { outline: 2px solid var(--accent, #c2410c); outline-offset: 0; border-color: transparent; }
.cka__send {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: var(--radius-md, 10px);
    background: var(--accent, #c2410c);
    color: var(--on-accent, #fff);
    cursor: pointer;
}
.cka__send:disabled { opacity: 0.5; cursor: default; }
.cka__send:focus-visible { outline: 2px solid var(--accent, #c2410c); outline-offset: 2px; }
.cka__note { margin: 0; padding: 0 1.1rem 0.7rem; font-size: 0.7rem; line-height: 1.35; color: var(--text-mute, #737378); }
.cka__note a { color: inherit; }

/* — Petits écrans : panneau en feuille basse, presque pleine largeur — */
@media (max-width: 560px) {
    .cka--app { bottom: calc(var(--cka-gap) + 48px + var(--space-3, 0.75rem) + env(safe-area-inset-bottom, 0px)); }
}
@media (max-width: 480px) {
    .cka { --cka-gap: var(--space-4, 1rem); }
    .cka.is-open { left: 0.5rem; right: 0.5rem; bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px)); }
    .cka.is-open .cka__panel { width: 100%; height: min(640px, calc(100dvh - 4.5rem)); }
}
/* Vitrine mobile : la barre « Offre Pionnier » (≈ 64 px) occupe le bas d'écran. */
@media (max-width: 720px) {
    body:has(.lp-stickybar.is-visible) .cka:not(.is-open) { bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }
}

@media (prefers-reduced-motion: reduce) {
    .cka__launcher { transition: none; }
    .cka__launcher:hover { transform: none; }
    .cka__typing span { animation: none; opacity: 0.6; }
}
@media print { .cka { display: none; } }
