/**
 * AI Chatbot Widget Styles
 * Version: 1.3.0 - With Lead Capture, Consent & Legal Disclaimer
 */

/* ============================================
   CSS Variables & Base
   ============================================ */
.chatbot {
  --chatbot-primary: #395935;
  --chatbot-primary-light: #4fa550;
  --chatbot-bg: #ffffff;
  --chatbot-surface: #f8faf8;
  --chatbot-text: #1a1a1a;
  --chatbot-text-muted: #6b7280;
  --chatbot-border: #e5e7eb;
  --chatbot-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  --chatbot-shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --chatbot-radius: 16px;
  --chatbot-radius-sm: 8px;
  --chatbot-width: 380px;
  --chatbot-height: 580px;
  --chatbot-z: 999999;
  
  position: fixed;
  z-index: var(--chatbot-z);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

/* Position variations */
.chatbot--bottom-right {
  bottom: 24px;
  right: 24px;
}

.chatbot--bottom-left {
  bottom: 24px;
  left: 24px;
}

/* ============================================
   Toggle Button
   ============================================ */
.chatbot__toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-primary-light) 100%);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--chatbot-shadow);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: visible; /* Changed to visible so badge isn't cropped */
}

.chatbot__toggle::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.2) 0%, transparent 50%);
  opacity: 0;
  transition: opacity 0.3s;
}

.chatbot__toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 30px 60px -15px rgba(57, 89, 53, 0.4);
}

.chatbot__toggle:hover::before {
  opacity: 1;
}

.chatbot__toggle:active {
  transform: scale(0.95);
}

.chatbot__toggle-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chatbot__toggle-icon--close {
  position: absolute;
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
}

.chatbot__toggle[aria-expanded="true"] .chatbot__toggle-icon--chat {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}

.chatbot__toggle[aria-expanded="true"] .chatbot__toggle-icon--close {
  opacity: 1;
  transform: rotate(0) scale(1);
}

.chatbot__toggle-text {
  position: absolute;
  right: 72px;
  background: var(--chatbot-bg);
  color: var(--chatbot-text);
  padding: 8px 16px;
  border-radius: 20px;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--chatbot-shadow-sm);
  opacity: 0;
  transform: translateX(10px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

.chatbot--bottom-left .chatbot__toggle-text {
  right: auto;
  left: 72px;
  transform: translateX(-10px);
}

.chatbot__toggle:hover .chatbot__toggle-text {
  opacity: 1;
  transform: translateX(0);
}

.chatbot__toggle[aria-expanded="true"] .chatbot__toggle-text {
  display: none;
}

/* Badge */
.chatbot__badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 20px;
  height: 20px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: chatbot-pulse 2s infinite;
}

.chatbot__toggle[aria-expanded="true"] .chatbot__badge {
  display: none;
}

@keyframes chatbot-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* Bounce animation to attract attention */
@keyframes chatbot-bounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

.chatbot__toggle--bounce {
  animation: chatbot-bounce 0.6s ease-in-out infinite;
}

/* Stop bounce on hover or when chat is open */
.chatbot__toggle:hover.chatbot__toggle--bounce,
.chatbot__toggle[aria-expanded="true"].chatbot__toggle--bounce {
  animation: none;
}

/* ============================================
   Chat Window
   ============================================ */
.chatbot__window {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: var(--chatbot-width);
  height: var(--chatbot-height);
  max-height: calc(100vh - 120px);
  background: var(--chatbot-bg);
  border-radius: var(--chatbot-radius);
  box-shadow: var(--chatbot-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transform-origin: bottom right;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.chatbot--bottom-left .chatbot__window {
  right: auto;
  left: 0;
  transform-origin: bottom left;
}

.chatbot__window[aria-hidden="false"] {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* ============================================
   Header
   ============================================ */
.chatbot__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-primary-light) 100%);
  color: #fff;
}

.chatbot__header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chatbot__avatar {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chatbot__header-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chatbot__title {
  font-size: 15px;
  font-weight: 600;
}

.chatbot__status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  opacity: 0.9;
}

.chatbot__status-dot {
  width: 8px;
  height: 8px;
  background: #4ade80;
  border-radius: 50%;
  animation: chatbot-online 2s infinite;
}

@keyframes chatbot-online {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.chatbot__close {
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.chatbot__close:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ============================================
   Messages
   ============================================ */
.chatbot__messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--chatbot-surface);
  scroll-behavior: smooth;
}

