/**
 * AI Assistant Drawer - Algolia Agent Studio
 * Full-panel AI shopping assistant triggered from header sparkle icon.
 * Uses SlideUpDrawer for positioning (right desktop, bottom mobile).
 *
 * BEM block: .ai-drawer
 * @see ai-drawer.js
 * @see common/components/slide-up-drawer/slide-up-drawer.css
 */

/* ==========================================================================
   HEADER TRIGGER ICON
   ========================================================================== */

/** Desktop trigger - visible on lg+ screens, hidden on mobile via BS d-lg-none inverse */
.ai-drawer__trigger {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  position: relative;
  padding: 0 4px;
  -webkit-user-select: none;
  user-select: none;
}

.ai-drawer__trigger:hover .ai-drawer__trigger-icon,
.ai-drawer__trigger:focus-visible .ai-drawer__trigger-icon {
  opacity: 0.75;
}

.ai-drawer__trigger:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
  border-radius: 4px;
}

.ai-drawer__trigger-icon {
  width: 28px;
  height: 28px;
  object-fit: contain;
  margin-top: -9px;
  transition: opacity 0.2s ease;
}

/** Nudge mobile trigger icon left to align with other header icons */
.d-lg-none .ai-drawer__trigger-icon {
  margin-left: -16px;
}

.ai-drawer__trigger-label {
  font-size: 14px;
  white-space: nowrap;
  font-family: var(--galls-font-gt-america-standard);
}

/** Red notification dot */
.ai-drawer__trigger-dot {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 8px;
  height: 8px;
  background: #d4183d;
  border-radius: 50%;
  pointer-events: none;
}

/** Hide desktop label on mobile */
@media (max-width: 992px) {
  .ai-drawer__trigger-label {
    display: none;
  }
}

/* Override SlideUpDrawer default body padding/overflow when AI drawer is active */
.slide-up-drawer__body:has(.ai-drawer),
.slide-up-drawer__body:has(.ai-drawer__chat) {
  padding: 0;
  overflow: hidden;
}

/* Hide SlideUpDrawer's own close button - AI drawer has its own per-view close */
.slide-up-drawer__body:has(.ai-drawer) ~ .slide-up-drawer__close,
.slide-up-drawer__body:has(.ai-drawer__chat) ~ .slide-up-drawer__close,
[data-target="slideUpDrawer"]:has(.ai-drawer) > .slide-up-drawer__close,
[data-target="slideUpDrawer"]:has(.ai-drawer__chat) > .slide-up-drawer__close {
  display: none;
}

/* ==========================================================================
   DRAWER LAYOUT  (injected into SlideUpDrawer body)
   ========================================================================== */

.ai-drawer {
  --ai-drawer-primary: var(--brand-primary);
  --ai-drawer-primary-hover: color-mix(in srgb, var(--brand-primary) 85%, black);
  --ai-drawer-text: #23263B;
  --ai-drawer-text-light: #666666;
  --ai-drawer-bg: #ffffff;
  --ai-drawer-bg-secondary: #f9fafb;
  --ai-drawer-border: #e3e3e3;
  --ai-drawer-radius: 12px;
  --ai-drawer-radius-sm: 8px;
  --ai-drawer-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);

  display: flex;
  flex-direction: column;
  height: 100%;
  font-family: var(--galls-font-gt-america-standard);
  color: var(--ai-drawer-text);
  background: var(--ai-drawer-bg);
}

/* ==========================================================================
   DRAWER HEADER
   ========================================================================== */

.ai-drawer__header {
  background: #004b8d;
  color: #ffffff;
  padding: 16px 16px 16px;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

/** Decorative radial gradient */
.ai-drawer__header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at top right, rgba(255, 255, 255, 0.12), transparent 60%);
  pointer-events: none;
}

.ai-drawer__header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  position: relative;
  z-index: 1;
}

.ai-drawer__header-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  margin-top: 8px;
  margin-bottom: 4px;
}

.ai-drawer__header-title-row {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-bottom: 8px;
}

.ai-drawer__header-title {
  font-family: Roboto, sans-serif;
  font-size: 20px;
  font-weight: 700;
  font-style: normal;
  line-height: 28px;
  letter-spacing: -0.449px;
  color: #fff;
}

