/* ==========================================================================
   C&E Worldwide - Chatbot Assistant Widget Styles (Level 2)
   ========================================================================== */

:root {
  --ce-chat-brand: #002147;
  --ce-chat-brand-dark: #001737;
  --ce-chat-accent: #76b82a;
  --ce-chat-accent-hover: #65a121;
  --ce-chat-surface: #f4f7f8;
  --ce-chat-white: #ffffff;
  --ce-chat-border: #d5e0e6;
  --ce-chat-ink: #002147;
  --ce-chat-ink-soft: #4a6382;
  --ce-chat-shadow: 0 16px 40px rgba(0, 33, 71, 0.22);
  --ce-chat-radius: 20px;
}

/* === Trigger Button === */
.ce-chatbot-trigger {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background-color: var(--ce-chat-brand);
  color: var(--ce-chat-white);
  border: 2px solid var(--ce-chat-accent);
  box-shadow: 0 8px 24px rgba(0, 33, 71, 0.28);
  z-index: 9998;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.2s ease, box-shadow 0.2s ease;
  padding: 0;
  outline: none;
}

.ce-chatbot-trigger:hover {
  transform: scale(1.08);
  background-color: var(--ce-chat-brand-dark);
  box-shadow: 0 12px 28px rgba(0, 33, 71, 0.35);
}

.ce-chatbot-trigger:focus-visible {
  outline: 3px solid var(--ce-chat-accent);
  outline-offset: 3px;
}

.ce-chatbot-trigger__icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ce-chatbot-trigger__icon svg {
  width: 100%;
  height: 100%;
}

.ce-chatbot-trigger__badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  background-color: var(--ce-chat-accent);
  color: var(--ce-chat-white);
  font-size: 11px;
  font-weight: 700;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--ce-chat-brand);
}

/* === Chat Window === */
.ce-chatbot-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 390px;
  max-width: calc(100vw - 32px);
  height: min(560px, 80dvh);
  max-height: calc(100vh - 110px);
  background-color: var(--ce-chat-white);
  border-radius: var(--ce-chat-radius);
  box-shadow: var(--ce-chat-shadow);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--ce-chat-border);
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.ce-chatbot-window.is-active {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* === Header === */
.ce-chatbot-header {
  background-color: var(--ce-chat-brand);
  color: var(--ce-chat-white);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid var(--ce-chat-accent);
}

.ce-chatbot-header__info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ce-chatbot-avatar {
  width: 40px;
  height: 40px;
  background-color: var(--ce-chat-white);
  border: 1.5px solid var(--ce-chat-accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}

.ce-chatbot-avatar__logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.ce-chatbot-title {
  margin: 0;
  font-size: 14.5px;
  font-weight: 700;
  color: var(--ce-chat-white);
  line-height: 1.2;
}

.ce-chatbot-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.85);
  margin-top: 2px;
}

.ce-chatbot-status__dot {
  width: 7px;
  height: 7px;
  background-color: #25d366;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 6px rgba(37, 211, 102, 0.6);
}

.ce-chatbot-header__actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ce-chatbot-clear,
.ce-chatbot-close {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, color 0.2s ease;
  padding: 0;
}

.ce-chatbot-clear:hover,
.ce-chatbot-close:hover {
  background-color: rgba(255, 255, 255, 0.15);
  color: var(--ce-chat-white);
}

.ce-chatbot-clear:focus-visible,
.ce-chatbot-close:focus-visible {
  outline: 2px solid var(--ce-chat-accent);
}

.ce-chatbot-clear svg,
.ce-chatbot-close svg {
  width: 18px;
  height: 18px;
}

/* === Body / Messages Container === */
.ce-chatbot-body {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  background-color: var(--ce-chat-surface);
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

/* Message Styles & Card Types */
.ce-chatbot-msg {
  max-width: 90%;
  padding: 12px 14px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.45;
  white-space: pre-line;
  word-break: break-word;
  animation: ceChatMsgFade 0.2s ease forwards;
}

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

.ce-chatbot-msg--bot {
  align-self: flex-start;
  background-color: var(--ce-chat-white);
  color: var(--ce-chat-ink);
  border: 1px solid var(--ce-chat-border);
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 33, 71, 0.04);
}

.ce-chatbot-msg--info {
  border-left: 3px solid #002147;
}

.ce-chatbot-msg--success {
  border-left: 3px solid #76b82a;
}

.ce-chatbot-msg--help {
  border-left: 3px solid #365172;
}

.ce-chatbot-msg--warning {
  border-left: 3px solid #e67e22;
}

.ce-chatbot-msg--user {
  align-self: flex-end;
  background-color: var(--ce-chat-brand);
  color: var(--ce-chat-white);
  border-bottom-right-radius: 4px;
}

