/* ==========================================================================
   Stellion — discussion : messages, réactions, zone de saisie
   Un seul composant de message (messages.js, buildMessageHTML), deux présentations :
     - salons de nexus (#chat-box) : liste — avatar, nom, heure, messages regroupés ;
     - messages privés et groupes (#mp-chat-box) : bulles, les miennes à droite en vert.
   Maquettes : SalonTexte, MP, Groupe, ChatMobile, BureauChat.
   ========================================================================== */

.chat-area {
  flex: 1;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.chat-box {
  flex: 1;
  min-height: 0;
  padding: var(--space-3) 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
}

/* ---------- En-tête d'un salon (maquette SalonTexte) ---------- */

.st-chat-head {
  flex-shrink: 0;
  min-height: 60px;
  padding: 0 var(--space-1) 0 6px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--bg);
}

.st-chat-head__title {
  flex: 1;
  min-width: 0;
  padding: 0 var(--space-1);
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.st-chat-head__name {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  min-width: 0;
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
}

.st-chat-head__name > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.st-chat-head__hash {
  color: var(--text-muted);
  font-weight: var(--weight-regular);
}

.st-chat-head__sub {
  font-weight: var(--weight-regular);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--text-muted);
}

.st-chat-head__sub:empty {
  display: none;
}

/* En-tête d'une conversation privée ou d'un groupe */
#mp-channel-title {
  flex-shrink: 0;
  display: block;
  font-weight: var(--weight-regular);
  backdrop-filter: none;
  width: 100%;
  height: auto;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
}

#mp-channel-title > .st-chat-head {
  width: 100%;
}

.st-chat-head--conv {
  gap: var(--space-1);
}

.st-chat-head__who {
  flex: 1;
  min-width: 0;
  width: auto;
  min-height: var(--tap-min);
  margin: 0;
  padding: 0 var(--space-1);
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  box-shadow: none;
  color: var(--text);
  font: inherit;
  letter-spacing: 0;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  cursor: pointer;
}

.st-chat-head__who:hover {
  background: var(--surface-2);
  filter: none;
  transform: none;
  box-shadow: none;
}

.st-chat-head__who > .st-avatar,
.st-chat-head__avatar {
  --avatar-size: 38px;
}

.st-chat-head__who .st-chat-head__title {
  padding: 0;
}

/* ☰ et « ‹ » : seulement sur mobile, la colonne est toujours visible sur ordinateur */
@media (min-width: 769px) {
  .st-chat-head__back {
    display: none;
  }
}

@media (min-width: 769px) {
  .st-chat-head__menu {
    display: none;
  }
}

/* Phrase sur le chiffrement (décision de Maxime), sous l'en-tête de chaque discussion */
.st-crypto-note {
  flex-shrink: 0;
  margin: 0;
  padding: 6px var(--space-4);
  border-bottom: 1px solid var(--hairline);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.st-crypto-note > svg {
  flex-shrink: 0;
}

.st-crypto-note > span {
  min-width: 0;
}

.st-crypto-note > a {
  flex-shrink: 0;
  margin-left: auto;
  padding: var(--space-2) 0;
  color: var(--accent-text);
  font-weight: var(--weight-semibold);
  text-decoration: none;
}

.st-crypto-note > a:hover {
  text-decoration: underline;
}

/* ---------- Séparateur de jour, mise en évidence ---------- */

.day-separator {
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.day-separator::before,
.day-separator::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--hairline);
}

.msg-highlight {
  animation: st-msg-flash 1.6s var(--ease-out);
}

@keyframes st-msg-flash {
  0%, 40% { background: var(--mention-bg); }
}

/* ---------- Message : présentation en liste (salons) ---------- */

.chat-msg-row {
  position: relative;
  padding: 6px var(--space-4);
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
}

.chat-msg-row:hover {
  background: var(--hover-row);
}

.chat-msg-row.msg-grouped {
  padding-top: 1px;
}

.msg-avatar-wrap {
  width: 38px;
  flex-shrink: 0;
  display: flex;
  justify-content: center;
}

.msg-avatar,
.msg-author,
.msg-reply-preview,
.msg-media-open,
.shared-post-preview,
.reaction-pill,
.msg-act-btn {
  width: auto;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
  color: inherit;
  font: inherit;
  letter-spacing: 0;
  cursor: pointer;
}

