/* Fournyl — design system "fiche de fournil". Tokens and rules: docs/DESIGN.md. */

@font-face { font-family: 'Atkinson Hyperlegible'; font-weight: 400; font-display: swap; src: url('../fonts/atkinson-hyperlegible-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Atkinson Hyperlegible'; font-weight: 700; font-display: swap; src: url('../fonts/atkinson-hyperlegible-latin-700-normal.woff2') format('woff2'); }
@font-face { font-family: 'Big Shoulders Display'; font-weight: 600; font-display: swap; src: url('../fonts/big-shoulders-display-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'Big Shoulders Display'; font-weight: 800; font-display: swap; src: url('../fonts/big-shoulders-display-latin-800-normal.woff2') format('woff2'); }
@font-face { font-family: 'Coustard'; font-weight: 400; font-display: swap; src: url('../fonts/coustard-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Courier Prime'; font-weight: 400; font-display: swap; src: url('../fonts/courier-prime-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Courier Prime'; font-weight: 700; font-display: swap; src: url('../fonts/courier-prime-latin-700-normal.woff2') format('woff2'); }

:root {
  /* Paper and ink */
  --paper: #FAF8F3;        /* farine: page background, almost white */
  --paper-2: #FFFEFB;      /* sheet: sidebar, panels on the map */
  --paper-3: #F0EBE1;      /* well: insets, segmented tracks, hover */
  --map-bg: #ECE7DD;
  --ink: #1C1A17;          /* text, rules, borders */
  --ink-2: #4A4339;        /* secondary text (8.3:1 on paper) */
  --ink-3: #6B6255;        /* captions, sources (5.1:1 on paper) */
  --rule-soft: #DCD3C2;    /* hairlines inside a sheet */
  /* Brand */
  --rouge: #FF0000;        /* the strong colour: brand mark, stamps, the one thing to look at. Never map data. */
  --rouge-deep: #C00000;
  --bleu: #1E3F8A;         /* bleu de travail: links, focus, and Go on the map */
  --bleu-deep: #142C63;
  --kraft: #D2B98E;        /* kraft: Avoid on the map, quiet fills */
  /* Map semantics: blue (good) <-> kraft (poor), Avoid also hatched. Colour-blind safe, no red/green. */
  --go-text: #1E3F8A;
  --avoid-text: #6E4E17;
  --hatch: repeating-linear-gradient(45deg, rgba(74, 52, 20, 0.6) 0 2px, transparent 2px 6px);

  --sidebar-w: 380px;
  --line: 1.5px solid var(--ink);
  --line-soft: 1px solid var(--rule-soft);
  --lift: 4px 4px 0 var(--ink);     /* hard offset: floating sheets on the map, never blurred */
  --font-ui: 'Atkinson Hyperlegible', system-ui, sans-serif;
  --font-brand: 'Coustard', Rockwell, 'Roboto Slab', Georgia, serif;
  --font-display: 'Big Shoulders Display', 'Arial Narrow', sans-serif-condensed, sans-serif;
  --font-num: 'Courier Prime', 'Courier New', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--paper); color: var(--ink); font-family: var(--font-ui); font-size: 15px; line-height: 1.45; }
a { color: var(--bleu); text-underline-offset: 2px; }
a:hover { color: var(--bleu-deep); text-decoration-thickness: 2px; }
button { font: inherit; }
:focus-visible { outline: 3px solid var(--bleu); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }

/* The label: monospace caps, the "printed form" voice of the system. */
.label, .sidebar h2, .card h3, .pg-card h3, .doc th, .pg-table th {
  font-family: var(--font-num); font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-2);
}

.app { display: flex; height: 100%; }

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 14px; border-bottom: 3px solid var(--rouge); }
.brand-link { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand-mark { width: 40px; height: 40px; flex-shrink: 0; display: block; }
.brand-name {
  margin: 0; font-family: var(--font-brand); font-weight: 400; font-size: 32px; line-height: 1;
  letter-spacing: 0;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; overflow-y: auto;
  background: var(--paper-2); border-right: var(--line); position: relative; z-index: 30;
}
.sidebar-body { padding: 24px 26px 24px; display: flex; flex-direction: column; gap: 22px; }
.sheet-toggle { display: none; }
.intro { color: var(--ink-2); margin: -8px 0 0; font-size: 14px; }
.sidebar h2 { margin: 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.link-btn { border: 0; background: transparent; padding: 4px 0; font-size: 13px; color: var(--bleu); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.help { margin: 6px 0 4px; font-size: 12px; line-height: 1.4; color: var(--ink-3); }
.filters { display: flex; flex-direction: column; }
#criteria { display: flex; flex-direction: column; gap: 16px; margin-top: 8px; }

.crit { display: flex; flex-direction: column; gap: 2px; }
.crit-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 28px; }
.crit-label { font-size: 14px; font-weight: 700; }
.crit-unit { font-weight: 400; color: var(--ink-3); font-size: 12px; }
.crit-vals { display: flex; justify-content: space-between; font-family: var(--font-num); font-size: 12px; color: var(--ink-3); }
.crit.is-empty .dual { opacity: 0.4; }

/* Dual range slider: two native inputs stacked on one track; chosen values in tags above. */
.dual { position: relative; height: 28px; margin-top: 26px; }
.bubble {
  position: absolute; top: -24px; transform: translateX(-50%); padding: 0 6px;
  background: var(--ink); color: var(--paper-2); font-family: var(--font-num); font-size: 12px; font-weight: 700; white-space: nowrap;
  pointer-events: none;
}
.bubble[hidden] { display: none; }
.dual .track, .dual .track-sel { position: absolute; top: 12px; height: 4px; }
.dual .track { left: 0; right: 0; background: var(--rule-soft); }
.dual .track-sel { background: var(--ink); }
.dual input[type=range] {
  position: absolute; left: 0; top: 0; width: 100%; height: 28px; margin: 0;
  background: transparent; pointer-events: none; -webkit-appearance: none; appearance: none;
}
.dual input[type=range]::-webkit-slider-runnable-track { background: transparent; height: 28px; }
.dual input[type=range]::-moz-range-track { background: transparent; }
.dual input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; pointer-events: auto; width: 22px; height: 26px; margin-top: 0;
  background: repeating-linear-gradient(90deg, var(--ink) 0 1.5px, transparent 1.5px 4px) center / 10px 12px no-repeat, var(--paper-2); border: 2px solid var(--ink); box-shadow: 2px 2px 0 var(--ink); cursor: grab;
  transition: transform .08s, box-shadow .08s;
}
.dual input[type=range]::-webkit-slider-thumb:hover { background: repeating-linear-gradient(90deg, var(--ink) 0 1.5px, transparent 1.5px 4px) center / 10px 12px no-repeat, var(--paper-3); }
.dual input[type=range]:active::-webkit-slider-thumb { cursor: grabbing; transform: translate(2px, 2px); box-shadow: none; }
.dual input[type=range]::-moz-range-thumb {
  pointer-events: auto; width: 18px; height: 22px; border-radius: 0; background: repeating-linear-gradient(90deg, var(--ink) 0 1.5px, transparent 1.5px 4px) center / 10px 12px no-repeat, var(--paper-2);
  border: 2px solid var(--ink); box-shadow: 2px 2px 0 var(--ink); cursor: grab;
}
.dual input[type=range]::-moz-range-thumb:hover { background: repeating-linear-gradient(90deg, var(--ink) 0 1.5px, transparent 1.5px 4px) center / 10px 12px no-repeat, var(--paper-3); }
.dual input[type=range]:active::-moz-range-thumb { cursor: grabbing; transform: translate(2px, 2px); box-shadow: none; }
.dual input[type=range]:focus-visible { outline: none; }
.dual input[type=range]:focus-visible::-webkit-slider-thumb { outline: 3px solid var(--bleu); outline-offset: 1px; }
.dual input[type=range]:focus-visible::-moz-range-thumb { outline: 3px solid var(--bleu); outline-offset: 1px; }

.top-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; border-top: var(--line-soft); }
.top-list li { border-bottom: var(--line-soft); }
.top-item {
  width: 100%; display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 6px 4px;
  border: 0; background: transparent; text-align: left; cursor: pointer; color: var(--ink);
}
.top-item:hover { background: var(--paper-3); }
.top-name { flex: 1; font-size: 14px; }
.top-score { font-family: var(--font-num); font-weight: 700; }
.top-empty { font-size: 13px; color: var(--ink-3); padding: 8px 0; border-bottom: 0 !important; }

.site-links { margin: 0; padding: 14px 0 0; border-top: var(--line); list-style: none; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; }
.site-note { margin: 0; font-size: 12px; color: var(--ink-3); }

.swatch { width: 14px; height: 14px; flex-shrink: 0; display: inline-block; border: 1px solid rgba(28, 26, 23, 0.35); }
.swatch-light { border-color: rgba(28, 26, 23, 0.45); }
.swatch.is-hatched { background-image: var(--hatch) !important; background-color: var(--kraft); }

/* ---------- Project mode: shop or round ---------- */
.mode { display: flex; flex-direction: column; gap: 6px; }
.mode-switch, .segmented { box-shadow: 3px 3px 0 var(--ink); }
.mode-switch { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border: var(--line); background: var(--paper-2); }
.mode-switch button {
  display: grid; grid-template-columns: 14px 1fr; column-gap: 8px; row-gap: 1px; align-content: center; min-height: 48px; padding: 6px 10px;
  border: 0; background: transparent; color: var(--ink); cursor: pointer; text-align: left;
}
.mode-switch button::before { grid-row: 1 / span 2; align-self: center; }
.mode-switch button b, .mode-switch button small { grid-column: 2; }
/* The radio box: empty square = available, filled square = chosen. Shape, not colour alone. */
.mode-switch button::before, .segmented button::before {
  content: ''; width: 14px; height: 14px; box-sizing: border-box; border: 2px solid currentColor; background: transparent;
}
.mode-switch button[aria-pressed="true"]::before, .segmented button[aria-pressed="true"]::before {
  background: radial-gradient(currentColor 0 0) center / 6px 6px no-repeat;
}
.mode-switch button:active, .segmented button:active { transform: translate(1px, 1px); }
.mode-switch button + button { border-left: var(--line); }
.mode-switch button b { font-size: 14px; }
.mode-switch button small { font-size: 11px; color: var(--ink-3); line-height: 1.25; }
.mode-switch button[aria-pressed="true"] { background: var(--ink); color: var(--paper-2); }
.mode-switch button[aria-pressed="true"] small { color: #DDD6C8; }
.mode-switch button:not([aria-pressed="true"]):hover { background: var(--paper-3); }
.mode-switch button:not([aria-pressed="true"]):hover b { text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Map and overlays ---------- */
.map-wrap { position: relative; flex: 1; min-width: 0; overflow: hidden; }
.map { position: absolute; inset: 0; background: var(--map-bg); }
.map-label {
  font-size: 12px; font-weight: 700; color: var(--ink); pointer-events: none; white-space: nowrap;
  text-shadow: 0 0 2px var(--paper-2), 0 0 2px var(--paper-2), 0 0 3px var(--paper-2);
}

.pill { background: var(--paper-2); border: var(--line); }
.topbar {
  position: absolute; left: 20px; right: 20px; top: 20px; z-index: 25;
  display: flex; align-items: center; gap: 12px; pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.topbar .mode { display: none; }
.grow { flex: 1; }
.breadcrumb { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 16px; font-size: 15px; white-space: nowrap; box-shadow: var(--lift); }
.breadcrumb .sep { color: var(--ink-3); }
.breadcrumb b { font-family: var(--font-display); font-size: 20px; font-weight: 800; letter-spacing: 0.03em; text-transform: uppercase; }
.counts { display: flex; align-items: center; gap: 6px; height: 44px; padding: 0 14px; font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.c-go { color: var(--go-text); }
.c-avoid { color: var(--avoid-text); }
.search { position: relative; }
.search input { width: 260px; height: 44px; padding: 0 14px; font: inherit; font-size: 14px; color: var(--ink); border-radius: 0; box-shadow: var(--lift); }
.search input::placeholder { color: var(--ink-3); }
#search-results {
  position: absolute; top: 50px; left: 0; right: 0; margin: 0; padding: 0; list-style: none;
  background: var(--paper-2); border: var(--line); box-shadow: var(--lift); max-height: 320px; overflow-y: auto;
}
#search-results li { display: flex; justify-content: space-between; gap: 8px; padding: 10px 12px; cursor: pointer; font-size: 14px; border-bottom: var(--line-soft); }
#search-results li small { color: var(--ink-3); font-family: var(--font-num); }
#search-results li[aria-selected="true"], #search-results li:hover { background: var(--paper-3); }
#search-results .search-none { cursor: default; color: var(--ink-3); }
.zoom { display: flex; overflow: hidden; box-shadow: var(--lift); }
.iconbtn { width: 44px; height: 42px; border: 0; background: transparent; font-size: 19px; cursor: pointer; color: var(--ink); display: grid; place-items: center; }
.iconbtn + .iconbtn { border-left: var(--line); }
.iconbtn:hover { background: var(--paper-3); }
.tool-btn { display: none; }
.tool-btn[aria-busy="true"] svg { animation: spin 1.2s linear infinite; }

.legend { position: absolute; left: 20px; bottom: 20px; z-index: 25; padding: 10px 12px; display: flex; flex-direction: column; gap: 7px; font-size: 12px; }
.legend .swatch { width: 16px; height: 16px; }
.legend > div { display: flex; flex-direction: column; align-items: stretch; gap: 6px; }
.legend > div[hidden] { display: none; }
.legend > div > div { display: flex; align-items: center; gap: 8px; }
.legend-title { font-family: var(--font-num); font-weight: 700; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; }
.legend-toggle { display: none; }

.tooltip {
  position: absolute; z-index: 26; padding: 9px 12px; display: flex; flex-direction: column; gap: 4px; min-width: 180px;
  background: var(--ink); color: var(--paper-2); pointer-events: none;
}
.tooltip[hidden] { display: none; }
.tip-name { font-family: var(--font-display); font-size: 19px; font-weight: 800; letter-spacing: 0.02em; text-transform: uppercase; line-height: 1.1; }
.tip-line { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.tip-pop { font-size: 12px; color: #DDD6C8; }

.status { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 20; font-size: 15px; color: var(--ink-2); }
.status:empty { display: none; }

/* ---------- Commune card (a ticket pinned on the map) ---------- */
.card {
  position: absolute; right: 20px; top: 80px; max-height: calc(100% - 100px); width: 340px; z-index: 27;
  padding: 18px 18px 16px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto;
  background: var(--paper-2); color: var(--ink); border: var(--line); box-shadow: var(--lift);
}
.card[hidden] { display: none; }
.card h3 { margin: 0 0 6px; }
.card section { display: flex; flex-direction: column; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; padding-bottom: 12px; border-bottom: var(--line); }
.card-name { margin: 0; font-family: var(--font-display); font-size: 30px; font-weight: 800; line-height: 1; letter-spacing: 0.02em; text-transform: uppercase; }
.card-name:focus { outline: none; }
.card-muted { font-size: 12px; color: var(--ink-3); margin: 4px 0 0; }
.card-close {
  width: 40px; height: 40px; flex-shrink: 0; border: var(--line); background: transparent; color: var(--ink); font-size: 22px; cursor: pointer; line-height: 1;
}
.card-close:hover { background: var(--paper-3); }
.card-score { display: flex; align-items: center; gap: 10px; }
.card-score .swatch { width: 20px; height: 20px; }
.card-score b { font-family: var(--font-num); font-size: 34px; line-height: 1; }
.card-score .card-muted { margin: 0; }
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; border-top: var(--line-soft); }
.kpi { display: flex; flex-direction: column; gap: 1px; padding: 8px 0; font-size: 12px; color: var(--ink-2); border-bottom: var(--line-soft); }
.kpi:nth-child(odd) { padding-right: 10px; border-right: var(--line-soft); }
.kpi:nth-child(even) { padding-left: 10px; }
.kpi b { font-family: var(--font-num); font-size: 19px; color: var(--ink); }
.kpi small { font-size: 11px; color: var(--ink-3); }
.card-source { margin: -4px 0 0; font-size: 11px; color: var(--ink-3); }
.card-actions { display: flex; gap: 8px; flex-shrink: 0; }
.card-page {
  flex: 1; height: 46px; display: flex; align-items: center; justify-content: center;
  background: var(--ink); color: var(--paper-2) !important; font-size: 14px; font-weight: 700; text-decoration: none; border: var(--line);
}
.card-page:hover { background: var(--bleu); border-color: var(--bleu); }
.card-star {
  width: 46px; height: 46px; border: var(--line); background: transparent; color: var(--ink); font-size: 20px; cursor: pointer;
}
.card-star[aria-pressed="true"] { color: var(--paper-2); background: var(--rouge); border-color: var(--rouge); }
.card-sources { margin: 0; font-size: 11px; line-height: 1.4; color: var(--ink-3); }
.card h4 { margin: 12px 0 2px; font-size: 12px; font-weight: 700; color: var(--ink-2); }

/* Shared figures used by the card and the commune page */
.pyr-head { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-3); margin-bottom: 4px; }
.pyr-row { display: grid; grid-template-columns: minmax(0, 1fr) 46px minmax(0, 1fr); align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); }
.pyr-m, .pyr-f { display: flex; align-items: center; gap: 4px; color: var(--ink-3); font-family: var(--font-num); }
.pyr-m { justify-content: flex-end; }
.pyr-m i, .pyr-f i { height: 10px; display: block; }
.pyr-m i { background: #3A6FB0; }
.pyr-f i { background: var(--kraft); }
.pyr-band { text-align: center; color: var(--ink-2); font-family: var(--font-num); }
.eco-row { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; padding: 6px 0; border-bottom: var(--line-soft); }
.eco-row small { color: var(--ink-3); font-size: 11px; }
.eco-row b { font-family: var(--font-num); }
.eco-price span { display: flex; flex-direction: column; gap: 2px; }
.eco-price small { line-height: 1.35; }
.eco-price b { white-space: nowrap; align-self: center; }
.sub { display: flex; flex-direction: column; gap: 3px; margin-bottom: 8px; }
.sub-head { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--ink-2); }
.sub-bar { height: 6px; background: var(--paper-3); }
.sub-bar i { display: block; height: 6px; background: var(--ink); }

.crumb { border: 0; background: transparent; padding: 0; color: var(--bleu); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; font-size: 15px; }
.breadcrumb .sep[hidden] { display: none; }

/* ---------- Delivery mode ---------- */
.delivery { display: flex; flex-direction: column; gap: 12px; padding: 14px; background: var(--paper-3); border: var(--line-soft); }
.delivery[hidden] { display: none; }
.segmented { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border: var(--line); background: var(--paper-2); }
.segmented button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; border: 0; font-size: 13px; font-weight: 700; cursor: pointer; background: transparent; color: var(--ink); }
.segmented button:not([aria-pressed="true"]):hover { background: var(--paper-3); text-decoration: underline; text-underline-offset: 3px; }
.segmented button + button { border-left: var(--line); }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--paper-2); }
.delivery-range { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; font-weight: 700; }
.delivery-range output { font-family: var(--font-num); font-weight: 700; color: var(--ink); }
.single { width: 100%; accent-color: var(--ink); height: 28px; margin: 0; }
.reach { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; font-size: 12px; color: var(--ink-2); }
.reach div { display: flex; flex-direction: column; gap: 2px; }
.reach b { font-family: var(--font-num); font-size: 20px; color: var(--ink); }
.reach b.is-opportunity { color: var(--go-text); }
.reach p { grid-column: 1 / -1; margin: 0; font-size: 12px; }
.filters-off { font-size: 12px; color: var(--ink-3); margin: 0; }
.filters[hidden], .filters-off[hidden] { display: none; }
.bakehouse-pin { width: 18px; height: 18px; background: var(--ink); border: 3px solid var(--paper-2); outline: 1.5px solid var(--ink); transform: rotate(45deg); }

/* Map loading indicator: shown while commune polygons download or draw. */
.map-busy {
  position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 26;
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  background: var(--paper-2); border: var(--line); box-shadow: var(--lift); font-size: 13px; color: var(--ink-2);
}
.map-busy[hidden] { display: none; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--rule-soft); border-top-color: var(--ink); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

/* ---------- Notice (first visit) and filters note on phones ---------- */
.notice {
  position: absolute; right: 20px; bottom: 20px; z-index: 28; width: min(420px, calc(100% - 40px));
  padding: 14px 16px; background: var(--paper-2); border: var(--line); box-shadow: var(--lift); font-size: 13px;
}
.notice[hidden] { display: none; }
.notice p { margin: 0 0 10px; }
.notice .notice-title { font-family: var(--font-num); font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 6px; }
.notice-actions { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 18px;
  background: var(--ink); color: var(--paper-2); border: var(--line); font-weight: 700; text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--bleu); border-color: var(--bleu); color: var(--paper-2); }
