@import 'jquery.textile';

//Assert form-actions and tag-input are accessible in fullscreen mode
body form:has(.textile-wrap.textile-fullscreen) {
  .form-actions.sticky {
    left: 0;
    padding: 1rem;
    position: fixed;
    right: 0;
    z-index: 2001;
  }

  .tag-input {
    bottom: 0.4rem;
    position: fixed;
    top: auto;
    z-index: 2002;

    @media (min-width: 991px) {
      left: 50%;
    }
  }
}

.content-textile,
.textile-preview {
  background-color: var(--primary-bg);
  overflow-wrap: break-word;
  position: relative;

  em {
    font-style: italic;
  }

  h5 {
    margin-top: 2rem;

    &:first-child {
      margin-top: 0;
    }
  }

  img {
    max-width: 100%;
    height: auto !important;
  }

  ol {
    list-style-type: decimal;
  }

  p:last-child {
    margin: 0;
  }

  pre {
    background-color: var(--secondary-bg);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    margin: 0.75rem 0;
    padding: 10px;
    white-space: pre-wrap;
    overflow-y: auto;
  }

  strong {
    font-weight: bold;
  }

  table {
    max-width: 100%;
    background-color: transparent;
    border-collapse: collapse;
    border-spacing: 0;
    width: 80%;
    margin: 0 auto;
    margin-bottom: 20px;

    tbody {
      > tr:nth-child(odd) > td,
      > tr:nth-child(odd) > th {
        background-color: var(--secondary-bg);
      }
      tr:hover td,
      tr:hover th {
        background-color: var(--secondary-bg-strong);
      }
    }

    td {
      overflow-wrap: anywhere;
    }

    // Cells
    th,
    td {
      padding: 8px;
      line-height: 20px;
      text-align: left;
      vertical-align: top;
      border-top: 1px solid var(--border-color);
    }

    th {
      font-weight: bold;
    }

    // Bottom align for column headings
    thead th {
      vertical-align: bottom;
    }

    // Remove top border from thead by default
    caption + thead tr:first-child th,
    caption + thead tr:first-child td,
    colgroup + thead tr:first-child th,
    colgroup + thead tr:first-child td,
    thead:first-child tr:first-child th,
    thead:first-child tr:first-child td {
      border-top: 0;
    }
  }

  ul {
    list-style-type: square !important;
  }

  ul,
  ol {
    margin-bottom: 2ex;
  }
}

.markup-help {
  h5 {
    margin-top: 2rem;
  }

  .example-img {
    height: 140px;
  }

  ol,
  ul {
    padding-left: 0;
  }
}

.textile-wrap {
  background-color: var(--primary-bg);
  word-break: break-word;

  &.textile-fullscreen {
    font-size: 0.9rem;
    max-height: 100vh;
    padding-top: 0;
    position: fixed;
    overflow: auto;

    .textile-inner {
      min-height: calc(100% - 3.5rem);
      position: absolute;
      top: 3.5rem;
      width: 100%;

      .textarea-container {
        padding-bottom: 0.5rem;
      }

      .textile-form-field {
        .textarea-container {
          padding-bottom: 0;
        }
      }

      .textile-preview {
        height: initial;
        padding-bottom: 0.5rem;
      }

      .sticky-toolbar .editor-toolbar {
        top: 0;
      }
    }

    .textile-toolbar {
      margin-top: 10px !important;
    }
  }

  .textile-inner {
    background: transparent;
    padding: 0;

    .editor-field {
      .textile {
        border: 0;
        border-right: 1px solid var(--border-color);
        border-radius: 0;
        box-shadow: none !important;
        padding: 0.5rem 1.5rem 0.5rem 1rem;
      }
    }

    .textile-form {
      .add-field {
        margin: 1rem 0.75rem;
      }

      .textile-form-body {
        background-color: var(--primary-bg);
        @media (min-width: 992px) {
          border-right: 1px solid var(--border-color);
        }
      }

      .textile-form-field {
        border-left: 4px solid transparent;
        position: relative;
        transition: border 0.2s ease-in-out;

        .actions {
          top: 0;
          opacity: 0;
          padding: 0.5rem 0;
          position: absolute;
          left: -1.25rem;
          transition: opacity 0.2s ease-in-out;
        }

        .editor-field {
          margin: 0;

          &.sticky-toolbar .editor-toolbar {
            width: initial;
          }
        }

        &:hover {
          border-color: $light;

          .actions {
            opacity: 1;
          }
        }

        .textarea-container {
          margin: 0 1rem;

          textarea {
            min-height: 34px;
            resize: none;
          }
        }
      }
    }

    .textile-preview {
      background: var(--primary-bg);
      padding: 0;
      overflow: auto;
      height: 100%;

      &.preview-placeholder {
        align-items: center;
        display: flex;
        height: 100%;
        justify-content: center;

        h5 {
          color: var(--text-muted);
          margin-bottom: 1.75rem;
        }
      }

      @include media-breakpoint-down(lg) {
        border-top: 1px solid var(--border-color);
        margin-top: 2rem;
        padding-top: 2rem;
      }
    }
  }

  ul.textile-toolbar {
    background: var(--primary-bg);
    border-bottom: 0px;
    margin-bottom: 1em !important;

    li {
      a {
        border-radius: 3px;
        border: 0px none;
        color: var(--text-link);

        &:hover {
          background: var(--secondary-bg);
          border: 0px none;
          color: var(--text-link-hover);
        }

        &.active {
          background: $primary;
          color: $white;
        }
      }
    }
  }
}
