/**
 * Spoon — Chatbot AI Widget
 *
 * Bubble flottante + pannello chat.
 * Variabili CSS riusano quelle del tema (--rc-primary, ecc.).
 */

/* ============================================================
   WRAPPER
   ============================================================ */
#rc-chatbot-wrap {
  position: fixed;
  bottom: 120px;
  right: 24px;
  z-index: 9999;
  font-family: inherit;
}

/* ============================================================
   BUBBLE (pulsante di apertura)
   ============================================================ */
#rc-chatbot-bubble {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--rc-primary, #C8963E);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .22);
  transition: transform .2s ease, box-shadow .2s ease;
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
}

#rc-chatbot-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .28);
}

#rc-chatbot-bubble:active {
  transform: scale(.96);
}

/* Icona chiudi (X) quando il panel è aperto */
#rc-chatbot-bubble.is-open::before {
  content: '✕';
  font-size: 1.1rem;
}

#rc-chatbot-bubble.is-open .rc-bubble-icon {
  display: none;
}

/* ============================================================
   PANNELLO CHAT
   ============================================================ */
#rc-chatbot-panel {
  position: absolute;
  bottom: 68px;
  right: 0;
  width: 340px;
  max-width: calc(100vw - 48px);
  height: 480px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, .18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  animation: rc-chat-open .22s ease forwards;
}

#rc-chatbot-panel[hidden] {
  display: none !important;
}

@keyframes rc-chat-open {
  from { opacity: 0; transform: scale(.92) translateY(12px); }
  to   { opacity: 1; transform: scale(1)   translateY(0); }
}

/* ── Header ── */
.rc-chat-header {
  background: var(--rc-primary, #C8963E);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.rc-chat-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.rc-chat-header-info {
  flex: 1;
  min-width: 0;
}

.rc-chat-title {
  font-size: .9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rc-chat-subtitle {
  font-size: .72rem;
  opacity: .85;
}

/* ── Messages area ── */
.rc-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f9f9f7;
}

.rc-chat-messages::-webkit-scrollbar { width: 4px; }
.rc-chat-messages::-webkit-scrollbar-track { background: transparent; }
.rc-chat-messages::-webkit-scrollbar-thumb { background: #ddd; border-radius: 2px; }

/* ── Singolo messaggio ── */
.rc-msg-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rc-msg-wrap.rc-msg-user  { align-items: flex-end; }
.rc-msg-wrap.rc-msg-bot   { align-items: flex-start; }

.rc-msg-bubble {
  max-width: 85%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: .875rem;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.rc-msg-user .rc-msg-bubble {
  background: var(--rc-primary, #C8963E);
  color: #fff;
  border-bottom-right-radius: 3px;
}

.rc-msg-bot .rc-msg-bubble {
  background: #fff;
  color: #1a1a1a;
  border: 1px solid #e5e5e5;
  border-bottom-left-radius: 3px;
}

/* ── Typing indicator ── */
.rc-msg-typing .rc-msg-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
}

.rc-typing-dot {
  width: 7px;
  height: 7px;
  background: #bbb;
  border-radius: 50%;
  animation: rc-typing-bounce .9s infinite ease-in-out;
}

.rc-typing-dot:nth-child(1) { animation-delay: 0s; }
.rc-typing-dot:nth-child(2) { animation-delay: .15s; }
.rc-typing-dot:nth-child(3) { animation-delay: .3s; }

@keyframes rc-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-6px); }
}

/* ── Rate limit warning ── */
.rc-chat-notice {
  font-size: .78rem;
  color: #888;
  text-align: center;
  padding: 4px 0;
}

/* ── Input area ── */
.rc-chat-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid #eee;
  background: #fff;
  flex-shrink: 0;
}

#rc-chat-input {
  flex: 1;
  border: 1px solid #ddd;
  border-radius: 20px;
  padding: 8px 14px;
  font-size: .875rem;
  outline: none;
  resize: none;
  line-height: 1.4;
  max-height: 80px;
  overflow-y: auto;
  font-family: inherit;
  transition: border-color .15s;
}

#rc-chat-input:focus {
  border-color: var(--rc-primary, #C8963E);
}

#rc-chat-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--rc-primary, #C8963E);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, opacity .15s;
}

#rc-chat-send:hover { background: var(--rc-primary-dark, #a5792f); }
#rc-chat-send:disabled { opacity: .45; cursor: default; }

#rc-chat-send svg {
  width: 16px;
  height: 16px;
  fill: #fff;
}

/* ============================================================
   MOBILE ADJUSTMENTS
   ============================================================ */
@media (max-width: 480px) {
  #rc-chatbot-wrap {
    bottom: 16px;
    right: 16px;
  }

  #rc-chatbot-panel {
    width: calc(100vw - 32px);
    right: 0;
    height: 420px;
  }
}
