/* ============================================================
   NomotecnIA · Assistente IA v2 — Widget (first-party)
   Un solo motore di conversazione · 3 contenitori (bolla · pannello · moduli inline).
   Estetica "strumento" (non messenger). Solo transform/opacity in animazione.
   Tutti i colori/raggi/ombre derivano da tokens.css (nessun valore inventato).
   Prefisso .nmt- per non collidere con lo stile legacy .chat.
   ============================================================ */

/* ---- Superficie condivisa (console bosco) --------------------------------- */
.nmt-surface {
  background: var(--surface-authority);
  color: var(--ink-on-authority);
  border: 1px solid var(--linea-scura);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}
/* Filetto d'oro: la firma cerimoniale (1px, decorativo) */
.nmt-surface::before {
  content: "";
  position: absolute; inset: 0;
  border-top: var(--filo-w) solid var(--filo-oro-soft);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  pointer-events: none;
}

/* ---- Testata pannello ----------------------------------------------------- */
.nmt-head {
  display: flex; align-items: center; gap: var(--space-2);
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--linea-scura);
}
.nmt-head__logo { flex: 0 0 auto; display: grid; place-items: center; width: 22px; height: 22px; }
.nmt-head__logo .nmt-mark { display: block; width: 22px; height: 22px; }
.nmt-head__id { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.nmt-head__brand {
  font-family: var(--font-sans); font-weight: 700;
  font-size: var(--fs-body); color: var(--ink-on-authority);
  letter-spacing: -0.01em; line-height: 1.1;
}
.nmt-head__role {
  font-family: var(--font-mono); font-size: var(--fs-mono);
  text-transform: uppercase; letter-spacing: var(--tracking-mono);
  color: var(--ink-on-authority-dim);
}
.nmt-badge {
  font-family: var(--font-mono); font-size: var(--fs-mono);
  letter-spacing: var(--tracking-mono); text-transform: uppercase;
  color: var(--accent-ceremonial);                 /* oro su scuro · 9.37:1 */
  border: 1px solid var(--filo-oro-soft);
  border-radius: var(--r-pill);
  padding: 3px 9px; line-height: 1; white-space: nowrap;
  margin-left: auto;
}
.nmt-close {
  flex: 0 0 auto;
  width: 44px; height: 44px; margin: -8px -6px -8px 4px;
  display: grid; place-items: center;
  background: transparent; border: 0; border-radius: var(--r-sm);
  color: var(--ink-on-authority-dim); cursor: pointer;
  transition: color var(--dur-fast) var(--ease-ui),
              background-color var(--dur-fast) var(--ease-ui);
}
.nmt-close:hover { color: var(--ink-on-authority); background: var(--superficie-scura); }
.nmt-close:focus-visible { outline: 2px solid var(--smeraldo-bright); outline-offset: 2px; }
.nmt-close svg { width: 20px; height: 20px; }

/* ---- Banner Art. 50 (persistente · una sola volta) ------------------------ */
.nmt-art50 {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 10px 20px;
  background: var(--superficie-scura);
  border-bottom: 1px solid var(--linea-scura);
  font-family: var(--font-mono); font-size: var(--fs-mono);
  letter-spacing: 0.04em; line-height: 1.45;
  color: var(--ink-on-authority-dim);
}
.nmt-art50 svg { flex: 0 0 auto; width: 14px; height: 14px; margin-top: 1px; color: var(--accent-ceremonial); }

/* ---- Filo conversazione (role=log) ---------------------------------------- */
.nmt-log {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; overflow-x: hidden;
  padding: var(--space-3) 20px var(--space-2);
  display: flex; flex-direction: column; gap: var(--space-3);
  scroll-behavior: smooth;
}
.nmt-msg { max-width: 720px; }
/* IA = blocco crema SENZA bolla (testo su bosco) */
.nmt-msg--ai {
  align-self: stretch;
  color: var(--ink-on-authority);
  font-size: var(--fs-body); line-height: var(--lh-body);
}
.nmt-msg--ai.nmt-msg--opening { color: var(--ink-on-authority-dim); font-size: var(--fs-small); }
/* Utente = pastiglia smeraldo tenue a destra */
.nmt-msg--user {
  align-self: flex-end; max-width: 82%;
  background: color-mix(in srgb, var(--smeraldo) 22%, var(--nero-giuridico));
  color: var(--ink-on-authority);
  border: 1px solid color-mix(in srgb, var(--smeraldo) 34%, transparent);
  border-radius: var(--r-md) var(--r-md) var(--r-sm) var(--r-md);
  padding: 10px 14px;
  font-size: var(--fs-body); line-height: 1.5;
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere;
}
.nmt-msg--ai { white-space: normal; word-wrap: break-word; overflow-wrap: anywhere; }
/* Link interni nel filo (es. informativa privacy nel messaggio di apertura) */
.nmt-msg--ai a {
  color: var(--accent-ceremonial);            /* oro su scuro · alto contrasto */
  text-decoration: underline; text-underline-offset: 2px;
  overflow-wrap: anywhere;
  transition: color var(--dur-fast) var(--ease-ui);
}
.nmt-msg--ai a:hover { color: var(--su-scuro-testo); }
.nmt-msg--ai a:focus-visible { outline: 2px solid var(--smeraldo-bright); outline-offset: 2px; }

/* Fonti (citazioni con deep-link interno) */
.nmt-sources {
  margin-top: 10px; padding-top: 8px;
  border-top: 1px dashed var(--linea-scura);
  display: flex; flex-direction: column; gap: 4px;
}
.nmt-sources__lbl {
  font-family: var(--font-mono); font-size: var(--fs-mono);
  text-transform: uppercase; letter-spacing: var(--tracking-mono);
  color: var(--ink-on-authority-dim);
}
.nmt-source {
  color: var(--accent-ceremonial);
  text-decoration: underline; text-underline-offset: 2px;
  font-size: var(--fs-small); width: fit-content;
  transition: color var(--dur-fast) var(--ease-ui);
}
.nmt-source:hover { color: var(--su-scuro-testo); }
.nmt-source:focus-visible { outline: 2px solid var(--smeraldo-bright); outline-offset: 2px; }
.nmt-source--plain { color: var(--ink-on-authority-dim); text-decoration: none; } /* href non valido → testo */

/* Indicatore "sta scrivendo" */
.nmt-typing { display: inline-flex; gap: 5px; align-items: center; padding: 4px 0; }
.nmt-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ink-on-authority-dim); opacity: .5;
  animation: nmt-blink 1.1s var(--ease-ui) infinite;
}
.nmt-typing span:nth-child(2){ animation-delay: .18s; }
.nmt-typing span:nth-child(3){ animation-delay: .36s; }
@keyframes nmt-blink { 0%,80%,100%{ opacity:.3 } 40%{ opacity:1 } }

