/* =========================================================
   CHATBOT « ZAKARIA » — assistant FAQ du site
   ========================================================= */

#chatbot-widget {
    --cb-navy: #0F2C5C;
    --cb-navy-2: #1E3A8A;
    --cb-blue: #3B76C0;
    --cb-red: #E11D2D;
    --cb-ink: #0F172A;
    --cb-text: #334155;
    --cb-muted: #64748B;
    --cb-line: #E2E8F0;
    --cb-soft: #F1F5F9;
    --cb-surface: #FFFFFF;
    --cb-green: #22C55E;

    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-variant-numeric: lining-nums;
}

/* ---------- Bouton flottant ---------- */
#chatbot-toggle {
    position: relative;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: none;
    padding: 0;
    cursor: pointer;
    background: radial-gradient(circle at 30% 25%, #2B5BA8 0%, var(--cb-navy) 70%);
    box-shadow: 0 10px 30px rgba(15, 44, 92, 0.35), inset 0 0 0 3px rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#chatbot-toggle:hover {
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 14px 34px rgba(15, 44, 92, 0.45), inset 0 0 0 3px #fff;
}

#chatbot-toggle:focus-visible {
    outline: 3px solid rgba(59, 118, 192, 0.6);
    outline-offset: 3px;
}

.chatbot-toggle-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    object-fit: cover;
    object-position: 50% 20%;
    background: radial-gradient(circle at 50% 30%, #FFFFFF 0%, #DCE7F7 75%);
    transition: transform 0.25s ease, opacity 0.2s ease;
}

.chatbot-toggle-close {
    position: absolute;
    color: #fff;
    opacity: 0;
    transform: rotate(-90deg) scale(0.6);
    transition: transform 0.25s ease, opacity 0.2s ease;
}

#chatbot-widget.is-open .chatbot-toggle-avatar {
    opacity: 0;
    transform: scale(0.6);
}

#chatbot-widget.is-open .chatbot-toggle-close {
    opacity: 1;
    transform: none;
}

.chatbot-online-dot {
    position: absolute;
    right: 3px;
    bottom: 3px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--cb-green);
    border: 2.5px solid #fff;
}

#chatbot-widget.is-open .chatbot-online-dot {
    display: none;
}

/* ---------- Bulle d'accroche ---------- */
.chatbot-teaser {
    position: absolute;
    right: 76px;
    bottom: 10px;
    width: max-content;
    max-width: 240px;
    background: var(--cb-surface);
    color: var(--cb-ink);
    border-radius: 16px 16px 4px 16px;
    padding: 12px 34px 12px 14px;
    font-size: 13.5px;
    line-height: 1.45;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.16);
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    cursor: pointer;
}

.chatbot-teaser strong {
    color: var(--cb-navy);
}

.chatbot-teaser.show {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}

.chatbot-teaser-close {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--cb-muted);
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
}

.chatbot-teaser-close:hover {
    background: var(--cb-soft);
}

/* ---------- Fenêtre ---------- */
#chatbot-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 390px;
    height: min(620px, calc(100vh - 120px));
    background: var(--cb-surface);
    border-radius: 22px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.22);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(14px) scale(0.98);
    transform-origin: bottom right;
    pointer-events: none;
    visibility: hidden;
    transition: opacity 0.22s ease, transform 0.22s ease, visibility 0s linear 0.22s;
}

#chatbot-widget.is-open #chatbot-window {
    opacity: 1;
    transform: none;
    pointer-events: auto;
    visibility: visible;
    transition: opacity 0.22s ease, transform 0.22s ease, visibility 0s;
}

/* En-tête */
.chatbot-header {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 16px 16px 18px;
    background: linear-gradient(135deg, var(--cb-navy) 0%, var(--cb-navy-2) 100%);
    color: #fff;
}

.chatbot-header::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--cb-blue) 0 33%, #fff 33% 66%, var(--cb-red) 66%);
}

.chatbot-header-avatar {
    position: relative;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    padding: 2px;
    background: #fff;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.chatbot-header-avatar img {
    display: block;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    object-position: 50% 20%;
    background: radial-gradient(circle at 50% 30%, #FFFFFF 0%, #DCE7F7 75%);
}

.chatbot-header-avatar .chatbot-online-dot {
    right: -1px;
    bottom: -1px;
    width: 13px;
    height: 13px;
    border-color: var(--cb-navy);
    display: block;
}

.chatbot-header-text {
    flex: 1;
    min-width: 0;
}

.chatbot-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 19px;
    font-weight: 700;
    letter-spacing: 0.01em;
    line-height: 1.1;
}

.chatbot-subtitle {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 12px;
    opacity: 0.85;
    margin-top: 4px;
}

