/* Orbi, l'assistant ACTUARUS : mascotte animée (components/orbi.js) et fenêtre de discussion (components/orbi-chat.js). */

/* ---------- Mascotte ---------- */
.orbi { display: block; overflow: visible; }
.orbi .orbi-planet { fill: #cff5b8; stroke: #16306b; stroke-width: 8; }
.orbi .orbi-antenna { fill: none; stroke: #16306b; stroke-width: 8; stroke-linejoin: round; stroke-linecap: round; }
.orbi .orbi-antenna-ball { fill: #16306b; }
.orbi .orbi-highlight { fill: none; stroke: #a6df8a; stroke-width: 7; stroke-linecap: round; }
.orbi .orbi-cheek { fill: #a9d3e0; }
.orbi .orbi-spot { fill: #a6df8a; }
.orbi .orbi-eyes path, .orbi .orbi-mouth { fill: none; stroke: #16306b; stroke-width: 6; stroke-linecap: round; }
.orbi .orbi-mouth { stroke-width: 5; }
.orbi .orbi-ring-line { fill: none; stroke: #93bfe3; stroke-width: 14; }
.orbi .orbi-ring-shine { fill: none; stroke: #ffffff; stroke-opacity: .85; stroke-width: 5; stroke-linecap: round; stroke-dasharray: 7 93; }
.orbi .orbi-stars circle { fill: #8fb8de; }
.orbi .orbi-shadow { fill: #16306b; opacity: .14; }

/* Animations : coordonnées des origines dans le repère du dessin (viewBox). */
.orbi .orbi-body { animation: orbi-float 4.2s ease-in-out infinite; }
.orbi .orbi-shadow { transform-box: view-box; transform-origin: 100px 198px; animation: orbi-shadow 4.2s ease-in-out infinite; }
.orbi .orbi-ring { transform-box: view-box; transform-origin: 100px 112px; animation: orbi-ring 6s ease-in-out infinite; }
.orbi .orbi-ring-shine { animation: orbi-shine 3.2s linear infinite; }
.orbi .orbi-eyes { transform-box: view-box; transform-origin: 100px 102px; animation: orbi-blink 5.5s ease-in-out infinite; }
.orbi .orbi-antenna-ball { transform-box: view-box; transform-origin: 100px 24px; }
.orbi .orbi-stars circle { animation: orbi-twinkle 3s ease-in-out infinite; }
.orbi .orbi-stars circle:nth-child(2) { animation-delay: .8s; }
.orbi .orbi-stars circle:nth-child(3) { animation-delay: 1.6s; }
.orbi .orbi-stars circle:nth-child(4) { animation-delay: 2.2s; }

/* Orbi écrit : antenne qui pulse, anneau et reflet qui accélèrent. */
.is-thinking .orbi .orbi-antenna-ball { fill: #2f62c8; animation: orbi-pulse .8s ease-in-out infinite; }
.is-thinking .orbi .orbi-ring { animation-duration: 1.8s; }
.is-thinking .orbi .orbi-ring-shine { animation-duration: .9s; }

@keyframes orbi-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }
@keyframes orbi-shadow { 0%, 100% { transform: scaleX(1); opacity: .16; } 50% { transform: scaleX(.8); opacity: .08; } }
@keyframes orbi-ring { 0%, 100% { transform: rotate(-16deg); } 50% { transform: rotate(-5deg); } }
@keyframes orbi-shine { to { stroke-dashoffset: -100; } }
@keyframes orbi-blink { 0%, 88%, 100% { transform: scaleY(1); } 91% { transform: scaleY(.12); } 94% { transform: scaleY(1); } }
@keyframes orbi-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.3); } }
@keyframes orbi-twinkle { 0%, 100% { opacity: .9; } 50% { opacity: .3; } }

@media (prefers-reduced-motion: reduce) {
  .orbi *, .orbi-typing span { animation: none !important; }
}

/* ---------- Bulle flottante ---------- */
.orbi-launcher {
  position: fixed; inset-inline-end: var(--space-5); bottom: var(--space-5); z-index: calc(var(--z-toast) - 1);
  width: 72px; height: 72px; padding: 6px; border-radius: 50%; border: 1px solid var(--border-2);
  background: #eef9e8; box-shadow: var(--shadow-3); cursor: pointer; display: grid; place-items: center;
  transition: transform var(--dur-2) var(--ease-out);
}
.orbi-launcher:hover { transform: translateY(-2px) scale(1.04); }
.orbi-launcher:focus-visible { outline: none; box-shadow: var(--shadow-focus), var(--shadow-3); }
.orbi-launcher.is-open { transform: scale(.92); }
/* Notifications au-dessus de la bulle. */
body.has-orbi .toast-region { bottom: calc(var(--space-5) + 84px); }

/* ---------- Fenêtre de discussion ---------- */
.orbi-panel {
  position: fixed; inset-inline-end: var(--space-5); bottom: calc(var(--space-5) + 84px); z-index: calc(var(--z-toast) - 1);
  width: min(390px, calc(100vw - 32px)); height: min(580px, calc(100vh - 140px));
  display: flex; flex-direction: column; background: var(--bg-surface); color: var(--fg-1);
  border: 1px solid var(--border-2); border-radius: var(--radius-lg); box-shadow: var(--shadow-3); overflow: hidden;
  animation: orbi-panel-in var(--dur-2) var(--ease-out);
}
.orbi-panel[hidden] { display: none; }
@keyframes orbi-panel-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.orbi-head { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4); background: #eef9e8; border-bottom: 1px solid var(--border-1); }
.orbi-avatar { flex: none; }
.orbi-title { flex: 1; display: flex; flex-direction: column; line-height: 1.25; color: #16306b; }
.orbi-title strong { font-size: var(--text-lg); }
.orbi-title span { font-size: var(--text-xs); color: #3d5a8f; }

.orbi-log { flex: 1; overflow-y: auto; padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); }
.orbi-msg { max-width: 88%; padding: var(--space-3) var(--space-4); border-radius: 16px; font-size: var(--text-sm); line-height: 1.5; overflow-wrap: anywhere; }
.orbi-msg p { margin: 0; }
.orbi-msg p + p, .orbi-msg p + ul, .orbi-msg ul + p { margin-top: var(--space-2); }
.orbi-msg ul { margin: 0; padding-inline-start: 1.2em; }
.orbi-msg-bot { align-self: flex-start; background: var(--bg-surface-2); border-end-start-radius: 4px; }
.orbi-welcome { background: #16306b; color: #ffffff; }
.orbi-msg-user { align-self: flex-end; background: var(--btn-primary); color: var(--fg-on-brand); border-end-end-radius: 4px; white-space: pre-wrap; }
.orbi-suggestions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.orbi-suggestions .chip { font-size: var(--text-xs); }

.orbi-typing { display: inline-flex; gap: 5px; align-items: center; }
.orbi-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--fg-3); animation: orbi-dot 1.1s infinite ease-in-out; }
.orbi-typing span:nth-child(2) { animation-delay: .15s; }
.orbi-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes orbi-dot { 0%, 80%, 100% { transform: translateY(0); opacity: .4; } 40% { transform: translateY(-4px); opacity: 1; } }

.orbi-form { display: flex; gap: var(--space-2); align-items: flex-end; padding: var(--space-3) var(--space-3) 0; border-top: 1px solid var(--border-1); }
.orbi-form .textarea { flex: 1; min-height: 44px; max-height: 140px; resize: none; }
.orbi-note { margin: 0; padding: var(--space-2) var(--space-4) var(--space-3); font-size: var(--text-xs); color: var(--fg-3); }

/* Thème sombre : l'en-tête et la bulle gardent les couleurs de la mascotte, assombries. */
[data-theme="dark"] .orbi-launcher, [data-theme="dark"] .orbi-head { background: #1d3354; }
[data-theme="dark"] .orbi-title { color: #e6efff; }
[data-theme="dark"] .orbi-title span { color: #a9bfe3; }
[data-theme="dark"] .orbi-welcome { background: #2a4a85; }

/* Mobile : fenêtre en bas de l'écran sur toute la largeur. */
@media (max-width: 640px) {
  .orbi-launcher { inset-inline-end: var(--space-4); bottom: var(--space-4); width: 62px; height: 62px; }
  .orbi-panel { inset-inline-end: 0; inset-inline-start: 0; bottom: 0; width: 100%; height: min(85vh, calc(100vh - 56px)); border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  body.has-orbi .toast-region { bottom: calc(var(--space-4) + 72px); }
}

/* ---------- Bulle de BD : Orbi signale une évolution de deal ou un nouveau message ---------- */
.orbi-speech {
  position: fixed; inset-inline-end: calc(var(--space-5) + 6px); bottom: calc(var(--space-5) + 90px); z-index: calc(var(--z-toast) - 1);
  width: min(320px, calc(100vw - 2 * var(--space-5))); padding: 14px 40px 14px 16px;
  background: #ffffff; color: #16306b; border: 2.5px solid #16306b; border-radius: 22px;
  box-shadow: 5px 5px 0 #16306b; font-size: var(--text-sm); line-height: 1.45;
  transform-origin: calc(100% - 34px) calc(100% + 18px); transform: scale(.4); opacity: 0;
  transition: transform .32s cubic-bezier(.34, 1.56, .64, 1), opacity .2s ease-out;
}
.orbi-speech.is-visible { transform: scale(1); opacity: 1; }
/* Pointe de la bulle, dirigée vers Orbi. */
.orbi-speech::before, .orbi-speech::after { content: ""; position: absolute; inset-inline-end: 26px; width: 0; height: 0; border-style: solid; }
.orbi-speech::before { bottom: -19px; border-width: 18px 0 0 18px; border-color: #16306b transparent transparent transparent; }
.orbi-speech::after { bottom: -13px; inset-inline-end: 29.5px; border-width: 12px 0 0 12px; border-color: #ffffff transparent transparent transparent; }
.orbi-speech-text { margin: 0 0 6px; font-weight: 600; }
.orbi-speech-quote { margin: 0 0 8px; color: #3a4f7a; font-style: italic; overflow-wrap: anywhere; }
.orbi-speech-link { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; color: #2856ad; text-decoration: underline; text-underline-offset: 3px; }
.orbi-speech-link:hover { color: #16306b; }
.orbi-speech-close { position: absolute; top: 8px; inset-inline-end: 8px; width: 28px; height: 28px; display: grid; place-items: center; border: 0; border-radius: 50%; background: transparent; color: #16306b; cursor: pointer; }
.orbi-speech-close:hover { background: #eef3fb; }
.orbi-speech-link:focus-visible, .orbi-speech-close:focus-visible { outline: none; box-shadow: var(--shadow-focus); border-radius: 6px; }
/* Bulle affichée : les notifications passent au-dessus. */
body.orbi-speaking .toast-region { bottom: calc(var(--space-5) + 90px + var(--orbi-speech-h, 140px)); }
/* Orbi parle : il se dandine, l'antenne s'allume. */
.orbi-launcher.is-talking { animation: orbi-talk 1.1s ease-in-out 3; }
.orbi-launcher.is-talking .orbi .orbi-antenna-ball { fill: #2f62c8; animation: orbi-pulse .8s ease-in-out infinite; }
@keyframes orbi-talk { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-8deg) translateY(-3px); } 75% { transform: rotate(8deg) translateY(-3px); } }
[data-theme="dark"] .orbi-speech { background: #12203d; color: #e6efff; border-color: #93bfe3; box-shadow: 5px 5px 0 #93bfe3; }
[data-theme="dark"] .orbi-speech::before { border-top-color: #93bfe3; }
[data-theme="dark"] .orbi-speech::after { border-top-color: #12203d; }
[data-theme="dark"] .orbi-speech-quote { color: #b9c9e6; }
[data-theme="dark"] .orbi-speech-link { color: #9cc2ff; }
[data-theme="dark"] .orbi-speech-close { color: #e6efff; }
[data-theme="dark"] .orbi-speech-close:hover { background: #1f3260; }
@media (max-width: 640px) {
  .orbi-speech { inset-inline-end: var(--space-4); bottom: calc(var(--space-4) + 80px); width: calc(100vw - 2 * var(--space-4)); }
  body.orbi-speaking .toast-region { bottom: calc(var(--space-4) + 80px + var(--orbi-speech-h, 140px)); }
}
@media (prefers-reduced-motion: reduce) {
  .orbi-speech { transition: none; transform: none; }
  .orbi-launcher.is-talking { animation: none; }
}

/* Écriture de droite à gauche : Orbi à gauche, pointe de la bulle retournée. */
[dir="rtl"] .orbi-speech::before { border-width: 18px 18px 0 0; }
[dir="rtl"] .orbi-speech::after { border-width: 12px 12px 0 0; }

/* Fenêtre ouverte : Orbi (bouton et bulle) masqué, il recouvrait les boutons de la fenêtre sur téléphone. */
body:has(.modal-backdrop) .orbi-launcher, body:has(.modal-backdrop) .orbi-speech { display: none; }
