:root {
  --bg: #f4efe6;
  --fg: #2b2a27;
  --accent: #8c5a2b;
  --accent-dark: #6a4420;
  --muted: #6d6a63;
  --panel-bg: #fbf7ef;
  --border: #d9cfbd;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  --banner-bg: #fff3dc;
  --banner-fg: #6a4420;
  --topbar-h: 84px;
}

* { box-sizing: border-box; }

/* L'attribut `hidden` doit l'emporter sur display:flex/grid, sinon les
   éléments masqués réapparaissent (MediaRecorder live/preview/error…). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  color: var(--fg);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  padding: 0.75rem 1.2rem;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.topbar-titles h1 {
  margin: 0;
  font-size: 1.4rem;
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.tagline {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-style: italic;
  font-size: 0.95rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.banner {
  background: var(--banner-bg);
  color: var(--banner-fg);
  border-bottom: 1px solid var(--border);
  padding: 0.45rem 0.5rem 0.45rem 1rem;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.banner-text {
  flex: 1;
  text-align: center;
}
.banner code {
  background: rgba(0,0,0,0.06);
  padding: 0 0.25rem;
  border-radius: 3px;
  font-size: 0.88em;
}
.banner-close {
  background: transparent;
  border: none;
  color: var(--banner-fg);
  font-size: 1.5rem;
  line-height: 1;
  padding: 0.1rem 0.5rem;
  cursor: pointer;
  min-width: 32px;
  min-height: 32px;
  border-radius: 3px;
}
.banner-close:hover {
  background: rgba(0, 0, 0, 0.06);
}

.btn-primary, .btn-ghost {
  font: inherit;
  cursor: pointer;
  padding: 0.55rem 1rem;
  border-radius: 4px;
  border: 1px solid var(--accent);
  min-height: 44px;
  touch-action: manipulation;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-dark); }

.btn-primary.btn-locked {
  background: #aa9a82;
  border-color: #aa9a82;
  cursor: help;
}

.btn-ghost {
  background: transparent;
  color: var(--accent);
}
.btn-ghost:hover { background: rgba(140, 90, 43, 0.08); }

.hint {
  font-style: italic;
  color: var(--accent-dark);
  font-size: 0.9rem;
}

main {
  flex: 1;
  position: relative;
  overflow: hidden;
  /* Layout vertical : la carte prend la place restante, le footer du site
     se loge en dessous (au lieu de flotter par-dessus la carte avec un
     fond semi-transparent qui rognait visuellement les contrôles
     Leaflet et l'attribution OSM). */
  display: flex;
  flex-direction: column;
}

#map {
  width: 100%;
  flex: 1;
  min-height: 0;
}

/* ── Panneau latéral (desktop) ─────────────────────────────── */
.panel {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: min(420px, 100%);
  background: var(--panel-bg);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  overflow-y: auto;
  padding: 1rem 1.2rem 4rem;
  z-index: 500;
  -webkit-overflow-scrolling: touch;
}

.panel[aria-hidden="false"] {
  transform: translateX(0);
}

.panel-close {
  position: absolute;
  top: 0.4rem;
  right: 0.6rem;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.55rem;
  font: inherit;
  font-size: 1rem;
  line-height: 1;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  color: var(--muted);
  min-height: 40px;
}
.panel-close span[aria-hidden] {
  font-size: 1.8rem;
  line-height: 0.7;
}
.panel-close-label {
  font-size: 0.9rem;
}
.panel-close:hover {
  color: var(--fg);
  background: rgba(0, 0, 0, 0.05);
  border-color: var(--border);
}

.panel h2 {
  margin: 0.4rem 0 0.2rem;
  font-size: 1.4rem;
  padding-right: 2.5rem;
}

.panel .desc {
  margin: 0 0 1rem;
  color: var(--muted);
}

.panel .add-story,
.entity-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.5rem 0 1.2rem;
}

.story {
  border-top: 1px solid var(--border);
  padding: 0.9rem 0;
}

.story h3 {
  margin: 0 0 0.2rem;
  font-size: 1.05rem;
}

