/* === ASSISTENTE GUIDATO === */

.sp-chat[hidden],
.sp-chat [hidden] {
  display: none !important;
}

.sp-chat-open,
.sp-chat-open body {
  overflow: hidden;
}

.sp-chat {
  position: fixed;
  inset: 0;
  z-index: 10000;
}

.sp-chat__overlay {
  position: absolute;
  inset: 0;
  background: rgba(var(--color-primary-90-rgb), 0.5);
  backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 200ms ease;
}

.sp-chat__panel {
  position: absolute;
  right: 30px;
  bottom: calc(30px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  width: min(25rem, calc(100vw - 2rem));
  height: min(42rem, calc(100dvh - 60px));
  padding: 1.25rem;
  background: var(--color-white);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  transform-origin: bottom right;
  transform: translateY(12px) scale(0.96);
  opacity: 0;
  transition: opacity 200ms ease, transform 200ms ease;
}

.sp-chat.is-open .sp-chat__overlay {
  opacity: 1;
}

.sp-chat.is-open .sp-chat__panel {
  transform: none;
  opacity: 1;
}

.sp-chat__header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--color-border);
}

.sp-chat__avatar {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-lg);
  background: var(--color-primary);
  color: var(--color-white);
  font-size: 1.125rem;
}

.sp-chat__avatar--sm {
  width: 28px;
  height: 28px;
  margin-top: 4px;
  border-radius: var(--radius-md);
  font-size: 0.75rem;
}

/* Il Logo Icona impostato nel sito è una sagoma viola: la rendiamo bianca
   sull'avatar viola, come l'icona usata prima. */
.sp-chat__avatar--logo img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: contain;
  filter: brightness(0) invert(1);
}

.sp-chat__heading {
  flex: 1;
  min-width: 0;
}

.sp-chat__title {
  margin: 0;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  line-height: var(--lh-base);
  color: var(--color-text);
  outline: none;
}

.sp-chat__subtitle {
  margin: 0;
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}

.sp-chat__close {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
}

.sp-chat__close:hover {
  background: var(--color-light-gray);
}

.sp-chat__progress {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.sp-chat__progress span {
  flex: 1;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--color-border);
}

.sp-chat__progress .is-done {
  background: var(--color-primary);
}

.sp-chat__messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0;
  margin-top: 1rem;
  padding-right: 4px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sp-chat__messages > * {
  flex-shrink: 0;
  animation: sp-chat-enter 240ms ease-out both;
}

@keyframes sp-chat-enter {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

.sp-chat__row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.sp-chat__bubble {
  width: fit-content;
  max-width: 85%;
  margin: 0;
  padding: 0.75rem 1rem;
  border-radius: 16px 16px 16px 4px;
  background: var(--color-accent-5);
  color: var(--color-text);
  font-size: var(--font-size-sm);
  line-height: var(--lh-relaxed);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.sp-chat__bubble--user {
  align-self: flex-end;
  border-radius: 16px 16px 4px 16px;
  background: var(--color-primary);
  color: var(--color-white);
}

.sp-chat__typing {
  display: flex;
  gap: 4px;
}

.sp-chat__typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-mid-gray);
  animation: sp-chat-pulse 1s ease-in-out infinite;
}

.sp-chat__typing span:nth-child(2) {
  animation-delay: 150ms;
}

.sp-chat__typing span:nth-child(3) {
  animation-delay: 300ms;
}

@keyframes sp-chat-pulse {
  50% {
    opacity: 0.3;
  }
}

.sp-chat__summary {
  padding: 1rem;
  border: 1px solid var(--color-accent-10);
  border-radius: var(--radius-xl);
  font-size: var(--font-size-sm);
  line-height: var(--lh-relaxed);
  overflow-wrap: anywhere;
}

.sp-chat__summary p {
  margin: 0;
}

.sp-chat__summary .sp-chat__summary-text {
  margin-top: 0.5rem;
  white-space: pre-wrap;
}

.sp-chat__actions {
  flex-shrink: 0;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
}

.sp-chat__actions:empty {
  display: none;
}

.sp-chat__choice {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.sp-chat__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0.5rem 1.25rem;
  border: 2px solid var(--color-primary);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-bold);
  text-decoration: none;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.sp-chat__btn--primary {
  background: var(--color-primary);
  color: var(--color-white);
}

.sp-chat__btn--primary:hover {
  background: var(--color-primary-dark);
  color: var(--color-white);
}

.sp-chat__btn--outline {
  background: transparent;
  color: var(--color-primary);
}

.sp-chat__btn--outline:hover {
  background: var(--color-accent-5);
}

.sp-chat__btn:disabled,
.sp-chat__link:disabled {
  opacity: 0.6;
  cursor: default;
}

.sp-chat__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

.sp-chat__chip {
  display: inline-flex;
  flex-grow: 1;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  max-width: 100%;
  min-height: 40px;
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--color-accent-20);
  border-radius: 20px;
  background: var(--color-white);
  color: var(--color-text);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: var(--font-weight-medium);
  cursor: pointer;
}

.sp-chat__chip i {
  color: var(--color-primary);
}

.sp-chat__chip:hover {
  border-color: var(--color-primary);
  background: var(--color-accent-5);
}

.sp-chat__chip--back {
  flex: 0 0 40px;
  padding: 0;
  background: var(--color-primary-dark);
}

.sp-chat__chip--back i {
  color: var(--color-white);
}

.sp-chat__chip--back:hover {
  background: var(--color-primary);
}

.sp-chat__note {
  margin: 0.75rem 0 0;
  font-size: var(--font-size-xs);
  line-height: var(--lh-normal);
  color: var(--color-text-muted);
}

/* 16px: sotto questa misura iOS ingrandisce la pagina al focus */
.sp-chat__field {
  width: 100%;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--color-primary-20);
  border-radius: var(--radius-lg);
  font-family: inherit;
  font-size: 16px;
  color: var(--color-text);
  resize: none;
}

.sp-chat__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.sp-chat__link {
  padding: 0.5rem 0;
  border: none;
  background: none;
  color: var(--color-text-muted);
  font-family: inherit;
  font-size: var(--font-size-sm);
  text-decoration: underline;
  cursor: pointer;
}

.sp-chat__privacy {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: var(--font-size-xs);
  line-height: var(--lh-normal);
  cursor: pointer;
}

.sp-chat__privacy input {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
}

.sp-chat__privacy a {
  color: var(--color-primary);
  text-decoration: underline;
}

.sp-chat__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.sp-chat :is(.sp-chat__btn, .sp-chat__chip, .sp-chat__link, .sp-chat__close, .sp-chat__field, a):focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

@media (max-width: 640px) {
  .sp-chat__panel {
    right: 1rem;
    bottom: calc(1rem + env(safe-area-inset-bottom));
    height: min(42rem, calc(100dvh - 2rem));
    padding: 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sp-chat *,
  .sp-chat__messages > * {
    animation: none;
    transition: none;
  }
}
