/* ============================================================
   WP AI Advisor — Chat Widget Stylesheet
   Design: Premium floating chat with product cards
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ── Widget Root ── */
.wapa-chat-widget {
  --wapa-primary:   #6366f1;
  --wapa-accent:    #818cf8;
  --wapa-bg:        #ffffff;
  --wapa-surface:   #f8f9fc;
  --wapa-border:    #e8eaf2;
  --wapa-text:      #1a1d2e;
  --wapa-text-sub:  #7c8098;
  --wapa-user-bg:   var(--wapa-primary);
  --wapa-user-text: #ffffff;
  --wapa-shadow:    0 20px 60px rgba(0,0,0,0.15), 0 4px 12px rgba(0,0,0,0.08);

  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  position: fixed;
  z-index: 99999;
  bottom: 24px;
  right: 24px;
}

.wapa-chat-widget.wapa-position--bottom-left { right: auto; left: 24px; }

/* Inline mode */
.wapa-chat-widget--inline {
  position: relative;
  bottom: auto;
  right: auto;
  left: auto;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: block;
}

.wapa-chat-widget--inline .wapa-chat-window {
  position: relative;
  bottom: auto;
  right: auto;
  transform: none;
  opacity: 1;
  pointer-events: all;
  width: 100%;
  max-height: 600px;
  border-radius: 16px;
}

/* ── Toggle Button ── */
.wapa-chat-toggle {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--wapa-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2), 0 0 0 0 var(--wapa-primary);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
  z-index: 1;
}

.wapa-chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 12px 32px rgba(0,0,0,0.25), 0 0 0 0 var(--wapa-primary);
}

.wapa-chat-toggle svg { width: 24px; height: 24px; color: #fff; transition: all 0.2s ease; }

.wapa-chat-toggle__icon { position: absolute; transition: all 0.2s ease; }
.wapa-chat-toggle__icon--close { opacity: 0; transform: rotate(-90deg) scale(0.5); }
.wapa-chat-toggle__icon--open  { opacity: 1; transform: rotate(0) scale(1); }

.wapa-chat-widget.wapa-is-open .wapa-chat-toggle__icon--open  { opacity: 0; transform: rotate(90deg) scale(0.5); }
.wapa-chat-widget.wapa-is-open .wapa-chat-toggle__icon--close { opacity: 1; transform: rotate(0) scale(1); }

/* Pulse animation */
.wapa-chat-toggle__pulse {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--wapa-primary);
  opacity: 0;
  animation: wapa-pulse 2.5s ease-out infinite;
}

@keyframes wapa-pulse {
  0%   { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(1.5); opacity: 0; }
}

/* ── Chat Window ── */
.wapa-chat-window {
  position: absolute;
  bottom: calc(100% + 16px);
  right: 0;
  width: 360px;
  max-height: 580px;
  background: var(--wapa-bg);
  border-radius: 20px;
  box-shadow: var(--wapa-shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform-origin: bottom right;
  transform: scale(0.92) translateY(12px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1), opacity 0.2s ease;
  border: 1px solid var(--wapa-border);
}

.wapa-position--bottom-left .wapa-chat-window {
  right: auto;
  left: 0;
  transform-origin: bottom left;
}

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

/* ── Header ── */
.wapa-chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: linear-gradient(135deg, var(--wapa-primary), var(--wapa-accent));
  position: relative;
  overflow: hidden;
}

.wapa-chat-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60'%3E%3Ccircle cx='30' cy='30' r='20' fill='none' stroke='white' stroke-width='0.5' opacity='0.1'/%3E%3C/svg%3E") center/60px;
}

.wapa-chat-header__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  border: 2px solid rgba(255,255,255,0.3);
  overflow: hidden;
}

.wapa-chat-header__avatar img { width: 100%; height: 100%; object-fit: cover; }
.wapa-chat-header__avatar span { font-size: 16px; font-weight: 700; color: #fff; }

.wapa-status-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 10px;
  height: 10px;
  background: #22c55e;
  border-radius: 50%;
  border: 2px solid white;
}

.wapa-chat-header__info {
  flex: 1;
  min-width: 0;
}

