/* Ripetute: chat (messaggi diretti e gruppi), come su Instagram. Solo colori del tema (chiaro e scuro). */

/* ---------- pagine a colonna: intestazione, elenco che scorre, campo sempre in fondo ---------- */
#chatDlg[open], #cshareDlg[open] { display: flex; flex-direction: column; overflow: hidden; }
/* PC: la chat con l'atleta guardato resta accanto al calendario (js/chat.js, Chat.coachDock), che si stringe per farle posto */
@media (min-width: 821px) {
  body.has-dock { --dock-w: clamp(320px, 30vw, 420px); padding-right: var(--dock-w); }
  #chatDlg.is-dock { width: var(--dock-w); z-index: 15; box-shadow: none; animation: none; }
}
#chatDlg > .sh-head, #cshareDlg > .sh-head { flex: none; }
#chatDlg > .sh-body, #cshareDlg > .sh-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }

/* pulsante in intestazione spinto a destra (sul PC la X resta subito dopo) */
.sh-top .ch-push { margin-left: auto; }
.sh-top .ch-push ~ .sh-close { margin-left: 4px; }
.ch-hbtn { color: var(--ink); }
.ch-hbtn svg { width: 22px; height: 22px; }

.ch-note { margin: 18px 0; color: var(--muted); text-align: center; }
.ch-gate { margin: 0; padding: 28px 4px; color: var(--muted); text-align: center; }
.ch-gate p { margin: 0 0 12px; }
.ch-gh { margin: 16px 0 4px; font: 600 13px/1 var(--f-display); text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }

/* foto profilo di riserva (se il social non c'è) e foto di gruppo */
.ch-ini {
  display: inline-grid; place-items: center; flex: none; border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 16%, var(--surface)); color: color-mix(in srgb, var(--accent) 70%, var(--ink)); font-weight: 700;
}
.ch-av2 { position: relative; display: block; flex: none; width: var(--s); height: var(--s); }
.ch-av2 > * { position: absolute !important; }
.ch-av2 > :first-child { top: 0; right: 0; }
.ch-av2 > :last-child { bottom: 0; left: 0; border-radius: 50%; box-shadow: 0 0 0 2px var(--surface); }
.ch-gico {
  display: grid; place-items: center; flex: none; width: var(--s); height: var(--s); border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface)); color: color-mix(in srgb, var(--accent) 75%, var(--ink));
}
.ch-gico svg { width: 50%; height: 50%; }
.ch-lock { display: inline-grid; flex: none; color: var(--muted); }
.ch-lock svg { width: 13px; height: 13px; }

/* ---------- Messaggi: elenco delle chat ---------- */
.ch-inbox { padding-top: 4px; }
.ch-rows, .ch-people { list-style: none; margin: 0 -20px; padding: 0; }
.ch-row, .ch-person {
  display: flex; align-items: center; gap: 12px; width: 100%; min-width: 0;
  border: 0; background: transparent; color: var(--ink); font: inherit; text-align: left; cursor: pointer;
}
.ch-row { min-height: 72px; padding: 8px 20px; }
.ch-row:hover, .ch-person:not(:disabled):hover { background: color-mix(in srgb, var(--ink) 4%, transparent); }
.ch-row:active, .ch-person:not(:disabled):active { background: color-mix(in srgb, var(--ink) 8%, transparent); }
.ch-rav { flex: none; display: grid; place-items: center; width: 52px; height: 52px; }
.ch-rt { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.ch-rt > b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; font-weight: 500; }
.ch-rp { display: flex; gap: 5px; min-width: 0; font-size: 13.5px; color: var(--muted); }
.ch-rx { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-rtm { flex: none; white-space: nowrap; }
.ch-rtm::before { content: "· "; }
.ch-row.is-unread .ch-rt > b, .ch-row.is-unread .ch-rp { font-weight: 700; color: var(--ink); }
.ch-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }

/* ---------- una chat ---------- */
.ch-who {
  display: flex; align-items: center; gap: 10px; flex: 1 1 auto; min-width: 0; margin: -3px 0; padding: 3px 6px 3px 2px;
  border: 0; border-radius: 10px; background: transparent; color: inherit; font: inherit; text-align: left;
}
button.ch-who { cursor: pointer; }
button.ch-who:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.ch-wt { display: flex; flex-direction: column; min-width: 0; }
.ch-wt b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16.5px; font-weight: 700; line-height: 1.2; }
.ch-wt small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; color: var(--muted); }

