/* Color Variables for easy theme change */
:root {
  --primary-dark: #4C51BF;
  --bg-light: #f8fafc;
  --bg-white: #ffffff;
  --text-dark: #1a202c;
  --ai-bubble-bg: #e2e8f0;
}

/* ===== CHAT CONTAINER ===== */
#ai-chatbot {
  position: fixed;
  bottom: 20px; 
  right: 20px; 
  z-index: 9999;
  font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* ===== TOGGLE BUTTON (Floating Action Button) ===== */
#chat-button {
  background-color: var(--primary-color);
  color: var(--bg-white);
  padding: 14px 22px; 
  border-radius: 40px; 
  cursor: pointer;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.3); 
  transition: all 0.2s ease-in-out;
}

#chat-button:hover {
  background-color: var(--primary-dark);
  transform: scale(1.05); 
}

/* ===== CHAT WINDOW ===== */
#chat-window {
  width: 500px; 
  height: 750px; 
  max-height: 80vh;
  background: var(--bg-white); /* 🟢 Ensure solid background for desktop/default */
  /* border-radius: 16px;  */
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(0, 0, 0, 0.05); 
  display: none;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(10px); 
  opacity: 0;
  transition: all 0.3s ease-out;
}

#ai-chatbot:has(#chat-window[style*="flex"]) #chat-window {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 768px) {
  #ai-chatbot {
    bottom: 0;
    right: 0;
  }
  #chat-window {
    width: 100vw;
    height: 85vh;
    max-height: 90vh;
    border-radius: 0;
    background-color: var(--bg-white); /* 🟢 CRITICAL FIX: Ensure full-screen chat is opaque */
  }
}

/* ===== HEADER ===== */
#chat-header {
  background: linear-gradient(135deg, var(--primary-color) 0%, #7681f2 100%); 
  color: var(--bg-white);
  padding: 15px 20px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#header-title {
  font-size: 1.1em;
}

#header-controls {
  display: flex;
  align-items: center;
  gap: 15px;
}

/* Close Button */
#chat-close {
  font-size: 1.6em;
  cursor: pointer;
  line-height: 1; 
  transition: opacity 0.2s;
}

#chat-close:hover {
    opacity: 0.8;
}

/* New Clear Chat Button */
#clear-chat {
  background: none;
  border: none;
  color: var(--bg-white);
  cursor: pointer;
  padding: 0;
  width: 20px;
  height: 20px;
  opacity: 0.8;
  transition: opacity 0.2s;
}

#clear-chat:hover {
  opacity: 1;
}

#clear-chat svg {
  width: 100%;
  height: 100%;
}


/* ===== BODY (Messages Container) ===== */
#chat-body {
  flex: 1;
  padding: 15px; 
  overflow-y: auto;
  background: var(--bg-light); /* 🟢 Ensure solid background for chat messages area */
  display: flex;
  flex-direction: column;
  gap: 12px; 
}

/* Custom Scrollbar for modern feel (optional, but nice) */
#chat-body::-webkit-scrollbar {
  width: 6px;
}
#chat-body::-webkit-scrollbar-thumb {
  background-color: #cbd5e0;
  border-radius: 3px;
}
#chat-body::-webkit-scrollbar-track {
  background-color: transparent;
}


/* ===== INPUT AREA ===== */
#chat-form {
  background: var(--bg-white);
  border-top: 1px solid #e2e8f0;
  /* padding: 12px 18px; */
}

.chat-input-wrapper {
  position: relative;
  width: 100%;
}

/* The Text Input */
#chat-input {
  width: 100%;
  min-height: 60px; /* 🟢 taller input */
  max-height: 150px;
  /* border-radius: 30px; */
  padding: 14px 60px 14px 20px; /* space for send button */
  border: 1px solid #e2e8f0;
  font-size: 1em;
  outline: none;
  resize: none;
  overflow-y: auto;
  line-height: 1.4;
  background-color: var(--bg-white);
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
  vertical-align: top;
}

#chat-input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(90, 103, 216, 0.1);
}


/* Send Button (inside the input box) */
#chat-send {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background-color: var(--primary-color);
  color: var(--bg-white);
  border: none;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  font-size: 1.1em;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.2s;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

#chat-send:hover {
  background-color: var(--primary-dark);
  transform: translateY(-50%) scale(1.05);
}

/* ===== MESSAGES ===== */
.message-user,
.message-ai {
  display: flex;
  max-width: 90%; 
  margin-bottom: 0px; 
}

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

.message-ai {
  align-self: flex-start;
  justify-content: flex-start;
}

.message-text {
  padding: 12px 16px; 
  border-radius: 18px; 
  word-wrap: break-word;
  line-height: 1.5;
  font-size: 0.95em;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1); 
  transition: box-shadow 0.2s;
}

/* User Message Styles */
.message-user .message-text {
  background-color: var(--primary-color);
  color: var(--bg-white);
  border-bottom-right-radius: 5px; 
}

/* AI Message Styles */
.message-ai .message-text {
  background-color: var(--ai-bubble-bg);
  color: var(--text-dark);
  border-bottom-left-radius: 5px; 
}

/* Initial Welcome Message Styling */
.welcome-message .message-text {
  /* No need to override, inherits message-ai styles */
}

.message-ai .message-text h3 {
  font-size: 1rem;
  font-weight: 600;
  margin: 10px 0 5px;
}

.message-ai .message-text ul, 
.message-ai .message-text ol {
  margin: 5px 0 5px 20px;
}

.message-ai .message-text p {
  margin-bottom: 8px;
}