/* ===== AI Chat Widget — Cactus Retro Theme ===== */

/* ---------- Variables ---------- */
:root {
  --ai-bg: #fafafa;
  --ai-bg-panel: #ffffff;
  --ai-text: #363533;
  --ai-text-muted: #666;
  --ai-accent: rgba(43, 188, 138, 1);
  --ai-accent-hover: rgba(35, 160, 118, 1);
  --ai-accent-light: rgba(43, 188, 138, 0.1);
  --ai-border: #e0e0e0;
  --ai-user-bubble: rgba(43, 188, 138, 0.12);
  --ai-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  --ai-radius: 12px;
  --ai-panel-w: 380px;
  --ai-panel-h: 520px;
  --ai-btn-size: 52px;
  --ai-z: 9999;
}

/* ---------- Floating Button ---------- */
#ai-chat-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: var(--ai-btn-size);
  height: var(--ai-btn-size);
  border-radius: 50%;
  background: var(--ai-accent);
  color: #fff;
  border: none;
  cursor: pointer;
  z-index: var(--ai-z);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(43, 188, 138, 0.35);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.3s ease,
              background 0.2s ease;
  animation: ai-pulse 3s ease-in-out infinite;
}

#ai-chat-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 24px rgba(43, 188, 138, 0.5);
  background: var(--ai-accent-hover);
}

#ai-chat-btn.open {
  animation: none;
  transform: rotate(45deg) scale(1);
}

#ai-chat-btn.open:hover {
  transform: rotate(45deg) scale(1.1);
}

#ai-chat-btn svg {
  width: 24px;
  height: 24px;
  transition: transform 0.3s ease;
}

@keyframes ai-pulse {
  0%, 100% { box-shadow: 0 4px 16px rgba(43, 188, 138, 0.35); }
  50%      { box-shadow: 0 4px 24px rgba(43, 188, 138, 0.55); }
}

/* ---------- Chat Panel ---------- */
#ai-chat-panel {
  position: fixed;
  bottom: 88px;
  right: 24px;
  width: var(--ai-panel-w);
  height: var(--ai-panel-h);
  background: var(--ai-bg-panel);
  border-radius: var(--ai-radius);
  box-shadow: var(--ai-shadow);
  z-index: var(--ai-z);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--ai-border);

  /* entry animation */
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.3s ease,
              transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

/* ---------- Header ---------- */
.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--ai-accent);
  color: #fff;
  flex-shrink: 0;
}

.ai-chat-header-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-chat-header-title svg {
  width: 18px;
  height: 18px;
}

.ai-chat-close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  font-size: 18px;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background 0.2s, color 0.2s;
  line-height: 1;
}

.ai-chat-close:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

/* ---------- Messages Area ---------- */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--ai-bg);
}

.ai-chat-messages::-webkit-scrollbar {
  width: 4px;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 2px;
}

/* ---------- Message Bubbles ---------- */
.ai-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--ai-radius);
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--ai-text);
  word-wrap: break-word;
  animation: ai-fade-in 0.25s ease;
}

.ai-msg.bot {
  align-self: flex-start;
  background: var(--ai-bg-panel);
  border: 1px solid var(--ai-border);
  border-bottom-left-radius: 4px;
}

.ai-msg.user {
  align-self: flex-end;
  background: var(--ai-user-bubble);
  border: 1px solid rgba(43, 188, 138, 0.2);
  border-bottom-right-radius: 4px;
}

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

/* ---------- Markdown in bot messages ---------- */
.ai-msg.bot strong {
  font-weight: 600;
}

.ai-msg.bot code {
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12.5px;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

.ai-msg.bot pre {
  background: rgba(0, 0, 0, 0.06);
  padding: 8px 10px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 6px 0;
}

.ai-msg.bot pre code {
  background: none;
  padding: 0;
}

.ai-msg.bot ul, .ai-msg.bot ol {
  margin: 4px 0;
  padding-left: 20px;
}

.ai-msg.bot a {
  color: var(--ai-accent);
  text-decoration: underline;
}

/* Cursor blink effect while streaming */
.ai-cursor::after {
  content: '▍';
  animation: ai-blink 0.6s step-end infinite;
  color: var(--ai-accent);
}

@keyframes ai-blink {
  50% { opacity: 0; }
}

/* ---------- Sources (context articles) ---------- */
.ai-sources {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--ai-border);
  font-size: 11.5px;
  color: var(--ai-text-muted);
}

.ai-sources summary {
  cursor: pointer;
  user-select: none;
}

.ai-sources a {
  color: var(--ai-accent);
  text-decoration: none;
}

.ai-sources a:hover {
  text-decoration: underline;
}

/* ---------- Input Area ---------- */
.ai-chat-input {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--ai-border);
  background: var(--ai-bg-panel);
  flex-shrink: 0;
}

.ai-chat-input textarea {
  flex: 1;
  border: 1px solid var(--ai-border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--ai-text);
  background: var(--ai-bg);
  resize: none;
  outline: none;
  min-height: 36px;
  max-height: 80px;
  line-height: 1.5;
  transition: border-color 0.2s;
}

.ai-chat-input textarea:focus {
  border-color: var(--ai-accent);
}

.ai-chat-input textarea::placeholder {
  color: #aaa;
}

.ai-chat-send {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: var(--ai-accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s;
}

.ai-chat-send:hover {
  background: var(--ai-accent-hover);
}

.ai-chat-send:active {
  transform: scale(0.92);
}

.ai-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ai-chat-send svg {
  width: 18px;
  height: 18px;
}

/* ---------- Mobile responsive ---------- */
@media (max-width: 480px) {
  #ai-chat-panel {
    width: calc(100vw - 16px);
    height: calc(100vh - 120px);
    bottom: 76px;
    right: 8px;
    border-radius: 16px;
  }

  #ai-chat-btn {
    bottom: 16px;
    right: 16px;
  }
}
