#jd-chat-root {
  --jd-bubble-size: 60px;
  --jd-panel-w: 360px;
  --jd-panel-h: 520px;
  --jd-radius: 14px;
  --jd-z: 9999;
}

#jd-chat-bubble {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: var(--jd-bubble-size);
  height: var(--jd-bubble-size);
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 24px var(--accent-glow), 0 2px 8px rgba(0, 0, 0, 0.4);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  z-index: var(--jd-z);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

#jd-chat-bubble:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 10px 32px var(--accent-glow), 0 4px 12px rgba(0, 0, 0, 0.5);
}

#jd-chat-bubble:focus-visible {
  outline: 2px solid var(--text-primary);
  outline-offset: 3px;
}

#jd-chat-bubble svg {
  width: 26px;
  height: 26px;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}

#jd-chat-bubble.is-open .jd-icon-chat { opacity: 0; transform: scale(0.6); position: absolute; }
#jd-chat-bubble:not(.is-open) .jd-icon-close { opacity: 0; transform: scale(0.6); position: absolute; }

#jd-chat-bubble .jd-pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 0 var(--accent-glow);
  animation: jd-pulse 2.4s ease-out infinite;
  pointer-events: none;
}

#jd-chat-bubble.is-open .jd-pulse { animation: none; }

@keyframes jd-pulse {
  0% { box-shadow: 0 0 0 0 rgba(74, 144, 217, 0.45); }
  70% { box-shadow: 0 0 0 22px rgba(74, 144, 217, 0); }
  100% { box-shadow: 0 0 0 0 rgba(74, 144, 217, 0); }
}

#jd-chat-panel {
  position: fixed;
  right: 24px;
  bottom: calc(24px + var(--jd-bubble-size) + 12px);
  width: var(--jd-panel-w);
  height: var(--jd-panel-h);
  max-height: calc(100vh - 140px);
  background:
    radial-gradient(1200px 400px at 20% -10%, rgba(74, 144, 217, 0.12), transparent 60%),
    radial-gradient(800px 300px at 100% 120%, rgba(74, 144, 217, 0.08), transparent 60%),
    var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--jd-radius);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: var(--jd-z);
  transform-origin: bottom right;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  pointer-events: none;
  transition: opacity var(--transition-smooth), transform var(--transition-smooth);
}

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

#jd-chat-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(1px 1px at 20% 30%, rgba(255, 255, 255, 0.25), transparent 60%),
    radial-gradient(1px 1px at 65% 18%, rgba(255, 255, 255, 0.18), transparent 60%),
    radial-gradient(1.5px 1.5px at 82% 62%, rgba(255, 255, 255, 0.14), transparent 60%),
    radial-gradient(1px 1px at 35% 78%, rgba(255, 255, 255, 0.2), transparent 60%),
    radial-gradient(1px 1px at 78% 88%, rgba(255, 255, 255, 0.12), transparent 60%);
  pointer-events: none;
  opacity: 0.75;
}

.jd-chat-header {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-subtle);
  background: linear-gradient(180deg, rgba(74, 144, 217, 0.1), transparent);
  z-index: 1;
}

.jd-chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.jd-chat-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.jd-chat-title strong {
  font-family: var(--font-heading);
  font-size: 15px;
  color: var(--text-primary);
  line-height: 1.2;
}

.jd-chat-title span {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.jd-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 6px rgba(74, 222, 128, 0.6);
}

.jd-chat-close {
  margin-left: auto;
  background: transparent;
  color: var(--text-secondary);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.jd-chat-close:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

.jd-chat-messages {
  position: relative;
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.jd-chat-messages::-webkit-scrollbar { width: 6px; }
.jd-chat-messages::-webkit-scrollbar-track { background: transparent; }
.jd-chat-messages::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); border-radius: 3px; }
.jd-chat-messages::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.3); }

.jd-msg {
  max-width: 82%;
  padding: 10px 13px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: jd-msg-in 0.22s ease-out;
}

@keyframes jd-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.jd-msg.jd-bot {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-bottom-left-radius: 4px;
}

.jd-msg.jd-user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.jd-msg a { color: var(--accent-hover); text-decoration: underline; }
.jd-msg.jd-user a { color: #fff; }

.jd-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
}

.jd-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: jd-bounce 1.2s infinite ease-in-out;
}

.jd-typing span:nth-child(2) { animation-delay: 0.15s; }
.jd-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes jd-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.jd-chat-input {
  position: relative;
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border-subtle);
  background: rgba(0, 0, 0, 0.2);
  z-index: 1;
}

.jd-chat-input textarea {
  flex: 1;
  resize: none;
  background: var(--bg-deep);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  max-height: 120px;
  line-height: 1.4;
  transition: border-color var(--transition-fast);
}

.jd-chat-input textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.jd-chat-input textarea::placeholder { color: var(--text-muted); }

.jd-chat-send {
  background: var(--accent);
  color: #fff;
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: flex-end;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

.jd-chat-send:hover { background: var(--accent-hover); }
.jd-chat-send:active { transform: scale(0.95); }
.jd-chat-send:disabled { background: var(--bg-card-hover); cursor: not-allowed; opacity: 0.6; }

.jd-chat-footer {
  padding: 8px 14px 10px;
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  border-top: 1px solid var(--border-subtle);
  background: rgba(0, 0, 0, 0.2);
  z-index: 1;
}

.jd-chat-footer a { color: var(--text-secondary); }

.jd-chat-error {
  align-self: stretch;
  padding: 10px 12px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  font-size: 13px;
  border-radius: 10px;
}

@media (max-width: 640px) {
  #jd-chat-panel {
    right: 12px;
    left: 12px;
    width: auto;
    bottom: calc(12px + var(--jd-bubble-size) + 10px);
    height: calc(100vh - 120px);
  }
  #jd-chat-bubble { right: 16px; bottom: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  #jd-chat-bubble .jd-pulse,
  .jd-typing span { animation: none; }
  .jd-msg { animation: none; }
  #jd-chat-panel { transition: opacity var(--transition-fast); }
}
