/**
 * layout.css — structural scaffolding for the Jouman theme.
 *
 * Containers, the main wrapper, grid helpers, stack/flow utilities and the
 * section spacing scale. Structure only: no colour beyond what a wrapper
 * genuinely needs, no component styling (see components.css).
 *
 * RTL: every directional value uses a logical property (margin-inline,
 * padding-inline, inset-inline-*, border-inline-*, text-align: start/end).
 * There is no `left` or `right` anywhere in this file, which is precisely why
 * the theme needs no rtl.css and no `direction` declaration.
 *
 * Mobile-first only. Breakpoints: sm 480 / md 768 / lg 1024 / xl 1280.
 */

/* ---------------------------------------------------------------------------
 * 1. Containers
 * ------------------------------------------------------------------------- */

.jm-container {
  inline-size: 100%;
  max-inline-size: var(--jm-container);
  margin-inline: auto;
  padding-inline: var(--jm-space-4);
}

@media (min-width: 768px) {
  .jm-container {
    padding-inline: var(--jm-space-6);
  }
}

/*
 * Deliberately does NOT keep growing past md. The container is already capped by
 * max-inline-size, so extra inline padding on wide screens only narrows the
 * content further and reads as an oversized gutter.
 */

.jm-container--narrow {
  max-inline-size: var(--jm-container-narrow);
}

/* Full-bleed row that still aligns its inner content to the container. */
.jm-container--flush {
  padding-inline: 0;
}

/* ---------------------------------------------------------------------------
 * 2. Main wrapper + vertical rhythm
 * ------------------------------------------------------------------------- */

.jm-main {
  display: block;
  padding-block: var(--jm-space-6);
}

@media (min-width: 768px) {
  .jm-main {
    padding-block: var(--jm-space-7);
  }
}

@media (min-width: 1024px) {
  .jm-main {
    padding-block-start: var(--jm-space-7);
    padding-block-end: var(--jm-space-8);
  }
}

/* Direct children of .jm-main are separated by gap, never by margins. */
.jm-main > * + * {
  margin-block-start: var(--jm-space-6);
}

/* ---------------------------------------------------------------------------
 * 3. Section spacing scale
 * ------------------------------------------------------------------------- */

.jm-section {
  padding-block: var(--jm-space-6);
}

.jm-section--tight {
  padding-block: var(--jm-space-5);
}

.jm-section--loose {
  padding-block: var(--jm-space-7);
}

.jm-section--flush {
  padding-block: 0;
}

@media (min-width: 768px) {
  .jm-section        { padding-block: var(--jm-space-7); }
  .jm-section--tight { padding-block: var(--jm-space-6); }
  .jm-section--loose { padding-block: var(--jm-space-8); }
  .jm-section--flush { padding-block: 0; }
}

@media (min-width: 1024px) {
  .jm-section--loose { padding-block: var(--jm-space-9); }
}

/* Optional hairline between stacked sections. */
.jm-section--ruled + .jm-section--ruled {
  border-block-start: 1px solid var(--jm-color-line-soft);
}

.jm-section__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--jm-space-3);
  margin-block-end: var(--jm-space-5);
  text-align: start;
}

/* ---------------------------------------------------------------------------
 * 4. Grid helpers
 *
 * `.jm-grid` alone is a single column. The numbered modifiers describe the
 * DESKTOP target; they collapse responsively, mobile-first.
 *
 * `.jm-grid--2` is also the product-grid shape: 2 columns from the smallest
 * viewport upward, because fashion shoppers scan pairs of garments on mobile.
 * ------------------------------------------------------------------------- */

.jm-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--jm-space-5);
}

.jm-grid--gap-sm { gap: var(--jm-space-3); }
.jm-grid--gap-lg { gap: var(--jm-space-6); }

