/* The templates' issue and pull request rows, kept out of the theme files, which are at their size limit. They follow
   GitHub's list for a signed-in reader:

     #8 · user opened on Oct 28 · Updated yesterday · ◔ 1 of 3 tasks · Approved · ✓ 2/2 · ⚑ 2.0
     [label] [label]

   the update only when the list is sorted by it, a pull request's tasks, review and checks after the event, the
   milestone after them and the labels on a line of their own. */

/* Every part of the meta line is one flex item, and every part after the first starts with a "·" with 4px on each
   side. The index's separator, which Forgejo's own meta line gets from the theme files as " ·", is spaced the same. */
#issue-list .issue-meta {
  gap: 0 4px;
}

#issue-list .issue-meta > .issue-meta-lead {
  display: contents;
}

#issue-list .issue-meta .index::after {
  content: "·";
  margin-left: 4px;
}

#issue-list
  .issue-meta
  > :is(
    .issue-meta-tasks,
    .issue-meta-review,
    .issue-meta-checks,
    .milestone,
    .project,
    .ref,
    .checklist,
    .due-date,
    .conflicting
  ),
#issue-list .issue-meta > .issue-meta-lead > .issue-meta-updated {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

#issue-list
  .issue-meta
  > :is(
    .issue-meta-tasks,
    .issue-meta-review,
    .issue-meta-checks,
    .milestone,
    .project,
    .ref,
    .checklist,
    .due-date,
    .conflicting
  )::before,
#issue-list .issue-meta > .issue-meta-lead > .issue-meta-updated::before {
  content: "·";
}

/* GitHub underlines the author with dots and the checks' tally with a line, as links in text. The author is the
   phrase's .author or, with Forgejo's wording, the link in Forgejo's sentence. */
#issue-list .issue-meta .issue-meta-event a {
  color: inherit;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}

/* Refined GitHub's avatar before the author's name: 14px, 4px from the name, on the text's bottom; the theme files
   already round every avatar in the list. It is hidden unless an admin or a user stylesheet sets
   --custom-list-avatars: inline-block on :root, so unset it has no box, and with loading="lazy" the browser does not
   fetch it. The space is the avatar's own margin, gone with it. Forgejo's avatar helper always adds .tw-align-middle,
   an !important utility, so the alignment needs one of its own. The own-user highlight below colours only the
   name's span after it, never the avatar. The rule covers every author link in a row; the compact density, whose
   rows show no avatar on GitHub, hides it again below. */
#issue-list .author > img.theme-list-avatar {
  display: var(--custom-list-avatars, none);
  width: 14px;
  height: 14px;
  margin: 0 4px 0 0;
  vertical-align: text-bottom !important;
}

/* Refined GitHub's highlight of the reader's own issues and pull requests: the author's name in the highlight colours
   GitHub gives a mention of the reader. It is off unless an admin or a user stylesheet sets --custom-own-highlight: 1
   on :root; at 0 or unset the name keeps the colour it inherits and no background. The name is the .author link's span
   with the theme's wording, or the link in Forgejo's sentence without it, and the compact meta's author. */
#issue-list
  :is(.issue-meta .issue-meta-event, .issue-meta-compact-author).theme-own
  :is(.author > span, a:not(.author)) {
  color: color-mix(in srgb, var(--color-highlight-fg) calc(100% * var(--custom-own-highlight, 0)), currentColor);
  background-color: color-mix(
    in srgb,
    var(--color-highlight-bg) calc(100% * var(--custom-own-highlight, 0)),
    transparent
  );
}

#issue-list .issue-meta .issue-meta-tasks {
  color: var(--color-text-light-1);
  white-space: nowrap;
}

/* GitHub's checks badge: a 16px icon in the emphasis colors. Forgejo colors it with .text.<color>, which forces its
   color variable, so the badge redefines those. */
#issue-list .issue-meta .issue-meta-checks {
  --color-thin-green: var(--github-bgColor-success-emphasis);
  --color-thin-red: var(--github-bgColor-danger-emphasis);
  --color-yellow: var(--github-bgColor-attention-emphasis);
}

#issue-list .issue-meta .issue-meta-checks .commit-status {
  width: 16px;
  height: 16px;
}

#issue-list .issue-meta .issue-meta-checks .commit-status-count {
  text-decoration: underline;
  text-underline-offset: 2px;
}

#issue-list .issue-meta .milestone > span {
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}

/* A pull request's review shows as text in the meta line; its icon is the compact cell's. */
#issue-list .issue-meta .issue-meta-review-icon {
  display: none;
}

/* The row renders an element for every cell of the compact layout, empty when it has no value; the meta line and the
   trailing column leave the empty ones out, and the column itself when all of its cells are. */
#issue-list .issue-meta > :empty,
#issue-list > .flex-item > .flex-item-trailing > :empty,
#issue-list > .flex-item > .flex-item-trailing:not(:has(> :not(:empty))),
#issue-list .issue-meta-compact {
  display: none;
}

/* The labels' own line, 2px below the meta line. */
#issue-list .flex-item-main > .labels-list {
  display: flex;
  margin-top: 2px;
}

/* GitHub's trailing column: the comment count, then the assignees, 8px apart, centred beside the whole row however
   many lines it has. On a phone it moves below the labels, in line with the title. */
#issue-list > .flex-item > .flex-item-trailing {
  align-self: center;
  gap: 8px;
}

@media (max-width: 767.98px) {
  #issue-list > .flex-item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
  }

  #issue-list > .flex-item > .flex-item-trailing {
    grid-column: 2;
    justify-content: start;
  }
}

