:root {
  --fond: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #ece9e2;
  --texte: #1d2321;
  --texte-doux: #5f6a66;
  --primaire: #0e6f68;
  --primaire-texte: #ffffff;
  --bulle-moi: #0e6f68;
  --bulle-moi-texte: #ffffff;
  --bulle-neo: #ffffff;
  --bordure: #dedad1;
  --danger: #b4372f;
  --ombre: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
  --rayon: 18px;
  --haut: env(safe-area-inset-top, 0px);
  --bas: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fond: #121615;
    --surface: #1b2120;
    --surface-2: #252c2a;
    --texte: #e8ecea;
    --texte-doux: #9aa6a2;
    --primaire: #2fa79d;
    --primaire-texte: #06201d;
    --bulle-moi: #1f6f68;
    --bulle-moi-texte: #f1fbf9;
    --bulle-neo: #1f2725;
    --bordure: #2c3532;
    --danger: #ef7d73;
    --ombre: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, textarea { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2;
      stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- écrans simples (chargement, invitation) ---------- */
.ecran-centre, .page-simple {
  min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px 16px;
}
.carte {
  width: 100%; max-width: 380px; background: var(--surface); border-radius: 24px;
  padding: 28px 22px; box-shadow: var(--ombre); text-align: center;
}
.carte h1 { font-size: 1.5rem; margin: 12px 0 8px; }
.carte p { margin: 8px 0; }
.carte form { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.carte input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--bordure);
  background: var(--fond);
}
.logo, .avatar {
  display: grid; place-items: center; border-radius: 50%; background: var(--primaire);
  color: var(--primaire-texte); font-weight: 800;
}
.logo { width: 64px; height: 64px; font-size: 30px; margin: 0 auto; }
.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(.92); opacity: .7; } }
.aide { color: var(--texte-doux); font-size: .92rem; }
.erreur { color: var(--danger); font-size: .92rem; }
.bouton {
  border: 0; border-radius: 12px; padding: 12px 18px; background: var(--primaire);
  color: var(--primaire-texte); font-weight: 600; cursor: pointer; width: 100%;
}
.bouton.petit { width: auto; padding: 10px 14px; }
.bouton:active { transform: scale(.98); }

/* ---------- structure de l'appli ---------- */
#appli {
  height: 100vh; height: 100dvh; display: flex; flex-direction: column;
  max-width: 720px; margin: 0 auto; background: var(--fond);
}
.entete {
  position: relative; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--haut)) 12px 10px 16px; background: var(--surface);
  border-bottom: 1px solid var(--bordure);
}
.avatar { width: 38px; height: 38px; font-size: 18px; }
.titres { flex: 1; min-width: 0; }
.nom { font-weight: 700; }
.sous-titre { font-size: .82rem; color: var(--texte-doux); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icone {
  display: grid; place-items: center; width: 42px; height: 42px; border: 0; border-radius: 50%;
  background: transparent; color: var(--texte-doux); cursor: pointer; flex: none;
}
.icone:active { background: var(--surface-2); }
.icone.actif { color: var(--primaire); }
#btn-notif.actif svg { fill: currentColor; fill-opacity: .18; }

.menu {
  position: absolute; right: 10px; top: calc(56px + var(--haut)); z-index: 10; min-width: 250px;
  background: var(--surface); border: 1px solid var(--bordure); border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,.18); padding: 6px; display: flex; flex-direction: column;
}
.menu button, .menu .option {
  display: flex; align-items: center; gap: 10px; text-align: left; border: 0; background: none;
  padding: 12px; border-radius: 10px; cursor: pointer;
}
.menu button:active, .menu .option:active { background: var(--surface-2); }
.menu .danger { color: var(--danger); }
.menu input { width: 18px; height: 18px; accent-color: var(--primaire); }

.bandeau {
  position: relative; padding: 10px 40px 10px 16px; font-size: .9rem;
  background: var(--surface-2); border-bottom: 1px solid var(--bordure);
}
.fermer {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 32px; height: 32px;
  border: 0; border-radius: 50%; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--texte-doux);
}

.vue { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }

/* ---------- discussion ---------- */
.fil {
  flex: 1; overflow-y: auto; padding: 16px 12px 8px; display: flex; flex-direction: column; gap: 6px;
  -webkit-overflow-scrolling: touch;
}
.bulle {
  max-width: 82%; padding: 9px 13px; border-radius: var(--rayon); white-space: pre-wrap;
  overflow-wrap: anywhere; box-shadow: var(--ombre); animation: apparait .18s ease-out;
}
@keyframes apparait { from { opacity: 0; transform: translateY(4px); } }
.bulle.moi { align-self: flex-end; background: var(--bulle-moi); color: var(--bulle-moi-texte); border-bottom-right-radius: 6px; }
.bulle.neo { align-self: flex-start; background: var(--bulle-neo); border-bottom-left-radius: 6px; }
.bulle.neo strong { font-weight: 650; }
.bulle img { display: block; max-width: 100%; border-radius: 12px; margin-bottom: 6px; }
.info { align-self: center; font-size: .8rem; color: var(--texte-doux); padding: 6px 0; }
.jour { align-self: center; font-size: .75rem; color: var(--texte-doux); background: var(--surface-2);
        padding: 3px 10px; border-radius: 99px; margin: 8px 0 4px; }
