/* ==============================================================================
   CHAT WITH BUNS — OFFICIAL AGO BUNS AI ASSISTANT WIDGET
   Theme-Aware Styles utilizing Storefront Dynamic CSS Variables
   ============================================================================== */

/* 1. Floating Launcher Button */
.buns-chat-launcher {
  position: fixed;
  bottom: 84px;
  right: 24px;
  z-index: 995;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-surface, #110A24);
  border: 1.5px solid var(--accent-orange, #A855F7);
  color: var(--text-main, #FFFFFF);
  padding: 8px 16px 8px 10px;
  border-radius: 50px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.4), 0 0 20px var(--accent-orange-glow, rgba(168, 85, 247, 0.35));
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
}

.buns-chat-launcher:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.5), 0 0 28px var(--accent-orange-glow, rgba(168, 85, 247, 0.55));
}

.buns-launcher-avatar {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-orange, #A855F7), var(--accent-amber, #EC4899));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
  font-size: 1.1rem;
}

.buns-launcher-pulse {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #10B981;
  border: 2px solid var(--bg-surface, #110A24);
  box-shadow: 0 0 8px #10B981;
}

.buns-launcher-label {
  display: flex;
  flex-direction: column;
  text-align: left;
}

.buns-launcher-title {
  font-family: var(--font-display, 'Chakra Petch', sans-serif);
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-main, #FFFFFF);
  line-height: 1.2;
}

.buns-launcher-subtitle {
  font-size: 0.72rem;
  color: var(--accent-orange, #A855F7);
  font-weight: 600;
  letter-spacing: 0.2px;
}

/* 2. Main Chat Drawer Window */
.buns-chat-window {
  position: fixed;
  bottom: 84px;
  right: 24px;
  width: 390px;
  max-width: calc(100vw - 32px);
  height: 590px;
  max-height: calc(100vh - 110px);
  z-index: 996;
  background: var(--bg-glass, rgba(17, 10, 36, 0.94));
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1.5px solid var(--border-subtle, rgba(168, 85, 247, 0.25));
  border-radius: var(--radius-lg, 24px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6), 0 0 35px var(--accent-orange-glow, rgba(168, 85, 247, 0.2));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px) scale(0.96);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.buns-chat-window.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* 3. Window Header */
.buns-chat-header {
  padding: 14px 18px;
  background: var(--bg-surface, #110A24);
  border-bottom: 1px solid var(--border-subtle, rgba(168, 85, 247, 0.2));
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.buns-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.buns-header-avatar {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-orange, #A855F7), var(--button-color, #9333EA));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
  font-size: 1.15rem;
}

.buns-header-titles h4 {
  font-family: var(--font-display, 'Chakra Petch', sans-serif);
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--text-main, #FFFFFF);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.buns-header-badge {
  font-size: 0.64rem;
  background: rgba(16, 185, 129, 0.15);
  color: #10B981;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-body, 'Inter', sans-serif);
  font-weight: 700;
  text-transform: uppercase;
}

.buns-header-titles span {
  font-size: 0.74rem;
  color: var(--text-muted, #C4B5FD);
}

.buns-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.buns-header-btn {
  background: transparent;
  border: none;
  color: var(--text-muted, #C4B5FD);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.2s ease;
}

.buns-header-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main, #FFFFFF);
}

/* 4. Messages Feed */
.buns-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.buns-chat-messages::-webkit-scrollbar {
  width: 5px;
}
.buns-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

.buns-msg-row {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  animation: bunsFadeUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.buns-msg-row.buns-user {
  align-self: flex-end;
}

.buns-msg-row.buns-assistant {
  align-self: flex-start;
}

.buns-bubble {
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 0.88rem;
  line-height: 1.5;
  word-break: break-word;
}

.buns-user .buns-bubble {
  background: var(--button-color, #9333EA);
  color: var(--button-text-color, #FFFFFF);
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}

.buns-assistant .buns-bubble {
  background: var(--bg-card, #1A1035);
  color: var(--text-main, #FAF5FF);
  border: 1px solid var(--border-subtle, rgba(168, 85, 247, 0.2));
  border-bottom-left-radius: 4px;
}

.buns-msg-time {
  font-size: 0.68rem;
  color: var(--text-muted, #C4B5FD);
  margin-top: 4px;
  padding: 0 4px;
}
.buns-user .buns-msg-time { text-align: right; }

/* 5. Suggestion Chips */
.buns-chips-container {
  padding: 8px 16px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  background: rgba(0, 0, 0, 0.15);
}
.buns-chips-container::-webkit-scrollbar { display: none; }

.buns-chip-btn {
  white-space: nowrap;
  background: var(--bg-card, #1A1035);
  border: 1px solid var(--border-subtle, rgba(168, 85, 247, 0.25));
  color: var(--text-main, #FAF5FF);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.76rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
}

.buns-chip-btn:hover {
  border-color: var(--accent-orange, #A855F7);
  background: var(--bg-card-hover, #241748);
  transform: translateY(-1px);
}

/* 6. Product Recommendation Cards */
.buns-recs-wrap {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.buns-rec-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-surface, #110A24);
  border: 1px solid var(--border-subtle, rgba(168, 85, 247, 0.3));
  border-radius: var(--radius-md, 14px);
  padding: 10px;
  transition: all 0.2s ease;
}

.buns-rec-card:hover {
  border-color: var(--accent-orange, #A855F7);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}

.buns-rec-thumb {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  object-fit: cover;
  background: #000000;
  border: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.buns-rec-body {
  flex: 1;
  min-width: 0;
}

.buns-rec-title {
  font-family: var(--font-display, 'Chakra Petch', sans-serif);
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text-main, #FFFFFF);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.buns-rec-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
  font-size: 0.74rem;
}

.buns-rec-price {
  color: var(--accent-green, #10B981);
  font-weight: 800;
}

.buns-rec-cat {
  color: var(--text-muted, #C4B5FD);
}

.buns-rec-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.buns-btn-action {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text-main, #FFFFFF);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
}

.buns-btn-action:hover {
  background: var(--accent-orange, #A855F7);
  border-color: var(--accent-orange, #A855F7);
  color: #FFFFFF;
}

.buns-btn-cart {
  background: var(--button-color, #9333EA);
  border-color: var(--button-color, #9333EA);
}

/* 7. Citations & Grounding Section */
.buns-citations-box {
  margin-top: 8px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  border-left: 3px solid var(--accent-green, #06B6D4);
  font-size: 0.74rem;
}

.buns-citations-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted, #C4B5FD);
  font-weight: 700;
  margin-bottom: 4px;
}

.buns-citations-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.buns-citation-link {
  color: var(--accent-green, #06B6D4);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 5px;
}

.buns-citation-link:hover {
  text-decoration: underline;
}

/* 8. Typing Indicator */
.buns-typing-indicator {
  display: none;
  align-self: flex-start;
  background: var(--bg-card, #1A1035);
  border: 1px solid var(--border-subtle, rgba(168, 85, 247, 0.2));
  padding: 10px 16px;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  align-items: center;
  gap: 6px;
}

.buns-typing-indicator.is-active {
  display: flex;
}

.buns-dot {
  width: 6px;
  height: 6px;
  background: var(--accent-orange, #A855F7);
  border-radius: 50%;
  animation: bunsBounce 1.4s infinite ease-in-out both;
}

.buns-dot:nth-child(1) { animation-delay: -0.32s; }
.buns-dot:nth-child(2) { animation-delay: -0.16s; }
.buns-dot:nth-child(3) { animation-delay: 0s; }

@keyframes bunsBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40% { transform: scale(1.2); opacity: 1; }
}

/* 9. Input Form Area */
.buns-chat-input-wrap {
  padding: 12px 16px;
  background: var(--bg-surface, #110A24);
  border-top: 1px solid var(--border-subtle, rgba(168, 85, 247, 0.2));
}

.buns-chat-form {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card, #1A1035);
  border: 1.5px solid var(--border-subtle, rgba(168, 85, 247, 0.25));
  border-radius: var(--radius-md, 14px);
  padding: 4px 6px 4px 14px;
  transition: all 0.2s ease;
}

.buns-chat-form:focus-within {
  border-color: var(--accent-orange, #A855F7);
  box-shadow: 0 0 12px var(--accent-orange-glow, rgba(168, 85, 247, 0.3));
}

.buns-input-field {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main, #FFFFFF);
  font-size: 0.88rem;
  font-family: var(--font-body, 'Inter', sans-serif);
  padding: 6px 0;
}

.buns-input-field::placeholder {
  color: var(--text-muted, #C4B5FD);
  opacity: 0.7;
}

.buns-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--button-color, #9333EA);
  border: none;
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.buns-send-btn:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 12px var(--accent-orange-glow, rgba(168, 85, 247, 0.4));
}

.buns-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* 10. Responsive Mobile Layout */
@media (max-width: 640px) {
  .buns-chat-launcher {
    bottom: 78px;
    right: 16px;
    padding: 6px 12px 6px 8px;
  }

  .buns-launcher-subtitle {
    display: none;
  }

  .buns-chat-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 85vh;
    max-height: 85vh;
    border-radius: 20px 20px 0 0;
    border-bottom: none;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.7);
  }
}
