/* Factures — typographie de la QR-facture (Helvetica/Arial), marques d'angle et ligne perforée */
:root {
  --fond: #f2f3f0;
  --surface: #ffffff;
  --encre: #15191d;
  --encre-2: #5b636b;
  --ligne: #d7dad4;
  --ligne-forte: #9aa19a;
  --rouge: #c4161c;
  --vert: #1e6b4f;
  --focus: #2f6fd6;
  --barre: #8e968f;
  --barre-fond: #e3e6e1;
  --rayon: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fond: #15181b;
    --surface: #1f2327;
    --encre: #eceeea;
    --encre-2: #a2a9a4;
    --ligne: #343a3f;
    --ligne-forte: #5d655f;
    --rouge: #ff6f66;
    --vert: #62c79c;
    --focus: #7aa8ff;
    --barre: #6f7872;
    --barre-fond: #2a2f33;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--fond);
  color: var(--encre);
  font: 17px/1.45 "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}
body.bloque { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.chargement { padding: 40vh 0 0; text-align: center; color: var(--encre-2); }

/* ---------- Structure ---------- */
.contenu {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 96px);
}
.entete { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 18px; }
.entete h1 { font-size: 26px; line-height: 1.15; margin: 0; letter-spacing: -0.01em; }
h2.section { font-size: 15px; font-weight: 700; margin: 28px 0 8px; color: var(--encre-2); }

/* ---------- Navigation du mois ---------- */
.mois-nav { display: flex; align-items: center; gap: 4px; }
.mois-nav h1 { flex: 1; text-align: center; }
.btn-rond {
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--ligne); background: var(--surface);
  font-size: 22px; line-height: 1; cursor: pointer;
}

/* ---------- Montant encadré (marques d'angle de la QR-facture) ---------- */
.coins {
  --c: var(--encre); --l: 16px; --w: 2px;
  background:
    linear-gradient(var(--c), var(--c)) top left / var(--l) var(--w),
    linear-gradient(var(--c), var(--c)) top left / var(--w) var(--l),
    linear-gradient(var(--c), var(--c)) top right / var(--l) var(--w),
    linear-gradient(var(--c), var(--c)) top right / var(--w) var(--l),
    linear-gradient(var(--c), var(--c)) bottom left / var(--l) var(--w),
    linear-gradient(var(--c), var(--c)) bottom left / var(--w) var(--l),
    linear-gradient(var(--c), var(--c)) bottom right / var(--l) var(--w),
    linear-gradient(var(--c), var(--c)) bottom right / var(--w) var(--l);
  background-repeat: no-repeat;
}
.total { padding: 22px 22px 20px; text-align: center; }
.total .etiquette { font-size: 15px; color: var(--encre-2); margin: 0; }
.total .somme { font-size: 44px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; margin: 6px 0 4px; }
.total .somme small { font-size: 20px; font-weight: 400; margin-right: 6px; color: var(--encre-2); }
.total .detail { font-size: 15px; color: var(--encre-2); margin: 0; }

/* Ligne perforée avec ciseaux */
.perfo { position: relative; border: 0; border-top: 1px dashed var(--ligne-forte); margin: 26px 0 4px; }
.perfo::before {
  content: "✂"; position: absolute; left: 14px; top: -12px;
  background: var(--fond); padding: 0 6px; color: var(--encre-2); font-size: 15px;
}

/* ---------- Répartition par payeur ---------- */
.repartition { margin: 0; padding: 0; list-style: none; }
.repartition li {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
  padding: 12px 0; border-bottom: 1px solid var(--ligne);
}
.repartition .qui { font-weight: 700; }
.repartition .reste { text-align: right; font-weight: 700; }
.repartition .paye { grid-column: 1 / -1; font-size: 14px; color: var(--encre-2); }
.repartition .vide { color: var(--encre-2); font-weight: 400; }

/* ---------- Lignes de facture ---------- */
.liste { display: flex; flex-direction: column; gap: 6px; }
.ligne {
  display: grid; grid-template-columns: 64px 1fr auto; align-items: center; gap: 12px;
  width: 100%; padding: 12px 14px; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--ligne); border-radius: var(--rayon);
}
.ligne .l-date { font-size: 14px; color: var(--encre-2); }
.ligne .l-nom { min-width: 0; }
.ligne .l-nom strong { display: block; font-weight: 700; overflow-wrap: anywhere; }
.ligne .l-meta { font-size: 14px; color: var(--encre-2); }
.ligne .l-retard { color: var(--rouge); font-weight: 700; }
.ligne .l-montant { font-weight: 700; text-align: right; white-space: nowrap; }
.ligne.retard { border-left: 4px solid var(--rouge); }
.ligne.retard .l-date { color: var(--rouge); }
.ligne.payee .l-montant { color: var(--vert); font-weight: 400; }
.vide-etat { color: var(--encre-2); padding: 12px 0; margin: 0; }

