/* BD Mushroom — Mushy chat widget (KAN-127, Slice 1)
 * Faithful port of the Claude Design "New Chat widget" (ui_kits/website/MushyChat.jsx,
 * project 7445b332). Self-contained: concrete token values baked in so the widget
 * does not depend on the theme's Tailwind config. All selectors are scoped under
 * #bdm-chat-widget. Behaviour lives in chat.js; this file is presentation only.
 */

#bdm-chat-widget {
  /* Tokens resolved from the design system (tokens/colors|effects|typography.css). */
  --mushy-action: hsl(142 65% 44%);
  --mushy-action-dark: hsl(142 65% 37%);
  --mushy-secondary: hsl(150 40% 22%);
  --mushy-forest-mid: hsl(150 42% 28%);
  --mushy-primary: hsl(348 83% 47%);
  --mushy-primary-10: hsl(348 83% 47% / 0.1);
  --mushy-foreground: hsl(150 10% 20%);
  --mushy-muted: hsl(150 10% 96%);
  --mushy-muted-fg: hsl(150 10% 45%);
  --mushy-border: hsl(150 15% 90%);
  --mushy-radius-lg: 0.5rem;
  --mushy-radius-xl: 0.75rem;
  --mushy-radius-2xl: 1rem;
  --mushy-radius-full: 9999px;
  --mushy-shadow-soft: 0 4px 20px -4px hsl(0 0% 0% / 0.08);
  --mushy-shadow-elevated: 0 20px 60px -15px hsl(0 0% 0% / 0.2);
  --mushy-ease-out: cubic-bezier(0, 0, 0.2, 1);
  --mushy-font-sans: 'Inter', system-ui, sans-serif;
  --mushy-font-heading: 'Lato', system-ui, sans-serif;

  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 180;
  font-family: var(--mushy-font-sans);
}

#bdm-chat-widget *,
#bdm-chat-widget *::before,
#bdm-chat-widget *::after { box-sizing: border-box; }

/* ── Panel ──────────────────────────────────────────────────────────────── */
.mushy-window {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 420px;
  max-width: calc(100vw - 32px);
  height: min(660px, calc(100vh - 48px));
  background: var(--mushy-muted);
  border: 1px solid hsl(150 15% 88%);
  border-radius: var(--mushy-radius-2xl);
  box-shadow: 0 30px 80px -20px hsl(150 40% 10% / 0.45);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transition: opacity 0.28s var(--mushy-ease-out), transform 0.32s var(--mushy-ease-out);
}
/* hidden (closed) state — the FAB toggles .hidden off */
.mushy-window.hidden {
  opacity: 0;
  transform: translateY(24px) scale(0.96);
  pointer-events: none;
}
/* docked full-height right rail */
.mushy-window.mushy-docked {
  top: 0;
  bottom: 0;
  right: 0;
  width: 440px;
  max-width: 100vw;
  height: 100vh;
  border-radius: 0;
}
.mushy-window.mushy-docked.hidden { transform: translateX(110%); }

/* ── Header ─────────────────────────────────────────────────────────────── */
.mushy-header {
  flex-shrink: 0;
  padding: 16px 16px 14px;
  color: #fff;
  background: linear-gradient(135deg, var(--mushy-secondary) 0%, var(--mushy-forest-mid) 55%, var(--mushy-action-dark) 130%);
}
.mushy-header-row { display: flex; align-items: center; gap: 12px; }
.mushy-avatar-wrap { position: relative; flex-shrink: 0; }
.mushy-avatar {
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  box-shadow: 0 1px 4px hsl(150 40% 12% / 0.25);
}
.mushy-avatar img { width: 78%; height: 78%; object-fit: contain; }
.mushy-pulse {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--mushy-action);
  border: 2px solid #fff;
  animation: mushyPulse 2s infinite;
}
.mushy-head-text { flex: 1; min-width: 0; }
.mushy-title-row { display: flex; align-items: center; gap: 8px; }
.mushy-title {
  font-family: var(--mushy-font-heading);
  font-weight: 900;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}
.mushy-badge {
  font-size: 10px;
  font-weight: 600;
  background: hsl(0 0% 100% / 0.16);
  padding: 2px 8px;
  border-radius: var(--mushy-radius-full);
  letter-spacing: 0.03em;
}
.mushy-status { margin: 1px 0 0; font-size: 12px; color: hsl(0 0% 100% / 0.72); }
.mushy-head-btns { display: flex; gap: 2px; }
.mushy-hdr-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: hsl(0 0% 100% / 0.12);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.mushy-hdr-btn:hover { background: hsl(0 0% 100% / 0.22); }
.mushy-hdr-btn svg { width: 18px; height: 18px; }
/* dock toggle: chevron points the other way once docked (no JS icon swap) */
.mushy-window.mushy-docked #bdm-chat-expand svg { transform: rotate(180deg); }

