/* ============================================================================
   AI CHATBOT WIDGET — #miChatbot (inc/chatbot/views/widget.php,
   assets/js/chatbot.js)
   Floating launcher + chat window in the brand palette: navy gradient header
   with the orange rule (same look as the Talk-to-Expert popup), palette-white
   conversation area, navy visitor bubbles, orange accents.

   Standalone stylesheet, enqueued by mi_chatbot_enqueue() only when the
   widget is shown. Plain CSS (not part of the Tailwind build), so no rebuild
   is needed after edits. Reads the --palette-* tokens defined in
   assets/css/input.css → style.css (with hex fallbacks), and is unlayered, so
   it wins over Tailwind's base/utility layers without !important.
   ============================================================================ */
.mi-chatbot {
  --mi-chat-navy: var(--palette-navy, #013047);
  --mi-chat-navy-2: #024a6a;
  --mi-chat-blue: var(--palette-blue, #219EBC);
  --mi-chat-orange: var(--palette-orange, #F16622);
  --mi-chat-orange-dark: color-mix(in srgb, var(--mi-chat-orange) 85%, black);
  --mi-chat-orange-soft: color-mix(in srgb, var(--mi-chat-orange) 8%, white);
  --mi-chat-orange-line: color-mix(in srgb, var(--mi-chat-orange) 30%, white);
  --mi-chat-green: var(--palette-green, #2D9B4D);
  --mi-chat-bg: var(--palette-white, #F3F5F6);
  --mi-chat-text: color-mix(in srgb, var(--palette-black, #121212) 85%, var(--palette-grey, #999999));
  --mi-chat-subtle: color-mix(in srgb, var(--palette-black, #121212) 55%, var(--palette-grey, #999999));
  --mi-chat-muted: color-mix(in srgb, var(--palette-grey, #999999) 85%, black);
  --mi-chat-border: color-mix(in srgb, var(--palette-black, #121212) 12%, var(--palette-white, #F3F5F6));
  --mi-chat-link: color-mix(in srgb, var(--mi-chat-blue) 70%, black);
  --mi-chat-launcher: 3rem; /* 48px, same as the Back-to-top button */
  --mi-chat-gap: 1.5rem;

  position: fixed;
  right: var(--mi-chat-gap);
  bottom: var(--mi-chat-gap);
  z-index: 90; /* above the sticky header (50), below popups like #talkToExpertModal (100) */
  line-height: 1.5;
}

/* ---- Launcher --------------------------------------------------------- */
.mi-chatbot-launcher {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--mi-chat-launcher);
  height: var(--mi-chat-launcher);
  padding: 0;
  border: 0;
  border-radius: 999px;
  color: #ffffff;
  background: linear-gradient(135deg, var(--mi-chat-orange) 0%, var(--mi-chat-orange-dark) 100%);
  box-shadow: 0 12px 28px -8px rgba(241, 102, 34, 0.55), 0 4px 10px rgba(1, 48, 71, 0.18);
  cursor: pointer;
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.25s ease, opacity 0.2s ease, visibility 0.2s ease;
}
.mi-chatbot-launcher:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 16px 32px -8px rgba(241, 102, 34, 0.6), 0 6px 14px rgba(1, 48, 71, 0.2);
}
.mi-chatbot-launcher:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--mi-chat-orange) 45%, white);
  outline-offset: 3px;
}
/* Soft attention ring — plays twice after page load, never while open. */
.mi-chatbot-launcher::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  animation: miChatPulse 2.4s ease-out 1.5s 2;
}
.mi-chatbot.is-open .mi-chatbot-launcher::after {
  animation: none;
}
@keyframes miChatPulse {
  from { box-shadow: 0 0 0 0 rgba(241, 102, 34, 0.45); }
  to   { box-shadow: 0 0 0 16px rgba(241, 102, 34, 0); }
}

/* Chat icon swaps to a chevron while the window is open. */
.mi-chatbot-launcher-icon {
  position: absolute;
  display: grid;
  place-items: center;
  transition: opacity 0.2s ease, transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.mi-chatbot-launcher-icon svg {
  width: 1.375rem;
  height: 1.375rem;
}
.mi-chatbot-launcher-icon--close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.6);
}
.mi-chatbot.is-open .mi-chatbot-launcher-icon--chat {
  opacity: 0;
  transform: rotate(90deg) scale(0.6);
}
.mi-chatbot.is-open .mi-chatbot-launcher-icon--close {
  opacity: 1;
  transform: none;
}

/* ---- Window ----------------------------------------------------------- */
.mi-chatbot-panel {
  position: absolute;
  right: 0;
  bottom: calc(var(--mi-chat-launcher) + 0.875rem);
  display: flex;
  flex-direction: column;
  width: min(25rem, calc(100vw - 2 * var(--mi-chat-gap)));
  height: min(40rem, calc(100vh - var(--mi-chat-launcher) - 3 * var(--mi-chat-gap)));
  height: min(40rem, calc(100dvh - var(--mi-chat-launcher) - 3 * var(--mi-chat-gap)));
  overflow: hidden;
  border-radius: 1.25rem;
  background: #ffffff;
  border: 1px solid rgba(1, 48, 71, 0.08);
  box-shadow: 0 24px 60px -20px rgba(1, 48, 71, 0.45), 0 8px 20px rgba(1, 48, 71, 0.12);
  transform-origin: bottom right;
  opacity: 0;
  visibility: hidden;
  transform: translate3d(0, 12px, 0) scale(0.96);
  transition: opacity 0.2s ease, transform 0.25s ease, visibility 0s linear 0.25s;
}
.mi-chatbot.is-open .mi-chatbot-panel {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity 0.25s ease, transform 0.38s cubic-bezier(0.22, 1, 0.36, 1), visibility 0s;
}

/* ---- Header ----------------------------------------------------------- */
.mi-chatbot-header {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
  padding: 1rem 0.875rem 1rem 1.125rem;
  color: #ffffff;
  background:
    radial-gradient(circle at 100% 0%, rgba(33, 158, 188, 0.35) 0%, transparent 55%),
    linear-gradient(135deg, var(--mi-chat-navy) 0%, var(--mi-chat-navy-2) 100%);
  border-bottom: 3px solid var(--mi-chat-orange);
}
.mi-chatbot-avatar {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.75rem;
  color: #ffffff;
  background: var(--mi-chat-orange);
  box-shadow: 0 6px 14px -4px rgba(241, 102, 34, 0.6);
}
.mi-chatbot-avatar svg {
  width: 1.25rem;
  height: 1.25rem;
}
.mi-chatbot-heading {
  flex: 1 1 auto;
  min-width: 0;
}
.mi-chatbot-eyebrow {
  margin: 0;
  font-size: 0.66rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mi-chat-orange);
}
.mi-chatbot-title {
  margin: 0.1rem 0 0;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: #ffffff;
}
.mi-chatbot-status {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.15rem 0 0;
  font-size: 0.75rem;
  line-height: 1.3;
  color: rgba(255, 255, 255, 0.75);
}
.mi-chatbot-status-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mi-chatbot-status-dot {
  flex-shrink: 0;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--mi-chat-green) 70%, white);
  box-shadow: 0 0 0 3px rgba(45, 155, 77, 0.3);
}
.mi-chatbot-header-actions {
  display: flex;
  align-self: flex-start;
  gap: 0.25rem;
  flex-shrink: 0;
}
.mi-chatbot-icon-btn {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 0;
  border-radius: 999px;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
  cursor: pointer;
  transition: background-color 0.2s ease;
}
.mi-chatbot-icon-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}
.mi-chatbot-icon-btn svg {
  width: 1rem;
  height: 1rem;
}

/* ---- Conversation ----------------------------------------------------- */
.mi-chatbot-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.125rem 1rem 1rem;
  background: var(--mi-chat-bg);
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}
.mi-chatbot-body:focus {
  outline: none;
}
.mi-chatbot-body::-webkit-scrollbar { width: 8px; }
.mi-chatbot-body::-webkit-scrollbar-track { background: transparent; }
.mi-chatbot-body::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 999px;
}

