/* ai-assistant.css — widget AI flottante (Sulla Soglia, riusa /api/guida-chat).
   Bubble bottom-right + pannello chat 380x520 + modale termini al primo uso.
   Disabilitato via body.no-ai-assistant. Token globali da style.css. */

/* ═══════════════════════════════════════════════════════════════
   BUBBLE — bottone fluttuante in basso a destra
   ═══════════════════════════════════════════════════════════════ */
.ai-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 0;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow:
    0 8px 24px -8px rgba(192, 68, 40, 0.55),
    0 2px 8px rgba(0, 0, 0, 0.12);
  z-index: 998;
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
}
.ai-bubble:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 12px 32px -10px rgba(192, 68, 40, 0.65);
}
.ai-bubble svg {
  width: 26px;
  height: 26px;
  stroke: #fff;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ai-bubble[hidden] {
  display: none;
}
.ai-bubble-pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--color-primary);
  pointer-events: none;
  animation: ai-bubble-pulse 2.4s ease-out infinite;
}
@keyframes ai-bubble-pulse {
  0% {
    transform: scale(1);
    opacity: 0.6;
  }
  100% {
    transform: scale(1.6);
    opacity: 0;
  }
}
body.no-ai-assistant .ai-bubble,
body.no-ai-assistant .ai-panel,
body.no-ai-assistant .ai-terms-modal {
  display: none !important;
}

/* ═══════════════════════════════════════════════════════════════
   PANEL — pannello chat che appare al click bubble
   ═══════════════════════════════════════════════════════════════ */
.ai-panel {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 540px;
  max-height: calc(100vh - 120px);
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 18px;
  box-shadow:
    0 20px 60px -20px rgba(20, 19, 15, 0.35),
    0 4px 12px rgba(20, 19, 15, 0.1);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 999;
  transform-origin: bottom right;
  animation: ai-panel-in 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.ai-panel.open {
  display: flex;
}
@keyframes ai-panel-in {
  0% {
    opacity: 0;
    transform: translateY(16px) scale(0.94);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Header del pannello */
.ai-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: var(--color-text);
  color: var(--color-bg);
  flex-shrink: 0;
}
.ai-head-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ai-head-avatar svg {
  width: 18px;
  height: 18px;
  stroke: #fff;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ai-head-text {
  flex: 1;
  min-width: 0;
}
.ai-head-text strong {
  font-family: var(--font-heading);
  font-weight: 400;
  font-size: 16px;
  display: block;
  letter-spacing: -0.01em;
}
.ai-head-text strong em {
  font-style: italic;
  color: var(--color-primary-light);
}
.ai-head-text small {
  font-family: var(--hd-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.7);
}
.ai-head-close {
  width: 32px;
  height: 32px;
  border: 0;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.ai-head-close:hover {
  background: rgba(255, 255, 255, 0.18);
}
.ai-head-close svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
}

/* Body chat (scrollabile) */
.ai-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--color-bg);
}
.ai-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}
.ai-msg.user {
  align-self: flex-end;
  background: var(--color-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ai-msg.bot {
  align-self: flex-start;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  border-bottom-left-radius: 4px;
}
.ai-msg.bot.error {
  border-color: #c53030;
  color: #c53030;
}
.ai-typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 4px;
  padding: 14px;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
.ai-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-muted);
  animation: ai-typing 1.2s ease-in-out infinite;
}
.ai-typing span:nth-child(2) {
  animation-delay: 0.15s;
}
.ai-typing span:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes ai-typing {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* Chip suggerimenti rapidi (visibili solo se chat vuota) */
.ai-chips {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}
.ai-chips-label {
  font-family: var(--hd-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}
.ai-chip {
  text-align: left;
  padding: 10px 14px;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--color-text);
  transition: all 0.15s;
}
.ai-chip:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  transform: translateX(2px);
}

