/* ---- AI Floating Bubble — iridescent pearlescent orb ---- */

:root {
  --orb-void:   #06000f;
  --orb-deep:   #12002a;
  --orb-purple: #2d0a5e;
  --orb-lilac:  #c084fc;
  --orb-ink:    rgba(255,255,255,.88);
  --orb-dim:    rgba(255,255,255,.45);
  --orb-ease:   cubic-bezier(.25,1,.5,1);
}

/* ================================================================
   WRAPPER
   ================================================================ */

#ai-bubble-wrap {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 14px;
  font-family: 'Switzer','Helvetica Neue',Helvetica,Arial,sans-serif;
}

/* ================================================================
   TRIGGER — unified pill: orb on left + label on right
   ================================================================ */

#ai-bubble-trigger {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 5px 18px 5px 5px;
  background: rgba(6,0,15,.84);
  border: 1px solid rgba(192,132,252,.18);
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow:
    0 8px 36px rgba(6,0,15,.88),
    0 0 0 1px rgba(124,58,237,.08),
    0 0 40px rgba(124,58,237,.08);
  transition: border-color .3s, box-shadow .35s;
  /* Gentle levitation on the whole pill */
  animation: orb-float 3.8s ease-in-out infinite;
}

#ai-bubble-trigger:hover {
  border-color: rgba(192,132,252,.38);
  box-shadow:
    0 8px 36px rgba(6,0,15,.92),
    0 0 0 1px rgba(124,58,237,.15),
    0 0 52px rgba(168,85,247,.18);
}

/* Orb container inside the pill */
.trigger-orb {
  width: 50px;
  height: 50px;
  flex-shrink: 0;
  position: relative;
}

/* The SVG inside the pill */
.orb-svg {
  width: 50px;
  height: 50px;
  display: block;
  overflow: visible;
  transition: transform .38s var(--orb-ease);
}

#ai-bubble-trigger:hover .orb-svg {
  transform: scale(1.1);
}

/* Text label */
.trigger-label {
  font-size: 12px;
  font-weight: 500;
  color: rgba(255,255,255,.35);
  letter-spacing: -.02em;
  white-space: nowrap;
  padding-left: 12px;
  flex: 1;
  min-width: 128px;
  pointer-events: none;
  transition: color .3s;
}

#ai-bubble-trigger:hover .trigger-label {
  color: rgba(255,255,255,.55);
}

/* Open state: label changes in JS, arrow rotates */
#ai-bubble-trigger[aria-expanded="true"] .trigger-label {
  color: rgba(192,132,252,.7);
}

/* Arrow icon */
.trigger-arrow {
  font-size: 14px;
  color: rgba(192,132,252,.45);
  pointer-events: none;
  padding-left: 10px;
  transition: transform .35s var(--orb-ease), color .3s;
}

#ai-bubble-trigger:hover .trigger-arrow {
  color: rgba(192,132,252,.75);
  transform: translate(2px, -2px);
}

#ai-bubble-trigger[aria-expanded="true"] .trigger-arrow {
  transform: rotate(90deg);
  color: rgba(192,132,252,.7);
}

/* --- Float keyframe --- */
@keyframes orb-float {
  0%, 100% { transform: translateY(0px); }
  50%       { transform: translateY(-6px); }
}

/* ================================================================
   SVG LAYER ANIMATIONS
   All 8 seconds, staggered with negative delays for organic feel.
   transform-box: fill-box makes transform-origin work per-element.
   ================================================================ */

/* All animated SVG children get fill-box so transforms are local */
.orb-aura,
.orb-irid-el,
.orb-hl-el,
.orb-ribbon-el,
.orb-dot-el,
.orb-iglow-el,
.orb-rim-el {
  transform-box: fill-box;
  transform-origin: center;
}

/* --- Outer aura: slow breathing glow --- */
.orb-aura {
  animation: orb-aura-breath 8s ease-in-out infinite;
}
@keyframes orb-aura-breath {
  0%, 100% { opacity: .18; transform: scale(1);    }
  45%       { opacity: .32; transform: scale(1.07); }
  72%       { opacity: .20; transform: scale(1.02); }
}

/* --- Iridescent layer: slow hue drift --- */
.orb-irid-el {
  animation: orb-irid-shift 8s ease-in-out infinite;
  animation-delay: -1.5s;
}
@keyframes orb-irid-shift {
  0%, 100% { filter: hue-rotate(0deg)   brightness(1);    opacity: 1;    }
  35%       { filter: hue-rotate(20deg)  brightness(1.08); opacity: .92;  }
  68%       { filter: hue-rotate(-12deg) brightness(.97);  opacity: 1.04; }
}

