/* Modulo: frontend/css/app.css
 * Scopo: Stili del client web: variabili di colore e tipografia, struttura, componenti.
 * Elenco funzioni: N/A.
 * Versione: 1.1.0
 * Metadati: 2026-11-17, 2026-11-17
 */

/* HEY — stile della Fase 0.
   Identità: carta fredda, inchiostro blu notte, un solo colore di richiamo (il giallo
   della "chiamata") usato per il marchio e per ciò che ti sta chiamando: i non letti. */

@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("/fonts/atkinson-hyperlegible-next-latin-wght-normal.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304,
    U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("/fonts/atkinson-hyperlegible-next-latin-ext-wght-normal.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1D00-1DBF,
    U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --ground: #eaeef4;
  --surface: #ffffff;
  --ink: #15223b;
  --muted: #56667f;
  --line: #d2dae6;
  --call: #ffc83a;
  --call-ink: #241b00;
  --link: #2148c9;
  --danger: #a8201a;

  /* Toni degli avatar con le iniziali: testo bianco sopra, contrasto almeno 4.5:1. */
  --tone-1: #2b5d8a;
  --tone-2: #6f3c93;
  --tone-3: #2c6e52;
  --tone-4: #93451c;
  --tone-5: #5b5e1d;
  --tone-6: #8a2f4f;
  --tone-ink: #ffffff;

  color-scheme: light;
  --font: "Atkinson Hyperlegible Next", system-ui, -apple-system, "Segoe UI", sans-serif;
  --text-s: 0.8125rem;
  --text-m: 0.9375rem;
  --text-l: 1.125rem;
  --radius: 6px;
  --radius-l: 12px;
  --quick: 140ms ease-out; /* durata dei passaggi di stato: brevi, mai decorativi */
}

/* Tema scuro: segue il sistema, salvo scelta manuale in "Il tuo account" (data-theme). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ground: #0e1626;
    --surface: #162036;
    --ink: #e8edf6;
    --muted: #9aa8c0;
    --line: #2b3a56;
    --link: #93b2ff;
    --danger: #ff9389;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ground: #0e1626;
  --surface: #162036;
  --ink: #e8edf6;
  --muted: #9aa8c0;
  --line: #2b3a56;
  --link: #93b2ff;
  --danger: #ff9389;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--ground);
  color: var(--ink);
  font: 400 var(--text-m) / 1.5 var(--font);
}

#app {
  height: 100%;
}

h1,
h2,
p,
ul,
ol {
  margin: 0;
  padding: 0;
}

ul,
ol {
  list-style: none;
}

input,
textarea,
button {
  font: inherit;
  color: inherit;
}

input,
select,
textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: var(--ink);
}

button:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

/* ---- marchio: una chiamata, con la coda del fumetto ---- */

.wordmark {
  display: inline-block;
  align-self: flex-start;
  padding: 0.15em 0.5em 0.4em;
  background: var(--call);
  color: var(--call-ink);
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: 0.04em;
  line-height: 1.1;
  clip-path: polygon(0 0, 100% 0, 100% 78%, 34% 78%, 12% 100%, 14% 78%, 0 78%);
}

.wordmark-large {
  align-self: flex-start;
  font-size: clamp(2.6rem, 9vw, 3.6rem);
}

/* ---- bottoni ---- */

.button {
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
}

.button.primary {
  padding: 0.55rem 1rem;
  background: var(--ink);
  color: var(--ground);
  font-weight: 700;
}

.button.primary:disabled {
  opacity: 0.6;
  cursor: default;
}

.button.small {
  padding: 0.35rem 0.7rem;
  font-size: var(--text-s);
}

.button.text {
  padding: 0.2rem 0;
  background: none;
  color: var(--link);
  text-align: left;
}

.button.text:hover {
  text-decoration: underline;
}

.hint {
  color: var(--muted);
  font-size: var(--text-s);
  font-weight: 400;
}

.form-error {
  color: var(--danger);
  font-size: var(--text-s);
}

.form-error:empty {
  display: none;
}

/* ---- accesso ---- */

.auth {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1rem;
  min-height: 100%;
  max-width: 27rem;
  margin: 0 auto;
  padding: 2rem 1.25rem;
}

/* Il modulo d'accesso sta su un foglio: separato dal fondo, non sparso sulla pagina. */
.auth-form {
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  box-shadow: 0 8px 30px color-mix(in srgb, var(--ink) 8%, transparent);
}

.tagline {
  font-size: var(--text-l);
  margin-bottom: 1rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-weight: 700;
}

.auth-form input {
  font-weight: 400;
}

/* ---- struttura ---- */

.shell {
  display: grid;
  grid-template-columns: 15rem minmax(0, 1fr);
  height: 100%;
  height: 100dvh; /* sul telefono: l'altezza visibile, senza le barre del browser */
}

.rail {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem 0.75rem;
  overflow-y: auto;
}

.rail-title {
  margin-top: 0.75rem;
  padding: 0 0.5rem;
  color: var(--muted);
  font-size: var(--text-s);
  font-weight: 700;
}

.channel {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  min-height: 2.1rem;
  padding: 0.3rem 0.6rem;
  background: none;
  border: 0;
  border-radius: 8px;
  text-align: left;
  cursor: pointer;
  transition: background-color var(--quick);
}

.channel .hash {
  display: inline-flex;
  justify-content: center;
  width: 1.1rem;
}

/* Titolo di sezione della barra, con il "+" per creare a destra. */
.rail-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.6rem;
}

