:root {
  --hopital: #1d4f91;
  --clinique: #6c3fa0;
  --maison_sante: #12806a;
  --centre_sante: #b5651d;
  --a_baliser: #7d8a96;
  --urgence: #e3001b;
  --ink: #1b2733;
  --paper: #f8fafb;
  --muted: #5a6875;
  --line: #d6dee4;
  --banner-h: 52px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--paper); }
a { color: #1d4f91; }

#banner {
  position: fixed; inset: 0 0 auto 0; height: var(--banner-h); z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 16px;
  background: linear-gradient(90deg, #163d70, #12806a); color: #ffffff; box-shadow: 0 2px 6px rgba(0, 0, 0, .25);
}
#banner h1 { flex: 1; min-width: 0; margin: 0; font-size: clamp(14px, 1.45vw, 22px); font-weight: 700; line-height: 1.15; }
#nearest {
  flex: none; border: 0; border-radius: 18px; padding: 7px 14px; font: inherit; font-weight: 600; cursor: pointer;
  background: #ffffff; color: #163d70;
}
#nearest:hover { background: #e3eef8; }
#banner .site-nav { flex: none; margin: 0; }
#nearest:focus-visible, #menu-toggle:focus-visible { outline: 3px solid #ffd54a; outline-offset: 2px; }
/* menu burger : petits écrans seulement (légende et options masquées tant qu'il est fermé) */
#menu-toggle {
  display: none; flex: none; width: 38px; height: 38px; border: 0; border-radius: 8px; cursor: pointer;
  background: rgba(255, 255, 255, .18); color: #ffffff; font-size: 22px; line-height: 1;
}
#menu-toggle[aria-expanded="true"] { background: #ffffff; color: #163d70; }

#map { position: fixed; inset: var(--banner-h) 0 0 0; background: #eef2f4; }

