/* ══ JOSUÉ — CHAT FIDÈLE ═══════════════════════════════════════════
   Écran C1 : conversation avec Josué, style épuré façon Claude.ai.
   ================================================================ */

#chat-app {
  display: flex;
  height: 100vh;
  background: var(--parchment);
}

/* ── Barre latérale ──────────────────────────────────────────── */
.chat-sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--navy);
  color: var(--white);
  display: flex;
  flex-direction: column;
  padding: 18px 16px;
}

.chat-sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Liste verticale (icône + libellé), même pattern que la nav admin
   (.nav-item/.nav-icon, layout.css) — un ancien toggle horizontal à
   largeur fixe débordait dès que le nombre d'onglets fidèle a dépassé 4
   (Chat/Podcasts/Bibliothèque/Prière/Plans/Témoignages/Mes données). */
.chat-sidebar-nav {
  display: flex;
  flex-direction: column;
  margin: 16px 0;
}

.podcast-view-header {
  padding: 24px 32px 0;
}

.podcast-view-header .section-title {
  font-family: var(--font-display);
  font-size: 20px;
  color: var(--text);
  margin-bottom: 14px;
}

.podcast-grid-member {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  padding: 0 32px 32px;
}

.library-panel {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.library-content {
  padding: 0 32px 20px;
  margin: 0 !important;
}

.privacy-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-xs);
}

.privacy-card h3 {
  font-family: var(--font-display);
  font-size: 17px;
  color: var(--navy);
}

.privacy-consent-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-top: 1px solid var(--border-soft);
}

.privacy-consent-row:first-child { border-top: none; }

.privacy-consent-label { font-size: 14px; color: var(--text); }

.privacy-consent-status {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
}

.privacy-consent-status.yes { background: var(--success-bg); color: var(--success); }
.privacy-consent-status.no { background: var(--border-soft); color: var(--text-muted); }

.privacy-request-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 13px;
  color: var(--text-soft);
  border-top: 1px solid var(--border-soft);
}

.privacy-request-row:first-child { border-top: none; }

.chat-sidebar-title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
}

.chat-sidebar-church {
  font-size: 11.5px;
  color: var(--text-light);
}

.chat-conversation-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-conversation-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 6px 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-light);
  cursor: pointer;
  transition: background .15s;
}

.chat-conversation-item:hover {
  background: var(--navy-mid);
  color: var(--white);
}

.chat-conversation-item.active {
  background: var(--navy-mid);
  color: var(--gold);
  font-weight: 600;
}

.chat-conversation-item-title {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-conversation-item-menu-btn {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: inherit;
  border-radius: 4px;
  cursor: pointer;
  opacity: 0;
  font-size: 14px;
  line-height: 22px;
}

.chat-conversation-item:hover .chat-conversation-item-menu-btn,
.chat-conversation-item.menu-open .chat-conversation-item-menu-btn {
  opacity: .8;
}

.chat-conversation-item-menu-btn:hover {
  opacity: 1;
  background: rgba(255,255,255,.12);
}

.chat-conversation-menu {
  position: absolute;
  right: 6px;
  top: calc(100% + 2px);
  z-index: 20;
  min-width: 150px;
  background: var(--navy-mid);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: var(--radius-sm);
  box-shadow: 0 6px 16px rgba(0,0,0,.35);
  overflow: hidden;
}

.chat-conversation-menu-item {
  padding: 9px 14px;
  font-size: 13px;
  color: var(--white);
  cursor: pointer;
  white-space: nowrap;
}

.chat-conversation-menu-item:hover {
  background: rgba(255,255,255,.1);
}

.chat-conversation-menu-item.danger {
  color: #e88;
}

.chat-sidebar-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-light);
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,.1);
}

.chat-sidebar-footer a {
  color: var(--gold);
  text-decoration: none;
}

