/* ═════════════════════════════════════════════════════════════════════
   eVamb v12.1 — Ask Buddy widget (retokenized to v12.0 palette)
   Extracted from neekos.evamb.com / cultivated v7.x build.
   Connects to Supabase project efykgrkrsolbuotpunow (buddy_handoffs table)
   ═════════════════════════════════════════════════════════════════════ */

/* Local Buddy-only color tokens — mapped to v12.0 brand palette */
#buddy-root {
  --gold:        #FFCB47;   /* was old gold, now saffron-2 */
  --gold-warm:   #FFB347;
  --gold-deep:   #E69B2A;
  --static-1:    rgba(248, 250, 252, 0.96);
  --static-2:    rgba(248, 250, 252, 0.62);
  --static-3:    rgba(248, 250, 252, 0.38);
  --ink:         #0A1428;
  --ink-2:       #0F1B36;
  --bd-divider:  rgba(248, 250, 252, 0.12);
  --buddy-bg:    rgba(15, 27, 54, 0.96);
  --buddy-fg:    #F8FAFC;
  --buddy-fg-2:  rgba(248, 250, 252, 0.72);
  --buddy-accent:#FFCB47;
  --buddy-accent-2:#2DD4BF;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--buddy-fg);
}

/* Status pills inside KB answers */
#buddy-root .bd-pill {
  display: inline-block;
  padding: 2px 8px; border-radius: 999px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 9px; letter-spacing: 0.12em; text-transform: uppercase;
  background: rgba(248, 250, 252, 0.08);
  color: var(--buddy-fg-2);
  border: 1px solid rgba(248, 250, 252, 0.18);
  margin: 0 2px;
  vertical-align: middle;
}
#buddy-root .bd-pill-live {
  background: rgba(45, 212, 191, 0.12);
  color: #5EEAD4;
  border-color: rgba(45, 212, 191, 0.4);
}

/* ─── FAB ─── */
.buddy-fab {
  pointer-events: auto;
  position: fixed;
  right: clamp(16px, 2.8vw, 28px);
  bottom: clamp(16px, 2.6vw, 28px);
  width: 60px; height: 60px;
  border: 0; padding: 0;
  background: transparent;
  cursor: pointer;
  color: var(--polar);
  display: grid; place-items: center;
  isolation: isolate;
  transition: transform .35s cubic-bezier(.2,.7,.2,1);
}
.buddy-fab:hover { transform: translateY(-2px); }
.buddy-fab:focus-visible {
  outline: 2px solid var(--plasma);
  outline-offset: 4px;
  border-radius: 50%;
}

.buddy-fab-glow {
  position: absolute; inset: -14px;
  background: radial-gradient(circle at 50% 50%,
    rgba(139, 92, 246, 0.55) 0%,
    rgba(34, 211, 238, 0.22) 45%,
    transparent 72%);
  filter: blur(10px);
  opacity: .85;
  z-index: -2;
  animation: buddy-glow 4.2s ease-in-out infinite;
}
@keyframes buddy-glow {
  0%, 100% { opacity: .75; transform: scale(1); }
  50%      { opacity: 1;   transform: scale(1.06); }
}

.buddy-fab-ring {
  position: absolute; inset: 0;
  border-radius: 50%;
  background: conic-gradient(from 0deg,
    var(--quantum), var(--plasma), var(--quantum));
  z-index: -1;
  animation: buddy-spin 8s linear infinite;
}
@keyframes buddy-spin { to { transform: rotate(360deg); } }

.buddy-fab-core {
  position: relative;
  width: 54px; height: 54px;
  border-radius: 50%;
  background: linear-gradient(180deg, #0E0E18 0%, #05060B 100%);
  display: grid; place-items: center;
  color: var(--polar);
  box-shadow:
    inset 0 1px 0 rgba(241, 245, 249, 0.08),
    inset 0 0 14px rgba(139, 92, 246, 0.18);
}
.buddy-fab.is-active .buddy-fab-core {
  background: var(--grad-brand);
  color: var(--deep-space);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.4),
    0 8px 28px -8px rgba(34, 211, 238, 0.55);
}

