:root {
  --cream: #fbf6ea;
  --paper: #fffdf7;
  --ink: #2b2a22;
  --muted: #7a7766;
  --line: #e8e0cb;
  --green: #2f5b3a;
  --green-dark: #1f4a2e;
  --green-soft: #e4edd9;
  --clay: #b9532f;
  --clay-dark: #9a4222;
  --clay-soft: #f6e3d8;
  --sky: #dbe9ee;
  --danger: #b3261e;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(60, 48, 20, 0.08);
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  padding-bottom: calc(66px + env(safe-area-inset-bottom));
}
h1, h2, h3, h4 { font-family: var(--serif); line-height: 1.15; margin: 0 0 0.5em; color: var(--green-dark); }
h1 { font-size: clamp(2rem, 6vw, 3.4rem); font-weight: 800; letter-spacing: -0.01em; }
h2 { font-size: clamp(1.35rem, 3.4vw, 1.75rem); }
h3 { font-size: 1.15rem; }
p { margin: 0 0 1em; }
a { color: var(--green); }
img { max-width: 100%; }
.ico { display: inline-flex; vertical-align: middle; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.center { text-align: center; }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid #e2a15a; outline-offset: 2px; border-radius: 6px; }

/* ---------- Structure */
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
main { min-height: 60vh; padding-bottom: 32px; }
.section { margin: 28px 0; }
.section-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.section-head .ico { color: var(--green); margin-top: 4px; }
.section-head h2 { margin: 0; }
.section-head p { margin: 2px 0 0; color: var(--muted); font-size: 0.95rem; }
.section-head .push { margin-left: auto; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.grid { display: grid; gap: 14px; }
@media (min-width: 720px) { .grid.c2 { grid-template-columns: repeat(2, 1fr); } .grid.c3 { grid-template-columns: repeat(3, 1fr); } .grid.c4 { grid-template-columns: repeat(4, 1fr); } }

/* ---------- En-tête */
.site-header { background: rgba(251, 246, 234, 0.94); backdrop-filter: blur(6px); position: relative; z-index: 900; border-bottom: 1px solid var(--line); }
.site-header .wrap { display: flex; align-items: center; gap: 18px; min-height: 64px; padding-top: 10px; padding-bottom: 10px; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--green-dark); }
.brand-text { font-family: var(--serif); font-weight: 800; font-size: 1.15rem; line-height: 1.05; }
.brand-text small { display: block; font: 600 0.62rem var(--sans); letter-spacing: 0.3em; color: var(--muted); margin-top: 3px; }
.nav { display: none; margin-left: auto; gap: 6px; align-items: center; }
.nav a, .nav button.link { color: var(--ink); text-decoration: none; padding: 8px 12px; border-radius: 999px; font-size: 0.95rem; background: none; border: 0; cursor: pointer; font-family: inherit; }
.nav a:hover, .nav a.on { background: var(--green-soft); }
.header-user { margin-left: auto; display: flex; gap: 8px; align-items: center; }
@media (min-width: 820px) { .site-header { position: sticky; top: 0; } .nav { display: flex; } .header-user { margin-left: 0; } .tabbar { display: none !important; } body { padding-bottom: 0; } }
@media (max-width: 819px) { .header-user .btn-text { display: none; } }
.nav a, .header-user .btn { white-space: nowrap; }
@media (min-width: 820px) and (max-width: 1100px) { .nav a { padding: 8px 8px; font-size: 0.9rem; } .header-user .btn:not(:first-child) .btn-text { display: none; } .site-header .wrap { gap: 10px; } }
@media (max-width: 480px) { .site-header .wrap { gap: 8px; } }

/* Barre d'onglets mobile */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 900; background: var(--paper); border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(3, 1fr); padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 9px; text-decoration: none; color: var(--muted); font-size: 0.75rem; min-width: 0; }
.tabbar a span:last-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabbar.dense a { font-size: 0.66rem; }
.tabbar.dense a .ico svg { width: 20px; height: 20px; }
.tabbar a.on { color: var(--green-dark); font-weight: 700; }

