/* ZIC Landing — Bouton flottant de messagerie (FAB) — home v4 (D3 / D4).
 *
 * Markup : templates/_chat_fab.html (inclus par base.html — home + Discover —
 * et par public/artist_public_stub.html — profil createur).
 *
 *   .zic-chat-fab-wrap   conteneur FIXE (pointer-events:none : seuls les deux
 *                        boutons sont cliquables). Desktop : bas-droite 26 px,
 *                        340 x 58 px ; le bouton rond occupe les 58 px de droite.
 *   .zic-chat-fab-clip   fenetre de clip (overflow:hidden) qui s'arrete 29 px
 *                        avant le bord droit = centre du bouton rond : la
 *                        pastille qui glisse vers la droite « rentre » dans le
 *                        bouton au lieu de le recouvrir.
 *   .zic-chat-fab-pill   pastille « Discute avec tes amis » + 4 avatars
 *                        decoratifs, animation CSS pure en boucle 7 s
 *                        (zic-chat-fab-pillcycle : sort, reste ~3,5 s, rentre),
 *                        en pause au survol du wrap. Ouvreur secondaire.
 *   .zic-chat-fab        bouton rond (ouvreur principal) : anneau PERMANENT
 *                        (.zic-chat-fab-ring, plus rapide avec .has-unread),
 *                        badge vert = vrais non-lus seulement, .is-attention
 *                        one-shot a l'arrivee d'un message (landing-chat-fab.js).
 *
 * Pages :
 *   - desktop : pastille visible home + Discover, jamais sur le profil createur
 *     (body.zh-public-profile-page) ;
 *   - mobile (<= 768) : bouton seul 54 px bas-droite partout, SAUF la home
 *     (body.zh-home-page) : wrap en haut a droite sous la nav (top 98 px +
 *     safe-area — le hero laisse 152 px de padding-top), bouton 46 px,
 *     pastille « verre » ; la pastille disparait des que le hero quitte le
 *     viewport (body.zh-hero-out, pose par landing-home.js).
 *   Cache pendant que l'overlay chat est ouvert (body.zh-chat-overlay-open).
 *
 * z-index : 100 (== nav ; au-dessus du sticky CTA mobile a 90, sous le menu
 * langue 120, le drawer 130/140 et l'overlay chat a 1200).
 */