.story .meta {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.story .body {
  white-space: pre-wrap;
  line-height: 1.55;
}

.story img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  margin-top: 0.4rem;
}

.story audio {
  width: 100%;
  margin-top: 0.4rem;
}

.story .type-badge {
  display: inline-block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--accent);
  color: #fff;
  padding: 0.15rem 0.45rem;
  border-radius: 3px;
  margin-right: 0.4rem;
  vertical-align: middle;
}

.story .story-title {
  color: var(--fg);
  text-decoration: none;
  border-bottom: 1px dashed transparent;
}
.story .story-title:hover {
  border-bottom-color: var(--accent);
}

.story-byline {
  margin: 0.3rem 0 0.3rem;
  padding: 0.35rem 0.6rem;
  background: rgba(140, 90, 43, 0.06);
  border-left: 3px solid var(--accent);
  border-radius: 0 3px 3px 0;
  font-size: 0.95rem;
  font-style: italic;
}
.story-byline small {
  color: var(--muted);
  font-style: normal;
}

.places-told {
  margin: 0.3rem 0 0.8rem;
  line-height: 1.8;
}

/* ── Complétions attribuées ─────────────────────────────────── */
.completion {
  margin: 0.7rem 0 0.3rem;
  padding: 0.6rem 0.8rem;
  background: rgba(122, 58, 106, 0.05);
  border-left: 3px solid #7a3a6a;
  border-radius: 0 4px 4px 0;
}
.completion-head {
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
}
.completion-head strong { color: var(--fg); }
.completion-head .rel {
  font-style: italic;
}
.completion-date { color: var(--muted); }
.completion-body {
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 0.95rem;
}

/* Actions de récit — placées juste après l'entête pour rester visibles
   sans scroller, y compris dans le bottom-sheet mobile. */
.story-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.5rem 0 0.6rem;
}
.story-actions button {
  font-size: 0.85rem;
  padding: 0.3rem 0.6rem;
  min-height: 34px;
}

/* ── Fieldset "contributor-id" ──────────────────────────────── */
fieldset.contributor-id {
  margin: 0.9rem 0 0.3rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.015);
}
fieldset.contributor-id legend {
  padding: 0 0.4rem;
  font-weight: 600;
  color: var(--accent-dark);
  font-size: 0.9rem;
}
fieldset.contributor-id legend small {
  font-weight: normal;
  color: var(--muted);
  font-style: italic;
}
fieldset.contributor-id label {
  margin: 0.4rem 0;
  font-size: 0.9rem;
}
fieldset.contributor-id label em {
  font-weight: normal;
  color: var(--muted);
  font-style: italic;
  font-size: 0.85rem;
}

/* ── Modal "Partager" (lien + QR code) ─────────────────────── */
#dlg-share .share-content { display: flex; flex-direction: column; gap: 0.8rem; }
.share-intro { margin: 0; color: var(--muted); font-size: 0.92rem; }
.share-url-label { font-weight: 600; font-size: 0.9rem; }
.share-url-row { display: flex; gap: 0.4rem; align-items: stretch; margin-top: 0.3rem; }
.share-url-row input[type="text"] { flex: 1; font-family: monospace; font-size: 0.88rem; }
.share-qr-wrap {
  display: flex;
  justify-content: center;
  padding: 0.6rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 5px;
}
.share-qr-wrap img { display: block; image-rendering: pixelated; }

/* ── Fieldset "visibility-choice" (radios public / membres) ──── */
fieldset.visibility-choice {
  margin: 0.9rem 0 0.3rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.015);
}
fieldset.visibility-choice legend {
  padding: 0 0.4rem;
  font-weight: 600;
  color: var(--accent-dark);
  font-size: 0.9rem;
}
fieldset.visibility-choice .visibility-option {
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
  margin: 0.45rem 0;
  font-size: 0.9rem;
  cursor: pointer;
  line-height: 1.35;
}
fieldset.visibility-choice .visibility-option input[type="radio"] {
  margin-top: 0.2rem;
  flex-shrink: 0;
}
fieldset.visibility-choice .visibility-option em {
  font-weight: normal;
  color: var(--muted);
  font-style: italic;
  font-size: 0.85rem;
}

