/* Blissful Blinds Co 369 — AI Sales & Support Assistant widget.
   Self-contained: only touches its own `.bb-*` classes, reuses the site's
   existing CSS custom properties (colours/fonts/shadows) from styles.css
   for visual consistency, but adds nothing to styles.css itself. */

.bb-chat-widget * {
  box-sizing: border-box;
}

/* ---------- Floating toggle button ---------- */
/* Mirrored onto the opposite (left) corner from the WhatsApp widget
   (bottom:28px/right:24px) so the two never stack on top of each other.
   Bottom offset is kept tall enough to still clear the cookie banner,
   which spans near-full width and can appear on either side. This is
   only the pre-JS default — makeFreelyDraggable() in this file converts
   it to explicit left/top on init and allows free movement in any
   direction from there. */
.bb-chat-toggle {
  position: fixed;
  bottom: 130px;
  left: 24px;
  z-index: 9997;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  cursor: grab;
  /* touch-action: none stops the page from scrolling under a touch
     drag instead of the button moving. -webkit-user-drag/user-select
     stop the browser's own native drag/text-selection gestures from
     competing with the custom pointer-based drag. */
  touch-action: none;
  -webkit-user-drag: none;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent, #d97706), var(--accent-hover, #b45309));
  color: #fff;
  box-shadow: 0 8px 24px rgba(217, 119, 6, 0.45);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s ease;
  animation: bbFadeInUp 0.5s ease-out both, bbPulse 2.8s ease-in-out 1.5s infinite;
}

.bb-chat-toggle:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 12px 32px rgba(217, 119, 6, 0.6);
}

.bb-chat-toggle.is-dragging {
  cursor: grabbing;
  transition: none;
  animation: none;
  /* Hints the compositor to put this on its own GPU layer while it's
     actively being transformed, avoiding a layer-promotion hitch on the
     very first drag frame. Removed once the drag ends so the layer
     isn't kept around needlessly. */
  will-change: transform;
}

/* One-time eased settle after a drag ends — magnetic edge snap and the
   viewport-resize reposition both use this. Deliberately a plain
   ease-out curve (no overshoot) per "no bounce glitches". */
.bb-chat-toggle.is-snapping {
  transition: left 0.32s cubic-bezier(0.22, 1, 0.36, 1), top 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.bb-chat-toggle:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

.bb-chat-toggle svg {
  width: 28px;
  height: 28px;
  position: absolute;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.bb-chat-toggle .bb-icon-close {
  opacity: 0;
  transform: scale(0.6) rotate(-45deg);
}

.bb-chat-widget.bb-open .bb-chat-toggle .bb-icon-chat {
  opacity: 0;
  transform: scale(0.6) rotate(45deg);
}

.bb-chat-widget.bb-open .bb-chat-toggle .bb-icon-close {
  opacity: 1;
  transform: scale(1) rotate(0);
}

.bb-chat-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-body, sans-serif);
  border: 2px solid #fff;
}

.bb-chat-widget.bb-open .bb-chat-badge,
.bb-chat-badge[hidden] {
  display: none;
}

