body {
  background-color: #ffffff;
}

.engineering-products-container {
  width: 90%;
  max-width: 1400px;
  margin: 7.5vw auto 0 auto;
  padding-bottom: 4rem;
}

.engineering-products-container h1 {
  text-align: center;
  font-size: clamp(2rem, 3vw, 3.5rem);
  color: #dc2827;
  margin-bottom: 2rem;
}

.engineering-products-container p {
  margin: 1.5rem 0;
  font-size: clamp(0.95rem, 1.05rem, 1.1rem);
  line-height: 1.7;
  color: #333;
}

/* ====================================
   TRUE PINTEREST-STYLE MASONRY - FIXED
   ==================================== */

.masonry-grid {
  column-count: 4;
  column-gap: 20px;
  margin-top: 3rem;
  padding-bottom: 40px; /* Add padding to prevent bottom cutoff */
  
}

.masonry-item {
  break-inside: avoid;
  page-break-inside: avoid; /* For older browsers */
  -webkit-column-break-inside: avoid; /* Safari/Chrome */
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  background: #fff;
  box-shadow: 
    0 2px 8px rgba(0, 0, 0, 0.06),
    0 8px 24px rgba(0, 0, 0, 0.08);
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  
  display: inline-block; /* Critical for break-inside to work */
  width: 100%;
  vertical-align: top; /* Prevents baseline alignment issues */
}

.masonry-item::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 16px;
  padding: 2px;
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.masonry-item:hover::after {
  opacity: 1;
}

.masonry-item:hover {
  transform: translateY(-8px) scale(1.02);
}

.masonry-item img {
  width: 100%;
  height: auto;
  display: block;
  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  vertical-align: middle; /* Removes extra space at bottom */
}

.masonry-item:hover img {
  transform: scale(1.1);
}

/* Varied heights for natural masonry feel */
.masonry-item:nth-child(3n+1) img {
  aspect-ratio: 1;
  object-fit: cover;
}

.masonry-item:nth-child(3n+2) img {
  aspect-ratio: 1/1;
  object-fit: cover;
}

.masonry-item:nth-child(3n+3) img {
  aspect-ratio: 1;
  object-fit: cover;
}

/* ====================================
   RESPONSIVE BREAKPOINTS
   ==================================== */

@media screen and (max-width: 1400px) {
  .masonry-grid {
    column-count: 4;
    column-gap: 18px;
    padding-bottom: 35px;
  }
}

@media screen and (max-width: 1024px) {
  .masonry-grid {
    column-count: 3;
    column-gap: 16px;
    padding-bottom: 30px;
  }
}

@media screen and (max-width: 768px) {
  .engineering-products-container {
    margin-top: 20vw;
  }
  
  .masonry-grid {
    column-count: 2;
    column-gap: 14px;
    padding-bottom: 25px;
  }
  
  .masonry-item {
    margin-bottom: 14px;
  }
}

@media screen and (max-width: 500px) {
  .engineering-products-container {
    margin-top: 23vw;
    width: 95%;
  }

  .masonry-grid {
    column-count: 1;
    padding-bottom: 20px;
  }
  
  .masonry-item {
    margin-bottom: 16px;
  }
}