/* ── Autocompletion des noms ───────────────────────────────── */
.autocomplete-menu {
  position: absolute;
  z-index: 3000;
  list-style: none;
  margin: 0;
  padding: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: var(--shadow);
  max-height: 220px;
  overflow-y: auto;
  font-size: 0.9rem;
}
.autocomplete-menu li {
  padding: 0.35rem 0.55rem;
  cursor: pointer;
  border-bottom: 1px solid rgba(0,0,0,0.05);
}
.autocomplete-menu li:last-child { border-bottom: none; }
.autocomplete-menu li:hover { background: rgba(140,90,43,0.1); }
.autocomplete-menu .ac-alias {
  color: var(--muted);
  font-style: italic;
  font-size: 0.85rem;
}

/* ── Nouvelle fiche (création à la volée) ──────────────────── */
details.new-person {
  margin: 0.4rem 0 0.8rem;
  padding: 0.4rem 0.7rem;
  background: rgba(122, 58, 106, 0.04);
  border: 1px solid var(--border);
  border-radius: 5px;
}
details.new-person > summary {
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--accent-dark);
  padding: 0.2rem 0;
  user-select: none;
}
details.new-person[open] > summary {
  margin-bottom: 0.4rem;
}
details.new-person .new-person-hint {
  font-size: 0.82rem;
  color: var(--muted);
  font-style: italic;
  margin: 0.25rem 0 0.4rem;
}

/* Boutons inline sur le header d'une complétion */
.completion-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.completion-byline { flex: 1; }
.btn-inline {
  padding: 0.15rem 0.4rem;
  min-height: 28px;
  font-size: 0.85rem;
}

/* ── Entête d'entité (lieu / personne / récit) ─────────────── */
.entity-header {
  margin: 0 0 0.6rem;
}
.entity-kind {
  display: inline-block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.2rem;
}
.entity-header h2 {
  margin: 0.2rem 0 0.3rem;
}
.entity-header small {
  color: var(--muted);
  font-weight: normal;
}
.aliases {
  font-style: italic;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.6;
}
.dates {
  color: var(--muted);
  font-size: 0.92rem;
  margin-top: 0.15rem;
}

.chip {
  display: inline-block;
  background: rgba(140, 90, 43, 0.09);
  border: 1px solid rgba(140, 90, 43, 0.25);
  border-radius: 12px;
  padding: 0.1rem 0.55rem;
  margin: 0.1rem 0.25rem 0.1rem 0;
  font-style: normal;
}

.section-title {
  margin: 1.2rem 0 0.4rem;
  padding-top: 0.3rem;
  border-top: 1px solid var(--border);
  font-size: 1rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.relations {
  list-style: none;
  padding: 0;
  margin: 0 0 0.6rem;
}
.relations li {
  padding: 0.25rem 0;
}

/* ── Mentions cliquables dans le corps des récits ──────────── */
.mention {
  text-decoration: none;
  border-bottom: 1px solid currentColor;
  padding-bottom: 1px;
  cursor: pointer;
}
.mention-person {
  color: #7a3a6a;
  background: rgba(122, 58, 106, 0.06);
  padding: 0 0.15rem;
  border-radius: 2px;
}
.mention-place {
  color: var(--accent-dark);
  background: rgba(140, 90, 43, 0.08);
  padding: 0 0.15rem;
  border-radius: 2px;
}
.mention:hover {
  background-color: rgba(140, 90, 43, 0.18);
}

.dialog-note {
  background: var(--banner-bg);
  border-left: 3px solid var(--accent);
  padding: 0.5rem 0.7rem;
  margin: 0.8rem 0 0;
  font-size: 0.88rem;
  color: var(--banner-fg);
  border-radius: 0 4px 4px 0;
}

/* ── UI de compression ─────────────────────────────────────── */
.compress-status {
  margin: 0.7rem 0;
  padding: 0.6rem 0.8rem;
  background: rgba(140, 90, 43, 0.06);
  border: 1px solid var(--border);
  border-radius: 5px;
}
.compress-label {
  font-size: 0.9rem;
  color: var(--accent-dark);
  margin-bottom: 0.35rem;
}
.compress-bar {
  width: 100%;
  height: 6px;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 3px;
  overflow: hidden;
}
.compress-bar #compress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s ease;
}

