/* PROPRIÉTÉ DE CASCADE : responsive global et offcanvas Info/Stats. Les
   structures historiques sont dans bar_flottante.css et la variante compacte
   dans panels-compact.css. Cette feuille doit rester chargée après les deux. */

.sous-titre { margin-left: 0; }

/* =========================================================
   RESPONSIVE GLOBAL - TABLETTES ET MOBILES
   ========================================================= */
/* Ce fichier complète les styles principaux pour les écrans réduits.
   Il évite les débordements, adapte les panneaux flottants et rend la popup
   d'entité utilisable sur mobile. */

:root {
  /* Espacement commun utilisé sur mobile, avec prise en compte des safe areas. */
  --mobile-page-padding: 10px;
  --mobile-toolbar-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
}

/* PANNEAUX <= 768 PX — unique propriétaire responsive.
   L'ordre des trois groupes conserve exactement l'ancienne cascade :
   structure historique, position finale, puis variante compacte. */
@media (max-width: 768px) {
  .tool-panel {
    width: 90%;
    left: 5% !important;
    right: 5%;
    transform: none !important;
  }

  .edit-style-panel {
    width: 90%;
    left: 5%;
    right: 5%;
  }

  .tool-panel {
    right: 10px;
    left: 10px !important;
    width: auto;
    max-height: 70vh;
  }

  #measure-style-panel {
    right: 10px;
    left: 10px;
    width: auto;
  }

  .tool-panel {
    min-width: 180px;
    max-width: 320px;
    font-size: 12px;
  }

  .tool-panel .panel-content {
    max-height: 55vh;
    padding: 10px;
  }

  #attribute-table-panel {
    min-width: auto;
    width: 95% !important;
    left: 2.5% !important;
  }
}

@media (max-width: 1024px) {
  /* Ajustements tablette : en-tête plus compact et carte recalculée en hauteur. */
  :root {
    --header-height: 70px;
  }

  header {
    margin: 0;
    border-radius: 0;
    padding: 0 12px;
  }

  .logo_entre {
    width: 118px;
  }

  .titre {
    font-size: 18px;
    white-space: normal;
    line-height: 1.15;
  }

  .sous-titre {
    margin-left: 0;
  }

  #address-input {
    width: min(320px, 34vw);
  }

  #map-container,
  .map {
    height: calc(100dvh - var(--header-height));
  }
}

/* =========================================================
   MOBILES - STRUCTURE PRINCIPALE
   ========================================================= */

@media (max-width: 760px) {
  /* Readable titles beside the logo, with the address search below. */
  :root {
    --header-height: 152px;
  }

  html,
  body {
    width: 100%;
    min-height: 100%;
    overflow: hidden;
  }

  body {
    background: #f7f3eb;
    touch-action: pan-x pan-y;
  }

  header {
    position: relative;
    height: var(--header-height);
    padding: 7px var(--mobile-page-padding);
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 96px 36px;
    align-items: start;
    gap: 8px;
    background: transparent;
    border-bottom: 0;
    box-shadow: none;
    z-index: 12001;
  }

  .logo {
    min-width: 0;
    width: 100%;
    align-items: center;
    flex-direction: row;
    height: 100%;
    justify-content: flex-start;
    gap: 9px;
  }

  .logo_entre {
    width: 48px;
    max-height: 42px;
    object-fit: contain;
  }

  .title-group {
    min-width: 0;
    width: 100%;
    gap: 2px;
    align-items: flex-start;
    text-align: left;
  }

  .titre {
    font-size: 18px;
    line-height: 1.1;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .sous-titre {
    display: block;
    margin-left: 0;
    align-self: flex-start;
    text-align: left;
    white-space: normal;
    font-size: 14px;
    line-height: 1.2;
  }

  #map-container,
  .map {
    height: calc(100dvh - var(--header-height));
  }

  #map-container {
    margin: 0;
  }
}

/* =========================================================
   RECHERCHE ADRESSE
   ========================================================= */