.wapa-chat-header__info strong {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wapa-chat-header__info small {
  font-size: 11px;
  color: rgba(255,255,255,0.75);
}

.wapa-chat-close {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: none;
  background: rgba(255,255,255,0.15);
  backdrop-filter: blur(4px);
  color: rgba(255,255,255,0.9);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}

.wapa-chat-close svg { width: 14px; height: 14px; }
.wapa-chat-close:hover { background: rgba(255,255,255,0.25); }

/* ── Messages ── */
.wapa-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  background: var(--wapa-surface);
}

.wapa-chat-messages::-webkit-scrollbar { width: 4px; }
.wapa-chat-messages::-webkit-scrollbar-track { background: transparent; }
.wapa-chat-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 99px; }

/* ── Individual Message ── */
.wapa-message {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: wapa-msg-in 0.25s ease;
}

@keyframes wapa-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.wapa-message--user {
  flex-direction: row-reverse;
}

.wapa-message__avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--wapa-primary), var(--wapa-accent));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.wapa-message__avatar img { width: 100%; height: 100%; object-fit: cover; }
.wapa-message__avatar span { font-size: 11px; font-weight: 700; color: #fff; }

.wapa-message--user .wapa-message__avatar { display: none; }

.wapa-message__bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--wapa-text);
  background: var(--wapa-bg);
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  border: 1px solid var(--wapa-border);
}

.wapa-message--user .wapa-message__bubble {
  background: var(--wapa-primary);
  color: #fff;
  border: none;
  border-radius: 18px 18px 4px 18px;
  box-shadow: 0 4px 12px rgba(99,102,241,0.3);
}

.wapa-message--bot .wapa-message__bubble {
  border-radius: 18px 18px 18px 4px;
}

.wapa-message__bubble p { margin: 0; }

/* Typing indicator */
.wapa-message__bubble--typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 14px 16px;
}

.wapa-message__bubble--typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--wapa-text-sub);
  animation: wapa-typing 1.2s ease infinite;
}

.wapa-message__bubble--typing span:nth-child(2) { animation-delay: 0.2s; }
.wapa-message__bubble--typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes wapa-typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ── Product Cards ── */
.wapa-products-wrap {
  margin-top: 8px;
  animation: wapa-msg-in 0.3s ease;
}

.wapa-products-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--wapa-text-sub);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  padding: 0 4px;
}

.wapa-products-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.wapa-product-card {
  background: var(--wapa-bg);
  border: 1px solid var(--wapa-border);
  border-radius: 14px;
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.wapa-product-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.1);
}

.wapa-product-card__img {
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--wapa-surface);
}

.wapa-product-card__img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.wapa-product-card:hover .wapa-product-card__img img { transform: scale(1.05); }

.wapa-product-card__body { padding: 10px; }

.wapa-product-card__title {
  font-size: 12px;
  font-weight: 600;
  color: var(--wapa-text);
  margin: 0 0 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.35;
}

.wapa-product-card__price {
  font-size: 13px;
  font-weight: 700;
  color: var(--wapa-primary);
  margin-bottom: 8px;
}

.wapa-product-card__price .sale { color: #ef4444; }
.wapa-product-card__price del { opacity: 0.5; font-size: 11px; font-weight: 400; }

.wapa-product-card__actions {
  display: flex;
  gap: 5px;
}

.wapa-product-btn {
  flex: 1;
  padding: 6px 8px;
  border-radius: 8px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all 0.15s;
  border: none;
  white-space: nowrap;
}

.wapa-product-btn--cart {
  background: var(--wapa-primary);
  color: #fff;
}

.wapa-product-btn--cart:hover {
  background: var(--wapa-accent);
  color: #fff;
}

.wapa-product-btn--view {
  background: var(--wapa-surface);
  color: var(--wapa-text);
  border: 1px solid var(--wapa-border);
}

.wapa-product-btn--view:hover {
  background: var(--wapa-border);
  color: var(--wapa-text);
}

.wapa-product-btn svg { width: 12px; height: 12px; flex-shrink: 0; }

/* Sale badge */
.wapa-product-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  background: #ef4444;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.wapa-product-card__img { position: relative; }

/* ── Input Area ── */
.wapa-chat-input-area {
  border-top: 1px solid var(--wapa-border);
  background: var(--wapa-bg);
  padding: 12px 14px 10px;
}

.wapa-chat-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--wapa-surface);
  border: 1.5px solid var(--wapa-border);
  border-radius: 14px;
  padding: 8px 8px 8px 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.wapa-chat-input-wrap:focus-within {
  border-color: var(--wapa-primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}

.wapa-chat-input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  color: var(--wapa-text);
  resize: none;
  outline: none;
  line-height: 1.5;
  max-height: 100px;
  min-height: 20px;
  overflow-y: auto;
  padding: 0;
}

