/* =========================================================================
   CABR InfoBot
   ========================================================================= */

#cabr-infobot-button {
  position: fixed;

  /* Responsive position + size.
     Browser zoom changes the effective viewport width, so clamp()
     also lets the InfoBot reduce/increase naturally when zooming. */
  bottom: clamp(16px, 2vw, 32px);
  right: clamp(16px, 2vw, 32px);
  width: clamp(56px, 5vw, 80px);
  height: clamp(56px, 5vw, 80px);

  border-radius: 50%;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  cursor: pointer;
  z-index: 9999;
  background: transparent;
  border: 1px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

#cabr-infobot-button img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: contain;
}

#cabr-infobot-popup {
  position: fixed;
  bottom: 140px;
  right: 32px;
  width: 360px;
  background: #f7f7f7;
  border-radius: 20px;
  box-shadow: 0 4px 32px rgba(0,0,0,0.18);
  font-family: 'Open Sans', sans-serif;
  z-index: 9999;
  display: flex;
  flex-direction: column;
}

.cabr-hidden {
  display: none !important;
}

/* Header */
.cabr-popup-header {
  background: #16a34a;
  padding: 18px 24px 12px;
  border-radius: 20px 20px 0 0;
}

.cabr-infobot-heading {
  color: #fff;
  text-align: center;
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
}

/* Search */
.cabr-search-row {
  display: flex;
  gap: 8px;
}

#cabr-infobot-search {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid #ccc;
  font-size: 15px;
}

.cabr-ask-btn {
  background: #004b88;
  color: #fff;
  border-radius: 10px;
  border: none;
  padding: 6px 10px;
  cursor: pointer;
}

.cabr-ask-btn:hover {
  background: #003a6d;
}

/* Body */
.cabr-popup-body {
  padding: 22px;
  max-height: 400px;
  overflow-y: auto;
}

/* AI inline */
.cabr-ai-inline {
  margin-bottom: 14px;
}

.cabr-ai-inline-text {
  font-size: 14px;
  color: #333;
  margin-bottom: 10px;
}

/* ✅ LEFT-ALIGN AI OPTION BUTTONS */
.cabr-ai-inline-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-start;
  align-items: flex-start;
}

/* AI option buttons */
.cabr-ai-btn {
  appearance: none;
  -webkit-appearance: none;
  background: #ffffff;
  color: #004b88;
  border: 2px solid #004b88;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.cabr-ai-btn:hover {
  background: #004b88;
  color: #ffffff;
}

.cabr-ai-btn:focus {
  outline: none;
}

.cabr-ai-btn:focus-visible {
  outline: 3px solid rgba(0,75,136,0.35);
  outline-offset: 2px;
}

/* =========================================================================
   ✅ Green borders for "Show All Above links" + "None of the above"
   + Keep "Show All Above links" dotted
   ========================================================================= */
#cabr-infobot-popup .cabr-ai-btn.cabr-ai-showlinks,
#cabr-infobot-popup .cabr-ai-btn.cabr-ai-none {
  border-color: #16a34a !important; /* match header green */
}

#cabr-infobot-popup .cabr-ai-btn.cabr-ai-showlinks {
  border-style: dotted !important; /* dotted everywhere */
}

/* Optional: make focus indicator dotted + green-ish */
#cabr-infobot-popup .cabr-ai-btn.cabr-ai-showlinks:focus-visible {
  outline: 2px dotted #16a34a;
  outline-offset: 2px;
}

/* Optional: green hover for these two buttons */
#cabr-infobot-popup .cabr-ai-btn.cabr-ai-showlinks:hover,
#cabr-infobot-popup .cabr-ai-btn.cabr-ai-none:hover {
  background: #16a34a;
  color: #ffffff;
}

/* Selection banner */
.cabr-selection {
  background: #ffffff;
  border: 1px solid #d7e6f5;
  border-left: 6px solid #004b88;
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 13px;
}

