/* Erpeaz Chatbot Widget Styles */

.erpeaz-chatbot {
  position: fixed;
  z-index: 10000;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.4;
}

.erpeaz-chatbot.bottom-right {
  bottom: 20px;
  right: 20px;
}

.erpeaz-chatbot.bottom-left {
  bottom: 20px;
  left: 20px;
}

/* Chat Button */
.chat-button {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  /* primary accent with subtle diagonal gradient */
  background: linear-gradient(135deg, #2570c8 0%, #1f55a6 60%);
  color: white;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.chat-button::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0.05) 100%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.chat-button:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 25px rgba(0,0,0,0.2);
}

.chat-button:hover::before {
  opacity: 1;
}

.chat-button:active {
  transform: scale(0.95);
}

.chat-button.active {
  /* Visual feedback when chat is open */
  background: linear-gradient(135deg, #1f55a6 0%, #154a95 60%);
  transform: scale(1.05);
  box-shadow: 0 6px 25px rgba(0,0,0,0.25);
}

.chat-button.active::before {
  opacity: 1;
}

/* Chat Window */
.chat-window {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 350px;
  height: 500px;
  background: #ffffff; /* primary background */
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.12);
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(0,0,0,0.06);
}

.erpeaz-chatbot.bottom-left .chat-window {
  right: auto;
  left: 0;
}

/* Fix positioning on small screens - iPhone SE and similar */
@media (max-width: 450px) {
  .chat-window {
    /* Position relative to viewport, not button */
    position: fixed !important;
    right: 10px !important;
    left: 10px !important;
    width: auto !important;
    bottom: 70px !important;
    transform: none !important;
  }
  
  .erpeaz-chatbot.bottom-left .chat-window {
    right: 10px !important;
    left: 10px !important;
  }
}

/* Specific fix for iPhone SE (375px) and smaller */
@media (max-width: 375px) {
  .chat-window {
    position: fixed !important;
    right: 8px !important;
    left: 8px !important;
    width: auto !important;
    bottom: 65px !important;
    height: 340px !important;
    max-height: 340px !important;
    min-height: 280px !important;
  }
  
  .erpeaz-chatbot.bottom-left .chat-window {
    right: 8px !important;
    left: 8px !important;
  }
}

.chat-window.open {
  display: flex;
  animation: slideUp 0.3s ease-out;
}

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

/* Chat Header */
.chat-header {
  /* header uses a soft gradient that blends to white for a fresher look */
  background: linear-gradient(180deg, #2566c0 0%, #2a79d1 45%, #ffffff 100%);
  color: white;
  padding: 16px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
}

.chat-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
}

.chat-title h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.chat-title p {
  margin: 4px 0 0 0;
  font-size: 13px;
  opacity: 0.95;
  font-weight: 400;
}

.close-button {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-button:hover {
  background: rgba(255,255,255,0.1);
  transform: scale(1.1);
}

.close-button:active {
  transform: scale(0.95);
}

/* Chat Messages */
.chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fafafa;
}

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

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: #ddd;
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: #ccc;
}

.message {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
  position: relative;
  animation: messageSlide 0.3s ease-out;
}

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

.message.user {
  background: #eaf4ff;
  color: #2566c0; /* accent color */
  align-self: flex-end;
  border-bottom-right-radius: 6px;
  box-shadow: 0 2px 8px rgba(37, 102, 192, 0.08);
}

.message.assistant {
  background: white;
  color: #333;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  border: 1px solid rgba(0,0,0,0.05);
}

.message.loading {
  background: #f0f0f0;
  color: #666;
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 8px;
  font-style: italic;
}

.loading-dots {
  display: inline-flex;
  gap: 4px;
}

.loading-dots span {
  width: 6px;
  height: 6px;
  background: #999;
  border-radius: 50%;
  animation: loading 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes loading {
  0%, 80%, 100% { 
    transform: scale(0);
    opacity: 0.5;
  }
  40% { 
    transform: scale(1);
    opacity: 1;
  }
}

/* Chat Input */
.chat-input-container {
  padding: 20px;
  border-top: 1px solid #eee;
  background: white;
}

.chat-input-wrapper {
  display: flex;
  gap: 8px;
  align-items: center;
}

.chat-input-wrapper input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid #ddd;
  border-radius: 24px;
  font-size: 14px;
  outline: none;
  transition: all 0.2s ease;
  background: #fafafa;
}

.chat-input-wrapper input:focus {
  border-color: #2566c0;
  background: white;
  box-shadow: 0 0 0 3px rgba(37,102,192,0.08);
}

.chat-input-wrapper input:disabled {
  background: #f5f5f5;
  cursor: not-allowed;
  opacity: 0.6;
}

