#crc-chat-widget {
  --crc-accent: #0b6ef6;
  --crc-accent-light: #5aa8fb;
  --crc-accent-rgb: 11, 110, 246;
  --crc-bubble: #ffffff;
  --crc-text: #1f2937;
  position: fixed !important;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  right: auto;
  z-index: 2147483000;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: visible;
}

#crc-chat-widget::before,
#crc-chat-widget::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  pointer-events: none;
  z-index: 1;
}

#crc-chat-widget::before {
  left: -14px;
  bottom: -14px;
  width: 88px;
  height: 88px;
  background: radial-gradient(circle, rgba(var(--crc-accent-rgb), 0.3) 0%, rgba(var(--crc-accent-rgb), 0.14) 42%, rgba(var(--crc-accent-rgb), 0) 72%);
  animation: crcHalo 3.6s ease-in-out infinite;
}

#crc-chat-widget::after {
  left: -24px;
  bottom: -24px;
  width: 108px;
  height: 108px;
  background: radial-gradient(circle, rgba(var(--crc-accent-rgb), 0.16) 0%, rgba(var(--crc-accent-rgb), 0.07) 45%, rgba(var(--crc-accent-rgb), 0) 72%);
  animation: crcHalo 3.6s ease-in-out infinite 1.8s;
}

#crc-chat-toggle {
  position: relative;
  z-index: 3;
  width: 60px;
  height: 60px;
  border-radius: 999px;
  border: none;
  background: var(--crc-accent);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  overflow: visible;
  isolation: isolate;
}

#crc-chat-toggle img,
#crc-chat-panel header img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#crc-chat-widget.is-open::before,
#crc-chat-widget.is-open::after {
  animation-play-state: paused;
  opacity: 0;
}

.crc-chat-icon,
.crc-chat-avatar-fallback {
  display: inline-flex;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  letter-spacing: 0.4px;
}

#crc-chat-panel {
  position: absolute;
  left: 0;
  bottom: 72px;
  z-index: 2;
  width: min(370px, calc(100vw - 24px));
  height: min(520px, calc(100vh - 120px));
  border: 1px solid rgba(15, 23, 42, 0.15);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(10px) scale(0.985);
  transform-origin: left bottom;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

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

#crc-chat-panel header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: linear-gradient(118deg, var(--crc-accent-light) 0%, var(--crc-accent) 58%, var(--crc-accent) 100%);
  color: #fff;
}

#crc-chat-panel header img,
#crc-chat-panel .crc-chat-avatar-fallback {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid #ffffff57;
  flex: 0 0 auto;
}

#crc-chat-panel header > div {
  min-width: 0;
  margin-right: auto;
}

#crc-chat-panel header h4 {
  margin: 0;
  font-size: 24px;
  line-height: 1;
  font-weight: 800;
  color: #fff;
}

#crc-chat-panel header small {
  display: block;
  margin-top: 4px;
  font-size: 14px;
  opacity: 0.95;
}

#crc-chat-close {
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 32px;
  line-height: 1;
  width: 34px;
  height: 34px;
  padding: 0;
  cursor: pointer;
  opacity: 0.95;
}

#crc-chat-messages {
  flex: 1;
  overflow: auto;
  padding: 14px 12px;
  background: #f2f3f5;
}

.crc-msg-wrap {
  display: flex;
  flex-direction: column;
  margin-bottom: 10px;
}

.crc-msg-wrap-assistant {
  align-items: flex-start;
}

.crc-msg-wrap-user {
  align-items: flex-end;
}

.crc-msg {
  padding: 10px 12px;
  border-radius: 13px;
  line-height: 1.4;
  font-size: 14px;
  white-space: pre-wrap;
  max-width: 82%;
}

.crc-msg p {
  margin: 0 0 8px;
}

.crc-msg p:last-child {
  margin-bottom: 0;
}

.crc-msg ul,
.crc-msg ol {
  margin: 0;
  padding-left: 18px;
}

.crc-msg li {
  margin: 0 0 8px;
}

.crc-msg li:last-child {
  margin-bottom: 0;
}

.crc-msg-strong {
  color: var(--crc-accent);
  font-weight: 800;
}

.crc-msg-link {
  color: var(--crc-accent);
  text-decoration: underline;
}

.crc-more-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(var(--crc-accent-rgb), 0.35);
  background: rgba(var(--crc-accent-rgb), 0.12);
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}

.crc-more-chip::after {
  content: "↗";
  font-size: 11px;
}

.crc-msg-user {
  background: var(--crc-accent);
  color: #fff;
  border-top-right-radius: 6px;
}

.crc-msg-assistant {
  background: var(--crc-bubble);
  color: var(--crc-text);
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-top-left-radius: 6px;
}

.crc-msg.is-typing {
  min-width: 58px;
}

.crc-typing {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.crc-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(var(--crc-accent-rgb), 0.9);
  animation: crcTypingPulse 1s ease-in-out infinite;
}

.crc-typing-dot:nth-child(2) {
  animation-delay: 0.16s;
}

.crc-typing-dot:nth-child(3) {
  animation-delay: 0.32s;
}

.crc-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.crc-msg-time {
  margin-top: 4px;
  font-size: 11px;
  color: #8b8f98;
  line-height: 1;
}

.crc-msg-wrap-user .crc-msg-time {
  text-align: right;
}

.crc-msg-time.is-hidden {
  visibility: hidden;
}

#crc-chat-form {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid rgba(15, 23, 42, 0.08);
  background: #fff;
}

#crc-chat-input {
  flex: 1;
  min-width: 0;
  border: 1px solid rgba(15, 23, 42, 0.16);
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 14px;
}

#crc-chat-form button {
  border: none;
  border-radius: 999px;
  background: var(--crc-accent);
  color: #fff;
  padding: 0 16px;
  font-weight: 700;
  cursor: pointer;
}

@keyframes crcHalo {
  0% {
    transform: scale(0.82);
    opacity: 0;
  }
  20% {
    opacity: 0.9;
  }
  70% {
    opacity: 0.22;
  }
  100% {
    transform: scale(1.28);
    opacity: 0;
  }
}

@keyframes crcTypingPulse {
  0%,
  80%,
  100% {
    transform: translateY(0) scale(0.86);
    opacity: 0.35;
  }
  40% {
    transform: translateY(-1px) scale(1);
    opacity: 1;
  }
}

@media (max-width: 480px) {
  #crc-chat-panel {
    width: min(370px, calc(100vw - 16px));
    height: min(520px, calc(100vh - 96px));
  }
}
