/* R-Support widget — CSS variables driven from server settings.
   Defaults below are the «classic» preset and act as a fallback if
   /api/widget/settings hasn't loaded yet. */

#rsup-root {
  --rsup-primary:        #4a7bff;
  --rsup-secondary:      #2d5bdc;
  --rsup-accent:         #4a7bff;
  --rsup-bg-panel:       #ffffff;
  --rsup-bg-chat:        #f7f9fc;
  --rsup-text:           #1a1d24;
  --rsup-text-muted:     #6b7280;
  --rsup-user-bg:        linear-gradient(135deg,#4a7bff 0%,#2d5bdc 100%);
  --rsup-user-text:      #ffffff;
  --rsup-ai-bg:          #ffffff;
  --rsup-ai-text:        #1a1d24;
  --rsup-op-bg:          #e8f3eb;
  --rsup-op-text:        #1a1d24;
  --rsup-border:         #e3e7ef;
  --rsup-radius-panel:   14px;
  --rsup-radius-bubble:  14px;
  --rsup-font:           -apple-system, BlinkMacSystemFont, "Segoe UI",
                         "Roboto", "Helvetica Neue", Arial, sans-serif;
  --rsup-font-display:   -apple-system, BlinkMacSystemFont, "Segoe UI",
                         "Roboto", "Helvetica Neue", Arial, sans-serif;
  --rsup-glow:           0 0 0 transparent; /* disabled by default */
}

#rsup-root, #rsup-root * { box-sizing: border-box; }
#rsup-root {
  position: fixed;
  /* Default anchor: bottom-right. `.rsup-pos-right` reaffirms it and
     `.rsup-pos-left` overrides via `right: auto; left: …`. The default
     matters when `/api/widget/settings` fails (e.g. on a brand-new
     embed before CORS is sorted) — without it the launcher would land
     at (0,0) hidden behind the site's header. */
  right: 24px; bottom: 24px;
  z-index: 2147483000;
  font-family: var(--rsup-font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--rsup-text);
}
#rsup-root.rsup-pos-right { right: 24px; bottom: 24px; }
#rsup-root.rsup-pos-left  { right: auto; left: 24px; bottom: 24px; }

/* ───── Launcher ───────────────────────────────────────────── */
#rsup-root .rsup-launcher {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: var(--rsup-user-bg);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow:
    0 6px 20px rgba(45, 91, 220, 0.40),
    0 1px 4px rgba(0,0,0,0.10),
    var(--rsup-glow);
  /* Two transitions stacked: fast hover (0.18s) and the genie open/close
     (0.28s, easeOutExpo). When `.rsup-open` is added the launcher
     shrinks + fades out exactly while the panel scales up — visually
     the panel «emerges from» the icon, MacOS-genie style. */
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.22s ease-out,
              box-shadow 0.18s ease;
  user-select: none;
  position: relative;
}
#rsup-root .rsup-launcher svg { width: 36px; height: 36px; }
#rsup-root .rsup-launcher:hover { transform: translateY(-2px); }
#rsup-root.rsup-anim-pulse .rsup-launcher::before {
  content: "";
  position: absolute; inset: -4px;
  border-radius: 50%;
  background: var(--rsup-user-bg);
  z-index: -1; opacity: 0.45;
  animation: rsup-pulse 2s ease-in-out infinite;
}
@keyframes rsup-pulse {
  0%   { transform: scale(1);   opacity: 0.45; }
  100% { transform: scale(1.4); opacity: 0;    }
}
#rsup-root.rsup-anim-glow .rsup-launcher {
  animation: rsup-glow 2.2s ease-in-out infinite;
}
@keyframes rsup-glow {
  0%, 100% { box-shadow: 0 0 18px var(--rsup-accent), 0 0 4px var(--rsup-accent); }
  50%      { box-shadow: 0 0 36px var(--rsup-accent), 0 0 12px var(--rsup-accent); }
}
#rsup-root.rsup-anim-bounce .rsup-launcher {
  animation: rsup-bounce 1.6s ease-in-out infinite;
}
@keyframes rsup-bounce {
  0%, 100% { transform: translateY(0);   }
  50%      { transform: translateY(-6px); }
}

