/* Messagerie client (views/app/partials/messenger.ejs), refaite de zéro le 18/11/2026.
   Téléphone : plein écran. Ordinateur (≥ 768 px) : panneau de 420 px à droite. Clair et sombre, cibles de 44 px,
   mouvement réduit respecté. Jetons propres (la fenêtre s'ouvre aussi sur des pages qui ne chargent pas app.css). */
#udc-msg {
  --m-bg: #F7F7F5; --m-surface: #FFFFFF; --m-s2: #F1F1EE; --m-border: #E3E3DE;
  --m-text: #121211; --m-muted: #62625E; --m-brand: #D81B60; --m-brand-ink: #B0124D; --m-brand-soft: #FCE9F0;
  --m-mine: #D81B60; --m-mine-text: #FFFFFF; --m-theirs: #FFFFFF; --m-err: #B42318; --m-focus: #0F62FE;
  --m-sh: 0 1px 2px rgba(0,0,0,.06), 0 1px 1px rgba(0,0,0,.04);
  position: fixed; inset: 0; z-index: 2000; font: 400 15px/1.45 'Inter', system-ui, -apple-system, sans-serif; color: var(--m-text);
}
[data-theme="dark"] #udc-msg {
  --m-bg: #111110; --m-surface: #1C1C1A; --m-s2: #262623; --m-border: #393934;
  --m-text: #F5F5F2; --m-muted: #B4B4AE; --m-brand: #FF5C93; --m-brand-ink: #FF8AB2; --m-brand-soft: #34172A;
  --m-mine: #C2185B; --m-mine-text: #FFFFFF; --m-theirs: #232320; --m-err: #FF8A80; --m-focus: #7AB2FF;
  --m-sh: 0 1px 2px rgba(0,0,0,.4);
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) #udc-msg {
    --m-bg: #111110; --m-surface: #1C1C1A; --m-s2: #262623; --m-border: #393934;
    --m-text: #F5F5F2; --m-muted: #B4B4AE; --m-brand: #FF5C93; --m-brand-ink: #FF8AB2; --m-brand-soft: #34172A;
    --m-mine: #C2185B; --m-mine-text: #FFFFFF; --m-theirs: #232320; --m-err: #FF8A80; --m-focus: #7AB2FF;
    --m-sh: 0 1px 2px rgba(0,0,0,.4);
  }
}
#udc-msg[hidden], #udc-msg [hidden] { display: none !important; }
#udc-msg *, #udc-msg *::before, #udc-msg *::after { box-sizing: border-box; }
/* :where() = spécificité nulle : les classes (bouton principal, action « danger ») gardent leur couleur. */
:where(#udc-msg) :where(button, input, textarea) { font: inherit; color: inherit; }
:where(#udc-msg) button { cursor: pointer; }
#udc-msg :focus-visible { outline: 2px solid var(--m-focus); outline-offset: 2px; }
#udc-msg svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
body.udc-msg-open { overflow: hidden; }

.udc-msg__scrim { position: absolute; inset: 0; background: rgba(10,10,10,.42); }
.udc-msg__panel { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--m-bg); overflow: hidden; }
@media (min-width: 768px) {
  .udc-msg__panel { left: auto; width: 420px; border-left: 1px solid var(--m-border); box-shadow: -12px 0 40px rgba(0,0,0,.18); }
}
@media (prefers-reduced-motion: no-preference) {
  #udc-msg:not([hidden]) .udc-msg__panel { animation: udcMsgIn 200ms cubic-bezier(0,0,.2,1); }
  @keyframes udcMsgIn { from { transform: translateY(12px); opacity: .6; } to { transform: none; opacity: 1; } }
}
.udc-msg__view { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.udc-msg__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* En-tête */
.udc-msg__head { display: flex; align-items: center; gap: 8px; padding: max(10px, env(safe-area-inset-top)) 8px 10px 16px; background: var(--m-surface); border-bottom: 1px solid var(--m-border); }
.udc-msg__head h2 { flex: 1; margin: 0; font-size: 22px; line-height: 1.2; font-weight: 700; letter-spacing: -.01em; }
.udc-msg__head--thread { padding-left: 4px; gap: 10px; }
.udc-msg__icon { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; color: var(--m-text); }
.udc-msg__icon:hover { background: var(--m-s2); }
.udc-msg__icon--soft { background: var(--m-s2); }

/* Onglets */
.udc-msg__tabs { display: flex; gap: 4px; padding: 8px 12px 0; background: var(--m-surface); border-bottom: 1px solid var(--m-border); }
.udc-msg__tab { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; border: 0; border-bottom: 3px solid transparent; background: none; font-weight: 600; color: var(--m-muted); }
.udc-msg__tab[aria-selected="true"] { color: var(--m-brand-ink); border-bottom-color: var(--m-brand); }
.udc-msg__count, .udc-msg__badge { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; background: var(--m-brand); color: #fff; font-size: 12px; font-weight: 700; }

.udc-msg__body { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 12px calc(20px + env(safe-area-inset-bottom)); overscroll-behavior: contain; }
.udc-msg__search { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 14px; margin-bottom: 12px; border-radius: 999px; background: var(--m-s2); color: var(--m-muted); }
.udc-msg__search input { flex: 1; min-width: 0; height: 100%; border: 0; background: transparent; outline: none; color: var(--m-text); font-size: 16px; }
.udc-msg__label { margin: 16px 4px 6px; font-size: 13px; font-weight: 700; color: var(--m-muted); }
.udc-msg__muted { color: var(--m-muted); font-size: 14px; }
.udc-msg__help { margin: 6px 4px 8px; font-size: 13px; color: var(--m-muted); }
.udc-msg__field { display: block; margin: 16px 4px 6px; font-size: 14px; font-weight: 600; }

/* Lignes (discussion, contact, support) */
.udc-msg__list { list-style: none; margin: 0; padding: 0; }
.udc-msg__row, .udc-msg__support { position: relative; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 64px; padding: 10px 12px; border: 0; border-radius: 14px; background: transparent; text-align: left; -webkit-touch-callout: none; user-select: none; }
.udc-msg__row:hover, .udc-msg__row:focus-visible { background: var(--m-surface); }
.udc-msg__support { background: var(--m-surface); border: 1px solid var(--m-border); box-shadow: var(--m-sh); }
.udc-msg__rowtext { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.udc-msg__rowtext b { font-size: 15px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.udc-msg__rowtext span { font-size: 13.5px; color: var(--m-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.udc-msg__row.is-unread .udc-msg__rowtext b, .udc-msg__row.is-unread .udc-msg__rowtext span { color: var(--m-text); font-weight: 700; }
.udc-msg__side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; font-size: 12px; color: var(--m-muted); }
.udc-msg__pin { width: 14px !important; height: 14px !important; color: var(--m-muted); }
.udc-msg__avatar { width: 44px; height: 44px; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; overflow: hidden; background: var(--m-brand-soft); color: var(--m-brand-ink); font-weight: 700; font-size: 17px; }
.udc-msg__avatar { position: relative; }
.udc-msg__avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.udc-msg__avatar--brand { background: var(--m-brand); color: #fff; }
.udc-msg__head .udc-msg__avatar { width: 40px; height: 40px; font-size: 16px; }

.udc-msg__me { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-radius: 14px; background: var(--m-brand-soft); }
.udc-msg__me .udc-msg__rowtext b { font-size: 17px; color: var(--m-brand-ink); }
.udc-msg__addrow input { width: 100%; height: 48px; padding: 0 14px; border: 1px solid var(--m-border); border-radius: 12px; background: var(--m-surface); font-size: 16px; }
.udc-msg__btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border: 1px solid var(--m-border); border-radius: 999px; background: var(--m-surface); font-weight: 600; white-space: nowrap; }
.udc-msg__btn--primary { background: var(--m-brand); border-color: var(--m-brand); color: #fff; }

.udc-msg__empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 28px 16px; text-align: center; }
.udc-msg__empty span { color: var(--m-muted); font-size: 14px; max-width: 30ch; }
.udc-msg__emptyicon { display: inline-flex; align-items: center; justify-content: center; width: 64px; height: 64px; border-radius: 50%; background: linear-gradient(135deg, #E91E63, #FF7A45); color: #fff !important; margin-bottom: 4px; }
.udc-msg__emptyicon svg { width: 30px; height: 30px; }

/* Fil — inspiré des messageries courantes (Messenger) : bulles groupées par personne, photo sur la dernière bulle,
   réponses citées au-dessus de la bulle, présentation de la personne en haut, bouton « ↓ ». */
.udc-msg__flowwrap { position: relative; flex: 1; min-height: 0; display: flex; }
.udc-msg__flow { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 10px 14px; display: flex; flex-direction: column; overscroll-behavior: contain; }
.udc-msg__flow > * { flex-shrink: 0; } /* un fil long ne doit jamais écraser les repères (pastilles à 10 px vues en production) */
.udc-msg__intro { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 18px 16px 10px; text-align: center; }
.udc-msg__intro b { font-size: 19px; font-weight: 700; }
.udc-msg__intro span:not(.udc-msg__avatar):not(.udc-msg__ini) { max-width: 34ch; color: var(--m-muted); font-size: 13px; }
.udc-msg__avatar--xl { width: 84px !important; height: 84px !important; font-size: 32px !important; margin-bottom: 4px; }
.udc-msg__avatar--xl svg { width: 38px; height: 38px; }
.udc-msg__first { text-align: center; padding: 6px 12px 16px; }
.udc-msg__day { align-self: center; margin: 14px 0 8px; color: var(--m-muted); font-size: 12px; font-weight: 600; letter-spacing: .02em; }
.udc-msg__topic { align-self: center; max-width: 92%; margin: 8px 0 6px; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--m-border); color: var(--m-muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.udc-msg__msg { display: flex; align-items: flex-end; gap: 8px; width: 100%; margin-top: 8px; }
.udc-msg__msg.has-prev { margin-top: 2px; }
.udc-msg__msg.is-mine { justify-content: flex-end; }
.udc-msg__col { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; max-width: min(78%, 520px); }
.udc-msg__msg.is-mine .udc-msg__col { align-items: flex-end; }
.udc-msg__mini { width: 28px; height: 28px; flex: none; display: inline-flex; align-items: center; justify-content: center; position: relative; overflow: hidden; border-radius: 50%; background: var(--m-brand-soft); color: var(--m-brand-ink); font-size: 12px; font-weight: 700; }
.udc-msg__mini svg { width: 16px; height: 16px; }
.udc-msg__mini img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.udc-msg__msg.has-next .udc-msg__mini { visibility: hidden; }
.udc-msg__bubble { position: relative; max-width: 100%; padding: 8px 13px 6px; border-radius: 20px; background: var(--m-s2); color: var(--m-text); overflow-wrap: break-word; word-break: normal; white-space: pre-wrap; -webkit-touch-callout: none; user-select: text; transition: transform 120ms ease-out; }
.udc-msg__msg.is-mine .udc-msg__bubble { background: var(--m-mine); color: var(--m-mine-text); }
/* Coins : à plat du côté de la personne entre deux bulles d'un même groupe. */
.udc-msg__msg.is-mine.has-next .udc-msg__bubble { border-bottom-right-radius: 6px; }
.udc-msg__msg.is-mine.has-prev .udc-msg__bubble { border-top-right-radius: 6px; }
.udc-msg__msg:not(.is-mine).has-next .udc-msg__bubble { border-bottom-left-radius: 6px; }
.udc-msg__msg:not(.is-mine).has-prev .udc-msg__bubble { border-top-left-radius: 6px; }
.udc-msg__bubble.is-media { padding: 0; background: transparent !important; overflow: hidden; }
.udc-msg__bubble.is-media .udc-msg__time { position: absolute; right: 8px; bottom: 8px; padding: 2px 6px; border-radius: 8px; background: rgba(0,0,0,.5); color: #fff; opacity: 1; }
.udc-msg__msg.is-flash .udc-msg__bubble { box-shadow: 0 0 0 3px var(--m-focus); }
.udc-msg__who { display: block; margin: 0 0 2px 12px; font-size: 12px; font-weight: 600; color: var(--m-muted); white-space: normal; }
.udc-msg__time { display: block; margin-top: 1px; text-align: right; font-size: 11px; opacity: .72; white-space: nowrap; }
.udc-msg__bubble a { color: inherit; text-decoration: underline; }
.udc-msg__quote { display: flex; flex-direction: column; align-items: inherit; gap: 2px; max-width: 100%; margin: 4px 0 -10px; padding: 0; border: 0; background: none; text-align: inherit; }
.udc-msg__quotelabel { display: inline-flex; align-items: center; gap: 4px; padding: 0 8px; font-size: 12px; color: var(--m-muted); }
.udc-msg__quotelabel svg { width: 14px !important; height: 14px !important; }
.udc-msg__quotetext { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 100%; padding: 8px 13px 16px; border-radius: 18px; background: var(--m-s2); color: var(--m-muted); font-size: 14px; opacity: .85; white-space: normal; }
.udc-msg__msg.is-mine .udc-msg__quotetext { border: 1px solid var(--m-border); background: var(--m-surface); }
.udc-msg__img { display: block; max-width: 100%; width: 240px; max-height: 320px; object-fit: cover; border-radius: 18px; background: var(--m-s2); }
.udc-msg__video { display: block; width: 240px; max-width: 100%; border-radius: 18px; background: #000; }
.udc-msg__file { display: flex; align-items: center; gap: 10px; min-width: 200px; white-space: normal; }
.udc-msg__file b { display: block; font-size: 14px; overflow-wrap: anywhere; }
.udc-msg__fileacts { display: flex; gap: 6px; margin-top: 6px; }
.udc-msg__fileacts a { display: inline-flex; align-items: center; min-height: 36px; padding: 0 12px; border-radius: 999px; background: rgba(127,127,127,.18); color: inherit !important; text-decoration: none !important; font-size: 13px; font-weight: 600; }
.udc-msg__audio { display: flex; align-items: center; gap: 10px; width: 230px; max-width: 100%; white-space: normal; }
.udc-msg__play { width: 44px; height: 44px; flex: none; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 50%; background: var(--m-brand); color: #fff; }
.udc-msg__msg.is-mine .udc-msg__play { background: #fff; color: var(--m-mine); }
.udc-msg__bar { flex: 1; height: 4px; border-radius: 4px; background: rgba(127,127,127,.35); overflow: hidden; }
.udc-msg__bar i { display: block; height: 100%; width: 0; background: currentColor; }
.udc-msg__dur { font-size: 12px; font-variant-numeric: tabular-nums; min-width: 34px; }
.udc-msg__pending { opacity: .6; }
.udc-msg__jump { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--m-border); border-radius: 50%; background: var(--m-surface); color: var(--m-text); box-shadow: 0 4px 14px rgba(0,0,0,.18); }
.udc-msg__back { position: relative; width: auto !important; min-width: 44px; padding: 0 6px; border-radius: 22px !important; gap: 2px; color: var(--m-brand-ink) !important; }
.udc-msg__backcount { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; background: var(--m-brand); color: #fff; font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.udc-msg__replybar { display: flex; align-items: center; gap: 8px; padding: 8px 6px 8px 16px; background: var(--m-surface); border-top: 1px solid var(--m-border); }
.udc-msg__replybar .udc-msg__rowtext b { font-size: 13px; }

/* Zone d'écriture */
.udc-msg__hint { padding: 8px 16px; font-size: 13px; color: var(--m-muted); background: var(--m-surface); border-top: 1px solid var(--m-border); }
.udc-msg__composer, .udc-msg__rec { display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: var(--m-surface); border-top: 1px solid var(--m-border); }
.udc-msg__rec { align-items: center; }
.udc-msg__composer { gap: 2px; }
.udc-msg__tools { display: flex; }
.udc-msg__tool { width: 44px; height: 44px; flex: none; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 50%; background: transparent; color: var(--m-brand); }
.udc-msg__tool:disabled { opacity: .4; cursor: not-allowed; }
.udc-msg__tool:hover { background: var(--m-brand-soft); }
.udc-msg__composer textarea { flex: 1; min-width: 0; min-height: 44px; max-height: 140px; margin: 0 4px; padding: 11px 16px; border: 0; border-radius: 22px; background: var(--m-s2); resize: none; font-size: 16px; line-height: 1.35; outline: none; }
.udc-msg__composer textarea:focus-visible { box-shadow: 0 0 0 2px var(--m-focus); }
.udc-msg__send:disabled { background: transparent; color: var(--m-muted); opacity: 1 !important; }
.udc-msg__send { width: 44px; height: 44px; flex: none; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 50%; background: var(--m-brand); color: #fff; }
.udc-msg__send:disabled, .udc-msg__icon:disabled { opacity: .45; cursor: not-allowed; }
.udc-msg__recdot { width: 10px; height: 10px; border-radius: 50%; background: #E5484D; }
@media (prefers-reduced-motion: no-preference) { .udc-msg__recdot { animation: udcMsgBlink 1s infinite; } @keyframes udcMsgBlink { 50% { opacity: .25; } } }
.udc-msg__rectime { font-variant-numeric: tabular-nums; font-weight: 700; }
.udc-msg__rec .udc-msg__muted { flex: 1; }

/* Feuille d'actions */
.udc-msg__sheet { position: absolute; inset: 0; z-index: 5; display: flex; align-items: flex-end; }
.udc-msg__sheetscrim { position: absolute; inset: 0; background: rgba(10,10,10,.38); }
.udc-msg__sheetbox { position: relative; width: 100%; max-height: 80%; overflow-y: auto; padding: 8px 12px calc(12px + env(safe-area-inset-bottom)); border-radius: 20px 20px 0 0; background: var(--m-surface); box-shadow: 0 -8px 30px rgba(0,0,0,.18); }
@media (prefers-reduced-motion: no-preference) { .udc-msg__sheet:not([hidden]) .udc-msg__sheetbox { animation: udcMsgUp 180ms cubic-bezier(0,0,.2,1); } @keyframes udcMsgUp { from { transform: translateY(30px); } to { transform: none; } } }
.udc-msg__grab { display: block; width: 40px; height: 4px; margin: 2px auto 8px; border-radius: 4px; background: var(--m-border); }
.udc-msg__sheettitle { margin: 0 4px 6px; font-size: 13px; color: var(--m-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.udc-msg__sheetitem { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 52px; padding: 0 12px; border: 0; border-radius: 12px; background: transparent; font-size: 16px; text-align: left; }
.udc-msg__sheetitem:hover { background: var(--m-s2); }
.udc-msg__sheetitem--danger { color: var(--m-err); }
.udc-msg__sheetitem--cancel { justify-content: center; margin-top: 6px; background: var(--m-s2); font-weight: 600; }

.udc-msg__toast { position: absolute; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 6; transform: translateX(-50%); max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px; background: #1E1E1C; color: #fff; font-size: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.3); }
.udc-msg__toast.is-error { background: #8F1D1D; }

/* Personnel : liste des clients */
.udc-msg__chips { display: flex; gap: 6px; margin: -4px 0 8px; overflow-x: auto; }
.udc-msg__chip { min-height: 36px; padding: 0 14px; border: 1px solid var(--m-border); border-radius: 999px; background: var(--m-surface); font-size: 13px; font-weight: 600; white-space: nowrap; position: relative; }
.udc-msg__chip::after { content: ''; position: absolute; inset: -4px 0; } /* zone de toucher portée à 44 px */
.udc-msg__chip[aria-pressed="true"] { background: var(--m-text); border-color: var(--m-text); color: var(--m-bg); }
.udc-msg__tags { display: flex !important; flex-wrap: wrap; gap: 4px; margin-top: 3px; overflow: visible !important; white-space: normal !important; }
.udc-msg__tag { display: inline-flex; padding: 1px 8px; border-radius: 999px; background: var(--m-s2); color: var(--m-muted) !important; font-size: 11px !important; font-weight: 600; }
.udc-msg__tag--ok { background: #E6F4EC; color: #17633E !important; }
.udc-msg__tag--warn { background: #FEF3E0; color: #8A4B00 !important; }
[data-theme="dark"] #udc-msg .udc-msg__tag--ok { background: #12301F; color: #6EE7A0 !important; }
[data-theme="dark"] #udc-msg .udc-msg__tag--warn { background: #33230A; color: #FCC66B !important; }
.udc-msg__legacy { display: inline-flex; align-items: center; min-height: 44px; margin: 8px 4px; color: var(--m-brand-ink) !important; font-weight: 600; }

/* Champ « Aa » avec bouton émoji intégré (comme Messenger) ; grille d'émojis au-dessus de la zone d'écriture. */
.udc-msg__field2 { position: relative; flex: 1; min-width: 0; display: flex; }
.udc-msg__field2 textarea { padding-right: 46px !important; }
.udc-msg__emoji { position: absolute; right: 4px; bottom: 0; width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 50%; background: transparent; color: var(--m-brand); }
.udc-msg__emojis { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; padding: 8px; background: var(--m-surface); border-top: 1px solid var(--m-border); }
.udc-msg__emo { height: 44px; border: 0; border-radius: 10px; background: transparent; font-size: 24px; line-height: 1; }
.udc-msg__emo:hover { background: var(--m-s2); }
