/* =====================================================
   CHATBOT — Romero Luna Brand Style
   Colors: green #66a307, ink #20201e, warm bg #fdfcfb
   Font: Nunito + Playfair Display
   Icons: Bootstrap Icons 1.11.3
   ===================================================== */

/* Widget Container */
#chatbot-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: 'Nunito', system-ui, sans-serif;
}

/* Trigger Button */
#chatbot-trigger {
  width: 85px;
  height: 65px;
  border-radius: 12px;
  background: #66a307;
  color: white;
  border: none;
  box-shadow: 0 4px 20px rgba(102, 163, 7, 0.4);
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  padding: 0;
  position: relative;
  /* Allow the tail to show */
  margin-bottom: 20px; 
}

/* The "pico" tail from the image */
#chatbot-trigger::after {
  content: "";
  position: absolute;
  bottom: -15px;
  left: 20px;
  width: 0;
  height: 0;
  border-left: 0px solid transparent;
  border-right: 20px solid transparent;
  border-top: 20px solid #66a307;
}

#chatbot-trigger img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: 8px;
}

#chatbot-trigger:hover {
  transform: scale(1.05) translateY(-2px);
  box-shadow: 0 8px 28px rgba(102, 163, 7, 0.5);
}

/* Main Popup */
#chatbot-popup {
  display: none;
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 370px;
  height: 540px;
  background: #fdfcfb;
  border-radius: 16px;
  border: 2px solid #20201e;
  box-shadow: 6px 6px 0 #20201e;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.3s ease forwards;
}

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

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Header */
#chatbot-header {
  background: #20201e;
  color: white;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 0.95rem;
  gap: 10px;
  flex-shrink: 0;
}

#chatbot-header .cb-header-bot {
  display: flex;
  align-items: center;
  gap: 10px;
}

#chatbot-header .cb-bot-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: white;
  object-fit: contain;
  padding: 2px;
  flex-shrink: 0;
}

#chatbot-header .cb-header-info small {
  display: block;
  font-size: 0.7rem;
  font-weight: 400;
  color: #66a307;
  margin-top: 1px;
}

.cb-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

#chatbot-filter-btn,
#chatbot-close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 6px;
  border-radius: 6px;
  transition: color 0.2s, background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

#chatbot-filter-btn:hover,
#chatbot-close:hover {
  color: white;
  background: rgba(255, 255, 255, 0.1);
}

/* Profiling Form Overlay */
#chatbot-form-container {
  display: none; /* Initially hidden */
  position: absolute;
  top: 60px; /* Below header */
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100; /* Above chat */
  padding: 18px;
  background: #fdfcfb;
  overflow-y: auto;
  border-top: 1.5px solid #20201e;
  animation: slideFadeDown 0.25s ease forwards;
}

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

#chatbot-form-container h3 {
  margin-top: 0;
  font-size: 15px;
  color: #20201e;
  margin-bottom: 14px;
  font-family: 'Playfair Display', serif;
}

.chatbot-form-group {
  margin-bottom: 12px;
}

.chatbot-form-group label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: #5a5a54;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chatbot-form-group input,
.chatbot-form-group select {
  width: 100%;
  padding: 8px 10px;
  border: 1.5px solid #20201e;
  border-radius: 8px;
  font-size: 14px;
  font-family: 'Nunito', sans-serif;
  box-sizing: border-box;
  background: white;
  outline: none;
  transition: border-color 0.2s;
}

.chatbot-form-group input:focus,
.chatbot-form-group select:focus {
  border-color: #66a307;
  box-shadow: 0 0 0 3px rgba(102, 163, 7, 0.12);
}

#chatbot-start-btn {
  width: 100%;
  padding: 11px;
  background: #66a307;
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  font-family: 'Nunito', sans-serif;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
  margin-top: 4px;
}

#chatbot-start-btn:hover {
  background: #4a8a2e;
  transform: translateY(-1px);
}

/* Chat Interface */
#chatbot-chat-container {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* Messages area with logo as faded background */
#cb-messages-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  background-color: #fbf8f5;
  display: flex;
  flex-direction: column;
}

#chatbot-messages {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  z-index: 2;
  background: transparent;
}

/* Starter Phrases (Persistent above input) */
#chatbot-starter-container {
  padding: 8px 12px;
  background: #fdfcfb;
  border-top: 1.5px solid #e0dbd4;
  animation: fadeIn 0.4s ease;
  overflow-x: auto;
  white-space: nowrap;
}

#chatbot-starter-container::-webkit-scrollbar {
  height: 4px;
}

#chatbot-starter-container::-webkit-scrollbar-thumb {
  background: #d4cfc9;
  border-radius: 10px;
}

.cb-starter-pills {
  display: flex;
  gap: 8px;
}

