/* ==========================================================================
   TecnoWeb AI — accesso all'assistente esterno da segretariatecnowebsalerno
   Prefisso unico: tw-ai-  ·  Nessuna dipendenza  ·  Nessun conflitto
   z-index: FAB 99998 · modale 99999
   ========================================================================== */

#tw-ai-root,
#tw-ai-root * {
  box-sizing: border-box;
}

#tw-ai-root {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Pulsante flottante (FAB) ---------- */
.tw-ai-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 99998;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  height: 40px;
  margin: 0;
  padding: 0 16px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background: linear-gradient(135deg, #9d151b 0%, #e8262f 52%, #ff525a 100%);
  color: #ffffff;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.01em;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  box-shadow:
    0 10px 22px -8px rgba(232, 38, 47, 0.55),
    0 3px 10px rgba(3, 8, 24, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transition:
    transform 0.22s cubic-bezier(0.16, 1, 0.3, 1),
    box-shadow 0.22s ease,
    opacity 0.2s ease;
}

.tw-ai-fab:hover {
  transform: translateY(-2px) scale(1.01);
  background: linear-gradient(135deg, #c51a22 0%, #ff525a 52%, #ff9297 100%);
  box-shadow:
    0 14px 28px -10px rgba(232, 38, 47, 0.6),
    0 6px 14px rgba(3, 8, 24, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.tw-ai-fab:active {
  transform: translateY(-1px) scale(0.99);
  box-shadow:
    0 8px 18px -8px rgba(232, 38, 47, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.tw-ai-fab:focus-visible {
  outline: 3px solid #ff9297;
  outline-offset: 3px;
}

.tw-ai-fab__label {
  display: block;
  white-space: nowrap;
}

/* Il FAB non deve galleggiare sopra le finestre già aperte dal sito */
body:has([role="dialog"][aria-modal="true"]:not(#tw-ai-panel)):not(.tw-ai-open) .tw-ai-fab {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

body.tw-ai-open .tw-ai-fab {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(10px) scale(0.96);
}

/* ---------- Sfondo con vetro ---------- */
.tw-ai-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(3, 7, 18, 0.62);
  -webkit-backdrop-filter: blur(14px) saturate(125%);
  backdrop-filter: blur(14px) saturate(125%);
  overscroll-behavior: contain;
  animation: tw-ai-fade 0.2s ease-out both;
}

.tw-ai-overlay[hidden] {
  display: none !important;
}

/* ---------- Finestra ---------- */
.tw-ai-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 480px;
  height: 85vh;
  height: 85dvh;
  overflow: hidden;
  border: 1px solid rgba(96, 165, 250, 0.28);
  border-radius: 16px;
  background: #070b16;
  color: #e2e8f0;
  font-family: inherit;
  box-shadow:
    0 40px 90px -20px rgba(0, 0, 0, 0.8),
    0 0 0 1px rgba(0, 0, 0, 0.45),
    0 0 80px -30px rgba(37, 99, 235, 0.55);
  transform-origin: 50% 60%;
  animation: tw-ai-pop 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* ---------- Intestazione blu ---------- */
.tw-ai-head {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
  padding: 13px 14px 13px 16px;
  background: linear-gradient(120deg, #0b1b4d 0%, #1d4ed8 58%, #0369a1 100%);
  color: #ffffff;
}

.tw-ai-head::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(130% 160% at 0% 0%, rgba(255, 255, 255, 0.2), transparent 58%);
  pointer-events: none;
}

.tw-ai-badge {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.14);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.24);
}

.tw-ai-badge svg {
  display: block;
  width: 22px;
  height: 22px;
}

.tw-ai-headtext {
  position: relative;
  z-index: 1;
  min-width: 0;
}

.tw-ai-title {
  margin: 0;
  padding: 0;
  font-family: inherit;
  font-size: 15px;
  font-weight: 650;
  line-height: 1.2;
  letter-spacing: 0.01em;
  color: #ffffff;
}

.tw-ai-sub {
  margin: 3px 0 0;
  padding: 0;
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(219, 234, 254, 0.82);
}

.tw-ai-actions {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex: none;
}

.tw-ai-iconbtn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  margin: 0;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  font: inherit;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    background-color 0.18s ease,
    transform 0.18s ease,
    border-color 0.18s ease;
}

.tw-ai-iconbtn:hover {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.32);
  transform: translateY(-1px);
}

.tw-ai-iconbtn:active {
  transform: translateY(0) scale(0.97);
}

.tw-ai-iconbtn:focus-visible {
  outline: 3px solid #bfdbfe;
  outline-offset: 2px;
}

.tw-ai-iconbtn svg {
  display: block;
  width: 17px;
  height: 17px;
  pointer-events: none;
}

/* ---------- Corpo / iframe ---------- */
.tw-ai-body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #05070f;
}

.tw-ai-frame {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #05070f;
  color-scheme: dark;
}

.tw-ai-frame[hidden] {
  display: none;
}

/* ---------- Caricamento ---------- */
.tw-ai-loader {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  background: #05070f;
  text-align: center;
  transition:
    opacity 0.35s ease,
    visibility 0.35s ease;
}

.tw-ai-loader.is-done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.tw-ai-spinner {
  display: block;
  width: 34px;
  height: 34px;
  border: 3px solid rgba(59, 130, 246, 0.22);
  border-top-color: #38bdf8;
  border-radius: 50%;
  animation: tw-ai-spin 0.9s linear infinite;
}

.tw-ai-loader-text {
  margin: 0;
  padding: 0;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: #94a3b8;
}

.tw-ai-loader-link {
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 500;
  color: #7dd3fc;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: rgba(125, 211, 252, 0.4);
  transition: color 0.18s ease;
}

.tw-ai-loader-link:hover {
  color: #bae6fd;
}

/* ---------- Blocco dello scorrimento del sito ---------- */
html.tw-ai-lock,
body.tw-ai-lock {
  overflow: hidden !important;
  overscroll-behavior: none;
}

/* ---------- Mobile: schermo intero ---------- */
@media (max-width: 768px) {
  .tw-ai-overlay {
    padding: 0;
    align-items: stretch;
  }

  .tw-ai-panel {
    max-width: none;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .tw-ai-head {
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
    padding-right: 12px;
    padding-left: 14px;
  }

  .tw-ai-fab {
    right: 14px;
    /* In basso, ma la chat di Lilia lascia libera questa fascia */
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    height: 38px;
    padding: 0 14px;
    font-size: 12px;
  }
}

@media (max-width: 370px) {
  .tw-ai-fab {
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    height: 34px;
    padding: 0 12px;
    font-size: 11px;
  }

  .tw-ai-head {
    gap: 10px;
    padding-left: 12px;
  }

  .tw-ai-badge {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }

  .tw-ai-title {
    font-size: 14px;
  }

  .tw-ai-sub {
    display: none;
  }

  .tw-ai-actions {
    gap: 5px;
  }

  .tw-ai-iconbtn {
    width: 32px;
    height: 32px;
  }
}

/* ---------- Animazioni (solo transform/opacity) ---------- */
@keyframes tw-ai-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes tw-ai-pop {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes tw-ai-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Utility ---------- */
.tw-ai-sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
