/* ============================================
Featured Category Cards
============================================ */

.home-category-cards .all-categories-scrollable,
.modal-category-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
  margin-bottom: 3rem;
  position: relative;
  min-height: 400px;
  transition: all 0.3s ease-in-out;
}

/* All Categories Scrollable Wrapper - inherits grid from parent by default */
.all-categories-scrollable {
  display: contents;
}

/* All Categories Expanded State */
@media only screen and (min-width: 640px) {
  #what-we-do.has-expanded-categories .wpb_column.vc_col-sm-6:first-child {
    padding: 0 2rem;
    margin-top: 2rem;
  }

  /* Container changes to flexbox to stack button and scrollable area */
  .home-category-cards.all-categories-expanded {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: auto;
    position: relative;
  }

  /* Close button styling - hidden by default */
  .all-categories-close-btn {
    display: none;
    align-self: flex-end;
    margin-bottom: 1rem;
  }

  .home-category-cards.all-categories-expanded .all-categories-close-btn {
    display: block;
    margin-right: 1.5rem !important;
  }

  /* Scrollable wrapper becomes actual grid in expanded state */
  .home-category-cards.all-categories-expanded .all-categories-scrollable {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.6rem;
    max-height: calc(2.5 * 180px + 3 * 0.6rem);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.5rem 1rem 1rem;
    scroll-behavior: auto;
    position: relative;
    margin: 1rem 0 0;
  }

  /* Fade overlay at bottom of scrollable area - positioned on parent so it doesn't scroll */
  .home-category-cards.all-categories-expanded::before {
    content: '';
    position: absolute;
    top: 3rem;
    left: 0;
    right: 3rem;
    height: calc(100% - 3rem);
    pointer-events: none;
    background: linear-gradient(0deg, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 15%);
    z-index: 10;
  }

  .home-category-cards.all-categories-expanded.scrolling::before {
    background: linear-gradient(180deg, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 10%, rgba(255, 255, 255, 0) 90%, rgba(255, 255, 255, 1) 100%);
  }

  .home-category-cards.all-categories-expanded.bottom::before {
    background: linear-gradient(0deg, rgba(255, 255, 255, 0) 90%, rgba(255, 255, 255, 1) 100%);
  }

  /* When a card is expanded, disable scrolling and hide scrollbar */
  .home-category-cards.all-categories-expanded.has-expanded-card .all-categories-scrollable {
    overflow-y: hidden;
  }

  /* Scrollbar styling for expanded view */
  .home-category-cards.all-categories-expanded .all-categories-scrollable::-webkit-scrollbar {
    width: 8px;
  }

  .home-category-cards.all-categories-expanded .all-categories-scrollable::-webkit-scrollbar-track {
    background: #eaf3ef;
    border-radius: 4px;
    /* Indent scrollbar track from top */
    margin-top: 0.5rem;
  }

  .home-category-cards.all-categories-expanded .all-categories-scrollable::-webkit-scrollbar-thumb {
    background: #7DA79A;
    border-radius: 4px;
  }

  .home-category-cards.all-categories-expanded .all-categories-scrollable::-webkit-scrollbar-thumb:hover {
    background: #2F9376;
  }

  /* Ensure cards in expanded view have consistent height */
  .home-category-cards.all-categories-expanded .category-card:not(.category-card--expanded) {
    height: 150px;
    max-height: 150px;
  }

  /* No scroll state: 9 or fewer categories */
  .home-category-cards.all-categories-expanded.no-scroll .all-categories-scrollable {
    overflow-y: hidden;
    max-height: none;
  }

  .home-category-cards.all-categories-expanded.no-scroll::before {
    display: none;
  }
}

/* All Categories Expanded State */
@media only screen and (min-width: 1024px) {

  /* When categories are expanded, adjust the parent row columns */
  #what-we-do.has-expanded-categories .wpb_column.vc_col-sm-6:first-child {
    width: calc(33.333% - 1rem) !important;
    flex: 0 0 calc(33.333% - 1rem) !important;
    transition: all 0.3s ease-in-out;
    padding: 0;
    margin-top: 3rem;
  }

  #what-we-do.has-expanded-categories .wpb_column.vc_col-sm-6:last-child {
    width: calc(66.666% - 1rem) !important;
    flex: 0 0 calc(66.666% - 1rem) !important;
    transition: all 0.3s ease-in-out;
    padding: 0;
  }

  .home-category-cards.all-categories-expanded::before {
    right: 10px;
  }
}

