:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --text: #1c1c1e;
  --muted: #6e6e73;
  --border: #d9d9de;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --yes: #1e8e3e;
  --maybe: #c77700;
  --no: #c5221f;
  --discuss: #7b3fb5;
  --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111114;
    --surface: #1c1c21;
    --text: #f2f2f5;
    --muted: #9a9aa2;
    --border: #34343c;
    --accent: #5b9bff;
    --accent-text: #0b1a33;
    --yes: #4cc26d;
    --maybe: #f0a53a;
    --no: #ff6b61;
    --discuss: #b388eb;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
h1 { font-size: 1.2rem; margin: 0; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
.muted { color: var(--muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }

button, select, input, textarea, .fab, a.ghost {
  font: inherit;
  color: inherit;
  border-radius: 10px;
}
button, select, .fab, a.ghost {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
}
button:disabled { opacity: .35; cursor: default; }
.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.ghost, a.ghost { background: transparent; border-color: transparent; }
.danger { color: var(--no); border-color: var(--no); background: transparent; }
#d-trash { width: 100%; margin-top: 8px; }
input, textarea, select { width: 100%; }
input, textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 16px; /* évite le zoom automatique sur iPhone */
}
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 10px; }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--text); }

/* ---- Connexion ---- */
#login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.card h1 { font-size: 1.5rem; }
.card .muted { margin-top: 4px; margin-bottom: 20px; }
.card button { width: 100%; margin-top: 6px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card .card-head button { width: auto; margin: 0; }
.lang-btn { font-size: .85rem; font-weight: 600; padding: 0 10px; }
.error { color: var(--no); font-size: .9rem; }
.hint { font-size: .8rem; color: var(--muted); margin-top: 16px; }

/* ---- Application ---- */
#app { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { flex: 1; }
.chip { font-size: .85rem; padding: 4px 10px; border-radius: 99px; background: var(--surface); border: 1px solid var(--border); }

.progress { padding: 12px 16px 4px; }
.progress-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; font-size: .9rem; }
.progress-row button { flex: none; min-height: 38px; font-size: .9rem; }
.bar { height: 8px; border-radius: 99px; background: var(--border); overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: var(--yes); transition: width .3s; }
#progress-bar.over { background: var(--maybe); }

.filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 16px;
  scrollbar-width: none;
}
.filter { flex: none; border-radius: 99px; min-height: 38px; font-size: .9rem; }
.filter[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.count { font-size: .75rem; opacity: .7; }

.toolbar { display: flex; gap: 8px; padding: 0 16px 12px; }
.toolbar select { flex: 1; width: auto; min-width: 0; }
.toolbar button { flex: none; }
.icon-btn { width: 44px; padding: 0; font-size: 1.2rem; }
.toolbar button[aria-pressed="true"], .filter[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

.trash-note { margin: 0 16px 12px; font-size: .85rem; color: var(--muted); }

.tile-check {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid #fff;
  background: rgba(0, 0, 0, .35);
  color: #fff;
  font-weight: 700;
}
.grid.selecting .tile-badge { display: none; }
.grid .tile.picked { border-color: var(--accent); }
.tile.picked img { opacity: .7; }
.tile.picked .tile-check { background: var(--accent); border-color: var(--accent); }

.select-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, .12);
}
.select-row { display: flex; align-items: center; gap: 8px; }
.select-row + .select-row { margin-top: 8px; }
.select-row > span { flex: 1; font-weight: 600; }
.select-row > button:not(.ghost) { flex: 1; margin: 0; }

.row-actions { display: flex; gap: 8px; margin-top: 8px; }
.row-actions button { flex: 1; margin: 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 6px;
  padding: 0 16px;
}
.tile {
  position: relative;
  padding: 0;
  aspect-ratio: 1;
  overflow: hidden;
  border: 3px solid transparent;
  border-radius: 10px;
  background: var(--surface);
  display: block;
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.noimg { display: grid; place-items: center; height: 100%; padding: 6px; font-size: .7rem; color: var(--muted); overflow-wrap: anywhere; }
.tile.st-selected { border-color: var(--yes); }
.tile.st-discuss { border-color: var(--discuss); }
.tile.st-rejected img { opacity: .4; }
.tile-foot {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 5px 3px;
  font-size: .7rem;
  color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, .7));
}
.tile-votes { display: flex; gap: 3px; }
.tile-gps {
  position: absolute;
  top: 4px;
  left: 4px;
  font-size: .7rem;
  background: rgba(0, 0, 0, .6);
  border-radius: 99px;
  padding: 1px 4px;
}
.locate { margin: -2px 0 12px; }
.locate button { width: 100%; }
.locate small { display: block; margin-top: 4px; font-size: .75rem; }
.tile-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: .7rem;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  border-radius: 99px;
  padding: 1px 6px;
}

.empty { text-align: center; color: var(--muted); padding: 40px 16px; }


