/**
 * dusty-chat.css
 * Styles for the Dusty AI chat widget and two-button choice UI
 * Uses existing design tokens from css/styles.css
 */

/* =================================================================
   ANIMATIONS
   ================================================================= */

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

@keyframes dustyFadeOut {
  from { opacity: 1; }
  to   { opacity: 0; }
}

@keyframes dustyBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

@keyframes dustyPulse {
  /* navy-800 (#1B2A4A) with alpha — cannot use var() in keyframes */
  0%   { box-shadow: 0 0 0 0 rgba(27, 42, 74, 0.4); }
  70%  { box-shadow: 0 0 0 12px rgba(27, 42, 74, 0); }
  100% { box-shadow: 0 0 0 0 rgba(27, 42, 74, 0); }
}

@keyframes dustyTriggerEntrance {
  0%   { opacity: 0; transform: scale(0.5) translateY(20px); }
  60%  { opacity: 1; transform: scale(1.1) translateY(-2px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

/* =================================================================
   TWO-BUTTON CHOICE UI
   ================================================================= */

.dusty-choice {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: var(--space-lg);
  animation: dustyFadeIn 0.4s ease;
}

.dusty-choice__card {
  background: var(--white);
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-xl) var(--space-lg);
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-base);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
  position: relative;
  overflow: hidden;
}

.dusty-choice__card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--blue-200);
}

.dusty-choice__card:focus-visible {
  outline: 2px solid var(--blue-500);
  outline-offset: 2px;
}

.dusty-choice__card--active,
.dusty-choice__card--active:hover {
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px rgba(59, 141, 214, 0.15), var(--shadow-md);
}

.dusty-choice__icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--blue-100);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: var(--blue-500);
  margin-bottom: var(--space-xs);
  transition: all var(--transition-base);
}

.dusty-choice__card:hover .dusty-choice__icon {
  background: var(--blue-200);
  transform: scale(1.08);
}

.dusty-choice__title {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--navy-800);
  margin: 0;
  line-height: 1.3;
}

.dusty-choice__subtitle {
  font-size: 0.875rem;
  color: var(--gray-400);
  margin: 0;
  line-height: 1.5;
}

/* Switch links below the choice cards */
.dusty-switch {
  text-align: center;
  margin-top: var(--space-md);
  animation: dustyFadeIn 0.3s ease;
}

.dusty-switch__link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--blue-500);
  cursor: pointer;
  border: none;
  background: none;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  transition: all var(--transition-fast);
}

.dusty-switch__link:hover {
  color: var(--blue-400);
  background: var(--blue-100);
}

.dusty-switch__link:focus-visible {
  outline: 2px solid var(--blue-500);
  outline-offset: 2px;
}

/* =================================================================
   CHAT INTERFACE
   ================================================================= */

.dusty-chat {
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  background: var(--white);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: dustyFadeIn 0.4s ease;
  height: 520px;
  max-height: 70vh;
}

/* Chat header */
.dusty-chat__header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  background: var(--navy-800);
  color: var(--white);
  flex-shrink: 0;
}

.dusty-chat__header-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.dusty-chat__header-info {
  flex: 1;
  min-width: 0;
}

.dusty-chat__header-name {
  font-size: 0.9375rem;
  font-weight: 600;
  margin: 0;
  line-height: 1.3;
}

.dusty-chat__header-status {
  font-size: 0.75rem;
  color: var(--cyan-300);
  margin: 0;
  line-height: 1.3;
}

/* Messages area */
.dusty-chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  scroll-behavior: smooth;
  background: var(--gray-50);
  scrollbar-width: thin;
  scrollbar-color: var(--gray-200) transparent;
}

/* Scrollbar styling */
.dusty-chat__messages::-webkit-scrollbar {
  width: 6px;
}

.dusty-chat__messages::-webkit-scrollbar-track {
  background: transparent;
}

.dusty-chat__messages::-webkit-scrollbar-thumb {
  background: var(--gray-200);
  border-radius: 3px;
}

.dusty-chat__messages::-webkit-scrollbar-thumb:hover {
  background: var(--gray-400);
}

