/* ---------------------------------------------------------
   Foglio di stile della bacheca.
   Nessun font o immagine presi da internet: tutto locale,
   cosi la pagina funziona anche senza connessione esterna.
   --------------------------------------------------------- */

:root {
  --sfondo:        #f4f4f5;
  --carta:         #ffffff;
  --testo:         #1c1c1e;
  --testo-tenue:   #6b6b70;
  --bordo:         #e2e2e5;
  --accento:       #2f6fed;
}

/* Se il sistema e impostato su tema scuro, cambiano solo questi colori */
@media (prefers-color-scheme: dark) {
  :root {
    --sfondo:      #17171a;
    --carta:       #212125;
    --testo:       #f2f2f4;
    --testo-tenue: #9a9aa2;
    --bordo:       #34343a;
    --accento:     #6d9bff;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 2rem 1rem 4rem;
  background: var(--sfondo);
  color: var(--testo);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
}

.bacheca {
  max-width: 42rem;
  margin: 0 auto;
}

header {
  margin-bottom: 1.5rem;
}

h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: -0.02em;
}

.stato {
  margin: 0.3rem 0 0;
  font-size: 0.85rem;
  color: var(--testo-tenue);
}

/* --- Modulo di scrittura --- */

form {
  background: var(--carta);
  border: 1px solid var(--bordo);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin-bottom: 2rem;
}

input,
textarea {
  width: 100%;
  padding: 0.6rem 0.7rem;
  font: inherit;
  color: var(--testo);
  background: var(--sfondo);
  border: 1px solid var(--bordo);
  border-radius: 8px;
  resize: vertical;
}

input:focus,
textarea:focus {
  outline: 2px solid var(--accento);
  outline-offset: 1px;
}

.riga-invio {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

#contatore {
  font-size: 0.8rem;
  color: var(--testo-tenue);
  font-variant-numeric: tabular-nums;
}

button {
  padding: 0.55rem 1.4rem;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accento);
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

button:hover  { filter: brightness(1.08); }
button:active { transform: translateY(1px); }

/* --- Riga di avviso (errori, attese) --- */

.avviso {
  margin: 0 0 1.2rem;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  font-size: 0.9rem;
  border: 1px solid var(--bordo);
  background: var(--carta);
  color: var(--testo-tenue);
}

/* Avviso di errore: sfondo e bordo rossastri */
.avviso.errore {
  border-color: #e0a0a0;
  background: #fdeeee;
  color: #8a2f2f;
}

@media (prefers-color-scheme: dark) {
  .avviso.errore {
    border-color: #6b3535;
    background: #2b1c1c;
    color: #f0b4b4;
  }
}

/* --- Intestazione dell'elenco --- */

.riga-elenco {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.7rem;
}

.riga-elenco h2 {
  margin: 0;
  font-size: 1rem;
  color: var(--testo-tenue);
  font-weight: 600;
}

/* Spia del collegamento in tempo reale */

.spia {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--testo-tenue);
}

/* Il pallino colorato prima del testo */
.spia::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #b9b9c0;
}

.spia[data-attiva="si"]::before {
  background: #2fae62;
  box-shadow: 0 0 0 3px rgba(47, 174, 98, 0.18);
}

/* Pulsante secondario: stessa forma, aspetto piu discreto */
button.secondario {
  padding: 0.35rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--testo-tenue);
  background: var(--carta);
  border: 1px solid var(--bordo);
}

button.secondario:hover {
  color: var(--testo);
  filter: none;
}

button:disabled {
  opacity: 0.55;
  cursor: default;
}

button:disabled:active {
  transform: none;
}

/* --- Elenco dei messaggi --- */

.lista {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.messaggio {
  background: var(--carta);
  border: 1px solid var(--bordo);
  border-radius: 12px;
  padding: 0.8rem 1rem;
}

.messaggio .intestazione {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.25rem;
}

.messaggio .autore {
  font-weight: 600;
}

.messaggio .quando {
  font-size: 0.78rem;
  color: var(--testo-tenue);
  white-space: nowrap;
}

.messaggio .testo {
  margin: 0;
  white-space: pre-wrap;   /* mantiene gli a capo scritti dall'utente */
  overflow-wrap: anywhere; /* spezza le parole lunghissime */
}

.vuoto {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--testo-tenue);
  border: 1px dashed var(--bordo);
  border-radius: 12px;
}