/* panneau unique à gauche : légende, affichage et à propos en onglets (app.js), repliable */
#panel {
  position: fixed; top: calc(var(--banner-h) + 10px); left: 10px; z-index: 2; width: min(320px, calc(100vw - 20px));
  max-height: calc(100vh - var(--banner-h) - 60px); display: flex; flex-direction: column; overflow: hidden;
}
.box { background: var(--paper); border-radius: 8px; box-shadow: 0 1px 6px rgba(0, 0, 0, .25); }
.box .title { font-weight: 700; }
.box .sub { color: var(--muted); font-size: 12px; }
.panel-head { flex: none; display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; padding: 9px 8px 7px 12px; }
.panel-summary { margin: 0; display: flex; flex-direction: column; min-width: 0; }
#panel-collapse {
  flex: none; width: 28px; height: 28px; border: 0; border-radius: 6px; background: transparent; color: var(--muted);
  font-size: 15px; cursor: pointer;
}
#panel-collapse:hover { background: #e3eef8; }
#panel-collapse span { display: inline-block; transition: transform .15s; }
#panel-collapse[aria-expanded="false"] span { transform: rotate(-90deg); }
#panel-body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
#panel-body[hidden] { display: none; }
.tabs { flex: none; display: flex; border-bottom: 1px solid var(--line); padding: 0 6px; }
.tabs [role="tab"] {
  flex: 1; border: 0; border-bottom: 3px solid transparent; margin-bottom: -1px; padding: 7px 4px 6px; background: none;
  font: inherit; font-weight: 600; color: var(--muted); cursor: pointer;
}
.tabs [role="tab"]:hover { color: var(--ink); }
.tabs [role="tab"][aria-selected="true"] { color: #1d4f91; border-bottom-color: #1d4f91; }
#panel :focus-visible { outline: 2px solid #1d4f91; outline-offset: -2px; }
.box .content { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 8px 12px 10px; }
.box .content[hidden] { display: none; }

.kind { display: flex; align-items: center; gap: 8px; padding: 3px 0; cursor: pointer; }
.kind .sw { flex: none; width: 14px; height: 14px; border-radius: 50%; background: var(--c); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--c); }
.kind small { color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 3px; font-weight: 600; margin-bottom: 6px; }
.field select { font: inherit; font-weight: normal; padding: 4px; border: 1px solid #b8c4ce; border-radius: 4px; background: #fff; max-width: 100%; }
.checks { border: 1px solid var(--line); border-radius: 6px; margin: 4px 0 10px; padding: 4px 10px 6px; }
.checks legend { font-weight: 600; padding: 0 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.cta { margin: 10px 0; padding: 10px; border-radius: 6px; background: #e8f3ee; border: 1px solid #b7dacb; font-size: 13px; }
.cta p { margin: 4px 0 8px; }
.cta a { display: inline-block; margin: 2px 8px 2px 0; }
.cta .btn, .popup .finess .btn { padding: 5px 10px; border-radius: 4px; background: #1d4f91; color: #fff; text-decoration: none; font-weight: 600; }
.cta .btn:hover, .popup .finess .btn:hover { background: #12806a; }

/* fiche d'un lieu */
.maplibregl-popup-content { font: 13px/1.4 system-ui, sans-serif; color: var(--ink); max-width: 280px; }
.popup h3 { margin: 0 0 2px; font-size: 15px; }
.popup .kind-label { color: var(--muted); font-size: 12px; margin: 0 0 6px; }
.popup dl { margin: 4px 0; display: grid; grid-template-columns: auto 1fr; gap: 1px 8px; font-size: 12px; }
.popup dt { color: var(--muted); }
.popup dd { margin: 0; overflow-wrap: anywhere; }
.popup .links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.popup .links a, .popup .links button {
  font: inherit; font-size: 12px; padding: 3px 8px; border-radius: 4px; border: 1px solid #b8c4ce;
  background: #fff; color: var(--ink); text-decoration: none; cursor: pointer;
}
.popup .links a:hover, .popup .links button:hover { background: #e3eef8; }
.popup .josm-status { font-size: 11px; color: var(--muted); margin: 4px 0 0; }

/* choix du fond de carte (bouton MapLibre) */
.basemap-ctrl { position: relative; }
.basemap-ctrl > button { width: 29px; height: 29px; font-size: 16px; }
.basemap-ctrl .menu {
  position: absolute; top: 0; right: 36px; width: 230px; max-height: 60vh; overflow-y: auto; padding: 6px;
  background: #fff; border-radius: 4px; box-shadow: 0 0 0 2px rgba(0, 0, 0, .1); font: 13px system-ui, sans-serif;
}
.basemap-ctrl .menu select { width: 100%; font: inherit; }

@media (max-width: 600px) {
  :root { --banner-h: 56px; }
  #banner { padding: 0 10px; gap: 8px; }
  #nearest { padding: 7px 10px; }
  #nearest .label { display: none; }
  #menu-toggle { display: block; }
  #banner h1 { flex: 1; }
  /* place pour le menu « Contribuer » : sur téléphone, seul le nom du site reste dans la barre */
  #banner .tagline { display: none; }
  #banner h1 .brand { font-size: 13px; letter-spacing: 0; opacity: 1; overflow-wrap: anywhere; }
  body:not(.menu-open) #panel { display: none; }
  /* panneau en bas d'écran, pleine largeur, ouvert par le menu burger (voir app.js) */
  #panel { top: auto; bottom: 48px; left: 8px; right: 8px; width: auto; max-height: 60vh; }
  .maplibregl-popup-content { max-width: 240px; }
}

/* pictogrammes Fork Awesome servis avec la carte (vendor/, sans CDN) */
@font-face { font-family: "ForkAwesomeLocal"; src: url("vendor/fork-awesome/forkawesome-webfont.woff2") format("woff2"); font-display: block; }
.kind .sw.ico {
  width: 22px; height: 22px; border-width: 1.5px; display: inline-flex; align-items: center; justify-content: center;
  font: normal 12px/1 "ForkAwesomeLocal"; color: #fff; font-style: normal;
}
.popup .rc-alert { margin: 6px 0 0; padding: 5px 7px; border-radius: 4px; background: #fff4d6; border: 1px solid #f0c96b; font-size: 12px; }
#nearest .cross { width: 16px; height: 16px; fill: currentColor; vertical-align: -3px; }
#banner .brand { display: block; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; opacity: .8; }
.credits { margin: 6px 0 0; padding-left: 18px; display: grid; gap: 4px; }
.btn-line { margin: 6px 0 2px; font: inherit; padding: 5px 10px; border-radius: 4px; border: 1px solid #b8c4ce; background: #fff; cursor: pointer; }
.btn-line[aria-pressed="true"] { background: #fff1de; border-color: #f57c00; }
.popup .finess { margin: 6px 0; }
.popup .finess .btn { display: inline-block; font-size: 12px; }
.popup .photo img { display: block; width: 100%; max-height: 180px; object-fit: cover; border-radius: 4px; margin: 4px 0; }
.popup code, .cta code { font-size: 11px; background: #e6ecf0; padding: 0 3px; border-radius: 3px; overflow-wrap: anywhere; }
/* fiche : Wikidata, Panoramax */
.popup .pano-links { margin: 2px 0 6px; font-size: 12px; }
.popup .wd { margin: 6px 0 0; padding-top: 6px; border-top: 1px solid var(--line); font-size: 12px; }
.popup .wd p { margin: 0 0 3px; }
.popup .wd-desc { color: var(--muted); }
/* rappel des numéros d'urgence, option et badge « urgences » */
.urgent { margin: 0 0 8px; padding: 7px 9px; border-radius: 6px; background: #fdecee; border: 1px solid #f3b6bd; color: #7a0010; font-size: 12px; }
.kind .sw.em { width: 14px; height: 14px; background: #fff; border: 3px solid var(--urgence); box-shadow: none; }
.em-only { margin-top: 4px; padding-top: 6px; border-top: 1px solid var(--line); }
.popup .badge-em { display: inline-block; margin: 0 0 6px; padding: 2px 8px; border-radius: 10px; background: var(--urgence); color: #fff; font-size: 12px; font-weight: 700; }
.popup code, .urgent code, .box code { font-size: 11px; background: #e6ecf0; padding: 0 3px; border-radius: 3px; }

/* ---------- panneau de détails (details.js) : à droite ; en bas de l'écran sur mobile ---------- */
#details {
  position: fixed; top: var(--banner-h); right: 0; bottom: 0; z-index: 4; width: min(400px, 100vw);
  overflow-y: auto; background: var(--paper); box-shadow: -2px 0 10px rgba(0, 0, 0, .25); font-size: 13px;
}
#details[hidden] { display: none; }
.details-head {
  position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
  padding: 10px 12px; background: var(--paper); border-bottom: 1px solid var(--line);
}
.details-head h2 { margin: 0; font-size: 16px; line-height: 1.25; }
.details-head .kind-label { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.details-close { flex: none; width: 32px; height: 32px; border: 1px solid var(--line); border-radius: 6px; background: #fff; font-size: 16px; cursor: pointer; }
.details-body { padding: 4px 12px 24px; }
.details-body section { margin: 12px 0; }
.details-body h4 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.details-body .kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px 10px; margin: 0; }
.details-body .kv dt { color: var(--muted); }
.details-body .kv dd { margin: 0; overflow-wrap: anywhere; }
.details-body .acts details { border-bottom: 1px solid var(--line); padding: 3px 0; }
.details-body .acts summary { cursor: pointer; font-weight: 600; }
.details-body .acts ul { margin: 4px 0 4px; padding-left: 18px; }
.details-body table.tags { width: 100%; border-collapse: collapse; font-size: 12px; }
.details-body table.tags th, .details-body table.tags td { text-align: left; vertical-align: top; padding: 3px 4px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.details-body table.tags th { font-weight: 600; width: 40%; font-family: ui-monospace, monospace; }
.details-body table.tags th a { color: var(--ink); text-decoration: none; }
.details-body table.tags td { font-family: ui-monospace, monospace; }
.thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.thumbs img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 4px; display: block; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 8px 0; }
.chips:empty { display: none; }
.chip { display: inline-block; padding: 2px 9px; border-radius: 11px; font-size: 12px; font-weight: 600; background: #e6ecf0; color: var(--ink); }
.chip-em { background: var(--urgence); color: #fff; }
.chip-em-light { background: #fdecee; color: #7a0010; }
.chip-mat { background: #f3e8fb; color: #5b2d86; }
.chip-crit { background: #fff1de; color: #7a4100; }
.chip-chu { background: #e3eef8; color: #163d70; }
.popup .btn-details { font: inherit; font-size: 12px; font-weight: 600; padding: 5px 10px; border-radius: 4px; border: 0; background: var(--hopital); color: #fff; cursor: pointer; }
.popup .btn-details:hover { background: var(--maison_sante); }
/* liste des catégories peu nombreuses (à baliser…) dans la légende */
.kind-list { margin: 0 0 6px 30px; max-height: 180px; overflow-y: auto; border-left: 2px solid var(--line); }
.kind-list ul { list-style: none; margin: 0; padding: 0 0 0 8px; }
.kind-list button { font: inherit; font-size: 12px; background: none; border: 0; padding: 2px 0; color: var(--hopital); text-decoration: underline; cursor: pointer; text-align: left; }
/* sélecteur d'étage (plan intérieur) */
.level-ctrl { display: flex; flex-direction: column; }
.level-ctrl[hidden] { display: none; }
.level-ctrl .level-title { font: 600 10px system-ui, sans-serif; padding: 3px 2px; text-align: center; color: var(--muted); }
.level-ctrl button { width: 29px; height: 26px; font: 600 12px system-ui, sans-serif; }
.level-ctrl button[aria-pressed="true"] { background: var(--hopital); color: #fff; }

@media (min-width: 601px) {
  /* le panneau ouvert ne cache pas les contrôles de la carte */
  body.details-open .maplibregl-ctrl-top-right { right: min(400px, 100vw); }
}
@media (max-width: 600px) {
  #details { top: auto; height: 62vh; width: 100vw; border-radius: 12px 12px 0 0; box-shadow: 0 -2px 10px rgba(0, 0, 0, .3); }
  body.details-open #panel { display: none; }
}
/* distance aux urgences (couche en option de la légende) */
.access { margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--line); }
.kind .sw.ramp { border-radius: 3px; border: 0; box-shadow: none;
  background: linear-gradient(90deg, #2e9e4f 0 25%, #f08c00 25% 50%, #d7301f 50% 75%, #5c1a5e 75%); }
.access-legend { margin: 2px 0 6px 22px; }
.access-legend p { margin: 4px 0; }
.access-legend ul { list-style: none; margin: 4px 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 2px 8px; font-size: 12px; }
.access-legend .sq { display: inline-block; width: 12px; height: 12px; border-radius: 2px; vertical-align: -1px; margin-right: 4px; background: var(--c); opacity: .8; }
