/* CAPIT Mail — WhatsApp-inspired Private Messaging & Calls Stylesheet (Shadow DOM + Standalone) */
:host, .cm-root {
  --cm-bg: #f4f2ee;
  --cm-surface: #ffffff;
  --cm-surface-alt: #f0ece3;
  --cm-chat-bg: #efeae2;
  --cm-border: #dfd8cb;
  --cm-text: #1c1917;
  --cm-muted: #655e57;
  --cm-accent: #653b88;
  --cm-accent-hover: #512d6f;
  --cm-accent-soft: #f2eaf9;
  --cm-bubble-out: #d9fdd3;
  --cm-bubble-out-text: #111b21;
  --cm-bubble-in: #ffffff;
  --cm-bubble-in-text: #111b21;
  --cm-online: #16a34a;
  --cm-offline: #9ca3af;
  --cm-danger: #dc2626;
  --cm-danger-soft: #fef2f2;
  --cm-warn: #d97706;
  --cm-warn-soft: #fffbeb;
  --cm-man: #225d91;
  --cm-woman: #963764;
  --cm-couple: #581278;
  --cm-neutral: #653b88;
  --cm-radius: 14px;
  --cm-font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

}

/* L'élément <capit-mail> lui-même n'impose aucune hauteur : il épouse son contenu. */
:host {
  display: block;
  width: 100%;
}

/* Hauteur : toute la hauteur d'écran disponible sous le widget (--cm-auto-height, calculée
   par le widget à l'affichage et à chaque redimensionnement de la fenêtre). La page hôte
   peut imposer une hauteur avec --cm-height. */
.cm-root {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: var(--cm-height, var(--cm-auto-height, calc(100dvh - 160px)));
  min-height: 420px;
  font-family: var(--cm-font);
  color: var(--cm-text);
  background: var(--cm-bg);
  box-sizing: border-box;
  container-type: inline-size;
  container-name: cm-root;
}

.cm-root[data-theme="dark"] {
  --cm-bg: #111318;
  --cm-surface: #1a1d24;
  --cm-surface-alt: #232730;
  --cm-chat-bg: #14171d;
  --cm-border: #2e3340;
  --cm-text: #f3f4f6;
  --cm-muted: #9ca3af;
  --cm-accent: #9d6fd4;
  --cm-accent-hover: #b388e8;
  --cm-accent-soft: #2b213a;
  --cm-bubble-out: #005c4b;
  --cm-bubble-out-text: #f9fafb;
  --cm-bubble-in: #202c33;
  --cm-bubble-in-text: #f3f4f6;
}

.cm-root *, .cm-root *::before, .cm-root *::after {
  box-sizing: border-box;
}

/* Main 2-column WhatsApp-like Shell */
.cm-shell {
  display: grid;
  grid-template-columns: 350px 1fr;
  grid-template-rows: minmax(0, 1fr);
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  background: var(--cm-surface);
  border: 1px solid var(--cm-border);
  border-radius: var(--cm-radius);
  overflow: hidden;
  position: relative;
}

/* Left Column: Sidebar (Conversations, Authorizations, Likes/Crushs, Blocages) */
.cm-sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--cm-border);
  background: var(--cm-surface);
  height: 100%;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.cm-sidebar-top {
  padding: 10px 10px 9px;
  border-bottom: 1px solid var(--cm-border);
  background: var(--cm-surface);
}

.cm-user-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.cm-user-identity {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.cm-user-name {
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cm-plan-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--cm-accent-soft);
  color: var(--cm-accent);
  white-space: nowrap;
}

/* Search Input */
.cm-search-wrap {
  position: relative;
  margin-bottom: 10px;
}

.cm-search-input {
  width: 100%;
  padding: 8px 12px 8px 32px;
  border: 1px solid var(--cm-border);
  border-radius: 999px;
  background: var(--cm-surface-alt);
  color: var(--cm-text);
  font-size: 0.86rem;
  font-family: inherit;
  outline: none;
}

.cm-search-input:focus {
  border-color: var(--cm-accent);
  background: var(--cm-surface);
}

.cm-search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.82rem;
  color: var(--cm-muted);
  pointer-events: none;
}

/* Primary Navigation Tabs (Icon-only Horizontal Bar with Tooltips) */
.cm-nav-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.cm-nav-tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 7px 6px;
  border-radius: 10px;
  border: 1px solid var(--cm-border);
  background: var(--cm-surface-alt);
  color: var(--cm-muted);
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.cm-nav-tab:hover {
  color: var(--cm-text);
  border-color: var(--cm-accent);
}

