/**
 * Harvest — shared two-column page shell (C-LAYOUT).
 *
 * Magento/blank still lays out `.columns` with float-era rules: `.column.main` and
 * `.sidebar-main` get percentage `width` + `float`, `.columns` carries a clearfix
 * `::before/::after`, and blank uses `order` to shuffle the rail. Any page that
 * re-skins `.columns` as a grid MUST neutralise all of that or it renders a
 * collapsed sliver rail, or counts a clearfix box as a grid item.
 *
 * This lives in the COMPONENT kit, not in a page file, on purpose: T4 Category
 * Grid, T5 Category List, search results and every account page share the identical
 * reset. Page-local copies drift — that exact reset bug already hit the sibling
 * themes (Voltage T21 rendered a 227px sliver; Atelier's account pages inherited
 * blank's 48.8% width). One definition, applied via the `.hrv-cols` body hook.
 *
 * USAGE — a page opts in with the body class and sets only its own track sizes:
 *   layout XML : <attribute name="class" value="hrv-cols hrv-page-category"/>
 *   page CSS   : .hrv-page-category .columns { grid-template-columns: 240px 1fr; }
 */

/* Grid shell. Track sizes are the PAGE's business; everything here is the reset. */
.hrv-cols .columns {
  display: grid;
  grid-template-columns: 1fr;   /* single column until a page declares its tracks */
  gap: 28px;
  align-items: start;
}

/* Blank's clearfix boxes would otherwise become phantom grid children. */
.hrv-cols .columns::before,
.hrv-cols .columns::after {
  content: none;
  display: none;
}

/* Defeat blank's float-era sizing so the grid actually governs both tracks.
   `min-width: 0` lets the main column shrink instead of overflowing the page. */
.hrv-cols .column.main,
.hrv-cols .sidebar-main,
.hrv-cols .sidebar-additional {
  width: auto;
  max-width: none;
  float: none;
  padding: 0;
  margin: 0;
  min-width: 0;
  order: 0;   /* blank uses `order` to reposition the rail */
}

/* Rail left, main right. A page that needs the rail on the right overrides
   `grid-column` itself.

   THE ROW IS PINNED, AND THAT IS THE WHOLE POINT OF THIS RULE.
   The previous version set only `grid-column` and justified it with "in source
   order". **THE SOURCE ORDER IS THE OTHER WAY ROUND.** Magento's 2columns-left
   markup emits `.column.main` FIRST and `.sidebar-main` SECOND — blank repositions
   the rail with `order`, which the reset above deliberately zeroes out.

   With only a column named, auto-placement put `.column.main` in row 1 / column 2,
   and then `.sidebar-main` asked for column 1 — which sparse auto-placement will not
   go backwards to reach — so it landed in ROW 2. Measured on
   /olive-oil-vinegar.html: grid-template-rows 1535.61px 408.125px, and the filter
   rail starting 1563px BELOW the main column, underneath the entire product grid,
   with a 240px empty gutter beside the products.

   *** IT SURVIVED BECAUSE EVERY PROBE MEASURED w/h/x AND NOT y. *** The rail
   reported x:32, width:240 — correct horizontally — and read as "correctly placed
   left". Only the raster showed it. Pinning both to row 1 is what makes the declared
   two-column layout actually two columns.

   This reset is shared by T5, search and the account pages, so the fix is not
   category-specific. */
.hrv-cols .sidebar-main { grid-column: 1; grid-row: 1; }
.hrv-cols .column.main  { grid-column: 2; grid-row: 1; }

/* When a category/page has no rail block at all (e.g. a non-anchor category renders
   no layered nav), `.sidebar-main` is absent or empty — collapse to one column so no
   dead track is left. :has() is supported by every browser this theme targets. */
.hrv-cols .columns:not(:has(.sidebar-main:not(:empty))) {
  grid-template-columns: 1fr;
}
.hrv-cols .columns:not(:has(.sidebar-main:not(:empty))) .column.main {
  grid-column: 1;
}

/* Single column on phones — pages may re-declare their own tracks above this. */
@media (max-width: 767px) {
  .hrv-cols .columns {
    grid-template-columns: 1fr;
    gap: 18px;
  }
  /* `grid-row: auto` IS LOAD-BEARING, AND ITS ABSENCE WAS A DEFECT I INTRODUCED.
     Pinning both children to row 1 fixed the desktop rail (see above) and then OVERLAPPED
     them here: at 375 the grid collapses to a single column and this block already forced
     both into column 1, so with row 1 pinned as well they occupied the SAME CELL.
     Measured: grid-template-columns "343px", grid-template-rows "1879.12px" — one track,
     one row — and an overlap test returned true. Restoring auto rows lets them stack, which
     is exactly the behaviour this page had before the desktop fix.
     A FIX THAT REPAIRS ONE VIEWPORT CAN BREAK ANOTHER; the row pin had to be checked at
     every width, not only the one it was written for. */
  .hrv-cols .sidebar-main,
  .hrv-cols .column.main {
    grid-column: 1;
    grid-row: auto;
  }
}