.msg-avatar:hover,
.msg-author:hover,
.msg-reply-preview:hover,
.msg-media-open:hover,
.shared-post-preview:hover,
.reaction-pill:hover,
.msg-act-btn:hover {
  filter: none;
  transform: none;
  box-shadow: none;
}

.msg-avatar {
  border-radius: var(--radius-full);
  display: flex;
}

.msg-avatar > .st-avatar {
  --avatar-size: 38px;
}

/* Messages suivants du même auteur : ni avatar ni nom, l'heure apparaît au survol */
.msg-grouped .msg-avatar,
.msg-grouped .msg-header {
  display: none;
}

.msg-hover-time {
  display: none;
  padding-top: 3px;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--text-muted);
}

.msg-grouped:hover .msg-hover-time,
.msg-grouped.msg-time-active .msg-hover-time {
  display: block;
}

.msg-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.msg-header {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
}

.msg-author {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
}

.msg-author:hover {
  text-decoration: underline;
}

/* Couleur du rôle dans le nexus : une pastille, le nom reste lisible */
.msg-role-dot {
  width: 8px;
  height: 8px;
  align-self: center;
  border-radius: var(--radius-full);
  background: var(--role-color, var(--text-muted));
}

.msg-time {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--text-muted);
}

.msg-content-wrap {
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  overflow-wrap: anywhere;
}

.msg-content-wrap[hidden],
.msg-content-wrap:empty {
  display: none;
}

.msg-emoji-jumbo {
  font-size: 40px;
  line-height: 1.2;
}

.chat-link {
  color: var(--accent-text);
  text-decoration: underline;
}

/* Mentions : ma mention en vert, celle d'un rôle à sa couleur */
.mention {
  padding: 1px 5px;
  border-radius: var(--radius-xs);
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: var(--weight-semibold);
  cursor: pointer;
}

.mention-role {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: inset 3px 0 0 var(--role-color, var(--accent));
}

/* Message qui me mentionne : fond vert pâle sur toute la ligne */
.chat-msg-row:has(.mention-self),
.chat-msg-row:has(.mention-everyone) {
  background: var(--mention-bg);
}

/* Citation d'une réponse */
.msg-reply-preview {
  max-width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-align: left;
}

.reply-preview-author {
  flex-shrink: 0;
  font-weight: var(--weight-semibold);
  color: var(--text);
}

.reply-preview-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-story-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--text-muted);
}

/* Images, vidéos, intégrations */
.media-container {
  position: relative;
  margin-top: var(--space-1);
  width: fit-content;
  max-width: 100%;
}

.msg-media-open {
  display: block;
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: zoom-in;
}

.chat-inline-image {
  display: block;
  max-width: min(320px, 68vw);
  max-height: 300px;
  width: auto;
  height: auto;
  border-radius: var(--radius-md);
}

.media-hover-btn {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--media-scrim);
  color: var(--on-media);
  display: none;
  align-items: center;
  justify-content: center;
}

.media-container:hover .media-hover-btn,
.media-hover-btn:focus-visible {
  display: flex;
}

.msg-embed {
  display: block;
  width: min(420px, 100%);
  aspect-ratio: 16 / 9;
  margin-top: var(--space-2);
  border: 0;
  border-radius: var(--radius-md);
}

/* Publication partagée */
.shared-post-preview {
  max-width: 280px;
  margin-top: var(--space-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  text-align: left;
}

.shared-post-preview-thumb {
  position: relative;
  height: 140px;
  background: var(--media-bg);
  color: var(--on-media);
  display: flex;
  align-items: center;
  justify-content: center;
}

.shared-post-preview-thumb > img,
.shared-post-preview-thumb > video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.shared-post-preview-thumb > svg {
  position: absolute;
}

.shared-post-preview-body {
  padding: 10px var(--space-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: var(--text-sm);
}

.shared-post-preview-label {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--text-muted);
}

.shared-post-preview-author {
  font-weight: var(--weight-semibold);
}

.shared-post-preview-text {
  color: var(--text-muted);
}

/* Appel manqué */
.msg-call {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.msg-call > svg {
  color: var(--danger);
}

.msg-call__text strong {
  color: var(--text);
}

.msg-call__btn {
  min-height: 36px;
}

/* ---------- Réactions ---------- */

.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.msg-reactions:empty {
  display: none;
}

.reaction-pill {
  min-height: 30px;
  padding: 0 var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--surface-2);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--text-md);
  position: relative;
}

