:root{
  --blue:#1e88e5;
  --blue-d:#1565c0;
  --panel:#2aa1ee;
  --gray:#d3d7db;
  --btn:#5f7a8a;
  --text:#222;
  --navy:#12306b;
}
*{box-sizing:border-box}
html,body{height:100%;margin:0}
html{-webkit-text-size-adjust:100%;text-size-adjust:100%}
body{display:flex;flex-direction:column;font-family:Arial,Helvetica,sans-serif;font-size:12.5px;color:var(--text);background:#fff;overflow:hidden}
.hidden{display:none!important}
.ic{width:16px;height:16px;fill:currentColor;flex:none}
button{font-family:inherit;cursor:pointer}

/* ---------- En-tête blanc ---------- */
#top{height:57px;flex:none;display:flex;align-items:center;gap:18px;padding:0 24px 0 12px;background:#fff;border-bottom:1px solid #e3e3e3}
body.head-closed #top{display:none}
.logo{display:block;line-height:0}
.logo img{max-height:48px;width:auto}
.titles{min-width:0}
.titles h1{margin:0;font-size:16px;font-weight:700;line-height:1.2}
.titles p{margin:1px 0 0;font-size:12px;color:#333}
.toplinks{margin-left:auto;display:flex;gap:28px;flex:none}
.toplinks a{color:#222;text-decoration:none;font-size:13px}
.toplinks a:hover{text-decoration:underline}

/* ---------- Barre bleue ---------- */
#toolbar{height:22px;flex:none;display:flex;align-items:center;background:var(--blue);color:#fff;position:relative;z-index:1000}
.spacer{flex:1}
.tb{height:22px;min-width:24px;border:0;background:transparent;color:#fff;display:flex;align-items:center;justify-content:center;padding:0 4px}
.tb:hover,.tb.on{background:var(--blue-d)}
.tb.txt{gap:5px;padding:0 9px;font-size:12px;font-weight:700;border-left:1px solid rgba(255,255,255,.35)}
#tb-head{min-width:22px;border-left:0}
.tb .ic{width:15px;height:15px}
#tb-scale{margin-right:14px;height:22px;display:flex;align-items:center;padding:0 7px;border-left:1px solid rgba(255,255,255,.35);border-right:1px solid rgba(255,255,255,.35)}
#scale-head{font-size:11px;font-weight:700;font-variant-numeric:tabular-nums;color:#fff;white-space:nowrap;letter-spacing:.01em}
#searchbox{width:196px;height:18px;margin:0 8px 0 12px;display:flex;background:#fff;border-radius:2px;overflow:hidden}
#search{flex:1;min-width:0;border:0;outline:0;padding:0 8px;font-size:12px;color:#222}
#search::placeholder{color:#777}
#search-go{width:24px;border:0;background:#fff;color:#333;display:flex;align-items:center;justify-content:center}
#tb-legend{min-width:14px;padding:0}

/* ---------- Scène ---------- */
#stage{flex:1;position:relative;min-height:0;overflow:hidden}
#map{position:absolute;inset:0;background:#a8c8f0}
#stage.deplacement-bloque #map.leaflet-grab{cursor:default}
.leaflet-container{font-family:Arial,Helvetica,sans-serif}
.leaflet-control-attribution{font-size:8px!important;background:rgba(255,255,255,.55)!important;color:#444}

.dio-label{background:transparent;border:0;box-shadow:none;color:var(--navy);font-weight:700;font-size:10px;line-height:1.2;padding:0;text-align:center;white-space:normal;overflow-wrap:break-word;max-width:118px;text-shadow:0 0 3px rgba(255,255,255,.9)}
.leaflet-tooltip.dio-label{white-space:normal}
.dio-label:before{display:none}
#map.no-labels .dio-label{display:none}
.par-tip{font-size:11px;font-weight:700}
.meas{background:#fff;border:1px solid #d32f2f;color:#d32f2f;font-weight:700;font-size:10px;padding:1px 4px}

/* ---------- Panneau gauche ---------- */
#panel{position:absolute;left:0;top:87px;bottom:0;width:187px;background:#fff;display:flex;flex-direction:column;z-index:800;transition:transform .2s}
#panel-title{background:var(--panel);color:#fff;font-weight:700;font-size:12px;text-align:center;height:23px;line-height:23px;padding:0 6px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
#panel-nav{background:var(--gray);height:24px;display:flex;align-items:center;justify-content:center;gap:6px;font-size:10px;font-weight:700;color:#333}
#panel-nav button{width:16px;height:16px;border:1px solid #8a8f94;background:#eef0f2;display:flex;align-items:center;justify-content:center;padding:0;color:#333}
#panel-nav .ic{width:13px;height:13px}
#panel-body{flex:1;overflow:auto;padding:6px 5px 4px;-webkit-overflow-scrolling:touch}
.ptitle{text-align:center;font-weight:700;font-size:12px;line-height:1.75;margin:12px 0 10px}
.ptable{width:100%;border-collapse:collapse;font-size:11px;border:1px solid #ddd}
.ptable td{border-bottom:1px solid #e3e3e3;padding:5px 5px;vertical-align:top}
.ptable td:first-child{width:56%;color:#222}
.ptable td:last-child{text-align:left}
.ctitle{font-weight:700;font-size:11px;margin:16px 0 4px}
.pchart{width:100%;height:150px}
.pchart.pie{height:130px}
.plegend{font-size:11px;margin:4px 0 0;display:flex;align-items:center;gap:5px}
.plegend .sq{width:9px;height:9px;display:inline-block}
.pfoot{font-size:10.5px;font-weight:700;margin:14px 0 6px;line-height:1.4}
.pfoot a{color:var(--blue-d)}
#panel-actions{display:flex;gap:6px;padding:8px 8px 10px;background:#fff}
#panel-actions button{flex:1;height:24px;border:0;border-radius:2px;background:var(--btn);color:#fff;font-size:10px;font-weight:700;display:flex;align-items:center;justify-content:center;gap:3px;padding:0 2px}
#panel-actions .ic{width:11px;height:11px}
#panel-actions button:hover{background:#4c6574}
#panel-toggle{position:absolute;left:187px;top:111px;width:18px;height:24px;border:0;background:var(--panel);color:#fff;display:flex;align-items:center;justify-content:center;padding:0;z-index:800;transition:left .2s}
#stage.panel-closed #panel{transform:translateX(-100%)}
#stage.panel-closed #panel-toggle{left:0}
#stage.panel-closed #panel-toggle .ic{transform:rotate(180deg)}

/* ---------- Légende bas droite ---------- */
#legend-wrap{position:absolute;right:0;top:50%;bottom:auto;transform:translateY(-50%);z-index:800;display:flex;align-items:flex-start}
#legend-strip{width:22px;margin-top:22px;height:290px;display:flex;flex-direction:column;justify-content:space-between}
#legend-strip .grp{display:flex;flex-direction:column;gap:1px}
#legend-strip button{width:22px;height:24px;border:0;background:var(--blue);color:#fff;display:flex;align-items:center;justify-content:center;padding:0}
#legend-strip button:hover,#legend-strip button.on{background:var(--blue-d)}
#btn-info{background:transparent!important;color:#444!important;height:20px!important;margin-bottom:6px}
#btn-info:hover{color:#000!important}

/* ---------- Lecteur de coordonnées (footer) ---------- */
#coord-bar{position:absolute;right:206px;bottom:0;z-index:810;width:372px;height:32px;display:flex;align-items:center;gap:8px;padding:0 8px;background:#f2f2f2;color:#111;font:12.5px/1 Arial,Helvetica,sans-serif;border-top:1px solid #d4d4d4;border-left:1px solid #d4d4d4;box-shadow:0 -1px 3px rgba(0,0,0,.05);white-space:nowrap}
#coord-bar .cb-label{flex:none;padding:0 2px 0 14px;font-size:12.5px;color:#111}
#coord-bar .cb-field{flex:1;height:22px;display:flex;align-items:center;gap:12px;padding:0 8px;background:#fff;border:1px solid #a6a6a6;font:12.5px/1 "Consolas","Courier New",monospace;color:#111;overflow:hidden}
#coord-bar b{font-weight:400;min-width:74px;text-align:left;font-variant-numeric:tabular-nums}
#legend{width:184px;height:312px;background:#fff;display:flex;flex-direction:column;box-shadow:0 0 6px rgba(0,0,0,.25)}
#stage.legend-closed #legend{display:none}
#stage.legend-closed #legend-strip{height:auto}
#legend-head{background:var(--blue);color:#fff;font-weight:700;font-size:12px;text-align:center;height:25px;line-height:25px}
#legend-tabs{display:flex;height:33px;background:#fff;box-shadow:0 2px 3px rgba(0,0,0,.15);position:relative;z-index:1}
.tab{flex:1;border:0;background:#fff;font-size:12px;color:#777;border-bottom:3px solid transparent}
.tab.on{color:#222;font-weight:700;border-bottom-color:#5b6770}
#legend-body{flex:1;overflow:auto;-webkit-overflow-scrolling:touch}
#legend-scale{flex:none;padding:8px 10px 9px;background:#f7fafc;border-top:1px solid #d6e0e9}
.ls-head{display:flex;align-items:baseline;justify-content:space-between;gap:8px;font-size:9px;font-weight:700;letter-spacing:.08em;text-transform:uppercase;color:#687984}
.ls-head b{font-size:11px;letter-spacing:0;text-transform:none;color:#1f2b34;font-variant-numeric:tabular-nums}
.ls-track{position:relative;width:104px;max-width:100%;height:7px;margin-top:6px;background:#fff;border:1px solid #6f7f8b;overflow:hidden;transition:width .16s ease}
#scale-bar-fill{display:block;width:100%;height:100%;background:repeating-linear-gradient(90deg,#6f7f8b 0 50%,#fff 50% 100%);background-size:14px 100%}
.ls-dist{display:flex;justify-content:space-between;width:104px;max-width:100%;margin-top:2px;font-size:8.5px;color:#6b7a85;font-variant-numeric:tabular-nums;transition:width .16s ease}
.layer{padding:8px 10px 10px;border-bottom:1px solid #ddd}
.layer.off{background:#efefef;color:#999}
.layer.off .sw i{opacity:.55}
.ltitle{display:flex;justify-content:space-between;gap:6px;font-weight:700;font-size:11.5px;line-height:1.3;cursor:pointer}
.ltitle input{margin:0 0 0 4px;flex:none}
.ldesc{font-size:11px;margin:2px 0 8px;color:inherit}
.sw{display:flex;justify-content:space-between}
.sw i{display:block;width:24px;height:17px;border:1px solid #8c8c8c;border-radius:3px}
.swl{display:flex;justify-content:space-between;font-size:8.5px;margin-top:2px}
.muted{color:#666;font-size:11px;margin:8px 10px}
.sk{display:block;width:calc(100% - 20px);margin:6px 10px;height:24px;border:0;border-radius:2px;background:var(--btn);color:#fff;font-size:11px;font-weight:700;cursor:pointer}
.sk.on{background:var(--blue-d)}
.sk-tools{display:grid;grid-template-columns:repeat(3,1fr);gap:4px;margin:6px 10px}
.sk-tools .sk{width:100%;margin:0;padding:0 2px;font-size:9.5px}
.sk-finish{height:22px;font-size:9.5px}
.sk-info{margin:6px 10px;padding:6px 7px;background:#f5f8fa;border-left:3px solid var(--panel);font-size:10px;line-height:1.4;color:#45535d}
.pro-form{margin:8px 10px 0;display:flex;flex-direction:column;gap:4px}
.pro-form label{font-size:9px;font-weight:700;color:#5b6b76;text-transform:uppercase;letter-spacing:.05em;margin-top:2px}
.pro-form input{width:100%;height:24px;border:1px solid #c8d2da;border-radius:3px;padding:0 6px;font-size:11px;color:#24313a;background:#fff}
.pro-form input:focus{outline:2px solid #9dc7e8;outline-offset:-1px;border-color:#5b9bd5}
.pro-save{width:100%;height:26px;margin-top:4px;border:0;border-radius:3px;background:var(--btn);color:#fff;font-size:11px;font-weight:700;cursor:pointer}
.pro-save:disabled{opacity:.55;cursor:wait}
.pro-row{display:flex;gap:6px;margin-top:4px}
.pro-row .pro-save{flex:2;margin-top:0}
.pro-second{flex:1;height:26px;border:1px solid #d2dbe2;border-radius:3px;background:#f6f8fa;color:#53636d;font-size:11px;font-weight:700;cursor:pointer}
.pro-status{margin:6px 10px 2px;font-size:10px;color:#687984;line-height:1.3}
.bm-item,.sk-item{display:flex;gap:6px;align-items:flex-start;padding:6px 10px;border-bottom:1px solid #edf0f2;font-size:10.5px}
.bm-main,.sk-main{flex:1;min-width:0}
.bm-main b,.sk-main b{display:block;color:#17324d;font-size:11px;line-height:1.25;word-break:break-word}
.bm-main small,.sk-main small{display:block;color:#71808a;font-size:9px;margin-top:2px;line-height:1.3}
.bm-main p,.sk-main p{margin:3px 0 0;color:#4d5b64;font-size:10px;line-height:1.3}
.bm-actions,.sk-actions{display:flex;flex-direction:column;gap:3px;flex:none}
.bm-actions button,.sk-actions button{height:18px;border:1px solid #d5dde3;border-radius:2px;background:#f7f9fa;color:#3c5a70;font-size:9px;font-weight:700;padding:0 5px;white-space:nowrap;cursor:pointer}
.bm-actions button:hover,.sk-actions button:hover{background:#e9f2f9}
.bm-actions .danger,.sk-actions .danger{color:#b3261e;border-color:#e8cbc7;background:#fff}

/* ---------- Menu Cartes & recherche ---------- */
#maps-menu{position:absolute;left:25px;top:0;width:250px;background:#fff;box-shadow:0 3px 10px rgba(0,0,0,.3);padding:8px 12px 12px;z-index:900;font-size:12px}
#maps-menu h4{margin:10px 0 5px;font-size:12px;color:var(--blue-d)}
#maps-menu label{display:block;margin:4px 0}
#maps-menu select{width:100%;padding:4px;font-size:12px}
#compteur{margin-top:10px;padding:5px 7px;background:#eef4fb;font-size:11px}
#search-results{position:absolute;right:40px;top:0;width:230px;background:#fff;box-shadow:0 3px 10px rgba(0,0,0,.3);z-index:900;max-height:260px;overflow:auto;-webkit-overflow-scrolling:touch}
#search-results div{padding:6px 9px;font-size:12px;border-bottom:1px solid #eee;cursor:pointer}
#search-results div:hover{background:#e8f1fb}
#search-results small{display:block;color:#666}

/* ---------- Modales génériques ---------- */
.modal{position:fixed;inset:0;background:rgba(0,0,0,.45);display:flex;align-items:center;justify-content:center;z-index:3000}
.modal-box{background:#fff;width:92%;max-width:1100px;max-height:90vh;display:flex;flex-direction:column;box-shadow:0 8px 30px rgba(0,0,0,.4)}
.modal-box.small{max-width:520px}
.modal-head{background:var(--blue);color:#fff;font-weight:700;font-size:13px;display:flex;justify-content:space-between;align-items:center;padding:0 0 0 14px;height:30px}
.modal-head button{height:30px;border:0;background:var(--blue-d);color:#fff;padding:0 14px;font-weight:700;font-size:11px}
.modal-content{padding:14px 16px 18px;overflow:auto;line-height:1.5;-webkit-overflow-scrolling:touch}
.modal-content h3{font-size:12px;margin:12px 0 6px}
.guide-box{max-width:840px;width:94%}
.guide-content{font-size:12px;line-height:1.55;padding:16px 22px 24px}
.guide-content h3{font-size:13px;color:var(--blue-d);margin:18px 0 6px;padding-bottom:4px;border-bottom:1px solid #e1e8ee}
.guide-content ul,.guide-content ol{margin:0 0 8px 18px;padding:0}
.guide-content li{margin:4px 0}
.guide-content b{color:#17324d}
.guide-intro{margin:0 0 12px;padding:9px 11px;background:#eef6fd;border-left:3px solid var(--blue);color:#2b3b47}
.guide-note{margin:6px 0 0;padding:7px 9px;background:#f5f7f9;border-left:2px solid #9aaab6;color:#5d6d78;font-size:11px}

#toast{position:fixed;left:50%;bottom:calc(30px + env(safe-area-inset-bottom,0px));transform:translateX(-50%);background:#333;color:#fff;padding:8px 16px;font-size:12px;border-radius:3px;opacity:0;pointer-events:none;transition:opacity .2s;z-index:4000;max-width:90vw;text-align:center}
#toast.show{opacity:1}

/* ---------- Footer ---------- */
#site-footer{flex:none;height:27px;display:flex;align-items:center;justify-content:center;gap:10px;padding:0 12px;background:#f3f6f8;border-top:1px solid #d8e2ea;color:#5f6f7a;font-size:12px;line-height:1.2;white-space:nowrap;overflow:hidden}
#site-footer b{color:#24313a;font-weight:700}
#site-footer .f-sep{width:1px;height:10px;background:#c9d5de;flex:none}
@media (max-width:760px){
  #site-footer{height:auto;min-height:32px;flex-wrap:wrap;gap:2px 8px;padding:4px 8px;font-size:8px;white-space:normal;text-align:center}
  #site-footer .f-sep{display:none}
}


/* ---------- Dashboard sobre et institutionnel ---------- */
.modal:has(.dash){background:rgba(30,40,50,.5);align-items:center;overflow:hidden;padding:0}
.dash{position:relative;background:#f1f4f6;border-radius:22px;width:96%;max-width:1320px;max-height:84vh;display:flex;flex-direction:column;overflow:hidden;padding:24px 14px 20px 30px;font-family:"Segoe UI","Open Sans",Arial,sans-serif}
.dash-title{flex:none;margin:0 0 16px;font-size:24px;font-weight:400;color:#222}
.dash-close{position:absolute;right:20px;top:16px;width:30px;height:30px;border:0;border-radius:50%;background:#fff;color:#555;font-size:13px}
.dash-close:hover{background:#e3e8ec}
.dash-filters{flex:none;display:flex;gap:14px;flex-wrap:wrap;margin-bottom:18px}
.dfilter{background:#fff;border-radius:3px;padding:7px 14px 8px;min-width:230px;display:block}
.dfilter span{display:block;font-size:12px;color:#666}
.dfilter select{width:100%;border:0;outline:0;background:#fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0h10L5 6z' fill='%23888'/%3E%3C/svg%3E") no-repeat right 2px center;appearance:none;-webkit-appearance:none;font-size:15px;color:#222;padding:2px 20px 0 0;font-family:inherit}
.dgrid{display:grid;grid-template-columns:minmax(170px,.8fr) 2.1fr 2.2fr;grid-template-rows:repeat(4,175px);gap:14px;grid-auto-rows:auto;flex:1;min-height:0;overflow-y:auto;padding:0 16px 4px 0;scrollbar-width:thin;scrollbar-color:#c3ccd3 transparent;-webkit-overflow-scrolling:touch}
.card{background:#fff;border-radius:14px;padding:16px 20px;display:flex;flex-direction:column;min-width:0;min-height:0}
.card h3{margin:0;font-size:14px;font-weight:400;color:#555}
.chart{flex:1;min-height:0;margin-top:6px}
.k1{grid-column:1;grid-row:1}.k2{grid-column:1;grid-row:2}
.k3{grid-column:1;grid-row:3}.k4{grid-column:1;grid-row:4}
.c-pie{grid-column:2;grid-row:1/3}.c-bar{grid-column:3;grid-row:1/3}
.c-area{grid-column:2/4;grid-row:3/5}
.c-tbl{grid-column:1/4;grid-row:5}
.kb{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px}
.kn{font-size:42px;font-weight:700;color:#333;line-height:1.05;letter-spacing:-.5px}
.kd{font-size:14px;color:#6fb374}
.kc{font-size:10px;color:#666;text-align:center}
#tbl-vic{margin-top:10px;overflow-x:auto;-webkit-overflow-scrolling:touch}
#tbl-vic table{width:100%;border-collapse:collapse;font-size:12.5px}
#tbl-vic th{font-weight:400;color:#777;text-align:right;padding:8px 10px;border-bottom:1px solid #e3e6e9;white-space:nowrap}
#tbl-vic td{padding:8px 10px;border-bottom:1px solid #eef0f2;text-align:right;color:#333;white-space:nowrap}
#tbl-vic th:first-child,#tbl-vic td:first-child{text-align:left}
#tbl-vic tr.tot td{font-weight:700;border-bottom:0}
.c-tbl{min-height:auto}
.dgrid{padding:0 16px 28px 0}
#tbl-vic .empty{padding:14px 4px;color:#888;font-size:13px;line-height:1.5}
#tbl-vic .empty code{background:#eef1f4;padding:1px 5px;border-radius:3px}
.chart-err{padding:22px 4px;color:#999;font-size:12px}
@media (max-width:900px){
  .dgrid{grid-template-columns:1fr 1fr;grid-template-rows:auto}
  .dgrid>*{grid-column:auto!important;grid-row:auto!important}
  .c-pie,.c-bar,.c-area,.c-tbl{grid-column:1/3!important}
  .chart{min-height:260px}
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */

/* --- Tablette --- */
@media (max-width:1024px){
  #top{gap:12px;padding:0 16px 0 10px}
  .toplinks{gap:16px}
  #panel{width:170px}
  #panel-toggle{left:170px}
  #legend{width:172px}
}

/* --- Tablette portrait / grand téléphone --- */
@media (max-width:900px){
  .titles p{display:none}
  #top{height:52px}
  .toplinks{gap:12px}
  .toplinks a{font-size:12px}
}

/* --- Téléphone : barre qui passe à la ligne, tiroirs plein écran --- */
@media (max-width:760px){
  #top{padding:0 10px}
  .titles h1{font-size:14px}
  .toplinks{display:none}

  /* Barre d'outils : boutons sur une ligne, recherche en dessous */
  #toolbar{flex-wrap:wrap;height:auto;min-height:24px;padding:2px 0}
  .spacer{display:none}
  #tb-scale{display:none}
  .tb{height:38px;min-width:42px;padding:0 6px}
  .tb .ic{width:19px;height:19px}
  .tb.txt{padding:0 12px;font-size:12.5px}
  #tb-legend{min-width:42px}
  #searchbox{order:50;flex:1 1 100%;height:38px;margin:4px 6px 6px;border-radius:4px}
  #search{font-size:16px;padding:0 12px}
  #search-go{width:46px}
  #search-go .ic{width:18px;height:18px}

  /* Panneau gauche : tiroir qui glisse depuis la gauche */
  #panel{top:0;bottom:0;width:min(84vw,320px);z-index:1500;box-shadow:2px 0 14px rgba(0,0,0,.3)}
  #panel-body{padding:8px 8px 6px}
  .ptable{font-size:11px}
  .ptable td{padding:7px 6px}
  .pchart{height:180px}
  .pchart.pie{height:150px}
  #panel-actions{padding:10px}
  #panel-actions button{height:38px;font-size:11px}
  #panel-actions .ic{width:14px;height:14px}
  #panel-toggle{top:auto;bottom:16px;left:0;width:40px;height:48px;border-radius:0 10px 10px 0;box-shadow:0 2px 8px rgba(0,0,0,.25)}
  #stage:not(.panel-closed) #panel-toggle{left:min(84vw,320px)}

  /* Légende : feuille en bas de l'écran */
  #legend-wrap{left:0;right:0;top:auto;bottom:0;transform:none;flex-direction:column;align-items:stretch;padding-bottom:env(safe-area-inset-bottom,0px)}
  #coord-bar{display:none}
  #legend-strip{order:1;width:auto;height:auto;margin:0;flex-direction:row;justify-content:flex-end;gap:2px;background:rgba(255,255,255,.85);padding:2px 4px}
  #legend-strip .grp{flex-direction:row;gap:2px}
  #legend-strip button{width:40px;height:40px}
  #btn-info{height:40px!important;margin-bottom:0!important;padding:0 8px}
  #legend{order:2;width:100%;height:auto;max-height:58vh;border-radius:12px 12px 0 0;overflow:hidden}
  #legend-head{height:30px;line-height:30px;font-size:12px}
  #legend-tabs{height:40px}
  .tab{font-size:13px}
  #measure-card{top:8px;width:calc(100% - 20px);max-width:none}
  .mc-total{font-size:22px}
  .mc-actions button{height:32px;font-size:11px}

  /* Menus flottants */
  #maps-menu{left:0;right:0;top:0;width:auto;max-height:75vh;overflow:auto;-webkit-overflow-scrolling:touch}
  #search-results{left:6px;right:6px;top:0;width:auto;max-height:45vh}

  /* Dashboard : plein écran, une colonne */
  .modal:has(.dash){align-items:stretch;padding:0;overflow:auto}
  .dash{width:100%;max-width:100%;max-height:100vh;height:100vh;border-radius:0;padding:16px 12px 12px}
  .dash-title{font-size:18px;margin-bottom:12px;padding-right:38px}
  .dash-close{right:12px;top:12px;width:34px;height:34px;font-size:15px}
  .dash-filters{gap:8px;margin-bottom:12px}
  .dfilter{min-width:0;width:100%;padding:8px 12px}
  .dfilter select{font-size:16px}
  .dgrid{grid-template-columns:1fr!important;grid-template-rows:auto!important;gap:10px;padding:0 4px 20px 0}
  .dgrid>*{grid-column:auto!important;grid-row:auto!important}
  .c-pie,.c-bar,.c-area,.c-tbl{grid-column:auto!important}
  .card{padding:14px 16px;border-radius:12px}
  .kn{font-size:34px}
  .chart{min-height:240px}
  #tbl-vic table{font-size:12px}
  #tbl-vic th,#tbl-vic td{padding:7px 8px}
}

/* --- Sélecteur de fond de carte : galerie de miniatures --- */
#legend-fond{padding:7px 9px 8px;background:linear-gradient(180deg,#f7fafd,#edf3f9);border-bottom:1px solid #dbe4ec}
.lf-title{display:flex;align-items:center;justify-content:space-between;margin-bottom:6px;font-size:8px;font-weight:700;letter-spacing:.09em;text-transform:uppercase;color:#5d6f7d}
.lf-title::after{content:"";flex:1;height:1px;margin-left:7px;background:#d6e0e9}
#fond-btns{display:grid;grid-template-columns:repeat(5,1fr);gap:4px}
#fond-btns button{position:relative;display:flex;flex-direction:column;gap:3px;min-width:0;padding:0;border:0;background:none;color:#4a5a66}
#fond-btns .prev{position:relative;display:block;width:100%;aspect-ratio:4/3;border-radius:3px;overflow:hidden;background:#c8d5df center/cover no-repeat;box-shadow:0 0 0 1px #b3c2ce,0 1px 2px rgba(18,48,107,.12);transition:transform .15s,box-shadow .15s}
#fond-btns button:hover .prev{transform:translateY(-1px);box-shadow:0 0 0 1px #7e97a8,0 2px 5px rgba(18,48,107,.22)}
#fond-btns button.on .prev{box-shadow:0 0 0 2px var(--blue),0 2px 6px rgba(30,136,229,.35)}
#fond-btns button.on .prev::after{content:"✓";position:absolute;top:3px;right:3px;width:11px;height:11px;border-radius:50%;background:var(--blue);color:#fff;font-size:8px;font-weight:700;line-height:11px;text-align:center;box-shadow:0 0 0 1.5px #fff}
#fond-btns button:focus-visible .prev{outline:2px solid var(--blue-d);outline-offset:2px}
#fond-btns .lbl{display:block;width:100%;font-size:7.5px;font-weight:700;line-height:1.1;text-align:center;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
#fond-btns button.on .lbl{color:var(--blue-d)}
#fond-btns [data-fond="esri"] .prev{background-image:url("img/fonds/plan.jpg")}
#fond-btns [data-fond="osm"] .prev{background-image:url("img/fonds/osm.jpg")}
#fond-btns [data-fond="sat"] .prev{background-image:url("img/fonds/sat.jpg")}
#fond-btns [data-fond="google"] .prev{background-image:url("img/fonds/google.jpg")}

/* --- Mesure de distance --- */
#measure-card{position:absolute;left:50%;top:12px;transform:translateX(-50%);z-index:900;width:250px;max-width:calc(100% - 24px);padding:9px 12px 10px;background:#fff;border-radius:6px;border-top:3px solid #d32f2f;box-shadow:0 4px 16px rgba(18,48,107,.28)}
.mc-title{font-size:9px;font-weight:700;letter-spacing:.06em;text-transform:uppercase;color:#b3261e}
.mc-total{margin-top:2px;font-size:20px;font-weight:700;line-height:1.2;color:#1d2b36;font-variant-numeric:tabular-nums}
.mc-hint{margin-top:3px;font-size:9px;line-height:1.35;color:#65747f}
.mc-actions{display:flex;gap:6px;margin-top:8px}
.mc-actions button{flex:1;height:24px;border:1px solid #d7dee4;border-radius:3px;background:#f6f8fa;color:#44545f;font-size:9px;font-weight:700}
.mc-actions button:hover{background:#e9eef2}
#mc-clear{color:#b3261e;border-color:#e6c3bf;background:#fff}
#mc-clear:hover{background:#fdf1f0}
.meas-wrap{background:none;border:0}
.meas-wrap .meas{display:inline-block;transform:translate(-50%,-50%);white-space:nowrap;box-shadow:0 1px 3px rgba(0,0,0,.18)}

/* --- Petit téléphone --- */
@media (max-width:400px){
  .tb{min-width:38px}
  .tb.txt{padding:0 9px;font-size:12px}
  .dash-title{font-size:16px}
  .kn{font-size:30px}
  #panel{width:min(90vw,300px)}
  #stage:not(.panel-closed) #panel-toggle{left:min(90vw,300px)}
}

.who{color:#666;font-size:12.5px;margin-right:4px}

/* ---------- Couches importées dans la légende ---------- */
#legend-dyn{border-top:1px solid #d6e0e9;margin-top:4px;padding:6px 0 2px}
#legend-dyn h4{margin:0 0 5px;font-size:10px;color:var(--blue-d);text-transform:uppercase;letter-spacing:.04em}
#legend-dyn label{display:flex;align-items:flex-start;gap:5px;margin:4px 0;font-size:10px;line-height:1.35}
#legend-dyn label small{color:#777}
#legend-dyn input{margin:1px 0 0;flex:none}


/* ==========================================================================
   COQUE MOBILE (type application cartographique)
   ========================================================================== */
#m-top,#m-menu,#m-searchrow,#m-fab-maps,#m-fab-fold{display:none}
#legend-strip .m-only{display:none}

@media (max-width:760px){
  html,body{height:100%}
  #top,#toolbar{display:none!important}
  #site-footer{height:auto;min-height:0;flex-wrap:wrap;justify-content:center;gap:1px 6px;padding:6px 8px;font-size:10.5px;line-height:1.3;white-space:normal;text-align:center}
  #site-footer .f-sep{display:none}

  /* En-tête compact + hamburger */
  #m-top{display:flex;flex:none;align-items:center;gap:10px;height:auto;min-height:calc(56px + env(safe-area-inset-top,0px));padding:env(safe-area-inset-top,0px) 10px 0;background:#fff;border-bottom:1px solid #e3e3e3;box-shadow:0 1px 4px rgba(18,48,107,.08);position:relative;z-index:1200}
  .m-logo{display:flex;align-items:center;justify-content:center;width:40px;height:40px;border-radius:9px;background:#f2f6fa;flex:none;overflow:hidden}
  .m-logo img{width:100%;height:100%;object-fit:contain}
  .m-brand{min-width:0;flex:1;line-height:1.15}
  .m-kicker{display:block;font-size:9.5px;font-weight:700;letter-spacing:.08em;text-transform:uppercase;color:#7b8b98;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .m-brand strong{display:block;font-size:14px;color:#12306b;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  #m-menu-btn{flex:none;width:42px;height:42px;border:1px solid #cdd8e1;border-radius:9px;background:#fff;color:#1f3a52;display:flex;align-items:center;justify-content:center}
  #m-menu-btn .ic{width:22px;height:22px}
  #m-menu-btn.on{background:#eaf3fb;border-color:#9dc7e8;color:var(--blue-d)}

  /* Menu hamburger */
  #m-menu{display:block;position:absolute;top:calc(100% + 55px);right:0;left:auto;min-width:220px;background:#fff;border-radius:11px;box-shadow:0 10px 30px rgba(18,48,107,.3);padding:6px;z-index:1400}
  #m-menu a{display:block;padding:11px 12px;border-radius:7px;color:#24313a;text-decoration:none;font-size:13px;font-weight:600}
  #m-menu a:hover{background:#eef5fb}
  #m-menu a+a{border-top:1px solid #eef1f4}

  /* Ligne de recherche pleine largeur */
  #m-searchrow{display:flex;flex:none;gap:6px;padding:7px 8px;background:#fff;border-bottom:1px solid #dfe7ee;position:relative;z-index:1100}
  #m-search{flex:1;min-width:0;height:40px;border:1px solid #c8d4de;border-radius:9px;padding:0 12px;font-size:16px;color:#222;background:#fff;outline:none}
  #m-search:focus{border-color:var(--blue);box-shadow:0 0 0 2px rgba(30,136,229,.18)}
  #m-searchrow button{flex:none;width:40px;height:40px;border:0;border-radius:9px;display:flex;align-items:center;justify-content:center;color:#fff;background:var(--blue)}
  #m-searchrow button .ic{width:20px;height:20px}
  #m-reload{background:#eaf3fb!important;color:var(--blue-d)!important}

  /* Actions flottantes gauche / bas */
  #m-fab-maps{display:flex;position:absolute;left:8px;top:10px;z-index:1000;width:44px;height:44px;border:0;border-radius:11px;background:rgba(20,20,20,.92);color:#fff;align-items:center;justify-content:center;box-shadow:0 3px 12px rgba(0,0,0,.28)}
  #m-fab-maps .ic,#m-fab-fold .ic{width:22px;height:22px}
  #m-fab-fold{display:flex;position:absolute;left:8px;bottom:calc(14px + env(safe-area-inset-bottom,0px));z-index:1000;width:44px;height:44px;border:0;border-radius:11px;background:rgba(20,20,20,.92);color:#fff;align-items:center;justify-content:center;box-shadow:0 3px 12px rgba(0,0,0,.28)}



  /* Rail droit : réutilisation de la bande de la légende */
  #legend-wrap{position:absolute;top:10px;right:8px;bottom:auto;left:auto;transform:none;flex-direction:row;align-items:flex-start;gap:8px;padding:0;z-index:1050;max-height:calc(100% - 20px)}
  #legend-strip{order:2;width:44px;height:auto;max-height:100%;margin:0;flex-direction:column;justify-content:flex-start;gap:6px;background:none;padding:0;overflow-y:auto;scrollbar-width:none}
  #legend-strip::-webkit-scrollbar{display:none}
  #legend-strip .grp{flex-direction:column;gap:6px}
  #legend-strip button{width:44px;height:44px;border:0;border-radius:11px;background:rgba(20,20,20,.92);color:#fff;box-shadow:0 3px 12px rgba(0,0,0,.28)}
  #legend-strip .m-only{display:flex}
  #legend-strip #ls-collapse{display:none}
  #legend-strip #btn-measure,#legend-strip #ls-sketch,#legend-strip #ls-bm{display:none}
  #legend-strip.tools-open #btn-measure,#legend-strip.tools-open #ls-sketch,#legend-strip.tools-open #ls-bm{display:flex}
  #legend-strip button:hover,#legend-strip button.on{background:var(--blue-d)}
  #legend-strip .ic{width:22px;height:22px}
  #btn-info{background:rgba(20,20,20,.92)!important;color:#fff!important;height:44px!important;margin-bottom:0!important}

  /* Panneau Légende : feuille latérale droite, à gauche du rail */
  #legend{order:1;width:min(calc(100vw - 150px),300px);height:auto;max-height:calc(100vh - 150px);min-height:0;border-radius:13px;overflow:hidden;box-shadow:0 8px 30px rgba(18,48,107,.3)}
  #legend-head{height:34px;line-height:34px;font-size:12px}
  #legend-tabs{height:38px}
  #legend-body{min-height:0}

  /* Panneau Détail : feuille latérale gauche */
  #panel{top:0;bottom:0;width:min(74vw,272px);z-index:1500;box-shadow:2px 0 18px rgba(0,0,0,.3);border-radius:0 13px 13px 0;overflow:hidden}
  #stage.panel-closed #panel{box-shadow:none}
  #stage:not(.panel-closed) #legend-wrap{display:none}
  #panel-title{position:relative;padding-right:34px;cursor:pointer}
  #panel-title::after{content:"×";position:absolute;right:10px;top:50%;transform:translateY(-50%);font-size:20px;line-height:1;font-weight:400;color:#fff;opacity:.9}
  #panel-body{padding:8px}
  .pchart{height:150px}
  .pchart.pie{height:130px}
  #panel-toggle{display:none}

  /* Menus flottants */
  #maps-menu{left:8px;right:auto;top:64px;width:min(268px,calc(100vw - 76px));max-height:calc(100% - 84px);overflow:auto;-webkit-overflow-scrolling:touch;border-radius:12px;z-index:1250}
  #search-results{left:8px;right:8px;top:0;width:auto;max-height:50vh;border-radius:0 0 12px 12px;z-index:1200}
  #coord-bar{display:none}
  #measure-card{top:64px;width:min(236px,calc(100vw - 76px));max-width:none}

  /* Attribution au-dessus du bouton bas-gauche */
  .leaflet-bottom.leaflet-left{bottom:62px}

  /* Dashboard : KPI sur deux colonnes, graphiques pleine largeur */
  .dash-title{font-size:20px;margin-bottom:10px}
  .dash-filters{display:grid;grid-template-columns:1fr 1fr;gap:6px;margin-bottom:10px}
  .dfilter{min-width:0;width:auto;padding:6px 10px}
  .dfilter span{font-size:10.5px}
  .dfilter select{font-size:16px}
  .dgrid{grid-template-columns:1fr 1fr!important;grid-template-rows:none!important;grid-auto-rows:auto!important;gap:10px;padding:0 2px 16px 0}
  .dgrid>*{grid-column:auto!important;grid-row:auto!important}
  .c-pie,.c-bar,.c-area,.c-tbl{grid-column:1/-1!important}
  .card{padding:12px 14px;border-radius:12px}
  .card.k1,.card.k2,.card.k3,.card.k4{height:110px;min-height:110px}
  .c-pie,.c-bar{height:270px}
  .c-area{height:330px}
  .kn{font-size:34px}
  .kd{font-size:10px}
  .kc{font-size:9.5px}
  .chart{flex:1;min-height:0;height:auto}
  #tbl-vic table{font-size:12px}
  #tbl-vic th,#tbl-vic td{padding:7px 8px}
}


/* ---------- Impression de la carte ---------- */
.print-only{display:none}

@media print{
  @page{size:A4 landscape;margin:8mm}
  html,body{height:100%!important;overflow:hidden!important;background:#fff!important}
  body{-webkit-print-color-adjust:exact;print-color-adjust:exact}
  #top,#toolbar,#panel,#panel-toggle,#legend-wrap,#coord-bar,#maps-menu,#search-results,#site-footer,#toast,#m-top,#m-menu,#m-searchrow,#m-fab-maps,#m-fab-fold{display:none!important}
  #stage{position:fixed!important;inset:0!important;overflow:hidden!important;background:#fff!important}
  #map{position:absolute!important;top:19mm!important;bottom:19mm!important;left:0!important;right:0!important;width:auto!important;height:auto!important}
  .print-only{display:flex!important}
  #print-head{position:absolute;z-index:1000;top:0;left:0;right:0;height:17mm;align-items:center;gap:3mm;padding:0 0 2mm;background:#fff;border-bottom:0.6mm solid #1565c0}
  #print-head img{height:12mm;width:auto}
  #print-head h1{margin:0;font-size:14pt;line-height:1.15;color:#222}
  #print-head p{margin:1mm 0 0;font-size:7.5pt;color:#555}
  #print-meta{margin-left:auto;text-align:right;font-size:7pt;line-height:1.45;color:#555;white-space:nowrap}
  #print-meta b{display:block;color:#222;font-size:7.5pt}
  #print-foot{position:absolute;z-index:1000;bottom:0;left:0;right:0;height:17mm;flex-direction:column;justify-content:flex-start;gap:1mm;padding:2mm 0 0;background:#fff;border-top:0.4mm solid #9aaab6}
  #print-legend{display:flex;flex-wrap:wrap;gap:1mm 4mm;padding-right:42mm;font-size:7pt;line-height:1.3;color:#222}
  #print-legend .pi{display:flex;align-items:center;gap:1.5mm}
  #print-legend .sw{width:4mm;height:2.5mm;display:inline-block;border:0.2mm solid #555;background:#fff}
  #print-legend .pi b{font-weight:600}
  #print-scale-wrap{position:absolute;right:0;top:2mm;text-align:right;font-size:7pt;color:#666;white-space:nowrap}
  #print-scale-wrap b{display:block;font-size:10pt;color:#222}
  #print-sources{font-size:6pt;color:#777;padding-top:1mm;border-top:0.2mm solid #e1e8ee}
}
