/* PWA famille (§6.2) — mobile, quatre onglets, même identité que le reste :
   vert pin, papier chaud, miel pour l'attention, brique pour raccrocher. */

:root {
  --paper: #F4F3EC;
  --card: #FFFFFF;
  --ink: #212B25;
  --ink-soft: #5A675F;
  --pine: #2E5B4F;
  --pine-dark: #234439;
  --sage: #E3EAE2;
  --honey: #C08A2A;
  --honey-soft: #F6EBD4;
  --brick: #A64435;
  --line: #D9DCD0;
  --nuit: #16261F;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(33,43,37,.06), 0 4px 14px rgba(33,43,37,.06);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: "Atkinson Hyperlegible", system-ui, sans-serif;
  font-size: 16px; line-height: 1.45; color: var(--ink);
  background: var(--paper);
}
h1, h2, h3 { font-family: "Bricolage Grotesque", sans-serif; margin: 0; }
button { font-family: inherit; font-size: 1rem; cursor: pointer; border: none; }
:focus-visible { outline: 3px solid var(--honey); outline-offset: 2px; }

#app { min-height: 100dvh; display: flex; flex-direction: column; }

/* ---------- entête & onglets ---------- */

.entete {
  position: sticky; top: 0; z-index: 20;
  background: var(--pine); color: #F6F4EE;
  padding: .8rem 1rem; display: flex; align-items: center; gap: .75rem;
}
.entete .titre { font-family: "Bricolage Grotesque", sans-serif; font-weight: 700; font-size: 1.1rem; flex: 1; }
/* logo de l'établissement — la hauteur mène, un bandeau large reste entier */
.entete .logo-residence { height: 30px; max-width: 96px; object-fit: contain; flex: 0 0 auto; }
.logo-residence.grand { max-height: 72px; max-width: 100%; object-fit: contain; margin-bottom: .5rem; }
.entete .reglages-btn { background: rgba(255,255,255,.15); color: inherit; border-radius: 50%; width: 38px; height: 38px; font-size: 1.1rem; }

main.contenu { flex: 1; padding: 1rem 1rem calc(80px + var(--safe-bottom)); max-width: 560px; width: 100%; margin: 0 auto; }

.onglets {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  background: var(--card); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: var(--safe-bottom);
}
.onglets button {
  background: none; padding: .55rem 0 .6rem; display: flex; flex-direction: column;
  align-items: center; gap: .15rem; font-size: .72rem; font-weight: 700;
  color: var(--ink-soft);
}
.onglets button .picto { font-size: 1.35rem; }
.onglets button.actif { color: var(--pine); }
.onglets button .pastille {
  position: absolute; transform: translate(14px, -4px);
  background: var(--brick); color: #fff; border-radius: 999px;
  min-width: 18px; height: 18px; font-size: .7rem;
  display: grid; place-items: center; padding: 0 4px;
}

/* ---------- cartes & boutons ---------- */

.carte {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1rem 1.1rem; margin-bottom: 1rem;
}

/* texte de diffusion mis en forme par markdown.js */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .7rem; }
.md h2, .md h3, .md h4 { font-size: 1rem; margin: .9rem 0 .4rem; }
.md ul, .md ol { margin: 0 0 .7rem; padding-left: 1.4rem; }
.md li { margin-bottom: .25rem; }
.md hr { border: none; border-top: 1px solid var(--line); margin: .9rem 0; }
.md code {
  font-family: ui-monospace, monospace; font-size: .9em;
  background: rgba(0, 0, 0, .05); border-radius: 4px; padding: 0 .25rem;
}
.btn {
  background: var(--pine); color: #fff; border-radius: 12px;
  padding: .8rem 1.2rem; font-weight: 700; font-size: 1rem;
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
}
.btn:active { transform: scale(.98); }
.btn.geant { width: 100%; padding: 1.05rem; font-size: 1.15rem; border-radius: 14px; }
.btn.doux { background: var(--sage); color: var(--pine-dark); }
.btn.rouge { background: var(--brick); }
.btn:disabled { opacity: .5; }

