/* === Design tokens === */
:root {
  --layer-ville: #1E5AA8;
  --layer-ems: #6E3AA8;
  --layer-region: #D4A017;
  --layer-sers: #C23030;
  --layer-spl: #14B8A6;
  --layer-hm: #15803D;
  --layer-assoc: #F59E0B;
  --layer-artf: #84CC16;
  --layer-vacante: #FACC15;
  --layer-parcel: #9CA3AF;
  --layer-bp: #1F2937;
  --layer-inconnu: #EC4899;
  --layer-conflict: #DC2626;

  --conf-confirmed: #15803D;
  --conf-probable: #1E5AA8;
  --conf-check: #D4A017;
  --conf-conflict: #C23030;

  --surface: #FAF7F2;
  --surface-elevated: #FFFFFF;
  --surface-sunken: #F2EDE4;
  --surface-ink: #1A1815;
  --surface-muted: #6B6559;
  --surface-border: #E5DED0;
  --shadow-pop: 0 8px 24px -8px rgba(26, 24, 21, 0.18);

  --font-sans: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --font-serif: 'Fraunces', Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-sans);
  color: var(--surface-ink);
  background: var(--surface);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--layer-ville); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Topbar === */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--surface-elevated);
  border-bottom: 1px solid var(--surface-border);
}
.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--surface-ink); }
.brand-mark {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, var(--layer-ville), var(--layer-ems), var(--layer-assoc), var(--layer-artf), var(--layer-ville));
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-family: var(--font-serif); font-weight: 600; font-size: 15px; }
.brand-text em { font-style: normal; font-size: 11px; color: var(--surface-muted); letter-spacing: 0.02em; }

.topnav { display: flex; gap: 4px; font-size: 13px; }
.topnav a {
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--surface-muted);
}
.topnav a:hover { background: var(--surface-sunken); text-decoration: none; color: var(--surface-ink); }
.topnav a.active { color: var(--surface-ink); background: var(--surface-sunken); }

/* === App layout === */
.app {
  position: relative;
  display: grid;
  grid-template-columns: 320px 1fr;
  height: calc(100dvh - 48px - 34px);
  min-height: 520px;
}
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; height: calc(100dvh - 48px - 34px); }
  .panel { position: absolute; left: 12px; top: 12px; width: min(320px, calc(100% - 24px)); max-height: calc(100% - 24px); overflow: auto; z-index: 10; }
}

.panel {
  background: var(--surface-elevated);
  border-right: 1px solid var(--surface-border);
  overflow-y: auto;
  padding: 16px 16px 20px;
}
.panel-section { padding: 0 0 16px; border-bottom: 1px solid var(--surface-border); margin-bottom: 14px; }
.panel-section:last-child { border-bottom: none; margin-bottom: 0; }
.panel-title { font-family: var(--font-serif); font-weight: 600; font-size: 16px; margin: 0 0 4px; }
.panel-subtitle { font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--surface-muted); margin: 0 0 8px; }
.panel-counts { font-size: 12px; color: var(--surface-muted); margin: 0 0 14px; }

.field { margin: 12px 0; }
.field-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--surface-muted); margin-bottom: 6px; display: block; }
.field-value { font-size: 12px; color: var(--surface-muted); font-variant-numeric: tabular-nums; min-width: 56px; text-align: right; }
.row { display: flex; align-items: center; gap: 8px; }
.row input[type=range] { flex: 1; accent-color: var(--layer-ville); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.chip {
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--surface-border);
  background: var(--surface-elevated);
  color: var(--surface-ink);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.12s;
}
.chip:hover { background: var(--surface-sunken); }
.chip[aria-pressed="true"] { background: var(--layer-ville); border-color: var(--layer-ville); color: white; }

