/**
 * 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: 20px;
  height: 20px;
  transition: opacity 0.2s ease;
}

.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 when AI drawer is active */
.slide-up-drawer__body:has(.ai-drawer),
.slide-up-drawer__body:has(.ai-drawer__chat) {
  padding: 0;
}

/* ==========================================================================
   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: #1a1a1a;
  --ai-drawer-text-light: #666666;
  --ai-drawer-bg: #ffffff;
  --ai-drawer-bg-secondary: #f5f5f5;
  --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: var(--ai-drawer-primary);
  color: #ffffff;
  padding: 24px 20px 20px;
  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: 8px;
  margin-bottom: 6px;
}

.ai-drawer__header-title {
  font-size: 20px;
  font-weight: var(--galls-fw-700, 700);
  line-height: 1.3;
}

.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: rgba(255, 255, 255, 0.1);
  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: 24px;
  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 2px 12px rgba(0, 0, 0, 0.18);
}

.ai-drawer__search-submit {
  position: absolute;
  right: 4px;
  top: 4px;
  bottom: 4px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--ai-drawer-primary);
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--ai-drawer-transition);
}

.ai-drawer__search-submit:hover:not(:disabled) {
  background: 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;
}

/* ==========================================================================
   LANDING VIEW — SCROLLABLE CONTENT
   ========================================================================== */

.ai-drawer__content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  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: 28px;
}

.ai-drawer__section-title {
  font-size: 15px;
  font-weight: var(--galls-fw-600, 600);
  color: var(--ai-drawer-text);
  margin-bottom: 12px;
}

/* --- Suggestion Pills --- */
.ai-drawer__pills {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.ai-drawer__pill {
  background: var(--ai-drawer-bg);
  color: var(--ai-drawer-primary);
  border: 1px solid var(--ai-drawer-border);
  font-family: var(--galls-font-gt-america-standard);
  font-size: 14px;
  font-weight: var(--galls-fw-700, 700);
  padding: 12px 16px;
  border-radius: var(--ai-drawer-radius-sm);
  cursor: pointer;
  text-align: center;
  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: var(--ai-drawer-primary);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.ai-drawer__pill:focus-visible {
  outline: 2px solid var(--ai-drawer-primary);
  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: 16px 8px;
  height: 96px;
  background: var(--ai-drawer-bg);
  border: 1px solid #f0f0f0;
  border-radius: var(--ai-drawer-radius-sm);
  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: var(--ai-drawer-text-light);
  text-align: center;
  line-height: 1.3;
}

/* --- Disclaimer Footer --- */
.ai-drawer__disclaimer {
  font-size: 11px;
  color: #aaaaaa;
  text-align: center;
  margin-top: auto;
  padding-top: 24px;
  padding-bottom: 8px;
}

/* ==========================================================================
   CHAT VIEW
   ========================================================================== */

.ai-drawer__chat {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/** Chat header bar with back button + search */
.ai-drawer__chat-header {
  background: var(--ai-drawer-primary);
  color: #ffffff;
  padding: 12px 16px 16px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.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: 8px;
  margin-bottom: 12px;
  position: relative;
  z-index: 1;
}

.ai-drawer__back-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  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;
  background: rgba(255, 255, 255, 0.1);
  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__chat-close-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.ai-drawer__chat-close-btn:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: 2px;
}

/* --- Messages Container --- */
.ai-drawer__messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  background: var(--ai-drawer-bg-secondary);
}

.ai-drawer__messages::-webkit-scrollbar {
  width: 6px;
}

.ai-drawer__messages::-webkit-scrollbar-track {
  background: transparent;
}

.ai-drawer__messages::-webkit-scrollbar-thumb {
  background: var(--ai-drawer-border);
  border-radius: 3px;
}

/* --- Message Bubbles --- */
.ai-drawer__message {
  display: flex;
  max-width: 85%;
}

.ai-drawer__message--user {
  align-self: flex-end;
}

.ai-drawer__message--assistant {
  align-self: flex-start;
}

.ai-drawer__message--error {
  align-self: center;
}

.ai-drawer__message-content {
  padding: 12px 16px;
  border-radius: var(--ai-drawer-radius-sm);
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  overflow-wrap: break-word;
}

.ai-drawer__message--user .ai-drawer__message-content {
  background: var(--ai-drawer-primary);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.ai-drawer__message--assistant .ai-drawer__message-content {
  background: var(--ai-drawer-bg);
  color: var(--ai-drawer-text);
  border-bottom-left-radius: 4px;
}

.ai-drawer__message--error .ai-drawer__message-content {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  font-size: 13px;
  text-align: center;
}

/* Message content formatting */
.ai-drawer__message-content p {
  margin: 0 0 8px 0;
}

.ai-drawer__message-content p:last-child {
  margin-bottom: 0;
}

.ai-drawer__message-content a {
  text-decoration: underline;
  word-break: break-all;
}

.ai-drawer__message--assistant .ai-drawer__message-content a {
  color: var(--ai-drawer-primary);
}

.ai-drawer__message-content strong {
  font-weight: var(--galls-fw-600, 600);
}

.ai-drawer__message-content ul,
.ai-drawer__message-content ol {
  margin: 4px 0;
  padding-left: 20px;
}

.ai-drawer__message-content li {
  margin-bottom: 4px;
}

/* --- Typing Indicator --- */
.ai-drawer__typing {
  display: flex;
  gap: 4px;
  padding: 4px 0;
  align-items: center;
}

.ai-drawer__typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ai-drawer-text-light);
  animation: ai-drawer-typing 1.4s infinite ease-in-out;
}

.ai-drawer__typing span:nth-child(1) { animation-delay: 0s; }
.ai-drawer__typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-drawer__typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes ai-drawer-typing {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* --- Product Cards in Chat --- */
.ai-drawer__product-card {
  display: flex;
  gap: 12px;
  padding: 12px;
  background: var(--ai-drawer-bg);
  border: 1px solid var(--ai-drawer-border);
  border-radius: var(--ai-drawer-radius-sm);
  margin-top: 8px;
  text-decoration: none;
  color: var(--ai-drawer-text);
  transition: box-shadow 0.15s ease;
  cursor: pointer;
}

.ai-drawer__product-card:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.ai-drawer__product-img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  border-radius: 4px;
  flex-shrink: 0;
  background: var(--ai-drawer-bg-secondary);
}

.ai-drawer__product-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.ai-drawer__product-title {
  font-size: 13px;
  font-weight: var(--galls-fw-600, 600);
  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);
}

.ai-drawer__product-rating {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ==========================================================================
   REDUCED MOTION
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .ai-drawer__typing span {
    animation: none;
    opacity: 0.6;
  }

  .ai-drawer__pill,
  .ai-drawer__help-btn,
  .ai-drawer__close-btn,
  .ai-drawer__back-btn,
  .ai-drawer__search-submit {
    transition: none;
  }
}

/* ==========================================================================
   PRINT
   ========================================================================== */

@media print {
  .ai-drawer__trigger,
  .ai-drawer {
    display: none !important;
  }
}
