/* Chatbot widget — responsive, scoped under .chatbot to avoid leaking. */

.chatbot {
  --cb-primary: #2563eb;
  --cb-primary-strong: #1d4ed8;
  --cb-bg: #ffffff;
  --cb-text: #0f172a;
  --cb-muted: #64748b;
  --cb-border: #e2e8f0;
  --cb-bubble-user: #2563eb;
  --cb-bubble-bot: #f1f5f9;
  --cb-radius: 18px;
  --cb-shadow: 0 12px 36px rgba(15, 23, 42, 0.18);
  --cb-z: 2147483000;

  position: fixed;
  inset: auto;
  z-index: var(--cb-z);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--cb-text);
  line-height: 1.45;
}

.chatbot *,
.chatbot *::before,
.chatbot *::after {
  box-sizing: border-box;
}

/* ---------- Toggle button ---------- */
.chatbot__toggle {
  position: fixed;
  bottom: 85px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.4);
  transition: transform 200ms ease, background 200ms ease;
  z-index: var(--cb-z);
}

.chatbot__toggle:hover {
  background: var(--cb-primary-strong);
  transform: translateY(-2px);
  opacity: 0.6;
}

.chatbot__toggle:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.4);
  outline-offset: 2px;
}

.chatbot__icon {
  width: 26px;
  height: 26px;
}

.chatbot__icon-img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

/* ---------- Panel ---------- */
.chatbot__panel {
  position: fixed;
  bottom: 80px;
  right: 24px;
  width: 380px;
  height: 560px;
  max-height: calc(100vh - 120px);
  background: var(--cb-bg);
  border-radius: var(--cb-radius);
  box-shadow: var(--cb-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--cb-border);
  animation: chatbotIn 220ms cubic-bezier(0.16, 1, 0.3, 1);
}

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

/* ---------- Header ---------- */
.chatbot__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--cb-primary), var(--cb-primary-strong));
  color: #fff;
}

.chatbot__title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
}

.chatbot__dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.7);
  animation: chatbotDot 1.6s ease-out infinite;
}

@keyframes chatbotDot {
  0%   { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.6); }
  70%  { box-shadow: 0 0 0 8px rgba(74, 222, 128, 0); }
  100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}

.chatbot__close {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  padding: 0 6px;
  border-radius: 6px;
}

.chatbot__close:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* ---------- Messages area ---------- */
.chatbot__messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #fafbfc;
  scroll-behavior: smooth;
}

.chatbot__messages::-webkit-scrollbar {
  width: 6px;
}
.chatbot__messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

.chatbot__empty {
  color: var(--cb-muted);
  font-size: 14px;
  padding: 8px 4px;
}

.chatbot__empty ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.chatbot__empty li {
  margin: 4px 0;
}

