@layer components {
  /* The sources on the citations page, like the links in the sidebar: close to the column's edge, rounded, no lines
     between them, grey under the pointer, the chosen one in blue */
  .citation-sources {
    display: flex;
    flex-direction: column;
    gap: var(--space-1); /* as the sidebar's links */
    padding: var(--space-2);
  }

  .citation-source {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: var(--space-2);
    border-radius: var(--radius-md);
    overflow-wrap: break-word; /* long German words in narrow columns */
    color: var(--color-ink);
    text-decoration: none;
    transition: background-color 0.2s ease;

    &:is(:hover, :focus-visible):not(.is-active) {
      background-color: var(--color-border);
    }

    &.is-active {
      background-color: var(--color-selected);
    }
  }

  /* Not bold, as the links in the sidebar; blue while chosen, as .nav-link--active */
  .citation-source__title {
    font-weight: var(--font-weight-medium);

    .is-active & {
      color: var(--color-blue-accent);
    }
  }

  /* While a citation's form is open (new or edit), the other citations and "Add citation manually" are greyed out until
     it's saved or cancelled, so their passages can't replace the one of the form in the PDF */
  [data-controller~="citation-ui"]:has(#citations turbo-frame .citation-form, #new_citation:not(.hidden)) {
    & #citations > turbo-frame:not(:has(.citation-form)),
    & .citation-add {
      opacity: 0.4;
      pointer-events: none;
    }
  }

  /* The citation (card or form) whose passage the PDF shows marked (citation-ui controller) */
  .card-panel.is-shown-in-pdf,
  .is-shown-in-pdf > .card-panel {
    border-color: var(--color-blue-accent);
    box-shadow: var(--shadow-focus);
  }

  /* "Add citation manually" gives way to the form it opened right below it (citation-ui controller) */
  .citation-add:has(+ #new_citation:not(.hidden)) {
    display: none;
  }

  /* What saving does to the text, first in the form and under the chapter once another is chosen (Niklas, 3.12.): dark,
     with an info icon, not muted as the other hints */
  .citation-form__note {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    color: var(--color-ink);

    .icon {
      margin-block-start: 0.15em;
      color: var(--color-blue-accent);
    }
  }

  /* What leaves the text on saving (another chapter for a citation in a sentence): the warning triangle, in the colour
     of the warnings ("No PDF", "Upload PDF"), the text as dark as the notes (Niklas, 3.12.) */
  .citation-form__note--warning .icon {
    color: var(--color-warning);
  }

  /* "Suggest paraphrase" under the text field, only once Paraphrase is chosen */
  .citation-form__suggest {
    display: none;
    justify-content: flex-end;
  }

  .citation-form:has(.segmented-control__input[value="paraphrase"]:checked) .citation-form__suggest {
    display: flex;
  }

  /* Below the chapter, that Write puts the citation there: not with "No chapter" */
  .citation-form__chapter:not(:has(option:checked:not([value=""]))) .citation-form__placement {
    display: none;
  }

  /* A citation in a sentence: that another chapter takes it out of the sentence, only once another one is chosen */
  .citation-form__chapter:not(:has(option[selected]:not(:checked))) .citation-form__moves {
    display: none;
  }

  /* A citation's card (statements/_statement_card), one per place in the text, or one not in it: a line with where it
     stands or is planned for, then its wording there and below it its pages, the arrow to it on Write, Edit and
     Delete. In the text its tick is green, as citations in the text are on Write; not yet, the open circle is grey.
     A click shows its passage in the PDF, as on any card. */
  .citation-used {
    padding-block: var(--space-2);
    color: var(--color-muted);
  }

  .citation-used__line {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
  }

  /* At the card's left edge, below the tick (Niklas, 1.12.) */
  .citation-used__place {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
  }

  /* Its wording as it stands in the text, as on a card not in the text (Niklas, 1.12.) */
  .citation-used__wording {
    margin: 0;
    color: var(--color-ink);
  }

  .citation-used__check {
    --icon-size: 1.25rem;
    color: var(--color-positive);
  }

  /* Not in the text yet: the open circle, grey */
  .citation-used__check--open {
    color: var(--color-muted);
  }

  /* Where it is used, cut short to the line (whole on hover) */
  .citation-used__where {
    flex: 1 1 4rem;
    min-inline-size: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* A citation's card with a passage: a click shows it in the PDF (citation-ui controller) */
  .citation-card--passage {
    cursor: pointer;
  }

  /* The pdf.js viewer fills the main column */
  .pdf-viewer {
    display: block;
    inline-size: 100%;
    block-size: 100%;
    border: 0;
  }
}
