/* Shared by the fleet, the detailed navigator and the illustrated map. */
:root {
  --visible-width: 100vw;
  --visible-height: 100vh;
  --visible-height: 100dvh;
  --visible-top: 0px;
  --visible-right: 0px;
  --visible-bottom: 0px;
  --visible-left: 0px;
}
html dialog[open] {
  --edge-gap: 8px;
  --gap-top: max(var(--edge-gap), env(safe-area-inset-top, 0px));
  --gap-right: max(var(--edge-gap), env(safe-area-inset-right, 0px));
  --gap-bottom: max(var(--edge-gap), env(safe-area-inset-bottom, 0px));
  --gap-left: max(var(--edge-gap), env(safe-area-inset-left, 0px));
  box-sizing: border-box;
  position: fixed;
  inset: calc(var(--visible-top) + var(--gap-top)) calc(var(--visible-right) + var(--gap-right))
         calc(var(--visible-bottom) + var(--gap-bottom)) calc(var(--visible-left) + var(--gap-left));
  margin: auto;
  min-width: 0;
  min-height: 0;
  max-width: calc(var(--visible-width) - var(--gap-left) - var(--gap-right));
  max-height: calc(var(--visible-height) - var(--gap-top) - var(--gap-bottom));
  overflow: auto;
  overscroll-behavior: contain;
  scroll-padding: 6px;
  overflow-wrap: anywhere;
}
html dialog[open].chart-dialog {
  --edge-gap: 0px;
  width: var(--visible-width);
  height: var(--visible-height);
}
html dialog[open] :is(button, a, select, input:not([type=radio], [type=checkbox]), fieldset) {
  max-width: 100%;
}
.fleet-app #modal[open],
.detail-navigator #routeDialog[open] {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}
#modal .modalhead,
#routeDialog .dialoghead {
  flex: none;
  margin: 0;
  padding: 10px 16px;
}
#modal .modalhead {
  border-bottom: 1px solid var(--border);
}
#modal .modalhead h2, #routeDialog .dialoghead h2 { min-width: 0; }
#modal .modalhead button, #routeDialog .dialoghead button { flex: none; }
#dialogBody, .route-fields {
  min-width: 0;
  min-height: 0;
  padding: 10px 16px 16px;
  overflow: auto;
  overscroll-behavior: contain;
  scroll-padding: 8px;
}
#dialogBody:has(> .route-fields), #routeDialog #routeForm {
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
}
.route-footer {
  flex: none;
  display: flex;
  padding: 8px 16px;
  background: white;
  border-top: 1px solid #b9cbc3;
}
.route-footer button { width: 100%; min-height: 48px; }
html[data-screen-layout="phone"] #mobile-info[open] { margin-block-start: auto; margin-block-end: 0; }
.fleet-app #sidebar {
  top: var(--visible-top);
  bottom: var(--visible-bottom);
  left: var(--visible-left);
  max-width: var(--visible-width);
  max-height: var(--visible-height);
  overflow-y: auto;
  overscroll-behavior: contain;
}
html[data-screen-layout="phone"] .fleet-app #sidebar {
  width: min(20rem, calc(var(--visible-width) - 44px));
  padding-top: max(16px, env(safe-area-inset-top, 0px));
  padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
}
#closeMenu { display: none; }
html[data-screen-layout="phone"] .drawer-top { display: flex; align-items: flex-start; gap: 4px; }
html[data-screen-layout="phone"] .drawer-top .brand { flex: 1; min-width: 0; padding: 3px 0 14px; overflow-wrap: anywhere; }
html[data-screen-layout="phone"] #closeMenu { display: inline-grid; flex: none; min-width: 44px; min-height: 44px; color: white; border: 1px solid #8ca7a4; }
html[data-screen-layout="phone"] #closeMenu:is(:hover, :focus-visible) { background: #29464b; }
.fleet-app #sidebar > * { flex-shrink: 0; }
.fleet-app #sidebar .sidebody { flex: 1 0 auto; overflow: visible; }
html[data-screen-layout="phone"] .fleet-app .feature {
  height: auto;
}
html[data-screen-layout="phone"] .fleet-app .sourcefoot,
html[data-screen-layout="phone"] .detail-navigator main > footer,
html[data-screen-layout="phone"] .illustrated-map main { padding-bottom: max(16px, env(safe-area-inset-bottom, 0px)); }
.fleet-app .fleet-update, .fleet-app .toast {
  bottom: calc(var(--visible-bottom) + max(12px, env(safe-area-inset-bottom, 0px)));
  max-width: calc(var(--visible-width) - 16px);
}
.fleet-app .fleet-update { flex-wrap: wrap; }