.chatbot-subtitle::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--cb-green);
}

.chatbot-header-btn {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    flex-shrink: 0;
}

.chatbot-header-btn:hover {
    background: rgba(255, 255, 255, 0.22);
}

.chatbot-header-btn svg {
    width: 17px;
    height: 17px;
}

/* Corps */
.chatbot-body {
    position: relative; /* repère de offsetTop pour le défilement */
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px 10px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: linear-gradient(180deg, #F8FAFC 0%, #FFFFFF 160px);
    scroll-behavior: smooth;
}

.chatbot-body::-webkit-scrollbar {
    width: 6px;
}

.chatbot-body::-webkit-scrollbar-thumb {
    background: #CBD5E1;
    border-radius: 6px;
}

/* Messages */
.chatbot-msg {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    animation: chatbot-pop 0.25s ease-out;
}

@keyframes chatbot-pop {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}

.chatbot-msg.user {
    justify-content: flex-end;
}

.chatbot-msg-avatar {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    border-radius: 50%;
    overflow: hidden;
    box-shadow: 0 0 0 1.5px #fff, 0 2px 6px rgba(15, 23, 42, 0.15);
}

.chatbot-msg-avatar img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: 50% 20%;
    background: radial-gradient(circle at 50% 30%, #FFFFFF 0%, #DCE7F7 75%);
}

.chatbot-bubble {
    max-width: 82%;
    padding: 11px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
}

.chatbot-msg.bot .chatbot-bubble {
    background: var(--cb-surface);
    color: var(--cb-text);
    border: 1px solid var(--cb-line);
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.04);
}

.chatbot-msg.bot .chatbot-bubble strong {
    color: var(--cb-ink);
}

.chatbot-msg.user .chatbot-bubble {
    background: var(--cb-navy);
    color: #fff;
    border-bottom-right-radius: 6px;
}

.chatbot-answer-title {
    display: block;
    font-weight: 700;
    color: var(--cb-ink);
    margin-bottom: 4px;
}

.chatbot-bubble p + p {
    margin-top: 8px;
}

/* Indicateur de frappe */
.chatbot-typing .chatbot-bubble {
    display: inline-flex;
    gap: 4px;
    padding: 14px 16px;
}

.chatbot-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94A3B8;
    animation: chatbot-dot 1.1s 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% { transform: translateY(0); opacity: 0.5; }
    30%           { transform: translateY(-4px); opacity: 1; }
}

/* CTA */
.chatbot-cta {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    padding: 9px 14px;
    background: var(--cb-navy);
    color: #fff !important;
    border-radius: 10px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 700;
    transition: background 0.15s, transform 0.15s;
}

.chatbot-cta:hover {
    background: var(--cb-navy-2);
    transform: translateY(-1px);
}

/* Sujets (tuiles) */
.chatbot-section-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--cb-muted);
    margin: 4px 2px -4px 36px;
}

.chatbot-topics {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding-left: 36px;
    animation: chatbot-pop 0.25s ease-out;
}

.chatbot-topic {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    column-gap: 10px;
    row-gap: 1px;
    align-items: center;
    padding: 9px 10px;
    background: var(--cb-surface);
    border: 1.5px solid var(--cb-line);
    border-radius: 14px;
    cursor: pointer;
    text-align: left;
    font: inherit;
    color: var(--cb-ink);
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.chatbot-topic:hover,
.chatbot-topic:focus-visible {
    border-color: var(--cb-blue);
    box-shadow: 0 6px 16px rgba(59, 118, 192, 0.15);
    transform: translateY(-1px);
    outline: none;
}

.chatbot-topic-icon {
    grid-row: 1 / span 2;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: linear-gradient(135deg, #EEF4FF, #DCE7F7);
    color: var(--cb-navy);
    display: flex;
    align-items: center;
    justify-content: center;
}

.chatbot-topic-icon svg {
    width: 18px;
    height: 18px;
}

.chatbot-topic-label {
    font-size: 13px;
    font-weight: 700;
    line-height: 1.2;
}

.chatbot-topic-count {
    font-size: 11px;
    color: var(--cb-muted);
}

.chatbot-topic:last-child:nth-child(odd) {
    grid-column: 1 / -1;
}

/* Questions (liste) */
.chatbot-questions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-left: 36px;
    animation: chatbot-pop 0.25s ease-out;
}

.chatbot-question {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    background: var(--cb-surface);
    border: 1.5px solid var(--cb-line);
    border-radius: 12px;
    font: inherit;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--cb-ink);
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.chatbot-question::after {
    content: "›";
    font-size: 20px;
    line-height: 1;
    color: var(--cb-blue);
    flex-shrink: 0;
}

.chatbot-question:hover,
.chatbot-question:focus-visible {
    border-color: var(--cb-blue);
    background: #F5F9FF;
    outline: none;
}

.chatbot-question.is-related {
    font-weight: 500;
    background: var(--cb-soft);
    border-color: transparent;
}

.chatbot-link-btn {
    align-self: flex-start;
    margin-left: 36px;
    background: none;
    border: none;
    color: var(--cb-blue);
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    padding: 4px 2px;
}

.chatbot-link-btn:hover {
    text-decoration: underline;
}

/* Barre de recherche */
.chatbot-footer {
    position: relative;
    padding: 10px 12px 12px;
    border-top: 1px solid var(--cb-line);
    background: var(--cb-surface);
}

.chatbot-search {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--cb-soft);
    border: 1.5px solid transparent;
    border-radius: 14px;
    padding: 4px 4px 4px 12px;
    transition: border-color 0.15s, background 0.15s;
}

