/*
 * Time tracking (024): the Time worked rows inside Log update and Log time,
 * the home page's Log time dialog and its search results, and a time entry
 * in a list (Activity, My hours today, a person's log). Entries reuse
 * .activity-item (activity_feed.css); everything here is tokens only.
 */
@layer components {
  /* The rows: one per person, the person's name (or a person select) then
     the hours. A nested fieldset, so forms.css gives it a hairline and a
     body-strong legend. */
  .time-worked {
    display: grid;
    gap: var(--space-2);
    margin: 0;

    & > p,
    & > p + p {
      margin: 0;
      max-inline-size: none;
    }
  }

  .time-worked__row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    margin: 0;

    /* The own row's label is the person's name, beside the hours. */
    & > label {
      flex: 0 0 12rem;
      font: var(--text-body);
    }

    & select {
      inline-size: auto;
      min-inline-size: 8rem;
    }

    & select[name$="[person_id]"] {
      min-inline-size: 14rem;
    }
  }

  .time-worked__others {
    display: grid;
    gap: var(--space-2);

    & > summary {
      font: var(--text-small);
      color: var(--color-muted);
      cursor: pointer;
    }

    & > p + p {
      margin-block-start: 0;
    }
  }

  .time-worked__hint {
    margin: 0;
    font: var(--text-small);
    color: var(--color-muted);
  }

  /* The prominent Log time button beside the user's name on /. */
  .home__log-time {
    margin-inline-start: auto;
  }

  /* The Log time dialog: the search, then the results the radios live in,
     the date and the rows. */
  .log-time__search {
    margin: 0;

    & input[type="search"] {
      inline-size: 100%;
      max-inline-size: none;
    }
  }

  .log-time__form {
    display: grid;
    gap: var(--space-4);

    & > p,
    & > p + p {
      margin: 0;
      max-inline-size: none;
    }
  }

  .log-time__subjects {
    margin: 0;
    padding: 0;
    border: 0;
  }

  .log-time-results {
    display: grid;
    gap: var(--space-1);
    max-block-size: 20rem;
    overflow-y: auto;
    padding: 0;
    list-style: none;

    & > li,
    & > li + li {
      margin: 0;
      max-inline-size: none;
    }
  }

  /* One result reads as a row: the radio, then badge, period and wording. */
  .log-time-results__item {
    display: flex;
    align-items: baseline;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-s);

    &:hover,
    &:has(input:checked) {
      background: var(--color-surface);
    }
  }

  .log-time-results__label {
    font: var(--text-small);
    color: var(--color-text);
    cursor: pointer;

    & .badge {
      margin-inline-end: var(--space-1);
    }
  }

  .log-time-results__period,
  .log-time-results__parent {
    margin-inline-end: var(--space-1);
    color: var(--color-muted);
  }

  .log-time-results__parent {
    display: block;
  }

  .log-time-results__empty {
    margin: 0;
    font: var(--text-small);
    color: var(--color-muted);
  }

  /* A time entry in a list: Change opens in place below the meta line, which
     wraps in a narrow column (a person's log). */
  .time-entry .activity-item__meta {
    flex-wrap: wrap;
    align-items: center;
  }

  /* Change is a control beside Delete, not a section: no hairline or top
     padding from the base <details> rule, and its summary looks like the
     small outlined button_to Delete is (buttons.css). Open, the disclosure
     takes its own row below the meta line, so Delete stays where it was. */
  .time-entry__change {
    padding: 0;
    border: 0;

    & > summary {
      display: inline-block;
      padding: var(--space-1) var(--space-3);
      border: 1px solid var(--color-line);
      border-radius: var(--radius-s);
      list-style: none;
      font: var(--text-small);
      font-weight: 500;
      color: var(--color-text);
      cursor: pointer;

      &::-webkit-details-marker {
        display: none;
      }

      &:hover {
        background: var(--color-paper);
        border-color: var(--color-text);
        color: var(--color-ink);
      }
    }

    &[open] {
      flex-basis: 100%;
      order: 1;
    }

    &[open] > summary {
      margin-block-end: 0;
      background: var(--color-paper);
      border-color: var(--color-text);
      color: var(--color-ink);
    }
  }

  .time-entry__form {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: var(--space-3);
    margin-block-start: var(--space-2);

    & > p,
    & > p + p {
      margin: 0;
    }

    /* Save sits in the row with the fields: no actions-row hairline. */
    & > p:has(> input[type="submit"]) {
      margin: 0;
      padding: 0;
      border: 0;
    }

    & select,
    & input[type="date"] {
      inline-size: auto;
    }
  }

  .time-entries__total {
    margin-block-start: var(--space-3);
    font: var(--text-small);
    color: var(--color-muted);

    & strong {
      color: var(--color-ink);
    }
  }
}