.cb-starter-btn {
  background: white;
  border: 1.5px solid #66a307;
  color: #66a307;
  padding: 6px 12px;
  border-radius: 18px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.cb-starter-btn:hover {
  background: #66a307;
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(102, 163, 7, 0.2);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Watermark logo - FIXED and CENTERED */
.cb-watermark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 180px;
  opacity: 0.08;
  z-index: 1;
  pointer-events: none;
  display: flex;
  justify-content: center;
  align-items: center;
}

.cb-watermark img {
  width: 100%;
  height: auto;
  filter: grayscale(100%);
}

/* --- Message Row: avatar + bubble --- */
.cb-message-row {
  display: flex;
  align-items: flex-end;
  gap: 7px;
}

.cb-message-row.bot {
  align-self: flex-start;
  flex-direction: row;
}

.cb-message-row.user {
  align-self: flex-end;
}

/* Avatar image/icon */
.cb-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: contain;
  background: white;
  border: 1.5px solid #20201e;
  padding: 2px;
}

.cb-avatar.user-avatar {
  background: #66a307;
  border-color: #66a307;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 13px;
  padding: 0;
}

/* Bubble */
.chatbot-message {
  max-width: 82%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  word-wrap: break-word;
}

.chatbot-message.bot {
  background: white;
  color: #20201e;
  border: 1.5px solid #e0dbd4;
  border-bottom-left-radius: 3px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
}

.chatbot-message.user {
  background: #66a307;
  color: white;
  border-bottom-right-radius: 3px;
  box-shadow: 0 1px 4px rgba(102, 163, 7, 0.25);
}

/* Sender label */
.cb-sender-label {
  font-size: 10px;
  font-weight: 700;
  color: #5a5a54;
  margin-bottom: 2px;
  padding: 0 2px;
}

.cb-message-wrap {
  display: flex;
  flex-direction: column;
}

.cb-message-row.user .cb-message-wrap {
  align-items: flex-end;
}

.cb-message-row.bot .cb-message-wrap {
  align-items: flex-start;
}

.cb-message-row.user .cb-sender-label {
  color: #4a8a2e;
  text-align: right;
}

/* --- Markdown rendering inside bot bubbles --- */
.chatbot-message.bot ul {
  list-style: none;
  padding: 0;
  margin: 6px 0 2px 0;
}

.chatbot-message.bot ul li {
  padding-left: 16px;
  position: relative;
  margin-bottom: 3px;
  color: #20201e;
}

.chatbot-message.bot ul li::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 8px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #66a307;
}

.chatbot-message.bot ol {
  padding-left: 18px;
  margin: 6px 0 2px 0;
}

.chatbot-message.bot ol li {
  margin-bottom: 3px;
  color: #20201e;
}

.chatbot-message.bot strong {
  color: #20201e;
  font-weight: 700;
}

.chatbot-message.bot em {
  font-style: italic;
  color: #5a5a54;
}

.chatbot-message.bot p {
  margin: 0 0 6px 0;
  max-width: none;
  text-shadow: none;
  color: #20201e;
  font-size: 13.5px;
}

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

.chatbot-message.bot h3,
.chatbot-message.bot h4 {
  font-family: 'Playfair Display', serif;
  font-size: 14px;
  margin: 6px 0 4px;
  color: #20201e;
}

.chatbot-message.bot a {
  color: #66a307;
  text-decoration: underline;
}

/* Stream cursor blink */
.chatbot-message.bot.streaming::after {
  content: '▌';
  display: inline-block;
  animation: blink 0.7s step-end infinite;
  color: #66a307;
  margin-left: 2px;
}

@keyframes blink {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0;
  }
}

/* Typing indicator */
.cb-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: white;
  border: 1.5px solid #e0dbd4;
  border-radius: 14px;
  border-bottom-left-radius: 3px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
  width: fit-content;
}

.cb-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #66a307;
  display: inline-block;
  animation: typing-bounce 1.2s infinite ease-in-out;
}

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

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

@keyframes typing-bounce {

  0%,
  80%,
  100% {
    transform: scale(0.7);
    opacity: 0.5;
  }

  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Input Area */
#chatbot-input-area {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background: white;
  border-top: 1.5px solid #e0dbd4;
  gap: 8px;
}

#chatbot-input {
  flex: 1;
  border: 1.5px solid #d4cfc9;
  border-radius: 22px;
  padding: 9px 15px;
  font-size: 13.5px;
  font-family: 'Nunito', sans-serif;
  outline: none;
  background: #fbf8f5;
  color: #20201e;
  transition: border-color 0.2s;
}

#chatbot-input:focus {
  border-color: #66a307;
  box-shadow: 0 0 0 3px rgba(102, 163, 7, 0.1);
}

#chatbot-send-btn {
  background: #66a307;
  color: white;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 14px;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s;
}

#chatbot-send-btn:hover {
  background: #4a8a2e;
  transform: scale(1.06);
}

#chatbot-send-btn:disabled {
  background: #b0c98a;
  cursor: not-allowed;
  transform: none;
}

/* Responsive */
@media (max-width: 450px) {
  #chatbot-popup {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    bottom: 0;
    right: 0;
    border-radius: 0;
    border: none;
    position: fixed;
    z-index: 10000;
  }
}