/* WayfairUSA (mondsubs) Collector SupportBot — Scoped Desktop + Mobile-First Stylesheet (Kalles 5.4.1 Safe) */
#wf-supportbot-root {
  --wf-sb-primary: #108474;
  --wf-sb-primary-hover: #0b695c;
  --wf-sb-primary-soft: #eaf6f4;
  --wf-sb-bg: #ffffff;
  --wf-sb-surface: #f6f8f7;
  --wf-sb-text: #111827;
  --wf-sb-muted: #6b7280;
  --wf-sb-border: #e5e7eb;
  --wf-sb-shadow: 0 20px 48px rgba(15, 23, 42, 0.18), 0 4px 12px rgba(15, 23, 42, 0.08);
  --wf-sb-closed-bottom: 22px;
  --wf-sb-admin-bar-h: 0px;
  --wf-sb-vvh: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  position: fixed;
  right: 22px;
  bottom: calc(var(--wf-sb-closed-bottom) + env(safe-area-inset-bottom, 0px));
  z-index: 2147483640;
  line-height: 1.45;
  box-sizing: border-box;
  transition: bottom 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

#wf-supportbot-root *,
#wf-supportbot-root *::before,
#wf-supportbot-root *::after {
  box-sizing: border-box;
}

/* Hard defensive reset against Kalles global button/input CSS */
#wf-supportbot-root button,
#wf-supportbot-root input {
  font-family: inherit !important;
  text-transform: none !important;
  letter-spacing: normal !important;
  min-height: 0 !important;
  height: auto;
  margin: 0 !important;
  box-shadow: none;
  appearance: none;
  -webkit-appearance: none;
}

/* Mobile Backdrop Dimmer (Hidden on desktop, shown when mobile sheet opens) */
.wf-sb-backdrop {
  display: none;
}

/* Floating Launcher Button */
#wf-supportbot-root .wf-sb-launcher {
  display: flex !important;
  align-items: center;
  gap: 9px;
  background: linear-gradient(135deg, #108474 0%, #0b6357 100%) !important;
  color: #ffffff !important;
  border: none !important;
  border-radius: 999px !important;
  padding: 12px 18px 12px 14px !important;
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(16, 132, 116, 0.38) !important;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s ease, padding 0.2s ease;
  font-size: 14px !important;
  font-weight: 600 !important;
  line-height: 1.2 !important;
  margin-left: auto !important;
}

#wf-supportbot-root .wf-sb-launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 32px rgba(16, 132, 116, 0.48) !important;
}

/* Hide launcher & nudge cleanly whenever chat panel is open */
#wf-supportbot-root.is-panel-open .wf-sb-launcher,
#wf-supportbot-root.is-panel-open .wf-sb-nudge {
  display: none !important;
}

.wf-sb-launcher-avatar {
  position: relative;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.wf-sb-online-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 8.5px;
  height: 8.5px;
  border-radius: 50%;
  background: #34d399;
  border: 2px solid #0e7466;
}

.wf-sb-unread-badge {
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

/* Proactive Dwell Nudge Bubble */
.wf-sb-nudge {
  position: absolute;
  right: 0;
  bottom: 60px;
  width: 304px;
  background: #ffffff;
  color: var(--wf-sb-text);
  border: 1px solid rgba(16, 132, 116, 0.24);
  border-radius: 15px 15px 4px 15px;
  padding: 11px 30px 11px 13px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.16);
  font-size: 13px;
  line-height: 1.42;
  cursor: pointer;
  animation: wfSbFadeUp 0.26s cubic-bezier(0.16, 1, 0.3, 1);
}

.wf-sb-nudge-header {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--wf-sb-primary);
  margin-bottom: 3px;
}

#wf-supportbot-root .wf-sb-nudge-close {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 22px !important;
  height: 22px !important;
  padding: 0 !important;
  border: none !important;
  background: #f3f4f6 !important;
  color: #6b7280 !important;
  border-radius: 50% !important;
  font-size: 14px !important;
  line-height: 1 !important;
  cursor: pointer;
  display: flex !important;
  align-items: center;
  justify-content: center;
}

