.cst-rag {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 2147483000;
  font-family: inherit;
  pointer-events: none;
  isolation: isolate;
  width: 64px;
  height: 64px;
}

.cst-rag.is-open {
  right: 20px;
  bottom: 20px;
  width: min(400px, calc(100vw - 24px));
  height: min(620px, calc(100vh - 32px));
}

.cst-rag.is-open .cst-rag-launch,
.cst-rag.is-open .cst-rag-tip,
.cst-rag.is-open .cst-rag-rope {
  display: none !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.cst-rag.is-hanging {
  right: 24px;
  bottom: 24px;
  animation: cst-rag-drop 2.1s cubic-bezier(0.22, 1.12, 0.36, 1) forwards;
}

.cst-rag.is-hanging .cst-rag-launch,
.cst-rag.is-hanging .cst-rag-launch::after,
.cst-rag.is-hanging .cst-rag-launch img {
  animation: none;
  opacity: 1;
}

.cst-rag.is-hanging .cst-rag-tip {
  opacity: 0 !important;
  pointer-events: none !important;
  animation: none !important;
}

.cst-rag.is-hanging .cst-rag-rope {
  display: block;
  opacity: 1;
  height: min(55vh, 420px);
  animation: cst-rag-rope-shrink 2.1s cubic-bezier(0.22, 1.12, 0.36, 1) forwards;
}

.cst-rag.is-docked .cst-rag-rope {
  opacity: 0;
  height: 0;
  transition: opacity 0.3s ease, height 0.3s ease;
}

.cst-rag-rope {
  position: absolute;
  left: 50%;
  bottom: 100%;
  width: 2px;
  height: 0;
  margin-left: -1px;
  background: linear-gradient(
    180deg,
    rgba(17, 17, 17, 0),
    var(--tp-theme-primary, rgb(56, 88, 233)) 40%,
    var(--tp-theme-primary, rgb(56, 88, 233))
  );
  opacity: 0;
  pointer-events: none;
  z-index: 1;
  transform-origin: bottom center;
}

.cst-rag-rope::before {
  content: "";
  position: absolute;
  top: -5px;
  left: 50%;
  width: 9px;
  height: 9px;
  margin-left: -4.5px;
  border-radius: 50%;
  background: var(--tp-theme-primary, rgb(56, 88, 233));
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.55);
}

@keyframes cst-rag-drop {
  0% {
    transform: translateY(calc(-100vh + 88px)) rotate(-12deg);
  }
  30% {
    transform: translateY(calc(-70vh + 88px)) rotate(9deg);
  }
  55% {
    transform: translateY(calc(-38vh + 60px)) rotate(-6deg);
  }
  78% {
    transform: translateY(calc(-12vh + 24px)) rotate(3deg);
  }
  90% {
    transform: translateY(6px) rotate(-1deg);
  }
  100% {
    transform: translateY(0) rotate(0deg);
  }
}

@keyframes cst-rag-rope-shrink {
  0% {
    height: min(92vh, 720px);
    opacity: 1;
  }
  100% {
    height: 48px;
    opacity: 0.75;
  }
}

.cst-rag > * {
  pointer-events: auto;
}

@keyframes cst-rag-float {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }
  40% {
    transform: translateY(-14px) scale(1.04);
  }
  70% {
    transform: translateY(-4px) scale(0.98);
  }
}

@keyframes cst-rag-pulse {
  0% {
    transform: scale(1);
    opacity: 0.55;
  }
  70% {
    transform: scale(1.85);
    opacity: 0;
  }
  100% {
    transform: scale(1.85);
    opacity: 0;
  }
}

@keyframes cst-rag-icon-bob {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }
  35% {
    transform: translateY(-3px) rotate(-8deg);
  }
  70% {
    transform: translateY(2px) rotate(7deg);
  }
}

@keyframes cst-rag-tip-in {
  0% {
    opacity: 0;
    transform: translateY(8px) scale(0.86);
  }
  55% {
    opacity: 1;
    transform: translateY(-2px) scale(1.04);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes cst-rag-tip-bounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-5px);
  }
}

