/* Chat Widget Styles with Markdown Support */

/* Chat button - the circular button at bottom right */
#chat-widget-button {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: transform 0.3s ease, box-shadow 0.3s ease, opacity 0.3s ease;
  opacity: 1;
}

/* Hide button when chat is open */
#chat-widget-button.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.8);
}

#chat-widget-button:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

#chat-widget-button svg {
  width: 28px;
  height: 28px;
  fill: white;
}

/* Chat window container */
#chat-widget-container {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 380px;
  height: 600px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  display: none;
  flex-direction: column;
  z-index: 9998;
  overflow: hidden;
  animation: slideUp 0.3s ease;
}

#chat-widget-container.open {
  display: flex;
}

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

/* Chat header */
#chat-widget-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#chat-widget-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

#chat-widget-close {
  background: none;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s;
}

#chat-widget-close:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* Messages area */
#chat-widget-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: #f8f9fa;
}

/* Individual message bubbles */
.chat-message {
  margin-bottom: 16px;
  display: flex;
  animation: fadeIn 0.3s ease;
}

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

.chat-message.user {
  justify-content: flex-end;
}

.chat-message.assistant {
  justify-content: flex-start;
}

.message-bubble {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: 18px;
  line-height: 1.5;
  word-wrap: break-word;
}

.chat-message.user .message-bubble {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-message.assistant .message-bubble {
  background: white;
  color: #333;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

/* Markdown formatting within message bubbles */
.message-bubble p {
  margin: 0 0 8px 0;
}

.message-bubble p:last-child {
  margin-bottom: 0;
}

.message-bubble strong {
  font-weight: 600;
}

.message-bubble em {
  font-style: italic;
}

.message-bubble ul,
.message-bubble ol {
  margin: 8px 0;
  padding-left: 20px;
}

.message-bubble li {
  margin: 4px 0;
}

.message-bubble code {
  background: rgba(0, 0, 0, 0.05);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
}

.message-bubble pre {
  background: rgba(0, 0, 0, 0.05);
  padding: 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
}

.message-bubble pre code {
  background: none;
  padding: 0;
}

.message-bubble a {
  color: inherit;
  text-decoration: underline;
}

.message-bubble blockquote {
  border-left: 3px solid rgba(0, 0, 0, 0.1);
  padding-left: 12px;
  margin: 8px 0;
  font-style: italic;
}

/* User messages should not have markdown formatting */
.chat-message.user .message-bubble p,
.chat-message.user .message-bubble ul,
.chat-message.user .message-bubble ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Typing indicator */
.typing-indicator {
  display: none;
  padding: 12px 16px;
  background: white;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  max-width: 75%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.typing-indicator.active {
  display: block;
}

.typing-indicator span {
  height: 8px;
  width: 8px;
  background: #999;
  border-radius: 50%;
  display: inline-block;
  margin-right: 4px;
  animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.7;
  }
  30% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

/* Input area */
#chat-widget-input-area {
  padding: 16px;
  background: white;
  border-top: 1px solid #e9ecef;
  display: flex;
  gap: 8px;
}

#chat-widget-input {
  flex: 1;
  border: 1px solid #dee2e6;
  border-radius: 24px;
  padding: 10px 16px;
  font-size: 16px;  /* Must be 16px or larger to prevent zoom on iOS */
  outline: none;
  transition: border-color 0.2s;
}

#chat-widget-input:focus {
  border-color: #667eea;
}

#chat-widget-send {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s;
}

#chat-widget-send:hover {
  transform: scale(1.05);
}

#chat-widget-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#chat-widget-send svg {
  width: 20px;
  height: 20px;
  fill: white;
}

/* Suggestion chips */
.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  padding: 0 20px 12px 20px;
}

.suggestion-chip {
  background: white;
  border: 1px solid #dee2e6;
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  color: #667eea;
  font-weight: 500;
}

.suggestion-chip:hover {
  background: #f8f9fa;
  border-color: #667eea;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.15);
}

.suggestion-chip:active {
  transform: translateY(0);
}

/* Mobile responsiveness */
@media (max-width: 480px) {
  #chat-widget-container {
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* Use dynamic viewport height for better keyboard handling */
    bottom: 0;
    right: 0;
    border-radius: 0;
    max-height: 100vh;
    max-height: 100dvh;
  }
  
  #chat-widget-button {
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  }
  
  #chat-widget-messages {
    /* Ensure messages area is scrollable on mobile */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  #chat-widget-input {
    font-size: 16px; /* Prevent zoom on iOS */
  }
  
  .suggestion-chip {
    font-size: 14px;
    padding: 10px 16px;
  }
}

/* Prevent body scroll when chat is open on mobile */
body.chat-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
}

/* Fix for iOS Safari address bar */
@supports (-webkit-touch-callout: none) {
  #chat-widget-container {
    height: -webkit-fill-available;
  }
}