/* Main Chat Panel */
.wf-sb-panel {
  width: 384px;
  height: 580px;
  max-height: calc(100vh - 96px);
  background: var(--wf-sb-bg);
  border-radius: 20px;
  box-shadow: var(--wf-sb-shadow);
  border: 1px solid rgba(15, 23, 42, 0.08);
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: wfSbFadeUp 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.wf-sb-panel.is-open {
  display: flex;
}

/* Header */
.wf-sb-header {
  background: linear-gradient(135deg, #108474 0%, #0a5c50 100%);
  color: #ffffff;
  padding: 13px 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.wf-sb-agent-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.wf-sb-agent-avatar {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  border: 1.5px solid rgba(255, 255, 255, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.wf-sb-agent-name {
  font-size: 14.5px;
  font-weight: 700;
  line-height: 1.2;
}

.wf-sb-agent-sub {
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.88);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#wf-supportbot-root .wf-sb-header-close {
  background: rgba(255, 255, 255, 0.16) !important;
  border: none !important;
  color: #ffffff !important;
  width: 32px !important;
  height: 32px !important;
  padding: 0 !important;
  border-radius: 50% !important;
  cursor: pointer;
  font-size: 20px !important;
  line-height: 1 !important;
  display: flex !important;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Single-Line Trust Ribbon (Never wraps awkwardly) */
.wf-sb-trust-bar {
  background: var(--wf-sb-primary-soft);
  color: #0b5d51;
  font-size: 11.5px;
  font-weight: 600;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  white-space: nowrap;
  border-bottom: 1px solid rgba(16, 132, 116, 0.14);
  flex-shrink: 0;
}

/* Messages Stream */
.wf-sb-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 14px 13px 10px;
  background: var(--wf-sb-surface);
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}

.wf-sb-msg-row,
.wf-sb-cards-wrap,
.wf-sb-track-card,
.wf-sb-typing,
#wf-supportbot-root .wf-sb-promo-pill {
  flex-shrink: 0 !important;
}

.wf-sb-msg-row {
  display: flex;
  flex-direction: column;
  max-width: 87%;
  animation: wfSbBubbleIn 0.18s ease-out;
}

.wf-sb-msg-row.is-bot {
  align-self: flex-start;
}

.wf-sb-msg-row.is-user {
  align-self: flex-end;
}

.wf-sb-bubble {
  padding: 10px 13px;
  font-size: 14px;
  line-height: 1.46;
  word-wrap: break-word;
}

.wf-sb-msg-row.is-bot .wf-sb-bubble {
  background: #ffffff;
  color: var(--wf-sb-text);
  border-radius: 15px 15px 15px 4px;
  border: 1px solid rgba(15, 23, 42, 0.07);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.04);
}

.wf-sb-msg-row.is-user .wf-sb-bubble {
  background: var(--wf-sb-primary);
  color: #ffffff;
  border-radius: 15px 15px 4px 15px;
}

.wf-sb-bubble a {
  color: var(--wf-sb-primary);
  font-weight: 600;
  text-decoration: underline;
  word-break: break-all;
}

/* Typing Dots Indicator */
.wf-sb-typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #ffffff;
  border: 1px solid rgba(15, 23, 42, 0.07);
  border-radius: 15px 15px 15px 4px;
  padding: 11px 14px;
  width: fit-content;
}

.wf-sb-typing span {
  width: 6.5px;
  height: 6.5px;
  background: #9ca3af;
  border-radius: 50%;
  animation: wfSbBounce 1.2s infinite ease-in-out both;
}

.wf-sb-typing span:nth-child(1) { animation-delay: -0.24s; }
.wf-sb-typing span:nth-child(2) { animation-delay: -0.12s; }

/* Promo Code Copy Pill (Protected against Kalles button squishing!) */
#wf-supportbot-root .wf-sb-promo-pill {
  margin-top: 2px !important;
  display: inline-flex !important;
  align-items: center;
  gap: 7px;
  background: #fffbeb !important;
  border: 1.5px dashed #d97706 !important;
  color: #92400e !important;
  padding: 8px 12px !important;
  height: auto !important;
  line-height: 1.35 !important;
  border-radius: 10px !important;
  font-size: 12.5px !important;
  font-weight: 600 !important;
  cursor: pointer;
  width: fit-content;
  max-width: 96%;
  flex-wrap: wrap;
}

