:root {
  --sfondo: #f6f7f9;
  --pannello: #ffffff;
  --laterale: #eef0f3;
  --testo: #15171c;
  --tenue: #5d6470;
  --bordo: #dfe2e7;
  --accento: #1f6f5c;
  --accento-testo: #ffffff;
  --mio: #1f6f5c;
  --mio-testo: #ffffff;
  --suo: #ffffff;
  --rosso: #b3261e;
  --ombra: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  --raggio: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --sfondo: #0f1115;
    --pannello: #161920;
    --laterale: #12151b;
    --testo: #e9ecf1;
    --tenue: #9aa3b0;
    --bordo: #262b35;
    --accento: #3fb495;
    --accento-testo: #07130f;
    --mio: #22735f;
    --mio-testo: #f1fbf8;
    --suo: #1b1f28;
    --rosso: #ff8a80;
    --ombra: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--sfondo); color: var(--testo);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }

/* ---------- accesso */
.accesso { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.scheda-accesso {
  width: 100%; max-width: 380px; background: var(--pannello); border: 1px solid var(--bordo);
  border-radius: 20px; padding: 28px 24px; box-shadow: var(--ombra); display: grid; gap: 14px;
}
.scheda-accesso label { display: grid; gap: 6px; font-size: 13px; color: var(--tenue); }
.scheda-accesso input {
  font-size: 16px; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--bordo);
  background: var(--sfondo); outline: none;
}
.scheda-accesso input:focus { border-color: var(--accento); }
.scheda-accesso button[type=submit] {
  margin-top: 6px; padding: 12px; border: 0; border-radius: 12px; background: var(--accento);
  color: var(--accento-testo); font-weight: 600; font-size: 16px;
}
.sottotitolo { margin: -6px 0 6px; color: var(--tenue); }
.errore { color: var(--rosso); min-height: 1.2em; margin: 0; font-size: 14px; }
.marchio { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.marchio img { width: 28px; height: 28px; }

/* ---------- impaginazione */
.app { display: flex; height: 100vh; height: 100dvh; }
.laterale {
  width: 290px; flex: none; background: var(--laterale); border-right: 1px solid var(--bordo);
  display: flex; flex-direction: column;
}
.laterale-testa { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px; }
.elenco-agenti { flex: 1; overflow-y: auto; padding: 6px 8px 12px; }
.voce-agente {
  width: 100%; display: flex; gap: 10px; align-items: center; text-align: left; border: 0;
  background: none; padding: 9px 10px; border-radius: 12px; margin-bottom: 2px;
}
.voce-agente:hover { background: color-mix(in srgb, var(--testo) 6%, transparent); }
.voce-agente.attiva { background: var(--pannello); box-shadow: var(--ombra); }
.voce-agente .ico { width: 34px; height: 34px; flex: none; display: grid; place-items: center; font-size: 18px;
  border-radius: 10px; background: color-mix(in srgb, var(--accento) 14%, transparent); }
.voce-agente .nomi { min-width: 0; flex: 1; }
.voce-agente .nome { font-weight: 600; display: flex; justify-content: space-between; gap: 6px; }
.voce-agente .ora { font-weight: 400; font-size: 12px; color: var(--tenue); }
.voce-agente .anteprima { font-size: 13px; color: var(--tenue); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.separatore { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--tenue); padding: 12px 10px 4px; }
.laterale-piede { border-top: 1px solid var(--bordo); padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; }
.chi-sono { color: var(--tenue); font-size: 14px; text-transform: capitalize; }

.principale { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--sfondo); }
.testa {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--bordo);
  background: color-mix(in srgb, var(--sfondo) 85%, transparent); backdrop-filter: blur(8px);
}
.testa-agente { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.testa-icona { font-size: 24px; }
.testa h1 { font-size: 17px; margin: 0; }
.testa p { margin: 0; font-size: 13px; color: var(--tenue); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.testa-agente > div { min-width: 0; }

.icona-btn {
  border: 0; background: none; width: 40px; height: 40px; border-radius: 12px; display: inline-grid;
  place-items: center; font-size: 19px; flex: none;
}
.icona-btn:hover { background: color-mix(in srgb, var(--testo) 7%, transparent); }
.testo-btn { border: 1px solid var(--bordo); background: var(--pannello); border-radius: 10px; padding: 6px 12px; font-size: 14px; }
.solo-mobile { display: none; }

/* ---------- messaggi */
.messaggi { flex: 1; overflow-y: auto; padding: 20px 20px 8px; scroll-behavior: smooth; }
.messaggi > * { max-width: 820px; margin-left: auto; margin-right: auto; }
.giorno { text-align: center; color: var(--tenue); font-size: 12px; margin: 18px auto 10px; }
.msg { display: flex; margin: 6px auto; }
.msg.mio { justify-content: flex-end; }
.bolla {
  max-width: min(680px, 86%); padding: 10px 14px; border-radius: var(--raggio); background: var(--suo);
  border: 1px solid var(--bordo); overflow-wrap: anywhere;
}
.msg.mio .bolla { background: var(--mio); color: var(--mio-testo); border-color: transparent; border-bottom-right-radius: 6px; }
.msg.suo .bolla { border-bottom-left-radius: 6px; }
.meta { font-size: 12px; color: var(--tenue); margin-bottom: 4px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.msg.mio .meta { color: color-mix(in srgb, var(--mio-testo) 75%, transparent); justify-content: flex-end; }
.etichetta { font-weight: 600; color: var(--accento); }
.msg.mio .etichetta { color: inherit; }
.via { font-size: 11px; border: 1px solid currentColor; border-radius: 6px; padding: 0 5px; opacity: .7; }
.corpo p { margin: 0 0 8px; } .corpo p:last-child { margin-bottom: 0; }
.corpo ul, .corpo ol { margin: 4px 0 8px; padding-left: 22px; }
.corpo code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
  background: color-mix(in srgb, var(--testo) 8%, transparent); padding: 1px 5px; border-radius: 5px; }
.corpo a { color: inherit; }
.corpo h3 { font-size: 15px; margin: 8px 0 4px; }
.file-lista { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin-top: 8px; }
.file {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px;
  background: color-mix(in srgb, var(--testo) 5%, transparent); border: 1px solid var(--bordo);
  text-decoration: none; color: inherit;
}
.msg.mio .file { border-color: color-mix(in srgb, var(--mio-testo) 25%, transparent); background: color-mix(in srgb, #000 12%, transparent); }
.file .tipo { font-size: 22px; }
.file .nome-file { display: block; flex: 1; min-width: 0; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file .peso { font-size: 12px; opacity: .7; }
.file .scarica { text-decoration: none; color: inherit; font-size: 13px; padding: 4px 8px; border-radius: 8px; border: 1px solid currentColor; opacity: .8; }
.anteprima-img { max-width: 100%; max-height: 320px; border-radius: 10px; display: block; margin-top: 8px; }
audio { width: 260px; max-width: 100%; display: block; margin-top: 4px; }
.vuoto { text-align: center; color: var(--tenue); margin-top: 18vh; }
.vuoto .grande { font-size: 40px; }

.scrive { display: flex; align-items: center; gap: 8px; color: var(--tenue); font-size: 13px; padding: 4px 20px 8px; max-width: 860px; margin: 0 auto; width: 100%; }
.puntini { display: inline-flex; gap: 3px; }
.puntini i { width: 6px; height: 6px; border-radius: 50%; background: var(--tenue); animation: rimbalzo 1.2s infinite; }
.puntini i:nth-child(2) { animation-delay: .15s; } .puntini i:nth-child(3) { animation-delay: .3s; }
@keyframes rimbalzo { 0%, 60%, 100% { opacity: .3; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }

/* ---------- compositore */
.compositore { padding: 8px 16px calc(14px + env(safe-area-inset-bottom)); }
.riga-compositore, .registrazione, .allegati {
  max-width: 820px; margin: 0 auto;
}
.riga-compositore {
  display: flex; align-items: flex-end; gap: 6px; background: var(--pannello); border: 1px solid var(--bordo);
  border-radius: 22px; padding: 6px; box-shadow: var(--ombra);
}
.riga-compositore textarea {
  flex: 1; border: 0; outline: none; resize: none; background: none; padding: 9px 6px; max-height: 40vh;
  font-size: 16px; line-height: 1.4;
}
.invia {
  border: 0; width: 40px; height: 40px; border-radius: 50%; background: var(--accento); color: var(--accento-testo);
  font-size: 17px; flex: none;
}
.invia:disabled { opacity: .4; cursor: default; }
.invia.piccolo { width: auto; border-radius: 12px; padding: 0 14px; font-size: 14px; height: 36px; }
.allegati { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--pannello); border: 1px solid var(--bordo);
  border-radius: 10px; padding: 4px 6px 4px 10px; font-size: 13px; max-width: 260px; }
.chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip button { border: 0; background: none; font-size: 14px; }
.registrazione { display: flex; align-items: center; gap: 12px; margin-top: 8px; padding: 8px 12px; background: var(--pannello);
  border: 1px solid var(--bordo); border-radius: 16px; }
.registrazione #durata { flex: 1; font-variant-numeric: tabular-nums; }
.rec { width: 10px; height: 10px; border-radius: 50%; background: var(--rosso); animation: rimbalzo 1s infinite; }

/* ---------- telefono */
@media (max-width: 760px) {
  .solo-mobile { display: inline-grid; }
  .laterale { position: fixed; inset: 0 auto 0 0; z-index: 20; width: min(86vw, 320px); transform: translateX(-100%);
    transition: transform .2s ease; box-shadow: var(--ombra); }
  .laterale.aperta { transform: none; }
  .velo { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 10; }
  .testa { padding: 10px 12px; }
  .messaggi { padding: 12px 12px 6px; }
  .bolla { max-width: 92%; }
  .compositore { padding: 6px 10px calc(10px + env(safe-area-inset-bottom)); }
  #ricomincia { display: none; }
}
