/* Customer-facing AI shopping assistant widget. Positioned as a second
   FAB stacked directly above the existing WhatsApp button (same right
   offset, same z-layer family) rather than a competing corner, so the
   two floating actions read as one related group instead of two
   separate systems fighting for attention. */

.ai-chat-fab {
  position: fixed;
  bottom: 96px;
  right: 26px;
  z-index: 300;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--color-gold-accent);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-charcoal-primary);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
}
.ai-chat-fab:hover { transform: scale(1.08); background: var(--color-gold-hover); }
.ai-chat-fab[aria-expanded="true"] { display: none; }

/* Real bug found and fixed (2026-08-22) -- see the matching comment on
   .whatsapp-fab (static/css/base.css): shrinking both FABs on mobile
   reduces how much real interactive content (e.g. a Shop-grid product
   card's wishlist button) they can sit on top of. 44px keeps this at
   the accessible touch-target minimum, not below it. Right offset
   recentered (18px vs .whatsapp-fab's 16px) so the two circles'
   centers still line up now that they're different mobile sizes
   (48px vs 44px). */
@media (max-width: 639px) {
  .ai-chat-fab { width: 44px; height: 44px; bottom: 72px; right: 18px; }
}

/* Same real fix and same offset as .whatsapp-fab's matching rule
   (static/css/base.css) -- kept stacked directly above it (this
   file's own "read as one grouped stack" choice, see top of file)
   rather than letting the two FABs drift apart once shifted. */
@media (max-width: 639px) {
  body.has-sticky-action-bar .ai-chat-fab { bottom: 148px; }
}

/* Real mobile bottom sheet (default/mobile-first) -- previously a small
   floating card anchored bottom-right (or, under 480px, bottom-center
   with side margins), which read as a notification toast, not a real
   tool with chat history and a whole gift-finder form inside it. Full
   width, anchored to the actual bottom edge, rounded top corners only,
   a real drag-handle affordance, slides up via transform (matching the
   same real pattern already used for the nav drawer and shop filter
   sheet on this site) instead of the old opacity/scale fade. */
.ai-chat-panel {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 301;
  width: auto;
  max-height: min(82vh, 640px);
  display: flex;
  flex-direction: column;
  background: var(--color-charcoal-surface);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow-dropdown);
  transform: translateY(100%);
  transition: transform 260ms cubic-bezier(0.22, 1, 0.36, 1);
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom);
}
.ai-chat-panel.is-open { transform: translateY(0); }
.ai-chat-panel::before {
  content: "";
  position: absolute;
  top: 10px; left: 50%;
  transform: translateX(-50%);
  width: 36px; height: 4px; border-radius: 2px;
  background: rgba(255, 255, 255, .15);
}
/* Real overlay, mobile and desktop both -- a genuine bottom sheet/side
   drawer needs a real backdrop, not just the panel floating over the
   page with nothing dimming it. Same real focus-trap/Escape/
   overlay-click/scroll-lock pattern as the nav drawer and shop filter
   sheet (see ai-chat.js). */
.ai-chat-overlay {
  display: block;
  position: fixed; inset: 0; z-index: 300;
  background: rgba(10, 9, 8, 0);
  transition: background 260ms ease;
}
.ai-chat-overlay.is-open { background: rgba(10, 9, 8, .5); }

/* Desktop: right-side drawer instead of the bottom sheet -- full
   viewport height, slides in from the right edge. */
@media (min-width: 980px) {
  .ai-chat-panel {
    position: fixed; inset: 0 0 0 auto; z-index: 301;
    width: min(420px, 100vw);
    max-height: none;
    border-radius: 0;
    border: none;
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: -24px 0 48px rgba(0, 0, 0, .35);
    padding-bottom: 0;
  }
  .ai-chat-panel::before { display: none; }
  .ai-chat-panel { transform: translateX(100%); }
  .ai-chat-panel.is-open { transform: translateX(0); }
}

