/* =====================================================
   Mon Multivers — Chat / Icare
   Conversation, messages, médias et états d'écriture.
   ===================================================== */

/* =====================================================
   ========================== Chat ======================
   ===================================================== */

/* Conversation façon téléphone / SMS. */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 70vh;
  min-height: 420px;
  overflow: hidden;
  padding: 0;
  background:
    radial-gradient(
      ellipse 120% 62% at 8% 0%,
      rgba(15,143,141,.035) 0%,
      rgba(15,143,141,.010) 45%,
      transparent 76%
    ),
    linear-gradient(180deg, #ffffff 0%, #fbfefe 100%);
  border: 1px solid rgba(15,143,141,.11);
  border-radius: 20px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.94),
    0 8px 24px rgba(15,143,141,.025);
}

.chat-contact-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 9px 13px;
  background: rgba(255,255,255,.90);
  border-bottom: 1px solid rgba(15,143,141,.09);
}

.chat-contact-avatar {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background:
    linear-gradient(
      145deg,
      rgba(236,251,250,.98),
      rgba(210,244,242,.98)
    );
  border: 1px solid rgba(15,143,141,.15);
  color: #0f7775;
  font-size: .96rem;
  font-weight: 760;
}

.chat-contact-copy {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.chat-contact-name {
  color: #1d2941;
  font-size: .98rem;
  line-height: 1.2;
  font-weight: 730;
}

.chat-contact-subtitle {
  color: #7a8797;
  font-size: .72rem;
  line-height: 1.2;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 13px;
  scrollbar-width: thin;
  scrollbar-color: rgba(15,143,141,.30) transparent;
}

.chat-messages::-webkit-scrollbar {
  width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: rgba(15,143,141,.28);
  background-clip: padding-box;
}

.message-row {
  width: 100%;
  display: flex;
}

.message-row.user {
  justify-content: flex-end;
}

.message-row.bot {
  justify-content: flex-start;
}

/* Les connexions externes apparaissent à droite, comme un second interlocuteur. */
.message-row.guest {
  justify-content: flex-end;
}

.message-stack {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: min(76%, 680px);
}

.message-row.user .message-stack,
.message-row.guest .message-stack {
  align-items: flex-end;
}

.message-row.bot .message-stack {
  align-items: flex-start;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 4px 4px;
  color: #84909f;
  font-size: .69rem;
  line-height: 1;
  white-space: nowrap;
}

.message-row.user .message-meta,
.message-row.guest .message-meta {
  justify-content: flex-end;
}

.message-row.bot .message-meta {
  justify-content: flex-start;
}

.message-sender {
  color: #526173;
  font-weight: 700;
}

.message-time {
  font-variant-numeric: tabular-nums;
}

.message-direction {
  width: 16px;
  height: 16px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  font-size: .66rem;
  line-height: 1;
  font-weight: 750;
}

.message-row.user .message-direction {
  background: rgba(15,143,141,.10);
  color: #0f7775;
}

.message-row.bot .message-direction {
  background: rgba(47,174,191,.10);
  color: #23879a;
}

.message-row.guest .message-direction {
  background: rgba(111,82,164,.10);
  color: #7056a3;
}

.message-row.guest .message-sender {
  color: #665087;
}

.message {
  position: relative;
  width: fit-content;
  max-width: 100%;
  padding: 10px 13px;
  border: 1px solid transparent;
  box-sizing: border-box;
  font-size: 15px;
  line-height: 1.46;
  overflow-wrap: anywhere;
  box-shadow:
    0 3px 10px rgba(31,82,105,.035),
    inset 0 1px 0 rgba(255,255,255,.54);
}

.message.user {
  background:
    linear-gradient(
      145deg,
      rgba(105,211,207,.96) 0%,
      rgba(54,181,177,.96) 58%,
      rgba(29,157,154,.97) 100%
    );
  border-color: rgba(12,125,123,.16);
  border-radius: 17px 17px 5px 17px;
  color: #ffffff;
  box-shadow:
    0 4px 12px rgba(15,143,141,.070),
    inset 0 1px 0 rgba(255,255,255,.32);
}

.message.bot {
  background:
    radial-gradient(
      ellipse 110% 90% at 10% 0%,
      rgba(47,174,191,.035) 0%,
      transparent 72%
    ),
    #ffffff;
  border-color: rgba(47,174,191,.13);
  border-radius: 17px 17px 17px 5px;
  color: #26384a;
  box-shadow:
    0 3px 11px rgba(45,157,176,.035),
    inset 0 1px 0 rgba(255,255,255,.92);
}

/* Interlocuteur temporaire d'un dialogue invité. */
.message.guest {
  background:
    radial-gradient(
      ellipse 115% 95% at 10% 0%,
      rgba(126,96,184,.08) 0%,
      transparent 72%
    ),
    #f8f6fc;
  border-color: rgba(111,82,164,.18);
  border-radius: 17px 17px 5px 17px;
  color: #342b43;
  box-shadow:
    0 3px 11px rgba(83,61,126,.045),
    inset 0 1px 0 rgba(255,255,255,.92);
}

.chat-input-area {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding:
    9px
    max(10px, env(safe-area-inset-right))
    calc(9px + env(safe-area-inset-bottom))
    max(10px, env(safe-area-inset-left));
  background: rgba(255,255,255,.94);
  border-top: 1px solid rgba(15,143,141,.09);
}

#chat-input {
  flex: 1;
  min-width: 0;
  min-height: 42px;
  padding: 10px 14px;
  background: #ffffff;
  border: 1px solid rgba(15,143,141,.17);
  border-radius: 999px;
  color: #243247;
  outline: none;
  box-shadow:
    inset 0 1px 2px rgba(15,23,42,.025);
  transition:
    border-color .16s ease,
    box-shadow .16s ease;
}

