/* =============================================================================
   Portail DGSF — assistant
   Bouton flottant, panneau, bulles de réponse, citations et sources.
   Ordre de chargement (setup.typoscript › includeCSS) : tokens, base, layout,
   subpages, chatbot, components, data, modules, puis drs-portal et workflow.
   ============================================================================= */

/* ============================================
   CHATBOT IA — Floating widget
   ============================================ */
.chatbot {
  position: fixed; right: 24px; bottom: 24px;
  z-index: var(--z-chatbot);
  font-family: var(--font-sans);
}

/* Launcher button */
.chatbot-launcher {
  position: relative;
  width: 64px; height: 64px; border-radius: 50%;
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-light) 100%);
  border: none; cursor: pointer;
  color: var(--navy-deep);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 12px 32px rgba(11,29,58,0.25), 0 4px 12px rgba(214,167,75,0.4);
  transition: transform var(--dur-slow) cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow var(--dur-slow) ease;
}
.chatbot-launcher:hover {
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 16px 40px rgba(11,29,58,0.3), 0 6px 16px rgba(214,167,75,0.5);
}
.chatbot-launcher:active { transform: translateY(-1px) scale(0.98); }
.chatbot-launcher-pulse {
  position: absolute; inset: 0; border-radius: 50%;
  background: var(--gold);
  opacity: 0.5;
  animation: chatbot-pulse-ring 2.4s ease-out 3 forwards; /* attire l'œil à l'arrivée puis se tait */
  z-index: -1;
}
@keyframes chatbot-pulse-ring {
  0% { transform: scale(1); opacity: 0.5; }
  80%, 100% { transform: scale(1.6); opacity: 0; }
}
.chatbot-launcher-icon {
  transition: transform var(--dur-slow) ease, opacity var(--dur-base) ease;
}
.chatbot-launcher-icon-close { position: absolute; opacity: 0; transform: rotate(-90deg); }
.chatbot[data-open="true"] .chatbot-launcher-icon-open { opacity: 0; transform: rotate(90deg); }
.chatbot[data-open="true"] .chatbot-launcher-icon-close { opacity: 1; transform: rotate(0deg); }
.chatbot[data-open="true"] .chatbot-launcher-pulse { display: none; }

.chatbot-launcher-badge {
  position: absolute; top: -4px; right: -4px;
  min-width: 22px; height: 22px; padding: 0 6px;
  background: var(--emerald);
  color: white;
  border: 2px solid white;
  border-radius: var(--radius-pill);
  font-size: var(--fs-small); font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(27,107,74,0.3);
}
.chatbot[data-open="true"] .chatbot-launcher-badge { display: none; }

/* Panel */
.chatbot-panel {
  position: absolute; bottom: 80px; right: 0;
  width: 420px; height: 600px; max-height: calc(100vh - 120px);
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 60px rgba(11,29,58,0.22), 0 8px 20px rgba(11,29,58,0.12);
  display: flex; flex-direction: column;
  overflow: hidden;
  opacity: 0; visibility: hidden;
  transform: translateY(16px) scale(0.96);
  transform-origin: bottom right;
  transition: opacity var(--dur-base) ease, transform var(--dur-slow) cubic-bezier(0.34, 1.56, 0.64, 1), visibility var(--dur-base);
}
.chatbot[data-open="true"] .chatbot-panel {
  opacity: 1; visibility: visible;
  transform: translateY(0) scale(1);
}

/* Header */
.chatbot-header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
  color: white;
  position: relative;
}
.chatbot-header::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0;
  height: 2px; background: linear-gradient(90deg, transparent, var(--gold), transparent);
  opacity: 0.6;
}
.chatbot-header-avatar {
  position: relative;
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255,255,255,0.12);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: var(--gold-light);
}
.chatbot-status-dot {
  position: absolute; bottom: 0; right: 0;
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--emerald-light);
  border: 2px solid var(--navy);
  box-shadow: 0 0 0 0 rgba(35,139,94,0.5);
  animation: chatbot-dot-pulse 2s ease infinite;
}
@keyframes chatbot-dot-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(35,139,94,0.5); }
  50% { box-shadow: 0 0 0 5px rgba(35,139,94,0); }
}
.chatbot-header-text { flex: 1; min-width: 0; }
.chatbot-header-title {
  font-size: var(--fs-body); font-weight: 700;
  letter-spacing: 0.01em;
  margin-bottom: 2px;
}
.chatbot-header-subtitle {
  font-size: var(--fs-small);
  color: rgba(255,255,255,0.7);
  display: flex; align-items: center; gap: 6px;
}
.chatbot-status-pulse {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--emerald-light);
  display: inline-block;
}
.chatbot-header-close {
  background: rgba(255,255,255,0.1); border: none;
  color: white; cursor: pointer;
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background var(--dur-base) ease;
}
.chatbot-header-close:hover { background: rgba(255,255,255,0.2); }

