/* ============================================================
   TigiBOT — stile TigiTAG (mobile-first)
   Font: Poppins (titoli) / Nunito (testi)
   Colori: Bianco / Blu notte #1A2B33
   Accenti: Azzurro Tigi #00BCD4 / Arancione #FF7043
   ============================================================ */

:root {
  --tigi-blu-notte: #1A2B33;
  --tigi-azzurro: #00BCD4;
  --tigi-arancione: #FF7043;
  --tigi-bianco: #ffffff;
  --tigi-verde: #2ECC71;
  --tigi-testo-titolo: #1A2B33;
  --tigi-testo-paragrafo: #5A6A72;
  --tigi-sfondo-chiaro: #F4F9FB;
  --tigi-bordo-chiaro: #E0E6E9;
  --radius-lg: 32px;
  --radius-xl: 50px;
  --shadow-soft: 0 10px 30px rgba(26, 43, 51, 0.08);
}

* {
  box-sizing: border-box;
}

/* Rete di sicurezza: qualsiasi classe che imposta "display" (flex, block, ...)
   ha la stessa specificità della regola [hidden] del browser, quindi vincerebbe
   per ordine nel foglio di stile e terrebbe l'elemento visibile anche con
   l'attributo hidden impostato. Con !important l'attributo hidden vince sempre. */
[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  /* Mai una scrollbar sulla PAGINA: solo .chat-area (o .news-page-list) scrolla
     internamente. Senza questo, su mobile lo scarto tra "100vh" e l'altezza
     visibile reale (barra indirizzi/tastiera) rende la pagina intera
     scrollabile e si finisce "in fondo" invece che in cima alla chat. */
  overflow: hidden;
  background-color: var(--tigi-bianco);
  font-family: 'Nunito', sans-serif;
  color: var(--tigi-testo-paragrafo);
}

/* Contenitore principale della PWA, con in più il comportamento "widget
   flottante" da 768px in su (vedi sotto). 100dvh (viewport dinamico) invece
   di 100vh: su mobile si adatta alla reale area visibile (barra
   indirizzi/tastiera), 100vh resta come fallback per i browser che non lo
   supportano ancora. position:relative ancora i pop-up (.modal-overlay) ai
   confini dello shell anche nel widget flottante da desktop. */
.app-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background-color: var(--tigi-bianco);
  overflow: hidden;
}

/* ---------- HEADER ---------- */
.tigi-header {
  position: relative;
  background-color: var(--tigi-blu-notte);
  padding: 18px 20px;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  box-shadow: var(--shadow-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* ---------- HAMBURGER (menu funzioni secondarie) ---------- */
.hamburger-btn {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.hamburger-btn:hover,
.hamburger-btn[aria-expanded="true"] {
  background-color: rgba(255, 255, 255, 0.12);
}

.hamburger-icon {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 20px;
}

.hamburger-icon span {
  display: block;
  height: 2px;
  border-radius: 2px;
  background-color: var(--tigi-bianco);
}

.hamburger-menu {
  position: absolute;
  top: 100%;
  left: 16px;
  margin-top: 8px;
  min-width: 190px;
  max-height: calc(100dvh - 90px);
  overflow-y: auto;
  background-color: var(--tigi-bianco);
  border: 1px solid var(--tigi-bordo-chiaro);
  border-radius: 18px;
  box-shadow: var(--shadow-soft);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 40;
}

.hamburger-menu-item {
  background: none;
  border: none;
  text-align: left;
  padding: 12px 14px;
  border-radius: 12px;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 14px;
  color: var(--tigi-testo-titolo);
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.hamburger-menu-item:hover {
  background-color: var(--tigi-sfondo-chiaro);
}

/* "Emergenza" risalta rispetto agli altri: sfondo arancione pieno, non il solito hover chiaro. */
.hamburger-menu-item[data-key="emergenza"] {
  background-color: var(--tigi-arancione);
  color: var(--tigi-bianco);
}

.hamburger-menu-item[data-key="emergenza"]:hover {
  background-color: #E85A2A;
}

.hamburger-lang-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px 4px;
  border-top: 1px solid var(--tigi-bordo-chiaro);
  margin-top: 4px;
}

/* ---------- ACCESSO CON GOOGLE (in cima al menu ☰) ---------- */
.hamburger-google-row {
  padding: 4px 14px 10px;
  border-bottom: 1px solid var(--tigi-bordo-chiaro);
  margin-bottom: 4px;
}

#google-signin-container {
  display: flex;
  justify-content: center;
}

/* ---------- BADGE "AREA PERSONALE" (mascotte a colori/grigia + puntino di stato) ---------- */
.account-status-btn {
  flex: 0 0 auto;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

.account-status-avatar {
  position: relative;
  display: block;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  overflow: hidden;
  background-color: var(--tigi-bianco);
  box-shadow: var(--shadow-soft);
}

.account-status-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: filter 0.2s ease;
}

/* Non loggato: mascotte "spenta". Tolta (vedi #account-status-img senza questa classe) appena loggato. */
.account-status-avatar img.is-off {
  filter: grayscale(1) opacity(0.55);
}

.account-status-dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--tigi-bianco);
  background-color: var(--tigi-testo-paragrafo);
  transition: background-color 0.2s ease;
}

