/* Unified desktop right rail. */
:root {
  --right-rail-width: 220px;
  --right-rail-gap: 14px;
  --right-rail-edge: 20px;
}

.overview-panel,
.overlay-panel,
.legend-panel,
.layer-panel {
  right: var(--right-rail-edge);
  width: var(--right-rail-width);
}

.overview-panel {
  top: 20px;
}

.overlay-panel {
  top: 222px;
}

/* PM2.5 colour scale moves from the left to the right rail. */
.legend-panel {
  left: auto;
  bottom: 98px;
}

.layer-panel {
  bottom: 20px;
}

/* Leave room for the expanded Current layer card. */
.app-container.layer-expanded .legend-panel {
  bottom: 222px;
}

/* Compact the middle card while metadata is expanded so the right rail remains
   a single non-overlapping column on ordinary laptop-height screens. */
.app-container.layer-expanded .overlay-panel {
  top: 188px;
  padding: 10px 13px;
}

.app-container.layer-expanded .overlay-panel h2 {
  margin-bottom: 5px;
}

.app-container.layer-expanded .overlay-panel label {
  padding: 3px 0;
}

@media (max-width: 760px) {
  :root {
    --right-rail-width: 190px;
    --right-rail-edge: 10px;
  }

  .overview-panel,
  .overlay-panel,
  .legend-panel {
    right: var(--right-rail-edge);
    width: var(--right-rail-width);
  }

  .overview-panel { top: 10px; }
  .overlay-panel { top: 205px; }
  .legend-panel {
    left: auto;
    bottom: 78px;
  }

  /* Current layer remains full-width on phones for readable metadata. */
  .layer-panel {
    right: 10px;
    width: calc(100% - 20px);
    bottom: 10px;
  }

  .app-container.layer-expanded .legend-panel {
    bottom: 205px;
  }
}

@media (max-width: 410px) {
  :root { --right-rail-width: 150px; }
  .overview-panel,
  .overlay-panel,
  .legend-panel {
    left: auto;
    right: 10px;
    width: var(--right-rail-width);
  }
}

/* Mobile bottom sheet: the information rail becomes one pull-up drawer and
   the Leaflet viewport ends above it, so controls and popups stay visible. */
.mobile-info-sheet { display: none; }

@media (max-width: 760px) {
  .app-container {
    --mobile-sheet-height: 72px;
  }

  .app-container.mobile-sheet-open {
    --mobile-sheet-height: min(54vh, 430px);
  }

  #map {
    bottom: var(--mobile-sheet-height);
    transition: bottom .28s cubic-bezier(.2,.8,.2,1);
  }

  .mobile-info-sheet {
    display: block;
    position: absolute;
    z-index: 1450;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--mobile-sheet-height);
    background: rgba(255,255,255,.97);
    border: 1px solid var(--border);
    border-bottom: 0;
    border-radius: 22px 22px 0 0;
    box-shadow: 0 -12px 36px rgba(45,27,27,.20);
    backdrop-filter: blur(18px);
    overflow: hidden;
    transition: height .28s cubic-bezier(.2,.8,.2,1);
  }

  .mobile-sheet-toggle {
    position: relative;
    width: 100%;
    height: 72px;
    padding: 18px 18px 10px;
    border: 0;
    background: transparent;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-align: left;
    cursor: pointer;
  }

  .mobile-sheet-handle {
    position: absolute;
    top: 8px;
    left: 50%;
    width: 42px;
    height: 5px;
    border-radius: 999px;
    background: #cdbfc3;
    transform: translateX(-50%);
  }

  .mobile-sheet-toggle > span:nth-child(2) { display: flex; flex-direction: column; gap: 1px; }
  .mobile-sheet-toggle b { color: var(--primary); font-size: 14px; }
  .mobile-sheet-toggle small { color: var(--muted); font-size: 10px; }
  .mobile-sheet-toggle i { color: var(--primary); font-style: normal; transition: transform .25s; }
  .mobile-info-sheet:not(.is-collapsed) .mobile-sheet-toggle i { transform: rotate(180deg); }

  .mobile-sheet-body {
    height: calc(100% - 72px);
    overflow: auto;
    overscroll-behavior: contain;
    padding: 0 12px max(18px, env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .mobile-sheet-body .floating-panel {
    position: relative;
    inset: auto;
    width: 100%;
    padding: 13px;
    border-radius: 15px;
    box-shadow: 0 4px 14px rgba(139,21,56,.10);
  }

  .mobile-sheet-body .layer-panel { order: 1; padding: 0; }
  .mobile-sheet-body .overview-panel { order: 2; }
  .mobile-sheet-body .overlay-panel { order: 3; }
  .mobile-sheet-body .legend-panel { order: 4; }
  .mobile-sheet-body .legend-panel .color-bar { height: 11px; }

  .research-note { display: none; }
  .leaflet-control-attribution { margin-bottom: 2px !important; }
}