.rail-section .rail-title {
  margin-top: 0;
}

.rail-add {
  min-width: 1.75rem;
  height: 1.75rem;
}

.rail-nav {
  margin-top: 0.25rem;
}

.channel:hover {
  background: color-mix(in srgb, var(--ink) 8%, transparent);
}

.channel .hash {
  color: var(--muted);
}

.channel.current {
  background: var(--ink);
  color: var(--ground);
}

.channel.current .hash {
  color: inherit;
  opacity: 0.6;
}

/* Non letto: il canale ti sta chiamando. */
.channel.unread {
  font-weight: 800;
}

.channel.unread::after {
  content: "";
  align-self: center;
  width: 0.55rem;
  height: 0.55rem;
  margin-left: auto;
  background: var(--call);
  border-radius: 50%;
}

/* Canale silenziato: attenuato (colore, non opacità: il contrasto resta AA), niente
   pallino; le menzioni restano. */
.muted-channel {
  color: var(--muted);
}

.channel.muted-channel::after {
  display: none;
}

.presence {
  flex-shrink: 0;
  align-self: center;
  width: 0.55rem;
  height: 0.55rem;
  border: 1.5px solid var(--muted);
  border-radius: 50%;
}

.presence-active {
  background: var(--ink);
  border-color: var(--ink);
}

/* Sulla voce selezionata (fondo scuro) il pallino si inverte. */
.current .presence {
  border-color: var(--ground);
}

.current .presence-active {
  background: var(--ground);
}

.avatar {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 6px;
  color: var(--tone-ink);
  font-size: 0.7rem;
  font-weight: 800;
  align-self: center;
}

img.avatar {
  object-fit: cover;
  background: var(--ground);
}

.avatar-large {
  width: 4rem;
  height: 4rem;
  border-radius: 12px;
  font-size: 1.3rem;
}

