.category-list {
  table-layout: fixed;
  .category-text-title {
    display: flex;
    align-items: baseline;
  }
  .category-name {
    display: inline-block;
    max-width: 100%;
    @include ellipsis;
    vertical-align: text-top;
    line-height: $line-height-medium;
  }
  &.with-topics {
    .subcategories-with-subcategories {
      .category-description {
        display: none;
      }
    }
  }
}

.category-boxes,
.category-boxes-with-topics {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  margin-top: 1em;
  margin-bottom: 1em;
  width: 100%;

  .category-box {
    position: relative;
    display: flex;
    flex-direction: row;
    align-content: flex-start;
    box-sizing: border-box;
    border-width: 0;
    border-left-width: 6px;
    border-style: solid;
    border-color: $primary-low;

    .mobile-view & {
      width: 100%;
    }

    .parent-box-link {
      // This avoids an issue with nested links by layering links instead
      &:before {
        content: "";
        position: absolute;
        z-index: 0;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
      }
    }

    .logo.aspect-image img {
      display: block;
      width: auto;
      height: 40px;
      margin: 0 auto 1em auto;
    }

    @supports (--custom: property) {
      .logo.aspect-image img {
        --height: 40px;
        height: var(--height);
        width: calc(var(--height) * var(--aspect-ratio));
        max-width: 100%;
      }
    }
  }

  .category-box-inner {
    box-sizing: border-box;
    width: 100%;
    padding: 0;
    display: flex;
    flex-direction: column;

    border-width: 2px;
    border-left-width: 0;

    border-style: solid;
    border-color: $primary-low;
  }

  &.no-logos {
    .logo {
      display: none;
    }
  }
}

.category-boxes {
  .category-box {
    width: 23%;
    margin: 0 1% 1.5em 1%;
    > a {
      width: 100%;
      padding: 0;
    }
    .category-box-inner {
      padding: 1em;

      .category-logo {
        float: none;
        margin: 0;
      }
    }
  }

  &.no-logos {
    .category-box .category-box-inner > a {
      padding: 3em 1em;
    }
  }

  .description {
    padding-bottom: 1em;
    text-align: center;
    font-size: $font-0;
    color: dark-light-choose($primary-medium, $secondary-high);
    position: relative;

    //  allow clicks to fall through the description text to the category below...
    pointer-events: none;
    .overflow {
      max-height: 6em;
      div a {
        //  ...but links in description should still be clickable
        pointer-events: auto;
      }
    }
  }

  h3 {
    font-size: $font-up-2;
    margin-bottom: 0.5em;
    margin-top: 0.25em;
    line-height: $line-height-medium;
    text-align: center;
    color: $primary;
    overflow: hidden;
  }

  h4 a {
    color: $primary;
  }

  .subcategory.with-subcategories {
    position: relative;
    border: none;
    border-left-width: 4px;
    border-left-style: solid;
    margin-bottom: 0.25em;

    .category-title-link {
      display: flex;
      .category-logo {
        flex: 1 0 auto;
        margin: 0.25em 0.5em 0.5em 0;
        --max-height: 40px;
      }
      .category-text-title {
        order: 2;
        line-height: $line-height-medium;
        overflow: hidden;
        margin-bottom: 0.25em;
        word-wrap: break-word;
      }
      &:before {
        // This avoids an issue with nested links by layering links instead
        content: "";
        position: absolute;
        z-index: 0;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
      }
    }

    .subcategory-box-inner {
      border: 1px solid $primary-low;
      border-left: none;
      padding: 0.5em 0.5em 0.4em 0.5em;
    }

    &:not(:last-of-type) {
      margin-bottom: 0.75em;
    }

    .subcategory {
      margin-bottom: 0.25em;
    }
  }

  .subcategories {
    display: flex;
    flex-flow: wrap;
    .subcategory {
      display: flex;
      align-items: center;
      @include ellipsis;
      margin-bottom: 0.6em;
      .badge-wrapper {
        overflow: hidden;
      }
      .subcategory-image-placeholder {
        display: inline-block;
        margin-right: 0.6em;
        flex: 1 0 auto;
      }
      .subcategory-link {
        min-width: 0;
        @include ellipsis;
      }
      .logo img {
        display: inline-block;
        --height: 20px;
        height: var(--height);
        width: calc(var(--height) * var(--aspect-ratio));
        margin: 0;
      }
    }
  }
}

.category-boxes-with-topics {
  .category-box {
    width: 31%;
    margin: 0 1% 1.5em 1%;
    padding: 0;
  }

  h3 {
    font-size: $font-up-2;
    text-align: center;
    overflow: hidden;
  }

  .category-box-heading {
    padding: 1em 1em 0.5em 1em;
    a[href] {
      width: 100%;
      color: $primary;
    }
  }

  .featured-topics {
    padding: 0.5em 1em 1em 1em;
    ul {
      color: $primary-medium;
      list-style: none;
      padding: 0;
      margin: 0;
    }
    li {
      padding: 4px 0;
      display: flex;
      align-items: baseline;
      .overflow {
        max-height: 3em;
        overflow: hidden;
      }
      .d-icon {
        margin-right: 0.15em;
        width: 0.76em;
        height: 0.76em;
      }
    }
  }
}

.categories-list .category {
  h3,
  h4 {
    margin-bottom: 0;
    .d-icon {
      color: $primary-high;
      height: 0.76em;
      width: 0.76em;
      vertical-align: baseline;
      margin-right: 0.1em;
    }
  }
  .category-description {
    margin-top: 0.5em;
    overflow: hidden;
    color: $primary-high;
  }
  .category-logo.aspect-image {
    margin-top: 0.5em;
  }
}

.category-boxes-with-topics,
.category-boxes {
  .category-box h3 .d-icon {
    margin-right: 0;
  }
}

.category-list.subcategories-with-subcategories {
  margin-top: 1em;
  margin-bottom: 0;
  border-top: 1px solid $primary-low;
  .category-description {
    font-size: $font-down-1;
  }
  .category-logo.aspect-image {
    --max-height: 75px;
  }
}

.categories-list .category.muted {
  font-size: $font-down-1;
  h3,
  .category-name {
    color: $primary-medium;
  }
}

.category-list {
  tbody {
    .category {
      &.no-category-style {
        border-color: transparent;
        border-left: 0px;
        padding-left: 0px;
      }
    }
  }
}

.category-box.no-category-boxes-style {
  border-left-width: 2px;
}
