/* Shared spacing and grids for the static site. */

/* Inline feature panels already sit next to padded content sections. */
body.z-type #main > :is(.section-pad, .page-hero, article, .z6-section) + .s2-feature {
  margin-block-start: calc(var(--section-y) / 2);
}

body.z-type #main > .s2-feature:has(+ :is(.section-pad, .z6-section)) {
  margin-block-end: calc(var(--section-y) / 2);
}

/* Retain the existing 24px grid gutter and card widths when a row is incomplete. */
@media (min-width: 768px) and (max-width: 1023px) {
  body.z-type #main :is(.z-scenarios-grid, .more-grid, .case-grid, #case-grid) {
    --card-column-gap: 24px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    column-gap: var(--card-column-gap);
  }

  body.z-type #main :is(.z-scenarios-grid, .more-grid, .case-grid, #case-grid) > .card {
    flex: 0 0 calc((100% - var(--card-column-gap)) / 2);
    min-width: 0;
  }
}

/* This listing filters in place. Flex wraps only the cards visible in the active filter. */
@media (min-width: 1024px) {
  body.z-type #main #case-grid {
    --card-column-gap: 24px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    column-gap: var(--card-column-gap);
  }

  body.z-type #main #case-grid > .case-item {
    flex: 0 0 calc((100% - 2 * var(--card-column-gap)) / 3);
    min-width: 0;
  }
}

@media (min-width: 768px) {
  body.z-type #main #case-grid > .case-item {
    align-self: stretch;
    height: auto;
  }

  /* Knowledge cards have a dedicated reading link after a variable-length summary. */
  body.z-type #main .more-grid > .more-card:has(> .mc-more) {
    display: flex;
    flex-direction: column;
  }

  body.z-type #main .more-grid .mc-more {
    align-self: flex-start;
    margin-top: auto;
  }
}

@media (max-width: 410px) {
  body.z-type[data-site-page="/cases/"] #main .filter-bar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body.z-type[data-site-page="/cases/"] #main .filter-chip {
    padding-inline: 3px;
  }

  body.z-type[data-site-page="/cases/"] #main .filter-chip[data-filter="all"] {
    grid-column: 1 / -1;
  }
}

/* Outdoor safety cards were block siblings because their Astro component scope was missing. */
body[data-site-page="/services/outdoor-led-display/"] #main .grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 768px) {
  body[data-site-page="/services/outdoor-led-display/"] #main .grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Keep a complete row of four short system or audience cards; center the last three. */
@media (min-width: 1100px) {
  body[data-site-page^="/services/"] #main .sys-grid:has(> :nth-child(8):last-child) {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  body[data-site-page^="/services/"] #main :is(.aud-grid,.pf-grid):has(> :nth-child(7):last-child) {
    grid-template-columns: repeat(8, minmax(0, 1fr));
  }
  body[data-site-page^="/services/"] #main :is(.aud-grid,.pf-grid):has(> :nth-child(7):last-child) > * {
    grid-column: span 2;
  }
  body[data-site-page^="/services/"] #main :is(.aud-grid,.pf-grid):has(> :nth-child(7):last-child) > :nth-child(5) {
    grid-column: 2 / span 2;
  }
}

/* Preserve the existing half-width when one card remains on a two-column row. */
@media (min-width: 768px) and (max-width: 1023px) {
  body[data-site-page^="/services/"] #main :is(.aud-grid,.pf-grid,.sys-grid,.grid-3):has(> :nth-child(odd):last-child) {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  body[data-site-page^="/services/"] #main :is(.aud-grid,.pf-grid,.sys-grid,.grid-3):has(> :nth-child(odd):last-child) > * {
    grid-column: span 2;
  }
  body[data-site-page^="/services/"] #main :is(.aud-grid,.pf-grid,.sys-grid,.grid-3) > :nth-child(odd):last-child {
    grid-column: 2 / span 2;
  }
}
@media (min-width: 768px) {
  body[data-site-page="/services/commercial-led-display/"] #main .commercial-article-links:has(> :nth-child(odd):last-child) {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  body[data-site-page="/services/commercial-led-display/"] #main .commercial-article-links:has(> :nth-child(odd):last-child) > * {
    grid-column: span 2;
  }
  body[data-site-page="/services/commercial-led-display/"] #main .commercial-article-links > :nth-child(odd):last-child {
    grid-column: 2 / span 2;
  }
}

/* Keep service descriptions and the following system/parameters adjacent. */
body[data-site-page="/services/"] #main .media-card__body > .card-desc {
  flex: none;
}
body[data-site-page="/services/"] #main .media-card__body > :is(.card-aud,.card-desc,.card-sys) {
  margin-bottom: 10px;
}

/* Phone step numbers form a narrow column next to the original title and description. */
@media (max-width: 767px) {
  body[data-site-page^="/services/"] #main .flow-grid > .flow-step {
    display: grid;
    grid-template-columns: 27px minmax(0, 1fr);
    gap: 5px 10px;
    align-content: start;
    align-items: start;
    padding-top: 13px;
  }
  body[data-site-page^="/services/"] #main .flow-step > :is(.flow-no,.flow-title,.flow-desc) {
    margin-block: 0;
  }
  body[data-site-page^="/services/"] #main .flow-step > :is(.flow-title,.flow-desc) {
    grid-column: 2;
  }
}

@media (min-width: 1024px) {
  body[data-site-page="/about/"] #main .intro-grid {
    grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
    column-gap: clamp(36px, 4vw, 56px);
  }
  body[data-site-page="/about/"] #main .intro-stats {
    align-self: center;
  }
}
@media (min-width: 360px) and (max-width: 767px) {
  body.z-type[data-site-page="/insights/"] #main .s2-category:not(#s2-cat-commercial) > .s2-category-grid > a {
    padding: 12px;
    text-wrap: balance;
  }
}

/* Keep the normal card width and centre the links left on the last line. */
@media (min-width: 640px) and (max-width: 767px) {
  body.z-type[data-site-page="/insights/"] #main .post-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    column-gap: 16px;
  }
  body.z-type[data-site-page="/insights/"] #main .post-grid > a {
    flex: 0 0 calc((100% - 16px) / 2);
    min-width: 0;
    height: auto;
  }
}
@media (min-width: 768px) {
  body.z-type[data-site-page="/insights/"] #main :is(.post-grid, .s2-category-grid) {
    --kb-card-width: calc((100% - 24px) / 2);
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    column-gap: 24px;
  }
  body.z-type[data-site-page="/insights/"] #main :is(.post-grid, .s2-category-grid) > a {
    flex: 0 0 var(--kb-card-width);
    min-width: 0;
    height: auto;
  }
}
@media (min-width: 1024px) {
  body.z-type[data-site-page="/insights/"] #main :is(.post-grid, .s2-category-grid) {
    --kb-card-width: calc((100% - 48px) / 3);
  }
  body.z-type[data-site-page="/insights/"] #main .s2-category-grid:has(> a:nth-child(4):last-child),
  body.z-type[data-site-page="/insights/"] #main .s2-category-grid:has(> a:nth-child(7):last-child) {
    --kb-card-width: calc((100% - 72px) / 4);
  }
}
@media (min-width: 360px) and (max-width: 767px) {
  body.z-type[data-site-page="/insights/"] #main .s2-category:not(#s2-cat-commercial) > .s2-category-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
  }
  body.z-type[data-site-page="/insights/"] #main .s2-category:not(#s2-cat-commercial) > .s2-category-grid > a {
    flex: 0 0 calc((100% - 10px) / 2);
    min-width: 0;
  }
}
