:root {
  --fond: #F6F4EF;
  --surface: #FFFFFF;
  --texte: #1F2430;
  --muted: #687082;
  --bord: #E3DFD6;
  --primaire: #2D3E5C;
  --primaire-texte: #FFFFFF;
  --or: #D9BE8A;
  --vert: #3E7D5A;
  --rouge: #B3413A;
  --hero: linear-gradient(135deg, #2D3E5C, #3B5B8C);
  --ombre: 0 1px 2px rgba(20, 24, 32, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fond: #14171D; --surface: #1E222A; --texte: #E8E6E1; --muted: #9AA1AE; --bord: #2E333D;
    --primaire: #9DB4DA; --primaire-texte: #10141B; --vert: #7CC49A; --rouge: #E58A82;
    --hero: linear-gradient(135deg, #22304A, #2E4770); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --fond: #14171D; --surface: #1E222A; --texte: #E8E6E1; --muted: #9AA1AE; --bord: #2E333D;
  --primaire: #9DB4DA; --primaire-texte: #10141B; --vert: #7CC49A; --rouge: #E58A82;
  --hero: linear-gradient(135deg, #22304A, #2E4770); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--fond); color: var(--texte);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
body.modal-ouvert { overflow: hidden; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
small { display: block; font-size: 12.5px; }
hr { border: 0; border-top: 1px solid var(--bord); margin: 12px 0; }
a { color: inherit; text-decoration: none; }

.muted { color: var(--muted); }
.petit { font-size: 13px; }
.centre { text-align: center; justify-content: center; }
.vert { color: var(--vert); }
.rouge { color: var(--rouge); }

/* En-tête et onglets */
.entete {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--primaire); color: var(--primaire-texte);
}
.entete-l { flex: 1; min-width: 0; }
.titre { font-weight: 650; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.etat { font-size: 12px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.etat.alerte { opacity: 1; font-weight: 600; }
.entete-r { display: flex; align-items: center; gap: 6px; }
.utilisateur { font-size: 13px; opacity: .9; }
.entete .btn.icone { background: transparent; color: inherit; border: 0; font-size: 22px; padding: 4px 10px; }

.onglets {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex;
  background: var(--surface); border-top: 1px solid var(--bord); padding-bottom: env(safe-area-inset-bottom);
}
.onglets a {
  flex: 1; display: flex; flex-direction: column; align-items: center; padding: 7px 2px 8px;
  font-size: 11px; color: var(--muted); min-width: 0;
}
.onglets a span { font-size: 20px; line-height: 1.2; }
.onglets a.actif { color: var(--primaire); font-weight: 650; }
@media (min-width: 900px) {
  body { padding-bottom: 24px; }
  .onglets { position: sticky; top: 58px; bottom: auto; border-top: 0; border-bottom: 1px solid var(--bord); justify-content: center; }
  .onglets a { flex: 0 0 auto; flex-direction: row; gap: 6px; padding: 12px 18px; font-size: 14px; }
  .onglets a span { font-size: 16px; }
}

main { max-width: 760px; margin: 0 auto; padding: 16px; }

/* Cartes */
.carte {
  background: var(--surface); border: 1px solid var(--bord); border-radius: 20px;
  padding: 16px; margin-bottom: 14px; box-shadow: var(--ombre);
}
.carte.vide { text-align: center; padding: 32px 20px; }
.hero { background: var(--hero); color: #fff; border: 0; }
.hero .btn.clair { margin-top: 12px; background: rgba(255,255,255,.14); color: #fff; border-color: rgba(255,255,255,.25); }
.hero-haut { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.hero-montant { font-size: 30px; font-weight: 700; letter-spacing: -.5px; }
.hero-montant small { display: inline; font-size: 15px; font-weight: 500; opacity: .8; }
.muted-clair { color: rgba(255,255,255,.75); font-size: 13.5px; }
.ceremonie { text-align: right; font-weight: 600; }
.hero .barre { background: rgba(255,255,255,.2); margin: 6px 0 8px; }

.grille { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--bord); border-radius: 16px; padding: 12px 14px; }
.stat-l { font-size: 12.5px; color: var(--muted); }
.stat-v { font-size: 18px; font-weight: 650; }
.stat-v small { display: inline; font-weight: 400; color: var(--muted); }
.stat.vert .stat-v { color: var(--vert); }
.stat.rouge .stat-v { color: var(--rouge); }

.alertes { border-color: color-mix(in srgb, var(--rouge) 40%, var(--bord)); }
.alertes ul { margin: 0; padding-left: 20px; }
.alertes li { margin: 4px 0; }
.alerte-bloc {
  margin: 10px 0; padding: 9px 12px; border-radius: 12px; font-size: 13.5px;
  color: var(--rouge); background: color-mix(in srgb, var(--rouge) 9%, transparent);
}

/* Rangées et lignes */
.rang { display: flex; align-items: center; gap: 12px; padding: 9px 0; }
.rang + .rang { border-top: 1px solid var(--bord); }
.rang-c { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.rang-d { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.rang-d small { color: var(--muted); }
.cliquable { cursor: pointer; }
.pastille {
  flex: 0 0 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-size: 18px; font-weight: 700;
}
.barre { height: 7px; border-radius: 99px; background: var(--bord); overflow: hidden; margin: 5px 0; }
.barre > div { height: 100%; border-radius: 99px; }
.sous { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.rubrique .lignes { margin-top: 10px; border-top: 1px solid var(--bord); padding-top: 4px; }
.groupe { font-size: 12.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin: 12px 0 2px; }
.ligne { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--bord); }
.ligne:last-of-type { border-bottom: 0; }
.ligne.payee .rang-c { color: var(--muted); }
.case input { width: 20px; height: 20px; accent-color: var(--vert); cursor: pointer; }
.jour { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.date-bloc { flex: 0 0 96px; font-weight: 600; font-size: 13.5px; }
.date-bloc small { font-weight: 400; color: var(--muted); }

.membre { border-top: 1px solid var(--bord); border-radius: 10px; }
.membre-v { padding: 0 0 10px 50px; }
.distribution { display: flex; height: 10px; border-radius: 99px; overflow: hidden; gap: 2px; margin: 8px 0; }
.segments { display: flex; border: 1px solid var(--bord); border-radius: 99px; overflow: hidden; margin: 10px 0 6px; }
.segments button {
  flex: 1; border: 0; background: transparent; padding: 9px; font: inherit; color: var(--texte); cursor: pointer;
}
.segments button.actif { background: var(--primaire); color: var(--primaire-texte); font-weight: 600; }

/* Boutons */
.btn {
  font: inherit; font-weight: 550; padding: 9px 16px; border-radius: 99px; cursor: pointer;
  background: var(--surface); color: var(--texte); border: 1px solid var(--bord);
}
.btn:hover { filter: brightness(.97); }
.btn.primaire { background: var(--primaire); color: var(--primaire-texte); border-color: var(--primaire); }
.btn.danger { color: var(--rouge); border-color: color-mix(in srgb, var(--rouge) 40%, var(--bord)); }
.btn.large { width: 100%; padding: 12px; margin-top: 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.actions.fin { justify-content: flex-end; }
.espace { flex: 1; }

/* Fenêtres */
.fond {
  position: fixed; inset: 0; z-index: 20; background: rgba(10, 12, 16, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.fenetre {
  background: var(--surface); width: 100%; max-width: 520px; max-height: 92vh; overflow: auto;
  border-radius: 22px 22px 0 0; padding: 20px 18px calc(18px + env(safe-area-inset-bottom));
}
@media (min-width: 600px) { .fond { align-items: center; } .fenetre { border-radius: 22px; } }
.formulaire label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 0; }
.formulaire input:not([type=checkbox]), .formulaire select, .formulaire textarea {
  display: block; width: 100%; margin-top: 4px; padding: 11px 12px; border-radius: 12px;
  border: 1px solid var(--bord); background: var(--fond); color: var(--texte); font: inherit; font-size: 16px;
}
.formulaire .ligne-case { display: flex; align-items: center; gap: 10px; color: var(--texte); font-size: 15px; margin-top: 14px; }
.formulaire .ligne-case input { width: 20px; height: 20px; accent-color: var(--vert); }
.erreur { color: var(--rouge); font-size: 14px; }

/* Installation */
.installation { text-align: center; }
.installation .install-icone { width: 72px; height: 72px; border-radius: 18px; margin: 4px auto 10px; display: block; }
.installation p { color: var(--muted); }
.etapes { text-align: left; padding-left: 22px; margin: 12px 0; }
.etapes li { margin: 10px 0; line-height: 1.5; }
.pict { display: inline-block; padding: 0 6px; border-radius: 8px; background: var(--fond); border: 1px solid var(--bord); }

/* Connexion */
.connexion { min-height: 100vh; display: grid; place-items: center; padding: 16px; margin-bottom: -72px; }
.connexion .carte { max-width: 400px; width: 100%; text-align: center; padding: 28px 22px; }
.connexion .logo { font-size: 44px; }
.connexion form { text-align: left; margin: 18px 0 10px; }
.connexion label { font-size: 13px; color: var(--muted); }
.connexion input {
  display: block; width: 100%; margin-top: 6px; padding: 12px; border-radius: 12px; font: inherit; font-size: 16px;
  border: 1px solid var(--bord); background: var(--fond); color: var(--texte);
}

#notif {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: #1F2430; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 30; max-width: calc(100% - 32px);
}
#notif.visible { opacity: 1; transform: translate(-50%, 0); }

/* Impression */
#impression { display: none; }
@media print {
  body { background: #fff; color: #000; padding: 0; font-size: 11pt; }
  #app > *:not(#impression), #notif, .fond { display: none !important; }
  #impression { display: block; }
  #impression h1 { font-size: 18pt; }
  #impression h2 { font-size: 12.5pt; margin-top: 16pt; break-after: avoid; }
  #impression table { width: 100%; border-collapse: collapse; margin-bottom: 6pt; }
  #impression th, #impression td { border-bottom: .5pt solid #bbb; padding: 3pt 5pt; text-align: left; font-size: 9.5pt; }
  #impression td:nth-last-child(-n+2), #impression th:nth-last-child(-n+2) { text-align: right; }
  #impression tfoot td { font-weight: 700; border-top: 1pt solid #000; }
}
