:root {
  --bleu: #1f5f8b;
  --bleu-clair: #e3eef6;
  --fond: #f4f6f8;
  --texte: #1c2329;
  --gris: #6b7680;
  --bordure: #c9d1d8;
  --rouge: #b3261e;
  --vert: #2e7d32;
  --orange: #b26a00;
  --rayon: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fond);
  color: var(--texte);
  font-size: 17px;
}
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  background: var(--bleu); color: #fff;
}
.topbar h1 { margin: 0; font-size: 1.2rem; }
.titre { color: inherit; text-decoration: none; }
main { padding: 16px; max-width: 720px; margin: 0 auto; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
section { display: flex; flex-direction: column; gap: 12px; }

.card { background: #fff; border-radius: var(--rayon); padding: 16px; box-shadow: 0 1px 3px rgb(0 0 0 / .08); }
form.card { display: flex; flex-direction: column; gap: 10px; }
label { font-weight: 600; font-size: .95rem; }
input, textarea {
  font: inherit; font-size: 1rem; padding: 12px; width: 100%;
  border: 1px solid var(--bordure); border-radius: 8px; background: #fff;
}
textarea { resize: vertical; }

.btn {
  font: inherit; font-size: 1rem; font-weight: 600; padding: 14px;
  border: 0; border-radius: 8px; background: var(--bleu); color: #fff; cursor: pointer;
}
.btn:disabled { opacity: .6; }
.btn-grand { font-size: 1.1rem; padding: 18px; }
.btn-secondaire { background: var(--bleu-clair); color: var(--bleu); }
.btn-danger { background: none; color: var(--rouge); border: 1px solid var(--rouge); }
.btn-link { background: none; border: 0; color: inherit; font-size: .95rem; text-decoration: underline; cursor: pointer; }
.actions-photo { display: grid; grid-template-columns: 2fr 1fr; gap: 8px; }

.muted { color: var(--gris); }
.petit { font-size: .85rem; margin: 0; }
.erreur { color: var(--rouge); margin: 0; }
.ok { color: var(--vert); }
.retour { color: var(--bleu); text-decoration: none; font-weight: 600; }

/* Liste */
.liste { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.liste a {
  display: flex; gap: 12px; align-items: center; padding: 8px;
  background: #fff; border-radius: var(--rayon); color: inherit; text-decoration: none;
  box-shadow: 0 1px 3px rgb(0 0 0 / .08);
}
.vignette {
  flex: none; width: 72px; height: 72px; border-radius: 8px; object-fit: cover;
  background: var(--bleu-clair); display: grid; place-items: center; font-size: 1.6rem;
}
.liste .infos { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.liste .ligne1 { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600;
  background: #fff3e0; color: var(--orange);
}
.badge.valide { background: #e8f5e9; color: var(--vert); }

/* Grille de photos */
.grille { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.grille:empty::before { content: "Aucune photo pour l'instant."; color: var(--gris); grid-column: 1 / -1; }
.tuile {
  position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden;
  background: var(--bleu-clair); border: 0; padding: 0; cursor: pointer;
}
.tuile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tuile .etat {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 3px 4px;
  background: rgb(0 0 0 / .6); color: #fff; font-size: .7rem; text-align: center;
}
.tuile.envoi img { opacity: .5; }
.tuile.erreur .etat { background: var(--rouge); }
.progression { position: absolute; left: 0; top: 0; height: 4px; background: var(--bleu); transition: width .2s; }

.tuile.selection { outline: 3px solid var(--bleu); outline-offset: 2px; }
.tuile.analyse-erreur .etat { background: var(--rouge); }

/* Photo sélectionnée et extractions */
.panneau { display: flex; flex-direction: column; gap: 10px; padding: 10px; }
.cadre-photo { position: relative; border-radius: 8px; overflow: hidden; background: #000; }
.cadre-photo img { display: block; width: 100%; height: auto; cursor: zoom-in; }
#zones { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#zones rect { fill: transparent; stroke-width: 2; vector-effect: non-scaling-stroke; }
#zones rect.ocr { stroke: #4fc3f7; }
#zones rect.code { stroke: #66bb6a; stroke-width: 3; }
#zones rect.actif { fill: rgb(255 235 59 / .35); stroke: #ffeb3b; stroke-width: 3; }
.boutons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.extractions { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.extractions li {
  display: flex; gap: 10px; align-items: baseline; padding: 8px 10px;
  border-radius: 8px; background: var(--fond); cursor: pointer;
}
.extractions li.actif { background: #fff9c4; }
.extractions .icone { flex: none; width: 1.4em; text-align: center; }
.extractions .texte { flex: 1; min-width: 0; overflow-wrap: anywhere; user-select: text; }
.extractions .meta { flex: none; font-size: .75rem; color: var(--gris); text-align: right; }
.extractions .faible .texte { color: var(--gris); }
.erreur-analyse { color: var(--rouge); }

/* Liste : filtres et export */
.filtres { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; }
.filtres select { font: inherit; padding: 10px; border: 1px solid var(--bordure); border-radius: 8px; background: #fff; }
.filtres .btn { padding: 10px 12px; text-decoration: none; text-align: center; font-size: .9rem; }

/* Validation */
.champ-valide { display: flex; flex-direction: column; gap: 4px; }
input.suggere { background: #fff9c4; border-color: #e0c200; }
.suggere-aide { color: var(--orange); }
.puces { display: flex; flex-wrap: wrap; gap: 6px; }
.puces:empty { display: none; }
.puces button, .copier button {
  font: inherit; font-size: .85rem; padding: 6px 10px; border-radius: 999px;
  border: 1px solid var(--bordure); background: #fff; color: var(--texte); cursor: pointer;
}
.puces button small { color: var(--gris); }
.btn-valider { background: var(--vert); }
.btn-valider.deja { background: var(--bleu-clair); color: var(--bleu); }
form hr { border: 0; border-top: 1px solid var(--bordure); margin: 6px 0; width: 100%; }
.copier { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px; border-radius: 8px; background: #fff9c4; }
.copier button { background: var(--bleu); color: #fff; border-color: var(--bleu); }
@keyframes flash { from { background: #c8e6c9; } to { background: #fff; } }
input.flash { animation: flash 1s ease-out; }

/* Menu */
#menu { display: flex; gap: 14px; align-items: center; }
#menu a { color: #fff; text-decoration: none; font-size: .95rem; }
#lien-admin { background: rgb(255 255 255 / .18); padding: 4px 10px; border-radius: 999px; }

/* Compte et administration */
h2 { font-size: 1.1rem; margin: 0; }
h3 { font-size: .95rem; margin: 8px 0 0; }
.admin-bloc { display: flex; flex-direction: column; gap: 10px; }
.ligne-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.ligne-form .btn { padding: 10px 14px; }
.liste-admin { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.liste-admin li {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 8px; border-radius: 8px; background: var(--fond);
}
.liste-admin li input, .liste-admin li select { flex: 1; min-width: 120px; padding: 8px; }
.liste-admin li .nom { flex: 1; min-width: 100px; font-weight: 600; overflow-wrap: anywhere; }
.liste-admin .petit-btn {
  font: inherit; font-size: .85rem; padding: 7px 10px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--bordure); background: #fff; color: var(--texte);
}
.liste-admin .petit-btn.primaire { background: var(--bleu); color: #fff; border-color: var(--bleu); }
.liste-admin .petit-btn.danger { color: var(--rouge); border-color: var(--rouge); }
.liste-admin .form-mdp { display: flex; gap: 8px; width: 100%; }
select { font: inherit; font-size: 1rem; padding: 10px; border: 1px solid var(--bordure); border-radius: 8px; background: #fff; }

/* Visionneuse */
dialog#visionneuse {
  border: 0; padding: 0; background: #000; width: 100vw; height: 100dvh;
  max-width: none; max-height: none; margin: 0;
}
dialog#visionneuse::backdrop { background: #000; }
#visionneuse-img { width: 100%; height: calc(100% - 80px); object-fit: contain; display: block; }
.visionneuse-actions { display: flex; gap: 8px; padding: 12px 16px; justify-content: space-between; }
.visionneuse-actions .btn-danger { color: #ff8a80; border-color: #ff8a80; }

#toast {
  position: fixed; left: 16px; right: 16px; bottom: max(16px, env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto; padding: 12px 16px; border-radius: 8px;
  background: #263238; color: #fff; box-shadow: 0 4px 12px rgb(0 0 0 / .25); z-index: 20;
}
#toast.erreur { background: var(--rouge); }

[hidden] { display: none !important; }
