:root {
  --sfondo: #05080d;
  --pannello: #0c131d;
  --bordo: rgba(120, 200, 255, 0.14);
  --bordo-forte: rgba(120, 200, 255, 0.3);
  --testo: #e6f1fb;
  --testo-tenue: #8aa0b6;
  --ciano: #3fd3ff;
  --viola: #a07bff;
  --ambra: #ffb547;
  --rosso: #ff6b7a;
  --verde: #4be3a4;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--sfondo); color: var(--testo);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
/* su iPhone l'app installata non deve mai scorrere tutta: scorre solo la chat */
html, body { position: fixed; inset: 0; width: 100%; overflow: hidden; overscroll-behavior: none; }
button, input, textarea { font: inherit; color: inherit; }
.nascosto { display: none !important; }
.tenue { color: var(--testo-tenue); }
.marchio { font-weight: 600; letter-spacing: 0.42em; font-size: 12px; color: var(--ciano); }

/* --- Collegamento --- */
.schermata { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px 16px; text-align: center; max-width: 440px; margin: 0 auto; }
.schermata h1 { font-weight: 500; font-size: 22px; margin: 4px 0 0; }
#form-collega { display: flex; flex-direction: column; gap: 10px; width: 100%; }
#form-collega input { background: var(--pannello); border: 1px solid var(--bordo-forte); border-radius: 12px;
  padding: 12px 14px; outline: none; }
#codice { font-size: 28px; letter-spacing: 0.35em; text-align: center; font-variant-numeric: tabular-nums; }
.errore { color: var(--rosso); min-height: 1.4em; margin: 0; }
button.primario { background: var(--ciano); color: #001018; border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600; }

/* --- App --- */
#app { position: fixed; left: 0; right: 0; top: var(--vv-alto, 0px); height: var(--vv-altezza, 100dvh);
  display: flex; flex-direction: column; }
/* con la tastiera aperta la sfera si nasconde, per lasciare spazio alla chat */
body.tastiera .palco { display: none; }
body.tastiera .comandi { padding-bottom: 8px; }
.barra { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; border-bottom: 1px solid var(--bordo); }
.stato { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--testo-tenue); min-width: 0; }
.stato span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pallino { width: 8px; height: 8px; border-radius: 50%; background: var(--testo-tenue); flex: none; }
.stato.ok .pallino { background: var(--verde); }
.stato.no .pallino { background: var(--rosso); }
button.icona { background: none; border: 0; font-size: 22px; padding: 4px 8px; color: var(--testo-tenue); }