.wapa-chat-input::placeholder { color: var(--wapa-text-sub); }

.wapa-chat-send {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--wapa-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
  color: #fff;
}

.wapa-chat-send:hover { background: var(--wapa-accent); transform: scale(1.05); }
.wapa-chat-send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.wapa-chat-send svg { width: 14px; height: 14px; }

.wapa-chat-footer {
  text-align: center;
  font-size: 10px;
  color: var(--wapa-text-sub);
  margin: 6px 0 0;
  opacity: 0.6;
}

/* ── Responsive ── */
@media (max-width: 480px) {
  .wapa-chat-widget {
    bottom: 16px;
    right: 16px;
  }

  .wapa-chat-window {
    width: calc(100vw - 32px);
    max-height: 70vh;
  }
}

/* ── Intent indicator ── */
.wapa-intent-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 600;
  margin-bottom: 4px;
  background: rgba(99,102,241,0.1);
  color: var(--wapa-primary);
  letter-spacing: 0.3px;
}

/* ═══════════════════════════════════════════════════════
   SLIDER MODE
   The bubble button is identical to floating mode.
   The chat panel lives outside the widget as a fixed
   full-height drawer injected by JS into <body>.
   ═══════════════════════════════════════════════════════ */

/* The widget itself stays exactly like floating — just a bubble */
.wapa-chat-widget--slider {
  /* inherits all floating styles — no overrides needed */
}

/* The drawer panel — injected as .wapa-slider-panel into <body> by JS */
.wapa-slider-panel {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 380px;
  max-width: 92vw;
  background: var(--wapa-bg, #fff);
  box-shadow: -8px 0 40px rgba(0,0,0,.18);
  display: flex;
  flex-direction: column;
  z-index: 999998;
  transition: transform .32s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
}

/* Right drawer (default) */
.wapa-slider-panel--right {
  right: 0;
  left: auto;
  transform: translateX(100%);
  border-radius: 16px 0 0 16px;
}

/* Left drawer */
.wapa-slider-panel--left {
  left: 0;
  right: auto;
  transform: translateX(-100%);
  border-radius: 0 16px 16px 0;
  box-shadow: 8px 0 40px rgba(0,0,0,.18);
}

/* Open state */
.wapa-slider-panel.wapa-is-open {
  transform: translateX(0);
}

/* Overlay */
.wapa-slider-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 999997;
  cursor: pointer;
  backdrop-filter: blur(2px);
}
.wapa-slider-overlay.active { display: block; }

/* The slider panel reuses all .wapa-chat-* inner elements */
.wapa-slider-panel .wapa-chat-header   { flex-shrink: 0; }
.wapa-slider-panel .wapa-chat-messages { flex: 1; overflow-y: auto; }
.wapa-slider-panel .wapa-chat-footer   { flex-shrink: 0; }

/* close btn in slider header */
.wapa-slider-close {
  background: none;
  border: none;
  color: rgba(255,255,255,.85);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  transition: color .2s, background .2s;
  margin-left: auto;
  flex-shrink: 0;
}
.wapa-slider-close:hover { color: #fff; background: rgba(255,255,255,.2); }
.wapa-slider-close svg   { width: 20px; height: 20px; }

/* Open/close icon swap — same as floating but uses wapa-is-open on widget */
.wapa-chat-widget--slider.wapa-is-open .wapa-chat-toggle__icon--open  { opacity: 0; transform: rotate(90deg) scale(0.5); }
.wapa-chat-widget--slider.wapa-is-open .wapa-chat-toggle__icon--close { opacity: 1; transform: rotate(0) scale(1); }

@media (max-width: 480px) {
  .wapa-slider-panel { width: 100vw; border-radius: 0; }
}