.cst-rag-tip {
  position: absolute;
  right: 0;
  bottom: calc(100% + 14px);
  width: max-content;
  max-width: min(220px, calc(100vw - 48px));
  padding: 10px 12px;
  /* Default: white background → blue tile */
  background: var(--tp-theme-primary, rgb(56, 88, 233));
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: 0.01em;
  box-shadow: 0 12px 28px rgba(36, 62, 192, 0.28);
  opacity: 0;
  pointer-events: none;
  transform-origin: 90% 100%;
  z-index: 3;
  border: 1px solid transparent;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.cst-rag-tip::after {
  content: "";
  position: absolute;
  right: 22px;
  top: 100%;
  border: 7px solid transparent;
  border-top-color: var(--tp-theme-primary, rgb(56, 88, 233));
  transition: border-top-color 0.2s ease;
}

/* Blue / dark background → white tile */
.cst-rag-tip.is-on-dark {
  background: #fff;
  color: var(--tp-theme-primary, rgb(56, 88, 233));
  border-color: rgba(56, 88, 233, 0.18);
  box-shadow: 0 12px 28px rgba(7, 11, 26, 0.14);
}

.cst-rag-tip.is-on-dark::after {
  border-top-color: #fff;
}

.cst-rag-tip.is-show {
  pointer-events: auto;
  cursor: pointer;
  animation:
    cst-rag-tip-in 0.55s cubic-bezier(0.22, 1, 0.36, 1) both,
    cst-rag-tip-bounce 1.8s ease-in-out 0.55s infinite;
}

.cst-rag.is-open .cst-rag-tip,
.cst-rag-tip.is-hide {
  opacity: 0 !important;
  pointer-events: none !important;
  animation: none !important;
  transform: translateY(6px) scale(0.92);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.cst-rag-tip.is-left {
  right: auto;
  left: 0;
  transform-origin: 10% 100%;
}

.cst-rag-tip.is-left::after {
  right: auto;
  left: 22px;
}

.cst-rag-launch {
  width: 64px;
  height: 64px;
  border: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 28%, #7b93ff 0%, #3858e9 42%, #243ec0 78%, #1a2f96 100%);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow:
    0 14px 28px rgba(36, 62, 192, 0.38),
    0 2px 0 rgba(255, 255, 255, 0.28) inset,
    0 -3px 8px rgba(10, 22, 90, 0.35) inset;
  position: relative;
  z-index: 2;
  transition: box-shadow 0.18s ease;
  animation: cst-rag-float 1.8s ease-in-out infinite;
  will-change: transform;
}

.cst-rag-launch::before {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 22%, rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0) 46%);
  pointer-events: none;
}

.cst-rag-launch::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(56, 88, 233, 0.55);
  pointer-events: none;
  z-index: 0;
  animation: cst-rag-pulse 2.2s ease-out infinite;
}

.cst-rag-launch svg,
.cst-rag-launch img,
.cst-rag-launch path {
  pointer-events: none;
}

.cst-rag-launch svg,
.cst-rag-launch img {
  width: 36px;
  height: 36px;
  position: relative;
  z-index: 1;
  filter: drop-shadow(0 2px 2px rgba(10, 22, 90, 0.25));
  animation: cst-rag-icon-bob 1.8s ease-in-out infinite;
  will-change: transform;
}

.cst-rag-launch:hover {
  animation-play-state: paused;
  transform: translateY(-4px) scale(1.06);
  box-shadow:
    0 20px 36px rgba(36, 62, 192, 0.5),
    0 2px 0 rgba(255, 255, 255, 0.32) inset,
    0 -3px 8px rgba(10, 22, 90, 0.35) inset;
}

.cst-rag-launch:hover svg,
.cst-rag-launch:hover img {
  animation-play-state: paused;
}

.cst-rag.is-open .cst-rag-launch,
.cst-rag.is-open .cst-rag-launch::after,
.cst-rag.is-open .cst-rag-launch svg,
.cst-rag.is-open .cst-rag-launch img {
  animation: none;
}

@media (prefers-reduced-motion: reduce) {
  .cst-rag.is-hanging {
    animation: none;
    transform: none;
  }

  .cst-rag-rope {
    display: none !important;
  }

  .cst-rag-launch,
  .cst-rag-launch::after,
  .cst-rag-launch svg,
  .cst-rag-launch img,
  .cst-rag-tip.is-show {
    animation: none;
  }

  .cst-rag-tip.is-show {
    opacity: 1;
  }
}

.cst-rag-panel {
  position: absolute;
  right: 0;
  bottom: 68px;
  width: min(380px, calc(100vw - 32px));
  height: min(520px, calc(100vh - 140px));
  display: none;
  flex-direction: column;
  background: #f7f8fc;
  border: 1px solid rgba(20, 28, 60, 0.08);
  border-radius: 0;
  box-shadow:
    0 24px 64px rgba(15, 23, 52, 0.22),
    0 2px 0 rgba(255, 255, 255, 0.65) inset;
  overflow: hidden;
  z-index: 1;
  backdrop-filter: blur(10px);
  animation: cst-rag-panel-in 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.cst-rag.is-open .cst-rag-panel {
  inset: 0;
  width: 100%;
  height: 100%;
  bottom: 0;
  right: 0;
}

.cst-rag.is-open .cst-rag-panel,
.cst-rag-panel:not([hidden]) {
  display: flex;
}

.cst-rag-panel[hidden] {
  display: none !important;
  animation: none;
}

@keyframes cst-rag-panel-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.cst-rag-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 14px 16px;
  background: var(--tp-theme-primary, rgb(56, 88, 233));
  color: #fff;
}

.cst-rag-head-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.cst-rag-avatar {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 6px 16px rgba(10, 22, 90, 0.2);
}

.cst-rag-avatar img {
  width: 28px;
  height: 28px;
  display: block;
  filter: drop-shadow(0 1px 1px rgba(10, 22, 90, 0.25));
}

.cst-rag-head strong {
  display: block;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.cst-rag-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: 12px;
  opacity: 0.92;
  font-weight: 500;
}