/* Message row */
.dusty-chat__message {
  display: flex;
  gap: var(--space-sm);
  max-width: 85%;
  animation: dustyFadeIn 0.3s ease;
}

.dusty-chat__message--assistant {
  align-self: flex-start;
}

.dusty-chat__message--user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

/* Broom avatar */
.dusty-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--blue-100);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  align-self: flex-end;
}

.dusty-chat__message--user .dusty-avatar {
  display: none;
}

/* Message bubble */
.dusty-chat__bubble {
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 0.9375rem;
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
}

.dusty-chat__message--assistant .dusty-chat__bubble {
  background: var(--blue-100);
  color: var(--gray-800);
  border-bottom-left-radius: 4px;
}

.dusty-chat__message--user .dusty-chat__bubble {
  background: var(--blue-500);
  color: var(--white);
  border-bottom-right-radius: 4px;
}

/* Typing indicator */
.dusty-typing {
  display: flex;
  gap: var(--space-sm);
  align-self: flex-start;
  max-width: 85%;
  animation: dustyFadeIn 0.3s ease;
}

.dusty-typing__dots {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 18px;
  background: var(--blue-100);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
}

.dusty-typing__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--blue-500);
  opacity: 0.4;
  animation: dustyBounce 1.4s ease infinite;
}

.dusty-typing__dot:nth-child(2) {
  animation-delay: 0.2s;
}

.dusty-typing__dot:nth-child(3) {
  animation-delay: 0.4s;
}

/* Input area */
.dusty-chat__input-area {
  display: flex;
  align-items: flex-end;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--gray-200);
  background: var(--white);
  flex-shrink: 0;
}

.dusty-chat__input {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 10px 16px;
  font-family: 'Outfit', sans-serif;
  font-size: 0.9375rem;
  color: var(--gray-800);
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  resize: none;
  overflow-y: auto;
  line-height: 1.5;
  transition: border-color var(--transition-fast);
}

.dusty-chat__input:focus {
  outline: 2px solid transparent;
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px rgba(59, 141, 214, 0.15);
}

.dusty-chat__input:focus-visible {
  outline: 2px solid var(--blue-500);
  outline-offset: 2px;
}

.dusty-chat__input::placeholder {
  color: var(--gray-400);
}

.dusty-chat__send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--blue-500);
  color: var(--white);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.dusty-chat__send:hover {
  background: var(--blue-400);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 141, 214, 0.3);
}

.dusty-chat__send:active {
  transform: translateY(0);
}

.dusty-chat__send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.dusty-chat__send:disabled:hover {
  background: var(--blue-500);
  transform: none;
  box-shadow: none;
}

/* =================================================================
   LEAD CONFIRMATION CARD
   ================================================================= */

.dusty-lead-card {
  background: var(--white);
  border: 1px solid var(--blue-200);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-lg);
  margin: var(--space-sm) 0;
  animation: dustyFadeIn 0.4s ease;
  max-width: 85%;
  align-self: flex-start;
}

.dusty-lead-card__title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--navy-800);
  margin: 0 0 var(--space-sm) 0;
}

.dusty-lead-card__detail {
  font-size: 0.8125rem;
  color: var(--gray-600);
  margin: 4px 0;
  line-height: 1.5;
}

.dusty-lead-card__detail strong {
  color: var(--gray-800);
  font-weight: 600;
}

.dusty-lead-card__actions {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-md);
}

.dusty-lead-card__btn {
  padding: 8px 20px;
  font-size: 0.8125rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  line-height: 1;
}

.dusty-lead-card__btn--confirm {
  background: var(--blue-500);
  color: var(--white);
}

.dusty-lead-card__btn--confirm:hover {
  background: var(--blue-400);
  transform: translateY(-1px);
}

.dusty-lead-card__btn--cancel {
  background: var(--gray-50);
  color: var(--gray-600);
  border: 1px solid var(--gray-200);
}

.dusty-lead-card__btn--cancel:hover {
  background: var(--gray-100);
}

