/* TerraTrend - chatbot.css
   AI chatbot FAB and panel */

/* ---------- AI Chatbot (FAB + panel) ---------- */
.chatbot-wrap {
  position: fixed;
  top: calc(var(--appbar-h) + 14px);
  bottom: 32px;
  right: 28px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 10px;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.chatbot-wrap > * { pointer-events: auto; }

/* Hide FAB when a variable/hotspot panel is open (all screens) or any panel on mobile */
.chatbot-wrap.panel-open { opacity: 0 !important; pointer-events: none !important; }
.chatbot-wrap.panel-open .chatbot-fab { pointer-events: none; }

/* The floating chat button */
.chatbot-fab {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(9, 10, 24, 0.95);
  border: 1px solid rgba(139, 124, 255, 0.45);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 8px 28px rgba(139, 124, 255, 0.35),
    0 0 0 4px rgba(139, 124, 255, 0.08);
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.22s, border-color 0.22s;
}
.chatbot-fab:hover {
  transform: scale(1.08) translateY(-2px);
  border-color: rgba(139, 124, 255, 0.75);
  box-shadow: 0 12px 36px rgba(139, 124, 255, 0.5), 0 0 0 4px rgba(139, 124, 255, 0.14);
}
.chatbot-fab svg { stroke: var(--accent-2); }

/* Chat panel */
.chatbot-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  width: min(320px, calc(100vw - 40px));
  background: rgba(5, 6, 20, 0.98);
  border: 1px solid rgba(140, 150, 255, 0.2);
  border-radius: 18px;
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.7),
    0 0 50px -20px rgba(139, 124, 255, 0.4),
    0 0 0 1px rgba(139, 124, 255, 0.06) inset;
  overflow: hidden;
  animation: chatSlideIn 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes chatSlideIn {
  from { opacity: 0; transform: translateX(16px) scale(0.97); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}
.chatbot-panel.closing {
  animation: chatSlideOut 0.21s cubic-bezier(0.4, 0, 1, 1) forwards;
}
@keyframes chatSlideOut {
  from { opacity: 1; transform: translateX(0) scale(1); }
  to   { opacity: 0; transform: translateX(16px) scale(0.97); }
}
.chatbot-panel[hidden] { display: none; }

/* Panel header with avatar */
.chatbot-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 14px;
  border-bottom: 1px solid rgba(140, 150, 255, 0.1);
  background: rgba(8, 9, 24, 0.6);
}
.chatbot-head-info {
  display: flex;
  align-items: center;
  gap: 10px;
}
.chatbot-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(34, 224, 238, 0.25), rgba(139, 124, 255, 0.35));
  border: 1px solid rgba(140, 150, 255, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chatbot-avatar svg { stroke: var(--accent-2); }
.chatbot-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
}
.chatbot-status {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  color: var(--accent);
  opacity: 0.8;
  margin-top: 1px;
}

/* Message thread */
.chatbot-messages {
  padding: 14px 14px 10px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: rgba(4, 5, 14, 0.5);
}
.chatbot-messages::-webkit-scrollbar { width: 4px; }
.chatbot-messages::-webkit-scrollbar-track { background: transparent; }
.chatbot-messages::-webkit-scrollbar-thumb { background: rgba(140, 150, 255, 0.2); border-radius: 99px; }

.chat-msg { display: flex; align-items: flex-end; gap: 8px; }
.chat-msg-ai  { justify-content: flex-start; }
.chat-msg-user { justify-content: flex-end; }

.chat-bubble {
  max-width: 84%;
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 0.8rem;
  line-height: 1.55;
  color: var(--text-secondary);
}
.chat-msg-ai .chat-bubble {
  background: rgba(139, 124, 255, 0.1);
  border: 1px solid rgba(139, 124, 255, 0.18);
  border-bottom-left-radius: 4px;
  color: var(--text-secondary);
}
.chat-msg-user .chat-bubble {
  background: rgba(34, 224, 238, 0.1);
  border: 1px solid rgba(34, 224, 238, 0.18);
  border-bottom-right-radius: 4px;
  color: var(--text);
}
.chat-coming-soon {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  color: var(--accent);
  opacity: 0.7;
  display: block;
  margin-top: 6px;
}