.cabr-selection-text {
  color: #004b88;
  font-weight: 700;
}

/* Results */
.cabr-result-item {
  margin-bottom: 22px;
}

.cabr-result-title a {
  font-size: 18px;
  font-weight: 600;
  color: #003366;
  text-decoration: underline;
}

.cabr-result-title a:hover {
  text-decoration: none;
}

.cabr-result-desc {
  color: #444;
  font-size: 15px;
}

/* Pagination */
#cabr-infobot-pagination {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

#cabr-infobot-popup #cabr-infobot-pagination button.cabr-page-btn {
  background: #004b88;
  color: #ffffff;
  border: none;
}

#cabr-infobot-popup #cabr-infobot-pagination button.cabr-page-btn:hover {
  background: #003a6d;
}

/* Contact */
.cabr-contact-bar {
  text-align: center;
  margin-top: 16px;
}

.cabr-contact-btn {
  background: #004b88;
  color: #fff;
  border-radius: 10px;
  padding: 6px 12px;
  border: none;
  cursor: pointer;
}

.cabr-contact-btn:hover {
  background: #003a6d;
}

/* Email */
.cabr-email-row {
  display: none;
  gap: 8px;
  justify-content: center;
  margin-bottom: 10px;
}

#cabr-email-to {
  max-width: 210px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #ccc;
  font-size: 13px;
}

.cabr-email-status {
  display: none;
  font-size: 12px;
  color: #444;
  margin-bottom: 10px;
}

/* Loading / no results */
.cabr-loading,
.cabr-no-results {
  font-size: 14px;
  color: #444;
}

/* Hide until JS shows */
#cabr-infobot-results,
#cabr-infobot-pagination {
  display: none;
}

/* =========================================================================
   🔙 Back to AI options button (BOTTOM, SMALL, ROUNDED)
   ========================================================================= */

.cabr-ai-back-bottom {
  text-align: center;
  margin: 12px 0 4px;
}

.cabr-ai-back-btn {
  appearance: none;
  -webkit-appearance: none;
  border-radius: 999px !important;
  padding: 4px 12px;
  font-size: 12px;
  background: #f5f7fa;
  border: 1px solid #d6dbe3;
  color: #0b3a66;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.cabr-ai-back-btn:hover {
  background: #eef3f8;
  border-color: #b9c7d6;
}

.cabr-ai-back-btn:focus {
  outline: none;
}

/* ✅ Back to previous suggestions button (same styling) */
.cabr-ai-back-prev-bottom {
  text-align: center;
  margin: 10px 0 4px;
}

.cabr-ai-back-prev-btn {
  appearance: none;
  -webkit-appearance: none;
  border-radius: 999px !important;
  padding: 4px 12px;
  font-size: 12px;
  background: #f5f7fa;
  border: 1px solid #d6dbe3;
  color: #0b3a66;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.cabr-ai-back-prev-btn:hover {
  background: #eef3f8;
  border-color: #b9c7d6;
}

.cabr-ai-back-prev-btn:focus {
  outline: none;
}

/* Move "New Search" down so it doesn't touch the email box */
#cabr-infobot-popup #cabr-infobot-new-search {
  margin-top: 10px !important;
}

/* Lock Contact Us button sizing so it doesn't grow in certain stages */
#cabr-infobot-popup a#cabr-contact-us-btn {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  width: auto !important;
  flex: 0 0 auto !important;
  padding: 10px 14px !important;
  font-size: 15px !important;
  line-height: 1.1 !important;
}

/* ✅ Lock New Search sizing the same as Contact Us */
#cabr-infobot-popup #cabr-infobot-new-search,
#cabr-infobot-popup .cabr-new-search-btn {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  width: auto !important;
  flex: 0 0 auto !important;
  padding: 10px 14px !important;
  font-size: 15px !important;
  line-height: 1.1 !important;
  text-decoration: none !important;
}