.account-status-dot.is-on {
  background-color: var(--tigi-verde);
}

.account-panel {
  position: absolute;
  top: 100%;
  left: 16px;
  right: 16px;
  margin-top: 8px;
  background-color: var(--tigi-bianco);
  border: 1px solid var(--tigi-bordo-chiaro);
  border-radius: 18px;
  box-shadow: var(--shadow-soft);
  padding: 14px;
  z-index: 40;
}

.account-panel-view {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.account-panel-view p {
  margin: 0;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 14px;
  color: var(--tigi-testo-titolo);
}

.account-panel-error {
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 13px;
  color: var(--tigi-arancione);
}

.account-panel-label {
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--tigi-testo-paragrafo);
}

.account-panel-value {
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 15px;
  color: var(--tigi-testo-titolo);
  word-break: break-word;
}

.account-signout-btn {
  align-self: flex-start;
  margin-top: 4px;
  background: none;
  border: none;
  padding: 0;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 13px;
  color: var(--tigi-azzurro);
  text-decoration: underline;
  cursor: pointer;
}

.hamburger-lang-row label {
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 13px;
  color: var(--tigi-testo-paragrafo);
}

.lang-switcher {
  background-color: var(--tigi-sfondo-chiaro);
  color: var(--tigi-testo-titolo);
  border: 1px solid var(--tigi-bordo-chiaro);
  border-radius: 100px;
  padding: 6px 10px;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}

.news-page-lang-row {
  display: flex;
  justify-content: flex-end;
  padding: 10px 16px 0;
}

.tigi-header-brand {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1;
}

/* ---------- BADGE STATO CONNESSIONE ---------- */
.connection-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 7px 12px;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.connection-badge.online {
  background-color: #E0F7FA;
  color: #007A86;
}

.connection-badge.online .connection-dot {
  background-color: var(--tigi-azzurro);
  animation: connection-pulse 2s infinite;
}

.connection-badge.offline {
  background-color: #FFF3E0;
  color: var(--tigi-arancione);
}

.connection-badge.offline .connection-dot {
  background-color: var(--tigi-arancione);
}

.connection-badge.checking {
  background-color: var(--tigi-sfondo-chiaro);
  color: var(--tigi-testo-paragrafo);
}

/* Visibile solo da offline: online (o non ancora verificato) non ha nulla da segnalare. */
.connection-badge.online,
.connection-badge.checking {
  display: none;
}

.connection-badge.checking .connection-dot {
  background-color: var(--tigi-testo-paragrafo);
}

@keyframes connection-pulse {
  0% { box-shadow: 0 0 0 0 rgba(0, 188, 212, 0.5); }
  70% { box-shadow: 0 0 0 5px rgba(0, 188, 212, 0); }
  100% { box-shadow: 0 0 0 0 rgba(0, 188, 212, 0); }
}

