/**
 * Hampstead Renovations - AI Chatbot Styles
 * Premium chat experience with lead capture, persistence, and analytics
 * Version 2.0 - Full Featured
 */

/* CSS Variables for theming */
:root {
  --chat-primary: #2c3e50;
  --chat-accent: #8b7355;
  --chat-accent-light: #a0896d;
  --chat-success: #27ae60;
  --chat-white: #ffffff;
  --chat-light: #f8f9fa;
  --chat-grey: #6c757d;
  --chat-border: #e9ecef;
  --chat-shadow: 0 10px 40px rgba(0,0,0,0.15);
  --chat-radius: 16px;
  --chat-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Main Container */
#hr-chatbot-container {
  position: fixed;
  bottom: 25px;
  right: 25px;
  z-index: 99999;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

/* Chat Toggle Button */
.hr-chat-fab {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chat-accent) 0%, var(--chat-accent-light) 100%);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(139,115,85,0.4);
  transition: var(--chat-transition);
  position: relative;
  animation: hr-pulse 2s infinite;
}

.hr-chat-fab:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 30px rgba(139,115,85,0.5);
}

.hr-chat-fab.active {
  animation: none;
  transform: rotate(0deg);
}

.hr-chat-fab svg {
  width: 28px;
  height: 28px;
  fill: white;
  transition: var(--chat-transition);
}

.hr-chat-fab.active .hr-icon-chat { display: none; }
.hr-chat-fab:not(.active) .hr-icon-close { display: none; }

@keyframes hr-pulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(139,115,85,0.4); }
  50% { box-shadow: 0 4px 30px rgba(139,115,85,0.6), 0 0 0 10px rgba(139,115,85,0.1); }
}

/* Notification Badge */
.hr-chat-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 24px;
  height: 24px;
  background: #e74c3c;
  color: white;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  border: 3px solid white;
  animation: hr-bounce 0.5s ease;
}

.hr-chat-badge.show { display: flex; }

@keyframes hr-bounce {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

/* Tooltip */
.hr-chat-tooltip {
  position: absolute;
  right: 75px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--chat-primary);
  color: white;
  padding: 12px 18px;
  border-radius: 10px;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  visibility: hidden;
  transition: var(--chat-transition);
  box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.hr-chat-tooltip::after {
  content: '';
  position: absolute;
  right: -8px;
  top: 50%;
  transform: translateY(-50%);
  border: 8px solid transparent;
  border-left-color: var(--chat-primary);
}

.hr-chat-fab:hover .hr-chat-tooltip {
  opacity: 1;
  visibility: visible;
}

/* Chat Window */
.hr-chat-window {
  position: fixed;
  bottom: 100px;
  right: 20px;
  width: 400px;
  height: 600px;
  background: var(--chat-white);
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--chat-border);
  transform: translateY(20px) scale(0.95);
  opacity: 0;
  transition: var(--chat-transition);
}

.hr-chat-window.open {
  display: flex;
  transform: translateY(0) scale(1);
  opacity: 1;
}

/* Chat Header */
.hr-chat-header {
  background: linear-gradient(135deg, var(--chat-primary) 0%, #37474f 100%);
  color: white;
  padding: 18px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.hr-chat-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.hr-chat-avatar {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--chat-accent) 0%, var(--chat-accent-light) 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  font-size: 22px;
}

.hr-chat-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.hr-online-dot {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  background: var(--chat-success);
  border-radius: 50%;
  border: 2px solid var(--chat-primary);
}

.hr-chat-header-info h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.hr-chat-header-info p {
  margin: 2px 0 0;
  font-size: 12px;
  opacity: 0.9;
}

.hr-chat-close {
  background: rgba(255,255,255,0.1);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--chat-transition);
}

.hr-chat-close:hover {
  background: rgba(255,255,255,0.2);
}

/* Lead Capture Form */
.hr-lead-capture {
  padding: 24px 20px;
  background: linear-gradient(to bottom, var(--chat-light) 0%, var(--chat-white) 100%);
  border-bottom: 1px solid var(--chat-border);
}

.hr-lead-capture.hidden { display: none; }

.hr-lead-capture h4 {
  margin: 0 0 8px;
  font-size: 16px;
  color: var(--chat-primary);
}

.hr-lead-capture p {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--chat-grey);
}

.hr-lead-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hr-lead-form input {
  padding: 12px 14px;
  border: 2px solid var(--chat-border);
  border-radius: 10px;
  font-size: 14px;
  transition: var(--chat-transition);
}

.hr-lead-form input:focus {
  outline: none;
  border-color: var(--chat-accent);
  box-shadow: 0 0 0 3px rgba(139,115,85,0.1);
}

.hr-lead-form button {
  background: linear-gradient(135deg, var(--chat-accent) 0%, var(--chat-accent-light) 100%);
  color: white;
  border: none;
  padding: 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--chat-transition);
}

.hr-lead-form button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(139,115,85,0.3);
}

.hr-skip-lead {
  background: none !important;
  color: var(--chat-grey) !important;
  font-size: 13px !important;
  margin-top: 8px;
}

.hr-skip-lead:hover {
  color: var(--chat-accent) !important;
  transform: none !important;
  box-shadow: none !important;
}

/* Quick Actions */
.hr-quick-actions {
  padding: 16px;
  background: var(--chat-light);
  border-bottom: 1px solid var(--chat-border);
}

