* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  color-scheme: dark;   /* date/time picker nativi in tema scuro */
  --bg: #0b141a;
  --panel: #111b21;
  --panel2: #202c33;
  --accent: #00a884;
  --text: #e9edef;
  --muted: #8696a0;
  --bubble-mine: #005c4b;
  --bubble-other: #202c33;
}
html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }

/* ---------- login ---------- */
#login-screen {
  height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.apk-hint { margin-top: 16px; font-size: .85rem; text-align: center; }
.apk-hint a { color: var(--muted); text-decoration: none; }
.apk-hint a:hover { color: var(--text); text-decoration: underline; }
.ios-hint { width: min(320px, 90vw); margin-top: 6px; font-size: .85rem; color: var(--muted); }
.ios-hint summary { cursor: pointer; text-align: center; list-style: none; padding: 4px; }
.ios-hint summary::-webkit-details-marker { display: none; }
.ios-hint[open] summary { margin-bottom: 6px; }
.ios-hint ol { margin: 0 0 6px; padding-left: 1.3em; line-height: 1.55; }
.ios-hint b { color: var(--text); font-weight: 600; }
.ios-note { font-size: .78rem; opacity: .8; margin: 0; }
/* logo Computer Angels in fondo alla schermata di login, cliccabile verso il sito */
#login-brand { display: block; margin-top: 26px; opacity: .55; transition: opacity .2s; }
#login-brand:hover { opacity: .9; }
#login-brand img { width: 150px; height: auto; }
#login-form {
  display: flex; flex-direction: column; gap: 12px;
  width: min(320px, 90vw);
  background: var(--panel);
  padding: 32px 28px; border-radius: 12px;
}
#login-form h1 { font-size: 1.6rem; text-align: center; }
#login-form .tagline { color: var(--muted); text-align: center; font-size: .85rem; margin-bottom: 8px; }
#login-form input {
  background: var(--panel2); border: none; border-radius: 8px;
  padding: 12px; color: var(--text); font-size: 1rem;
}
#login-form button {
  background: var(--accent); border: none; border-radius: 8px;
  padding: 12px; color: #fff; font-size: 1rem; cursor: pointer;
}
#login-error { color: #f15c6d; font-size: .85rem; text-align: center; min-height: 1em; }