/* ---------- BADGE NEWS (barra sotto l'header, visibile solo online) ---------- */
.news-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 7px 12px;
  border: none;
  background-color: #E0F7FA;
  color: #007A86;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
}

.news-badge .connection-dot {
  background-color: var(--tigi-azzurro);
}

@keyframes news-blink {
  0%, 50% { opacity: 1; }
  25%, 75% { opacity: 0.4; }
}

.news-badge.is-new {
  animation: news-blink 1.2s infinite;
}

.news-view-all-btn {
  display: block;
  margin-top: 16px;
  background: none;
  border: none;
  padding: 0;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 13px;
  color: var(--tigi-azzurro);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.news-view-all-btn:hover {
  color: var(--tigi-blu-notte);
}

/* ---------- POP-UP GENERICO (overlay + card), usato dai due pop-up News ---------- */
.modal-overlay {
  position: absolute;
  inset: 0;
  background-color: rgba(26, 43, 51, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 250;
}

.modal-card {
  background-color: var(--tigi-bianco);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 380px;
  max-height: 80%;
  overflow-y: auto;
  padding: 20px;
  position: relative;
  box-shadow: var(--shadow-soft);
}

.modal-close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  font-size: 20px;
  color: var(--tigi-testo-paragrafo);
  cursor: pointer;
}

/* ---------- ELENCO NEWS AD ACCORDION (dentro il pop-up "Vedi tutte") ---------- */
.news-page-list {
  padding: 20px 16px;
  overflow-y: auto;
  flex: 1;
}

.news-page-item {
  padding: 16px 0;
  border-bottom: 1px solid var(--tigi-sfondo-chiaro);
}

.news-page-item:last-child {
  border-bottom: none;
}

.news-page-item-toggle {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

.news-page-item-date {
  font-size: 12px;
  color: var(--tigi-testo-paragrafo);
  font-weight: 700;
  margin-bottom: 6px;
}

.news-page-item-title {
  display: block;
  font-size: 15px;
  font-weight: 700;
  color: var(--tigi-testo-titolo);
}

.news-page-item-content {
  margin-top: 10px;
  font-size: 15px;
  color: var(--tigi-testo-titolo);
  line-height: 1.5;
}

.news-page-item-content p {
  margin: 0 0 8px;
}

.news-page-empty,
.news-page-error {
  text-align: center;
  color: var(--tigi-testo-paragrafo);
  padding: 40px 20px;
}

.tigi-header-logo {
  font-family: 'Poppins', sans-serif;
  font-weight: 800;
  font-size: 22px;
  color: var(--tigi-bianco);
}

.tigi-header-logo .accent {
  color: var(--tigi-azzurro);
}

.tigi-badge {
  background-color: rgba(0, 188, 212, 0.15);
  color: var(--tigi-azzurro);
  padding: 6px 14px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ---------- OFFLINE BANNER ---------- */
.offline-banner {
  background-color: #FFF3E0;
  color: var(--tigi-arancione);
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 14px;
  text-align: center;
  padding: 10px 16px;
}

/* ---------- CHAT AREA ---------- */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* "Carta da parati" della chat, in stile WhatsApp: un fondo leggermente
     diverso dal bianco puro delle bolle, così i messaggi risaltano di più. */
  background-color: #EAF3F5;
  background-image:
    radial-gradient(rgba(0, 188, 212, 0.05) 1px, transparent 1px);
  background-size: 18px 18px;
}

.chat-bubble {
  position: relative;
  max-width: 82%;
  padding: 10px 14px 8px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.4;
  box-shadow: var(--shadow-soft);
  animation: bubble-in 0.2s ease-out;
}

.chat-bubble-text {
  display: block;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-bubble-text a {
  color: var(--tigi-azzurro);
  font-weight: 700;
  text-decoration: underline;
}

.chat-bubble.user .chat-bubble-text a {
  color: var(--tigi-bianco);
}

/* ---------- PULSANTI RAPIDI DENTRO UNA BOLLA (mostrati alla prima apertura) ---------- */
.chat-quickreply-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.chat-quickreply-btn {
  display: inline-block;
  flex: 0 0 auto;
  background-color: var(--tigi-sfondo-chiaro);
  color: var(--tigi-azzurro);
  border: 1px solid var(--tigi-bordo-chiaro);
  padding: 8px 14px;
  border-radius: 100px;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chat-quickreply-btn:hover,
.chat-quickreply-btn:focus-visible {
  background-color: var(--tigi-azzurro);
  color: var(--tigi-bianco);
  border-color: var(--tigi-azzurro);
}

/* Dentro la bolla di scelta login lo sfondo è già azzurro: l'hover generico
   ci sparirebbe dentro. Qui serve un colore che si stacchi sempre. */
.login-choice-bubble .chat-quickreply-btn:hover,
.login-choice-bubble .chat-quickreply-btn:focus-visible {
  background-color: var(--tigi-blu-notte);
  color: var(--tigi-bianco);
  border-color: var(--tigi-blu-notte);
}

/* "Emergenza" risalta rispetto agli altri pulsanti rapidi: sfondo arancione pieno. */
.chat-quickreply-btn[data-key="emergenza"] {
  background-color: var(--tigi-arancione);
  color: var(--tigi-bianco);
  border-color: var(--tigi-arancione);
}

.chat-quickreply-btn[data-key="emergenza"]:hover,
.chat-quickreply-btn[data-key="emergenza"]:focus-visible {
  background-color: #E85A2A;
  border-color: #E85A2A;
}

.chat-quickreply-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ---------- MODULO LOGIN SMS DENTRO UNA BOLLA (numero -> codice) ---------- */
.otp-step {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.otp-input {
  /* flex-basis "auto" (mai un numero fisso): un flex-basis numerico cambia
     asse di riferimento in base a flex-direction (larghezza in riga, altezza
     in colonna) — qui l'input vive sia in righe (bolle di chat) sia in
     colonne (pannello "area personale"), quindi larghezza/altezza vanno
     dichiarate esplicitamente per restare un rettangolo in entrambi i casi. */
  flex: 0 1 auto;
  width: 100%;
  min-width: 0;
  height: 40px;
  padding: 8px 12px;
  border-radius: 100px;
  border: 1px solid var(--tigi-bordo-chiaro);
  font-family: 'Nunito', sans-serif;
  font-size: 14px;
  background-color: var(--tigi-bianco);
  color: inherit;
}

.otp-input:disabled {
  opacity: 0.6;
}

.chat-bubble-time {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  text-align: right;
  opacity: 0.65;
}

/* Bolla del bot: bianca, allineata a sinistra, "codina" a sinistra */
.chat-bubble.bot {
  align-self: flex-start;
  background-color: var(--tigi-bianco);
  color: var(--tigi-testo-titolo);
  border-bottom-left-radius: 4px;
}

.chat-bubble.bot::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: -7px;
  width: 12px;
  height: 13px;
  background-color: var(--tigi-bianco);
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
}

/* Bolla di scelta login: risalta rispetto a un normale messaggio del bot per
   invitare all'accesso (stesso schema colori della bolla utente). */
.chat-bubble.bot.login-choice-bubble {
  background-color: var(--tigi-azzurro);
  color: var(--tigi-bianco);
}

.chat-bubble.bot.login-choice-bubble::after {
  background-color: var(--tigi-azzurro);
}

/* Modulo login SMS: a differenza di un normale messaggio, un campo da compilare
   sta più comodo su tutta la larghezza della chat invece che nell'82% di una bolla. */
.chat-bubble.otp-bubble {
  max-width: 100%;
  align-self: stretch;
}

/* Bolla dell'utente: azzurro Tigi, allineata a destra, "codina" a destra */
.chat-bubble.user {
  align-self: flex-end;
  background-color: var(--tigi-azzurro);
  color: var(--tigi-bianco);
  border-bottom-right-radius: 4px;
}

.chat-bubble.user::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: -7px;
  width: 12px;
  height: 13px;
  background-color: var(--tigi-azzurro);
  clip-path: polygon(0 0, 100% 100%, 0 100%);
}

.chat-bubble.system-warning {
  align-self: center;
  background-color: #FFF3E0;
  color: var(--tigi-arancione);
  font-weight: 700;
  font-size: 13px;
  text-align: center;
  box-shadow: none;
}

/* Bolla divisoria che introduce lo storico ripristinato al login: stesso layout
   dell'avviso ma con colori neutri, per non sembrare un errore. */
.chat-bubble.system-info {
  align-self: center;
  background-color: var(--tigi-sfondo-chiaro);
  color: var(--tigi-testo-paragrafo);
  font-weight: 700;
  font-size: 13px;
  text-align: center;
  box-shadow: none;
}

/* ---------- INDICATORE "sta scrivendo..." ---------- */
.chat-bubble.typing-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 16px;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--tigi-testo-paragrafo);
  opacity: 0.5;
  animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

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

@keyframes bubble-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- INPUT ROW ---------- */
.chat-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px calc(env(safe-area-inset-bottom, 0px) + 12px);
  border-top: 1px solid var(--tigi-bordo-chiaro);
  background-color: var(--tigi-bianco);
}

.app-footer {
  padding: 6px 16px calc(env(safe-area-inset-bottom, 0px) + 6px);
  text-align: center;
  font-style: italic;
  font-size: 11px;
  color: var(--tigi-testo-paragrafo);
  background-color: var(--tigi-bianco);
  border-top: 1px solid var(--tigi-bordo-chiaro);
}

.app-footer a {
  color: var(--tigi-azzurro);
  font-weight: 700;
  text-decoration: none;
}

.app-footer a:hover {
  text-decoration: underline;
}

.chat-input {
  flex: 1;
  padding: 14px 20px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--tigi-bordo-chiaro);
  font-family: 'Nunito', sans-serif;
  font-size: 15px;
  color: var(--tigi-testo-titolo);
  outline: none;
  transition: border-color 0.2s ease;
}