.cm-nav-tab.active {
  background: var(--cm-accent);
  border-color: var(--cm-accent);
  color: #fff;
}

.cm-tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--cm-danger);
  color: #fff;
}

.cm-nav-tab.active .cm-tab-badge {
  background: #fff;
  color: var(--cm-accent);
}

/* Folder Filter Sub-bar */
.cm-folder-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-bottom: 1px solid var(--cm-border);
  background: var(--cm-surface-alt);
  overflow-x: auto;
  font-size: 0.78rem;
}

.cm-folder-chip {
  border: 0;
  background: transparent;
  color: var(--cm-muted);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.cm-folder-chip.active {
  background: var(--cm-surface);
  color: var(--cm-accent);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

/* Conversation List */
.cm-conv-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

.cm-conv-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--cm-border);
  cursor: pointer;
  background: var(--cm-surface);
  transition: background 0.12s;
  text-align: left;
  width: 100%;
  border-left: 3px solid transparent;
}

.cm-conv-item:hover {
  background: var(--cm-surface-alt);
}

.cm-conv-item.active {
  background: var(--cm-accent-soft);
  border-left-color: var(--cm-accent);
}

.cm-conv-item.locked {
  opacity: 0.72;
  background: var(--cm-surface-alt);
}

/* Avatar + Presence Dot (Identical to chat-jeanne .avatar) */
.cm-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.cm-avatar {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.95rem;
  color: #653b88;
  background: #e9dfef;
  overflow: hidden;
  flex-shrink: 0;
}

.cm-avatar img.cm-avatar-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.cm-avatar.cm-gender-man {
  background: #e3eef9;
  color: #225d91;
}

.cm-avatar.cm-gender-woman {
  background: #f8e4ee;
  color: #963764;
}

.cm-avatar.cm-gender-couple {
  background: #ede7f6;
  color: #581278;
}

.cm-presence-dot {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--cm-surface);
  background: var(--cm-offline);
}

.cm-presence-dot.online {
  background: var(--cm-online);
}

.cm-conv-body {
  flex: 1;
  min-width: 0;
}

.cm-conv-row1 {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 3px;
}

.cm-conv-name {
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--cm-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cm-conv-name.cm-gender-man,
.cm-peer-title.cm-gender-man {
  color: #225d91;
}

.cm-conv-name.cm-gender-woman,
.cm-peer-title.cm-gender-woman {
  color: #963764;
}

.cm-conv-name.cm-gender-couple,
.cm-peer-title.cm-gender-couple {
  color: #581278;
}

.cm-conv-time {
  font-size: 0.74rem;
  color: var(--cm-muted);
  flex-shrink: 0;
}

.cm-conv-row2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.cm-conv-preview {
  font-size: 0.83rem;
  color: var(--cm-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cm-unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--cm-accent);
  color: #fff;
  font-size: 0.73rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* 10-Conversation Limit Card in Sidebar */
.cm-limit-10-card {
  margin: 12px;
  padding: 14px;
  border-radius: 12px;
  background: var(--cm-warn-soft);
  border: 1px solid #fcd34d;
  color: #78350f;
  font-size: 0.83rem;
}

.cm-limit-10-card strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.88rem;
}

.cm-limit-10-card a {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--cm-accent);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.8rem;
}

/* Right Column: Conversation Panel / Authorizations View */
.cm-main {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  background: var(--cm-chat-bg);
  position: relative;
  /* L'en-tête s'adapte à la largeur du panneau lui-même (pas à celle de la page) */
  container-type: inline-size;
  container-name: cm-main;
}

/* Conversation Header */
.cm-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  background: var(--cm-surface);
  border-bottom: 1px solid var(--cm-border);
  z-index: 5;
}

.cm-chat-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 auto;
}

.cm-back-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--cm-border);
  background: var(--cm-surface-alt);
  color: var(--cm-text);
  cursor: pointer;
  font-size: 1rem;
  flex-shrink: 0;
}

.cm-peer-meta {
  min-width: 0;
  flex: 1 1 auto;
}