@media (max-width: 760px) {
  /* Le champ de recherche devient pleine largeur et les suggestions restent
     lisibles sans dépasser l'écran. */
  .search-bar {
    width: 100%;
    min-width: 0;
  }

  #address-input {
    width: 100%;
    min-height: 42px;
    padding: 10px 44px 10px 14px;
    font-size: 14px;
    border-radius: 999px;
    background: #fff;
  }

  .search-btn {
    right: 4px;
    width: 34px;
    height: 34px;
    font-size: 15px;
  }

  .address-suggestions-list {
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    max-height: min(46dvh, 280px);
    border-radius: 10px;
    z-index: 12000;
  }

  .suggestion-item {
    min-height: 44px;
    padding: 11px 14px;
    font-size: 13px;
    line-height: 1.25;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
}

/* =========================================================
   BARRE FLOTTANTE MOBILE
   ========================================================= */

@media (max-width: 760px) {
  /* La barre passe en navigation horizontale compacte en bas d'écran. */
  .floating-toolbar {
    opacity: 1 !important;
    left: var(--mobile-page-padding);
    right: var(--mobile-page-padding);
    bottom: calc(34px + env(safe-area-inset-bottom, 0px));
    transform: none;
    width: auto;
    max-width: none;
  }

  .floating-toolbar.is-visible {
    animation: mobileToolbarIn 0.22s ease;
  }

  .toolbar-container {
    opacity: 1 !important;
    background: #0d3380 !important;
    width: 100%;
    height: 48px;
    padding: 0 8px;
    border-radius: 999px;
    justify-content: space-between;
  }

  .separator {
    display: none;
  }

  .nav-button {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
  }

  .tools-list {
    flex: 1 1 auto;
    gap: 6px;
    padding: 0 6px;
    max-width: none;
    scroll-snap-type: x proximity;
  }

  .tool-item {
    background: transparent !important;
    opacity: 1 !important;
    min-width: 46px;
    min-height: 44px;
    padding: 4px 3px;
    scroll-snap-align: center;
  }

  .tool-icon {
    opacity: 1 !important;
    width: 34px;
    height: 34px;
    margin: 0 auto;
    font-size: 13px;
  }

  .tool-label {
    opacity: 1 !important;
    max-width: 54px;
    font-size: 8px;
    line-height: 1;
    margin-top: 4px;
  }

  .toolbar-toggle-btn {
    opacity: 1 !important;
    background: #0d3380 !important;
    bottom: var(--mobile-toolbar-bottom);
    width: 36px;
    height: 36px;
    font-size: 13px;
  }
}

@keyframes mobileToolbarIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* =========================================================
   PANNEAUX OUTILS EN BOTTOM SHEET
   ========================================================= */

@media (max-width: 760px) {
  /* Les panneaux ne flottent plus à droite : ils deviennent des bottom sheets. */
  .tool-panel,
  #legend-panel {
    opacity: 1 !important;
    background: #fff !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    min-height: 0 !important;
    height: auto !important;
    max-height: min(68dvh, 560px) !important;
    left: var(--mobile-page-padding) !important;
    right: var(--mobile-page-padding) !important;
    top: auto !important;
    bottom: calc(104px + env(safe-area-inset-bottom, 0px)) !important;
    transform: none !important;
    border-radius: 14px !important;
    resize: none !important;
    overflow: hidden;
    isolation: isolate;
  }

  .tool-panel.is-active {
    opacity: 1 !important;
    animation: mobilePanelIn 0.2s ease;
  }

  .tool-panel .panel-header,
  .panel-header {
    background: #f8f9fa !important;
    opacity: 1 !important;
    min-height: 48px;
    padding: 12px 14px;
    cursor: default;
  }

  .tool-panel .panel-header h3,
  .panel-header h3 {
    min-width: 0;
    font-size: 14px;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tool-panel .panel-close,
  .panel-close {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    font-size: 18px;
  }

  .tool-panel .panel-content,
  .panel-content {
    background: #fff !important;
    opacity: 1 !important;
    padding: 12px;
    max-height: calc(min(68dvh, 560px) - 48px) !important;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .panel-resizer {
    display: none;
  }
}

@keyframes mobilePanelIn {
  from {
    transform: translateY(14px);
  }
  to {
    transform: translateY(0);
  }
}

/* =========================================================
   CONTENUS DES PANNEAUX
   ========================================================= */

@media (max-width: 760px) {
  /* Les contrôles sont agrandis pour le tactile et gardent des hauteurs stables. */
  .layer-panel-item,
  .layer-selection-list .panel-btn,
  #basemap-content .layer-panel-item {
    min-height: 44px;
  }

  .layer-checkbox-label {
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
  }

  .layer-checkbox-label input {
    width: 20px;
    height: 20px;
    flex: 0 0 20px;
  }

  .panel-btn {
    min-height: 44px;
    padding: 11px 12px;
    font-size: 14px;
    border-radius: 8px;
  }

  .info-section {
    padding: 10px;
    margin-bottom: 10px;
  }

  .info-section h4 {
    font-size: 14px;
    margin-bottom: 6px;
  }

  .info-section p {
    font-size: 13px;
    line-height: 1.35;
  }

  .add-header {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px;
    align-items: center;
  }

  .btn-back {
    min-height: 38px;
    padding: 8px 10px;
  }

  #add-selected-layer-name {
    margin: 0;
    font-size: 14px;
    overflow-wrap: anywhere;
  }

  .form-control,
  input[type="text"],
  input[type="number"],
  input[type="email"],
  input[type="url"],
  select,
  textarea {
    min-height: 42px;
    font-size: 16px;
  }
}