/* ---------- layout ---------- */
#main-screen { height: 100%; display: flex; }
#sidebar {
  width: 320px; min-width: 240px;
  background: var(--panel);
  border-right: 1px solid #222d34;
  display: flex; flex-direction: column;
}
#sidebar header {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 16px; background: var(--panel2);
}
#me-name { font-weight: 600; flex: 1; }
#conn-status { color: #f15c6d; font-size: .8rem; transition: color .3s; }
#conn-status.online { color: var(--accent); }
#logout-btn {
  background: none; border: 1px solid var(--muted); color: var(--muted);
  border-radius: 6px; padding: 2px 10px; cursor: pointer; font-size: .8rem;
}
#push-prompt {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; background: var(--panel2);
  border-bottom: 1px solid #1c262d; font-size: .85rem;
}
#push-prompt span { flex: 1; }
#push-enable {
  background: var(--accent); color: #fff; border: none;
  border-radius: 6px; padding: 5px 12px; cursor: pointer; font-size: .82rem;
}
#push-dismiss {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 1rem; line-height: 1;
}
#update-banner {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; background: var(--panel2);
  border-bottom: 1px solid #1c262d; font-size: .85rem;
}
#update-banner span { flex: 1; }
#update-reload {
  background: var(--accent); color: #fff; border: none;
  border-radius: 6px; padding: 5px 12px; cursor: pointer; font-size: .82rem;
}
#update-dismiss {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 1rem; line-height: 1;
}
#add-contact {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--panel);
  border-bottom: 1px solid #1c262d;
}
#add-contact-input {
  flex: 1; min-width: 0; background: var(--panel2); border: none; border-radius: 8px;
  padding: 8px 10px; color: inherit; font-size: .85rem;
}
#add-contact-input::placeholder { color: var(--muted); }
#add-contact-btn {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  width: 34px; height: 34px; flex: 0 0 auto; cursor: pointer; font-size: 1.1rem; line-height: 1;
}
#requests-list { list-style: none; }
#requests-list .req {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 16px; font-size: .85rem;
  border-bottom: 1px solid #1c262d; background: var(--panel);
}
#requests-list .req.in { background: #16232b; }
#requests-list .req-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#requests-list .req button {
  background: var(--accent); color: #fff; border: none; border-radius: 6px;
  min-width: 30px; padding: 4px 8px; cursor: pointer; font-size: .9rem; line-height: 1;
}
#requests-list .req button.danger { background: none; color: var(--muted); border: 1px solid var(--muted); }
#conv-list { list-style: none; overflow-y: auto; flex: 1; }
#conv-list li {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; cursor: pointer;
  border-bottom: 1px solid #1c262d;
}
#conv-list li:hover, #conv-list li.active { background: var(--panel2); }
.avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: #3b4a54; color: #cfd9df;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 1.1rem; flex-shrink: 0;
  position: relative;
}
.avatar .dot {
  position: absolute; right: -1px; bottom: -1px;
  width: 12px; height: 12px; border-radius: 50%;
  background: #667781; border: 2px solid var(--panel);
}
.avatar .dot.online { background: var(--accent); }
.conv-info { flex: 1; min-width: 0; }
.conv-name { font-weight: 500; }
.conv-preview {
  color: var(--muted); font-size: .82rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-preview.live { color: var(--accent); font-style: italic; }
/* badge non-letti, sovrapposto all'angolo dell'avatar del contatto */
.avatar .badge {
  position: absolute; top: -4px; right: -4px;
  min-width: 18px; height: 18px; box-sizing: border-box;
  padding: 0 5px; border-radius: 999px;
  background: var(--accent); color: #fff;
  border: 2px solid var(--panel);
  font-size: .7rem; font-weight: 700; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
/* badge SEPARATO «attività condivise aggiornate»: angolo in basso a sinistra, distinto
   dal badge rosso dei messaggi non letti (in alto a destra) e dal pallino di presenza */
.avatar .task-badge {
  position: absolute; bottom: -5px; left: -5px;
  width: 19px; height: 19px; box-sizing: border-box;
  border-radius: 50%; background: #f0a500;
  border: 2px solid var(--panel);
  font-size: .62rem; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}

/* ---------- chat ---------- */
#chat { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
#empty-chat {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--muted); text-align: center; line-height: 1.7;
}
#empty-chat .empty-inner { display: flex; flex-direction: column; align-items: center; gap: 22px; }
#empty-chat .brand-logo { display: block; opacity: .9; transition: opacity .2s; }
#empty-chat .brand-logo:hover { opacity: 1; }
#empty-chat .brand-logo img { width: 240px; max-width: 60vw; height: auto; }
/* logo cliccabile in fondo alla lista contatti (visibile anche su mobile) */
#sidebar-brand {
  display: flex; justify-content: center; align-items: center;
  padding: 14px 16px; border-top: 1px solid #222d34;
  opacity: .55; transition: opacity .2s; flex-shrink: 0;
}
#sidebar-brand:hover { opacity: .9; }
#sidebar-brand img { width: 96px; height: auto; }
#chat header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; background: var(--panel2);
}
#back-btn {
  background: none; border: none; color: var(--text);
  font-size: 1.6rem; cursor: pointer; display: none; line-height: 1;
}
#chat-headinfo { flex: 1; min-width: 0; }
#chat-title { font-weight: 600; }
#chat-sub { color: var(--muted); font-size: .78rem; min-height: 1em; }
#call-btn, #video-btn, #tasks-btn, #search-btn {
  background: none; border: none; color: var(--accent);
  font-size: 1.4rem; cursor: pointer; flex-shrink: 0; padding: 4px 6px; line-height: 1;
}
#tasks-btn, #search-btn { color: var(--muted); font-size: 1.3rem; }
/* 📞 audio: emoji un po' più grande e brillante — prima si vedeva poco */
#call-btn { font-size: 1.7rem; filter: brightness(1.3) saturate(1.25) drop-shadow(0 0 2px rgba(80,200,120,.5)); }
#call-btn:hover, #video-btn:hover, #tasks-btn:hover, #search-btn:hover { filter: brightness(1.35); color: var(--text); }

