/* ========================================================================
   Confidence Talk - Agent Voice Presence (Living Lobby)
   Floating "ambassador" orb — site-wide rotating agent invitations.
   Loaded on all CT pages EXCEPT the dashboard.
   ======================================================================== */

#ct-avp-orb {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 999999;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #f0c98a, #CD853F 55%, #8B4513);
  box-shadow: 0 8px 24px rgba(139, 69, 19, 0.45),
    inset 0 0 0 2px rgba(255, 255, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #fff;
  font-weight: 700;
  font-family: inherit;
  animation: ctAvpFloat 4.5s ease-in-out infinite;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  -webkit-user-select: none;
  user-select: none;
}

#ct-avp-orb:hover,
#ct-avp-orb:focus-visible {
  transform: scale(1.08);
  box-shadow: 0 10px 30px rgba(139, 69, 19, 0.6),
    inset 0 0 0 2px rgba(255, 255, 255, 0.35);
  outline: none;
}

/* ★ ALIVE: a soft "breathing" glow halo behind the orb (cosmetic, optional).
   Rendered as a ::before behind the orb so it never conflicts with the existing
   float / hover / state animations, and it never intercepts clicks. */
#ct-avp-orb::before {
  content: "";
  position: absolute;
  inset: -12px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(205, 133, 63, 0.5), rgba(205, 133, 63, 0) 70%);
  z-index: -1;
  animation: ctAvpBreath 4s ease-in-out infinite;
  pointer-events: none;
}

@keyframes ctAvpBreath {
  0%,
  100% {
    transform: scale(0.9);
    opacity: 0.5;
  }
  50% {
    transform: scale(1.14);
    opacity: 0.9;
  }
}

#ct-avp-orb .ct-avp-icon {
  font-size: 22px;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Once an agent is active and has a portrait, use it as the orb face. */
#ct-avp-orb.ct-avp-active .ct-avp-icon {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--ct-avp-portrait, none) center / cover no-repeat;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35);
  font-size: 18px;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

#ct-avp-orb .ct-avp-ring {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid rgba(205, 133, 63, 0.35);
  animation: ctAvpPing 3s ease-out infinite;
  pointer-events: none;
}

#ct-avp-orb .ct-avp-label {
  position: absolute;
  right: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  background: rgba(20, 16, 10, 0.92);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  padding: 7px 12px;
  border-radius: 999px;
  white-space: nowrap;
  border: 1px solid rgba(205, 133, 63, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  max-width: 60vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

#ct-avp-orb:hover .ct-avp-label,
#ct-avp-orb:focus-visible .ct-avp-label,
#ct-avp-orb.ct-avp-active .ct-avp-label {
  opacity: 1;
}

#ct-avp-orb.ct-avp-loading {
  pointer-events: none;
  opacity: 0.7;
}

#ct-avp-orb.ct-avp-empty {
  animation: none;
}

@keyframes ctAvpFloat {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

@keyframes ctAvpPing {
  0% {
    transform: scale(0.9);
    opacity: 0.9;
  }
  70%,
  100% {
    transform: scale(1.35);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  #ct-avp-orb,
  #ct-avp-orb .ct-avp-ring,
  #ct-avp-orb::before {
    animation: none;
  }
}

/* ========================================================================
   Concierge live states (Batch 0.4) — the orb mirrors the test talk:
   listening (mic pulse), speaking (active glow), thinking (dashed spin).
   ======================================================================== */
#ct-avp-orb.ct-avp-listening {
  box-shadow: 0 0 0 6px rgba(205, 133, 63, 0.25),
    0 8px 24px rgba(139, 69, 19, 0.55);
}

#ct-avp-orb.ct-avp-listening .ct-avp-ring {
  border-color: rgba(240, 201, 138, 0.9);
  animation: ctAvpListen 1.3s ease-out infinite;
}

#ct-avp-orb.ct-avp-speaking .ct-avp-ring {
  border-color: rgba(218, 165, 32, 0.95);
  animation: ctAvpSpeak 1s ease-in-out infinite;
}

#ct-avp-orb.ct-avp-thinking .ct-avp-ring {
  border-style: dashed;
  border-color: rgba(205, 133, 63, 0.6);
  animation: ctAvpThink 1.6s linear infinite;
}

@keyframes ctAvpListen {
  0% {
    transform: scale(1);
    opacity: 0.9;
  }
  70% {
    transform: scale(1.35);
    opacity: 0.35;
  }
  100% {
    transform: scale(1);
    opacity: 0.9;
  }
}

@keyframes ctAvpSpeak {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.18);
    opacity: 0.7;
  }
}