/* ---------- Boutons et formulaires */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); border-radius: 999px; padding: 10px 18px; font: 600 0.95rem var(--sans); cursor: pointer; text-decoration: none; min-height: 44px; }
.btn:hover { background: #f3ecda; }
.btn.primary { background: var(--clay); border-color: var(--clay); color: #fff; }
.btn.primary:hover { background: var(--clay-dark); }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.green:hover { background: var(--green-dark); }
.btn.danger { color: var(--danger); border-color: #e7c1be; }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: 0.85rem; }
.btn.big { padding: 14px 26px; font-size: 1.05rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: 0.55; cursor: default; }
.btn.ghost { background: transparent; }
.field { display: block; margin-bottom: 14px; font-weight: 600; font-size: 0.92rem; }
.field .hint { display: block; font-weight: 400; color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
input[type='text'], input[type='email'], input[type='password'], input[type='date'], input[type='number'], input[type='search'], input[type='color'], select, textarea {
  width: 100%; margin-top: 5px; padding: 11px 13px; border: 1px solid #d8ceb4; border-radius: 10px; background: #fff; font: 400 1rem var(--sans); color: var(--ink);
}
input[type='color'] { padding: 3px; height: 44px; }
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid #e2a15a66; border-color: #c98a4b; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 0.92rem; margin: 6px 0 14px; font-weight: 400; }
.check input { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--green); flex: none; }
.err { color: var(--danger); font-size: 0.92rem; margin: 8px 0; min-height: 1.2em; }
.notice { border-radius: 12px; padding: 12px 14px; margin: 12px 0; background: var(--green-soft); font-size: 0.93rem; }
.notice.warn { background: #fdf0d4; }
.notice.bad { background: #fbe4e1; }
.form-narrow { max-width: 460px; margin: 28px auto; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--green-soft); font-size: 0.82rem; color: var(--green-dark); border: 0; }
.chip.clay { background: var(--clay-soft); color: var(--clay-dark); }
.chip button { background: none; border: 0; cursor: pointer; padding: 0; color: inherit; font-size: 1rem; line-height: 1; }
.badge-demo { display: inline-block; padding: 2px 10px; border-radius: 6px; background: #efe9d6; color: var(--muted); font-size: 0.72rem; }

/* ---------- Accueil */
.hero { position: relative; overflow: hidden; padding: 22px 0 6px; background: linear-gradient(180deg, #fffaf0, var(--cream)); }
.hero .wrap { display: grid; gap: 8px; align-items: center; }
.hero h1 em { font-style: normal; display: block; }
.hero h1::after { content: ''; display: block; width: 92px; height: 4px; border-radius: 3px; background: var(--clay); margin-top: 12px; opacity: 0.8; }
.hero p.lead { font-size: 1.05rem; max-width: 440px; margin: 18px 0; }
.brand-logo { height: 100px; width: auto; display: block; }
.hero-art { display: flex; justify-content: center; }
.hero-art .challenge { max-width: 420px; width: 100%; padding: 20px 24px; margin: 0; }
.hero-art .count-big { font-size: 3rem; }
.form-logo { display: block; max-width: 300px; margin: 0 auto 6px; }
.form-logo img { width: 100%; height: auto; display: block; }
@media (max-width: 819px) { .brand-logo { height: 84px; } .hero-art { justify-content: flex-start; margin-top: 18px; } .hero-art .challenge { max-width: 360px; } .hero-art .count-big { font-size: 2.4rem; } }
@media (min-width: 820px) { .hero .wrap { grid-template-columns: 1.1fr 1fr; padding-top: 18px; padding-bottom: 8px; } }
.challenge { background: var(--paper); border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: 16px; padding: 14px 18px; max-width: 360px; margin-top: 4px; }
.challenge h3 { display: flex; gap: 8px; align-items: center; font-size: 0.95rem; margin: 0 0 4px; }
.challenge .ico { color: var(--green); }
.count-big { font-family: var(--serif); font-size: 2.4rem; font-weight: 800; color: var(--green-dark); line-height: 1.1; }
.count-big small { font-size: 0.45em; font-weight: 400; color: var(--muted); margin-left: 6px; }
.count-big .goal { font-weight: 400; color: #4a4a3a; }
.progress { display: flex; align-items: center; gap: 12px; margin: 8px 0 4px; }
.progress .bar { flex: 1; height: 10px; border-radius: 6px; background: #e3ddc9; overflow: hidden; }
.progress .bar i { display: block; height: 100%; background: linear-gradient(90deg, #4f8a4c, var(--green)); border-radius: 6px; }
.progress b { font-size: 0.9rem; color: var(--green-dark); }

/* ---------- Carte */
.map-shell { position: relative; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; background: #e9efe0; box-shadow: var(--shadow); }
.map-canvas { height: 460px; width: 100%; z-index: 1; }
.map-shell.tall .map-canvas { height: calc(100vh - 230px); min-height: 440px; }
.map-search { position: relative; margin-bottom: 12px; max-width: 560px; }
.map-search input { padding-left: 42px; border-radius: 999px; margin: 0; }
.map-search .ico { position: absolute; left: 14px; top: 12px; color: var(--muted); }
.suggest { position: absolute; z-index: 1200; left: 0; right: 0; top: 100%; margin-top: 4px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.suggest button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 10px 14px; font: inherit; cursor: pointer; }
.suggest button:hover, .suggest button:focus { background: var(--green-soft); }
.suggest small { color: var(--muted); }
.legend { position: absolute; z-index: 500; left: 10px; top: 10px; background: rgba(255, 253, 247, 0.96); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; max-width: 250px; max-height: calc(100% - 20px); overflow: auto; box-shadow: var(--shadow); font-size: 0.85rem; }
.legend summary { font-weight: 700; cursor: pointer; list-style: none; display: flex; align-items: center; gap: 6px; }
.legend summary::-webkit-details-marker { display: none; }
.legend h4 { margin: 10px 0 4px; font: 700 0.8rem var(--sans); color: var(--ink); }
.legend label { display: flex; align-items: center; gap: 8px; padding: 3px 0; cursor: pointer; font-weight: 400; }
.legend input[type=checkbox] { accent-color: var(--green); width: 16px; height: 16px; }
.legend select, .legend input[type=date] { margin: 2px 0; padding: 6px 8px; font-size: 0.85rem; }
.legend .tcount { margin-left: auto; color: var(--muted); }
.nb-marker { filter: drop-shadow(0 1px 2px rgba(0,0,0,.35)); }
.nb-cluster { display: flex; align-items: center; justify-content: center; border-radius: 50%; background: var(--green); color: #fff; font: 700 14px var(--sans); border: 3px solid rgba(255, 255, 255, 0.9); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35); }
.leaflet-popup-content { font-family: var(--sans); margin: 12px 14px; }
.pop { min-width: 220px; }
.pop img { display: block; width: 100%; height: 120px; object-fit: cover; border-radius: 8px; margin-bottom: 8px; }
.pop h4 { margin: 0 0 4px; font-size: 1.05rem; }
.pop-type { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 0.9rem; margin-bottom: 2px; }
.pop-species { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0 0; }
.pop-last { margin: 8px 0 0; font-size: 0.85rem; font-style: italic; color: var(--ink); }
.pop a.btn { color: #fff; text-decoration: none; }
.pop .muted { font-size: 0.85rem; }
.map-note { position: absolute; z-index: 500; right: 10px; bottom: 26px; background: rgba(255,253,247,.92); border-radius: 8px; padding: 3px 8px; font-size: 0.72rem; color: var(--muted); }
@media (max-width: 600px) { .map-canvas { height: 420px; } .legend { max-width: 190px; } }

/* ---------- Journal / observations */
.obs-cards { display: grid; gap: 12px; }
@media (min-width: 720px) { .obs-cards { grid-template-columns: repeat(3, 1fr); } }
.obs-card { display: flex; gap: 12px; padding: 10px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: inherit; box-shadow: var(--shadow); align-items: stretch; }
.obs-card:hover { background: #fff; }
.obs-thumb { flex: none; width: 92px; min-height: 80px; border-radius: 8px; overflow: hidden; background: var(--green-soft); display: flex; align-items: center; justify-content: center; }
.obs-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.obs-card .date { font-size: 0.8rem; color: var(--muted); }
.obs-card h4 { margin: 2px 0 4px; font-size: 1rem; }
.obs-card .where { font-size: 0.8rem; color: var(--muted); }

.timeline { position: relative; margin: 8px 0 0; padding-left: 22px; border-left: 2px solid var(--line); }
.entry { position: relative; margin-bottom: 20px; }
.entry::before { content: ''; position: absolute; left: -29px; top: 6px; width: 12px; height: 12px; border-radius: 50%; background: var(--green); border: 3px solid var(--cream); }
.entry .date { font: 700 1rem var(--serif); color: var(--green-dark); }
.entry .photos { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.entry .photos img, .gallery img { width: 110px; height: 110px; object-fit: cover; border-radius: 10px; cursor: zoom-in; border: 1px solid var(--line); }
.gallery { display: flex; gap: 8px; flex-wrap: wrap; }
.gallery .ph { position: relative; }
.gallery .ph .x { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; }
.empty { text-align: center; padding: 28px 16px; color: var(--muted); border: 2px dashed var(--line); border-radius: var(--radius); }

/* ---------- Statistiques */
.stat-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 720px) { .stat-row { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); }
.stat b { display: block; font: 800 1.9rem var(--serif); color: var(--green-dark); line-height: 1.1; }
.stat span { font-size: 0.85rem; color: var(--muted); }
.bars .brow { display: grid; grid-template-columns: 38px 1fr 56px; gap: 10px; align-items: center; margin: 7px 0; font-size: 0.9rem; }
.bars .brow .lbl { grid-column: 2; }
.bars .brow.icon { grid-template-columns: 34px 1fr 52px; }
.bars .track { height: 8px; border-radius: 4px; background: #eadfc6; overflow: hidden; margin-top: 3px; }
.bars .track i { display: block; height: 100%; border-radius: 4px; }
.bars .pct { text-align: right; font-weight: 700; }
.evo { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: 8px; }
.evo div { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; font-size: 0.65rem; color: var(--muted); }
.evo i { display: block; width: 100%; background: var(--green); border-radius: 4px 4px 0 0; min-height: 2px; }

/* ---------- Page territoire */
.territory-hero { background: linear-gradient(180deg, #fffaf0, var(--cream)); padding: 22px 0 8px; }
.crumbs { font-size: 0.85rem; color: var(--muted); margin-bottom: 8px; }
.crumbs a { color: var(--muted); }
.big-progress { height: 16px; border-radius: 10px; background: #e3ddc9; overflow: hidden; margin: 12px 0 6px; }
.big-progress i { display: block; height: 100%; background: linear-gradient(90deg, #4f8a4c, var(--green)); border-radius: 10px; }
.remaining { font: 700 1.2rem var(--serif); color: var(--clay-dark); margin: 10px 0 16px; }

/* ---------- Fiche nichoir & formulaires en étapes */
.fiche-head { display: grid; gap: 14px; }
.facts { display: flex; flex-wrap: wrap; gap: 8px 18px; color: var(--muted); font-size: 0.95rem; margin: 6px 0 12px; }
.type-grid { display: grid; gap: 10px; grid-template-columns: repeat(2, 1fr); }
@media (min-width: 720px) { .type-grid { grid-template-columns: repeat(3, 1fr); } }
.type-opt { position: relative; display: flex; gap: 10px; align-items: center; padding: 12px; border: 2px solid var(--line); border-radius: 12px; background: var(--paper); cursor: pointer; font-weight: 600; font-size: 0.9rem; }
.type-opt input { position: absolute; opacity: 0; }
.type-opt:has(input:checked) { border-color: var(--green); background: var(--green-soft); }
.type-opt:has(input:focus-visible) { outline: 3px solid #e2a15a; }
.steps { display: flex; gap: 8px; margin: 0 0 18px; }
.steps span { flex: 1; text-align: center; padding: 8px 4px; border-radius: 10px; background: #efe9d6; font-size: 0.82rem; color: var(--muted); }
.steps span.on { background: var(--green); color: #fff; font-weight: 700; }
.steps span.done { background: var(--green-soft); color: var(--green-dark); }
.pick-map { height: 300px; border-radius: 12px; border: 1px solid var(--line); margin: 8px 0 6px; }
.previews { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.previews .ph { position: relative; }
.previews img { width: 90px; height: 90px; object-fit: cover; border-radius: 10px; }
.previews .x { position: absolute; top: 3px; right: 3px; width: 24px; height: 24px; border: 0; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; }
.species-pick { position: relative; }
.species-pick .chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }

/* ---------- Mon espace, listes, administration */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tabs button { background: none; border: 0; padding: 10px 14px; font: 600 0.95rem var(--sans); color: var(--muted); cursor: pointer; white-space: nowrap; border-bottom: 3px solid transparent; }
.tabs button.on { color: var(--green-dark); border-bottom-color: var(--clay); }
.nest-list { display: grid; gap: 12px; }
@media (min-width: 720px) { .nest-list { grid-template-columns: repeat(2, 1fr); } }
.nest-item { display: flex; gap: 12px; align-items: center; padding: 12px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: inherit; }
.nest-item:hover { background: #fff; }
.nest-item .pic { flex: none; width: 64px; height: 64px; border-radius: 10px; overflow: hidden; background: var(--green-soft); display: flex; align-items: center; justify-content: center; }
.nest-item .pic img { width: 100%; height: 100%; object-fit: cover; }
.table-wrap { overflow-x: auto; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #f6f0de; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
tr.dim td { opacity: 0.55; }
td .row { gap: 6px; }

/* ---------- Fenêtres, messages */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3); background: var(--paper); color: var(--ink); }
dialog::backdrop { background: rgba(30, 26, 14, 0.55); }
dialog .dlg { padding: 20px; }
dialog .dlg-head { display: flex; align-items: center; margin-bottom: 12px; }
dialog .dlg-head h3 { margin: 0; flex: 1; }
dialog .dlg-head button { background: none; border: 0; cursor: pointer; }
dialog.lightbox { width: min(900px, 96vw); background: #111; }
dialog.lightbox img { display: block; width: 100%; max-height: 86vh; object-fit: contain; }
#toast { position: fixed; left: 50%; bottom: 84px; transform: translate(-50%, 20px); background: #2b2a22; color: #fff; padding: 11px 18px; border-radius: 999px; opacity: 0; pointer-events: none; transition: 0.25s; z-index: 5000; max-width: 92vw; font-size: 0.93rem; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--danger); }
.consent { position: fixed; z-index: 4000; left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 6px 28px rgba(0, 0, 0, 0.25); padding: 14px 16px; font-size: 0.92rem; }
.consent p { margin: 0 0 10px; }
.consent .row { justify-content: flex-end; }
@media (min-width: 820px) { .consent { bottom: 16px; left: 16px; right: auto; margin: 0; } }
.site-footer { border-top: 1px solid var(--line); padding: 22px 0; color: var(--muted); font-size: 0.88rem; margin-top: 30px; }
.site-footer a { color: var(--muted); margin-right: 14px; }
.spinner { text-align: center; padding: 40px; color: var(--muted); }
.prose { max-width: 720px; }
.prose h2 { margin-top: 1.6em; }
@media print { .site-header, .tabbar, .site-footer { display: none; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