/* ---------- ricerca nella conversazione ---------- */
#search-panel {
  position: absolute; inset: 0; z-index: 5;
  display: flex; flex-direction: column;
  background: var(--bg);
}
#search-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; background: var(--panel2); flex-shrink: 0;
}
#search-input {
  flex: 1; min-width: 0; background: var(--panel); border: none; border-radius: 8px;
  color: var(--text); padding: 9px 12px; font-size: .95rem;
}
#search-input::placeholder { color: var(--muted); }
#search-count { color: var(--muted); font-size: .8rem; white-space: nowrap; }
#search-close {
  background: none; border: none; color: var(--muted);
  font-size: 1.2rem; cursor: pointer; line-height: 1; padding: 4px 6px;
}
#search-close:hover { color: var(--text); }
#search-results { flex: 1; overflow-y: auto; padding: 8px 0; }
#search-results .sr-empty { color: var(--muted); text-align: center; padding: 28px 16px; }
#search-results .sr-item {
  padding: 8px 16px; cursor: pointer; border-bottom: 1px solid #1c262d;
}
#search-results .sr-item:hover { background: var(--panel2); }
#search-results .sr-head {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: .74rem; color: var(--muted); margin-bottom: 2px;
}
#search-results .sr-who { font-weight: 600; color: #53bdeb; }
#search-results .sr-text {
  font-size: .9rem; line-height: 1.35; white-space: pre-wrap; word-break: break-word;
}
#search-results .sr-text mark { background: #f0a500; color: #000; border-radius: 2px; padding: 0 1px; }
#search-results .sr-att { font-size: .82rem; color: var(--muted); }
/* pulsante «torna ai messaggi recenti» quando si guarda un punto vecchio della cronologia */
#context-latest {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: 76px; z-index: 4;
  background: var(--accent); color: #fff; border: none;
  border-radius: 999px; padding: 8px 16px; font-size: .85rem; font-weight: 600;
  cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
