/* ═══════════════════════════════════════════════════
   Tanwir IA — style.css
   Ministère de l'Éducation — Mauritanie
   ═══════════════════════════════════════════════════ */
:root {
  --green:      #1f7a45;
  --green-dk:   #145730;
  --green-md:   #2d9b5a;
  --green-lt:   #4cbb7a;
  --green-pale: #eaf4ee;
  --green-bg:   #f4f9f6;
  --gold:       #c9a227;
  --red:        #c0392b;
  --white:      #fff;
  --text:       #14231a;
  --text-2:     #3d5c48;
  --text-3:     #82a892;
  --border:     #cce3d5;
  --sh:         0 2px 12px rgba(20,87,48,.08);
  --sh-lg:      0 4px 24px rgba(20,87,48,.11);
}

*,*::before,*::after { box-sizing:border-box; margin:0; padding:0 }
html, body { height:100% }
body {
  font-family:'Cairo',sans-serif;
  background:var(--green-bg);
  color:var(--text);
  display:flex; flex-direction:column;
  overflow:hidden;
  direction:rtl;
}

/* ══ HEADER ═══════════════════════════════════════════ */
header {
  background:var(--white);
  border-bottom:2.5px solid var(--green);
  height:68px;
  padding:0 22px;
  display:flex; align-items:center; justify-content:space-between;
  flex-shrink:0;
  box-shadow:var(--sh);
  position:relative; z-index:20;
  direction:ltr;          /* LTR indispensable — sinon gauche/droite inversés */
}

.hd-left { display:flex; align-items:center; gap:10px }
.coat    { height:48px; width:auto; object-fit:contain; flex-shrink:0 }
.ministry-txt { display:flex; flex-direction:column; gap:1px; direction:rtl; text-align:right }
.ministry-title { font-size:11.5px; font-weight:700; color:var(--text); white-space:nowrap }
.ministry-sub   { font-size:9.5px;  color:var(--text-2); white-space:nowrap }

.hd-center {
  position:static!important;
  transform:none!important;
  margin-right:auto!important;
  margin-left:120px!important;   /* ← Décalage vers la droite */
}
.tanwir-logo { height:50px; width:auto; object-fit:contain }

.hd-right { display:flex; align-items:center; margin-left:auto }

/* Stats dans le header */
.hd-stats {
  display:flex; align-items:center; gap:10px;
  background:var(--green);
  border-radius:10px;
  padding:6px 16px;
}
.hd-stat { display:flex; flex-direction:column; align-items:center }
.hds-num {
  font-family:'Cairo',sans-serif; font-weight:800;
  font-size:1.1rem; color:#fff; line-height:1.1;
}
.hds-lbl { font-size:.6rem; color:rgba(255,255,255,.85) }
.hds-sep { width:1px; height:28px; background:rgba(255,255,255,.3) }

/* ══ CORPS ═════════════════════════════════════════════ */
main { flex:1; display:flex; flex-direction:column; overflow:hidden }

/* ══ MESSAGES CENTRÉS ══════════════════════════════════ */
.messages {
  flex:1; overflow-y:auto;
  padding:16px 16px 6px;
  display:flex; flex-direction:column;
  align-items:center;
  gap:14px; scroll-behavior:smooth;
}
.messages::-webkit-scrollbar { width:4px }
.messages::-webkit-scrollbar-thumb { background:var(--border); border-radius:4px }

/* ══ ÉCRAN D'ACCUEIL ═══════════════════════════════════ */
#welcome { width:100%; max-width:940px }
.welcome-wrap { display:flex; gap:14px; align-items:flex-start; direction:ltr }

.welcome-card {
  flex:1; background:var(--white); border-radius:16px;
  padding:24px 20px; border:1px solid var(--border);
  box-shadow:var(--sh-lg); text-align:center; direction:rtl;
}
.wcard-icon {
  width:62px; height:62px; border-radius:14px;
  margin:0 auto 14px;
  background:linear-gradient(135deg,var(--green),var(--green-lt));
  display:flex; align-items:center; justify-content:center;
  box-shadow:0 5px 18px rgba(31,122,69,.22);
  overflow:hidden;
}
.welcome-card h2 { font-size:18px; font-weight:800; color:var(--green-dk); margin-bottom:7px }
.welcome-card > p { font-size:12.5px; color:var(--text-2); line-height:1.9; margin-bottom:16px }

