/* =====================================================================
   Assistant JISR — mise en forme du chatbot.
   Utilise les variables du site (--jisr-*). Propriétés logiques : RTL natif.
   ===================================================================== */
.jc-root {
  --jc-w: 390px;
  position: fixed;
  inset-block-end: max(16px, env(safe-area-inset-bottom, 0px));
  inset-inline-end: 16px;
  z-index: 80;
  font-family: var(--font-body, system-ui, sans-serif);
  font-size: 15px;
  line-height: 1.5;
  color: var(--jisr-text, #1d2520);
}
.jc-root *, .jc-root *::before, .jc-root *::after { box-sizing: border-box; }
.jc-root button { font: inherit; color: inherit; cursor: pointer; }
.jc-root :focus-visible { outline: 3px solid var(--jisr-red, #a5282c); outline-offset: 2px; }
.jc-flip { display: block; }
[dir="rtl"] .jc-flip { transform: scaleX(-1); }

/* ---------- Bouton flottant ---------- */
.jc-launcher {
  display: block;
  width: 68px; height: 68px;
  padding: 0;
  border-radius: 50%;
  border: 3px solid var(--jisr-cream, #f7f2e7);
  background: radial-gradient(circle at 30% 22%, #3f8068, #1c3d33 70%);
  overflow: hidden;
  box-shadow: 0 14px 30px -8px rgba(15, 35, 28, 0.6), 0 0 0 1px rgba(15, 35, 28, 0.25);
  animation: jcPulse 2.6s ease-out 1.2s 3;
  transition: transform 0.25s var(--ease, ease);
}
.jc-launcher:hover { transform: translateY(-3px) scale(1.04); }
.jc-launcher img { width: 100%; height: 100%; object-fit: cover; display: block; }
@keyframes jcPulse {
  0%   { box-shadow: 0 14px 30px -8px rgba(15,35,28,.6), 0 0 0 0 rgba(165,40,44,.5); }
  100% { box-shadow: 0 14px 30px -8px rgba(15,35,28,.6), 0 0 0 20px rgba(165,40,44,0); }
}

/* ---------- Bulle d'invitation ---------- */
.jc-teaser {
  position: absolute;
  inset-block-end: 82px;
  inset-inline-end: 0;
  display: flex; align-items: stretch;
  max-width: min(260px, calc(100vw - 40px));
  background: var(--jisr-paper, #fffdf8);
  border: 1px solid var(--jisr-border, #ded4bc);
  border-radius: 16px;
  border-end-end-radius: 4px;
  box-shadow: 0 14px 34px -12px rgba(15, 35, 28, 0.45);
  animation: jcIn 0.35s var(--ease, ease);
}
.jc-teaser-text { flex: 1; text-align: start; border: 0; background: none; padding: 12px 6px 12px 16px; font-weight: 600; color: var(--jisr-green, #1c3d33); }
[dir="rtl"] .jc-teaser-text { padding: 12px 16px 12px 6px; }
.jc-teaser-x { border: 0; background: none; width: 40px; color: var(--jisr-muted, #56605a); display: flex; align-items: center; justify-content: center; }
.jc-teaser-x svg { width: 16px; height: 16px; }

/* ---------- Fenêtre ---------- */
.jc-window { display: none; position: absolute; inset-block-end: 0; inset-inline-end: 0; width: min(var(--jc-w), calc(100vw - 32px)); height: min(640px, calc(100vh - 110px)); }
.jc-root.is-open .jc-window { display: block; animation: jcIn 0.3s var(--ease, ease); }
.jc-root.is-open .jc-launcher, .jc-root.is-open .jc-teaser { display: none; }
@keyframes jcIn { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; transform: none; } }

.jc-panel {
  position: relative; z-index: 1;
  display: flex; flex-direction: column;
  height: 100%;
  background: var(--jisr-cream, #f7f2e7);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: 0 34px 80px -22px rgba(15, 35, 28, 0.6), 0 0 0 1px rgba(15, 35, 28, 0.14);
}

/* Mascotte : debout à côté de la fenêtre (grands écrans), buste qui dépasse (autres écrans) */
.jc-lion { display: none; pointer-events: none; user-select: none; }
.jc-bust { display: block; position: absolute; z-index: 2; inset-inline-start: 10px; top: -54px; width: 100px; height: auto; pointer-events: none; user-select: none; filter: drop-shadow(0 6px 8px rgba(15,35,28,.25)); }
[dir="rtl"] .jc-bust { transform: scaleX(-1); }

.jc-head { display: flex; align-items: center; gap: 10px; padding: 14px 12px 14px 118px; color: var(--jisr-cream, #f7f2e7); background: linear-gradient(160deg, #1d4536, #0f231c); }
[dir="rtl"] .jc-head { padding: 14px 118px 14px 12px; }
.jc-head-avatar { display: none; width: 44px; height: 44px; border-radius: 50%; background: #2b5a4a; object-fit: cover; border: 2px solid rgba(247, 242, 231, 0.6); }
.jc-head-text { flex: 1; min-width: 0; }
.jc-title { margin: 0; font-family: var(--font-display, Georgia, serif); font-weight: 600; font-size: 1.12rem; line-height: 1.2; }
html[lang="ar"] .jc-title { font-weight: 700; line-height: 1.5; }
.jc-status { margin: 2px 0 0; display: flex; align-items: center; gap: 7px; font-size: 0.78rem; color: rgba(247, 242, 231, 0.8); }
.jc-dot { width: 8px; height: 8px; border-radius: 50%; background: #4ad694; box-shadow: 0 0 0 3px rgba(74, 214, 148, 0.25); flex-shrink: 0; }
.jc-iconbtn { width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(247, 242, 231, 0.1); color: var(--jisr-cream, #f7f2e7); display: flex; align-items: center; justify-content: center; transition: background 0.2s; }
.jc-iconbtn:hover { background: rgba(247, 242, 231, 0.22); }
.jc-root .jc-head :focus-visible { outline-color: var(--jisr-cream, #f7f2e7); }

/* ---------- Conversation ---------- */
.jc-log { flex: 1; overflow-y: auto; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 12px; scroll-behavior: auto; overscroll-behavior: contain; }
.jc-row { display: flex; gap: 8px; align-items: flex-end; animation: jcMsg 0.3s var(--ease, ease); }
.jc-row--bot { align-items: flex-start; }
.jc-row--user { justify-content: flex-end; }
@keyframes jcMsg { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.jc-msg-avatar { width: 32px; height: 32px; border-radius: 50%; background: #2b5a4a; flex-shrink: 0; object-fit: cover; margin-top: 2px; }
.jc-col { display: flex; flex-direction: column; gap: 8px; min-width: 0; max-width: calc(100% - 42px); align-items: flex-start; }
.jc-bubble { padding: 10px 14px; border-radius: 18px; overflow-wrap: anywhere; }
.jc-bubble p { margin: 0 0 6px; }
.jc-bubble p:last-child { margin-bottom: 0; }
.jc-bubble .jc-li { padding-inline-start: 4px; }
.jc-bubble--bot { background: var(--jisr-paper, #fffdf8); border: 1px solid var(--jisr-border, #ded4bc); border-start-start-radius: 4px; box-shadow: 0 1px 2px rgba(15,35,28,.06); }
.jc-bubble--user { background: var(--jisr-green, #1c3d33); color: #fff; border-start-end-radius: 4px; max-width: 86%; }
html[lang="ar"] .jc-root { line-height: 1.8; }

.jc-typing { display: flex; gap: 5px; align-items: center; padding: 14px 16px; }
.jc-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--jisr-muted, #56605a); opacity: .5; animation: jcDot 1s infinite ease-in-out; }
.jc-typing span:nth-child(2) { animation-delay: .15s; }
.jc-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes jcDot { 0%, 80%, 100% { transform: translateY(0); opacity: .35; } 40% { transform: translateY(-5px); opacity: 1; } }

.jc-links { display: flex; flex-wrap: wrap; gap: 8px; }
.jc-link { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 8px 16px; border-radius: 999px; background: var(--jisr-red, #a5282c); color: #fff; font-weight: 700; font-size: 0.92rem; text-decoration: none; transition: background 0.2s, transform 0.2s var(--ease, ease); }
.jc-link:hover { background: #8c2024; transform: translateY(-1px); }

.jc-chips { display: flex; flex-direction: column; align-items: flex-start; gap: 7px; }
.jc-chips-title { margin: 2px 0 0; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--jisr-muted, #56605a); }
html[lang="ar"] .jc-chips-title { letter-spacing: 0; text-transform: none; font-size: 0.86rem; }
.jc-chip { min-height: 40px; padding: 8px 14px; text-align: start; border-radius: 16px; border: 1.5px solid var(--jisr-green, #1c3d33); background: transparent; color: var(--jisr-green, #1c3d33); font-weight: 600; font-size: 0.92rem; line-height: 1.3; transition: background 0.2s, color 0.2s; }
.jc-chip:hover { background: var(--jisr-green, #1c3d33); color: var(--jisr-cream, #f7f2e7); }

/* ---------- Saisie ---------- */
.jc-form { display: flex; gap: 8px; padding: 10px 12px 6px; border-top: 1px solid var(--jisr-border, #ded4bc); background: var(--jisr-paper, #fffdf8); }
.jc-input { flex: 1; min-width: 0; height: 46px; padding: 0 16px; border-radius: 999px; border: 1.5px solid var(--jisr-border, #ded4bc); background: var(--jisr-cream, #f7f2e7); color: inherit; font: inherit; font-size: 16px; outline: none; transition: border-color 0.2s, box-shadow 0.2s, background 0.2s; }
.jc-root .jc-input:focus-visible { outline: none; }
.jc-input:focus { border-color: var(--jisr-green, #1c3d33); background: #fff; box-shadow: 0 0 0 4px rgba(28, 61, 51, 0.16); }
.jc-send { width: 46px; height: 46px; flex-shrink: 0; border: 0; border-radius: 50%; background: var(--jisr-red, #a5282c); color: #fff; display: flex; align-items: center; justify-content: center; transition: background 0.2s, transform 0.2s var(--ease, ease); }
.jc-send:hover { background: #8c2024; transform: scale(1.06); }
.jc-note { margin: 0; padding: 4px 14px 10px; font-size: 0.74rem; line-height: 1.4; color: var(--jisr-muted, #56605a); text-align: center; background: var(--jisr-paper, #fffdf8); }

/* ---------- Grand écran : le lion se tient à côté de la fenêtre ---------- */
@media (min-width: 1180px) {
  .jc-bust { display: none; }
  .jc-head, [dir="rtl"] .jc-head { padding: 14px 12px; }
  .jc-head-avatar { display: block; }
  .jc-lion {
    --flip: 1;
    display: block;
    position: absolute; z-index: 0;
    inset-block-end: 0;
    inset-inline-end: calc(100% - 30px);
    height: min(560px, calc(100vh - 70px)); width: auto;
    filter: drop-shadow(0 20px 22px rgba(15, 35, 28, 0.3));
    animation: jcLion 0.6s 0.12s var(--ease, ease) both;
  }
  [dir="rtl"] .jc-lion { --flip: -1; }
}
@keyframes jcLion { from { opacity: 0; transform: scaleX(var(--flip, 1)) translateY(30px); } to { opacity: 1; transform: scaleX(var(--flip, 1)) translateY(0); } }

/* ---------- Mobile : feuille plein largeur ---------- */
@media (max-width: 560px) {
  .jc-root { inset-inline-end: 12px; }
  .jc-launcher { width: 60px; height: 60px; }
  .jc-window { position: fixed; inset-inline: 0; inset-block-end: 0; width: 100%; height: min(86vh, 720px); }
  .jc-panel { border-radius: 22px 22px 0 0; }
  .jc-note { padding-bottom: max(10px, env(safe-area-inset-bottom, 0px)); }
}

@media (prefers-reduced-motion: reduce) {
  .jc-root *, .jc-root *::before, .jc-root *::after { animation: none !important; transition: none !important; }
}
@media print { .jc-root { display: none !important; } }