/* The filter bar, as GitHub's: Open and Closed on the left and the filters on the right, on one row. The filters take
   the room left over and the ones that do not fit go behind the "⋯" menu at the end of the row
   (components/common/overflow). Only when not even that menu fits beside Open and Closed, on a phone, do the filters
   move to a row of their own, still at the right. The row keeps the template's order: Forgejo reorders the sort menu
   on phones. */
#issue-filters {
  flex-wrap: wrap;
  row-gap: 8px;
}

#issue-filters > .issue-list-toolbar-left {
  flex: none;
}

/* 32px: the "⋯" button. The display density toggle follows the filters, 4px after Sort or the "⋯" button, outside
   the overflowing row, which overflow.js sizes to the room the toggle leaves. */
#issue-filters > .issue-list-toolbar-right {
  display: flex;
  flex: 1 1 32px;
  gap: 4px;
  justify-content: flex-end;
  min-width: 0;
}

#issue-filters > .issue-list-toolbar-right > .filter.menu {
  flex-wrap: nowrap;
  margin: 0;
  overflow: visible;
}

#issue-filters > .issue-list-toolbar-right > .filter.menu > * {
  order: 0;
  margin-inline-start: 0;
}

/* GitHub's compact display density (components/common/density), from 768px; phones keep the rows above, as GitHub's
   compact rows are no phone layout. Each row is one 37px line with a 1px border:

     (icon) Title of the issue… acme/webapp • sam        —        (comment) 2        —        (avatar)

   the icon, the title and the short meta (#N for a pull request, the repository for an issue on the dashboard) on one
   line, then GitHub's four 72px cells, 8px apart, with "—" in an empty one: an issue's tracked time, comments, tasks
   and assignees, a pull request's review, checks, comments and assignees. Labels, the meta line's event and the rest
   are not shown. The row's boxes give way (display: contents) so the cells, wherever the template keeps them, are the
   grid's items; equal orders keep the template's order, so an issue's tasks, which the template keeps in the meta
   line, follow its comments. The scope is the theme files' row rules' (styles/components/issues/issue_list.ts) with
   the density on top, so these win over them. */
@media (min-width: 768px) {
  :root[data-theme-list-density="compact"] .page-content.issue-list:is(.github-issues, .github-pull-list) #issue-list {
    & > .flex-item {
      display: grid;
      grid-template-columns: auto minmax(0, 1fr) repeat(4, 72px);
      align-items: center;
      gap: 0 8px;
      min-height: 37px;
      padding: 0 4px 0 16px;
    }

    & > .flex-item > .flex-item-icon {
      align-self: center;
      padding: 0;
    }

    & > .flex-item > :is(.flex-item-main, .flex-item-trailing),
    & > .flex-item > .flex-item-main > .issue-meta {
      display: contents;
    }

    & > .flex-item > .flex-item-main > .labels-list,
    & .issue-meta > :not(.issue-meta-review, .issue-meta-checks, .checklist),
    & .issue-meta .issue-meta-review-text,
    & .issue-meta > .checklist > progress,
    & > .flex-item > .flex-item-trailing > .theme-comfortable-only {
      display: none;
    }

    /* The title and the meta share the line, 4px apart: the title keeps its length while it fits and ellipsizes
       after, the meta takes what is left. */
    & > .flex-item > .flex-item-main > .flex-item-header {
      display: flex;
      align-items: baseline;
      gap: 4px;
      min-width: 0;
      min-height: 0;
    }

    & .flex-item-header > .flex-item-title {
      flex: 0 1 auto;
      min-width: 2em;
      overflow: hidden;
      font-size: 14px;
      font-weight: 400;
      line-height: 21px;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    & .flex-item-title > .issue-title {
      display: inline;
      font-weight: 400;
    }

    & .flex-item-header > .issue-meta-compact {
      display: flex;
      flex: 1 1 auto;
      min-width: 0;
      color: var(--color-text-light-1);
      font-size: 12px;
      line-height: 18px;
      white-space: nowrap;
    }

    & .issue-meta-compact > * {
      flex: 0 1 auto;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    & .issue-meta-compact > .issue-meta-compact-ref {
      color: inherit;
    }

    & .issue-meta-compact > .issue-meta-compact-ref:hover {
      color: var(--github-fgColor-accent);
    }

    & .issue-meta-compact > .issue-meta-compact-ref + .issue-meta-compact-author::before {
      content: "•";
      margin-inline: 4px;
    }

    & .issue-meta-compact .author {
      color: inherit;
      text-decoration: underline dotted;
      text-underline-offset: 2px;
    }

    /* GitHub's compact rows have no avatar, so Refined GitHub's, behind --custom-list-avatars, stays out of them. */
    & .issue-meta-compact .author > img.theme-list-avatar {
      display: none;
    }

    /* The cells: 12px muted text after a 16px icon, from the start of the cell; the assignees centred. */
    & .issue-meta > :is(.issue-meta-review, .issue-meta-checks, .checklist),
    & > .flex-item > .flex-item-trailing > * {
      display: flex;
      align-items: center;
      justify-content: flex-start;
      gap: 4px;
      min-width: 0;
      overflow: hidden;
      color: var(--color-text-light-1);
      font-size: 12px;
      line-height: 18px;
      white-space: nowrap;
    }

    & .issue-meta > :is(.issue-meta-review, .issue-meta-checks, .checklist)::before {
      content: none;
    }

    & .issue-meta > :is(.issue-meta-review, .issue-meta-checks, .checklist):empty::before,
    & > .flex-item > .flex-item-trailing > :empty::before {
      content: "—";
    }

    & .issue-meta .issue-meta-review-icon {
      display: flex;
    }

    & .issue-meta > .checklist {
      order: 1;
    }

    & > .flex-item > .flex-item-trailing > .issue-trailing-assignees {
      order: 2;
      justify-content: center;
    }
  }
}