.chatbot__message {
  display: flex;
  gap: 10px;
  max-width: 85%;
  animation: chatbot-message-in 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes chatbot-message-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chatbot__message--bot {
  align-self: flex-start;
}

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

.chatbot__message-avatar {
  width: 28px;
  height: 28px;
  min-width: 28px;
  background: var(--chatbot-primary);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 4px;
}

.chatbot__message--user .chatbot__message-avatar {
  background: var(--chatbot-text-muted);
}

.chatbot__message-content {
  padding: 12px 16px;
  border-radius: var(--chatbot-radius);
  background: var(--chatbot-bg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.chatbot__message--bot .chatbot__message-content {
  border-bottom-left-radius: 4px;
}

.chatbot__message--user .chatbot__message-content {
  background: var(--chatbot-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chatbot__message-content p {
  margin: 0;
  word-wrap: break-word;
}

.chatbot__message--user .chatbot__message-avatar {
  display: none;
}

/* ============================================
   Quick Actions
   ============================================ */
.chatbot__quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  animation: chatbot-message-in 0.4s cubic-bezier(0.4, 0, 0.2, 1) 0.2s both;
}

.chatbot__quick-btn {
  padding: 8px 14px;
  border: 1px solid var(--chatbot-primary);
  background: var(--chatbot-bg);
  color: var(--chatbot-primary);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.chatbot__quick-btn:hover {
  background: var(--chatbot-primary);
  color: #fff;
}

/* ============================================
   Typing Indicator
   ============================================ */
.chatbot__typing {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 0 20px 16px;
  background: var(--chatbot-surface);
}

.chatbot__typing[aria-hidden="false"] {
  display: flex;
}

.chatbot__typing-dots {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: var(--chatbot-bg);
  border-radius: var(--chatbot-radius);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.chatbot__typing-dots span {
  width: 8px;
  height: 8px;
  background: var(--chatbot-text-muted);
  border-radius: 50%;
  animation: chatbot-typing 1.4s infinite;
}

.chatbot__typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.chatbot__typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes chatbot-typing {
  0%, 60%, 100% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  30% {
    opacity: 1;
    transform: scale(1);
  }
}

/* ============================================
   Input Area
   ============================================ */
.chatbot__input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px;
  background: var(--chatbot-bg);
  border-top: 1px solid var(--chatbot-border);
}

.chatbot__phone-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border: none;
  background: var(--chatbot-surface);
  color: var(--chatbot-primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.chatbot__phone-btn:hover {
  background: var(--chatbot-primary);
  color: #fff;
}

.chatbot__input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--chatbot-border);
  border-radius: 24px;
  font-size: 16px; /* 16px prevents iOS/Chrome zoom on focus */
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: var(--chatbot-surface);
  touch-action: manipulation; /* Prevents zoom on double-tap */
  -webkit-text-size-adjust: 100%; /* Prevents text size adjustment */
}

.chatbot__input:focus {
  border-color: var(--chatbot-primary);
  box-shadow: 0 0 0 3px rgba(57, 89, 53, 0.1);
}

.chatbot__input::placeholder {
  color: var(--chatbot-text-muted);
}

.chatbot__send {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border: none;
  background: var(--chatbot-primary);
  color: #fff;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.chatbot__send:hover {
  background: var(--chatbot-primary-light);
  transform: scale(1.05);
}

.chatbot__send:active {
  transform: scale(0.95);
}

.chatbot__send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ============================================
   Footer
   ============================================ */
.chatbot__footer {
  padding: 10px 16px;
  text-align: center;
  font-size: 10px;
  line-height: 1.4;
  color: var(--chatbot-text-muted);
  background: var(--chatbot-bg);
  border-top: 1px solid var(--chatbot-border);
}

.chatbot__footer-disclaimer {
  display: block;
}

.chatbot__footer a {
  color: var(--chatbot-primary);
  text-decoration: underline;
}

.chatbot__footer a:hover {
  text-decoration: none;
}

/* ============================================
   Error State
   ============================================ */
.chatbot__message--error .chatbot__message-content {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
}

/* ============================================
   Lead Capture Form
   ============================================ */
.chatbot__lead-form {
  width: 100%;
  max-width: 100%;
  animation: chatbot-message-in 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.chatbot__lead-form-inner {
  background: var(--chatbot-bg);
  border-radius: var(--chatbot-radius);
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  border: 1px solid var(--chatbot-border);
}

.chatbot__lead-field {
  margin-bottom: 12px;
}

.chatbot__lead-field:last-of-type {
  margin-bottom: 16px;
}

.chatbot__lead-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--chatbot-text);
  margin-bottom: 4px;
}

.chatbot__lead-field input,
.chatbot__lead-field select,
.chatbot__lead-field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--chatbot-border);
  border-radius: var(--chatbot-radius-sm);
  font-size: 16px; /* 16px prevents iOS/Chrome zoom on focus */
  font-family: inherit;
  background: var(--chatbot-surface);
  color: var(--chatbot-text);
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
  touch-action: manipulation; /* Prevents zoom on double-tap */
  -webkit-text-size-adjust: 100%; /* Prevents text size adjustment */
}

.chatbot__lead-field input:focus,
.chatbot__lead-field select:focus,
.chatbot__lead-field textarea:focus {
  outline: none;
  border-color: var(--chatbot-primary);
  box-shadow: 0 0 0 3px rgba(57, 89, 53, 0.1);
}

.chatbot__lead-field input::placeholder,
.chatbot__lead-field textarea::placeholder {
  color: var(--chatbot-text-muted);
}

.chatbot__lead-field select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='%236b7280'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.chatbot__lead-field textarea {
  resize: vertical;
  min-height: 60px;
}

.chatbot__lead-actions {
  display: flex;
  gap: 8px;
}

.chatbot__lead-submit {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-primary-light) 100%);
  color: #fff;
  border: none;
  border-radius: var(--chatbot-radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.chatbot__lead-submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(57, 89, 53, 0.3);
}