@keyframes ctAvpThink {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Barge-in "I'm listening" state — the guide stopped to attend to the user. */
#ct-avp-orb.ct-avp-attending {
  box-shadow: 0 0 0 6px rgba(74, 222, 128, 0.3),
    0 8px 24px rgba(139, 69, 19, 0.55);
}

#ct-avp-orb.ct-avp-attending .ct-avp-ring {
  border-color: rgba(74, 222, 128, 0.95);
  animation: ctAvpAttend 1.1s ease-in-out infinite;
}

@keyframes ctAvpAttend {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.85;
  }
  50% {
    transform: scale(1.28);
    opacity: 0.55;
  }
}

/* ========================================================================
   NEXT-GEN DORMANCY: rest -> doze -> sleep. When the visitor goes quiet the
   orb calms down (no audio nudges, no spoken "finish") and eventually dims +
   sleeps, closing its mic. A tap wakes it back to listening. The only text is
   the orb's own status pill.
   ======================================================================== */
#ct-avp-orb.ct-avp-rest {
  opacity: 0.9;
  animation: ctAvpRest 5.5s ease-in-out infinite;
}
#ct-avp-orb.ct-avp-rest .ct-avp-ring {
  animation: ctAvpPing 5s ease-out infinite;
}

#ct-avp-orb.ct-avp-doze {
  opacity: 0.7;
  animation: ctAvpRest 7s ease-in-out infinite;
}
#ct-avp-orb.ct-avp-doze .ct-avp-ring {
  opacity: 0.5;
}

#ct-avp-orb.ct-avp-sleep {
  opacity: 0.45;
  box-shadow: 0 5px 16px rgba(139, 69, 19, 0.3);
  animation: ctAvpSleep 8s ease-in-out infinite;
}
#ct-avp-orb.ct-avp-sleep .ct-avp-ring {
  animation: none;
  opacity: 0;
}
#ct-avp-orb.ct-avp-sleep .ct-avp-icon {
  opacity: 0.7;
}
/* While asleep, show a single "Tap to talk" pill so the orb stays discoverable. */
#ct-avp-orb.ct-avp-sleep .ct-avp-label {
  opacity: 0.85;
}

@keyframes ctAvpRest {
  0%,
  100% {
    transform: translateY(0) scale(0.98);
  }
  50% {
    transform: translateY(3px) scale(1.01);
  }
}
@keyframes ctAvpSleep {
  0%,
  100% {
    transform: translateY(0) scale(0.88);
  }
  50% {
    transform: translateY(3px) scale(0.9);
  }
}

@media (prefers-reduced-motion: reduce) {
  #ct-avp-orb.ct-avp-listening,
  #ct-avp-orb.ct-avp-listening .ct-avp-ring,
  #ct-avp-orb.ct-avp-speaking .ct-avp-ring,
  #ct-avp-orb.ct-avp-thinking .ct-avp-ring,
  #ct-avp-orb.ct-avp-attending .ct-avp-ring,
  #ct-avp-orb.ct-avp-rest,
  #ct-avp-orb.ct-avp-rest .ct-avp-ring,
  #ct-avp-orb.ct-avp-doze,
  #ct-avp-orb.ct-avp-doze .ct-avp-ring,
  #ct-avp-orb.ct-avp-sleep,
  #ct-avp-orb.ct-avp-sleep .ct-avp-ring {
    animation: none;
  }
}

/* ========================================================================
   "Now speaking" chip (Batch 1.2) — small pill under the orb during the
   Hear-Them-All carousel. Shows the current agent's face + name.
   ======================================================================== */
.ct-avp-chip {
  position: fixed;
  right: 18px;
  bottom: 96px;
  z-index: 999998;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(20, 16, 10, 0.92);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  padding: 6px 12px 6px 6px;
  border-radius: 999px;
  border: 1px solid rgba(205, 133, 63, 0.45);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
  pointer-events: none;
  white-space: nowrap;
}

.ct-avp-chip-face {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #CD853F;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  overflow: hidden;
}

.ct-avp-chip-name {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 480px) {
  .ct-avp-chip {
    right: 12px;
    bottom: 80px;
  }
  .ct-avp-chip-name {
    max-width: 120px;
  }
}

@media (max-width: 480px) {
  #ct-avp-orb {
    right: 14px;
    bottom: 16px;
    width: 68px;
    height: 68px;
  }
  /* Show the status pill ABOVE the orb so the talk/listen state is always
     readable on a small screen. Anchor it to the right edge so it grows leftward
     and never clips off either side. */
  #ct-avp-orb .ct-avp-label {
    right: 0;
    left: auto;
    top: auto;
    bottom: calc(100% + 12px);
    transform: none;
    max-width: 80vw;
    white-space: normal;
    text-align: left;
    font-size: 13px;
    padding: 8px 14px;
  }
}