/* Zone tactile de 44 px autour de la pastille */
.reaction-pill::after {
  content: "";
  position: absolute;
  inset: -7px -2px;
}

.reaction-pill > span {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.reaction-pill[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--react-on);
}

.reaction-pill[aria-pressed="true"] > span {
  color: var(--accent-text);
}

/* ---------- Barre d'actions au survol (ordinateur) ---------- */

.msg-actions {
  position: absolute;
  top: -18px;
  right: var(--space-4);
  z-index: 2;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-float);
  display: none;
  gap: 2px;
}

.chat-msg-row:hover > .msg-actions,
.msg-actions:focus-within {
  display: flex;
}

.msg-act-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--icon);
  font-size: var(--text-lg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.msg-act-btn:hover {
  background: var(--surface-2);
}

/* Sur écran tactile, pas de survol : l'appui long ouvre le menu du message */
@media (hover: none) {
  /* L'appui long ne doit pas lancer la sélection de texte du navigateur (loupe, menu
     « Copier ») : il ouvre le menu du message, qui propose « Copier le texte ». */
  .chat-msg-row {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }

  .chat-msg-row:hover {
    background: none;
  }

  .chat-msg-row:hover > .msg-actions {
    display: none;
  }
}

/* ---------- Modifier un message ---------- */

.msg-edit-area {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.msg-edit-btns {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
}

.msg-edit-hint {
  flex: 1;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--text-muted);
}

/* ---------- Bulles : messages privés et groupes ---------- */

#mp-chat-box .chat-msg-row {
  padding: 1px var(--space-4);
  gap: var(--space-2);
}

#mp-chat-box .chat-msg-row:hover {
  background: none;
}

#mp-chat-box .msg-pos-first,
#mp-chat-box .msg-pos-isolated {
  padding-top: var(--space-2);
}

#mp-chat-box .msg-avatar-wrap {
  width: var(--avatar-sm);
  align-self: flex-end;
}

#mp-chat-box .msg-avatar > .st-avatar {
  --avatar-size: var(--avatar-sm);
}

/* L'avatar n'apparaît qu'au dernier message d'une série ; la place reste réservée */
#mp-chat-box .msg-avatar {
  visibility: hidden;
}

#mp-chat-box .msg-pos-last .msg-avatar,
#mp-chat-box .msg-pos-isolated .msg-avatar {
  display: flex;
  visibility: visible;
}

#mp-chat-box .msg-hover-time {
  display: none;
}

#mp-chat-box .msg-body {
  flex: 0 1 auto;
  max-width: min(75%, 520px);
  align-items: flex-start;
}

/* Nom au-dessus de la série : seulement dans un groupe, et jamais sur mes messages */
#mp-chat-box .msg-header {
  display: none;
  padding-left: var(--space-3);
}

#mp-chat-box[data-kind="group"] .chat-msg-row:not(.msg-own):is(.msg-pos-first, .msg-pos-isolated) .msg-header {
  display: flex;
}

#mp-chat-box .msg-author {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

#mp-chat-box .msg-content-wrap:not(:empty) {
  padding: 9px 14px;
  border-radius: var(--radius-xl);
  background: var(--bubble-theirs);
}

/* Coins : la série forme un bloc, côté expéditeur */
#mp-chat-box .chat-msg-row:not(.msg-own).msg-pos-first .msg-content-wrap { border-bottom-left-radius: var(--radius-xs); }
#mp-chat-box .chat-msg-row:not(.msg-own).msg-pos-middle .msg-content-wrap { border-top-left-radius: var(--radius-xs); border-bottom-left-radius: var(--radius-xs); }
#mp-chat-box .chat-msg-row:not(.msg-own).msg-pos-last .msg-content-wrap { border-top-left-radius: var(--radius-xs); }

#mp-chat-box .msg-own {
  flex-direction: row-reverse;
}

#mp-chat-box .msg-own .msg-avatar-wrap {
  display: none;
}

#mp-chat-box .msg-own .msg-body {
  align-items: flex-end;
}

#mp-chat-box .msg-own .msg-content-wrap {
  background: var(--bubble-mine);
  color: var(--on-bubble-mine);
}

