/**
 * Lella Chat — WA-style chat interface for /parla-con-noi
 * Author: Luca — 07/05/2026 — event bot-lella-giada-20260507
 *
 * Brand tokens Giada:
 *   coral   #F19D76    crema   #FFF5E6
 *   salvia  #A8B99C    bordeaux #4B1528
 *
 * Mantiene la cifra Giada ma adotta il pattern WhatsApp che il pubblico
 * di Meta Ads conosce (le bolle, l'header sticky, l'input fissa in basso).
 * Verde WA scelto sull'header per affinita' percettiva con il canale
 * WhatsApp che Giada usa quotidianamente — non e' verde brand Giada.
 */

/* Reset difensivo per /parla-con-noi PWA: blocca overflow-x e forza il
   viewport meta come constraint visivo anche se il main stylesheet non e'
   caricato (la pagina chat carica solo bootstrap-giada.css come framework
   base, non style.css con il reset originale). Luca 11/05/2026. */
html, body {
  overflow-x: hidden;
  max-width: 100vw;
}

/* ----------------------------------------------------------------
   Full-screen chat-app mode (body.lella-fullscreen)
   ----------------------------------------------------------------
   Carlo 11/05/2026: la landing chat deve sentirsi come una chat app
   stand-alone — niente navbar Bootstrap, niente offset, niente footer
   visibile. La lella-shell occupa l'intero viewport (100dvh per evitare
   la barra bianca da chrome mobile su iOS/Android).

   Vale sia desktop che mobile. Le altre pagine del sito mantengono la
   navbar normale: la classe vive solo qui (set in parla-con-noi.php).
   Luca 11/05/2026 (event chat-fix-20260511). */
body.lella-fullscreen nav.navbar.navbar-giada,
body.lella-fullscreen > header,
body.lella-fullscreen .site-footer-giada {
  display: none !important;
}

body.lella-fullscreen main {
  padding-top: 0 !important;
  margin-top: 0 !important;
}

body.lella-fullscreen,
body.lella-fullscreen html {
  margin: 0;
  padding: 0;
  height: 100%;
}

/* Su questa pagina la shell e' gia' position:fixed inset:0,
   ma forziamo height esplicita per il dynamic viewport.
   Ordine fallback (cascade vince l'ultima supportata):
     100vh        → fallback browser vecchi (include URL bar)
     100svh       → small viewport, esclude URL bar (sempre visibile)
     100dvh       → dynamic viewport, si adatta (Firefox 122+, Safari 15.4+)
   Su Firefox Android la URL bar copriva il fondo (input area tagliata,
   bottone send oltre la fold): 100svh garantisce che la shell stia
   SEMPRE dentro la viewport visibile, anche con URL bar mostrata.
   Luca 11/05/2026 (event chat-fix-20260511-3). */
body.lella-fullscreen .lella-shell {
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  max-height: 100svh; /* ancora di sicurezza: mai oltre il small viewport */
}

:root {
  --lc-wa-header:    #075E54;
  --lc-wa-header-2:  #128C7E;
  --lc-wa-bg:        #ECE5DD;
  --lc-bubble-in:    #FFFFFF;
  --lc-bubble-out:   #DCF8C6;
  --lc-text:         #1F2C34;
  --lc-text-muted:   #667781;
  --lc-coral:        #F19D76;
  --lc-coral-dark:   #D97847;
  --lc-crema:        #FFF5E6;
  --lc-salvia:       #A8B99C;
  --lc-bordeaux:     #4B1528;
  --lc-shadow-soft:  0 1px 2px rgba(11, 20, 26, 0.13);
  --lc-shadow-bar:   0 -2px 8px rgba(11, 20, 26, 0.08);
}

/* ----------------------------------------------------------------
   Shell & layout
---------------------------------------------------------------- */

.lella-shell {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--lc-wa-bg);
  z-index: 5;
  /* Sotto la navbar sticky principale (z-index 1030 di Bootstrap). */
}

.lella-shell--embedded {
  position: relative;
  inset: auto;
  height: calc(100vh - 80px);
  min-height: 520px;
}

/* ----------------------------------------------------------------
   Header chat (verde WA + avatar Lella)
---------------------------------------------------------------- */

.lella-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: linear-gradient(180deg, var(--lc-wa-header) 0%, var(--lc-wa-header-2) 100%);
  color: #fff;
  box-shadow: var(--lc-shadow-soft);
  flex: 0 0 auto;
}

