/* Carte des risques — styles (v3.28.4 « Vigie Républicaine » : Ardoise Civique & Bleu Barse, sans dégradé décoratif) */
  :root {
    --navy: #1F4E79;
    --teal: #1F4E79;
    --slate-header: #0F172A;
    --panel-bg: rgba(255, 255, 255, 0.98);
    --panel-radius: 10px;
    --panel-shadow: 0 4px 16px rgba(15, 23, 42, 0.22);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
  }
  * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
  html, body { margin:0; padding:0; width:100%; height:100%; overflow:hidden; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; background:#e2e8f0; }

  /* Bandeau supérieur adaptatif (repliable) */
  #header {
    position: absolute; top: 0; left: 0; right: 0; z-index: 1050;
    background: var(--slate-header);
    border-bottom: 2px solid #1F4E79;
    color: #fff; display: flex; align-items: center; justify-content: space-between;
    gap: 8px; padding: 6px 12px; min-height: 48px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.25); transition: transform 0.25s ease;
  }
  body.fullscreen-map #header { transform: translateY(-100%); }
  #header .title-wrap { min-width: 0; flex: 1; }
  #header .commune-blason { width:34px; height:40px; object-fit:contain; flex:0 0 auto; }
  #header h1 { font-size: clamp(13px, 1.5vw, 16px); margin: 0; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #header .sub { font-size: clamp(11px, 1.1vw, 12.5px); color: #CBD5E1; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #header .badge {
    background: #FFEDD5; color: #9A3412; font-size: clamp(11px, 1.1vw, 12px);
    font-weight: 800; padding: 4px 8px; border-radius: 6px; border: 1.5px solid #C2410C;
    white-space: nowrap; flex-shrink: 0;
  }

  /* Conteneur carte plein écran garanti */
  #map { position: absolute; top: 48px; bottom: 0; left: 0; right: 0; z-index: 1; }
  body.fullscreen-map #map { top: 0 !important; }

  /* Barre d'outils flottante adaptative (PC / Mac / Tablette / Téléphone) */
  #ui-toolbar {
    position: absolute; top: 58px; left: 50%; transform: translateX(-50%);
    z-index: 1020; display: flex; align-items: center; gap: 6px;
    background: rgba(15, 23, 42, 0.94); backdrop-filter: blur(8px);
    padding: 5px 8px; border-radius: 12px; box-shadow: 0 3px 12px rgba(0,0,0,0.3);
    border: 1px solid #334155;
    max-width: calc(100vw - 96px); overflow-x: auto; scrollbar-width: none;
    transition: top 0.25s ease;
  }
  #ui-toolbar::-webkit-scrollbar { display: none; }
  body.fullscreen-map #ui-toolbar { top: 10px; }

  .tb-btn {
    appearance: none; border: 1px solid rgba(255,255,255,0.28);
    background: #1E293B; color: #F8FAFC;
    font-size: clamp(12px, 1.2vw, 13.5px); font-weight: 700;
    padding: 6px 12px; min-height: 38px; border-radius: 8px; cursor: pointer;
    white-space: nowrap; display: inline-flex; align-items: center; gap: 5px;
    transition: all 0.15s ease; line-height: 1.1;
  }
  .tb-btn:hover { background: #334155; }
  .tb-btn.active { background: #1F4E79; border-color: #93C5FD; color: #fff; box-shadow: 0 0 0 2px rgba(147,197,253,0.4); }
  .tb-btn.rga-active { background: #B91C1C; border-color: #FCA5A5; color: #fff; }

  /* Sélecteur rapide de fond de carte (IGN / OSM) en haut à droite */
  #basemap-bar {
    position: absolute; top: 58px; right: 10px; z-index: 1015;
    background: var(--panel-bg); padding: 4px 8px; border-radius: 8px;
    box-shadow: var(--panel-shadow); border: 1.5px solid #94a3b8;
    display: flex; align-items: center; gap: 6px; font-size: 12.5px;
    transition: top 0.25s ease;
  }
  body.fullscreen-map #basemap-bar { top: 10px; }
  #basemap-select {
    border: 1.5px solid #64748b; border-radius: 6px; padding: 4px 8px;
    font-size: 12.5px; font-weight: 700; color: #0F172A; background: #f8fafc; cursor: pointer;
  }

  /* Encadrés flottants dynamiques (Couches, Légende, Synthèse) */
  .floating-panel {
    position: absolute; z-index: 1010; background: var(--panel-bg);
    border-radius: var(--panel-radius); box-shadow: var(--panel-shadow);
    border: 1.5px solid #94a3b8;
    display: flex; flex-direction: column;
    transition: opacity 0.2s ease, transform 0.2s ease;
    overflow: hidden;
  }
  .floating-panel.hidden {
    opacity: 0; pointer-events: none; transform: translateY(10px) scale(0.98);
    display: none !important;
  }
  .panel-header {
    background: var(--slate-header);
    border-bottom: 2px solid #1F4E79;
    color: #fff; padding: 8px 12px; display: flex; align-items: center;
    justify-content: space-between; gap: 8px; font-size: clamp(13px, 1.3vw, 14px);
    font-weight: 800; flex-shrink: 0; user-select: none;
  }
  .panel-close {
    background: #1E293B; color: #fff; border: 1px solid #64748B;
    border-radius: 6px; padding: 4px 10px; font-size: 12.5px; font-weight: 700;
    cursor: pointer; line-height: 1.2; min-height: 32px;
  }
  .panel-close:hover { background: #B91C1C; border-color: #FCA5A5; }
  .panel-body {
    padding: 10px 12px; overflow-y: auto; -webkit-overflow-scrolling: touch;
    font-size: clamp(12.5px, 1.15vw, 13.5px); line-height: 1.45; color: #0F172A;
  }

  /* Positions dynamiques sur PC / Mac (> 900px) */
  #panel-layers {
    top: 102px; right: 10px;
    width: clamp(280px, 26vw, 370px);
    max-height: calc(100dvh - 116px);
  }
  #panel-legend {
    bottom: calc(12px + var(--safe-bottom)); left: 10px;
    width: clamp(260px, 24vw, 345px);
    max-height: min(52dvh, calc(100dvh - 120px));
  }
  #panel-info {
    bottom: calc(12px + var(--safe-bottom)); right: 10px;
    width: clamp(270px, 25vw, 355px);
    max-height: min(46dvh, calc(100dvh - 120px));
  }
  body.fullscreen-map #panel-layers { top: 54px; max-height: calc(100dvh - 68px); }

  /* Styles internes Couches */
  .preset-bar { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; padding-bottom: 7px; border-bottom: 1px solid #cbd5e1; }
  .preset-btn {
    flex: 1 1 auto; background: #f1f5f9; border: 1.5px solid #94a3b8; color: #0F172A;
    border-radius: 6px; padding: 5px 8px; font-size: 12px; font-weight: 700; cursor: pointer; text-align: center;
  }
  .preset-btn:hover { background: #EFF6FF; border-color: #1F4E79; color: #1F4E79; }
  .layer-group-title {
    font-weight: 800; color: #1F4E79; font-size: 12px; text-transform: uppercase;
    letter-spacing: 0.3px; margin: 8px 0 4px 0; padding-top: 5px; border-top: 1px solid #cbd5e1;
  }
  .layer-group-title:first-of-type { margin-top: 0; padding-top: 0; border-top: none; }
  .layer-item {
    display: flex; align-items: flex-start; gap: 7px; padding: 5px 4px;
    border-radius: 4px; cursor: pointer; font-size: clamp(12.5px, 1.1vw, 13.5px); color: #0F172A;
  }
  .layer-item:hover { background: #f1f5f9; }
  .layer-item input[type="checkbox"] { margin-top: 2px; width: 16px; height: 16px; accent-color: #1F4E79; cursor: pointer; flex-shrink: 0; }

  /* Styles internes Légende & Synthèse */
  .swatch { display:inline-block; width:13px; height:13px; margin-right:6px; vertical-align:middle; border:1px solid #334155; flex-shrink:0; }
  .legend-sec { display:block; margin-bottom:4px; margin-top:8px; color:#1F4E79; font-weight:800; border-bottom:1px solid #cbd5e1; padding-bottom:2px; }
  .legend-sec:first-child { margin-top:0; }
  .src { font-size:11.5px; color:#334155; font-style:italic; margin-top:8px; display:block; border-top:1px solid #cbd5e1; padding-top:6px; }
  .risk { margin-bottom:7px; border-bottom:1px solid #e2e8f0; padding-bottom:5px; }
  .gap-note { font-size:12px; color:#9A3412; font-style:italic; }
  .alert-box { margin-top:5px; padding:6px 8px; background:#FEE2E2; border-left:4px solid #B91C1C; color:#7F1D1D; font-size:12px; font-weight:600; }
  .rga-btn { background:#1F4E79; color:#fff; border:none; padding:8px 10px; border-radius:6px; font-size:12.5px; font-weight:700; cursor:pointer; margin-top:6px; width:100%; }
  .rga-btn.active { background:#B91C1C; }

  /* Popups Leaflet adaptatifs */
  .leaflet-popup-content-wrapper { border-radius: 8px !important; }
  .leaflet-popup-content { margin: 10px 12px !important; font-size: clamp(12.5px, 1.2vw, 13.5px) !important; line-height: 1.45 !important; max-width: min(310px, 78vw) !important; }

  /* ============================================================================
     ADAPTATION TABLETTE & TÉLÉPHONE (iOS / Android / iPad)
     ============================================================================ */
  @media (max-width: 900px) {
    #header { flex-wrap: wrap; padding: 5px 10px; }
    #header .sub { display: none; }
    #header .badge { font-size: 11px; padding: 2px 6px; }
    #ui-toolbar {
      top: auto; bottom: calc(10px + var(--safe-bottom)); left: 8px; right: 8px;
      transform: none; max-width: none; justify-content: space-between;
      padding: 6px 8px; border-radius: 12px;
    }
    body.fullscreen-map #ui-toolbar { top: auto; bottom: calc(10px + var(--safe-bottom)); }
    .tb-btn { flex: 1 1 auto; justify-content: center; padding: 8px 6px; font-size: 12px; min-height: 44px; }
    #basemap-bar { top: 56px; right: 8px; left: auto; }
    body.fullscreen-map #basemap-bar { top: 8px; }

    /* Tiroirs bas (Bottom-Sheet) sur mobile/tablette pour ne jamais bloquer la carte */
    #panel-layers, #panel-legend, #panel-info {
      top: auto !important; left: 8px !important; right: 8px !important;
      bottom: calc(60px + var(--safe-bottom)) !important;
      width: auto !important;
      max-height: 58dvh !important;
      border-radius: 12px;
    }
    .layer-item { padding: 7px 4px; font-size: 14px; }
    .layer-item input[type="checkbox"] { width: 18px; height: 18px; }
  }
#fond-etat{padding:6px 12px;background:#FEE2E2;color:#7F1D1D;font-weight:700;font-size:13px;border-bottom:1.5px solid #B91C1C}
.bandeau-travail{padding:9px 15px;background:#FFEDD5;color:#7C2D12;font-weight:700;font-size:13.5px;border-bottom:2px solid #C2410C}
#basemap-bar label{font-weight:700;color:#0F172A}

/* fond de secours hors ligne (carte de synthèse fixe du PCS) */
.fond-secours { position: fixed; inset: 0; z-index: 2000; background: #fff; display: flex; flex-direction: column; gap: 6px; padding: 8px; }
.fond-secours[hidden] { display: none; }
.fond-secours img { flex: 1 1 auto; min-height: 0; width: 100%; object-fit: contain; }
.fond-secours-titre { margin: 0; font-weight: 700; font-size: 1rem; color: #7C2D12; background: #FFEDD5; border: 1px solid #C2410C; padding: 6px 10px; border-radius: 6px; }
.fond-secours button { align-self: flex-start; min-height: 48px; padding: 0 14px; font-size: 1rem; font-weight: 700; border: 1.5px solid #475569; border-radius: 6px; background: #fff; color: #0F172A; cursor: pointer; touch-action: manipulation; }