/* ── Zone principale ─────────────────────────────────────────── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-pastor-banner {
  background: var(--gold-pale);
  color: var(--gold-muted);
  padding: 10px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 1px solid var(--gold-line);
}

.chat-pastor-banner-link {
  text-decoration: underline;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}

.chat-empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 18px;
}

.chat-empty-emblem {
  font-size: 40px;
  color: var(--gold);
}

.chat-empty-state h2 {
  font-family: var(--font-display);
  font-size: 20px;
  color: var(--text);
  font-weight: 600;
  margin-bottom: -10px;
}

.chat-welcome-message {
  font-style: italic;
  font-size: 14px;
  color: var(--text-muted);
  max-width: 420px;
  margin-bottom: -10px;
}

.chat-empty-subtitle {
  font-size: 15px;
  color: var(--text-light);
}

.chat-suggestions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  max-width: 560px;
}

.chat-suggestion {
  background: var(--white);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 12.5px;
  color: var(--text-soft);
  text-align: left;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}

.chat-suggestion:hover {
  border-color: var(--gold);
  box-shadow: var(--shadow);
}

.chat-bubble-row {
  display: flex;
  margin-bottom: 18px;
}

.chat-bubble-row.user {
  justify-content: flex-end;
}

.chat-bubble {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 14.5px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.chat-bubble-row.user .chat-bubble {
  background: var(--navy);
  color: var(--white);
  border-bottom-right-radius: 4px;
}

.chat-bubble-row.assistant .chat-bubble {
  background: var(--white);
  color: var(--text);
  border: 1px solid var(--border-soft);
  border-bottom-left-radius: 4px;
  /* Contenu désormais rendu en HTML structuré (renderMarkdownLite), pas du
     texte brut préformaté — pre-wrap doublerait les espacements avec les
     marges de <p>/<h4>/<li> ci-dessous. */
  white-space: normal;
}

.chat-bubble p { margin: 0 0 10px; }
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble h4, .chat-bubble h5, .chat-bubble h6 {
  font-family: var(--font-display);
  color: var(--navy);
  margin: 14px 0 6px;
}
.chat-bubble h4:first-child, .chat-bubble h5:first-child, .chat-bubble h6:first-child { margin-top: 0; }
.chat-bubble ul, .chat-bubble ol { margin: 0 0 10px 20px; padding: 0; }
.chat-bubble li { margin-bottom: 4px; }
.chat-bubble ul:last-child, .chat-bubble ol:last-child { margin-bottom: 0; }

.chat-bubble-row.assistant.distress .chat-bubble,
.chat-bubble-row.assistant.degraded .chat-bubble {
  border-left: 3px solid var(--gold);
}

.chat-cited-verses {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chat-cited-verse-tag {
  font-size: 10.5px;
  font-weight: 700;
  padding: 3px 9px;
  background: var(--gold-pale);
  color: var(--gold-muted);
  border-radius: 20px;
}

.chat-typing-cursor {
  display: inline-block;
  width: 2px;
  height: 14px;
  background: var(--text-muted);
  animation: chat-blink 1s step-start infinite;
  vertical-align: text-bottom;
  margin-left: 1px;
}

@keyframes chat-blink {
  50% { opacity: 0; }
}

/* ── Barre de saisie ─────────────────────────────────────────── */
.chat-input-bar {
  max-width: 760px;
  width: calc(100% - 48px);
  margin: 0 auto 6px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 10px 10px 18px;
  box-shadow: var(--shadow);
}

.chat-input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 14.5px;
  color: var(--text);
  max-height: 160px;
  line-height: 1.5;
  padding: 6px 0;
}

.chat-send-btn {
  background: var(--navy);
  color: var(--white);
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s;
}

.chat-send-btn:hover {
  background: var(--navy-mid);
}

.chat-send-btn:disabled {
  opacity: .4;
  cursor: not-allowed;
}

.chat-disclaimer {
  text-align: center;
  font-size: 10.5px;
  color: var(--text-muted);
  padding-bottom: 10px;
}