.dusty-lead-card__btn:focus-visible {
  outline: 2px solid var(--blue-500);
  outline-offset: 2px;
}

/* Success confirmation inline */
.dusty-lead-success {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 12px 16px;
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid var(--success);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  color: #166534;
  max-width: 85%;
  align-self: flex-start;
  animation: dustyFadeIn 0.4s ease;
}

.dusty-lead-success i {
  color: var(--success);
  font-size: 1.1rem;
}

/* =================================================================
   ERROR MESSAGE IN CHAT
   ================================================================= */

.dusty-chat__error {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 10px 14px;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  color: var(--error);
  max-width: 85%;
  align-self: center;
  animation: dustyFadeIn 0.3s ease;
}

/* =================================================================
   TRANSITION BETWEEN FORM AND CHAT
   ================================================================= */

.dusty-fade-out {
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.dusty-fade-in {
  animation: dustyFadeIn 0.4s ease;
}

.dusty-hidden {
  display: none !important;
}

/* z-index scale: 900 mobile-cta, 950 dusty-trigger, 1000 navbar, 1005 overlay, 1010 hamburger */

/* =================================================================
   DUSTY TRIGGER BUTTON (OTHER PAGES)
   ================================================================= */

.dusty-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--navy-800);
  color: var(--white);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  z-index: 950;
  box-shadow: var(--shadow-md);
  transition: all var(--transition-base);
  animation: dustyTriggerEntrance 0.6s ease forwards,
             dustyPulse 2s ease 1s 3;
}

.dusty-trigger:hover {
  background: var(--navy-700);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.dusty-trigger:active {
  transform: translateY(0);
}

.dusty-trigger:focus-visible {
  outline: 2px solid var(--blue-500);
  outline-offset: 3px;
}

/* Tooltip */
.dusty-trigger__tooltip {
  position: absolute;
  right: 56px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--navy-800);
  color: var(--white);
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
  box-shadow: var(--shadow-md);
}

.dusty-trigger:hover .dusty-trigger__tooltip {
  opacity: 1;
}

/* Hide trigger on contact page */
body.page-contact .dusty-trigger {
  display: none;
}

/* Move trigger up when mobile CTA is visible */
@media (max-width: 767px) {
  .dusty-trigger {
    bottom: 80px;
  }
}

/* =================================================================
   MOBILE RESPONSIVE
   ================================================================= */

@media (max-width: 575px) {
  .dusty-choice {
    grid-template-columns: 1fr;
    gap: var(--space-md);
  }

  .dusty-choice__card {
    padding: var(--space-lg) var(--space-md);
  }

  .dusty-chat {
    height: 460px;
    max-height: 65vh;
    border-radius: var(--radius-md);
  }

  .dusty-chat__messages {
    padding: var(--space-md);
    gap: var(--space-sm);
  }

  .dusty-chat__input-area {
    padding: var(--space-sm) var(--space-md);
  }

  .dusty-chat__message {
    max-width: 90%;
  }

  .dusty-lead-card,
  .dusty-lead-success {
    max-width: 90%;
  }

  .dusty-chat__bubble {
    font-size: 0.875rem;
    padding: 10px 14px;
  }

  .dusty-avatar {
    width: 30px;
    height: 30px;
    font-size: 0.9rem;
  }

  .dusty-trigger__tooltip {
    display: none;
  }
}

@media (max-width: 767px) {
  .dusty-chat__header {
    padding: var(--space-sm) var(--space-md);
  }
}

/* =================================================================
   PRINT STYLES
   ================================================================= */

@media print {
  .dusty-trigger,
  .dusty-chat,
  .dusty-choice,
  .dusty-switch {
    display: none !important;
  }
}

/* =================================================================
   REDUCED MOTION
   ================================================================= */

@media (prefers-reduced-motion: reduce) {
  .dusty-trigger,
  .dusty-choice,
  .dusty-chat,
  .dusty-chat__message,
  .dusty-typing__dot,
  .dusty-fade-in,
  .dusty-lead-card,
  .dusty-lead-success,
  .dusty-chat__error {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }
}