.lella-header__back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  background: transparent;
  color: #fff;
  text-decoration: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.lella-header__back:hover { background: rgba(255,255,255,0.12); color: #fff; }

.lella-header__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--lc-coral) center/cover no-repeat;
  flex: 0 0 auto;
  border: 2px solid rgba(255,255,255,0.3);
}

.lella-header__meta {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  flex: 1 1 auto;
  min-width: 0;
}

.lella-header__title {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lella-header__status {
  font-size: 12px;
  opacity: 0.85;
  margin: 1px 0 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.lella-header__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #25D366;
  display: inline-block;
}

.lella-header__dot--human {
  background: var(--lc-coral);
  box-shadow: 0 0 0 3px rgba(241, 157, 118, 0.25);
  animation: lc-pulse 1.6s ease-in-out infinite;
}

@keyframes lc-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(241, 157, 118, 0.55); }
  50%      { box-shadow: 0 0 0 8px rgba(241, 157, 118, 0); }
}

/* ----------------------------------------------------------------
   Banner take-over umano
---------------------------------------------------------------- */

.lella-takeover-banner {
  background: var(--lc-crema);
  color: var(--lc-bordeaux);
  border-bottom: 1px solid rgba(75, 21, 40, 0.15);
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

/* ----------------------------------------------------------------
   Log messaggi
---------------------------------------------------------------- */

.lella-log {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 12px 18px;
  background-color: var(--lc-wa-bg);
  /* Texture WA-style sottile */
  background-image:
    radial-gradient(circle at 12% 22%, rgba(255,255,255,0.35) 0, transparent 1.2px),
    radial-gradient(circle at 78% 72%, rgba(0,0,0,0.04) 0, transparent 1.2px);
  background-size: 28px 28px, 36px 36px;
  scroll-behavior: smooth;
}

.lella-msg {
  display: flex;
  margin: 4px 0;
  align-items: flex-end;
  gap: 6px;
}

.lella-msg--in   { justify-content: flex-start; }
.lella-msg--out  { justify-content: flex-end; }
.lella-msg--system { justify-content: center; }

.lella-bubble {
  max-width: min(80%, 560px);
  padding: 7px 10px 8px;
  border-radius: 8px;
  background: var(--lc-bubble-in);
  color: var(--lc-text);
  box-shadow: var(--lc-shadow-soft);
  font-size: 14.5px;
  line-height: 1.4;
  word-wrap: break-word;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
}

.lella-msg--out .lella-bubble {
  background: var(--lc-bubble-out);
}

/* Code WA-style con clip-path (no SVG, niente asset extra) */
.lella-msg--in .lella-bubble::before,
.lella-msg--out .lella-bubble::before {
  content: '';
  position: absolute;
  bottom: 0;
  width: 8px;
  height: 13px;
  background: inherit;
}
.lella-msg--in .lella-bubble::before {
  left: -7px;
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
}
.lella-msg--out .lella-bubble::before {
  right: -7px;
  clip-path: polygon(0 0, 100% 100%, 0 100%);
}

.lella-bubble__time {
  font-size: 11px;
  color: var(--lc-text-muted);
  margin-left: 8px;
  float: right;
  margin-top: 4px;
  user-select: none;
}

.lella-bubble--system {
  background: rgba(225, 245, 254, 0.85);
  color: #024;
  font-size: 12.5px;
  text-align: center;
  padding: 6px 12px;
  box-shadow: none;
  border-radius: 16px;
  max-width: 85%;
}

/* ----------------------------------------------------------------
   Indicatore "sta scrivendo..."
---------------------------------------------------------------- */

.lella-typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
}
.lella-typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--lc-text-muted);
  opacity: 0.5;
  animation: lc-typing 1.2s infinite ease-in-out;
}
.lella-typing span:nth-child(2) { animation-delay: 0.2s; }
.lella-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes lc-typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* ----------------------------------------------------------------
   Form lead capture (inline nella conversazione)
---------------------------------------------------------------- */

.lella-leadform {
  background: #fff;
  border-radius: 12px;
  padding: 14px 14px 12px;
  margin: 6px 0 6px 0;
  max-width: min(85%, 520px);
  box-shadow: var(--lc-shadow-soft);
  border-left: 3px solid var(--lc-coral);
}

.lella-leadform__title {
  font-size: 14.5px;
  font-weight: 600;
  margin: 0 0 8px;
  color: var(--lc-bordeaux);
}

.lella-leadform__row {
  margin-bottom: 8px;
}