.ai-chat-panel__header {
  display: flex; align-items: center; justify-content: space-between;
  /* Extra top padding on mobile clears the drag-handle bar
     (.ai-chat-panel::before, absolutely positioned at top:10px) -- reset
     to the original 16px on desktop, where the bottom-sheet-only handle
     is hidden. */
  padding: 24px 18px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}
@media (min-width: 980px) {
  .ai-chat-panel__header { padding-top: 16px; }
}
.ai-chat-panel__title {
  display: flex; align-items: center; gap: 8px;
  color: var(--color-beige-light);
  font-family: var(--font-serif);
  font-size: 15px;
}
.ai-chat-panel__title svg { color: var(--color-gold-accent); }
.ai-chat-panel__close {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  background: none; border: none; color: var(--color-text-grey);
  cursor: pointer; border-radius: 50%;
}
.ai-chat-panel__close:hover { background: rgba(255, 255, 255, 0.06); color: var(--color-beige-light); }

.ai-chat-tabs {
  display: flex; flex-shrink: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.ai-chat-tab {
  flex: 1;
  background: none; border: none;
  padding: 12px 8px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.05em;
  color: var(--color-text-grey-dim);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.ai-chat-tab.is-active { color: var(--color-gold-accent); border-bottom-color: var(--color-gold-accent); }

.ai-chat-quicklink {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px;
  font-size: 12.5px; font-weight: 600;
  color: var(--color-text-grey);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}
.ai-chat-quicklink:hover { color: var(--color-gold-accent); }
.ai-chat-quicklink svg:first-child { color: var(--color-gold-accent); flex-shrink: 0; }
.ai-chat-quicklink span { flex: 1; }
.ai-chat-quicklink svg:last-child { flex-shrink: 0; opacity: 0.6; }

.ai-chat-tabpanel { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.ai-chat-tabpanel[hidden] { display: none; }

/* Real gap found in the mobile motion audit (2026-08-21), Phase 13: tab
   switching just toggled `hidden` instantly -- "do not instantly replace
   the entire UI abruptly". One-shot directional keyframes, driven by
   static/js/ai-chat.js's real animationend-sequenced swap (the outgoing
   panel finishes leaving, THEN gets hidden and the incoming one starts
   entering -- not two things happening at once). Kept fast/subtle
   (--motion-fast) since this is a UI state swap, not an editorial
   reveal. Reduced-motion still works correctly here without a separate
   override: tokens.css's global animation-duration:0.001ms just makes
   these near-instant, and the JS logic is driven by the real
   animationend event either way, not a fixed timer. */
@keyframes ai-tab-out-left { from { opacity: 1; transform: translateX(0); } to { opacity: 0; transform: translateX(-10px); } }
@keyframes ai-tab-out-right { from { opacity: 1; transform: translateX(0); } to { opacity: 0; transform: translateX(10px); } }
@keyframes ai-tab-in-from-right { from { opacity: 0; transform: translateX(10px); } to { opacity: 1; transform: translateX(0); } }
@keyframes ai-tab-in-from-left { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: translateX(0); } }
.ai-tab-out-left { animation: ai-tab-out-left var(--motion-fast) var(--ease-premium) forwards; }
.ai-tab-out-right { animation: ai-tab-out-right var(--motion-fast) var(--ease-premium) forwards; }
.ai-tab-in-from-right { animation: ai-tab-in-from-right var(--motion-fast) var(--ease-premium) forwards; }
.ai-tab-in-from-left { animation: ai-tab-in-from-left var(--motion-fast) var(--ease-premium) forwards; }

.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex; flex-direction: column; gap: 10px;
  min-height: 220px;
}
.ai-chat-msg {
  font-size: 13.5px; line-height: 1.55;
  padding: 10px 13px;
  border-radius: 12px;
  max-width: 88%;
}
.ai-chat-msg--bot {
  background: var(--color-charcoal-surface-2);
  color: var(--color-text-grey);
  align-self: flex-start;
  border-bottom-left-radius: 3px;
}
.ai-chat-msg--user {
  background: var(--color-gold-accent);
  color: var(--color-charcoal-primary);
  align-self: flex-end;
  border-bottom-right-radius: 3px;
}
.ai-chat-msg--error {
  background: rgba(220, 90, 70, 0.12);
  color: #e2a596;
  align-self: stretch;
  max-width: 100%;
  text-align: center;
  font-size: 12.5px;
}
/* Real typing indicator (mobile motion overhaul, 2026-08-21), Phase 33 --
   replaces the old plain "Thinking..." text with the standard 3-dot
   pulse (WhatsApp/iMessage/etc. pattern). Removed the instant the real
   response lands (static/js/ai-chat.js), never a fixed/artificial delay. */
.ai-chat-msg--typing { display: flex; align-items: center; gap: 4px; padding: 14px 16px; }
.ai-chat-typing-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--color-text-grey-dim);
  animation: ai-chat-typing-pulse 1.1s ease-in-out infinite;
}
.ai-chat-typing-dot:nth-child(2) { animation-delay: .15s; }
.ai-chat-typing-dot:nth-child(3) { animation-delay: .3s; }
@keyframes ai-chat-typing-pulse {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}

