/* -----------------------------------------------------------------------------
 * abdelkader-widget.css — Widget vanilla « Abdelkader » (Sprint 3, 2026-09-09)
 * Remplace l'iframe Dify par un widget léger, cohérent avec le glossaire.
 * Palette GMP : accent #0f7380, crème #f5f3ec, vert pâle user #dee5cc.
 * Préfixe .ab- pour éviter tout conflit avec la page hôte.
 * -----------------------------------------------------------------------------
 */

.abdelkader-widget {
  --ab-accent: #0f7380;
  --ab-accent-strong: #0a5762;
  --ab-cream: #f5f3ec;
  --ab-user-bg: #dee5cc;
  --ab-bot-bg: #ffffff;
  --ab-text: #1e2a2b;
  --ab-text-muted: #5a6a6c;
  --ab-border: rgba(15, 115, 128, 0.15);
  --ab-shadow: 0 12px 32px -8px rgba(15, 115, 128, 0.28), 0 4px 12px -4px rgba(0, 0, 0, 0.08);
  --ab-radius: 16px;
  --ab-radius-bubble: 12px;
  --ab-fab-size: 58px;
  --ab-fab-offset: 20px;
  --ab-panel-w: 460px;
  --ab-panel-gap: 0px;

  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI Variable', 'Segoe UI', system-ui, 'Inter', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  color: var(--ab-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============================================================================
 * Bouton flottant (FAB)
 * ============================================================================
 */
.ab-fab {
  position: fixed;
  right: var(--ab-fab-offset);
  bottom: var(--ab-fab-offset);
  width: var(--ab-fab-size);
  height: var(--ab-fab-size);
  border: none;
  border-radius: 50%;
  background: var(--ab-accent);
  color: #ffffff;
  cursor: pointer;
  box-shadow: var(--ab-shadow);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 2147483000;
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
  padding: 0;
}
.ab-fab:hover,
.ab-fab:focus-visible {
  background: var(--ab-accent-strong);
  transform: translateY(-2px);
  outline: none;
  box-shadow: 0 16px 36px -8px rgba(15, 115, 128, 0.4), 0 6px 14px -4px rgba(0, 0, 0, 0.12);
}
.ab-fab:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 3px;
}
.ab-fab svg {
  width: 26px;
  height: 26px;
  display: block;
}
.ab-fab .ab-fab-close { display: none; }
/* Quand le panneau est ouvert, le FAB glisse hors écran (le bouton × du header
   sert alors à fermer). Évite qu'il recouvre le bouton d'envoi sur mobile. */
.abdelkader-widget[data-open='true'] .ab-fab {
  transform: translateX(140%);
  opacity: 0;
  pointer-events: none;
}

/* ============================================================================
 * Panneau
 * ============================================================================
 */
.ab-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--ab-panel-w);
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: var(--ab-cream);
  box-shadow: -12px 0 40px -12px rgba(15, 115, 128, 0.28), -4px 0 12px -4px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 2147482999;
  transform: translateX(100%);
  opacity: 1;
  pointer-events: none;
  transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
  border-left: 1px solid var(--ab-border);
}
.abdelkader-widget[data-open='true'] .ab-panel {
  transform: translateX(0);
  pointer-events: auto;
}

/* En-tête */
.ab-header {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(180deg, rgba(15, 115, 128, 0.09), transparent);
  border-bottom: 1px solid var(--ab-border);
  flex-shrink: 0;
}
.ab-title {
  font-family: inherit;
  font-size: 2.1rem;
  font-weight: 600;
  color: var(--ab-accent-strong);
  margin: 0;
  flex-grow: 1;
  letter-spacing: 0.01em;
}
.ab-header-btn {
  width: 45px;
  height: 45px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--ab-text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
  padding: 0;
}
.ab-header-btn:hover,
.ab-header-btn:focus-visible {
  background: rgba(15, 115, 128, 0.1);
  color: var(--ab-accent-strong);
  outline: none;
}
.ab-header-btn:focus-visible {
  outline: 2px solid var(--ab-accent);
  outline-offset: 1px;
}
.ab-header-btn svg { width: 26px; height: 26px; }