.chatbot__chips {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.chatbot__chip {
  appearance: none;
  text-align: left;
  font: inherit;
  color: var(--cb-bot-fg, #1f2937);
  background: var(--cb-bot-bg, #f3f4f6);
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 14px;
  padding: 9px 12px;
  cursor: pointer;
  line-height: 1.35;
  transition: background 120ms ease, transform 120ms ease, border-color 120ms ease;
}

.chatbot__chip:hover {
  background: var(--cb-accent-bg, #eaf2ff);
  border-color: var(--cb-accent, #2563eb);
}

.chatbot__chip:active {
  transform: translateY(1px);
}

.chatbot__chip:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.chatbot__msg {
  display: flex;
  flex-direction: column;
  margin-bottom: 14px;
  max-width: 85%;
}

.chatbot__msg--user {
  margin-left: auto;
  align-items: flex-end;
}

.chatbot__msg--assistant {
  margin-right: auto;
  align-items: flex-start;
}

.chatbot__row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
}

.chatbot__msg--user .chatbot__row {
  justify-content: flex-end;
}

.chatbot__avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
  border: 1px solid var(--cb-border);
  flex: 0 0 32px;
  padding: 2px;
}

.chatbot__bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.chatbot__msg--user .chatbot__bubble {
  background: var(--cb-bubble-user);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chatbot__msg--assistant .chatbot__bubble {
  background: var(--cb-bubble-bot);
  color: var(--cb-text);
  border-bottom-left-radius: 4px;
}

.chatbot__typing {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  vertical-align: middle;
}

.chatbot__typing i {
  width: 6px;
  height: 6px;
  background: var(--cb-muted);
  border-radius: 50%;
  animation: chatbotDots 1.2s infinite ease-in-out both;
}

.chatbot__typing i:nth-child(2) { animation-delay: 0.15s; }
.chatbot__typing i:nth-child(3) { animation-delay: 0.3s; }

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

/* ---------- Product cards ---------- */
.chatbot__products {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.chatbot__product {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: #fff;
  border: 1px solid var(--cb-border);
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  transition: border-color 150ms ease, transform 150ms ease;
}

.chatbot__product:hover {
  border-color: var(--cb-primary);
  transform: translateY(-1px);
}

.chatbot__product img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 8px;
  flex: 0 0 44px;
  background: #f1f5f9;
}

.chatbot__product-body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  flex: 1 1 auto;
}

.chatbot__product-name {
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chatbot__product-price {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--cb-primary);
  margin-top: 1px;
}

/* ---------- Footer / input ---------- */
.chatbot__footer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--cb-border);
  background: #fff;
}

.chatbot__input {
  flex: 1 1 auto;
  /* min-width:0 lets the flex item shrink below its content width on
     mobile when the on-screen keyboard appears — without this, the
     textarea's intrinsic min-width pushes the footer (and the whole
     panel) past the viewport edge on focus. */
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
  resize: none;
  border: 1px solid var(--cb-border);
  border-radius: 14px;
  padding: 10px 12px;
  /* 16px+ on mobile to prevent iOS auto-zoom when input is focused. */
  font-size: 16px;
  font-family: inherit;
  line-height: 1.4;
  max-height: 120px;
  outline: none;
  background: #fff;
  color: var(--cb-text);
}

@media (min-width: 768px) {
  .chatbot__input {
    font-size: 14px;
  }
}

.chatbot__input:focus {
  border-color: var(--cb-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.chatbot__send {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--cb-primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 40px;
  transition: background 150ms ease, transform 150ms ease;
}

.chatbot__send:not(:disabled):hover {
  background: var(--cb-primary-strong);
  transform: scale(1.05);
}

.chatbot__send:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
}

.chatbot__send svg {
  width: 18px;
  height: 18px;
}

/* ---------- Mobile (<768px) ---------- */
@media (max-width: 767px) {
  .chatbot__toggle {
    bottom: calc(85px + env(safe-area-inset-bottom, 0px));
    right: 16px;
    width: 52px;
    height: 52px;
  }

  .chatbot__panel {
    /* Bottom-sheet style: panel hugs the bottom of the screen with a
       small gap at the top so the user can see / tap the page behind it.
       Uses dvh so the panel resizes when the on-screen keyboard opens. */
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    max-width: 100vw;
    /* 85% of dynamic viewport height — leaves ~15% gap at the top.
       Falls back to vh on older browsers. */
    height: 85vh;
    height: 85dvh;
    max-height: 85dvh;
    border-radius: 18px 18px 0 0;
    border: 0;
    box-sizing: border-box;
    overflow: hidden;
  }

  .chatbot__footer {
    /* Constrain footer to panel width — without this, a wide textarea
       on focus can push the footer past the right edge. */
    width: 100%;
    box-sizing: border-box;
    min-width: 0;
  }

  .chatbot__messages {
    /* Let the messages list shrink so the input stays visible above
       the keyboard (flexbox: header + messages + footer). */
    min-height: 0;
    flex: 1 1 auto;
    -webkit-overflow-scrolling: touch;
  }

  footer.chatbot__footer,
  .chatbot__panel > footer {
    /* Account for iOS home-indicator safe area. */
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }

  .chatbot__product {
    padding: 6px;
    gap: 7px;
  }

  .chatbot__product img {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    border-radius: 7px;
  }

  .chatbot__product-name,
  .chatbot__product-price {
    font-size: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chatbot__panel { animation: none; }
  .chatbot__dot   { animation: none; }
  .chatbot__typing i { animation: none; }
}
