/*
 * THE RUN'S FEED. Flat rows on one left edge so the timeline reads as a column of moments, not a
 * tree. The row's wash bleeds 8px (equal negative margin and padding) so its corners never pinch
 * the dot; sub-content indents past the dot column.
 */
@layer theme, base, lotics, components, utilities;
@layer lotics.tokens, lotics.reset, lotics.components;

@layer lotics.components {
  /*
   * On the bare root, so a run nested in another presentation resets them rather than inheriting.
   */
  .lotics-agent-run {
    /*
     * A Marker declares `--lotics-stepper-node` on itself, so its column restates it; must equal
     * `stepper_layout.ts`'s `NODE`.
     */
    --lotics-agent-run-node: 24px;
    --lotics-agent-run-gap: var(--lotics-space-10);
    --lotics-agent-run-inset: calc(var(--lotics-agent-run-node) + var(--lotics-agent-run-gap));
  }

  /*
   * Scoped: the pane's root is a scroller wearing this class, and `flex-direction: column` would
   * fight its `column-reverse` follow.
   */
  .lotics-agent-run[data-variant="feed"] {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--lotics-agent-run-gap);
    min-width: 0;
  }

  /* Step rows against step rows sit a rung tighter than the run's rhythm. */
  .lotics-agent-run__group,
  .lotics-agent-run__step,
  .lotics-agent-run__steps,
  .lotics-agent-run__kept {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--lotics-space-2);
    min-width: 0;
  }

  .lotics-agent-run__row {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: var(--lotics-agent-run-gap);
    min-height: var(--lotics-control-height);
    min-width: 0;
    margin-inline: calc(var(--lotics-row-wash-bleed) * -1);
    padding-inline: var(--lotics-row-wash-bleed);
    border: 0 solid var(--border);
    border-radius: var(--lotics-radius-control);
    background-color: transparent;
    /* §5 rule 1 — a `<button>` hands the UA's 13.33px face to anything that states no rung. */
    font-family: var(--font-sans);
    font-size: var(--lotics-text-sm);
    line-height: var(--lotics-leading-sm);
    letter-spacing: var(--lotics-tracking-sm);
    color: var(--lotics-ink-default);
    text-align: start;
    appearance: none;
    /* A row that only reports is not a control. */
    cursor: auto;
    user-select: none;
    transition: background-color var(--lotics-duration-fast) var(--lotics-ease-standard);
  }

  /* A disclosure takes the pointer (`CURSOR_ACTION`); the washes are §2.3's row for a control. */
  .lotics-agent-run__row[data-control] {
    cursor: pointer;
  }

  .lotics-agent-run__row[data-control]:hover {
    background-color: var(--lotics-wash-selected);
  }

  .lotics-agent-run__row[data-control]:active {
    background-color: var(--lotics-wash-press);
  }

  .lotics-agent-run__row[data-control]:focus-visible {
    outline: var(--lotics-ring-width) solid var(--ring);
    outline-offset: 0;
  }

  .lotics-agent-run__dot {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: var(--lotics-agent-run-node);
  }

  /* A column, so the label fills the body and `text-overflow` has something to trim. */
  .lotics-agent-run__body {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    flex: 1;
    min-width: 0;
  }

  .lotics-agent-run__chevron {
    flex-shrink: 0;
    --lotics-icon-color: var(--lotics-ink-muted);
  }

  /* The same 1500ms as the marker's live halo, so dot and label breathe together. */
  .lotics-agent-run__label[data-live] {
    animation-name: lotics-agent-run-breath;
    animation-duration: calc(var(--lotics-duration-slow) * 6.25);
    animation-timing-function: var(--lotics-ease-standard);
    animation-iteration-count: infinite;
  }

  /* An infinite animation collapsed to 1ms strobes instead of stopping (docs/theming.md §2.3). */
  @media (prefers-reduced-motion: reduce) {
    .lotics-agent-run__label[data-live] {
      animation: none;
    }
  }

  @keyframes lotics-agent-run-breath {
    0% {
      opacity: 1;
    }
    50% {
      opacity: 0.6;
    }
    100% {
      opacity: 1;
    }
  }

  /* Flush, so the consumer's gutter governs alignment. */
  .lotics-agent-run__narration {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    min-width: 0;
  }

  .lotics-agent-run__work {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--lotics-agent-run-gap);
    padding-block-start: var(--lotics-space-6);
    min-width: 0;
  }

  .lotics-agent-run__reasoning,
  .lotics-agent-run__detail {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--lotics-space-8);
    padding-inline-start: var(--lotics-agent-run-inset);
    min-width: 0;
  }

  .lotics-agent-run__reasoning {
    padding-block-end: var(--lotics-space-4);
  }

  .lotics-agent-run__detail {
    padding-block-start: var(--lotics-space-2);
    padding-block-end: var(--lotics-space-6);
  }

  /*
   * The pane's root is whichever scroller the phase calls for, so one class reaches both; the
   * gutter is the dialog's token so the band shares the header's edge.
   */
  .lotics-agent-run[data-variant="pane"] .lotics-agent-run__content {
    padding-inline: var(--lotics-dialog-gutter);
    /* Air under the newest row, so a bottom-pinned feed does not end on the dialog's edge. */
    padding-block-end: var(--lotics-space-24);
  }

  .lotics-agent-run[data-variant="pane"] .lotics-agent-run__question {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--lotics-space-8);
    padding-block: var(--lotics-space-4);
    min-width: 0;
  }

  /*
   * The pill's geometry is the `Composer` compact pill's, so the swap reads as a morph. The 4-grid
   * gutters are offsets from the rungs so a theme moving the scale moves the pill.
   */
  .lotics-agent-run[data-variant="pill"] {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--lotics-space-8);
    min-width: 0;
  }

  .lotics-agent-run__panel {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    min-width: 0;
    overflow: hidden;
    border-radius: var(--lotics-radius-card);
    background: var(--card);
    box-shadow: 0 6px 24px color-mix(in srgb, var(--lotics-shadow-color) 10%, transparent);
  }

  .lotics-agent-run__pill {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: var(--lotics-space-10);
    /* A floating surface holding a 32px mark, so the height is its own measure. */
    min-height: 52px;
    padding-inline-start: var(--lotics-space-10);
    padding-inline-end: var(--lotics-space-16);
    padding-block: 0;
    margin: 0;
    border-radius: var(--lotics-radius-full);
    background-color: var(--card);
    color: var(--lotics-ink-default);
    /* §5 rule 1: a `<button>` root that stops at the family hands down the UA's 13.33px face. */
    font-family: var(--font-sans);
    font-size: var(--lotics-text-sm);
    line-height: var(--lotics-leading-sm);
    letter-spacing: var(--lotics-tracking-sm);
    box-shadow: 0 4px 14px color-mix(in srgb, var(--lotics-shadow-color) 8%, transparent);
    appearance: none;
    cursor: pointer;
    text-align: start;
    transition-property: background-color;
    transition-duration: var(--lotics-duration-fast);
    transition-timing-function: var(--lotics-ease-standard);
  }

  /* Over the pill's ground rather than replacing it, so a themed `--card` shows through. */
  .lotics-agent-run__pill:hover {
    background-image: linear-gradient(
      0deg,
      var(--lotics-wash-selected),
      var(--lotics-wash-selected)
    );
  }

  .lotics-agent-run__pill:active {
    background-image: linear-gradient(0deg, var(--lotics-wash-press), var(--lotics-wash-press));
  }

  .lotics-agent-run__pill:focus-visible {
    outline: var(--lotics-ring-width) solid var(--ring);
    outline-offset: 0;
  }

  /* Direct child: the panel holds a whole run of this same anatomy. */
  .lotics-agent-run__pill > .lotics-agent-run__label {
    flex: 1;
    min-width: 0;
  }
}
