/* Dedicated narrow-screen overrides.
   Loaded after style.css so these rules win without disturbing desktop. */

@media (max-width: 600px) {
  :root {
    --mobile-side: 8px;
    --mobile-bottom-safe: max(8px, env(safe-area-inset-bottom));
  }

  #topbar {
    display: grid;
    grid-template-columns: auto auto 1fr auto auto;
    grid-template-areas:
      'logo status spacer zones filters'
      'stats stats stats stats stats'
      'search search search search search';
    align-items: center;
    gap: 6px;
    padding: 8px var(--mobile-side) 10px;
  }

  #logo {
    grid-area: logo;
    min-width: 0;
    font-size: 12px;
  }
  #status {
    grid-area: status;
    white-space: nowrap;
  }
  #zones-toggle {
    grid-area: zones;
  }
  #filters-toggle {
    grid-area: filters;
  }
  #stats {
    grid-area: stats;
    margin: 0;
    min-width: 0;
  }
  #search {
    grid-area: search;
    min-width: 0;
    width: 100%;
    height: 42px;
  }
  #zone {
    display: none;
  }

  #stats > div:first-child {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #legend {
    left: var(--mobile-side);
    right: var(--mobile-side);
    bottom: calc(54px + var(--mobile-bottom-safe));
    width: auto;
    min-height: 38px;
    max-height: 42px;
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    scrollbar-width: none;
    padding: 7px 10px;
    gap: 12px;
  }

  #legend::-webkit-scrollbar {
    display: none;
  }
  .legend-item {
    flex: 0 0 auto;
  }

  #lang-switcher {
    left: 50%;
    right: auto;
    bottom: var(--mobile-bottom-safe);
    width: min(280px, calc(100vw - 32px));
    transform: translateX(-50%);
    justify-content: center;
  }

  .lang-btn {
    flex: 1 1 0;
    min-width: 0;
    padding: 7px 5px;
    font-size: 10px;
  }

  .leaflet-top.leaflet-right {
    top: 130px;
  }
  .leaflet-bottom.leaflet-right {
    bottom: calc(108px + var(--mobile-bottom-safe));
  }

  #panel,
  #filters-panel,
  #zones-panel {
    left: var(--mobile-side) !important;
    right: var(--mobile-side) !important;
    bottom: calc(104px + var(--mobile-bottom-safe)) !important;
    max-height: calc(100dvh - 220px);
  }
}

@media (max-width: 380px) {
  #topbar {
    grid-template-columns: auto auto 1fr auto auto;
    gap: 5px;
    padding-inline: 7px;
  }

  #logo {
    font-size: 11px;
    letter-spacing: 0.7px;
  }
  #logo .dot {
    width: 7px;
    height: 7px;
  }
  #status,
  .toolbtn {
    font-size: 9px;
    padding: 5px 6px;
  }
  #stats > div {
    font-size: 9px;
    padding: 4px 7px;
  }
  #stats > div:nth-child(2) {
    display: none;
  }
  #search {
    font-size: 11px;
    padding-inline: 10px;
  }

  #legend {
    font-size: 8.5px;
    gap: 10px;
  }
}

@media (max-height: 700px) and (max-width: 600px) {
  #legend {
    display: none;
  }
  #panel,
  #filters-panel,
  #zones-panel {
    bottom: calc(58px + var(--mobile-bottom-safe)) !important;
    max-height: calc(100dvh - 170px);
  }
}
