* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
:root {
  --rosa: #e8577a;
  --rosa-scuro: #c93d62;
  --vetro: rgba(255, 255, 255, 0.72);
}
body {
  font-family: "Quicksand", -apple-system, system-ui, sans-serif;
  color: #2b2b2b;
  background: linear-gradient(160deg, #ffd6e0 0%, #fbe3f0 45%, #e9e0ff 100%);
  background-attachment: fixed;
}
.nascosto { display: none !important; }
button { font-family: inherit; }

/* ---------- Login ---------- */
#login { height: 100%; display: grid; place-items: center; padding: 24px; }
#form-login {
  width: 100%; max-width: 330px; display: flex; flex-direction: column; gap: 12px;
  background: var(--vetro); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  padding: 36px 26px; border-radius: 28px; text-align: center;
  box-shadow: 0 20px 50px rgba(232, 87, 122, 0.25); border: 1px solid rgba(255,255,255,.6);
}
.cuore { font-size: 46px; color: var(--rosa); animation: battito 1.6s ease-in-out infinite; }
@keyframes battito { 0%,100% { transform: scale(1); } 15% { transform: scale(1.15); } 30% { transform: scale(1); } 45% { transform: scale(1.1); } }
#form-login h1 { font-weight: 700; color: var(--rosa-scuro); margin-bottom: 6px; }
#form-login input {
  padding: 13px 16px; border: 1px solid rgba(232,87,122,.2); border-radius: 14px; font-size: 16px;
  font-family: inherit; background: rgba(255,255,255,.85); outline: none;
}
#form-login input:focus { border-color: var(--rosa); box-shadow: 0 0 0 3px rgba(232,87,122,.15); }
#form-login button[type=submit] {
  border: 0; background: linear-gradient(135deg, #f06b8d, var(--rosa-scuro)); color: #fff; font-size: 16px;
  font-weight: 700; border-radius: 14px; padding: 13px; cursor: pointer; box-shadow: 0 6px 16px rgba(232,87,122,.35);
}
#errore { color: #c0392b; min-height: 1em; font-size: 14px; }

/* ---------- Chat ---------- */
#chat { height: 100%; display: flex; flex-direction: column; position: relative; }

/* Sfondo: foto scelta (salvata solo su questo dispositivo) o sfumatura con cuoricini */
#sfondo-chat {
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(circle at 20% 20%, rgba(255,255,255,.5) 0 2px, transparent 3px) 0 0 / 60px 60px,
    linear-gradient(160deg, #ffd6e0 0%, #fbe3f0 45%, #e9e0ff 100%);
  background-size: 60px 60px, cover;
}
#sfondo-chat.con-foto { background-size: cover; background-position: center 30%; background-color: #f3c9a8; }
#sfondo-chat.con-foto::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,.18), rgba(0,0,0,.02) 35%, rgba(0,0,0,.25));
}

header {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: rgba(232, 87, 122, 0.82); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  color: #fff; box-shadow: 0 2px 12px rgba(0,0,0,.08); position: relative; z-index: 2;
}
header > div:first-child { display: flex; flex-direction: column; }
#titolo { font-size: 18px; font-weight: 700; }
#stato { opacity: .9; font-size: 12px; }
.azioni { display: flex; gap: 8px; }
.icona-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(255,255,255,.22); color: #fff; font-size: 17px; display: grid; place-items: center;
}
.icona-btn:active { transform: scale(.94); }

/* Menu per scegliere lo sfondo */
#menu-sfondo {
  position: absolute; top: calc(66px + env(safe-area-inset-top)); right: 12px; z-index: 5;
  display: flex; flex-direction: column; gap: 6px; padding: 10px; border-radius: 18px;
  background: var(--vetro); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 12px 30px rgba(0,0,0,.15);
}
#menu-sfondo button {
  border: 0; border-radius: 12px; padding: 11px 16px; font-size: 15px; font-weight: 600; text-align: left;
  background: rgba(255,255,255,.9); color: #333; cursor: pointer;
}
#menu-sfondo button.secondario { background: transparent; color: #888; text-align: center; }

#messaggi { flex: 1; overflow-y: auto; padding: 16px 12px; display: flex; flex-direction: column; gap: 6px; }
.avviso, .giorno {
  align-self: center; text-align: center; font-size: 12px; font-weight: 600; color: #8a5a66;
  background: rgba(255,255,255,.75); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  padding: 5px 12px; border-radius: 12px; max-width: 90%;
}
.avviso { margin-bottom: 8px; }
.giorno { margin: 8px 0; text-transform: capitalize; }

.msg {
  max-width: 78%; padding: 9px 13px 6px; border-radius: 20px; line-height: 1.38; font-size: 15.5px;
  white-space: pre-wrap; word-wrap: break-word; box-shadow: 0 2px 8px rgba(0,0,0,.08);
  animation: entra .22s ease-out;
}
@keyframes entra { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
.msg.suo {
  align-self: flex-start; background: rgba(255,255,255,.88); border-bottom-left-radius: 6px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.msg.mio {
  align-self: flex-end; color: #fff; border-bottom-right-radius: 6px;
  background: linear-gradient(135deg, #f37a98, var(--rosa-scuro));
}
.meta { display: block; text-align: right; font-size: 11px; color: #999; margin-top: 2px; }
.msg.mio .meta { color: rgba(255,255,255,.8); }
.meta .spunte.lette { color: var(--rosa); font-weight: 700; }
.msg.mio .meta .spunte.lette { color: #fff; }

#form-msg {
  display: flex; gap: 8px; padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.6); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid rgba(255,255,255,.5);
}
#testo {
  flex: 1; resize: none; border: 1px solid rgba(232,87,122,.15); border-radius: 22px; padding: 11px 16px;
  font: inherit; font-size: 16px; max-height: 120px; background: rgba(255,255,255,.95); outline: none;
}
#form-msg button {
  width: 46px; height: 46px; border-radius: 50%; padding: 0; align-self: flex-end; border: 0; cursor: pointer;
  background: linear-gradient(135deg, #f06b8d, var(--rosa-scuro)); color: #fff; font-size: 18px;
  box-shadow: 0 4px 12px rgba(232,87,122,.4);
}

/* Occhio per vedere la password */
.campo-pw { position: relative; display: flex; }
.campo-pw input { flex: 1; min-width: 0; width: 100%; padding-right: 48px !important; }
#mostra-pw {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; font-size: 18px; cursor: pointer; padding: 6px; opacity: .6;
}
#mostra-pw.attivo { opacity: 1; }