#context-latest:hover { filter: brightness(1.1); }
/* messaggio evidenziato brevemente dopo il salto dal risultato di ricerca */
.msg.flash-hit { animation: msgflash 1.6s ease-out; }
@keyframes msgflash {
  0%, 30% { background: #f0a500; }
  100% { }
}
.msg-link { color: #7ec8ff; text-decoration: underline; word-break: break-all; }
.msg.mine .msg-link { color: #cfeaff; }
#messages {
  flex: 1; overflow-y: auto; padding: 16px 8%;
  display: flex; flex-direction: column; gap: 4px;
}
.msg {
  max-width: 72%;
  padding: 7px 10px; border-radius: 8px;
  font-size: .94rem; line-height: 1.35;
  white-space: pre-wrap; word-break: break-word;
  align-self: flex-start; background: var(--bubble-other);
}
.msg.mine { align-self: flex-end; background: var(--bubble-mine); }
.msg .sender { font-size: .76rem; font-weight: 600; color: #53bdeb; display: block; }
.msg .meta { float: right; margin: 8px 0 0 10px; display: inline-flex; gap: 4px; align-items: baseline; }
.msg .time { font-size: .68rem; color: var(--muted); }
.msg .check { font-size: .72rem; color: var(--muted); }
.msg .check.read { color: #53bdeb; }
.msg .edited { font-size: .62rem; color: var(--muted); font-style: italic; }
.msg.live {
  background: transparent;
  border: 1px dashed var(--accent);
  color: #b8d4cd;
  opacity: .95;
}
.msg.live .sender { color: var(--accent); }
.msg.live .caret {
  display: inline-block; width: 2px; height: 1em;
  background: var(--accent); margin-left: 1px;
  vertical-align: text-bottom;
  animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.day-sep {
  align-self: center; background: var(--panel2); color: var(--muted);
  font-size: .74rem; padding: 4px 12px; border-radius: 8px; margin: 10px 0 6px;
}
#chat footer {
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px 16px; background: var(--panel2);
}
#composer { display: flex; gap: 8px; align-items: flex-end; }
#attach-btn {
  background: none; border: none; color: var(--muted);
  font-size: 1.4rem; cursor: pointer; flex-shrink: 0;
  padding: 6px; line-height: 1;
}
#attach-btn:hover { color: var(--text); }
#mic-btn {
  background: none; border: none; color: var(--muted);
  font-size: 1.35rem; cursor: pointer; flex-shrink: 0;
  padding: 6px; line-height: 1;
}
#mic-btn:hover { color: var(--text); }
#mic-btn.recording { color: #f15c6d; animation: blink 1s step-end infinite; }
#emoji-btn {
  background: none; border: none; cursor: pointer; flex-shrink: 0;
  font-size: 1.35rem; padding: 6px; line-height: 1; opacity: .85;
}
#emoji-btn:hover { opacity: 1; }
/* pannello emoji: griglia sopra il composer, glyph dei font di sistema */
#emoji-panel {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
  max-height: 190px; overflow-y: auto; margin-bottom: 8px;
  padding: 8px; background: var(--panel2); border-radius: 10px;
}
#emoji-panel button {
  background: none; border: none; cursor: pointer; border-radius: 8px;
  font-size: 1.5rem; line-height: 1; padding: 6px 0;
}
#emoji-panel button:hover { background: var(--panel); }
@media (max-width: 700px) { #emoji-panel { grid-template-columns: repeat(7, 1fr); } }
#attach-pending, #edit-banner {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border-radius: 8px;
  padding: 6px 10px; font-size: .85rem; color: var(--text);
}
#attach-pending span, #edit-banner span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#attach-pending button, #edit-banner button {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: .95rem; line-height: 1;
}
#edit-banner { border-left: 3px solid var(--accent, #53bdeb); }
/* allegati nelle bolle */
.msg .attach { margin-bottom: 4px; }
.msg .attach-img {
  max-width: 260px; max-height: 320px; width: auto; height: auto;
  border-radius: 6px; cursor: pointer; display: block;
  /* iOS: sopprime il callout nativo («Salva immagine») sul long-press, così può aprirsi
     il NOSTRO menù (long-press → 🗑 Elimina) anche su una foto/allegato. */
  -webkit-touch-callout: none; -webkit-user-select: none; user-select: none;
}
.msg .attach-file {
  display: flex; align-items: center; gap: 10px;
  background: rgba(0,0,0,.18); border-radius: 8px;
  padding: 8px 10px; text-decoration: none; color: var(--text);
  min-width: 180px; max-width: 260px;
  -webkit-touch-callout: none; -webkit-user-select: none; user-select: none;
}
.msg .attach-audio { display: block; width: 260px; max-width: 100%; height: 40px; }
.msg .attach-dur { display: block; font-size: .72rem; color: var(--muted); margin-top: 2px; }
.msg .attach-ic { font-size: 1.5rem; flex-shrink: 0; }
.msg .attach-info { display: flex; flex-direction: column; min-width: 0; }
.msg .attach-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .attach-size { font-size: .72rem; color: var(--muted); }
#input {
  flex: 1; resize: none; border: none; border-radius: 10px;
  background: var(--panel); color: var(--text);
  padding: 11px 14px; font-size: 1rem; font-family: inherit;
  max-height: 120px;
}
#input:focus { outline: none; }
#send-btn {
  background: var(--accent); color: #fff; border: none;
  border-radius: 50%; width: 44px; height: 44px;
  font-size: 1.1rem; cursor: pointer; flex-shrink: 0;
}

