/* ==========================================================================
   Housecall Chiropractic — chat assistant widget
   ========================================================================== */

.chatbot {
  position: fixed;
  bottom: var(--space-md);
  right: var(--space-md);
  z-index: 99995;
  font-family: var(--font-body);
}

.chatbot__trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.875rem 1.125rem;
  background-image: var(--gradient-gold);
  color: var(--color-cta-text);
  border: 1px solid rgba(241, 201, 97, 0.35);
  border-radius: 100px;
  box-shadow: var(--shadow-lg);
  font-size: 0.9375rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  min-height: 52px;
}

.chatbot__trigger:hover,
.chatbot__trigger:focus-visible {
  transform: translateY(-2px);
  filter: brightness(1.05);
  outline: none;
}

.chatbot__trigger-label {
  line-height: 1;
}

.chatbot__panel {
  position: absolute;
  bottom: calc(100% + 0.75rem);
  right: 0;
  width: min(380px, calc(100vw - 2rem));
  max-height: min(560px, calc(100vh - 8rem));
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  transform-origin: bottom right;
  animation: chatbot-rise 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

.chatbot__panel[hidden] {
  display: none !important;
}

.chatbot__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: linear-gradient(135deg, #251803 0%, #181611 100%);
  border-bottom: 1px solid var(--color-border);
}

.chatbot__title {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
  line-height: 1.2;
}

.chatbot__subtitle {
  margin: 0.2rem 0 0;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.chatbot__close {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--color-text-muted);
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  cursor: pointer;
  flex-shrink: 0;
}

.chatbot__close:hover,
.chatbot__close:focus-visible {
  color: var(--color-text);
  border-color: var(--color-gold);
  outline: none;
}

.chatbot__messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--space-sm);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  min-height: 220px;
  max-height: 360px;
  background: var(--color-background);
}

.chatbot__message {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-width: 92%;
}

.chatbot__message--user {
  align-self: flex-end;
  align-items: flex-end;
}

.chatbot__message--bot {
  align-self: flex-start;
  align-items: flex-start;
}

.chatbot__bubble {
  padding: 0.65rem 0.85rem;
  font-size: 0.875rem;
  line-height: 1.55;
  border-radius: 14px;
}

.chatbot__message--user .chatbot__bubble {
  background: var(--gradient-gold);
  color: var(--color-cta-text);
  border-bottom-right-radius: 4px;
}

.chatbot__message--bot .chatbot__bubble {
  background: var(--color-surface-elevated);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-bottom-left-radius: 4px;
}

.chatbot__message.is-new .chatbot__bubble {
  animation: chatbot-fade-in 200ms ease;
}

.chatbot__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.chatbot__chip {
  padding: 0.35rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-gold-light);
  background: var(--color-accent-soft);
  border: 1px solid rgba(212, 152, 36, 0.35);
  border-radius: 100px;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.chatbot__chip:hover,
.chatbot__chip:focus-visible {
  background: rgba(212, 152, 36, 0.18);
  border-color: var(--color-gold);
  outline: none;
}

.chatbot__link {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-gold-light);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chatbot__form {
  display: flex;
  gap: 0.5rem;
  padding: var(--space-sm);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}

.chatbot__input {
  flex: 1;
  min-width: 0;
  padding: 0.7rem 0.85rem;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--color-text);
  background: #1e1a13;
  border: 1px solid var(--color-border);
  border-radius: 100px;
}

.chatbot__input:focus {
  outline: none;
  border-color: var(--color-gold);
  box-shadow: 0 0 0 3px rgba(212, 152, 36, 0.2);
}

.chatbot__send {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-image: var(--gradient-gold);
  color: var(--color-cta-text);
  border: none;
  border-radius: 50%;
  cursor: pointer;
}

.chatbot__send:hover,
.chatbot__send:focus-visible {
  filter: brightness(1.06);
  outline: none;
}

.chatbot__typing .chatbot__bubble {
  display: inline-flex;
  gap: 0.3rem;
  align-items: center;
  min-width: 3rem;
}

.chatbot__typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-gold);
  animation: chatbot-dot 1.2s infinite ease-in-out;
}

.chatbot__typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.chatbot__typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes chatbot-rise {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes chatbot-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes chatbot-dot {
  0%, 80%, 100% { opacity: 0.35; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1); }
}

@media (max-width: 767px) {
  .chatbot {
    bottom: calc(var(--space-md) + 56px + env(safe-area-inset-bottom, 0px));
    right: calc(var(--space-sm) + env(safe-area-inset-right, 0px));
  }

  .chatbot__trigger-label {
    display: none;
  }

  .chatbot__trigger {
    width: 52px;
    height: 52px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
  }

  .chatbot__panel {
    width: min(360px, calc(100vw - 1rem));
    right: 0;
  }
}

@media (min-width: 768px) {
  .fab-book ~ .chatbot,
  .chatbot {
    bottom: var(--space-md);
  }
}

@media (prefers-reduced-motion: reduce) {
  .chatbot__panel,
  .chatbot__message.is-new .chatbot__bubble,
  .chatbot__typing span {
    animation: none;
  }
}