.chat-input:focus {
  border-color: var(--tigi-azzurro);
}

.chat-input:disabled {
  background-color: var(--tigi-sfondo-chiaro);
  color: var(--tigi-testo-paragrafo);
  cursor: not-allowed;
}

.btn-send {
  flex: 0 0 auto;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  background-color: var(--tigi-azzurro);
  color: var(--tigi-bianco);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-soft);
}

.btn-send:hover {
  background-color: var(--tigi-blu-notte);
  transform: translateY(-2px);
}

.btn-send:disabled {
  background-color: var(--tigi-bordo-chiaro);
  color: var(--tigi-testo-paragrafo);
  cursor: not-allowed;
  transform: none;
}

/* Dettatura vocale (Web Speech API): pulsante secondario, non compete con l'invio. */
.btn-mic {
  flex: 0 0 auto;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 1px solid var(--tigi-bordo-chiaro);
  background-color: var(--tigi-bianco);
  color: var(--tigi-azzurro);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-mic:hover {
  background-color: var(--tigi-sfondo-chiaro);
}

.btn-mic:disabled {
  background-color: var(--tigi-bordo-chiaro);
  color: var(--tigi-testo-paragrafo);
  cursor: not-allowed;
}

/* In registrazione: stesso arancione usato per "attenzione/azione in corso" (Emergenza). */
.btn-mic.is-recording {
  background-color: var(--tigi-arancione);
  border-color: var(--tigi-arancione);
  color: var(--tigi-bianco);
  animation: mic-pulse 1.2s infinite ease-in-out;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 112, 67, 0.45); }
  50% { box-shadow: 0 0 0 8px rgba(255, 112, 67, 0); }
}