.chatbot-search:focus-within {
    border-color: var(--cb-blue);
    background: #fff;
}

.chatbot-search svg {
    width: 17px;
    height: 17px;
    color: var(--cb-muted);
    flex-shrink: 0;
}

.chatbot-search input {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    outline: none;
    font: inherit;
    font-size: 14px;
    color: var(--cb-ink);
    padding: 8px 0;
}

.chatbot-send {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: none;
    background: var(--cb-navy);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, opacity 0.15s;
}

.chatbot-send:disabled {
    opacity: 0.35;
    cursor: default;
}

.chatbot-send svg {
    color: #fff;
}

.chatbot-suggestions {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: calc(100% - 4px);
    background: var(--cb-surface);
    border: 1px solid var(--cb-line);
    border-radius: 14px;
    box-shadow: 0 -10px 30px rgba(15, 23, 42, 0.12);
    padding: 6px;
    display: none;
    max-height: 240px;
    overflow-y: auto;
}

.chatbot-suggestions.show {
    display: block;
}

.chatbot-suggestion {
    display: block;
    width: 100%;
    padding: 9px 10px;
    border: none;
    border-radius: 10px;
    background: none;
    text-align: left;
    font: inherit;
    font-size: 13.5px;
    color: var(--cb-ink);
    cursor: pointer;
}

.chatbot-suggestion small {
    display: block;
    font-size: 11.5px;
    color: var(--cb-muted);
    margin-top: 2px;
}

.chatbot-suggestion:hover,
.chatbot-suggestion.active {
    background: #F5F9FF;
}

.chatbot-suggestion mark {
    background: #FEF3C7;
    color: inherit;
    border-radius: 3px;
    padding: 0 1px;
}

.chatbot-credit {
    margin-top: 8px;
    text-align: center;
    font-size: 11px;
    color: #94A3B8;
}

/* ---------- RTL (interface arabe) ---------- */
[dir="rtl"] #chatbot-widget {
    right: auto;
    left: 24px;
}

[dir="rtl"] #chatbot-window {
    right: auto;
    left: 0;
    transform-origin: bottom left;
}

[dir="rtl"] .chatbot-teaser {
    right: auto;
    left: 76px;
    border-radius: 16px 16px 16px 4px;
}

[dir="rtl"] .chatbot-topics,
[dir="rtl"] .chatbot-questions {
    padding-left: 0;
    padding-right: 36px;
}

[dir="rtl"] .chatbot-section-label { margin: 4px 36px -4px 2px; }
[dir="rtl"] .chatbot-link-btn { margin-left: 0; margin-right: 36px; align-self: flex-end; }
[dir="rtl"] .chatbot-topic,
[dir="rtl"] .chatbot-question,
[dir="rtl"] .chatbot-suggestion { text-align: right; }
[dir="rtl"] .chatbot-question::after { content: "‹"; }

/* ---------- Mobile ---------- */
@media (max-width: 520px) {
    #chatbot-widget {
        right: 14px;
        bottom: 14px;
    }

    [dir="rtl"] #chatbot-widget {
        left: 14px;
    }

    #chatbot-toggle {
        width: 58px;
        height: 58px;
    }

    .chatbot-toggle-avatar {
        width: 50px;
        height: 50px;
    }

    #chatbot-window {
        position: fixed;
        left: 8px;
        right: 8px;
        bottom: 84px;
        width: auto;
        height: min(640px, calc(100dvh - 100px));
        border-radius: 20px;
    }

    [dir="rtl"] #chatbot-window {
        left: 8px;
        right: 8px;
    }

    .chatbot-teaser {
        max-width: calc(100vw - 110px);
    }
}

@media (prefers-reduced-motion: reduce) {
    #chatbot-widget *,
    #chatbot-widget *::before,
    #chatbot-widget *::after {
        animation: none !important;
        transition: none !important;
    }
}