.cm-peer-title {
  font-weight: 700;
  font-size: 0.96rem;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cm-peer-subtitle {
  font-size: 0.78rem;
  color: var(--cm-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
}

.cm-peer-subtitle > span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.cm-peer-subtitle > span:first-child {
  flex-shrink: 0;
}

/* Header Action & Call Buttons */
.cm-chat-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.cm-call-btn,
.cm-header-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  border-radius: 9px;
  border: 1px solid var(--cm-border);
  background: var(--cm-surface);
  color: var(--cm-text);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, opacity 0.15s;
}

.cm-call-btn:hover:not(:disabled),
.cm-header-btn:hover:not(:disabled) {
  background: var(--cm-accent-soft);
  border-color: var(--cm-accent);
  color: var(--cm-accent);
}

.cm-call-btn:disabled,
.cm-call-btn[ aria-disabled="true" ] {
  opacity: 0.42;
  cursor: not-allowed;
  background: var(--cm-surface-alt);
  color: var(--cm-muted);
  pointer-events: auto;
}

.cm-report-btn {
  color: var(--cm-danger);
  border-color: rgba(220, 38, 38, 0.28);
}

.cm-report-btn:hover {
  background: var(--cm-danger-soft);
}

/* Messages Stream (Scroll Container) */
.cm-messages-viewport {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: auto;
}

.cm-loading-hourglass {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 100%;
  min-height: 220px;
  color: var(--cm-muted);
  font-size: 0.94rem;
  font-weight: 600;
}

.cm-loading-hourglass-icon {
  font-size: 2.2rem;
  animation: cm-spin-pulse 1.6s ease-in-out infinite;
}

/* Échec de chargement (conversation ou messagerie) : la raison, puis « Réessayer » */
.cm-load-error,
.cm-notice-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: auto;
  padding: 22px 20px;
  max-width: 460px;
  text-align: center;
  color: var(--cm-text);
}

.cm-load-error {
  background: var(--cm-surface);
  border: 1px solid var(--cm-border);
  border-radius: 12px;
}

.cm-load-error-title {
  font-size: 1rem;
  font-weight: 700;
}

.cm-load-error-text {
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--cm-muted);
}

.cm-load-error .cm-banner-actions,
.cm-notice-card .cm-banner-actions {
  justify-content: center;
}

.cm-notice-card {
  max-width: none;
  background: var(--cm-surface);
  border: 1px solid var(--cm-border);
  border-radius: var(--cm-radius);
}

/* Messagerie non chargée (non connecté, service injoignable) : un encart court, pas un grand cadre vide */
.cm-root[data-state="signed-out"],
.cm-root[data-state="error"] {
  height: auto;
  min-height: 0;
  max-height: none;
  background: transparent;
}

/* Séparateur de dates (Aujourd'hui, Hier, lundi 16 novembre) */
.cm-date-sep {
  display: flex;
  justify-content: center;
  margin: 6px 0 2px;
}

.cm-date-sep span {
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--cm-surface);
  border: 1px solid var(--cm-border);
  color: var(--cm-muted);
  font-size: 0.74rem;
  font-weight: 600;
  text-transform: capitalize;
}

/* Message système (par exemple « Autorisation donnée ») : mention centrée, pas une bulle */
.cm-system-row {
  align-self: center;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 90%;
  padding: 5px 14px;
  border-radius: 999px;
  background: var(--cm-accent-soft);
  color: var(--cm-accent);
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
}

.cm-system-time {
  font-weight: 400;
  font-size: 0.72rem;
  opacity: 0.8;
}

/* État d'envoi d'un message */
.cm-msg-row.cm-sending .cm-bubble {
  opacity: 0.72;
}

.cm-msg-row.cm-failed .cm-bubble {
  background: var(--cm-danger-soft);
  border: 1px solid rgba(220, 38, 38, 0.35);
  color: var(--cm-text);
}

.cm-send-state {
  font-size: 0.72rem;
  color: var(--cm-muted);
}

.cm-send-state.cm-send-failed {
  color: var(--cm-danger);
  font-weight: 700;
}

.cm-retry-btn {
  color: var(--cm-danger);
  font-weight: 700;
}

.cm-bubble-body {
  overflow-wrap: anywhere;
}

.cm-list-more {
  display: flex;
  justify-content: center;
  padding: 12px;
  color: var(--cm-muted);
  font-size: 0.84rem;
}

.cm-load-older-state {
  color: var(--cm-muted);
  font-size: 0.82rem;
}

.cm-empty-conversation {
  margin: auto;
  padding: 18px;
  max-width: 420px;
  text-align: center;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--cm-muted);
}

@keyframes cm-spin-pulse {
  0%, 100% { transform: scale(1); opacity: 0.85; }
  50% { transform: scale(1.12); opacity: 1; }
}