.ai-drawer__header-subtitle {
  font-size: 14px;
  opacity: 0.85;
  line-height: 1.4;
  text-align: center;
  max-width: 280px;
}

.ai-drawer__close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: 50%;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--ai-drawer-transition);
  z-index: 2;
}

.ai-drawer__close-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.ai-drawer__close-btn:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: 2px;
}

/* ==========================================================================
   SEARCH BAR  (shared between landing + chat views)
   ========================================================================== */

.ai-drawer__search {
  position: relative;
  z-index: 1;
  margin-top: 16px;
}

.ai-drawer__search-input {
  width: 100%;
  padding: 12px 52px 12px 16px;
  border-radius: 12px;
  border: none;
  font-size: 14px;
  font-family: var(--galls-font-gt-america-standard);
  color: var(--ai-drawer-text);
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  outline: none;
  transition: box-shadow 0.2s ease;
}

.ai-drawer__search-input::placeholder {
  color: #999999;
}

.ai-drawer__search-input:focus {
  box-shadow: 0 0 0 1.5px var(--ai-drawer-primary), 0 2px 8px rgba(0, 0, 0, 0.1);
}

.ai-drawer__search-submit {
  position: absolute;
  right: 4px;
  top: 4px;
  bottom: 4px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--ai-drawer-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--ai-drawer-transition);
}

.ai-drawer__search-submit:hover:not(:disabled) {
  color: var(--ai-drawer-primary-hover);
}

.ai-drawer__search-submit:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: 2px;
}

.ai-drawer__search-submit:disabled {
  opacity: 0.5;
  cursor: default;
}

.ai-drawer__return-btn {
  display: block;
  width: 100%;
  padding: 12px 16px;
  margin-top: 14px;
  background: transparent;
  border: 2px solid #fff;
  border-radius: 8px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.10), 0 4px 6px -4px rgba(0, 0, 0, 0.10);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  position: relative;
  z-index: 1;
  transition: background 0.2s ease;
}

.ai-drawer__return-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.ai-drawer__return-btn:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: 2px;
}

/* ==========================================================================
   LANDING VIEW - SCROLLABLE CONTENT
   ========================================================================== */

.ai-drawer__content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  background: var(--ai-drawer-bg-secondary);
}

.ai-drawer__content::-webkit-scrollbar {
  width: 6px;
}

.ai-drawer__content::-webkit-scrollbar-track {
  background: transparent;
}

.ai-drawer__content::-webkit-scrollbar-thumb {
  background: var(--ai-drawer-border);
  border-radius: 3px;
}

/* --- Sections --- */
.ai-drawer__section {
  margin-bottom: 32px;
}

.ai-drawer__section-title {
  font-family: var(--galls-font-gt-america-condensed);
  font-size: 18px;
  font-weight: var(--galls-fw-600, 600);
  line-height: 27px;
  letter-spacing: -0.44px;
  color: var(--ai-drawer-text);
  margin-bottom: 8px;
  display: inline-block;
}