#chat-input::placeholder {
  color: #8994a2;
  opacity: 1;
}

#chat-input:hover {
  border-color: rgba(15,143,141,.30);
}

#chat-input:focus {
  border-color: rgba(15,143,141,.52);
  box-shadow:
    0 0 0 3px rgba(15,143,141,.075),
    inset 0 1px 2px rgba(15,23,42,.020);
}

#chat-send {
  width: 42px;
  height: 42px;
  min-width: 42px;
  min-height: 42px;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(15,143,141,.16);
  border-radius: 50%;
  background:
    linear-gradient(
      145deg,
      rgba(64,190,186,.98),
      rgba(15,143,141,.98)
    );
  color: #ffffff;
  font-size: 1.05rem;
  line-height: 1;
  font-weight: 700;
  box-shadow:
    0 3px 10px rgba(15,143,141,.085);
  cursor: pointer;
  transition:
    transform .12s ease,
    box-shadow .16s ease,
    filter .16s ease;
}

#chat-send:hover:not(:disabled) {
  filter: brightness(1.025);
  box-shadow:
    0 5px 13px rgba(15,143,141,.12);
}

#chat-send:active:not(:disabled) {
  transform: scale(.96);
}

#chat-send:disabled {
  opacity: .38;
  cursor: default;
  box-shadow: none;
}

@media (max-width: 768px) {
  .chat-container {
    min-height: 0;
    border-radius: 14px;
  }

  .chat-contact-bar {
    min-height: 54px;
    padding: 7px 10px;
  }

  .chat-contact-avatar {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
    font-size: .90rem;
  }

  .chat-messages {
    padding: 13px 8px 10px;
    gap: 11px;
  }

  .message-stack {
    max-width: 86%;
  }

  .message-meta {
    margin-bottom: 3px;
    font-size: .66rem;
  }

  .message {
    padding: 9px 11px;
    font-size: .92rem;
    line-height: 1.44;
  }

  .chat-input-area {
    padding:
      7px
      max(8px, env(safe-area-inset-right))
      calc(7px + env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }

  #chat-input {
    min-height: 44px;
  }

  #chat-send {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    flex-basis: 44px;
  }
}

/* =====================================================
   ============== Icare est en train d'écrire ==========
   ===================================================== */

.typing-row .message-stack {
  max-width: min(70%, 220px);
}

.typing-label {
  margin: 0 4px 4px;

  color: #7f8b99;
  font-size: .68rem;
  line-height: 1;
  font-weight: 600;
}

.typing-bubble {
  width: fit-content;
  min-width: 48px;
  height: 32px;

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;

  padding: 0 11px;

  background:
    radial-gradient(
      ellipse 110% 90% at 10% 0%,
      rgba(47,174,191,.032) 0%,
      transparent 72%
    ),
    #ffffff;

  border: 1px solid rgba(47,174,191,.12);
  border-radius: 16px 16px 16px 5px;

  box-shadow:
    0 3px 10px rgba(45,157,176,.028),
    inset 0 1px 0 rgba(255,255,255,.92);
}

.guest-typing-row .message-stack {
  align-items: flex-end;
}

.guest-typing-row .typing-label {
  color: #725b93;
  text-align: right;
}

.guest-typing-row .typing-bubble {
  background:
    radial-gradient(
      ellipse 110% 90% at 10% 0%,
      rgba(126,96,184,.07) 0%,
      transparent 72%
    ),
    #f8f6fc;
  border-color: rgba(111,82,164,.16);
  border-radius: 16px 16px 5px 16px;
}

