/* Chat AI OsintInfo — stessa palette del sito (#1991eb, sezioni scure, Michroma per i titoli) */
.chat-section {
  --chat-accent: #1991eb;
  --chat-line: rgba(255, 255, 255, 0.08);
  --chat-text: #d1d5db;
  --chat-muted: #8b95a5;
  --chat-read: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.chat-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.chat-collection-label { color: var(--chat-muted); font-size: 0.85rem; }
.chat-toolbar .chat-collection {
  flex: 1 1 220px;
  width: auto;
  padding: 0.6rem 2.2rem 0.6rem 0.9rem;
  font-size: 0.85rem;
  border-radius: 0.8rem;
}
.chat-collection:disabled { opacity: 0.6; }
.chat-reset {
  background: transparent;
  border: 1px solid var(--chat-line);
  color: var(--chat-muted);
  border-radius: 0.8rem;
  padding: 0.6rem 0.9rem;
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
}
.chat-reset:hover { color: #fff; border-color: var(--chat-accent); }

/* ---- conversazione ---- */
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 260px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 1rem 0.25rem 1rem 0;
  border-top: 1px solid var(--chat-line);
  border-bottom: 1px solid var(--chat-line);
  scroll-behavior: smooth;
}
.chat-msg {
  max-width: 88%;
  padding: 0.85rem 1rem;
  border-radius: 1rem;
  border: 1px solid var(--chat-line);
  background: rgba(255, 255, 255, 0.03);
}
.chat-user {
  align-self: flex-end;
  background: rgba(25, 145, 235, 0.14);
  border-color: rgba(25, 145, 235, 0.45);
  border-bottom-right-radius: 0.3rem;
}
.chat-bot { align-self: flex-start; border-bottom-left-radius: 0.3rem; }
.chat-error { border-color: rgba(248, 113, 113, 0.5); }
.chat-error .chat-body { color: #fca5a5; }

.chat-who {
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--chat-accent);
  margin-bottom: 0.4rem;
}
.chat-body {
  font-family: var(--chat-read);
  font-size: 0.98rem;
  line-height: 1.6;
  color: var(--chat-text);
  overflow-wrap: anywhere;
}
.chat-body p { margin: 0 0 0.7em; color: var(--chat-text); }
.chat-body p:last-child { margin-bottom: 0; }
.chat-body ul, .chat-body ol { margin: 0.2em 0 0.8em; padding-left: 1.3em; }
.chat-body li { margin: 0.25em 0; }
.chat-body strong { color: #fff; }
.chat-body code { background: rgba(255,255,255,0.08); padding: 0.05em 0.35em; border-radius: 0.3em; font-size: 0.9em; }
.chat-body a { color: #7cc4ff; text-decoration: underline; text-underline-offset: 2px; }
.chat-body .chat-h { color: #fff; font-weight: 600; margin-top: 0.4em; }

/* numeri delle fonti nel testo */
.chat-cite {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35em;
  height: 1.35em;
  padding: 0 0.3em;
  margin: 0 0.1em;
  border: 0;
  border-radius: 0.4em;
  background: rgba(25, 145, 235, 0.25);
  color: #cfe8ff;
  font: 600 0.72em/1 var(--chat-read);
  vertical-align: 0.15em;
  cursor: pointer;
}
.chat-cite:hover { background: var(--chat-accent); color: #fff; }

/* elenco fonti */
.chat-sources {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.8rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--chat-line);
}
.chat-sources-label { font-size: 0.65rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--chat-muted); margin-right: 0.2rem; }
.chat-source {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  max-width: 100%;
  padding: 0.35rem 0.7rem 0.35rem 0.35rem;
  border: 1px solid var(--chat-line);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--chat-text);
  font: 0.82rem/1.2 var(--chat-read);
  text-align: left;
  cursor: pointer;
}
.chat-source:hover:not(:disabled) { border-color: var(--chat-accent); color: #fff; }
.chat-source:disabled { cursor: default; opacity: 0.8; }
.chat-source-n {
  flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.4rem; height: 1.4rem;
  border-radius: 50%;
  background: rgba(25, 145, 235, 0.25);
  color: #cfe8ff;
  font-size: 0.72rem; font-weight: 600;
}

/* domande suggerite */
.chat-suggestions { display: flex; flex-direction: column; gap: 0.45rem; margin-top: 0.9rem; }
.chat-suggestion {
  text-align: left;
  padding: 0.6rem 0.85rem;
  border: 1px solid rgba(25, 145, 235, 0.4);
  border-radius: 0.8rem;
  background: transparent;
  color: #cfe8ff;
  font: 0.9rem/1.4 var(--chat-read);
  cursor: pointer;
}
.chat-suggestion:hover { background: rgba(25, 145, 235, 0.15); color: #fff; }

/* in attesa */
.chat-typing .chat-body { color: var(--chat-muted); font-size: 0.9rem; }
.chat-dots { display: inline-flex; gap: 0.25rem; margin-right: 0.35rem; vertical-align: middle; }
.chat-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--chat-accent); animation: chat-blink 1.2s infinite ease-in-out; }
.chat-dots i:nth-child(2) { animation-delay: 0.15s; }
.chat-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-blink { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }
@media (prefers-reduced-motion: reduce) { .chat-dots i { animation: none; opacity: 0.7; } .chat-log { scroll-behavior: auto; } }

/* ---- input ---- */
.chat-form { display: flex; gap: 0.75rem; align-items: flex-end; margin-top: 1rem; }
.chat-form textarea {
  flex: 1;
  min-height: 3.1rem;
  max-height: 200px;
  resize: none;
  box-sizing: border-box;
  padding: 0.85rem 1rem;
  border: 1px solid var(--chat-accent);
  border-radius: 1rem;
  background: rgba(0, 0, 0, 0.3);
  color: #fff;
  font: 1rem/1.4 var(--chat-read);
}
.chat-form textarea:focus { outline: none; box-shadow: 0 0 0 3px rgba(25, 145, 235, 0.35); }
.chat-form textarea::placeholder { color: var(--chat-muted); }
.section .chat-form .chat-send { margin-top: 0; padding: 0.9rem 1.5rem; }
.chat-send:disabled, .chat-form textarea:disabled { opacity: 0.55; cursor: wait; }
.section .chat-note { font-size: 0.72rem; color: var(--chat-muted); margin: 0.75rem 0 0; }

/* ---- pannello della fonte aperta ---- */
.chat-risorsa-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.chat-risorsa-head h3 { margin: 0 0 1rem; }
.chat-risorsa-close {
  flex: none;
  width: 2.2rem; height: 2.2rem;
  border: 1px solid var(--chat-line, rgba(255,255,255,0.08));
  border-radius: 50%;
  background: transparent;
  color: #ccc;
  font-size: 1.3rem; line-height: 1;
  cursor: pointer;
}
.chat-risorsa-close:hover { color: #fff; border-color: #1991eb; }
.chat-risorsa-body img { max-width: 100% !important; height: auto !important; display: block; margin: 0 auto; border-radius: 1rem; }

@media screen and (max-width: 768px) {
  .chat-msg { max-width: 100%; }
  .chat-log { max-height: 65vh; }
  .chat-form { flex-direction: column; align-items: stretch; }
  .section .chat-form .chat-send { width: 100%; }
}

/* [hidden] deve vincere sulle regole display delle classi */
.chat-section [hidden], .chat-risorsa[hidden] { display: none !important; }

/* ---- accesso con email ---- */
.chat-gate { display: grid; grid-template-columns: 1.1fr 1fr; gap: 2rem; align-items: start; }
.chat-gate-how h3 { margin: 0 0 .6rem; font-size: 1.05rem; }
.chat-gate-how ol, .chat-gate-how p { font-family: var(--chat-read); color: var(--chat-text); line-height: 1.6; }
.chat-gate-how ol { padding-left: 1.3em; margin: 0 0 .8em; }
.chat-gate-how li { margin: .35em 0; }
.chat-gate-how p { font-size: .9rem; color: var(--chat-muted); }
.chat-gate-form { display: flex; flex-direction: column; gap: .7rem; padding: 1.2rem; border: 1px solid var(--chat-line); border-radius: 1rem; background: rgba(0,0,0,.25); }
.chat-gate-form label { font-size: .8rem; color: var(--chat-muted); }
.chat-gate-form input[type=email], .chat-gate-form input[type=text] {
  box-sizing: border-box; width: 100%; padding: .8rem 1rem; border: 1px solid var(--chat-accent); border-radius: .8rem;
  background: rgba(0,0,0,.3); color: #fff; font: 1rem var(--chat-read);
}
.chat-gate-form input[type=text] { letter-spacing: .3em; font-size: 1.3rem; text-align: center; }
.chat-gate-form input:focus { outline: none; box-shadow: 0 0 0 3px rgba(25,145,235,.35); }
.chat-check { display: flex; gap: .6rem; align-items: flex-start; font: .8rem/1.45 var(--chat-read) !important; color: var(--chat-text) !important; }
.chat-check input { margin-top: .25em; flex: none; accent-color: var(--chat-accent); }
.chat-check a { color: #7cc4ff; }
.section .chat-gate-form .btn { margin-top: .2rem; }
.chat-gate-sent { font-family: var(--chat-read); color: var(--chat-text); margin: 0; }
.chat-gate-links { margin: 0; font-size: .8rem; color: var(--chat-muted); }
.chat-link { background: none; border: 0; padding: 0; color: #7cc4ff; font: inherit; font-size: .8rem; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.chat-link:hover { color: #fff; }
.chat-gate-msg { margin: 0; min-height: 1.2em; font: .85rem var(--chat-read); color: var(--chat-muted); }
.chat-gate-err { color: #fca5a5; }

/* ---- barra utente / quota ---- */
.chat-userbar { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; margin: -.3rem 0 .6rem; font: .8rem var(--chat-read); color: var(--chat-muted); }
.chat-user-email { color: var(--chat-text); }
.chat-quota { padding: .15rem .6rem; border-radius: 999px; background: rgba(25,145,235,.15); color: #cfe8ff; }
.chat-quota-low { background: rgba(251,191,36,.18); color: #fde68a; }
.chat-quota-over { background: rgba(248,113,113,.18); color: #fca5a5; }
.chat-userbar .chat-push { margin-left: auto; }

/* ---- selettore lingua nell'header ---- */
.lang-switch a { font-size: .85rem; margin: 0 .25rem; padding: .15rem .35rem; border-radius: .4rem; }
.lang-switch a.active { color: #fff; background: rgba(25,145,235,.35); }

@media screen and (max-width: 768px) {
  .chat-gate { grid-template-columns: 1fr; }
  .lang-switch a { font-size: .75rem; margin: 0 .1rem; }
}

/* ---- riquadri iridescenti come il box AI di OsintGraph:
        bordo multicolore che scorre, alone sfumato, lampo di colore all'arrivo ---- */
.chat-section {
  --chat-iris: linear-gradient(90deg, #ff5f6d, #ffc371, #47e891, #3fa9f5, #a66cff,
                                      #ff5f6d, #ffc371, #47e891, #3fa9f5, #a66cff, #ff5f6d);
}
.chat-log { padding: 1.2rem 1.1rem; }
.chat-msg {
  --chat-fill: #181f2d;                /* fondo pieno: il bordo e' il gradiente che resta visibile attorno */
  position: relative;                  /* niente isolation: l'alone (z-index -1) deve stare DIETRO il riquadro */
  border: 2px solid transparent;
  background: linear-gradient(var(--chat-fill), var(--chat-fill)) padding-box, var(--chat-iris) border-box;
  background-size: 100% 100%, 200% 100%;
  animation: chat-flow 5s linear infinite;
}
.chat-user { --chat-fill: #12293f; border-color: transparent; }
.chat-msg::before {                    /* alone sfumato che scorre con il bordo */
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: inherit;
  z-index: -1;
  pointer-events: none;
  background: var(--chat-iris);
  background-size: 200% 100%;
  filter: blur(14px);
  opacity: .45;
  animation: chat-glowflow 5s linear infinite;
}
/* nuovo messaggio: un lampo di colore che si allarga e poi si calma */
.chat-msg.chat-intro::before { animation: chat-glowflow 5s linear infinite, chat-intro 1.6s ease-out 1; }
/* l'assistente sta cercando: scorre piu' veloce e pulsa */
.chat-typing, .chat-typing::before { animation-duration: 1.1s; }
.chat-typing::before { opacity: .85; animation: chat-glowflow 1.1s linear infinite, chat-pulse 1.4s ease-in-out infinite; }
.chat-shimmer {
  font-weight: 600;
  background: linear-gradient(90deg, #a78bfa, #f472b6, #fbbf24, #4ade80, #60a5fa, #a78bfa);
  background-size: 200% 100%;
  -webkit-background-clip: text;
          background-clip: text;
  color: transparent;
  animation: chat-glowflow 1.6s linear infinite;
}
.chat-error {
  background: linear-gradient(var(--chat-fill), var(--chat-fill)) padding-box,
              linear-gradient(rgba(248, 113, 113, .75), rgba(248, 113, 113, .75)) border-box;
  animation: none;
}
.chat-error::before { display: none; }
@keyframes chat-flow     { from { background-position: 0 0, 0% 50%; } to { background-position: 0 0, 100% 50%; } }
@keyframes chat-glowflow { from { background-position: 0% 50%; }       to { background-position: 100% 50%; } }
@keyframes chat-intro {
  0%   { opacity: 0;   transform: scale(.96); filter: blur(4px); }
  35%  { opacity: 1;   transform: scale(1.04); filter: blur(22px); }
  100% { opacity: .45; transform: scale(1);    filter: blur(14px); }
}
@keyframes chat-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.025); } }
@media (prefers-reduced-motion: reduce) {
  .chat-msg, .chat-msg::before, .chat-shimmer { animation: none !important; }
}
@media (max-width: 640px) { .chat-log { padding: 1rem .7rem; } }