/* ───── Open panel ─────────────────────────────────────────── */
/* Panel is always rendered (display:flex) so we can transition its
   transform — `display:none` can't animate. When closed it sits at
   scale(0.05) with opacity:0 and pointer-events:none, anchored to the
   launcher's corner so the open animation looks like the chat «grows
   out of» the icon, MacOS-genie style. */
#rsup-root .rsup-panel {
  width: 360px;
  height: min(560px, calc(100vh - 80px));
  background: var(--rsup-bg-panel);
  border-radius: var(--rsup-radius-panel);
  border: 1px solid var(--rsup-border);
  box-shadow:
    0 12px 40px rgba(20, 30, 60, 0.18),
    0 2px 8px rgba(0,0,0,0.08),
    var(--rsup-glow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: absolute;
  right: 0; bottom: 0;
  transform: scale(0.05);
  transform-origin: bottom right;
  opacity: 0;
  pointer-events: none;
  /* Genie curve — `easeOutExpo`, smooth «stretch out» without overshoot. */
  transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.22s ease-out;
  will-change: transform, opacity;
}
#rsup-root.rsup-pos-left .rsup-panel {
  right: auto; left: 0;
  transform-origin: bottom left;
}
#rsup-root.rsup-open .rsup-panel {
  transform: scale(1);
  opacity: 1;
  pointer-events: auto;
}
#rsup-root.rsup-open .rsup-launcher {
  transform: scale(0.3);
  opacity: 0;
  pointer-events: none;
  /* Stop pulse/glow/bounce while the icon is invisible — the keyframe
     transforms would otherwise override our scale(0.3). */
  animation: none;
}

@media (prefers-reduced-motion: reduce) {
  #rsup-root .rsup-panel,
  #rsup-root .rsup-launcher {
    transition: none;
  }
}

/* ───── Header ─────────────────────────────────────────────── */
#rsup-root .rsup-head {
  background: var(--rsup-user-bg);
  color: #fff;
  padding: 14px 16px;
  display: flex; align-items: center; gap: 10px;
  position: relative;
}
#rsup-root .rsup-head .rsup-title {
  font-weight: 700; font-size: 15px; flex: 1;
  font-family: var(--rsup-font-display);
  letter-spacing: 0.02em;
}
#rsup-root .rsup-head .rsup-lang-wrap {
  position: relative;
}
#rsup-root .rsup-head .rsup-lang {
  background: rgba(255,255,255,0.18);
  border: 0; color: #fff;
  padding: 4px 10px;
  border-radius: 999px; font-size: 12px; cursor: pointer;
  font-family: inherit;
}
#rsup-root .rsup-head .rsup-lang:hover { background: rgba(255,255,255,0.28); }

#rsup-root .rsup-lang-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 132px;
  background: var(--rsup-bg-panel);
  color: var(--rsup-text);
  border: 1px solid var(--rsup-border);
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.35);
  padding: 4px;
  display: none;
  z-index: 10;
  font-family: var(--rsup-font);
}
#rsup-root .rsup-lang-menu.rsup-lang-menu-open { display: block; }
#rsup-root .rsup-lang-item {
  display: block; width: 100%;
  background: transparent; border: 0;
  padding: 8px 12px;
  text-align: left; font-size: 13px;
  color: var(--rsup-text);
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
}
#rsup-root .rsup-lang-item:hover {
  background: color-mix(in srgb, var(--rsup-primary) 14%, transparent);
}
#rsup-root .rsup-lang-item.active {
  background: color-mix(in srgb, var(--rsup-primary) 22%, transparent);
  color: var(--rsup-primary);
  font-weight: 600;
}
#rsup-root .rsup-head .rsup-close {
  background: transparent; border: 0; color: #fff;
  font-size: 22px; cursor: pointer; line-height: 1;
  padding: 0 4px;
}

