#co-ai-chat-root {
  position: fixed;
  bottom: var(--kfc-vert, 24px);
  z-index: 9980;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Position variants — applied by JS */
#co-ai-chat-root.co-ai-pos-right {
  right: var(--kfc-horz, 24px);
  left: auto;
}
#co-ai-chat-root.co-ai-pos-left {
  left: var(--kfc-horz, 24px);
  right: auto;
}

/* ── Glow ring wrapper ──────────────────────────────────────────────────── */
.co-ai-glow-ring {
  position: relative;
  display: inline-flex;
  border-radius: 50%;
}

.co-ai-glow-ring::before {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    #c084fc 0%,
    #818cf8 25%,
    #38bdf8 55%,
    #a78bfa 75%,
    #c084fc 100%
  );
  animation: coAiSpin 2.5s linear infinite;
  z-index: -1;
  opacity: 0.95;
}

/* Soft pulse behind button */
.co-ai-glow-ring::after {
  content: '';
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(129,140,248,0.25) 0%, transparent 70%);
  animation: coAiPulse 2.5s ease-in-out infinite;
  z-index: -2;
}

/* Hide ring when panel is open (shows close icon) */
.co-ai-open .co-ai-glow-ring::before,
.co-ai-open .co-ai-glow-ring::after {
  opacity: 0;
  animation: none;
}

@keyframes coAiSpin {
  to { transform: rotate(360deg); }
}

@keyframes coAiPulse {
  0%, 100% { transform: scale(1);    opacity: 0.6; }
  50%       { transform: scale(1.18); opacity: 1;   }
}

/* ── AI label pill ─────────────────────────────────────────────────────── */
.co-ai-btn-label {
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(90deg, #818cf8, #c084fc);
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1;
  padding: 3px 7px;
  border-radius: 20px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 2;
  box-shadow: 0 2px 8px rgba(129,140,248,0.5);
}

.co-ai-open .co-ai-btn-label { display: none; }

/* ── Toggle Button ─────────────────────────────────────────────────────── */
#co-ai-chat-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7026fc, #9b5cf6);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 4px 20px rgba(112, 38, 252, 0.45), 0 0 0 2px rgba(255,255,255,0.15) inset;
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
  z-index: 1;
}

#co-ai-chat-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(112, 38, 252, 0.6), 0 0 0 2px rgba(255,255,255,0.2) inset;
}

#co-ai-chat-btn svg { transition: opacity 0.2s, transform 0.2s; }
#co-ai-chat-btn .co-ai-chat-close-icon {
  position: absolute;
  opacity: 0;
  transform: rotate(-90deg);
}

.co-ai-open #co-ai-chat-btn svg:first-child {
  opacity: 0;
  transform: rotate(90deg);
}
.co-ai-open #co-ai-chat-btn .co-ai-chat-close-icon {
  opacity: 1;
  transform: rotate(0deg);
}

/* ── Panel ─────────────────────────────────────────────────────────────── */
#co-ai-chat-panel {
  position: absolute;
  bottom: 56px;
  width: 340px;
  max-height: 480px;
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

/* Panel opens toward the button's side */
.co-ai-pos-right #co-ai-chat-panel { right: 0; left: auto; }
.co-ai-pos-left  #co-ai-chat-panel { left: 0;  right: auto; }

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

/* ── Header ────────────────────────────────────────────────────────────── */
#co-ai-chat-header {
  background: var(--code-order-primary, #7026fc);
  padding: 14px 16px;
  color: #fff;
}

.co-ai-chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.co-ai-chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}

.co-ai-chat-name {
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.2;
}

.co-ai-chat-status {
  font-size: 0.72rem;
  opacity: 0.8;
  display: flex;
  align-items: center;
  gap: 4px;
}

.co-ai-chat-status::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
}

/* ── Messages ──────────────────────────────────────────────────────────── */
#co-ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f8f7fc;
  scroll-behavior: smooth;
}

#co-ai-chat-messages::-webkit-scrollbar { width: 4px; }
#co-ai-chat-messages::-webkit-scrollbar-track { background: transparent; }
#co-ai-chat-messages::-webkit-scrollbar-thumb { background: #ddd; border-radius: 4px; }

.co-ai-msg {
  display: flex;
  animation: coAiIn 0.18s ease;
}