.btn-ghost { background: transparent; color: var(--ink); }
.btn-ghost:hover { background: var(--paper-3); color: var(--ink); border-color: var(--ink); }
.mobile-filters { display: none; }

/* ---------- Phones: map first, ranking in a bottom sheet, no sliders ---------- */
@media (max-width: 720px) {
  .app { display: block; }
  .map-wrap { position: absolute; inset: 0; }
  .sidebar {
    position: absolute; left: 0; right: 0; bottom: 0; width: auto; max-height: 56px; overflow: hidden;
    border-right: 0; border-top: var(--line); transition: max-height 0.2s;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .sidebar.is-open { max-height: 72vh; overflow-y: auto; }
  .sheet-toggle {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; height: 56px; padding: 0 16px; border: 0;
    font-family: var(--font-num); font-weight: 700; font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; cursor: pointer; color: var(--ink);
    position: sticky; top: 0; z-index: 1; background: var(--paper-2); border-bottom: var(--line-soft);
  }
  .sheet-toggle::after { content: '▲'; font-size: 11px; }
  .sidebar.is-open .sheet-toggle::after { content: '▼'; }
  .sidebar-body { padding: 14px 16px 24px; }
  .sidebar .brand, .sidebar .intro, .sidebar .filters, .sidebar .filters-off, .sidebar .mode { display: none; }
  .mobile-filters { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 0; font-size: 12px; color: var(--ink-2); }
  .mobile-filters[hidden] { display: none; }

  .topbar { left: 12px; right: 12px; top: calc(10px + env(safe-area-inset-top)); flex-wrap: wrap; gap: 8px; }
  .breadcrumb, .zoom, .counts { display: none; }
  .grow { display: block; }
  .tool-btn { display: grid; width: 44px; height: 44px; background: var(--paper-2); }
  .search { display: none; }
  .topbar.is-searching .search { display: block; flex: 1 1 100%; order: 2; }
  .topbar.is-searching .tool-btn#search-open { background: var(--ink); color: var(--paper-2); }
  .topbar .brand-chip { display: grid; }
  .search input { width: 100%; box-shadow: none; }
  #search-results { box-shadow: none; }
  .topbar .mode { display: flex; flex: 1 1 100%; order: 1; }
  .topbar .mode .label { display: none; }
  .mode-switch button { min-height: 40px; padding: 4px 10px; }
  .mode-switch button small { display: none; }
  .legend { left: 12px; bottom: 68px; padding: 6px 8px; gap: 4px; font-size: 11px; max-width: calc(100% - 24px); }
  .legend .legend-toggle { display: block; }
  .legend.is-collapsed > div { display: none; }
  .legend-toggle { border: 0; background: transparent; padding: 2px 0; font: inherit; font-family: var(--font-num); font-weight: 700; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink); cursor: pointer; text-align: left; }
  /* The card shrinks to a strip over the map; the details live on the commune page (its own URL). */
  .card {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: auto; max-height: none; z-index: 40; gap: 10px;
    border-width: 1.5px 0 0; box-shadow: none; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  }
  .card .kpis, .card .card-source { display: none; }
  .card-head { padding-bottom: 8px; }
  .card-name { font-size: 24px; }
  .card-score b { font-size: 26px; }
  .map-busy { bottom: auto; top: calc(116px + env(safe-area-inset-top)); }
  .notice { left: 12px; right: 12px; top: calc(116px + env(safe-area-inset-top)); bottom: auto; width: auto; }
}
.brand-chip { display: none; width: 44px; height: 44px; place-items: center; flex-shrink: 0; }
.brand-chip img { width: 44px; height: 44px; display: block; }