.buddy-fab-pulse {
  position: absolute;
  top: 6px; right: 6px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.7);
  animation: buddy-pulse 2.4s ease-out infinite;
}
@keyframes buddy-pulse {
  0%   { box-shadow: 0 0 0 0   rgba(52, 211, 153, 0.7); }
  70%  { box-shadow: 0 0 0 11px rgba(52, 211, 153, 0); }
  100% { box-shadow: 0 0 0 0   rgba(52, 211, 153, 0); }
}
.buddy-fab.is-active .buddy-fab-pulse { display: none; }

.buddy-fab-tag {
  position: absolute;
  right: 70px; top: 50%;
  transform: translateY(-50%) translateX(8px);
  opacity: 0;
  padding: 6px 11px;
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--polar);
  background: rgba(14, 14, 24, 0.92);
  border: 1px solid var(--line-warm);
  border-radius: 8px;
  white-space: nowrap;
  pointer-events: none;
  backdrop-filter: blur(8px);
  transition: opacity .25s ease, transform .25s ease;
}
.buddy-fab:hover .buddy-fab-tag {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}
.buddy-fab.is-active .buddy-fab-tag { display: none; }

/* ---------------------------------------- */
.buddy-panel {
  pointer-events: auto;
  position: fixed;
  right: clamp(16px, 2.8vw, 28px);
  bottom: calc(clamp(16px, 2.6vw, 28px) + 78px);
  width: min(380px, calc(100vw - 32px));
  max-height: min(640px, calc(100dvh - 140px));
  display: flex; flex-direction: column;
  background: rgba(10, 10, 18, 0.92);
  border: 1px solid var(--line-warm);
  border-radius: 18px;
  box-shadow:
    0 30px 80px -28px rgba(0,0,0,0.75),
    0 12px 28px -12px rgba(139, 92, 246, 0.28),
    inset 0 1px 0 rgba(241, 245, 249, 0.04);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  overflow: hidden;
  transform: translateY(14px) scale(0.985);
  opacity: 0;
  transition: opacity .26s cubic-bezier(.2,.7,.2,1), transform .26s cubic-bezier(.2,.7,.2,1);
}
.buddy-panel.is-open { transform: translateY(0) scale(1); opacity: 1; }

/* Subtle aurora glow inside the panel */
.buddy-panel::before {
  content: '';
  position: absolute;
  inset: -1px;
  background:
    radial-gradient(420px 220px at 20% -10%, rgba(139, 92, 246, 0.18), transparent 60%),
    radial-gradient(420px 220px at 100% 110%, rgba(34, 211, 238, 0.15), transparent 60%);
  pointer-events: none;
  z-index: 0;
}

/* ---------------------------------------- */
.buddy-header {
  position: relative; z-index: 1;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(139, 92, 246, 0.06) 0%, transparent 100%);
}
.buddy-id { display: flex; align-items: center; gap: 11px; min-width: 0; }
.buddy-avatar {
  position: relative;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--grad-brand);
  display: grid; place-items: center;
  flex: 0 0 auto;
  box-shadow: 0 6px 18px -6px rgba(139, 92, 246, 0.6);
}
.buddy-avatar-inner {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--polar);
  box-shadow: 0 0 14px rgba(241, 245, 249, 0.6);
}
.buddy-id-text { min-width: 0; }
.buddy-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.005em;
  display: flex; align-items: center; gap: 8px;
}
.buddy-online {
  font-size: 9px;
  letter-spacing: 0.18em;
  color: var(--mint);
  transition: color .25s ease;
}
/* v7.1: AWAY state ---------------------------------------- */
.buddy-online.buddy-away {
  color: var(--static-2);
}
.buddy-role {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--static-2);
  margin-top: 2px;
}
.buddy-close {
  background: rgba(241, 245, 249, 0.05);
  border: 1px solid var(--line);
  color: var(--static);
  width: 30px; height: 30px; border-radius: 9px;
  display: grid; place-items: center;
  cursor: pointer;
  transition: all .2s ease;
  flex: 0 0 auto;
}
.buddy-close:hover { color: var(--polar); border-color: var(--plasma); }
.buddy-close:focus-visible { outline: 2px solid var(--plasma); outline-offset: 2px; }