/* --- Main white highlight: drifts gently across upper surface --- */
.orb-hl-el {
  animation: orb-hl-drift 8s ease-in-out infinite;
  animation-delay: -.6s;
}
@keyframes orb-hl-drift {
  0%,  100% { transform: translate(0px,  0px)  scale(1, 1);         opacity: .88; }
  18%        { transform: translate(4px, -3px)  scale(1.08, .94);    opacity: .95; }
  40%        { transform: translate(-2px, 4px)  scale(.93, 1.07);    opacity: .78; }
  65%        { transform: translate(-5px, 1px)  scale(1.05, .98);    opacity: .92; }
  82%        { transform: translate(2px, -1px)  scale(1.02, 1.01);   opacity: .86; }
}

/* --- Ribbon of pink-magenta light on the right, flowing --- */
.orb-ribbon-el {
  animation: orb-ribbon-flow 8s ease-in-out infinite;
  animation-delay: -2.1s;
}
@keyframes orb-ribbon-flow {
  0%,  100% { transform: translate(0px,  0px)  rotate(0deg)   scaleX(1);    opacity: .70; }
  22%        { transform: translate(3px, -5px)  rotate(7deg)   scaleX(.80);  opacity: .88; }
  46%        { transform: translate(-3px, 6px)  rotate(-6deg)  scaleX(1.22); opacity: .58; }
  70%        { transform: translate(5px, -2px)  rotate(5deg)   scaleX(.90);  opacity: .82; }
}

/* --- Sharp dot highlight: tiny organic drift --- */
.orb-dot-el {
  animation: orb-dot-shift 8s ease-in-out infinite;
  animation-delay: -1.0s;
}
@keyframes orb-dot-shift {
  0%,  100% { transform: translate(0px,  0px); opacity: .92; }
  22%        { transform: translate(2px, -2px); opacity: 1.0; }
  52%        { transform: translate(-1px, 2px); opacity: .70; }
  76%        { transform: translate(-2px, 0px); opacity: .85; }
}

/* --- Inner luminosity: slow breathing --- */
.orb-iglow-el {
  animation: orb-iglow-breath 8s ease-in-out infinite;
  animation-delay: -3.2s;
}
@keyframes orb-iglow-breath {
  0%,  100% { opacity: .50; }
  42%        { opacity: .90; }
  70%        { opacity: .42; }
}

/* --- Rim light: gentle pulse --- */
.orb-rim-el {
  animation: orb-rim-breath 8s ease-in-out infinite;
  animation-delay: -4.0s;
}
@keyframes orb-rim-breath {
  0%,  100% { opacity: .85; }
  45%        { opacity: 1.0; }
  72%        { opacity: .78; }
}


/* ================================================================
   PANEL
   ================================================================ */

#ai-bubble-panel {
  width: 375px;
  height: 510px;
  background: var(--orb-void);
  border: 1px solid rgba(192,132,252,.16);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transform: scale(.82) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform .4s var(--orb-ease), opacity .32s;
  box-shadow:
    0 32px 80px rgba(6,0,15,.95),
    0 0 0 1px rgba(124,58,237,.1),
    0 0 80px rgba(124,58,237,.1);
}

#ai-bubble-panel.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* Header */
.bubble-head {
  position: relative;
  background: linear-gradient(135deg, var(--orb-deep) 0%, var(--orb-purple) 100%);
  padding: 13px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(192,132,252,.12);
  overflow: hidden;
}

.bubble-head::after {
  content: '';
  position: absolute;
  right: -18px;
  top: -18px;
  width: 80px;
  height: 80px;
  background: radial-gradient(circle, rgba(168,85,247,.18) 0%, transparent 70%);
  pointer-events: none;
}

/* Mini static orb in header */
.bubble-head-orb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 34%, #e9d5ff 0%, #c084fc 30%, #7c3aed 65%, #2d0a5e 100%);
  box-shadow: 0 0 10px rgba(168,85,247,.45), inset 0 0 6px rgba(255,255,255,.18);
  flex-shrink: 0;
  animation: mini-orb-glow 4s ease-in-out infinite;
}

@keyframes mini-orb-glow {
  0%, 100% { box-shadow: 0 0 8px rgba(168,85,247,.4);  }
  50%       { box-shadow: 0 0 16px rgba(168,85,247,.7); }
}

.bubble-head-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.bubble-head-name {
  font-size: 12.5px;
  font-weight: 600;
  color: #fff;
  letter-spacing: -.025em;
}

.bubble-head-status {
  font-size: 10px;
  color: var(--orb-lilac);
  letter-spacing: .04em;
  text-transform: uppercase;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
}

.bubble-head-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--orb-lilac);
  flex-shrink: 0;
  animation: dot-pulse 2.8s ease-in-out infinite;
}