/* Body */
.chatbot-body {
  flex: 1; overflow-y: auto;
  padding: 20px 18px;
  background: linear-gradient(180deg, var(--surface-alt) 0%, var(--surface) 60%);
  display: flex; flex-direction: column; gap: 14px;
}
.chatbot-body::-webkit-scrollbar { width: 6px; }
.chatbot-body::-webkit-scrollbar-track { background: transparent; }
.chatbot-body::-webkit-scrollbar-thumb { background: rgba(11,29,58,0.12); border-radius: var(--radius-sm); }
.chatbot-body::-webkit-scrollbar-thumb:hover { background: rgba(11,29,58,0.2); }

.chatbot-msg {
  display: flex; align-items: flex-end; gap: 8px;
  max-width: 90%;
  animation: chatbot-msg-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes chatbot-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
/* L'attribut [hidden] doit gagner sur display:flex (bulles + indicateur de saisie) */
.chatbot-msg[hidden],
.chatbot-typing[hidden] { display: none !important; }
.chatbot-msg-bot { align-self: flex-start; }
.chatbot-msg-user { align-self: flex-end; flex-direction: row-reverse; }
.chatbot-msg-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
  color: var(--gold-light);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.chatbot-msg-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: var(--fs-body); line-height: 1.5;
}
.chatbot-msg-bot .chatbot-msg-bubble {
  background: white;
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(11,29,58,0.06), 0 0 0 1px rgba(11,29,58,0.04);
}
.chatbot-msg-bot .chatbot-msg-bubble p + p { margin-top: 6px; }
.chatbot-msg-user .chatbot-msg-bubble {
  background: var(--navy);
  color: white;
  border-bottom-right-radius: 4px;
}
.chatbot-msg-bot .chatbot-msg-bubble mark {
  background: rgba(214,167,75,0.25);
  color: var(--navy-deep);
  padding: 0 2px;
  border-radius: var(--radius-sm);
  font-weight: 600;
}