.ai-chat-input-row {
  display: flex; gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}
.ai-chat-input {
  flex: 1;
  background: var(--color-charcoal-surface-2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-input);
  padding: 10px 14px;
  font-size: 13.5px;
  color: var(--color-beige-light);
  outline: none;
}
.ai-chat-input:focus { border-color: var(--color-gold-accent); }
.ai-chat-send {
  width: 40px; height: 40px; flex-shrink: 0;
  border-radius: 50%;
  background: var(--color-gold-accent);
  border: none; color: var(--color-charcoal-primary);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.ai-chat-send:disabled { opacity: 0.5; cursor: default; }

.ai-gift-form {
  padding: 16px 18px;
  display: flex; flex-direction: column; gap: 12px;
  overflow-y: auto;
}
.ai-gift-field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--color-text-grey); }
.ai-gift-field select, .ai-gift-field input {
  background: var(--color-charcoal-surface-2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-input);
  padding: 9px 12px;
  font-size: 13.5px;
  color: var(--color-beige-light);
  outline: none;
}
.ai-gift-field select:focus, .ai-gift-field input:focus { border-color: var(--color-gold-accent); }
.ai-gift-submit { width: 100%; margin-top: 4px; }

.ai-gift-results {
  padding: 0 18px 18px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px;
}
.ai-gift-result-card {
  display: flex; gap: 12px;
  padding: 10px;
  background: var(--color-charcoal-surface-2);
  border-radius: 10px;
  text-decoration: none;
}
.ai-gift-result-card img {
  width: 56px; height: 56px; border-radius: 8px; object-fit: cover; flex-shrink: 0;
  background: var(--color-charcoal-primary);
}
.ai-gift-result-card__name { color: var(--color-beige-light); font-size: 13px; font-weight: 600; }
.ai-gift-result-card__price { color: var(--color-gold-accent); font-size: 12px; margin-top: 2px; }
.ai-gift-result-card__reason { color: var(--color-text-grey-dim); font-size: 11.5px; margin-top: 4px; line-height: 1.4; }

@media (prefers-reduced-motion: reduce) {
  .ai-chat-panel { transition: none; }
  .ai-chat-fab { transition: none; }
}

/* Shown instead of the FAB+panel when ai_widget_available is false
   (apps/ai/context_processors.py) -- a small, honest, non-interactive
   pill rather than a chat interface customers could submit to with no
   real provider behind it. */
.ai-chat-coming-soon {
  position: fixed;
  bottom: 96px;
  right: 26px;
  z-index: 300;
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--color-charcoal-surface);
  border: 1px solid rgba(201, 162, 39, .3);
  color: var(--color-text-grey-dim);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  padding: 9px 14px 9px 10px;
  border-radius: 20px;
  box-shadow: 0 8px 20px rgba(0,0,0,.35);
  pointer-events: none;
}
.ai-chat-coming-soon svg { color: var(--color-gold-accent); flex-shrink: 0; }
@media (max-width: 479px) {
  .ai-chat-coming-soon { right: 16px; font-size: 9px; padding: 8px 12px 8px 9px; }
}