#mp-chat-box .msg-own.msg-pos-first .msg-content-wrap { border-bottom-right-radius: var(--radius-xs); }
#mp-chat-box .msg-own.msg-pos-middle .msg-content-wrap { border-top-right-radius: var(--radius-xs); border-bottom-right-radius: var(--radius-xs); }
#mp-chat-box .msg-own.msg-pos-last .msg-content-wrap { border-top-right-radius: var(--radius-xs); }

#mp-chat-box .msg-own .chat-link,
#mp-chat-box .msg-own .mention {
  color: inherit;
}

/* Emoji seul : sans bulle */
#mp-chat-box .msg-content-wrap:has(> .msg-emoji-jumbo:only-child) {
  padding: 0;
  background: none;
}

/* Image seule : sans bulle autour */
#mp-chat-box .msg-content-wrap:has(> .media-container:only-child) {
  padding: 0;
  background: none;
}

#mp-chat-box .msg-actions {
  right: auto;
  left: calc(var(--avatar-sm) + var(--space-6));
}

#mp-chat-box .msg-own .msg-actions {
  left: auto;
  right: var(--space-4);
}

/* ---------- Zone de saisie ---------- */

.input-area {
  flex-shrink: 0;
  padding: var(--space-2) var(--space-3) var(--space-3);
  background: var(--bg);
}

/* Barre « Réponse à … » accrochée au-dessus du champ */
.reply-banner {
  margin: 0 var(--space-3);
  padding: var(--space-1) var(--space-1) var(--space-1) var(--space-3);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.reply-banner > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reply-banner strong {
  color: var(--text);
}

.composer-shell {
  display: flex;
  align-items: flex-end;
  gap: var(--space-1);
}

.composer-tool {
  width: var(--tap-min);
  height: var(--tap-min);
  flex-shrink: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-full);
  background: none;
  box-shadow: none;
  color: var(--icon);
  font: inherit;
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.composer-tool:hover {
  background: var(--surface-2);
  filter: none;
  transform: none;
  box-shadow: none;
}

.composer-plus-btn {
  background: var(--surface-2);
}

.composer-tool-gif {
  font-family: var(--font-mono);
}

.composer-field {
  flex: 1;
  min-width: 0;
  min-height: var(--tap-min);
  padding-left: var(--space-4);
  border-radius: 22px;
  background: var(--surface-2);
  display: flex;
  align-items: flex-end;
}

.composer-field:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Le champ grandit jusqu'à 6 lignes, puis défile (hauteur posée par autoResizeChatInput) */
.chat-input {
  flex: 1;
  min-width: 0;
  width: auto;
  max-height: calc(6 * 1.45em + 22px);
  margin: 0;
  padding: 11px 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  outline: none;
  color: var(--text);
  font: inherit;
  font-size: var(--text-base);
  line-height: 1.45;
  resize: none;
}

.chat-input:focus {
  background: transparent;
  box-shadow: none;
}

.chat-input::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

.send-btn {
  background: var(--accent);
  color: var(--on-accent);
}

.send-btn:hover {
  background: var(--accent);
  opacity: 0.9;
}

.btn-voice-msg.recording-pulse {
  background: var(--danger);
  color: var(--on-danger);
  animation: st-pulse 1s ease-in-out infinite;
}

/* Mobile : emoji dans le champ, puis micro (champ vide) ou envoi (champ rempli) */
.composer-tool-gif,
.composer-emoji-desk {
  display: none;
}

.composer-shell:not(.has-text) .send-btn {
  display: none;
}

.composer-shell.has-text .btn-voice-msg {
  display: none;
}

/* Ordinateur : « + », champ, GIF, emoji, envoi */
@media (min-width: 769px) {
  .composer-emoji,
  .btn-voice-msg {
    display: none;
  }

  .composer-tool-gif,
  .composer-emoji-desk,
  .composer-shell:not(.has-text) .send-btn {
    display: flex;
  }

  .composer-shell:not(.has-text) .send-btn {
    background: var(--surface-2);
    color: var(--text-muted);
  }

  .composer-field {
    padding-right: var(--space-4);
  }
}

/* Ancienne zone de saisie du forum (refaite avec l'écran forum) */
.composer-right-tools {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}
