/* Chat live: pulsante flottante + pannello (dal basso su telefono, flottante su computer). */
.chat-fab {
  position: fixed; z-index: 32; right: max(1rem, env(safe-area-inset-right)); bottom: max(1rem, env(safe-area-inset-bottom));
  width: 3.6rem; height: 3.6rem; border-radius: 50%; display: grid; place-items: center; cursor: pointer;
  border: 1px solid var(--hair-2); color: var(--ink);
  background: radial-gradient(circle at 30% 25%, rgba(255, 61, 154, 0.55), rgba(139, 92, 246, 0.55) 60%, rgba(18, 15, 30, 0.9));
  box-shadow: 0 10px 40px -10px rgba(255, 61, 154, 0.55), inset 0 1px 1px rgba(255, 255, 255, 0.25);
  transition: transform 0.5s var(--spring), box-shadow 0.5s var(--spring);
  -webkit-tap-highlight-color: transparent;
}
.chat-fab:hover { transform: translateY(-2px) scale(1.04); }
.chat-fab:active { transform: scale(0.96); }
.chat-fab .icon { width: 1.5rem; height: 1.5rem; }
.chat-fab.on { background: rgba(18, 15, 30, 0.92); box-shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.6); }
.chat-badge {
  position: absolute; top: -0.2rem; right: -0.2rem; min-width: 1.35rem; height: 1.35rem; padding: 0 0.35rem;
  display: grid; place-items: center; border-radius: 999px; background: var(--magenta); color: #fff;
  font: 700 0.72rem/1 var(--mono); border: 2px solid var(--bg); animation: chat-pop 0.5s var(--spring);
}
@keyframes chat-pop { from { transform: scale(0.4); } }

.chat {
  position: fixed; z-index: 33; display: flex; flex-direction: column; overflow: hidden;
  right: 1rem; bottom: calc(5.4rem + env(safe-area-inset-bottom));
  width: min(380px, calc(100vw - 2rem)); height: min(560px, calc(100dvh - 8rem));
  border-radius: 1.6rem; border: 1px solid var(--hair-2);
  background: rgba(14, 11, 24, 0.94);
  backdrop-filter: blur(22px) saturate(1.3); -webkit-backdrop-filter: blur(22px) saturate(1.3);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.75), inset 0 1px 1px rgba(255, 255, 255, 0.08);
  opacity: 0; transform: translateY(16px) scale(0.98); transform-origin: bottom right;
  transition: opacity 0.45s var(--out), transform 0.55s var(--spring);
}
.chat.in { opacity: 1; transform: none; }
.chat[hidden] { display: none; }