.me {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.me-name {
  overflow: hidden;
  text-overflow: ellipsis;
}

.avatar-form {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.tone-1 { background: var(--tone-1); }
.tone-2 { background: var(--tone-2); }
.tone-3 { background: var(--tone-3); }
.tone-4 { background: var(--tone-4); }
.tone-5 { background: var(--tone-5); }
.tone-6 { background: var(--tone-6); }

.status-emoji {
  font-size: 0.9em;
}

.typing {
  min-height: 1.3rem;
  padding: 0 1.25rem;
  color: var(--muted);
  font-size: var(--text-s);
}

.emoji-input {
  width: 4.5rem;
}

/* Con il numero delle menzioni il pallino non serve. */
.channel.called::after {
  display: none;
}

.badge {
  margin-left: auto;
  padding: 0 0.45rem;
  background: var(--call);
  color: var(--call-ink);
  border-radius: 999px;
  font-size: var(--text-s);
  font-weight: 800;
}

.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.rail > .button.text {
  margin: 0.25rem 0.5rem;
}

.new-channel {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.25rem 0.5rem;
}

.row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.rail-foot {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  margin-top: auto;
  padding: 0.75rem 0.5rem 0;
  border-top: 1px solid var(--line);
}

.me {
  padding: 0;
  background: none;
  border: 0;
  font-weight: 700;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.me:hover {
  text-decoration: underline;
}

.main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-left: 1px solid var(--line);
}

.main-head {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1.25rem;
  border-bottom: 1px solid var(--line);
}

.title {
  flex: 1;
  min-width: 0;
}

.title h1 {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  font-size: var(--text-l);
  font-weight: 800;
}

.topic {
  color: var(--muted);
  font-size: var(--text-s);
}

.search {
  flex: 0 1 16rem;
}

/* Solo sul telefono (vedi sotto i 720 px). Doppia classe: la regola generica dei bottoni
   a icona viene dopo e altrimenti li mostrerebbe anche sul computer. */
.icon-button.rail-toggle,
.icon-button.search-toggle,
.backdrop {
  display: none;
}

.title h1 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status {
  padding: 0.4rem 1.25rem;
  background: var(--call);
  color: var(--call-ink);
  font-size: var(--text-s);
  font-weight: 700;
}

/* ---- messaggi ---- */

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.75rem 0.75rem 1rem;
}

/* Messaggio: colonna dell'avatar a sinistra, testo allineato a destra di questa. */
.message {
  display: grid;
  grid-template-columns: 2.25rem minmax(0, 1fr);
  column-gap: 0.7rem;
  margin-top: 0.55rem;
  padding: 0.3rem 0.6rem;
  border-radius: 8px;
  transition: background-color var(--quick);
}

.message.grouped {
  margin-top: 0;
  padding-top: 0.1rem;
  padding-bottom: 0.1rem;
}

.message-main {
  min-width: 0;
  max-width: 46rem;
}

.gutter .avatar {
  width: 2.25rem;
  height: 2.25rem;
  margin-top: 0.15rem;
  border-radius: 8px;
  font-size: 0.75rem;
}

.gutter-time {
  display: block;
  padding-top: 0.2rem;
  color: var(--muted);
  font-size: 0.6875rem;
  text-align: right;
  visibility: hidden;
}

.message:hover .gutter-time,
.message:focus-within .gutter-time {
  visibility: visible;
}

.message:hover,
.message:focus-within {
  background: color-mix(in srgb, var(--ink) 4%, transparent);
}

/* Freccia del menu del messaggio: in alto a destra, al passaggio del mouse o col fuoco. */
.actions {
  position: absolute;
  top: 0.2rem;
  right: 0.25rem;
  display: none;
}

.menu-button {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 2px 6px color-mix(in srgb, var(--ink) 12%, transparent);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.9rem;
  height: 1.9rem;
  padding: 0 0.35rem;
  background: none;
  border: 0;
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
}

.icon-button:hover,
.icon-button:focus-visible {
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  color: var(--ink);
}

.icon-button-on {
  color: var(--link);
}

.icon-button.confirm {
  color: var(--danger);
  font-size: var(--text-s);
  font-weight: 800;
}

.marks {
  display: flex;
  gap: 0.8rem;
}

.mark {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.mark .action-icon {
  width: 0.8rem;
  height: 0.8rem;
}

.action-icon {
  width: 1.05rem;
  height: 1.05rem;
}

.message:hover .actions,
.message:focus-within .actions {
  display: flex;
}

.muted {
  color: var(--muted);
  font-style: italic;
}

.replies {
  display: block;
  margin-top: 0.15rem;
  font-size: var(--text-s);
  font-weight: 700;
}

.edited {
  color: var(--muted);
  font-size: var(--text-s);
}

.small-text {
  color: var(--muted);
  font-size: var(--text-s);
}

.versions {
  margin: 0.3rem 0;
  padding-left: 0.75rem;
  border-left: 2px solid var(--line);
}

.edit-form {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.2rem;
}

.thread {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-left: 1px solid var(--line);
}

.wide {
  grid-template-columns: 15rem minmax(0, 1fr) minmax(20rem, 26rem);
}

.message.reply {
  margin-left: 1.25rem;
  padding-left: 0.75rem;
  border-left: 2px solid var(--line);
}

.meta {
  display: flex;
  flex-wrap: wrap; /* in colonne strette va a capo per intero, non a pezzi */
  align-items: baseline;
  gap: 0.6rem;
}

.author {
  font-weight: 800;
}

.meta time,
.where {
  color: var(--muted);
  font-size: var(--text-s);
}

.body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.body p,
.body blockquote,
.body pre,
.md-list {
  margin: 0.15rem 0;
}

.body blockquote {
  padding-left: 0.75rem;
  border-left: 3px solid var(--line);
  color: var(--muted);
}

.body code {
  padding: 0.05rem 0.3rem;
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  border-radius: 4px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.9em;
}

.body pre {
  padding: 0.6rem 0.75rem;
  overflow-x: auto;
  background: color-mix(in srgb, var(--ink) 6%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  white-space: pre;
}

.body pre code {
  padding: 0;
  background: none;
}

.md-list {
  padding-left: 1.4rem;
  list-style: disc;
  white-space: normal;
}

ol.md-list {
  list-style: decimal;
}

.body a {
  color: var(--link);
}

.composer,
.edit-form {
  position: relative;
}

.mention-popup {
  position: absolute;
  bottom: 100%;
  left: 1.25rem;
  z-index: 3;
  min-width: 16rem;
  max-width: calc(100% - 2.5rem);
  padding: 0.3rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px color-mix(in srgb, var(--ink) 18%, transparent);
}

.option {
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
}

.active {
  background: var(--ink);
  color: var(--surface);
}

.message {
  position: relative;
}

.reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin: 0.25rem 0;
}

.reaction {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.05rem 0.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}

.reaction-mine {
  background: color-mix(in srgb, var(--link) 12%, transparent);
  border-color: var(--link);
}

.reaction-count {
  font-size: var(--text-s);
  font-weight: 700;
}

.picker {
  position: absolute;
  left: 0;
  top: 100%;
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  width: 18rem;
  padding: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px color-mix(in srgb, var(--ink) 18%, transparent);
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  max-height: 12rem;
  overflow-y: auto;
}

.emoji {
  padding: 0.2rem;
  background: none;
  border: 0;
  border-radius: 4px;
  font-size: 1.25rem;
  cursor: pointer;
}

.emoji:hover,
.emoji:focus-visible {
  background: color-mix(in srgb, var(--ink) 10%, transparent);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 12vh;
  background: color-mix(in srgb, var(--ink) 35%, transparent);
}

.switcher {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: min(32rem, calc(100% - 2rem));
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px color-mix(in srgb, var(--ink) 25%, transparent);
}

.switcher-list {
  max-height: 22rem;
  overflow-y: auto;
}

.skip {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 9;
  padding: 0.5rem 0.8rem;
  background: var(--ink);
  color: var(--ground);
  border: 0;
  border-radius: var(--radius);
  transform: translateY(-200%);
}

.skip:focus {
  transform: none;
}

.message:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: -2px;
}

.keys {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.6rem 1.5rem;
  margin: 0;
}

.keys dd {
  margin: 0;
}

kbd {
  padding: 0.1rem 0.45rem;
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: 4px;
  font: 700 var(--text-s) var(--font);
}

/* ---- allegati ---- */

.tray {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.tray:empty {
  display: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  max-width: 20rem;
  margin-bottom: 0.4rem;
  padding: 0.2rem 0.3rem 0.2rem 0.6rem;
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: var(--text-s);
}

.chip-error {
  border-color: var(--danger);
  color: var(--danger);
}

.chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip progress {
  width: 4rem;
  accent-color: var(--link);
}

.attach {
  align-self: center;
  font-size: 1.2rem;
}

.dropping {
  outline: 3px dashed var(--link);
  outline-offset: -6px;
}

.files {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0.35rem 0;
}

.file-image {
  display: block;
  max-width: min(100%, 22rem);
}

.file-image img {
  display: block;
  max-width: 100%;
  max-height: 18rem;
  object-fit: contain;
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.file-media {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin: 0;
}

.file-media video {
  max-width: min(100%, 26rem);
  max-height: 18rem;
  border-radius: var(--radius);
}

.file-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 16rem;
  max-width: 26rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.file-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.2rem;
  height: 2.2rem;
  background: var(--ground);
  border-radius: 4px;
  font-size: var(--text-s);
  font-weight: 800;
}

.toast {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  z-index: 10;
  transform: translateX(-50%);
  padding: 0.6rem 1rem;
  background: var(--ink);
  color: var(--surface);
  border-radius: var(--radius);
}

.mention {
  padding: 0 0.2rem;
  border-radius: 4px;
  background: color-mix(in srgb, var(--link) 12%, transparent);
  color: var(--link);
  font-weight: 700;
}

.mention-me {
  background: var(--call);
  color: var(--call-ink);
}

.day {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.25rem 0 0.25rem;
  color: var(--muted);
  font-size: var(--text-s);
  font-weight: 700;
}

.day::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.new-line {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.75rem 0 0.25rem;
  font-size: var(--text-s);
  font-weight: 800;
}

.new-line span {
  padding: 0 0.5rem;
  background: var(--call);
  color: var(--call-ink);
  border-radius: 999px;
}

.new-line::after {
  content: "";
  flex: 1;
  height: 2px;
  background: var(--call);
}

.day:first-child,
.older + .day {
  margin-top: 0.25rem;
}

.empty {
  padding: 2rem 0;
  color: var(--muted);
}

/* ---- scrittura ---- */

.composer,
.join-bar {
  padding: 0.75rem 1.25rem 1rem;
  padding-bottom: max(1rem, env(safe-area-inset-bottom)); /* barra in basso dell'iPhone */
  border-top: 1px solid var(--line);
}

.join-bar {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
}

/* Campo di scrittura: un unico riquadro con graffetta e invio dentro. */
.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 0.25rem;
  padding: 0.3rem;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-l);
  transition: border-color var(--quick), box-shadow var(--quick);
}

