:root {
  --vert: #14532d; --vert2: #1f7a3f; --vert3: #2f9e57; --vert-clair: #e9f6ee; --rouge: #c62828; --orange: #d9600b; --bleu: #1d64c2;
  --gris: #5f6b76; --gris2: #8a95a0; --bord: #e4e8ec; --bord2: #eef1f4; --fond: #f4f6f5; --texte: #18222b; --radius: 12px;
  --ombre: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .04);
  --ombre2: 0 10px 30px rgba(16, 24, 40, .10);
  --side: #0f2a1c;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.5 "Segoe UI", "Inter", Roboto, Arial, sans-serif; color: var(--texte); background: var(--fond); -webkit-font-smoothing: antialiased; }
a { color: var(--bleu); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 23px; margin: 0 0 2px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 650; }
h3 { font-size: 13px; margin: 18px 0 8px; color: var(--vert2); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--gris); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Mise en page ---------- */
#app { display: flex; min-height: 100vh; }
.sidebar { width: 248px; background: var(--side); background: linear-gradient(180deg, #123522 0%, #0c2418 100%); color: #fff; flex-shrink: 0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 1500; }
.sidebar .brand { padding: 20px 18px 18px; display: flex; align-items: center; gap: 11px; font-weight: 700; font-size: 15px; line-height: 1.25; }
.sidebar .brand .logo { width: 38px; height: 38px; border-radius: 10px; background: linear-gradient(135deg, #34c26a, #1f7a3f); display: grid; place-items: center; flex-shrink: 0; box-shadow: 0 4px 12px rgba(0,0,0,.25); overflow: hidden; }
.sidebar .brand .logo img { width: 100%; height: 100%; object-fit: cover; }
.sidebar .brand small { display: block; font-weight: 400; opacity: .6; font-size: 11.5px; margin-top: 2px; }
.sidebar nav { padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; }
.sidebar nav .sec { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; opacity: .45; padding: 14px 10px 6px; }
.sidebar nav a { display: flex; align-items: center; gap: 11px; color: rgba(255,255,255,.78); padding: 8px 10px; text-decoration: none; border-radius: 8px; font-size: 13.5px; transition: background .12s, color .12s; }
.sidebar nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar nav a.active { background: rgba(255,255,255,.13); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 #4ade80; }
.sidebar nav .ico { width: 18px; display: inline-flex; opacity: .85; }
.ic { flex-shrink: 0; vertical-align: -3px; }
.ic.ok { color: var(--vert2); vertical-align: -2px; }
.sidebar .user { margin: auto 10px 12px; padding: 12px; border-radius: 10px; background: rgba(255,255,255,.06); font-size: 13px; display: flex; gap: 10px; align-items: center; }
.sidebar .user .av { width: 34px; height: 34px; border-radius: 50%; background: #2f9e57; display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.sidebar .user .who { min-width: 0; flex: 1; }
.sidebar .user .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar .user .who span { opacity: .6; font-size: 12px; }
.sidebar .user .links { display: flex; gap: 10px; margin-top: 4px; }
.sidebar .user a { color: #a7f3c0; display: inline-flex; align-items: center; gap: 3px; font-size: 12px; }
main { flex: 1; min-width: 0; padding: 26px 32px 48px; max-width: 1480px; }
.topbar { display: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .muted { margin-top: 2px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Composants ---------- */
.card { background: #fff; border: 1px solid var(--bord); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; box-shadow: var(--ombre); }
.card > h2:first-child { display: flex; align-items: center; gap: 8px; }
.grid { display: grid; gap: 18px; }
.grid > .card { margin-bottom: 0; }
.grid + .grid, .grid + .card, .tiles + .grid { margin-top: 18px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g21 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 1200px) { .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g3 { grid-template-columns: 1fr 1fr; } .g21 { grid-template-columns: 1fr; } }

/* Tuiles d'indicateurs */
.kpi { background: #fff; border: 1px solid var(--bord); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--ombre); position: relative; overflow: hidden; }
.kpi::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--vert3); }
.kpi .label { color: var(--gris); font-size: 12.5px; font-weight: 600; }
.kpi .value { font-size: 25px; font-weight: 700; margin-top: 4px; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--gris); margin-top: 2px; }
.kpi.bleu::before { background: var(--bleu); } .kpi.rouge::before { background: var(--rouge); } .kpi.orange::before { background: var(--orange); }
.kpi.rouge .value { color: var(--rouge); }

.tile { background: #fff; border: 1px solid var(--bord); border-radius: var(--radius); padding: 16px 18px 14px; box-shadow: var(--ombre); display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tile .t-top { display: flex; align-items: center; gap: 8px; color: var(--gris); font-size: 12.5px; font-weight: 600; }
.tile .t-ico { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--vert-clair); color: var(--vert2); }
.tile .t-ico.b { background: #e8f1fc; color: #1d64c2; } .tile .t-ico.r { background: #fdeeee; color: #c62828; } .tile .t-ico.o { background: #fff2e6; color: #c2570b; }
.tile .t-val { font-size: 27px; font-weight: 700; letter-spacing: -.02em; margin-top: 8px; font-variant-numeric: tabular-nums; line-height: 1.15; }
.tile .t-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; }
.tile .t-sub { font-size: 12px; color: var(--gris); margin-top: 4px; }
.delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 650; font-size: 12px; padding: 1px 7px; border-radius: 20px; }
.delta.up { color: #006c10; background: #e6f6ea; } .delta.down { color: #b42318; background: #fdeceb; } .delta.eq { color: var(--gris); background: #eef1f4; }
.meter { height: 8px; border-radius: 4px; background: #eef1f4; margin-top: 10px; overflow: hidden; }
.meter > div { height: 100%; border-radius: 4px; background: #257de0; }

/* Cartes de graphiques */
.chart-card .c-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.chart-card .c-head h2 { margin: 0; }
.chart-card .c-head .muted { font-size: 12px; }
.chart-card .c-body { min-height: 60px; }
.chart-card .c-body svg .hit { cursor: default; }
.chart-card .c-body svg .hit.on[fill="transparent"] { fill: rgba(25, 34, 43, .05); }
.chart-card .c-body .t { font-size: 13px; }
.seg { display: inline-flex; background: #eef1f4; border-radius: 8px; padding: 2px; gap: 2px; flex-shrink: 0; }
.seg button { border: 0; background: none; padding: 4px 10px; border-radius: 6px; font: inherit; font-size: 12.5px; color: var(--gris); cursor: pointer; display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.seg button.on { background: #fff; color: var(--texte); font-weight: 600; box-shadow: 0 1px 2px rgba(16,24,40,.12); }
.seg.lg button { padding: 6px 12px; font-size: 13px; }
.chart-tip { position: fixed; z-index: 4000; pointer-events: none; background: #18222b; color: #fff; padding: 6px 10px; border-radius: 7px; font-size: 12.5px; box-shadow: var(--ombre2); opacity: 0; transition: opacity .08s; white-space: nowrap; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.alertes { display: flex; flex-direction: column; gap: 6px; background: #fff8eb; border: 1px solid #f6dfb3; border-radius: var(--radius); padding: 12px 16px; margin-bottom: 18px; }
.alertes div { display: flex; gap: 8px; align-items: center; }
.alertes .ic { color: #c2570b; }

/* Boutons */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid #d5dbe1; background: #fff; color: var(--texte); padding: 7px 14px; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 550; text-decoration: none !important; white-space: nowrap; box-shadow: 0 1px 2px rgba(16,24,40,.05); transition: background .12s, border-color .12s; }
.btn:hover { background: #f5f7f9; border-color: #c4ccd4; }
.btn.primary { background: var(--vert2); border-color: var(--vert2); color: #fff; }
.btn.primary:hover { background: var(--vert); border-color: var(--vert); }
.btn.danger { color: var(--rouge); border-color: #f1c0c0; }
.btn.danger:hover { background: #fdecea; }
.btn.sm { padding: 3px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: default; }

/* Tableaux */
table.t { width: 100%; border-collapse: collapse; background: #fff; }
table.t th { text-align: left; font-weight: 650; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--gris); background: #f8faf9; border-bottom: 1px solid var(--bord); padding: 9px 12px; white-space: nowrap; }
table.t td { border-bottom: 1px solid var(--bord2); padding: 9px 12px; vertical-align: top; font-variant-numeric: tabular-nums; }
table.t tr:last-child td { border-bottom: 0; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: #f3f9f5; }
table.t tr.annule td { color: #9aa5b1; text-decoration: line-through; }
table.t tr.tot td { font-weight: 700; background: #f8faf9; border-top: 1px solid var(--bord); }
.table-wrap { overflow-x: auto; border: 1px solid var(--bord); border-radius: var(--radius); background: #fff; box-shadow: var(--ombre); }
.card .table-wrap { box-shadow: none; }
.table-wrap table.t { border: 0; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.b-vert { background: #e6f6ea; color: #17692f; } .b-rouge { background: #fdeceb; color: #b42318; }
.b-orange { background: #fff1e3; color: #b54708; } .b-gris { background: #eef1f4; color: var(--gris); } .b-bleu { background: #e8f1fc; color: #1d58a8; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

/* Formulaires */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; background: #fff; border: 1px solid var(--bord); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--ombre); }
.filters label { font-size: 12px; color: var(--gris); font-weight: 600; display: flex; flex-direction: column; gap: 4px; }
input, select, textarea { font: inherit; padding: 7px 10px; border: 1px solid #cfd6dd; border-radius: 8px; background: #fff; color: var(--texte); min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(47, 158, 87, .18); border-color: var(--vert3); }
.form { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px 16px; }
.form .f { display: flex; flex-direction: column; gap: 4px; }
.form .f.full { grid-column: 1 / -1; }
.form .f > span { font-size: 12.5px; color: #3e4c59; font-weight: 600; }
.form .f > span .req { color: var(--rouge); }
.form .hint { font-size: 12px; color: var(--gris); font-weight: 400; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 4px 0; }
.checks label { display: flex; align-items: center; gap: 6px; font-weight: 400; font-size: 13.5px; color: var(--texte); }
.photo-prev { width: 120px; height: 86px; object-fit: cover; border-radius: 8px; border: 1px solid var(--bord); background: #f1f3f5; display: block; margin-top: 4px; }

/* Fenêtre modale */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.5); backdrop-filter: blur(2px); display: flex; align-items: flex-start; justify-content: center; z-index: 2000; padding: 40px 12px; overflow-y: auto; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 640px; box-shadow: 0 24px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 900px; }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--bord); display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 15px; }
.modal header button { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--gris); line-height: 1; }
.modal .body { padding: 18px 20px; }
.modal footer { padding: 12px 20px; border-top: 1px solid var(--bord); display: flex; justify-content: flex-end; gap: 8px; background: #fafbfb; border-radius: 0 0 14px 14px; }

#toast { position: fixed; bottom: 20px; right: 20px; z-index: 3000; display: flex; flex-direction: column; gap: 8px; }
#toast div { background: #18222b; color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: var(--ombre2); max-width: 380px; }
#toast div.err { background: var(--rouge); }
#toast div.ok { background: var(--vert2); }

/* Connexion */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; width: 100%; background: radial-gradient(1200px 600px at 10% 0%, #1f7a3f 0%, transparent 60%), radial-gradient(900px 500px at 100% 100%, #2f9e57 0%, transparent 55%), #0f2a1c; }
.login-box { background: #fff; padding: 34px 32px; border-radius: 18px; width: 380px; max-width: 92vw; box-shadow: 0 30px 70px rgba(0,0,0,.35); }
.login-box .logo { width: 48px; height: 48px; border-radius: 12px; background: linear-gradient(135deg, #34c26a, #1f7a3f); display: grid; place-items: center; color: #fff; margin-bottom: 14px; }
.login-box h1 { color: var(--vert); font-size: 21px; }
.login-box label { display: block; margin-top: 14px; font-size: 13px; font-weight: 600; }
.login-box input { width: 100%; margin-top: 5px; padding: 11px 12px; }
.login-box .btn { width: 100%; justify-content: center; margin-top: 20px; padding: 11px; }

/* Anciens graphiques simples (encore utilisés par quelques pages) */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 190px; padding-top: 10px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.bars .bar div.b { width: 100%; max-width: 24px; background: #257de0; border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.bars .bar span { font-size: 11px; color: var(--gris); margin-top: 4px; white-space: nowrap; }
.hbar { margin-bottom: 10px; }
.hbar .top { display: flex; justify-content: space-between; font-size: 13px; }
.hbar .track { background: #eef1f4; border-radius: 4px; height: 10px; margin-top: 3px; }
.hbar .fill { background: #257de0; height: 100%; border-radius: 4px; }

/* Carte */
.map-layout { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 16px; height: calc(100vh - 130px); min-height: 480px; }
.map-layout .map { border: 1px solid var(--bord); border-radius: var(--radius); height: 100%; box-shadow: var(--ombre); }
.map-side { overflow-y: auto; }
.map-side .card { margin-bottom: 12px; }
.mini-map { height: 270px; border-radius: 10px; border: 1px solid var(--bord); }
.pick-map { height: 320px; border-radius: 10px; border: 1px solid var(--bord); }
.stat-line { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--bord2); }
.stat-line:last-of-type { border-bottom: 0; }
.stat-line > span:first-child { color: var(--gris); }
.leaflet-popup-content { font-size: 13px; }

/* Fiche d'un site */
.site-hero { display: flex; align-items: center; gap: 16px; background: #fff; border: 1px solid var(--bord); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--ombre); margin-bottom: 18px; flex-wrap: wrap; }
.site-hero .sh-ico { width: 54px; height: 54px; border-radius: 14px; background: linear-gradient(135deg, #34c26a, #1f7a3f); color: #fff; display: grid; place-items: center; flex-shrink: 0; }
.site-hero .sh-main { flex: 1; min-width: 220px; }
.site-hero .sh-code { font: 700 13px ui-monospace, Consolas, monospace; color: var(--vert2); letter-spacing: .04em; }
.site-hero h1 { margin: 2px 0 6px; }
.site-hero .sh-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; color: var(--gris); font-size: 13px; }
.site-hero .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.photos { display: flex; gap: 12px; margin-top: 12px; flex-wrap: wrap; }

.alloc { margin-top: 10px; border: 1px dashed #9fd8b2; background: #f4fbf6; border-radius: 10px; padding: 10px 12px; }
.alloc .stat-line { border-bottom-color: #dcefe2; }
.empty { padding: 30px; text-align: center; color: var(--gris); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; }
.matrix select { padding: 3px 4px; font-size: 12.5px; }
.matrix td, .matrix th { text-align: center; }
.matrix td:first-child, .matrix th:first-child { text-align: left; }
.receipt-box { background: #e9ecef; padding: 20px; border-radius: var(--radius); }
.receipt-box .receipt { box-shadow: 0 4px 14px rgba(0,0,0,.15); }
.sticker { width: 70mm; border: 2px solid var(--vert); border-radius: 8px; padding: 4mm; text-align: center; margin: 0 auto; background: #fff; }
.sticker svg { width: 45mm; height: auto; }
.bulletin { max-width: 720px; margin: 0 auto; background: #fff; padding: 20px; }
@page a4 { size: A4; margin: 15mm; }
@media print { .print-area.a4 { page: a4; width: auto !important; position: static !important; } }

/* Rapports : aperçu de la page A4 */
.rpt-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 18px; align-items: start; }
.rpt-side { position: sticky; top: 16px; }
.rpt-side .card { margin-bottom: 14px; }
.rpt-side label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--gris); margin-bottom: 10px; }
.rpt-side .checks { flex-direction: column; gap: 7px; }
.rpt-side .btn { width: 100%; justify-content: center; margin-top: 8px; }
.rpt-stage { background: #e6e9ec; border-radius: var(--radius); padding: 24px; overflow-x: auto; }
.rpt-page { background: #fff; width: 210mm; max-width: 100%; min-height: 297mm; margin: 0 auto; padding: 16mm 15mm; box-shadow: 0 6px 24px rgba(0,0,0,.12); border-radius: 2px; }
@media (max-width: 1100px) { .rpt-layout { grid-template-columns: 1fr; } .rpt-side { position: static; } }

/* Guide de démarrage */
.demarrage { border-left: 4px solid var(--orange); background: #fff8e1; }

/* ---------- Téléphone et tablette ---------- */
@media (max-width: 860px) {
  #app { flex-direction: column; }
  .topbar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 1400; background: #123522; color: #fff; padding: 10px 14px; font-weight: 700; }
  .topbar button { background: rgba(255,255,255,.1); border: 0; color: #fff; border-radius: 8px; padding: 6px; display: grid; cursor: pointer; }
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--ombre2); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open::after { content: ''; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1450; }
  main { padding: 16px 14px 40px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .tiles.g4 { grid-template-columns: 1fr 1fr; }
  .form { grid-template-columns: 1fr; }
  .map-layout { grid-template-columns: 1fr; height: auto; } .map-layout .map { height: 60vh; }
  .rpt-stage { padding: 8px; } .rpt-page { padding: 8mm 6mm; min-height: 0; }
}
@media (max-width: 480px) { .tiles.g4 { grid-template-columns: 1fr; } .tile .t-val { font-size: 23px; } }
.tile .t-top { min-height: 28px; }
.sidebar { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.18) transparent; }
/* Logo Usafi Kwetu (rond, fond blanc) */
.sidebar .brand .logo { background: #fff; padding: 1px; width: 44px; height: 44px; border-radius: 50%; }
.sidebar .brand .logo img { border-radius: 50%; object-fit: contain; }
.login-box .logo-usafi { width: 96px; height: 96px; display: block; margin: 0 auto 10px; }
.login-box h1 { text-align: center; } .login-box > .muted { text-align: center; }