/* ---------- WIDGET FLUTTUANTE (tablet/PC) ---------- */
/* Sotto i 768px (smartphone): l'app-shell resta a piena pagina, come sopra.
   Il pulsante "launcher" e quello di chiusura del widget restano nascosti:
   su smartphone la chat È la pagina, non c'è nulla da apri/chiudere. */
.chat-launcher {
  display: none;
}

.widget-close-btn {
  display: none;
}

@media (min-width: 768px) {
  .app-shell {
    position: fixed;
    right: 24px;
    bottom: 24px;
    left: auto;
    margin: 0;
    width: 400px;
    max-width: calc(100vw - 48px);
    height: 640px;
    max-height: calc(100vh - 120px);
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 60px rgba(26, 43, 51, 0.28);
    border: 1px solid var(--tigi-bordo-chiaro);
    z-index: 200;
    opacity: 0;
    transform: translateY(16px) scale(0.97);
    pointer-events: none;
    visibility: hidden;
    transition: opacity 0.18s ease, transform 0.18s ease;
  }

  /* JS aggiunge/rimuove "widget-open" sul body per apri/chiudi. */
  body.widget-open .app-shell {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    visibility: visible;
  }

  .chat-launcher {
    display: block;
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    border: 2px solid var(--tigi-azzurro);
    background-color: var(--tigi-bianco);
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(0, 188, 212, 0.4);
    z-index: 199;
    transition: transform 0.2s ease, opacity 0.2s ease;
  }

  /* Riempie il cerchio (vedi DATI/esempioChat.png): l'immagine è più larga del
     bottone quadrato, "cover" la scala e ne ritaglia i lati — è proprio lì,
     sul bordo, che deve "rompersi" la punta del megafono (vedi sotto). */
  .chat-launcher-face {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
  }

  /* Stessa immagine, stessa scala (height:100% + width:auto usa il rapporto
     naturale del file, identico a quello di "cover" sopra: le due copie
     restano sovrapposte pixel per pixel, senza calcoli di posizione a mano).
     Il contenitore non ritaglia più (niente overflow:hidden su .chat-launcher),
     quindi la finestra di clip-path può davvero sporgere fuori dal cerchio. */
  .chat-launcher-overflow {
    position: absolute;
    top: 50%;
    left: 50%;
    height: 100%;
    width: auto;
    transform: translate(-50%, -50%);
    clip-path: inset(18px 43px 18px 0 round 10px);
    filter: drop-shadow(-3px 3px 4px rgba(0, 0, 0, 0.35));
    pointer-events: none;
  }

  .chat-launcher:hover {
    transform: translateY(-3px);
  }

  body.widget-open .chat-launcher {
    opacity: 0;
    transform: scale(0.85);
    pointer-events: none;
  }

  .widget-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: none;
    color: var(--tigi-bianco);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    transition: background-color 0.2s ease;
  }

  .widget-close-btn:hover {
    background-color: rgba(255, 255, 255, 0.15);
  }
}

