/* Orynela — Assistant chatbot (widget flottant).
   Utilise les variables de thème du site (fallbacks fournis pour robustesse).
   Chargé uniquement par le partial _chatbot.php (absent des pages légales / si désactivé). */

#cb-root {
    --cb-accent: var(--accent-gold, var(--accent, #c79a3a));
    --cb-bg: var(--bg-card, #15171c);
    --cb-bg-2: var(--bg-secondary, #1c1f26);
    --cb-input: var(--bg-input, #11131a);
    --cb-text: var(--text-primary, #eceef2);
    --cb-muted: var(--text-muted, #97a0ad);
    --cb-border: var(--border-subtle, rgba(255, 255, 255, .08));
    --cb-radius: var(--radius-lg, 16px);
    --cb-shadow: var(--shadow-lg, 0 18px 48px rgba(0, 0, 0, .45));
    position: fixed;
    z-index: 2147483000; /* au-dessus du contenu, sous d'éventuels overlays critiques */
    inset: auto 0 0 auto;
    font-family: inherit;
}

/* ── Bouton flottant ── */
.cb-launcher {
    position: fixed;
    right: 22px;
    bottom: 22px;
    width: 58px;
    height: 58px;
    border-radius: var(--radius-full, 999px);
    border: 1px solid var(--cb-border);
    background: linear-gradient(135deg, var(--cb-accent), var(--accent-gold-muted, #9a7320));
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--cb-shadow);
    transition: transform .18s ease, box-shadow .18s ease, opacity .18s ease;
}
.cb-launcher:hover { transform: translateY(-2px) scale(1.04); }
.cb-launcher:focus-visible { outline: 2px solid var(--cb-accent); outline-offset: 3px; }
.cb-launcher svg { width: 28px; height: 28px; }
.cb-launcher .cb-dot {
    position: absolute; top: 12px; right: 13px; width: 9px; height: 9px;
    background: #34d399; border-radius: 50%; border: 2px solid var(--cb-bg);
}
#cb-root.cb-open .cb-launcher { opacity: 0; pointer-events: none; transform: scale(.6); }

/* ── Panneau ── */
.cb-panel {
    position: fixed;
    right: 22px;
    bottom: 22px;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 96px);
    display: flex;
    flex-direction: column;
    background: var(--cb-bg);
    border: 1px solid var(--cb-border);
    border-radius: var(--cb-radius);
    box-shadow: var(--cb-shadow);
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(.98);
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
    backdrop-filter: blur(var(--glass-blur, 14px));
}
#cb-root.cb-open .cb-panel { opacity: 1; transform: none; pointer-events: auto; }

.cb-header {
    display: flex; align-items: center; gap: 10px;
    padding: 13px 14px;
    background: var(--cb-bg-2);
    border-bottom: 1px solid var(--cb-border);
}
.cb-header .cb-avatar {
    width: 30px; height: 30px; border-radius: 50%;
    background: linear-gradient(135deg, var(--cb-accent), var(--accent-gold-muted, #9a7320));
    display: flex; align-items: center; justify-content: center; color: #fff; flex: 0 0 auto;
}
.cb-header .cb-avatar svg { width: 18px; height: 18px; }
.cb-titles { line-height: 1.2; min-width: 0; }
.cb-titles strong { color: var(--cb-text); font-size: 14px; display: block; }
.cb-titles span { color: var(--cb-muted); font-size: 11.5px; }
.cb-header .cb-actions { margin-inline-start: auto; display: flex; gap: 4px; }
.cb-iconbtn {
    background: transparent; border: 0; color: var(--cb-muted); cursor: pointer;
    width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
}
.cb-iconbtn:hover { background: rgba(255, 255, 255, .07); color: var(--cb-text); }
.cb-iconbtn svg { width: 18px; height: 18px; }

.cb-messages {
    flex: 1 1 auto; overflow-y: auto; padding: 14px;
    display: flex; flex-direction: column; gap: 10px;
    scrollbar-width: thin;
}
.cb-msg { max-width: 86%; padding: 9px 12px; border-radius: 13px; font-size: 13.5px; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word; }
.cb-msg.cb-bot { align-self: flex-start; background: var(--cb-bg-2); color: var(--cb-text); border: 1px solid var(--cb-border); border-bottom-left-radius: 4px; }
.cb-msg.cb-user { align-self: flex-end; background: var(--cb-accent); color: #1a1306; border-bottom-right-radius: 4px; }
.cb-msg a { color: var(--cb-accent); text-decoration: underline; }
.cb-msg.cb-user a { color: #1a1306; }

.cb-typing { align-self: flex-start; display: flex; gap: 4px; padding: 11px 13px; background: var(--cb-bg-2); border: 1px solid var(--cb-border); border-radius: 13px; }
.cb-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--cb-muted); opacity: .5; animation: cb-blink 1.2s infinite both; }
.cb-typing i:nth-child(2) { animation-delay: .2s; }
.cb-typing i:nth-child(3) { animation-delay: .4s; }
@keyframes cb-blink { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.cb-error { padding: 8px 14px; font-size: 12.5px; color: #fca5a5; background: rgba(239, 68, 68, .08); border-top: 1px solid var(--cb-border); display: none; }
.cb-error.cb-show { display: block; }

.cb-inputbar { display: flex; gap: 8px; align-items: flex-end; padding: 10px; border-top: 1px solid var(--cb-border); background: var(--cb-bg); }
.cb-inputbar textarea {
    flex: 1 1 auto; resize: none; max-height: 110px; min-height: 40px;
    background: var(--cb-input); color: var(--cb-text);
    border: 1px solid var(--border-input, var(--cb-border)); border-radius: 11px;
    padding: 10px 12px; font: inherit; font-size: 13.5px; line-height: 1.4;
}
.cb-inputbar textarea:focus { outline: none; border-color: var(--cb-accent); }
.cb-send {
    flex: 0 0 auto; width: 40px; height: 40px; border-radius: 11px; border: 0; cursor: pointer;
    background: var(--cb-accent); color: #1a1306; display: flex; align-items: center; justify-content: center;
    transition: opacity .15s ease;
}
.cb-send:disabled { opacity: .45; cursor: default; }
.cb-send svg { width: 19px; height: 19px; }
.cb-foot { text-align: center; font-size: 10.5px; color: var(--cb-muted); padding: 0 10px 8px; background: var(--cb-bg); }

/* ── Mobile ── */
@media (max-width: 560px) {
    .cb-panel { right: 0; bottom: 0; width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
    .cb-launcher { right: 16px; bottom: 16px; }
}

@media (prefers-reduced-motion: reduce) {
    .cb-launcher, .cb-panel { transition: none; }
    .cb-typing i { animation: none; }
}