/* Zone de messages */
.ab-messages {
  flex-grow: 1;
  overflow-y: auto;
  padding: 16px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-anchor: none;
  scroll-behavior: auto;
}
.ab-messages::-webkit-scrollbar { width: 6px; }
.ab-messages::-webkit-scrollbar-thumb { background: rgba(15, 115, 128, 0.3); border-radius: 3px; }
.ab-messages::-webkit-scrollbar-track { background: transparent; }

.ab-msg {
  max-width: 92%;
  padding: 14px 18px;
  border-radius: var(--ab-radius-bubble);
  line-height: 1.55;
  font-size: 1.7rem;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  animation: ab-fadein 0.18s ease-out;
}
@keyframes ab-fadein {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.ab-msg-bot {
  background: var(--ab-bot-bg);
  color: var(--ab-text);
  align-self: flex-start;
  border: 1px solid var(--ab-border);
  border-top-left-radius: 4px;
}

/* --- Streaming polish : gradient mask + curseur ------------------------------
 * Pendant que la réponse arrive, le bas du corps est légèrement fondu ; le
 * dernier bloc porte un curseur discret. Une fois le stream terminé, la
 * classe est retirée, tout redevient net. */
.ab-msg-bot--streaming .ab-msg-body {
  -webkit-mask-image: linear-gradient(to bottom, black calc(100% - 22px), transparent 100%);
          mask-image: linear-gradient(to bottom, black calc(100% - 22px), transparent 100%);
}
.ab-msg-bot--streaming .ab-msg-body > *:last-child::after {
  content: '▍';
  display: inline-block;
  margin-left: 2px;
  color: var(--ab-accent);
  font-weight: 400;
  animation: ab-blink 1s steps(2, start) infinite;
  vertical-align: baseline;
  transform: translateY(1px);
}
@keyframes ab-blink {
  to { visibility: hidden; }
}
@media (prefers-reduced-motion: reduce) {
  .ab-msg-bot--streaming .ab-msg-body > *:last-child::after { animation: none; }
}
.ab-msg-user {
  background: var(--ab-user-bg);
  color: var(--ab-text);
  align-self: flex-end;
  border-top-right-radius: 4px;
}
.ab-msg-error {
  background: #fbeaea;
  color: #7a1f1f;
  border: 1px solid #e5b7b7;
  align-self: flex-start;
  font-size: 0.92rem;
}

/* Contenu markdown à l'intérieur des bulles */
.ab-msg p { margin: 0 0 0.5em 0; }
.ab-msg p:last-child { margin-bottom: 0; }
.ab-msg ul, .ab-msg ol { margin: 0.35em 0; padding-left: 1.25em; }
.ab-msg li { margin: 0.15em 0; }
.ab-msg strong { font-weight: 700; color: var(--ab-accent-strong); }
.ab-msg em { font-style: italic; }
.ab-msg a { color: var(--ab-accent); text-decoration: underline; text-underline-offset: 2px; }
.ab-msg a:hover { color: var(--ab-accent-strong); }
.ab-msg code {
  background: rgba(15, 115, 128, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: 'SFMono-Regular', Menlo, Consolas, monospace;
  font-size: 0.9em;
}
.ab-msg h1, .ab-msg h2, .ab-msg h3 {
  font-family: inherit;
  color: var(--ab-accent-strong);
  margin: 0.4em 0 0.2em;
  line-height: 1.25;
}
.ab-msg h1 { font-size: 1.15em; }
.ab-msg h2 { font-size: 1.08em; }
.ab-msg h3 { font-size: 1em; }
.ab-msg blockquote {
  margin: 0.3em 0;
  padding-left: 0.75em;
  border-left: 3px solid var(--ab-accent);
  color: var(--ab-text-muted);
  font-style: italic;
}

/* Indicateur de typing */
.ab-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 4px 0;
}
.ab-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ab-accent);
  opacity: 0.35;
  animation: ab-bounce 1.2s infinite ease-in-out;
}
.ab-typing span:nth-child(2) { animation-delay: 0.15s; }
.ab-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes ab-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Sources RAG */
.ab-sources {
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px dashed var(--ab-border);
  font-size: 0.85em;
  color: var(--ab-text-muted);
}
.ab-sources-title {
  font-size: 0.75em;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
  color: var(--ab-accent);
}
.ab-source-item {
  display: block;
  margin: 2px 0;
  padding: 3px 8px;
  border-radius: 4px;
  background: rgba(15, 115, 128, 0.06);
  color: var(--ab-text);
  text-decoration: none;
  border: none;
  font-size: 0.85em;
}
.ab-source-item:hover { background: rgba(15, 115, 128, 0.14); }