/* Search results inside a bot message */
.chatbot-msg-results { max-width: 100%; }
.chatbot-msg-results .chatbot-msg-bubble {
  width: 100%;
  background: white;
  padding: 10px 12px;
}
.chatbot-results {
  display: flex; flex-direction: column; gap: 8px;
  margin-top: 8px;
}
.chatbot-result {
  display: block;
  padding: 10px 12px;
  background: var(--warm-white);
  border: 1px solid rgba(11,29,58,0.08);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--text-primary);
  transition: var(--dur-base) ease; transition-property: var(--transition-ui);
}
.chatbot-result:hover {
  border-color: var(--navy);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.chatbot-result-type {
  display: inline-block;
  background: var(--navy);
  color: white;
  font-size: var(--fs-caption); font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase;
  padding: 2px 8px;
  border-radius: var(--radius-md);
  margin-bottom: 4px;
}
.chatbot-result-title {
  display: block;
  font-size: var(--fs-small);
  color: var(--navy);
  margin-bottom: 4px;
  line-height: 1.3;
}
.chatbot-result-excerpt {
  display: block;
  font-size: var(--fs-small);
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 6px;
}
.chatbot-result-excerpt mark {
  background: rgba(214,167,75,0.3);
  color: var(--navy-deep);
  padding: 0 2px;
  border-radius: var(--radius-sm);
  font-weight: 600;
}
.chatbot-result-cta {
  display: inline-block;
  font-size: var(--fs-small);
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.02em;
}

/* ============================================================
   Chatbot — bulles "réponse Claude" avec citations + sources
   ============================================================ */
.chatbot-msg-claude .chatbot-msg-bubble {
  font-size: var(--fs-body);
  line-height: 1.55;
}
.chatbot-msg-claude .chatbot-msg-bubble p {
  margin: 0 0 8px;
}
.chatbot-msg-claude .chatbot-msg-bubble p:last-child { margin-bottom: 0; }
/* Intertitres et filets des réponses longues (analyses) */
.chatbot-msg-claude .chatbot-msg-bubble .chatbot-h { font-weight: 700; color: var(--navy); margin: 12px 0 4px; }
.chatbot-msg-claude .chatbot-msg-bubble .chatbot-h:first-child { margin-top: 0; }
.chatbot-msg-claude .chatbot-msg-bubble hr { border: 0; border-top: 1px solid var(--border-subtle); margin: 10px 0; }
.chatbot-msg-claude .chatbot-msg-bubble ol { margin: 6px 0 10px; padding-left: 20px; }
.chatbot-msg-claude .chatbot-msg-bubble strong { color: var(--navy-deep); font-weight: 700; }
.chatbot-msg-claude .chatbot-msg-bubble ul {
  margin: 6px 0 8px 0;
  padding-left: 18px;
}
.chatbot-msg-claude .chatbot-msg-bubble li {
  margin-bottom: 3px;
}

/* Curseur clignotant pendant que Claude streame la réponse */
.chatbot-msg-claude.is-streaming [data-stream-text]::after {
  content: '▍';
  display: inline-block;
  color: var(--gold);
  font-weight: 700;
  margin-left: 2px;
  animation: chatbotCaretBlink 900ms steps(2) infinite;
}
@keyframes chatbotCaretBlink {
  to { opacity: 0.3; }
}
@media (prefers-reduced-motion: reduce) {
  .chatbot-msg-claude.is-streaming [data-stream-text]::after { animation: none; opacity: 0.6; }
}

/* Renvois aux sources : petit numéro discret, une fois par paragraphe ou par liste */
.chatbot-cite {
  display: inline-block; vertical-align: super; line-height: 1;
  margin-left: 2px; padding: 1px 4px; border-radius: var(--radius-sm);
  font-size: 0.68em; font-weight: 700; color: var(--gold-ink);
  background: rgba(214,167,75,0.14);
}

/* Sources sous la réponse : seulement celles qui sont citées, une ligne chacune */
.chatbot-sources {
  margin-top: 12px; padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}
.chatbot-sources-title {
  font-size: var(--fs-caption); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-light); margin-bottom: 4px;
}
.chatbot-msg-claude .chatbot-msg-bubble .chatbot-sources-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.chatbot-msg-claude .chatbot-msg-bubble .chatbot-sources-list li { margin: 0; }
.chatbot-source {
  display: flex; align-items: baseline; gap: 8px; padding: 4px 6px; margin-inline: -6px;
  border-radius: var(--radius-sm); text-decoration: none !important;
  transition: background var(--dur-base) ease;
}
.chatbot-source:hover { background: rgba(214,167,75,0.12); }
.chatbot-source-n {
  flex-shrink: 0; min-width: 18px; text-align: center;
  font-size: var(--fs-caption); font-weight: 700; color: var(--gold-ink);
  background: rgba(214,167,75,0.14); border-radius: var(--radius-sm); padding: 0 4px;
}
.chatbot-source-title {
  font-size: var(--fs-small); font-weight: 600; line-height: 1.35; color: var(--navy);
  text-decoration: underline; text-decoration-color: rgba(11,29,58,0.25); text-underline-offset: 3px;
}
.chatbot-source:hover .chatbot-source-title { text-decoration-color: var(--gold); }