.mi-chatbot-msg {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  max-width: 100%;
}
.mi-chatbot-msg--user {
  justify-content: flex-end;
}
.mi-chatbot-msg.is-new {
  animation: miChatMsgIn 0.32s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes miChatMsgIn {
  from { opacity: 0; transform: translate3d(0, 8px, 0); }
  to   { opacity: 1; transform: none; }
}

.mi-chatbot-msg-avatar {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 999px;
  color: var(--mi-chat-orange);
  background: var(--mi-chat-orange-soft);
  border: 1px solid var(--mi-chat-orange-line);
}
.mi-chatbot-msg-avatar svg {
  width: 0.9rem;
  height: 0.9rem;
}

.mi-chatbot-bubble {
  max-width: 82%;
  padding: 0.65rem 0.9rem;
  font-size: 0.875rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
  border-radius: 1rem;
}
.mi-chatbot-msg--bot .mi-chatbot-bubble {
  color: var(--mi-chat-text);
  background: #ffffff;
  border: 1px solid var(--mi-chat-border);
  border-bottom-left-radius: 0.3rem;
  box-shadow: 0 1px 2px rgba(1, 48, 71, 0.05);
}
.mi-chatbot-msg--user .mi-chatbot-bubble {
  color: #ffffff;
  white-space: pre-wrap;
  background: linear-gradient(135deg, var(--mi-chat-navy) 0%, var(--mi-chat-navy-2) 100%);
  border-bottom-right-radius: 0.3rem;
  box-shadow: 0 4px 12px -6px rgba(1, 48, 71, 0.5);
}

/* Formatted bot replies (Markdown subset rendered by chatbot.js). Tailwind's
   preflight strips list styles and margins, so they're set explicitly.
   :where() keeps the reset at zero extra specificity so the spacing rule
   right after it wins. */
.mi-chatbot-bubble :where(p, ul, ol) {
  margin: 0;
}
.mi-chatbot-bubble > * + * {
  margin-top: 0.5rem;
}
.mi-chatbot-bubble ul,
.mi-chatbot-bubble ol {
  padding-left: 1.15rem;
}
.mi-chatbot-bubble ul { list-style: disc; }
.mi-chatbot-bubble ol { list-style: decimal; }
.mi-chatbot-bubble li + li {
  margin-top: 0.2rem;
}
.mi-chatbot-bubble li::marker {
  color: var(--mi-chat-orange);
}
.mi-chatbot-bubble strong {
  font-weight: 700;
  color: var(--mi-chat-navy);
}
.mi-chatbot-msg--user .mi-chatbot-bubble strong {
  color: inherit;
}
.mi-chatbot-bubble em {
  font-style: italic;
}
.mi-chatbot-bubble a {
  font-weight: 600;
  color: var(--mi-chat-link);
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-decoration-color: color-mix(in srgb, var(--mi-chat-blue) 40%, transparent);
  text-underline-offset: 2px;
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
}
.mi-chatbot-bubble a:hover {
  color: var(--mi-chat-orange-dark);
  text-decoration-color: currentColor;
}
.mi-chatbot-bubble code {
  padding: 0.1rem 0.35rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8em;
  border-radius: 0.35rem;
  background: var(--mi-chat-bg);
}

/* Suggested questions (under the welcome message, until the first send). */
.mi-chatbot-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding-left: 2.25rem; /* lines up with the bubbles, past the avatar */
  animation: miChatMsgIn 0.4s cubic-bezier(0.22, 1, 0.36, 1) 0.1s both;
}
.mi-chatbot-chip {
  padding: 0.45rem 0.85rem;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.3;
  text-align: left;
  color: var(--mi-chat-navy);
  background: #ffffff;
  border: 1px solid var(--mi-chat-orange-line);
  border-radius: 999px;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.15s ease;
}
.mi-chatbot-chip:hover {
  color: var(--mi-chat-orange-dark);
  background: var(--mi-chat-orange-soft);
  border-color: var(--mi-chat-orange);
  transform: translateY(-1px);
}