/* Suggestions */
.ab-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}
.ab-sugg {
  background: #ffffff;
  border: 1px solid var(--ab-border);
  color: var(--ab-accent-strong);
  padding: 10px 16px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 1.6rem;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
.ab-sugg:hover,
.ab-sugg:focus-visible {
  background: rgba(15, 115, 128, 0.08);
  transform: translateY(-1px);
  outline: none;
}
.ab-sugg:focus-visible { outline: 2px solid var(--ab-accent); outline-offset: 1px; }
.ab-sugg:active { transform: translateY(0); }

/* Formulaire */
.ab-form {
  padding: 10px 12px 14px;
  border-top: 1px solid var(--ab-border);
  display: flex;
  gap: 8px;
  align-items: stretch;
  background: rgba(255, 255, 255, 0.4);
  flex-shrink: 0;
}
.ab-input {
  flex-grow: 1;
  border: 1px solid var(--ab-border);
  border-radius: 12px;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 1.65rem;
  line-height: 1.45;
  resize: none;
  background: #ffffff;
  color: var(--ab-text);
  min-height: 54px;
  max-height: 160px;
  overflow-y: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
/* La scrollbar n'apparaît que si le contenu dépasse la max-height (posée par JS). */
.ab-input.ab-scrollable { overflow-y: auto; }
.ab-input:focus-visible {
  outline: none;
  border-color: var(--ab-accent);
  box-shadow: 0 0 0 3px rgba(15, 115, 128, 0.14);
}
.ab-send {
  align-self: stretch;
  width: 52px;
  border: none;
  border-radius: 12px;
  background: var(--ab-accent);
  color: #ffffff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.1s ease;
  padding: 0;
  flex-shrink: 0;
}
.ab-send:hover:not(:disabled),
.ab-send:focus-visible {
  background: var(--ab-accent-strong);
  outline: none;
}
.ab-send:focus-visible { outline: 2px solid var(--ab-accent); outline-offset: 2px; }
.ab-send:disabled {
  background: var(--ab-border);
  color: var(--ab-text-muted);
  cursor: not-allowed;
}
.ab-send svg { width: 32px; height: 32px; }

/* ============================================================================
 * Responsive — pleine largeur / plein écran ≤ 600 px (téléphones).
 * Au-delà (tablettes, ordinateurs) : colonne de largeur fixe ancrée à droite.
 * On utilise left:0 + right:0 (et non 100vw) pour couvrir exactement la zone
 * de contenu, quelle que soit la largeur de la barre de défilement.
 * ============================================================================
 */
@media (max-width: 600px) {
  .abdelkader-widget {
    --ab-fab-size: 54px;
    --ab-fab-offset: 14px;
  }
  .ab-panel {
    left: 0;
    right: 0;
    width: auto;
    max-width: none;
    border-left: none;
    box-shadow: none;
  }
  .ab-messages { padding: 14px 14px 6px; }
  .ab-form { padding: 10px 12px calc(14px + env(safe-area-inset-bottom, 0)); }
}

/* Texte réservé aux lecteurs d'écran (typing indicator, annonce SR finale) */
.ab-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Réduit les animations si l'utilisateur préfère */
@media (prefers-reduced-motion: reduce) {
  .abdelkader-widget *,
  .abdelkader-widget *::before,
  .abdelkader-widget *::after {
    animation-duration: 0.001s !important;
    transition-duration: 0.001s !important;
  }
  .abdelkader-widget .ab-messages {
    scroll-behavior: auto !important;
  }
}