/* =========================================================
   LEGENDE ET POPUPS
   ========================================================= */
/* Popup d'information d'entité. Elle reprend le langage visuel des panneaux de
   la barre flottante tout en gardant un corps scrollable pour les longs attributs. */

.feature-selection-panel.offcanvas-start {
  top: 85px !important;
  bottom: 0;
  left: 0;
  width: 360px;
  max-width: calc(100vw - 48px);
  z-index: 10000;
  background: #fff;
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
  border: 0 !important;
  border-right: 1px solid rgba(0, 0, 0, 0.12) !important;
  border-radius: 0 12px 0 0 !important;
}

@media (max-width: 760px) {
  .feature-selection-panel.offcanvas-start {
    top: var(--header-height) !important;
  }
}

.feature-selection-panel #feature-popup-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.feature-selection-panel .popup-header {
  flex-shrink: 0;
  border-radius: 0 !important;
}

.feature-selection-panel.offcanvas .popup-body {
  max-height: none !important;
  overflow-y: auto !important;
  padding-bottom: calc(16px + env(safe-area-inset-bottom)) !important;
}

.feature-info-panel.feature-popup {
  position: fixed !important;
  top: 95px !important;
  left: 50px !important;
  right: auto !important;
  bottom: auto !important;
  width: 300px !important;
  min-width: 0 !important;
  max-width: calc(100vw - 40px) !important;
  height: auto !important;
  min-height: 0 !important;
  max-height: calc(100dvh - 125px) !important;
  display: none !important;
  flex-direction: column !important;
  padding: 0 !important;
  overflow: hidden !important;
  border-radius: 10px !important;
  background: #ffffff !important;
  box-shadow: 0 6px 25px rgba(0, 0, 0, 0.18) !important;
  z-index: 10000 !important;
}

.feature-info-panel.feature-popup.is-active {
  display: flex !important;
}

.feature-info-panel.feature-popup::before,
.feature-info-panel.feature-popup::after {
  display: none !important;
  content: none !important;
}

.feature-info-panel .popup-header {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  margin: 0 !important;
  padding: 10px 14px !important;
  background: #f8f9fa !important;
  border-bottom: 1px solid #e9ecef !important;
  border-radius: 10px 10px 0 0 !important;
}

.feature-info-panel .popup-header h3 {
  min-width: 0;
  margin: 0;
  color: #333;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
}

.feature-info-panel .popup-header h3 i {
  color: #0066cc;
  font-size: 13px;
}