.hr-quick-actions p {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--chat-grey);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.hr-quick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.hr-quick-btn {
  background: white;
  border: 1.5px solid var(--chat-border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: var(--chat-transition);
  color: var(--chat-primary);
  font-weight: 500;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
}

.hr-quick-btn:hover {
  background: linear-gradient(135deg, var(--chat-accent) 0%, var(--chat-accent-light) 100%);
  color: white;
  border-color: var(--chat-accent);
  transform: translateY(-2px);
}

/* Messages Area */
.hr-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: linear-gradient(to bottom, var(--chat-white) 0%, #fafbfc 100%);
  scroll-behavior: smooth;
}

.hr-message {
  margin-bottom: 16px;
  animation: hr-slideIn 0.3s ease;
}

@keyframes hr-slideIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.hr-message-bot {
  text-align: left;
}

.hr-message-user {
  text-align: right;
}

.hr-message-content {
  display: inline-block;
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 16px;
  position: relative;
}

.hr-message-bot .hr-message-content {
  background: white;
  color: var(--chat-primary);
  border: 1px solid var(--chat-border);
  border-radius: 16px 16px 16px 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.hr-message-user .hr-message-content {
  background: linear-gradient(135deg, var(--chat-accent) 0%, var(--chat-accent-light) 100%);
  color: white;
  border-radius: 16px 16px 4px 16px;
}

.hr-message-time {
  display: block;
  font-size: 11px;
  color: var(--chat-grey);
  margin-top: 4px;
}

/* Typing Indicator */
.hr-typing {
  display: none;
  padding: 12px 16px;
  background: white;
  border: 1px solid var(--chat-border);
  border-radius: 16px;
  width: fit-content;
}

.hr-typing.show { display: flex; gap: 4px; }

.hr-typing-dot {
  width: 8px;
  height: 8px;
  background: var(--chat-accent);
  border-radius: 50%;
  animation: hr-typingBounce 1.4s infinite;
}

.hr-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.hr-typing-dot:nth-child(3) { animation-delay: 0.4s; }

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

/* Suggested Replies */
.hr-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.hr-suggestion {
  background: var(--chat-light);
  border: 1px solid var(--chat-border);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 12px;
  cursor: pointer;
  transition: var(--chat-transition);
  color: var(--chat-primary);
}

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

/* Input Area */
.hr-input-area {
  padding: 16px;
  background: white;
  border-top: 1px solid var(--chat-border);
  display: flex;
  gap: 10px;
  align-items: center;
}

.hr-input-area input {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid var(--chat-border);
  border-radius: 24px;
  font-size: 14px;
  transition: var(--chat-transition);
}

.hr-input-area input:focus {
  outline: none;
  border-color: var(--chat-accent);
}

.hr-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chat-accent) 0%, var(--chat-accent-light) 100%);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--chat-transition);
}

.hr-send-btn:hover {
  transform: scale(1.1);
}

.hr-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.hr-send-btn svg {
  width: 20px;
  height: 20px;
  fill: white;
}

/* Footer */
.hr-chat-footer {
  padding: 10px 16px;
  background: var(--chat-light);
  text-align: center;
  font-size: 11px;
  color: var(--chat-grey);
  border-top: 1px solid var(--chat-border);
}

.hr-chat-footer a {
  color: var(--chat-accent);
  text-decoration: none;
}

/* WhatsApp Button */
.hr-whatsapp-btn {
  position: fixed;
  bottom: 100px;
  right: 20px;
  width: 56px;
  height: 56px;
  background: #25d366;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 15px rgba(37,211,102,0.4);
  transition: var(--chat-transition);
  text-decoration: none;
  z-index: 99998;
}

.hr-whatsapp-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 25px rgba(37,211,102,0.5);
}

.hr-whatsapp-btn svg {
  width: 32px;
  height: 32px;
  fill: white;
}

/* When chat is open, move WhatsApp up */
#hr-chatbot-container.chat-open ~ .hr-whatsapp-btn,
.hr-whatsapp-btn.shifted {
  bottom: 720px;
}

/* Mobile Responsive */
@media (max-width: 480px) {
  #hr-chatbot-container {
    bottom: 20px;
    right: 15px;
  }

  .hr-chat-fab {
    width: 56px;
    height: 56px;
  }

  .hr-chat-window {
    width: calc(100vw - 20px);
    height: calc(100vh - 100px);
    right: 10px;
    left: 10px;
    bottom: 85px;
    max-height: 550px;
  }

  .hr-chat-tooltip { display: none; }

  .hr-whatsapp-btn {
    width: 50px;
    height: 50px;
    bottom: 85px;
    left: 15px;
    right: auto;
  }

  .hr-whatsapp-btn.shifted {
    bottom: 85px;
    left: 15px;
    right: auto;
  }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  .hr-chat-window {
    background: #1a1a1a;
    border-color: #333;
  }

  .hr-messages {
    background: linear-gradient(to bottom, #1a1a1a 0%, #222 100%);
  }

  .hr-message-bot .hr-message-content {
    background: #2d2d2d;
    color: #e0e0e0;
    border-color: #444;
  }

  .hr-quick-btn {
    background: #2d2d2d;
    color: #e0e0e0;
    border-color: #444;
  }

  .hr-input-area {
    background: #1a1a1a;
    border-color: #333;
  }

  .hr-input-area input {
    background: #2d2d2d;
    color: #e0e0e0;
    border-color: #444;
  }
}

/* Accessibility */
.hr-chat-fab:focus,
.hr-quick-btn:focus,
.hr-send-btn:focus,
.hr-input-area input:focus {
  outline: 3px solid rgba(139,115,85,0.5);
  outline-offset: 2px;
}

/* Screen reader only */
.hr-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Print - hide chatbot */
@media print {
  #hr-chatbot-container,
  .hr-whatsapp-btn {
    display: none !important;
  }
}