.composer-box:focus-within {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--link) 15%, transparent);
}

.send-button {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  background: var(--ink);
  border: 0;
  border-radius: 50%;
  color: var(--ground);
  cursor: pointer;
  transition: transform var(--quick);
}

.send-button:active {
  transform: scale(0.92);
}

.composer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 1.4rem;
  padding: 0.2rem 0.4rem 0;
}

.composer-hint {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.75rem;
}

.join-bar {
  align-items: center;
  justify-content: space-between;
}

.composer textarea {
  align-self: center;
  max-height: 200px;
  padding: 0.45rem 0.4rem;
  overflow-y: hidden;
  background: none;
  border: 0;
  resize: none;
}

.composer textarea:focus-visible {
  outline: none; /* il fuoco lo mostra il riquadro intorno */
}

/* ---- ricerca ---- */

.results {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem 1.25rem;
}

.results-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.results-head h2 {
  font-size: var(--text-l);
  font-weight: 800;
}

.results .messages {
  padding: 0;
  overflow: visible;
}

.result-open {
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 0.5rem 0.6rem;
  margin-left: -0.6rem;
  background: none;
  border: 0;
  border-radius: var(--radius);
  text-align: left;
  cursor: pointer;
}

.result-open:hover {
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}

/* ---- pagine al posto della conversazione (inviti) ---- */

