/* ============================================
   RAG Chat Widget — LastManBoarding
   A floating conversational assistant
   ============================================ */

/* --- Trigger pill --- */
.chat-trigger {
  position: fixed;
  bottom: var(--space-xl);
  right: var(--space-xl);
  z-index: 400;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 0.7em 1.2em 0.7em 0.9em;
  background: var(--color-dark);
  color: #fff;
  border: none;
  border-radius: 100px;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 8px 32px rgba(26, 26, 24, 0.2), 0 2px 8px rgba(26, 26, 24, 0.1);
  transition: transform var(--duration-normal) var(--ease-spring),
              box-shadow var(--duration-normal) var(--ease-out),
              background var(--duration-normal) var(--ease-out);
}

.chat-trigger:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 40px rgba(26, 26, 24, 0.25), 0 4px 12px rgba(26, 26, 24, 0.12);
  background: var(--color-dark-soft);
}

.chat-trigger:active {
  transform: translateY(0) scale(0.98);
}

.chat-trigger.is-hidden {
  transform: translateY(80px);
  opacity: 0;
  pointer-events: none;
}

.chat-trigger-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--color-red);
  border-radius: 50%;
  flex-shrink: 0;
}

.chat-trigger-text {
  white-space: nowrap;
}

.chat-trigger-dot {
  width: 6px;
  height: 6px;
  background: #4ade80;
  border-radius: 50%;
  flex-shrink: 0;
  animation: chatPulse 2s ease-in-out infinite;
}

@keyframes chatPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* --- Chat panel --- */
.chat-panel {
  position: fixed;
  bottom: var(--space-xl);
  right: var(--space-xl);
  z-index: 401;
  width: min(420px, calc(100vw - 2 * var(--space-xl)));
  height: min(600px, calc(100dvh - 2 * var(--space-xl)));
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: 0 24px 80px rgba(26, 26, 24, 0.15), 0 8px 24px rgba(26, 26, 24, 0.08);
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.95);
  transform-origin: bottom right;
  transition: opacity var(--duration-normal) var(--ease-out),
              visibility var(--duration-normal),
              transform var(--duration-normal) var(--ease-spring);
}

.chat-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* --- Chat header --- */
.chat-header {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--color-border-light);
  flex-shrink: 0;
}

.chat-avatar {
  width: 36px;
  height: 36px;
  background: var(--color-dark);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-avatar svg {
  color: #fff;
}

.chat-header-info {
  flex: 1;
  min-width: 0;
}

.chat-header-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text);
}

.chat-header-status {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  color: var(--color-text-tertiary);
}

.chat-header-status::before {
  content: '';
  width: 6px;
  height: 6px;
  background: #4ade80;
  border-radius: 50%;
}

.chat-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-tertiary);
  transition: background var(--duration-fast), color var(--duration-fast);
}

.chat-close:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

/* --- Chat messages --- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  overscroll-behavior: contain;
}

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

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 2px;
}

/* Message bubbles */
.chat-msg {
  display: flex;
  gap: var(--space-sm);
  max-width: 88%;
  animation: msgIn 0.3s var(--ease-out) both;
}

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

.chat-msg--bot {
  align-self: flex-start;
}

.chat-msg--user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-msg-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 2px;
}

.chat-msg--bot .chat-msg-avatar {
  background: var(--color-dark);
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-msg--bot .chat-msg-avatar svg {
  width: 12px;
  height: 12px;
  color: #fff;
}

.chat-msg-bubble {
  padding: 0.65em 0.9em;
  font-size: 0.875rem;
  line-height: 1.55;
  border-radius: var(--radius-lg);
}

.chat-msg--bot .chat-msg-bubble {
  background: var(--color-bg);
  color: var(--color-text);
  border-bottom-left-radius: var(--radius-sm);
}

.chat-msg--user .chat-msg-bubble {
  background: var(--color-dark);
  color: #fff;
  border-bottom-right-radius: var(--radius-sm);
}

.chat-msg-bubble a {
  color: var(--color-accent);
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat-msg--user .chat-msg-bubble a {
  color: var(--color-accent);
}

.chat-msg-bubble strong {
  font-weight: 600;
}

/* Typing indicator */
.chat-typing {
  display: flex;
  gap: 4px;
  padding: 0.65em 0.9em;
  background: var(--color-bg);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: var(--radius-sm);
  align-self: flex-start;
}

.chat-typing-dot {
  width: 6px;
  height: 6px;
  background: var(--color-text-tertiary);
  border-radius: 50%;
  animation: typingBounce 1.2s ease-in-out infinite;
}

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

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

/* --- Suggested questions --- */
.chat-suggestions {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  margin-top: var(--space-sm);
}

.chat-suggestion {
  display: inline-flex;
  padding: 0.45em 0.75em;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 100px;
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease-out),
              color var(--duration-fast) var(--ease-out),
              background var(--duration-fast) var(--ease-out);
  align-self: flex-start;
}

.chat-suggestion:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
  background: var(--color-accent-subtle);
}

/* --- Result card inside chat --- */
.chat-result-card {
  display: flex;
  gap: var(--space-sm);
  padding: var(--space-sm);
  margin-top: var(--space-sm);
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: inherit;
  transition: border-color var(--duration-fast);
}

.chat-result-card:hover {
  border-color: var(--color-accent);
}

.chat-result-card img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.chat-result-card-info {
  min-width: 0;
}

.chat-result-card-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-result-card-meta {
  font-size: 0.7rem;
  color: var(--color-text-tertiary);
  margin-top: 2px;
}

/* --- Chat input --- */
.chat-input-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--color-border-light);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  padding: 0.6em 0.9em;
  font-family: var(--font-body);
  font-size: 0.875rem;
  color: var(--color-text);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 100px;
  outline: none;
  transition: border-color var(--duration-fast);
}

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

.chat-input::placeholder {
  color: var(--color-text-tertiary);
}

.chat-send {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-dark);
  color: #fff;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background var(--duration-fast), transform var(--duration-fast);
}

.chat-send:hover {
  background: var(--color-dark-soft);
}

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

.chat-send:disabled {
  opacity: 0.3;
  cursor: default;
}

/* --- Mobile --- */
@media (max-width: 640px) {
  .chat-trigger {
    bottom: var(--space-lg);
    right: var(--space-lg);
  }

  .chat-panel {
    bottom: 0;
    right: 0;
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
    border: none;
  }

  .chat-trigger-text {
    display: none;
  }

  .chat-trigger {
    padding: 0.7em;
  }
}
