/*
 * THE COMMAND SURFACE, in two shapes on one anatomy: without `data-expanded` the compact pill
 * `AgentRun variant="pill"` morphs into, with it the full box. The focused edge keys on the
 * textarea's focus, not the shell's, so the send button's own ring is the only one when it holds
 * focus (§2.3). The mirror is absolutely positioned, so the field must win the stack or the tint
 * paints over the words.
 */
@layer theme, base, lotics, components, utilities;
@layer lotics.tokens, lotics.reset, lotics.components;

@layer lotics.components {
  .lotics-composer {
    /*
     * A tall click target at a fixed row, so the multiline field cannot balloon to its two-row
     * intrinsic size.
     */
    --lotics-composer-pill-height: 52px;
    --lotics-composer-compact-field-height: 44px;
    /* One number for field and mirror, or the tint drifts. */
    --lotics-composer-text-inset: var(--lotics-space-10);

    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    min-width: 0;
    min-height: var(--lotics-composer-pill-height);
    padding-inline: var(--lotics-space-6);
    border-width: 1.5px;
    border-style: solid;
    border-color: var(--border);
    border-radius: var(--lotics-radius-full);
    background-color: var(--card);
    transition: border-color var(--lotics-duration-fast) var(--lotics-ease-standard);
  }

  .lotics-composer[data-expanded] {
    gap: var(--lotics-space-8);
    min-height: auto;
    padding: var(--lotics-space-8);
    border-width: 2px;
    border-radius: var(--lotics-radius-card);
  }

  .lotics-composer:has(.lotics-composer__textarea:focus-within) {
    border-color: var(--ring);
  }

  .lotics-composer__pills {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--lotics-space-4);
    min-width: 0;
  }

  /* Sideways, since a second row of thumbnails pushes the field off a phone. */
  .lotics-composer__files {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: var(--lotics-space-8);
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .lotics-composer__extra {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    min-width: 0;
  }

  .lotics-composer__input {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: var(--lotics-space-6);
    min-width: 0;
  }

  .lotics-composer[data-expanded] .lotics-composer__input {
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    padding: var(--lotics-space-4);
  }

  .lotics-composer__lead,
  .lotics-composer__trail {
    display: flex;
    flex-direction: row;
    align-items: center;
    flex-shrink: 0;
  }

  .lotics-composer__field {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    position: relative;
    flex: 1;
    min-width: 0;
    height: var(--lotics-composer-compact-field-height);
  }

  /*
   * Floored at one line: the measurement arrives from a ref callback, so the first render has none.
   */
  .lotics-composer[data-expanded] .lotics-composer__field {
    flex: none;
    height: max(var(--lotics-input-leading), var(--lotics-composer-field-height));
  }

  .lotics-composer__textarea {
    display: block;
    flex: 1;
    width: 100%;
    min-width: 0;
    margin: 0;
    /* Above the mirror, on the published rung for in-flow content over a positioned sibling. */
    position: relative;
    z-index: var(--lotics-z-row-content);
    padding-inline: var(--lotics-composer-text-inset);
    padding-block: calc(
      (var(--lotics-composer-compact-field-height) - var(--lotics-input-leading)) / 2
    );
    border: 0 solid transparent;
    border-radius: 0;
    background-color: transparent;
    color: var(--lotics-ink-default);
    font-family: var(--font-sans);
    font-size: var(--lotics-input-text);
    line-height: var(--lotics-input-leading);
    letter-spacing: var(--lotics-input-tracking);
    font-weight: var(--lotics-weight-regular);
    font-feature-settings: var(--lotics-font-features);
    appearance: none;
    /* The shell paints the edge. */
    outline-style: none;
    /* A drag handle would fight the computed auto-grow height. */
    resize: none;
    overflow: hidden;
    cursor: text;
  }

  /* Expanded, the field is the box: the row already spent the inset. */
  .lotics-composer[data-expanded] .lotics-composer__textarea {
    padding: 0;
  }

  .lotics-composer__textarea[data-scroll] {
    overflow-y: auto;
  }

  .lotics-composer__overlay {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    position: absolute;
    inset: 0;
    overflow: hidden;
    padding-inline: var(--lotics-composer-text-inset);
    padding-block: calc(
      (var(--lotics-composer-compact-field-height) - var(--lotics-input-leading)) / 2
    );
    pointer-events: none;
  }

  .lotics-composer[data-expanded] .lotics-composer__overlay {
    padding: 0;
  }

  /*
   * The field's type rung and nothing else: a tracking of its own drifts the tint along a long
   * line.
   */
  .lotics-composer__mirror {
    display: block;
    color: transparent;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    font-family: var(--font-sans);
    font-size: var(--lotics-input-text);
    line-height: var(--lotics-input-leading);
    letter-spacing: var(--lotics-input-tracking);
    font-weight: var(--lotics-weight-regular);
    font-feature-settings: var(--lotics-font-features);
    transform: translateY(var(--lotics-composer-mirror-offset));
  }

  /* A ground behind the field's words, not coloured text. */
  .lotics-composer__highlight {
    /* A tint behind words, so softer than any control. */
    border-radius: calc(var(--lotics-radius-control) - var(--lotics-space-4));
    background-color: var(--lotics-tone-blue-strong);
  }

  .lotics-composer__placeholder {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    position: absolute;
    inset: 0;
    padding-inline: var(--lotics-composer-text-inset);
    pointer-events: none;
  }

  /*
   * Painted here because a prompt is field chrome, not a prose role. Anchored on the root, since a
   * lone part class ties with `.lotics-text` and resolves on emit order (`metric.css`).
   */
  .lotics-composer .lotics-composer__placeholder-text {
    color: var(--lotics-ink-placeholder);
  }

  .lotics-composer[data-expanded] .lotics-composer__placeholder {
    justify-content: flex-start;
    padding-inline: 0;
    padding-block-start: var(--lotics-space-2);
  }

  .lotics-composer__footer {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: var(--lotics-space-8);
    min-width: 0;
    /* Above the positioned mirror. */
    z-index: var(--lotics-z-row-content);
  }

  .lotics-composer__footer-left,
  .lotics-composer__footer-right {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: var(--lotics-space-8);
  }
}
