@layer components {
  /* A work permit being started: its task typed as the page's name, its facts as fields, each stage answered under its heading. */
  .permit .page-header__title .autoresize__textarea {
    border-block-end: 1px dashed var(--color-ink-medium);
    border-radius: 0;
    padding-block-end: 0.1em;
  }

  /* The first day, then for how many. */
  .permit__window {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 0.25em var(--inline-space);

    .input.permit__days {
      inline-size: 4.5em;
    }
  }

  /* A work permit's own page. Under its task: the act it takes or how it stands, who filled it in, and a word on what is missing. */
  .permit__head .finding__byline {
    margin-block: var(--block-space) 0;
  }

  /* Signed by a link: the same page with less on it, named by the task and ended by the pad. */
  .permit__signing {
    max-inline-size: 32rem;
  }

  /* On a phone the one act takes the line whole. */
  .permit .permit__sign {
    align-self: start;

    @media (max-width: 639px) {
      align-self: stretch;
    }
  }

  /* How it stands, where the button that closes it would be and as tall, with nothing to press: waiting, good in green, ended badly in red. */
  .permit__state {
    --btn-background: var(--color-meta-fill);
    --btn-hover-amount: 0%;

    cursor: default;

    .record-page__box {
      background-color: currentColor;

      .icon {
        color: var(--color-canvas);
      }
    }
  }

  .permit__state--success {
    --btn-background: color-mix(in srgb, var(--color-success) 10%, var(--color-canvas));
    --btn-border-color: color-mix(in oklch, var(--color-success) 45%, transparent);
    --btn-color: var(--color-success-text);
  }

  .permit__state--error {
    --btn-background: color-mix(in srgb, var(--color-error) 10%, var(--color-canvas));
    --btn-border-color: color-mix(in oklch, var(--color-error) 45%, transparent);
    --btn-color: var(--color-error-text);
  }

  /* Beside the button that closes it: what it authorises, or that its days are over. */
  .permit .permit__sentence {
    font-size: inherit;
    font-weight: 400;
    white-space: normal;
  }

  .permit__note {
    color: var(--color-meta);
    font-size: var(--text-control);
    margin: var(--block-space-half) 0 0;
  }

  /* Why it was cancelled, in the canceller's words. */
  .permit__reason {
    font-size: var(--text-row);
    margin: var(--block-space) 0 0;
    max-inline-size: 70ch;
  }

  .permit__aside {
    color: var(--color-meta);
  }

  /* The stages a work permit goes through, on one line: those passed ticked, the one it is at a tag with a stripe on top, those to come outlined. */
  .permit__steps {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    font-size: 0.875rem;                                /* 14px */
    gap: 4px 6px;
    line-height: 1.7;
    list-style: none;
    margin: 0;
    padding: 0.1em 0;

    @media (min-width: 100ch) {
      font-size: 0.842rem;                              /* 16px */
      line-height: 1.625;                               /* 26px */
    }
  }

  .permit__step {
    --icon-size: 0.875em;

    align-items: center;
    border-radius: var(--radius-md);
    color: var(--color-meta);
    display: inline-flex;
    gap: 4px;
    padding: 1px 9px;
    white-space: nowrap;

    .icon {
      color: var(--color-success);
    }
  }

  .permit__step--upcoming {
    box-shadow: inset 0 0 0 1px var(--color-ink-light);
  }

  .permit__step--current {
    --step-color: oklch(var(--lch-yellow-medium));
    --step-text: var(--color-warning-text);

    background-color: color-mix(in srgb, var(--step-color) 18%, var(--color-canvas));
    box-shadow: inset 0 3px 0 var(--step-color);
    color: var(--step-text);
    font-weight: 700;
  }

  .permit__step--success {
    --step-color: var(--color-success);
    --step-text: var(--color-success-text);
  }

  .permit__step--error {
    --step-color: var(--color-error);
    --step-text: var(--color-error-text);
  }

  .permit__step--ended {
    --step-color: var(--color-ink-medium);
    --step-text: var(--color-ink);
  }

  /* Who signs, one under the other: a round mark, ticked once signed, the part they sign as, and under it who signed and when.
     At the line's end the signature as drawn, or the ways to get it. */
  .signers {
    display: grid;
    list-style: none;
    margin: 0;
    padding: 0;
  }

  .signer {
    align-items: start;
    column-gap: 10px;
    display: grid;
    grid-template-columns: 1.5rem minmax(0, 1fr);
    padding-block: 2px;

    @media (min-width: 100ch) {
      grid-template-columns: 1.263rem minmax(0, 1fr) auto;   /* 24px */
    }
  }

  .signer__mark {
    --icon-size: 0.65em;

    aspect-ratio: 1;
    border: 1.5px solid var(--color-ink-medium);
    border-radius: 50%;
    display: grid;
    margin-block-start: calc((1lh - 1.5rem) / 2);
    place-content: center;

    @media (min-width: 100ch) {
      margin-block-start: calc((1lh - 1.263rem) / 2);
    }

    .signer--signed & {
      background-color: var(--color-success);
      border-color: var(--color-success);
      color: var(--color-canvas);
    }
  }

  .signer__body {
    display: flex;
    flex-direction: column;
    min-inline-size: 0;
  }

  .signer__detail {
    color: var(--color-meta);
    font-size: var(--text-pill);
    line-height: 1.5;
  }

  .signer__end {
    grid-column: 2;
    justify-self: start;
    margin-block: 4px;

    @media (min-width: 100ch) {
      align-self: center;
      grid-column: 3;
      margin-block: 0;
    }
  }

  .signer__actions {
    align-items: center;
    display: flex;
    font-size: var(--text-control);
    gap: 4px;

    .btn {
      --btn-padding: 0 0.7em;
      --icon-size: 1.2em;

      min-block-size: var(--control-size);
      min-inline-size: var(--control-size);
    }
  }

  /* One more to sign: a prompt on a dashed line under the last of them. */
  .signers__adding {
    margin-block-start: 0.25em;
    padding-inline-start: calc(1.5rem + 10px);

    @media (min-width: 100ch) {
      padding-inline-start: calc(1.263rem + 10px);
    }
  }

  .signers__add {
    background: none;
    border: 0;
    border-block-end: 1px dashed var(--color-ink-medium);
    color: var(--color-text-placeholder);
    cursor: pointer;
    font: inherit;
    inline-size: 100%;
    padding: 0.2em 0 0.3em;
    text-align: start;

    @media (any-hover: hover) {
      &:hover {
        color: var(--color-ink);
      }
    }
  }

  /* A stage as it was answered: the same lines, each showing at its end only what was chosen or written, and under it what was seen. */
  .stage--answered {
    .paper__options {
      display: flex;
      flex-wrap: wrap;
      gap: 0.1em 0.8em;

      @media (min-width: 100ch) {
        justify-content: flex-end;
      }
    }

    .paper__option {
      display: none;
    }

    .paper__option:is(.paper__option--chosen, .paper__option--right, .paper__option--wrong) {
      --btn-border-size: 0;
      --btn-padding: 0;

      display: inline-flex;
      font-weight: 600;
      min-block-size: 0;
      padding-block: 0;
    }

    .paper__option--right {
      --btn-color: var(--color-success-text);
    }

    .paper__option--wrong {
      --btn-color: var(--color-error-text);
    }

    .paper__box > .paper__written {
      font-weight: 600;
      margin: 0;

      @media (min-width: 100ch) {
        grid-column: 2;
        grid-row: 1 / span 3;
        justify-self: end;
        max-inline-size: 28em;
        text-align: end;
      }
    }

    .paper__box > :is(.paper__grid, .lexxy-content) {
      grid-column: 1 / -1;
    }

    .paper__blank {
      color: var(--color-meta);
      font-weight: 400;
    }

    .paper__note {
      margin: 0;
    }
  }

  /* Closing or cancelling is written at the foot of the thread, in the place and with the card of a finding's closing. */
  .comment--new .finding__closing {
    margin-block-start: 0;
  }

  /* A type of work permit: its note under its name, then what it is, and each stage with what it asks. */
  .page-header:has(+ .permit-type) {
    margin-block-end: 0.25rem;
  }

  .permit-type__head {
    > * {
      margin-block: 0;
    }

    .finding__byline {
      margin-block: var(--block-space-half) 0;
    }
  }

  .permit-type .stage__statement .txt-link {
    white-space: nowrap;
  }

  /* A stage's items answered where they are read: the question on its line, its answer at the line's end.
     The three answers of a conformity, and the options to pick one from, stand side by side as one control. */
  .stage {
    .paper__body,
    .paper__sections {
      display: grid;
      gap: var(--block-space);
    }

    .paper__section {
      gap: 0;
    }

    .paper__heading {
      font-size: var(--text-row);
      margin-block: var(--block-space-half) 0.2em;
    }

    .paper__count {
      color: var(--color-meta);
      font-size: var(--text-control);
      font-weight: 400;
    }

    .paper__questions {
      display: block;
      list-style: none;
      padding: 0;
    }

    .paper__number {
      display: none;
    }

    .paper__box {
      align-items: center;
      column-gap: var(--inline-space);
      display: grid;
      font-size: var(--text-row);
      grid-template-columns: minmax(0, 1fr);
      line-height: 1.5;
      padding-block: 0.33em;                            /* 6px */
      row-gap: 2px;

      @media (min-width: 100ch) {
        grid-template-columns: minmax(40%, 1fr) minmax(0, auto);

        > * {
          grid-column: 1;
        }

        > :is(.paper__options, .input.paper__line) {
          grid-column: 2;
          grid-row: 1 / span 3;
          justify-self: end;
        }

        > :is(.autoresize__wrapper, lexxy-editor, .paper__rows, .paper__note, .paper__missed) {
          grid-column: 1 / -1;
        }
      }
    }

    .paper__prompt {
      font-weight: 400;
    }

    .paper__box > .txt-small {
      color: var(--color-meta);
      font-size: var(--text-control);
    }

    .paper__options {
      margin: 0;
    }

    /* Several of a few: a pill to each, its own box to tick before its word. */
    .paper__options:has([type=checkbox]) {
      display: flex;
      flex-wrap: wrap;
      gap: 0.3rem;

      > .btn {
        --btn-padding: 0 0.7em 0 0.55em;

        font-size: var(--text-control);
        min-block-size: var(--control-size);

        &:has(:checked) {
          --btn-background: var(--color-canvas);
          --btn-border-color: var(--color-ink);
          --btn-color: var(--color-ink);

          font-weight: 600;
        }
      }

      > .btn > .checkbox {
        border-radius: 20%;
        font-size: 0.9em;
        inset: auto;
        position: static;
        transform: none;
      }
    }

    /* One answer of a few is a row of segments, good in green and wrong in red. Each field lies over its word, unseen. */
    .paper__options:has([type=radio]) > .btn {
      --btn-background: transparent;
      --btn-border-size: 0;

      flex: 1 1 auto;
      padding-block: 0;

      /* On a phone the answers take the line whole, a fingertip tall. */
      @media (max-width: 639px) {
        min-block-size: 2.25rem;
      }

      > .checkbox {
        block-size: auto;
        inline-size: auto;
        opacity: 0;
        transform: none;
      }

      &:has([value=ok]:checked) {
        background-color: color-mix(in srgb, var(--color-success) 12%, var(--color-canvas));
        box-shadow: 0 0 0 1px color-mix(in oklch, var(--color-success) 50%, transparent);
        color: var(--color-success-text);
      }

      &:has([value=not_ok]:checked) {
        background-color: color-mix(in srgb, var(--color-error) 12%, var(--color-canvas));
        box-shadow: 0 0 0 1px color-mix(in oklch, var(--color-error) 45%, transparent);
        color: var(--color-error-text);
      }
    }

    /* The paper says them in capitals; here they read as words. */
    .paper__options--conformity > .btn > span {
      display: inline-block;
      text-transform: lowercase;

      &::first-letter {
        text-transform: uppercase;
      }
    }

    .input.paper__line {
      inline-size: 14em;
      max-inline-size: 100%;

      &:is([type=number], [type=time]) {
        inline-size: auto;
      }
    }

    /* What was seen, on a quiet line under its item. */
    .paper__note {
      align-items: baseline;
      color: var(--color-meta);
      display: flex;
      font-size: var(--text-control);
      gap: var(--inline-space-half);

      .input.paper__line {
        --input-border-radius: 0;
        --input-padding: 0.1em 0;

        border-block-end: 1px dashed var(--color-ink-medium);
        border-width: 0 0 1px;
        flex: 1 1 auto;
        font-size: max(16px, 1em);
        inline-size: auto;
      }
    }

    .paper__missed {
      color: var(--color-error-text);
      font-size: var(--text-control);
      margin: 0;
    }
  }

  .stage__count {
    color: var(--color-meta);
    font-size: var(--text-control);
    font-weight: 400;
    letter-spacing: 0;
  }

  /* What those who release the work declare by signing: a quiet card under the stage's items. */
  .stage__statement {
    background-color: var(--color-meta-fill);
    border-radius: var(--radius-lg);
    font-size: 1rem;                                    /* 16px */
    line-height: 1.5;
    margin: 0;
    max-inline-size: 46rem;                             /* 872px */
    padding: 0.75em 1em;

    @media (min-width: 100ch) {
      font-size: 0.842rem;                              /* 16px */
    }
  }
}
