/*
 * THE RUN'S FEED. Flat rows on one left edge — no indent, collapsed or expanded —
 * so the timeline reads as a column of moments rather than a tree.
 *
 * The row's wash BLEEDS 8px past its content on each side (equal negative margin
 * and padding, net zero for layout), so its rounded edges never pinch against the
 * leading dot and the feed's left edge still meets the consumer's own gutter.
 *
 * Everything below a pressable row indents past the DOT COLUMN — the panel is that
 * row's sub-content, and the one number both read is declared once here.
 */
@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 of this anatomy —
     the pane's feed, the pill's panel — resets them rather than inheriting. */
  .lotics-agent-run {
    /* The dot IS a stepper `Marker`, and a Marker declares `--lotics-stepper-node`
       on ITSELF — so the column that seats it cannot read that value and states
       the same measure here instead. It must equal `stepper_layout.ts`'s `NODE`. */
    --lotics-agent-run-node: 24px;
    /* Dot to body. The panels below a row indent past both. */
    --lotics-agent-run-gap: var(--lotics-space-10);
    --lotics-agent-run-inset: calc(var(--lotics-agent-run-node) + var(--lotics-agent-run-gap));
  }

  /* THE FEED's own column. Scoped, because the pane's root is a SCROLLER wearing
     this same class and a `flex-direction: column` on it fights the
     `column-reverse` the follow is built out of. */
  .lotics-agent-run[data-variant="feed"] {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--lotics-agent-run-gap);
    min-width: 0;
  }

  /* One segment, the rows a settled group rolls out, and the decided calls a closed
     fold keeps on screen — all step rows against step rows, a rung tighter than the
     run's own 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 own 13.33px face to anything the
       row holds that does not state a 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; the disclosure below asks for
       the hand back. */
    cursor: auto;
    user-select: none;
    transition: background-color var(--lotics-duration-fast) var(--lotics-ease-standard);
  }

  /* A DISCLOSURE acts, so it takes the pointer (`control_surface.ts`'s
     `CURSOR_ACTION`), and the washes are §2.3's row for a control on the page. */
  .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 rather than sizing to its own glyphs:
     `text-overflow` needs a box narrower than the text to have anything 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 BREATH, and the ONE rhythm every unsettled row shares — the same 1500ms the
     marker's live halo runs, so a row's dot and its 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 is what the duration tokens cannot retime: collapsed to
     1ms the breath strobes instead of stopping — see 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;
    }
  }

  /* No horizontal self-inset: the run sits flush so the CONSUMER'S gutter governs
     alignment. */
  .lotics-agent-run__narration {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    min-width: 0;
  }

  /* The folded work, opened: segment spacing (the run's own gap), and a small
     lead-in under the header so the rolled-out work reads as its content. */
  .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;
  }

  /* A row's sub-content starts where its LABEL starts. */
  .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: the run inside a dialog ─────────────────────────────────────
     Its ROOT is whichever scroller the phase calls for — `FollowScroll` while the
     transcript grows, `DialogScrollArea` once the agent asks — so one class reaches
     the box in both. The gutter is the DIALOG's own token, so this band shares the
     left edge of the header, the footer and the close row. */
  .lotics-agent-run[data-variant="pane"] .lotics-agent-run__content {
    padding-inline: var(--lotics-dialog-gutter);
    /* Air under the newest row, so a feed pinned to the bottom does not end on
       the dialog's own 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: the run out of the way ──────────────────────────────────────
     Its geometry is the `Composer` compact pill's — same minimum height, same full
     radius, the same left inset for the mark — so the composer→run swap reads as a
     MORPH. The two gutters are a 4-grid the 8-grid does not name, written as offsets
     from the rungs so a theme that moves 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 pill, not a control rung: it holds a 32px mark and reads as a floating
       surface, 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, the `<button>` trap `button.css` documents: a root that names a
       family and stops keeps the UA's own 13.33px face for everything it hands
       down. */
    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);
  }

  /* The wash rides OVER the pill's own ground rather than replacing it, so a
     themed `--card` still shows through (the ladder `button.css` set). */
  .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;
  }

  /* A DIRECT child, so it reaches the pill's own label and not the feed's step
     labels inside the panel — the panel holds a whole run of this same anatomy. */
  .lotics-agent-run__pill > .lotics-agent-run__label {
    flex: 1;
    min-width: 0;
  }
}
