:root {
  --bg: #faf7f0;
  --surface: #ffffff;
  --ink: #1f2a1c;
  --muted: #6b7466;
  --line: #e6e1d4;
  --green: #2f6b3a;
  --green-dark: #24542d;
  --green-soft: #e5f0e2;
  --amber: #c8841a;
  --danger: #b42318;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(31, 42, 28, 0.12);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); display: flex; flex-direction: column; min-height: 100vh; }
a { color: var(--green); }

/* ---------- En-tête ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: relative; z-index: 1000;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; margin-right: auto; }
.brand-icon { font-size: 30px; }
.brand strong { display: block; font-size: 18px; color: var(--green-dark); }
.brand small { color: var(--muted); font-size: 12px; }

.search { position: relative; flex: 0 1 320px; min-width: 200px; }
.search input, .field input, .field textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px;
  font: inherit; background: var(--surface); color: inherit;
}
.search input:focus, .field input:focus, .field textarea:focus { outline: 2px solid var(--green); outline-offset: -1px; }
.search-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; margin: 0; padding: 4px;
  list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.search-results button { width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none; border-radius: 8px; font: inherit; cursor: pointer; color: inherit; }
.search-results button:hover { background: var(--green-soft); }
.search-results small { color: var(--muted); }
.search-results .empty { padding: 8px 10px; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; text-decoration: none; white-space: nowrap;
}
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); }
.btn-primary:disabled { opacity: .6; cursor: wait; }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--green-soft); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: #f1c4c0; }
.btn-danger:hover { background: #fdecea; }
.btn-sm { padding: 6px 10px; font-size: 13px; }

/* ---------- Filtres ---------- */
.filters {
  display: flex; gap: 8px; padding: 10px 16px; overflow-x: auto; scrollbar-width: thin;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); font: inherit; font-size: 14px;
  color: var(--muted); cursor: pointer; white-space: nowrap; user-select: none;
}
.chip small { font-size: 12px; opacity: .75; }
.chip.on, .chip:has(input:checked) { background: var(--green-soft); border-color: var(--green); color: var(--green-dark); }
.chip input { accent-color: var(--green); margin: 0; }

/* ---------- Carte + colonne pub ---------- */
.layout { flex: 1; display: grid; grid-template-columns: 1fr 336px; min-height: 0; }
.map-wrap { position: relative; min-height: 400px; }
#map { position: absolute; inset: 0; background: #e8e4da; }
.count-badge {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 500;
  background: var(--surface); padding: 6px 14px; border-radius: 999px; box-shadow: var(--shadow);
  font-size: 13px; font-weight: 600; color: var(--green-dark); pointer-events: none;
}