/* Typing indicator */
.mi-chatbot-typing {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  height: 1.35rem;
}
.mi-chatbot-typing span {
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 999px;
  background: var(--mi-chat-muted);
  animation: miChatTyping 1.2s ease-in-out infinite;
}
.mi-chatbot-typing span:nth-child(2) { animation-delay: 0.15s; }
.mi-chatbot-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes miChatTyping {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30%           { transform: translateY(-4px); opacity: 0.9; }
}

/* Error bubble with retry */
.mi-chatbot-msg--error .mi-chatbot-bubble {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  background: var(--mi-chat-orange-soft);
  border-color: var(--mi-chat-orange-line);
}
.mi-chatbot-error-icon {
  flex-shrink: 0;
  margin-top: 0.1rem;
  color: var(--mi-chat-orange-dark);
}
.mi-chatbot-error-icon svg {
  display: block;
  width: 1rem;
  height: 1rem;
}
.mi-chatbot-error-body p {
  margin: 0;
}
.mi-chatbot-retry {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.5rem;
  padding: 0.3rem 0.7rem;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--mi-chat-orange-dark);
  background: #ffffff;
  border: 1px solid var(--mi-chat-orange-line);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.2s ease;
}
.mi-chatbot-retry:hover {
  border-color: var(--mi-chat-orange);
}
.mi-chatbot-retry svg {
  width: 0.8rem;
  height: 0.8rem;
}