/* ── Barre mobile (hamburger) ──────────────────────────────────────
   Masquée par défaut : sur desktop, .chat-sidebar est toujours visible en
   colonne, cette barre n'a alors aucune utilité. */
.chat-mobile-topbar {
  display: none;
  align-items: center;
  gap: 10px;
  height: 52px;
  padding: 0 14px;
  background: var(--navy);
  color: var(--white);
  position: sticky;
  top: 0;
  z-index: 150;
  flex-shrink: 0;
}

.chat-mobile-topbar .mobile-menu-btn { color: var(--white); }
.chat-mobile-topbar .mobile-menu-btn:hover { background: rgba(255,255,255,.1); }

.chat-mobile-topbar-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
}

@media (max-width: 720px) {
  #chat-app { flex-direction: column; height: 100vh; }

  .chat-mobile-topbar { display: flex; }

  /* Tiroir coulissant plutôt que masquée sans recours (bug réel corrigé
     le 24/07/2026 : aucun moyen de la rouvrir, ni de se déconnecter, une
     fois cachée sur mobile). .sidebar-open posée par toggleMobileSidebar()
     (js/ui.js), même mécanisme que la barre latérale admin (layout.css). */
  .chat-sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: min(280px, 84vw);
    z-index: 200;
    transform: translateX(-100%);
    transition: transform var(--dur) var(--ease-smooth);
  }
  .chat-sidebar.sidebar-open { transform: translateX(0); }

  .chat-suggestions { grid-template-columns: 1fr; }
  .podcast-view-header { padding: 16px 16px 0; }
  .podcast-grid-member { grid-template-columns: repeat(2, 1fr); padding: 0 16px 16px; gap: 12px; }
  .library-content { padding: 0 16px 16px; }
}

@media (max-width: 480px) {
  .podcast-grid-member { grid-template-columns: 1fr; }
}

/* ── DreamBib : rendu structuré des analyses de rêves ────────── */
.dreambib-content h4, .dreambib-content h5, .dreambib-content h6 {
  color: var(--primary);
  margin: 1.2em 0 0.4em 0;
  font-family: var(--font-heading, 'EB Garamond', serif);
}
.dreambib-content h4 { font-size: 1.25rem; }
.dreambib-content h5 { font-size: 1.1rem; }
.dreambib-content p { margin: 0.5em 0; line-height: 1.7; }
.dreambib-content strong { color: var(--text); }
.dreambib-content ol, .dreambib-content ul { padding-left: 1.5em; margin: 0.5em 0; }
.dreambib-content li { margin: 0.3em 0; line-height: 1.6; }

/* ── Chat staff — parcours Ministre/Responsable ──────────────────
   Contrairement au chat fidèle (chat.html, page plein écran dédiée avec
   #chat-app en display:flex sur 100vh), cette version vit DANS le
   tableau de bord staff existant (index.html, .page/.content) —
   .staff-chat-layout fournit son propre contexte flex/hauteur pour que
   .chat-main/.chat-messages (flex:1, overflow-y:auto, déjà stylées
   ci-dessus) se comportent correctement une fois imbriquées. */
.staff-chat-layout {
  display: flex;
  gap: 20px;
  height: calc(100vh - var(--topbar-h) - 180px);
  min-height: 420px;
}
.staff-chat-sidebar {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.staff-chat-sidebar .chat-conversation-list {
  background: var(--white, #fff);
  border: 1px solid var(--border-soft, #e5e0d5);
  border-radius: 12px;
  padding: 8px;
}
#staff-chat-view.chat-main {
  border: 1px solid var(--border-soft, #e5e0d5);
  border-radius: 12px;
  background: var(--parchment, #faf8f3);
  overflow: hidden;
}
@media (max-width: 760px) {
  .staff-chat-layout { flex-direction: column; height: auto; }
  .staff-chat-sidebar { width: 100%; }
  #staff-chat-view.chat-main { height: 60vh; }
}