.stat-row { display:flex; flex-wrap:wrap; justify-content:center; gap:6px; margin-bottom:16px; direction:ltr }
.stat-chip {
  display:inline-flex; align-items:center; gap:5px;
  background:var(--green-pale); border:1.5px solid var(--border);
  border-radius:20px; padding:4px 12px;
  font-size:11px; font-weight:700; color:var(--green-dk); direction:ltr;
}
.sc-dot { width:6px; height:6px; background:var(--green-md); border-radius:50%; flex-shrink:0 }

.sug-label {
  font-size:10.5px; font-weight:700; color:var(--text-3);
  text-transform:uppercase; letter-spacing:.9px;
  margin-bottom:9px; display:flex; align-items:center; gap:8px;
}
.sug-label::before,.sug-label::after { content:''; flex:1; height:1px; background:var(--border) }

.sug-grid { display:flex; flex-wrap:wrap; gap:7px; justify-content:center }
.sug {
  padding:8px 14px; background:var(--green-pale);
  border:1.5px solid var(--border); border-radius:20px;
  font-size:12px; font-weight:600; color:var(--green-dk);
  cursor:pointer; transition:all .18s; user-select:none;
  font-family:'Cairo',sans-serif;
}
.sug:hover {
  background:var(--green); border-color:var(--green); color:#fff;
  transform:translateY(-2px); box-shadow:0 4px 12px rgba(31,122,69,.25);
}

.info-panel {
  width:224px; flex-shrink:0;
  background:var(--white); border-radius:14px;
  border:1px solid var(--border); box-shadow:var(--sh);
  padding:18px 16px; direction:rtl;
}
.info-title { font-size:12.5px; font-weight:700; color:var(--green-dk); margin-bottom:14px; display:flex; align-items:center; gap:6px }
.info-steps { display:flex; flex-direction:column; gap:11px; margin-bottom:14px }
.step { display:flex; align-items:flex-start; gap:9px }
.step-num {
  width:26px; height:26px; border-radius:7px; flex-shrink:0;
  background:linear-gradient(135deg,var(--green),var(--green-lt));
  color:#fff; font-size:12px; font-weight:700;
  display:flex; align-items:center; justify-content:center;
}
.step-txt { display:flex; flex-direction:column; gap:1px }
.step-txt b    { font-size:11.5px; font-weight:700; color:var(--text) }
.step-txt span { font-size:10.5px; color:var(--text-3) }
.info-note {
  background:#fff8e6; border:1px solid #f0d070; border-radius:8px;
  padding:7px 10px; font-size:10.5px; color:#7a5c00;
  display:flex; align-items:flex-start; gap:5px; line-height:1.6;
}

/* ══ BULLES ═════════════════════════════════════════════ */
.msg {
  display:flex; gap:9px;
  width:100%; max-width:900px;
  animation:slideIn .22s ease both;
  direction:ltr;
}
@keyframes slideIn { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:none} }

.msg.bot  { flex-direction:row }
.msg.user { flex-direction:row-reverse }

