/* Flash messages and form errors */
.flash,
.form-errors {
  margin-bottom: var(--pico-spacing);
  padding: 0.75rem 1rem;
  border-left: 0.25rem solid;
  border-radius: var(--pico-border-radius);

  p:last-child,
  ul:last-child {
    margin-bottom: 0;
  }
}

.flash-notice {
  border-color: var(--pico-ins-color);
  background: color-mix(in srgb, var(--pico-ins-color) 12%, transparent);
}

.flash-alert,
.form-errors {
  border-color: var(--pico-del-color);
  background: color-mix(in srgb, var(--pico-del-color) 12%, transparent);
}

/* Ticket status badges */
.status {
  display: inline-block;
  padding: 0.0625rem 0.5rem;
  border-radius: 1rem;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  vertical-align: middle;
}

.status-todo {
  background: var(--pico-muted-border-color);
  color: var(--pico-muted-color);
}

.status-doing {
  background: color-mix(in srgb, var(--pico-primary) 18%, transparent);
  color: var(--pico-primary);
}

.status-done {
  background: color-mix(in srgb, var(--pico-ins-color) 18%, transparent);
  color: var(--pico-ins-color);
}

/* Note cards in lists */
.note-item {
  margin-block: 0 0.75rem;
  padding: 0.75rem 1rem;

  h3 {
    margin-bottom: 0.25rem;
    font-size: 1.0625rem;

    small {
      margin-left: 0.5rem;
      font-weight: normal;
    }
  }

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

/*
 * Clickable cards and rows: the .stretched-link covers the whole .clickable element.
 * Other links inside stay on top so they remain clickable on their own.
 */
.clickable {
  position: relative;

  .stretched-link::after {
    content: "";
    position: absolute;
    inset: 0;
  }

  a:not(.stretched-link) {
    position: relative;
    z-index: 1;
  }

  &:not(article):hover,
  &:not(article):has(.stretched-link:focus-visible) {
    background-color: var(--pico-table-row-stripped-background-color);
  }
}

/*
 * Cards (and their header/footer sections) keep their own background,
 * so the same tint is layered on top of it.
 */
article.clickable:is(:hover, :has(.stretched-link:focus-visible)),
article.clickable:is(:hover, :has(.stretched-link:focus-visible)) > :is(header, footer) {
  background-image: linear-gradient(var(--pico-table-row-stripped-background-color), var(--pico-table-row-stripped-background-color));
}

tr.clickable:hover > td,
tr.clickable:has(.stretched-link:focus-visible) > td {
  background-color: var(--pico-table-row-stripped-background-color);
}

/* Card grid for projects and tags */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  gap: var(--pico-spacing);
  margin-bottom: var(--pico-spacing);

  > .card {
    display: flex;
    flex-direction: column;
    margin: 0;

    > p {
      margin-bottom: 0;
    }

    > footer {
      display: flex;
      flex-wrap: wrap;
      align-items: flex-end;
      justify-content: space-between;
      gap: 0.25rem 0.5rem;
      margin-top: auto;
    }

    .last-noted {
      margin-left: auto;
      white-space: nowrap;
    }
  }
}

.muted {
  color: var(--pico-muted-color);
}

.tag-badge {
  display: inline-block;
  margin: 0 0.25rem 0.25rem 0;
  padding: 0.0625rem 0.5rem;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: 1rem;
  font-size: 0.75rem;
  text-decoration: none;
}

/* Compact one-line forms (project links, milestones) that wrap on narrow screens. */
.inline-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5rem 0.75rem;
  margin-bottom: var(--pico-spacing);

  > div {
    flex: 1 1 9rem;
    min-width: 0;
  }

  > div.wide {
    flex: 3 1 16rem;
  }

  > div.narrow {
    flex: 0 1 6rem;
  }

  > .form-errors {
    flex-basis: 100%;
  }

  label {
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
  }

  :is(input, select),
  [type="submit"] {
    margin-bottom: 0;
  }
}