/* Riga di errore (causa + azione, mai muto) */
.nmt-error {
  align-self: stretch;
  display: flex; align-items: flex-start; gap: 8px;
  padding: 10px 12px; border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--stato-rischio) 14%, var(--nero-giuridico));
  border: 1px solid color-mix(in srgb, var(--stato-rischio) 34%, transparent);
  color: var(--ink-on-authority); font-size: var(--fs-small); line-height: 1.5;
}
.nmt-error svg { flex:0 0 auto; width:16px; height:16px; margin-top:2px; color: var(--stato-rischio); }
.nmt-error button {
  background: none; border: 0; padding: 0; margin-top: 4px;
  color: var(--smeraldo-bright); font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
}
.nmt-error button:focus-visible { outline: 2px solid var(--smeraldo-bright); outline-offset: 2px; }

/* ---- Chips (empty-state) -------------------------------------------------- */
.nmt-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 20px var(--space-2); }
.nmt-chip {
  font: inherit; font-size: var(--fs-small); line-height: 1;
  background: var(--superficie-scura);
  color: var(--ink-on-authority);
  border: 1px solid var(--linea-scura);
  border-radius: var(--r-pill); padding: 9px 14px; cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-ui),
              color var(--dur-fast) var(--ease-ui);
}
.nmt-chip:hover { border-color: var(--filo-oro-soft); color: var(--su-scuro-testo); }
.nmt-chip:focus-visible { outline: 2px solid var(--smeraldo-bright); outline-offset: 2px; }

