/* =====================================================================
 * MESSAGERIE — panneau de conversation (fiche prestataire) et page
 * « Mes messages ». Classes préfixées « mg- » (commun) et « ms- » (page).
 * ===================================================================== */
body[data-page="prestataire"], body[data-page="messages"] {
    --mg-g900: #11301F;
    --mg-g700: #1F4A38;
    --mg-g500: #2F6B50;
    --mg-g100: #E4EFE8;
    --mg-g50:  #F2F7F3;
    --mg-sand: #FBF7F0;
    --mg-or:   #D97706;
    --mg-or-d: #B45F04;
    --mg-or-s: #FDF0DA;
    --mg-ink:  #16231B;
    --mg-mut:  #5C6A61;
    --mg-line: #DCE3DE;
    --mg-serif: 'Fraunces', Georgia, 'Times New Roman', serif;
}
.mg-panneau .ic, .ms-page .ic { width: 1em; height: 1em; flex-shrink: 0; }
body.mg-ouvert { overflow: hidden; }

/* ---------- Boutons partagés (aussi utilisés dans profil.css) ---------- */
.pf-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    padding: .85rem 1.3rem; border-radius: 12px; border: 1.5px solid transparent;
    font-family: inherit; font-weight: 600; font-size: .95rem; line-height: 1; cursor: pointer;
    text-decoration: none; transition: background .15s, border-color .15s; margin: 0;
}
.pf-btn--or { background: var(--mg-or); color: #fff; }
.pf-btn--or:hover { background: var(--mg-or-d); }
.pf-btn--vert { background: var(--mg-g700); color: #fff; }
.pf-btn--vert:hover { background: var(--mg-g900); }
.pf-btn--ligne { background: #fff; color: var(--mg-g700); border-color: var(--mg-line); }
.pf-btn--ligne:hover { border-color: var(--mg-g700); }

/* ---------- Panneau latéral de la fiche ---------- */
.mg-panneau {
    position: fixed; inset: 0; z-index: 1000;
    background: rgba(17, 48, 31, .45);
    display: flex; justify-content: flex-end;
}
.mg-panneau[hidden] { display: none; }
.mg-panneau-boite {
    width: min(440px, 100%); height: 100%; background: #fff;
    display: flex; flex-direction: column;
    box-shadow: -20px 0 60px -30px rgba(17,48,31,.6);
    animation: mg-entree .22s ease-out;
    padding-top: env(safe-area-inset-top, 0px);
}
@keyframes mg-entree { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.mg-panneau-tete { display: flex; align-items: center; gap: .8rem; padding: 1rem 1.1rem; border-bottom: 1px solid var(--mg-line); }
.mg-panneau-tete img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; background: var(--mg-g100); }
.mg-panneau-tete div { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mg-panneau-tete strong { color: var(--mg-g900); font-size: 1rem; }
.mg-panneau-tete small { color: var(--mg-mut); font-size: .8rem; }
.mg-fermer {
    width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent; color: var(--mg-mut);
    display: grid; place-items: center; font-size: 1.25rem; cursor: pointer;
}
.mg-fermer:hover { background: var(--mg-g50); color: var(--mg-g900); }

.mg-confidentialite {
    display: flex; align-items: center; gap: .5rem;
    margin: 0; padding: .55rem 1.1rem; background: var(--mg-g50); color: var(--mg-g700);
    font-size: .76rem; border-bottom: 1px solid var(--mg-line);
}

/* ---------- Fil de messages (commun) ---------- */
.mg-corps {
    flex: 1; overflow-y: auto; padding: 1.1rem; background: var(--mg-sand);
    display: flex; flex-direction: column; gap: .45rem;
}
.mg-jour {
    align-self: center; margin: .7rem 0 .3rem; padding: .25rem .7rem; border-radius: 999px;
    background: #fff; border: 1px solid var(--mg-line); color: var(--mg-mut); font-size: .72rem; text-transform: capitalize;
}
.mg-bulle {
    max-width: 82%; padding: .6rem .8rem .45rem; border-radius: 16px; font-size: .92rem; line-height: 1.45;
    word-wrap: break-word; overflow-wrap: anywhere;
}
.mg-bulle p { margin: 0; white-space: pre-wrap; }
.mg-heure { display: block; text-align: right; font-size: .68rem; margin-top: .2rem; opacity: .65; }
.mg-moi { align-self: flex-end; background: var(--mg-g700); color: #fff; border-bottom-right-radius: 5px; }
.mg-autre { align-self: flex-start; background: #fff; color: var(--mg-ink); border: 1px solid var(--mg-line); border-bottom-left-radius: 5px; }

.mg-chargement { margin: auto; color: var(--mg-mut); font-size: .9rem; }
.mg-etat { margin: auto; text-align: center; max-width: 320px; display: flex; flex-direction: column; align-items: center; gap: .7rem; }
.mg-etat-ico { font-size: 2rem; line-height: 1; }
.mg-etat h3 { font-family: var(--mg-serif); font-weight: 600; font-size: 1.25rem; color: var(--mg-g900); margin: 0; }
.mg-etat p { color: var(--mg-mut); font-size: .9rem; line-height: 1.55; margin: 0; }
.mg-etat .pf-btn { width: 100%; }
.mg-idees { display: flex; flex-wrap: wrap; justify-content: center; gap: .45rem; margin-top: .3rem; }
.mg-idees button {
    border: 1px solid var(--mg-line); background: #fff; color: var(--mg-g700); border-radius: 999px;
    padding: .45rem .85rem; font: inherit; font-size: .82rem; font-weight: 600; cursor: pointer;
}
.mg-idees button:hover { border-color: var(--mg-g500); background: var(--mg-g50); }

/* ---------- Zone de saisie (commune) ---------- */
.mg-saisie { padding: .8rem 1rem calc(.8rem + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--mg-line); background: #fff; }
.mg-saisie[hidden] { display: none; }
.mg-saisie-ligne { display: flex; align-items: flex-end; gap: .55rem; }
.mg-saisie textarea {
    flex: 1; resize: none; min-height: 46px; max-height: 160px; border: 1.5px solid var(--mg-line); border-radius: 14px;
    padding: .7rem .9rem; font: inherit; font-size: .95rem; line-height: 1.4; color: var(--mg-ink); background: #fff;
}
.mg-saisie textarea:focus { outline: none; border-color: var(--mg-g500); box-shadow: 0 0 0 3px rgba(47,107,80,.15); }
.mg-envoyer {
    width: 46px; height: 46px; border-radius: 14px; border: 0; background: var(--mg-g700); color: #fff;
    display: grid; place-items: center; font-size: 1.15rem; cursor: pointer; flex-shrink: 0;
}
.mg-envoyer:hover { background: var(--mg-g900); }
.mg-envoyer:disabled { opacity: .6; cursor: wait; }
.mg-alerte { margin: 0 0 .6rem; padding: .55rem .8rem; border-radius: 10px; background: #FEF2F2; color: #991B1B; font-size: .82rem; }
.mg-alerte[hidden] { display: none; }
.mg-lien-boite { display: block; text-align: center; margin-top: .6rem; font-size: .8rem; color: var(--mg-g500); font-weight: 600; text-decoration: none; }
.mg-lien-boite:hover { text-decoration: underline; }

/* =====================================================================
 * PAGE « MES MESSAGES »
 * ===================================================================== */
body[data-page="messages"] { background: var(--mg-sand); }
body[data-page="messages"] footer { margin-top: 0; }
.ms-page { padding-block: 2.2rem 3.5rem; }
.ms-wrap {
    max-width: 1180px; margin-inline: auto;
    padding-left: max(20px, env(safe-area-inset-left, 0px));
    padding-right: max(20px, env(safe-area-inset-right, 0px));
}
.ms-tete h1 { font-family: var(--mg-serif); font-weight: 600; font-size: clamp(1.8rem, 3vw, 2.3rem); color: var(--mg-g900); margin: 0; }
.ms-tete p { color: var(--mg-mut); margin: .3rem 0 1.4rem; }

.ms-avis-pro {
    display: flex; gap: .8rem; align-items: flex-start; margin-bottom: 1.2rem;
    background: var(--mg-or-s); color: #7A4204; border-radius: 14px; padding: .95rem 1.1rem; font-size: .9rem; line-height: 1.55;
}
.ms-avis-pro[hidden] { display: none; }
.ms-avis-pro .ic { font-size: 1.2rem; margin-top: .15rem; }
.ms-avis-pro p { margin: 0; }
.ms-avis-pro a { color: #7A4204; font-weight: 700; margin: 0; }

.ms-boite {
    display: grid; grid-template-columns: minmax(0, 340px) minmax(0, 1fr);
    height: min(72vh, 760px); min-height: 480px;
    background: #fff; border: 1px solid var(--mg-line); border-radius: 22px; overflow: hidden;
    box-shadow: 0 30px 60px -45px rgba(17,48,31,.5);
}
.ms-colonne { border-right: 1px solid var(--mg-line); overflow-y: auto; min-width: 0; }
.ms-liste { display: flex; flex-direction: column; }
.ms-item {
    display: flex; align-items: center; gap: .8rem; width: 100%; text-align: left;
    padding: .9rem 1rem; border: 0; border-bottom: 1px solid var(--mg-line); background: #fff; cursor: pointer; font: inherit;
}
.ms-item:hover { background: var(--mg-g50); }
.ms-item.actif { background: var(--mg-g50); box-shadow: inset 3px 0 0 var(--mg-g700); }
.ms-av {
    width: 46px; height: 46px; border-radius: 50%; object-fit: cover; flex-shrink: 0;
    background: var(--mg-g100); color: var(--mg-g700); display: grid; place-items: center; font-weight: 700; font-size: .9rem; overflow: hidden;
}
.ms-av { position: relative; }
.ms-av img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 1; }
.ms-item-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .2rem; }
.ms-item-haut, .ms-item-bas { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.ms-item-haut strong { color: var(--mg-g900); font-size: .93rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-item-haut small { color: var(--mg-mut); font-size: .74rem; flex-shrink: 0; }
.ms-extrait { color: var(--mg-mut); font-size: .84rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-item.non-lu .ms-extrait { color: var(--mg-ink); font-weight: 600; }
.ms-badge { background: var(--mg-or); color: #fff; font-size: .7rem; font-weight: 700; border-radius: 999px; min-width: 20px; height: 20px; padding: 0 .4rem; display: grid; place-items: center; flex-shrink: 0; }
.ms-vide { padding: 2.5rem 1.4rem; text-align: center; display: flex; flex-direction: column; align-items: center; gap: .7rem; color: var(--mg-mut); font-size: .9rem; line-height: 1.55; }
.ms-vide h3 { font-family: var(--mg-serif); font-weight: 600; color: var(--mg-g900); font-size: 1.2rem; margin: 0; }
.ms-vide p { margin: 0; }

.ms-fil-col { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.ms-fil-vide { margin: auto; text-align: center; color: var(--mg-mut); display: flex; flex-direction: column; gap: .6rem; align-items: center; }
.ms-fil-vide[hidden] { display: none; }
.ms-fil-zone { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.ms-fil-zone[hidden] { display: none; }
.ms-fil-tete { display: flex; align-items: center; gap: .8rem; padding: .85rem 1.1rem; border-bottom: 1px solid var(--mg-line); }
.ms-fil-tete > div { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ms-fil-tete strong { color: var(--mg-g900); }
.ms-fil-tete small { color: var(--mg-mut); font-size: .78rem; }
.ms-fil-tete .ms-av { width: 40px; height: 40px; }
.ms-voir-profil { font-size: .84rem; font-weight: 600; color: var(--mg-g700); border: 1.5px solid var(--mg-line); border-radius: 10px; padding: .45rem .8rem; text-decoration: none; margin: 0; }
.ms-voir-profil[hidden] { display: none; }
.ms-voir-profil:hover { border-color: var(--mg-g700); }
.ms-retour { display: none; width: 38px; height: 38px; border: 0; border-radius: 10px; background: transparent; color: var(--mg-g900); font-size: 1.2rem; cursor: pointer; place-items: center; }
.ms-fil { min-height: 0; }

@media (max-width: 880px) {
    .ms-page { padding-block: 1.2rem 2rem; }
    .ms-boite { grid-template-columns: 1fr; height: calc(100vh - 210px); min-height: 440px; border-radius: 18px; }
    .ms-colonne { border-right: 0; }
    .ms-fil-col { display: none; }
    .ms-boite.ms-fil-ouvert .ms-colonne { display: none; }
    .ms-boite.ms-fil-ouvert .ms-fil-col { display: flex; }
    .ms-retour { display: grid; }
    .ms-voir-profil { padding: .4rem .6rem; font-size: .78rem; }
}
@media (max-width: 480px) {
    .mg-panneau-boite { width: 100%; }
}
/* Le bouton d'Awa ne doit pas recouvrir la saisie ni la barre « Écrire » */
@media (max-width: 880px) {
    body[data-page="messages"] .ai-agent-launcher { display: none; }
}
@media (max-width: 960px) {
    body[data-page="prestataire"] .ai-agent-launcher { bottom: calc(96px + env(safe-area-inset-bottom, 0px)) !important; }
    body.mg-ouvert .ai-agent-launcher { display: none; }
}

body[data-page="prestataire"] :is(a, button, textarea):focus-visible,
body[data-page="messages"] :is(a, button, textarea):focus-visible { outline: 2px solid var(--mg-or); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
    .mg-panneau-boite { animation: none; }
}
