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

/* ========================================================================
   ★ NEXT-GEN (P3.3) — CANONICAL Z-INDEX SCALE.
   The orb, its chip, the concierge CTA and the toast container all used to sit
   in the 999997–999999 band, so a toast could render BEHIND the orb and the
   CTA/chip collided with it. These tokens give every floating surface a
   deliberate order. Reuse them instead of pasting magic numbers.
   ======================================================================== */
:root {
  --aisg-z-cta: 999997;    /* "Open dashboard" CTA button       */
  --aisg-z-chip: 999998;   /* "Now speaking" agent chip         */
  --aisg-z-orb: 999999;    /* the voice-guide orb (primary)     */
  --aisg-z-toast: 1000000; /* #aisg-toast-container (always above) */
}

#aisg-avp-orb {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: var(--aisg-z-orb, 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: aisgAvpFloat 4.5s ease-in-out infinite;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  -webkit-user-select: none;
  user-select: none;
  /* ★ NEXT-GEN (P1.2): the orb is a touch target — never let iOS delay the tap. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#aisg-avp-orb:hover,
#aisg-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. */
#aisg-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: aisgAvpBreath 4s ease-in-out infinite;
  pointer-events: none;
}

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

#aisg-avp-orb .aisg-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 the orb is armed (always, per `build()`), use the portrait as its face.
   ★ NEXT-GEN (P3.4): this keyed off `aisg-avp-active`, which `build()` no longer
   applies (that class also force-opened the label). `aisg-avp-armed` is set on
   every orb, so the portrait face + hover ring behave exactly as before. */
#aisg-avp-orb.aisg-avp-armed .aisg-avp-icon {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--aisg-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);
}

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

#aisg-avp-orb .aisg-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;
}

#aisg-avp-orb:hover .aisg-avp-label,
#aisg-avp-orb:focus-visible .aisg-avp-label,
/* ★ NEXT-GEN (P3.4): the transient reveal used by handleTap() + every state
   change. Replaces the old permanently-open `aisg-avp-active` label. */
#aisg-avp-orb.aisg-avp-showlabel .aisg-avp-label {
  opacity: 1;
}

/* ★ NEXT-GEN (P3.2): the two states the concierge actually toggles. Previously
   `aisg-avp-holding` and `aisg-avp-cancel` were applied by `_setOrbState()` but had
   NO CSS at all (an invisible no-op). */
#aisg-avp-orb.aisg-avp-holding {
  box-shadow: 0 0 0 6px rgba(205, 133, 63, 0.3),
    0 8px 24px rgba(139, 69, 19, 0.55);
}

#aisg-avp-orb.aisg-avp-holding .aisg-avp-ring {
  border-color: rgba(240, 201, 138, 0.95);
  animation: aisgAvpHold 1.2s ease-in-out infinite;
}

#aisg-avp-orb.aisg-avp-cancel {
  background: radial-gradient(circle at 30% 30%, #ff9f9f, #c0392b 55%, #7b1c14);
}

#aisg-avp-orb.aisg-avp-cancel .aisg-avp-ring {
  border-color: rgba(255, 120, 120, 0.95);
}

@keyframes aisgAvpHold {
  0%, 100% { transform: scale(1); opacity: 0.85; }
  50%      { transform: scale(1.2); opacity: 0.6; }
}

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

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

@media (prefers-reduced-motion: reduce) {
  #aisg-avp-orb,
  #aisg-avp-orb .aisg-avp-ring,
  #aisg-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).
   ======================================================================== */
#aisg-avp-orb.aisg-avp-listening {
  box-shadow: 0 0 0 6px rgba(205, 133, 63, 0.25),
    0 8px 24px rgba(139, 69, 19, 0.55);
}

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

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

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

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

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

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

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

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

@keyframes aisgAvpAttend {
  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.
   ======================================================================== */
/* ========================================================================
   ★ NEXT-GEN LIVENESS (Track C4): honest recovery states. The orb must never
   look like it is listening while the microphone is actually dead.
   ======================================================================== */
#aisg-avp-orb.aisg-avp-reviving {
  background: radial-gradient(circle at 30% 30%, #9fd6ff, #2f7fd0 55%, #14406e);
  box-shadow: 0 8px 26px rgba(47, 127, 208, 0.6),
    inset 0 0 0 2px rgba(255, 255, 255, 0.3);
  animation: aisgAvpPulse 0.9s ease-in-out infinite;
}

#aisg-avp-orb.aisg-avp-deaf {
  background: radial-gradient(circle at 30% 30%, #d9d9d9, #8a8a8a 55%, #4a4a4a);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.4),
    inset 0 0 0 2px rgba(255, 255, 255, 0.2);
  animation: aisgAvpFloat 4.5s ease-in-out infinite;
}

@keyframes aisgAvpPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* ★ INSTANT ACK (Track C4): a bright ring flash the moment a turn is sent, so
   the visitor SEES that she heard them even before audio starts. */
#aisg-avp-orb.aisg-avp-ack .aisg-avp-ring {
  animation: aisgAvpAck 0.45s ease-out 1;
}

