/**
 * Chatbot Body Styles
 * Messages container and content display
 */

.mr-chatbot-body {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  opacity: 1;
  background-color: var(--mr-chatbot-color-white);
  border-radius: var(--mr-chatbot-box-border-radius);
  padding: var(--mr-chatbot-spacing);
  padding-bottom: calc(var(--mr-chatbot-spacing) + max(env(safe-area-inset-bottom, 0px), var(--mr-kb, 0px)));
  -webkit-overflow-scrolling: touch;
  transition: var(--mr-chatbot-transition);
}

/* Body visibility states */
.mr-chatbot-container.minimized .mr-chatbot-body {
  display: none;
}

.mr-chatbot-container.opening .mr-chatbot-body,
.mr-chatbot-container.closing .mr-chatbot-body {
  display: unset;
  opacity: 0;
}

/* Base text styles */
.mr-chatbot-body b,
.mr-chatbot-body strong {
  color: var(--mr-chatbot-color-dark-gray);
  font-weight: var(--mr-chatbot-font-weight-semibold);
}

.mr-chatbot-body i,
.mr-chatbot-body em {
  font-style: italic;
}

.mr-chatbot-body u {
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 2px;
  text-decoration-color: var(--mr-chatbot-color-primary);
}

/* Links */
.mr-chatbot-body a {
  color: var(--mr-chatbot-color-primary);
  font-weight: var(--mr-chatbot-font-weight-normal);
  text-decoration: none;
}

.mr-chatbot-body a:hover,
.mr-chatbot-body a:focus {
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Lists */
.mr-chatbot-body ul:not(.navbar-nav),
.mr-chatbot-body ol {
  margin: 0.25em 0;
  padding-left: 1.25em;
}

.mr-chatbot-body ul:not(.navbar-nav) li,
.mr-chatbot-body ol li {
  margin: 0.25em 0;
}

.mr-chatbot-body ul:not(.navbar-nav) li::marker,
.mr-chatbot-body ol li::marker {
  color: var(--mr-chatbot-color-primary);
}

.mr-chatbot-body ol li::marker {
  font-weight: var(--mr-chatbot-font-weight-semibold);
}

/* Info panel */
.mr-chatbot-info {
  height: unset;
  padding-left: 16px;
  padding-right: 8px;
  opacity: 1;
  overflow: unset;
  border: 1px solid var(--mr-chatbot-color-blush);
  border-radius: 16px;
  padding: 23px 21px;
  transition: opacity 275ms ease;
}

.mr-chatbot-info.hidden {
  opacity: 0;
  height: 0;
  overflow: hidden;
  padding: 0;
  border-width: 0;
  transition: opacity 275ms ease, height 0ms 275ms, overflow 0ms 275ms, padding 0ms 275ms;
}

.mr-chatbot-info p,
.mr-chatbot-info p * {
  font-size: var(--mr-chatbot-font-content) !important;
  line-height: var(--mr-chatbot-line-height) !important;
  color: var(--mr-chatbot-color-dark-gray);
}

.mr-chatbot-info p a {
  color: var(--mr-chatbot-color-primary);
}

.mr-chatbot-info p:last-of-type {
  margin-bottom: 0;
}

.mr-chatbot-info-section {
  margin-bottom: var(--mr-chatbot-spacing);
}

.mr-chatbot-info-section:last-child {
  margin-bottom: 0;
}

.mr-chatbot-info-section h3 {
  margin-bottom: calc(var(--mr-chatbot-spacing) / 2);
  font-size: var(--mr-chatbot-font-content);
  font-weight: var(--mr-chatbot-weight-semibold);
  color: var(--mr-chatbot-color-dark-gray);
}

/* Messages container */
.mr-chatbot-messages {
  height: unset;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  list-style: none;
  opacity: 1;
  overflow: unset;
  overflow-anchor: none;
  transition: opacity 275ms ease;
}

.mr-chatbot-messages.hidden {
  opacity: 0;
  height: 0;
  overflow: hidden;
  transition: opacity 275ms ease, height 0ms 275ms, overflow 0ms 275ms;
}

/* Message bubbles — base */
.mr-chatbot-message {
  margin: 0 0 calc(var(--mr-chatbot-spacing) / 2) 0 !important;
  padding: var(--mr-chatbot-bubble-padding-v) var(--mr-chatbot-bubble-padding-h);
  word-wrap: break-word;
  text-align: left;
  font-size: var(--mr-chatbot-font-content) !important;
  font-weight: var(--mr-chatbot-weight-light);
  line-height: var(--mr-chatbot-line-height) !important;
  color: var(--mr-chatbot-color-dark-gray);
}

.mr-chatbot-message:last-child {
  margin-bottom: 0 !important;
}

/* Bot message */
.mr-chatbot-message-bot {
  position: relative;
  background: var(--mr-chatbot-color-light-gray);
  margin-left: var(--mr-chatbot-icon-offset) !important;
  border-radius: 0 var(--mr-chatbot-bubble-radius) var(--mr-chatbot-bubble-radius) var(--mr-chatbot-bubble-radius);
  max-width: 100%;
}

.mr-chatbot-message-content {
  white-space: normal;
  word-break: break-word;
  overflow-wrap: break-word;
}

.mr-chatbot-message-content p:last-of-type {
  margin-bottom: 0;
}

/* Hemmy icon beside bot messages */
.mr-chatbot-message-bot::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: calc(-1 * var(--mr-chatbot-icon-offset));
  width: var(--mr-chatbot-icon-size);
  height: var(--mr-chatbot-icon-size);
  background: url('../../Images/hemmy.svg') no-repeat;
  background-size: contain;
}

