/* ============================================================
   PIPELINE SOUTH — LEAD-GEN ASSISTANT ("Sipho")
   Self-contained chat widget. Matches pipelinesouth.css tokens.
   Loads AFTER pipelinesouth.css so same-specificity rules win.
   ============================================================ */

/* Launcher lives bottom-LEFT; the site's WhatsApp/Call widget stays bottom-right. */

/* ---------------- LAUNCHER ---------------- */
.psb-launcher {
  position: fixed; bottom: 28px; left: 16px; z-index: 10000;
  width: 62px; height: 62px; border-radius: 50%;
  border: 1.5px solid rgba(255,92,31,0.45); cursor: pointer; padding: 0;
  background: radial-gradient(circle at 32% 28%, #1a1d21 0%, #0a0c0e 100%);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 30px rgba(255,92,31,0.4);
  transition: transform 0.25s var(--ease-spring), box-shadow 0.25s, opacity 0.2s;
}
.psb-launcher:hover { transform: scale(1.07); box-shadow: 0 10px 38px rgba(255,92,31,0.6); }
.psb-launcher:active { transform: scale(0.96); }
.psb-launcher svg { width: 26px; height: 26px; transition: transform 0.3s var(--ease-spring); }
.psb-launcher .psb-ic-chat .pipey { width: 38px; height: 38px; }
.psb-launcher .psb-ic-close { position: absolute; opacity: 0; transform: rotate(-45deg) scale(0.4); }
.psb-launcher .psb-ic-chat  { opacity: 1; transform: rotate(0) scale(1); }
.psb-open .psb-ic-close { opacity: 1; transform: rotate(0) scale(1); }
.psb-open .psb-ic-chat  { opacity: 0; transform: rotate(45deg) scale(0.4); }

/* pulse ring while idle */
.psb-launcher::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid var(--signal); opacity: 0.6;
  animation: psb-pulse 2.4s var(--ease-out) infinite;
}
.psb-open.psb-launcher::after { animation: none; opacity: 0; }
@keyframes psb-pulse {
  0%   { transform: scale(1);    opacity: 0.6; }
  70%  { transform: scale(1.5);  opacity: 0; }
  100% { transform: scale(1.5);  opacity: 0; }
}

/* unread dot */
.psb-launcher .psb-badge {
  position: absolute; top: -2px; right: -2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #25D366; color: #fff; border: 2px solid var(--bg);
  font: 700 10px/1 var(--font-mono);
  display: none; align-items: center; justify-content: center;
}
.psb-has-unread .psb-badge { display: flex; }