.ce-chatbot-msg__link,
.ce-chatbot-msg__wa-btn,
.ce-chatbot-msg__call-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  max-width: 100%;
  min-height: 34px;
  margin-top: 10px;
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none !important;
}

.ce-chatbot-msg__link {
  border: 1px solid var(--ce-chat-border);
  background-color: var(--ce-chat-white);
  color: var(--ce-chat-brand) !important;
}

.ce-chatbot-msg__wa-btn {
  background-color: #25d366;
  color: #ffffff !important;
}

.ce-chatbot-msg__call-btn {
  background-color: var(--ce-chat-brand);
  color: var(--ce-chat-white) !important;
}

.ce-chatbot-phone-number {
  margin: 6px 0 0;
  color: var(--ce-chat-brand-dark);
  font-size: 14px;
  font-weight: 800;
  user-select: text;
}

/* Typing Indicator Dots */
.ce-chatbot-typing {
  align-self: flex-start;
  background-color: var(--ce-chat-white);
  border: 1px solid var(--ce-chat-border);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.ce-chatbot-typing__dot {
  width: 6px;
  height: 6px;
  background-color: var(--ce-chat-ink-soft);
  border-radius: 50%;
  animation: ceTypingBlink 1.2s infinite ease-in-out both;
}

.ce-chatbot-typing__dot:nth-child(1) { animation-delay: 0s; }
.ce-chatbot-typing__dot:nth-child(2) { animation-delay: 0.2s; }
.ce-chatbot-typing__dot:nth-child(3) { animation-delay: 0.4s; }

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

/* === Level 2: Product Cards inside Chatbot === */
.ce-chatbot-products-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
  width: 100%;
}

.ce-chatbot-product-card {
  background-color: var(--ce-chat-white);
  border: 1px solid var(--ce-chat-border);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 2px 6px rgba(0, 33, 71, 0.05);
}

.ce-chatbot-product-card__header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ce-chatbot-product-card__thumb {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  background-color: var(--ce-chat-surface);
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--ce-chat-border);
}

.ce-chatbot-product-card__thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.ce-chatbot-product-card__thumb-fallback {
  font-size: 10px;
  font-weight: 700;
  color: var(--ce-chat-ink-soft);
  text-align: center;
}

.ce-chatbot-product-card__info {
  flex: 1;
  min-width: 0;
}

.ce-chatbot-product-card__title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--ce-chat-brand);
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ce-chatbot-product-card__meta {
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--ce-chat-ink-soft);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ce-chatbot-product-card__meta-item {
  background-color: var(--ce-chat-surface);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid #e2ebee;
}

.ce-chatbot-product-card__actions {
  display: flex;
  gap: 6px;
  margin-top: 2px;
}

.ce-chatbot-btn {
  flex: 1;
  padding: 7px 10px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  text-decoration: none !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: background-color 0.2s ease, transform 0.15s ease;
  text-align: center;
}

.ce-chatbot-btn--detail {
  background-color: var(--ce-chat-brand);
  color: var(--ce-chat-white) !important;
}

.ce-chatbot-btn--detail:hover {
  background-color: var(--ce-chat-brand-dark);
}

.ce-chatbot-btn--inquiry {
  background-color: var(--ce-chat-surface);
  color: var(--ce-chat-brand) !important;
  border: 1px solid var(--ce-chat-border);
}

.ce-chatbot-btn--inquiry:hover {
  background-color: #e7f1f4;
}

.ce-chatbot-btn--wa {
  background-color: #25d366;
  color: #ffffff !important;
}

.ce-chatbot-btn--wa:hover {
  background-color: #1eb857;
}

.ce-chatbot-load-more {
  background-color: var(--ce-chat-surface);
  color: var(--ce-chat-brand);
  border: 1px solid var(--ce-chat-border);
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  align-self: center;
  margin-top: 4px;
  transition: all 0.2s ease;
}

.ce-chatbot-load-more:hover {
  background-color: var(--ce-chat-brand);
  color: var(--ce-chat-white);
}

/* Quick Options Chips */
.ce-chatbot-options-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}

.ce-chatbot-options-title {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ce-chat-ink-soft);
  margin-bottom: 2px;
}

.ce-chatbot-options-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ce-chatbot-chip {
  background-color: var(--ce-chat-white);
  color: var(--ce-chat-brand);
  border: 1px solid var(--ce-chat-border);
  padding: 7px 11px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  outline: none;
  text-align: left;
}

.ce-chatbot-chip:hover {
  background-color: var(--ce-chat-brand);
  color: var(--ce-chat-white);
  border-color: var(--ce-chat-brand);
  transform: translateY(-1px);
}

.ce-chatbot-chip:focus-visible {
  outline: 2px solid var(--ce-chat-accent);
}