@keyframes aisgAvpAck {
  0% { transform: scale(0.7); opacity: 0.9; }
  100% { transform: scale(1.5); opacity: 0; }
}

/* ★ NEXT-GEN (Track B5): latency dev overlay (only mounts when debugLatency is on). */
#aisg-avp-orb .aisg-avp-latency {
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 10px;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.72);
  color: #9fe8ff;
  font-weight: 600;
  pointer-events: none;
  z-index: 2;
}

#aisg-avp-orb.aisg-avp-rest {
  opacity: 0.9;
  animation: aisgAvpRest 5.5s ease-in-out infinite;
}
#aisg-avp-orb.aisg-avp-rest .aisg-avp-ring {
  animation: aisgAvpPing 5s ease-out infinite;
}

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

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

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

@media (prefers-reduced-motion: reduce) {
  #aisg-avp-orb.aisg-avp-listening,
  #aisg-avp-orb.aisg-avp-listening .aisg-avp-ring,
  #aisg-avp-orb.aisg-avp-speaking .aisg-avp-ring,
  #aisg-avp-orb.aisg-avp-thinking .aisg-avp-ring,
  #aisg-avp-orb.aisg-avp-attending .aisg-avp-ring,
  #aisg-avp-orb.aisg-avp-reviving,
  #aisg-avp-orb.aisg-avp-deaf,
  #aisg-avp-orb.aisg-avp-ack .aisg-avp-ring,
  #aisg-avp-orb.aisg-avp-rest,
  #aisg-avp-orb.aisg-avp-rest .aisg-avp-ring,
  #aisg-avp-orb.aisg-avp-doze,
  #aisg-avp-orb.aisg-avp-doze .aisg-avp-ring,
  #aisg-avp-orb.aisg-avp-sleep,
  #aisg-avp-orb.aisg-avp-sleep .aisg-avp-ring,
  /* ★ NEXT-GEN (P3.2): the newly-styled holding state must also respect the
     reduced-motion preference. */
  #aisg-avp-orb.aisg-avp-holding .aisg-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.
   ======================================================================== */
.aisg-avp-chip {
  position: fixed;
  right: 18px;
  bottom: 96px;
  z-index: var(--aisg-z-chip, 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;
}

.aisg-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;
}

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

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

@media (max-width: 480px) {
  #aisg-avp-orb {
    right: 14px;
    /* ★ NEXT-GEN (P3.5): respect the iOS home-bar / Android gesture inset so the
       orb is never trapped under the system UI. */
    bottom: calc(env(safe-area-inset-bottom, 0px) + 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. */
  #aisg-avp-orb .aisg-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;
  }
  /* ★ NEXT-GEN (P3.5): lift the CTA + chip clear of the orb's own pill so the
     three floating surfaces never overlap on a phone. */
  .aisg-concierge-cta {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 150px) !important;
  }
  .aisg-avp-chip {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 210px);
  }
}

/* ========================================================================
   DASHBOARD ORB STYLES — REMOVED (2026-09-20).
   ======================================================================== */

/* There used to be a `body.aisg-dashboard-active #aisg-avp-orb` block here docking
 * the orb at the bottom-right (and top-right in the immersive mobile chat) as
 * the dashboard's "nav hub + live-presence indicator". It styled an element that
 * could never exist: the v2 loop's `canRun()` refused the dashboard, so the orb
 * was never built there, and the dashboard is now excluded at enqueue time in
 * `AISG_Agent_Voice_Presence::maybe_enqueue()`.
 *
 * The dashboard's hostess surface is the "Ask the Hostess" tab
 * (`AISG_Public::render_tab_hostess()`), and its navigation is the 4-tab bottom bar
 * (aisg-responsive-nav.js). Both are unrelated to this stylesheet.
 *
 * Note: `aisg-orb.css` styles `#aisg-avp-orb` itself and is the v2 stylesheet. This
 * file is the LEGACY orb stylesheet — only loaded when `aisg_orb_v2` is 0.
 */