#wf-supportbot-root .wf-sb-promo-pill.is-copied {
  background: #ecfdf5 !important;
  border-color: #10b981 !important;
  color: #065f46 !important;
}

.wf-sb-promo-code {
  background: #fde68a;
  color: #78350f;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 5px;
  letter-spacing: 0.4px;
}

/* Inline Product Recommendation Cards */
.wf-sb-cards-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 2px;
  width: 100%;
  max-width: 96%;
}

.wf-sb-prod-card {
  display: flex;
  gap: 10px;
  background: #ffffff;
  border: 1px solid var(--wf-sb-border);
  border-radius: 12px;
  padding: 9px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
  align-items: center;
}

.wf-sb-prod-img {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  object-fit: cover;
  background: #f3f4f6;
  flex-shrink: 0;
  border: 1px solid #f1f5f9;
}

.wf-sb-prod-body {
  flex: 1;
  min-width: 0;
}

.wf-sb-prod-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--wf-sb-text) !important;
  text-decoration: none !important;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wf-sb-prod-meta {
  font-size: 11.5px;
  color: var(--wf-sb-muted);
  margin-top: 2px;
}

.wf-sb-prod-price-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  gap: 6px;
}

.wf-sb-prod-price {
  font-size: 14px;
  font-weight: 800;
  color: var(--wf-sb-primary);
}

.wf-sb-prod-compare {
  font-size: 11.5px;
  color: #9ca3af;
  text-decoration: line-through;
  margin-left: 4px;
  font-weight: 400;
}

#wf-supportbot-root .wf-sb-add-btn {
  background: var(--wf-sb-primary) !important;
  color: #ffffff !important;
  border: none !important;
  border-radius: 7px !important;
  padding: 6px 11px !important;
  height: auto !important;
  line-height: 1.2 !important;
  font-size: 12px !important;
  font-weight: 700 !important;
  cursor: pointer;
  white-space: nowrap;
}

#wf-supportbot-root .wf-sb-add-btn.is-added {
  background: #059669 !important;
}

/* Live Order Tracking Card */
.wf-sb-track-card {
  background: #ffffff;
  border: 1px solid #d1fae5;
  border-left: 4px solid var(--wf-sb-primary);
  border-radius: 11px;
  padding: 10px 12px;
  font-size: 12.5px;
  max-width: 94%;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.wf-sb-track-btn {
  display: inline-block;
  margin-top: 8px;
  background: #111827;
  color: #ffffff !important;
  text-decoration: none !important;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 7px;
}

/* Quick-Reply Chips Bar */
.wf-sb-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 12px;
  background: #ffffff;
  border-top: 1px solid #f1f5f9;
  scrollbar-width: none;
  flex-shrink: 0;
}

.wf-sb-chips::-webkit-scrollbar {
  display: none;
}

#wf-supportbot-root .wf-sb-chip {
  background: var(--wf-sb-primary-soft) !important;
  color: #0b5d51 !important;
  border: 1px solid rgba(16, 132, 116, 0.24) !important;
  border-radius: 999px !important;
  padding: 6px 11px !important;
  height: auto !important;
  line-height: 1.25 !important;
  font-size: 12px !important;
  font-weight: 600 !important;
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
}

