:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6a66;
  --line: #e3e1db;
  --accent: #e8590c;
  --accent-ink: #ffffff;
  --shadow: 0 8px 30px rgba(0, 0, 0, .14);
  --radius: 10px;
  --header-h: 60px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --panel: #20201e;
    --text: #ecebe7;
    --muted: #9c9a94;
    --line: #34332f;
    --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;  /* pas de « tirer pour rafraîchir » sur la carte */
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }

/* Barre d'outils */
.toolbar {
  position: fixed; inset: 0 0 auto 0; z-index: 1000;
  min-height: calc(var(--header-h) + var(--safe-top));
  display: flex; align-items: center; gap: 16px;
  padding: calc(10px + var(--safe-top)) calc(16px + var(--safe-right)) 10px calc(16px + var(--safe-left));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand svg { width: 22px; height: 22px; fill: var(--accent); }
.filters { display: flex; align-items: center; gap: 8px; flex: 1; flex-wrap: wrap; }
.filters input, .filters select {
  height: 36px; padding: 0 10px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
}
.filters input:focus, .filters select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.search { position: relative; flex: 1; min-width: 180px; max-width: 360px; }
.search svg { position: absolute; left: 10px; top: 10px; width: 16px; height: 16px; fill: var(--muted); }
.search input { width: 100%; padding-left: 32px; }
.date { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.date input { color: var(--text); }
.status { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.count { color: var(--muted); font-variant-numeric: tabular-nums; }

.ghost {
  height: 36px; padding: 0 12px;
  background: transparent; border: 1px solid var(--line); border-radius: 8px;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center;
}
.ghost:hover { border-color: var(--accent); color: var(--accent); }
.icon { width: 36px; justify-content: center; padding: 0; }
.icon svg { width: 18px; height: 18px; fill: currentColor; }
#sync.spinning svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Carte */
#map { position: fixed; inset: calc(var(--header-h) + var(--safe-top)) 0 0 0; background: var(--bg); }
.leaflet-bottom { margin-bottom: var(--safe-bottom); }
.sync-banner {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%); z-index: 1000;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 16px; box-shadow: var(--shadow); color: var(--muted);
}

.pin {
  width: 44px; height: 44px; border-radius: 50%;
  border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.35);
  background: #ccc center/cover no-repeat;
  position: relative;
}
.pin.cluster { width: 56px; height: 56px; }
.pin b {
  position: absolute; right: -6px; top: -6px;
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 12px; line-height: 22px; text-align: center;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.leaflet-marker-icon:hover .pin { transform: scale(1.08); }
.pin { transition: transform .12s; }

/* Galerie */
.gallery {
  position: fixed; top: calc(var(--header-h) + var(--safe-top)); right: 0; bottom: 0; z-index: 900;
  width: min(440px, 100%);
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  transform: translateX(105%); transition: transform .25s ease;
}
.gallery.open { transform: none; }
.gallery-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.gallery-head h2 { margin: 0; font-size: 17px; }
.gallery-head p { margin: 2px 0 0; color: var(--muted); }
.gallery-actions { display: flex; gap: 6px; }
.gallery-body { overflow-y: auto; overscroll-behavior: contain; padding: 8px calc(16px + var(--safe-right)) calc(24px + var(--safe-bottom)) 16px; flex: 1; }
.day { margin: 14px 0 6px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 4px; }
.grid button {
  aspect-ratio: 1; padding: 0; border: 0; border-radius: 4px; overflow: hidden;
  background: var(--line); cursor: pointer;
}
.grid img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.grid button:hover img { transform: scale(1.05); }
.sentinel { height: 1px; }

/* Visionneuse */
.lightbox {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(10, 10, 10, .94); color: #eee;
  display: flex; align-items: center; justify-content: center;
}
.lightbox[hidden] { display: none; }
.lightbox figure { margin: 0; max-width: 100%; max-height: 100%; display: flex; flex-direction: column; align-items: center; padding: 16px 64px; }
.lightbox img { max-width: 100%; max-height: calc(100vh - 110px); object-fit: contain; border-radius: 4px; }
.lightbox figcaption { display: flex; gap: 16px; align-items: center; justify-content: space-between; width: 100%; margin-top: 10px; color: #bbb; }
.lightbox figcaption .ghost { color: #eee; border-color: #555; }
#lb-info strong { color: #fff; }
#lb-info a { color: #f0a070; }
.lb-close, .lb-nav {
  position: absolute; background: rgba(255,255,255,.08); border: 0; color: #fff; cursor: pointer;
  border-radius: 50%; width: 48px; height: 48px; font-size: 26px; line-height: 1;
}
.lb-close { top: calc(16px + var(--safe-top)); right: calc(16px + var(--safe-right)); font-size: 18px; }
.lb-prev { left: 12px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 12px; top: 50%; transform: translateY(-50%); }
.lb-close:hover, .lb-nav:hover { background: rgba(255,255,255,.2); }

.offline-banner {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%);
  z-index: 1000; background: #3b3a36; color: #fff; border-radius: 999px; padding: 6px 14px;
  font-size: 13px; box-shadow: var(--shadow); white-space: nowrap;
}

/* Utilisateur */
.user { color: var(--muted); max-width: 180px; overflow: hidden; text-overflow: ellipsis; }

/* Page de connexion */
.login-page { display: grid; place-items: center; min-height: 100%; overflow: auto; padding: 16px; }
.login-card {
  width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow); padding: 28px 24px;
}
.login-card .brand { font-size: 20px; }
.login-card .brand svg { width: 28px; height: 28px; }
.login-hint { color: var(--muted); margin: 8px 0 20px; }
.login-card form { display: grid; gap: 14px; }
.login-card label { display: grid; gap: 6px; font-weight: 500; }
.login-card input {
  height: 40px; padding: 0 12px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px;
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.primary {
  height: 42px; border: 0; border-radius: 8px; cursor: pointer; font-weight: 600;
  background: var(--accent); color: var(--accent-ink); margin-top: 4px;
}
.primary:disabled { opacity: .6; cursor: progress; }
.login-error { margin: 0; color: #d63b3b; }
.login-card label.remember { display: flex; align-items: center; gap: 8px; font-weight: 400; cursor: pointer; }
.login-card .remember input { width: 18px; height: 18px; accent-color: var(--accent); }

@media (max-width: 860px) {
  :root { --header-h: 108px; }
  .toolbar { flex-wrap: wrap; gap: 8px; padding: 8px 16px; }
  .filters { order: 3; flex-basis: 100%; flex-wrap: nowrap; overflow-x: auto; }
  .status { margin-left: auto; }
  .date span { display: none; }
  .search { min-width: 140px; }
  .user { display: none; }
  .gallery { top: auto; height: 62vh; width: 100%; border-left: 0; border-top: 1px solid var(--line);
             border-radius: 14px 14px 0 0; transform: translateY(105%); }
  .grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
  .lightbox figure { padding: calc(56px + var(--safe-top)) 8px calc(16px + var(--safe-bottom)); }
  .lb-nav { top: auto; bottom: calc(16px + var(--safe-bottom)); transform: none; }
}