.cm-peer-link {
  color: inherit;
  text-decoration: none;
}

.cm-peer-link:hover {
  text-decoration: underline;
}

.cm-load-older-bar {
  display: flex;
  justify-content: center;
  margin-bottom: 8px;
}

.cm-load-older-btn {
  padding: 5px 14px;
  border-radius: 999px;
  border: 1px solid var(--cm-border);
  background: var(--cm-surface);
  color: var(--cm-muted);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

/* Date Separator */
.cm-date-sep {
  align-self: center;
  margin: 8px 0;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--cm-border);
  color: var(--cm-muted);
  font-size: 0.75rem;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.cm-root[data-theme="dark"] .cm-date-sep {
  background: var(--cm-surface-alt);
}

/* Message Bubbles */
.cm-msg-row {
  display: flex;
  flex-direction: column;
  max-width: 78%;
  position: relative;
}

.cm-msg-row.cm-out {
  align-self: flex-end;
}

.cm-msg-row.cm-in {
  align-self: flex-start;
}

.cm-bubble {
  padding: 9px 12px 7px;
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  font-size: 0.92rem;
  line-height: 1.46;
  word-break: break-word;
  position: relative;
}

.cm-out .cm-bubble {
  background: var(--cm-bubble-out);
  color: var(--cm-bubble-out-text);
  border-bottom-right-radius: 4px;
}

.cm-in .cm-bubble {
  background: var(--cm-bubble-in);
  color: var(--cm-bubble-in-text);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--cm-border);
}

/* Quote Block Inside Bubble (Reply or Extracted Legacy Quote) */
.cm-bubble-quote {
  margin-bottom: 7px;
  padding: 6px 10px;
  border-left: 3px solid var(--cm-accent);
  background: rgba(101, 59, 136, 0.08);
  border-radius: 6px;
  font-size: 0.81rem;
  color: var(--cm-muted);
  cursor: pointer;
}

.cm-bubble-quote-author {
  font-weight: 700;
  color: var(--cm-accent);
  font-size: 0.77rem;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cm-bubble-quote-excerpt {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cm-bubble-quote.expanded .cm-bubble-quote-excerpt {
  -webkit-line-clamp: unset;
}

/* Rich Body Content */
.cm-bubble-body p {
  margin: 0 0 6px;
}

.cm-bubble-body p:last-child {
  margin-bottom: 0;
}

.cm-bubble-body a {
  color: var(--cm-accent);
  text-decoration: underline;
}

.cm-bubble-body blockquote {
  margin: 4px 0;
  padding-left: 8px;
  border-left: 2px solid var(--cm-accent);
  color: var(--cm-muted);
}

/* Attachments inside Bubble */
.cm-bubble-media {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cm-bubble-media img {
  max-width: 240px;
  max-height: 200px;
  border-radius: 8px;
  object-fit: cover;
  cursor: pointer;
}

.cm-bubble-media audio {
  max-width: 230px;
  height: 36px;
}

/* Bubble Footer (Timestamp, Channel Badge, Read Status, Reply & Report Actions) */
.cm-bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 4px;
  font-size: 0.71rem;
  color: var(--cm-muted);
}

.cm-read-ticks {
  font-weight: 700;
  letter-spacing: -1px;
}

.cm-read-ticks.read {
  color: var(--cm-accent);
}

.cm-msg-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  /* Affichées au survol, au clavier ou au toucher seulement (plus en permanence sous chaque message). */
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease;
}

.cm-msg-row:hover .cm-msg-actions,
.cm-msg-row:focus-within .cm-msg-actions,
.cm-msg-row.cm-touched .cm-msg-actions {
  opacity: 0.85;
  visibility: visible;
}

@media (hover: none) {
  .cm-msg-row.cm-touched .cm-msg-actions {
    opacity: 1;
  }
}

/* Avis d'une annonce de l'équipe (annonce 3…) : carte d'avis, pas une bulle de membre */
.cm-notice-row {
  align-self: center;
  width: min(92%, 560px);
}

.cm-notice {
  border: 1px solid var(--cm-accent-soft);
  border-left: 4px solid var(--cm-accent);
  background: var(--cm-accent-soft);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.88rem;
}

.cm-notice-title {
  font-weight: 700;
  margin-bottom: 4px;
}

.cm-notice-body a {
  color: var(--cm-accent);
  text-decoration: underline;
}

.cm-notice-time {
  margin-top: 6px;
  font-size: 0.72rem;
  opacity: 0.75;
  text-align: right;
}

.cm-album-link {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.82rem;
  color: inherit;
  text-decoration: underline;
}

.cm-msg-action-btn {
  border: 0;
  background: transparent;
  color: var(--cm-muted);
  font-size: 0.72rem;
  padding: 1px 4px;
  border-radius: 4px;
  cursor: pointer;
}

.cm-msg-action-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--cm-text);
}

