/**
 * Shared left-edge map tab stack (Layers + Live Leaderboard + Top Reports).
 * Positions refined at runtime by wxmap-left-edge-tabs.js — these rules set
 * defaults + touch targets so tabs never share the mid-left top:50% slot.
 * v10: open legend hides/clamps @WxMatt2; credit z below Legend chip.
 * v11: stack @WxMatt2 ABOVE Legend chip at left edge (not to the right).
 * v12: when Layers is just above the chip, credit stacks above Layers.
 * v13: embedded snow note clears zoom + parent Top Weather (JS layout).
 * v14: Live board short label + taller vertical tab (no clipped glyphs).
 * v18: coordinate with snow phone zoom-below-header (#748 top overlap).
 */
:root {
  --wxmap-left-tab-inset: calc(6px + env(safe-area-inset-left, 0px));
  --wxmap-left-tab-gap: 10px;
  --wxmap-left-tab-min: 44px;
  --wxmap-zoom-past-tabs-left: calc(52px + env(safe-area-inset-left, 0px));
}

#mapLiveLeaderboardFloat.map-liveleaderboard-float,
.map-liveleaderboard-float#mapLiveLeaderboardFloat {
  min-height: 96px;
  min-width: 36px;
  width: auto;
  height: auto;
  padding: 12px 7px;
  font-size: 11px;
  line-height: 1.15;
  letter-spacing: 0.4px;
  white-space: nowrap;
  overflow: visible;
  box-sizing: border-box;
}

body.wxmap-layers-dock-left #mapLegendFloat.map-legend-float,
body.wxmap-layers-dock-left .map-legend-float#mapLegendFloat {
  min-height: var(--wxmap-left-tab-min);
  min-width: var(--wxmap-left-tab-min);
  box-sizing: border-box;
  background: #0d9488 !important;
  border-radius: 0 8px 8px 0 !important;
}

/* Phone portrait OR phone landscape (short height): left-edge stack.
   JS sets --wxmap-*-top / flips Layers right when vertical room is gone. */