/* ── Post-tagging des mentions ─────────────────────────────── */
.tag-popover {
  position: absolute;
  z-index: 1500;
}
.tag-popover button {
  padding: 0.45rem 0.8rem;
  font-size: 0.92rem;
  box-shadow: var(--shadow);
}

.tag-type-toggle {
  display: flex;
  gap: 1rem;
  margin: 0.8rem 0 0.3rem;
}
.tag-type-toggle label {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
}
.tag-type-toggle input {
  width: auto;
  min-height: auto;
  margin: 0;
}

.tag-results {
  list-style: none;
  padding: 0;
  margin: 0.2rem 0;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
}
.tag-results li {
  padding: 0.45rem 0.7rem;
  cursor: pointer;
  border-bottom: 1px solid rgba(0,0,0,0.05);
  font-size: 0.94rem;
}
.tag-results li:last-child { border-bottom: none; }
.tag-results li:hover { background: rgba(140,90,43,0.08); }
.tag-results li.selected { background: rgba(140,90,43,0.18); }
.tag-results .alias-hint {
  color: var(--muted);
  font-style: italic;
  font-size: 0.88rem;
}
.tag-result-empty {
  color: var(--muted);
  font-style: italic;
  padding: 0.55rem 0.7rem;
  cursor: default !important;
  background: transparent !important;
}

.tag-chosen {
  margin: 0.35rem 0 0;
  padding: 0.4rem 0.7rem;
  background: rgba(80,150,80,0.1);
  border-left: 3px solid #4a7a4a;
  color: #2a5a2a;
  border-radius: 0 3px 3px 0;
  font-size: 0.9rem;
}

/* Rend les zones de texte des récits sélectionnables de manière évidente */
.story .body {
  user-select: text;
  -webkit-user-select: text;
}

/* ── Enregistreur audio in-browser ─────────────────────────── */
.recorder {
  margin: 0.8rem 0 0.3rem;
  padding: 0.8rem 0.9rem;
  background: rgba(140, 90, 43, 0.05);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.recorder-label {
  font-weight: 600;
  color: var(--accent-dark);
  margin-bottom: 0.55rem;
}
.recorder-body > * + * { margin-top: 0.5rem; }
.rec-live {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.5rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
}
.rec-dot {
  width: 14px;
  height: 14px;
  background: #cc3333;
  border-radius: 50%;
  animation: pulse 1s infinite alternate;
}
@keyframes pulse {
  from { transform: scale(0.85); opacity: 0.7; }
  to   { transform: scale(1.1);  opacity: 1;   }
}
.rec-timer {
  font-family: Consolas, Menlo, monospace;
  font-size: 1rem;
  color: var(--fg);
  flex: 1;
}
.rec-preview audio {
  width: 100%;
}
.rec-preview-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.4rem;
}
.rec-ready {
  color: #4a7a4a;
  font-weight: 600;
  font-size: 0.9rem;
}
.rec-error {
  color: #a14040;
  background: rgba(161, 64, 64, 0.08);
  border: 1px solid rgba(161, 64, 64, 0.3);
  padding: 0.4rem 0.6rem;
  border-radius: 3px;
  font-size: 0.88rem;
}
.recorder-or {
  text-align: center;
  color: var(--muted);
  font-style: italic;
  margin: 0.6rem 0 -0.3rem;
  font-size: 0.88rem;
}