/* Floating New Messages Pill (when user is reading older history) */
.cm-new-msg-pill {
  position: sticky;
  bottom: 10px;
  align-self: center;
  z-index: 12;
  padding: 7px 16px;
  border-radius: 999px;
  background: var(--cm-accent);
  color: #fff;
  font-size: 0.81rem;
  font-weight: 700;
  border: 0;
  box-shadow: 0 4px 14px rgba(101, 59, 136, 0.35);
  cursor: pointer;
}

/* State Banners: 24h Restriction, Empty Retention (3 months), Unauthorized Free User, Blocked */
.cm-state-banner {
  margin: 10px 16px;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--cm-surface);
  border: 1px solid var(--cm-border);
  box-shadow: 0 2px 10px rgba(0,0,0,0.04);
  font-size: 0.88rem;
}

.cm-state-banner.cm-banner-24h {
  background: #fdf8ff;
  border-color: var(--cm-accent);
}

.cm-state-banner.cm-banner-blocked {
  background: var(--cm-danger-soft);
  border-color: #fca5a5;
  color: #991b1b;
}

.cm-banner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.cm-cta-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 9px;
  background: var(--cm-accent);
  color: #fff;
  font-size: 0.84rem;
  font-weight: 700;
  text-decoration: none;
  border: 0;
  cursor: pointer;
}

.cm-cta-btn.secondary {
  background: var(--cm-surface-alt);
  color: var(--cm-text);
  border: 1px solid var(--cm-border);
}

/* Discreet 3-month Retention Footer Bar */
.cm-retention-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px 14px;
  background: var(--cm-surface-alt);
  border-top: 1px solid var(--cm-border);
  font-size: 0.76rem;
  color: var(--cm-muted);
}

.cm-retention-notice a {
  color: var(--cm-accent);
  font-weight: 700;
  text-decoration: underline;
}

/* Bottom WYSIWYG Composer (Shared with Forum CAPIT) */
.cm-composer {
  background: var(--cm-surface);
  border-top: 1px solid var(--cm-border);
  padding: 8px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cm-reply-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  background: var(--cm-accent-soft);
  border-left: 3px solid var(--cm-accent);
  border-radius: 6px;
  font-size: 0.8rem;
}

.cm-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

.cm-tool-btn {
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--cm-border);
  background: var(--cm-surface-alt);
  color: var(--cm-text);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.cm-tool-btn:hover {
  background: var(--cm-accent-soft);
  color: var(--cm-accent);
}

.cm-editor-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  /* Place pour l'icône de Jeanne (en bas à droite de la page) : elle ne recouvre plus « Envoyer ». */
  padding-right: 76px;
}

/* Zone de saisie : mêmes dimensions que l'éditeur des forums (108 px, jusqu'à 260 px) */
.cm-editor {
  flex: 1;
  min-width: 0;
  min-height: 108px;
  max-height: 260px;
  overflow-y: auto;
  padding: 11px 14px;
  border: 1px solid var(--cm-border);
  border-radius: 12px;
  background: var(--cm-surface);
  color: var(--cm-text);
  font-size: 1rem;
  line-height: 1.5;
  outline: none;
  overflow-wrap: anywhere;
}

.cm-editor:focus {
  border-color: var(--cm-accent);
}

.cm-editor[data-placeholder]:empty::before {
  content: attr(data-placeholder);
  color: var(--cm-muted);
  pointer-events: none;
}

.cm-send-btn {
  padding: 10px 18px;
  border-radius: 12px;
  border: 0;
  background: var(--cm-accent);
  color: #fff;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  flex-shrink: 0;
}

.cm-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Authorizations View (2 Distinct Sections) */
.cm-auth-view {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--cm-bg);
}

.cm-auth-section {
  background: var(--cm-surface);
  border: 1px solid var(--cm-border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 18px;
}

.cm-auth-section h3 {
  margin: 0 0 12px;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cm-auth-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--cm-border);
  border-radius: 10px;
  margin-bottom: 10px;
  background: var(--cm-surface-alt);
}

