/* AiCare Widget — scoped styles, no theme conflicts */
:root {
  --aicare-primary: #0066cc;
  --aicare-bg: #ffffff;
  --aicare-text: #1a1a1a;
  --aicare-user-bg: var(--aicare-primary);
  --aicare-user-text: #ffffff;
  --aicare-bot-bg: #f0f4f8;
  --aicare-bot-text: #1a1a1a;
  --aicare-border: #e2e8f0;
  --aicare-radius: 12px;
  --aicare-shadow: 0 8px 32px rgba(0,0,0,0.15);
  --aicare-z: 9999;
}

#aicare-root * {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Floating button */
#aicare-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--aicare-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: var(--aicare-shadow);
  z-index: var(--aicare-z);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#aicare-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 12px 40px rgba(0,0,0,0.2);
}

#aicare-btn svg {
  width: 26px;
  height: 26px;
  fill: white;
}

#aicare-btn.aicare-left {
  right: auto;
  left: 24px;
}

/* Chat window */
#aicare-window {
  position: fixed;
  bottom: 90px;
  right: 24px;
  width: 400px;
  max-width: calc(100vw - 32px);
  height: 500px;
  max-height: calc(100vh - 120px);
  background: var(--aicare-bg);
  border-radius: var(--aicare-radius);
  box-shadow: var(--aicare-shadow);
  z-index: var(--aicare-z);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#aicare-window.aicare-hidden {
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  pointer-events: none;
}

#aicare-window.aicare-left {
  right: auto;
  left: 24px;
}

/* Header */
#aicare-header {
  background: var(--aicare-primary);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

#aicare-header-title {
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}

#aicare-header-title::before {
  content: '';
  width: 8px;
  height: 8px;
  background: #4ade80;
  border-radius: 50%;
  display: inline-block;
}

#aicare-close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.8);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background 0.15s;
}

#aicare-close:hover {
  background: rgba(255,255,255,0.15);
  color: #fff;
}

/* Messages */
#aicare-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.aicare-msg {
  max-width: 80%;
  padding: 10px 13px !important;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}

.aicare-msg ul {
  margin: 6px 0 !important;
  padding-left: 18px !important;
}

.aicare-msg li {
  margin-bottom: 3px;
}

.aicare-msg li:last-child {
  margin-bottom: 0;
}

.aicare-msg strong {
  font-weight: 600;
}

.aicare-msg-user {
  background: var(--aicare-user-bg);
  color: var(--aicare-user-text);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.aicare-msg-assistant {
  background: var(--aicare-bot-bg);
  color: var(--aicare-bot-text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

/* Bot avatar (admin-configurable in AiCare > Impostazioni), shown next to
   each assistant bubble instead of the bubble being appended directly. */
.aicare-msg-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  align-self: flex-start;
  max-width: 85%;
}

.aicare-msg-row .aicare-msg-assistant {
  max-width: 100%;
  min-width: 0;
}

.aicare-msg-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: #f1f5f9;
}

.aicare-msg-operator {
  background: #d4edda;
  color: #155724;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  border: 1px solid #a3d9af;
  position: relative;
}

.aicare-msg-operator::before {
  content: 'Operatore';
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  opacity: 0.7;
  margin-bottom: 3px;
}

/* Typing indicator */
.aicare-typing {
  display: flex;
  gap: 4px;
  padding: 10px 13px;
  background: var(--aicare-bot-bg);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  width: fit-content;
}

.aicare-typing span {
  width: 7px;
  height: 7px;
  background: #94a3b8;
  border-radius: 50%;
  animation: aicare-bounce 1.2s infinite ease-in-out;
}

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

@keyframes aicare-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* Product cards (RAG catalog search results) */
.aicare-product-cards {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-self: flex-start;
  width: 100%;
  max-width: 85%;
  margin-bottom: 4px;
}

.aicare-product-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 5px;
  overflow: hidden;
  text-decoration: none;
  transition: border-color 0.15s ease;
}

.aicare-product-card:hover {
  border-color: var(--aicare-primary, #0066cc);
}

.aicare-product-thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 5px 0 0 5px;
  flex-shrink: 0;
  background: #f1f5f9;
  border-right: 1px solid #eee;
}

.aicare-product-info {
  min-width: 0;
}

.aicare-product-title {
  font-size: 13px;
  font-weight: 600;
  color: #1a1a1a;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.aicare-product-price {
  font-size: 12px;
  color: #64748b;
  margin-top: 2px;
  font-weight: 500;
}

/* Confirmation card */
#aicare-confirm-card {
  margin: 8px 16px;
  padding: 12px 14px;
  background: #fff8e1;
  border: 1px solid #fbbf24;
  border-radius: 8px;
  font-size: 13px;
  color: #92400e;
  flex-shrink: 0;
}

#aicare-confirm-card.aicare-hidden { display: none; }

.aicare-confirm-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.aicare-btn-confirm,
.aicare-btn-cancel-action {
  padding: 7px 14px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: opacity 0.15s;
}

.aicare-btn-confirm {
  background: var(--aicare-primary);
  color: #fff;
}

.aicare-btn-cancel-action {
  background: #e2e8f0;
  color: #475569;
}

.aicare-btn-confirm:hover,
.aicare-btn-cancel-action:hover { opacity: 0.85; }

/* Footer */
#aicare-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--aicare-border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

#aicare-input {
  flex: 1;
  border: 1px solid var(--aicare-border);
  border-radius: 5px;
  padding: 9px 14px;
  font-size: 14px;
  outline: none;
  resize: none;
  min-height: 38px;
  max-height: 100px;
  overflow-y: auto;
  transition: border-color 0.15s;
  color: var(--aicare-text);
}

#aicare-input:focus {
  border-color: var(--aicare-primary);
}

#aicare-send {
  background: var(--aicare-primary);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

#aicare-send:hover { opacity: 0.85; }
#aicare-send:disabled { opacity: 0.45; cursor: not-allowed; }

#aicare-send svg {
  width: 16px;
  height: 16px;
  fill: white;
}

#aicare-escalate {
  background: none;
  border: none;
  color: #64748b;
  font-size: 12px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  transition: color 0.15s;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Hidden until the AI detects an explicit request to talk to a human
   (IntentClassifier → ESCALATE), to avoid the button nudging everyone
   towards a human agent instead of trying the assistant first. */
#aicare-escalate.aicare-hidden {
  display: none;
}
#aicare-escalate:disabled {
  color: #ccc;
  cursor: not-allowed;
}

#aicare-escalate:hover { color: var(--aicare-primary); }

#aicare-escalate svg{
  width: 30px;
}

/* Scrollbar */
#aicare-messages::-webkit-scrollbar { width: 4px; }
#aicare-messages::-webkit-scrollbar-track { background: transparent; }
#aicare-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

/* Mobile */
@media (max-width: 480px) {
  #aicare-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 85vh;
    border-radius: var(--aicare-radius) var(--aicare-radius) 0 0;
  }

  #aicare-btn {
    bottom: 16px;
    right: 16px;
  }
}