/* Two-up: two columns everywhere. */
.jm-grid--2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* Three-up: 2 on mobile, 3 from md. */
.jm-grid--3 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* Four-up (the product grid): 2 on mobile, 3 at md, 4 at lg. */
.jm-grid--4 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (min-width: 768px) {
  .jm-grid--3,
  .jm-grid--4 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .jm-grid--4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* Item span helpers. */
.jm-grid__span-2 { grid-column: span 2; }
.jm-grid__span-full { grid-column: 1 / -1; }

/* ---------------------------------------------------------------------------
 * 5. Sidebar / content split (archive filters, account pages)
 * ------------------------------------------------------------------------- */

.jm-split {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--jm-space-6);
}

@media (min-width: 1024px) {
  .jm-split {
    grid-template-columns: minmax(0, 16rem) minmax(0, 1fr);
    gap: var(--jm-space-7);
    align-items: start;
  }

  /* Media/detail split, e.g. product gallery beside summary. */
  .jm-split--media {
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  }
}

/* ---------------------------------------------------------------------------
 * 6. Flow / stack / cluster utilities — gap, never margins
 * ------------------------------------------------------------------------- */

.jm-stack {
  display: flex;
  flex-direction: column;
  gap: var(--jm-space-4);
}

.jm-stack--1 { gap: var(--jm-space-1); }
.jm-stack--2 { gap: var(--jm-space-2); }
.jm-stack--3 { gap: var(--jm-space-3); }
.jm-stack--5 { gap: var(--jm-space-5); }
.jm-stack--6 { gap: var(--jm-space-6); }
.jm-stack--7 { gap: var(--jm-space-7); }

/* Horizontal group that wraps. */
.jm-cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--jm-space-3);
}

.jm-cluster--2 { gap: var(--jm-space-2); }
.jm-cluster--5 { gap: var(--jm-space-5); }
.jm-cluster--between { justify-content: space-between; }
.jm-cluster--end { justify-content: flex-end; }
.jm-cluster--center { justify-content: center; }
.jm-cluster--top { align-items: flex-start; }

/* Pushes the following sibling to the far inline edge in a flex row. */
.jm-push-end {
  margin-inline-start: auto;
}

/* Horizontal scroller for mobile carousels. */
.jm-rail {
  display: flex;
  gap: var(--jm-space-4);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding-block-end: var(--jm-space-2);
  -webkit-overflow-scrolling: touch;
}

.jm-rail > * {
  flex: 0 0 auto;
  scroll-snap-align: start;
  inline-size: 66%;
  max-inline-size: 20rem;
}

@media (min-width: 768px) {
  .jm-rail > * {
    inline-size: 33%;
  }
}

/* ---------------------------------------------------------------------------
 * 7. Small structural utilities
 * ------------------------------------------------------------------------- */

.jm-measure {
  max-inline-size: 68ch;
}

.jm-center {
  margin-inline: auto;
}

.jm-text-start  { text-align: start; }
.jm-text-end    { text-align: end; }
.jm-text-center { text-align: center; }

.jm-hidden { display: none; }

/* Narrow-only element: hidden from md upward. */
@media (min-width: 768px) {
  .jm-hidden-md-up { display: none; }
}

/* Wide-only element: hidden by default, revealed from md upward.
 * Expressed this way (rather than a max-width query) to keep the file
 * strictly mobile-first. */
.jm-md-up-only { display: none; }

@media (min-width: 768px) {
  .jm-md-up-only { display: block; }
  .jm-md-up-only.jm-cluster,
  .jm-md-up-only.jm-rail { display: flex; }
  .jm-md-up-only.jm-grid { display: grid; }
}

.jm-full-bleed {
  inline-size: 100%;
  max-inline-size: none;
}

.jm-aspect-portrait {
  aspect-ratio: 3 / 4;
  overflow: hidden;
}

.jm-aspect-square {
  aspect-ratio: 1 / 1;
  overflow: hidden;
}

/* Images that must fill a fixed-ratio box without shifting layout. */
.jm-aspect-portrait > img,
.jm-aspect-square > img {
  inline-size: 100%;
  block-size: 100%;
  object-fit: cover;
}
