.chat-markdown {
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: break-word;
  font-size: 0.9375rem;
  line-height: 1.5;
  color: hsl(var(--foreground));

  ::ng-deep {
    remark {
      display: contents;
    }

    p {
      margin: 0.25em 0;
    }

    strong {
      font-weight: 700;
      color: hsl(var(--foreground));
    }

    em {
      font-style: italic;
    }

    del {
      text-decoration: line-through;
      opacity: 0.7;
    }

    a {
      color: hsl(var(--primary));
      text-decoration: underline;
      text-decoration-thickness: 1px;
      text-underline-offset: 2px;
      cursor: pointer;

      &:hover {
        opacity: 0.8;
      }
    }

    h1, h2, h3, h4, h5, h6 {
      margin: 0.5em 0 0.25em;
      color: hsl(var(--foreground));
      font-weight: 700;
    }

    h1 { font-size: 1.5em; }
    h2 { font-size: 1.3em; }
    h3 { font-size: 1.15em; }

    ul, ol {
      margin: 0.25em 0;
      padding-left: 1.5em;
    }

    ul {
      list-style-type: disc;
    }

    ol {
      list-style-type: decimal;
    }

    li {
      margin: 0.125em 0;
    }

    blockquote {
      margin: 0.5em 0;
      border-left: 3px solid hsl(var(--primary) / 0.5);
      border-radius: 0 var(--radius) var(--radius) 0;
      background: hsl(var(--secondary) / 0.3);
      padding: 0.25em 0.75em;
      color: hsl(var(--muted-foreground));
    }

    code:not([class*='language-']) {
      white-space: pre-wrap;
      word-break: break-word;
      border-radius: 4px;
      background: hsl(var(--secondary));
      padding: 0.15em 0.35em;
      font-family: 'Fira Code', 'Cascadia Code', 'JetBrains Mono', monospace;
      font-size: 0.875em;
    }

    pre {
      margin: 0.5em 0;
      max-width: 100%;
      overflow-x: auto;
      border: 1px solid hsl(var(--border));
      border-radius: var(--radius);
      background: hsl(var(--secondary));
      padding: 0.75em 1em;

      code:not([class*='language-']) {
        border-radius: 0;
        background: transparent;
        padding: 0;
        white-space: pre;
        word-break: normal;
      }
    }

    pre[class*='language-'],
    code[class*='language-'] {
      text-shadow: none;
      font-family: 'Fira Code', 'Cascadia Code', 'JetBrains Mono', monospace;
      font-size: 0.875em;
    }

    pre[class*='language-'] {
      border: 1px solid hsl(var(--border));
      border-radius: var(--radius);
      padding: 0.875em 1rem;
    }

    pre[class*='language-'] > code[class*='language-'] {
      display: block;
      border-radius: 0;
      background: transparent;
      padding: 0;
      white-space: pre;
      word-break: normal;
    }

    hr {
      margin: 0.75em 0;
      border: none;
      border-top: 1px solid hsl(var(--border));
    }

    table {
      display: block;
      margin: 0.5em 0;
      width: auto;
      max-width: 100%;
      overflow-x: auto;
      border-collapse: collapse;
      font-size: 0.875em;
    }

    th, td {
      border: 1px solid hsl(var(--border));
      padding: 0.35em 0.75em;
      text-align: left;
    }

    th {
      background: hsl(var(--secondary));
      font-weight: 600;
    }

    img {
      display: block;
      max-height: 320px;
      max-width: 100%;
      height: auto;
      border-radius: var(--radius);
    }

    p + p {
      margin-top: 0.25em;
    }

    remark-mermaid {
      display: block;
      max-width: 100%;
      overflow-x: auto;

      svg {
        pointer-events: none;
        max-width: 100%;
        height: auto;
      }
    }
  }
}

.edit-textarea {
  min-height: 42px;
  max-height: 520px;
  overflow-y: hidden;
  resize: none;
  transition: height 0.12s ease;
}