.menu { position: absolute; right: 12px; top: calc(env(safe-area-inset-top) + 52px); z-index: 10; background: var(--pannello);
  border: 1px solid var(--bordo-forte); border-radius: 14px; padding: 6px; min-width: 250px; box-shadow: 0 12px 40px #000a; }
.menu .riga { display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%;
  padding: 11px 10px; background: none; border: 0; text-align: left; border-radius: 10px; }
.menu .riga input { width: 20px; height: 20px; accent-color: var(--ciano); }
.menu .pericolo { color: var(--rosso); }

.barra-chat { display: flex; align-items: center; gap: 8px; padding: 8px 12px 0; flex: none; }
.titolo-chat { flex: 1; min-width: 0; text-align: left; background: none; border: 0; color: var(--testo); font-size: 14px;
  padding: 6px 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.titolo-chat::before { content: "💬 "; }
.titolo-chat .pieno { color: var(--testo-tenue); font-size: 12px; }
.barra-chat .pillola { height: 32px; font-size: 13px; color: var(--ciano); }
.elenco-chat { position: absolute; left: 10px; right: 10px; top: calc(env(safe-area-inset-top) + 100px); z-index: 20;
  max-height: 60%; overflow-y: auto; background: var(--pannello); border: 1px solid var(--bordo-forte); border-radius: 14px;
  box-shadow: 0 16px 50px #000b; padding: 6px; }
.testa-elenco { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px; }
.voce-chat { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 10px; }
.voce-chat.attiva { background: rgba(63, 211, 255, .1); }
.voce-chat .nome { flex: 1; min-width: 0; display: flex; flex-direction: column; cursor: pointer; }
.voce-chat .nome b { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.voce-chat .nome small { color: var(--testo-tenue); font-size: 12px; }
.palco { display: flex; flex-direction: column; align-items: center; padding: 12px 0 4px; flex: none; }
.sfera { width: 76px; height: 76px; border-radius: 50%; position: relative;
  background: radial-gradient(circle at 50% 45%, rgba(63, 211, 255, .55), rgba(63, 211, 255, .08) 58%, transparent 70%);
  box-shadow: 0 0 40px rgba(63, 211, 255, .25), inset 0 0 22px rgba(63, 211, 255, .35);
  animation: respira 4s ease-in-out infinite; transition: filter .3s; }
.sfera.piccola { width: 64px; height: 64px; }
.sfera::after { content: ""; position: absolute; inset: -8px; border-radius: 50%; border: 1px solid rgba(63, 211, 255, .25); }
.sfera.ascolto { filter: hue-rotate(150deg) saturate(1.6); animation: pulsa .7s ease-in-out infinite; }
.sfera.penso { filter: hue-rotate(40deg); animation: gira 1.2s linear infinite; }
.sfera.parlo { animation: pulsa .45s ease-in-out infinite; }
@keyframes respira { 50% { transform: scale(1.05); } }
@keyframes pulsa { 50% { transform: scale(1.12); } }
@keyframes gira { 50% { transform: scale(.94) rotate(180deg); } to { transform: rotate(360deg); } }
.sotto { font-size: 13px; color: var(--testo-tenue); min-height: 1.4em; margin-top: 10px; padding: 0 16px; text-align: center; }

.chat { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 16px 12px; display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch; }
.msg { max-width: 88%; padding: 9px 13px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; }
.msg .chi { display: block; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--testo-tenue); margin-bottom: 2px; }
.msg.tu { align-self: flex-end; background: rgba(63, 211, 255, .14); border: 1px solid var(--bordo-forte); border-bottom-right-radius: 5px; }
.msg.jarvis { align-self: flex-start; background: var(--pannello); border: 1px solid var(--bordo); border-bottom-left-radius: 5px; }
.msg.jarvis.esperto { border-color: rgba(160, 123, 255, .45); }
.msg.jarvis.esperto .chi { color: var(--viola); }
.msg.file { min-width: 230px; }
.msg.file .anteprima { display: block; max-width: 100%; max-height: 260px; border-radius: 10px; margin: 4px 0 8px; }
.riga-file { display: flex; align-items: center; gap: 10px; }
.icona-file { font-size: 28px; }
.nome-file { display: flex; flex-direction: column; min-width: 0; white-space: normal; }
.nome-file b { font-weight: 500; overflow-wrap: anywhere; }
.nome-file small { color: var(--testo-tenue); }
.azioni-file { display: flex; gap: 8px; margin-top: 10px; }
.azioni-file a, .azioni-file button { flex: 1; text-align: center; padding: 8px 10px; border-radius: 10px; font-size: 14px;
  border: 1px solid var(--bordo-forte); background: none; color: var(--ciano); text-decoration: none; }
.msg { position: relative; transition: transform .15s; }
.cit-nel-msg { display: block; font-size: 13px; color: var(--testo-tenue); border-left: 2px solid var(--ciano);
  padding: 2px 0 2px 8px; margin: 2px 0 6px; max-height: 3.2em; overflow: hidden; white-space: normal; }
.rispondi-btn { display: none; margin-top: 8px; background: none; border: 1px solid var(--bordo-forte); color: var(--ciano);
  border-radius: 10px; padding: 5px 10px; font-size: 13px; }
.msg.scelto .rispondi-btn { display: inline-block; margin-right: 6px; }
.msg.scelto { border-color: var(--bordo-forte); }
.citazione { display: flex; gap: 8px; align-items: flex-start; margin: 0 12px; padding: 8px 10px; border-radius: 12px 12px 0 0;
  background: var(--pannello); border: 1px solid var(--bordo-forte); border-bottom: 0; }
.citazione > div { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 13px; }
.citazione b { color: var(--ciano); font-weight: 600; }
.citazione span { color: var(--testo-tenue); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.citazione .icona { font-size: 16px; padding: 0 4px; }
.allega { flex: none; background: none; border: 0; font-size: 20px; padding: 6px 4px 6px 0; align-self: center; }
.scrivi { padding-left: 8px; }
.allegati { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 12px 6px; }
.chip-allegato { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 5px 6px 5px 10px; border-radius: 14px;
  background: var(--pannello); border: 1px solid var(--bordo-forte); font-size: 13px; color: var(--testo); overflow: hidden; }
.chip-allegato.errore { border-color: var(--rosso); }
.chip-allegato button { background: none; border: 0; color: var(--testo-tenue); font-size: 13px; padding: 0 4px; }
.tabella-chat { border-collapse: collapse; margin: 8px 0; font-size: 13px; white-space: normal; display: block; overflow-x: auto; max-width: 100%; }
.tabella-chat th, .tabella-chat td { border: 1px solid var(--bordo-forte); padding: 5px 9px; text-align: left; }
.tabella-chat th { background: rgba(63, 211, 255, .1); font-weight: 600; }
.msg a.link { color: var(--ciano); word-break: break-all; }
.msg.avviso { align-self: center; font-size: 13px; color: var(--ambra); background: none; padding: 2px 8px; }
.msg.scrive .testo::after { content: "▍"; animation: lampeggia 1s steps(1) infinite; color: var(--ciano); }
@keyframes lampeggia { 50% { opacity: 0; } }

.comandi { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px);
  border-top: 1px solid var(--bordo); background: var(--sfondo); }
.scrivi { flex: 1; display: flex; align-items: flex-end; gap: 6px; background: var(--pannello);
  border: 1px solid var(--bordo-forte); border-radius: 22px; padding: 4px 4px 4px 14px; min-width: 0; }
.scrivi textarea { flex: 1; resize: none; border: 0; background: none; outline: none; padding: 8px 0; max-height: 120px; min-width: 0; }
.tondo { width: 40px; height: 40px; border-radius: 50%; border: 0; flex: none; display: grid; place-items: center; font-size: 17px; }
.tondo.primario { background: var(--ciano); color: #001018; }
.tondo.mic { width: 48px; height: 48px; font-size: 21px; background: var(--pannello); border: 1px solid var(--bordo-forte); }
.tondo.mic.attivo { background: var(--rosso); border-color: var(--rosso); animation: pulsa .7s ease-in-out infinite; }
.pillola { flex: none; height: 40px; padding: 0 12px; border-radius: 20px; background: none; border: 1px solid var(--bordo-forte);
  color: var(--testo-tenue); font-size: 13px; }
.pillola[aria-pressed="true"] { background: rgba(160, 123, 255, .2); border-color: var(--viola); color: #d9ccff; }
