/* ==========================================================================
   Chat Widget, Cache Valley Bee Supply
   Floating chatbot panel, matches site design tokens.
   ========================================================================== */

/* --- Fab (floating action button) --- */
.chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1050;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--color-orange);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-fab:hover {
  background: var(--color-orange-dark);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
}
.chat-fab:focus-visible {
  outline: 3px solid var(--color-gold);
  outline-offset: 3px;
}
.chat-fab svg {
  width: 26px;
  height: 26px;
  fill: currentColor;
}
/* Hide fab when panel is open */
.chat-open .chat-fab { display: none; }

/* --- Panel --- */
.chat-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1050;
  width: 380px;
  max-height: 520px;
  display: none;
  flex-direction: column;
  background: var(--color-white, #fff);
  border: 1px solid var(--color-border, #e5e0d8);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  font-family: var(--font-body, system-ui, -apple-system, sans-serif);
}
.chat-open .chat-panel { display: flex; }

/* --- Header --- */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--color-brown, #aa5922);
  color: #fff;
}
.chat-header-title {
  font-size: 0.95em;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-header-title svg {
  width: 18px;
  height: 18px;
  fill: var(--color-gold, #f0a030);
}
.chat-close {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  line-height: 1;
  font-size: 1.2em;
  opacity: 0.8;
  transition: opacity 0.15s;
}
.chat-close:hover { opacity: 1; }
.chat-close:focus-visible {
  outline: 2px solid var(--color-gold);
  outline-offset: 2px;
}

/* --- Messages area --- */
.chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--color-cream, #f9f7f4);
  min-height: 200px;
  max-height: 340px;
}

/* Scrollbar */
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
  background: var(--color-border, #e5e0d8);
  border-radius: 3px;
}

/* --- Message bubbles --- */
.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.88em;
  line-height: 1.55;
  color: var(--color-text-dark, #333);
  word-wrap: break-word;
}
.chat-msg--user {
  align-self: flex-end;
  background: var(--color-orange, #d75f04);
  color: #fff;
  border-bottom-right-radius: 3px;
}
.chat-msg--bot {
  align-self: flex-start;
  background: var(--color-white, #fff);
  border: 1px solid var(--color-border, #e5e0d8);
  border-bottom-left-radius: 3px;
}

/* Bold/italic in bot responses */
.chat-msg--bot strong { color: var(--color-brown, #aa5922); }

/* --- Sources (collapsible) --- */
.chat-sources {
  font-size: 0.78em;
  color: var(--color-text-light, #999);
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--color-border, #e5e0d8);
}
.chat-sources summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--color-text, #666);
}
.chat-sources ul {
  margin: 4px 0 0 0;
  padding-left: 16px;
  list-style: disc;
}

/* --- Disclaimer (small text below bot answers) --- */
.chat-disclaimer {
  font-size: 0.78em;
  color: var(--color-text-light, #999);
  font-style: italic;
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--color-border, #e5e0d8);
  line-height: 1.4;
}

/* --- Follow-up / starter suggestion chips --- */
.chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0;
}
.chat-chips--starter {
  padding-top: 12px;
}
.chat-chip {
  border: 1px solid var(--color-border, #e5e0d8);
  background: var(--color-white, #fff);
  color: var(--color-brown, #aa5922);
  font-family: inherit;
  font-size: 0.8em;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  line-height: 1.3;
  text-align: left;
}
.chat-chip:hover {
  background: var(--color-cream, #f9f7f4);
  border-color: var(--color-gold, #f0a030);
}
.chat-chip:focus-visible {
  outline: 2px solid var(--color-gold);
  outline-offset: 2px;
}

/* --- Inline links in bot answers --- */
.chat-msg--bot a {
  color: var(--color-orange, #d75f04);
  text-decoration: underline;
  font-weight: 600;
}
.chat-msg--bot a:hover {
  color: var(--color-orange-dark, #c45603);
}

/* --- Inline YesCartGo cart widget --- */
.chat-cart-widget {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--color-border, #e5e0d8);
}
.chat-cart-heading {
  font-size: 0.85em;
  font-weight: 600;
  color: var(--color-brown, #aa5922);
  margin-bottom: 8px;
}
.chat-cart-heading span {
  margin-right: 4px;
}
.chat-cart-slot {
  /* YesCartGo kit.js renders a .clw card here. Constrain max width so
     the card fits inside the chat panel comfortably. */
  margin: 0 -4px 8px;
}
.chat-cart-slot .clw {
  max-width: 100% !important;
  font-size: 0.92em;
}
/* Direct Amazon fallback button (visible until YesCartGo widget loads,
   then hidden by the JS handler). Uses a form POST under the hood for
   reliability with multi-item carts. */
.chat-cart-fallback {
  display: inline-block;
  background: var(--color-orange, #d75f04);
  color: #fff !important;
  text-decoration: none !important;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.85em;
  padding: 9px 14px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.chat-cart-fallback:hover {
  background: var(--color-orange-dark, #c45603);
}
.chat-cart-fallback:focus-visible {
  outline: 3px solid var(--color-gold, #f0a030);
  outline-offset: 2px;
}


/* --- Typing indicator --- */
.chat-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 10px 16px;
  background: var(--color-white, #fff);
  border: 1px solid var(--color-border, #e5e0d8);
  border-radius: 10px;
  border-bottom-left-radius: 3px;
}
.chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-text-light, #999);
  animation: chatBounce 1.2s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chatBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

/* --- Welcome message --- */
.chat-welcome {
  text-align: center;
  color: var(--color-text, #666);
  font-size: 0.85em;
  line-height: 1.5;
  padding: 12px 8px;
}
.chat-welcome strong { color: var(--color-brown, #aa5922); }

/* --- Input area --- */
.chat-input-wrap {
  display: flex;
  padding: 10px 12px;
  gap: 8px;
  border-top: 1px solid var(--color-border, #e5e0d8);
  background: var(--color-white, #fff);
}
.chat-input {
  flex: 1;
  border: 1px solid var(--color-border, #e5e0d8);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.88em;
  font-family: var(--font-body, system-ui, sans-serif);
  color: var(--color-text-dark, #333);
  resize: none;
  min-height: 40px;
  max-height: 80px;
  line-height: 1.4;
  transition: border-color 0.2s;
}
.chat-input:focus {
  outline: none;
  border-color: var(--color-gold, #f0a030);
  box-shadow: 0 0 0 2px rgba(240, 160, 48, 0.2);
}
.chat-input::placeholder { color: var(--color-text-light, #999); }
.chat-send {
  align-self: flex-end;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: var(--color-orange, #d75f04);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}
.chat-send:hover { background: var(--color-orange-dark, #c45603); }
.chat-send:focus-visible {
  outline: 3px solid var(--color-gold);
  outline-offset: 2px;
}
.chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.chat-send svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* --- Error state --- */
.chat-error {
  font-size: 0.82em;
  color: #c0392b;
  text-align: center;
  padding: 6px 12px;
}

/* --- Responsive --- */
@media (max-width: 480px) {
  .chat-panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-height: 100dvh;
    border-radius: 0;
  }
  .chat-messages {
    max-height: calc(100dvh - 130px);
  }
  .chat-fab {
    bottom: 16px;
    right: 16px;
  }
}
