@use '../mixins/_scroll';

.markdown-preview,
.markdown {
  @include scroll.scrollY;
  overflow-wrap: anywhere;
  hyphens: auto;

  *:first-child {
    margin-top: 0;
    padding-top: 0;
  }

  > *:last-child {
    margin-bottom: 0;
  }

  img {
    max-width: 100%;
    height: auto;
    display: block;
  }

  table {
    margin-bottom: var(--s2);
  }

  ul,
  ol {
    margin: 0 var(--s) var(--s2);
    padding-left: var(--s2);
    padding-inline-start: 20px;
  }

  > ul {
    padding-left: var(--s2);
  }

  ul ul,
  ul ol,
  ol ul,
  ol ol {
    margin-bottom: 0;
    padding-top: 0;
    padding-left: var(--s2);
    padding-inline-start: var(--s2);
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    line-height: 1;
    margin-top: 16px;
  }

  h1,
  h2,
  h3 {
    &,
    .mat-typography & {
      margin-bottom: var(--s);
      margin-top: var(--s2);

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

  h1 {
    font-size: 22px;
    line-height: 24px;
  }

  h2 {
    font-size: 18px;
    line-height: 22px;
  }

  pre {
    max-width: 100%;
    overflow-x: auto;
    // we need this, otherwise it might break inside tables
    white-space: pre-wrap;

    code {
      font-size: 12px;
    }
  }

  // Hide native checkbox from marked's default checkbox renderer.
  // The custom .checkbox span (Material Icons) handles all checkbox rendering.
  .checkbox-wrapper > input[type='checkbox'] {
    display: none;
  }

  .checkbox {
    display: inline-block;
    font-size: 20px;
    width: 20px;
    line-height: 1;
    text-align: center;
    margin-left: -28px;
    vertical-align: middle;
    padding-right: var(--s);
    position: relative;
    cursor: pointer;

    &:after {
      content: '';
      position: absolute;
      top: -4px;
      right: -12px;
      left: -12px;
      bottom: -4px;
    }
  }

  .checkbox-wrapper {
    display: block;
    list-style: none;
    padding-bottom: var(--s);

    &.done {
      opacity: 0.6;
      text-decoration: line-through;
    }
  }

  // Only the checkbox icon and this text label toggle the item; the empty rest
  // of the row is not interactive (see clickPreview).
  .checkbox-label {
    cursor: pointer;
  }

  // A markdown link with a disallowed URL scheme, or an image with an unsafe
  // (remote file:// / UNC) src, renders as inert text instead of an anchor/img
  // (security: GHSA-hr87-735w-hfq3, see marked-options-factory.ts). Style it as
  // muted, non-interactive text with a help cursor so blocked content reads as
  // intentionally disabled, not body copy (the title attribute explains why on
  // hover).
  .markdown-blocked-link {
    color: var(--text-color-muted);
    text-decoration: underline dotted;
    cursor: help;
  }
}