details.repli > summary { cursor: pointer; color: var(--encre-2); font-weight: 700; font-size: 15px; margin: 28px 0 8px; }

/* ---------- Liste : filtres ---------- */
.filtres { display: flex; gap: 0; border: 1px solid var(--ligne); border-radius: var(--rayon); overflow: hidden; margin-bottom: 10px; }
.filtres button { flex: 1; padding: 10px 6px; border: 0; background: var(--surface); cursor: pointer; font-size: 15px; }
.filtres button + button { border-left: 1px solid var(--ligne); }
.filtres button[aria-pressed="true"] { background: var(--encre); color: var(--fond); font-weight: 700; }
.recherche { width: 100%; margin-bottom: 14px; }

/* ---------- Barre du bas ---------- */
.barre {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: 1fr 1fr auto 1fr; gap: 4px; align-items: center;
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 8px);
  background: color-mix(in srgb, var(--fond) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--ligne);
}
.barre .onglet {
  border: 0; background: none; padding: 10px 2px; cursor: pointer; white-space: nowrap;
  color: var(--encre-2); font-size: 15px;
}
.barre .onglet[aria-current="page"] { color: var(--encre); font-weight: 700; }
.barre .ajouter {
  border: 0; border-radius: 999px; padding: 12px 18px; cursor: pointer; white-space: nowrap;
  background: var(--encre); color: var(--fond); font-weight: 700;
}

/* ---------- Formulaires ---------- */
.pile { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 15px; color: var(--encre-2); }
input:not([type="radio"]):not([type="checkbox"]):not([type="file"]), select {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--ligne-forte); border-radius: 8px;
  background: var(--surface); color: var(--encre); font-size: 17px;
}
input[type="file"] { font-size: 15px; color: var(--encre); }
.rang { display: grid; grid-template-columns: 1fr 96px; gap: 10px; }
.montant-saisie input { font-size: 22px !important; font-weight: 700; }
.erreur { color: var(--rouge); margin: 0; min-height: 0; }
.erreur:empty { display: none; }
.info { background: var(--fond); border-radius: 8px; padding: 10px 12px; margin: 0 0 14px; font-size: 15px; }
.info.alerte { color: var(--rouge); }

fieldset.choix { border: 0; padding: 0; margin: 0; }
fieldset.choix legend { font-size: 15px; color: var(--encre-2); padding: 0; margin-bottom: 6px; }
.pastilles { display: flex; flex-wrap: wrap; gap: 8px; }
.pastilles label { flex-direction: row; }
.pastilles input { position: absolute; opacity: 0; pointer-events: none; }
.pastilles span {
  display: inline-block; padding: 9px 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--ligne-forte); color: var(--encre); background: var(--surface); font-size: 16px;
}
.pastilles input:checked + span { background: var(--encre); color: var(--fond); border-color: var(--encre); font-weight: 700; }
.pastilles input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

details.details-paiement > summary { cursor: pointer; font-size: 15px; color: var(--encre-2); }
details.details-paiement[open] > summary { margin-bottom: 10px; }
details.details-paiement .pile { gap: 10px; }

.btn {
  min-height: 48px; padding: 12px 18px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--ligne-forte); background: var(--surface); color: var(--encre); font-weight: 700;
}
.btn.principal { background: var(--encre); color: var(--fond); border-color: var(--encre); }
.btn.danger { color: var(--rouge); border-color: transparent; background: none; }
.btn.lien { border: 0; background: none; padding: 8px 0; min-height: 0; color: var(--encre-2); font-weight: 400; text-decoration: underline; }
.btn:disabled { opacity: 0.5; }
.actions { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }

/* ---------- Connexion ---------- */
.login { max-width: 380px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 18vh) 20px 40px; }
.marque { display: flex; align-items: center; gap: 12px; font-size: 30px; font-weight: 700; margin-bottom: 28px; }
.croix { width: 34px; height: 34px; background: var(--encre); position: relative; flex: none; }
.croix::before, .croix::after { content: ""; position: absolute; background: var(--fond); left: 50%; top: 50%; transform: translate(-50%, -50%); }
.croix::before { width: 20px; height: 6px; }
.croix::after { width: 6px; height: 20px; }