/* ---------- menù azioni (long-press / tasto destro) ---------- */
.ctx-menu {
  position: fixed; z-index: 100;
  background: var(--panel2); border: 1px solid #33434d; border-radius: 10px;
  padding: 4px; min-width: 170px;
  box-shadow: 0 8px 28px rgba(0,0,0,.5);
  display: flex; flex-direction: column;
}
.ctx-menu button {
  background: none; border: none; color: var(--text);
  text-align: left; padding: 10px 14px; font-size: .92rem;
  border-radius: 7px; cursor: pointer;
}
.ctx-menu button:hover { background: var(--panel); }
.ctx-menu button.danger { color: #f15c6d; }

/* toast di conferma (richiesta trascrizione/vocale) */
#flash {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--panel2); color: var(--text);
  border: 1px solid #33434d; border-radius: 20px;
  padding: 10px 18px; font-size: .86rem; z-index: 101;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: 90vw; text-align: center;
}
#flash.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- attività / scadenze condivise ---------- */
#tasks-panel {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(400px, 100%);
  background: var(--panel);
  border-left: 1px solid #222d34;
  display: flex; flex-direction: column;
  z-index: 60;
  box-shadow: -8px 0 28px rgba(0,0,0,.4);
}
#tasks-panel header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; background: var(--panel2);
}
#tasks-close {
  background: none; border: none; color: var(--text);
  font-size: 1.6rem; cursor: pointer; line-height: 1;
}
#tasks-headinfo { flex: 1; min-width: 0; }
#tasks-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#tasks-sub { color: var(--muted); font-size: .74rem; }
#tasks-filter {
  background: var(--panel); color: var(--text); border: 1px solid #33434d;
  border-radius: 8px; padding: 6px 8px; font-size: .82rem; cursor: pointer;
}
#tasks-list { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.tasks-empty { color: var(--muted); text-align: center; padding: 30px 12px; font-size: .9rem; line-height: 1.5; }
#tasks-panel footer { padding: 12px 16px; background: var(--panel2); }
#tasks-add-btn {
  width: 100%; background: var(--accent); color: #fff; border: none;
  border-radius: 10px; padding: 12px; font-size: .95rem; cursor: pointer;
}
.task {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--panel2); border-radius: 10px; padding: 10px 12px;
}
.task.done { opacity: .6; }
.task-check { width: 20px; height: 20px; margin-top: 2px; flex-shrink: 0; cursor: pointer; accent-color: var(--accent); }
.task-body { flex: 1; min-width: 0; }
.task-title { font-weight: 500; word-break: break-word; }
.task.done .task-title { text-decoration: line-through; }
.task-descr { color: var(--muted); font-size: .84rem; margin-top: 2px; white-space: pre-wrap; word-break: break-word; }
.task-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 5px; font-size: .76rem; }
.task-due { color: var(--muted); }
.task-due.overdue { color: #f15c6d; font-weight: 600; }
.task-recur { color: var(--accent); }
.task-actions { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }
.task-actions button {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: .95rem; line-height: 1; padding: 2px 4px;
}
.task-actions button:hover { color: var(--text); }
.task-actions button.danger:hover { color: #f15c6d; }

#task-modal {
  position: fixed; inset: 0; z-index: 120;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.task-modal-card {
  background: var(--panel); border-radius: 14px; padding: 20px;
  width: min(420px, 100%); display: flex; flex-direction: column; gap: 12px;
  max-height: 90vh; overflow-y: auto;
}
.task-modal-card h3 { font-size: 1.1rem; }
#tf-title, #tf-descr {
  background: var(--panel2); border: none; border-radius: 8px;
  padding: 11px; color: var(--text); font-size: 1rem; font-family: inherit; width: 100%;
}
#tf-descr { resize: vertical; }
.tf-field { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: .82rem; }
.tf-field input, .tf-field select {
  background: var(--panel2); border: none; border-radius: 8px;
  padding: 10px; color: var(--text); font-size: .95rem; font-family: inherit;
}
.task-modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.task-modal-actions button { border: none; border-radius: 8px; padding: 10px 18px; cursor: pointer; font-size: .92rem; }
#tf-cancel { background: var(--panel2); color: var(--text); }
#tf-save { background: var(--accent); color: #fff; }

/* pulsante «Nuovo gruppo» nella sidebar */
#new-group-btn {
  margin: 0 16px 8px; padding: 9px 12px; border: none; border-radius: 8px;
  background: var(--panel2); color: var(--text); cursor: pointer; font-size: .9rem; text-align: left;
}
#new-group-btn:hover { background: #2a3942; }
/* modale gruppo (riusa .task-modal-card) */
#group-modal {
  position: fixed; inset: 0; z-index: 120; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
#gf-name {
  background: var(--panel2); border: none; border-radius: 8px;
  padding: 11px; color: var(--text); font-size: 1rem; font-family: inherit; width: 100%;
}
.group-modal-hint { color: var(--muted); font-size: .82rem; margin: 2px 0 0; }
#gf-members { display: flex; flex-direction: column; gap: 2px; max-height: 40vh; overflow-y: auto; }
#gf-members label {
  display: flex; align-items: center; gap: 10px; padding: 8px 6px;
  border-radius: 8px; cursor: pointer;
}
#gf-members label:hover { background: var(--panel2); }
#gf-members input { width: 18px; height: 18px; accent-color: var(--accent); }
#gf-members .gf-empty { color: var(--muted); font-size: .85rem; padding: 8px 6px; }
#gf-cancel { background: var(--panel2); color: var(--text); }
#gf-save { background: var(--accent); color: #fff; }
#gf-leave { background: var(--panel2); color: var(--text); margin-right: auto; }
#gf-delete { background: #c62b2b; color: #fff; }

