/* RRAIL R5 gap polish v2 · PRODUCTION R9.
 * Based on R5 weather #r51PanelClosed / #r5Collapse and real RailPublicR18.
 * No changes to native open/close, map size, train data or weather content.
 * 15–16px clearance between map-action dock and open/closed side tab.
 */
@media (min-width: 1060px) {
  /* The R5 weather checkbox can remain unchecked while Trains is selected.
     Its high-specificity #r5Collapse display rule previously left a ghost
     weather arrow at the old 358px edge, even while the rail tab sat at the
     actual viewport edge. Always suppress both weather tabs in train mode. */
  html:has(#r5Panel):has(#r51PanelClosed)
  body[data-railpub-r17="trains"]
  :is(#r5Collapse,#r5Reopen,.r53-edge-handle) {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }

  /* Also release R5's viewport-control translation when weather is not the
     active mode; otherwise the action column can stay ~358px in from right
     even after trains have been closed and their launcher is on the edge. */
  html:has(#r5Panel):has(#r51PanelClosed)
  body[data-railpub-r17="trains"]
  .r59-viewport-map-control {
    translate: none !important;
    transition: none !important;
  }

  /* Weather: right edge tab is ~27px; 42px anchor gives ~15px clear air.
     Keep the existing R5 translation -358px for weather OPEN as-is. */
  html:has(#r5Panel)
  body[data-railpub-r17="off"]
  #app[data-mode="weather"] .map-actions {
    right: 42px !important;
  }

  /* Trains CLOSED: railPubLauncher is 36px wide, so 52px leaves 16px gap.
     Trains OPEN: handle protrudes 27px left of the 358px panel boundary;
     42px inset gives ~15px gap. Move the *group* only, not every button. */
  body[data-railpub-r17="trains"] .map-actions {
    right: 52px !important;
    translate: none !important;
    transition: none !important;
  }
  body[data-railpub-r17="trains"]:has(#railPubR17:not([hidden])) .map-actions {
    right: calc(var(--rrail-r5-width, 358px) + 42px) !important;
  }

  /* Native MapLibre widgets are separate from .map-actions, and are positioned
     relative to #map itself. Keep the same clearance from the rail tabs. */
  body[data-railpub-r17="trains"]
  #map :is(.maplibregl-ctrl-top-right,.maplibregl-ctrl-bottom-right) {
    right: 52px !important;
    translate: none !important;
    transition: none !important;
  }
  body[data-railpub-r17="trains"]:has(#railPubR17:not([hidden]))
  #map :is(.maplibregl-ctrl-top-right,.maplibregl-ctrl-bottom-right) {
    right: 42px !important;
  }
}
/* Mobile and tablet (<1060px): native presentation untouched. */