/* ---------- Feuille (panneau) ---------- */
#feuille { position: fixed; inset: 0; z-index: 20; }
.feuille-fond { position: absolute; inset: 0; background: rgb(0 0 0 / 0.45); }
.feuille {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 94vh; overflow-y: auto;
  max-width: 640px; margin: 0 auto;
  background: var(--surface); border-radius: 16px 16px 0 0;
  padding: 16px 18px calc(env(safe-area-inset-bottom) + 20px);
  animation: monte 0.22s ease-out;
}
@keyframes monte { from { transform: translateY(24px); opacity: 0.6; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .feuille { animation: none; } }
.f-tete { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.f-tete h2 { margin: 0; font-size: 22px; }
.btn-x { width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--fond); cursor: pointer; font-size: 18px; }

.choix-ajout { display: flex; flex-direction: column; gap: 10px; }
.choix-ajout .btn { width: 100%; text-align: left; border-radius: var(--rayon); padding: 16px 18px; }
.choix-ajout .btn small { display: block; font-weight: 400; color: var(--encre-2); font-size: 14px; margin-top: 2px; }
.choix-ajout .btn.principal small { color: color-mix(in srgb, var(--fond) 75%, transparent); }

/* Viseur caméra : mêmes marques d'angle que le montant */
.viseur { position: relative; border-radius: var(--rayon); overflow: hidden; background: #000; aspect-ratio: 3 / 4; max-height: 62vh; margin: 0 auto; }
.viseur video { width: 100%; height: 100%; object-fit: cover; display: block; }
.viseur .cadre { position: absolute; inset: 18%; --c: #fff; --l: 28px; --w: 3px; }
.aide { text-align: center; color: var(--encre-2); margin: 12px 0 0; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 84px); z-index: 30;
  transform: translateX(-50%); background: var(--encre); color: var(--fond);
  padding: 10px 18px; border-radius: 999px; font-size: 15px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity 0.2s; white-space: nowrap;
}
#toast.visible { opacity: 1; }

/* ---------- Bilan ---------- */
.graphe { display: block; width: 100%; height: auto; overflow: visible; }
.graphe .g-cible { fill: transparent; cursor: pointer; }
.graphe .g-base { stroke: var(--ligne-forte); stroke-width: 1; }
.graphe .barre-mois { fill: var(--barre); }
.graphe .barre-mois.sel { fill: var(--encre); }
.graphe .g-mois:hover .barre-mois:not(.sel) { fill: var(--encre-2); }
.graphe text { font-size: 11px; fill: var(--encre-2); font-family: inherit; }
.graphe .g-mois-txt.sel { fill: var(--encre); font-weight: 700; }
.graphe .g-valeur { fill: var(--encre); font-weight: 700; font-size: 12px; }
.graphe .g-mois:focus { outline: none; }
.g-detail { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; font-size: 15px; color: var(--encre-2); margin: 10px 0 0; }
.g-detail strong { color: var(--encre); }
.tableau-repli > summary { margin-top: 12px; }
.tableau { width: 100%; border-collapse: collapse; font-size: 15px; }
.tableau td { padding: 6px 0; border-bottom: 1px solid var(--ligne); }
.tableau td:last-child { text-align: right; }

.barres-h { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.barres-h li { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; }
.bh-nom { font-weight: 700; }
.bh-val { text-align: right; font-weight: 700; }
.bh-val small { font-weight: 400; color: var(--encre-2); margin-left: 8px; font-size: 14px; }
.bh-piste { grid-column: 1 / -1; width: 100%; height: 8px; display: block; border-radius: 4px; overflow: hidden; }
.bh-fond { fill: var(--barre-fond); }
.bh-barre { fill: var(--encre); }

.top { margin: 0; padding: 0; list-style: none; counter-reset: top; }
.top li { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--ligne); }
.top li span small { display: block; font-size: 14px; color: var(--encre-2); }
.top li strong { white-space: nowrap; }
.note { font-size: 14px; color: var(--encre-2); margin-top: 24px; }

/* ---------- QR code et copie ---------- */
.qr-carte { background: #ffffff; border-radius: var(--rayon); padding: 18px; max-width: 320px; margin: 0 auto; }
.qr-zone svg { display: block; width: 100%; height: auto; }
.copies { display: flex; flex-direction: column; gap: 8px; margin: 16px 0; }
.copie {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center;
  width: 100%; padding: 10px 14px; text-align: left; cursor: pointer;
  background: var(--fond); border: 1px solid var(--ligne); border-radius: var(--rayon);
}
.copie span { font-size: 14px; color: var(--encre-2); grid-column: 1; }
.copie strong { grid-column: 1; font-weight: 700; overflow-wrap: anywhere; letter-spacing: 0.01em; }
.copie small { grid-column: 2; grid-row: 1 / span 2; font-size: 14px; font-weight: 700; text-decoration: underline; }

/* ---------- Récurrentes ---------- */
.btn.bloc { width: 100%; margin-bottom: 12px; border-radius: var(--rayon); }
.aide.gauche { text-align: left; margin: 0 0 14px; font-size: 15px; }

.version { text-align: center; font-size: 13px; color: var(--encre-2); margin: 32px 0 0; }
