/* Chatbot Art Mall — widget styling
 * Palette: nero #0a0a0a + giallo elettrico #ffeb00, mobile-first.
 * Tutto namespaced sotto #amm-chat per non conflittare con tema WordPress.
 */

#amm-chat,
#amm-chat *,
#amm-chat *::before,
#amm-chat *::after {
  box-sizing: border-box;
}

/* === Reset aggressivo button (evita override dal tema WordPress) === */
#amm-chat button {
  background: transparent;
  border: none;
  outline: none;
  color: inherit;
  font: inherit;
  text-transform: none;
  letter-spacing: normal;
  text-shadow: none;
  box-shadow: none;
  text-decoration: none;
  padding: 0;
  margin: 0;
  line-height: normal;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

#amm-chat button:hover,
#amm-chat button:focus,
#amm-chat button:active {
  background: transparent;
  color: inherit;
  text-decoration: none;
  outline: none;
}

#amm-chat {
  --amm-bg: #0a0a0a;
  --amm-bg-alt: #1a1a1a;
  --amm-border: #2a2a2a;
  --amm-text: #f5f5f5;
  --amm-text-muted: #9a9a9a;
  --amm-accent: #ffeb00;
  --amm-accent-hover: #ffd400;
  --amm-accent-text: #0a0a0a;
  --amm-error: #ff4d4d;

  font-family: 'Inter', 'Manrope', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  color: var(--amm-text);
  position: fixed;
  bottom: 0;
  right: 0;
  z-index: 2147483000;
  pointer-events: none;
}

#amm-chat * {
  pointer-events: auto;
}

/* === Floating button === */
#amm-chat .amm-fab {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 60px;
  height: 60px;
  border-radius: 50% !important;
  background: var(--amm-accent) !important;
  color: var(--amm-accent-text) !important;
  border: none !important;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35) !important;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

#amm-chat .amm-fab:hover {
  transform: scale(1.06);
  background: var(--amm-accent) !important;
  color: var(--amm-accent-text) !important;
  box-shadow: 0 10px 30px rgba(255, 235, 0, 0.35) !important;
}

.amm-fab svg {
  width: 28px;
  height: 28px;
}

.amm-fab.amm-hidden {
  display: none;
}

/* === Attention seek: dopo il trigger proattivo il FAB oscilla + pulsa ===
 * Cicla ogni 3.6s con una pausa lunga di "respiro" per non essere fastidioso.
 * Disattivato in caso di prefers-reduced-motion. */
#amm-chat .amm-fab.amm-fab-attention {
  animation: amm-fab-attention 3.6s ease-in-out infinite;
}

@keyframes amm-fab-attention {
  0%, 70%, 100% {
    transform: scale(1) rotate(0deg);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  }
  10% { transform: scale(1.1) rotate(-10deg); }
  20% { transform: scale(1.1) rotate(10deg); }
  30% { transform: scale(1.1) rotate(-8deg); }
  40% { transform: scale(1.1) rotate(8deg); }
  50% {
    transform: scale(1.1) rotate(0deg);
    box-shadow: 0 12px 32px rgba(255, 235, 0, 0.55);
  }
  60% { transform: scale(1) rotate(0deg); }
}

@media (prefers-reduced-motion: reduce) {
  #amm-chat .amm-fab.amm-fab-attention {
    animation: none;
  }
}

/* === Proactive bubble === */
.amm-bubble {
  position: fixed;
  bottom: 95px;
  right: 20px;
  max-width: 260px;
  background: var(--amm-bg-alt);
  color: var(--amm-text);
  padding: 12px 36px 12px 14px;
  border-radius: 14px 14px 4px 14px;
  border: 1px solid var(--amm-border);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  font-size: 14px;
  line-height: 1.35;
  animation: amm-fade-in 0.3s ease;
}

#amm-chat .amm-bubble-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border: none !important;
  background: transparent !important;
  color: var(--amm-text-muted) !important;
  cursor: pointer;
  border-radius: 50% !important;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: none !important;
}

#amm-chat .amm-bubble-close:hover {
  background: var(--amm-border) !important;
  color: var(--amm-text) !important;
}

.amm-bubble.amm-hidden {
  display: none;
}

/* === Chat window === */
.amm-window {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 380px;
  height: 600px;
  max-height: calc(100vh - 40px);
  background: var(--amm-bg);
  border: 1px solid var(--amm-border);
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: amm-slide-up 0.25s ease;
}

.amm-window.amm-hidden {
  display: none;
}

/* === Header === */
.amm-header {
  background: var(--amm-bg-alt);
  border-bottom: 1px solid var(--amm-border);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.amm-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.amm-logo {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: #fff;
  padding: 2px;
  flex-shrink: 0;
  object-fit: contain;
}

.amm-header-text {
  display: flex;
  flex-direction: column;
}

.amm-header-title {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.2px;
  color: var(--amm-accent);
}

.amm-header-subtitle {
  font-size: 11px;
  color: var(--amm-text-muted);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.amm-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #00d96d;
  display: inline-block;
  box-shadow: 0 0 0 2px rgba(0, 217, 109, 0.2);
}

.amm-header-actions {
  display: flex;
  gap: 4px;
}

#amm-chat .amm-icon-button {
  width: 34px;
  height: 34px;
  border: none !important;
  background: transparent !important;
  color: var(--amm-text-muted) !important;
  cursor: pointer;
  border-radius: 8px !important;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
  box-shadow: none !important;
}

