@use "00-base/configure" as *;

$rich-text-spacing: 1.75rem;
$rich-text-spacing-mobile: 1.5rem;
$heading-indent: $gutter;

.ma__rich-text {

  @include clearfix;

  &__flame {
    text-transform: uppercase;
  }

  &--description {
    margin-bottom: 1rem;
  }

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

  .pre-content > &__container,
  .pre-content > &,
  .post-content > &__container,
  .main-content--full .page-content > &__container,
  .main-content--full .page-content .layout--onecol-mass-service-section .layout__region--content > &,
  .main-content .page-content .layout--onecol-mass-service-section .layout__region--content .js-lpb-component > &,
  .main-content--full .page-content > & {

    // By default richt text have a right padding, unless a .no-sidebar class is added to the section container.

    @include ma-container('restricted');
  }

  .main-content--full .no-sidebar .page-content .layout--onecol-mass-service-section .layout__region--content > &,
  .no-sidebar .page-content .layout--onecol-mass-service-section .layout__region--content .js-lpb-component > &,
  .main-content--full .no-sidebar .page-content > & {

    // Use the .no-sidebar class to overide the right padding.

    @include ma-container();
  }

  .ma__split-columns__column > &__container,
  .ma__split-columns__column > & {
    margin-bottom: 1em;
    max-width: 100%;
    padding-left: 0;
    padding-right: 0;
  }

  .ma__comp-heading + & {
    margin-top: 0;
  }

  .page-content.ma__announcement__page-content &__container & {

    @include ma-component-spacing;
  }

  // extra specificity was needed to override & a { ... }

  & &__footnote {
    border-style: solid;
    border-width: 2px;
    font-size: $fonts-small;
    line-height: 1;
    padding: 0.5px 6.5px;
    position: relative;
    top: .5em;
    vertical-align: top;
    transition: all ease .4s;

    &:hover {
      border-width: 2px;
    }
  }

  // rich text has an optional title

  h2:not(.ma__comp-heading),
  h3:not(.ma__comp-heading),
  h3:not(.ma__sidebar-heading),
  h4 {

    @include ma-comp-heading;
  }

  & h2,
  &__container h2 {
    padding-top: .75em;

    &:first-child:not(.sticky-toc-jump-target) {
      padding-top: 0;
    }
  }

  /**
   * Rich text content can be styled like an outline when a modifier class is added by rich-text.js
   * 1. Headings will be indented
   * 2. Content nested under each heading will be further indented
   */

  &__indent[data-ma-heading-parent='H2'] {
    margin-left: $heading-indent; // 2.
  }

  h3 {

    &.ma__rich-text__indent {
      margin-left: $heading-indent; // 1.
    }
  }

  &__indent[data-ma-heading-parent='H3'] {
    margin-left: $heading-indent * 2; // 2.
  }

  h4 {
    margin-bottom: .6em;
    padding-bottom: .45em;

    &:after {
      width: 1.5em;
    }

    &.ma__rich-text__indent {
      margin-left: $heading-indent * 2; // 1.
    }
  }

  &__indent[data-ma-heading-parent='H4'] {
    margin-left: $heading-indent * 3; // 2.
  }

  h5 {
    display: block;
    margin-bottom: 0;

    &.ma__rich-text__indent {
      margin-left: $heading-indent * 3; // 1.
    }
  }

  &__indent[data-ma-heading-parent='H5'] {
    margin-left: $heading-indent * 4; // 2.
  }

  h6 {
    display: block;

    &.ma__rich-text__indent {
      margin-left: $heading-indent * 4; // 1.
    }
  }

  &__indent[data-ma-heading-parent='H6'] {
    margin-left: $heading-indent * 5; // 2.
  }

  p,
  section.ma__link-list {
    margin-bottom: $rich-text-spacing-mobile;

    @media ($bp-small-min) {
      margin-bottom: $rich-text-spacing;
    }
  }

  // List styles

  ul {
    margin-bottom: $rich-text-spacing-mobile;
    padding-left: 20px;

    &.ma__link-list__items--no-bullets {
      padding-left: 0;
    }

    @media ($bp-small-min) {
      margin-bottom: $rich-text-spacing;
    }

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

  ul ul {
    margin-top: 0.5em;
    margin-bottom: 0;
  }

  ol {
    margin-bottom: $rich-text-spacing-mobile;
    padding-left: 20px;

    @media ($bp-small-min) {
      margin-bottom: $rich-text-spacing;
    }

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

  li {
    margin-bottom: .5em;
    padding-left: 5px;

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

  // end list styles

  // link styles

  a {

    @include ma-link-underline;
    border-bottom-width: 1px;
    overflow-wrap: break-word;
    transition: border .3s;
    word-wrap: break-word;
    word-break: normal;
  }

  // end link styles

  // TABLE styles

  table {
    margin-bottom: $rich-text-spacing-mobile;
    min-width: 450px;
    width: 100%;

    @media ($bp-small-min) {
      margin-bottom: $rich-text-spacing;

      & td > table {
        margin-bottom: 0;
      }
    }
  }

  &__table-wrapper {
    margin-bottom: 1em;
    overflow: auto;

    table {
      margin-bottom: 0;
    }
  }
  // end Table styles

  // last element in the rich text content

  & > :last-child {
    margin-bottom: 0 !important;
  }

  pre,
  code,
  kbd,
  samp,
  var {
    font-size: 1em;
    font-family: $fonts-mono !important;
  }

  pre,
  code,
  kbd {
    border: 1px solid var(--mf-c-gray-lighter);
  }

  pre:not(:has(> code)) { // code block styles will be handled by highlight.js in openmass
    background-color: var(--mf-c-gray-lightest);
    padding: 1em;
  }

  code:not(pre > code), // code block styles will be handled by highlight.js in openmass
  kbd {
    font-size: 90%;
    padding: .2em .4em;
    margin-left: 0;
    margin-right: 0;
    background-color: var(--mf-c-gray-lightest);
    border-radius: 4px;
  }

  kbd {
    font-weight: $fonts-bold;
    box-shadow: $box-shadow;
  }
}

// Fix display issue after left floated image in IE11.

@media all and (-ms-high-contrast:none) {

  .page-content .ma__rich-text {

    ul,
    ol {
      margin-left: -40px;
      list-style-position: inside;
    }
  }
}

//theme

.ma__rich-text {

  &__flame {
    font-weight: bold;
  }

  &__footnote {
    border-color: var(--mf-c-link);

    &:hover {
      background-color: var(--mf-c-font-link);
      color: var(--mf-c-font-inverse);
    }
  }

  h2, h3, h4 {

    @include ma-comp-heading($c-primary-alt);
  }

  h2.ma__collapsible-header,
  h3.ma__collapsible-header,
  h4.ma__collapsible-header {

    &:after {
      display: none;
    }
  }

  h5 {
    font-weight: $fonts-bold;
  }

  a {
    border-bottom-color: var(--mf-c-link);

    &:hover {
      border-bottom-width: 3px;
    }
  }

  .list-style-disc {
    list-style-type: disc;
  }

  .list-style-circle {
    list-style-type: circle;
  }

  .list-style-square {
    list-style-type: square;
  }

  .list-style-decimal {
    list-style-type: decimal;
  }

  .list-style-decimal-leading-zero {
    list-style-type: decimal-leading-zero;
  }

  .list-style-lower-roman {
    list-style-type: lower-roman;
  }

  .list-style-upper-roman {
    list-style-type: upper-roman;
  }

  .list-style-lower-alpha {
    list-style-type: lower-alpha;
  }

  .list-style-upper-alpha {
    list-style-type: upper-alpha;
  }

  // Cards

  a.ma__card__wrapper {
    border-block-end: 0;
    border-block-end-color: transparent;
  }

}


// auto clearl foat after floating images

.ma__figure--large + .ma__rich-text,
.ma__figure--medium + .ma__figure--medium + .ma__rich-text,
.ma__figure--small + .ma__figure--small + .ma__figure--small + .ma__rich-text
.ma__figure--x-small + .ma__figure--x-small + .ma__figure--x-small + .ma__figure--x-small + .ma__rich-text {
  clear: both;
}