/* Input Composer */
.wf-sb-composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px 11px;
  background: #ffffff;
  border-top: 1px solid var(--wf-sb-border);
  flex-shrink: 0;
}

#wf-supportbot-root .wf-sb-input {
  flex: 1;
  border: 1px solid #d1d5db !important;
  border-radius: 999px !important;
  padding: 9px 14px !important;
  height: 40px !important;
  font-size: 14px !important;
  line-height: 1.3 !important;
  color: var(--wf-sb-text) !important;
  outline: none !important;
  background: #f9fafb !important;
}

#wf-supportbot-root .wf-sb-input:focus {
  border-color: var(--wf-sb-primary) !important;
  background: #ffffff !important;
}

#wf-supportbot-root .wf-sb-send {
  width: 38px !important;
  height: 38px !important;
  padding: 0 !important;
  border-radius: 50% !important;
  border: none !important;
  background: var(--wf-sb-primary) !important;
  color: #ffffff !important;
  cursor: pointer;
  display: flex !important;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#wf-supportbot-root .wf-sb-send:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

@keyframes wfSbFadeUp {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

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

@keyframes wfSbBounce {
  0%, 80%, 100% { transform: scale(0.65); opacity: 0.45; }
  40% { transform: scale(1); opacity: 1; }
}

/* ==========================================================================
   MOBILE & SMALL VIEWPORT OPTIMIZATIONS (iPhone SE 375px -> Pro Max 430px)
   ========================================================================== */
@media (max-width: 640px) {
  #wf-supportbot-root {
    right: 12px;
    /* Dynamically computed by JS to sit cleanly above Kalles .hdt-toolbar & sticky Add-to-Cart! */
    bottom: var(--wf-sb-closed-bottom, 68px);
  }

  /* Sleek compact launcher on mobile so it never crowds product photos or prices */
  #wf-supportbot-root .wf-sb-launcher {
    padding: 9px 13px 9px 10px !important;
    font-size: 13px !important;
    gap: 7px;
    box-shadow: 0 6px 18px rgba(16, 132, 116, 0.34) !important;
  }

  .wf-sb-launcher-avatar {
    width: 24px;
    height: 24px;
    font-size: 13px;
  }

  /* Compact 2-line max mobile nudge so it never covers product photos */
  .wf-sb-nudge {
    width: 248px;
    bottom: 50px;
    padding: 9px 28px 9px 11px;
    font-size: 12px;
    line-height: 1.36;
  }

  #wf-sb-nudge-text {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  /* Dimmer backdrop behind open bottom sheet */
  #wf-supportbot-root.is-panel-open .wf-sb-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(1.5px);
    -webkit-backdrop-filter: blur(1.5px);
    z-index: -1;
  }

  /* Full-width bottom-sheet drawer with visualViewport & admin-bar clearance */
  .wf-sb-panel.is-open {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--wf-sb-admin-bar-h, 0px);
    width: 100vw;
    height: min(78dvh, calc(var(--wf-sb-vvh, 100dvh) - var(--wf-sb-admin-bar-h, 0px) - 28px));
    max-height: calc(var(--wf-sb-vvh, 100dvh) - var(--wf-sb-admin-bar-h, 0px) - 20px);
    margin: 0;
    border-radius: 18px 18px 0 0;
    border-bottom: none;
  }

  .wf-sb-trust-bar {
    font-size: 10.5px;
    padding: 5px 10px;
    justify-content: space-around;
  }

  .wf-sb-composer {
    padding: 8px 10px calc(10px + env(safe-area-inset-bottom, 0px));
  }

  /* CRITICAL iOS SAFARI FIX: 16px prevents Safari from auto-zooming page on input focus! */
  #wf-supportbot-root .wf-sb-input {
    font-size: 16px !important;
    height: 42px !important;
    padding: 9px 14px !important;
  }

  #wf-supportbot-root .wf-sb-send {
    width: 40px !important;
    height: 40px !important;
  }
}