#cabr-infobot-popup .cabr-contact-bar {
  align-items: flex-start;
}

/* Respect users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  #cabr-infobot-button {
    animation: none !important;
  }

  #cabr-infobot-button img {
    animation: none !important;
  }
}

/* Wobble animation */
@keyframes cabrWobble {
  0%, 88%, 100% {
    transform: rotate(0deg);
  }

  90% {
    transform: rotate(6deg);
  }

  92% {
    transform: rotate(-6deg);
  }

  94% {
    transform: rotate(4deg);
  }

  96% {
    transform: rotate(-4deg);
  }

  98% {
    transform: rotate(2deg);
  }
}

/* Apply to the whole floating button */
#cabr-infobot-button {
  transform-origin: 50% 60%;
  animation: cabrWobble 5s ease-in-out infinite;
}

/* Stop animation while popup is open */
#cabr-infobot-button.cabr-open,
#cabr-infobot-button.cabr-open img {
  animation: none !important;
}

/* =========================================================================
   ✅ New UI bits for "None of these fit" + Back stack
   (SAFE: scoped to InfoBot only)
   ========================================================================= */

/* Make sure the back wrap always sits nicely under pagination */
#cabr-infobot-popup .cabr-ai-back-wrap.cabr-ai-back-bottom {
  width: 100%;
  display: flex;
  justify-content: center;
  margin: 10px 0 6px;
}

/* OPTIONAL: style "None of these fit" as a softer secondary button */
#cabr-infobot-popup .cabr-ai-btn.cabr-ai-none {
  background: #ffffff;
  color: #444;
  border: 2px solid #c9d4e1;
}

#cabr-infobot-popup .cabr-ai-btn.cabr-ai-none:hover {
  background: #f3f6fa;
  color: #222;
  border-color: #b7c6d8;
}

/* Keep "Show Citizens Advice links" looking consistent */
#cabr-infobot-popup .cabr-ai-btn.cabr-ai-showlinks {
  border-style: dotted !important;
}

/* 

/* ================================================================
   InfoBot logo -> close (×) button while popup is open
   Add this block to the END of assets/infobot.css
   ================================================================ */

/* The existing logo remains visible while InfoBot is closed. */
#cabr-infobot-button.cabr-open {
  position: fixed;
  background: #16a34a;
  border-color: #ffffff;
  animation: none !important;

  /* Keep the close button proportionate as the viewport/zoom changes. */
  width: clamp(44px, 3.25vw, 52px);
  height: clamp(44px, 3.25vw, 52px);
}

/* Hide the logo only while the popup is open. */
#cabr-infobot-button.cabr-open img {
  display: none !important;
}

/* Replace it with a clean white close cross. */
#cabr-infobot-button.cabr-open::before {
  content: "×";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-family: Arial, Helvetica, sans-serif;
  font-size: clamp(21px, 1.6vw, 24px);
  font-weight: 300;
  line-height: 1;
  transform: none;
  pointer-events: none;
}

/* Slight hover feedback for the close button on desktop. */
#cabr-infobot-button.cabr-open:hover {
  filter: brightness(0.94);
}


/* Remove blue tap/highlight box on mobile */
#cabr-infobot-button {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  outline: none !important;
  user-select: none;
  -webkit-user-select: none;
}

#cabr-infobot-button:active,
#cabr-infobot-button:focus {
  outline: none !important;
}

#cabr-infobot-button img {
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
  -webkit-user-select: none;
}

=========================================================================
   Mobile
   ========================================================================= */


/* =========================================================================
   Responsive InfoBot button - tablet / smaller desktop
   ========================================================================= */

@media (max-width: 900px) {
  #cabr-infobot-button {
    bottom: clamp(16px, 2.5vw, 24px);
    right: clamp(16px, 2.5vw, 24px);
    width: clamp(58px, 8vw, 70px);
    height: clamp(58px, 8vw, 70px);
  }

  #cabr-infobot-button.cabr-open {
    width: clamp(44px, 5.5vw, 50px);
    height: clamp(44px, 5.5vw, 50px);
  }
}