.sidebar {
  background: var(--surface); border-left: 1px solid var(--line); overflow-y: auto;
  padding: 16px 18px; display: flex; flex-direction: column; gap: 14px;
  max-height: calc(100vh - 120px);
}
.ad-slot {
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  margin: 0 auto; width: 300px; max-width: 100%;
  background: repeating-linear-gradient(45deg, #f6f3ea, #f6f3ea 10px, #f1ede2 10px, #f1ede2 20px);
  border: 1px dashed #d6cfbd; border-radius: 8px; color: #a39b86; font-size: 12px; text-transform: uppercase; letter-spacing: .08em;
}
.ad-rect { height: 250px; }
.ad-tall { height: 600px; }

.list-title { font-size: 15px; margin: 4px 0 0; }
.casier-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.casier-item {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left; cursor: pointer;
  padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font: inherit; color: inherit;
}
.casier-item:hover { border-color: var(--green); background: #fbfdfa; }
.casier-item .emoji { font-size: 18px; flex-shrink: 0; max-width: 56px; overflow: hidden; white-space: nowrap; }
.casier-item .txt { flex: 1; min-width: 0; }
.casier-item strong { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.casier-item small { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.casier-item .dist { font-size: 12px; color: var(--green-dark); font-weight: 600; flex-shrink: 0; }
.empty { color: var(--muted); font-size: 14px; padding: 10px 2px; line-height: 1.5; }

.footer {
  display: flex; flex-wrap: wrap; gap: 6px 24px; justify-content: space-between;
  padding: 10px 16px; font-size: 12px; color: var(--muted); background: var(--surface); border-top: 1px solid var(--line);
}

/* ---------- Repères ---------- */
.pin { background: none; border: 0; }
.pin span {
  display: flex; align-items: center; justify-content: center; width: 34px; height: 34px;
  background: var(--surface); border: 3px solid var(--green); border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg); box-shadow: 0 2px 6px rgba(0,0,0,.3);
}
.pin i { transform: rotate(45deg); font-style: normal; font-size: 16px; line-height: 1; }
.pin.pin-pain span { border-color: var(--amber); }

.popup h3 { margin: 0 0 6px; font-size: 16px; }
.popup p { margin: 4px 0; font-size: 13px; }
.popup .tags { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.tag { background: var(--green-soft); color: var(--green-dark); border-radius: 999px; padding: 2px 8px; font-size: 12px; }
.popup-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.popup-actions .btn-primary { color: #fff; }
.popup .source { color: var(--muted); font-size: 11px; margin-top: 8px; }

/* ---------- Fenêtres ---------- */
.dialog {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0;
  border: 0; border-radius: 16px; box-shadow: var(--shadow); color: inherit; background: var(--surface);
}
.dialog-small { width: min(420px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(20, 28, 18, .45); }
.dialog form { padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog-head h2 { margin: 0; font-size: 20px; }
.close { border: 0; background: none; font-size: 18px; cursor: pointer; color: var(--muted); padding: 4px 8px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.hint { margin: 0; color: var(--muted); font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.field input, .field textarea { font-weight: 400; }
.row { display: flex; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; font-weight: 400; }
.role { display: flex; gap: 16px; border: 0; padding: 0; margin: 0; font-size: 14px; }
.radio { display: flex; gap: 8px; align-items: center; font-weight: 400; padding: 3px 0; }
.add-map { height: 220px; border-radius: 10px; border: 1px solid var(--line); }
.error { margin: 0; color: var(--danger); font-size: 14px; background: #fdecea; padding: 8px 12px; border-radius: 8px; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 3000;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; box-shadow: var(--shadow);
  max-width: calc(100vw - 32px); font-size: 14px;
}

.footer-links { display: flex; gap: 16px; flex-wrap: wrap; }

/* ---------- Pages départements et pages de texte ---------- */
html:has(body.page), body.page { height: auto; }
.seo { max-width: 1120px; width: 100%; margin: 0 auto; padding: 20px 16px 48px; flex: 1; line-height: 1.6; }
.seo h1 { font-size: 28px; line-height: 1.25; margin: 8px 0 12px; color: var(--green-dark); }
.seo h2 { font-size: 20px; margin: 28px 0 10px; }
.seo .commune { font-size: 15px; color: var(--muted); margin: 18px 0 8px; text-transform: uppercase; letter-spacing: .04em; }
.crumbs { font-size: 13px; color: var(--muted); }
.seo-grid { display: grid; grid-template-columns: 1fr 300px; gap: 28px; align-items: start; }
.seo-map { height: 380px; border-radius: var(--radius); border: 1px solid var(--line); }
.seo-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.seo-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.seo-card h3 { margin: 0 0 6px; font-size: 15px; line-height: 1.3; }
.seo-card p { margin: 4px 0; font-size: 13px; }
.seo-card .tags { display: flex; flex-wrap: wrap; gap: 4px; }
.seo-actions { margin-top: 8px !important; }
.seo-side { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 12px; }
.seo-side h2 { margin: 8px 0 0; font-size: 16px; }
.dept-links { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow: hidden auto; font-size: 13px; display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; }
.dept-links li { padding: 2px 0; min-width: 0; overflow-wrap: anywhere; }
.dept-index { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 6px 20px; }
.dept-index li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.dept-index a { text-decoration: none; font-weight: 600; }
.dept-index a span { display: inline-block; min-width: 2.4em; color: var(--muted); font-weight: 400; }
.dept-index small { color: var(--muted); display: block; padding-left: 2.4em; }
.cta { margin-top: 32px; padding: 18px 20px; background: var(--green-soft); border-radius: var(--radius); }
.cta p { margin: 4px 0 12px; }
.legal h2 { font-size: 18px; }
.todo { background: #fff4e0; color: #8a5300; padding: 0 4px; border-radius: 4px; }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  html, body { height: auto; }
  .layout { grid-template-columns: 1fr; flex: none; }
  .map-wrap { height: 62vh; }
  .sidebar { border-left: 0; border-top: 1px solid var(--line); max-height: none; }
  .ad-tall { height: 250px; }
  .brand small { display: none; }
  .search { flex: 1 1 100%; order: 3; }
  .topbar .btn { flex: 1; }
  .seo-grid { grid-template-columns: 1fr; }
  .seo-side { position: static; }
  .seo h1 { font-size: 23px; }
  .seo-map { height: 300px; }
}