/* Glitch effect for header title (cyberpunk preset) */
#rsup-root.rsup-glitch .rsup-head .rsup-title {
  position: relative;
}
#rsup-root.rsup-glitch .rsup-head .rsup-title::before,
#rsup-root.rsup-glitch .rsup-head .rsup-title::after {
  content: attr(data-text);
  position: absolute; top: 0; left: 0;
  width: 100%; overflow: hidden;
}
#rsup-root.rsup-glitch .rsup-head .rsup-title::before {
  color: var(--rsup-accent);
  animation: rsup-glitch1 2.8s infinite linear alternate-reverse;
  clip-path: polygon(0 0, 100% 0, 100% 35%, 0 35%);
}
#rsup-root.rsup-glitch .rsup-head .rsup-title::after {
  color: var(--rsup-primary);
  animation: rsup-glitch2 2.6s infinite linear alternate-reverse;
  clip-path: polygon(0 65%, 100% 65%, 100% 100%, 0 100%);
}
@keyframes rsup-glitch1 {
  0%, 60%, 100% { transform: translate(0, 0); }
  62% { transform: translate(-1.5px, 0.5px); }
  64% { transform: translate(1px, -0.5px); }
  66% { transform: translate(0, 0); }
}
@keyframes rsup-glitch2 {
  0%, 70%, 100% { transform: translate(0, 0); }
  72% { transform: translate(1px, -0.5px); }
  74% { transform: translate(-1.5px, 0.5px); }
  76% { transform: translate(0, 0); }
}

/* Scanlines overlay (cyberpunk preset) */
#rsup-root.rsup-scanlines .rsup-panel::before {
  content: "";
  position: absolute; inset: 0;
  pointer-events: none; z-index: 5;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 255, 240, 0.04) 0,
    rgba(0, 255, 240, 0.04) 1px,
    transparent 1px,
    transparent 3px
  );
  border-radius: var(--rsup-radius-panel);
}

/* ───── Body — message list ────────────────────────────────── */
#rsup-root .rsup-body {
  flex: 1; overflow-y: auto; padding: 14px 12px;
  background: var(--rsup-bg-chat);
  /* Dark-themed scrollbar so it matches the panel instead of the
     OS-default white track. Firefox uses scrollbar-color; WebKit /
     Chromium uses ::-webkit-scrollbar. */
  scrollbar-width: thin;
  scrollbar-color:
    color-mix(in srgb, var(--rsup-primary) 50%, transparent)
    transparent;
}
#rsup-root .rsup-body::-webkit-scrollbar {
  width: 8px;
}
#rsup-root .rsup-body::-webkit-scrollbar-track {
  background: transparent;
}
#rsup-root .rsup-body::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--rsup-primary) 35%, transparent);
  border-radius: 4px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
#rsup-root .rsup-body::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--rsup-primary) 60%, transparent);
  background-clip: padding-box;
}
#rsup-root .rsup-msg {
  margin: 6px 0; max-width: 85%;
  padding: 9px 12px; border-radius: var(--rsup-radius-bubble);
  word-wrap: break-word; white-space: pre-wrap;
  /* Soft "float-up" intro: each newly-appended bubble fades in while
     sliding 14px from below. Feels less jarring than a hard pop-in
     when chunks arrive in sequence. The animation only plays once on
     mount (no `infinite`) so existing messages stay still on scroll. */
  animation: rsup-msg-in 1040ms cubic-bezier(.2,.8,.2,1) both;
}
@keyframes rsup-msg-in {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
/* Typing indicator gets the same gentle entrance so the dots don't
   pop in either. */
#rsup-root .rsup-typing {
  animation: rsup-msg-in 760ms cubic-bezier(.2,.8,.2,1) both;
}
@media (prefers-reduced-motion: reduce) {
  #rsup-root .rsup-msg,
  #rsup-root .rsup-typing {
    animation: none;
  }
}
/* Inline screenshots — visitor or AI/operator can attach an image.
   Tap opens the full image in a new tab (handled in widget.js). */
#rsup-root .rsup-msg-img {
  display: block;
  max-width: 100%;
  max-height: 220px;
  border-radius: 10px;
  margin: 0 0 6px;
  cursor: zoom-in;
  background: rgba(255,255,255,0.04);
}
#rsup-root .rsup-msg.user {
  background: var(--rsup-user-bg);
  color: var(--rsup-user-text);
  margin-left: auto;
  border-bottom-right-radius: 4px;
}
#rsup-root .rsup-msg.ai {
  background: var(--rsup-ai-bg);
  color: var(--rsup-ai-text);
  border: 1px solid var(--rsup-border);
  border-bottom-left-radius: 4px;
}
#rsup-root .rsup-msg.operator {
  background: var(--rsup-op-bg);
  color: var(--rsup-op-text);
  border: 1px solid var(--rsup-accent);
  border-bottom-left-radius: 4px;
}
#rsup-root .rsup-msg.system {
  font-style: italic; color: var(--rsup-text-muted);
  background: transparent; border: 0;
  font-size: 12px; text-align: center;
  margin: 8px auto;
}
/* Auto-linkified URLs inside any message bubble. Inherit the bubble's
   text color so contrast works on user / ai / operator backgrounds
   (and any future theme) without per-role overrides. */
