/* iw.chips_css
   Mapped from tot_map.chips_css (see /workspace/iw/chips_up/NOTE_M119.md
   and /workspace/tot-web/chips-up/files/tot-map-chips.css).
   Overflow filter chips stack AWAY from the map. The first full row
   (starting with All) sits against the map.

   Default layout: .im-cats is above .im-canvas, so the chip bar is
   ABOVE the map. flex-wrap: wrap-reverse puts the first flex line at
   the bottom of the bar, next to the map. Later lines (overflow chips)
   stack upward.

   Selectors mapped from ToT:
     #totmap -> #iwmap, #lhmap, #iwplan
     .tm-bar.tm-cats / .tm-cats-scroll -> .im-bar.im-cats
     .tm-fit -> .im-fit
     .tm-full.tm-showf -> .im-full.im-showf
   #lhmap .im-bar.im-flt2 is an IW-only second chip row (status) that
   also sits above the map, so it gets the same wrap-reverse.

   On ToT, .tm-fit is a grid sibling of the chip bar; align-self: end
   keeps it on the map-adjacent row on viewports wider than 640px.
   On IW, the engine moves button.im-fit into .im-cats (order:99,
   margin-left:auto) when the viewport is wider than 640px, and into
   .im-fitbar under the map on smaller screens. order:99 would send
   the button to the last flex line, which wrap-reverse draws at the
   top, away from the map. The rules below pin it to the bottom-right
   of the chip bar (map-adjacent) and reserve space so chips do not
   overlap it. On phones, :has(> button.im-fit) is false because the
   button lives in .im-fitbar, so those rules do not apply.

   The rule flips when the chip bar is BELOW the map:
     1) fullscreen filter sheet (#iwmap.im-full.im-showf > .im-cats
        is position:absolute; bottom:0)
     2) a defensive sibling hook if .im-cats is moved after .im-canvas
        in the DOM
   In those cases use normal wrap so the main row is at the top of the
   bar, nearest the map.

   Touch targets, typography, colors, and gaps are unchanged.
   Dynamic count updates (display:none when a chip's in-view count is
   0) still apply; wrap-reverse just reflows the remaining chips.
   Scoped with html #iwmap / #lhmap / #iwplan and !important so this
   file wins whether it loads before or after the engine style tags.
*/

/* Chip bar is above the map: overflow stacks up. */
html #iwmap .im-bar.im-cats,
html #lhmap .im-bar.im-cats,
html #lhmap .im-bar.im-flt2,
html #iwplan .im-cats{
  flex-wrap:wrap-reverse!important;
}

/* Desktop: keep "Show the whole waterway" on the map-adjacent row. */
html #iwmap > .im-fit,
html #lhmap > .im-fit,
html #iwplan > .im-fit{
  align-self:end!important;
}

/* IW difference: .im-fit is a flex item of .im-cats on desktop.
   Pin it to the bottom-right (the map-adjacent edge under
   wrap-reverse) and reserve space so the last chip does not overlap. */
html #iwmap .im-cats:has(> button.im-fit),
html #lhmap .im-cats:has(> button.im-fit),
html #iwplan .im-cats:has(> button.im-fit){
  position:relative;
  padding-right:188px;
}
html #iwmap .im-cats > button.im-fit,
html #lhmap .im-cats > button.im-fit,
html #iwplan .im-cats > button.im-fit{
  position:absolute;
  right:0;
  bottom:0;
  margin-left:0!important;
  order:0!important;
}

/* Fullscreen filter sheet sits on the bottom edge of the map, so
   the main row must be at the TOP of the sheet. Do not pin .im-fit
   to the bottom of the sheet. #lhmap .im-flt2 in fullscreen is a
   top bar (nearest the map at its bottom edge), so it keeps
   wrap-reverse and is not listed here. */
html #iwmap.im-full.im-showf > .im-cats,
html #lhmap.im-full.im-showf > .im-cats,
html #iwplan.im-full.im-showf > .im-cats{
  flex-wrap:wrap!important;
  padding-right:0;
}
html #iwmap.im-full.im-showf .im-cats > button.im-fit,
html #lhmap.im-full.im-showf .im-cats > button.im-fit,
html #iwplan.im-full.im-showf .im-cats > button.im-fit{
  position:static;
  margin-left:auto!important;
  order:99!important;
}

/* If a page ever moves the chip bar below the canvas in the DOM,
   use normal wrap so the main row stays nearest the map. */
html #iwmap > .im-canvas ~ .im-cats,
html #lhmap > .im-canvas ~ .im-cats,
html #iwplan > .im-canvas ~ .im-cats{
  flex-wrap:wrap!important;
}