/* ── Messages ───────────────────────────────────────────────────────────── */
.mushy-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.mushy-row { display: flex; flex-direction: column; gap: 8px; animation: mushyPop 0.35s var(--mushy-ease-out) both; }
.mushy-row.mushy-user { align-items: flex-end; }
.mushy-bubble-line { display: flex; gap: 8px; align-items: flex-end; max-width: 100%; }
.mushy-row.mushy-user .mushy-bubble-line { flex-direction: row-reverse; max-width: 85%; align-self: flex-end; }
.mushy-bubble {
  padding: 11px 14px;
  border-radius: var(--mushy-radius-xl);
  font-size: 13.5px;
  line-height: 1.5;
  background: #fff;
  color: var(--mushy-foreground);
  box-shadow: var(--mushy-shadow-soft);
  border-bottom-left-radius: 4px;
}
.mushy-bubble p { margin: 0 0 6px; }
.mushy-bubble p:last-child { margin-bottom: 0; }
.mushy-bubble a { color: var(--mushy-action-dark); text-decoration: underline; text-underline-offset: 2px; }
.mushy-bubble ul, .mushy-bubble ol { margin: 4px 0; padding-left: 18px; }
.mushy-bubble li { margin: 2px 0; }
.mushy-row.mushy-user .mushy-bubble {
  background: var(--mushy-primary);
  color: #fff;
  box-shadow: none;
  border-bottom-left-radius: var(--mushy-radius-xl);
  border-bottom-right-radius: 4px;
}
/* bot avatar beside a bubble */
.mushy-msg-avatar { width: 28px; height: 28px; }
.mushy-indent { padding-left: 36px; }

/* ── Product card ───────────────────────────────────────────────────────── */
.mushy-cards { padding-left: 36px; display: flex; flex-direction: column; gap: 8px; }
.mushy-card {
  display: flex;
  gap: 12px;
  align-items: center;
  background: #fff;
  border: 1px solid var(--mushy-border);
  border-radius: var(--mushy-radius-xl);
  padding: 10px;
  box-shadow: var(--mushy-shadow-soft);
  text-decoration: none;
  color: inherit;
}
.mushy-card:hover { border-color: var(--mushy-action); }
.mushy-card-thumb {
  width: 52px;
  height: 52px;
  border-radius: var(--mushy-radius-lg);
  overflow: hidden;
  flex-shrink: 0;
  background: var(--mushy-muted);
}
.mushy-card-thumb img { width: 100%; height: 100%; object-fit: cover; }
.mushy-card-body { flex: 1; min-width: 0; }
.mushy-card-name {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--mushy-foreground);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mushy-card-price { color: var(--mushy-secondary); font-weight: 700; font-size: 14px; }
.mushy-card-add {
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  height: 34px;
  width: 34px;
  padding: 0;
  border-radius: var(--mushy-radius-lg);
  background: var(--mushy-primary-10);
  color: var(--mushy-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--mushy-font-sans);
  transition: all 0.2s;
}
.mushy-card-add svg { width: 16px; height: 16px; }
.mushy-card-add.mushy-added {
  width: auto;
  padding: 0 12px;
  border-radius: var(--mushy-radius-full);
  background: var(--mushy-action);
  color: #fff;
}
.mushy-card-add.mushy-added svg { width: 15px; height: 15px; }

/* ── Chips ──────────────────────────────────────────────────────────────── */
.mushy-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.mushy-chip {
  border: 1px solid var(--mushy-action);
  background: hsl(142 65% 44% / 0.08);
  color: var(--mushy-action-dark);
  border-radius: var(--mushy-radius-full);
  padding: 7px 14px;
  font-size: 12.5px;
  font-weight: 600;
  font-family: var(--mushy-font-sans);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.mushy-chip:hover { background: var(--mushy-action); color: #fff; }

/* ── Typing indicator ───────────────────────────────────────────────────── */
.mushy-typing-line { display: flex; align-items: flex-end; gap: 8px; }
.mushy-typing {
  background: #fff;
  box-shadow: var(--mushy-shadow-soft);
  border-radius: var(--mushy-radius-xl);
  border-bottom-left-radius: 4px;
  padding: 12px 14px;
  display: flex;
  gap: 5px;
  align-items: center;
}
.mushy-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--mushy-action);
  animation: mushyDots 1.2s var(--mushy-ease-out) infinite;
}
.mushy-typing span:nth-child(2) { animation-delay: 0.16s; }
.mushy-typing span:nth-child(3) { animation-delay: 0.32s; }