.ch-mid { position: relative; isolation: isolate; display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
/* in ogni chat, dietro i messaggi, la formica del marchio appena accennata (ferma mentre i messaggi scorrono) */
.ch-mid::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background-color: var(--accent); opacity: .06;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='56 88 412 340'%3E%3Cg transform='translate(-8 6)'%3E%3Cellipse cx='160' cy='292' rx='86' ry='66' transform='rotate(-12 160 292)'/%3E%3Ccircle cx='246' cy='282' r='16'/%3E%3Cellipse cx='290' cy='266' rx='48' ry='32' transform='rotate(-22 290 266)'/%3E%3Ccircle cx='366' cy='222' r='50'/%3E%3Cg fill='none' stroke='%23000' stroke-width='18' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M356 176C352 132 376 108 410 100M380 178C392 140 424 124 456 128'/%3E%3Cpath d='M270 284L222 334L196 398M290 288L292 342L270 402M312 280L352 328L378 392'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E") center / min(62%, 280px) auto no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='56 88 412 340'%3E%3Cg transform='translate(-8 6)'%3E%3Cellipse cx='160' cy='292' rx='86' ry='66' transform='rotate(-12 160 292)'/%3E%3Ccircle cx='246' cy='282' r='16'/%3E%3Cellipse cx='290' cy='266' rx='48' ry='32' transform='rotate(-22 290 266)'/%3E%3Ccircle cx='366' cy='222' r='50'/%3E%3Cg fill='none' stroke='%23000' stroke-width='18' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M356 176C352 132 376 108 410 100M380 178C392 140 424 124 456 128'/%3E%3Cpath d='M270 284L222 334L196 398M290 288L292 342L270 402M312 280L352 328L378 392'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E") center / min(62%, 280px) auto no-repeat;
}/* pochi messaggi: stanno in basso, vicino al campo (come in ogni chat) */
.ch-list {
  display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0;
  overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; padding: 8px 16px 10px;
}
.ch-msgs { display: flex; flex-direction: column; margin-top: auto; }

.ch-intro { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 20px 0 10px; text-align: center; }
.ch-intro > b { margin-top: 6px; font-size: 18px; }
.ch-intro > small { color: var(--muted); }
.ch-intro .btn { margin-top: 10px; }

