@import '../config/import';

%layout {
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

@mixin animationSlide($name) {
  animation-name: $name;

  @keyframes #{$name} {
    from {
      opacity: var(--opacity-0);
      top: calc(var(--su-4) * -1);
    }
    to {
      opacity: 1;
      top: 0;
    }
  }
}

.crayons-article-form {
  --article-form-actions-height: 56px;
  max-width: var(--site-width);
  display: grid;
  padding: 0 var(--layout-padding);
  height: 100vh;
  gap: 0 var(--layout-gap);
  margin: 0 auto;
  font-size: var(--fs-base);
  grid-template-columns: 100%;
  grid-template-rows: min-content 1fr min-content;

  &__logo,
  &__aside {
    display: none;

    @media (min-width: $breakpoint-m) {
      display: block;
    }
  }

  @media (min-width: $breakpoint-s) {
    --article-form-actions-height: 72px;
  }

  @media (min-width: $breakpoint-m) {
    grid-template-columns: 64px 7fr 3fr;
  }

  @media (min-width: $breakpoint-l) {
    --article-form-actions-height: 88px;
  }

  &__header {
    display: flex;
    align-items: center;
    height: var(--header-height);
    padding: 0 var(--su-2);

    @media (min-width: $breakpoint-m) {
      grid-column-end: span 2;
      padding: 0;
    }

    @media (min-width: $breakpoint-l) {
      grid-column-start: 1;
      grid-column-end: 3;
    }
  }

  &__content {
    overflow-y: auto;
    height: calc(
      100vh - var(--header-height) - var(--article-form-actions-height)
    );
    box-shadow: 0 0 0 1px var(--card-border);
    display: flex;
    flex-direction: column;

    @media (min-width: $breakpoint-m) {
      grid-column-end: span 2;
    }

    @media (min-width: $breakpoint-l) {
      grid-column-start: 2;
      grid-column-end: 2;
    }
  }

  &__aside {
    display: none;

    @media (min-width: $breakpoint-m) {
      display: block;
    }
  }

  &__footer {
    height: var(--article-form-actions-height);
    display: flex;
    align-items: center;
    position: relative;
    padding: 0 var(--su-2);

    @media (min-width: $breakpoint-m) {
      padding: 0;
    }

    @media (min-width: $breakpoint-l) {
      grid-column-start: 2;
      grid-column-end: span 2;
    }
  }
}

.crayons-article-form {
  &__logo {
    margin-right: var(--su-1);
    @media (min-width: $breakpoint-s) {
      margin-right: var(--layout-gap);
    }
  }

  &__close {
    margin-left: var(--su-1);
    @media (min-width: $breakpoint-l) {
      position: absolute;
      right: var(--su-2);
      top: var(--su-2);
      margin-left: 0;
    }
  }

  &__top {
    border-radius: var(--radius) var(--radius) 0 0;
  }

  &__body {
    flex: 1 0 auto;
    position: relative;
    outline: none;
    display: flex;
    flex-direction: column;
    border-radius: 0 0 var(--radius) var(--radius);

    &__field {
      flex: 1 auto;
      overflow: hidden;
    }
  }

  &__toolbar {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    background: var(--base-0);
    padding: var(--su-2) var(--content-padding-x);
    padding-right: var(--content-padding-x, 0);
    flex-shrink: 0;
    margin: calc(var(--content-padding-y) * -1)
      calc(var(--content-padding-x) * -1) var(--su-6)
      calc(var(--content-padding-x) * -1);

    .editor-toolbar {
      overflow-x: auto;

      @media (min-width: $breakpoint-xs) {
        overflow-x: unset;
        position: relative;
      }
    }

    > :first-child {
      @media (min-width: $breakpoint-m) {
        margin-left: calc(var(--su-2) * -1);
      }
    }
  }

  &__cover {
    margin-bottom: var(--su-4);
    display: flex;
    align-items: flex-start;
    flex-direction: column;

    @media (min-width: $breakpoint-s) {
      flex-direction: row;
      align-items: center;
      margin-bottom: var(--su-5);
    }

    &__image {
      width: 250px;
      height: 105px;
      border-radius: var(--radius);
      object-fit: scale-down;
      margin-bottom: var(--su-2);

      @media (min-width: $breakpoint-s) {
        margin-bottom: 0;
        margin-right: var(--su-4);
      }
    }

    @media (max-width: $breakpoint-s) {
      .items-center {
        width: 100%;
      }
      .crayons-btn {
        width: 100%;
      }
    }
  }

  &__title {
    margin-bottom: var(--su-2);
    position: relative;
  }

  &__tagsfield {
    position: relative;
  }

  &__help {
    position: relative;
    animation-duration: 0.25s;
    animation-iteration-count: 1;
    animation-timing-function: var(--transition-func);

    &--title {
      @include animationSlide(slideInTitle);
    }

    &--tags {
      @include animationSlide(slideInTags);
    }

    &--body {
      @include animationSlide(slideInBody);
    }

    .pl-6 {
      padding-left: var(--su-6);
    }

    .list-disc {
      list-style-type: disc;
      //list-style-position: inside;

      li {
        margin-bottom: 0.5rem;
      }
    }
  }
}

.js-focus-visible
  .crayons-article-form__tag-selection
  .c-btn.focus-visible:focus {
  background-color: var(--tag-bg);
  color: var(--base-80);
}

// Styling for drag'n'drop functionality...

.drop-area {
  &--active {
    background: rgba(var(--accent-brand-rgb), 0.1);
    box-shadow: inset 0 0 0 1px var(--focus);

    // ideally this one shouldn't be there, but I'm not sure how else we could handle that right now...
    .crayons-article-form__toolbar {
      opacity: var(--opacity-0);
    }
  }
}

.crayons-preview {
  // Image cover section for preview loading.
  &__cover {
    display: block;
    width: 100%;
    height: auto;
    padding-bottom: 42%;
    background-size: cover;
    background-color: var(--body-bg);
    background-position: center center;

    @media (min-width: $breakpoint-s) {
      border-radius: var(--radius) var(--radius) 0 0;
    }
  }
}
