/* ============================================================================
   (V291) CHATS FACON MESSAGERIE — bulles groupées, séparateurs de jour, outils discrets,
   composeur arrondi. Chargé après styles.css : à spécificité égale, ces règles l'emportent.
   ============================================================================ */
:root{
  --chat-fond:#f4ecdc;
  --chat-moi:#1f6f8b;
  --chat-moi-texte:#ffffff;
  --chat-eux:#ffffff;
  --chat-eux-texte:#241c10;
  --chat-meta:rgba(36,28,16,.55);
}

/* Le fil */
#chat-messages,
.modern-chat-messages{
  display:flex;flex-direction:column;gap:2px;
  background:var(--chat-fond);
  background-image:radial-gradient(rgba(120,90,40,.07) 1px,transparent 1px);
  background-size:18px 18px;
  scroll-behavior:smooth;
}
#chat-messages{max-height:min(46vh,360px);padding:8px 6px;border-radius:12px}
.modern-chat-messages{padding:12px 12px 8px}

/* Séparateur de jour */
.chat-jour{display:flex;justify-content:center;margin:12px 0 6px}
.chat-jour span{
  background:rgba(255,255,255,.92);color:#5f5345;font-size:12px;font-weight:700;
  padding:4px 12px;border-radius:999px;box-shadow:0 1px 2px rgba(36,28,16,.12);text-transform:none
}

