/* ============================================
   <xm-grid> — N-column (default 12) layout grid.

   Slotted children are grid items (the <slot> is layout-transparent,
   like xm-chip-group). A child spans N columns by setting the inline
   custom property --xm-col-span on itself; default span is 1.
   Optional --xm-col-start for explicit placement. Gutter via
   gap="…" → --xm-gutter-* (the --s-N-aliased layout tier).

   Below --xm-breakpoint-sm (520px) the grid collapses to a single
   column. NOTE: the 520px literal is repeated in the @media below
   because @media cannot read var(--xm-breakpoint-sm); the token in
   styles/_layout.css is the source of truth (docs/adr/0001).

   BEM block `grid`; modifiers --gap-*. Registered in
   scripts/check-bem.sh STRICT_BLOCKS.
   ============================================ */

.grid {
  display: grid;
  grid-template-columns: repeat(var(--xm-grid-columns, 12), minmax(0, 1fr));
  gap: var(--xm-gutter-md);
  /* Inherited ink so currentColor in slotted content reads on the desk
     surface (AD-13) — also satisfies the --md-sys-* token gate. */
  color: var(--md-sys-color-on-surface);
}

.grid--gap-none { gap: var(--xm-gutter-none); }
.grid--gap-xs   { gap: var(--xm-gutter-xs); }
.grid--gap-sm   { gap: var(--xm-gutter-sm); }
.grid--gap-md   { gap: var(--xm-gutter-md); }
.grid--gap-lg   { gap: var(--xm-gutter-lg); }
.grid--gap-xl   { gap: var(--xm-gutter-xl); }

/* Per-child placement, authored as inline custom properties on the child.
   minmax(0, 1fr) + min-width: 0 keeps a wide / unbreakable child from
   blowing its track out instead of honouring the span. */
.grid ::slotted(*) {
  grid-column: var(--xm-col-start, auto) / span var(--xm-col-span, 1);
  min-width: 0;
}

/* Compact: collapse to one column. The 520px literal mirrors
   --xm-breakpoint-sm (styles/_layout.css); @media can't read the token
   (docs/adr/0001). */
@media (max-width: 520px) {
  .grid {
    grid-template-columns: 1fr;
  }
  .grid ::slotted(*) {
    grid-column: auto;
  }
}
