/* ============================================================
   MASCOTTE WIDGET — componente riutilizzabile
   Personalizza tramite variabili CSS impostate da JS (vedi mascotte-widget.js)
   ============================================================ */

.mw-root{
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 99999;
  font-family: var(--mw-font, 'Inter', system-ui, sans-serif);
}

/* ---- Bolla fluttuante ---- */
.mw-bubble{
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: var(--mw-accent, #2563eb);
  box-shadow: 0 8px 24px rgba(0,0,0,.22), 0 2px 6px rgba(0,0,0,.12);
  border: 3px solid #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  transition: transform .25s ease;
  animation: mw-bob 3.2s ease-in-out infinite;
}
.mw-bubble:hover{ transform: scale(1.06); }
.mw-bubble img{
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
}
.mw-bubble .mw-fallback-icon{
  width: 60%;
  height: 60%;
  color: #fff;
}

@keyframes mw-bob{
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.mw-ping{
  position: absolute;
  top: -4px;
  right: -4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ef4444;
  border: 2px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: #fff;
  font-weight: 700;
}

/* ---- Bubble di richiamo ---- */
.mw-teaser{
  position: absolute;
  bottom: 6px;
  right: 90px;
  background: #fff;
  color: #16233b;
  padding: 10px 16px;
  border-radius: 16px 16px 4px 16px;
  box-shadow: 0 6px 18px rgba(0,0,0,.14);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  opacity: 0;
  transform: translateX(8px);
  animation: mw-teaser-in .4s ease .6s forwards;
  pointer-events: none;
}
@keyframes mw-teaser-in{
  to{ opacity: 1; transform: translateX(0); }
}

/* ---- Pannello chat ---- */
.mw-panel{
  position: absolute;
  bottom: 92px;
  right: 0;
  width: 360px;
  max-width: calc(100vw - 32px);
  max-height: 520px;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(.97);
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
}
.mw-root.mw-open .mw-panel{
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.mw-root.mw-open .mw-teaser{ display: none; }

.mw-header{
  background: var(--mw-header-bg, #16233b);
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.mw-header .mw-avatar-sm{
  width: 42px;
  height: 42px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--mw-accent, #2563eb);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(255,255,255,.3);
}
.mw-header .mw-avatar-sm img{ width: 100%; height: 100%; object-fit: cover; object-position: top center; }
.mw-header .mw-avatar-sm .mw-fallback-icon{ width: 60%; height: 60%; color: #fff; }
.mw-header-text{ flex: 1; }
.mw-header-text .mw-name{ font-weight: 800; font-size: 15px; line-height: 1.2; }
.mw-header-text .mw-status{ font-size: 12px; opacity: .8; display:flex; align-items:center; gap:5px; margin-top:2px; }
.mw-header-text .mw-status::before{
  content: '';
  width: 7px; height: 7px; border-radius: 50%;
  background: #22c55e;
  display: inline-block;
}
.mw-close{
  background: rgba(255,255,255,.12);
  border: none;
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.mw-close:hover{ background: rgba(255,255,255,.22); }

.mw-body{
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  background: #f5f7fb;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mw-msg{
  max-width: 88%;
  padding: 12px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
}
.mw-msg.mw-from-milo{
  background: #fff;
  color: #1c2a42;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.mw-msg.mw-from-user{
  background: var(--mw-accent, #2563eb);
  color: #fff;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}
.mw-msg p{ margin: 0 0 8px; }
.mw-msg p:last-child{ margin-bottom: 0; }

.mw-options{
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-self: stretch;
}
.mw-option-btn{
  background: #fff;
  border: 1.5px solid var(--mw-accent, #2563eb);
  color: var(--mw-accent, #2563eb);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13.5px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.mw-option-btn:hover{
  background: var(--mw-accent, #2563eb);
  color: #fff;
}

.mw-cta-btn{
  display: inline-block;
  margin-top: 6px;
  background: var(--mw-accent, #2563eb);
  color: #fff !important;
  text-decoration: none;
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
}

.mw-back-btn{
  align-self: flex-start;
  background: none;
  border: none;
  color: #6b7789;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  padding: 4px 0;
  display: flex;
  align-items: center;
  gap: 4px;
}
.mw-back-btn:hover{ color: var(--mw-accent, #2563eb); }

.mw-footer{
  padding: 10px 18px;
  text-align: center;
  font-size: 11px;
  color: #9aa4b2;
  background: #fff;
  border-top: 1px solid #eef0f4;
}
.mw-footer a{ color: inherit; }

/* ---- Domanda libera (chat AI opzionale) ---- */
.mw-ai-note{
  font-size: 10.5px;
  line-height: 1.4;
  color: #9aa4b2;
  text-align: center;
  padding: 6px 16px 0;
  background: #fff;
}
.mw-chatbar{
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: #fff;
  border-top: 1px solid #eef0f4;
}
.mw-chat-input{
  flex: 1;
  border: 1.5px solid #e2e6ed;
  border-radius: 20px;
  padding: 9px 14px;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  min-width: 0;
}
.mw-chat-input:focus{ border-color: var(--mw-accent, #2563eb); }
.mw-chat-send{
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--mw-accent, #2563eb);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 15px;
  transition: opacity .15s;
}
.mw-chat-send:disabled{ opacity: .5; cursor: default; }
.mw-chat-send:hover:not(:disabled){ opacity: .88; }

.mw-typing{
  display: flex;
  gap: 4px;
  padding: 14px 16px;
  align-self: flex-start;
  background: #fff;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.mw-typing span{
  width: 6px; height: 6px; border-radius: 50%;
  background: #b7c0cc;
  animation: mw-typing-bounce 1.2s infinite ease-in-out;
}
.mw-typing span:nth-child(2){ animation-delay: .15s; }
.mw-typing span:nth-child(3){ animation-delay: .3s; }
@keyframes mw-typing-bounce{
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

@media (max-width: 480px){
  .mw-panel{ width: calc(100vw - 32px); right: -12px; }
}