/* Hide icon for consecutive bot messages */
.mr-chatbot-message-bot:has(+ .mr-chatbot-message-bot)::before {
  display: none;
}

/* User message */
.mr-chatbot-message-user {
  background: var(--mr-chatbot-color-dark-gray);
  border-radius: var(--mr-chatbot-bubble-radius) var(--mr-chatbot-bubble-radius) 0 var(--mr-chatbot-bubble-radius);
  align-self: end;
  max-width: 85%;
  color: #fff !important;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
}

.mr-chatbot-message-user .mr-chatbot-message-content {
  color: #fff;
}

/* Loading animation */
.mr-chatbot-loading {
  display: none;
  justify-content: start;
  align-items: start;
  margin-top: var(--mr-chatbot-spacing);
  transition: var(--mr-chatbot-transition);
}

.mr-chatbot-loading:not(.hidden) {
  display: flex;
}

.mr-chatbot-loading-dot {
  width: 6px;
  height: 6px;
  margin-right: 4px;
  border-radius: 50%;
  background-color: #DBBFC2;
  opacity: 0;
  animation: mr-chatbot-grow 1.5s infinite ease-in-out;
}

.mr-chatbot-loading-dot:nth-child(1) {
  animation-delay: 0.35s;
}

.mr-chatbot-loading-dot:nth-child(2) {
  animation-delay: 0.7s;
}

.mr-chatbot-loading-dot:nth-child(3) {
  animation-delay: 1.05s;
}

@keyframes mr-chatbot-grow {
  0% {
    transform: scale(0);
    opacity: 0.25;
  }
  50% {
    transform: scale(1);
    opacity: 0.85;
  }
  100% {
    transform: scale(0);
    opacity: 0.25;
  }
}

/* Inline citations */
.mr-chatbot-message-content .mr-chatbot-citations {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: 2px;
  vertical-align: super;
  font-size: 0.72em;
  line-height: 1;
  white-space: nowrap;
}

.mr-chatbot-message-content .mr-chatbot-citation-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 2px;
  min-width: 1.35em;
  height: 1.35em;
  padding: 0 0.3em;
  vertical-align: super;
  font-size: 0.72em;
  line-height: 1;
  border: 1px solid var(--mr-chatbot-color-blush);
  border-radius: 999px;
  background: #fff;
  color: var(--mr-chatbot-color-primary);
  font-weight: var(--mr-chatbot-weight-semibold);
  text-decoration: none;
}

.mr-chatbot-message-content .mr-chatbot-citation-link:hover {
  background: var(--mr-chatbot-color-blush);
  text-decoration: none;
}

/* Sources display */
.mr-chatbot-sources {
  margin-top: calc(var(--mr-chatbot-spacing) / 2);
  padding-top: calc(var(--mr-chatbot-spacing) / 2);
  border-top: 1px solid var(--mr-chatbot-color-blush);
  font-size: 0.92em;
  counter-reset: mr-chatbot-source;
}

.mr-chatbot-sources-title {
  font-weight: var(--mr-chatbot-weight-semibold);
  margin-bottom: calc(var(--mr-chatbot-spacing) / 4);
  color: var(--mr-chatbot-color-dark-gray);
}

.mr-chatbot-body .mr-chatbot-sources-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.mr-chatbot-body .mr-chatbot-source-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 6px;
  align-items: baseline;
  margin: 0;
}

.mr-chatbot-body .mr-chatbot-source-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.4em;
  height: 1.4em;
  border-radius: 999px;
  background: var(--mr-chatbot-color-blush);
  color: var(--mr-chatbot-color-primary);
  font-size: 0.82em;
  font-weight: var(--mr-chatbot-weight-semibold);
  line-height: 1;
}

.mr-chatbot-body .mr-chatbot-sources a {
  min-width: 0;
  color: var(--mr-chatbot-color-primary);
  text-decoration: none;
  font-size: inherit;
  overflow-wrap: anywhere;
}

.mr-chatbot-body .mr-chatbot-sources a:hover {
  text-decoration: underline;
}

.mr-chatbot-body .mr-chatbot-sources > a {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 6px;
  align-items: baseline;
  margin-top: 4px;
}

.mr-chatbot-body .mr-chatbot-sources > a::before {
  counter-increment: mr-chatbot-source;
  content: counter(mr-chatbot-source);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.4em;
  height: 1.4em;
  border-radius: 999px;
  background: var(--mr-chatbot-color-blush);
  color: var(--mr-chatbot-color-primary);
  font-size: 0.82em;
  font-weight: var(--mr-chatbot-weight-semibold);
  line-height: 1;
}

/* Mobile adjustments */
@media (max-width: 576px) {
  /* --mr-chatbot-icon-size: 24px is set on .mr-chatbot-container in container.css icon-offset, icon-size in ::before, and message margin-left all cascade automatically */
  .mr-chatbot-body {
    padding: var(--mr-chatbot-spacing) calc(var(--mr-chatbot-spacing) / 2);
  }
}