.page {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1.25rem 1.5rem 2.5rem;
}

.page > * {
  max-width: 44rem;
}

/* Ogni sezione della pagina si apre con una linea: si capisce dove finisce la precedente. */
.page-subtitle {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
  font-size: var(--text-l);
  font-weight: 800;
}

.invite-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-weight: 700;
}

.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-bottom: 0.55rem;
}

.checkbox {
  width: auto;
  margin: 0;
}

.invite-result {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.people-picker {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-width: 26rem;
}

.people-list {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  max-height: 16rem;
  overflow-y: auto;
}

.button.danger {
  color: var(--danger);
}

.icon {
  width: 0.85em;
  height: 0.85em;
  vertical-align: -0.05em;
}

.channel-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.copy {
  flex-shrink: 0;
  white-space: nowrap;
}

.invite-result:empty {
  display: none;
}

.item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--line);
}

.item-info {
  display: flex;
  flex-direction: column;
}

/* ---- schermi stretti: i canali diventano un pannello a scomparsa ---- */

/* ---- sotto i 1100 px la discussione prende il posto della conversazione ---- */

@media (max-width: 1100px) {
  .wide {
    grid-template-columns: 15rem minmax(0, 1fr);
  }

  .covered {
    display: none;
  }
}

@media (max-width: 720px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .wide {
    grid-template-columns: minmax(0, 1fr);
  }

  .rail {
    display: none;
    position: fixed;
    inset: 0 20% 0 0;
    z-index: 2;
    background: var(--ground);
    border-right: 1px solid var(--line);
  }

  .rail.open {
    display: flex;
  }

  .icon-button.rail-toggle,
  .icon-button.search-toggle {
    display: inline-flex;
  }

  .main-head {
    gap: 0.25rem;
    padding: 0.4rem 0.5rem;
  }

  .title {
    padding-left: 0.25rem;
  }

  .topic {
    display: none; /* resta nei dettagli: qui ruberebbe una riga a ogni schermata */
  }

  /* La ricerca è un'icona; toccata, il campo prende tutta la riga. */
  .search {
    display: none;
  }

  .searching .search {
    display: flex;
    flex: 1;
  }

  .searching .title,
  .main-head.searching .search-toggle,
  .searching .head-details {
    display: none;
  }

  /* Con i canali aperti, il resto dello schermo è velato e chiude la barra se toccato. */
  .rail.open ~ .backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1;
    border: 0;
    background: color-mix(in srgb, var(--ink) 30%, transparent);
  }

  .rail {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }

  /* Niente zoom automatico di iOS: i campi sotto i 16 px lo fanno scattare. */
  input,
  select,
  textarea {
    font-size: 16px;
  }

  .messages {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .composer,
  .join-bar {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .main {
    border-left: 0;
  }

  .search {
    flex-basis: 9rem;
  }
}

/* ---- schermi touch: niente passaggio del mouse, bersagli da dito ---- */

@media (hover: none) {
  /* Sul telefono la freccia compare sul messaggio toccato; la pressione lunga apre il menu. */
  .message:hover .actions {
    display: none;
  }

  .message:focus-within .actions {
    display: flex;
  }

  .icon-button {
    min-width: 2.75rem;
    height: 2.75rem;
  }

  .action-icon {
    width: 1.25rem;
    height: 1.25rem;
  }

  .reaction {
    min-height: 2.25rem;
  }

  .message {
    -webkit-touch-callout: none; /* la pressione lunga apre il menu di HEY, non quello di iOS */
  }
}

/* ---- menu del messaggio (A-18) ---- */

.menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
}

