/* ============================================
   Jewelry Chatbot Widget — Styles
   Design: Bordeaux & Rose — Bijouterie élégante
   Préfixe jw- sur toutes les classes/IDs
   ============================================ */

:root {
  --jw-accent: #692819;
  --jw-accent-hover: #551F13;
  --jw-accent-light: #FFF5F5;
  --jw-dark: #692819;
  --jw-dark-soft: #7A3322;
  --jw-bg: #ffffff;
  --jw-bg-light: #FFF5F5;
  --jw-text: #692819;
  --jw-text-light: #A08078;
  --jw-border: #F0DCDA;
  --jw-shadow: rgba(105, 40, 25, 0.10);
  --jw-radius: 20px;
}

/* Reset dans le scope du widget */
#jw-chatbot {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#jw-chatbot *,
#jw-chatbot *::before,
#jw-chatbot *::after {
  box-sizing: border-box;
  font-family: inherit;
  -webkit-font-smoothing: antialiased;
}

/* ---- Bulle flottante ---- */
#jw-chatbot {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 99999;
}

#jw-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--jw-dark);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 56px;
  height: 56px;
  padding: 0;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.22);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#jw-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.24);
  background: var(--jw-dark-soft);
}

#jw-toggle svg {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
}

#jw-toggle.jw-hidden {
  display: none;
}

/* ---- Fenêtre de chat ---- */
#jw-window {
  display: none;
  flex-direction: column;
  width: 400px;
  height: 580px;
  background: var(--jw-bg);
  border-radius: var(--jw-radius);
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.14), 0 0 0 1px rgba(0, 0, 0, 0.04);
  overflow: hidden;
  position: fixed;
  bottom: 24px;
  right: 24px;
  animation: jw-slide-up 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

#jw-window.jw-open {
  display: flex;
}

@keyframes jw-slide-up {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ---- Header ---- */
#jw-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background: var(--jw-dark);
  color: white;
  flex-shrink: 0;
}

#jw-header .jw-header-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.jw-online-dot {
  width: 8px;
  height: 8px;
  background: #34D399;
  border-radius: 50%;
  flex-shrink: 0;
}

#jw-close {
  background: none;
  border: none;
  color: white;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  opacity: 0.5;
  transition: opacity 0.2s;
}

#jw-close:hover {
  opacity: 1;
}

/* ---- Zone messages ---- */
#jw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--jw-bg-light);
}

#jw-messages::-webkit-scrollbar {
  width: 3px;
}

#jw-messages::-webkit-scrollbar-thumb {
  background: #D0CCC5;
  border-radius: 3px;
}

/* ---- Bulles de message ---- */
.jw-message {
  max-width: 82%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.55;
  animation: jw-fade-in 0.3s ease-out;
  word-wrap: break-word;
}

@keyframes jw-fade-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.jw-message-assistant {
  align-self: flex-start;
  background: var(--jw-bg);
  color: var(--jw-text);
  border: 1px solid var(--jw-border);
  border-bottom-left-radius: 6px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.jw-message-user {
  align-self: flex-end;
  background: var(--jw-dark);
  color: #fff;
  border-bottom-right-radius: 6px;
}

/* ---- Cartes produits ---- */
.jw-products-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 85%;
  align-self: flex-start;
}

.jw-product-card {
  display: flex;
  gap: 12px;
  background: var(--jw-bg);
  border: 1px solid var(--jw-border);
  border-radius: 14px;
  padding: 12px;
  max-width: 290px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  animation: jw-fade-in 0.3s ease-out both;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}

.jw-product-card:nth-child(2) { animation-delay: 0.1s; }
.jw-product-card:nth-child(3) { animation-delay: 0.2s; }

.jw-product-card:hover {
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
  transform: translateY(-2px);
  border-color: var(--jw-accent);
}

.jw-product-img {
  width: 72px;
  height: 72px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--jw-bg-light);
}

.jw-product-img-placeholder {
  width: 72px;
  height: 72px;
  border-radius: 10px;
  background: var(--jw-bg-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--jw-accent);
  font-size: 24px;
}

.jw-product-info {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  min-width: 0;
}

.jw-product-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--jw-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.jw-product-price {
  font-size: 14px;
  font-weight: 700;
  color: var(--jw-accent);
}

.jw-product-old-price {
  font-size: 12px;
  color: var(--jw-text-light);
  text-decoration: line-through;
  margin-left: 4px;
}

.jw-product-link {
  font-size: 12px;
  color: var(--jw-accent);
  text-decoration: none;
  font-weight: 500;
}

.jw-product-link:hover {
  text-decoration: underline;
}

/* ---- Quick replies ---- */
.jw-quick-replies {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  max-width: 90%;
  align-self: flex-start;
  margin-top: 2px;
  animation: jw-fade-in 0.3s ease-out 0.15s both;
}

.jw-quick-reply {
  background: var(--jw-bg);
  border: 1.5px solid var(--jw-border);
  color: var(--jw-text);
  border-radius: 50px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  line-height: 1.3;
}

.jw-quick-reply:hover {
  background: var(--jw-dark);
  border-color: var(--jw-dark);
  color: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

/* ---- Zone input ---- */
#jw-input-area {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--jw-border);
  background: var(--jw-bg);
  flex-shrink: 0;
}

#jw-input {
  flex: 1;
  border: 1px solid var(--jw-border);
  border-radius: 50px;
  padding: 10px 18px;
  font-size: 16px; /* 16px minimum pour empêcher le zoom iOS */
  outline: none;
  transition: border-color 0.2s;
  color: var(--jw-text);
  background: var(--jw-bg-light);
  -webkit-appearance: none;
  touch-action: manipulation;
}

#jw-input::placeholder {
  color: var(--jw-text-light);
}

#jw-input:focus {
  border-color: var(--jw-accent);
  background: var(--jw-bg);
}

#jw-input:disabled {
  opacity: 0.6;
}

#jw-send {
  background: var(--jw-dark);
  color: white;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

#jw-send:hover {
  background: var(--jw-accent);
}

#jw-send:active {
  transform: scale(0.95);
}

#jw-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#jw-send svg {
  width: 17px;
  height: 17px;
}

/* ---- Error message ---- */
.jw-error {
  font-size: 12px;
  color: var(--jw-text-light);
  font-style: italic;
  text-align: center;
  padding: 8px;
}

/* ---- Responsive : plein écran sur mobile ---- */
@media (max-width: 480px) {
  #jw-window {
    width: 100vw !important;
    /* Hauteur : 100dvh s'adapte automatiquement au clavier iOS 15+ */
    height: 100vh !important;
    height: 100dvh !important;
    top: 0 !important;
    left: 0 !important;
    right: auto !important;
    bottom: auto !important;
    border-radius: 0;
    max-height: none;
  }

  #jw-header {
    flex-shrink: 0;
  }

  #jw-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  #jw-input-area {
    flex-shrink: 0;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }

  #jw-chatbot {
    bottom: 14px;
    right: 14px;
  }

  .jw-product-card {
    max-width: 100%;
  }

  body.jw-chat-open {
    overflow: hidden !important;
  }
}