.feature-info-panel .popup-header h3 {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.popup-header-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.feature-info-panel .popup-body {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  max-height: calc(100dvh - 180px) !important;
  padding: 10px 14px 14px !important;
  overflow-y: scroll !important;
  scrollbar-width: thin;
  scrollbar-color: #b8c2d6 #f3f4f6;
}

.feature-info-panel .popup-body::-webkit-scrollbar {
  width: 8px;
}

.feature-info-panel .popup-body::-webkit-scrollbar-track {
  background: #f3f4f6;
  border-radius: 999px;
}

.feature-info-panel .popup-body::-webkit-scrollbar-thumb {
  background: #b8c2d6;
  border-radius: 999px;
}

.feature-info-panel .popup-body::-webkit-scrollbar-thumb:hover {
  background: #8ea0bd;
}

.feature-attributes-list {
  margin: 0;
}

.feature-attribute-row {
  padding: 8px 0;
  border-bottom: 1px solid #e9ecef;
}

.feature-attribute-row:last-child {
  border-bottom: 0;
}

.feature-attribute-row dt {
  margin: 0 0 3px;
  color: #003366;
  font-size: 12px;
  font-weight: 700;
}

.feature-attribute-row dd {
  margin: 0;
  color: #0d3380;
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.feature-popup-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.feature-popup-member {
  border: 1px solid #d9e2ef;
  border-radius: 8px;
  background: #ffffff;
  overflow: hidden;
}

.feature-popup-member-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: #f3f7fc;
}

.feature-popup-member h4 {
  min-width: 0;
  margin: 0;
  color: #0d3380;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.feature-popup-member .feature-attributes-list {
  padding: 0 10px;
}

.feature-info-panel .popup-empty {
  margin: 0 !important;
  color: #6b7280;
  font-size: 13px;
}

@media (max-width: 760px) {
  /* Sur mobile, la popup devient un panneau bas pleine largeur pour ne pas
     masquer toute la carte et rester accessible au pouce. */
  .legend-list {
    gap: 7px;
  }

  .legend-item {
    min-height: 42px;
    padding: 8px;
  }

  .legend-symbol {
    width: 32px;
    height: 24px;
  }

  .legend-label {
    font-size: 13px;
    white-space: normal;
    line-height: 1.25;
  }

  .feature-info-panel.feature-popup {
    top: auto !important;
    left: var(--mobile-page-padding) !important;
    right: var(--mobile-page-padding) !important;
    bottom: calc(84px + env(safe-area-inset-bottom)) !important;
    width: auto !important;
    max-width: none !important;
    max-height: min(68dvh, 520px) !important;
    font-size: 13px;
  }

  .feature-info-panel .popup-body {
    max-height: calc(min(68dvh, 520px) - 48px) !important;
  }

  .popup-close-btn {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
  }

  .ol-control {
    touch-action: manipulation;
  }
}

/* =========================================================
   PETITS ECRANS
   ========================================================= */

@media (max-width: 390px) {
  :root {
    --header-height: 152px;
    --mobile-page-padding: 8px;
  }

  .logo_entre {
    width: 48px;
  }

  .titre {
    font-size: 18px;
  }

  .sous-titre {
    display: block;
  }

  #address-input {
    min-height: 40px;
    font-size: 13px;
  }

  .floating-toolbar {
    bottom: calc(34px + env(safe-area-inset-bottom, 0px));
  }

  .toolbar-container {
    height: 48px;
    padding: 0 5px;
  }

  .nav-button {
    display: none;
  }

  .tool-item {
    min-width: 46px;
  }

  .tool-label {
    font-size: 7.5px;
  }

  .tool-panel,
  #legend-panel {
    bottom: calc(96px + env(safe-area-inset-bottom, 0px)) !important;
  }
}

/* =========================================================
   MOBILE PAYSAGE
   ========================================================= */

@media (max-width: 420px) and (orientation: portrait) {
  :root { --header-height: 184px; }
  header { grid-template-rows: 128px 36px; }
}
@media (max-width: 360px) and (orientation: portrait) {
  :root { --header-height: 216px; }
  header { grid-template-rows: 160px 36px; }
}