/* greeting nudge bubble */
.psb-nudge {
  position: fixed; bottom: 40px; left: 88px; z-index: 9999;
  max-width: 240px;
  background: var(--surface); color: var(--white);
  border: 1px solid var(--faint); border-radius: 14px 14px 14px 4px;
  padding: 12px 14px; font: 500 13.5px/1.5 var(--font-body);
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  opacity: 0; transform: translateY(8px) scale(0.96); pointer-events: none;
  transition: opacity 0.35s var(--ease-out), transform 0.35s var(--ease-spring);
}
.psb-nudge.psb-show { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.psb-nudge strong { color: var(--signal); }
.psb-nudge-close {
  position: absolute; top: -8px; right: -8px; width: 22px; height: 22px;
  border-radius: 50%; border: 1px solid var(--faint); background: var(--bg);
  color: var(--muted); font-size: 13px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.psb-nudge-close:hover { color: var(--white); }

/* ---------------- PANEL ---------------- */
.psb-panel {
  position: fixed; bottom: 100px; left: 16px; z-index: 10000;
  width: 384px; max-width: calc(100vw - 32px);
  height: 620px; max-height: calc(100vh - 130px);
  background: var(--bg-mid);
  border: 1px solid var(--faint); border-radius: 20px;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 24px 70px rgba(0,0,0,0.6);
  opacity: 0; transform: translateY(20px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.3s var(--ease-out), transform 0.32s var(--ease-spring);
}
.psb-panel.psb-show { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }

/* header */
.psb-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px; flex-shrink: 0;
  background: linear-gradient(180deg, var(--surface), var(--bg-mid));
  border-bottom: 1px solid var(--ghost);
}
.psb-head-av {
  width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0;
  background: var(--signal-dim); border: 1px solid var(--signal);
  display: flex; align-items: center; justify-content: center; position: relative;
}
.psb-head-av svg { width: 24px; height: 24px; }
.psb-head-av::after {
  content: ""; position: absolute; bottom: 1px; right: 1px;
  width: 10px; height: 10px; border-radius: 50%;
  background: #25D366; border: 2px solid var(--bg-mid);
}
.psb-head-meta { flex: 1; min-width: 0; }
.psb-head-name { font: 700 15px/1.2 var(--font-body); color: var(--white); }
.psb-head-status {
  font: 500 11px/1.3 var(--font-mono); color: var(--muted);
  letter-spacing: 0.04em; display: flex; align-items: center; gap: 5px;
}
.psb-head-status::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: #25D366;
}
.psb-head-x {
  width: 32px; height: 32px; border-radius: 8px; border: none;
  background: transparent; color: var(--muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: 0.2s;
}
.psb-head-x:hover { background: var(--ghost); color: var(--white); }
.psb-head-x svg { width: 18px; height: 18px; }

/* messages area */
.psb-body {
  flex: 1; overflow-y: auto; padding: 20px 16px 8px;
  display: flex; flex-direction: column; gap: 12px;
  scrollbar-width: thin; scrollbar-color: var(--faint) transparent;
}
.psb-body::-webkit-scrollbar { width: 6px; }
.psb-body::-webkit-scrollbar-thumb { background: var(--faint); border-radius: 3px; }

/* message rows */
.psb-msg { display: flex; gap: 8px; max-width: 100%; animation: psb-in 0.34s var(--ease-out) both; }
@keyframes psb-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.psb-msg-av {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0; margin-top: auto;
  background: var(--signal-dim); border: 1px solid var(--signal);
  display: flex; align-items: center; justify-content: center;
}
.psb-msg-av svg { width: 16px; height: 16px; }
.psb-bubble {
  font: 400 14px/1.55 var(--font-body); padding: 10px 14px;
  border-radius: 16px; word-wrap: break-word; overflow-wrap: anywhere;
}
.psb-bot .psb-bubble {
  background: var(--surface); color: var(--white);
  border: 1px solid var(--ghost); border-bottom-left-radius: 5px;
}
.psb-bot .psb-bubble strong { color: var(--signal); font-weight: 700; }
.psb-bot .psb-bubble a { color: var(--signal); }
.psb-user { justify-content: flex-end; }
.psb-user .psb-bubble {
  background: var(--signal); color: #fff; border-bottom-right-radius: 5px;
  max-width: 78%;
}
.psb-bot { max-width: 90%; }

/* typing indicator */
.psb-typing .psb-bubble { display: flex; gap: 4px; padding: 14px; }
.psb-typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--muted);
  animation: psb-bounce 1.3s infinite;
}
.psb-typing span:nth-child(2) { animation-delay: 0.18s; }
.psb-typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes psb-bounce { 0%,60%,100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-5px); opacity: 1; } }