/* Suggestions */
.chatbot-suggestions {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding-left: 36px;
  margin-top: -4px;
}
.chatbot-suggestion {
  background: white;
  border: 1px solid rgba(11,29,58,0.1);
  color: var(--navy);
  padding: 7px 12px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-small); font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: var(--dur-base) ease; transition-property: var(--transition-ui);
}
.chatbot-suggestion:hover {
  background: var(--navy);
  color: white;
  border-color: var(--navy);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* Typing indicator */
.chatbot-typing {
  display: flex; align-items: flex-end; gap: 8px;
  align-self: flex-start;
}
.chatbot-typing-bubble {
  background: white;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
  display: flex; gap: 4px;
}
.chatbot-typing-bubble span {
  width: 7px; height: 7px; border-radius: 50%;
  background: rgba(11,29,58,0.35);
  animation: chatbot-typing-bounce 1.2s ease infinite;
}
.chatbot-typing-bubble span:nth-child(2) { animation-delay: 0.15s; }
.chatbot-typing-bubble span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chatbot-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Input */
.chatbot-input {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 12px 14px;
  background: white;
  border-top: 1px solid rgba(11,29,58,0.08);
}
.chatbot-input-attach,
.chatbot-input-mic,
.chatbot-input-send {
  width: 38px; height: 38px; border-radius: 50%;
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: var(--dur-base) ease; transition-property: var(--transition-ui);
}
.chatbot-input-attach {
  background: transparent;
  color: var(--text-light);
}
.chatbot-input-attach:hover:not(:disabled) {
  background: rgba(11,29,58,0.06);
  color: var(--navy);
}
.chatbot-input-attach:disabled { opacity: 0.4; cursor: not-allowed; }
.chatbot-input-field {
  flex: 1;
  border: 1px solid var(--border-input);
  border-radius: var(--radius-pill);
  padding: 9px 14px;
  font-family: inherit;
  font-size: var(--fs-small);
  resize: none;
  max-height: 100px;
  background: var(--warm-white);
  color: var(--text-primary);
  transition: border-color var(--dur-base) ease, box-shadow var(--dur-base) ease;
}
.chatbot-input-field:focus {
  outline: none;
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(11,29,58,0.08);
  background: white;
}
.chatbot-input-field::placeholder { color: var(--text-light); }
.chatbot-input-send {
  background: var(--navy);
  color: white;
}
.chatbot-input-send:hover {
  background: var(--navy-light);
  transform: scale(1.05);
}
.chatbot-input-send:active { transform: scale(0.96); }

/* Dictée vocale (micro, langue, état) et lecture à voix haute */
.chatbot-input-mic { background: transparent; color: var(--navy); }
.chatbot-input-mic:hover { background: rgba(11,29,58,0.06); }
.chatbot-input-mic.is-unavailable { color: var(--text-light); }
.chatbot-input-mic.is-listening {
  background: var(--danger); color: var(--on-dark);
  animation: chatbot-mic-pulse 1.4s ease-out infinite;
}
@keyframes chatbot-mic-pulse {
  0% { box-shadow: 0 0 0 0 rgba(180,35,24,0.45); }
  100% { box-shadow: 0 0 0 10px rgba(180,35,24,0); }
}
.chatbot-voice-lang {
  height: 38px; min-width: 38px; padding: 0 8px; flex-shrink: 0; cursor: pointer;
  border: 1px solid var(--border-input); border-radius: var(--radius-pill); background: var(--surface);
  font: inherit; font-size: var(--fs-caption); font-weight: 700; letter-spacing: 0.04em; color: var(--navy);
}
.chatbot-voice-lang:hover { border-color: var(--navy); }
.chatbot-voice-status {
  margin: 0; padding: 10px 14px 0; background: var(--surface);
  font-size: var(--fs-caption); line-height: 1.45; color: var(--text-secondary);
  border-top: 1px solid rgba(11,29,58,0.08);
}
.chatbot-voice-status.is-error { color: var(--danger); }
.chatbot-voice-status:not([hidden]) + .chatbot-input { border-top: 0; }
.chatbot-listen {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 10px; min-height: 32px; padding: 4px 12px; cursor: pointer;
  font: inherit; font-size: var(--fs-caption); font-weight: 600; color: var(--navy);
  background: transparent; border: 1px solid var(--border-input); border-radius: var(--radius-pill);
}
.chatbot-listen:hover { border-color: var(--navy); }
.chatbot-listen[aria-pressed="true"] { background: var(--navy); border-color: var(--navy); color: var(--on-dark); }
@media (prefers-reduced-motion: reduce) {
  .chatbot-input-mic.is-listening { animation: none; box-shadow: 0 0 0 3px rgba(180,35,24,0.35); }
}

/* Footer */
.chatbot-footer {
  padding: 8px 14px 12px;
  background: white;
  font-size: var(--fs-small);
  color: var(--text-light);
  text-align: center;
  display: flex; align-items: center; justify-content: center; gap: 5px;
  border-top: 1px solid rgba(11,29,58,0.04);
}
.chatbot-footer-badge {
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-light) 100%);
  color: var(--navy-deep);
  padding: 1px 7px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: var(--fs-caption);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Mobile: full-screen panel */
@media (max-width: 640px) {
  .chatbot { right: 16px; bottom: 16px; }
  .chatbot-launcher { width: 56px; height: 56px; }
  .chatbot-panel {
    position: fixed;
    inset: 12px;
    width: auto; height: auto;
    max-height: none;
    border-radius: var(--radius-lg);
  }
}
