/* ============================================
   CHATBOT - FONT PIÙ GRANDI E VISIBILI
   ============================================ */

#aa-chat-launcher {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10000;
  border: none;
  background: #e63977;
  color: #fff;
  border-radius: 999px;
  padding: 10px 16px;
  box-shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.6);
  cursor: pointer;
  font: 700 16px/1 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  transition: transform 0.2s ease;
}

#aa-chat-launcher:hover {
  transform: translateY(-2px);
}

.chat-launcher-inner {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-launcher-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.8);
  background: #fff;
  flex: 0 0 auto;
}

.chat-launcher-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-launcher-icon {
  font-size: 20px;
  line-height: 1;
}

.chat-launcher-text {
  display: inline-block;
  font-weight: 700;
}

.chat-widget {
  position: fixed;
  right: 16px;
  bottom: 84px;
  width: min(420px, calc(100vw - 32px));
  height: min(620px, calc(100vh - 120px));
  max-height: 80vh;
  background: #fff;
  border-radius: 22px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.22);
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  z-index: 9999;
}

.chat-widget.is-open {
  display: flex;
}

.chat-header {
  background: linear-gradient(135deg, #e63977 0%, #ff7b7b 100%);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px 14px 14px;
  position: relative;
  flex: 0 0 auto;
  min-height: 68px;
}

.chat-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.75);
  flex: 0 0 auto;
  background: #fff;
}

.chat-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-header-text {
  flex: 1;
  min-width: 0;
  padding-right: 72px;
}

.chat-header-text strong {
  display: block;
  font-size: 18px;
  line-height: 1.3;
  font-weight: 700;
}

.chat-header-text span {
  display: block;
  font-size: 13px;
  opacity: 0.92;
  font-weight: 400;
}

.chat-btn {
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 22px;
  line-height: 1;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.chat-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.chat-close {
  font-size: 26px;
  position: absolute;
  top: 12px;
  right: 12px;
}

.chat-dots {
  position: absolute;
  top: 12px;
  right: 48px;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 24px;
  line-height: 1;
  width: 34px;
  height: 34px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s ease;
}

.chat-dots:hover {
  background: rgba(255, 255, 255, 0.15);
}

.chat-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  background: #f4f7fb;
  min-height: 0;
}

.chat-message {
  max-width: 92%;
  margin: 0 0 12px;
  padding: 12px 16px;
  border-radius: 16px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 16px;
}

.chat-message.bot {
  background: #fff;
  color: #1f2d3d;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.chat-message.user {
  background: #dff3ff;
  color: #1f2d3d;
  margin-left: auto;
  border-bottom-right-radius: 4px;
}

.chat-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  background: #fff;
  display: flex;
  gap: 10px;
  flex: 0 0 auto;
  min-height: 68px;
  align-items: center;
}

.chat-footer input {
  flex: 1;
  border: 1.5px solid rgba(0, 0, 0, 0.14);
  border-radius: 999px;
  padding: 14px 18px;
  font-size: 16px;
  min-width: 0;
  outline: none;
  height: 50px;
  background: #f8f9fa;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-footer input:focus {
  border-color: #e63977;
  box-shadow: 0 0 0 4px rgba(230, 57, 119, 0.12);
  background: #fff;
}

.chat-footer input::placeholder {
  color: #999;
  font-size: 15px;
}

.chat-footer button {
  border: none;
  background: #e63977;
  color: #fff;
  border-radius: 999px;
  padding: 14px 22px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  flex: 0 0 auto;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.chat-footer button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(230, 57, 119, 0.35);
}

.chat-footer button:disabled,
.chat-footer input:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.chat-menu {
  position: absolute;
  top: 56px;
  right: 12px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.16);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 220px;
  z-index: 20;
}

.chat-menu[hidden] {
  display: none !important;
}

.chat-menu button {
  border: 0;
  background: #f3f6fb;
  color: #1f2d3d;
  border-radius: 10px;
  padding: 12px 16px;
  text-align: left;
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
  transition: background 0.15s ease;
}

.chat-menu button:hover {
  background: #e9ecf2;
}

.chat-modal {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.28);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 14px;
  z-index: 30;
}

.chat-modal[hidden] {
  display: none !important;
}

.chat-modal-box {
  width: 100%;
  background: #fff;
  border-radius: 20px;
  padding: 20px;
  max-height: 78%;
  overflow: auto;
  position: relative;
}

.chat-modal-box h3 {
  font-size: 20px;
  margin-bottom: 12px;
  color: #1f2d3d;
}

.chat-modal-box p {
  font-size: 16px;
  line-height: 1.6;
  color: #4a5568;
}

.chat-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  border: 0;
  background: transparent;
  font-size: 30px;
  cursor: pointer;
  color: #666;
  transition: color 0.2s ease;
}

.chat-modal-close:hover {
  color: #1f2d3d;
}

/* ============================================
   FIX PER CHROME MOBILE
   ============================================ */

@supports (-webkit-touch-callout: none) {
  .chat-widget {
    height: -webkit-fill-available !important;
    max-height: -webkit-fill-available !important;
  }
}

@media screen and (-webkit-min-device-pixel-ratio: 0) and (max-width: 640px) {
  @media not all and (min-resolution: .001dpcm) {
    .chat-widget {
      max-height: 60vh !important;
      height: auto !important;
      bottom: 80px !important;
    }
  }
}

/* ============================================
   MOBILE RESPONSIVE - FONT PIÙ GRANDI
   ============================================ */