@keyframes coAiIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.co-ai-msg--bot  { justify-content: flex-start; }
.co-ai-msg--user { justify-content: flex-end; }

.co-ai-bubble {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.875rem;
  line-height: 1.5;
  word-break: break-word;
}

.co-ai-msg--bot .co-ai-bubble {
  background: #fff;
  color: #1a1a2e;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}

.co-ai-msg--user .co-ai-bubble {
  background: var(--code-order-primary, #7026fc);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Typing dots */
.co-ai-dots {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 2px 0;
}

.co-ai-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #aaa;
  animation: coAiDot 1.2s infinite;
}

.co-ai-dots span:nth-child(2) { animation-delay: 0.2s; }
.co-ai-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes coAiDot {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
  40%            { transform: scale(1.2); opacity: 1; }
}

/* ── Status bubble ─────────────────────────────────────────────────────── */
.co-ai-bubble--status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.82rem;
  font-weight: 600;
}

.co-ai-bubble--status-open   { background: #f0fdf4; color: #15803d; box-shadow: none; border: 1px solid #bbf7d0; }
.co-ai-bubble--status-closed { background: #fff7ed; color: #c2410c; box-shadow: none; border: 1px solid #fed7aa; }

.co-ai-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.co-ai-status-dot--open   { background: #22c55e; box-shadow: 0 0 0 2px #bbf7d0; }
.co-ai-status-dot--closed { background: #f97316; box-shadow: 0 0 0 2px #fed7aa; }

/* ── Footer / Input ────────────────────────────────────────────────────── */
#co-ai-chat-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid #eee;
  background: #fff;
}

#co-ai-chat-input {
  flex: 1;
  border: 1px solid #e2e0ec;
  border-radius: 22px;
  padding: 9px 14px;
  font-size: 16px;
  outline: none;
  background: #f8f7fc;
  color: #1a1a2e;
  transition: border-color 0.15s;
  font-family: inherit;
}

#co-ai-chat-input:focus {
  border-color: var(--code-order-primary, #7026fc);
  background: #fff;
}

#co-ai-chat-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--code-order-primary, #7026fc);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.15s;
}

#co-ai-chat-send:hover { opacity: 0.88; transform: scale(1.06); }
#co-ai-chat-send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ── Nudge bubble ──────────────────────────────────────────────────────── */
#co-ai-nudge {
  position: absolute;
  bottom: calc(100% + 12px);
  white-space: nowrap;
  max-width: 220px;
  white-space: normal;
  background: #fff;
  color: #1a1a2e;
  font-size: 0.82rem;
  line-height: 1.45;
  font-weight: 500;
  padding: 10px 14px;
  border-radius: 14px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.14);
  pointer-events: auto;
  animation: coNudgeIn 0.3s cubic-bezier(0.34,1.56,0.64,1) both;
  z-index: 10;
}

/* Tail pointing down */
#co-ai-nudge::after {
  content: '';
  position: absolute;
  bottom: -7px;
  width: 14px;
  height: 14px;
  background: #fff;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.08));
}

.co-ai-pos-right #co-ai-nudge { right: 0; }
.co-ai-pos-right #co-ai-nudge::after { right: 15px; }
.co-ai-pos-left  #co-ai-nudge { left: 0; }
.co-ai-pos-left  #co-ai-nudge::after { left: 15px; }

/* Close ×  button inside nudge */
#co-ai-nudge-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: 6px;
  right: 6px;
  width: 18px;
  height: 18px;
  border: none;
  background: none;
  cursor: pointer;
  color: #94a3b8;
  padding: 0;
  border-radius: 50%;
  font-size: 14px;
  line-height: 1;
  transition: color 0.15s;
}
#co-ai-nudge-close:hover { color: #475569; }

@keyframes coNudgeIn {
  from { opacity: 0; transform: translateY(10px) scale(0.92); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes coNudgeOut {
  to { opacity: 0; transform: translateY(6px) scale(0.94); }
}

#co-ai-nudge.co-ai-nudge--hide {
  animation: coNudgeOut 0.2s ease forwards;
}

/* ── Mobile ────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #co-ai-chat-panel {
    width: calc(100vw - 32px);
    bottom: 58px;
    max-height: 420px;
    border-radius: 14px;
  }
  .co-ai-pos-right #co-ai-chat-panel { right: -4px; }
  .co-ai-pos-left  #co-ai-chat-panel { left: -4px; }
}
