/*
 * ObjectiveDetailComponent: what is particular to the objective's page. The
 * layout (header, main column, sidebar) lives in detail.css, rendered through
 * DetailPageComponent.
 */
@layer components {
  /* The wording as plain text, when the objective is archived. */
  .objective-detail__title {
    font: var(--text-title);
    color: var(--color-muted);
    max-inline-size: none;
  }

  /* Completed (015): the wording in full colour, the header strip green. */
  .objective-detail--completed {
    & .objective-detail__title {
      color: var(--color-text);
    }

    & .detail__header {
      padding-inline-start: var(--space-3);
      border-inline-start: var(--space-1) solid var(--color-positive);
      background: var(--color-positive-surface);
    }
  }

  /*
   * A closed objective's header strip (015, Max 2026-11-12): it carries more
   * than fits on one line (Completed on … by …, Progress, assignees; Key
   * result of moved to the sidebar in 022), and squeezed into one row each
   * item wrapped on its own. Deliberate lines instead: the back link and the
   * state badge first, then each meta item on a row of its own, whole.
   */
  .objective-detail:is(.objective-detail--completed, .objective-detail--archived) .detail__header {
    flex-wrap: wrap;
    row-gap: var(--space-1);

    /* Each row starts where the back link's text does (.btn--small's inline padding). */
    & > .detail__meta {
      flex-basis: 100%;
      padding-inline-start: var(--space-3);
    }
  }

  /*
   * The title block (016): level badge, title and the target / due date
   * line as one tight group, closed by the divider that separates it from
   * Key results onward. Its first child sits at the column's top padding.
   */
  .objective-detail__heading {
    display: grid;
    gap: var(--space-2);
    padding-block-end: var(--space-5);
    border-block-end: var(--border);

    & > * {
      margin: 0;
    }
  }

  /* The heading's divider is the rule above Key results: no second one. */
  .objective-detail #key-results {
    border-block-start: 0;
  }

  /* The level above the title, in its colour (2026-11-12). */
  .objective-detail__level {
    margin: 0;
  }

  /*
   * An annual or quarterly objective's own number, on one line: the target
   * part (target, current value, progress) and the due date part, split by a
   * divider. For an editor each part is a button opening its dialog.
   */
  .objective-detail__measure {
    display: block;
  }

  .objective-detail__figures {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    margin: 0;
    max-inline-size: none;
  }

  .objective-detail__part {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: start;
  }

  button.objective-detail__part {
    cursor: pointer;

    &:hover {
      text-decoration: underline;
    }
  }

  .objective-detail__part--due {
    border-radius: 0;
    padding-inline-start: var(--space-3);
    border-inline-start: var(--border);
  }

  .objective-detail__target {
    font: var(--text-title);
    font-variant-numeric: tabular-nums;
  }

  /*
   * Funded by (020): the grant objectives an objective is linked to, each
   * its wording over its grant and state, with Unlink beside.
   */
  .funded-by__list {
    display: grid;
    gap: var(--space-3);
    margin: 0;
    padding: 0;
    list-style: none;

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

  .funded-by__item {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: var(--space-1) var(--space-2);
    align-items: start;
  }

  .funded-by__objective {
    font: var(--text-small);
    color: var(--color-ink);
  }

  .funded-by__grant {
    grid-column: 1;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: baseline;
    font: var(--text-small);
    color: var(--color-muted);
  }

  .funded-by__unlink {
    grid-column: 2;
    grid-row: 1 / span 2;
  }

  /*
   * The "Link grant objectives" dialog (020): the grant picker over the
   * chosen grant's objectives, each a row with Link or Linked at its end.
   */
  .grant-objective-picker__form {
    display: grid;
    gap: var(--space-2);
  }

  .grant-objective-picker {
    display: block;
    margin-block-start: var(--space-4);
  }

  .grant-objective-picker__list {
    display: grid;
    gap: var(--space-1);
    max-block-size: 24rem;
    overflow-y: auto;
    margin: 0;
    padding: 0;
    list-style: none;

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

  .grant-objective-picker__item {
    display: flex;
    gap: var(--space-3);
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-s);
    background: var(--color-surface);
  }

  .grant-objective-picker__description {
    font: var(--text-small);
    color: var(--color-ink);
  }

  .grant-objective-picker__empty {
    font: var(--text-small);
    color: var(--color-muted);
  }

  .grant-objective-picker__alert {
    margin-block-end: var(--space-3);
    font: var(--text-small);
    color: var(--color-negative);
  }

  /*
   * The "Add key result" target. The huge scroll margin clamps the scroll
   * position to the top of the page, so following the link never jumps.
   * Taken out of the heading's grid flow, so it adds no height or gap.
   */
  .objective-detail__anchor {
    position: absolute;
    scroll-margin-block-start: 100vh;
  }
}

/*
 * The summary (023): a few sentences under the title block saying what the
 * objective is about. Body text at reading width, line breaks kept. For an
 * editor it is the title form's in-place field at body size (chained, as
 * title_form.css loads later), growing with its text.
 */
@layer components {
  .objective-detail__summary {
    margin: 0;
    max-inline-size: var(--width-reading);
    white-space: pre-line;
    text-wrap: pretty;
  }

  .title-form.objective-detail__summary-form {
    max-inline-size: var(--width-reading);
  }

  .title-form__input.objective-detail__summary-input {
    font: var(--text-body);
    color: var(--color-text);
    text-wrap: pretty;
  }
}