/* Avatar */
.av {
  width:34px; height:34px; border-radius:10px; flex-shrink:0;
  display:flex; align-items:center; justify-content:center;
  font-size:15px;
}
.bot-av {
  background:linear-gradient(135deg,var(--green),var(--green-lt));
  box-shadow:0 2px 7px rgba(31,122,69,.25);
  color:#fff;
}
.msg.user .av { background:linear-gradient(135deg,#1a5fa0,#2e86de); box-shadow:0 2px 7px rgba(26,95,160,.25) }

/* Bulle */
.bubble {
  padding:11px 15px; border-radius:13px;
  font-size:13.5px; line-height:1.85;
  max-width:calc(100% - 44px); min-width:0; word-break:break-word;
}
.msg.user .bubble {
  background:linear-gradient(135deg,var(--green),var(--green-dk));
  color:#fff; border-top-right-radius:3px;
  box-shadow:0 3px 10px rgba(31,122,69,.18);
  direction:rtl; text-align:right;
}
.msg.bot .bubble {
  background:var(--white); color:var(--text);
  border-top-left-radius:3px;
  border:1px solid var(--border); box-shadow:var(--sh);
  direction:rtl; text-align:right;
}
/* Bulle française : LTR forcé */
.msg.bot .bubble.ltr,
.msg.bot .bubble.ltr .stream-text,
.msg.bot .bubble.ltr .stream-text h4,
.msg.bot .bubble.ltr .stream-text strong,
.msg.bot .bubble.ltr .stream-text p {
  direction: ltr !important;
  text-align: left !important;
}
.err-bub  { color:var(--red) !important }
.err-inline { color:var(--red); font-size:12.5px; margin-top:7px }


/* ══ HTML STRUCTURÉ DANS LES BULLES ════════════════════
   Le LLM génère du HTML : h4, ul/li, strong
   ═══════════════════════════════════════════════════ */
.stream-text h4 {
  font-size:13px; font-weight:800; color:var(--green-dk);
  margin:6px 0 2px; padding-bottom:2px;
  border-bottom:1.5px solid var(--green-pale);
  line-height:1.4;
}
.stream-text h4:first-child { margin-top:0 }
.stream-text ul, .stream-text ol {
  margin:2px 0; padding:0; list-style:none;
}
/* Cacher les éléments vides */
.stream-text li:empty,
.stream-text p:empty,
.stream-text ul:empty { display:none }
/* li : flex géré par applyDir() en JS (puces span.tbul) */
.stream-text li { list-style:none; }
.stream-text strong { color:var(--green-dk); font-weight:700 }
.stream-text p { margin:0 0 2px; line-height:1.65 }
.stream-text p:last-child { margin-bottom:0 }
.stream-text > *:first-child { margin-top:0 }
.stream-text > *:last-child  { margin-bottom:0 }
/* Éviter double-espacement entre h4 et ul qui suit */
.stream-text h4 + ul { margin-top:1px }

/* Curseur stream */
.cursor {
  display:inline-block; width:2px; height:1em;
  background:var(--green-md); margin-right:2px;
  vertical-align:text-bottom; animation:blink .7s step-end infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }

/* ══ SOURCES ════════════════════════════════════════════ */
.srcs {
  margin-top:9px; padding-top:8px; border-top:1px solid var(--border);
  display:flex; flex-wrap:wrap; gap:5px; direction:ltr;
}
.stag {
  display:inline-flex; align-items:center; gap:5px;
  background:var(--green-pale); border:1px solid var(--border);
  color:var(--green-dk); font-size:10px; font-weight:600;
  padding:3px 9px; border-radius:20px; direction:ltr;
}
.stag svg { flex-shrink:0; stroke:var(--green-dk) }

/* ══ RECOMMANDATIONS — style professionnel ══════════════ */
.reco-sec {
  margin-top:13px; padding-top:12px;
  border-top:2px solid var(--green-pale);
}

/* Titre section */
.reco-ttl {
  display:flex; align-items:center; gap:7px;
  font-size:10.5px; font-weight:700;
  color:var(--green-dk); text-transform:uppercase; letter-spacing:.7px;
  margin-bottom:10px; direction:rtl;
}
.reco-ttl svg { stroke:var(--green); flex-shrink:0 }

/* Carte ressource */
.rcard {
  display:flex; align-items:center; gap:11px;
  padding:10px 13px;
  background:var(--white);
  border:1.5px solid var(--border);
  border-radius:12px; margin-bottom:7px;
  text-decoration:none;
  transition:all .18s ease;
  direction:ltr;
  box-shadow:0 1px 4px rgba(20,87,48,.05);
}
.rcard:hover {
  border-color:var(--green);
  background:var(--green-pale);
  transform:translateX(3px);
  box-shadow:0 3px 12px rgba(31,122,69,.12);
}

/* Icône ressource (SVG coloré dans cercle) */
.rico {
  width:38px; height:38px; border-radius:10px; flex-shrink:0;
  display:flex; align-items:center; justify-content:center;
  transition:transform .18s;
}
.rico.scorm {
  background:linear-gradient(135deg,rgba(31,122,69,.14),rgba(31,122,69,.06));
  color:var(--green);
}
.rico.pdf {
  background:linear-gradient(135deg,rgba(192,57,43,.14),rgba(192,57,43,.06));
  color:var(--red);
}
.rico svg { stroke:currentColor }
.rcard:hover .rico { transform:scale(1.08) }

/* Info centre */
.rinfo { flex:1; min-width:0; direction:rtl; text-align:right }
.rinfo strong {
  display:block; font-size:12.5px; font-weight:700; color:var(--text);
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
  margin-bottom:3px;
}
.rinfo-course {
  display:inline-flex; align-items:center; gap:4px;
  font-size:10.5px; color:var(--text-3);
}
.rinfo-course svg { stroke:var(--text-3); flex-shrink:0 }
.rinfo-course span { white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:160px }

/* Droite : badge + action */
.rcard-right {
  display:flex; flex-direction:column; align-items:flex-end; gap:6px; flex-shrink:0;
}
.rtag {
  font-size:9.5px; font-weight:700; padding:2px 8px; border-radius:7px; white-space:nowrap;
}
.rtag.scorm { background:rgba(31,122,69,.12); color:var(--green-dk) }
.rtag.pdf   { background:rgba(192,57,43,.10); color:var(--red) }

.raction {
  display:flex; align-items:center; gap:4px;
  font-size:10px; font-weight:600;
  color:var(--green); opacity:.7;
  transition:opacity .18s;
}
.raction svg { stroke:var(--green); flex-shrink:0 }
.rcard:hover .raction { opacity:1 }

/* ══ TYPING INDICATOR ══════════════════════════════════ */
.typing-row { display:flex; gap:9px; direction:ltr; width:100%; max-width:900px }
.typing-bub {
  background:var(--white); border:1px solid var(--border);
  border-radius:13px; border-top-left-radius:3px;
  padding:13px 16px; box-shadow:var(--sh);
  display:flex; align-items:center; gap:5px;
}
.typing-bub span {
  width:7px; height:7px; background:var(--green);
  border-radius:50%; animation:bou 1.3s ease infinite;
}
.typing-bub span:nth-child(2) { animation-delay:.18s }
.typing-bub span:nth-child(3) { animation-delay:.36s }
@keyframes bou {
  0%,80%,100% { transform:scale(.65); opacity:.3 }
  40%          { transform:scale(1);   opacity:1  }
}

/* ══ INPUT ══════════════════════════════════════════════ */
.inp-area {
  flex-shrink:0; background:var(--white);
  border-top:2px solid var(--border);
  padding:10px 16px 12px;
  box-shadow:0 -3px 12px rgba(20,87,48,.06);
  display:flex; justify-content:center;
}
.inp-wrap { width:100%; max-width:900px; direction:ltr }
.inp-row  { display:flex; gap:9px; align-items:flex-end }

textarea {
  flex:1; background:var(--green-bg);
  border:2px solid var(--border); border-radius:12px;
  color:var(--text); font-size:13.5px;
  font-family:'Cairo',sans-serif;
  padding:10px 14px; resize:none; outline:none;
  min-height:44px; max-height:110px; line-height:1.6;
  transition:border-color .2s, box-shadow .2s, background .2s;
  direction:rtl; text-align:right;
}
textarea:focus {
  border-color:var(--green);
  box-shadow:0 0 0 3px rgba(31,122,69,.10);
  background:var(--white);
}
textarea::placeholder { color:var(--text-3) }

#sendBtn {
  width:44px; height:44px; border-radius:11px; border:none;
  background:linear-gradient(135deg,var(--green),var(--green-dk));
  color:#fff; cursor:pointer; flex-shrink:0;
  display:flex; align-items:center; justify-content:center;
  transition:transform .15s, box-shadow .2s, opacity .2s;
  box-shadow:0 3px 11px rgba(31,122,69,.35);
}
#sendBtn:hover   { transform:scale(1.06); box-shadow:0 5px 16px rgba(31,122,69,.42) }
#sendBtn:active  { transform:scale(.95) }
#sendBtn:disabled { opacity:.4; cursor:not-allowed; transform:none; box-shadow:none }

.inp-hint { text-align:center; font-size:10px; color:var(--text-3); margin-top:5px }

/* ══ FOOTER ═════════════════════════════════════════════ */
footer {
  flex-shrink:0; background:var(--green-dk);
  color:rgba(255,255,255,.72); font-size:10.5px;
  text-align:center; padding:6px 20px;
  display:flex; justify-content:center; align-items:center; gap:8px;
  direction:rtl;
}
.ft-sep { color:rgba(255,255,255,.3) }

/* ══ RESPONSIVE ══════════════════════════════════════════ */
@media (max-width:800px) {
  .welcome-wrap  { flex-direction:column; direction:rtl }
  .info-panel    { width:100% }
  .msg,.typing-row { max-width:100% }
  .ministry-txt  { display:none }
  header         { padding:0 12px; height:62px }
  .tanwir-logo   { height:44px }
  .coat          { height:42px }
  .hd-stats      { padding:5px 10px; gap:7px }
  .hds-num       { font-size:.95rem }
}