/* ---------- Panel ---------- */
.bb-chat-panel {
  position: fixed;
  bottom: 130px;
  left: 24px;
  z-index: 10000;
  width: 392px;
  max-width: calc(100vw - 32px);
  height: min(640px, calc(100vh - 166px));
  background: var(--bg-primary, #fff);
  border-radius: var(--radius-lg, 20px);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28), 0 4px 16px rgba(15, 23, 42, 0.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--font-body, sans-serif);
  transform-origin: bottom left;
  animation: bbPanelIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.bb-chat-panel[hidden] {
  display: none;
}

@keyframes bbPanelIn {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes bbFadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes bbPulse {
  0%, 100% { box-shadow: 0 8px 24px rgba(217, 119, 6, 0.45); }
  50% { box-shadow: 0 8px 24px rgba(217, 119, 6, 0.45), 0 0 0 10px rgba(217, 119, 6, 0.12); }
}

/* ---------- Header ---------- */
.bb-chat-header {
  background: linear-gradient(120deg, #0f172a 0%, #1c2c4c 50%, #0f172a 100%);
  color: #fff;
  padding: 16px 16px 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.bb-chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.bb-chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(217, 119, 6, 0.22);
  color: var(--accent-light, #fef3c7);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.1rem;
}

.bb-chat-title {
  font-family: var(--font-heading, sans-serif);
  font-weight: 700;
  font-size: 0.9375rem;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bb-chat-subtitle {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.72);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.bb-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
  flex-shrink: 0;
}

.bb-chat-close {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s ease, transform 0.2s ease;
  font-size: 1.1rem;
  line-height: 1;
}

.bb-chat-close:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: rotate(90deg);
}

.bb-chat-close:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* ---------- Messages ---------- */
.bb-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--bg-secondary, #f8fafc);
  scroll-behavior: smooth;
}

.bb-msg {
  display: flex;
  flex-direction: column;
  max-width: 86%;
  animation: bbFadeInUp 0.25s ease-out both;
}

.bb-msg-bot { align-self: flex-start; }
.bb-msg-user { align-self: flex-end; align-items: flex-end; }

.bb-msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.875rem;
  line-height: 1.5;
  white-space: pre-line;
}

.bb-msg-bot .bb-msg-bubble {
  background: #fff;
  color: var(--text-primary, #0f172a);
  border: 1px solid var(--border-color, #e2e8f0);
  border-bottom-left-radius: 4px;
}

.bb-msg-user .bb-msg-bubble {
  background: linear-gradient(135deg, var(--accent, #d97706), var(--accent-hover, #b45309));
  color: #fff;
  border-bottom-right-radius: 4px;
}

.bb-msg-bubble a {
  color: inherit;
  text-decoration: underline;
  font-weight: 600;
}

.bb-msg-bot .bb-msg-bubble a {
  color: var(--accent-hover, #b45309);
}

.bb-msg-time {
  font-size: 0.6875rem;
  color: var(--text-muted, #94a3b8);
  margin-top: 4px;
  padding: 0 4px;
}

/* Typing / loading indicator */
.bb-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  width: fit-content;
}

.bb-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted, #94a3b8);
  animation: bbTypingDot 1.2s ease-in-out infinite;
}

.bb-typing span:nth-child(2) { animation-delay: 0.15s; }
.bb-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bbTypingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ---------- Suggestions ---------- */
.bb-chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 16px 12px;
  flex-shrink: 0;
  background: var(--bg-secondary, #f8fafc);
}

.bb-chip {
  border: 1px solid var(--accent, #d97706);
  color: var(--accent-hover, #b45309);
  background: #fff;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
  font-family: var(--font-body, sans-serif);
}

.bb-chip:hover {
  background: var(--accent, #d97706);
  color: #fff;
  transform: translateY(-1px);
}

.bb-chip:focus-visible {
  outline: 2px solid var(--accent-hover, #b45309);
  outline-offset: 2px;
}

/* ---------- Input row ---------- */
.bb-chat-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border-color, #e2e8f0);
  flex-shrink: 0;
  background: #fff;
}

.bb-chat-input-row input[type="text"] {
  flex: 1;
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 0.875rem;
  font-family: var(--font-body, sans-serif);
  color: var(--text-primary, #0f172a);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.bb-chat-input-row input[type="text"]:focus {
  border-color: var(--accent, #d97706);
  box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.15);
}

.bb-chat-send {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--accent, #d97706), var(--accent-hover, #b45309));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.bb-chat-send:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 14px rgba(217, 119, 6, 0.4);
}

.bb-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.bb-chat-send svg { width: 16px; height: 16px; }

/* ---------- Footer contact strip ---------- */
.bb-chat-footer {
  display: flex;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--border-color, #e2e8f0);
  flex-shrink: 0;
  background: #fff;
}

.bb-chat-footer a {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 10px;
  border-radius: 10px;
  font-size: 0.8125rem;
  font-weight: 600;
  text-decoration: none;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.bb-chat-footer a:first-child {
  background: var(--text-primary, #0f172a);
  color: #fff;
}

.bb-chat-footer a:last-child {
  background: #25d366;
  color: #fff;
}

.bb-chat-footer a:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.25);
}

.bb-chat-footer a:focus-visible {
  outline: 2px solid var(--accent, #d97706);
  outline-offset: 2px;
}

/* ---------- Lead capture form (inline in chat) ---------- */
.bb-lead-form {
  background: #fff;
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 100%;
}

.bb-lead-form label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary, #475569);
  margin-bottom: 3px;
  display: block;
}

.bb-lead-form input,
.bb-lead-form textarea,
.bb-lead-form select {
  width: 100%;
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.8125rem;
  font-family: var(--font-body, sans-serif);
  color: var(--text-primary, #0f172a);
}

.bb-lead-form input:focus,
.bb-lead-form textarea:focus,
.bb-lead-form select:focus {
  outline: none;
  border-color: var(--accent, #d97706);
  box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.15);
}

.bb-lead-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.bb-lead-submit {
  margin-top: 4px;
  background: linear-gradient(135deg, var(--accent, #d97706), var(--accent-hover, #b45309));
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 10px;
  font-weight: 700;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.bb-lead-submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(217, 119, 6, 0.4);
}

.bb-lead-success {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #15803d;
  font-weight: 600;
  font-size: 0.8125rem;
}

/* ---------- Screen-reader only ---------- */
.bb-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Mobile ---------- */
@media (max-width: 480px) {
  .bb-chat-toggle {
    bottom: 16px;
    left: 16px;
    width: 56px;
    height: 56px;
  }

  .bb-chat-panel {
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    border-radius: 0;
  }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .bb-chat-toggle,
  .bb-chat-panel,
  .bb-msg,
  .bb-typing span,
  .bb-chip,
  .bb-chat-send,
  .bb-chat-footer a,
  .bb-lead-submit {
    animation: none !important;
    transition: none !important;
  }
  .bb-chat-toggle:hover,
  .bb-chat-close:hover {
    transform: none;
  }
}