#rsup-root .rsup-msg a.rsup-link {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
  transition: opacity 120ms ease;
}
#rsup-root .rsup-msg a.rsup-link:hover {
  opacity: 0.75;
}

/* ───── Soft lead-info card ────────────────────────────────── */
/* Slides into the chat body after the visitor's first message. Email
   is visually highlighted as the only "important" field but nothing
   here is blocking — Skip dismisses, the chat input stays usable
   regardless. The AI consultant can re-ask in plain conversation later
   if it actually needs the data. */
#rsup-root .rsup-leadcard {
  margin: 10px 8px;
  padding: 12px;
  background: var(--rsup-ai-bg);
  color: var(--rsup-ai-text);
  border: 1px solid var(--rsup-border);
  border-left: 3px solid var(--rsup-accent);
  border-radius: var(--rsup-radius-bubble);
  display: flex; flex-direction: column; gap: 8px;
  animation: rsup-leadcard-in 0.32s ease-out;
}
@keyframes rsup-leadcard-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0);   }
}
#rsup-root .rsup-leadcard-hint {
  font-size: 12.5px; line-height: 1.4;
  color: var(--rsup-text-muted);
}
#rsup-root .rsup-leadcard input {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--rsup-border);
  background: var(--rsup-bg-panel);
  color: var(--rsup-text);
  border-radius: 8px;
  font-size: 13px; font-family: inherit;
}
#rsup-root .rsup-leadcard input:focus {
  outline: none; border-color: var(--rsup-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--rsup-accent) 20%, transparent);
}
#rsup-root .rsup-leadcard input.rsup-leadcard-required {
  border-color: color-mix(in srgb, var(--rsup-accent) 55%, var(--rsup-border));
}
#rsup-root .rsup-leadcard-btns {
  display: flex; gap: 8px; margin-top: 2px;
}
#rsup-root .rsup-leadcard-save,
#rsup-root .rsup-leadcard-skip {
  flex: 1; padding: 8px 12px;
  border-radius: 8px; cursor: pointer;
  font-size: 13px; font-weight: 600;
  font-family: inherit;
}
#rsup-root .rsup-leadcard-save {
  background: var(--rsup-user-bg);
  color: var(--rsup-user-text);
  border: 0;
}
#rsup-root .rsup-leadcard-save:disabled { opacity: 0.5; cursor: wait; }
#rsup-root .rsup-leadcard-skip {
  background: transparent;
  color: var(--rsup-text-muted);
  border: 1px solid var(--rsup-border);
}
#rsup-root .rsup-leadcard-skip:hover {
  background: color-mix(in srgb, var(--rsup-text-muted) 10%, transparent);
}

/* ───── Input bar ──────────────────────────────────────────── */
/* @property declaration (top-level) — Chrome/Edge/Safari ≥16 animate
   `<angle>` smoothly. Browsers without @property fall back to the
   simple pulsing border defined further down. */
@property --rsup-beam-angle {
  syntax: '<angle>'; inherits: false; initial-value: 0deg;
}

#rsup-root .rsup-input {
  display: flex; gap: 8px;
  padding: 10px 12px;
  background: var(--rsup-bg-panel);
  border-top: 1px solid var(--rsup-border);
}

/* Textarea with the «orbiting beam» border — same trick as the
   landing page chat: conic-gradient on a 2px ring via `border-box`,
   solid panel fill on the inside via `padding-box`. The animation
   spins --rsup-beam-angle 0 → 360, the gradient follows it. Stops
   when the user is actually typing so it doesn't distract from input. */