.accueil { margin: auto; text-align: center; color: var(--texte-doux); padding: 24px; max-width: 340px; }
.accueil .logo { margin-bottom: 14px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.suggestions button {
  border: 1px solid var(--bordure); background: var(--surface); border-radius: 99px;
  padding: 8px 12px; font-size: .88rem; cursor: pointer;
}
.ecrit { display: inline-flex; gap: 4px; padding: 14px 16px; }
.ecrit i { width: 7px; height: 7px; border-radius: 50%; background: var(--texte-doux); animation: rebond 1.2s infinite; }
.ecrit i:nth-child(2) { animation-delay: .15s; }
.ecrit i:nth-child(3) { animation-delay: .3s; }
@keyframes rebond { 0%, 60%, 100% { opacity: .3; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }

.apercu { position: relative; padding: 8px 12px 0; }
.apercu img { height: 72px; border-radius: 12px; border: 1px solid var(--bordure); }
.apercu .fermer { left: 78px; right: auto; top: 14px; transform: none; background: var(--surface); }

.saisie {
  display: flex; align-items: flex-end; gap: 4px; padding: 8px 8px 8px 6px;
  background: var(--surface); border-top: 1px solid var(--bordure);
}
.saisie textarea {
  flex: 1; resize: none; max-height: 140px; padding: 10px 14px; border-radius: 22px;
  border: 1px solid var(--bordure); background: var(--fond); outline: none; line-height: 1.35;
}
.saisie textarea:focus { border-color: var(--primaire); }
.envoyer {
  width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--primaire);
  color: var(--primaire-texte); display: grid; place-items: center; cursor: pointer; flex: none;
}
.envoyer:disabled { opacity: .45; }
#btn-micro.ecoute { color: #fff; background: var(--danger); animation: pulse 1.2s infinite; }

/* ---------- courses ---------- */
.ajout { display: flex; gap: 8px; padding: 14px 12px; }
.ajout input {
  flex: 1; min-width: 0; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--bordure);
  background: var(--surface);
}
.liste { list-style: none; margin: 0; padding: 0 12px 16px; overflow-y: auto; flex: 1; }
.liste li {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin-bottom: 6px;
  background: var(--surface); border-radius: 14px; box-shadow: var(--ombre); transition: opacity .25s, transform .25s;
}
.liste li.coche { opacity: 0; transform: translateX(30px); }
.liste .case {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--bordure); background: none;
  flex: none; cursor: pointer; display: grid; place-items: center; color: var(--primaire-texte); padding: 0;
}
.liste li.coche .case { background: var(--primaire); border-color: var(--primaire); }
.liste .case svg { width: 16px; height: 16px; stroke-width: 3; }
.liste .article { flex: 1; overflow-wrap: anywhere; }
.liste .par { font-size: .78rem; color: var(--texte-doux); }
.vide { text-align: center; color: var(--texte-doux); padding: 32px 16px; }

/* ---------- agenda ---------- */
.agenda { overflow-y: auto; padding: 8px 12px 16px; flex: 1; }
.agenda h2 { font-size: .85rem; text-transform: capitalize; color: var(--texte-doux); margin: 16px 4px 6px; font-weight: 600; }
.evt {
  display: flex; gap: 12px; padding: 12px 14px; margin-bottom: 6px; background: var(--surface);
  border-radius: 14px; box-shadow: var(--ombre); border-left: 4px solid var(--primaire);
}
.evt .heure { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 48px; }
.evt .lieu { font-size: .85rem; color: var(--texte-doux); }

/* ---------- onglets ---------- */
.onglets {
  display: flex; background: var(--surface); border-top: 1px solid var(--bordure);
  padding-bottom: var(--bas);
}
.onglet {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 10px;
  border: 0; background: none; font-size: .75rem; color: var(--texte-doux); cursor: pointer;
}
.onglet.actif { color: var(--primaire); font-weight: 600; }
.agenda:empty, .liste:empty { display: none; }
@media (prefers-color-scheme: dark) { .liste .case { border-color: var(--texte-doux); } }