.chatbot__lead-submit:active {
  transform: translateY(0);
}

.chatbot__lead-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.chatbot__lead-submit svg {
  flex-shrink: 0;
}

/* Consent checkbox */
.chatbot__lead-field--consent {
  margin-top: 16px;
  margin-bottom: 16px;
}

.chatbot__consent-label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1.4;
}

.chatbot__consent-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-width: 18px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--chatbot-primary);
}

.chatbot__consent-text {
  color: var(--chatbot-text-muted);
}

.chatbot__consent-text a {
  color: var(--chatbot-primary);
  text-decoration: underline;
}

.chatbot__consent-text a:hover {
  text-decoration: none;
}

/* Form success state */
.chatbot__lead-form--success .chatbot__lead-form-inner {
  text-align: center;
  padding: 24px 16px;
}

.chatbot__lead-form--success .chatbot__success-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-primary-light) 100%);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: chatbot-success-pop 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes chatbot-success-pop {
  0% { transform: scale(0); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.chatbot__lead-form--success .chatbot__success-text {
  font-size: 14px;
  color: var(--chatbot-text);
  margin: 0;
}

/* Form loading state */
.chatbot__lead-form--loading .chatbot__lead-submit {
  position: relative;
  color: transparent;
}

.chatbot__lead-form--loading .chatbot__lead-submit::after {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: chatbot-spin 0.8s linear infinite;
}

@keyframes chatbot-spin {
  to { transform: rotate(360deg); }
}

/* Form error state */
.chatbot__lead-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 8px 12px;
  border-radius: var(--chatbot-radius-sm);
  font-size: 13px;
  margin-bottom: 12px;
  display: none;
}

.chatbot__lead-form--error .chatbot__lead-error {
  display: block;
}

/* ============================================
   Mobile Responsive
   ============================================ */
@media (max-width: 480px) {
  .chatbot--bottom-right,
  .chatbot--bottom-left {
    bottom: 16px;
    right: 16px;
    left: auto;
  }

  .chatbot__toggle {
    width: 56px;
    height: 56px;
  }

  .chatbot__toggle-text {
    display: none;
  }

  .chatbot__window {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    bottom: 0;
    transform: translateY(100%);
  }

  .chatbot__window[aria-hidden="false"] {
    transform: translateY(0);
  }

  .chatbot__header {
    padding: 16px;
    padding-top: calc(16px + env(safe-area-inset-top, 0));
  }

  .chatbot__messages {
    padding: 16px;
  }

  .chatbot__input-area {
    padding: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
  }
}

/* ============================================
   Reduced Motion
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  .chatbot__toggle,
  .chatbot__window,
  .chatbot__message,
  .chatbot__quick-actions,
  .chatbot__toggle-icon,
  .chatbot__badge {
    animation: none;
    transition: opacity 0.2s;
  }
}