.ch-day { align-self: center; margin: 16px 0 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.ch-msg { display: flex; flex-direction: column; align-items: flex-start; margin-top: 2px; }
.ch-msg.is-first { margin-top: 10px; }
.ch-msg.is-mine { align-items: flex-end; }
.ch-from { margin: 0 0 3px 48px; font-size: 12px; color: var(--muted); }
.ch-line { display: flex; align-items: flex-end; gap: 8px; max-width: 86%; min-width: 0; }
.ch-msg.is-mine .ch-line { max-width: 80%; }
.ch-mav { flex: none; width: 28px; }
.ch-avb { display: block; padding: 0; border: 0; border-radius: 50%; background: none; cursor: pointer; }
.ch-bw { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; min-width: 0; }
.ch-msg.is-mine .ch-bw { align-items: flex-end; }

/* fumetti: degli altri in grigio, i miei col colore dell'app; angoli stretti dove si toccano */
.ch-b {
  max-width: 100%; padding: 8px 13px; border-radius: 20px;
  background: color-mix(in srgb, var(--ink) 8%, var(--surface)); color: var(--ink);
  font-size: 15px; line-height: 1.35; white-space: pre-wrap; overflow-wrap: anywhere;
}
.ch-b a { color: inherit; text-decoration: underline; }
.ch-msg.is-mine .ch-b { background: var(--accent); color: var(--accent-ink); }
/* risposta a un messaggio (js/chat.js, «Rispondi»): in cima al fumetto il riquadro della citazione, con la striscia a
   sinistra, chi l'aveva scritto e l'inizio del messaggio; toccandolo si torna al messaggio citato, che lampeggia */
.ch-b.has-q { display: flex; flex-direction: column; gap: 5px; padding-top: 6px; }
.ch-quote {
  display: flex; flex-direction: column; gap: 1px; min-width: 0; max-width: 100%; margin: 0 -7px; padding: 5px 10px 6px;
  border: 0; border-left: 3px solid color-mix(in srgb, var(--accent) 80%, var(--ink)); border-radius: 12px 12px 12px 6px;
  background: color-mix(in srgb, var(--ink) 7%, transparent); color: inherit; font: inherit; text-align: left; white-space: normal; cursor: pointer;
}
.ch-quote b { font-size: 12.5px; font-weight: 700; color: color-mix(in srgb, var(--accent) 80%, var(--ink)); }
.ch-quote span { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; font-size: 13px; line-height: 1.3; opacity: .85; }
.ch-quote:hover { background: color-mix(in srgb, var(--ink) 11%, transparent); }
.ch-quote:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.ch-msg.is-mine .ch-quote { border-left-color: var(--accent-ink); background: color-mix(in srgb, var(--accent-ink) 16%, transparent); }
.ch-msg.is-mine .ch-quote b { color: var(--accent-ink); }
.ch-msg.is-mine .ch-quote:hover { background: color-mix(in srgb, var(--accent-ink) 24%, transparent); }
.ch-bt { display: block; }
/* il messaggio citato, raggiunto dalla citazione */
.ch-msg.is-flash .ch-bw { animation: ch-flash 1.5s ease-out; }
@keyframes ch-flash { 0%, 35% { filter: brightness(1.35); transform: scale(1.02); } 100% { filter: none; transform: none; } }
@media (prefers-reduced-motion: reduce) { .ch-msg.is-flash .ch-bw { animation: none; outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 20px; } }
/* sul PC, passando sopra un fumetto: la frecciina per rispondere (accanto, dalla parte libera) */
.ch-qr {
  flex: none; align-self: center; display: grid; place-items: center; width: 30px; height: 30px; padding: 0;
  border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer; opacity: 0; transition: opacity .12s;
}
.ch-qr svg { width: 17px; height: 17px; }
.ch-msg.is-mine .ch-qr { order: -1; }
.ch-msg:hover .ch-qr, .ch-qr:focus-visible { opacity: 1; }
.ch-qr:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); color: var(--ink); }
@media (hover: none) { .ch-qr { display: none; } }
/* la barra «Rispondi a Silvia» sopra il campo (stessa forma di quella del video) */
.ch-rbar-in { cursor: default; }
.ch-rbar-in .ch-sbar-t { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.ch-rbar-in .ch-sbar-t svg { flex: none; width: 16px; height: 16px; }

/* «▶ 2:35»: il commento a un momento del video (⏱ in cima al messaggio, js/chat.js): toccandolo il video parte da lì */
.ch-ts {
  display: inline-flex; align-items: center; gap: 3px; max-width: 100%; margin: -2px 1px -2px -5px; padding: 2px 8px 2px 6px; vertical-align: 1px;
  border: 0; border-radius: 99px; background: color-mix(in srgb, var(--accent) 16%, var(--surface)); color: color-mix(in srgb, var(--accent) 80%, var(--ink));
  font: 700 13px/1.3 var(--f-body); font-variant-numeric: tabular-nums; white-space: nowrap; cursor: pointer;
}
.ch-ts svg { flex: none; width: 11px; height: 11px; }
/* «· video 2 del 19/10»: quale video, se non è l'ultimo mandato o se il suo messaggio ne ha più d'uno */
.ch-ts small { min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 12px; font-weight: 600; opacity: .85; }
.ch-ts:hover { background: color-mix(in srgb, var(--accent) 26%, var(--surface)); }
.ch-ts:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* nel mio fumetto (colore dell'app) il tasto prende il colore del testo */
.ch-msg.is-mine .ch-ts { background: color-mix(in srgb, var(--accent-ink) 20%, transparent); color: var(--accent-ink); }
.ch-msg.is-mine .ch-ts:hover { background: color-mix(in srgb, var(--accent-ink) 30%, transparent); }
.ch-msg.is-mine .ch-ts:focus-visible { outline-color: var(--accent-ink); }
.ch-msg:not(.is-mine):not(.is-first) .ch-bw > :first-child { border-top-left-radius: 6px; }
.ch-msg:not(.is-mine):not(.is-last) .ch-bw > :last-child { border-bottom-left-radius: 6px; }
.ch-msg.is-mine:not(.is-first) .ch-bw > :first-child { border-top-right-radius: 6px; }
.ch-msg.is-mine:not(.is-last) .ch-bw > :last-child { border-bottom-right-radius: 6px; }
.ch-msg .ch-b.ch-gone, .ch-msg.is-mine .ch-b.ch-gone {
  background: transparent; color: var(--muted); border: 1px dashed var(--line); font-style: italic; font-size: 13.5px;
}
.ch-msg.is-sending .ch-bw, .ch-msg.is-failed .ch-bw { opacity: .6; }
.ch-msg.is-menu .ch-bw { filter: brightness(.94); }

.ch-meta { margin: 3px 4px 0 40px; font-size: 11px; color: var(--muted); }
.ch-msg.is-mine .ch-meta { margin-left: 0; }
.ch-meta.is-err { color: var(--missed); font-weight: 600; }
.ch-retry { margin: -8px -4px; padding: 8px 4px; border: 0; background: none; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; }

/* menu del messaggio (tenendo premuto o col tasto destro) */
.ch-acts { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 6px 0 2px 36px; }
.ch-msg.is-mine .ch-acts { justify-content: flex-end; margin-left: 0; }
.ch-when { font-size: 12px; color: var(--muted); }
.ch-act {
  min-height: 34px; padding: 6px 13px; border: 1px solid var(--line); border-radius: 99px;
  background: var(--surface); color: var(--ink); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.ch-act { display: inline-flex; align-items: center; gap: 6px; }
.ch-act svg { flex: none; width: 15px; height: 15px; }
.ch-act.is-danger { color: var(--missed); }
.ch-act.is-armed { background: var(--missed); border-color: var(--missed); color: #fff; }

/* post condiviso */
.ch-post {
  display: flex; flex-direction: column; width: min(240px, 62vw); padding: 0; overflow: hidden;
  border: 1px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--ink);
  font: inherit; text-align: left; cursor: pointer;
}
.ch-phead { display: flex; align-items: center; gap: 8px; min-width: 0; min-height: 40px; padding: 8px 10px; font-size: 13px; }
.ch-phead b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-pthumb { position: relative; display: block; aspect-ratio: 1 / 1; overflow: hidden; background: var(--surface-2); }
.ch-pthumb img, .ch-pthumb video { display: block; width: 100%; height: 100%; object-fit: cover; }
.ch-pthumb.is-wk { aspect-ratio: auto; padding: 4px 10px 10px; background: transparent; }
.ch-play { position: absolute; top: 8px; right: 8px; width: 22px; height: 22px; color: #fff; filter: drop-shadow(0 1px 2px rgb(0 0 0 / .55)); }
.ch-play svg { width: 100%; height: 100%; }
.ch-pcap {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
  padding: 8px 10px 10px; font-size: 13px; line-height: 1.35; overflow-wrap: anywhere;
}
.ch-pwk {
  display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 0 8px; padding: 8px 10px;
  border-radius: 12px; background: color-mix(in srgb, var(--c) 10%, var(--surface)); border-left: 3px solid var(--c);
}
.ch-pwi { grid-row: span 2; display: grid; place-items: center; color: var(--c); }
.ch-pwi svg { width: 22px; height: 22px; }
.ch-pwk b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; }
.ch-pwk small { color: var(--muted); font-size: 12px; }
.ch-post.is-wait { cursor: default; }
.ch-post.is-wait .ch-phead i { display: block; width: 60%; height: 10px; border-radius: 99px; background: var(--surface-2); }
.ch-post.is-wait .ch-pthumb { animation: ch-wait 1.2s ease-in-out infinite alternate; }
@keyframes ch-wait { to { opacity: .45; } }

/* foto e video nel messaggio: uno solo con le sue proporzioni (style in chat.js), di più in griglia */
.ch-media {
  position: relative; display: grid; grid-template-columns: 1fr 1fr; gap: 2px; width: min(250px, 64vw);
  overflow: hidden; border-radius: 18px; background: var(--surface-2);
}
.ch-media.n-1 { grid-template-columns: 1fr; }
.ch-media.n-3 > .ch-mi:first-child { grid-column: 1 / -1; aspect-ratio: 2 / 1; }
.ch-mi {
  position: relative; display: block; min-width: 0; aspect-ratio: 1 / 1; margin: 0; padding: 0; overflow: hidden;
  border: 0; border-radius: 0; background: var(--surface-2); color: inherit; font: inherit; cursor: zoom-in;
}
.ch-media.n-1 .ch-mi { aspect-ratio: 4 / 5; max-height: 340px; }
.ch-mi img, .ch-mi video { display: block; width: 100%; height: 100%; object-fit: cover; }
.ch-media.n-1 .ch-mi.is-vid video { object-fit: contain; }
.ch-mi.is-vid, .ch-media.is-local .ch-mi { cursor: default; }
.ch-mi:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
/* in invio: le anteprime più chiare, l'avanzamento ben leggibile sopra */
.ch-msg.is-sending .ch-bw:has(> .ch-media), .ch-msg.is-failed .ch-bw:has(> .ch-media) { opacity: 1; }
.ch-msg.is-sending .ch-media .ch-mi, .ch-msg.is-failed .ch-media .ch-mi { opacity: .55; }
.ch-mprog {
  position: absolute; left: 50%; top: 50%; z-index: 1; transform: translate(-50%, -50%);
  max-width: calc(100% - 16px); padding: 6px 12px; overflow: hidden; border-radius: 99px;
  background: color-mix(in srgb, var(--surface) 92%, transparent); color: var(--ink); box-shadow: var(--shadow);
  font-size: 12.5px; font-weight: 700; white-space: nowrap; text-overflow: ellipsis; font-variant-numeric: tabular-nums;
}
/* PC e telefono (finestre e lettore dei video, js/media-win.js): il video nel fumetto è un'anteprima ferma, primo
   fotogramma, ▶ e durata; toccandolo si apre nella sua finestra (PC) o nel lettore del telefono */
.ch-mi.is-vid.ch-poster { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.ch-poster video { pointer-events: none; }
.ch-vplay {
  position: absolute; left: 50%; top: 50%; display: grid; place-items: center; width: 46px; height: 46px; margin: -23px 0 0 -23px;
  border-radius: 50%; background: color-mix(in srgb, var(--ink) 58%, transparent); color: var(--surface); pointer-events: none;
  transition: transform .15s ease, background-color .15s ease;
}
.ch-vplay svg { width: 22px; height: 22px; margin-left: 3px; }
/* col mouse si accende passandoci sopra; col dito solo mentre lo si tocca (sul telefono resterebbe acceso) */
@media (hover: hover) { .ch-poster:hover .ch-vplay { transform: scale(1.08); background: var(--accent); color: var(--accent-ink); } }
@media (hover: none) { .ch-poster:active .ch-vplay { transform: scale(.94); background: var(--accent); color: var(--accent-ink); } }
@media (max-width: 820px) {
  .ch-vplay { width: 52px; height: 52px; margin: -26px 0 0 -26px; }
  .ch-vplay svg { width: 24px; height: 24px; }
}
.ch-vdur {
  position: absolute; right: 7px; bottom: 7px; padding: 1px 6px; border-radius: 6px; pointer-events: none;
  background: color-mix(in srgb, var(--ink) 62%, transparent); color: var(--surface);
  font-size: 11.5px; font-weight: 700; line-height: 1.45; font-variant-numeric: tabular-nums;
}
.ch-vdur[hidden] { display: none; }
@media (prefers-reduced-motion: reduce) { .ch-vplay { transition: none; } }

/* da 2 a 4 foto (e le foto del check sulla scrivania del coach): una pila in prospettiva (R.photoStackHTML in js/chat.js).
   Le foto vanno indietro verso destra, ognuna un po' girata; quelle dietro si vedono di lato.
   --s: quanto è aperta (1 = del tutto), --o: da che parte sta quando è chiusa (0 sinistra, 1 destra),
   --ry: quanto è girata ogni foto, --dz: quanto va indietro ognuna. Col dito è sempre aperta: si tocca la foto giusta */
.ch-stack {
  --cw: 62%; --s: 1; --o: 0; --ry: 10deg; --dz: -18px;
  position: relative; display: block; flex: none; width: min(250px, 64vw); aspect-ratio: 5 / 4;
  perspective: 640px; perspective-origin: 100% 50%;
}
.ch-stack.n-3 { --cw: 56%; }
.ch-stack.n-4 { --cw: 52%; }
.ch-msg.is-mine .ch-stack { --o: 1; } /* le mie a destra, come i fumetti */
.ch-stack-card {
  position: absolute; top: 5%; z-index: calc(var(--n) - var(--i)); width: var(--cw); height: 90%; margin: 0; padding: 0;
  left: calc((100% - var(--cw)) * ((1 - var(--s)) * var(--o) + var(--i) / (var(--n) - 1) * var(--s)));
  overflow: hidden; border: 2px solid var(--surface); border-radius: 12px; background: var(--surface-2); box-shadow: var(--shadow);
  color: inherit; font: inherit; cursor: zoom-in; -webkit-tap-highlight-color: transparent;
  transform-origin: 0 50%; transform: translateZ(calc(var(--i) * var(--dz))) rotateY(var(--ry));
  transition: left .26s cubic-bezier(.2, .8, .2, 1), transform .26s cubic-bezier(.2, .8, .2, 1);
}
/* una foto sola (il check con una foto): una carta girata, dalla parte di --o */
.ch-stack.n-1 { --cw: 68%; }
.ch-stack.n-1 .ch-stack-card { left: calc((100% - var(--cw)) * var(--o)); }
.ch-stack-card img { display: block; width: 100%; height: 100%; object-fit: cover; -webkit-user-drag: none; -webkit-user-select: none; user-select: none; }
.ch-stack-card:focus-visible { z-index: 9; outline: 2px solid var(--accent); outline-offset: 2px; }
/* il nome della foto (Fronte, Lato, Dietro): in basso a destra, la parte che si vede anche delle foto dietro */
.ch-stack-tag {
  position: absolute; right: 5px; bottom: 5px; padding: 2px 6px; border-radius: 6px; pointer-events: none;
  background: color-mix(in srgb, var(--ink) 62%, transparent); color: var(--surface); font-size: 10.5px; font-weight: 700; line-height: 1.2;
}
/* quante sono: sulla foto davanti, in alto a sinistra */
.ch-stack-n {
  position: absolute; top: calc(5% + 7px); left: calc((100% - var(--cw)) * (1 - var(--s)) * var(--o) + 7px); z-index: 10;
  display: inline-flex; align-items: center; gap: 3px; padding: 2px 7px 2px 5px; border-radius: 99px; pointer-events: none;
  background: color-mix(in srgb, var(--ink) 62%, transparent); color: var(--surface);
  font-size: 11.5px; font-weight: 700; line-height: 1.3; font-variant-numeric: tabular-nums;
  transition: left .26s cubic-bezier(.2, .8, .2, 1);
}
.ch-stack-n svg { width: 13px; height: 13px; }
/* PC: chiusa e più girata; passandoci sopra (o col tasto Tab) si apre e la foto sotto il mouse viene davanti */
@media (hover: hover) and (pointer: fine) {
  .ch-stack { --s: .62; --ry: 18deg; --dz: -26px; }
  .ch-stack:hover, .ch-stack:focus-within { --s: 1; --ry: 8deg; --dz: -16px; }
  .ch-stack-card:hover { z-index: 9; }
}
@media (pointer: coarse) {
  .ch-stack { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
}
@media (prefers-reduced-motion: reduce) {
  .ch-stack-card, .ch-stack-n { transition: none; }
}

/* arrivati messaggi mentre si leggono quelli vecchi */
.ch-newpill {
  position: absolute; left: 50%; bottom: 10px; z-index: 2; transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 4px; min-height: 36px; padding: 6px 14px 6px 10px;
  border: 0; border-radius: 99px; background: var(--ink); color: var(--bg); box-shadow: var(--shadow);
  font: inherit; font-size: 13px; font-weight: 600; white-space: nowrap; cursor: pointer;
}
.ch-newpill svg { width: 16px; height: 16px; }

/* ---------- campo per scrivere: sempre in fondo, sopra la barra e la tastiera ---------- */
.ch-comp {
  flex: none; display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--surface); border-top: 1px solid var(--line);
}
.ch-comp textarea {
  flex: 1 1 auto; width: auto; min-width: 0; height: 44px; min-height: 44px; max-height: calc(5 * 1.4em + 22px);
  padding: 10px 16px; border: 1px solid var(--line); border-radius: 22px; background: var(--surface-2); color: var(--ink);
  font-size: 16px; line-height: 1.4; resize: none; overflow-y: auto;
}
.ch-comp textarea:focus, .ch-scomp input:focus, .ch-fld input:focus { border-color: var(--accent); outline: 2px solid color-mix(in srgb, var(--accent) 30%, transparent); outline-offset: 0; }
.ch-send {
  flex: none; min-height: 44px; padding: 0 8px; border: 0; background: transparent;
  color: var(--accent); font: inherit; font-size: 15px; font-weight: 700; cursor: pointer;
}
.ch-send:disabled { color: var(--muted); opacity: .55; cursor: default; }
/* ---------- vocali (js/voice.js, js/chat.js) ---------- */
/* il microfono al posto di «Invia» col campo vuoto: tondo, del colore dell'app; tenendolo premuto si registra */
.ch-mic {
  flex: none; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); cursor: pointer; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
.ch-mic[hidden] { display: none; }
.ch-mic svg { width: 22px; height: 22px; }
.ch-mic:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* mentre si registra: al posto del campo la barra (cestino, pallino rosso, tempo, volume, invio) */
.ch-comp.is-rec .ch-addm, .ch-comp.is-rec textarea { display: none; }
.ch-rec { flex: 1 1 auto; display: flex; align-items: center; gap: 10px; min-width: 0; height: 44px; padding: 0 4px 0 2px; }
.ch-rec[hidden] { display: none; }
.ch-rec-x, .ch-rec-go {
  flex: none; display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%; cursor: pointer;
}
.ch-rec-x { background: transparent; color: var(--muted); }
.ch-rec-x:hover { color: var(--missed); background: color-mix(in srgb, var(--missed) 10%, transparent); }
.ch-rec-go { background: var(--accent); color: var(--accent-ink); }
.ch-rec-x svg { width: 22px; height: 22px; }
.ch-rec-go svg { width: 19px; height: 19px; margin-left: 2px; }
.ch-rec-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--missed); animation: ch-rec-blink 1s ease-in-out infinite; }
@keyframes ch-rec-blink { 50% { opacity: .25; } }
.ch-rec-t { flex: none; min-width: 2.6em; font: 700 16px/1 var(--f-body); font-variant-numeric: tabular-nums; }
.ch-rec-lv { flex: 1 1 auto; display: flex; align-items: center; justify-content: flex-end; gap: 2px; min-width: 0; height: 28px; overflow: hidden; }
.ch-rec-lv i { flex: none; width: 3px; height: calc(4px + var(--v) * 24px); border-radius: 2px; background: color-mix(in srgb, var(--ink) 55%, transparent); }
/* tenendo premuto: niente cestino né invio (si lascia per mandarlo); la barra scivola col dito verso sinistra */
.ch-comp.is-hold .ch-rec-x, .ch-comp.is-hold .ch-rec-go { display: none; }
.ch-comp.is-hold .ch-rec { transform: translateX(var(--slide, 0px)); opacity: calc(1 + var(--slide, 0px) / 120px); }
.ch-comp.is-rec:not(.is-hold) .ch-mic { display: none; }
.ch-comp.is-hold .ch-mic { transform: scale(1.18); background: var(--missed); color: #fff; box-shadow: 0 0 0 8px color-mix(in srgb, var(--missed) 20%, transparent); }
@media (prefers-reduced-motion: reduce) { .ch-rec-dot { animation: none; } }

/* il fumetto del vocale: ▶, le barrette (si colorano mentre va; toccandole si salta lì), il tempo e la velocità */
.ch-voice {
  display: flex; align-items: center; gap: 10px; width: min(300px, 70vw); padding: 8px 10px 8px 8px; border-radius: 20px;
  background: color-mix(in srgb, var(--ink) 8%, var(--surface)); color: var(--ink);
}
.ch-msg.is-mine .ch-voice { background: var(--accent); color: var(--accent-ink); }
.ch-vbtn {
  flex: none; display: grid; place-items: center; width: 38px; height: 38px; padding: 0; border: 0; border-radius: 50%;
  background: color-mix(in srgb, currentColor 14%, transparent); color: inherit; cursor: pointer;
}
.ch-vbtn svg { width: 18px; height: 18px; }
.ch-vbtn:focus-visible, .ch-vspd:focus-visible { outline: 2px solid currentColor; outline-offset: 1px; }
.ch-vwave { flex: 1 1 auto; display: flex; align-items: center; gap: 2px; min-width: 0; height: 30px; cursor: pointer; }
.ch-vwave i { flex: 1 1 0; min-width: 2px; max-width: 4px; height: calc(4px + var(--v) * 2.6px); border-radius: 2px; background: currentColor; opacity: .38; transition: opacity .1s; }
.ch-vwave i.is-done { opacity: 1; }
.ch-vside { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.ch-vtime { font: 600 12px/1 var(--f-body); font-variant-numeric: tabular-nums; opacity: .85; }
.ch-vspd {
  min-width: 34px; padding: 2px 6px; border: 0; border-radius: 99px; background: color-mix(in srgb, currentColor 14%, transparent);
  color: inherit; font: 700 11px/1.2 var(--f-body); cursor: pointer;
}
/* mentre parte: l'avanzamento sotto il fumetto */
.ch-vlocal { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.ch-vlocal .ch-mprog { position: static; transform: none; }

/* foto e video: a sinistra del campo (c'è solo con supabase/chat_media.sql eseguito) */
.ch-addm {
  flex: none; display: grid; place-items: center; width: 40px; height: 44px; margin-right: -4px;
  border-radius: 12px; color: var(--accent); cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.ch-addm svg { width: 26px; height: 26px; }
.ch-addm:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.ch-addm:active { background: color-mix(in srgb, var(--ink) 10%, transparent); }
.ch-comp:has(#chFile:focus-visible) .ch-addm { outline: 2px solid var(--accent); outline-offset: 1px; }

/* commento a un momento del video (telefono, Chat.stampBar in js/chat.js): come «rispondi» su WhatsApp, subito sopra
   il campo. Striscia del colore dell'app a sinistra, «⏱ 0:07» e di chi è il video, la miniatura, la ✕ */
.ch-sbar {
  flex: none; display: flex; align-items: center; gap: 2px; padding: 8px 4px 0 12px;
  background: var(--surface); border-top: 1px solid var(--line); animation: ch-sbar-in .16s ease-out;
}
.ch-sbar[hidden] { display: none; }
.ch-sbar:not([hidden]) + .ch-comp { padding-top: 6px; border-top: 0; }
@keyframes ch-sbar-in { from { opacity: 0; transform: translateY(6px); } }
.ch-sbar-in {
  flex: 1 1 auto; display: flex; align-items: center; gap: 10px; min-width: 0; min-height: 52px; padding: 6px 6px 6px 12px;
  border-left: 4px solid var(--accent); border-radius: 10px; background: color-mix(in srgb, var(--accent) 9%, var(--surface-2));
  cursor: text; -webkit-tap-highlight-color: transparent;
}
.ch-sbar-tx { flex: 1 1 auto; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.ch-sbar-t { font: 700 15px/1.25 var(--f-body); font-variant-numeric: tabular-nums; color: color-mix(in srgb, var(--accent) 82%, var(--ink)); }
.ch-sbar-w { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--muted); }
.ch-sbar-th { position: relative; flex: none; width: 40px; height: 40px; overflow: hidden; border-radius: 8px; background: var(--surface-2); }
.ch-sbar-th video { display: block; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.ch-sbar-pl {
  position: absolute; left: 50%; top: 50%; display: grid; place-items: center; width: 22px; height: 22px; margin: -11px 0 0 -11px;
  border-radius: 50%; background: color-mix(in srgb, var(--ink) 58%, transparent); color: var(--surface);
}
.ch-sbar-pl svg { width: 12px; height: 12px; margin-left: 2px; }
.ch-sbar-x { width: 44px; height: 44px; border-radius: 50%; color: var(--muted); }
.ch-sbar-x svg { width: 20px; height: 20px; }
@media (prefers-reduced-motion: reduce) { .ch-sbar { animation: none; } }

/* condividi: messaggio e «Invia» in fondo */
.ch-scomp { flex-direction: column; align-items: stretch; }
.ch-scomp input {
  width: 100%; height: 44px; padding: 0 16px; border: 1px solid var(--line); border-radius: 22px;
  background: var(--surface-2); color: var(--ink); font-size: 16px;
}
.ch-scomp .btn { justify-content: center; min-height: 44px; font-size: 15px; }
.ch-scomp .btn:disabled { opacity: .5; cursor: default; }
/* il testo che parte (il link di una scheda): al massimo 3 righe, il link lungo va a capo */
.ch-sbody {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden;
  margin: 0; padding: 8px 12px; border-left: 3px solid var(--accent); border-radius: 8px;
  background: var(--surface-2); color: var(--muted); font-size: 13px; line-height: 1.4; white-space: pre-line; overflow-wrap: anywhere;
}

/* ---------- nuovo messaggio, nuovo gruppo, aggiungi persone, condividi ---------- */
.ch-pick, .ch-share { padding-top: 12px; }
.ch-seg { display: flex; width: 100%; max-width: 420px; margin-bottom: 10px; }
.ch-seg button { flex: 1 1 0; min-height: 36px; }
.ch-fld { display: flex; flex-direction: column; gap: 4px; min-width: 0; margin-bottom: 10px; }
.ch-fld > span:not(.vh) { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.ch-fld input {
  width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink); font-size: 16px;
}
.ch-search {
  display: flex; align-items: center; gap: 8px; padding: 0 12px; border-radius: 12px;
  background: color-mix(in srgb, var(--ink) 7%, transparent); color: var(--muted);
}
.ch-search:focus-within { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); }
.ch-search svg { width: 18px; height: 18px; flex: none; }
.ch-search input { flex: 1 1 auto; min-width: 0; height: 42px; padding: 0; border: 0; background: transparent; color: var(--ink); font-size: 16px; outline: none; }
.ch-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.ch-chips:empty { display: none; }
.ch-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-height: 34px; padding: 3px 10px 3px 4px;
  border: 0; border-radius: 99px; background: color-mix(in srgb, var(--accent) 14%, var(--surface)); color: var(--ink);
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.ch-chip > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-chip > svg { flex: none; width: 14px; height: 14px; color: var(--muted); }
.ch-person { min-height: 62px; padding: 8px 20px; }
.ch-person:disabled { cursor: default; opacity: .55; }
.ch-pt { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.ch-pt b { display: flex; align-items: center; gap: 4px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14.5px; font-weight: 600; }
.ch-pt b em { font-style: normal; font-weight: 400; color: var(--muted); }
.ch-pt small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--muted); }
.ch-tick {
  flex: none; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--line); color: transparent;
}
.ch-tick svg { width: 14px; height: 14px; }
.ch-person.is-on .ch-tick { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ---------- dettagli del gruppo ---------- */
.ch-iback { margin-left: -8px; color: var(--ink); }
.ch-info { padding-top: 16px; }
.ch-ihero { display: flex; flex-direction: column; align-items: center; gap: 4px; padding-bottom: 6px; text-align: center; }
.ch-ihero > b { margin-top: 6px; font-size: 18px; overflow-wrap: anywhere; }
.ch-ihero > small { color: var(--muted); }
.ch-rename { display: flex; align-items: flex-end; gap: 8px; max-width: 560px; margin-top: 12px; }
.ch-rename .ch-fld { flex: 1 1 auto; margin-bottom: 0; }
.ch-rename .btn { min-height: 44px; }
.ch-addi {
  display: grid; place-items: center; flex: none; width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--line); color: var(--ink);
}
.ch-addi svg { width: 20px; height: 20px; }
.ch-leave { margin-top: 18px; color: var(--missed); }
.ch-leave:hover { color: var(--missed); }

/* ---------- telefono ---------- */
@media (max-width: 820px) {
  .ch-rows, .ch-people { margin-inline: -14px; }
  .ch-row, .ch-person { padding-inline: 14px; }
  .ch-list { padding-inline: 12px; }
  .ch-line { max-width: 88%; }
  .ch-msg.is-mine .ch-line { max-width: 82%; }
  /* sopra la barra in basso il bordo dello schermo è già lasciato dalla barra */
  dialog.sheet:not(:modal) .ch-comp { padding-bottom: 10px; }
  body.is-typing dialog.sheet:not(:modal) .ch-comp { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  /* tastiera aperta: la pagina finisce sopra i tasti, niente margine in più */
  body.is-typing dialog.sheet.is-kb:not(:modal) .ch-comp, dialog.sheet.is-kb:not(:modal) .ch-comp { padding-bottom: 8px; }
  .ch-comp { padding-inline: 10px; }
  .ch-sbar { padding-left: 10px; }
  /* il video agganciato in cima alla chat (js/media-win.js) copre l'inizio dell'elenco: --mw-top-h è la sua altezza,
     i messaggi cominciano sotto e scorrendo restano leggibili (js/chat.js, watchList, tiene in fondo chi era in fondo) */
  #chatDlg .ch-list { padding-top: calc(8px + var(--mw-top-h, 0px)); scroll-padding-top: var(--mw-top-h, 0px); }
}
/* col dito: tenendo premuto un messaggio si apre il menu, non la selezione del testo */
@media (pointer: coarse) {
  .ch-b, .ch-post, .ch-media { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
}

/* ---------- foto e video a tutto schermo (sopra tutto, anche sopra la barra in basso) ---------- */
.ch-view {
  position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 0;
  border: 0; overflow: hidden; overscroll-behavior: contain; color: var(--ink); background: transparent;
}
/* lo sfondo: trascinando in giù sfuma (--vfade da chat.js) */
.ch-view::before { content: ""; position: absolute; inset: 0; background: var(--bg); opacity: var(--vfade, 1); }
.ch-view::backdrop { background: transparent; }
.ch-view[open] { display: block; animation: ch-vin .16s ease-out; }
@keyframes ch-vin { from { opacity: 0; } }
.ch-vbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between;
  padding: calc(6px + env(safe-area-inset-top, 0px)) max(8px, env(safe-area-inset-right, 0px)) 6px max(16px, env(safe-area-inset-left, 0px));
  pointer-events: none;
}
.ch-vbar > * { pointer-events: auto; }
.ch-vcount { font-size: 14px; font-weight: 700; color: var(--muted); }
.ch-vclose { width: 44px; height: 44px; border-radius: 50%; color: var(--ink); background: color-mix(in srgb, var(--surface) 75%, transparent); }
.ch-vclose svg { width: 22px; height: 22px; }
.ch-vtrack { position: relative; display: flex; height: 100%; touch-action: none; transition: transform .26s cubic-bezier(.2, .8, .2, 1); }
.ch-vtrack.is-drag { transition: none; }
.ch-vslide {
  flex: 0 0 100%; min-width: 0; height: 100%; display: grid; place-items: center;
  padding: calc(56px + env(safe-area-inset-top, 0px)) 0 calc(16px + env(safe-area-inset-bottom, 0px));
}
.ch-vtrack:not(.is-drag) .ch-vslide { transition: transform .2s ease-out; }
.ch-vslide img, .ch-vslide video {
  display: block; width: 100%; height: 100%; min-height: 0; object-fit: contain; -webkit-user-select: none; user-select: none;
}
.ch-vslide img { -webkit-user-drag: none; }
.ch-vnav {
  position: absolute; top: 50%; z-index: 2; display: grid; place-items: center; width: 44px; height: 44px; margin-top: -22px;
  border: 0; border-radius: 50%; background: color-mix(in srgb, var(--surface) 88%, transparent); color: var(--ink);
  box-shadow: var(--shadow); cursor: pointer;
}
.ch-vnav svg { width: 22px; height: 22px; }
.ch-vnav.is-prev { left: 12px; }
.ch-vnav.is-next { right: 12px; }
/* col dito si scorre: le frecce servono solo col mouse */
@media (hover: none) { .ch-vnav { display: none; } }
@media (prefers-reduced-motion: reduce) {
  .ch-view[open] { animation: none; }
  .ch-vtrack, .ch-vtrack:not(.is-drag) .ch-vslide { transition: none; }
}

/* foto ingrandita: come su Instagram (js/chat.js, zoomTo) */
.ch-vslide img { transform-origin: center center; will-change: transform; cursor: zoom-in; }
.ch-vslide img.is-anim { transition: transform .2s ease-out; }
.ch-vtrack.is-zoom .ch-vslide img { cursor: grab; }
.ch-vtrack.is-zoom .ch-vslide img:active { cursor: grabbing; }
@media (prefers-reduced-motion: reduce) { .ch-vslide img.is-anim { transition: none; } }

/* la chat accanto al calendario quando non vi siete ancora scritti: l'invito a scrivere */
.ch-start { align-items: center; justify-content: center; gap: 14px; padding: 24px; text-align: center; }
.ch-start p { margin: 0; color: var(--muted); font-size: 15px; }