/* Une ligne de message */
.chat-msg-row{display:flex;align-items:flex-end;gap:6px;max-width:86%;margin-top:1px}
.chat-msg-row.chat-debut{margin-top:8px}
.chat-msg-row.is-mine{align-self:flex-end;flex-direction:row-reverse}
.chat-msg-row.is-theirs{align-self:flex-start}
.chat-msg-row.is-mine .chat-msg-avatar{display:none}
.chat-msg-avatar{width:30px;height:30px;min-width:30px;border-radius:50%;font-size:12px;background:#4b89a6;color:#fff;font-weight:800}
.chat-msg-row:not(.chat-fin) .chat-msg-avatar{background:transparent}
.chat-msg-bundle{min-width:0;display:flex;flex-direction:column;gap:2px}
.chat-msg-ligne{display:flex;align-items:center;gap:4px;min-width:0}
.chat-msg-row.is-mine .chat-msg-ligne{flex-direction:row-reverse}
.chat-name{font-size:12px;font-weight:800;color:#7a5225;margin:0 0 2px 12px}

/* Les bulles */
.chat-msg{
  position:relative;min-width:56px;max-width:100%;padding:8px 12px 6px;
  border-radius:20px;line-height:1.38;font-size:15px;word-break:break-word;overflow-wrap:anywhere;
  box-shadow:0 1px 1.5px rgba(36,28,16,.16);border:0;outline-offset:2px
}
.chat-msg::after{display:none}
.chat-msg.mine{background:var(--chat-moi);color:var(--chat-moi-texte)}
.chat-msg.theirs{background:var(--chat-eux);color:var(--chat-eux-texte);border:0}
/* Coins resserrés côté auteur, comme dans les messageries : groupe de bulles « collées ». */
.chat-msg-row.is-mine .chat-msg{border-top-right-radius:6px;border-bottom-right-radius:6px}
.chat-msg-row.is-mine.chat-debut .chat-msg{border-top-right-radius:20px}
.chat-msg-row.is-mine.chat-fin .chat-msg{border-bottom-right-radius:20px}
.chat-msg-row.is-theirs .chat-msg{border-top-left-radius:6px;border-bottom-left-radius:6px}
.chat-msg-row.is-theirs.chat-debut .chat-msg{border-top-left-radius:20px}
.chat-msg-row.is-theirs.chat-fin .chat-msg{border-bottom-left-radius:20px}
.chat-msg-row.is-mine.chat-fin .chat-msg{border-bottom-right-radius:4px}
.chat-msg-row.is-theirs.chat-fin .chat-msg{border-bottom-left-radius:4px}

.chat-texte{white-space:pre-wrap}
.chat-msg-meta{
  display:inline-flex;align-items:center;gap:5px;float:right;margin:6px 0 -2px 10px;
  font-size:11px;line-height:1;white-space:nowrap;opacity:1;color:var(--chat-meta)
}
.chat-msg.mine .chat-msg-meta{color:rgba(255,255,255,.82)}
.chat-modifie{font-style:italic}
/* (V378) Message supprimé par son auteur : place conservée, texte de remplacement discret. */
.chat-supprime{font-style:italic;opacity:.72}
.chat-readers{background:none;border:0;padding:0;margin:0;font:inherit;color:inherit;cursor:pointer;box-shadow:none;min-height:0}
.chat-msg.mine .chat-readers{color:#bfe9ff;font-weight:800}
.chat-envoye{font-weight:800}

/* Citation dans une bulle */
.chat-cite{display:block;margin:0 0 6px;padding:6px 9px;border-radius:10px;border-left:4px solid #c98a1d;background:rgba(36,28,16,.06);font-size:13px}
.chat-msg.mine .chat-cite{border-left-color:#fff;background:rgba(255,255,255,.18);color:rgba(255,255,255,.95)}
.chat-cite__nom{display:block;font-size:12px}

/* Outils : discrets, révélés au survol, au clavier ou d'un toucher sur la bulle */
.chat-msg-outils{display:flex;gap:2px;opacity:0;pointer-events:none;transition:opacity .15s}
.chat-msg-row:hover .chat-msg-outils,
.chat-msg-row:focus-within .chat-msg-outils,
.chat-msg-row.chat-outils-visibles .chat-msg-outils{opacity:1;pointer-events:auto}
.chat-msg-outils .chat-react-btn{width:30px;height:30px;min-width:30px;font-size:14px;opacity:.9;background:#fff;box-shadow:0 1px 3px rgba(0,0,0,.12)}
@media (hover:none){
  /* Sur écran tactile, seul le « ⋮ » reste visible, très discret ; l'appui long ouvre aussi le menu. */
  .chat-msg-outils{opacity:1;pointer-events:auto}
  .chat-msg-outils .chat-react-btn:not(.chat-msg-actions){display:none}
  .chat-msg-outils .chat-msg-actions{width:24px;min-width:24px;height:24px;background:transparent;box-shadow:none;border:0;opacity:.55}
  .chat-msg-row.chat-outils-visibles .chat-msg-outils .chat-react-btn{display:inline-flex}
}

/* Réactions */
.chat-reaction-bar{margin:-6px 8px 2px;position:relative;z-index:1}
.chat-msg-row.is-mine .chat-reaction-bar{justify-content:flex-end}
.chat-reaction-chip{background:#fff;border:1px solid rgba(82,65,43,.14);box-shadow:0 1px 2px rgba(0,0,0,.1)}

/* « Nouveaux messages » quand on lit plus haut */
.chat-nouveaux{
  position:sticky;bottom:8px;align-self:center;margin:-44px auto 8px;z-index:3;
  background:var(--chat-moi);color:#fff;border:0;border-radius:999px;padding:8px 16px;
  font-weight:800;font-size:13px;box-shadow:0 4px 12px rgba(0,0,0,.2);cursor:pointer;display:block
}

/* Composeur */
.chat-composeur{display:flex !important;align-items:flex-end;gap:8px;padding:8px 10px;background:#fffdf8}
.modern-chat-compose.chat-composeur{display:flex !important;grid-template-columns:none}
.chat-composeur .chat-ta261{
  flex:1 1 auto;min-width:0;min-height:44px;max-height:160px;resize:none;
  border-radius:22px;padding:11px 16px;border:1px solid #d9c9a6;background:#fff;
  font-size:16px;line-height:1.35
}
.chat-composeur .chat-ta261:focus{border-color:var(--chat-moi);box-shadow:0 0 0 3px rgba(31,111,139,.15);outline:none}
.chat-btn-rond{flex:0 0 44px !important;width:44px;height:44px;min-height:44px;border-radius:50% !important;padding:0 !important;font-size:20px;display:inline-flex;align-items:center;justify-content:center}
.chat-btn-envoi{
  flex:0 0 44px !important;width:44px;height:44px;min-height:44px;border-radius:50% !important;padding:0 !important;
  display:inline-flex;align-items:center;justify-content:center;background:var(--chat-moi) !important;color:#fff !important;border:0 !important;
  box-shadow:0 2px 6px rgba(31,111,139,.35) !important
}
.chat-btn-envoi svg{width:22px;height:22px;fill:currentColor}
.chat-btn-envoi .chat-envoi-txt{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.modern-chat-compose #tchat-send{grid-column:auto;width:44px}
.chat-compteur{font-size:12px;color:#8a5a14;text-align:right;padding:0 14px 4px}
.chat-compteur.limite{color:#a32d1c;font-weight:800}

/* Fenêtre de salon : en-tête plus net */
.modern-chat-header{background:#fffdf8}
.modern-chat-header h3{font-size:17px !important}

/* Chat latéral (grand écran) */
.side-chat-messages{font-size:13px}

/* Confort visuel : contraste renforcé */
html[data-a11y-contrast="on"] .chat-msg.theirs{background:#fff !important;color:#000 !important;border:2px solid #000 !important}
html[data-a11y-contrast="on"] .chat-msg.mine{background:#0b3d52 !important;color:#fff !important}
html[data-a11y-size="large"] .chat-msg{font-size:17px}
html[data-a11y-size="xlarge"] .chat-msg{font-size:19px}

@media (max-width:600px){
  .chat-msg-row{max-width:92%}
  .modern-chat-compose.chat-composeur{padding:8px}
}

/* ============================================================================
   (V310) États d'envoi, messages précédents, repère « Nouveaux messages »
   ============================================================================ */
.chat-attente{font-size:11px;line-height:1}
.chat-msg-row.chat-en-attente .chat-msg{opacity:.85}
/* Envoi refusé : la bulle reste, avec « Réessayer » et « Supprimer ». */
.chat-msg-echec{background:#fdecea !important;color:#7a1f14 !important;border:1px solid #f1b8ae}
.chat-msg-echec .chat-msg-meta{color:#a02818}
.chat-echec-actions{display:flex;align-items:center;justify-content:flex-end;flex-wrap:wrap;gap:6px;margin:3px 6px 6px;font-size:12px;color:#a02818;font-weight:700}
.chat-echec-btn{background:none;border:1px solid #e3a297;border-radius:999px;padding:4px 12px;min-height:32px;font:inherit;font-weight:800;color:#a02818;cursor:pointer;box-shadow:none}
.chat-echec-btn:hover,.chat-echec-btn:focus-visible{background:#fff4f2}
/* Bouton de chargement des messages précédents, en tête de conversation. */
.chat-plus-anciens{display:flex;justify-content:center;margin:4px 0 10px}
.chat-plus-btn{border-radius:999px;padding:6px 16px;min-height:36px;font-size:13px;font-weight:800}
/* Repère : où le joueur s'était arrêté de lire. */
.chat-repere-nouveaux{display:flex;align-items:center;gap:10px;margin:10px 4px;color:#a0521d;font-size:12px;font-weight:800;text-transform:uppercase;letter-spacing:.04em}
.chat-repere-nouveaux::before,.chat-repere-nouveaux::after{content:"";flex:1 1 auto;height:1px;background:#e2b48a}