#rsup-root .rsup-input textarea {
  flex: 1; resize: none;
  background:
    linear-gradient(var(--rsup-bg-panel), var(--rsup-bg-panel)) padding-box,
    conic-gradient(
      from var(--rsup-beam-angle),
      color-mix(in srgb, var(--rsup-primary) 18%, transparent),
      color-mix(in srgb, var(--rsup-primary) 80%, transparent) 14%,
      color-mix(in srgb, var(--rsup-accent)  80%, transparent) 30%,
      color-mix(in srgb, var(--rsup-primary) 18%, transparent) 50%,
      color-mix(in srgb, var(--rsup-secondary) 18%, transparent) 66%,
      color-mix(in srgb, var(--rsup-secondary) 80%, transparent) 84%,
      color-mix(in srgb, var(--rsup-primary) 18%, transparent) 100%
    ) border-box;
  border: 1.5px solid transparent;
  color: var(--rsup-text);
  border-radius: 18px;
  padding: 8px 12px; font-size: 14px;
  font-family: inherit; max-height: 100px;
  line-height: 1.4;
  animation: rsup-spotlight 6s linear infinite;
  transition: box-shadow .15s ease;
}
#rsup-root .rsup-input textarea:focus {
  outline: none;
  animation-play-state: paused;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--rsup-accent) 20%, transparent);
}
@keyframes rsup-spotlight {
  to { --rsup-beam-angle: 360deg; }
}

/* Attach (paperclip) button — sits before the textarea, opens the
   native file picker. Quiet styling: transparent, muted icon, hover
   gets a subtle lift. Distinct from the loud «supernova» send button.*/
#rsup-root .rsup-input button.rsup-attach {
  background: transparent;
  border: 0; padding: 0; margin-right: 2px;
  width: 34px; height: 34px;
  border-radius: 50%;
  color: var(--rsup-text-muted);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.15s ease, background 0.15s ease;
}
#rsup-root .rsup-input button.rsup-attach svg { width: 20px; height: 20px; }
#rsup-root .rsup-input button.rsup-attach:hover {
  color: var(--rsup-primary);
  background: color-mix(in srgb, var(--rsup-primary) 10%, transparent);
}

/* Send button — «supernova» pulsing halo. Two stacked pseudo-rings
   with offset delay to look like a slow detonation, not a strobe.
   Works regardless of @property support: only uses scale/opacity. */
#rsup-root .rsup-input button:not(.rsup-attach) {
  background: var(--rsup-user-bg);
  color: var(--rsup-user-text);
  border: 0; border-radius: 50%;
  width: 38px; height: 38px;
  font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  position: relative; isolation: isolate;
  z-index: 0;
}
#rsup-root .rsup-input button:not(.rsup-attach)::before,
#rsup-root .rsup-input button:not(.rsup-attach)::after {
  content: ""; position: absolute; inset: 0;
  border-radius: 50%;
  background: var(--rsup-user-bg);
  z-index: -1; opacity: 0;
  animation: rsup-supernova 2.6s cubic-bezier(.5,0,.7,1) infinite;
  pointer-events: none;
}
#rsup-root .rsup-input button:not(.rsup-attach)::after { animation-delay: 1.3s; }
@keyframes rsup-supernova {
  0%   { transform: scale(0.85); opacity: 0.65; }
  60%  { transform: scale(1.6);  opacity: 0; }
  100% { transform: scale(1.6);  opacity: 0; }
}
#rsup-root .rsup-input button:hover {
  filter: brightness(1.08);
}
#rsup-root .rsup-input button:disabled {
  opacity: 0.4; cursor: not-allowed;
  animation: none;
}
#rsup-root .rsup-input button:disabled::before,
#rsup-root .rsup-input button:disabled::after {
  animation: none; opacity: 0;
}

/* Fallback for browsers without @property (very old Firefox) — the
   conic gradient stays still; soft pulsing ring on the textarea
   keeps the «something is alive» feel. */
@supports not (background: paint(something)) {
  #rsup-root .rsup-input textarea {
    animation: rsup-input-pulse 3s ease-in-out infinite;
  }
  @keyframes rsup-input-pulse {
    0%, 100% { box-shadow: 0 0 8px color-mix(in srgb, var(--rsup-accent) 25%, transparent); }
    50%      { box-shadow: 0 0 14px color-mix(in srgb, var(--rsup-accent) 45%, transparent); }
  }
}

@media (prefers-reduced-motion: reduce) {
  #rsup-root .rsup-input textarea,
  #rsup-root .rsup-input button::before,
  #rsup-root .rsup-input button::after {
    animation: none !important;
  }
}