.chat-input-wrapper button {
  width: 40px;
  height: 40px;
  border: none;
  /* send button: circular gradient matching the brand */
  background: linear-gradient(135deg, #2b79d6 0%, #1f55a6 100%);
  color: white;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

/* subtle glossy overlay on interactive accents */
.chat-button::after,
.chat-input-wrapper button::after,
.chat-header::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255,255,255,0.18) 0%, rgba(255,255,255,0.04) 30%, rgba(255,255,255,0) 60%);
  mix-blend-mode: overlay;
  opacity: 0.7;
}

.chat-input-wrapper button::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0.05) 100%);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.chat-input-wrapper button:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.chat-input-wrapper button:hover:not(:disabled)::before {
  opacity: 1;
}

.chat-input-wrapper button:active:not(:disabled) {
  transform: scale(0.95);
}

.chat-input-wrapper button:disabled {
  background: #ccc;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Sources */
.ources, .sources {
  margin-top: 8px;
  padding: 8px 12px;
  background: #f8f9fa;
  border-radius: 8px;
  font-size: 12px;
  color: #666;
  border-left: 3px solid #2566c0;
}

.sources-title {
  font-weight: 600;
  margin-bottom: 4px;
  color: #333;
}

.source-item {
  margin: 2px 0;
  padding: 2px 0;
  border-bottom: 1px solid #eee;
  transition: color 0.2s ease;
}

.source-item:hover {
  color: #667eea;
}

.source-item:last-child {
  border-bottom: none;
}

/* Dark Theme */
.dark .chat-window {
  background: #2d3748;
  color: #e2e8f0;
  border-color: #4a5568;
}

.dark .chat-messages {
  background: #1a202c;
}

.dark .message.user {
  background: linear-gradient(135deg, #2b6cb0 0%, #3182ce 100%);
  color: #e6fffa;
}

.dark .message.assistant {
  background: #4a5568;
  color: #e2e8f0;
  border-color: #718096;
}

.dark .message.loading {
  background: #4a5568;
  color: #a0aec0;
}

.dark .chat-input-container {
  background: #2d3748;
  border-top-color: #4a5568;
}

.dark .chat-input-wrapper input {
  background: #4a5568;
  border-color: #718096;
  color: #e2e8f0;
}

.dark .chat-input-wrapper input:focus {
  background: #2d3748;
  border-color: #667eea;
}

.dark .chat-input-wrapper input:disabled {
  background: #4a5568;
  opacity: 0.6;
}

.dark .sources {
  background: #4a5568;
  color: #a0aec0;
  border-left-color: #667eea;
}

.dark .sources-title {
  color: #e2e8f0;
}

.dark .source-item {
  border-bottom-color: #718096;
}

.dark .source-item:hover {
  color: #90cdf4;
}

/* Responsive Design */
@media (max-width: 768px) {
  .erpeaz-chatbot.bottom-right {
    bottom: 15px;
    right: 15px;
  }

  .erpeaz-chatbot.bottom-left {
    bottom: 15px;
    left: 15px;
  }

  .chat-button {
    width: 56px;
    height: 56px;
  }

  .chat-window {
    /* Ensure proper positioning on tablets with reduced height */
    position: fixed !important;
    width: calc(100vw - 30px);
    height: 450px;
    bottom: 75px;
    right: 15px;
    left: 15px;
    max-height: 450px;
    min-height: 350px;
  }
  
  .erpeaz-chatbot.bottom-left .chat-window {
    right: 15px;
    left: 15px;
  }
  
  .chat-header {
    padding: 14px 16px;
  }
  
  .chat-title h3 {
    font-size: 16px;
  }
  
  .chat-title p {
    font-size: 12px;
  }
  
  .chat-messages {
    padding: 15px;
    gap: 10px;
  }
  
  .message {
    max-width: 85%;
    padding: 10px 14px;
    font-size: 14px;
  }
  
  .chat-input-container {
    padding: 15px;
  }
}

@media (max-width: 480px) {
  .erpeaz-chatbot.bottom-right {
    bottom: 10px;
    right: 10px;
  }

  .erpeaz-chatbot.bottom-left {
    bottom: 10px;
    left: 10px;
  }

  .chat-button {
    width: 50px;
    height: 50px;
  }

  .chat-window {
    /* Use fixed positioning with reduced height for mobile */
    position: fixed !important;
    width: calc(100vw - 20px);
    height: 380px;
    bottom: 65px;
    right: 10px;
    left: 10px;
    max-height: 380px;
    min-height: 300px;
    border-radius: 8px;
  }
  
  .erpeaz-chatbot.bottom-left .chat-window {
    right: 10px;
    left: 10px;
  }
  
  .chat-header {
    padding: 12px 14px;
  }
  
  .chat-title h3 {
    font-size: 15px;
  }
  
  .chat-title p {
    font-size: 11px;
  }
  
  .chat-messages {
    padding: 12px;
    gap: 8px;
  }
  
  .message {
    max-width: 90%;
    padding: 8px 12px;
    font-size: 13px;
    border-radius: 14px;
  }
  
  .message.user {
    border-bottom-right-radius: 4px;
  }
  
  .message.assistant {
    border-bottom-left-radius: 4px;
  }
  
  .chat-input-container {
    padding: 12px;
  }
  
  .chat-input-wrapper input {
    padding: 10px 14px;
    font-size: 14px;
    border-radius: 20px;
  }
  
  .chat-input-wrapper button {
    width: 36px;
    height: 36px;
  }
  
  /* Status message styling for mobile */
  .chat-status {
    font-size: 12px;
    margin-top: 8px;
    padding: 4px 8px;
    text-align: center;
    min-height: 16px;
  }
}

/* Very small screens */
@media (max-width: 360px) {
  .chat-window {
    width: calc(100vw - 16px);
    height: 350px;
    bottom: 60px;
    right: 8px;
    left: 8px;
    border-radius: 6px;
    max-height: 350px;
    min-height: 280px;
  }
  
  .erpeaz-chatbot.bottom-left .chat-window {
    right: 8px;
    left: 8px;
  }
  
  .chat-header {
    padding: 10px 12px;
  }
  
  .chat-messages {
    padding: 10px;
  }
  
  .message {
    padding: 7px 10px;
    font-size: 12px;
  }
  
  .chat-input-container {
    padding: 10px;
  }
}

/* Landscape orientation on mobile */
@media (max-height: 500px) and (max-width: 768px) {
  .chat-window {
    height: 300px;
    bottom: 55px;
    max-height: 300px;
  }
  
  .chat-messages {
    padding: 10px;
  }
  
  .chat-header {
    padding: 8px 12px;
  }
  
  .chat-input-container {
    padding: 8px 12px;
  }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  .chat-button,
  .chat-window,
  .message,
  .chat-input-wrapper button {
    transition: none;
  }
  
  .chat-window.open {
    animation: none;
  }
  
  .message {
    animation: none;
  }
  
  .loading-dots span {
    animation: none;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  .chat-button {
    border: 2px solid white;
  }
  
  .message.user {
    border: 1px solid #1565c0;
  }
  
  .message.assistant {
    border: 1px solid #333;
  }
  
  .chat-input-wrapper input {
    border-width: 2px;
  }
}

/* iOS Safari specific fixes */
@supports (-webkit-touch-callout: none) {
  @media (max-width: 768px) {
    .erpeaz-chatbot {
      /* Use viewport units that work better on iOS */
      position: fixed;
      z-index: 999999;
    }
    
    .chat-window {
      /* Fix for iOS viewport height issues */
      height: calc(100vh - 120px);
      height: calc(100dvh - 120px); /* Dynamic viewport height for newer browsers */
    }
    
    .chat-window.open {
      /* Ensure proper stacking on iOS */
      transform: translateZ(0);
      -webkit-transform: translateZ(0);
    }
  }
  
  @media (max-width: 480px) {
    .chat-window {
      height: calc(100vh - 80px);
      height: calc(100dvh - 80px);
    }
  }
}

/* Android Chrome specific fixes */
@media screen and (max-width: 768px) {
  .erpeaz-chatbot {
    /* Prevent widget from being cut off by mobile browsers */
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
  }
  
  .chat-window {
    /* Ensure proper rendering on mobile */
    transform: translate3d(0, 0, 0);
    -webkit-transform: translate3d(0, 0, 0);
  }
}

/* Prevent zoom on input focus on iOS */
@media (max-width: 768px) {
  .chat-input-wrapper input {
    font-size: 16px; /* Prevents zoom on iOS */
  }
  
  /* Ensure mobile positioning overrides all other rules */
  .erpeaz-chatbot .chat-window {
    position: fixed !important;
    left: 15px !important;
    right: 15px !important;
    width: auto !important;
    height: 450px !important;
    max-height: 450px !important;
  }
}

@media (max-width: 480px) {
  .erpeaz-chatbot .chat-window {
    left: 10px !important;
    right: 10px !important;
    height: 380px !important;
    max-height: 380px !important;
  }
}

@media (max-width: 375px) {
  .erpeaz-chatbot .chat-window {
    left: 8px !important;
    right: 8px !important;
    height: 340px !important;
    max-height: 340px !important;
  }
}