/* ---------------------------------------- */
.buddy-body {
  position: relative; z-index: 1;
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex; flex-direction: column; gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(241,245,249,0.18) transparent;
}
.buddy-body::-webkit-scrollbar { width: 6px; }
.buddy-body::-webkit-scrollbar-thumb {
  background: rgba(241,245,249,0.18);
  border-radius: 3px;
}

/* ---------------------------------------- */
.buddy-row {
  display: flex;
  gap: 8px;
  animation: buddy-enter .32s cubic-bezier(.2,.7,.2,1);
}
@keyframes buddy-enter {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.buddy-row-user { justify-content: flex-end; }
.buddy-row-bot  { justify-content: flex-start; }

.buddy-bubble-avatar {
  flex: 0 0 auto;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--grad-brand);
  display: grid; place-items: center;
  margin-top: 4px;
  box-shadow: 0 3px 10px -4px rgba(139, 92, 246, 0.6);
}
.bba-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--polar);
}

.buddy-bubble-stack {
  display: flex; flex-direction: column; gap: 8px;
  max-width: 84%;
  min-width: 0;
}

.buddy-bubble {
  font-size: 13.5px;
  line-height: 1.55;
  padding: 10px 13px;
  border-radius: 13px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.buddy-bubble a { color: var(--plasma); border-bottom: 1px solid rgba(34, 211, 238, 0.35); }
.buddy-bubble a:hover { color: var(--polar); border-bottom-color: var(--polar); }
.buddy-bubble b { color: var(--polar); font-weight: 600; }
.buddy-bubble i { color: var(--static-3); font-style: italic; }

.buddy-bubble-bot {
  background: rgba(241, 245, 249, 0.05);
  border: 1px solid var(--line);
  color: var(--static-3);
  border-top-left-radius: 4px;
}
.buddy-bubble-user {
  background: var(--grad-brand);
  color: var(--deep-space);
  font-weight: 500;
  max-width: 80%;
  border-top-right-radius: 4px;
  box-shadow: 0 4px 14px -6px rgba(34, 211, 238, 0.45);
}
.buddy-bubble-user::selection { background: rgba(5, 6, 11, 0.4); color: var(--polar); }

/* small KB UI fragments injected from KB strings */
.bd-mono {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--static);
  margin-right: 4px;
}
.bd-pill {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.14em;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--line-warm);
  vertical-align: middle;
  margin-left: 4px;
}
.bd-pill-live    { color: var(--mint);   border-color: rgba(52, 211, 153, 0.45);  background: rgba(52, 211, 153, 0.08); }
.bd-pill-trial   { color: var(--plasma); border-color: rgba(34, 211, 238, 0.45);  background: rgba(34, 211, 238, 0.08); }
.bd-pill-pilot   { color: var(--quantum);border-color: rgba(139, 92, 246, 0.55);  background: rgba(139, 92, 246, 0.10); }
.bd-pill-roadmap { color: var(--static); border-color: var(--line-warm); }

/* ---------------------------------------- */
.buddy-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 2px;
}
.buddy-chip {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  color: var(--static-3);
  padding: 6px 11px;
  border-radius: 999px;
  background: rgba(241, 245, 249, 0.04);
  border: 1px solid var(--line-warm);
  cursor: pointer;
  transition: all .2s ease;
  white-space: nowrap;
}
.buddy-chip:hover {
  color: var(--polar);
  border-color: var(--plasma);
  background: rgba(34, 211, 238, 0.07);
  transform: translateY(-1px);
}
.buddy-chip:focus-visible { outline: 2px solid var(--plasma); outline-offset: 2px; }