/* ---------- SCHERMATA RISOLUZIONE EVENTO (prima della chat) ---------- */
.event-gate {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding: 32px 20px;
  font-family: 'Nunito', sans-serif;
  overflow-y: auto;
}

.event-screen h2 {
  font-family: 'Poppins', sans-serif;
  color: var(--tigi-testo-titolo);
  font-size: 20px;
  margin: 0 0 16px;
}

.event-screen p {
  color: var(--tigi-testo-paragrafo);
  font-size: 15px;
  line-height: 1.5;
}

.event-select-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.event-select-item {
  width: 100%;
  text-align: left;
  background-color: var(--tigi-sfondo-chiaro);
  border: 1px solid var(--tigi-bordo-chiaro);
  border-radius: 16px;
  padding: 14px 16px;
  font-family: 'Nunito', sans-serif;
  cursor: pointer;
  transition: all 0.2s ease;
}

.event-select-item:hover,
.event-select-item:focus-visible {
  background-color: var(--tigi-azzurro);
  border-color: var(--tigi-azzurro);
  color: var(--tigi-bianco);
}

.event-select-item-name {
  display: block;
  font-weight: 700;
  color: var(--tigi-testo-titolo);
  font-size: 15px;
}

.event-select-item:hover .event-select-item-name,
.event-select-item:focus-visible .event-select-item-name {
  color: var(--tigi-bianco);
}

.event-select-item-meta {
  display: block;
  font-size: 13px;
  margin-top: 2px;
  opacity: 0.8;
}