@media (max-height: 520px) and (orientation: landscape) {
  :root {
    --header-height: 72px;
  }

  header {
    display: grid;
    margin: 0;
    grid-template-columns: minmax(0, 1fr) minmax(180px, 34vw);
    grid-template-rows: 1fr;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
  }

  .logo {
    flex-direction: row;
    align-items: center;
    min-width: 0;
    width: 100%;
    gap: 8px;
  }

  .title-group {
    min-width: 0;
    width: 100%;
    align-items: flex-start;
    text-align: left;
  }

  header .logo_entre {
    width: 104px;
    max-height: 36px;
  }

  .titre {
    font-size: 18px;
    white-space: normal;
  }

  .sous-titre {
    display: block;
    margin-left: 0;
    align-self: flex-start;
    text-align: left;
    white-space: normal;
    font-size: 12px;
    line-height: 1.25;
  }

  .search-bar {
    align-self: center;
  }

  #address-input {
    min-height: 38px;
  }

  .floating-toolbar {
    left: auto;
    right: 10px;
    bottom: 10px;
    width: min(460px, 58vw);
  }

  .toolbar-toggle-btn {
    left: auto;
    right: 12px;
    transform: none;
    bottom: 72px;
  }

  .toolbar-toggle-btn:hover {
    transform: none;
  }

  .tool-panel,
  #legend-panel {
    left: 10px !important;
    right: auto !important;
    bottom: 10px !important;
    width: min(420px, 48vw) !important;
    max-height: calc(100dvh - var(--header-height) - 20px) !important;
  }

  .tool-panel .panel-content,
  .panel-content {
    max-height: calc(100dvh - var(--header-height) - 68px) !important;
  }
}

/* Le panneau Stats partage toute sa hauteur entre les trois graphiques. Cette
   surcharge reste ciblée afin que le panneau Info conserve son défilement. */
#stats-panel #stats-content {
  display: grid;
  grid-template-rows: repeat(3, minmax(0, 1fr));
  flex: 1 1 auto;
  min-height: 0;
  gap: 4px;
  padding: 8px 10px !important;
  overflow: hidden !important;
}

#stats-panel .stats-section {
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin-top: 0;
  padding-top: 4px;
  overflow: hidden;
}

#stats-panel .stats-section h4 {
  flex: 0 0 auto;
  margin-bottom: 4px;
  line-height: 1.15;
}

#stats-panel .stats-list {
  min-height: 0;
  flex: 1 1 auto;
  gap: 0;
}

#stats-panel .stats-chart-wrap,
#stats-panel .stats-chart-wrap.is-compact {
  height: 100% !important;
  min-height: 0;
  flex: 1 1 auto;
}

/* =========================================================
   TOUCH
   ========================================================= */

@media (pointer: coarse) {
  button,
  .tool-item,
  .panel-btn,
  .nav-button,
  .panel-close,
  .layer-checkbox-label,
  .suggestion-item {
    -webkit-tap-highlight-color: transparent;
  }
}

/* =========================================================
   ESPACE D'ADMINISTRATION
   ========================================================= */

/* Le workspace est un panneau latéral non modal : seule sa propre emprise
   intercepte les interactions, la carte reste disponible à côté. */
#admin-workspace {
  position: fixed;
  top: 0;
  right: 0;
  bottom: auto;
  left: auto;
  width: 520px;
  max-width: 100%;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  z-index: 11000;
  overflow: hidden;
}

@media (max-width: 760px) {
  #admin-workspace {
    width: 100%;
    max-width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
  }

  #admin-workspace .admin-workspace-body {
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-rows: auto minmax(0, 1fr) !important;
  }

  #admin-workspace .admin-workspace-nav {
    flex-direction: row !important;
    min-width: 0;
    padding: 6px 8px !important;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-bottom: 1px solid var(--admin-border);
    -webkit-overflow-scrolling: touch;
  }

  #admin-workspace .admin-workspace-nav button {
    flex: 0 0 104px;
    min-height: 48px !important;
    padding: 7px 6px !important;
    border-left: 1px solid transparent;
    border-bottom: 3px solid transparent;
  }

  #admin-workspace .admin-workspace-nav button[aria-selected="true"] {
    border-left-color: var(--admin-accent);
    border-bottom-color: var(--admin-accent);
  }

  #admin-workspace .admin-workspace-content {
    min-width: 0;
    min-height: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    overflow: hidden;
  }

  #admin-workspace [data-admin-workspace-view] > .panel-content {
    min-height: 0;
    max-height: none !important;
    overflow-y: auto;
  }
}

/* Un téléphone en paysage peut dépasser le seuil mobile de 760 px. Le panneau
   conserve alors sa largeur d'atelier tout en restant entre les deux encoches. */
