:root {
  --bg: #0f172a;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #1d4ed8;
  --brand-ink: #ffffff;
  --shadow: 0 10px 30px rgba(15, 23, 42, .12);
  --radius: 14px;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: #f1f5f9;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
a { color: var(--brand); }

/* ---------- Carte (index) ---------- */
.app {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: 100vh;
}
#map { height: 100vh; width: 100%; }

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar header {
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 16px; letter-spacing: -.01em;
}
.brand .dot { width: 26px; height: 26px; border-radius: 8px;
  background: linear-gradient(135deg, #1d4ed8, #06b6d4); display:grid; place-items:center; color:#fff; font-size:14px; }
.subtitle { color: var(--muted); font-size: 12.5px; margin-top: 4px; }

.toolbar { padding: 12px 18px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 8px 12px; border-radius: 10px; font-weight: 600; font-size: 13px;
  display: inline-flex; gap: 6px; align-items: center;
}
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn:hover { filter: brightness(.97); }
.count { margin-left: auto; color: var(--muted); font-size: 12px; }

.filters { padding: 10px 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.filters .filters-head { display:flex; justify-content: space-between; align-items:center; padding: 4px 6px 8px; }
.filters .filters-head span { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.filters .filters-head button { background: none; border: none; color: var(--brand); font-size: 12px; font-weight: 600; }

.stage-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 10px; border: 1px solid transparent;
  user-select: none;
}
.stage-row:hover { background: #f8fafc; }
.stage-row.off { opacity: .42; }
.stage-row .swatch { width: 26px; height: 26px; border-radius: 8px; display:grid; place-items:center; color:#fff; font-size: 13px; flex: 0 0 auto; box-shadow: inset 0 0 0 1px rgba(255,255,255,.25); }
.stage-row .num { font-weight: 800; font-variant-numeric: tabular-nums; width: 20px; text-align: center; color: var(--muted); }
.stage-row .name { font-size: 13.5px; font-weight: 600; flex: 1; line-height: 1.2; }
.stage-row .badge { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 22px; text-align: right; }

/* Marqueurs carte */
.photo-marker {
  width: 38px; height: 38px; border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid #fff; box-shadow: 0 3px 8px rgba(0,0,0,.35);
  background-size: cover; background-position: center;
  display: grid; place-items: center;
}
.photo-marker .pin-num {
  transform: rotate(45deg);
  background: rgba(0,0,0,.55); color: #fff; font-size: 10px; font-weight: 800;
  width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center;
  margin-top: -10px; margin-left: 12px;
}
.cluster { background: var(--brand); color:#fff; border-radius: 50%; display:grid; place-items:center;
  font-weight: 800; border: 3px solid #fff; box-shadow: 0 3px 8px rgba(0,0,0,.3); }

/* Popup carte */
.leaflet-popup-content { margin: 0; width: 240px !important; }
.popup img { width: 100%; height: 160px; object-fit: cover; display: block; border-radius: 10px 10px 0 0; cursor: zoom-in; }
.popup .meta { padding: 10px 12px; }
.popup .chip { display:inline-flex; gap:6px; align-items:center; font-size:11px; font-weight:700; color:#fff; padding: 3px 8px; border-radius: 999px; }
.popup .note { font-size: 12.5px; color: var(--ink); margin: 8px 0 4px; }
.popup .when { font-size: 11px; color: var(--muted); }
.popup .nogps { font-size: 11px; color: #b45309; }

/* Lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(2,6,23,.92); display: none; place-items: center; z-index: 9999; padding: 20px; }
.lightbox.open { display: grid; }
.lightbox img { max-width: 96vw; max-height: 88vh; border-radius: 12px; box-shadow: var(--shadow); }
.lightbox .close { position: absolute; top: 16px; right: 20px; color:#fff; background:rgba(255,255,255,.12); border:none; border-radius: 10px; padding: 8px 12px; font-size: 14px; }

/* Mobile carte */
.mobile-toggle { display: none; }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 86%; max-width: 340px; z-index: 1200; transform: translateX(-100%); transition: transform .25s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  #map { height: 100vh; }
  .mobile-toggle { display: inline-flex; position: fixed; top: 12px; left: 12px; z-index: 1100; }
}

/* ---------- Capture (PWA) ---------- */
.capture {
  max-width: 520px; margin: 0 auto; min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; padding: 16px 16px 28px;
}
.capture .top { display:flex; align-items:center; justify-content: space-between; margin-bottom: 12px; }
.capture h1 { font-size: 18px; margin: 0; letter-spacing: -.01em; }
.capture .link { font-size: 13px; font-weight: 600; text-decoration: none; }

.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 14px; }
.label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 8px; }

.photo-drop {
  border: 2px dashed var(--line); border-radius: 12px; min-height: 220px;
  display: grid; place-items: center; text-align: center; color: var(--muted);
  background: #f8fafc; overflow: hidden; position: relative;
}
.photo-drop img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.photo-drop .hint { padding: 24px; font-size: 14px; }
.photo-drop .hint .big { font-size: 38px; display:block; margin-bottom: 8px; }

.photo-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.photo-action { flex: 1 1 0; justify-content: center; text-align: center; }

.grid-stages { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stage-btn {
  border: 1.5px solid var(--line); background: #fff; border-radius: 12px; padding: 10px;
  display: flex; align-items: center; gap: 10px; text-align: left;
}
.stage-btn .sw { width: 30px; height: 30px; border-radius: 9px; display:grid; place-items:center; color:#fff; font-weight:800; flex:0 0 auto; }
.stage-btn .t { font-size: 12.5px; font-weight: 600; line-height: 1.15; }
.stage-btn.sel { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(15,23,42,.08); }

.gps-state { display:flex; align-items:center; gap:10px; font-size: 13px; padding: 4px 2px; }
.gps-dot { width: 10px; height: 10px; border-radius: 50%; background: #cbd5e1; flex: 0 0 auto; }
.gps-dot.ok { background: #16a34a; }
.gps-dot.warn { background: #f59e0b; }
.gps-dot.err { background: #dc2626; }

input[type=text], textarea, input[type=password] {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  font-size: 14px; font-family: inherit; color: var(--ink);
}
textarea { resize: vertical; min-height: 60px; }

.send-btn {
  width: 100%; padding: 15px; border-radius: 12px; border: none;
  background: var(--brand); color: #fff; font-size: 16px; font-weight: 800; margin-top: 14px;
}
.send-btn:disabled { opacity: .5; }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow); opacity: 0; transition: all .25s; z-index: 9999; pointer-events: none; max-width: 92vw; text-align:center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { background: #166534; }
.toast.err { background: #991b1b; }

.muted-note { font-size: 12px; color: var(--muted); margin-top: 10px; line-height: 1.4; }

/* ---------- Manage / delete page ---------- */
.manage-wrap { max-width: 1120px; margin: 0 auto; padding: 18px 16px 40px; }
.manage-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.manage-head h1 { font-size: 20px; margin: 0; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
.manage-head .link { font-size: 13px; font-weight: 600; text-decoration: none; }

.manage-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; box-shadow: var(--shadow); margin: 10px 0 18px;
}
.manage-bar .field { display: flex; flex-direction: column; gap: 3px; }
.manage-bar label { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.manage-bar input[type=password], .manage-bar select {
  border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; font-size: 13px; font-family: inherit; color: var(--ink); background: #fff;
}
.manage-bar .grow { flex: 1; }
.manage-bar .count { color: var(--muted); font-size: 13px; font-weight: 600; }

.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 14px; }
.pcard { background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.pcard .thumb { width: 100%; height: 168px; object-fit: cover; cursor: zoom-in; background: #eef2f7; display: block; }
.pcard .body { padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.pcard .note { font-size: 13px; color: var(--ink); line-height: 1.3; }
.pcard .meta-line { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pcard .nogps { color: #b45309; font-weight: 600; }
.pcard .actions { margin-top: auto; display: flex; gap: 6px; }
.pcard .loc-btn,
.pcard .del {
  flex: 1; padding: 8px 10px; border-radius: 9px; font-weight: 700; font-size: 13px;
  display: inline-flex; gap: 6px; align-items: center; justify-content: center;
}
.pcard .loc-btn { border: 1px solid var(--line); background: #fff; color: var(--ink); }
.pcard .loc-btn:hover { background: #f8fafc; }
.pcard .del { border: 1px solid #fecaca; background: #fff5f5; color: #b91c1c; }
.pcard .del:hover { background: #fee2e2; }

.stage-chip { display: inline-flex; gap: 6px; align-items: center; font-size: 11px; font-weight: 700; color: #fff; padding: 3px 9px; border-radius: 999px; align-self: flex-start; }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; font-size: 15px; }

/* Modal d'edition de position */
.loc-modal { position: fixed; inset: 0; background: rgba(2,6,23,.55); display: none; place-items: center; z-index: 9999; padding: 20px; }
.loc-modal.open { display: grid; }
.loc-modal-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); width: 100%; max-width: 560px; overflow: hidden; }
.loc-modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); font-weight: 700; }
.loc-modal-head .close { border: none; background: none; font-size: 15px; color: var(--muted); cursor: pointer; padding: 4px 8px; }
.loc-map { height: 320px; width: 100%; }
.loc-modal-foot { padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; }
.loc-modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