/* ---- Composer ------------------------------------------------------------- */
.nmt-composer {
  display: flex; align-items: flex-end; gap: 10px;
  padding: 14px 20px calc(16px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--linea-scura);
}
.nmt-composer__field {
  flex: 1 1 auto;
  background: var(--superficie-scura);
  border: 1px solid var(--linea-scura);
  border-radius: var(--r-md);
  transition: border-color var(--dur-fast) var(--ease-ui);
}
.nmt-composer__field:focus-within { border-color: var(--smeraldo-bright); }
.nmt-composer textarea {
  display: block; width: 100%; resize: none;
  max-height: 132px; min-height: 24px;
  background: transparent; border: 0; outline: none;
  color: var(--ink-on-authority);
  font-family: var(--font-sans); font-size: var(--fs-body); line-height: 1.5;
  padding: 11px 14px;
}
.nmt-composer textarea::placeholder { color: var(--ink-on-authority-dim); opacity: .8; }
.nmt-send {
  flex: 0 0 auto;
  width: 44px; height: 44px; display: grid; place-items: center;
  background: var(--smeraldo); color: #05130D;
  border: 0; border-radius: var(--r-md); cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-ui), opacity var(--dur-fast) var(--ease-ui);
}
.nmt-send:hover { background: var(--smeraldo-bright); }
.nmt-send:disabled { opacity: .45; cursor: not-allowed; }
.nmt-send:focus-visible { outline: 2px solid var(--smeraldo-bright); outline-offset: 2px; }
.nmt-send svg { width: 20px; height: 20px; }

/* ---- Form-lead (consenso just-in-time) ------------------------------------ */
.nmt-lead {
  align-self: stretch; margin-top: 4px;
  background: var(--superficie-scura);
  border: 1px solid var(--linea-scura);
  border-radius: var(--r-md);
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.nmt-lead__title {
  font-weight: 700; font-size: var(--fs-body); color: var(--ink-on-authority);
}
.nmt-lead__row { display: flex; flex-direction: column; gap: 5px; }
.nmt-lead__row label {
  font-family: var(--font-mono); font-size: var(--fs-mono);
  text-transform: uppercase; letter-spacing: var(--tracking-mono);
  color: var(--ink-on-authority-dim);
}
.nmt-lead input[type=text], .nmt-lead input[type=email] {
  background: var(--nero-giuridico); color: var(--ink-on-authority);
  border: 1px solid var(--linea-scura); border-radius: var(--r-sm);
  padding: 10px 12px; font: inherit; font-size: var(--fs-body);
}
.nmt-lead input:focus-visible { outline: none; border-color: var(--smeraldo-bright); }
/* Casella consenso: SEPARATA dal pulsante, NON pre-marcata */
.nmt-consent { display: flex; gap: 10px; align-items: flex-start; }
.nmt-consent input[type=checkbox] {
  flex: 0 0 auto; width: 20px; height: 20px; margin: 1px 0 0;
  accent-color: var(--smeraldo); cursor: pointer;
}
.nmt-consent label { font-size: var(--fs-small); line-height: 1.5; color: var(--ink-on-authority); }
.nmt-consent a { color: var(--accent-ceremonial); text-decoration: underline; text-underline-offset: 2px; }
.nmt-revoca { font-size: var(--fs-mono); line-height: 1.5; color: var(--ink-on-authority-dim); }
.nmt-lead__submit {
  align-self: flex-start;
  background: var(--smeraldo); color: #05130D;
  border: 0; border-radius: var(--r-md); padding: 11px 20px;
  font: inherit; font-weight: 600; cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-ui), opacity var(--dur-fast) var(--ease-ui);
}
.nmt-lead__submit:hover:not(:disabled) { background: var(--smeraldo-bright); }
.nmt-lead__submit:disabled { opacity: .45; cursor: not-allowed; }
.nmt-lead__submit:focus-visible { outline: 2px solid var(--smeraldo-bright); outline-offset: 2px; }
.nmt-lead__ok {
  align-self: stretch; display: flex; gap: 8px; align-items: center;
  color: var(--smeraldo-bright); font-weight: 600; font-size: var(--fs-body);
}
.nmt-lead__ok svg { width: 18px; height: 18px; }

/* ============================================================
   CONTENITORE 1 · Bolla flottante
   ============================================================ */