/* ════════ Cosmic-digital themes ═══════════════════════════════
   Three presets that share «animated cosmic background + extra send-
   button pulse + bubble glow» but each picks its own metaphor. The
   `.rsup-theme-{name}` class is added by widget.js from the active
   preset's `theme` field.

   Common: an animated layer rendered via `.rsup-panel::before` so it
   sits behind the chat body but inside the panel's rounded clip.
*/
#rsup-root[class*="rsup-theme-"] .rsup-panel {
  isolation: isolate;
}
#rsup-root[class*="rsup-theme-"] .rsup-panel > .rsup-cosmic-bg {
  position: absolute; inset: 0; z-index: 0;
  pointer-events: none; border-radius: inherit;
  overflow: hidden;
}
/* Head must beat body's stacking context so the language popover (which
   drops down from the «English» pill into the chat-body area) is hit-
   testable. With both at z-index:1 the later sibling (body) was winning
   and swallowing clicks. */
#rsup-root[class*="rsup-theme-"] .rsup-head  { position: relative; z-index: 5; }
#rsup-root[class*="rsup-theme-"] .rsup-body,
#rsup-root[class*="rsup-theme-"] .rsup-input { position: relative; z-index: 1; }

/* All three themes amp the send-button pulse — slightly faster supernova
   ring + a constant aura behind the glyph. The base supernova still
   plays from widget.css; we layer a softer halo on top.
   The `:not(.rsup-attach)` is critical — without it the paperclip icon
   on the left also picks up the pulse, which makes the calm muted
   button suddenly throb. */
#rsup-root[class*="rsup-theme-"] .rsup-input button:not(.rsup-attach) {
  box-shadow:
    0 0 0 0 color-mix(in srgb, var(--rsup-accent) 60%, transparent);
  animation: rsup-cosmic-send-pulse 1.6s ease-out infinite;
}
@keyframes rsup-cosmic-send-pulse {
  0%   { box-shadow: 0 0 0 0   color-mix(in srgb, var(--rsup-accent) 70%, transparent),
                     0 0 12px  color-mix(in srgb, var(--rsup-primary) 40%, transparent); }
  70%  { box-shadow: 0 0 0 12px color-mix(in srgb, var(--rsup-accent) 0%,  transparent),
                     0 0 18px  color-mix(in srgb, var(--rsup-primary) 25%, transparent); }
  100% { box-shadow: 0 0 0 0   color-mix(in srgb, var(--rsup-accent) 0%,  transparent),
                     0 0 12px  color-mix(in srgb, var(--rsup-primary) 40%, transparent); }
}

/* Bubble flair — subtle accent glow on AI/op messages so the chat feels
   alive without being noisy. */
#rsup-root[class*="rsup-theme-"] .rsup-msg.ai,
#rsup-root[class*="rsup-theme-"] .rsup-msg.op {
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--rsup-accent) 18%, transparent),
              0 4px 14px rgba(0, 0, 0, 0.18);
}

/* ── Stargate ── digital-cyan + gold; star-tunnel radial pulse ── */
#rsup-root.rsup-theme-stargate .rsup-panel::before {
  content: ""; position: absolute; inset: 0; z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 50%,
      color-mix(in srgb, var(--rsup-primary) 30%, transparent) 0%,
      transparent 38%),
    repeating-radial-gradient(circle at 50% 50%,
      color-mix(in srgb, var(--rsup-accent) 18%, transparent) 0,
      color-mix(in srgb, var(--rsup-accent) 18%, transparent) 1px,
      transparent 1px, transparent 70px);
  filter: blur(0.4px);
  animation: rsup-stargate-tunnel 7s ease-in-out infinite;
  border-radius: inherit;
}
@keyframes rsup-stargate-tunnel {
  0%, 100% { transform: scale(1.0);  opacity: 0.55; }
  50%      { transform: scale(1.15); opacity: 0.85; }
}

