:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --text: #0b0b0b;
  --muted: #52514e;
  --border: #dddcd7;
  --accent: #2a78d6;
  --accent-text: #fff;
  --ok: #0ca30c;
  --warn: #e08a00;
  --danger: #d03b3b;
  --hl: rgba(42, 120, 214, .18);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --text: #f0efec;
    --muted: #c3c2b7;
    --border: #383835;
    --accent: #3987e5;
    --hl: rgba(57, 135, 229, .28);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
main { max-width: 960px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.5rem; margin: 8px 0 16px; }
h2 { font-size: 1.1rem; margin: 24px 0 8px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.petit { font-size: .85rem; }
.ligne { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.espace { justify-content: space-between; }

/* ---------- Boutons et champs */
button, .btn {
  font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 10px 14px; border-radius: 10px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px;
}
button.primaire, .btn.primaire { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--danger); }
button:disabled { opacity: .5; }
label { display: block; font-size: .85rem; color: var(--muted); margin: 12px 0 4px; }
input, select, textarea {
  font: inherit; width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 2px solid var(--border); background: var(--surface); color: var(--text); min-height: 44px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
.grille2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

/* Confiance de l'OCR sur un champ pré-rempli */
.conf-haute { border-color: color-mix(in srgb, var(--ok) 60%, var(--border)); }
.conf-basse { border-color: var(--warn); }
.conf-vide { border-style: dashed; }
.indice { font-size: .75rem; margin-left: 4px; }
.indice.basse { color: var(--warn); }

/* ---------- Cartes et listes */
.carte {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px;
}
a.carte { display: block; color: inherit; text-decoration: none; }
.facture { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.facture .montant { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.pastille { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.tag { display: inline-block; font-size: .75rem; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); margin: 2px 4px 0 0; }
.statut { font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: var(--bg); }
.statut.error { color: var(--danger); }

.actions-scan { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions-scan label {
  margin: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 110px; border-radius: var(--radius); cursor: pointer; font-size: 1rem; color: var(--text);
  background: var(--surface); border: 2px dashed var(--border);
}
.actions-scan label.primaire { background: var(--accent); color: var(--accent-text); border: none; }
.actions-scan .icone { font-size: 2rem; line-height: 1; }
.actions-scan input { display: none; }
.zone-depot.survol { outline: 3px solid var(--accent); }

.dossiers { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.dossiers .carte { margin: 0; border-left: 6px solid var(--c, var(--border)); }

/* ---------- Écran de validation */
.validation { display: grid; gap: 16px; }
@media (min-width: 820px) { .validation { grid-template-columns: 1.1fr 1fr; align-items: start; } .apercu-wrap { position: sticky; top: 16px; } }
.apercu { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); background: #fff; }
.apercu img { display: block; width: 100%; height: auto; }
.apercu .boite { position: absolute; border-radius: 3px; cursor: pointer; }
.apercu .boite:hover { background: var(--hl); }
.apercu .boite.active { background: rgba(250, 178, 25, .35); outline: 2px solid #fab219; }
.alerte { border-left: 4px solid var(--warn); }
details pre { white-space: pre-wrap; font-size: .8rem; max-height: 300px; overflow: auto; }
.barre-actions {
  position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); background: var(--bg);
  padding: 10px 0; display: flex; gap: 8px; flex-wrap: wrap;
}
.barre-actions .primaire { flex: 1; justify-content: center; }
.chargement { text-align: center; padding: 48px 16px; }
.spinner { width: 36px; height: 36px; border: 4px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: tourne 1s linear infinite; margin: 0 auto 12px; }
@keyframes tourne { to { transform: rotate(360deg); } }

/* ---------- Statistiques */
.tuiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.tuile .valeur { font-size: 1.6rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.delta { font-size: .85rem; color: var(--muted); }
.histo { display: flex; align-items: flex-end; gap: 2px; height: 180px; padding-top: 22px; border-bottom: 1px solid var(--border); }
.histo .col { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; cursor: default; }
.histo .col::before { content: ""; position: absolute; inset: 0 -1px; } /* zone de survol plus large que la barre */
.histo .barre { width: 100%; max-width: 36px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 0; }
.histo .col.courant .barre { background: color-mix(in srgb, var(--accent) 100%, black 15%); }
.axe { display: flex; gap: 2px; }
.axe span { flex: 1; text-align: center; font-size: .7rem; color: var(--muted); }
.bulle {
  position: fixed; pointer-events: none; background: var(--text); color: var(--bg); font-size: .8rem;
  padding: 6px 10px; border-radius: 8px; z-index: 20; white-space: nowrap; transform: translate(-50%, -110%);
}
.barres-h .rang { display: grid; grid-template-columns: minmax(90px, 30%) 1fr auto; gap: 10px; align-items: center; padding: 6px 0; color: inherit; text-decoration: none; }
.barres-h .rang .piste { height: 12px; }
.barres-h .rang .rempli { height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; min-width: 2px; }
.barres-h .rang .nom { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barres-h .rang .v { font-variant-numeric: tabular-nums; font-size: .9rem; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
td, th { padding: 6px 4px; border-bottom: 1px solid var(--border); text-align: left; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Navigation */
#nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex;
  background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
#nav[hidden] { display: none; }
#nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0;
  font-size: .75rem; color: var(--muted); text-decoration: none; position: relative; min-height: 56px; justify-content: center;
}
#nav a span { font-size: 1.3rem; line-height: 1; }
#nav a.actif { color: var(--accent); }
#badge {
  position: absolute; top: 4px; left: 55%; background: var(--danger); color: #fff; font-size: .7rem;
  border-radius: 999px; padding: 0 6px; min-width: 18px; text-align: center;
}
#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 30; max-width: calc(100% - 32px);
}
.login { max-width: 360px; margin: 15vh auto 0; }