/* ---------- listes : puces et rayons ---------- */
.puces { display: flex; gap: 8px; overflow-x: auto; padding: 12px 12px 0; scrollbar-width: none; flex: none; }
.puces::-webkit-scrollbar { display: none; }
.puce {
  flex: none; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--bordure);
  background: var(--surface); border-radius: 99px; padding: 7px 14px; font-size: .9rem; cursor: pointer;
}
.puce.actif { background: var(--primaire); color: var(--primaire-texte); border-color: var(--primaire); font-weight: 600; }
.puce.plus { color: var(--texte-doux); border-style: dashed; }
.puce .compte { font-size: .75rem; opacity: .75; }
.liste-zone { overflow-y: auto; flex: 1; padding: 0 12px 16px; }
.liste-zone .liste { padding: 0; overflow: visible; }
.rayon { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--texte-doux); margin: 14px 4px 6px; font-weight: 600; }

/* ---------- semaine & défis ---------- */
.defile { overflow-y: auto; padding: 8px 12px 20px; flex: 1; }
.defile h2 { font-size: .85rem; text-transform: capitalize; color: var(--texte-doux); margin: 16px 4px 6px; font-weight: 600; }
.defile h2.titre-section { text-transform: none; font-size: .9rem; color: var(--texte); }
.centre { text-align: center; }
.evt.rappel { border-left-color: #c98a1b; }
.evt.repas { border-left-color: var(--bordure); }
.score { text-align: center; padding: 16px 0 4px; }
.score .points { font-size: 2.6rem; font-weight: 800; color: var(--primaire); line-height: 1; }
.ligne-defi {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; margin-bottom: 6px;
  background: var(--surface); border-radius: 14px; box-shadow: var(--ombre);
}
.ligne-defi .quoi { flex: 1; overflow-wrap: anywhere; }
.ligne-defi .par { font-size: .78rem; color: var(--texte-doux); }
.etiquette { font-size: .8rem; color: var(--texte-doux); white-space: nowrap; }
.mini {
  border: 0; border-radius: 10px; padding: 8px 12px; font-weight: 600; cursor: pointer; white-space: nowrap;
  background: var(--surface-2); color: var(--texte);
}
.mini.fait { background: var(--primaire); color: var(--primaire-texte); }
.mini.ok { background: var(--primaire); color: var(--primaire-texte); min-width: 40px; }
.mini.non { background: var(--surface-2); color: var(--danger); min-width: 40px; }
.mini:disabled { opacity: .45; }
.onglet { position: relative; }
.pastille {
  position: absolute; top: 4px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 99px; background: var(--danger); color: #fff; font-size: .7rem; font-weight: 700;
  display: grid; place-items: center;
}

/* ---------- vote ---------- */
.carte-vote {
  margin: 10px 12px 0; padding: 12px; background: var(--surface); border-radius: 16px; box-shadow: var(--ombre);
  border: 1px solid var(--bordure); flex: none;
}
.carte-vote .question { font-weight: 650; margin-bottom: 8px; }
.carte-vote .choix { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.option-vote {
  --part: 0%; position: relative; display: flex; justify-content: space-between; gap: 8px; text-align: left;
  border: 1px solid var(--bordure); border-radius: 10px; padding: 9px 12px; cursor: pointer; overflow: hidden;
  background: linear-gradient(90deg, color-mix(in srgb, var(--primaire) 16%, transparent) var(--part), var(--fond) var(--part));
}
.option-vote.mien { border-color: var(--primaire); font-weight: 650; }
.option-vote .voix { color: var(--texte-doux); font-variant-numeric: tabular-nums; }

/* ---------- jauges (plafond, équipe) ---------- */
.jauge { margin: 10px 2px; }
.jauge-texte { font-size: .85rem; margin-bottom: 5px; }
.jauge-barre { height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.jauge-plein { height: 100%; border-radius: 99px; background: var(--primaire); transition: width .4s; }
.jauge-plein.complet { background: #d49b1f; }
.carte-enfant { padding: 12px 14px 4px; margin-bottom: 6px; background: var(--surface); border-radius: 14px; box-shadow: var(--ombre); }
.mini.info:disabled { opacity: 1; background: var(--surface-2); color: var(--texte-doux); }
.budget { margin: 0 4px 8px; }
.budget.temporaire { color: #b07a10; font-weight: 600; }
.carte-vote.compact { padding: 0; }
.vote-compact {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; padding: 10px 12px;
  border: 0; background: none; text-align: left; cursor: pointer; border-radius: 16px;
}
.vote-compact .question { font-weight: 650; }

/* ---------- demandes de films à valider (admin) ---------- */
.carte-films { max-height: 45vh; overflow-y: auto; }
.carte-films .film-demande { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 8px 0; border-top: 1px solid var(--bordure); }
.carte-films .film-texte { flex: 1 1 180px; min-width: 0; }
.carte-films .film-titre { font-weight: 600; overflow-wrap: anywhere; }
.carte-films .film-actions { display: flex; gap: 6px; margin-left: auto; }
.carte-films > .aide:last-child { margin-top: 6px; }