.layers { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.layer-toggle {
  display: flex; align-items: center; gap: 7px;
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid var(--surface-border);
  background: var(--surface-elevated);
  font-size: 12px;
  cursor: pointer;
  text-align: left;
  transition: all 0.12s;
}
.layer-toggle:hover { background: var(--surface-sunken); }
.layer-toggle.off { opacity: 0.55; background: var(--surface-sunken); }
.layer-toggle .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.layer-toggle .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.segmented {
  display: inline-flex;
  border: 1px solid var(--surface-border);
  border-radius: 6px;
  overflow: hidden;
  font-size: 12px;
}
.segmented button {
  padding: 5px 10px;
  border: none;
  background: var(--surface-elevated);
  color: var(--surface-ink);
  cursor: pointer;
}
.segmented button.active { background: var(--surface-ink); color: white; }

/* Hierarchy block */
.hierarchy-list { list-style: none; padding: 0; margin: 0 0 8px; font-size: 12px; color: var(--surface-ink); display: flex; flex-direction: column; gap: 6px; }
.hierarchy-list li { line-height: 1.4; }
.tier {
  display: inline-block;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  margin-right: 6px;
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.t1 { background: rgba(21, 128, 61, 0.1); color: var(--conf-confirmed); }
.t2 { background: rgba(30, 90, 168, 0.1); color: var(--layer-ville); }
.t3 { background: rgba(212, 160, 23, 0.12); color: var(--conf-check); }
.hierarchy-rule {
  margin: 8px 0 0;
  padding: 6px 10px;
  border-left: 3px solid var(--layer-conflict);
  background: rgba(220, 38, 38, 0.05);
  font-size: 12px;
  font-weight: 500;
  color: var(--layer-conflict);
  border-radius: 0 4px 4px 0;
}

/* === Map === */
.map-wrap { position: relative; background: var(--surface-sunken); }
#map { position: absolute; inset: 0; }
.maplibregl-ctrl-bottom-right { margin-bottom: 8px; margin-right: 8px; }

.card {
  background: var(--surface-elevated);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  box-shadow: var(--shadow-pop);
}
.legend {
  position: absolute;
  right: 12px;
  bottom: 12px;
  padding: 8px 10px 10px;
  font-size: 12px;
  min-width: 210px;
  z-index: 10;
}
.legend .legend-title { text-transform: uppercase; letter-spacing: 0.08em; font-size: 10px; color: var(--surface-muted); margin-bottom: 6px; }
.legend ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.legend li { display: flex; align-items: center; gap: 7px; }
.legend li .dot { width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 0 1px rgba(255,255,255,0.9); flex-shrink: 0; }
.legend li .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* === Sidebar === */
.sidebar {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 420px;
  background: var(--surface-elevated);
  border-left: 1px solid var(--surface-border);
  box-shadow: var(--shadow-pop);
  overflow-y: auto;
  z-index: 20;
  animation: slide-in 0.18s ease-out;
}
@media (max-width: 600px) { .sidebar { width: 100%; } }
@keyframes slide-in { from { transform: translateX(12px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.sidebar-head {
  position: sticky; top: 0;
  background: var(--surface-elevated);
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--surface-border);
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  z-index: 1;
}
.sidebar-layer { display: flex; align-items: center; gap: 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--surface-muted); }
.sidebar-dot { width: 8px; height: 8px; border-radius: 50%; }
.sidebar-title { font-family: var(--font-serif); font-size: 19px; font-weight: 600; line-height: 1.2; margin: 4px 0 0; }
.sidebar-addr { font-size: 13px; color: var(--surface-muted); margin: 4px 0 0; }
.sidebar-close { background: none; border: none; font-size: 26px; line-height: 1; color: var(--surface-muted); cursor: pointer; padding: 0 4px; }
.sidebar-close:hover { color: var(--surface-ink); }

.sidebar-body { padding: 16px 20px 24px; display: flex; flex-direction: column; gap: 18px; }
.sidebar-body h3 { font-size: 13px; font-weight: 600; margin: 0 0 10px; }
.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kv .k { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--surface-muted); margin-bottom: 2px; }
.kv .v { font-size: 14px; }
.kv .v.mono { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.kv .v.accent { color: var(--layer-ville); font-weight: 600; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid;
}
.badge-confirmed { color: var(--conf-confirmed); border-color: var(--conf-confirmed); background: rgba(21,128,61,0.06); }
.badge-probable { color: var(--conf-probable); border-color: var(--conf-probable); background: rgba(30,90,168,0.06); }
.badge-check { color: var(--conf-check); border-color: var(--conf-check); background: rgba(212,160,23,0.08); }
.badge-conflict { color: var(--conf-conflict); border-color: var(--conf-conflict); background: rgba(194,48,48,0.06); }

.note {
  font-size: 12px;
  color: var(--surface-muted);
  border-top: 1px solid var(--surface-border);
  padding-top: 12px;
  line-height: 1.55;
}
.sources-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.sources-list a { font-size: 12px; word-break: break-all; }

.signal {
  padding: 8px 10px;
  background: var(--surface-sunken);
  border: 1px solid var(--surface-border);
  border-radius: 6px;
  font-size: 13px;
}
.signal .k { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--surface-muted); margin-bottom: 2px; }

/* === Footer === */
.footer {
  height: 34px;
  background: var(--surface-elevated);
  border-top: 1px solid var(--surface-border);
  font-size: 11px;
  color: var(--surface-muted);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
}
.footer a { color: var(--surface-muted); text-decoration: underline; text-decoration-color: var(--surface-border); }
.footer a:hover { color: var(--surface-ink); }

/* === Methodology page === */
.prose {
  max-width: 780px;
  margin: 0 auto;
  padding: 32px 20px 60px;
}
.prose h1 { font-family: var(--font-serif); font-size: 32px; font-weight: 600; margin: 0 0 8px; }
.prose h2 { font-family: var(--font-serif); font-size: 20px; font-weight: 600; margin: 32px 0 10px; }
.prose p, .prose li { font-size: 15px; line-height: 1.6; }
.prose ul, .prose ol { padding-left: 22px; }
.prose li { margin: 4px 0; }
.prose strong { font-weight: 600; }
.prose .lead { color: var(--surface-muted); font-size: 15px; margin: 0 0 24px; }

.tier-table { border: 1px solid var(--surface-border); border-radius: 8px; overflow: hidden; margin: 12px 0 16px; }
.tier-table .row {
  display: grid;
  grid-template-columns: 200px 1fr;
  border-bottom: 1px solid var(--surface-border);
}
.tier-table .row:last-child { border-bottom: none; }
.tier-table .left {
  padding: 10px 12px;
  border-right: 1px solid var(--surface-border);
  font-weight: 600;
  font-size: 13px;
}
.tier-table .right { padding: 10px 12px; font-size: 14px; }
.tier-table .row.n1 .left { background: rgba(21, 128, 61, 0.08); color: var(--conf-confirmed); }
.tier-table .row.n2 .left { background: rgba(30, 90, 168, 0.08); color: var(--conf-probable); }
.tier-table .row.n3 .left { background: rgba(212, 160, 23, 0.1); color: var(--conf-check); }

.callout {
  margin: 16px 0;
  padding: 12px 14px;
  border-left: 4px solid var(--layer-conflict);
  background: rgba(220,38,38,0.04);
  font-size: 14px;
}

.def-list {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 8px 14px;
  font-size: 14px;
  margin: 8px 0;
}
.def-list dt { font-weight: 600; }
.def-list dd { margin: 0; color: var(--surface-muted); }

/* Sidebar scrollbar polish */
.sidebar::-webkit-scrollbar, .panel::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb, .panel::-webkit-scrollbar-thumb { background: var(--surface-border); border-radius: 999px; }
.sidebar::-webkit-scrollbar-thumb:hover, .panel::-webkit-scrollbar-thumb:hover { background: var(--surface-muted); }