@media (max-width: 480px) {
  #cabr-infobot-button {
    bottom: clamp(14px, 5vw, 20px);
    right: clamp(14px, 5vw, 20px);
    width: clamp(52px, 16vw, 62px);
    height: clamp(52px, 16vw, 62px);
  }

  #cabr-infobot-button.cabr-open {
    width: clamp(42px, 12vw, 48px);
    height: clamp(42px, 12vw, 48px);
  }

  #cabr-infobot-button.cabr-open::before {
    font-size: clamp(20px, 6vw, 23px);
  }

  #cabr-infobot-popup {
    width: 90%;
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%);
    bottom: 120px;
  }
}

/* =========================================================================
   InfoBot "Here to Help" speech bubble
   - Positioned by JS from the ACTUAL rendered InfoBot button, so the gap
     stays consistent on desktop, mobile and at different browser zoom levels.
   ========================================================================= */

#cabr-infobot-help-bubble {
  position: fixed;
  /* Keep the complete bubble AND its tail above the floating logo. */
  z-index: 10002;

  /* JS sets left/top from #cabr-infobot-button.getBoundingClientRect(). */
  left: 0;
  top: 0;
  right: auto;
  bottom: auto;

  box-sizing: border-box;
  width: max-content;
  max-width: min(180px, calc(100vw - 16px));
  padding: 10px 16px;

  /* Match the green used by the InfoBot logo/header. */
  background: #16a34a;
  color: #ffffff;
  border: 2px solid #16a34a;
  border-radius: 20px;
  box-shadow: 0 5px 18px rgba(0,0,0,0.16);

  font-family: 'Open Sans', Arial, sans-serif;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  text-align: center;

  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px) scale(0.88);
  transform-origin: 80% 100%;
}

/*
 * Downward-pointing tail. JS updates --cabr-tail-left so the point stays
 * aimed at the centre of the actual InfoBot button even when zoom/size changes.
 */
#cabr-infobot-help-bubble::before {
  content: "";
  position: absolute;
  left: var(--cabr-tail-left, calc(100% - 38px));
  bottom: -8px;
  width: 16px;
  height: 16px;
  background: #16a34a;
  transform: rotate(45deg);
  border-bottom-right-radius: 2px;
}

#cabr-infobot-help-bubble.cabr-show {
  visibility: visible;
  animation: cabrHelpBubblePop 4s ease-in-out both;
}

@keyframes cabrHelpBubblePop {
  0% {
    opacity: 0;
    transform: translateY(8px) scale(0.88);
  }

  10% {
    opacity: 1;
    transform: translateY(-1px) scale(1.03);
  }

  16%, 78% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  100% {
    opacity: 0;
    transform: translateY(5px) scale(0.94);
  }
}

/* The message is only for the closed logo, never the green close (×) button. */
body:has(#cabr-infobot-button.cabr-open) #cabr-infobot-help-bubble {
  display: none !important;
}

/* Keep typography compact on smaller screens; positioning itself is JS-driven. */
@media (max-width: 900px) {
  #cabr-infobot-help-bubble {
    font-size: 14px;
    padding: 9px 14px;
  }
}

@media (max-width: 480px) {
  #cabr-infobot-help-bubble {
    max-width: calc(100vw - 16px);
    padding: 8px 12px;
    border-radius: 18px;
    font-size: 13px;
  }

  #cabr-infobot-help-bubble::before {
    bottom: -7px;
    width: 14px;
    height: 14px;
  }
}

/* Accessibility: show without movement for people who prefer reduced motion. */
@media (prefers-reduced-motion: reduce) {
  #cabr-infobot-help-bubble.cabr-show {
    animation: none !important;
    opacity: 1;
    visibility: visible;
    transform: none;
  }
}
