@layer cinder.tokens, cinder.foundation, cinder.components, cinder.utilities;
@import '/assets/f47cf25678047dc1d0c5372c25b330b4ffdf35604610caa62c68ff9ad26b877e/components/button/button.css';
@import '/assets/f47cf25678047dc1d0c5372c25b330b4ffdf35604610caa62c68ff9ad26b877e/components/form-field/form-field.css';

@layer cinder.components {
  /* ========================================
 * SETTING ROW
 *
 * Label, raw key and description on the left, with the save status, the error and the managed line
 * under them; the control on the right in a fixed column (rows 47i–47n). Below a container width
 * (row 50i) the control stacks under the label and the row reads as one column.
 * ======================================== */

  /* Every row is at least 44px tall, the height of a record-details row (InspectorRow), so a
     settings page and a details page share one rhythm. */
  .cinder-setting-row {
    container-type: inline-size;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: var(--cinder-space-2);
    min-block-size: 2.75rem;
  }

  /* Doubled with the form field's own class, so the grid wins over `.cinder-form-field`'s flex
     column whichever stylesheet a bundle puts last. */
  .cinder-form-field.cinder-setting-row__field {
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--cinder-setting-row-control-width, 15rem);
    column-gap: var(--cinder-space-6);
    /* The control spans every row of the left column, so rows add no gap of their own and each
       line sets its own space above it. */
    row-gap: 0;
    align-items: start;
  }

  .cinder-setting-row__field > * {
    grid-column: 1;
    min-inline-size: 0;
  }

  /* The control is whichever child is not one of the text lines. */
  .cinder-setting-row__field
    > :not(
      .cinder-form-field__label,
      .cinder-form-field__label-row,
      .cinder-form-field__description,
      .cinder-form-field__note,
      .cinder-form-field__warning,
      .cinder-form-field__managed,
      .cinder-form-field__error,
      .cinder-setting-row__status
    ) {
    grid-column: 2;
    grid-row: 1 / span 8;
    /* Aligned to the end, the control sizes to its content; a control that sets its own size,
       such as a switch, keeps it. */
    justify-self: end;
    align-self: center;
    max-inline-size: 100%;
  }

  /* `controlAlign="stretch"`: the control fills its column instead of sitting at the end. */
  .cinder-setting-row[data-cinder-control-align='stretch']
    .cinder-setting-row__field
    > :not(
      .cinder-form-field__label,
      .cinder-form-field__label-row,
      .cinder-form-field__description,
      .cinder-form-field__note,
      .cinder-form-field__warning,
      .cinder-form-field__managed,
      .cinder-form-field__error,
      .cinder-setting-row__status
    ) {
    justify-self: stretch;
  }

  .cinder-setting-row__field .cinder-form-field__label {
    font-size: var(--cinder-text-base);
    font-weight: var(--cinder-font-semibold);
  }

  .cinder-setting-row__field .cinder-form-field__label-row {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    column-gap: var(--cinder-space-2);
  }

  .cinder-setting-row__identifier {
    font-family: var(--cinder-font-mono);
    font-size: var(--cinder-text-xs);
    color: var(--cinder-text-muted);
    overflow-wrap: anywhere;
  }

  .cinder-setting-row__field .cinder-form-field__description,
  .cinder-setting-row__field .cinder-form-field__note,
  .cinder-setting-row__field .cinder-form-field__warning {
    margin-block-start: var(--cinder-space-0-5);
    font-size: var(--cinder-text-sm);
  }

  /* A setting can sit in a wide page column, but its explanatory sentence stays at a readable
     measure. Notes and warnings retain the row's full available width because their contents can
     be operational detail rather than prose. */
  .cinder-setting-row__field .cinder-form-field__description {
    max-inline-size: var(--cinder-content-width-prose);
  }

  /* The status, managed and error lines sit one step under the description. */
  .cinder-setting-row__status:empty {
    display: none;
  }

  .cinder-setting-row__field .cinder-form-field__managed,
  .cinder-setting-row__field .cinder-form-field__error[data-cinder-error],
  .cinder-setting-row__status {
    margin-block-start: var(--cinder-space-1-5);
  }

  .cinder-setting-row__field .cinder-form-field__managed {
    color: var(--cinder-text-default);
  }

  .cinder-setting-row__status {
    font-size: var(--cinder-text-xs);
    line-height: var(--cinder-leading-normal);
    color: var(--cinder-text-muted);
  }

  .cinder-setting-row__status-line {
    display: inline-flex;
    align-items: center;
    gap: var(--cinder-space-1-5);
  }

  .cinder-setting-row__status-line[data-cinder-status='saved'] {
    color: var(--cinder-status-success-text);
  }

  .cinder-setting-row__status-line[data-cinder-status='saved-restart'] {
    font-weight: var(--cinder-font-medium);
  }

  .cinder-setting-row__glyph {
    flex: none;
  }

  .cinder-setting-row__glyph--spinning {
    animation: cinder-setting-row-spin 1.2s linear infinite;
  }

  @keyframes cinder-setting-row-spin {
    to {
      transform: rotate(360deg);
    }
  }

  @media (prefers-reduced-motion: reduce) {
    :root:not([data-cinder-reduced-motion='false']):not([data-reduced-motion='off'])
      .cinder-setting-row__glyph--spinning {
      animation: none;
    }
  }

  /* The amber dot of "Saved, waiting for a restart": the word stays neutral. */
  .cinder-setting-row__dot {
    flex: none;
    inline-size: 0.5rem;
    block-size: 0.5rem;
    border-radius: var(--cinder-radius-full);
    background: var(--cinder-status-warning-indicator);
  }

  @media (forced-colors: active) {
    .cinder-setting-row__dot {
      background: Highlight;
    }
  }

  /* A quiet Retry beside a failed save: an accent link, semibold, underlined, no chrome. */
  .cinder-setting-row__retry {
    padding: 0;
    border: 0;
    background: none;
    font: inherit;
    font-weight: var(--cinder-font-semibold);
    color: var(--cinder-accent-text);
    text-decoration: underline;
    text-underline-offset: 0.15em;
    cursor: pointer;
  }

  .cinder-setting-row__retry:focus-visible {
    outline: var(--cinder-ring-width) solid var(--cinder-ring-color);
    outline-offset: 2px;
    border-radius: var(--cinder-radius-sm);
  }

  @media (any-pointer: coarse) {
    .cinder-setting-row__retry {
      position: relative;
    }

    /* Keep the inline link's line height while making the button easier to touch. */
    .cinder-setting-row__retry::after {
      position: absolute;
      inset-block: min(0px, calc((100% - var(--cinder-touch-target-min)) / 2));
      inset-inline: 0;
      content: '';
    }
  }

  /* `stacked` is an owner-selected runtime state, for a page that knows its viewport policy. */
  /* @runtime-state */

  /* Narrow: the label and its description lead, the control stacks under them, and the status, the
     managed line and the error sit directly under the control (row 50i). Order reads the lines
     into that sequence whatever the markup order is. */
  @container (inline-size < 30rem) or style(--cinder-setting-row-stack: stacked) {
    .cinder-form-field.cinder-setting-row__field {
      display: flex;
      flex-direction: column;
      align-items: stretch;
      row-gap: var(--cinder-space-1-5);
    }

    .cinder-setting-row__field
      > :not(
        .cinder-form-field__label,
        .cinder-form-field__label-row,
        .cinder-form-field__description,
        .cinder-form-field__note,
        .cinder-form-field__warning,
        .cinder-form-field__managed,
        .cinder-form-field__error,
        .cinder-setting-row__status
      ) {
      align-self: stretch;
      justify-self: auto;
      order: 2;
    }

    .cinder-setting-row__field .cinder-form-field__description,
    .cinder-setting-row__field .cinder-form-field__note,
    .cinder-setting-row__field .cinder-form-field__warning {
      order: 1;
    }

    .cinder-setting-row__field .cinder-form-field__managed,
    .cinder-setting-row__status {
      order: 3;
    }

    .cinder-setting-row__field .cinder-form-field__error {
      order: 4;
    }

    /* The row gap spaces the lines now, so they add none of their own. */
    .cinder-setting-row__field .cinder-form-field__description,
    .cinder-setting-row__field .cinder-form-field__note,
    .cinder-setting-row__field .cinder-form-field__warning,
    .cinder-setting-row__field .cinder-form-field__managed,
    .cinder-setting-row__field .cinder-form-field__error[data-cinder-error],
    .cinder-setting-row__status {
      margin-block-start: 0;
    }
  }
}