/* ---------- mobile ---------- */
@media (max-width: 700px) {
  #sidebar { width: 100%; min-width: 0; }
  #main-screen.chat-open #sidebar { display: none; }
  #main-screen:not(.chat-open) #chat,
  #main-screen:not(.chat-open) #empty-chat { display: none; }
  #empty-chat { display: none; }
  #back-btn { display: block; }
  #messages { padding: 12px 3%; }
  .msg { max-width: 85%; }
}

/* ---- Overlay chiamata (Fase 1: squillo; il media resta Jitsi) ---- */
#call-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.72);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.call-card {
  background: var(--panel); border-radius: 18px; padding: 28px 24px;
  width: min(360px, 100%); text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.call-avatar {
  width: 84px; height: 84px; border-radius: 50%;
  background: var(--panel2); display: flex; align-items: center; justify-content: center;
  font-size: 38px; animation: call-pulse 1.6s ease-in-out infinite;
}
@keyframes call-pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(0,168,132,.45); }
  50%     { box-shadow: 0 0 0 16px rgba(0,168,132,0); }
}
.call-card h3 { font-size: 1.35rem; }
.call-card #call-status { color: var(--muted); }
.call-actions { display: flex; gap: 16px; margin-top: 12px; }
.call-actions button {
  border: none; border-radius: 999px; padding: 12px 22px;
  font-size: 1rem; font-weight: 600; color: #fff; cursor: pointer;
}
.call-actions .call-accept { background: var(--accent); }
.call-actions .call-reject { background: #d64541; }

/* ---- Chiamata Jitsi incorporata nella pagina (Fase 2: IFrame API) ---- */
#jitsi-modal {
  position: fixed; inset: 0; z-index: 210;
  background: #000; display: flex; flex-direction: column;
}
#jitsi-bar {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; background: var(--panel); color: var(--text);
  padding-top: calc(8px + env(safe-area-inset-top));   /* notch iPhone in standalone */
}
#jitsi-title { font-weight: 600; }
#jitsi-close {
  border: none; background: #d64541; color: #fff; cursor: pointer;
  width: 34px; height: 34px; border-radius: 50%; font-size: 16px; line-height: 34px;
}
#jitsi-container { flex: 1 1 auto; min-height: 0; }
#jitsi-container iframe { width: 100% !important; height: 100% !important; border: 0; }

/* ---- Chiamata audio interna (WebRTC): iframe a tutto schermo su call-audio.html ---- */
#audio-modal { position: fixed; inset: 0; z-index: 210; background: #0f1621; }
#audio-modal iframe { width: 100%; height: 100%; border: 0; }
#audio-close {
  position: fixed; top: calc(12px + env(safe-area-inset-top)); right: 12px; z-index: 211;
  border: none; background: rgba(0,0,0,.45); color: #fff; cursor: pointer;
  width: 34px; height: 34px; border-radius: 50%; font-size: 16px; line-height: 34px;
}

/* ---- Pannello profilo (email per la trascrizione Jitsi via mail) ---- */
#profile-btn {
  background: none; border: none; color: var(--muted); cursor: pointer; font-size: 18px;
}
#profile-panel {
  display: flex; flex-direction: column; gap: 6px;
  padding: 10px 12px; background: var(--panel2); border-bottom: 1px solid rgba(255,255,255,.06);
}
#profile-panel label { font-size: .8rem; color: var(--muted); }
#profile-panel input {
  padding: 8px 10px; border-radius: 8px; border: 1px solid rgba(255,255,255,.12);
  background: var(--panel); color: var(--text); font-size: .95rem;
}
#profile-panel .profile-hint { font-size: .74rem; color: var(--muted); line-height: 1.3; }
#profile-save {
  align-self: flex-start; border: none; border-radius: 8px; padding: 7px 16px;
  background: var(--accent); color: #fff; font-weight: 600; cursor: pointer;
}
