:root {
  --green: #007a3d;
  --green-2: #00a651;
  --green-bg: #e8f5ee;
  --orange: #f08c00;
  --red: #c62828;
  --ink: #1b1f1d;
  --muted: #5f6b65;
  --line: #d5ddd8;
  --bg: #f4f6f5;
  --card: #fff;
  --radius: 12px;
  --tap: 48px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.spacer { flex: 1; }

/* ---------- Barre supérieure ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--green); color: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.topbar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar-title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 17px; }
.topbar-title small { opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: var(--tap); height: var(--tap); border: 0; border-radius: 50%;
  background: rgba(255,255,255,.15); color: #fff; font-size: 22px;
}
.sync-pill {
  display: flex; align-items: center; gap: 6px; flex-shrink: 0; max-width: 48%; white-space: nowrap; overflow: hidden;
  border: 0; border-radius: 99px; padding: 8px 12px; min-height: 40px;
  background: rgba(255,255,255,.18); color: #fff; font-size: 13px; font-weight: 600;
}
.sync-pill .dot { width: 10px; height: 10px; border-radius: 50%; background: #bbb; }
.sync-pill.ok .dot { background: #7CFC9A; }
.sync-pill.pending .dot { background: #ffc94d; }
.sync-pill.offline .dot { background: #ff8a80; }
.sync-pill.busy .dot { background: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .2; } }

.banner { padding: 10px 14px; background: #fff7e0; border-bottom: 1px solid #f2d27a; font-size: 14px; }
.banner.warn { background: #fdecea; border-color: #f5b5ad; }
.link { background: none; border: 0; color: var(--green); font-weight: 700; text-decoration: underline; font-size: inherit; }

main { max-width: 820px; margin: 0 auto; padding: 14px 14px 110px; }

/* ---------- Cartes / listes ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.card h3 { margin: 0 0 8px; font-size: 17px; }
.agent-card { display: flex; align-items: center; justify-content: space-between; }
.agent-card small { display: block; color: var(--muted); }

.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.toolbar input { flex: 1; }
.toolbar select { width: auto; }

.list { display: flex; flex-direction: column; gap: 10px; }
.item {
  display: block; width: 100%; text-align: left; border: 0; cursor: pointer;
  background: var(--card); border-radius: var(--radius); padding: 12px 14px;
  box-shadow: 0 1px 2px rgba(0,0,0,.06); font: inherit; color: inherit;
  border-left: 5px solid var(--orange);
}
.item.done { border-left-color: var(--green-2); }
.item .l1 { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; }
.item .l2 { color: var(--muted); font-size: 14px; margin-top: 2px; }
.item .tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.tag { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: #eee; color: #444; }
.tag.orange { background: #fff1db; color: #8a5200; }
.tag.green { background: var(--green-bg); color: var(--green); }
.tag.grey { background: #eceff1; color: #546e7a; }
.tag.red { background: #fdecea; color: var(--red); }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.home-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 24px; }

.fab {
  position: fixed; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 15;
  border: 0; border-radius: 99px; padding: 16px 22px; font-size: 17px; font-weight: 700;
  background: var(--green); color: #fff; box-shadow: 0 4px 14px rgba(0,0,0,.25);
}

/* ---------- Formulaires ---------- */
input, select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  font: inherit; font-size: 17px; color: var(--ink);
  border: 1.5px solid var(--line); border-radius: 10px; background: #fff;
}
input:focus, select:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(0,122,61,.15); }
.f { display: block; margin-bottom: 12px; font-size: 14px; font-weight: 600; color: #34403a; }
.f input, .f select { margin-top: 4px; font-weight: 400; }
.star { color: var(--red); }
.f.invalid input { border-color: var(--red); background: #fffafa; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .row2 { grid-template-columns: 1fr; gap: 0; } }

fieldset { border: 0; padding: 0; margin: 0 0 12px; }
legend { font-size: 14px; font-weight: 600; color: #34403a; margin-bottom: 4px; }
.seg { display: flex; gap: 8px; }
.seg label { flex: 1; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span {
  display: flex; align-items: center; justify-content: center; min-height: var(--tap);
  border: 1.5px solid var(--line); border-radius: 10px; background: #fff; font-weight: 700;
}
.seg input:checked + span { background: var(--green); border-color: var(--green); color: #fff; }

.gps { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 10px 16px; border-radius: 10px;
  border: 1.5px solid var(--green); background: #fff; color: var(--green);
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
}
.btn.small { min-height: 40px; padding: 6px 12px; font-size: 14px; }
.btn.primary { background: var(--green); color: #fff; }
.btn.success { background: var(--green-2); border-color: var(--green-2); color: #fff; }
.btn.danger { border-color: var(--red); color: var(--red); }
.btn.ghost { border-color: var(--line); color: #34403a; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.actions-col { display: flex; flex-direction: column; gap: 10px; }

/* ---------- Étapes ---------- */
.steps {
  position: sticky; top: 68px; z-index: 10;
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  margin: -14px -14px 10px; padding: 10px 14px; background: var(--bg);
}
.steps button {
  flex: 0 0 auto; border: 1.5px solid var(--line); background: #fff; border-radius: 99px;
  padding: 8px 14px; font: inherit; font-size: 14px; font-weight: 600; color: #34403a;
}
.steps button.active { background: var(--green); border-color: var(--green); color: #fff; }
.steps button.ok:not(.active) { border-color: var(--green-2); color: var(--green); }
.count { display: inline-block; min-width: 22px; padding: 0 6px; border-radius: 99px; background: rgba(0,0,0,.1); font-size: 12px; text-align: center; }
.saved { font-size: 12px; color: var(--muted); text-align: right; min-height: 16px; margin-bottom: 6px; }
.step { background: var(--card); border-radius: var(--radius); padding: 16px 14px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.step-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 12;
  display: flex; gap: 10px; justify-content: space-between;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid var(--line);
}
.step-nav .btn { flex: 1; max-width: 400px; }

.list-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.list-head p { margin: 0; }
.people { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.person {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  border: 1.5px solid var(--line); border-radius: 10px; background: #fff; padding: 8px 10px; font: inherit; color: inherit;
}
.person .num { flex: 0 0 32px; height: 32px; border-radius: 50%; background: var(--green-bg); color: var(--green); font-weight: 700; display: flex; align-items: center; justify-content: center; }
.person .info { flex: 1; min-width: 0; }
.person .info b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person .info small { color: var(--muted); }
.person img { width: 70px; height: 28px; object-fit: contain; }
.person .nosig { font-size: 12px; color: var(--orange); font-weight: 600; }

.checks { list-style: none; padding: 0; margin: 0; }
.checks li { padding: 6px 0; border-bottom: 1px dashed var(--line); }
.checks li.ok::before { content: "✔ "; color: var(--green-2); font-weight: 700; }
.checks li.ko::before { content: "✖ "; color: var(--red); font-weight: 700; }
.checks li.warn::before { content: "! "; color: var(--orange); font-weight: 700; }

/* ---------- Dialogues ---------- */
dialog {
  width: min(640px, 100vw); max-width: 100vw; max-height: 100dvh; margin: auto;
  border: 0; border-radius: 16px; padding: 18px; overflow: auto;
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h3 { margin: 0 0 12px; }
@media (max-width: 520px) {
  dialog { width: 100vw; min-height: 100dvh; border-radius: 0; }
}
@media (max-width: 520px) {
  .dlg-actions .spacer { display: none; }
  .dlg-actions .btn { flex: 1 1 40%; }
  .dlg-actions #btnPersonSave { flex-basis: 100%; order: 3; }
}
.dlg-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 14px; position: sticky; bottom: -18px; background: #fff; padding: 10px 0; }
.sig-wrap { border: 1.5px dashed var(--line); border-radius: 10px; padding: 10px; }
.sig-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
#sigCanvas { display: block; width: 100%; aspect-ratio: 2.5 / 1; background: #fff; border: 1px solid var(--line); border-radius: 8px; touch-action: none; }

dialog.full { width: 100vw; height: 100dvh; max-height: 100dvh; padding: 0; border-radius: 0; display: none; flex-direction: column; }
dialog.full[open] { display: flex; }
.pdf-bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: var(--green); color: #fff; }
#pdfFrame { flex: 1; border: 0; width: 100%; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 50;
  background: #222; color: #fff; padding: 12px 18px; border-radius: 10px; max-width: 90vw; font-size: 15px;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
}

/* ---------- Fenêtres de confirmation (confirmer() dans app.js) ---------- */
dialog.confirmation {
  width: min(420px, calc(100vw - 32px)); min-height: 0; max-height: calc(100dvh - 32px);
  padding: 0; border-radius: 20px; overflow: auto; box-shadow: 0 24px 64px rgba(0,0,0,.3);
}
dialog.confirmation::backdrop { background: rgba(8,30,18,.55); }
dialog.confirmation[open] { animation: cf-entree .18s ease-out; }
@keyframes cf-entree { from { opacity: 0; transform: translateY(14px) scale(.97); } }
@media (prefers-reduced-motion: reduce) { dialog.confirmation[open] { animation: none; } }
.cf-corps { padding: 24px 20px 18px; text-align: center; }
.cf-icone { width: 60px; height: 60px; margin: 0 auto 14px; border-radius: 50%; display: grid; place-items: center; }
.cf-icone svg { width: 30px; height: 30px; }
.ton-success .cf-icone { background: var(--green-bg); color: var(--green); }
.ton-warn .cf-icone { background: #fff3df; color: #a85400; }
.ton-danger .cf-icone { background: #fdecea; color: var(--red); }
.ton-info .cf-icone { background: #e6f0fb; color: #1565c0; }
.cf-titre { margin: 0 0 8px; font-size: 19px; line-height: 1.25; }
.cf-message { margin: 0; color: var(--muted); white-space: pre-line; text-align: center; }
.cf-message:empty { display: none; }
.cf-details { margin: 10px 0 0; padding: 10px 12px 10px 30px; text-align: left; background: #fff8ec; border-radius: 10px; color: #6b4a14; font-size: 14px; }
.cf-details li + li { margin-top: 4px; }
.cf-choix { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 12px; }
.cf-choix .btn { min-height: 44px; border-color: var(--green); color: var(--green); }

/* Village : état par rapport au référentiel */
.aide-village { display: block; margin-top: 4px; font-size: 13px; font-weight: 500; color: var(--muted); min-height: 18px; }
.aide-village.liste { color: var(--green); }
.aide-village.hors { color: #a85400; font-weight: 600; }
.aide-village.inconnu { color: var(--red); font-weight: 600; }
.cf-saisie { display: block; margin-top: 16px; text-align: left; font-size: 14px; font-weight: 600; color: #34403a; }
.cf-saisie input {
  display: block; width: 100%; margin-top: 6px; min-height: var(--tap); padding: 10px 12px;
  border: 1.5px solid var(--line); border-radius: 10px; font: inherit; font-weight: 400; color: var(--ink);
}
.cf-saisie input:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(0,122,61,.15); }
.cf-actions { display: flex; gap: 10px; margin-top: 22px; }
.cf-actions .btn { flex: 1; }
.cf-ok { color: #fff; }
.ton-success .cf-ok, .ton-info .cf-ok { background: var(--green); border-color: var(--green); }
.ton-warn .cf-ok { background: #a85400; border-color: #a85400; }
.ton-danger .cf-ok { background: var(--red); border-color: var(--red); }
.cf-ok:disabled { opacity: .45; }
@media (max-width: 400px) {
  .cf-actions { flex-direction: column-reverse; }
}

/* ---------- Plateforme : statuts serveur, photos, connexion ---------- */
.tag.blue { background: #e6f0fb; color: #1565c0; }
.item.corr-item { border-left-color: var(--red); }
.item.valid { border-left-color: var(--green); }
.card.corr { border-left: 5px solid var(--orange); background: #fff8ec; }
.card.corr.ok { border-left-color: var(--green-2); background: var(--green-bg); }
.card.corr.ko { border-left-color: var(--red); background: #fdecea; }
.card.corr b { display: block; margin-bottom: 4px; }
.card.corr .com { white-space: pre-line; }
.conflit-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 4px; }
.error { color: var(--red); font-weight: 600; background: #fdecea; padding: 8px 10px; border-radius: 8px; }
.login-logos { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.login-logos img { height: 48px; }
.actions-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-top: 8px; }
.thumbs.inline { display: flex; flex-wrap: wrap; margin: 0; }
.thumb { position: relative; padding: 0; border: 1.5px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; width: 84px; height: 84px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .st { position: absolute; right: 3px; bottom: 3px; font-size: 11px; background: rgba(0,0,0,.6); color: #fff; border-radius: 99px; padding: 0 6px; }
.photo-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.photo-view { flex: 1; display: flex; align-items: center; justify-content: center; background: #111; overflow: auto; }
.photo-view img { max-width: 100%; max-height: 100%; }
.locked input, .locked select { background: #f3f5f4; color: #555; }
.small { font-size: 13px; }
