/* =============================================================
   Chatbot Jonathan — widget conversationnel
   Dark theme + glass cohérent avec app.css. Z-index 8000 (sous
   cookie consent icon à 9000 pour ne pas bloquer la modale cookie).
   ============================================================= */

/* ===== Trigger flottant ===== */
.chatbot-trigger {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 42px;
    height: 42px;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    border: 0.5px solid rgb(var(--tint) / 0.18);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    cursor: pointer;
    z-index: 8000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 240ms ease, box-shadow 240ms ease;
}
.chatbot-trigger:hover {
    transform: scale(1.06);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.55);
}
.chatbot-trigger:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 4px;
}

/* ===== Overlay (backdrop blur, ferme au click) ===== */
.chatbot-overlay {
    position: fixed;
    inset: 0;
    background: var(--scrim);
    backdrop-filter: blur(12px) saturate(140%);
    -webkit-backdrop-filter: blur(12px) saturate(140%);
    z-index: 7999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 280ms ease;
    cursor: pointer;
}
.chatbot-overlay[data-visible="true"] {
    opacity: 1;
    pointer-events: auto;
}

/* ===== Widget centré (style Spotlight / Vision Pro) ===== */
.chatbot-widget {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -48%) scale(0.96);
    width: min(560px, calc(100vw - 48px));
    height: min(640px, calc(100vh - 100px));
    background: var(--surface-elevated);
    backdrop-filter: blur(32px) saturate(180%);
    -webkit-backdrop-filter: blur(32px) saturate(180%);
    border: 0.5px solid rgb(var(--tint) / 0.14);
    border-radius: 20px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.7), 0 0 0 0.5px rgb(var(--tint) / 0.05) inset;
    z-index: 8000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 280ms ease, transform 320ms cubic-bezier(0.32, 0.72, 0, 1);
}
.chatbot-widget[data-visible="true"] {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

/* ===== Header ===== */
.chatbot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 0.5px solid rgb(var(--tint) / 0.08);
    flex-shrink: 0;
}
.chatbot-header__title {
    font-weight: 500;
    color: var(--text);
    font-size: 15px;
    letter-spacing: -0.005em;
}
.chatbot-header__close {
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 6px;
    transition: color 200ms ease, background 200ms ease;
}
.chatbot-header__close:hover {
    color: var(--text);
    background: rgb(var(--tint) / 0.06);
}

/* ===== Messages container ===== */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

/* ===== Bulles messages ===== */
.chatbot-message {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    max-width: 85%;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.chatbot-message--bot {
    background: rgb(var(--tint) / 0.06);
    color: var(--text);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.chatbot-message--bot a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
    text-decoration-thickness: 1px;
}
.chatbot-message--bot a:hover {
    text-decoration-thickness: 2px;
}
.chatbot-message--bot strong { font-weight: 600; color: var(--text); }
.chatbot-message--bot em { font-style: italic; color: var(--text-dim); }
.chatbot-message__context {
    margin: 10px 0 0;
    font-size: 13px;
    color: var(--text-dim);
    line-height: 1.5;
    font-style: italic;
}
.chatbot-message--bot small {
    display: block;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 0.5px solid rgb(var(--tint) / 0.08);
    font-size: 13px;
    color: var(--text-dim);
    line-height: 1.5;
}
.chatbot-message--bot small a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.chatbot-message--user {
    background: var(--accent);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}
.chatbot-message--error {
    background: rgba(255, 122, 122, 0.12);
    color: #ff7a7a;
    border: 0.5px solid rgba(255, 122, 122, 0.35);
    align-self: flex-start;
}

/* ===== Form (input + submit) ===== */
.chatbot-form {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 0.5px solid rgb(var(--tint) / 0.08);
    flex-shrink: 0;
}
.chatbot-input {
    flex: 1;
    min-width: 0;
    background: rgb(var(--tint) / 0.04);
    border: 0.5px solid rgb(var(--tint) / 0.1);
    border-radius: 999px;
    padding: 10px 16px;
    color: var(--text);
    font-size: 14px;
    font-family: var(--font-sans);
    outline: none;
    transition: border-color 200ms ease, background 200ms ease;
}
.chatbot-input:focus {
    border-color: var(--accent);
    background: rgb(var(--tint) / 0.06);
}
.chatbot-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.chatbot-submit {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 999px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: filter 200ms ease, transform 200ms ease;
    flex-shrink: 0;
}
.chatbot-submit:hover { filter: brightness(1.1); }
.chatbot-submit:active { transform: scale(0.95); }
.chatbot-submit:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Loading dots (pendant streaming) ===== */
.chatbot-typing {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}
.chatbot-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-dim);
    animation: chatbot-dot 1.4s infinite ease-in-out;
}
.chatbot-typing span:nth-child(2) { animation-delay: 0.15s; }
.chatbot-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chatbot-dot {
    0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
}

/* ===== Mobile : widget full-screen, overlay caché (le widget couvre déjà tout) ===== */
@media (max-width: 640px) {
    .chatbot-overlay { display: none; }
    .chatbot-widget {
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-height: none;
        border-radius: 0;
        border: none;
        transform: translateY(20px);
    }
    .chatbot-widget[data-visible="true"] {
        transform: translateY(0);
    }
    .chatbot-trigger {
        bottom: 16px;
        right: 16px;
    }
}

/* ===== Quand le chatbot est ouvert : masquer l'icône cookie persistante =====
   Sinon elle apparaît par-dessus le widget chat (cookie z-index 8999 > chat 8000)
   et bloque visuellement la conversation, surtout sur mobile full-screen.
   L'utilisateur retrouve l'icône cookie à la fermeture du chat. */
body[data-chatbot-open="true"] .cookie-icon-wrap { display: none; }

/* ===== Bulle consent RGPD (Phase 3 chatbot-persistence) =====
   Affichée en tête de la conversation quand aucune décision n'a été prise.
   Injectée par le controller Stimulus au connect() si localStorage vide. */
.chatbot-message--consent {
    max-width: 95%;
    border: 0.5px solid rgb(var(--tint) / 0.12);
    background:
        radial-gradient(100% 100% at 0% 0%, rgba(0, 113, 227, 0.05), transparent 60%),
        rgb(var(--tint) / 0.06);
}
.chatbot-consent-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}
.chatbot-consent-btn {
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: filter 160ms ease, transform 120ms ease, background 160ms ease;
    font-family: inherit;
    line-height: 1.2;
}
.chatbot-consent-btn--accept {
    background: var(--accent);
    color: #fff;
    border: 0.5px solid var(--accent);
}
.chatbot-consent-btn--accept:hover { filter: brightness(1.1); }
.chatbot-consent-btn--accept:active { transform: scale(0.97); }
.chatbot-consent-btn--refuse {
    background: transparent;
    color: var(--text-dim);
    border: 0.5px solid rgb(var(--tint) / 0.18);
}
.chatbot-consent-btn--refuse:hover {
    background: rgb(var(--tint) / 0.06);
    color: var(--text);
}
.chatbot-consent-btn--refuse:active { transform: scale(0.97); }
.chatbot-consent-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Message de confirmation apres choix consent (accept ou refuse).
   Plus petit + un peu plus dim, l'user a deja fait son choix. */
.chatbot-message--consent-confirm {
    font-size: 12px;
    color: var(--text-dim);
    padding: 8px 12px;
    max-width: 90%;
}