@media (max-width: 768px), (max-height: 520px) {
  /* +/- clear of left Top Reports / Live Leaderboard strip (JS may refine). */
  body:has(#mapTopReportsFloat) .leaflet-control-zoom,
  body:has(#mapLiveLeaderboardFloat) .leaflet-control-zoom,
  body.reports-on-left .leaflet-control-zoom {
    left: var(--wxmap-zoom-past-tabs-left) !important;
    right: auto !important;
  }

  /* Legend chip vs @WxMatt2 — stack credit ABOVE the chip at the left edge.
     z-index below legend shell/chip so the credit never steals Legend taps.
     JS (clearLegendVsAttribution) refines bottom and hides only on collision. */
  body:has(.wxmap-legend-shell) #wx-attribution-link.wx-attribution,
  body:has(.wxmap-legend-shell) a.wx-attribution,
  body:has(#rain-legend-shell) #wx-attribution-link.wx-attribution,
  body:has(#wind-legend-shell) #wx-attribution-link.wx-attribution,
  body:has(#hail-legend-shell) #wx-attribution-link.wx-attribution,
  body:has(#snow-legend-shell) #wx-attribution-link.wx-attribution {
    left: max(8px, calc(8px + env(safe-area-inset-left, 0px))) !important;
    right: auto !important;
    /* Closed chip ~36px + 8px gap above shell bottom clearance. */
    bottom: calc(
      var(--wxmap-map-bottom-clearance, calc(72px + env(safe-area-inset-bottom, 0px)))
      + 52px
    ) !important;
    z-index: 100100 !important;
    max-width: min(160px, calc(100vw - 24px - env(safe-area-inset-right, 0px))) !important;
  }

  #mapLiveLeaderboardFloat,
  .map-liveleaderboard-float {
    left: var(--wxmap-left-tab-inset) !important;
    right: auto !important;
    transform: none !important;
    border-radius: 0 8px 8px 0 !important;
    /* Fallback under zoom; JS overwrites with --wxmap-live-lb-top when set */
    top: var(
      --wxmap-live-lb-top,
      max(168px, calc(var(--wxmap-map-chrome-top, 0px) + 156px))
    ) !important;
    bottom: auto !important;
    z-index: 10045 !important;
  }

  body.wxmap-layers-dock-left #mapLegendFloat.map-legend-float,
  body.wxmap-layers-dock-left .map-legend-float#mapLegendFloat {
    left: var(--wxmap-left-tab-inset) !important;
    right: auto !important;
    transform: none !important;
    top: var(--wxmap-layers-tab-top, auto) !important;
    bottom: var(
      --wxmap-layers-tab-bottom,
      calc(var(--wxmap-map-bottom-clearance, 88px) + 96px)
    ) !important;
    z-index: 10050 !important;
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  body.wxmap-layers-dock-left .map-legend-panel {
    left: -280px !important;
    right: auto !important;
    top: var(--wxmap-layers-panel-top, auto) !important;
    bottom: var(
      --wxmap-layers-panel-bottom,
      calc(var(--wxmap-map-bottom-clearance, 88px) + 96px)
    ) !important;
    width: min(260px, 88vw) !important;
    max-height: min(45vh, 220px) !important;
    height: auto !important;
    transform: none !important;
    transition: left 0.25s ease !important;
  }

  body.wxmap-layers-dock-left .map-legend-panel.open {
    left: 0 !important;
    transform: none !important;
  }

  /* Short / landscape: if JS flips Layers to the right edge */
  body.wxmap-layers-dock-left.wxmap-layers-tab-right #mapLegendFloat.map-legend-float,
  body.wxmap-layers-dock-left.wxmap-layers-tab-right .map-legend-float#mapLegendFloat {
    left: auto !important;
    right: calc(3px + env(safe-area-inset-right, 0px)) !important;
    border-radius: 8px 0 0 8px !important;
  }

  body.wxmap-layers-dock-left.wxmap-layers-tab-right .map-legend-panel {
    left: auto !important;
    right: -100% !important;
    top: 0 !important;
    bottom: 0 !important;
    max-height: 100vh !important;
    height: 100% !important;
  }

  body.wxmap-layers-dock-left.wxmap-layers-tab-right .map-legend-panel.open {
    right: 0 !important;
    left: auto !important;
  }

  /*
    Matt #748 S3: snow phone Legend|Layers pill row — open Layers is a short
    scrollable card above the pills, not a full-height right drawer.
  */
  @media (max-width: 700px) {
    /* Closed: stay off-canvas (do not force right:8px on the dormant panel). */
    body.snow-map-ui.wxmap-layers-dock-left.wxmap-layers-tab-right .map-legend-panel,
    body.snow-map-ui.wxmap-snow-pill-row .map-legend-panel,
    body.wxmap-snow-live.wxmap-snow-pill-row .map-legend-panel {
      top: auto !important;
      bottom: calc(
        var(--wxmap-pill-bottom, calc(72px + env(safe-area-inset-bottom, 0px) + 36px))
        + var(--wxmap-pill-height, 34px)
        + 8px
      ) !important;
      left: auto !important;
      right: -110% !important;
      width: min(260px, calc(100vw - 20px)) !important;
      max-height: min(36vh, 220px) !important;
      height: auto !important;
      overflow: auto !important;
      -webkit-overflow-scrolling: touch !important;
      transform: none !important;
      border-radius: 10px !important;
    }
    body.snow-map-ui.wxmap-layers-dock-left.wxmap-layers-tab-right .map-legend-panel.open,
    body.snow-map-ui.wxmap-snow-pill-row .map-legend-panel.open,
    body.wxmap-snow-live.wxmap-snow-pill-row .map-legend-panel.open {
      right: max(8px, env(safe-area-inset-right, 0px)) !important;
      left: auto !important;
      display: flex !important;
      flex-direction: column !important;
    }
    body.snow-map-ui.wxmap-snow-pill-row .map-legend-panel .panel-content,
    body.snow-map-ui.wxmap-snow-pill-row .map-legend-panel #mapLegendPanelContent,
    body.snow-map-ui.wxmap-layers-dock-left.wxmap-layers-tab-right .map-legend-panel .panel-content,
    body.snow-map-ui.wxmap-layers-dock-left.wxmap-layers-tab-right .map-legend-panel #mapLegendPanelContent {
      flex: 1 1 auto !important;
      min-height: 0 !important;
      overflow-y: auto !important;
      -webkit-overflow-scrolling: touch !important;
    }
  }
}

@media (min-width: 769px) {
  body.wxmap-layers-dock-left #mapLiveLeaderboardFloat {
    left: var(--wxmap-left-tab-inset) !important;
    right: auto !important;
    top: var(--wxmap-live-lb-top, 250px) !important;
    bottom: auto !important;
    transform: none !important;
    border-radius: 0 8px 8px 0 !important;
    z-index: 10045 !important;
  }

  body.wxmap-layers-dock-left #mapLegendFloat.map-legend-float {
    left: var(--wxmap-left-tab-inset) !important;
    right: auto !important;
    top: var(--wxmap-layers-tab-top, auto) !important;
    bottom: var(--wxmap-layers-tab-bottom, 140px) !important;
    transform: none !important;
    border-radius: 0 8px 8px 0 !important;
    background: #0d9488 !important;
    z-index: 10050 !important;
  }
}

/* Embedded /maps: keep Live Leaderboard visible (do not display:none). */
html.wxmap-embedded #mapLiveLeaderboardFloat,
html.wxmap-embedded .map-liveleaderboard-float {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
}
