/* ── CHATBOT AI ─────────────────────────────────────────────────────────────
   Pulsante flottante con il logo, posizionato sopra il pulsante WhatsApp,
   e finestra di chat con l'assistente virtuale. */
.qf-chat-launcher {
  position: fixed;
  right: 1.5rem;
  bottom: calc(1.5rem + 60px + 1rem + env(safe-area-inset-bottom, 0px));
  z-index: 9999;
  width: 64px; height: 64px;
  border-radius: 50%;
  border: 3px solid #004B87;
  background: #fff;
  padding: 0;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0,75,135,.35);
  display: flex; align-items: center; justify-content: center;
  animation: qf-float 3s ease-in-out infinite;
  transition: box-shadow .2s;
}
.qf-chat-launcher::before {
  content: "";
  position: absolute; inset: -3px;
  border-radius: 50%;
  border: 3px solid #0073CF;
  animation: qf-pulse 2.4s ease-out infinite;
  pointer-events: none;
}
.qf-chat-launcher img {
  width: 100%; height: 100%;
  border-radius: 50%;
  object-fit: contain;
  padding: 6px;
  animation: qf-wiggle 6s ease-in-out infinite;
}
.qf-chat-launcher:hover { box-shadow: 0 10px 28px rgba(0,75,135,.45); animation-play-state: paused; }
.qf-chat-launcher:focus-visible { outline: 3px solid #0073CF; outline-offset: 4px; }
.qf-chat-badge {
  position: absolute; top: -4px; left: -4px;
  background: #0073CF; color: #fff;
  font: 600 10px/1 'DM Sans', system-ui, sans-serif;
  padding: 4px 6px; border-radius: 10px;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.qf-chat-tip {
  position: absolute; right: calc(100% + 12px); top: 50%;
  transform: translateY(-50%);
  background: #004B87; color: #fff;
  font: 500 13px/1.3 'DM Sans', system-ui, sans-serif;
  padding: 8px 12px; border-radius: 10px;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0,0,0,.2);
  opacity: 0; pointer-events: none;
  transition: opacity .25s;
}
.qf-chat-launcher:hover .qf-chat-tip,
.qf-chat-launcher.qf-show-tip .qf-chat-tip { opacity: 1; }
.qf-chat-open .qf-chat-launcher .qf-chat-tip { opacity: 0; }

@keyframes qf-float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes qf-pulse { 0% { transform: scale(1); opacity: .8; } 100% { transform: scale(1.45); opacity: 0; } }
@keyframes qf-wiggle { 0%,85%,100% { transform: rotate(0); } 88% { transform: rotate(-10deg); } 91% { transform: rotate(10deg); } 94% { transform: rotate(-6deg); } 97% { transform: rotate(4deg); } }

.qf-chat-panel {
  position: fixed;
  right: 1.5rem;
  bottom: calc(1.5rem + 60px + 1rem + 64px + 1rem + env(safe-area-inset-bottom, 0px));
  z-index: 10000;
  width: 370px; max-width: calc(100vw - 2rem);
  height: 520px; max-height: calc(100vh - 220px);
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
  display: flex; flex-direction: column;
  overflow: hidden;
  font-family: 'DM Sans', system-ui, sans-serif;
  opacity: 0; transform: translateY(16px) scale(.97);
  pointer-events: none; visibility: hidden;
  transition: opacity .25s, transform .25s, visibility .25s;
}
.qf-chat-open .qf-chat-panel { opacity: 1; transform: none; pointer-events: auto; visibility: visible; }

.qf-chat-header {
  background: linear-gradient(135deg, #004B87, #0073CF);
  color: #fff; padding: 14px 16px;
  display: flex; align-items: center; gap: 10px;
}
.qf-chat-header img { width: 38px; height: 38px; border-radius: 50%; background: #fff; object-fit: contain; padding: 3px; }
.qf-chat-header strong { display: block; font-size: 15px; }
.qf-chat-header span { font-size: 12px; opacity: .85; }
.qf-chat-close {
  margin-left: auto; background: rgba(255,255,255,.15); border: 0; color: #fff;
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-size: 20px; line-height: 1;
}
.qf-chat-close:hover { background: rgba(255,255,255,.3); }

.qf-chat-messages {
  flex: 1; overflow-y: auto; padding: 16px;
  background: #FAF7F2;
  display: flex; flex-direction: column; gap: 10px;
}
.qf-msg {
  max-width: 85%; padding: 10px 13px; border-radius: 14px;
  font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word;
}
.qf-msg-bot { background: #fff; color: #1A2E1F; border: 1px solid #E6F0FA; align-self: flex-start; border-bottom-left-radius: 4px; }
.qf-msg-user { background: #004B87; color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.qf-msg-error { background: #FDECEC; color: #8A1C1C; border-color: #F5C2C2; }
.qf-msg a { color: inherit; text-decoration: underline; }
.qf-typing { display: inline-flex; gap: 4px; }
.qf-typing i { width: 7px; height: 7px; border-radius: 50%; background: #0073CF; animation: qf-dot 1.2s infinite; }
.qf-typing i:nth-child(2) { animation-delay: .2s; }
.qf-typing i:nth-child(3) { animation-delay: .4s; }
@keyframes qf-dot { 0%,80%,100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-4px); } }

.qf-chat-suggest { display: flex; flex-wrap: wrap; gap: 6px; }
.qf-chat-suggest button {
  background: #E6F0FA; color: #004B87; border: 1px solid #cfe1f3;
  border-radius: 14px; padding: 6px 10px; font: 500 12.5px 'DM Sans', system-ui, sans-serif; cursor: pointer;
}
.qf-chat-suggest button:hover { background: #d6e7f7; }

.qf-chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid #eee; background: #fff; }
.qf-chat-form textarea {
  flex: 1; resize: none; border: 1px solid #d5dde5; border-radius: 12px;
  padding: 10px 12px; font: 14px 'DM Sans', system-ui, sans-serif; max-height: 100px; outline: none;
}
.qf-chat-form textarea:focus { border-color: #0073CF; }
.qf-chat-form button {
  background: #004B87; color: #fff; border: 0; border-radius: 12px;
  width: 44px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.qf-chat-form button:disabled { opacity: .5; cursor: default; }
.qf-chat-form button svg { width: 20px; height: 20px; fill: currentColor; }
.qf-chat-note { font-size: 11px; color: #6b7a70; text-align: center; padding: 0 10px 8px; background: #fff; }
.qf-chat-note a { color: #004B87; }

@media (max-width: 600px) {
  .qf-chat-launcher { right: 1rem; bottom: calc(1rem + 54px + .85rem + env(safe-area-inset-bottom, 0px)); width: 56px; height: 56px; }
  .qf-chat-tip { display: none; }
  .qf-chat-panel {
    right: .5rem; left: .5rem; width: auto; max-width: none;
    bottom: calc(1rem + 54px + .85rem + 56px + .75rem + env(safe-area-inset-bottom, 0px));
    height: auto; top: 80px; max-height: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  .qf-chat-launcher, .qf-chat-launcher::before, .qf-chat-launcher img { animation: none; }
}