.fab {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 6;
  min-height: 52px;
  padding: 0 20px;
  border-radius: 99px;
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
}

/* ---- Cartes ---- */
.map-wrap { padding: 0 16px; }
.map-view, .mini-map {
  isolation: isolate; /* les contrôles Leaflet restent sous les barres collantes */
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}
/* laisse la place au bouton « Ajouter » sous la carte */
.map-view { height: calc(100dvh - 350px); min-height: 300px; }
.map-note { font-size: .8rem; color: var(--muted); margin: 0 0 8px; }
.map-note:empty { display: none; }
.mini-map { height: 200px; margin: -2px 0 10px; }
.gps-pin { font-size: 28px; line-height: 32px; text-align: center; }
.photo-pin span {
  position: relative;
  display: block;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .4);
  background: #fff;
}
.photo-pin img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.photo-pin.st-selected span { border-color: var(--yes); }
.photo-pin.st-discuss span { border-color: var(--discuss); }
.photo-pin b {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 20px;
  padding: 0 5px;
  border-radius: 99px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: .7rem;
  line-height: 20px;
  text-align: center;
}
.map-popup { display: grid; grid-template-columns: repeat(auto-fill, 76px); gap: 6px; max-height: 260px; overflow-y: auto; }
.map-popup button { display: flex; flex-direction: column; min-height: 0; padding: 0; border: 0; background: none; gap: 2px; font-size: .7rem; color: #333; }
.map-popup img { width: 76px; height: 76px; object-fit: cover; border-radius: 6px; }
.leaflet-container { font: inherit; }

/* ---- Détail ---- */
dialog {
  width: 100%;
  max-width: 720px;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 auto;
  padding: 0;
  border: 0;
  background: var(--surface);
  color: var(--text);
  overflow-y: auto;
  overscroll-behavior: contain;
}
@media (min-width: 760px) {
  dialog { height: auto; max-height: 92dvh; margin: auto; border-radius: var(--radius); }
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
.detail-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(4px + env(safe-area-inset-top)) 8px 4px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.detail-img { position: relative; background: #000; display: flex; justify-content: center; touch-action: pan-y; }
.detail-img img { max-width: 100%; max-height: 60dvh; object-fit: contain; display: block; }
.nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  min-height: 56px;
  font-size: 2rem;
  background: rgba(0, 0, 0, .35);
  color: #fff;
  border: 0;
}
.nav.prev { left: 4px; }
.nav.next { right: 4px; }
.detail-body { padding: 16px; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

.votes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.vote { font-weight: 600; padding: 0 6px; white-space: nowrap; font-size: .95rem; }
.vote-yes[aria-pressed="true"] { background: var(--yes); border-color: var(--yes); color: #fff; }
.vote-maybe[aria-pressed="true"] { background: var(--maybe); border-color: var(--maybe); color: #fff; }
.vote-no[aria-pressed="true"] { background: var(--no); border-color: var(--no); color: #fff; }
#d-others { font-size: .9rem; margin: 8px 0 16px; }


.comments { list-style: none; margin: 0; padding: 0; font-size: .9rem; }
.comments li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.comments time { display: block; font-size: .75rem; color: var(--muted); }
.inline-form { display: flex; gap: 8px; margin-top: 8px; }
.inline-form button { flex: none; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  min-height: 34px;
  padding: 0 10px;
  border-radius: 99px;
  font-size: .85rem;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}
.tag .x { opacity: .6; font-size: 1rem; }
.tags.suggest { margin-top: 8px; }
.tag.add { background: transparent; border-style: dashed; color: var(--muted); }

.info { margin-top: 20px; border: 1px solid var(--border); border-radius: 10px; padding: 0 12px; }
.info summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; font-weight: 600; }
.info dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; margin: 0 0 12px; font-size: .85rem; }
.info dt { color: var(--muted); }
.info dd { margin: 0; overflow-wrap: anywhere; }
.info dd.full { grid-column: 1 / -1; }
.info a { color: var(--accent); }
.meta { font-size: .8rem; color: var(--muted); margin-top: 16px; }

/* ---- Toast ---- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: .9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 10;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
body:has(.select-bar:not([hidden])) #toast { bottom: calc(130px + env(safe-area-inset-bottom)); }

/* ---- Impression (Dossier PDF) ---- */
#print-view { display: none; }
@media print {
  body { background: #fff; color: #000; }
  body > :not(#print-view) { display: none !important; }
  #print-view { display: block; font-size: 11pt; }
  #print-view h1 { font-size: 16pt; }
  #print-view > p { margin: 4pt 0 12pt; }
  #print-view figure {
    margin: 0 0 14pt;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  #print-view img { max-width: 100%; max-height: 105mm; display: block; margin: 0 auto 4pt; }
  #print-view figcaption { text-align: center; }
  #print-view .cap { display: block; font-style: italic; }
  #print-view .tags-line { display: block; font-size: 9pt; color: #555; }
}
