/* ── Messagerie ────────────────────────────────────────────────────────────
   Deux volets sur écran large, un seul sur téléphone. Un fil de discussion sur
   360 px partagé en deux colonnes ne montre ni la liste ni le fil ; c'est le
   seul écran du dashboard où la bascule vaut mieux que le rétrécissement. */
.msg-page {
    display: grid;
    grid-template-columns: minmax(0, 320px) minmax(0, 1fr);
    gap: var(--sp-3);
    /* Hauteur fixe et non `min-height` : le fil défile DANS son volet. Laisser
       la page défiler ferait remonter le champ de saisie hors de l'écran dès
       qu'une conversation s'allonge. */
    height: calc(100vh - 140px);
    min-height: 420px;
    padding: var(--sp-4);
}

.msg-list,
.msg-thread {
    display: flex;
    flex-direction: column;
    min-height: 0;      /* sans ça, le contenu déborde au lieu de défiler */
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-lg);
    overflow: hidden;
}

.msg-list-head {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-3);
    border-bottom: 1px solid var(--border-subtle);
    font-family: var(--font-display);
    font-weight: 700;
    color: var(--text-primary);
}
.msg-list-head .btn { margin-left: auto; }
.msg-list-body { flex: 1; overflow-y: auto; min-height: 0; }

.msg-row {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    width: 100%;
    padding: 11px 13px;
    border: none;
    border-bottom: 1px solid var(--border-subtle);
    background: none;
    color: var(--text-secondary);
    font-family: var(--font-body);
    text-align: left;
    cursor: pointer;
}
.msg-row.is-open { background: var(--gold-glow); }
.msg-row-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.msg-row-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.88rem;
    overflow-wrap: anywhere;
}
.msg-row-kind { font-size: 0.72rem; color: var(--text-faint); }
.msg-row .nav-count { margin-left: auto; }

.msg-thread-head {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-3);
    border-bottom: 1px solid var(--border-subtle);
}
.msg-thread-id { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.msg-thread-id strong { color: var(--text-primary); overflow-wrap: anywhere; }
.msg-thread-head .btn { margin-left: auto; }

/* Le retour n'existe que sur téléphone : au-dessus, les deux volets sont là. */
.msg-back {
    display: none;
    min-width: var(--pr-touch-target);
    min-height: var(--pr-touch-target);
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
}

.msg-messages {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding: var(--sp-3);
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
}

.msg-bubble {
    max-width: min(560px, 88%);
    padding: 8px 12px;
    border-radius: 12px;
    background: var(--bg-overlay);
    border: 1px solid var(--border-subtle);
}
/* Les siens à droite : c'est la convention de toutes les messageries, et s'en
   écarter demande de lire le nom pour savoir qui parle. */
.msg-bubble.is-mine {
    align-self: flex-end;
    background: var(--gold-glow);
    border-color: var(--border-gold);
}
.msg-bubble.is-staff { border-left: 3px solid var(--gold); }
.msg-bubble-head {
    display: flex;
    gap: var(--sp-2);
    align-items: baseline;
    font-size: 0.72rem;
    color: var(--text-faint);
    margin-bottom: 3px;
}
.msg-bubble-head strong { color: var(--text-secondary); }
.msg-bubble-body {
    font-size: 0.88rem;
    line-height: 1.5;
    color: var(--text-primary);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.msg-compose {
    display: flex;
    gap: var(--sp-2);
    align-items: flex-end;
    padding: var(--sp-3);
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-base);
}
.msg-compose textarea {
    flex: 1;
    min-height: var(--pr-touch-target);
    max-height: 140px;
    padding: 10px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border-mid);
    border-radius: var(--r-md);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.9rem;
    resize: vertical;
}
.msg-compose textarea:focus { outline: none; border-color: var(--border-gold); }

.msg-placeholder { margin: auto; padding: var(--sp-4); text-align: center; }
.msg-closed { margin: 0; padding: var(--sp-3); border-top: 1px solid var(--border-subtle); }

.msg-new { padding: var(--sp-4); overflow-y: auto; display: flex;
           flex-direction: column; gap: var(--sp-3); }
.msg-new h3 { margin: 0; font-family: var(--font-display); color: var(--text-primary); }

.msg-choice {
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-mid);
    border-radius: var(--r-md);
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-family: var(--font-body);
    text-align: left;
    cursor: pointer;
}
.msg-choice:hover { border-color: var(--border-gold); }
.msg-choice strong { color: var(--text-primary); font-size: 0.9rem; }
.msg-choice span { font-size: 0.76rem; color: var(--text-muted); }

.msg-overlay {
    position: fixed;
    inset: 0;
    z-index: 3200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-4);
    background: rgba(0, 0, 0, 0.62);
}
.msg-modal {
    width: min(420px, 100%);
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    padding: var(--sp-4);
    background: var(--bg-raised);
    border: 1px solid var(--border-gold);
    border-radius: var(--r-lg);
}
.msg-modal h3 { margin: 0 0 var(--sp-2); font-family: var(--font-display);
                color: var(--text-primary); }

@media (max-width: 768px) {
    .msg-page {
        grid-template-columns: minmax(0, 1fr);
        height: calc(100vh - 108px);
        padding: var(--sp-2);
    }
    /* Un seul volet à la fois : le fil prend la place de la liste. */
    .msg-list.is-hidden-mobile { display: none; }
    .msg-list.is-hidden-mobile + .msg-thread { display: flex; }
    .msg-list:not(.is-hidden-mobile) + .msg-thread { display: none; }
    .msg-back { display: block; }
}

/* ── Bulle de message rapide ───────────────────────────────────────────────
   Le raccourci permanent, en bas à droite. Il ne rend aucun fil : un raccourci
   qui recopie l'écran qu'il raccourcit finit par en diverger. */
.qm { position: fixed; right: 18px; bottom: 18px; z-index: 2400; }
.qm-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: 1px solid var(--border-gold);
    background: var(--bg-raised);
    color: var(--gold);
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.qm-btn [data-icon] { width: 22px; height: 22px; display: inline-flex; }
.qm-btn [data-icon] svg { width: 100%; height: 100%; }
.qm-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--r-full);
    background: var(--gold);
    color: #111;
    font-size: 0.66rem;
    font-weight: 700;
}
.qm-badge[hidden] { display: none; }

.qm-panel {
    position: absolute;
    right: 0;
    bottom: 62px;
    width: min(300px, calc(100vw - 36px));
    display: flex;
    flex-direction: column;
    background: var(--bg-raised);
    border: 1px solid var(--border-gold);
    border-radius: var(--r-lg);
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.6);
    overflow: hidden;
}
.qm-panel[hidden] { display: none; }
.qm-head {
    padding: 10px 13px;
    border-bottom: 1px solid var(--border-subtle);
    font-family: var(--font-display);
    font-weight: 700;
    color: var(--text-primary);
    font-size: 0.9rem;
}
.qm-body { max-height: 260px; overflow-y: auto; }
.qm-row {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: 10px 13px;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.84rem;
}
.qm-row:hover { background: var(--bg-hover); }
.qm-row-title { min-width: 0; overflow: hidden; text-overflow: ellipsis;
                white-space: nowrap; }
.qm-row .nav-count { margin-left: auto; }
.qm-all { margin: var(--sp-2); text-align: center; }
.qm-body .empty-note { padding: var(--sp-3); }
