/* AI Widget - Minichiello Gianpiero */
#ai-widget-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #2d6a4f;
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 26px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}
#ai-widget-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(0,0,0,0.32);
}
#ai-widget-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 360px;
  height: 520px;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.22);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  background: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  transition: opacity 0.2s, transform 0.2s;
}
#ai-widget-window.ai-hidden {
  display: none;
}
#ai-widget-header {
  background: #2d6a4f;
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
#ai-widget-header-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
#ai-widget-close {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 0 2px;
  opacity: 0.85;
}
#ai-widget-close:hover { opacity: 1; }
#ai-widget-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f8faf8;
}
.ai-msg {
  max-width: 82%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}
.ai-msg-user {
  align-self: flex-end;
  background: #2d6a4f;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ai-msg-ai {
  align-self: flex-start;
  background: #e9f0eb;
  color: #1a2e22;
  border-bottom-left-radius: 4px;
}
/* Bouncing dots typing indicator */
.ai-typing-dots {
  align-self: flex-start;
  display: flex;
  gap: 5px;
  align-items: center;
  background: #e9f0eb;
  padding: 12px 16px;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
.ai-typing-dots span {
  width: 8px;
  height: 8px;
  background: #5a7a65;
  border-radius: 50%;
  display: block;
  animation: ai-typing-bounce 1.2s infinite ease-in-out;
}
.ai-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-7px); }
}
/* ── Tooltip fumetto ── */
#ai-tooltip-bubble {
  position: fixed;
  z-index: 99998;
  background: white;
  border-radius: 14px;
  padding: 12px 32px 12px 14px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15), 0 1px 4px rgba(0,0,0,0.1);
  max-width: 200px;
  min-width: 170px;
  border: 1.5px solid #e8f5e9;
  opacity: 0;
  transform: scale(0.85);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}
#ai-tooltip-bubble.ai-tooltip-visible {
  opacity: 1;
  transform: scale(1);
  pointer-events: all;
}
#ai-tooltip-bubble.ai-tooltip-hiding {
  opacity: 0;
  transform: scale(0.85);
  pointer-events: none;
}
#ai-tooltip-bubble p {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: #1a1a1a;
}
#ai-tooltip-bubble strong {
  color: #2d6a4f;
}
#ai-tooltip-close {
  position: absolute;
  top: 6px;
  right: 8px;
  background: none;
  border: none;
  font-size: 11px;
  color: #999;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
}
#ai-tooltip-close:hover { color: #333; }
.ai-tooltip-arrow {
  position: absolute;
  width: 0;
  height: 0;
  top: 50%;
  transform: translateY(-50%);
}
.ai-tooltip-arrow.arrow-right {
  right: -10px;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-left: 10px solid white;
}
.ai-tooltip-arrow.arrow-right::before {
  content: '';
  position: absolute;
  right: 1px;
  top: -9px;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  border-left: 11px solid #e8f5e9;
  z-index: -1;
}
.ai-tooltip-arrow.arrow-left {
  left: -10px;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-right: 10px solid white;
}
.ai-tooltip-arrow.arrow-left::before {
  content: '';
  position: absolute;
  left: 1px;
  top: -9px;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  border-right: 11px solid #e8f5e9;
  z-index: -1;
}
@media (max-width: 480px) {
  #ai-tooltip-bubble { max-width: 175px; font-size: 12px; }
}

.ai-contact-buttons {
  display: flex;
  gap: 8px;
  margin: 10px 0 4px 0;
  flex-wrap: wrap;
}
.ai-contact-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 25px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none !important;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  flex: 1;
  justify-content: center;
  min-width: 120px;
}
.ai-whatsapp-btn {
  background: #25D366;
  color: white !important;
}
.ai-whatsapp-btn:hover {
  background: #1ebe5d;
  transform: translateY(-1px);
}
.ai-phone-btn {
  background: #2d6a4f;
  color: white !important;
}
.ai-phone-btn:hover {
  background: #1e4d38;
  transform: translateY(-1px);
}

#ai-widget-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: #fff;
  border-top: 1px solid #e0e8e2;
  flex-shrink: 0;
}
#ai-widget-input {
  flex: 1;
  border: 1.5px solid #c5d9cc;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13.5px;
  outline: none;
  resize: none;
  font-family: inherit;
  color: #1a2e22;
  background: #f8faf8;
  line-height: 1.4;
}
#ai-widget-input:focus {
  border-color: #2d6a4f;
  background: #fff;
}
#ai-widget-send {
  background: #2d6a4f;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 9px 15px;
  cursor: pointer;
  font-size: 18px;
  flex-shrink: 0;
  transition: background 0.15s;
}
#ai-widget-send:hover { background: #1e4d38; }
#ai-widget-send:disabled { background: #8ab49e; cursor: default; }

/* Rich AI message container resets white-space so HTML renders properly */
.ai-msg-rich {
  white-space: normal;
  max-width: 95%;
  background: transparent;
  padding: 0;
}
.ai-msg-rich p {
  background: #e9f0eb;
  color: #1a2e22;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 9px 13px;
  margin: 4px 0;
  font-size: 13.5px;
  line-height: 1.5;
}

/* ── Product cards ── */
.ai-product-card {
  display: flex;
  gap: 10px;
  background: #f8f9fa;
  border: 1px solid #e0e0e0;
  border-left: 3px solid #2d6a4f;
  border-radius: 10px;
  padding: 10px;
  margin: 6px 0;
  align-items: flex-start;
}
.ai-product-img-wrap {
  flex-shrink: 0;
  width: 80px;
  height: 80px;
  border-radius: 8px;
  overflow: hidden;
  background: #eee;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ai-product-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.ai-product-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-width: 0;
}
.ai-product-name {
  font-size: 13px;
  font-weight: 700;
  color: #1a1a1a;
  line-height: 1.3;
}
.ai-product-desc {
  font-size: 11px;
  color: #666;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.ai-product-price {
  font-size: 13px;
  font-weight: 700;
  color: #2d6a4f;
}
.ai-product-btn {
  display: inline-block;
  margin-top: 4px;
  background: #2d6a4f;
  color: white !important;
  text-decoration: none !important;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  transition: background 0.2s;
}
.ai-product-btn:hover { background: #1e4d38; }

@media (max-width: 420px) {
  #ai-widget-window {
    width: calc(100vw - 16px);
    right: 8px;
    bottom: 84px;
    height: 72vh;
    max-height: 520px;
  }
  #ai-widget-btn {
    right: 16px;
    bottom: 16px;
  }
  .ai-product-card {
    flex-direction: column;
  }
  .ai-product-img-wrap {
    width: 100%;
    height: 120px;
  }
}