/* --- Suggestion Pills --- */
.ai-drawer__pills {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.ai-drawer__pill {
  background: #ffffff;
  color: #005596;
  border: 1px solid #e5e7eb;
  font-family: var(--galls-font-gt-america-standard);
  font-size: 14px;
  font-weight: var(--galls-fw-700, 700);
  padding: 12px 16px;
  border-radius: 8px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.ai-drawer__pill:hover {
  background: #eef4fc;
  border-color: #005596;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  color: #005596;
}

.ai-drawer__pill:focus-visible {
  outline: 2px solid #005596;
  outline-offset: 2px;
}

/* --- Help & Service Grid --- */
.ai-drawer__help-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.ai-drawer__help-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 23px 8px;
  height: 96px;
  background: var(--ai-drawer-bg);
  border: 1px solid #f0f0f0;
  border-radius: var(--ai-drawer-radius);
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  transition: box-shadow 0.15s ease;
  text-decoration: none;
  font-family: var(--galls-font-gt-america-standard);
}

.ai-drawer__help-btn:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.ai-drawer__help-btn:focus-visible {
  outline: 2px solid var(--ai-drawer-primary);
  outline-offset: 2px;
}

.ai-drawer__help-icon {
  width: 24px;
  height: 24px;
  color: var(--ai-drawer-primary);
}

.ai-drawer__help-label {
  font-size: 12px;
  font-weight: var(--galls-fw-500, 500);
  color: #364153;
  text-align: center;
  line-height: 1.3;
}

/* --- Disclaimer Footer --- */
.ai-drawer__disclaimer {
  font-size: 12px;
  color: #99a1af;
  text-align: center;
  margin-top: auto;
  padding-top: 24px;
  padding-bottom: 8px;
}

/* ==========================================================================
   CHAT VIEW
   ========================================================================== */

.ai-drawer__chat {
  /* Redeclare tokens - .ai-drawer__chat is a sibling root, not a child of .ai-drawer */
  --ai-drawer-primary: var(--brand-primary);
  --ai-drawer-primary-hover: color-mix(in srgb, var(--brand-primary) 85%, black);
  --ai-drawer-text: #23263B;
  --ai-drawer-text-light: #666666;
  --ai-drawer-bg: #ffffff;
  --ai-drawer-bg-secondary: #f9fafb;
  --ai-drawer-border: #e3e3e3;
  --ai-drawer-radius: 12px;
  --ai-drawer-radius-sm: 8px;
  --ai-drawer-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);

  display: flex;
  flex-direction: column;
  height: 100%;
  font-family: var(--galls-font-gt-america-standard);
  color: var(--ai-drawer-text);
  background: var(--ai-drawer-bg);
}

/** Chat header */
.ai-drawer__chat-header {
  background: #005dac;
  color: #ffffff;
  padding: 12px 16px;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

.ai-drawer__chat-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at top right, rgba(255, 255, 255, 0.12), transparent 60%);
  pointer-events: none;
}

.ai-drawer__chat-top-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  position: relative;
  z-index: 1;
}

.ai-drawer__back-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: 50%;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--ai-drawer-transition);
}

.ai-drawer__back-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.ai-drawer__back-btn:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: 2px;
}

.ai-drawer__chat-title {
  font-size: 16px;
  font-weight: var(--galls-fw-600, 600);
  flex: 1;
}

.ai-drawer__chat-close-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--ai-drawer-transition);
}

.ai-drawer__chat-close-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.ai-drawer__chat-close-btn:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: 2px;
}

/* --- Gear Advisor Icon (PNG) --- */
.ai-drawer__icon,
.ai-drawer__chat-sparkle,
.ai-drawer__welcome-msg-icon {
  flex-shrink: 0;
  display: block;
  object-fit: contain;
  margin-top: -14px;
  height: 40px;
  width: auto;
}

/* --- Ellipsis Menu Button & Dropdown --- */
.ai-drawer__menu-wrapper {
  position: relative;
  margin-left: auto;
  flex-shrink: 0;
}

.ai-drawer__menu-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background var(--ai-drawer-transition);
}

.ai-drawer__menu-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.ai-drawer__menu-btn:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: 2px;
}

.ai-drawer__menu-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  min-width: 160px;
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  z-index: 10;
  overflow: hidden;
}

.ai-drawer__menu-dropdown--open {
  display: block;
}

.ai-drawer__menu-item {
  display: block;
  width: 100%;
  padding: 6px 16px;
  border: none;
  background: transparent;
  color: #23263B;
  font-size: 14px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease;
}

.ai-drawer__menu-item:hover {
  background: #f5f5fa;
}

.ai-drawer__menu-item:focus-visible {
  outline: 2px solid var(--ai-drawer-primary, #005596);
  outline-offset: -2px;
}

/* ==========================================================================
   INSTANTSEARCH CHAT WIDGET OVERRIDES
   The chat() widget renders into #aiDrawerChatWidget.
   We hide its built-in header/toggle (we use our own) and style the rest
   to match the drawer's design.
   ========================================================================== */

/** Widget container - fill below our custom header */
.ai-drawer__chat-widget {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--ai-drawer-bg);
}