.lella-leadform__row label {
  display: block;
  font-size: 12.5px;
  color: var(--lc-text-muted);
  margin-bottom: 3px;
  font-weight: 500;
}

.lella-leadform__row input[type="text"],
.lella-leadform__row input[type="tel"],
.lella-leadform__row input[type="email"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #d6dbe0;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}

.lella-leadform__row input:focus {
  border-color: var(--lc-coral);
  outline: 2px solid rgba(241, 157, 118, 0.25);
  outline-offset: 0;
}

.lella-leadform__consent {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--lc-text-muted);
  margin: 8px 0 12px;
}
.lella-leadform__consent input[type="checkbox"] {
  margin-top: 2px;
  flex: 0 0 auto;
}
.lella-leadform__consent a { color: var(--lc-coral-dark); }

.lella-leadform__submit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border: 0;
  border-radius: 999px;
  background: var(--lc-coral);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background 120ms;
}
.lella-leadform__submit:hover { background: var(--lc-coral-dark); }
.lella-leadform__submit:disabled { background: #c9c9c9; cursor: not-allowed; }

.lella-leadform__error {
  font-size: 12.5px;
  color: #b3261e;
  margin: -2px 0 6px;
  min-height: 16px;
}

/* ----------------------------------------------------------------
   Input bar
---------------------------------------------------------------- */

.lella-inputbar {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px max(8px, env(safe-area-inset-bottom));
  /* Safe-area orizzontali: alcune dashboard mobile (Firefox Android in
     landscape, iPhone Pro notch) inset i lati: rispettiamo entrambe per
     non far uscire il bottone send a destra. Luca 11/05/2026. */
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
  background: #F0F2F5;
  box-shadow: var(--lc-shadow-bar);
  border-top: 1px solid rgba(0,0,0,0.06);
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.lella-inputbar__textarea {
  flex: 1 1 auto;
  /* CRITICO: senza min-width:0 il textarea su flex child non puo'
     shrinkare sotto il proprio intrinsic min-content, e su Firefox
     mobile (viewport stretto + placeholder/contenuto) spinge il
     bottone send fuori a destra del viewport. Vale per tutti i
     browser ma Firefox Android e' quello che lo manifesta peggio.
     Luca 11/05/2026 (event chat-fix-20260511-3). */
  min-width: 0;
  width: 100%;
  resize: none;
  min-height: 42px;
  max-height: 120px;
  padding: 10px 14px;
  border-radius: 22px;
  border: 0;
  background: #fff;
  font-size: 15px;
  line-height: 1.4;
  font-family: inherit;
  outline: none;
  box-shadow: var(--lc-shadow-soft);
  box-sizing: border-box;
}

.lella-inputbar__textarea:focus {
  outline: 2px solid rgba(241, 157, 118, 0.4);
  outline-offset: 0;
}

.lella-inputbar__send {
  /* flex-shrink:0 esplicito: garantisce che il bottone non si comprima
     mai sotto i 44px richiesti dalle linee guida accessibilita' touch.
     Luca 11/05/2026 (event chat-fix-20260511-3). */
  flex: 0 0 44px;
  flex-shrink: 0;
  width: 44px;
  min-width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: var(--lc-wa-header-2);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 120ms, transform 80ms;
}
.lella-inputbar__send:hover  { background: var(--lc-wa-header); }
.lella-inputbar__send:active { transform: scale(0.94); }
.lella-inputbar__send:disabled { background: #aab2b8; cursor: not-allowed; }
.lella-inputbar__send svg { width: 22px; height: 22px; }

/* ----------------------------------------------------------------
   Mobile tweaks
---------------------------------------------------------------- */

@media (max-width: 480px) {
  .lella-bubble { max-width: 86%; font-size: 14.5px; }
  .lella-header__title { font-size: 14.5px; }
  .lella-header__status { font-size: 11.5px; }
}

/* ----------------------------------------------------------------
   Stato errore di rete
---------------------------------------------------------------- */

.lella-net-error {
  text-align: center;
  font-size: 12.5px;
  color: #b3261e;
  padding: 8px 12px;
  background: #fff3f3;
  border-bottom: 1px solid #ffd7d7;
}

/* ----------------------------------------------------------------
   Accessibilita': focus visibili
---------------------------------------------------------------- */

.lella-shell button:focus-visible,
.lella-shell a:focus-visible,
.lella-shell input:focus-visible,
.lella-shell textarea:focus-visible {
  outline: 3px solid var(--lc-coral);
  outline-offset: 2px;
}