/* quick-reply chips */
.psb-chips {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 16px 8px 52px;
  animation: psb-in 0.3s var(--ease-out) both;
}
.psb-chip {
  font: 600 12.5px/1 var(--font-body);
  background: transparent; color: var(--signal);
  border: 1px solid rgba(255,92,31,0.5); border-radius: 20px;
  padding: 9px 14px; cursor: pointer; transition: 0.18s;
}
.psb-chip:hover { background: var(--signal); color: #fff; transform: translateY(-1px); }

/* WhatsApp / email handoff card */
.psb-handoff {
  margin: 4px 16px 8px 52px; padding: 14px;
  background: var(--surface); border: 1px solid var(--ghost); border-radius: 14px;
  animation: psb-in 0.34s var(--ease-out) both;
}
.psb-handoff-lead {
  font: 500 12px/1.6 var(--font-mono); color: var(--muted);
  white-space: pre-wrap; margin-bottom: 12px;
  border-left: 2px solid var(--signal); padding-left: 10px;
}
.psb-wa-btn {
  display: flex; align-items: center; justify-content: center; gap: 9px;
  width: 100%; padding: 13px; border-radius: 11px;
  background: #25D366; color: #fff; text-decoration: none;
  font: 700 14.5px/1 var(--font-body);
  box-shadow: 0 6px 20px rgba(37,211,102,0.35); transition: 0.2s;
}
.psb-wa-btn:hover { transform: translateY(-2px); box-shadow: 0 9px 26px rgba(37,211,102,0.5); }
.psb-wa-btn svg { width: 19px; height: 19px; }
.psb-alt {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  margin-top: 9px; padding: 10px; border-radius: 10px;
  background: transparent; border: 1px solid var(--faint);
  color: var(--muted); text-decoration: none;
  font: 600 13px/1 var(--font-body); transition: 0.2s;
}
.psb-alt:hover { color: var(--white); border-color: var(--signal); }
.psb-alt svg { width: 16px; height: 16px; }

/* input dock */
.psb-foot {
  flex-shrink: 0; padding: 12px 14px 14px;
  border-top: 1px solid var(--ghost); background: var(--bg-mid);
}
.psb-input-wrap {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface); border: 1px solid var(--faint);
  border-radius: 14px; padding: 6px 6px 6px 14px;
  transition: border-color 0.2s;
}
.psb-input-wrap:focus-within { border-color: var(--signal); }
.psb-input {
  flex: 1; background: transparent; border: none; resize: none;
  color: var(--white); font: 400 14px/1.5 var(--font-body);
  max-height: 96px; padding: 6px 0; outline: none;
}
.psb-input::placeholder { color: var(--muted); }
.psb-send {
  width: 38px; height: 38px; border-radius: 10px; border: none; flex-shrink: 0;
  background: var(--signal); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: 0.2s;
}
.psb-send:hover { transform: scale(1.06); }
.psb-send:disabled { opacity: 0.4; cursor: default; transform: none; }
.psb-send svg { width: 18px; height: 18px; }
.psb-foot-note {
  text-align: center; margin-top: 8px;
  font: 500 10px/1.3 var(--font-mono); color: var(--faint);
  letter-spacing: 0.04em;
}
.psb-foot-note .accent { color: var(--muted); }

/* ---------------- PIPEY (animated avatar) ---------------- */
.pipey { overflow: visible; }
.pipey-float { animation: pipey-bob 3.4s ease-in-out infinite; transform-origin: center; }
.pipey-eye {
  transform-box: fill-box; transform-origin: center;
  animation: pipey-blink 4.6s infinite;
}
.pipey-eye.r { animation-delay: 0.04s; }
.pipey-ping {
  transform-box: fill-box; transform-origin: center;
  animation: pipey-ping 1.9s ease-in-out infinite;
}
@keyframes pipey-bob  { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-1.6px); } }
@keyframes pipey-blink { 0%,90%,100% { transform: scaleY(1); } 95% { transform: scaleY(0.12); } }
@keyframes pipey-ping { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.45; transform: scale(1.4); } }

/* reduced motion */
@media (prefers-reduced-motion: reduce) {
  .psb-launcher::after { animation: none; }
  .psb-msg, .psb-chips, .psb-handoff { animation: none; }
  .psb-typing span { animation: none; }
  .pipey-float, .pipey-eye, .pipey-ping { animation: none; }
}

/* mobile */
@media (max-width: 480px) {
  .psb-panel {
    bottom: 0; left: 0; right: 0; width: 100vw; max-width: 100vw;
    height: 100dvh; max-height: 100dvh; border-radius: 0;
  }
  .psb-nudge { display: none; }
  .psb-launcher { bottom: 20px; left: 14px; width: 54px; height: 54px; }
}
