/*
 * THE SHELL PAINTS THE FIELD; the text element only holds the words. The two
 * optional slots are then flex ITEMS, and the focus ring sits on the shell via
 * `:focus-within`, painted once however many elements sit inside (§2.3).
 *
 * The height is a fixed number rather than a floor, because the line box a field
 * renders at is larger than the box it must occupy: at 16px the input rung leads
 * 26, and a 40px control would grow to 42 on a phone.
 *
 * A LINE BUDGET is that number times the input rung's own leading at THIS width
 * (`constitution.md` §10). An AUTO-GROWING field takes the taller of that floor
 * and its measured content plus the padding AND border: the box is `border-box`.
 */
@layer theme, base, lotics, components, utilities;
@layer lotics.tokens, lotics.reset, lotics.components;

@layer lotics.components {
  .lotics-text-input {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    min-width: 0;
    --lotics-text-input-floor: var(--lotics-control-height);
    height: var(--lotics-text-input-floor);
    border-width: 1px;
    border-style: solid;
    border-color: var(--input);
    border-radius: var(--lotics-radius-control);
    /* The field surface is a RAISED one on ANY ground — on a tinted panel a
       transparent field inherits the tint and stops reading as one. */
    background-color: var(--card);
    transition-property: border-color, outline-color;
    transition-duration: var(--lotics-duration-fast);
    transition-timing-function: var(--lotics-ease-standard);
  }

  /* The line budget, at the rung this width renders. `space-16` is the field's
     own padding, both sides — the same pair the input's `padding-block` spends. */
  .lotics-text-input[data-lines] {
    --lotics-text-input-floor: calc(
      var(--lotics-input-leading) * var(--lotics-text-input-lines) + var(--lotics-space-16)
    );
  }

  /* Grown, the box is the content plus that padding and the 1px edge each side. A
     literal rather than a property, because `inline_value.test.tsx` measures the
     declaration and a `var()` is not a length it can resolve. */
  .lotics-text-input[data-grow] {
    height: max(
      var(--lotics-text-input-floor),
      calc(var(--lotics-text-input-content) + var(--lotics-space-16) + 2px)
    );
  }

  .lotics-text-input__input {
    flex: 1;
    min-width: 0;
    align-self: stretch;
    margin: 0;
    padding-block: var(--lotics-space-8);
    padding-inline: var(--lotics-space-8);
    border-width: 0;
    border-style: solid;
    border-color: 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-input-weight);
    appearance: none;
    /* The shell owns the ring, so the element inside it must not draw a second. */
    outline-style: none;
    /* A drag handle would fight the auto-grow measurement the height comes from. */
    resize: none;
    cursor: text;
  }

  .lotics-text-input__input::placeholder {
    color: var(--lotics-ink-placeholder);
    /* Firefox dims a placeholder by default; the ink role already is the dim. */
    opacity: 1;
  }

  /* HOVER IS A DARKER EDGE, focus is the ring, and those are the only two. */
  .lotics-text-input:not([data-disabled]):hover {
    border-color: var(--lotics-border-hover);
  }

  /* The HOST paints the surface AND owns the text inset — one box, one owner.
     `border-width: 0`, not a transparent colour: a transparent border still
     occupies its pixel, stacking the host's inset on a second one. */
  .lotics-text-input[data-seamless] {
    border-width: 0;
    background-color: transparent;
  }

  .lotics-text-input__input[data-seamless] {
    padding-inline: 0;
  }

  /* CODE. The family only — the size stays the input rung, which is what keeps
     the field on the band and stops iOS zooming a focused one. */
  .lotics-text-input__input[data-font="mono"] {
    font-family: var(--font-mono);
  }

  /* HOW THE VALUE READS — a completed item, or an address. */
  .lotics-text-input__input[data-reading="struck"] {
    color: var(--lotics-ink-muted);
    text-decoration-line: line-through;
  }

  .lotics-text-input__input[data-reading="link"] {
    color: var(--lotics-accent);
    font-weight: var(--lotics-weight-medium);
    text-decoration-line: underline;
  }

  .lotics-text-input:focus-within {
    outline-width: var(--lotics-ring-width);
    outline-style: solid;
    outline-color: var(--ring);
    outline-offset: 0;
  }

  /* The shell's ring says TYPING GOES HERE, so it stands down when focus is on the
     ✕ instead — its own control, wearing its own ring (§2.3). */
  .lotics-text-input:has(.lotics-text-input__clear:focus-within) {
    outline-style: none;
  }

  .lotics-text-input[data-seamless]:focus-within {
    outline-style: none;
  }

  .lotics-text-input[data-disabled] {
    opacity: var(--lotics-disabled-opacity);
  }

  .lotics-text-input__input[data-disabled] {
    cursor: default;
  }

  /* THE LEADING GLYPH sits at the first line, so a multiline field's icon stays
     beside the line it annotates. */
  .lotics-text-input__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    align-self: flex-start;
    width: 20px;
    height: 20px;
    margin-block-start: var(--lotics-space-8);
    margin-inline-start: var(--lotics-space-8);
    --lotics-icon-color: var(--lotics-ink-inactive);
  }

  .lotics-text-input__input[data-icon] {
    padding-inline-start: var(--lotics-space-6);
  }

  /* Pinned to the TOP like the glyph: on an auto-grown field the ✕ stays reachable
     at the first line rather than floating mid-box. */
  .lotics-text-input__clear {
    display: flex;
    flex-shrink: 0;
    align-self: flex-start;
    margin-block-start: var(--lotics-control-pad-y);
    margin-inline-end: var(--lotics-space-6);
  }

  /* The button's own interior padding IS the visual gap, so the text may run up
     to the box edge. */
  .lotics-text-input__input[data-clear] {
    padding-inline-end: 0;
  }

  .lotics-text-input__shortcut {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    align-self: center;
    margin-inline-end: var(--lotics-space-12);
  }

  .lotics-text-input__input[data-shortcut] {
    padding-inline-end: 0;
  }
}