/* Form input */
.ai-input-row {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--color-border);
  background: var(--color-bg-card);
  flex-shrink: 0;
}
.ai-input {
  flex: 1;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  border-radius: 10px;
  padding: 10px 14px;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--color-text);
  outline: 0;
  resize: none;
  min-height: 40px;
  max-height: 100px;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}
.ai-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(192, 68, 40, 0.1);
}
.ai-send {
  width: 40px;
  height: 40px;
  border: 0;
  background: var(--color-primary);
  color: #fff;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.ai-send:hover:not(:disabled) {
  background: var(--color-primary-dark);
}
.ai-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.ai-send svg {
  width: 16px;
  height: 16px;
  stroke: #fff;
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Footer disclaimer */
.ai-foot {
  padding: 6px 14px 8px;
  background: var(--color-bg-card);
  border-top: 1px solid color-mix(in srgb, var(--color-border) 50%, transparent);
  font-family: var(--hd-mono);
  font-size: 9px;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  text-align: center;
  flex-shrink: 0;
}
.ai-foot a {
  color: inherit;
  text-decoration: underline;
}

/* ═══════════════════════════════════════════════════════════════
   TERMS MODAL — primo uso, accettazione termini
   ═══════════════════════════════════════════════════════════════ */
.ai-terms-modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 19, 15, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1001;
  padding: 20px;
  backdrop-filter: blur(2px);
}
.ai-terms-modal.open {
  display: flex;
}
.ai-terms-card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 18px;
  padding: 28px 30px;
  max-width: 460px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 60px -10px rgba(0, 0, 0, 0.4);
  animation: ai-terms-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes ai-terms-in {
  0% {
    opacity: 0;
    transform: scale(0.94);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}
.ai-terms-card h2 {
  font-family: var(--font-heading);
  font-weight: 400;
  font-size: 24px;
  line-height: 1.15;
  letter-spacing: -0.015em;
  color: var(--color-text);
  margin: 0 0 14px;
}
.ai-terms-card h2 em {
  font-style: italic;
  color: var(--color-primary);
}
.ai-terms-card p {
  font-size: 14px;
  line-height: 1.6;
  color: var(--color-text-light);
  margin: 0 0 12px;
}
.ai-terms-list {
  list-style: none;
  padding: 0;
  margin: 0 0 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ai-terms-list li {
  display: flex;
  gap: 10px;
  padding: 8px 12px;
  background: var(--color-bg-warm);
  border-radius: 8px;
  font-size: 13px;
  color: var(--color-text);
}
.ai-terms-list li::before {
  content: '•';
  color: var(--color-primary);
  font-weight: 700;
}
.ai-terms-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.ai-terms-actions button {
  padding: 10px 18px;
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: all 0.15s;
}
.ai-terms-actions .btn-decline {
  background: transparent;
  border-color: var(--color-border);
  color: var(--color-text);
}
.ai-terms-actions .btn-decline:hover {
  background: var(--color-bg-warm);
}
.ai-terms-actions .btn-accept {
  background: var(--color-text);
  color: var(--color-bg);
}
.ai-terms-actions .btn-accept:hover {
  background: var(--color-primary);
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .ai-bubble {
    bottom: 16px;
    right: 16px;
    width: 52px;
    height: 52px;
  }
  .ai-panel {
    bottom: 80px;
    right: 16px;
    left: 16px;
    width: auto;
    max-width: none;
    height: calc(100vh - 110px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-bubble,
  .ai-panel,
  .ai-bubble-pulse,
  .ai-typing span,
  .ai-chip,
  .ai-terms-card {
    animation: none;
    transition: none;
  }
  .ai-bubble:hover,
  .ai-chip:hover {
    transform: none;
  }
}

/* Dark mode */
[data-theme='dark'] .ai-msg.user {
  background: var(--color-primary);
}
[data-theme='dark'] .ai-msg.bot,
[data-theme='dark'] .ai-typing,
[data-theme='dark'] .ai-chip {
  background: var(--color-bg-card);
  border-color: var(--color-border);
}