/* ---------- Text pages: sources, updates, legal ---------- */
body.doc { height: auto; background: var(--paper); }
.doc-top { border-bottom: var(--line); background: var(--paper-2); }
.doc-top-inner { max-width: 820px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.doc-top .brand-link .brand-mark { width: 32px; height: 32px; }
.doc-top .brand-name { font-size: 25px; }
.doc-main { max-width: 820px; margin: 0 auto; padding: 28px 16px 48px; }
.doc h1 { font-family: var(--font-display); font-weight: 800; font-size: 46px; line-height: 1; letter-spacing: 0.02em; text-transform: uppercase; margin: 8px 0 14px; }
.doc h2 { font-family: var(--font-display); font-weight: 800; font-size: 26px; letter-spacing: 0.02em; text-transform: uppercase; margin: 36px 0 10px; padding-top: 10px; border-top: var(--line); }
.doc h3 { font-size: 16px; margin: 20px 0 6px; }
.doc-intro { font-size: 17px; color: var(--ink-2); margin: 0; }
.doc ul { padding-left: 20px; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.doc li { line-height: 1.55; }
.doc p { line-height: 1.6; }
.table-wrap { overflow-x: auto; border: var(--line); background: var(--paper-2); }
.doc table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 640px; }
.doc th, .doc td { text-align: left; padding: 9px 12px; border-bottom: var(--line-soft); vertical-align: top; }
.doc th { font-size: 11px; border-bottom: var(--line); }
.doc td.num, .doc td .num { white-space: nowrap; }
.doc tr:last-child td { border-bottom: 0; }
.doc-footer { margin-top: 28px; font-size: 13px; color: var(--ink-3); }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); border: var(--line); background: var(--paper-2); margin: 18px 0 0; }
.facts div { padding: 12px 14px; border-right: var(--line-soft); border-bottom: var(--line-soft); }
.facts span { display: block; font-family: var(--font-num); font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-2); }
.facts b { display: block; font-family: var(--font-num); font-size: 20px; margin-top: 2px; }
.callout { margin: 18px 0; padding: 14px 16px; border: var(--line); border-left-width: 6px; border-left-color: var(--rouge); background: var(--paper-2); }
.callout p { margin: 0; }
.callout p + p { margin-top: 8px; }

