/* Messagerie interne : icône à côté de la cloche, panneau des derniers messages, barre de contacts en bas de page, fenêtres de discussion.
   Sobre : traits fins, couleurs du thème (clair / sombre) ; aucune image. Voir public/js/messagerie.js. */

/* --- icônes (mêmes réglages que icons.css) --- */
.ic-msg { --ic: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22black%22 stroke-width=%221.8%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22%3E%3Cpath d=%22M14 9a2 2 0 0 1-2 2H6l-4 4V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2z%22/%3E%3Cpath d=%22M18 9h2a2 2 0 0 1 2 2v11l-4-4h-6a2 2 0 0 1-2-2v-1%22/%3E%3C/svg%3E"); }
.ic-send { --ic: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22black%22 stroke-width=%221.8%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22%3E%3Cpath d=%22M22 2 11 13%22/%3E%3Cpath d=%22M22 2 15 22l-4-9-9-4z%22/%3E%3C/svg%3E"); }
.ic-back { --ic: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22black%22 stroke-width=%221.8%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22%3E%3Cpath d=%22m15 18-6-6 6-6%22/%3E%3C/svg%3E"); }
.ic-minus { --ic: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22black%22 stroke-width=%221.8%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22%3E%3Cpath d=%22M5 12h14%22/%3E%3C/svg%3E"); }
.ic-more { --ic: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22black%22 stroke-width=%222.6%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22%3E%3Cpath d=%22M5 12h.01M12 12h.01M19 12h.01%22/%3E%3C/svg%3E"); }
.ic-chevron { --ic: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22black%22 stroke-width=%221.8%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22%3E%3Cpath d=%22m6 15 6-6 6 6%22/%3E%3C/svg%3E"); }
.msg-btn .ic, .mcm-dock .ic, .msg-panel .ic { margin-right: 0; }
.msg-btn .ic { width: 1.15em; height: 1.15em; }

/* --- bouton du bandeau --- */
/* Un panneau ouvert (messages ou notifications) passe au-dessus des notes du dossier (z-index 60/61) : l'en-tête est sinon sous elles. */
header.topbar:has(.notif-panel:not([style*="display:none"]):not([style*="display: none"])) { z-index: 120; }
.msg-wrap { margin-left: 6px; }
.msg-btn { position: relative; }
.msg-btn[aria-expanded="true"] { background: var(--card-hover); }
.msg-navdot { position: absolute; top: 3px; right: 3px; width: 9px; height: 9px; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 2px var(--bg); }
#navToggle { position: relative; }

/* --- avatars et pastilles de présence --- */
.mcm-av { position: relative; flex: none; width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: .76rem; font-weight: 600; letter-spacing: .02em; background: hsl(var(--h, 200) 16% 30%); color: #eceef0; }
:root[data-theme="light"] .mcm-av { background: hsl(var(--h, 200) 28% 86%); color: #1d2a33; }
.mcm-av.sm { width: 28px; height: 28px; font-size: .68rem; }
.mcm-dot { position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--raised); background: var(--faint); box-sizing: content-box; }
.mcm-av.sm .mcm-dot { width: 8px; height: 8px; }
.mcm-dot.online { background: var(--green); }
.mcm-dot.away { background: var(--orange); }
.mcm-dot.offline { background: var(--faint); }
.mcm-sub { color: var(--muted); font-size: .76rem; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mcm-sub .ic { width: .95em; height: .95em; margin-right: .3em; vertical-align: -0.12em; color: var(--blue); }
.mcm-count { flex: none; min-width: 18px; padding: 2px 6px; border-radius: 10px; background: var(--blue); color: var(--accent-ink); font-size: .68rem; font-weight: 600; font-family: var(--font-mono, ui-monospace, monospace); text-align: center; line-height: 1.2; }

/* --- panneau des derniers messages (sous l'icône) --- */
.msg-panel { width: 380px; }
.msg-list { max-height: min(60vh, 460px); }
.msg-row { display: flex; align-items: center; gap: 12px; width: 100%; box-sizing: border-box; padding: 11px 16px; border: 0; border-bottom: 1px solid var(--line); background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.msg-row:hover, .msg-row:focus-visible { background: var(--card-hover); outline: none; }
.msg-row.unread { background: color-mix(in srgb, var(--blue) 7%, transparent); }
.msg-row-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.msg-row-top { display: flex; align-items: baseline; gap: 8px; }
.msg-row-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .88rem; font-weight: 500; }
.msg-row.unread .msg-row-name, .msg-row.unread .msg-row-prev { font-weight: 600; color: var(--text); }
.msg-row-time { flex: none; color: var(--muted); font-size: .72rem; }
.msg-row-prev { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: .8rem; }
.msg-empty { margin: 0; padding: 16px; color: var(--muted); font-size: .85rem; line-height: 1.5; }
.msg-foot { padding: 10px 16px; border-top: 1px solid var(--line); text-align: center; }
.msg-foot button { all: unset; cursor: pointer; color: var(--blue); font-size: .82rem; }
.msg-foot button:hover { text-decoration: underline; }

/* --- barre en bas de page (ordinateur) --- */
.mcm-dock { position: fixed; z-index: 80; right: 92px; bottom: var(--mcc-h, 0px); display: flex; flex-direction: row; align-items: flex-end; gap: 10px; pointer-events: none; }
.mcm-dock > * { pointer-events: auto; }
body.sn-open .mcm-dock { right: calc(var(--sn-w, 0px) + 154px); }
.mcm-wins { display: flex; flex-direction: row-reverse; align-items: flex-end; gap: 10px; pointer-events: none; }
.mcm-wins > * { pointer-events: auto; }
.mcm-bar, .mcm-win { display: flex; flex-direction: column; box-sizing: border-box; background: var(--raised); border: 1px solid var(--line-strong); border-bottom: 0; border-radius: 10px 10px 0 0; box-shadow: var(--shadow-pop); color: var(--text); overflow: hidden; }
.mcm-bar { width: 250px; }
.mcm-bar-head { all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; cursor: pointer; font-size: .86rem; font-weight: 500; }
.mcm-bar-head:hover { background: var(--card-hover); }
.mcm-bar-head:focus-visible, .mcm-win-title:focus-visible { outline: 2px solid var(--blue); outline-offset: -3px; }
.mcm-bar-head b { font-weight: 400; color: var(--muted); font-size: .76rem; margin-right: auto; }
.mcm-bar-head .mcm-lead { margin-right: auto; }
.mcm-bar-body { display: flex; flex-direction: column; height: min(440px, calc(100vh - 150px)); border-top: 1px solid var(--line); }
.mcm-bar-body[hidden] { display: none; }
.mcm-tools { display: flex; align-items: center; gap: 6px; padding: 8px 8px 8px 10px; border-bottom: 1px solid var(--line); }
.mcm-tools input[type="search"] { flex: 1; min-width: 0; height: 30px; box-sizing: border-box; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--card); color: var(--text); font: inherit; font-size: .82rem; }
.mcm-tools input[type="search"]:focus { outline: 2px solid color-mix(in srgb, var(--blue) 60%, transparent); outline-offset: 0; }
.mcm-iconbtn { all: unset; box-sizing: border-box; flex: none; width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; cursor: pointer; color: var(--muted); }
.mcm-iconbtn:hover { background: var(--card-hover); color: var(--text); }
.mcm-iconbtn:focus-visible { outline: 2px solid var(--blue); }
.mcm-iconbtn .ic { width: 1.1em; height: 1.1em; }
.mcm-opts { padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: .8rem; color: var(--muted); line-height: 1.45; background: var(--card); }
.mcm-opts[hidden] { display: none; }
.mcm-opts label { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: .84rem; cursor: pointer; }
.mcm-opts p { margin: 6px 0 0; }
.mcm-contacts { flex: 1; overflow-y: auto; padding: 4px 0 8px; }
.mcm-sec { padding: 10px 14px 4px; color: var(--faint); font-size: .68rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.mcm-contact { all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 14px; cursor: pointer; }
.mcm-contact:hover, .mcm-contact:focus-visible { background: var(--card-hover); }
.mcm-contact:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; }
.mcm-contact-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mcm-contact-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .86rem; }
.mcm-contact.off .mcm-contact-name { color: var(--muted); }
.mcm-empty { padding: 16px 14px; color: var(--muted); font-size: .82rem; line-height: 1.5; }

/* --- fenêtre de discussion --- */
.mcm-win { width: 304px; height: 400px; }
.mcm-win.min { height: 40px; }
.mcm-win-head { display: flex; align-items: center; flex: none; height: 40px; border-bottom: 1px solid var(--line); }
.mcm-win.min .mcm-win-head { border-bottom: 0; }
.mcm-win-title { all: unset; box-sizing: border-box; flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; height: 100%; padding: 0 4px 0 10px; cursor: pointer; }
.mcm-win-title:hover { background: var(--card-hover); }
.mcm-win-who { min-width: 0; display: flex; flex-direction: column; }
.mcm-win-who b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .84rem; font-weight: 500; line-height: 1.2; }
.mcm-win-who .mcm-sub { font-size: .68rem; line-height: 1.2; }
.mcm-win.unread .mcm-win-head { background: color-mix(in srgb, var(--blue) 16%, transparent); }
.mcm-win-head .mcm-iconbtn { width: 32px; height: 40px; border-radius: 0; }
.mcm-win-back { display: none; }
.mcm-win.min .mcm-win-body, .mcm-win.min .mcm-comp { display: none; }
.mcm-win-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.mcm-log { flex: 1; overflow-y: auto; padding: 10px 12px 4px; display: flex; flex-direction: column; gap: 2px; overscroll-behavior: contain; }
.mcm-day { align-self: center; margin: 10px 0 6px; color: var(--faint); font-size: .7rem; }
.mcm-more { all: unset; align-self: center; cursor: pointer; margin: 2px 0 8px; color: var(--blue); font-size: .76rem; }
.mcm-more:hover { text-decoration: underline; }
.mcm-grp { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; max-width: 86%; }
.mcm-grp.mine { align-self: flex-end; align-items: flex-end; }
.mcm-grp.theirs { align-self: flex-start; align-items: flex-start; }
.mcm-b { padding: 7px 11px; border-radius: 14px; font-size: .86rem; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.mcm-grp.theirs .mcm-b { background: var(--card-hover); border: 1px solid var(--line); border-top-left-radius: 5px; }
.mcm-grp.mine .mcm-b { background: var(--blue); color: var(--accent-ink); border-top-right-radius: 5px; }
.mcm-grp.mine .mcm-b a { color: inherit; }
.mcm-b a { color: var(--blue); text-decoration: underline; }
.mcm-b.pending { opacity: .6; }
.mcm-meta { color: var(--faint); font-size: .66rem; padding: 0 3px; }
.mcm-err { color: var(--red); font-size: .72rem; padding: 0 3px; }
.mcm-err button { all: unset; cursor: pointer; text-decoration: underline; margin-left: 4px; }
.mcm-comp { display: flex; align-items: flex-end; gap: 6px; flex: none; padding: 8px; border-top: 1px solid var(--line); }
.mcm-comp textarea { flex: 1; min-width: 0; box-sizing: border-box; resize: none; max-height: 96px; min-height: 34px; padding: 7px 11px; border: 1px solid var(--line-strong); border-radius: 17px; background: var(--card); color: var(--text); font: inherit; font-size: .86rem; line-height: 1.35; }
.mcm-comp textarea:focus { outline: 2px solid color-mix(in srgb, var(--blue) 60%, transparent); outline-offset: 0; }
.mcm-send { all: unset; box-sizing: border-box; flex: none; width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; background: var(--blue); color: var(--accent-ink); }
.mcm-send:hover { filter: brightness(1.08); }
.mcm-send:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.mcm-send[disabled] { opacity: .45; cursor: default; filter: none; }
.mcm-send .ic { width: 1.05em; height: 1.05em; }
.mcm-note { padding: 18px 14px; color: var(--muted); font-size: .8rem; text-align: center; line-height: 1.5; }

@media (prefers-reduced-motion: no-preference) {
  .mcm-win, .mcm-bar { animation: mcm-in .16s ease-out; }
  @keyframes mcm-in { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }
}
@media print { .mcm-dock, .msg-wrap { display: none !important; } }

/* --- téléphone et tablette (le menu du haut est replié) : pas de barre en bas, la discussion occupe l'écran --- */
@media (max-width: 900px) {
  /* Le conteneur n'est plus fixe : une fenêtre fixe dans un parent fixe resterait dans son empilement (z-index 80) et passerait sous la bulle de l'assistant. */
  .mcm-dock { position: static; display: block; }
  .mcm-bar { display: none; }
  .msg-wrap { margin-left: 0; }
  .msg-panel { width: auto; }
  /* Panneaux des notifications et des messages : sur petit écran ils sont fixes ; portail-pro.css les plaçait à "100 % + 6 px" du haut de l'ÉCRAN, donc hors de la vue. */
  body.pro header.topbar .notif-panel { top: 64px; left: 8px; right: 8px; width: auto; max-width: none; max-height: calc(100vh - 76px); overflow-y: auto; }
  @supports (height: 100dvh) { body.pro header.topbar .notif-panel { max-height: calc(100dvh - 76px); } }
  .mcm-wins { display: block; }
  /* --mcm-h / --mcm-top : zone réellement visible (clavier ouvert), posées par messagerie.js ; --mcc-h : hauteur du bandeau de cookies tant qu'il est affiché. */
  .mcm-win, .mcm-win.min { position: fixed; z-index: 960; top: var(--mcm-top, 0px); left: 0; right: 0; bottom: auto; width: auto; height: calc(var(--mcm-h, 100vh) - var(--mcc-h, 0px)); border: 0; border-radius: 0; box-shadow: none; animation: none; }
  .mcm-win.min .mcm-win-body, .mcm-win.min .mcm-comp { display: flex; }
  .mcm-win-head { height: 52px; padding-top: env(safe-area-inset-top); box-sizing: content-box; }
  .mcm-win-title { padding-left: 4px; }
  .mcm-win-back { display: inline-flex; }
  .mcm-win-min, .mcm-win-close { display: none; }
  .mcm-win-head .mcm-iconbtn { width: 44px; height: 52px; }
  .mcm-win-who b { font-size: .95rem; }
  .mcm-win-who .mcm-sub { font-size: .74rem; }
  .mcm-log { padding: 12px 14px 6px; }
  .mcm-b { font-size: .95rem; }
  .mcm-comp { padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
  .mcm-comp textarea, body.pro .mcm-win .mcm-comp textarea { font-size: 16px !important; } /* 16 px : évite le zoom automatique d'iPhone à la saisie */
  .mcm-send { width: 40px; height: 40px; }
  .msg-row { padding: 13px 16px; }
}

/* --- barre déplaçable (ordinateur) : décalage posé par messagerie.js (--mcm-dx, --mcm-dy), jamais sur téléphone (les fenêtres y sont plein écran) --- */
@media (min-width: 901px) {
  .mcm-dock { transform: translate(var(--mcm-dx, 0px), var(--mcm-dy, 0px)); }
  .mcm-bar-head, .mcm-win-head .mcm-win-title { cursor: grab; touch-action: none; }
  .mcm-bar-head, .mcm-win-head { -webkit-user-select: none; user-select: none; }
  body.mcm-dragging, body.mcm-dragging * { cursor: grabbing !important; user-select: none !important; }
  body.mcm-dragging .mcm-dock { opacity: .92; }
}.mcm-opts .mcm-reset { all: unset; cursor: pointer; color: var(--blue); font-size: .8rem; }
.mcm-opts .mcm-reset:hover { text-decoration: underline; }
.mcm-opts .mcm-reset:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