#amm-chat .amm-icon-button:hover {
  background: var(--amm-border) !important;
  color: var(--amm-text) !important;
}

.amm-icon-button svg {
  width: 18px;
  height: 18px;
}

/* === Messages area === */
.amm-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.amm-messages::-webkit-scrollbar {
  width: 6px;
}

.amm-messages::-webkit-scrollbar-track {
  background: transparent;
}

.amm-messages::-webkit-scrollbar-thumb {
  background: var(--amm-border);
  border-radius: 3px;
}

.amm-msg {
  max-width: 80%;
  padding: 10px 13px;
  border-radius: 14px;
  word-wrap: break-word;
  white-space: pre-wrap;
  animation: amm-fade-in 0.18s ease;
}

.amm-msg-bot {
  align-self: flex-start;
  background: var(--amm-bg-alt);
  border: 1px solid var(--amm-border);
  border-bottom-left-radius: 4px;
}

.amm-msg-user {
  align-self: flex-end;
  background: var(--amm-accent);
  color: var(--amm-accent-text);
  border-bottom-right-radius: 4px;
  font-weight: 500;
}

.amm-msg a {
  color: var(--amm-accent);
  text-decoration: underline;
}

.amm-msg-user a {
  color: var(--amm-accent-text);
}

.amm-msg-error {
  align-self: center;
  background: transparent;
  color: var(--amm-error);
  border: 1px dashed var(--amm-error);
  font-size: 13px;
  text-align: center;
  max-width: 90%;
}

/* === Typing indicator === */
.amm-typing {
  align-self: flex-start;
  background: var(--amm-bg-alt);
  border: 1px solid var(--amm-border);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 12px 14px;
  display: flex;
  gap: 4px;
}

.amm-typing.amm-hidden {
  display: none;
}

.amm-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--amm-text-muted);
  animation: amm-blink 1.4s infinite ease-in-out both;
}

.amm-typing-dot:nth-child(1) { animation-delay: 0s; }
.amm-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.amm-typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* === Input area === */
.amm-input-area {
  border-top: 1px solid var(--amm-border);
  padding: 12px;
  background: var(--amm-bg);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.amm-textarea {
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  padding: 10px 12px;
  background: var(--amm-bg-alt);
  border: 1px solid var(--amm-border);
  border-radius: 10px;
  color: var(--amm-text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  resize: none;
  outline: none;
  transition: border-color 0.15s ease;
}

.amm-textarea:focus {
  border-color: var(--amm-accent);
}

.amm-textarea::placeholder {
  color: var(--amm-text-muted);
}

#amm-chat .amm-send {
  width: 40px;
  height: 40px;
  border: none !important;
  background: var(--amm-accent) !important;
  color: var(--amm-accent-text) !important;
  border-radius: 10px !important;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease, opacity 0.15s ease;
  box-shadow: none !important;
  text-transform: none !important;
  letter-spacing: normal !important;
}

#amm-chat .amm-send:hover {
  background: var(--amm-accent-hover) !important;
  color: var(--amm-accent-text) !important;
}

#amm-chat .amm-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: var(--amm-accent) !important;
}

.amm-send svg {
  width: 18px;
  height: 18px;
}

/* === Footer disclaimer === */
.amm-disclaimer {
  font-size: 11px;
  color: var(--amm-text-muted);
  text-align: center;
  padding: 6px 12px 10px;
  background: var(--amm-bg);
}

.amm-disclaimer strong {
  color: var(--amm-text);
}

/* === Animazioni === */
@keyframes amm-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes amm-slide-up {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes amm-blink {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1); }
}

/* === Mobile (floating card - chat overlay sopra al sito, NON full-screen) === */
@media (max-width: 480px) {
  .amm-window {
    /* Floating card: margini su tutti i lati, si vede pagina sotto */
    width: calc(100% - 16px);
    height: 78vh;
    height: 78dvh;             /* dynamic viewport: si adatta a tastiera */
    max-height: 78vh;
    max-height: 78dvh;
    bottom: max(16px, env(safe-area-inset-bottom));
    right: 8px;
    left: 8px;
    border-radius: 16px;       /* arrotondato su TUTTI i lati */
    border: 1px solid var(--amm-border);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
    animation: amm-slide-up-mobile 0.26s cubic-bezier(0.32, 0.72, 0, 1);
  }

  /* Tap target minimo 44x44 (Apple HIG) */
  .amm-icon-button {
    width: 44px;
    height: 44px;
  }
  .amm-icon-button svg {
    width: 20px;
    height: 20px;
  }

  .amm-messages {
    padding: 14px 16px;
  }

  /* Mobile: chatbot a destra, alzato al 19% del viewport per non sovrapporsi al CTA "Chiama".
   * Usa #amm-chat per matchare la specificity del selettore base (altrimenti il bottom desktop
   * sovrascrive il mobile). */
  #amm-chat .amm-fab {
    bottom: 19%;
    right: 21px;
    width: 60px;
    height: 60px;
  }

  .amm-bubble {
    right: 21px;
    /* Bottom = FAB bottom (19%) + altezza FAB (60px) + gap (12px) */
    bottom: calc(19% + 72px);
    max-width: calc(100vw - 42px);
  }

  /* Input area in fondo (la card si occupa gia della safe-area col bottom margin) */
  .amm-input-area {
    padding-bottom: 12px;
  }
}

@keyframes amm-slide-up-mobile {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