/* ── Arbre généalogique ────────────────────────────────────── */
.tree-wrap {
  overflow-x: auto;
  overflow-y: hidden;
  background: #fbf7ef;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem;
  margin: 0.4rem 0 0.6rem;
  -webkit-overflow-scrolling: touch;
}
.tree-svg {
  display: block;
  max-width: none;
}
.tree-svg .card-bg {
  fill: #fff;
  stroke: var(--border);
  stroke-width: 1;
  transition: fill 0.15s, stroke 0.15s;
}
.tree-svg .tree-card:hover .card-bg {
  fill: rgba(140, 90, 43, 0.08);
  stroke: var(--accent);
}
.tree-svg .tree-card.focus .card-bg {
  fill: rgba(140, 90, 43, 0.15);
  stroke: var(--accent);
  stroke-width: 2;
}
.tree-svg .card-name {
  fill: var(--fg);
  font-family: Georgia, serif;
  font-size: 13px;
  font-weight: 600;
  pointer-events: none;
}
.tree-svg .card-dates {
  fill: var(--muted);
  font-size: 11px;
  pointer-events: none;
}
.tree-svg .card-meta {
  fill: var(--muted);
  font-size: 10px;
  font-style: italic;
  pointer-events: none;
}
.tree-svg .edge {
  stroke: var(--accent-dark);
  stroke-width: 1.3;
  fill: none;
}
.tree-svg .edge-marriage {
  stroke: var(--accent);
  stroke-width: 2;
}
.tree-svg .tree-card:focus {
  outline: none;
}
.tree-svg .tree-card:focus .card-bg {
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 4 2;
}
.tree-empty {
  font-style: italic;
  color: var(--muted);
  padding: 0.5rem 0;
}
.tree-full-link {
  margin: 0.3rem 0 0.8rem;
  font-size: 0.92rem;
}
.tree-full-link a {
  color: var(--accent-dark);
  text-decoration: none;
  border-bottom: 1px dashed var(--accent);
}

/* ── Overlay plein écran ───────────────────────────────────── */
.tree-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.tree-overlay-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 1.2rem;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
}
.tree-overlay-title {
  flex: 1;
  font-size: 1.1rem;
}
.tree-overlay-title strong {
  color: var(--fg);
}
.tree-overlay-close {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.35rem 0.7rem;
  line-height: 1;
  min-height: 40px;
}
.tree-overlay-close span[aria-hidden] {
  font-size: 1.4rem;
  line-height: 0.8;
}
.tree-overlay-close .close-label {
  font-size: 0.92rem;
}
.tree-overlay-body {
  flex: 1;
  overflow: auto;
  padding: 1.2rem;
  -webkit-overflow-scrolling: touch;
}
.tree-overlay-body .tree-wrap {
  border: none;
  padding: 0;
  background: transparent;
  overflow: visible;
}
@media (max-width: 600px) {
  .tree-overlay-head {
    flex-wrap: wrap;
    padding: 0.5rem 0.8rem;
  }
  .tree-overlay-title {
    flex: 1 0 100%;
    font-size: 1rem;
    margin-bottom: 0.3rem;
  }
}

/* ── Modals ────────────────────────────────────────────────── */
dialog {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.2rem 1.4rem;
  max-width: 520px;
  width: calc(100% - 2rem);
  background: var(--panel-bg);
  color: var(--fg);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

dialog h2 {
  margin: 0 0 0.6rem;
}

dialog label {
  display: block;
  margin: 0.7rem 0;
  font-size: 0.95rem;
}

dialog input[type=text],
dialog input[type=file],
dialog textarea,
dialog select {
  font: inherit;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.55rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  min-height: 44px;
}

dialog textarea {
  resize: vertical;
  min-height: 100px;
}

dialog .coords {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0 0 0.6rem;
}

.place-position {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}
.place-position .coords { margin: 0; }
.btn-small {
  padding: 0.3rem 0.7rem;
  font-size: 0.9rem;
  min-height: 36px;
}

.btn-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent-dark);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}
.btn-link:hover { color: var(--accent); }
.btn-link:disabled { cursor: wait; opacity: 0.6; }