/* Page title with actions on the right (e.g. the edit button) */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-bottom: var(--pico-spacing);

  h1 {
    margin-bottom: 0;
  }
}

/* Label/value rows such as tech stack and links */
dl.meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  align-items: baseline;
  gap: 0.5rem 1rem;
  margin-bottom: var(--pico-spacing);

  dt {
    color: var(--pico-muted-color);
    font-size: 0.875rem;
  }

  dd {
    margin: 0;
  }
}

/* Small square button such as "+" */
button.icon-button {
  width: auto;
  margin: 0;
  padding: 0 0.5rem;
  font-size: 0.875rem;
  line-height: 1.5;
  vertical-align: baseline;
}

/* Rows with actions on the right, used in the links modal */
ul.item-list {
  padding: 0;

  > li {
    list-style: none;
    padding-block: 0.5rem;
    border-bottom: 1px solid var(--pico-muted-border-color);
  }
}

.item-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;

  .item-main {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .item-actions {
    white-space: nowrap;
  }

  /* The edit form replaces the row inside the same turbo frame. */
  > form {
    flex-basis: 100%;
  }
}

dialog > article {
  width: min(48rem, 100%);
}

/* A row of actions, filters, and toggles above a list */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;

  a[role="button"].action {
    margin: 0;
  }

  .show-completed {
    margin: 0 0 0 auto;
    font-size: 0.875rem;
  }
}

/* Roadmap: milestones with ticket progress */
.roadmap-list {
  padding: 0;
}

.roadmap-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(8rem, 1fr) minmax(12rem, 2fr) 7rem;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--pico-muted-border-color);
  list-style: none;

  .roadmap-due {
    text-align: right;
  }

  /* Narrow screens: name and due date on the first line, progress below. */
  @media (width < 640px) {
    grid-template-columns: 1fr auto;

    .progress {
      grid-column: 1 / -1;
      order: 1;
    }
  }
}

/* Completed milestones are hidden unless "show completed" is checked. */
.roadmap:not(:has(.show-completed input:checked)) .roadmap-row.completed {
  display: none;
}

.roadmap-due {
  font-size: 0.875rem;
  white-space: nowrap;

  &.overdue {
    color: var(--pico-del-color);
    font-weight: 600;
  }
}

/* Stacked progress bar: done / doing / todo */
:root {
  /* Amber, brighter than the green done color so the two are easy to tell apart. */
  --app-progress-doing: light-dark(#eba23a, #f5c46e);
}

.progress {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.progress-bar {
  display: flex;
  flex: 1 1 auto;
  height: 0.625rem;
  min-width: 6rem;
  overflow: hidden;
  border-radius: 1rem;
  background: var(--pico-muted-border-color);

  > .progress-done {
    background: var(--pico-ins-color);
  }

  > .progress-doing {
    background: var(--app-progress-doing);
  }

  > .progress-todo {
    background: color-mix(in srgb, var(--pico-muted-color) 40%, transparent);
  }
}

.progress-text {
  font-size: 0.8125rem;
  color: var(--pico-muted-color);
  white-space: nowrap;
}

/* Destructive actions at the bottom of a page */
.danger-zone {
  margin-top: calc(var(--pico-spacing) * 2);
  padding-top: var(--pico-spacing);
  border-top: 1px solid var(--pico-muted-border-color);
}

/* Checkbox choices laid out side by side (tech stack, tickets) */
.check-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;

  label {
    margin: 0;
  }
}

/* Ticket choices in the note form, one row per status */
.ticket-choices {
  display: grid;
  grid-template-columns: max-content 1fr;
  align-items: baseline;
  gap: 0.5rem 1rem;
}

.ticket-status-row {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: subgrid;
  align-items: baseline;
}

.ticket-status-label {
  color: var(--pico-muted-color);
  font-size: 0.875rem;
}

.ticket-choices > .show-done {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 0.875rem;
}

/* Done tickets are hidden unless "show" is checked. */
.ticket-choices:not(:has(.show-done input:checked)) .ticket-status-done .check-options {
  display: none;
}
