/* Widget "Assistant IA" (RAG) — styles autonomes (aucune dépendance au thème) */
.assistant-widget {
    --assistant-color: #1f2937;
    --assistant-accent: #2563eb;
    --assistant-bg: #ffffff;
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 9990;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    color: var(--assistant-color);
}
.assistant-widget__toggle {
    position: relative;
    width: 60px;
    height: 60px;
    border: 0;
    border-radius: 50%;
    background: var(--assistant-accent);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .15s ease;
}
.assistant-widget__toggle:hover { transform: scale(1.05); }
.assistant-widget__close { display: none; font-size: 30px; line-height: 1; }
.assistant-widget[data-open="true"] .assistant-widget__toggle svg { display: none; }
.assistant-widget[data-open="true"] .assistant-widget__close { display: block; }

.assistant-widget__panel {
    position: absolute;
    right: 0;
    bottom: 72px;
    width: min(380px, calc(100vw - 40px));
    height: min(560px, calc(100vh - 120px));
    background: var(--assistant-bg);
    border-radius: 16px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, .25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: assistant-fade .2s ease-out;
}
.assistant-widget__panel[hidden] { display: none; }
@keyframes assistant-fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Préfixe .assistant-widget + propriétés de position explicites : l'en-tête reste dans le
   flux du panneau même si le thème du site stylise les en-têtes (sticky, fond, bordure). */
.assistant-widget .assistant-widget__header {
    position: static;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: auto;
    margin: 0;
    padding: 14px 16px;
    border: 0;
    box-shadow: none;
    transform: none;
    background: var(--assistant-accent);
    color: #fff;
}
.assistant-widget .assistant-widget__header strong { color: inherit; font-size: 16px; font-weight: 600; }
.assistant-widget__reset {
    border: 0;
    background: transparent;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    opacity: .85;
}
.assistant-widget__reset:hover { opacity: 1; }

.assistant-widget__messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f5f7fb;
}
.assistant-msg { display: flex; flex-direction: column; max-width: 88%; }
.assistant-msg--user { align-self: flex-end; align-items: flex-end; }
.assistant-msg--assistant { align-self: flex-start; }
.assistant-msg__bubble {
    padding: 10px 14px;
    border-radius: 14px;
    word-break: break-word;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
}
.assistant-msg__bubble--plain { white-space: pre-wrap; }
.assistant-msg--user .assistant-msg__bubble { background: var(--assistant-accent); color: #fff; border-bottom-right-radius: 4px; }
.assistant-msg--assistant .assistant-msg__bubble { border-bottom-left-radius: 4px; }
.assistant-msg--pending .assistant-msg__bubble { padding: 12px 16px; }

/* Indicateur de génération ● ● ● */
.assistant-typing { display: inline-flex; gap: 5px; align-items: center; height: 14px; }
.assistant-typing i {
    display: block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #9ca3af;
    animation: assistant-blink 1s ease-in-out infinite;
}
.assistant-typing i:nth-child(2) { animation-delay: .15s; }
.assistant-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes assistant-blink {
    0%, 80%, 100% { opacity: .25; transform: scale(.85); }
    40% { opacity: 1; transform: scale(1); }
}

/* Contenu Markdown rendu dans la bulle assistant */
.assistant-msg--assistant .assistant-msg__bubble p,
.assistant-msg--assistant .assistant-msg__bubble ul,
.assistant-msg--assistant .assistant-msg__bubble ol,
.assistant-msg--assistant .assistant-msg__bubble blockquote,
.assistant-msg--assistant .assistant-msg__bubble pre { margin: 0 0 8px; }
.assistant-msg--assistant .assistant-msg__bubble > :last-child { margin-bottom: 0; }
.assistant-msg--assistant .assistant-msg__bubble ul,
.assistant-msg--assistant .assistant-msg__bubble ol { padding-left: 20px; }
.assistant-msg--assistant .assistant-msg__bubble li { margin: 2px 0; }
.assistant-msg--assistant .assistant-msg__bubble li > ul,
.assistant-msg--assistant .assistant-msg__bubble li > ol { margin: 2px 0 0; }
.assistant-msg--assistant .assistant-msg__bubble blockquote {
    border-left: 3px solid var(--assistant-accent);
    padding: 2px 0 2px 10px;
    color: #4b5563;
}
.assistant-msg--assistant .assistant-msg__bubble code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .92em;
    background: #eef1f6;
    border-radius: 4px;
    padding: 1px 4px;
}
.assistant-msg--assistant .assistant-msg__bubble pre {
    background: #1f2937;
    color: #f9fafb;
    border-radius: 8px;
    padding: 10px 12px;
    overflow-x: auto;
    white-space: pre;
}
.assistant-msg--assistant .assistant-msg__bubble pre code { background: transparent; padding: 0; font-size: 13px; }
.assistant-msg--assistant .assistant-msg__bubble a { color: var(--assistant-accent); text-decoration: underline; }
.assistant-msg--assistant .assistant-msg__bubble a:hover { text-decoration: none; }
.assistant-msg--assistant .assistant-msg__bubble strong.assistant-md__h { display: block; font-size: 1.05em; }
.assistant-msg--assistant .assistant-msg__bubble hr { border: 0; border-top: 1px solid #e5e7eb; margin: 8px 0; }

/* Apparition progressive des blocs de la réponse */
.assistant-md-block.is-entering { display: none; }
.assistant-md-block.is-revealed { animation: assistant-block-in .3s ease-out; }
@keyframes assistant-block-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}
.assistant-msg__sources { margin-top: 6px; font-size: 13px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.assistant-msg__sources-label { color: #6b7280; }
.assistant-msg__sources a {
    color: var(--assistant-accent);
    background: #e8efff;
    border-radius: 999px;
    padding: 2px 10px;
    text-decoration: none;
}
.assistant-msg__sources a:hover { text-decoration: underline; }

.assistant-widget__form {
    display: flex;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
}
.assistant-widget__form textarea {
    flex: 1;
    resize: none;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    padding: 9px 12px;
    font: inherit;
    max-height: 120px;
}
.assistant-widget__form textarea:focus { outline: 2px solid var(--assistant-accent); border-color: transparent; }
.assistant-widget__form button {
    border: 0;
    border-radius: 10px;
    background: var(--assistant-accent);
    color: #fff;
    width: 44px;
    cursor: pointer;
    font-size: 18px;
}
.assistant-widget__form button:disabled { opacity: .5; cursor: default; }

@media (max-width: 480px) {
    .assistant-widget { right: 12px; bottom: 12px; }
    .assistant-widget__panel { bottom: 70px; height: min(70vh, calc(100vh - 100px)); }
}

@media (prefers-reduced-motion: reduce) {
    .assistant-widget__panel { animation: none; }
    .assistant-md-block.is-revealed { animation: none; }
    .assistant-typing i { animation: none; opacity: .6; }
}