.ligne-raccourcis { display: grid; grid-template-columns: repeat(3, 1fr); gap: .7rem; }
.raccourci {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: .8rem .4rem; display: flex; flex-direction: column;
  align-items: center; gap: .3rem; font-size: .8rem; font-weight: 700; color: var(--ink);
}
.raccourci .picto { font-size: 1.6rem; }

/* ---------- accueil ---------- */

.resident-carte { display: flex; align-items: center; gap: 1rem; }
.photo-ronde {
  width: 64px; height: 64px; border-radius: 50%; object-fit: cover;
  background: var(--sage); display: grid; place-items: center;
  font-family: "Bricolage Grotesque", sans-serif; font-weight: 700;
  font-size: 1.5rem; color: var(--pine-dark); flex: none;
}
.photo-ronde.grande { width: 110px; height: 110px; font-size: 2.5rem; }
.statut { font-size: .85rem; }
.statut .point { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #9AA79E; margin-right: .3rem; }
.statut.present .point { background: #4CAF74; box-shadow: 0 0 0 3px rgba(76,175,116,.25); }

.fil-evenement { display: flex; gap: .7rem; align-items: baseline; padding: .45rem 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.fil-evenement:last-child { border-bottom: none; }
.fil-evenement .quand { color: var(--ink-soft); font-size: .78rem; white-space: nowrap; }

/* ---------- messages (fil) ---------- */

.fil { display: flex; flex-direction: column; gap: .6rem; }
.bulle {
  max-width: 82%; border-radius: 16px; padding: .7rem .9rem;
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow);
  align-self: flex-start; font-size: .95rem;
}
.bulle.moi { align-self: flex-end; background: var(--sage); border-color: var(--sage); }
.bulle .meta { font-size: .72rem; color: var(--ink-soft); margin-top: .3rem; display: flex; gap: .5rem; }
.bulle .accuse { color: var(--pine); font-weight: 700; }
.bulle audio, .bulle video { max-width: 100%; border-radius: 8px; }
.bulle img { max-width: 100%; border-radius: 10px; display: block; }
.bulle.appel-trace { align-self: center; background: var(--honey-soft); border-color: var(--honey-soft); font-size: .85rem; color: #6A5310; }

.barre-envoi {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: .7rem; margin-top: 1rem;
}

/* ---------- enregistreur ---------- */

.enregistreur { text-align: center; padding: 1rem 0; }
.enregistreur .rec { color: var(--brick); font-weight: 700; animation: pulse 1.2s infinite; font-size: 1.1rem; }
@keyframes pulse { 0%,100% { opacity: .55; } 50% { opacity: 1; } }
.enregistreur video { width: 100%; border-radius: 12px; background: #000; margin-bottom: .7rem; }

/* ---------- médias ---------- */

.grille-photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin: .8rem 0; }
.grille-photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; }

/* ---------- appel ---------- */

.plein-ecran {
  position: fixed; inset: 0; z-index: 40; background: var(--nuit); color: #F6F4EE;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1.4rem; padding: 2rem 1.5rem calc(2rem + var(--safe-bottom)); text-align: center;
}
.plein-ecran h1 { font-size: 1.7rem; }
.plein-ecran .provenance { opacity: .8; }
.sonne-photo { animation: sonnerie 1.2s ease-in-out infinite; }
@keyframes sonnerie { 0%,100% { transform: scale(1); } 50% { transform: scale(1.07); } }
.boutons-appel { display: flex; gap: 1rem; width: 100%; max-width: 380px; }
.boutons-appel .btn { flex: 1; padding: 1rem; }
.duree-appel { font-variant-numeric: tabular-nums; font-size: 1.2rem; opacity: .85; }
/* Cadre vidéo : la photo occupe le cadre tant qu'aucune image n'arrive —
   jamais de rectangle noir en attendant (§8.1). */
.zone-video-app {
  position: relative; overflow: hidden;
  width: 100%; max-width: 420px; aspect-ratio: 3/4; border-radius: 16px;
  background: #0E1A14;
}
.zone-video-app .visio-scene { position: absolute; inset: 0; }
.zone-video-app .visio-attente {
  position: absolute; inset: 0; display: grid; place-items: center;
}
.zone-video-app .visio-attente[hidden] { display: none; }
/* auto-vue : assez grande pour vérifier son cadrage, jamais au centre */
.zone-video-app .visio-vignette {
  position: absolute; right: .6rem; top: .6rem; width: 28%; aspect-ratio: 3/4;
  border-radius: 10px; overflow: hidden; background: #08100C;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .4);
}
.zone-video-app .visio-vignette:empty { display: none; }

/* Micro / Caméra en pastilles rondes ; « Activer le son » garde ses mots. */
.commandes-visio {
  display: flex; align-items: center; justify-content: center;
  gap: .8rem; flex-wrap: wrap;
}
.commandes-visio[hidden] { display: none; }
.rond-appel {
  width: 52px; height: 52px; border-radius: 50%; font-size: 1.35rem;
  background: rgba(255, 255, 255, .16); color: #F6F4EE;
  display: inline-flex; align-items: center; justify-content: center;
}
.rond-appel.coupe { background: var(--brick); }
.rond-appel:active { transform: scale(.95); }
.commandes-visio .son-bloque { padding: .55rem .9rem; font-size: .9rem; }

/* ---------- connexion / installation ---------- */

.plein-centre { min-height: 100dvh; display: grid; place-items: center; padding: 1.2rem; }
.boite-auth { width: 100%; max-width: 420px; }
.boite-auth .marque { text-align: center; margin-bottom: 1.2rem; }
.boite-auth .marque img { width: 64px; height: 64px; border-radius: 16px; }
.auth-onglets { display: flex; gap: .5rem; margin-bottom: .9rem; }
.auth-onglets button { flex: 1; border: 1px solid var(--line); background: var(--card); padding: .55rem; border-radius: 10px; font-weight: 700; color: var(--ink-soft); }
.auth-onglets button.actif { background: var(--pine); border-color: var(--pine); color: #fff; }

/* Passer sur téléphone (§6.2.1) : proposé seulement sur grand écran, où
   l'invitation vient d'être lue dans une boîte mail. */
.qr-telephone {
  display: flex; align-items: center; gap: .9rem; margin-top: .9rem;
}
.qr-telephone svg { flex: 0 0 auto; width: 92px; height: 92px; border-radius: 6px; }
.qr-titre { font-weight: 700; margin: 0 0 .15rem; }
.qr-detail { margin: 0; color: var(--ink-soft); font-size: .85rem; line-height: 1.45; }

label.champ { display: block; margin-bottom: .85rem; }
label.champ > span { display: block; font-weight: 700; font-size: .85rem; margin-bottom: .3rem; }
input, textarea {
  width: 100%; padding: .7rem .8rem; font: inherit; border: 1px solid var(--line);
  border-radius: 10px; background: #FDFDFB; color: var(--ink);
}

.etape-install { text-align: center; }
.etape-install ol { text-align: left; padding-left: 1.4rem; }
.etape-install li { margin-bottom: .5rem; }
.lien-discret { background: none; color: var(--ink-soft); text-decoration: underline; font-size: .85rem; margin-top: 1rem; }

/* ---------- divers ---------- */

.vide { color: var(--ink-soft); text-align: center; padding: 1.4rem 0; }
.tag { display: inline-block; border-radius: 999px; padding: .1rem .6rem; font-size: .78rem; font-weight: 700; }
.tag.vert { background: var(--sage); color: var(--pine-dark); }
.tag.miel { background: var(--honey-soft); color: #7A5314; }
.tag.gris { background: #E9E9E4; color: var(--ink-soft); }

#toast-root { position: fixed; bottom: calc(86px + var(--safe-bottom)); left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: .5rem; width: max-content; max-width: 92vw; }
.toast { background: var(--ink); color: #F6F4EE; border-radius: 999px; padding: .55rem 1.1rem; font-size: .9rem; box-shadow: var(--shadow); text-align: center; }
.toast.erreur { background: var(--brick); }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }
