/* Messagerie Inside Pace — fenêtre de discussion large et immersive.
   La liste des athlètes reste la porte d’entrée ; cliquer sur un athlète ouvre
   une vraie fenêtre dans l’application, sans changer d’onglet ni de page. */

body:has(input[placeholder="Rechercher un athlète…"]):has(section > .msg-conversation-layout) {
  overflow: hidden;
}

body:has(input[placeholder="Rechercher un athlète…"]):has(section > .msg-conversation-layout)::before {
  position: fixed;
  z-index: 1190;
  inset: 0;
  background: rgba(3, 9, 26, 0.72);
  backdrop-filter: blur(8px);
  content: '';
}

body:has(input[placeholder="Rechercher un athlète…"]) section:has(> .msg-conversation-layout) {
  position: fixed !important;
  z-index: 1200;
  inset: 18px !important;
  width: auto !important;
  max-width: 1480px;
  height: calc(100dvh - 36px);
  margin: auto !important;
  border-radius: 28px !important;
  display: flex !important;
  flex-direction: column;
  overflow: hidden !important;
  box-shadow:
    0 32px 90px rgba(0, 0, 0, 0.48),
    inset 0 1px 0 rgba(255, 255, 255, 0.09) !important;
  animation: msg-modal-in 170ms ease-out both;
}

body:has(input[placeholder="Rechercher un athlète…"])
  section:has(> .msg-conversation-layout) > div:first-child {
  flex: 0 0 auto;
  min-height: 68px;
  padding: 14px 20px !important;
}

body:has(input[placeholder="Rechercher un athlète…"]) .msg-conversation-layout {
  grid-template-columns: minmax(250px, 320px) minmax(0, 1fr) !important;
  flex: 1 1 auto;
  min-height: 0 !important;
  overflow: hidden;
}

body:has(input[placeholder="Rechercher un athlète…"]) .msg-session-list {
  display: block !important;
  min-height: 0;
  height: 100%;
  max-height: none !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

body:has(input[placeholder="Rechercher un athlète…"]) .msg-session-button {
  min-width: 0 !important;
  max-width: none !important;
}

body:has(input[placeholder="Rechercher un athlète…"]) .msg-thread-pane {
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

body:has(input[placeholder="Rechercher un athlète…"]) .msg-thread-heading {
  flex: 0 0 auto;
  min-height: 58px;
  padding: 12px 18px !important;
}

/* Zone des messages : elle prend tout l’espace disponible et défile comme une
   messagerie classique. Le dernier échange reste en bas grâce au scroll déjà
   géré par React. */
body:has(input[placeholder="Rechercher un athlète…"])
  .msg-thread-pane > div:nth-last-child(2) {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  max-height: none !important;
  overflow-y: auto !important;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  padding: 22px clamp(18px, 3vw, 44px) !important;
  gap: 13px !important;
  scrollbar-width: thin;
}

body:has(input[placeholder="Rechercher un athlète…"])
  .msg-thread-pane > div:nth-last-child(2) > div[style*="justify-self: start"],
body:has(input[placeholder="Rechercher un athlète…"])
  .msg-thread-pane > div:nth-last-child(2) > div[style*="justify-self: end"] {
  max-width: min(78%, 820px) !important;
}

/* Le composer reste en bas de la fenêtre, toujours visible. */
body:has(input[placeholder="Rechercher un athlète…"]) .msg-thread-pane > div:last-child {
  flex: 0 0 auto;
  max-height: 36vh;
  overflow-y: auto;
  padding: 12px 18px max(14px, env(safe-area-inset-bottom)) !important;
}

body:has(input[placeholder="Rechercher un athlète…"]) .msg-thread-pane textarea {
  min-height: 88px !important;
  max-height: 170px;
}

@keyframes msg-modal-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 860px) {
  body:has(input[placeholder="Rechercher un athlète…"]) section:has(> .msg-conversation-layout) {
    inset: 0 !important;
    width: 100% !important;
    max-width: none;
    height: 100dvh;
    border-radius: 0 !important;
  }

  body:has(input[placeholder="Rechercher un athlète…"])
    section:has(> .msg-conversation-layout) > div:first-child {
    min-height: 62px;
    padding: max(10px, env(safe-area-inset-top)) 12px 10px !important;
  }

  body:has(input[placeholder="Rechercher un athlète…"]) .msg-conversation-layout {
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-rows: auto minmax(0, 1fr);
  }

  body:has(input[placeholder="Rechercher un athlète…"]) .msg-session-list {
    display: flex !important;
    height: auto;
    max-height: 154px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    border-right: 0 !important;
  }

  body:has(input[placeholder="Rechercher un athlète…"]) .msg-session-button {
    min-width: 210px !important;
    max-width: 250px !important;
  }

  body:has(input[placeholder="Rechercher un athlète…"])
    .msg-thread-pane > div:nth-last-child(2) {
    padding: 16px 12px !important;
  }

  body:has(input[placeholder="Rechercher un athlète…"])
    .msg-thread-pane > div:nth-last-child(2) > div[style*="justify-self: start"],
  body:has(input[placeholder="Rechercher un athlète…"])
    .msg-thread-pane > div:nth-last-child(2) > div[style*="justify-self: end"] {
    max-width: 92% !important;
  }

  body:has(input[placeholder="Rechercher un athlète…"]) .msg-thread-pane > div:last-child {
    max-height: 43vh;
    padding: 10px 12px max(12px, env(safe-area-inset-bottom)) !important;
  }

  body:has(input[placeholder="Rechercher un athlète…"]) .msg-thread-pane textarea {
    min-height: 74px !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  body:has(input[placeholder="Rechercher un athlète…"]) section:has(> .msg-conversation-layout) {
    animation: none;
  }
}