.menu-overlay-sheet {
  display: flex;
  align-items: flex-end;
  background: color-mix(in srgb, var(--ink) 35%, transparent);
}

.msg-menu {
  position: fixed;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 15rem;
  padding: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 30px color-mix(in srgb, var(--ink) 22%, transparent);
}

.msg-sheet {
  position: static;
  width: 100%;
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  border-radius: 16px 16px 0 0;
}

.quick {
  display: flex;
  justify-content: space-between;
  gap: 0.25rem;
  padding: 0.25rem;
  border-bottom: 1px solid var(--line);
}

.quick-emoji {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  background: var(--ground);
  border: 0;
  border-radius: 50%;
  font-size: 1.35rem;
  cursor: pointer;
}

.quick-more {
  color: var(--ink);
  font-size: 1.2rem;
  font-weight: 700;
}

.quick-emoji:hover,
.quick-emoji:focus-visible {
  background: color-mix(in srgb, var(--ink) 12%, transparent);
}

.menu-items {
  display: flex;
  flex-direction: column;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  width: 100%;
  min-height: 2.6rem;
  padding: 0.45rem 0.75rem;
  background: none;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.menu-item:hover,
.menu-item:focus-visible {
  background: color-mix(in srgb, var(--ink) 8%, transparent);
}

.menu-danger {
  margin-top: 0.25rem;
  border-top: 1px solid var(--line);
  border-radius: 0 0 8px 8px;
  color: var(--danger);
}

.menu-danger.confirm {
  font-weight: 800;
}

.msg-sheet .menu-item {
  min-height: 2.9rem;
}

/* ---- risposte con citazione ---- */

.quote,
.reply-bar {
  display: flex;
  gap: 0.15rem;
  max-width: 30rem;
  padding: 0.35rem 0.6rem;
  background: color-mix(in srgb, var(--link) 7%, transparent);
  border: 0;
  border-left: 3px solid var(--link);
  border-radius: 6px;
}

.quote {
  flex-direction: column;
  width: fit-content;
  max-width: min(100%, 30rem);
  margin: 0.2rem 0;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.quote-deleted {
  border-left-color: var(--line);
  font-style: italic;
}

.quote-author {
  color: var(--link);
  font-size: var(--text-s);
  font-weight: 800;
}

.quote-snippet {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  color: var(--muted);
  font-size: var(--text-s);
}

.reply-bar {
  align-items: center;
  justify-content: space-between;
  max-width: none;
  margin-bottom: 0.4rem;
}

.reply-bar-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.flash {
  animation: flash 1.6s ease-out;
}

@keyframes flash {
  from {
    background: color-mix(in srgb, var(--call) 45%, transparent);
  }
}

@media (prefers-reduced-motion: reduce) {
  .flash {
    animation: none;
    outline: 2px solid var(--call);
  }
}

.offscreen {
  position: fixed;
  left: -9999px;
}

/* ---- movimento: brevi passaggi di stato, mai decorativi ---- */

.icon-button,
.menu-item,
.quick-emoji,
.reaction,
.button {
  transition: background-color var(--quick), color var(--quick), transform var(--quick);
}

.quick-emoji:active,
.reaction:active {
  transform: scale(0.92);
}

/* Le animazioni solo per chi non ha chiesto movimento ridotto. */
@media (prefers-reduced-motion: no-preference) {
  .msg-menu,
  .picker,
  .mention-popup,
  .switcher {
    animation: pop 120ms ease-out;
  }

  .msg-sheet {
    animation: rise 180ms ease-out;
  }

  .menu-overlay-sheet,
  .overlay {
    animation: fade 160ms ease-out;
  }

  .toast {
    animation: toast-in 180ms ease-out;
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 0.75rem);
  }
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }
}

@keyframes rise {
  from {
    transform: translateY(100%);
  }
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

@media (max-width: 720px) and (prefers-reduced-motion: no-preference) {
  .rail.open {
    animation: slide-in 180ms ease-out;
  }
}

@media (hover: none) {
  .composer-hint {
    display: none; /* parla di tasti: sul telefono non c'è una tastiera fisica */
  }
}

@keyframes slide-in {
  from {
    transform: translateX(-100%);
  }
}