/* ── Composer ───────────────────────────────────────────────────────────── */
.mushy-composer {
  flex-shrink: 0;
  background: #fff;
  border-top: 1px solid var(--mushy-border);
  padding: 12px 14px 10px;
}
.mushy-composer form { display: flex; gap: 8px; align-items: center; }
.mushy-input {
  flex: 1;
  border: 1px solid var(--mushy-border);
  outline: none;
  border-radius: var(--mushy-radius-full);
  padding: 0 16px;
  height: 42px;
  font-family: var(--mushy-font-sans);
  font-size: 13.5px;
  background: var(--mushy-muted);
  color: var(--mushy-foreground);
  transition: border-color 0.2s, background 0.2s;
}
.mushy-input:focus { border-color: var(--mushy-action); background: #fff; }
.mushy-send {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  flex-shrink: 0;
  cursor: pointer;
  background: var(--mushy-action);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.mushy-send svg { width: 18px; height: 18px; }
.mushy-order-help {
  display: inline-block;
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--mushy-primary);
  border: 1px solid var(--mushy-primary-10);
  background: transparent;
  border-radius: var(--mushy-radius-full);
  padding: 5px 12px;
  cursor: pointer;
}
.mushy-order-help:hover { background: var(--mushy-primary-10); }

/* ── Powered by ─────────────────────────────────────────────────────────── */
.mushy-powered {
  text-align: center;
  margin-top: 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  color: var(--mushy-muted-fg);
  letter-spacing: 0.02em;
  font-weight: 500;
}
.mushy-powered b { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; }
.mushy-powered .mushy-diamond {
  width: 8px;
  height: 8px;
  background: currentColor;
  transform: rotate(45deg);
  border-radius: 1.5px;
  display: inline-block;
}

/* ── FAB ────────────────────────────────────────────────────────────────── */
.mushy-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  height: 60px;
  border: none;
  cursor: pointer;
  border-radius: var(--mushy-radius-full);
  padding: 0 22px 0 8px;
  background: linear-gradient(135deg, var(--mushy-action) 0%, var(--mushy-secondary) 130%);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 14px 32px -8px hsl(150 45% 20% / 0.55);
  transition: transform 0.2s, opacity 0.25s var(--mushy-ease-out);
}
.mushy-fab:active { transform: scale(0.94); }
.mushy-fab.mushy-hidden { opacity: 0; pointer-events: none; transform: scale(0.85); }
.mushy-fab-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: hsl(0 0% 100% / 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.mushy-fab-label { font-weight: 700; font-size: 15px; white-space: nowrap; padding-right: 2px; }

/* ── Proactive toast ────────────────────────────────────────────────────── */
.mushy-toast {
  position: fixed;
  bottom: 96px;
  right: 26px;
  z-index: 178;
  width: 258px;
  background: #fff;
  border: 1px solid var(--mushy-border);
  border-radius: var(--mushy-radius-xl);
  box-shadow: var(--mushy-shadow-elevated);
  padding: 13px 14px 13px 12px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  cursor: pointer;
  transition: opacity 0.3s var(--mushy-ease-out), transform 0.3s var(--mushy-ease-out);
}
.mushy-toast.mushy-hidden { opacity: 0; transform: translateY(12px); pointer-events: none; }
.mushy-toast-title { margin: 0 0 2px; font-size: 13px; font-weight: 700; color: var(--mushy-foreground); }
.mushy-toast-body { margin: 0; font-size: 12.5px; color: var(--mushy-muted-fg); line-height: 1.4; }
.mushy-toast-x {
  border: none;
  background: none;
  color: var(--mushy-muted-fg);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.mushy-toast-x svg { width: 16px; height: 16px; }

/* ── Animations ─────────────────────────────────────────────────────────── */
@keyframes mushyDots {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}
@keyframes mushyPulse {
  0% { box-shadow: 0 0 0 0 hsl(142 65% 50% / 0.6); }
  70% { box-shadow: 0 0 0 8px hsl(142 65% 50% / 0); }
  100% { box-shadow: 0 0 0 0 hsl(142 65% 50% / 0); }
}
@keyframes mushyPop {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  #bdm-chat-widget *, .mushy-window, .mushy-fab, .mushy-toast { animation: none !important; transition: none !important; }
}