/* ── Quasar ── magenta core that breathes from the top of the panel ── */
#rsup-root.rsup-theme-quasar .rsup-panel::before {
  content: ""; position: absolute; inset: 0; z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% -10%,
      color-mix(in srgb, var(--rsup-primary) 70%, transparent) 0%,
      color-mix(in srgb, var(--rsup-primary) 30%, transparent) 18%,
      transparent 45%);
  animation: rsup-quasar-pulse 2.4s cubic-bezier(.6,0,.4,1) infinite;
  border-radius: inherit;
}
@keyframes rsup-quasar-pulse {
  0%, 100% { opacity: 0.55; transform: scale(1.0); }
  50%      { opacity: 1.0;  transform: scale(1.08); }
}
/* Twin pulse from the chat body's bottom for a heartbeat effect. */
#rsup-root.rsup-theme-quasar .rsup-body::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0;
  height: 60%; pointer-events: none; z-index: 0;
  background: radial-gradient(circle at 50% 110%,
    color-mix(in srgb, var(--rsup-accent) 30%, transparent) 0%,
    transparent 50%);
  animation: rsup-quasar-pulse 2.4s cubic-bezier(.6,0,.4,1) infinite reverse;
}
#rsup-root.rsup-theme-quasar .rsup-body { isolation: isolate; }
#rsup-root.rsup-theme-quasar .rsup-msg { position: relative; z-index: 1; }

/* ── Wormhole ── orbiting spotlight border + soft outer halo,
   replicates the cheburator.bot landing chat effect 1:1 (uses the
   same `--rsup-beam-angle` property + 8s rotation). The chat itself
   sits stationary; only the colored ring + the blurred halo behind
   the panel rotate. As soon as the visitor focuses the input the
   widget gets `.rsup-chat-engaged` and the rotation freezes — same
   UX as cheburator's «notice → freeze» pattern. */
#rsup-root.rsup-theme-wormhole .rsup-panel {
  background:
    linear-gradient(var(--rsup-bg-panel), var(--rsup-bg-panel)) padding-box,
    conic-gradient(
      from var(--rsup-beam-angle, 0deg),
      color-mix(in srgb, var(--rsup-primary)   18%, transparent),
      color-mix(in srgb, var(--rsup-primary)   65%, transparent) 14%,
      color-mix(in srgb, var(--rsup-accent)    65%, transparent) 30%,
      color-mix(in srgb, var(--rsup-primary)   18%, transparent) 50%,
      color-mix(in srgb, var(--rsup-secondary) 18%, transparent) 66%,
      color-mix(in srgb, var(--rsup-secondary) 65%, transparent) 84%,
      color-mix(in srgb, var(--rsup-primary)   18%, transparent) 100%
    ) border-box;
  border: 2px solid transparent;
  animation: rsup-wormhole-spotlight 8s linear infinite;
}
#rsup-root.rsup-theme-wormhole .rsup-panel::before {
  content: ""; position: absolute; inset: -6px; border-radius: inherit;
  background: conic-gradient(
    from var(--rsup-beam-angle, 0deg),
    transparent 0deg,
    color-mix(in srgb, var(--rsup-primary)   30%, transparent) 30deg,
    transparent 90deg,
    color-mix(in srgb, var(--rsup-accent)    30%, transparent) 180deg,
    transparent 240deg,
    color-mix(in srgb, var(--rsup-secondary) 30%, transparent) 300deg,
    transparent 360deg);
  filter: blur(16px);
  opacity: 0.65;
  z-index: -1;
  pointer-events: none;
  animation: rsup-wormhole-spotlight 8s linear infinite;
}
@keyframes rsup-wormhole-spotlight {
  to { --rsup-beam-angle: 360deg; }
}
#rsup-root.rsup-chat-engaged.rsup-theme-wormhole .rsup-panel,
#rsup-root.rsup-chat-engaged.rsup-theme-wormhole .rsup-panel::before {
  animation-play-state: paused;
}
/* Fallback for browsers without @property — keep a still pulsing glow
   so the panel still reads as «alive» before interaction. */
@supports not (background: paint(something)) {
  #rsup-root.rsup-theme-wormhole .rsup-panel {
    animation: rsup-wormhole-pulse 3s ease-in-out infinite;
  }
  #rsup-root.rsup-theme-wormhole .rsup-panel::before { display: none; }
  @keyframes rsup-wormhole-pulse {
    0%, 100% { box-shadow: 0 0 22px color-mix(in srgb, var(--rsup-primary) 30%, transparent); }
    50%      { box-shadow: 0 0 30px color-mix(in srgb, var(--rsup-accent)  45%, transparent); }
  }
}