/* With a landscape keyboard there may be space for only one or two controls.
   Give the whole panel one scroll area so everything remains reachable. */
html[data-short-screen] :is(.fleet-app #modal, .detail-navigator #routeDialog)[open] { display: block; overflow: auto; }
html[data-short-screen] :is(#dialogBody, #routeDialog #routeForm, .route-fields) { display: block; overflow: visible; }
html[data-short-screen] :is(.reading-options .reading-done, .chart-dialog .chart-tools) { position: static; }

/* In the expanded phone map the deck selector doubles as the heading. Keep the
   plan and its zoom buttons visible, including at the largest text setting. */
html[data-screen-layout="phone"] .chart-dialog[open] #chartFrame {
  display:grid;
  grid-template-columns:minmax(0,1fr) auto auto;
  grid-template-rows:auto auto minmax(min(100px,25dvh),1fr) auto;
  grid-template-areas:"deck orientation close" "tools tools tools" "map map map" "detail detail detail";
  align-items:stretch;
  height:100%;
  min-height:0;
}
html[data-screen-layout="phone"] .chart-dialog[open] :is(.mapbar,.mapchoices) { display:contents; }
html[data-screen-layout="phone"] .chart-dialog[open] :is(.mapbar h2,.deckstrip,.deck-picker-label) { display:none; }
html[data-screen-layout="phone"] .chart-dialog[open] .easy-deck {
  grid-area:deck;
  display:flex;
  flex-wrap:nowrap;
  min-width:0;
  padding:5px 3px 5px 6px;
  background:transparent;
}
html[data-screen-layout="phone"] .chart-dialog[open] .easy-deck select {
  width:100%;
  min-width:0;
  padding:3px;
  font-size:1rem;
}
html[data-screen-layout="phone"] .chart-dialog[open] #map-orientation { grid-area:orientation; align-self:center; }
html[data-screen-layout="phone"] .chart-dialog[open] :is(.orientation-trigger,.chart-close-action) {
  display:grid;
  place-items:center;
  width:48px;
  min-height:48px;
  margin:5px 3px;
  padding:0;
  gap:0;
  font-size:0;
}
html[data-screen-layout="phone"] .chart-dialog[open] .orientation-trigger span { font-size:1.4rem; }
html[data-screen-layout="phone"] .chart-dialog[open] .chart-close-action { grid-area:close; }
html[data-screen-layout="phone"] .chart-dialog[open] .chart-close-action .ic { width:24px; height:24px; }
html[data-screen-layout="phone"] .chart-dialog[open] .plan-tools { grid-area:tools; position:relative; z-index:6; }
html[data-screen-layout="phone"] .chart-dialog[open] .plan-tools>summary {
  display:list-item;
  min-height:44px;
  padding:4px 12px;
  align-content:center;
  cursor:pointer;
  font-size:.9rem;
}
html[data-screen-layout="phone"] .chart-dialog[open] .plan-tools .chart-tools {
  position:absolute;
  inset:100% 0 auto;
  max-height:52dvh;
  overflow:auto;
  overscroll-behavior:contain;
  background:#f7faf5;
  box-shadow:0 6px 12px #193d4a30;
}
html[data-screen-layout="phone"] .chart-dialog[open] #plot { grid-area:map; min-height:0; height:100%; width:100%; }
html[data-screen-layout="phone"] .chart-dialog[open] #selection {
  grid-area:detail;
  max-height:32dvh;
  min-height:0;
  overflow:auto;
  overscroll-behavior:contain;
}