/* Tablet: Scrollable categories with fade masks (641px - 1024px) */
@media only screen and (min-width: 641px) and (max-width: 1024px) {
  .home-category-cards .all-categories-scrollable {
    max-height: 32rem;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    scroll-behavior: smooth;
    padding: 1rem;
  }

  /* Fade overlay at bottom of scrollable area - positioned on parent so it doesn't scroll */
  .home-category-cards:not(.all-categories-expanded)::before {
    opacity: 0;
  }

  .home-category-cards::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 10px;
    height: calc(100% - 3rem);
    pointer-events: none;
    background: linear-gradient(0deg, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 15%);
    z-index: 10;
  }

  /* When scrolling (not at top), show both top and bottom fades */
  .home-category-cards.scrolling::before {
    background: linear-gradient(180deg, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 10%, rgba(255, 255, 255, 0) 90%, rgba(255, 255, 255, 1) 100%);
  }

  /* When at bottom, show only top fade */
  .home-category-cards.bottom::before {
    background: linear-gradient(0deg, rgba(255, 255, 255, 0) 90%, rgba(255, 255, 255, 1) 100%);
  }

  /* Scrollbar styling for tablets */
  .home-category-cards .all-categories-scrollable::-webkit-scrollbar {
    width: 8px;
  }

  .home-category-cards .all-categories-scrollable::-webkit-scrollbar-track {
    background: #eaf3ef;
    border-radius: 4px;
    margin-top: 0.5rem;
  }

  .home-category-cards .all-categories-scrollable::-webkit-scrollbar-thumb {
    background: #7DA79A;
    border-radius: 4px;
  }

  .home-category-cards .all-categories-scrollable::-webkit-scrollbar-thumb:hover {
    background: #2F9376;
  }

  /* Horizontal scrollbar styling for vertical-picker on tablets */
  .vertical-picker__track::-webkit-scrollbar {
    display: none;
  }

  /* Scroll arrow button for vertical-picker on tablets */
  .vertical-picker {
    position: relative;
  }

  .vertical-picker__scroll-arrow-container {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    opacity: 1;
    transition: opacity 0.4s ease;
    background: linear-gradient(90deg, #eaf3ef00, #eaf3ef 35%);
    border-radius: 0 100px 100px 0;
    width: 5rem;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 0.5rem;
  }

  .vertical-picker__scroll-arrow-container.hidden {
    opacity: 0;
    pointer-events: none;
  }

  .vertical-picker__scroll-arrow {
    width: 32px;
    height: 32px;
    background: #869590;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: none;
    padding: 0;
    transition: transform 0.2s ease;
  }

  .vertical-picker__scroll-arrow::after {
    content: '';
    width: 16px;
    height: 16px;
    background-image: url('/wp-content/uploads/2025/07/icon-arrow-r-w.svg');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
  }

  .vertical-picker__scroll-arrow:hover {
    transform: scale(1.1);
  }
}

/* Small grid: limit card height when there are fewer than 5 cards */
.home-category-cards.small-grid .category-card:not(.category-card--expanded) {
  max-height: 150px;
}

.home-category-cards.small-grid {
  min-height: auto;
}

/* Expanded card state: grow container to accommodate expanded card */
.home-category-cards.has-expanded-card {
  min-height: 450px;
}

.home-category-cards.small-grid.has-expanded-card {
  min-height: 450px;
}

.category-card,
.modal-category-card {
  background: #ffffff;
  box-shadow: inset 0 0 0 1px #f1f6f4, 0 3px 24px 0 #c4c3b63d;
  padding: 1.5rem;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  display: flex;
}

.category-card--more::after,
.modal-category-card--more::after {
  content: '';
  position: absolute;
  right: 1.5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  background-image: url('/wp-content/uploads/2025/07/icon-arrow-r-g.svg');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  opacity: 0.5;
  transition: all 0.2s ease-in-out;
}

.category-card--more:hover::after,
.modal-category-card--more:hover::after {
  opacity: 0.8;
}

.category-card:hover,
.modal-category-card:hover {
  transform: translateY(-1px);
  box-shadow: inset 0 0 0 1px #f1f6f4, 0 3px 24px 0 #c4c3b653;
}

.category-card__content,
.modal-category-card__content {
  display: flex;
  flex-direction: column;
  width: 100%;
}

.category-card__title,
.modal-category-card__title {
  font-size: 1.2rem !important;
  color: #252827;
  margin: 0;
}

.category-card__count,
.modal-category-card__count {
  font-size: 0.8rem;
  color: #8C9F9A;
  margin: 0;
}

@media only screen and (max-width: 1024px) {

  .category-card__title,
  .modal-category-card__title {
    line-height: 1.4rem !important;
  }
}