.chat-head {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0.35rem 0.6rem;
  padding: 0.9rem 0.9rem 0.75rem 1.1rem; border-bottom: 1px solid var(--hair);
}
.chat-title { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.chat-title strong { font-family: var(--font-display); font-size: 0.92rem; letter-spacing: 0.02em; }
.chat-online { display: inline-flex; align-items: center; gap: 0.35rem; font: 0.75rem var(--mono); color: var(--ink-2); }
.chat-online i { width: 0.45rem; height: 0.45rem; border-radius: 50%; background: var(--lime); box-shadow: 0 0 10px var(--lime); }
.chat-x {
  width: 2.25rem; height: 2.25rem; border-radius: 50%; display: grid; place-items: center; cursor: pointer;
  border: 1px solid var(--hair); background: rgba(255, 255, 255, 0.04); color: var(--ink-2);
}
.chat-x .icon { width: 1.05rem; height: 1.05rem; }
.chat-now { grid-column: 1 / -1; display: flex; gap: 0.45rem; align-items: baseline; min-width: 0; font-size: 0.78rem; color: var(--ink-3); }
.chat-now span { flex: none; text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.64rem; color: var(--cyan); }
.chat-now b { font-weight: 500; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-list {
  flex: 1; min-height: 0; margin: 0; padding: 0.7rem 0.6rem 0.9rem; list-style: none;
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; scrollbar-width: thin;
}
.cm {
  position: relative; padding: 0.38rem 2rem 0.38rem 0.55rem; border-radius: 0.8rem;
  font-size: 0.92rem; line-height: 1.42; overflow-wrap: anywhere; animation: chat-in 0.45s var(--out);
}
@keyframes chat-in { from { opacity: 0; transform: translateY(6px); } }
.cm:hover { background: rgba(255, 255, 255, 0.035); }
.cm-nick { font-weight: 700; color: hsl(var(--h) 85% 72%); margin-right: 0.35rem; }
.cm-badge {
  display: inline-block; margin: 0 0.4rem 0 -0.1rem; padding: 0.05rem 0.4rem; border-radius: 999px; vertical-align: 0.08em;
  font: 700 0.62rem/1.4 var(--mono); text-transform: uppercase; letter-spacing: 0.08em;
  color: #120f1e; background: linear-gradient(90deg, var(--magenta), var(--cyan));
}
.cm.mod { background: rgba(255, 61, 154, 0.08); }
.cm.mod .cm-nick { color: var(--ink); }
.cm.me { background: rgba(139, 92, 246, 0.1); }
.cm-text { color: var(--ink); }
.cm time { margin-left: 0.4rem; font: 0.68rem var(--mono); color: var(--ink-3); white-space: nowrap; }
.cm-flag {
  position: absolute; top: 0.3rem; right: 0.25rem; width: 1.7rem; height: 1.7rem; display: grid; place-items: center;
  border: 0; border-radius: 50%; background: none; color: var(--ink-3); cursor: pointer; opacity: 0;
  transition: opacity 0.3s var(--out), color 0.3s var(--out);
}
.cm-flag .icon { width: 0.9rem; height: 0.9rem; }
.cm:hover .cm-flag, .cm-flag:focus-visible { opacity: 1; }
.cm-flag:hover { color: var(--danger); }
.cm.sys { padding: 0.3rem 0.55rem; margin: 0.35rem 0; text-align: center; font-size: 0.75rem; color: var(--cyan); background: none; }
.cm.empty { padding: 2.5rem 1rem; text-align: center; color: var(--ink-3); background: none; animation: none; }

.chat-jump {
  position: absolute; left: 50%; bottom: 6.6rem; transform: translateX(-50%); z-index: 1;
  display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.4rem 0.85rem; border-radius: 999px; cursor: pointer;
  border: 1px solid rgba(45, 226, 230, 0.35); background: rgba(10, 30, 36, 0.92); color: var(--cyan); font-size: 0.78rem; font-weight: 600;
}
.chat-jump .icon { width: 0.9rem; height: 0.9rem; }

.chat-form { padding: 0.7rem 0.75rem calc(0.6rem + env(safe-area-inset-bottom)); border-top: 1px solid var(--hair); background: rgba(8, 6, 14, 0.6); }
.chat-row { display: flex; gap: 0.5rem; }
.chat-row[hidden] { display: none; }
.chat-input {
  flex: 1; min-width: 0; height: 2.85rem; padding: 0 1rem; border-radius: 999px;
  border: 1px solid var(--hair-2); background: rgba(255, 255, 255, 0.05); color: var(--ink);
  font-size: 16px; /* 16px: iOS non ingrandisce la pagina quando si tocca il campo */
  transition: border-color 0.3s var(--out), background 0.3s var(--out);
}
.chat-input::placeholder { color: var(--ink-3); }
.chat-input:focus { outline: none; border-color: rgba(45, 226, 230, 0.6); background: rgba(255, 255, 255, 0.07); }
.chat-send {
  flex: none; width: 2.85rem; height: 2.85rem; border-radius: 50%; display: grid; place-items: center; cursor: pointer;
  border: 0; color: #fff; background: linear-gradient(135deg, var(--magenta), var(--violet));
  transition: transform 0.4s var(--spring);
}
.chat-send:active { transform: scale(0.94); }
.chat-send.wide { width: auto; padding: 0 1.2rem; border-radius: 999px; font-weight: 700; font-size: 0.9rem; }
.chat-send .icon { width: 1.15rem; height: 1.15rem; }
.chat-err { margin: 0.5rem 0.3rem 0; font-size: 0.82rem; color: #ffc1c9; }
.chat-meta { margin: 0.5rem 0.3rem 0; font-size: 0.74rem; color: var(--ink-3); }
.chat-meta b { color: var(--ink-2); font-weight: 600; }
.chat-link { padding: 0; border: 0; background: none; color: var(--cyan); font-size: inherit; cursor: pointer; text-decoration: none; }
.chat-link:hover { text-decoration: underline; }

/* Telefono: pannello dal basso, alto circa 3/4 dello schermo, sempre sopra la tastiera. */
@media (max-width: 719px) {
  .chat {
    left: 0; right: 0; width: auto;
    bottom: var(--kb, 0px);
    height: min(74dvh, calc(var(--vvh, 100dvh) - 0.6rem));
    border-radius: 1.6rem 1.6rem 0 0; border-bottom: 0;
    transform: translateY(40px); transform-origin: bottom center;
  }
  .chat-head::before {
    content: ''; position: absolute; left: 50%; top: 0.45rem; width: 2.6rem; height: 0.28rem; margin-left: -1.3rem;
    border-radius: 999px; background: var(--hair-2);
  }
  .chat-head { padding-top: 1.1rem; }
  .chat.in ~ .chat-fab, .chat-fab.on { opacity: 0; pointer-events: none; transform: scale(0.6); }
  .cm-flag { opacity: 0.45; }
  html.chat-lock, html.chat-lock body { overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  .chat, .chat-fab, .cm { transition: none; animation: none; }
}