/* ---------------------------------------- */
.buddy-cta {
  margin-top: 4px;
  align-self: flex-start;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 12.5px;
  color: var(--deep-space);
  background: var(--grad-brand);
  background-size: 200% 200%;
  border: 0;
  padding: 9px 16px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 6px 22px -10px rgba(34, 211, 238, 0.6);
  animation: btn-breath 5s ease-in-out infinite;
  transition: transform .25s ease;
}
.buddy-cta:hover { transform: translateY(-1px); }
.buddy-cta:focus-visible { outline: 2px solid var(--plasma); outline-offset: 2px; }
.buddy-arrow { display: inline-block; transition: transform .25s ease; margin-left: 4px; }
.buddy-cta:hover .buddy-arrow { transform: translateX(2px); }

/* ---------------------------------------- */
.buddy-typing {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 12px 14px;
}
.td {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--static);
  animation: buddy-dot 1s ease-in-out infinite;
}
.td:nth-child(2) { animation-delay: .12s; }
.td:nth-child(3) { animation-delay: .24s; }
@keyframes buddy-dot {
  0%, 80%, 100% { opacity: .3; transform: translateY(0); }
  40%           { opacity: 1;  transform: translateY(-3px); }
}

/* ---------------------------------------- */
.buddy-input {
  position: relative; z-index: 1;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px 8px;
  border-top: 1px solid var(--line);
  background: rgba(5, 6, 11, 0.45);
}
.buddy-input-text {
  flex: 1 1 auto;
  background: rgba(241, 245, 249, 0.04);
  border: 1px solid var(--line-warm);
  border-radius: 999px;
  padding: 10px 16px;
  color: var(--polar);
  font-family: var(--font-body);
  font-size: 13.5px;
  outline: 0;
  transition: border-color .2s ease, background .2s ease;
}
.buddy-input-text::placeholder { color: var(--static); }
.buddy-input-text:focus {
  border-color: var(--plasma);
  background: rgba(34, 211, 238, 0.05);
}
.buddy-send {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--grad-brand);
  color: var(--deep-space);
  border: 0;
  display: grid; place-items: center;
  cursor: pointer;
  transition: transform .25s ease, box-shadow .25s ease;
  box-shadow: 0 6px 18px -6px rgba(34, 211, 238, 0.55);
}
.buddy-send:hover { transform: translateY(-1px); }
.buddy-send:focus-visible { outline: 2px solid var(--plasma); outline-offset: 2px; }

.buddy-foot {
  position: relative; z-index: 1;
  text-align: center;
  font-size: 9.5px;
  letter-spacing: 0.1em;
  color: var(--static);
  padding: 0 12px 10px;
  background: rgba(5, 6, 11, 0.45);
}
.buddy-foot a { color: var(--plasma); }
.buddy-foot a:hover { color: var(--polar); }

/* ---------------------------------------- */
@media (max-width: 540px) {
  .buddy-panel {
    right: 8px; left: 8px;
    width: auto;
    bottom: 80px;
    max-height: min(70dvh, 560px);
  }
  .buddy-fab { right: 14px; bottom: 14px; }
  .buddy-fab-tag { display: none; }
}

/* ---------------------------------------- */
@media (max-height: 620px) {
  .buddy-panel { max-height: calc(100dvh - 110px); }
}

/* ---------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .buddy-fab-glow, .buddy-fab-ring, .buddy-fab-pulse,
  .buddy-cta, .td { animation: none !important; }
  .buddy-panel { transition: opacity .15s linear !important; transform: none !important; }
}

/* ---------------------------------------- */
.buddy-handoff {
  display: flex; flex-direction: column; gap: 9px;
  margin-top: 4px;
  padding: 11px;
  background: rgba(5, 6, 11, 0.55);