/**
 * Reset Algolia's default fixed-overlay positioning.
 * The base CSS sets .ais-Chat as position:fixed with width/height constraints
 * since it expects a floating widget. We embed it inside our drawer instead.
 */
.ai-drawer__chat-widget .ais-Chat {
  position: static;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  display: flex;
  flex-direction: column;
  pointer-events: auto;
}

.ai-drawer__chat-widget .ais-Chat-container {
  opacity: 1;
  transform: none;
  border-radius: 0;
  box-shadow: none;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/** Loading / error states while ESM deps load */
.ai-drawer__loading,
.ai-drawer__error {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  font-size: 14px;
  color: #6b7280;
  padding: 24px;
  text-align: center;
}
.ai-drawer__error { color: #dc2626; }

/** Hide the widget's built-in header - we render our own chat header */
.ai-drawer__widget-header,
.ai-drawer__chat-widget .ais-Chat-header {
  display: none !important;
}

/** Hide the widget's floating toggle button (drawer has its own trigger) */
.ai-drawer__widget-toggle-hidden,
.ai-drawer__chat-widget .ais-Chat-toggleButton,
.ai-drawer__chat-widget .ais-Chat-toggleButtonWrapper {
  display: none !important;
}

/** Hide copy/regenerate action buttons - not in our design */
.ai-drawer__chat-widget .ais-ChatMessage-actions {
  display: none !important;
}

/** Hide carousel header on mobile (result count, "View all" button, scroll arrows) */
.ai-drawer__chat-widget .ais-ChatToolSearchIndexCarouselHeader {
  display: none !important;
}

/** Show carousel navigation arrows on desktop only */
@media (min-width: 992px) {
  .ai-drawer__chat-widget .ais-ChatToolSearchIndexCarouselHeader {
    display: flex !important;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
    padding: 0 0 6px;
  }

  /** Hide non-button children (result count, "View all" link) */
  .ai-drawer__chat-widget .ais-ChatToolSearchIndexCarouselHeader > :not(button) {
    display: none !important;
  }

  .ai-drawer__chat-widget .ais-ChatToolSearchIndexCarouselHeader button {
    width: 28px;
    height: 28px;
    border: 1px solid var(--ai-drawer-border, #e3e3e3);
    border-radius: 50%;
    background: #ffffff;
    color: var(--ai-drawer-text, #23263B);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s ease, border-color 0.15s ease;
  }

  .ai-drawer__chat-widget .ais-ChatToolSearchIndexCarouselHeader button:hover {
    background: #f5f5fa;
    border-color: var(--ai-drawer-primary, #005596);
  }

  .ai-drawer__chat-widget .ais-ChatToolSearchIndexCarouselHeader button:disabled {
    opacity: 0.3;
    cursor: default;
  }
}

/** Scroll-to-bottom FAB - small branded pill at bottom of messages */
.ai-drawer__chat-widget .ais-ChatMessages-scrollToBottom {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--ai-drawer-border, #e3e3e3);
  background: #ffffff;
  color: var(--ai-drawer-text, #23263B);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  padding: 0;
  transition: opacity 0.2s ease, box-shadow 0.15s ease;
}

.ai-drawer__chat-widget .ais-ChatMessages-scrollToBottom svg {
  width: 16px;
  height: 16px;
  stroke-width: 2;
}

.ai-drawer__chat-widget .ais-ChatMessages-scrollToBottom:hover {
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.ai-drawer__chat-widget .ais-ChatMessages-scrollToBottom--hidden {
  opacity: 0;
  pointer-events: none;
}

/** Carousel card spacing - override Algolia's grid-auto-columns for chat context */
.ai-drawer__chat-widget .ais-Carousel-list {
  scrollbar-color: var(--ai-drawer-border, #e3e3e3) transparent;
  padding-bottom: 14px;
  will-change: transform;
}

/** Control card width — force grid-auto-columns so desktop and mobile show ~2 cards */
.ai-drawer__chat-widget .ais-ChatMessage-message .ais-Carousel-list {
  --ais-chat-carousel-item-width: 42%;
  grid-auto-columns: 42% !important;
  gap: 8px !important;
}

.ai-drawer__chat-widget .ais-Carousel-list::-webkit-scrollbar-track {
  background-color: transparent;
}

.ai-drawer__chat-widget .ais-Carousel-list::-webkit-scrollbar-thumb {
  background-color: var(--ai-drawer-border, #e3e3e3);
  border-radius: 3px;
}

/** Messages panel - scrollable area */
.ai-drawer__widget-messages,
.ai-drawer__chat-widget .ais-ChatMessages {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.ai-drawer__chat-widget .ais-ChatMessages-scroll {
  overflow-y: auto;
  padding: 12px;
  height: 100%;
  overscroll-behavior-y: contain;
}

/** Vertical spacing between messages (articles) and inner content */
.ai-drawer__chat-widget .ais-ChatMessages-content {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.ai-drawer__chat-widget .ais-ChatMessage-message {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-wrap: break-word;
  word-break: break-word;
  min-width: 0;
  line-height: 1.5;
}

.ai-drawer__chat-widget .ais-ChatMessages-scroll::-webkit-scrollbar {
  width: 6px;
}

.ai-drawer__chat-widget .ais-ChatMessages-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.ai-drawer__chat-widget .ais-ChatMessages-scroll::-webkit-scrollbar-thumb {
  background: var(--ai-drawer-border);
  border-radius: 3px;
}

/** Prompt / input area at bottom - per Figma: white pill with border, send inside */
.ai-drawer__widget-prompt,
.ai-drawer__chat-widget .ais-ChatPrompt {
  flex-shrink: 0;
  padding: 0 12px 12px 12px;
  background: var(--ai-drawer-bg, #ffffff);
  border-top: none;
}

/** Prompt body - flex row so textarea + submit sit side by side inside the pill */
.ai-drawer__chat-widget .ais-ChatPrompt-body {
  display: flex;
  flex-direction: row !important;
  align-items: center;
  gap: 12px;
  background: #ffffff;
  border: 1px solid var(--ai-drawer-border, #e3e3e3);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  height: auto !important;
  max-height: none !important;
}

.ai-drawer__chat-widget .ais-ChatPrompt-textarea {
  flex: 1;
  min-width: 0;
  padding: 0;
  border-radius: 0;
  border: none;
  font-size: 16px;
  font-family: var(--galls-font-gt-america-standard);
  color: var(--ai-drawer-text);
  background: transparent;
  box-shadow: none;
  outline: none;
  resize: none;
  line-height: 20px;
  min-height: 20px !important;
  max-height: 60px; /* ~3 lines at 20px line-height */
  height: auto !important;
  overflow-y: auto;
  field-sizing: content;
}

.ai-drawer__chat-widget .ais-ChatPrompt-textarea:focus {
  box-shadow: none;
}

/** Textarea scrollbar - match messages scrollbar style */
.ai-drawer__chat-widget .ais-ChatPrompt-textarea::-webkit-scrollbar {
  width: 6px;
}

.ai-drawer__chat-widget .ais-ChatPrompt-textarea::-webkit-scrollbar-track {
  background: transparent;
}

.ai-drawer__chat-widget .ais-ChatPrompt-textarea::-webkit-scrollbar-thumb {
  background: var(--ai-drawer-border);
  border-radius: 3px;
}

.ai-drawer__chat-widget .ais-ChatPrompt-textarea {
  scrollbar-width: thin;
  scrollbar-color: var(--ai-drawer-border, #e3e3e3) transparent;
}

/** Submit button - icon only, no circle / shadow */
.ai-drawer__chat-widget .ais-ChatPrompt-actions {
  flex-shrink: 0;
  align-self: flex-end;
}

.ai-drawer__chat-widget .ais-ChatPrompt-submit,
.ai-drawer__chat-widget .ais-Chat-prompt button[type="submit"] {
  background: transparent !important;
  color: var(--ai-drawer-primary, #005596);
  border: none !important;
  border-radius: 8px;
  width: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s ease;
  padding: 0;
  box-shadow: none !important;
  position: relative;
}

/** Hide the native SVG icon - we replace it with a paper-plane pseudo-element */
.ai-drawer__chat-widget .ais-ChatPrompt-submit svg {
  display: none;
}

/** Paper-plane icon (matches landing-page send button) via CSS mask */
.ai-drawer__chat-widget .ais-ChatPrompt-submit::after {
  content: '';
  display: block;
  width: 16px;
  height: 16px;
  background-color: currentColor;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='22' y1='2' x2='11' y2='13'/%3E%3Cpolygon points='22 2 15 22 11 13 2 9 22 2'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='22' y1='2' x2='11' y2='13'/%3E%3Cpolygon points='22 2 15 22 11 13 2 9 22 2'/%3E%3C/svg%3E");
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
}

/** Active streaming state - show the native stop-square SVG, hide pseudo-element */
.ai-drawer__chat-widget .ais-ChatPrompt-submit:not([data-status="ready"]):not(:disabled) svg {
  display: block;
  width: 14px;
  height: 14px;
}
.ai-drawer__chat-widget .ais-ChatPrompt-submit:not([data-status="ready"]):not(:disabled)::after {
  display: none;
}

.ai-drawer__chat-widget .ais-ChatPrompt-submit:hover {
  opacity: 0.7;
}

.ai-drawer__chat-widget .ais-ChatPrompt-submit:disabled {
  opacity: 0.3;
  cursor: default;
}

/** Disclaimer footer below prompt - per Figma */
.ai-drawer__chat-widget .ais-ChatPrompt-footer {
  padding-top: 12px;
}

.ai-drawer__chat-widget .ais-ChatPrompt-disclaimer {
  font-size: 11px;
  line-height: 16px;
  color: #99a1af;
  text-align: center;
}

/** User message bubbles - small grey rounded pill per Figma */
.ai-drawer__chat-widget .ais-ChatMessage[data-role="user"] .ais-ChatMessage-container {
  max-width: 85%;
  margin-inline-start: auto;
  width: fit-content;
  min-width: 0;
  overflow: hidden;
}

.ai-drawer__chat-widget .ais-ChatMessage[data-role="user"] .ais-ChatMessage-message {
  background: #f5f5fa;
  color: #23263b;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 16px;
  line-height: 1.5;
  overflow-wrap: break-word;
  word-break: break-word;
}

/** Assistant message content */
.ai-drawer__chat-widget .ais-Chat-message--assistant,
.ai-drawer__chat-widget .ais-ChatMessage--assistant {
  align-self: flex-start;
  max-width: 92%;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ai-drawer-text);
}

.ai-drawer__chat-widget .ais-Chat-message--assistant a,
.ai-drawer__chat-widget .ais-ChatMessage--assistant a {
  color: var(--ai-drawer-primary);
  text-decoration: underline;
}

.ai-drawer__chat-widget .ais-Chat-message--assistant strong,
.ai-drawer__chat-widget .ais-ChatMessage--assistant strong {
  font-weight: var(--galls-fw-600, 600);
}

/** Constrain inline images in chat responses (not carousel product images) */
.ai-drawer__chat-widget .ais-ChatMessage-message img {
  max-height: 200px;
  border-radius: 8px;
}

/** Undo height limit for carousel product images */
.ai-drawer__chat-widget .ais-Carousel-hit-image img,
.ai-drawer__chat-widget .ai-drawer__product-img {
  max-height: none;
  border-radius: 0;
}

/** Font family for the whole widget */
.ai-drawer__chat-widget .ais-Chat,
.ai-drawer__is-chat {
  font-family: var(--galls-font-gt-america-standard);
}

/** Loading / skeleton - spinner circle + shimmer bars while assistant responds */
.ai-drawer__chat-widget .ais-ChatMessageLoader .ais-ChatMessage-leading {
  display: none !important;
}

.ai-drawer__chat-widget .ais-ChatMessageLoader .ais-ChatMessageLoader-spinner {
  width: 24px;
  height: 24px;
  color: var(--ai-drawer-primary, #005596);
  flex-shrink: 0;
}

.ai-drawer__chat-widget .ais-ChatMessageLoader .ais-ChatMessageLoader-spinner svg {
  width: 100%;
  height: 100%;
  animation: ai-drawer-spin 0.8s linear infinite;
}

.ai-drawer__chat-widget .ais-ChatMessageLoader .ais-ChatMessageLoader-spinner circle {
  stroke-dasharray: 45;
  stroke-dashoffset: 12;
  stroke-width: 3;
}

.ai-drawer__chat-widget .ais-ChatMessageLoader .ais-ChatMessageLoader-text {
  font-family: var(--galls-font-gt-america-standard);
}

.ai-drawer__chat-widget .ais-ChatMessageLoader .ais-ChatMessageLoader-skeletonWrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 70%;
}

.ai-drawer__chat-widget .ais-ChatMessageLoader .ais-ChatMessageLoader-skeletonItem {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, rgba(0,85,150,0.08) 25%, rgba(0,85,150,0.18) 50%, rgba(0,85,150,0.08) 75%);
  background-size: 200% 100%;
  animation: ai-drawer-skeleton-shimmer 1.5s ease-in-out infinite;
}

.ai-drawer__chat-widget .ais-ChatMessageLoader .ais-ChatMessageLoader-skeletonItem:last-child {
  width: 60%;
}

@keyframes ai-drawer-spin {
  to { transform: rotate(360deg); }
}

@keyframes ai-drawer-skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/** Welcome message - shown after refresh / new conversation */
.ai-drawer__welcome-msg {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 24px 16px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ai-drawer-text, #23263B);
}

/* ==========================================================================
   PRODUCT CAROUSEL (in chat messages)
   ========================================================================== */

.ai-drawer__product-carousel {
  width: 100%;
  max-width: 100%;
  margin-top: 8px;
  overflow: hidden;
}

/* Horizontal scroll card container */
.ai-drawer__product-cards {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  gap: 10px;
  padding: 4px 2px 8px;
  scrollbar-width: none; /* Firefox */
}
.ai-drawer__product-cards::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

/* --- Individual product card (vertical layout inside carousel) --- */
.ai-drawer__product-card {
  flex: 0 0 55%;
  max-width: 180px;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  background: var(--ai-drawer-bg);
  border: 1px solid var(--ai-drawer-border);
  border-radius: var(--ai-drawer-radius-sm);
  text-decoration: none;
  color: var(--ai-drawer-text);
  transition: box-shadow 0.15s ease;
  cursor: pointer;
  scroll-snap-align: start;
  overflow: hidden;
  contain: layout style paint;
  height: 100%;
}

.ai-drawer__product-card:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.ai-drawer__product-img {
  width: 100%;
  aspect-ratio: 1;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  background-color: var(--ai-drawer-bg-secondary);
  flex-shrink: 0;
}

.ai-drawer__product-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 10px 10px;
  min-width: 0;
  flex: 1;
}

.ai-drawer__product-brand {
  font-size: 11px;
  color: var(--ai-drawer-text-light);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  line-height: 1.2;
}

.ai-drawer__product-title {
  font-size: 13px;
  font-weight: 400;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.ai-drawer__product-price {
  font-size: 14px;
  font-weight: var(--galls-fw-700, 700);
  color: var(--ai-drawer-text);
  margin-top: auto;
}

.ai-drawer__product-rating {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 2px;
}

.ai-drawer__product-review-count {
  font-size: 11px;
  color: var(--ai-drawer-text-light);
  margin-left: 2px;
}

/* --- Suggestion Chips (rendered by InstantSearch templates.suggestions) --- */
.ai-drawer__suggestion-chips {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-self: flex-start;
  max-width: 85%;
  width: fit-content;
  margin-top: 12px;
}

.ai-drawer__suggestion-chip {
  background: #f5f5fa;
  color: #23263b;
  border: none;
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 14px;
  font-family: var(--galls-font-gt-america-standard);
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease;
  word-break: break-word;
}

.ai-drawer__suggestion-chip:hover {
  background: #ebebf0;
}

.ai-drawer__suggestion-chip:focus-visible {
  outline: 2px solid var(--ai-drawer-primary);
  outline-offset: 2px;
}

/* ==========================================================================
   iOS SAFE AREAS
   ========================================================================== */

/** Prevent iOS zoom on input/textarea focus - font-size must be 16px */
@media (max-width: 991px) {
  .ai-drawer__search-input {
    font-size: 16px;
  }
  .ai-drawer__chat-widget .ais-ChatPrompt-textarea {
    font-size: 16px;
  }

  /**
   * iOS keyboard body scroll lock  scoped to AI drawer only.
   * SlideUpDrawer adds .slide-up-drawer-no-scroll to html+body with overflow:hidden,
   * but iOS Safari still allows background scroll unless body is position:fixed.
   * Only apply when AI drawer is active to avoid breaking other drawers (stock messages, etc).
   */
  /**
   * Desktop only  lock background scroll when AI drawer is open.
   * Mobile skips this: the drawer is 100dvh so background isn't visible,
   * and removing position:fixed lets the mobile browser chrome collapse on scroll.
   */
  @media (min-width: 992px) {
    html.slide-up-drawer-no-scroll:has(.ai-drawer),
    html.slide-up-drawer-no-scroll:has(.ai-drawer__chat) {
      position: fixed;
      width: 100%;
      height: 100%;
      overscroll-behavior: none;
    }
    body.slide-up-drawer-no-scroll:has(.ai-drawer),
    body.slide-up-drawer-no-scroll:has(.ai-drawer__chat) {
      position: fixed;
      width: 100%;
      height: 100%;
      overscroll-behavior: none;
    }
  }

  /** Bottom safe area - white background behind home indicator / URL bar */
  html:has(.slide-up-drawer--open .ai-drawer),
  html:has(.slide-up-drawer--open .ai-drawer__chat),
  html:has(.slide-up-drawer--open .ai-drawer) body,
  html:has(.slide-up-drawer--open .ai-drawer__chat) body {
    background-color: #ffffff;
  }

  .slide-up-drawer[data-position="bottom"]:has(.ai-drawer),
  .slide-up-drawer[data-position="bottom"]:has(.ai-drawer__chat) {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

@supports (padding: env(safe-area-inset-top)) {
  @media (max-width: 991px) {
    .ai-drawer__header {
      padding-top: calc(24px + env(safe-area-inset-top, 0px));
    }
    .ai-drawer__chat-header {
      padding-top: calc(12px + env(safe-area-inset-top, 0px));
    }
    .ai-drawer__content {
      padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    }
    .ai-drawer__widget-prompt,
    .ai-drawer__chat-widget .ais-ChatPrompt {
      padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }
  }
}

/* ==========================================================================
   MAGICAL EFFECTS
   ========================================================================== */

@keyframes ai-drawer-input-glow {
  0%   { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); }
  40%  { box-shadow: 0 0 0 3px rgba(0, 93, 172, 0.3), 0 2px 20px rgba(0, 93, 172, 0.2); }
  100% { box-shadow: 0 0 0 2px var(--ai-drawer-primary), 0 2px 12px rgba(0, 93, 172, 0.15); }
}

.ai-drawer__search-input--glow {
  animation: ai-drawer-input-glow 0.5s ease-out forwards;
}

/** Shield icon flash  soft brief white flash on drawer open, triggered by JS */
@keyframes ai-drawer-icon-flash {
  0%   { filter: brightness(1); }
  25%  { filter: brightness(1.6); }
  100% { filter: brightness(1); }
}

.ai-drawer__icon--flash,
.ai-drawer__chat-sparkle--flash {
  animation: ai-drawer-icon-flash 1.2s ease-out 0.7s forwards;
}


/* ==========================================================================
   REDUCED MOTION
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .ai-drawer__search-input--glow {
    animation: none;
    box-shadow: 0 0 0 2px var(--ai-drawer-primary), 0 2px 12px rgba(0, 93, 172, 0.15);
  }

  .ai-drawer__icon,
  .ai-drawer__chat-sparkle {
    animation: none;
  }

  .ai-drawer__pill,
  .ai-drawer__help-btn,
  .ai-drawer__close-btn,
  .ai-drawer__back-btn,
  .ai-drawer__chat-close-btn,
  .ai-drawer__menu-btn,
  .ai-drawer__search-submit,
  .ai-drawer__suggestion-chip {
    transition: none;
  }
}

/* ==========================================================================
   PRINT
   ========================================================================== */

@media print {
  .ai-drawer__trigger,
  .ai-drawer {
    display: none !important;
  }
}