@media (max-height: 520px) and (orientation: landscape) {
  #admin-workspace {
    right: env(safe-area-inset-right, 0px);
    width: 520px;
    max-width: calc(100% - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
  }

  #admin-workspace .admin-workspace-content {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

/* =========================================================
   OFFCANVAS INFO ET STATISTIQUES
   ========================================================= */

.tool-panel.offcanvas:is(.offcanvas-start,.offcanvas-end) {
  --bs-offcanvas-width: min(380px, 100vw);
  display: flex !important;
  top: 85px !important;
  right: 0 !important;
  bottom: 0 !important;
  left: auto !important;
  width: var(--bs-offcanvas-width) !important;
  min-width: 0 !important;
  min-height: 0 !important;
  height: auto !important;
  max-height: none !important;
  border: 0 !important;
  border-left: 1px solid rgba(0, 0, 0, 0.12) !important;
  border-radius: 12px 0 0 0 !important;
  resize: none !important;
  overflow: hidden !important;
  transform: translateX(100%) !important;
  visibility: hidden;
}

.tool-panel.offcanvas:is(.offcanvas-start,.offcanvas-end).show,
.tool-panel.offcanvas:is(.offcanvas-start,.offcanvas-end).showing,
.tool-panel.offcanvas:is(.offcanvas-start,.offcanvas-end).is-active {
  transform: none !important;
  visibility: visible;
}

.tool-panel.offcanvas:is(.offcanvas-start,.offcanvas-end).hiding {
  visibility: visible;
}

.tool-panel.offcanvas:is(.offcanvas-start,.offcanvas-end) .panel-content {
  min-height: 0 !important;
  max-height: none !important;
  overflow-y: auto !important;
}

.tool-panel.offcanvas:is(.offcanvas-start,.offcanvas-end) .panel-resizer {
  display: none !important;
}

@media (max-width: 760px) {
  .tool-panel.offcanvas:is(.offcanvas-start,.offcanvas-end) {
    --bs-offcanvas-width: min(360px, 100vw);
    top: var(--header-height) !important;
    right: 0 !important;
    bottom: 0 !important;
    left: auto !important;
    height: auto !important;
    max-height: none !important;
    border-radius: 12px 0 0 0 !important;
  }

  .tool-panel.offcanvas:is(.offcanvas-start,.offcanvas-end) .panel-content {
    max-height: none !important;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .tool-panel.offcanvas:is(.offcanvas-start,.offcanvas-end) {
    --bs-offcanvas-width: min(380px, 48vw);
    top: var(--header-height) !important;
    right: 0 !important;
    bottom: 0 !important;
    left: auto !important;
    height: auto !important;
    max-height: none !important;
  }

  .tool-panel.offcanvas:is(.offcanvas-start,.offcanvas-end) .panel-content {
    max-height: none !important;
  }
}

/* STATS - PAYSAGE BAS
   Les graphiques passent côte à côte, tout en laissant la carte accessible. */
@media (max-height: 520px) and (orientation: landscape) {
  #stats-panel.tool-panel.offcanvas:is(.offcanvas-start,.offcanvas-end) {
    --bs-offcanvas-width: min(85vw, 720px);
    top: 0 !important;
    width: min(85vw, 720px) !important;
    border-radius: 0 !important;
  }

  #stats-panel #stats-content {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: minmax(0, 1fr);
    gap: 0;
    padding: 6px !important;
    overflow: hidden !important;
  }

  #stats-panel .stats-section {
    margin: 0;
    padding: 0 4px;
    border-top: 0;
    border-left: 1px solid #e5e7eb;
  }

  #stats-panel .stats-section:first-child {
    border-left: 0;
  }

  #stats-panel .stats-section h4 {
    display: block;
    margin: 0 0 3px;
    font-size: 11px;
    line-height: 1.15;
  }

  #stats-panel .stats-chart-wrap,
  #stats-panel .stats-chart-wrap.is-compact {
    min-height: 120px;
  }
}

