/**
 * ST-ARTICLE-TILE-GRID-RESTORE – Nur Kachel-Raster (Geräte/Spalten/Solo-Kachel).
 * Keine anderen Styles. !important + weight 500 = gewinnt gegen st-homepage/st-startseite-teaser.
 * Sicherung: st-article-tile-grid.css.fixed (1:1-Kopie bei Regression)
 * Spec: .cursor/rules/article-tile-grid-css.mdc · scripts/check-article-tile-grid-css.sh
 */

.st-category-rows:has(> article.category-card),
#sidebar-box-main #st-homepage-grid,
.category-articles__grid {
  display: grid !important;
  gap: var(--st-space-20);
  grid-template-columns: minmax(0, 1fr) !important;
  align-items: stretch;
  container-type: inline-size;
  container-name: st-article-tile-grid;
}

.st-category-rows > .st-category-row--lead {
  grid-column: 1 / -1 !important;
}

/*
 * Geräte-Raster (freigegeben 2026-06). Nicht per JS laden.
 * Handy 1/2 · Tablet 2/3 · Desktop 3 (schmal 2) · Solo-Kachel nur letzte unvollständige Zeile.
 */
/* ── Handy hoch: 1 Spalte ── */
@media (max-width: 767px) and (orientation: portrait) {
  .st-category-rows:has(> article.category-card),
  #sidebar-box-main #st-homepage-grid,
  .category-articles__grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .st-category-row__articles-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}

/* ── Handy quer: 2 Spalten, letzte Solo-Kachel volle Breite ── */
@media (max-width: 932px) and (orientation: landscape) and (max-height: 500px) {
  .st-category-rows:has(> article.category-card),
  #sidebar-box-main #st-homepage-grid,
  .category-articles__grid,
  .st-category-row__articles-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .st-category-rows:has(> article.category-card) > article.category-card:last-child:nth-child(odd):not(:only-child),
  #sidebar-box-main #st-homepage-grid > li:last-child:nth-child(odd):not(:only-child),
  .category-articles__grid > article.category-card:last-child:nth-child(odd):not(:only-child) {
    grid-column: 1 / -1 !important;
  }
}

/* ── Tablet hoch: 2 Spalten, letzte Solo-Kachel volle Breite ── */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
  .st-category-rows:has(> article.category-card),
  #sidebar-box-main #st-homepage-grid,
  .category-articles__grid,
  .st-category-row__articles-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .st-category-rows:has(> article.category-card) > article.category-card:last-child:nth-child(odd):not(:only-child),
  #sidebar-box-main #st-homepage-grid > li:last-child:nth-child(odd):not(:only-child),
  .category-articles__grid > article.category-card:last-child:nth-child(odd):not(:only-child) {
    grid-column: 1 / -1 !important;
  }
}

/* ── Tablet quer: 3 Spalten (3 Kacheln = eine Zeile); Solo nur bei 4, 7, 10 … ── */
@media (min-width: 768px) and (max-width: 1366px) and (orientation: landscape) and (min-height: 501px) {
  .st-category-rows:has(> article.category-card),
  #sidebar-box-main #st-homepage-grid,
  .category-articles__grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }

  .st-category-row__articles-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .st-category-rows:has(> article.category-card) > article.category-card:last-child:nth-child(3n + 1):not(:only-child),
  #sidebar-box-main #st-homepage-grid > li:last-child:nth-child(3n + 1):not(:only-child),
  .category-articles__grid > article.category-card:last-child:nth-child(3n + 1):not(:only-child) {
    grid-column: 1 / -1 !important;
  }
}

/* ── Desktop: initial 3 Spalten; Solo bei 4, 7, 10 … ── */
@media (min-width: 1025px) {
  .st-category-rows:has(> article.category-card),
  #sidebar-box-main #st-homepage-grid,
  .category-articles__grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }

  .st-category-rows:has(> article.category-card) > article.category-card:last-child:nth-child(3n + 1):not(:only-child),
  #sidebar-box-main #st-homepage-grid > li:last-child:nth-child(3n + 1):not(:only-child),
  .category-articles__grid > article.category-card:last-child:nth-child(3n + 1):not(:only-child) {
    grid-column: 1 / -1 !important;
  }
}

/* ── Desktop schmale Content-Spalte (nur 2 Spalten): nächste Solo-Kachel volle Breite ── */
@media (min-width: 1367px) {
  @container st-article-tile-grid (max-width: 960px) {
    .st-category-rows:has(> article.category-card),
    #sidebar-box-main #st-homepage-grid,
    .category-articles__grid {
      grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .st-category-rows:has(> article.category-card) > article.category-card:last-child:nth-child(3n + 1),
    #sidebar-box-main #st-homepage-grid > li:last-child:nth-child(3n + 1),
    .category-articles__grid > article.category-card:last-child:nth-child(3n + 1) {
      grid-column: auto !important;
    }

    .st-category-rows:has(> article.category-card) > article.category-card:last-child:nth-child(odd):not(:only-child),
    #sidebar-box-main #st-homepage-grid > li:last-child:nth-child(odd):not(:only-child),
    .category-articles__grid > article.category-card:last-child:nth-child(odd):not(:only-child) {
      grid-column: 1 / -1 !important;
    }
  }
}