.guest-typing-row .typing-dot {
  background: #8067a7;
}

.typing-dot {
  width: 5px;
  height: 5px;

  display: block;

  border-radius: 50%;
  background: rgba(15,143,141,.58);

  animation: icareTypingDot 1.05s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: .14s;
}

.typing-dot:nth-child(3) {
  animation-delay: .28s;
}

@keyframes icareTypingDot {
  0%,
  60%,
  100% {
    opacity: .35;
    transform: translateY(0);
  }

  30% {
    opacity: .92;
    transform: translateY(-3px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .typing-dot {
    animation: none;
    opacity: .65;
  }
}

@media (max-width: 768px) {
  .typing-label {
    font-size: .65rem;
  }

  .typing-bubble {
    min-width: 46px;
    height: 30px;
    padding-inline: 10px;
  }
}

/* =====================================================
   ================= Icare hors ligne ===================
   ===================================================== */

.chat-contact-subtitle.is-online,
.chat-contact-subtitle.is-offline {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chat-contact-subtitle.is-online {
  color: #5f6f66;
}

.chat-contact-subtitle.is-offline {
  color: #8a6666;
}

.chat-contact-subtitle.is-online::before,
.chat-contact-subtitle.is-offline::before {
  content: "";
  display: inline-block;

  width: 6px;
  height: 6px;
  flex: 0 0 6px;

  border-radius: 50%;
}

.chat-contact-subtitle.is-online::before {
  background: #22a447;
  box-shadow: 0 0 0 2px rgba(34,164,71,.10);
}

.chat-contact-subtitle.is-offline::before {
  background: #d84a4a;
  box-shadow: 0 0 0 2px rgba(216,74,74,.10);
}

.chat-system-status {
  align-self: center;

  margin: 3px auto;
  padding: 6px 10px;

  border: 1px solid rgba(82,98,122,.10);
  border-radius: 999px;

  background: rgba(247,249,251,.92);

  color: #7c8796;
  font-size: .70rem;
  line-height: 1.15;
  font-weight: 600;
  text-align: center;
}

#chat-input:disabled {
  color: #8b95a2;
  background: #f7f8fa;
  border-color: rgba(82,98,122,.10);
  cursor: default;
}

#chat-send[aria-disabled="true"] {
  opacity: .30;
  cursor: default;
}

@media (max-width: 768px) {
  .chat-system-status {
    font-size: .67rem;
    padding: 5px 9px;
  }
}

/* =========================================================
   CHAT — correction largeur des bulles sur mobile
   ---------------------------------------------------------
   La pile de message reçoit une vraie largeur disponible.
   Cela évite qu'elle se réduise à la largeur du petit bandeau
   "Moi · heure · envoyé", ce qui pouvait provoquer presque
   un retour à la ligne par mot sur téléphone.
   ========================================================= */
@media (max-width: 768px) {
  #panel-chat .message-row .message-stack {
    width: 86%;
    max-width: 86%;
    min-width: 0;
  }

  #panel-chat .message {
    width: fit-content;
    max-width: 100%;
    min-width: 0;

    /* On coupe seulement un mot réellement trop long. */
    overflow-wrap: break-word;
    word-break: normal;
  }

  #panel-chat .message-row.user .message {
    align-self: flex-end;
  }

  #panel-chat .message-row.bot .message {
    align-self: flex-start;
  }

  #panel-chat .message-row.guest .message {
    align-self: flex-end;
  }

  /*
   * L'indicateur d'écriture, lui, reste volontairement compact
   * malgré la largeur stabilisée des messages ordinaires.
   */
  #panel-chat .typing-row .message-stack {
    width: auto;
    max-width: min(70%, 220px);
  }
}

/* =====================================================
   ===== Dialogues invités — harmonisation thème sombre ==
   =====================================================
   Les visiteurs conservent leur identité violette, mais
   utilisent la même profondeur anthracite que les bulles
   d'Icare afin d'éviter un contraste trop lumineux.
   ===================================================== */

html[data-site-theme="dark"] #panel-chat .message.guest {
  background:
    radial-gradient(
      ellipse 115% 95% at 10% 0%,
      rgba(139, 108, 190, .14) 0%,
      rgba(139, 108, 190, .045) 50%,
      transparent 76%
    ),
    #3e3a44;

  border-color: rgba(151, 121, 198, .28);
  color: #eeeaf3;

  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.045),
    0 3px 11px rgba(0,0,0,.10);
}

html[data-site-theme="dark"] #panel-chat .message-row.guest .message-sender {
  color: #d8cdea;
}