/* Suggestion chips */
.chat-suggestions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 2px;
}
.chat-suggestion-btn {
  background: rgba(139, 124, 255, 0.07);
  border: 1px solid rgba(139, 124, 255, 0.22);
  border-radius: 10px;
  color: rgba(200, 196, 255, 0.85);
  font-family: var(--font-display);
  font-size: 0.73rem;
  line-height: 1.4;
  padding: 7px 11px;
  text-align: left;
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s;
}
.chat-suggestion-btn:hover {
  background: rgba(139, 124, 255, 0.16);
  border-color: rgba(139, 124, 255, 0.45);
  color: #fff;
}

/* Input row */
.chatbot-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid rgba(140, 150, 255, 0.1);
  background: rgba(8, 9, 24, 0.6);
}
.chatbot-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(140, 150, 255, 0.18);
  border-radius: 999px;
  color: var(--text-secondary);
  font-family: var(--font-display);
  font-size: 0.78rem;
  padding: 8px 14px;
  outline: none;
  cursor: text;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.chatbot-input:focus {
  border-color: rgba(139, 124, 255, 0.45);
  box-shadow: 0 0 0 2px rgba(139, 124, 255, 0.1);
}
.chatbot-input:disabled { cursor: not-allowed; opacity: 0.5; }
.chatbot-send {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(139, 124, 255, 0.12);
  border: 1px solid rgba(139, 124, 255, 0.25);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.chatbot-send:not(:disabled):hover {
  background: rgba(139, 124, 255, 0.22);
  border-color: rgba(139, 124, 255, 0.55);
  box-shadow: 0 0 14px -4px rgba(139, 124, 255, 0.5);
}
.chatbot-send:disabled { cursor: not-allowed; opacity: 0.4; }
.chatbot-send svg { stroke: currentColor; }

/* Thinking dots (shown while waiting for API response) */
.chat-thinking { min-height: 36px; display: flex; align-items: center; }
.thinking-dots { display: inline-flex; gap: 5px; align-items: center; padding: 2px 0; }
.thinking-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(139, 124, 255, 0.65);
  animation: ttDotBounce 1.3s ease-in-out infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.18s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.36s; }
@keyframes ttDotBounce {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.35; }
  30%            { transform: translateY(-6px); opacity: 1;    }
}

/* Panel link chips — injected below AI replies that mention a hotspot */
.chat-panel-links {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 2px 0 2px 4px;
}
.chat-panel-link-btn {
  background: transparent;
  border: 1px solid rgba(139, 124, 255, 0.3);
  border-radius: 999px;
  color: rgba(180, 170, 255, 0.85);
  font-family: var(--font-mono);
  font-size: 0.63rem;
  letter-spacing: 0.05em;
  padding: 3px 10px;
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, color 0.18s;
  white-space: nowrap;
}
.chat-panel-link-btn:hover {
  background: rgba(139, 124, 255, 0.14);
  border-color: rgba(139, 124, 255, 0.65);
  color: #fff;
}

/* Mobile: FAB floats above the dock; panel slides up when opened */
/* MUST be last so it wins over the base bottom/top/right above  */
@media (max-width: 900px) {
  .chatbot-wrap {
    top: calc(var(--appbar-h) + 10px);
    bottom: calc(120px + env(safe-area-inset-bottom, 0px));
    right: 14px;
  }
  /* Panel fills the full wrap height and stretches to near-full width */
  .chatbot-panel {
    flex: 1;
    height: auto;
    width: calc(100vw - 28px);
  }
  /* (panel-open hiding handled globally above) */
}