/* ---- Composer --------------------------------------------------------- */
.mi-chatbot-composer {
  flex-shrink: 0;
  margin: 0;
  padding: 0.75rem 0.875rem 0.65rem;
  background: #ffffff;
  border-top: 1px solid var(--mi-chat-border);
}
.mi-chatbot-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.35rem 0.35rem 0.35rem 0.9rem;
  background: var(--mi-chat-bg);
  border: 1px solid var(--mi-chat-border);
  border-radius: 1rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}
.mi-chatbot-input-wrap:focus-within {
  background: #ffffff;
  border-color: var(--mi-chat-orange);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--mi-chat-orange) 18%, transparent);
}
.mi-chatbot-input {
  flex: 1 1 auto;
  min-width: 0;
  max-height: 120px;
  margin: 0;
  padding: 0.45rem 0;
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.45;
  color: var(--palette-black, #121212);
  background: transparent;
  border: 0;
  border-radius: 0;
  outline: none;
  box-shadow: none;
  resize: none;
  overflow-y: hidden;
}
.mi-chatbot-input:focus,
.mi-chatbot-input:focus-visible {
  outline: none;
  box-shadow: none;
}
.mi-chatbot-input::placeholder {
  color: var(--mi-chat-muted);
}
.mi-chatbot-send {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 0;
  border-radius: 0.75rem;
  color: #ffffff;
  background: var(--mi-chat-orange);
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, transform 0.15s ease;
}
.mi-chatbot-send:hover:not(:disabled) {
  background: var(--mi-chat-orange-dark);
  transform: translateY(-1px);
}
.mi-chatbot-send:disabled {
  color: var(--mi-chat-muted);
  background: var(--mi-chat-border);
  cursor: not-allowed;
}
.mi-chatbot-send svg {
  width: 1.05rem;
  height: 1.05rem;
}
/* Inline (not flex) so the shield icon flows with the text when it wraps. */
.mi-chatbot-fineprint {
  margin: 0.55rem 0 0;
  font-size: 0.68rem;
  line-height: 1.45;
  text-align: center;
  color: var(--mi-chat-subtle);
}
.mi-chatbot-fineprint svg {
  display: inline-block;
  width: 0.8rem;
  height: 0.8rem;
  margin-right: 0.2rem;
  vertical-align: -0.15em;
  color: var(--mi-chat-green);
}
.mi-chatbot-fineprint a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.mi-chatbot-fineprint a:hover {
  color: var(--mi-chat-orange-dark);
}

/* ---- Back-to-top sits beside the launcher instead of underneath it ---- */
body.has-mi-chatbot #backToTop {
  right: calc(1.5rem + 3rem + 0.75rem);
  bottom: 1.5rem;
}

/* ---- Phones: full-screen chat ----------------------------------------- */
@media (max-width: 639px) {
  .mi-chatbot {
    --mi-chat-gap: 1rem;
  }
  .mi-chatbot-panel {
    position: fixed;
    inset: 0;
    width: auto;
    height: auto;
    border: 0;
    border-radius: 0;
    transform-origin: bottom center;
    transform: translate3d(0, 24px, 0);
  }
  .mi-chatbot-header {
    padding-top: max(1rem, env(safe-area-inset-top));
  }
  .mi-chatbot-composer {
    padding-bottom: max(0.65rem, env(safe-area-inset-bottom));
  }
  .mi-chatbot.is-open .mi-chatbot-launcher {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }
  .mi-chatbot-bubble {
    max-width: 86%;
  }
  /* 16px stops iOS Safari from zooming the page when the input is focused. */
  .mi-chatbot-input {
    font-size: 1rem;
  }
  html.mi-chatbot-open,
  html.mi-chatbot-open body {
    overflow: hidden;
  }
  body.has-mi-chatbot #backToTop {
    right: calc(1rem + 3rem + 0.75rem);
    bottom: 1rem;
  }
}

@media print {
  .mi-chatbot {
    display: none;
  }
}