.cst-rag-status i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #7CFFB2;
  box-shadow: 0 0 0 3px rgba(124, 255, 178, 0.25);
  animation: cst-rag-online 1.8s ease-in-out infinite;
}

@keyframes cst-rag-online {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

.cst-rag-close {
  border: 0;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 0;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  display: grid;
  place-items: center;
  transition: background 0.15s ease;
}

.cst-rag-close:hover {
  background: rgba(255, 255, 255, 0.24);
}

.cst-rag-messages {
  flex: 1;
  overflow: auto;
  padding: 16px;
  background:
    radial-gradient(circle at top right, rgba(56, 88, 233, 0.06), transparent 42%),
    #f3f5fb;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cst-rag-bubble {
  max-width: 88%;
  padding: 11px 13px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  border-radius: 0;
}

.cst-rag-bubble.is-bot {
  align-self: flex-start;
  background: #fff;
  color: #151922;
  border: 1px solid rgba(20, 28, 60, 0.06);
  box-shadow: 0 6px 16px rgba(20, 28, 60, 0.05);
}

.cst-rag-bubble.is-thinking {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 148px;
  padding: 12px 16px;
  border: 1px solid rgba(56, 88, 233, 0.14);
  background: #fff;
  color: #1a1a1a;
  border-radius: 0;
  box-shadow: 0 6px 16px rgba(20, 28, 60, 0.05);
}

.cst-rag-think-ring {
  position: relative;
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
}

.cst-rag-think-ring::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(56, 88, 233, 0.18);
}

.cst-rag-think-ring span {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: #3858e9;
  border-right-color: #7b93ff;
  animation: cst-rag-spin 0.85s linear infinite;
  will-change: transform;
}

.cst-rag-thinking-copy {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.cst-rag-thinking-label {
  font-size: 13px;
  font-weight: 600;
  color: #243ec0;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.cst-rag-thinking-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 12px;
}

.cst-rag-thinking-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #3858e9;
  opacity: 0.25;
  animation: cst-rag-dot 1.2s ease-in-out infinite;
  will-change: transform, opacity;
}

.cst-rag-thinking-dots i:nth-child(2) {
  animation-delay: 0.15s;
}

.cst-rag-thinking-dots i:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes cst-rag-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes cst-rag-dot {
  0%,
  100% {
    opacity: 0.25;
    transform: translate3d(0, 0, 0);
  }
  40% {
    opacity: 1;
    transform: translate3d(0, -3px, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .cst-rag-think-ring span,
  .cst-rag-thinking-dots i {
    animation: none;
  }

  .cst-rag-thinking-dots i {
    opacity: 0.7;
  }
}

.cst-rag-bubble.is-user {
  align-self: flex-end;
  background: linear-gradient(135deg, #3858e9 0%, #243ec0 100%);
  color: #fff;
  box-shadow: 0 8px 18px rgba(36, 62, 192, 0.22);
}

.cst-rag-bubble.is-muted {
  align-self: center;
  background: transparent;
  border: 0;
  color: #6b7280;
  font-size: 12px;
  padding: 2px 0;
  box-shadow: none;
}

.cst-rag-sources {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cst-rag-sources a {
  display: inline-block;
  padding: 5px 10px;
  border: 1px solid rgba(56, 88, 233, 0.14);
  border-radius: 0;
  color: #243ec0 !important;
  font-size: 11px;
  font-weight: 600;
  text-decoration: none;
  background: #eef2ff;
}

.cst-rag-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-self: flex-start;
  max-width: 100%;
  position: relative;
  z-index: 5;
  pointer-events: auto;
}

.cst-rag-chip {
  border: 1px solid rgba(56, 88, 233, 0.18);
  background: #fff;
  color: #243ec0;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.25;
  padding: 9px 12px;
  cursor: pointer;
  border-radius: 0;
  pointer-events: auto;
  position: relative;
  z-index: 6;
  box-shadow: 0 4px 12px rgba(20, 28, 60, 0.05);
  -webkit-tap-highlight-color: rgba(56, 88, 233, 0.2);
  touch-action: manipulation;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.cst-rag-chip:hover {
  background: #3858e9;
  border-color: #3858e9;
  color: #fff;
}

.cst-rag-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px 14px;
  border-top: 1px solid rgba(20, 28, 60, 0.06);
  background: rgba(255, 255, 255, 0.92);
}

.cst-rag-form input {
  flex: 1;
  min-width: 0;
  height: 46px;
  border: 1px solid rgba(20, 28, 60, 0.1);
  border-radius: 0;
  padding: 0 14px;
  font-size: 14px;
  color: #151922;
  background: #fff;
  outline: none;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset;
}

.cst-rag-form input:focus {
  border-color: rgba(56, 88, 233, 0.45);
  box-shadow: 0 0 0 3px rgba(56, 88, 233, 0.12);
}

.cst-rag-form button {
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: linear-gradient(135deg, #3858e9 0%, #243ec0 100%);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(36, 62, 192, 0.28);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.cst-rag-form button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(36, 62, 192, 0.34);
}

.cst-rag-form button:disabled {
  opacity: 0.55;
  cursor: wait;
  transform: none;
}

.cst-rag-form button svg {
  display: block;
}