/* ── Liste de fichiers à uploader avec légende ──────────────── */
.media-captions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0.6rem 0 0.4rem;
}
.media-caption-row {
  display: flex;
  gap: 0.6rem;
  align-items: stretch;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.4rem;
}
.media-thumb {
  flex: 0 0 64px;
  width: 64px;
  height: 64px;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  overflow: hidden;
}
.media-thumb img { width: 100%; height: 100%; object-fit: cover; }
.media-cap-right {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}
.media-fname {
  font-size: 0.82rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.media-caption-input {
  width: 100%;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  font: inherit;
  font-size: 0.92rem;
}

/* ── Popover de mentions inline @nom ─────────────────────────── */
/* position:fixed pour fonctionner aussi quand l'input est dans un
   <dialog> modal (top-layer du navigateur). Le JS insère le popover
   dans la dialog active pour passer au-dessus du backdrop. */
.mention-popover {
  position: fixed;
  z-index: 1500;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
  max-height: 240px;
  overflow-y: auto;
  font-family: inherit;
}
.mention-item {
  padding: 0.45rem 0.7rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}
.mention-item:last-child { border-bottom: none; }
.mention-item:hover,
.mention-item.active {
  background: rgba(140, 90, 43, 0.10);
}
.mention-ctx {
  color: var(--muted);
  font-size: 0.85em;
}
.mention-create {
  background: rgba(140, 90, 43, 0.04);
  border-top: 1px solid var(--border);
}
.mention-create strong { font-weight: 600; }
.mention-flash {
  position: fixed;
  z-index: 1600;
  background: var(--accent-dark);
  color: #fff;
  padding: 0.5rem 0.8rem;
  border-radius: 6px;
  font-size: 0.85rem;
  max-width: 320px;
  box-shadow: var(--shadow);
}

/* ── Recherche d'adresse sur la carte ────────────────────────── */
.map-search {
  position: absolute;
  top: 10px;
  right: 56px;       /* laisse la place aux contrôles Leaflet (topright) */
  left: 56px;        /* laisse la place aux contrôles Leaflet (topleft) */
  max-width: 420px;
  margin-left: auto;
  z-index: 500;
  font-family: inherit;
}
.map-search-row {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
}
.map-search-row::before {
  content: '🔍';
  position: absolute;
  left: 0.65rem;
  font-size: 0.95rem;
  pointer-events: none;
}
.map-search input {
  flex: 1;
  padding: 0.55rem 2.2rem 0.55rem 2.1rem;
  border: none;
  background: transparent;
  font: inherit;
  color: var(--fg);
  border-radius: 6px;
  min-height: 40px;
}
.map-search input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.map-search-clear {
  position: absolute;
  right: 0.35rem;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 4px;
}
.map-search-clear:hover { background: rgba(0, 0, 0, 0.05); color: var(--fg); }

.map-search-results {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
  max-height: 50vh;
  overflow-y: auto;
}
.map-search-results li {
  padding: 0.5rem 0.7rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.92rem;
}
.map-search-results li:last-child { border-bottom: none; }
.map-search-results li:hover,
.map-search-results li:focus {
  background: rgba(140, 90, 43, 0.08);
}
.map-search-results strong { font-weight: 600; }
.map-search-ctx {
  color: var(--muted);
  font-size: 0.85rem;
}
.map-search-empty,
.map-search-error {
  color: var(--muted);
  font-style: italic;
  cursor: default !important;
}
.map-search-error { color: #a04a30; }

/* ── Sélecteur de couches : fonds modernes / anciens / cadastre ───── */
.map-layers {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 500;
  display: flex;
  flex-direction: column-reverse;  /* le panneau s'ouvre vers le haut */
  align-items: flex-start;
  gap: 6px;
  font-family: inherit;
  max-width: calc(100% - 20px);
}
.map-layers-toggle {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 0.45rem 0.8rem;
  font: inherit;
  font-size: 0.92rem;
  color: var(--accent-dark);
  cursor: pointer;
  min-height: 38px;
}
.map-layers-toggle:hover { background: #fff; }
.map-layers-body {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 0.7rem 0.8rem 0.65rem;
  font-size: 0.88rem;
  width: 270px;
  max-width: calc(100vw - 30px);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.map-layers-body[hidden] { display: none; }
.map-layers-bases {
  border: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.map-layers-bases legend {
  font-weight: 600;
  color: var(--accent-dark);
  font-size: 0.82rem;
  margin-bottom: 0.2rem;
  padding: 0;
}
.map-layers-bases label,
.map-layers-overlay {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  line-height: 1.2;
}
.map-layers-overlay {
  border-top: 1px dashed var(--border);
  padding-top: 0.5rem;
  font-weight: 500;
}
.map-layers-opacity {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  border-top: 1px dashed var(--border);
  padding-top: 0.5rem;
}
.map-layers-opacity label {
  font-size: 0.82rem;
  color: var(--muted);
}
.map-layers-opacity input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}
.map-layers-opacity.disabled {
  opacity: 0.45;
  pointer-events: none;
}
.map-layers-timeline {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.3rem;
  border-top: 1px dashed var(--border);
  padding-top: 0.5rem;
}
.map-layers-timeline button {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.35rem 0.2rem;
  font: inherit;
  font-size: 0.82rem;
  color: var(--accent-dark);
  cursor: pointer;
  min-height: 32px;
}
.map-layers-timeline button:hover { background: rgba(0, 0, 0, 0.04); }
.map-layers-timeline button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent-dark);
}

dialog .actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1rem;
}

/* ── Responsive : tablette ─────────────────────────────────── */
@media (max-width: 860px) {
  .topbar { padding: 0.6rem 0.9rem; }
  .topbar-titles h1 { font-size: 1.2rem; }
  .tagline { font-size: 0.88rem; }
}

/* ── Responsive : mobile ───────────────────────────────────── */
@media (max-width: 600px) {
  .topbar {
    padding: 0.4rem 0.7rem;
    gap: 0.3rem;
  }
  .topbar-titles h1 {
    font-size: 1.05rem;
    line-height: 1.15;
  }
  /* Le sous-titre prend de la place précieuse sur petit écran. */
  .tagline { display: none; }
  .topbar-actions {
    width: 100%;
    justify-content: stretch;
    gap: 0.35rem;
    flex-wrap: wrap;
  }
  .topbar-actions .btn-primary,
  .topbar-actions .btn-ghost {
    flex: 1 1 auto;
    padding: 0.35rem 0.5rem;
    font-size: 0.85rem;
    min-height: 36px;
  }
  /* Salutation membre : masquée en mobile (le bouton Déconnexion suffit). */
  #member-greeting { display: none !important; }
  /* Astuce d'ajout en pleine largeur quand le mode addMode est actif. */
  #add-hint { flex: 1 0 100%; font-size: 0.82rem; line-height: 1.2; }

  .banner {
    font-size: 0.78rem;
    padding: 0.35rem 0.3rem 0.35rem 0.6rem;
  }
  .banner code { font-size: 0.85em; }

  /* Le panneau devient un bottom sheet. 72vh : assez haut pour que les
     actions d'un récit (Compléter / Modifier) soient visibles sans
     scroller, assez court pour qu'on voie encore une bonne part de la
     carte en arrière-plan. */
  .panel {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 72vh;
    max-height: 85vh;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    padding: 1.1rem 1rem 3rem;
  }
  .panel[aria-hidden="false"] {
    transform: translateY(0);
  }
  .panel::before {
    /* petite barre de "drag" visuelle */
    content: '';
    display: block;
    width: 42px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: -0.6rem auto 0.6rem;
  }
  /* Bouton Fermer bien visible sur mobile (le back Android n'est pas
     toujours évident, surtout sur les surfaces plein écran). */
  .panel-close {
    top: 0.3rem;
    right: 0.5rem;
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    padding: 0.35rem 0.75rem;
    min-height: 44px;
    font-weight: 600;
  }
  .panel-close:hover,
  .panel-close:active {
    background: var(--accent-dark);
    color: #fff;
    border-color: var(--accent-dark);
  }
  .panel-close-label { font-size: 0.95rem; }

  /* Pousse un peu la carte vers le haut pour laisser la place au panneau */
  body.panel-open #map {
    filter: brightness(0.92);
  }

  /* L'attribution Leaflet en bas-droite passe sur deux lignes en mobile,
     ce qui faisait chevaucher le bouton "Couches". On le remonte pour
     dégager la barre d'attribution. */
  .map-layers {
    bottom: 28px;
  }
  /* Quand on consulte un contenu, on rend le bandeau invisible pour
     rendre tout l'espace à la lecture. Il réapparaît à la fermeture. */
  body.panel-open .banner {
    display: none;
  }

  /* Dialogs : pleine largeur confortable sur mobile */
  dialog {
    width: calc(100% - 1rem);
    padding: 1rem;
    max-height: 90vh;
    overflow-y: auto;
  }
  dialog .actions {
    flex-direction: column-reverse;
    gap: 0.5rem;
  }
  dialog .actions .btn-primary,
  dialog .actions .btn-ghost {
    width: 100%;
  }

  .banner { font-size: 0.82rem; padding: 0.5rem 0.8rem; }

  /* Sur mobile, on laisse les boutons +/- de Leaflet à gauche et la barre
     prend l'espace restant à droite (≈ 60 px de marge à gauche pour ne
     pas chevaucher les contrôles). */
  .map-search {
    left: 60px;
    right: 8px;
    top: 8px;
    max-width: none;
  }
  .map-search input { font-size: 0.92rem; padding: 0.45rem 2rem 0.45rem 2rem; }

  .place-position { flex-direction: column; align-items: stretch; }
  .place-position .btn-small { width: 100%; }
}