@keyframes dot-pulse {
  0%, 100% { opacity: 1;  transform: scale(1);  box-shadow: 0 0 5px var(--orb-lilac); }
  50%       { opacity: .4; transform: scale(.6); box-shadow: none; }
}

.bubble-head-close {
  width: 28px;
  height: 28px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.06);
  border-radius: 50%;
  color: var(--orb-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  padding: 0;
  transition: background .2s, border-color .2s, color .2s;
  flex-shrink: 0;
}

.bubble-head-close:hover {
  background: rgba(168,85,247,.2);
  border-color: rgba(168,85,247,.5);
  color: var(--orb-lilac);
}

/* Log */
.bubble-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(192,132,252,.15) transparent;
}

.bubble-log::-webkit-scrollbar { width: 3px; }
.bubble-log::-webkit-scrollbar-thumb {
  background: rgba(192,132,252,.2);
  border-radius: 3px;
}

/* Messages */
.bubble-msg { display: flex; flex-direction: column; gap: 4px; }

.bubble-msg-who {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(255,255,255,.28);
}

.bubble-msg.bubble-user .bubble-msg-who {
  align-self: flex-end;
  color: rgba(192,132,252,.55);
}

.bubble-msg-body {
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--orb-ink);
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 12px;
  padding: 9px 13px;
  max-width: 90%;
  word-break: break-word;
}

.bubble-msg.bubble-user .bubble-msg-body {
  align-self: flex-end;
  background: rgba(45,10,94,.5);
  border-color: rgba(124,58,237,.35);
}

.bubble-msg-body.pending {
  color: rgba(255,255,255,.3);
  font-style: italic;
}

/* Markdown */
.bubble-msg-body.md p               { margin: 0 0 .45em; }
.bubble-msg-body.md p:last-child    { margin: 0; }
.bubble-msg-body.md ul,
.bubble-msg-body.md ol              { margin: .2em 0; padding-left: 1.3em; }
.bubble-msg-body.md li              { margin-bottom: .2em; }
.bubble-msg-body.md a               { color: var(--orb-lilac); text-decoration: underline; }
.bubble-msg-body.md strong          { color: #f0abfc; font-weight: 600; }
.bubble-msg-body.md code {
  font-size: 11px;
  background: rgba(168,85,247,.15);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: 'SF Mono','Fira Code',monospace;
  color: var(--orb-lilac);
}

/* Full-chat link */
.bubble-full-link {
  text-align: center;
  padding: 5px 14px 8px;
  flex-shrink: 0;
}

.bubble-full-link a {
  font-size: 10.5px;
  font-weight: 600;
  color: rgba(168,85,247,.65);
  letter-spacing: .02em;
  text-decoration: none;
  transition: color .2s;
}

.bubble-full-link a:hover { color: var(--orb-lilac); }

/* Form */
.bubble-form {
  display: flex;
  gap: 8px;
  padding: 10px 12px 14px;
  border-top: 1px solid rgba(192,132,252,.08);
  flex-shrink: 0;
}

.bubble-form input {
  flex: 1;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px;
  color: #fff;
  font-family: inherit;
  font-size: 12px;
  letter-spacing: -.02em;
  padding: 9px 13px;
  outline: none;
  transition: border-color .25s, background .25s;
}

.bubble-form input:focus {
  border-color: rgba(168,85,247,.5);
  background: rgba(168,85,247,.06);
}

.bubble-form input::placeholder { color: rgba(255,255,255,.22); }

.bubble-form button[type="submit"] {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #5b21b6, #9333ea);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 15px;
  font-weight: 600;
  transition: opacity .2s, transform .15s;
}

.bubble-form button[type="submit"]:hover:not(:disabled) {
  opacity: .85;
  transform: scale(1.07);
}

.bubble-form button[type="submit"]:disabled {
  opacity: .3;
  cursor: not-allowed;
}

/* Mobile */
@media (max-width: 520px) {
  #ai-bubble-wrap    { bottom: 16px; right: 16px; }
  .orb-svg           { width: 44px; height: 44px; }
  .trigger-orb       { width: 44px; height: 44px; }
  #ai-bubble-trigger { padding: 4px 14px 4px 4px; }
  .trigger-label     { min-width: 100px; font-size: 11px; }
  #ai-bubble-panel   { width: calc(100vw - 32px); height: 440px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  #ai-bubble-trigger,
  .orb-aura, .orb-irid-el, .orb-hl-el,
  .orb-ribbon-el, .orb-dot-el, .orb-iglow-el,
  .orb-rim-el, .bubble-head-orb, .bubble-head-dot { animation: none; }
  #ai-bubble-panel { transition: opacity .15s; }
}
