.portfolio__title {
  max-width: 700px;
  margin-bottom: 60px;

  @media screen and (max-width: 768px) {
    margin-bottom: 40px;
  }
}

.portfolio-filter {
  --portfolio-filter-line-height: 64px;

  display: flex;
  column-gap: 40px;
  align-items: stretch;

  padding: 20px;
  border-radius: 80px;
  margin-bottom: 80px;
  background-color: #fff;
  box-shadow: 0 4px 24px 0px rgba(0,0,0,0.2);

  @media screen and (max-width: 1200px) {
    column-gap: 24px;
  }
  @media screen and (max-width: 1024px) {
    --portfolio-filter-line-height: 54px;

    padding: 14px;
    column-gap: 16px;
  }
  @media screen and (max-width: 991px) {
    column-gap: 12px;
  }
  @media screen and (max-width: 768px) {
    row-gap: 16px;
    flex-direction: column;
    border-radius: 24px;
    margin-bottom: 40px;
  }

  & .portfolio-filter-select {
    width: 100%;
    height: var(--portfolio-filter-line-height);
    z-index: 10;
    position: relative;

    border-radius: 34px;
    border: 1px solid #7d9c9e;
    transition: .3s;

    @media screen and (min-width: 769px) {
      max-width: 420px;
    }
    @media screen and (max-width: 1024px) {
      border-radius: 28px;
    }

    &:hover {
      border-color: #222222;
    }
    &:not(.shown) {
      cursor: pointer;
    }
    &.shown {
      z-index: 11;
      border-color: transparent;
    }
    &:not(:hover) {
      transition: 0s;
    }

    & .portfolio-filter-select-control {
      z-index: 11;
      position: absolute;
      right: 20px;
      top: 50%;
      transform: translateY(-50%);

      width: 20px;
      height: 20px;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    & :is(.portfolio-filter-select-arrow, .portfolio-filter-select-close) {
      width: 100%;
      height: 100%;
      display: block;
      fill: #7d9c9e;
      stroke: #7d9c9e;

      &.portfolio-filter-select-close {
        width: 16px;
        height: 16px;
        cursor: pointer;
      }
    }
    &.shown .portfolio-filter-select-arrow {
      display: none;
    }
    &:not(.shown) .portfolio-filter-select-close {
      display: none;
    }
  }
  & .portfolio-filter-options {
    width: calc(100% + 2px);
    min-height: calc(100% + 2px);
    overflow-y: hidden;

    z-index: 1;
    position: relative;
    left: -1px;
    top: -1px;

    border-radius: 34px;
    border: 1px solid transparent;

    @media screen and (max-width: 1024px) {
      border-radius: 28px;
    }

    .portfolio-filter-select.shown & {
      /* padding: 8px 0; */
      position: absolute;
      border-color: #222222;
      background-color: #fff;
    }
    & .portfolio-filter-select-list {
      width: 100%;
      height: 100%;
      max-height: 400px;
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
      overscroll-behavior-y: contain;

      padding: 12px 0;
      display: flex;
      flex-direction: column;
    }
  }
  & .portfolio-filter-option {
    display: block;
    min-height: 40px;
    font-weight: 300;
    font-family: "Mulish", sans-serif;
    font-size: calc(16px + 4 * ((100vw - 375px) / 1545));
    text-decoration: none;
    padding: 8px 20px;
    color: #7d9c9e;
    transition: color .3s;

    @media screen and (max-width: 1024px) {
      padding: 4px 20px;
    }

    &::before {
      content: '';
      z-index: 1;
      position: absolute;
      inset: 0;
    }
    &:not([data-select="1"]) {
      display: none;
    }
    .portfolio-filter-select.shown &[data-select="1"]::before {
      background-color: rgba(125,156,158,.1);
    }

    &:not(:has(img)):not([data-value="0"]) {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      width: 100%;
    }

    .portfolio-filter-select:is(.shown, :hover) & {
      z-index: 0;
      position: relative;
      color: #222222;
    }
    .portfolio-filter-select:not(.shown) & {
      pointer-events: none;
    }
    .portfolio-filter-select.shown & {
      display: block;
      padding: 8px 20px;
      
      &:hover {
        text-decoration: underline;
      }
      &[data-select="1"] {
        color: #7d9c9e;
      }
      &[data-select="1"] {
        pointer-events: none;
      }
    }
  }
  & .portfolio-filter-option:has(img) {
    min-height: auto;

    & .portfolio-filter-doctor-photo {
      width: 60px;
      min-width: 60px;
      height: 60px;

      overflow: hidden;
      border-radius: 50%;
      border: 1px solid #7d9c9e;

      & img {
        display: block;
        object-fit: cover;
        object-position: center top;
      }
    }
    & .portfolio-filter-doctor-info {
      display: flex;
      row-gap: 8px;
      flex-direction: column;
    }
    & .portfolio-filter-doctor-position {
      font-size: 14px;
      color: #222222;
    }
    & .portfolio-filter-doctor-name {
      font-size: 20px;
      color: #7d9c9e;
    }

    &:hover {
      text-decoration: none !important;

      & .portfolio-filter-doctor-name {
        text-decoration: underline !important;
      }
    }

    .portfolio-filter-select.shown & {
      display: flex;
      column-gap: 12px;
      align-items: center;
    }
    .portfolio-filter-select:not(.shown) &[data-select="1"] *:not(.portfolio-filter-doctor-name):not(.portfolio-filter-doctor-info) {
      display: none;
    }
    .portfolio-filter-select:not(.shown) & .portfolio-filter-doctor-name {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      width: 100%;
      line-height: 1;
    }
  }
  & .portfolio-filter-reset {
    width: var(--portfolio-filter-line-height);
    min-width: var(--portfolio-filter-line-height);
    height: var(--portfolio-filter-line-height);

    display: flex;
    column-gap: 16px;
    align-items: center;
    justify-content: center;
    margin-left: auto;

    color: #fff;
    opacity: .5;
    cursor: pointer;
    border-radius: 50%;
    pointer-events: none;
    text-decoration: none;
    background-color: #7d9c9e;
    transition: background-color .3s;

    @media screen and (max-width: 768px) {
      width: 100%;
      border-radius: 24px;
    }

    & svg {
      width: 20px;
      height: 20px;
      stroke: currentColor;

      @media screen and (max-width: 1024px) {
        width: 16px;
        height: 16px;
      }
    }
    & span {
      display: none;
      font-weight: 400;
      font-family: "Forum", serif;
      font-size: calc(16px + 4 * ((100vw - 375px) / 1545));

      @media screen and (max-width: 768px) {
        display: block;
      }
    }
    &:hover {
      background-color: #222222;
    }
    .portfolio-filter-select.selected ~ & {
      opacity: 1;
      pointer-events: all;
    }
    .portfolio-filter:has(.portfolio-filter-option[data-select="1"]:not([data-value="0"])) & {
      opacity: 1;
      pointer-events: all;
    }
  }
}

.portfolio-list {
  margin: 0;
  padding: 0;
  width: 100%;
  list-style: none;

  display: grid;
  gap: 40px;
  grid-template-columns: repeat(auto-fit, minmax(600px, 1fr));

  @media screen and (max-width: 1600px) {
    gap: 20px;
    grid-template-columns: repeat(auto-fit, minmax(463px, 1fr));
  }
  @media screen and (max-width: 1024px) and (min-width: 621px) {
    gap: 40px;
  }
  @media screen and (max-width: 480px) {
    grid-template-columns: 1fr;
  }

  & .portfolio-list__item {
    z-index: 0;
    position: relative;
    break-inside: avoid;
    display: inline-block;
    width: 100%;

    &.hide {
      display: none !important;
    }
    &::before {
      content: '';
      z-index: -1;
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      border-bottom-right-radius: 60px;
      background-color: rgba(125,156,158,.1);

      @media screen and (max-width: 1300px) {
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        border-bottom-right-radius: 30px;
      }
    }
  }
}

.portfolio-with-filter:has(.portfolio-filter.inited) {
  & .portfolio-list__item.shown {
    display: inline-block !important;
  }
  &:has(.portfolio-list__item.shown) .portfolio-list__item:not(.shown) {
    display: none;
  }
  &:has(.portfolio-list__item.shown) .portfolio-paginav {
    display: none;
  }
}
.portfolio-with-filter.empty :is(.portfolio-list, .portfolio-paginav) {
  display: none;
}

/* Обычный вывод */
.portfolio-work:not(.portfolio-work--extended) {
  display: flex;
  column-gap: 0;
  align-items: stretch;

  @media screen and (max-width: 1400px) and (min-width: 1026px) {
    flex-direction: column;
  }
  @media screen and (max-width: 768px) {
    flex-direction: column;
  }

  & .portfolio-work__media {
    width: 47%;
    min-width: 47%;
    display: flex;
    row-gap: 14px;
    flex-direction: column;

    @media screen and (max-width: 1400px) and (min-width: 1026px) {
      width: 100%;
      column-gap: 14px;
      flex-direction: row;
    }
    @media screen and (max-width: 1025px) and (min-width: 880px) {
      width: 35%;
      min-width: 35%;
    }
    @media screen and (max-width: 879px) {
      width: 40%;
      min-width: 40%;
    }
    @media screen and (max-width: 768px) and (min-width: 481px) {
      width: 100%;
      column-gap: 14px;
      flex-direction: row;
    }
    @media screen and (max-width: 480px) {
      width: 100%;
    }

    & :is(.portfolio-work__before, .portfolio-work__after) {
      width: 100%;
      position: relative;
    }
    & img {
      width: 100%;
      aspect-ratio: 350 / 220;
      display: block;
      object-fit: cover;
      border-radius: 0 0 36px 0;
    }
    & span {
      z-index: 1;
      position: absolute;
      left: 21px; bottom: 15px;
      color: #161615;
      font-weight: 400;
      font-size: calc(21px + 5 * ((100vw - 375px) / 1545));
      font-family: "Forum", serif;
      background-color: white;
      padding: 4px 14px;
      border-radius: 40px;
    }
  }

  & .portfolio-work__info {
    display: flex;
    row-gap: 18px;
    flex-direction: column;
    padding: 24px 30px 24px 24px;

    @media screen and (max-width: 768px) {
      padding: 24px 10px;
    }

    & .portfolio-work__name {
      line-height: 1;
      font-weight: 400;
      font-size: calc(26px + 8 * ((100vw - 375px) / 1545));
      font-family: "Forum", serif;
      color: #161615;
    }

    & :is(.portfolio-work__description, .portfolio-work__services, .portfolio-work__doctors) {
      display: flex;
      row-gap: 6px;
      flex-direction: column;
      
      &:not(:last-child) {
        margin-bottom: 12px;

        @media screen and (max-width: 1400px) {
          margin-bottom: 0;
        }
      }
    }
    & .portfolio-work__doctors:not(:has(.portfolio-work__doctor)) {
      display: none;
    }
    & .portfolio-work__label {
      line-height: 1.6;
      font-weight: 400;
      font-size: calc(16px + 2 * ((100vw - 375px) / 1545));
      font-family: "Mulish", serif;
      text-transform: uppercase;
      color: #9F9F9F;
    }
    .portfolio-work__text {
      line-height: 1.3;
      font-weight: 400;
      font-size: calc(14px + 2 * ((100vw - 375px) / 1545));
      font-family: "Mulish", serif;
      color: #222222;
    }
    & .portfolio-work__list {
      display: flex;
      row-gap: 8px;
      column-gap: 15px;
      flex-wrap: wrap;
      align-items: center;
      list-style: none;
      margin: 0;
      padding: 0;

      & a {
        line-height: 1.3;
        font-weight: 400;
        font-size: calc(14px + 2 * ((100vw - 375px) / 1545));
        font-family: "Mulish", serif;
        color: #2F494F;
        text-decoration: none;
        border-bottom: 1px solid currentColor;
        transition: color .3s;

        &:hover {
          color: #7d9c9e;
        }
      }
    }
    & .portfolio-work__doctor {
      display: grid;
      row-gap: 5px;
      column-gap: 10px;
      grid-template-columns: 50px 1fr;
      grid-template-areas:
        "photo name"
        "photo specialisations";
      text-decoration: none;

      & .portfolio-work__doctor-photo {
        grid-area: photo;
        height: 50px;
        overflow: hidden;

        & img {
          width: 100%;
          display: block;
        }
      }
      & .portfolio-work__doctor-name {
        grid-area: name;
        font-weight: 400;
        font-size: calc(14px + 2 * ((100vw - 375px) / 1545));
        font-family: "Mulish", serif;
        line-height: 1.3;
        color: #222222;
        transition: color .3s;
        align-self: flex-end;
      }
      &:hover .portfolio-work__doctor-name {
        color: #7d9c9e;
      }
      & .portfolio-work__doctor-specialisations {
        grid-area: specialisations;
        font-weight: 400;
        font-size: calc(12px + 0 * ((100vw - 375px) / 1545));
        font-family: "Mulish", serif;
        line-height: 1;
        color: #9F9F9F;
        align-self: flex-start;

        & span:nth-child(1n + 2)::before {
          content: ', ';
        }
      }
    }
  }
}

/* Расширенный вывод */
.portfolio-list:has(.portfolio-work--extended) {
  gap: 24px;
  grid-template-columns: repeat(2, 1fr);

  @media screen and (min-width: 1201px) {
    grid-template-columns: repeat(1, 1fr);
  }
  @media screen and (max-width: 991px) {
    grid-template-columns: repeat(1, 1fr);
  }
}
.portfolio-work--extended {
  display: flex;
  column-gap: 0;
  align-self: stretch;
  border-radius: 0 0 30px 0;
  background-color: #EFF3F3;

  @media screen and (max-width: 1200px) {
    flex-direction: column;
  }

  &:not(:has(.portfolio-work__media--vertical)) {
    flex-direction: column;
  }

  & .portfolio-work__media {
    width: 45.64%;
    min-width: 45.64%;
    position: relative;

    display: flex;
    row-gap: 0;
    flex-direction: column;

    @media screen and (max-width: 1200px) {
      width: 100%;
    }

    & :is(.portfolio-work__before, .portfolio-work__after) {
      width: 100%;
      aspect-ratio: 712 / 370;
    }

    &.portfolio-work__media--vertical {
      height: 100%;
      column-gap: 0;
      flex-direction: row;
      align-items: stretch;

      & :is(.portfolio-work__before, .portfolio-work__after) {
        aspect-ratio: 356 / 550;
      }
    }
    &:not(.portfolio-work__media--vertical) {
      width: 100%;
      height: 100%;

      @media screen and (min-width: 1201px) {
        column-gap: 0;
        flex-direction: row;
        align-items: stretch;
      }

      @media screen and (max-width: 991px) and (min-width: 575px) {
        column-gap: 0;
        flex-direction: row;
        align-items: stretch;
      }
    }
  }

  & :is(.portfolio-work__before, .portfolio-work__after) {
    overflow: hidden;
    position: relative;

    & img {
      width: 100%;
      height: 100%;
      display: block;
      object-fit: cover;
    }

    & span {
      z-index: 1;
      left: 24px;
      bottom: 24px;
      position: absolute;
      padding: 8px 24px;
      border-radius: 99px;
      background-color: white;

      color: #000000;
      font-size: 30px;
      line-height: 33px;
      letter-spacing: 4%;
      text-transform: uppercase;
      font-family: "Forum", serif;

      @media screen and (max-width: 768px) {
        font-size: 18px;
        left: 16px;
        bottom: 16px;
      }
      @media screen and (max-width: 480px) {
        font-size: 14px;
        padding: 5px 16px;
      }
    }
  }

  & .portfolio-work__info {
    display: grid;
    row-gap: 32px;
    column-gap: 48px;
    grid-template-areas:
      "history result"
      "doctors services";

    width: 100%;
    height: max-content;
    padding: 44px 32px 32px;
    position: relative;

    @media screen and (max-width: 1200px) and (min-width: 992px) {
      display: flex;
      flex-direction: column;
    }
    @media screen and (max-width: 768px) {
      display: flex;
      flex-direction: column;

      padding: 32px 24px 24px;
    }
    @media screen and (max-width: 480px) {
      padding: 24px 16px 16px;
    }

    & .portfolio-work__label {
      margin-bottom: 16px;

      font-size: 20px;
      line-height: 22px;
      letter-spacing: 4%;
      text-transform: uppercase;
      font-family: "Forum", serif;

      @media screen and (max-width: 768px) {
        font-size: 17px;
      }
    }
    & .portfolio-work__text {
      font-size: 14px;
      line-height: 160%;
      letter-spacing: 2%;
      font-family: "Mulish", sans-serif;
    }
    
    & .portfolio-work__description--history {
      grid-area: history;
    }
    .portfolio-work__media--vertical ~ & .portfolio-work__description--history {
      min-height: 200px;

      @media screen and (max-width: 1200px) {
        min-height: auto;
      }
    }
    & .portfolio-work__description--result {
      grid-area: result;
    }
    .portfolio-work__media--vertical ~ & .portfolio-work__description--result {
      min-height: 200px;

      @media screen and (max-width: 1200px) {
        min-height: auto;
      }
    }
    & .portfolio-work__services {
      order: 5;
      grid-area: services;
      position: relative;
    }
    & .portfolio-work__doctors {
      grid-area: doctors;
      position: relative;
    }

    &:not(:has(.portfolio-work__description--history)) {
      grid-template-areas:
        "result result"
        "doctors services";
    }
    &:not(:has(.portfolio-work__description--result)) {
      grid-template-areas:
        "history history"
        "doctors services";
    }
    &:not(:has(.portfolio-work__description--history)):not(:has(.portfolio-work__description--result)) {
      grid-template-areas:
        "doctors services";
    }

    &::before {
      content: '';
      z-index: 2;
      position: absolute;
      left: 50%;
      top: 0;

      width: 1px;
      height: 100%;
      background: linear-gradient(
        0deg,
        transparent 0%,
        #7D9C9E 50%,
        transparent 100%
      );

      @media screen and (max-width: 1200px) and (min-width: 992px) {
        content: none;
      }
      @media screen and (max-width: 768px) {
        content: none;
      }
    }
    &:not(:has(.portfolio-work__description--history))::before, &:not(:has(.portfolio-work__description--result))::before {
      content: none;
    }
    &:not(:has(.portfolio-work__description--history)) .portfolio-work__doctors::before, &:not(:has(.portfolio-work__description--result)) .portfolio-work__doctors::before {
      content: '';
      z-index: 2;
      position: absolute;
      left: calc(100% - 2px);
      top: 0;

      width: 1px;
      height: 100%;
      background: linear-gradient(
        0deg,
        transparent 0%,
        #7D9C9E 50%,
        transparent 100%
      );

      @media screen and (max-width: 1200px) and (min-width: 992px) {
        content: none;
      }
      @media screen and (max-width: 768px) {
        content: none;
      }
    }
  }

  & .portfolio-work__doctor {
    display: grid;
    row-gap: 3px;
    column-gap: 16px;
    align-items: center;
    grid-template-columns: 60px 1fr;
    grid-template-areas:
      "photo name"
      "photo roles";

    font-size: 14px;
    font-weight: 500;
    line-height: 120%;
    letter-spacing: 0%;
    text-decoration: none;
    font-family: "Mulish", sans-serif;

    & .portfolio-work__doctor-photo {
      width: 60px;
      min-width: 60px;
      height: 60px;
      overflow: hidden;
      grid-area: photo;

      & img {
        width: 100%;
        height: 100%;
        display: block;
        object-fit: cover;
      }
    }
    & .portfolio-work__doctor-name {
      color: #000000;
      grid-area: name;
    }
    & .portfolio-work__doctor-specialisations {
      color: #9F9F9F;
      grid-area: roles;
    }

    &:not(:last-child) {
      margin-bottom: 20px;
    }
    &:hover .portfolio-work__doctor-name {
      text-decoration: underline;
    }
  }

  & .portfolio-work__list {
    display: flex;
    row-gap: 12px;
    flex-direction: column;

    margin: 0;
    padding: 0;
    list-style: none;

    & a {
      font-size: 14px;
      line-height: 120%;
      letter-spacing: 0%;
      font-family: "Mulish", sans-serif;

      &:hover {
        text-decoration: none;
      }
    }
  }

  & .portfolio-work__video {
    z-index: 1;
    position: absolute;
    right: 36px;
    bottom: 36px;

    @media screen and (max-width: 768px) {
      right: 24px;
      bottom: 24px;
    }

    & a {
      display: flex;
      align-items: center;
      justify-content: center;

      width: 68px;
      height: 68px;
      border-radius: 50%;
      transition: all .25s;
      background-color: rgba(125, 156, 158, 0.5);
    }
    & svg {
      width: 23px;
      height: 26px;
      fill: white;
      transition: all .25s;
      transform: translateX(2px);
    }
    & a:hover {
      background-color: #222222;
    }
    & a:hover svg {
      transform: scale(1.1, 1.1) translateX(2px);
    }
  }
}