/* grid-balance.css — 2026-10-13. Site-wide: no lopsided card rows.
   Picks a column count from the number of items (4 cards -> 2x2, 9 links -> 3x3)
   and centers any short last row. Desktop/tablet only; phones keep their 1-column stacks.
   Loaded from includes/header.php AFTER $extraHead so it wins over per-page grid CSS. */
@media (min-width: 600px) {
  html body :is(.loc-grid, .hrc-features, .svc-grid, .rev-grid, .hrc-related, .loc-svc-grid, .city-grid) {
    display: flex !important; flex-wrap: wrap; justify-content: center;
    --c: 2; --g: 1.5rem; gap: var(--g) !important;
  }
  html body :is(.loc-svc-grid, .hrc-related) { --g: 1rem; }
  html body .city-grid { --g: .75rem; }
  html body .rev-grid { --g: 1.25rem; }
  html body :is(.loc-grid, .hrc-features, .svc-grid, .rev-grid, .hrc-related, .loc-svc-grid, .city-grid) > * {
    flex: 0 0 calc((100% - (var(--c) - 1) * var(--g)) / var(--c));
    max-width: calc((100% - (var(--c) - 1) * var(--g)) / var(--c));
    min-width: 0; box-sizing: border-box;
  }
  /* chip rows: just center them */
  html body :is(.related-services, .svc-areas, .hrc-areas, .loc-nearby) { justify-content: center; }
}
@media (min-width: 900px) {
  /* cards */
  html body :is(.loc-grid, .hrc-features, .svc-grid, .rev-grid, .hrc-related) { --c: 3; }
  html body :is(.loc-grid, .hrc-features, .svc-grid, .rev-grid, .hrc-related):has(> :nth-child(1):last-child) { --c: 1; }
  html body :is(.loc-grid, .hrc-features, .svc-grid, .rev-grid, .hrc-related):has(> :nth-child(2):last-child) { --c: 2; }
  html body :is(.loc-grid, .hrc-features, .svc-grid, .rev-grid, .hrc-related):has(> :nth-child(4):last-child) { --c: 2; }
  html body :is(.loc-grid, .hrc-features, .svc-grid, .rev-grid, .hrc-related):is(:has(> :nth-child(7):last-child), :has(> :nth-child(8):last-child)) { --c: 4; }
  /* link tiles */
  html body :is(.loc-svc-grid, .city-grid) { --c: 4; }
  html body :is(.loc-svc-grid, .city-grid):is(:has(> :nth-child(3):last-child), :has(> :nth-child(6):last-child), :has(> :nth-child(9):last-child)) { --c: 3; }
  html body :is(.loc-svc-grid, .city-grid):is(:has(> :nth-child(5):last-child), :has(> :nth-child(10):last-child)) { --c: 5; }
  html body :is(.loc-svc-grid, .city-grid):has(> :nth-child(2):last-child) { --c: 2; }
}

/* 2026-10-24: 10 service links (fiber added) -> 2 rows of 5 on wide screens, 5 rows of 2 between 600 and 1099px */
@media (min-width: 900px) and (max-width: 1099px) {
  html body .loc-svc-grid:has(> :nth-child(10):last-child) { --c: 2; }
}
@media (min-width: 1100px) {
  html body .loc-svc-grid:has(> :nth-child(10):last-child) { --c: 5; }
}

/* 2026-11-06: city pages now list 14-15 service links -> rows of 5 on wide screens, 3 between 900 and 1099px */
@media (min-width: 900px) and (max-width: 1099px) {
  html body .loc-svc-grid:is(:has(> :nth-child(14):last-child), :has(> :nth-child(15):last-child)) { --c: 3; }
}
@media (min-width: 1100px) {
  html body .loc-svc-grid:is(:has(> :nth-child(14):last-child), :has(> :nth-child(15):last-child)) { --c: 5; }
}