.site-footer { border-top: var(--line); background: var(--paper-2); }
.site-footer-inner { max-width: 1180px; margin: 0 auto; padding: 18px 24px 28px; display: flex; flex-direction: column; gap: 10px; font-size: 13px; color: var(--ink-2); }
.site-footer ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 18px; }
.site-footer p { margin: 0; max-width: 80ch; }
.doc .site-footer-inner { max-width: 820px; padding: 18px 16px 28px; }

/* Infos légales: one page, internal navigation */
.legal-nav { margin: 20px 0 8px; border: var(--line); background: var(--paper-2); position: sticky; top: 0; z-index: 2; }
.legal-nav ol { list-style: none; margin: 0; padding: 0; display: flex; overflow-x: auto; }
.legal-nav li { flex: 1 0 auto; }
.legal-nav li + li { border-left: var(--line-soft); }
.legal-nav a { display: block; padding: 11px 14px; font-family: var(--font-num); font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink); text-decoration: none; white-space: nowrap; text-align: center; }
.legal-nav a:hover { background: var(--paper-3); }
.legal-part { scroll-margin-top: 56px; }
.legal-part .doc-intro { margin-bottom: 4px; }

/* Ma sélection */
.sel-list { list-style: none; padding: 0; margin: 8px 0 0; border: var(--line); background: var(--paper-2); display: block; }
.sel-list li { display: grid; grid-template-columns: 24px 14px minmax(0, 1fr) auto 44px; align-items: center; gap: 10px; padding: 6px 4px 6px 12px; border-bottom: var(--line-soft); }
.sel-list li:last-child { border-bottom: 0; }
.sel-list input { width: 20px; height: 20px; accent-color: var(--ink); margin: 0; }
.sel-list a { font-weight: 700; }
.sel-list small { grid-column: 3; grid-row: 2; margin-top: -4px; color: var(--ink-3); font-size: 12px; }
.sel-list b { grid-column: 4; grid-row: 1 / span 2; font-size: 20px; }
.sel-remove { grid-column: 5; grid-row: 1 / span 2; width: 40px; height: 40px; border: var(--line); background: transparent; font-size: 20px; cursor: pointer; }
.sel-remove:hover { background: var(--paper-3); }
.doc .sel-list { padding: 0; gap: 0; }
.doc .sel-table th[scope="row"] { border-bottom: var(--line-soft); position: sticky; left: 0; background: var(--paper-2); z-index: 1; border-right: var(--line-soft); }
.sel-table { min-width: 0 !important; }
@media (max-width: 520px) {
  .sel-table .best-tag { display: block; width: max-content; margin-top: 3px; }
  .sel-table th, .sel-table td { padding: 8px 8px; }
  .sel-table thead th a { font-size: 17px; }
}
.sel-table th[scope="row"] { font-family: var(--font-ui); font-size: 13px; letter-spacing: 0; text-transform: none; color: var(--ink); font-weight: 700; }
.sel-table thead th a { font-family: var(--font-display); font-size: 20px; letter-spacing: 0.02em; text-transform: uppercase; color: var(--ink); }
.sel-table thead th small { font-family: var(--font-ui); text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--ink-3); }
.sel-table td { font-family: var(--font-num); }
.sel-table td.is-best { font-weight: 700; background: #EEF1F7; }
.best-tag { display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; padding: 0 4px; border: 1px solid var(--bleu); color: var(--bleu); }

/* ---------- Commune page ---------- */
body.page { height: auto; background: var(--paper); overflow-x: clip; }
.page-top {
  /* Full-width band; its content lines up with .page-main (max 1180 px, 24 px gutter). */
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 12px max(24px, calc((100% - 1180px) / 2 + 24px));
  background: var(--paper-2); border-bottom: var(--line);
  position: sticky; top: 0; z-index: 21; /* constant height, so sticking never moves the page */
}
.page-brand { display: flex; align-items: center; gap: 8px; font-family: var(--font-brand); font-size: 25px; font-weight: 400; letter-spacing: 0; color: var(--ink); text-decoration: none; }
.page-brand img { width: 32px; height: 32px; }
.page-crumbs { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; color: var(--ink-3); }
.page-main { max-width: 1180px; margin: 0 auto; padding: 28px 24px 56px; }
.page-title { margin: 0; font-family: var(--font-display); font-size: 58px; font-weight: 800; letter-spacing: 0.01em; line-height: 0.95; text-transform: uppercase; }
.page-lead { color: var(--ink-2); }
.pg-muted { color: var(--ink-3); margin: 6px 0 0; }
.pg-muted.small { font-size: 12px; margin-top: 2px; }
.pg-hero { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 28px; align-items: start; }
.pg-head { margin: 0; }
/* Compact copy of name + postcode + score, fixed under the sticky top band once the block has scrolled away. */
.pg-fixbar {
  position: fixed; top: var(--top-h, 0px); left: 0; right: 0; z-index: 20; background: var(--paper-2); border-bottom: var(--line);
  transform: translateY(-100%); visibility: hidden; transition: transform .18s ease, visibility 0s .18s;
}
.pg-fixbar.is-on { transform: none; visibility: visible; transition: transform .18s ease; }
.pg-fixbar-inner { max-width: 1180px; margin: 0 auto; padding: 8px 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.pg-fixbar-id { display: grid; min-width: 0; }
.pg-fixbar-id b { font-family: var(--font-display); font-size: 26px; font-weight: 800; letter-spacing: 0.02em; text-transform: uppercase; line-height: 1.15; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pg-fixbar-id small { font-size: 12px; color: var(--ink-3); }
.pg-fixbar-score { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.pg-fixbar-score .swatch { width: 18px; height: 18px; }
.pg-fixbar-score b { font-family: var(--font-num); font-size: 26px; line-height: 1; }
.pg-fixbar-score span:last-child { color: var(--ink-2); font-size: 14px; }
@media (prefers-reduced-motion: reduce) { .pg-fixbar, .pg-fixbar.is-on { transition: none; } }
.pg-score { display: flex; align-items: center; gap: 12px; margin-top: 16px; padding: 10px 0; border-top: var(--line); border-bottom: var(--line); }
.pg-score .swatch { width: 24px; height: 24px; }
.pg-score b { font-family: var(--font-num); font-size: 46px; line-height: 1; }
.pg-score span:last-child { color: var(--ink-2); }
.pg-summary { font-size: 17px; line-height: 1.5; margin: 14px 0 0; max-width: 62ch; }
.pg-actions { display: flex; gap: 8px; margin: 16px 0 20px; }
.pg-button {
  display: inline-flex; align-items: center; height: 46px; padding: 0 18px; border: var(--line);
  background: var(--ink); color: var(--paper-2); font-weight: 700; text-decoration: none;
}
.pg-button:hover { background: var(--bleu); border-color: var(--bleu); color: var(--paper-2); }
.pg-star { width: 46px; height: 46px; border: var(--line); background: var(--paper-2); font-size: 20px; cursor: pointer; color: var(--ink); }
.pg-star[aria-pressed="true"] { color: var(--paper-2); background: var(--rouge); border-color: var(--rouge); }
.pg-tiles.is-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.pg-none { display: grid; gap: 4px; margin: 8px 0; padding: 14px 16px; border: var(--line); background: var(--paper-2); }
.pg-none b { font-size: 18px; }
.pg-none span { color: var(--ink-2); }
.pg-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 8px 0; border: var(--line); background: var(--paper-2); }
.pg-tile { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border-right: var(--line-soft); border-bottom: var(--line-soft); }
.pg-tile span { font-family: var(--font-num); font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-2); }
.pg-tile b { font-family: var(--font-num); font-size: 24px; }
.pg-tile small { font-size: 11px; color: var(--ink-3); }
.pg-locator { margin: 0; }
.pg-locator-map { height: 380px; overflow: hidden; border: var(--line); background: var(--paper); }
.pg-locator figcaption { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; font-size: 12px; color: var(--ink-2); }
.pg-locator figcaption span { display: inline-flex; align-items: center; gap: 6px; }
.pg-locator figcaption i { width: 12px; height: 12px; display: inline-block; border: 1px solid rgba(28, 26, 23, 0.35); }
.map-label.is-here { font-size: 13px; font-weight: 700; }
.pg-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-top: 28px; }
.pg-card { padding: 20px 22px; background: var(--paper-2); border: var(--line); min-width: 0; }
.pg-card.is-wide { grid-column: 1 / -1; }
.pg-card h2 { margin: 0 0 12px; font-family: var(--font-display); font-weight: 800; font-size: 28px; letter-spacing: 0.02em; text-transform: uppercase; line-height: 1; }
.pg-card h3 { margin: 18px 0 6px; }
.pg-row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: var(--line-soft); font-size: 14px; }
.pg-row small { color: var(--ink-3); font-size: 12px; }
.pg-row b { font-family: var(--font-num); text-align: right; }
.pg-price span { display: flex; flex-direction: column; gap: 2px; }
.pg-price b { align-self: center; white-space: nowrap; }
.pg-bar { display: grid; grid-template-columns: minmax(0, 11rem) minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 4px 0; font-size: 13px; }
.pg-bar small { color: var(--ink-3); }
.pg-bar b { font-family: var(--font-num); white-space: nowrap; }
.pg-bar-track { height: 10px; background: var(--paper-3); }
.pg-bar-track i { display: block; height: 10px; background: var(--ink); }
.pg-why { margin: 10px 0; }
.pg-why-head { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 4px 12px; font-size: 14px; margin-bottom: 4px; }
.pg-why-head small { color: var(--ink-3); }
.pg-why-label small { white-space: nowrap; }
/* Rank in big figures; the criterion's weight in small caps under it: present, never competing. */
.pg-why-rank { display: grid; justify-items: end; text-align: right; white-space: nowrap; }
.pg-why-rank b { font-family: var(--font-num); font-size: 18px; line-height: 1; }
.pg-why-rank small { font-family: var(--font-num); font-size: 12px; }
.pg-why-weight { font-family: var(--font-num); font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
.pg-why-na { font-size: 14px; color: var(--ink-2); }
.pg-why.is-missing .pg-why-label { color: var(--ink-2); }
.pg-why-note { margin: 12px 0 0; font-size: 12px; color: var(--ink-3); }
.pg-why-title { display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pg-why-score { font-family: var(--font-num); font-size: 22px; font-weight: 700; letter-spacing: 0; text-transform: none; padding: 2px 8px; background: var(--ink); color: var(--paper-2); }
/* "?" next to a section title: opens an explanation panel (a disclosure, not a hover tooltip, so it works on touch and keyboard). */
.info-btn {
  width: 26px; height: 26px; display: inline-grid; place-items: center; padding: 0; cursor: pointer;
  font-family: var(--font-num); font-size: 15px; font-weight: 700; color: var(--ink);
  background: var(--paper-2); border: 1.5px solid var(--ink); box-shadow: 2px 2px 0 var(--ink);
}
.info-btn:hover { background: var(--paper-3); }
.info-btn[aria-expanded="true"] { background: var(--ink); color: var(--paper-2); box-shadow: none; transform: translate(2px, 2px); }
.info-pop { margin: 12px 0 6px; padding: 12px 14px; background: var(--paper-3); border: var(--line); font-size: 13px; line-height: 1.5; }
.info-pop ul { margin: 0 0 8px; padding-left: 18px; display: grid; gap: 6px; }
.info-pop[hidden] { display: none; }
.pg-chart { width: 100%; height: auto; display: block; }
.pg-chart text { font-size: 11px; fill: var(--ink-3); font-family: var(--font-num); }
.pg-chart .grid { stroke: var(--rule-soft); }
.pg-chart .line { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; }
.pg-chart .dot { fill: var(--rouge); stroke: var(--paper-2); stroke-width: 1.5; }
.pg-chart-wrap { position: relative; touch-action: pan-y; }
.pg-chart .guide { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 3 3; }
.pg-chart .dot-on { fill: var(--rouge); stroke: var(--ink); stroke-width: 2; }
.pg-chart-tip {
  position: absolute; transform: translate(-50%, calc(-100% - 12px)); pointer-events: none; white-space: nowrap;
  padding: 3px 8px; background: var(--ink); color: var(--paper-2); font-family: var(--font-num); font-size: 13px; font-weight: 700;
}
.pg-table-wrap { overflow-x: auto; }
.pg-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.pg-table th, .pg-table td { text-align: left; padding: 7px 8px; border-bottom: var(--line-soft); }
.pg-table th { font-size: 11px; border-bottom: var(--line); }
.pg-table td:not(:first-child), .pg-table th:not(:first-child) { text-align: right; font-family: var(--font-num); }
.pg-table tr.is-here td { font-weight: 700; background: var(--paper-3); }
.pg-sources { margin-top: 28px; font-size: 12px; color: var(--ink-3); }
.pg-bread { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 18px; align-items: start; }
.pg-bread-map { height: 420px; overflow: hidden; border: var(--line); }
.pg-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--ink-2); margin-bottom: 8px; }
.pg-legend span { display: inline-flex; align-items: center; gap: 6px; }
.pg-legend i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.pg-legend i.is-pin { background: var(--ink); border: 2px solid var(--paper-2); box-shadow: 0 0 0 1px var(--ink); }
.pg-points { list-style: none; margin: 0; padding: 0; max-height: 360px; overflow-y: auto; }
.pg-points li { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 7px 0; border-bottom: var(--line-soft); font-size: 13px; }
.pg-points small { color: var(--ink-3); }
.pg-points b { font-family: var(--font-num); white-space: nowrap; }
.pg-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.bread-pin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid #FFFFFF; box-shadow: 0 0 0 1px var(--ink); cursor: pointer; padding: 0; }
.bread-pin:focus-visible { outline: 3px solid var(--bleu); outline-offset: 2px; }
.pg-photo { margin: 0 0 22px; overflow: hidden; background: var(--map-bg); position: relative; border: var(--line); }
.pg-photo[hidden] { display: none; }
.pg-photo img { display: block; width: 100%; height: 320px; object-fit: cover; filter: saturate(0.9); }
.pg-photo figcaption {
  position: absolute; right: 0; bottom: 0; max-width: 100%; padding: 4px 10px; font-size: 11px; color: var(--paper-2);
  background: rgba(28, 26, 23, 0.82); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pg-photo figcaption a { color: var(--paper-2); }
.pg-wiki { margin: 8px 0 0; font-size: 14px; }
.pg-disclaimer { margin-top: 18px; }

@media (max-width: 900px) {
  .pg-hero, .pg-grid { grid-template-columns: minmax(0, 1fr); }
  .pg-locator-map { height: 300px; }
  .pg-bread { grid-template-columns: minmax(0, 1fr); }
  .pg-bread-map { height: 320px; }
}
@media (max-width: 520px) {
  .page-main { padding: 20px 16px 40px; }
  .pg-fixbar-inner { padding: 8px 16px; }
  .pg-fixbar-id b, .pg-fixbar-score b { font-size: 22px; }
  .pg-fixbar-score span:last-child { font-size: 12px; }
  .page-top { padding: 10px max(16px, calc((100% - 1180px) / 2 + 16px)); gap: 6px 14px; }
  .page-title { font-size: 42px; }
  .pg-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pg-card { padding: 16px 14px; }
  .pg-bar { grid-template-columns: minmax(0, 1fr) auto; }
  .pg-bar .pg-bar-track { grid-column: 1 / -1; grid-row: 2; }
  .pg-photo img { height: 200px; }
  .pg-photo figcaption { white-space: normal; }
  .doc h1 { font-size: 38px; }
  .site-footer-inner { padding: 16px 16px 24px; }
}