/* ───── Typing indicator ───────────────────────────────────── */
#rsup-root .rsup-typing {
  display: flex; gap: 4px; padding: 8px 14px;
  align-items: center; height: 32px;
}
#rsup-root .rsup-typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--rsup-accent);
  animation: rsup-blink 1.2s infinite;
  opacity: 0.5;
}
#rsup-root .rsup-typing span:nth-child(2) { animation-delay: 0.15s; }
#rsup-root .rsup-typing span:nth-child(3) { animation-delay: 0.30s; }
@keyframes rsup-blink {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30%           { opacity: 1; transform: translateY(-3px); }
}

/* ───── Resize handles ─────────────────────────────────────── */
/* The panel always opens at its default size; these grab zones let the
   visitor stretch it afterwards to fit their own screen (size is then
   remembered in localStorage by widget-core.js). They live *inside* the
   panel — it is `overflow: hidden`, so anything hanging outside would be
   clipped — on the two free edges: the panel is pinned to its bottom
   corner, so it can only grow upwards and inwards. */
#rsup-root .rsup-resize {
  position: absolute;
  z-index: 12;
  touch-action: none;        /* drag must not scroll the host page */
}
#rsup-root .rsup-resize-n {
  top: 0; left: 16px; right: 16px; height: 6px; cursor: ns-resize;
}
#rsup-root .rsup-resize-w {
  top: 16px; bottom: 16px; left: 0; width: 6px; cursor: ew-resize;
}
#rsup-root.rsup-pos-left .rsup-resize-w { left: auto; right: 0; }
/* Corner grab zone. Deliberately NOT drawn — a visible marker in the
   header corner read as a stray glyph. The resize cursor on hover is
   the affordance on desktop; on touch the zone is just bigger. */
#rsup-root .rsup-resize-nw {
  top: 0; left: 0; width: 20px; height: 20px; cursor: nwse-resize;
}
#rsup-root.rsup-pos-left .rsup-resize-nw {
  left: auto; right: 0; cursor: nesw-resize;
}
/* While dragging: no genie transition fighting the new width/height,
   and no accidental text selection across the host page. */
#rsup-root.rsup-resizing .rsup-panel { transition: none; }
#rsup-root.rsup-resizing,
#rsup-root.rsup-resizing * { user-select: none; -webkit-user-select: none; }

/* ───── Mobile ────────────────────────────────────────────── */
/* On phones the panel sits a bit smaller than the screen so the host
   page is still visible at the edges and the user can pinch-zoom the
   page (or close + reopen without losing context). `dvh` tracks the
   real viewport on iOS Safari — `vh` includes the address bar area
   and produced a panel that overflowed under the keyboard. */
@media (max-width: 480px) {
  #rsup-root.rsup-pos-right { right: 16px; bottom: 16px; }
  #rsup-root.rsup-pos-left  { left:  16px; bottom: 16px; }
  #rsup-root .rsup-panel {
    width: calc(100vw - 32px);
    /* Opens at half the screen, not the whole of it — the visitor keeps
       sight of the page they were reading, and can drag the panel taller
       (up to the full viewport) whenever they want more room. The 320px
       floor keeps the chat usable on short screens, where half a screen
       would leave almost nothing between the header and the input.
       dvh tracks the real viewport on iOS Safari — vh includes the
       address-bar strip and pushed the panel under the keyboard. */
    height: 50vh;
    height: max(50dvh, 320px);
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
  }
  /* iOS auto-zooms inputs whose font-size < 16px on focus, which
     re-frames the page and feels broken. Bump form/textarea fonts
     to 16px on touch screens so focus stays put — and the user can
     still pinch-zoom manually if they want a closer look. */
  #rsup-root .rsup-leadcard input,
  #rsup-root .rsup-input textarea {
    font-size: 16px;
  }
  /* Phones resize too, but the grab zones are re-cut for fingers and for
     what sits underneath. The side edge is dropped: the panel is already
     as wide as the screen, and a 16px strip down the left would swallow
     taps on links at the edge of message bubbles. What's left lives in
     the header, which has no tappable content on its left side. */
  #rsup-root .rsup-resize-w { display: none; }
  #rsup-root .rsup-resize-n { height: 18px; left: 0; right: 120px; }
  #rsup-root .rsup-resize-nw { width: 30px; height: 30px; }
  /* Left-docked panel grows to the right — where the language pill and
     the close button live. No corner zone there; the top edge still
     adjusts the height. */
  #rsup-root.rsup-pos-left .rsup-resize-nw { display: none; }
  #rsup-root.rsup-pos-left .rsup-resize-n { left: 120px; right: 0; }
}
