/*
 * Action Text content styles.
 * Trix editor/toolbar rules removed — this app uses Lexxy, not Trix.
 * Only .trix-content is kept: ActionText wraps all rendered rich text in
 * <div class="trix-content"> regardless of which editor produced it.
 *
 * Lexxy's own content styles sit in the base layer (lexxy-overrides.css, #1297), so these
 * win by layer order.
 */

@layer components {
  .trix-content {
    line-height: var(--exam-line-height, 1.5);
    overflow-wrap: break-word;
    word-break: break-word;
    *:not(input):not(select):not(textarea):not(button):not(ul):not(ol) {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }
    h1 {
      font-size: 1.2em;
      line-height: 1.2;
    }
    blockquote {
      border: 0 solid var(--color-border);
      border-inline-start-width: 0.3em;
      margin-inline-start: 0.3em;
      padding-inline-start: 0.6em;
    }
    /* Lists keep an indent with outside markers, so wrapped lines align with the item text
       (#1467). ul and ol are left out of the reset above, which would zero their padding. */
    ul,
    ol {
      margin: 0;
      padding-inline-start: 1.5em;
    }
    /* Lexxy nests a sub-list inside a wrapper li; only the inner items show a marker. Lexxy's
       own rule for this needs a .lexxy-content ancestor, which rendered rich text lacks. */
    li.lexxy-nested-listitem {
      counter-increment: list-item 0; /* the wrapper takes no number either */
      list-style-type: none;
    }
    pre {
      background-color: var(--color-surface-sunken);
      display: inline-block;
      font-family: monospace;
      font-size: 0.9em;
      inline-size: 100%;
      overflow-x: auto;
      padding: 0.5em;
      vertical-align: top;
      white-space: pre;
    }
    table {
      border-collapse: collapse;
      border-spacing: 0;
      inline-size: 100%;
      margin: 0.75em 0;
    }
    /* tr raises these above core.css's tr:last-child td, so the last row keeps its border
       whatever order the stylesheets link in. */
    table tr th,
    table tr td {
      border: 1px solid var(--color-border);
      padding: 0.5em 0.75em;
      text-align: start;
      vertical-align: top;
    }
    table th {
      background-color: var(--exam-bg-colour, var(--color-surface-sunken));
      font-weight: bold;
    }
  }

  /* Tables in Lexxy content (outside .trix-content) */
  .lexxy-content__table-wrapper {
    table {
      border-collapse: collapse;
      border-spacing: 0;
      inline-size: 100%;
      margin: 0.75em 0;
    }
    table tr th,
    table tr td {
      border: 1px solid var(--color-border);
      padding: 0.5em 0.75em;
      text-align: start;
      vertical-align: top;
    }
    table th {
      background-color: var(--exam-bg-colour, var(--color-surface-sunken));
      font-weight: bold;
    }
  }

  .trix-content {
    img {
      block-size: auto;
      max-inline-size: 100%;
    }
    .attachment {
      display: inline-block;
      max-inline-size: 100%;
      position: relative;
    }
    .attachment a {
      color: inherit;
      text-decoration: none;
    }
    .attachment a:hover,
    .attachment a:visited:hover {
      color: inherit;
    }
    .attachment__caption {
      text-align: center;
    }
    .attachment__caption .attachment__name + .attachment__size::before {
      content: ' \2022 ';
    }
    .attachment--preview {
      inline-size: 100%;
      text-align: center;
    }
    .attachment--preview .attachment__caption {
      color: var(--color-text-secondary);
      font-size: 0.9em;
      line-height: 1.2;
    }
    .attachment--file {
      border: 1px solid var(--color-border);
      border-radius: 5px;
      color: var(--color-text);
      line-height: 1;
      margin: 0 2px 2px 2px;
      padding: 0.4em 1em;
    }
    .attachment-gallery {
      display: flex;
      flex-wrap: wrap;
      position: relative;
    }
    .attachment-gallery .attachment {
      flex: 1 0 33%;
      max-inline-size: 33%;
      padding: 0 0.5em;
    }
    .attachment-gallery.attachment-gallery--2 .attachment,
    .attachment-gallery.attachment-gallery--4 .attachment {
      flex-basis: 50%;
      max-inline-size: 50%;
    }
    /* Override gallery styles for <action-text-attachment> wrapper elements */
    .attachment-gallery > action-text-attachment,
    .attachment-gallery > .attachment {
      flex: 1 0 33%;
      max-inline-size: 33%;
      padding: 0 0.5em;
    }
    .attachment-gallery.attachment-gallery--2 > action-text-attachment,
    .attachment-gallery.attachment-gallery--2 > .attachment,
    .attachment-gallery.attachment-gallery--4 > action-text-attachment,
    .attachment-gallery.attachment-gallery--4 > .attachment {
      flex-basis: 50%;
      max-inline-size: 50%;
    }
    action-text-attachment .attachment {
      max-inline-size: 100% !important;
      padding: 0 !important;
    }
  }

  /* Paragraph alignment from the toolbar's Left/Centre/Right/Justify buttons (#1581), stored as
     a class because both sanitisers drop a text-align style. Unscoped, so every place rich text
     renders (student, marker, preview, Lexxy content) shows it. */
  .align-left { text-align: start; }
  .align-center { text-align: center; }
  .align-right { text-align: end; }
  .align-justify { text-align: justify; }

  /* Media embeds: YouTube/Vimeo iframes */
  .media-embed {
    inline-size: 100%;
    margin: 0.75rem 0;
    padding-block-end: 56.25%; /* 16:9 */
    position: relative;
  }

  .media-embed__iframe {
    block-size: 100%;
    border: none;
    inline-size: 100%;
    inset: 0;
    position: absolute;
  }

  /* Uploaded video/audio */
  .media-embed__video,
  .media-embed__audio {
    border-radius: var(--radius-sm, 4px);
    inline-size: 100%;
    max-inline-size: 100%;
  }

  /* Uploaded video/audio — editor placeholder (player renders in views) */
  .blob-media__placeholder {
    background: oklch(var(--oklch-canvas-raised));
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm, 4px);
    color: var(--color-text-secondary);
    display: inline-block;
    font-size: 0.875rem;
    padding: 0.4rem 0.75rem;
  }

  /* Editor-only preview (thumbnail shown while editing; iframe renders in views) */
  .media-embed-preview {
    display: inline-block;
    max-inline-size: 100%;
    position: relative;
  }

  .media-embed-preview__thumb {
    border-radius: var(--radius-sm, 4px);
    display: block;
    max-inline-size: 320px;
    opacity: 0.85;
  }

  .media-embed-preview__label {
    color: var(--color-text-secondary);
    display: block;
    font-size: 0.8rem;
    margin-block-start: 0.25rem;
    text-align: center;
  }
}