.nmt-launcher {
  position: fixed;
  right: max(20px, env(safe-area-inset-right, 0px));
  bottom: max(20px, env(safe-area-inset-bottom, 0px));
  z-index: var(--z-modal);
  display: inline-flex; align-items: center; gap: 10px;
  height: 58px; padding: 0 20px 0 18px;
  background: var(--nero-giuridico); color: var(--su-scuro-testo);
  border: 1px solid var(--filo-oro-soft); border-radius: var(--r-pill);
  box-shadow: var(--shadow-lg);
  font-family: var(--font-sans); font-weight: 600; font-size: var(--fs-body);
  cursor: pointer;
  transition: background-color var(--dur) var(--ease-ui),
              box-shadow var(--dur) var(--ease-ui),
              opacity var(--dur) var(--ease-ui);
}
.nmt-launcher:hover { background: #12241C; box-shadow: var(--shadow-lg), var(--glow-ok-scuro); } /* nessun resize */
.nmt-launcher:focus-visible { outline: 2px solid var(--smeraldo-bright); outline-offset: 3px; }
/* Logo composito: N monogramma (verde) centrata + "La Squadra" (2 squadre oro) che la inquadra */
.nmt-launcher__ic {
  position: relative; flex: 0 0 auto; width: 24px; height: 24px;
}
.nmt-launcher__ic .nmt-logo__n {
  position: absolute; top: 50%; left: 50%;
  width: 16px; height: 16px;                 /* N alla dimensione minima di marca (16px) */
  transform: translate(-50%, -50%);          /* solo centratura, mai animata */
}
.nmt-launcher__ic .nmt-sq {
  position: absolute; width: 9px; height: 9px;
  will-change: transform;
}
/* "La Squadra che respira": inquadratura che misura, lenta e discreta (solo transform) */
@keyframes nmt-sq-tl { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(1.5px, 1.5px); } }
@keyframes nmt-sq-br { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(-1.5px, -1.5px); } }
.nmt-launcher__ic .nmt-sq--tl { top: 1px; left: 1px; animation: nmt-sq-tl 3.5s ease-in-out infinite; }
.nmt-launcher__ic .nmt-sq--br { bottom: 1px; right: 1px; animation: nmt-sq-br 3.5s ease-in-out infinite; }
/* Stato "sta pensando": la squadra pulsa (più marcata: transform + opacity) */
@keyframes nmt-sq-think-tl { 0%, 100% { transform: translate(0, 0); opacity: .55; } 50% { transform: translate(2.4px, 2.4px); opacity: 1; } }
@keyframes nmt-sq-think-br { 0%, 100% { transform: translate(0, 0); opacity: .55; } 50% { transform: translate(-2.4px, -2.4px); opacity: 1; } }
.nmt-launcher.is-thinking .nmt-sq--tl { animation: nmt-sq-think-tl 1s ease-in-out infinite; }
.nmt-launcher.is-thinking .nmt-sq--br { animation: nmt-sq-think-br 1s ease-in-out infinite; }
.nmt-launcher[hidden] { display: none; }

/* Teaser descartable */
.nmt-teaser {
  position: fixed; z-index: var(--z-modal);
  right: max(20px, env(safe-area-inset-right, 0px));
  bottom: calc(58px + max(20px, env(safe-area-inset-bottom, 0px)) + 12px);
  max-width: 248px;
  background: var(--carta); color: var(--inchiostro);
  border-radius: var(--r-md); box-shadow: var(--shadow-lg);
  padding: 12px 34px 12px 14px;
  font-size: var(--fs-small); line-height: 1.45;
  opacity: 0; transform: translateY(6px);
  transition: opacity var(--dur) var(--ease-entrance), transform var(--dur) var(--ease-entrance);
}
.nmt-teaser.is-in { opacity: 1; transform: translateY(0); }
.nmt-teaser__x {
  position: absolute; top: 4px; right: 4px;
  width: 26px; height: 26px; display: grid; place-items: center;
  background: none; border: 0; border-radius: var(--r-sm);
  color: var(--grigio-testo); cursor: pointer; font-size: 16px; line-height: 1;
}
.nmt-teaser__x:focus-visible { outline: 2px solid var(--smeraldo); outline-offset: 1px; }

/* ============================================================
   CONTENITORE 2 · Pannello overlay (dialog)
   ============================================================ */