/* ── Conteneur fixe ─────────────────────────────────────────────────────── */
.zic-chat-fab-wrap {
  position: fixed;
  right: 26px;
  bottom: calc(26px + env(safe-area-inset-bottom, 0px));
  z-index: 100;
  width: 340px;
  height: 58px;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

/* Fenetre de clip : deborde de 10 px en haut / en bas pour laisser passer
   l'ombre de la pastille ; s'arrete au centre du bouton rond (29 px). */
.zic-chat-fab-clip {
  position: absolute;
  top: -10px;
  bottom: -10px;
  left: 0;
  right: 29px;
  overflow: hidden;
  pointer-events: none;
}

/* ── Pastille (ouvreur secondaire) ──────────────────────────────────────── */
.zic-chat-fab-pill {
  position: absolute;
  right: 0;
  top: 10px;
  height: 58px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 40px 0 10px;
  border-radius: 100px 0 0 100px;
  border: 1px solid rgba(123, 63, 242, 0.25);
  border-right: none;
  background: #fff;
  box-shadow: 0 14px 36px -14px rgba(31, 19, 64, 0.45);
  cursor: pointer;
  white-space: nowrap;
  pointer-events: auto;
  will-change: transform;
  transform: translateX(110%);
  animation: zic-chat-fab-pillcycle 7s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  font-family: "DM Sans", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.zic-chat-fab-wrap:hover .zic-chat-fab-pill {
  animation-play-state: paused;
}
/* Focus clavier sur l'un des deux ouvreurs : la pastille reste visible
   (sinon l'outline :focus-visible est rogne par le clip pendant ~50 % du cycle). */
.zic-chat-fab-wrap:focus-within .zic-chat-fab-pill {
  animation: none;
  transform: none;
}

.zic-chat-fab-pill:focus-visible {
  outline: 3px solid rgba(167, 139, 250, 0.9);
  outline-offset: -3px;
}

.zic-chat-fab-avatars {
  display: flex;
}

/* Sélecteur de classe nu : s'applique aux <span> (initiales) ET aux <img>
   (vraies photos, lot 6), y compris la variante mobile 26 px plus bas. */
.zic-chat-fab-av {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #fff;
  margin-left: -9px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  object-fit: cover; /* <img> */
  flex-shrink: 0;
  background: #cbd5e1; /* repli sous une photo (les <span> gardent leur background inline) */
  font-family: "Space Grotesk", sans-serif;
  font-weight: 800;
  font-size: 9.5px;
  color: #fff;
}

.zic-chat-fab-av:first-child {
  margin-left: 0;
}

.zic-chat-fab-pill-txt {
  display: flex;
  flex-direction: column;
  text-align: left;
}

.zic-chat-fab-pill-title {
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: 13.5px;
  color: #1f1340;
}

.zic-chat-fab-pill-sub {
  font-size: 11px;
  color: #6b6383;
}

/* ── Bouton rond (ouvreur principal) ────────────────────────────────────── */
.zic-chat-fab {
  position: absolute;
  right: 0;
  top: 0;
  width: 58px;
  height: 58px;
  padding: 0;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  pointer-events: auto;
  border: 1.5px solid rgba(255, 255, 255, 0.35);
  background: linear-gradient(135deg, #a855f7 0%, #7b3ff2 55%, #5b21b6 100%);
  box-shadow: 0 14px 36px -10px rgba(123, 63, 242, 0.65);
  transition: transform 0.18s ease, box-shadow 0.25s ease, opacity 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.zic-chat-fab:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow:
    0 18px 44px -10px rgba(123, 63, 242, 0.75),
    0 0 0 10px rgba(123, 63, 242, 0.14);
}

.zic-chat-fab:active {
  transform: translateY(0) scale(0.96);
}

.zic-chat-fab:focus-visible {
  outline: 3px solid rgba(167, 139, 250, 0.9);
  outline-offset: 3px;
}

/* Icone deux bulles */
.zic-chat-fab-icon {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
}

.zic-chat-fab-icon svg {
  width: 27px;
  height: 27px;
  display: block;
}

/* Anneau de pulsation PERMANENT (plus rapide / plus dense avec des non-lus). */
.zic-chat-fab-ring {
  position: absolute;
  inset: -6px;
  z-index: 1;
  border-radius: 50%;
  border: 2px solid rgba(168, 85, 247, 0.45);
  opacity: 1;
  pointer-events: none;
  animation: zic-chat-fab-ring 2.4s ease-out infinite;
}

.zic-chat-fab.has-unread .zic-chat-fab-ring {
  animation-duration: 1.4s;
  border-color: rgba(168, 85, 247, 0.75);
}

/* Badge compteur de non-lus (vrai compteur uniquement, hidden si 0). */
.zic-chat-fab-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  z-index: 3;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: #22c55e;
  border: 2px solid #fff;
  color: #fff;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 800;
  font-size: 10px;
  line-height: 16px;
  text-align: center;
  box-sizing: border-box;
  transform-origin: center;
  animation: zic-chat-fab-badge-pop 0.28s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.zic-chat-fab-badge[hidden] {
  display: none;
}

/* Animation "attention" one-shot a l'arrivee d'un nouveau message. */
.zic-chat-fab.is-attention {
  animation: zic-chat-fab-attention 0.85s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

/* Masquer tout le FAB tant que l'overlay chat est ouvert. */
body.zh-chat-overlay-open .zic-chat-fab-wrap {
  opacity: 0;
  pointer-events: none;
}

body.zh-chat-overlay-open .zic-chat-fab-wrap * {
  pointer-events: none;
}

/* Profil createur : jamais de pastille (meme sur desktop), bouton seul. */
body.zh-public-profile-page .zic-chat-fab-clip {
  display: none;
}

/* ── Keyframes ──────────────────────────────────────────────────────────── */

/* Cycle 7 s de la pastille : sort du bouton (0 → 12 %), reste lisible
   (12 → 62 %), rentre (62 → 76 %), pause hors champ (76 → 100 %). */
@keyframes zic-chat-fab-pillcycle {
  0% {
    transform: translateX(110%);
  }
  12% {
    transform: translateX(0);
  }
  62% {
    transform: translateX(0);
  }
  76% {
    transform: translateX(110%);
  }
  100% {
    transform: translateX(110%);
  }
}

@keyframes zic-chat-fab-ring {
  0% {
    transform: scale(0.85);
    opacity: 0.9;
  }
  100% {
    transform: scale(1.35);
    opacity: 0;
  }
}

@keyframes zic-chat-fab-badge-pop {
  0% {
    transform: scale(0);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes zic-chat-fab-attention {
  0%,
  100% {
    transform: rotate(0) scale(1);
  }
  15% {
    transform: rotate(-12deg) scale(1.08);
  }
  30% {
    transform: rotate(10deg) scale(1.08);
  }
  45% {
    transform: rotate(-8deg) scale(1.05);
  }
  60% {
    transform: rotate(6deg) scale(1.03);
  }
  75% {
    transform: rotate(-3deg) scale(1.01);
  }
}

/* ── Mobile (<= 768) ────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Generique (Discover, profil createur…) : bouton seul 54 px bas-droite,
     pas de pastille. */
  .zic-chat-fab-wrap {
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    width: 54px;
    height: 54px;
  }
  .zic-chat-fab {
    width: 54px;
    height: 54px;
  }
  .zic-chat-fab-icon svg {
    width: 26px;
    height: 26px;
  }
  .zic-chat-fab-clip {
    display: none;
  }

  /* Home uniquement (D4) : haut-droite sous la nav, bouton 46 px, pastille
     « verre » sur le hero sombre (masquee des que le hero sort du viewport). */
  body.zh-home-page .zic-chat-fab-wrap {
    top: calc(98px + env(safe-area-inset-top, 0px));
    bottom: auto;
    width: 300px;
    height: 46px;
  }
  body.zh-home-page .zic-chat-fab-clip {
    display: block;
    right: 23px;
  }
  body.zh-home-page .zic-chat-fab-pill {
    height: 46px;
    top: 10px;
    gap: 8px;
    padding: 0 34px 0 8px;
    background: rgba(255, 255, 255, 0.14);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.26);
    border-right: none;
    box-shadow: none;
  }
  body.zh-home-page .zic-chat-fab-pill-title {
    color: #fff;
    font-family: "DM Sans", sans-serif;
    font-weight: 700;
    font-size: 12.5px;
  }
  body.zh-home-page .zic-chat-fab-pill-sub {
    display: none;
  }
  body.zh-home-page .zic-chat-fab-av {
    width: 26px;
    height: 26px;
    border-color: rgba(20, 8, 64, 0.9);
    margin-left: -8px;
    font-size: 10px;
    font-weight: 700;
  }
  body.zh-home-page .zic-chat-fab-av:first-child {
    margin-left: 0;
  }
  body.zh-home-page .zic-chat-fab {
    width: 46px;
    height: 46px;
    border: none;
    box-shadow:
      0 10px 28px -8px rgba(123, 63, 242, 0.7),
      0 0 0 4px rgba(168, 85, 247, 0.22);
  }
  body.zh-home-page .zic-chat-fab-icon svg {
    width: 21px;
    height: 21px;
  }
  body.zh-home-page .zic-chat-fab-ring {
    animation-duration: 2.2s;
  }
  body.zh-home-page .zic-chat-fab-badge {
    min-width: 18px;
    height: 18px;
    top: -4px;
    right: -4px;
    border-color: #1a0840;
    line-height: 14px;
  }
  /* Hero sorti du viewport : la pastille verre serait illisible sur les
     sections claires → on ne garde que le bouton. */
  body.zh-home-page.zh-hero-out .zic-chat-fab-clip {
    display: none;
  }
}

/* ── Reduced motion ─────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  /* Pastille statique (libelle visible, aucun mouvement), anneau cache. */
  .zic-chat-fab-pill {
    animation: none;
    transform: none;
  }
  .zic-chat-fab-ring {
    animation: none;
    opacity: 0;
  }
  .zic-chat-fab-wrap {
    transition: none;
  }
  .zic-chat-fab,
  .zic-chat-fab:hover,
  .zic-chat-fab:active {
    transition: none;
    transform: none;
  }
  .zic-chat-fab.is-attention,
  .zic-chat-fab-badge {
    animation: none;
  }
}
