/* Root */
.mai-root {}

/* Floating action button (rounded square, image cover) */
.mai-fab {
  --mai-btn-size: 64px;
  --mai-logo: none;
  --mai-primary: #2e3094;
  /* Default for fallback */

  position: fixed;
  right: 20px;
  bottom: 20px;
  width: var(--mai-btn-size);
  height: var(--mai-btn-size);
  border-radius: 12px;
  /* Rounded square style */
  border: none;
  /* Use CSS variable for background color and logo */
  background: var(--mai-primary) var(--mai-logo) center/contain no-repeat;
  color: #fff;
  box-shadow: 0 10px 24px rgba(0, 0, 0, .2);
  cursor: pointer;
  z-index: 999999;
  transition: transform .15s ease, box-shadow .15s ease, background-color .2s ease;
}

.mai-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 30px rgba(0, 0, 0, .25);
}

/* Popup shell */
.mai-popup {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .25);
  z-index: 999998;
  display: none;
}

.mai-popup.is-open {
  display: block;
}

.mai-popup__card {
  position: absolute;
  right: 24px;
  bottom: 100px;
  width: 380px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
  transform-origin: bottom right;
  transition: transform .2s ease;
}

@media (max-width: 480px) {
  .mai-popup__card {
    right: 10px;
    bottom: 80px;
    width: 95%;
    max-height: 90vh;
  }
}

.mai-popup.is-closing .mai-popup__card {
  transform: scale(0.9);
  opacity: 0;
}

/* Header */
.mai-popup__head {
  padding: 12px 16px;
  /* Use the primary color variable for branding */
  background: var(--mai-primary, #2e3094);
  color: var(--mai-header-text, #ffffff);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 16px;
}

.mai-close-btn,
.mai-clear-btn {
  background: none;
  border: none;
  color: inherit;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
  /* Added padding to clear button */
}

/* Messages area */
.mai-popup__body {
  flex-grow: 1;
  padding: 16px 12px;
  overflow-y: auto;
  background: #f7f7f7;
  max-height: 100%;
  /* Important for flex layout */
  min-height: 150px;
}

.mai-msg {
  display: flex;
  margin-bottom: 10px;
}

.mai-user {
  justify-content: flex-end;
}

.mai-assistant {
  justify-content: flex-start;
}

.mai-bubble {
  max-width: 90%;
  padding: 10px 12px;
  border-radius: 12px;
  line-height: 1.35;
  font-size: 14px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .06);
  box-sizing: border-box;
  overflow-wrap: break-word;
  /* Modern property */
  word-wrap: break-word;
  /* Legacy support */
  word-break: break-word;
  /* Non-standard but helpful in WebKit */
}

.mai-user .mai-bubble {
  /* Use the primary color variable for user messages */
  background: var(--mai-primary, #2e3094);
  color: #fff;
  border-top-right-radius: 4px;
}

.mai-assistant .mai-bubble,
.mai-msg.mai-assistant .mai-bubble {
  background: #fff;
  color: #171717;
  border-top-left-radius: 4px;
  border: 1px solid #e6e7ea;
}

.mai-loading .mai-bubble {
  opacity: .7;
  font-style: italic;
}

/* Enforce link formatting */
.mai-bubble a {
  display: inline-block;
  /* Essential to enforce new line breaks */
  margin-top: 6px;
  /* Links in assistant message use primary color */
  color: var(--mai-primary, #2e3094);
  text-decoration: underline;
  word-break: break-all;
}

/* Ensure paragraph breaks are visible */
.mai-bubble br+br {
  display: block;
  content: " ";
  margin-top: 10px;
  /* Space between paragraphs */
}

/* Footer */
.mai-popup__foot {
  padding: 12px;
  border-top: 1px solid #e6e7ea;
  background: #fff;
}

.mai-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.mai-input {
  border: 1px solid #d9dbe0;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
}

/* Input focus border uses primary color */
.mai-input:focus {
  border-color: var(--mai-primary, #2e3094);
}

.mai-submit-btn {
  /* Use the primary color variable for the submit button */
  background: var(--mai-primary, #2e3094);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 0 16px;
  cursor: pointer;
  transition: opacity .15s ease;
}

.mai-submit-btn:disabled {
  opacity: .5;
  cursor: default;
}

.mai-powered-by {
  font-size: 10px;
  text-align: center;
  color: #888;
  margin-top: 5px;
}

/* Suggestion Chips */
.mai-suggestions-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
  justify-content: flex-end;
  /* Align chips to the right */
}

.mai-chip {
  background: transparent;
  border: 1px solid var(--mai-primary, #2e3094);
  color: var(--mai-primary, #2e3094);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: normal;
  max-width: 100%;
  text-align: left;
  word-break: break-word;
}

.mai-chip:hover {
  background: var(--mai-primary, #2e3094);
  color: #fff;
}