html[data-site-theme="dark"] #panel-chat .message-row.guest .message-direction {
  background: rgba(139,108,190,.15);
  color: #cdbde5;
}

html[data-site-theme="dark"] #panel-chat .guest-typing-row .typing-label {
  color: #c8bcda;
}

html[data-site-theme="dark"] #panel-chat .guest-typing-row .typing-bubble {
  background:
    radial-gradient(
      ellipse 110% 90% at 10% 0%,
      rgba(139,108,190,.14) 0%,
      rgba(139,108,190,.04) 50%,
      transparent 76%
    ),
    #3e3a44;

  border-color: rgba(151,121,198,.27);

  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.045),
    0 3px 10px rgba(0,0,0,.10);
}

html[data-site-theme="dark"] #panel-chat .guest-typing-row .typing-dot {
  background: #a991c9;
}

/* =====================================================
   ============ Musique Icare — lecteur messagerie =====
   ===================================================== */

#panel-chat .chat-audio-stack {
  width: min(82vw, 340px);
  max-width: min(82vw, 340px);
  min-width: min(250px, 82vw);
  align-items: flex-start;
}

#panel-chat .chat-audio {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px 10px 10px;
  box-sizing: border-box;
}

#panel-chat .chat-audio-toggle {
  width: 38px;
  height: 38px;
  min-width: 38px;
  flex: 0 0 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #0f8f8d;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 2px 7px rgba(15,143,141,.16);
  transition: transform .12s ease, filter .15s ease, opacity .15s ease;
}

#panel-chat .chat-audio-toggle:hover:not(:disabled) {
  filter: brightness(1.06);
}

#panel-chat .chat-audio-toggle:active:not(:disabled) {
  transform: scale(.95);
}

#panel-chat .chat-audio-toggle:disabled {
  opacity: .42;
  cursor: default;
}

#panel-chat .chat-audio-toggle-icon {
  display: block;
  margin-left: 2px;
  font-size: .83rem;
  line-height: 1;
}

#panel-chat .chat-audio-toggle.is-playing .chat-audio-toggle-icon {
  margin-left: 0;
  font-size: .70rem;
  letter-spacing: -2px;
}

#panel-chat .chat-audio-content {
  flex: 1 1 auto;
  min-width: 0;
}

#panel-chat .chat-audio-title {
  margin: 0 0 5px;
  overflow: hidden;
  color: inherit;
  font-size: .82rem;
  line-height: 1.2;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#panel-chat .chat-audio-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

#panel-chat .chat-audio-progress {
  --audio-progress: #0f8f8d;
  --audio-track: rgba(76, 98, 116, .20);

  flex: 1 1 auto;
  min-width: 0;
  height: 18px;
  margin: 0;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
}

#panel-chat .chat-audio-progress:disabled {
  opacity: .45;
  cursor: default;
}

#panel-chat .chat-audio-progress::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 999px;
  background: var(--audio-track);
}

#panel-chat .chat-audio-progress::-webkit-slider-thumb {
  width: 11px;
  height: 11px;
  margin-top: -4px;
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  border-radius: 50%;
  background: var(--audio-progress);
  box-shadow: 0 1px 3px rgba(15,143,141,.18);
}

#panel-chat .chat-audio-progress::-moz-range-track {
  height: 3px;
  border: 0;
  border-radius: 999px;
  background: var(--audio-track);
}

#panel-chat .chat-audio-progress::-moz-range-progress {
  height: 3px;
  border-radius: 999px;
  background: var(--audio-progress);
}

#panel-chat .chat-audio-progress::-moz-range-thumb {
  width: 11px;
  height: 11px;
  border: 0;
  border-radius: 50%;
  background: var(--audio-progress);
  box-shadow: 0 1px 3px rgba(15,143,141,.18);
}

#panel-chat .chat-audio-time {
  flex: 0 0 auto;
  min-width: 34px;
  color: #758293;
  font-size: .68rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

#panel-chat .chat-audio-element {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

html[data-site-theme="dark"] #panel-chat .chat-audio-time {
  color: #aeb9c2;
}

html[data-site-theme="dark"] #panel-chat .chat-audio-progress {
  --audio-track: rgba(218, 230, 234, .22);
}

@media (max-width: 480px) {
  #panel-chat .chat-audio-stack {
    width: min(88%, 330px);
    max-width: min(88%, 330px);
    min-width: min(230px, 88%);
  }

  #panel-chat .chat-audio {
    gap: 9px;
    padding: 9px 10px 9px 9px;
  }

  #panel-chat .chat-audio-toggle {
    width: 36px;
    height: 36px;
    min-width: 36px;
    flex-basis: 36px;
  }
}