.cm-auth-card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.cm-btn-accept {
  padding: 6px 12px;
  border-radius: 8px;
  border: 0;
  background: #16a34a;
  color: #fff;
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
}

.cm-btn-refuse {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--cm-border);
  background: var(--cm-surface);
  color: var(--cm-text);
  font-weight: 600;
  font-size: 0.8rem;
  cursor: pointer;
}

.cm-btn-block {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid #fca5a5;
  background: var(--cm-danger-soft);
  color: var(--cm-danger);
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
}

/* Active Call Modal / Overlay & Report Modal */
.cm-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 19, 24, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 40;
}

.cm-modal {
  background: var(--cm-surface);
  color: var(--cm-text);
  border: 1px solid var(--cm-border);
  border-radius: 16px;
  padding: 22px;
  width: 100%;
  max-width: 460px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}

.cm-call-videos {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 8px;
  margin: 12px 0;
  background: #0f172a;
  border-radius: 12px;
  padding: 10px;
  min-height: 180px;
  align-items: center;
  justify-items: center;
  color: #fff;
}

.cm-call-videos video {
  width: 100%;
  max-height: 220px;
  border-radius: 8px;
  background: #000;
}

/* Widget Signature Footer */
.cm-signature {
  flex: 0 0 auto;
  padding: 5px 12px;
  text-align: right;
  font-size: 0.73rem;
  background: var(--cm-surface);
  border-top: 1px solid var(--cm-border);
}

.cm-signature a {
  color: var(--cm-muted);
  text-decoration: none;
}

.cm-signature a:hover {
  color: var(--cm-accent);
  text-decoration: underline;
}

/* En-tête de conversation dans un panneau étroit (tablette, téléphone) : les boutons gardent
   leur icône et leur infobulle, le libellé disparaît ; le nom du correspondant reste lisible
   et la flèche de retour reste cliquable. */
@container cm-main (max-width: 760px) {
  .cm-chat-header-actions .cm-call-btn span,
  .cm-chat-header-actions .cm-header-btn span {
    display: none;
  }
  .cm-chat-header-actions .cm-call-btn,
  .cm-chat-header-actions .cm-header-btn {
    width: 38px;
    height: 38px;
    padding: 0;
    justify-content: center;
    font-size: 1.02rem;
  }
}

@container cm-main (max-width: 430px) {
  .cm-chat-header {
    padding: 8px 10px;
    gap: 6px;
  }
  .cm-chat-header-left {
    gap: 8px;
  }
  .cm-chat-header-actions {
    gap: 4px;
  }
  /* La photo et le nom ouvrent déjà la fiche : le bouton Profil ferait doublon */
  .cm-chat-header-actions .cm-header-profile-btn {
    display: none;
  }
  .cm-chat-header-actions .cm-call-btn,
  .cm-chat-header-actions .cm-header-btn {
    width: 36px;
    height: 36px;
  }
}

/* Mobile-first Responsive Container Queries (List -> Full-Screen Conversation + Back Button) */
@container cm-root (max-width: 720px) {
  .cm-shell {
    grid-template-columns: 1fr;
  }
  .cm-shell[data-mobile-pane="chat"] .cm-sidebar {
    display: none;
  }
  .cm-shell[data-mobile-pane="list"] .cm-main {
    display: none;
  }
  .cm-back-btn {
    display: inline-flex;
  }
  .cm-msg-row {
    max-width: 88%;
  }
  .cm-editor {
    min-height: 84px;
    max-height: 200px;
  }
}

@media (max-width: 720px) {
  .cm-shell {
    grid-template-columns: 1fr;
  }
  .cm-shell[data-mobile-pane="chat"] .cm-sidebar {
    display: none;
  }
  .cm-shell[data-mobile-pane="list"] .cm-main {
    display: none;
  }
  .cm-back-btn {
    display: inline-flex;
  }
}

/* Affichage compact « une seule conversation » (mode="conversation") : client du chat privé.
   Pas de liste ni d'onglets ; la hauteur est celle que donne la page hôte (au moins 320 px). */
.cm-shell.cm-compact {
  grid-template-columns: 1fr;
  height: var(--cm-height, 100%);
  min-height: 320px;
}
.cm-shell.cm-compact .cm-back-btn {
  display: none;
}
.cm-shell.cm-compact .cm-header-btn span {
  display: none;
}
.cm-typing {
  font-style: italic;
}