/* ── Accessibilité : focus visible ─────────────────────────── */
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ── Modal d'accueil ──────────────────────────────────────── */
.welcome-dialog {
  max-width: 640px;
  width: calc(100% - 2rem);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  background: var(--panel-bg, #fffaf2);
  color: var(--fg, #2b2a27);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.welcome-dialog::backdrop {
  background: rgba(20, 30, 20, 0.55);
  backdrop-filter: blur(2px);
}
.welcome-content {
  padding: 1.4rem 1.6rem 1.2rem;
  line-height: 1.55;
  font-size: 1rem;
  max-height: 60vh;
  overflow-y: auto;
}
.welcome-content h1 {
  font-size: 1.5rem;
  margin: 0 0 0.6rem;
  color: var(--accent-dark, #6a4420);
}
.welcome-content h2 {
  font-size: 1.15rem;
  margin: 1.1rem 0 0.4rem;
}
.welcome-content h3 {
  font-size: 1rem;
  margin: 0.8rem 0 0.3rem;
}
.welcome-content p { margin: 0.5rem 0; }
.welcome-content ul,
.welcome-content ol { margin: 0.4rem 0; padding-left: 1.4rem; }
.welcome-content li { margin: 0.15rem 0; }
.welcome-content a {
  color: var(--accent-dark, #6a4420);
  text-decoration: underline;
}
.welcome-content code {
  background: rgba(0, 0, 0, 0.05);
  padding: 0.05rem 0.3rem;
  border-radius: 3px;
  font-size: 0.92em;
}

.welcome-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.9rem 1.4rem;
  border-top: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.02);
}
.welcome-dontshow {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: var(--muted, #5a5a4a);
  cursor: pointer;
}
.welcome-buttons {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.welcome-buttons .btn-ghost,
.welcome-buttons .btn-primary {
  text-decoration: none;
}

@media (max-width: 480px) {
  .welcome-dialog { width: calc(100% - 1rem); border-radius: 6px; }
  .welcome-content { padding: 1rem 1.1rem 0.8rem; max-height: 55vh; }
  .welcome-actions { padding: 0.7rem 1rem; }
}

/* ── Bandeau de déplacement de lieu (mode admin) ────────────── */
.move-place-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 1rem;
  background: var(--banner-bg, #fff3dc);
  color: var(--banner-fg, #6a4420);
  border-bottom: 2px solid var(--accent, #8c5a2b);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  font-size: 0.92rem;
  animation: move-banner-slide 0.18s ease-out;
}
.move-place-banner.active { display: flex; }
.move-place-banner .move-banner-text { flex: 1; }
.move-place-banner em {
  font-style: italic;
  color: var(--accent-dark, #6a4420);
  font-weight: 600;
}
@keyframes move-banner-slide {
  from { transform: translateY(-100%); }
  to   { transform: translateY(0); }
}