/* Mobile: keep header, panels and bottom controls in separate screen areas. */
@media (max-width: 760px), (max-height: 520px) and (orientation: landscape) {
  :root {
    --mobile-controls-clearance: calc(90px + env(safe-area-inset-bottom, 0px));
  }

  .floating-toolbar { z-index: 9000; }
  .toolbar-toggle-btn { z-index: 9000; }
  #map-attribution { z-index: 9001; }

  .tool-panel,
  #legend-panel,
  .feature-selection-panel.offcanvas-start,
  .tool-panel.offcanvas:is(.offcanvas-start,.offcanvas-end),
  #stats-panel.tool-panel.offcanvas:is(.offcanvas-start,.offcanvas-end) {
    bottom: var(--mobile-controls-clearance) !important;
    max-height: calc(100dvh - var(--header-height) - var(--mobile-controls-clearance) - 8px) !important;
  }

  .feature-selection-panel.offcanvas-start,
  .tool-panel.offcanvas:is(.offcanvas-start,.offcanvas-end),
  #stats-panel.tool-panel.offcanvas:is(.offcanvas-start,.offcanvas-end) {
    top: var(--header-height) !important;
  }

  .toolbar-container { height: 48px; padding: 0 4px; }
  .tools-list { gap: 2px; padding: 0 2px; }
  .tool-item { min-width: 46px; min-height: 44px; padding: 3px 2px; }
  .tool-icon { width: 28px; height: 28px; font-size: 12px; }
  .tool-label { font-size: 9px; line-height: 12px; margin-top: 2px; }
  .nav-button { width: 28px; height: 36px; flex-basis: 28px; }
  .toolbar-toggle-btn {
    width: 28px;
    height: 28px;
    font-size: 12px;
    bottom: calc(4px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }
  .toolbar-toggle-btn:hover { transform: translateX(-50%); }
  .floating-toolbar {
    bottom: calc(34px + env(safe-area-inset-bottom, 0px));
    left: var(--mobile-page-padding);
    right: var(--mobile-page-padding);
    width: auto;
    max-width: 460px;
    margin: 0 auto;
    transform: none;
  }
  .tool-panel .panel-header { min-height: 40px; padding: 6px 10px; }
  .tool-panel .panel-header h3 { font-size: 13px; }
  .tool-panel .panel-close { width: 32px; height: 32px; flex-basis: 32px; }
  #stats-panel .stats-chart-wrap,
  #stats-panel .stats-chart-wrap.is-compact { min-height: 0; }
}

@media (max-width: 760px) {
  header { gap: 4px; }
  .logo_entre {
    width: 120px;
    max-height: 40px;
    object-fit: contain;
  }
  .auth-controls { position: absolute; top: 2px; right: 8px; font-size: 10px; }
  #address-input { height: 36px; min-height: 36px; font-size: 14px; }
  .search-btn { width: 30px; height: 30px; font-size: 13px; }
}

@media (max-width: 760px) and (max-height: 640px) {
  #stats-panel .stats-chart-center { font-size: 12px; }
  #stats-panel .stats-chart-center span { font-size: 9px; }
}

/* BEGIN mobile toolbar alignment */
@media (max-width: 760px), (max-height: 520px) and (orientation: landscape) {
  #floating-toolbar, #toolbar-toggle-btn { z-index: 10002; }
  #floating-toolbar .tool-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 48px;
    gap: 2px;
  }
  #floating-toolbar .tool-icon { flex: none; margin: 0; }
  #floating-toolbar .tool-label { flex: none; margin: 0; max-width: none; line-height: 12px; }
  #floating-toolbar .nav-button { background-color: #fff; color: #0d3380; opacity: 1; }
}
/* Keep the reopen button blue in every viewport and interaction state. */
#toolbar-toggle-btn,
#toolbar-toggle-btn:hover,
#toolbar-toggle-btn:focus,
#toolbar-toggle-btn:active {
  background: #0d3380 !important;
  color: #fff !important;
  opacity: 1 !important;
  border: 2px solid #fff;
  z-index: 10002;
}
/* END mobile toolbar alignment */
/* Longer campaign headings need additional room on narrow landscape phones. */
@media (max-width: 760px) and (max-height: 520px) and (orientation: landscape) {
  :root { --header-height: 96px; }
}
@media (max-width: 600px) and (max-height: 520px) and (orientation: landscape) {
  :root { --header-height: 128px; }
}

/* BEGIN info panel left */
#info-panel.tool-panel.offcanvas-start {
  left: 0 !important;
  right: auto !important;
  border-left: 0 !important;
  border-right: 1px solid rgba(0, 0, 0, 0.12) !important;
  border-radius: 0 12px 0 0 !important;
  transform: translateX(-100%) !important;
}
#info-panel.tool-panel.offcanvas-start:is(.show,.showing,.is-active) {
  transform: none !important;
}
/* END info panel left */