.nmt-scrim {
  position: fixed; inset: 0; z-index: var(--z-overlay);
  background: color-mix(in srgb, var(--nero-giuridico) 55%, transparent);
  opacity: 0; visibility: hidden; pointer-events: none;   /* chiuso: NON cattura click */
  /* visibility resta "visible" durante il fade-out (ritardata di --dur), poi si nasconde */
  transition: opacity var(--dur) var(--ease-ui), visibility 0s linear var(--dur);
}
.nmt-scrim.is-open {
  opacity: 1; visibility: visible; pointer-events: auto;
  transition: opacity var(--dur) var(--ease-ui), visibility 0s;  /* visibile subito all'apertura */
}
.nmt-panel {
  position: fixed; z-index: var(--z-modal);
  right: 20px; bottom: 20px; top: auto;
  width: 410px; max-width: calc(100vw - 40px);
  height: 70vh; max-height: 680px; min-height: 420px;
  display: flex; flex-direction: column;
  opacity: 0; transform: translateY(14px);
  visibility: hidden; pointer-events: none;   /* chiuso: NON cattura click */
  transition: opacity var(--dur) var(--ease-entrance), transform var(--dur) var(--ease-entrance), visibility 0s linear var(--dur);
}
.nmt-panel.is-open {
  opacity: 1; transform: translateY(0);
  visibility: visible; pointer-events: auto;
  transition: opacity var(--dur) var(--ease-entrance), transform var(--dur) var(--ease-entrance), visibility 0s;
}
.nmt-panel .nmt-log { flex: 1 1 auto; }

/* ============================================================
   CONTENITORE 3 · Moduli inline (home · contatti)
   ============================================================ */
.nmt-inline { display: block; }
.nmt-inline .nmt-surface { display: flex; flex-direction: column; }
/* Composer editoriale (home, stato iniziale) */
.nmt-editorial { padding: clamp(24px, 3vw, 40px); }
.nmt-editorial__kick {
  font-family: var(--font-mono); font-size: var(--fs-mono);
  text-transform: uppercase; letter-spacing: var(--tracking-mono);
  color: var(--accent-ceremonial); margin: 0 0 12px;
}
.nmt-editorial__title {
  font-family: var(--font-display); font-weight: var(--display-w-medium);
  font-size: var(--fs-h2); line-height: var(--lh-heading);
  letter-spacing: var(--tracking-tight);
  color: var(--ink-on-authority); margin: 0 0 10px;
}
.nmt-editorial__sub {
  font-size: var(--fs-body); line-height: var(--lh-body);
  color: var(--ink-on-authority-dim); max-width: 52ch; margin: 0 0 22px;
}
.nmt-editorial .nmt-composer { padding: 0; border-top: 0; margin-bottom: 16px; }
.nmt-editorial .nmt-composer__field { background: var(--nero-giuridico); }
.nmt-editorial .nmt-chips { padding: 0; }
/* Vista conversazione inline (dopo il primo invio) */
.nmt-inline .nmt-log { max-height: 60vh; }
.nmt-inline[data-view="chat"] .nmt-editorial { display: none; }
.nmt-inline[data-view="editorial"] .nmt-head,
.nmt-inline[data-view="editorial"] .nmt-log,
.nmt-inline[data-view="editorial"] > .nmt-surface > .nmt-composer,
.nmt-inline[data-view="editorial"] > .nmt-surface > .nmt-art50 { display: none; }

/* ---- Mobile: pannello full-screen / bottom-sheet -------------------------- */
@media (max-width: 560px) {
  .nmt-panel {
    right: 0; left: 0; bottom: 0; top: 0;
    width: 100%; max-width: 100%;
    height: 100dvh; max-height: none; min-height: 0;
    border-radius: 0;
  }
  .nmt-panel .nmt-surface { border-radius: 0; border: 0; box-shadow: none; height: 100%; }
  .nmt-head { padding-top: calc(18px + env(safe-area-inset-top, 0px)); }
  .nmt-launcher { height: 54px; padding: 0 18px; }
}

/* ---- Header opener: affordance desktop; su mobile subentra la bolla -------- */
/* Il menu del sito collassa a ≤860px (nav-toggle): lì il pulsante header
   spingerebbe le azioni fuori schermo. La bolla flottante copre il mobile. */
@media (max-width: 860px) {
  .site-header__actions [data-nmt-open] { display: none; }
}

/* ---- Reduced motion ------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .nmt-scrim, .nmt-panel, .nmt-teaser, .nmt-launcher,
  .nmt-close, .nmt-send, .nmt-chip, .nmt-source, .nmt-lead__submit { transition: none !important; }
  .nmt-typing span { animation: none !important; opacity: .6; }
  /* "La Squadra" resta ferma (inquadratura statica), N sempre centrata */
  .nmt-launcher__ic .nmt-sq,
  .nmt-launcher.is-thinking .nmt-sq { animation: none !important; transform: none !important; opacity: 1; }
  .nmt-log { scroll-behavior: auto; }
}
