@use "../bubble-mixins" as bubble;

// Markdown surfaces and borders derive from currentColor so they stay legible
// on both bubble backgrounds (own / reciprocal) and in both themes, without
// depending on theme tokens that may equal the bubble background itself.
$markdown-surface: color-mix(in srgb, currentcolor 8%, transparent);
$markdown-surface-strong: color-mix(in srgb, currentcolor 14%, transparent);
$markdown-border: color-mix(in srgb, currentcolor 24%, transparent);

.stream-message {
  position: relative;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 10px 12px;
  text-align: start;

  &--self {
    @include bubble.bubble-base-self();
  }

  &--other {
    @include bubble.bubble-base-other();
  }

  &__content {
    min-width: 0;
    overflow-wrap: anywhere;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.5;

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

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

    p,
    blockquote,
    pre,
    table,
    ul,
    ol {
      margin: 8px 0;
    }

    h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
      margin: 12px 0 8px;
      line-height: 1.3;
    }

    // The global normalize resets `ul, li` to `list-style: none`, so markers
    // must be restored explicitly, including on `li` where the reset applies
    // directly and would otherwise beat inheritance from the list element.
    ul,
    ol {
      padding-inline-start: 24px;
    }

    ul {
      list-style: disc outside;
    }

    ol {
      list-style: decimal outside;
    }

    li {
      margin: 4px 0;
      list-style: inherit;
    }

    // GFM task list items render a checkbox instead of a marker.
    li:has(> input[type="checkbox"]) {
      list-style: none;
    }

    li > input[type="checkbox"] {
      display: inline-block;
      margin-inline-end: 6px;
      vertical-align: baseline;
    }

    ul ul,
    ul ol,
    ol ul,
    ol ol {
      margin: 4px 0;
    }

    ul ul {
      list-style: circle outside;
    }

    ul ul ul {
      list-style: square outside;
    }

    table {
      display: block;
      width: max-content;
      max-width: 100%;
      overflow-x: auto;
      border-collapse: collapse;
      border-spacing: 0;
    }

    th,
    td {
      padding: 4px 8px;
      border: 1px solid $markdown-border;
      text-align: start;
    }

    th {
      background-color: $markdown-surface-strong;
      font-weight: 600;
    }

    pre {
      max-width: 100%;
      overflow-x: auto;
      padding: 8px;
      border-radius: 4px;
      background-color: $markdown-surface;
      white-space: pre;
    }

    code {
      padding: 2px 4px;
      border-radius: 4px;
      background-color: $markdown-surface;
      font-family: monospace;
      font-size: 0.92em;
      white-space: pre-wrap;
    }

    pre code {
      padding: 0;
      border-radius: 0;
      background: none;
      font-size: 1em;
      white-space: inherit;
    }

    hr {
      height: 0;
      margin: 12px 0;
      border: 0;
      border-top: 1px solid $markdown-border;
    }

    blockquote {
      padding-inline-start: 10px;
      border-inline-start: 3px solid currentcolor;
      opacity: 0.8;
    }

    a {
      color: inherit;
      text-decoration: underline;
    }

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