/* Opening station details does not change the Layers anchor. */
body { --layers-map-inset: var(--sidebar-width); }
body:not(.results-collapsed), body.filters-open { --layers-map-inset: calc(var(--sidebar-width) + var(--results-width)); }
body[data-map-projection='globe'] #map { background: #000000; }
body #mapLayersDock {
  position: absolute;
  left: calc(var(--layers-map-inset) + 20px) !important;
  right: auto;
  bottom: 20px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  max-width: calc(100vw - var(--layers-map-inset) - 40px);
  z-index: 1800;
}
#mapLayersDock #legendToggle {
  position: relative;
  width: 80px;
  min-width: 80px;
  height: 80px;
  flex: 0 0 80px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 5px;
  padding: 0 6px 9px;
  overflow: hidden;
  border: 1px solid var(--control-border);
  border-radius: 8px;
  background: #000;
  color: #fff;
  box-shadow: 0 2px 6px #0005;
  cursor: pointer;
}
#mapLayersDock #legendToggle::after {
  content: '';
  display: block;
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(32deg,transparent 35%,#292929 36% 39%,transparent 40%), linear-gradient(135deg,transparent 44%,#343434 45% 47%,transparent 48%);
}
#mapLayersDock #legendToggle > span {
  position: relative;
  z-index: 1;
  margin: 0;
  padding: 0;
  transform: none;
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  line-height: 18px;
  text-shadow: 0 1px 2px #000;
}
#mapLayersDock #legendToggle svg {
  position: relative;
  z-index: 1;
  display: block;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  margin: 0;
  transform: none;
  stroke: currentColor;
  fill: none;
}
#layersTray {
  display: grid;
  grid-template-columns: repeat(5, minmax(52px, 1fr));
  align-items: center;
  gap: 4px;
  width: 340px;
  height: 80px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 2px 8px #0004;
}
#mapLayersDock [hidden] { display: none !important; }
#mapLayersDock:has(#mapDetailsPanel:not([hidden])) #legendToggle { visibility: hidden; }
#mapLayersDock .layer-choice {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 5px;
  min-width: 0;
  min-height: 62px;
  padding: 2px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 11px;
  line-height: 15px;
  cursor: pointer;
}
#mapLayersDock .layer-choice:hover { background: var(--panel-2); }
#mapLayersDock .layer-choice[aria-pressed='true'] .layer-preview { outline: 2px solid var(--accent); outline-offset: 2px; }
#mapLayersDock button:focus-visible, #mapLegendHeading:focus-visible { outline: 2px solid var(--control-border); outline-offset: 3px; }
.layer-preview {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 44px;
  height: 44px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
  background-color: var(--panel-2);
}
.preview-dark, .preview-light, .preview-bright, .preview-liberty, .preview-fiord, .preview-3d {
  background-image: linear-gradient(34deg, transparent 35%, var(--preview-road) 36% 42%, transparent 43%), linear-gradient(132deg, transparent 41%, var(--preview-road) 42% 47%, transparent 48%), linear-gradient(90deg, transparent 65%, var(--preview-water) 66%);
}
.preview-dark { background-color: #16181c; --preview-road: #84919d; --preview-water: #334a54; }
.preview-light { background-color: #e9edee; --preview-road: #fff; --preview-water: #c5dfe6; }
.preview-bright { background-color: #f0ead5; --preview-road: #efbd59; --preview-water: #aed9e8; }
.preview-liberty { background-color: #cae4c6; --preview-road: #fff; --preview-water: #9edce8; }
.preview-fiord { background-color: #293a4d; --preview-road: #7d96ad; --preview-water: #152638; }
.preview-3d { background-color: #cde3c8; --preview-road: #fff; --preview-water: #9edce8; }
.preview-3d::after { content: ''; width: 12px; height: 20px; background: #708b9f; border-top: 4px solid #b7c7d3; box-shadow: 12px 8px #8fa4b4, -10px 6px #536e83; transform: skewY(-18deg); }
.preview-legend i { width: 8px; height: 8px; border-radius: 50%; background: #ff3a3a; }
.preview-legend i:nth-child(2) { background: #a0a0a0; }
.preview-legend i:nth-child(3) { background: #50c88c; }
.layer-preview svg { width: 24px; height: 24px; stroke: currentColor; stroke-width: 1.6; fill: none; }
#mapDetailsPanel {
  position: absolute;
  z-index: 2;
  bottom: 0;
  left: 0;
  right: auto;
  width: 268px;
  max-width: calc(100vw - var(--layers-map-inset) - 40px);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 4px 16px #0005;
}
#mapLayersDock #legendPanel {
  position: static;
  display: block;
  width: auto;
  max-width: none;
  height: auto;
  max-height: none;
  padding: 16px 20px 20px;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  overflow: visible;
  background: var(--panel);
}
#mapLayersDock .explorer-legend-head {
  position: sticky;
  top: -1px;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: -16px -20px 12px;
  padding: 12px 16px 8px 20px;
  background: var(--panel);
}
#mapLayersDock .explorer-legend-head h3 { margin: 0; font-size: 14px; font-weight: 600; }
#mapLayersDock .explorer-legend-head button { width: 32px; height: 32px; padding: 0; border: 0; font-size: 22px; background: transparent; }
#mapLayersDock h4 { margin: 0 0 14px; font-size: 12px; font-weight: 600; }
.layer-details-section { padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.layer-style-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 10px; }
.layer-tools-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
#mapLayersDock .globe-overview { width: 100%; min-height: 44px; margin: 0 0 12px; }
#mapLayersDock .map-legend-disclosure { border: 0; padding: 0; margin: 0; }
#mapLayersDock .map-legend-disclosure > summary { cursor: pointer; min-height: 44px; padding: 6px 20px 6px 0; font-size: 12px; line-height: 1.5; }
#mapLayersDock .map-legend-disclosure > summary strong { font-weight: 600; }
#mapLayersDock .map-legend-disclosure > summary span { display: block; color: var(--muted); font-size: 11px; margin-left: 14px; }
#mapLayersDock .map-legend-body { padding-top: 14px; }
#mapLayersDock .explorer-legend-status, #mapLayersDock .explorer-legend-prices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 8px; font-size: 11px; line-height: 16px; }
#mapLayersDock .explorer-legend-status > span, #mapLayersDock .explorer-legend-prices > span { display: flex; align-items: center; gap: 7px; }
#mapLayersDock .explorer-legend-status { padding-bottom: 16px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
#mapLayersDock .legend-new-badge { font-size: 10px; padding: 2px 5px; background: var(--accent); color: var(--bg); border-radius: 4px; }
#mapLayersDock #legendPriceNote { font-size: 11px; line-height: 16px; margin: 8px 0 12px; }
#mapLayersDock #legendCurrency { margin: 0 0 12px; min-height: 32px; padding: 7px 10px; font-size: 11px; color: var(--text); background: var(--panel); border: 1px solid var(--control-border); border-radius: 6px; }
#mapLayersDock #legendPriceRows[hidden] { display: none; }
#mapLayersDock .legend-price-heading { margin: 0; padding: 0; border: 0; }

@media (min-width: 821px) and (max-width: 1020px) {
  #layersTray { position: absolute; left: 0; bottom: 90px; width: min(340px, calc(100vw - var(--layers-map-inset) - 40px)); }
}
@media (min-width: 821px) {
  /* The station sheet covers Layers without changing its left-side anchor. */
  body #mapLayersDock { z-index: 1400; }
}
@media (max-width: 820px) {
  body { --layers-map-inset: 0px !important; }
  body #mapLayersDock { left: 0 !important; right: auto; bottom: var(--mobile-sheet-bottom); max-width: 100vw; z-index: 2700; }
  #layersTray { display: none; }
  #mapDetailsPanel {
    position: fixed;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: var(--mobile-sheet-bottom);
    width: auto;
    max-width: none;
    max-height: var(--mobile-sheet-max);
  }
  #mapLayersDock .layer-choice { min-height: 72px; font-size: 12px; }
  #mapLayersDock .explorer-legend-head button { width: 44px; height: 44px; }
  #mapLayersDock .explorer-legend-status, #mapLayersDock .explorer-legend-prices { font-size: 12px; }
}

/* Menu and scrim are body siblings so the fixed map shell cannot trap them
   underneath the sidebar's stacking context. */
.app-menu-drawer > p { margin: 0; padding: 14px 20px; display: flex; gap: 8px; flex-wrap: wrap; }
body.app-menu-open .app-menu-drawer { z-index: 4000; }
body.app-menu-open .app-menu-scrim { z-index: 3950; }
@media (prefers-reduced-motion: reduce) {
  .app-menu-drawer, .app-menu-scrim { transition: none; }
}

@media (min-width:821px) and (pointer:coarse) {
  #mapDetailsPanel { width:340px; }
  #mapLayersDock .layer-choice { min-width:48px; min-height:76px; font-size:12px; }
  #mapLayersDock .explorer-legend-head button { width:48px; height:48px; flex-shrink:0; }
  #mapLayersDock #legendCurrency { min-height:48px; }
  #mapLayersDock .globe-overview, #mapLayersDock .map-legend-disclosure > summary { min-height:48px; }
}
