.acf-block-fos-form {
  --fos-border-color: rgba(255, 255, 255, .2);

  position: relative;
  isolation: isolate;
  padding: 30px 30px 50px;
  color: var(--color-main-background);
  overflow: hidden;
  background-image: url('/wp-content/plugins/custom-blocks/blocks/fos-form/img/form-background.jpg');
  background-position: center;
  background-size: cover;

  @media (max-width: 875px) {
    padding: 20px;
  }

  /* Второй фон для состояния с корзиной: слой плавно проявляется по data-cart-state */

  &::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 0;
    background-image: url('/wp-content/plugins/custom-blocks/blocks/fos-form/img/form-background-filled.jpg');
    background-position: center;
    background-size: cover;
    opacity: 0;
    pointer-events: none;
    transition: opacity .5s ease-in-out;
  }

  &[data-cart-state="filled"]::after {
    opacity: 1;
  }

  @media (prefers-reduced-motion: reduce) {
    &::after {
      transition: none;
    }
  }

  /* После успешной отправки в форме остаётся только текст благодарности */

  &[data-fos-state="success"] .fos-form {
    display: block;
  }

  .fos-form {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    grid-template-areas:
      "content steps"
      "fields steps";
    grid-template-rows: auto 1fr;
    width: 100%;

    /* Левая вертикальная линия формы */

    &::before {
      content: "";
      position: absolute;
      top: -30px;
      left: 0;
      width: 1px;
      height: calc(100% + 80px);
      background: var(--fos-border-color);
    }

    @media (max-width: 875px) {
      display: flex;
      flex-direction: column;
    }
  }

  /* Правая вертикальная линия формы в состоянии с корзиной убрана */

  .fos-form__left {
    grid-area: content;
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .form-text {
    position: relative;
    margin-bottom: 55px;

    @media (min-width: 768px) {
      min-height: 211px;
    }

    > .h2 {
      position: relative;
      padding-top: 20px;
      margin-bottom: 20px;

      &::before,
      &::after {
        content: "";
        position: absolute;
        left: -30px;
        width: calc(100% + 30px);
        height: 1px;
        background: var(--fos-border-color);

        @media (max-width: 875px) {
          left: -20px;
          width: calc(100% + 20px);
        }
      }

      &::before {
        top: 0;
      }

      &::after {
        bottom: -10px;
      }
    }
  }

  &[data-cart-state="filled"] {
    .form-text {
      min-height: auto;
      margin-bottom: 0;

      > .h2 {
        @media (min-width: 875px) {
          padding-top: 32px;
        }
      }
    }
  }

  .form-selections {
    position: relative;
    display: none;
    flex-direction: row;
    gap: 0;
    max-height: 336px;
    margin-top: auto;

    &::before,
    &::after {
      content: "";
      position: absolute;
      left: -30px;
      width: calc(100% + 30px);
      height: 1px;
      background: var(--fos-border-color);

      @media (max-width: 875px) {
        left: -20px;
        width: calc(100% + 20px);
      }
    }

    &::before {
      top: 0;
    }

    &::after {
      bottom: 0;
    }

    @media (max-width: 900px) {
      flex-direction: column;
      gap: 20px;
      max-height: none;
      margin-top: 40px;
    }
  }

  &[data-cart-state="filled"] .form-selections {
    display: flex;
  }

  .form-selection-col {
    position: relative;
    flex: 1;
    min-width: 0;

    .form-selection-title {
      border-bottom: 1px solid var(--fos-border-color);
    }

    @media (min-width: 875px) {
      &:first-child {
        border-right: 1px solid var(--fos-border-color);
      }
    }

    @media (max-width: 875px) {
      &:not(.active-js) {
        .form-selection-title {
          &::before {
            transform: translateY(-50%) rotate(-45deg);
          }
        }

        .form-selection-items {
          height: 0;
          padding: 0;
          overflow-y: scroll;
          -ms-overflow-style: none;
          scrollbar-width: none;
        }
      }
    }
  }

  .form-selection-title {
    position: relative;
    padding: 16px 23px;
    margin-bottom: 20px;
    font-size: 18px;
    font-weight: 400;
    line-height: 1.25;
    letter-spacing: -0.36px;

    @media (max-width: 875px) {
      &::before {
        content: "";
        position: absolute;
        top: 50%;
        right: 15px;
        display: block;
        width: 12px;
        height: 12px;
        border-bottom: 2px solid var(--color-main-background);
        border-left: 2px solid var(--color-main-background);
        transition: all .3s ease-in-out;
        transform: rotate(135deg);
      }

      &::after {
        content: "";
        position: absolute;
        bottom: 0;
        left: -76px;
        width: calc(100vw + 76px);
        height: 1px;
        background: var(--fos-border-color);
      }
    }
  }

  .form-selection-items {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 250px;
    padding: 0 0 20px 23px;
    transition: all .3s ease-in-out;
    overflow: auto;

    /* SimpleBar оборачивает пункты в .simplebar-content, поэтому gap нужен и внутри */

    .simplebar-content {
      display: flex;
      flex-direction: column;
      gap: 10px;

      /* SimpleBar добавляет clearfix-псевдоэлементы, в flex они становятся пунктами */

      &::before,
      &::after {
        display: none;
      }
    }
  }

  .selection-checkbox {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;

    input[type="checkbox"] {
      position: relative;
      flex: 0 0 15px;
      width: 15px;
      height: 15px;
      padding: 0;
      margin: 0;
      border: 1px solid currentColor;
      background: transparent;
      cursor: pointer;
      appearance: none;
      -webkit-appearance: none;
    }

    input[type="checkbox"]:checked::after {
      content: "";
      position: absolute;
      background: currentColor;
      inset: 4px;
    }

    input[type="checkbox"]:focus-visible {
      outline: 1px dashed currentColor;
      outline-offset: 1px;
    }

    span {
      font-size: 18px;
      line-height: 1.25;
      letter-spacing: -0.36px;
    }
  }

  .form-fields {
    position: relative;
    grid-area: fields;
    display: flex;
    flex-wrap: wrap;
    gap: 30px;
    min-width: 0;
  }

  .form-col {
    position: relative;
    width: calc(50% - 15px);
    min-width: 0;

    @media (max-width: 875px) {
      width: 100%;
    }
  }

  /* Горизонтальные линии полей — только в состоянии без корзины */

  &[data-cart-state="empty"] {
    .form-fields {
      &::before,
      &::after {
        content: "";
        position: absolute;
        left: -30px;
        width: calc(100% + 30px);
        height: 1px;
        background: var(--fos-border-color);

        @media (max-width: 875px) {
          left: -20px;
          width: calc(100% + 20px);
        }
      }

      &::before {
        top: 0;
      }

      &::after {
        bottom: 0;

        @media (max-width: 900px) {
          display: none;
        }
      }
    }

    .form-col .form-row:last-child {
      margin-bottom: 0;
    }

    .checkboxes {
      @media (min-width: 875px) {
        padding: 8px 15px;
        margin: -3px 0 20px;
        border-top: 1px solid var(--fos-border-color);
        border-bottom: 1px solid var(--fos-border-color);
      }
    }
  }

  &[data-cart-state="filled"] {
    .fos-form {
      grid-template-columns: minmax(0, 1fr) 551px;
      grid-template-areas: "content fields";
      grid-template-rows: 1fr;

      @media (max-width: 1200px) {
        grid-template-columns: minmax(0, 1fr) 480px;
      }

      @media (max-width: 1000px) {
        grid-template-columns: minmax(0, 1fr) 420px;
      }

      @media (max-width: 875px) {
        display: flex;
      }
    }

    .form-fields {
      flex-direction: column;
      flex-wrap: nowrap;
      gap: 0;
      padding-left: 76px;

      /* Вертикальная линия между выбором и полями */

      &::before {
        content: "";
        position: absolute;
        top: -30px;
        left: 0;
        width: 1px;
        height: calc(100% + 80px);
        background: var(--fos-border-color);

        @media (max-width: 900px) {
          display: none;
        }
      }

      @media (max-width: 1200px) {
        padding-left: 55px;
      }

      @media (max-width: 1000px) {
        padding-left: 40px;
      }

      @media (max-width: 875px) {
        padding-left: 0;
      }
    }

    .form-col {
      width: 100%;
    }

    .form-col:last-child .form-row:last-child {
      margin-bottom: 0;
    }

    .checkboxes {
      padding: 8px 0;
      margin: -3px 0 20px;
      border: 0;
    }

    .form-steps {
      display: none;
    }
  }

  .form-steps {
    --fos-steps-pad: 60px;

    position: relative;
    grid-area: steps;
    min-width: 0;
    padding-left: var(--fos-steps-pad);

    /* Вертикальная линия, отделяющая описание */

    &::before {
      content: "";
      position: absolute;
      top: -30px;
      left: 0;
      width: 1px;
      height: calc(100% + 80px);
      background: var(--fos-border-color);
    }

    @media (max-width: 1200px) {
      --fos-steps-pad: 40px;
    }

    @media (max-width: 875px) {
      display: none;
    }
  }

  .form-steps__title {
    padding-top: 20px;
    margin-bottom: 30px;
    font: 400 clamp(24px, 2.083vw, 30px)/1.1 "Helios", sans-serif;
    letter-spacing: -0.036rem;
  }

  .form-steps__list {
    padding: 0;
    margin: 0;
    list-style: none;
  }

  .form-step {
    display: flex;
    gap: 20px;
    padding: 20px 30px 20px var(--fos-steps-pad);
    margin: 0 -30px 0 calc(-1 * var(--fos-steps-pad));
    border-top: 1px solid var(--fos-border-color);

    &:last-child {
      padding-bottom: 0;
    }
  }

  .form-step__num {
    flex: 0 0 auto;
    font-size: 20px;
    line-height: 1.2;
  }

  .form-step__body {
    min-width: 0;
  }

  .form-step__title {
    margin-bottom: 6px;
    font: 400 20px/1.2 "Helios", sans-serif;
  }

  .form-step__text {
    font-size: 18px;
    line-height: 1.29;
  }

  textarea {
    height: 120px;
    resize: none;
    overflow: auto;
    scrollbar-width: none;
  }

  textarea::-webkit-scrollbar {
    display: none;
  }

  .checkboxes {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 0 15px;
    margin-bottom: 20px;
  }

  .checkbox {
    display: flex;
    align-items: flex-start;
    gap: 6px;

    input[type="checkbox"] {
      position: relative;
      flex: 0 0 10px;
      width: 10px;
      height: 10px;
      padding: 0;
      margin: 2px 0 0;
      border: 1px solid currentColor;
      background: transparent;
      cursor: pointer;
      appearance: none;
      -webkit-appearance: none;

      &.error {
        border: 1px solid var(--color-error);
      }
    }

    input[type="checkbox"]:checked::after {
      content: "";
      position: absolute;
      background: currentColor;
      inset: 1px;
    }

    input[type="checkbox"]:focus-visible {
      outline: 1px dashed currentColor;
      outline-offset: 1px;
    }

    label {
      font-size: 12px;
      cursor: pointer;
    }
  }

  .white-button {
    position: relative;
    width: 100%;
    font-weight: 400;
    color: #d0904f;
    text-align: left;

    @media (max-width: 875px) {
      &::before,
      &::after {
        content: "";
        position: absolute;
        left: -30px;
        width: calc(100% + 60px);
        height: 1px;
        background: var(--fos-border-color);
      }

      &::before {
        top: 0;
      }

      &::after {
        bottom: 0;
      }
    }
  }

  .form-row--captcha {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .smartcaptcha-container {
    min-height: 0;

    iframe {
      background: #ffffff;
      border-radius: 8px;
    }
  }

  input[name="lastname"] {
    position: absolute;
    left: -9999px;
  }
}