/* === Footer & Live Suggestions Wrapper === */
.ce-chatbot-footer-wrapper {
  position: relative;
  background-color: var(--ce-chat-white);
}

.ce-chatbot-suggestions {
  position: absolute;
  bottom: 100%;
  left: 12px;
  right: 12px;
  background-color: var(--ce-chat-white);
  border: 1px solid var(--ce-chat-border);
  border-radius: 12px;
  box-shadow: 0 -8px 24px rgba(0, 33, 71, 0.12);
  margin-bottom: 6px;
  max-height: 170px;
  overflow-y: auto;
  z-index: 10500;
  display: flex;
  flex-direction: column;
}

.ce-chatbot-suggestion-item {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 9px 14px;
  font-size: 12.5px;
  color: var(--ce-chat-ink);
  cursor: pointer;
  transition: background-color 0.15s ease;
  border-bottom: 1px solid var(--ce-chat-surface);
}

.ce-chatbot-suggestion-item__thumb {
  width: 38px;
  height: 38px;
  border-radius: 6px;
  background-color: var(--ce-chat-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.ce-chatbot-suggestion-item__thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.ce-chatbot-suggestion-item__text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ce-chatbot-suggestion-item__label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.ce-chatbot-suggestion-item__category,
.ce-chatbot-suggestion-item__variant {
  flex: 0 0 auto;
  color: var(--ce-chat-muted);
  font-size: 11.5px;
  font-weight: 500;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ce-chatbot-suggestion-item:last-child {
  border-bottom: none;
}

.ce-chatbot-suggestion-item:hover,
.ce-chatbot-suggestion-item.is-selected {
  background-color: var(--ce-chat-surface);
  color: var(--ce-chat-brand);
  font-weight: 600;
}

.ce-chatbot-suggestion-item:hover .ce-chatbot-suggestion-item__category,
.ce-chatbot-suggestion-item.is-selected .ce-chatbot-suggestion-item__category {
  color: var(--ce-chat-brand);
}

.ce-chatbot-footer {
  padding: 12px 14px;
  background-color: var(--ce-chat-white);
  border-top: 1px solid var(--ce-chat-border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.ce-chatbot-input {
  flex: 1;
  border: 1px solid var(--ce-chat-border);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13.5px;
  color: var(--ce-chat-ink);
  background-color: var(--ce-chat-surface);
  outline: none;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.ce-chatbot-input:focus {
  border-color: var(--ce-chat-brand);
  background-color: var(--ce-chat-white);
}

.ce-chatbot-send-btn {
  width: 40px;
  height: 40px;
  background-color: var(--ce-chat-brand);
  color: var(--ce-chat-white);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, transform 0.15s ease;
  padding: 0;
  flex-shrink: 0;
}

.ce-chatbot-send-btn:hover {
  background-color: var(--ce-chat-brand-dark);
  transform: scale(1.04);
}

.ce-chatbot-send-btn:focus-visible {
  outline: 2px solid var(--ce-chat-accent);
}

.ce-chatbot-send-btn svg {
  width: 18px;
  height: 18px;
  transform: translateX(1px);
}

/* Highlighted product card when deep-linked from chatbot */
.products-catalog-card.ce-highlight-product,
.product-catalog-card.ce-highlight-product {
  animation: ceProductHighlight 2s ease forwards;
}

@keyframes ceProductHighlight {
  0% { box-shadow: 0 0 0 4px var(--ce-chat-accent); transform: scale(1.02); }
  70% { box-shadow: 0 0 0 4px var(--ce-chat-accent); transform: scale(1); }
  100% { box-shadow: none; transform: scale(1); }
}

/* === Accessibility: Reduced Motion === */
@media (prefers-reduced-motion: reduce) {
  .ce-chatbot-trigger,
  .ce-chatbot-window,
  .ce-chatbot-msg,
  .ce-chatbot-chip,
  .ce-chatbot-typing__dot,
  .products-catalog-card.ce-highlight-product,
  .product-catalog-card.ce-highlight-product {
    transition: none !important;
    animation: none !important;
  }
}

/* === Responsive adjustments === */
@media (max-width: 480px) {
  .ce-chatbot-trigger {
    bottom: 76px;
    right: 16px;
    width: 52px;
    height: 52px;
  }

  .ce-chatbot-window {
    bottom: 16px;
    right: 10px;
    left: 10px;
    width: auto;
    max-width: none;
    height: min(560px, 85dvh);
    max-height: calc(100vh - 80px);
    z-index: 10001;
  }
}

@media (max-width: 360px) {
  .ce-chatbot-header {
    padding: 10px 12px;
  }
  .ce-chatbot-title {
    font-size: 13.5px;
  }
  .ce-chatbot-avatar {
    width: 32px;
    height: 32px;
    font-size: 11px;
  }
}