@media (max-width: 640px) {
  #aa-chat-launcher {
    right: 10px;
    bottom: 10px;
    padding: 8px 12px;
    font-size: 14px;
  }

  .chat-launcher-text {
    display: none;
  }

  .chat-launcher-avatar {
    width: 30px;
    height: 30px;
  }

  .chat-launcher-icon {
    font-size: 18px;
  }

  .chat-widget {
    right: 10px;
    bottom: 78px;
    width: calc(100% - 20px);
    max-width: calc(100% - 20px);
    height: auto;
    max-height: 60vh;
    min-height: 350px;
    border-radius: 18px;
  }

  .chat-header {
    padding: 12px 14px;
    min-height: 58px;
    gap: 10px;
  }

  .chat-avatar {
    width: 38px;
    height: 38px;
  }

  .chat-header-text {
    padding-right: 60px;
  }

  .chat-header-text strong {
    font-size: 16px;
  }

  .chat-header-text span {
    font-size: 12px;
  }

  .chat-btn {
    width: 30px;
    height: 30px;
    font-size: 20px;
  }

  .chat-close {
    font-size: 22px;
    top: 10px;
    right: 10px;
  }

  .chat-dots {
    font-size: 20px;
    right: 38px;
    top: 10px;
    width: 28px;
    height: 28px;
  }

  .chat-body {
    padding: 12px;
    max-height: 200px;
    flex: 1 1 auto;
  }

  .chat-message {
    font-size: 15px;
    padding: 10px 14px;
    margin-bottom: 10px;
    border-radius: 14px;
  }

  .chat-footer {
    padding: 10px 12px;
    min-height: 58px;
    gap: 8px;
  }

  .chat-footer input {
    padding: 10px 14px;
    font-size: 15px;
    height: 42px;
    min-height: 42px;
  }

  .chat-footer input::placeholder {
    font-size: 14px;
  }

  .chat-footer button {
    padding: 10px 16px;
    font-size: 15px;
    height: 42px;
    min-height: 42px;
  }

  .chat-menu {
    right: 10px;
    top: 48px;
    min-width: 180px;
    max-width: calc(100% - 20px);
  }

  .chat-menu button {
    font-size: 14px;
    padding: 10px 14px;
  }

  .chat-modal-box h3 {
    font-size: 18px;
  }

  .chat-modal-box p {
    font-size: 15px;
  }
}

/* ============================================
   SCHERMI MOLTO PICCOLI
   ============================================ */

@media (max-width: 380px) {
  .chat-widget {
    right: 6px;
    bottom: 70px;
    width: calc(100% - 12px);
    max-width: calc(100% - 12px);
    max-height: 55vh;
    min-height: 280px;
    border-radius: 14px;
  }

  .chat-header {
    padding: 10px 12px;
    min-height: 50px;
  }

  .chat-avatar {
    width: 32px;
    height: 32px;
  }

  .chat-header-text {
    padding-right: 50px;
  }

  .chat-header-text strong {
    font-size: 14px;
  }

  .chat-header-text span {
    font-size: 11px;
  }

  .chat-body {
    padding: 10px;
    max-height: 160px;
  }

  .chat-message {
    font-size: 14px;
    padding: 8px 12px;
  }

  .chat-footer {
    padding: 8px 10px;
    min-height: 50px;
  }

  .chat-footer input {
    padding: 8px 12px;
    font-size: 14px;
    height: 36px;
    min-height: 36px;
  }

  .chat-footer input::placeholder {
    font-size: 13px;
  }

  .chat-footer button {
    padding: 8px 14px;
    font-size: 14px;
    height: 36px;
    min-height: 36px;
  }

  .chat-dots {
    font-size: 18px;
    right: 32px;
    top: 8px;
    width: 24px;
    height: 24px;
  }

  .chat-close {
    font-size: 20px;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
  }

  .chat-menu {
    right: 6px;
    top: 40px;
    min-width: 150px;
  }

  .chat-menu button {
    font-size: 13px;
    padding: 8px 12px;
  }

  #aa-chat-launcher {
    right: 8px;
    bottom: 8px;
    padding: 6px 10px;
  }

  .chat-launcher-avatar {
    width: 26px;
    height: 26px;
  }

  .chat-launcher-icon {
    font-size: 16px;
  }
}

/* ============================================
   TABLET
   ============================================ */

@media (min-width: 641px) and (max-width: 1024px) {
  .chat-widget {
    right: 14px;
    bottom: 80px;
    width: min(380px, calc(100vw - 28px));
    height: min(580px, calc(100vh - 110px));
  }

  .chat-header-text {
    padding-right: 68px;
  }

  .chat-dots {
    right: 42px;
  }
}


/* ============================================
   FIX SOVRAPPOSIZIONE LAUNCHER CON PULSANTE INVIA
   ============================================ */

/* Il launcher rimane in basso a destra ma con un offset maggiore */
#aa-chat-launcher {
  bottom: 20px !important;
  right: 20px !important;
}

/* Su mobile, spostiamo il launcher più in alto quando il form è visibile */
@media (max-width: 640px) {
  #aa-chat-launcher {
    bottom: 90px !important;
    right: 16px !important;
    z-index: 9999 !important;
  }

  /* Se la chat è aperta, il launcher scompare */
  #aa-chat-launcher.chat-open {
    display: none !important;
  }

  /* Il pulsante invia del form deve stare più in alto */
  .lead-form .submit-btn {
    margin-bottom: 80px !important;
  }

  /* La sezione CTA deve avere più padding in basso */
  .cta-section {
    padding-bottom: 100px !important;
  }

  /* Se il modulo è nell'ultima sezione, diamo spazio */
  #annuncio {
    scroll-margin-bottom: 100px;
  }
}

/* Schermi molto piccoli */
@media (max-width: 380px) {
  #aa-chat-launcher {
    bottom: 80px !important;
    right: 12px !important;
  }

  .lead-form .submit-btn {
    margin-bottom: 70px !important;
  }
}