/*
 * THE LABELLED ACTION. `data-variant` carries emphasis, `data-tone` valence, so
 * `[data-tone="danger"]` is one selector across the kit and no variant name
 * compounds the two.
 *
 * Hover and press are painted two ways, by §2.3's pairing rule: a SURFACE ground
 * takes the neutral wash ladder, an alpha overlay that composites over whatever
 * the button sits on; a SOLID ground takes the on-solid STRENGTHS, mixed against
 * the ground itself so a themed primary stays its own colour. The danger tints
 * take the red family: a neutral wash over a red tint reads as greying out.
 */
@layer theme, base, lotics, components, utilities;
@layer lotics.tokens, lotics.reset, lotics.components;

@layer lotics.components {
  .lotics-button {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    /* A control never gives way: the label is already clamped, and a shrunk button
       is a verb nobody can read. A flex item shrinks by default, which ellipsised
       the verb in a column narrower than the label. */
    flex-shrink: 0;
    min-width: 0;
    position: relative;
    height: var(--lotics-control-height);
    /* 10 and 6 — the control's own inset and its icon gutter, each written as
       the rungs it is made of rather than as a number of its own. */
    padding-inline: var(--lotics-space-10);
    gap: var(--lotics-space-6);
    border: 0 solid var(--border);
    border-radius: var(--lotics-radius-control);
    background-color: transparent;
    background-image: none;
    /* §5 rule 1. A `<button>` carries the UA's own 13.33px font, so a root that
       states nothing hands that face to whatever it is given directly. */
    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);
    /* One declaration paints a variant: the glyph strokes the button's own ink. */
    --lotics-icon-color: currentColor;
    appearance: none;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    transition: background-color var(--lotics-duration-fast) var(--lotics-ease-standard);
  }

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

  .lotics-button__label {
    font-family: var(--font-sans);
    font-size: var(--lotics-text-sm);
    line-height: var(--lotics-leading-sm);
    letter-spacing: var(--lotics-tracking-sm);
    font-weight: var(--lotics-weight-medium);
    color: inherit;
    /* One line, ellipsised — a verb that wraps has stopped being a button. */
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .lotics-button[data-align="flex-start"] {
    align-self: flex-start;
  }
  .lotics-button[data-align="flex-end"] {
    align-self: flex-end;
  }
  .lotics-button[data-align="center"] {
    align-self: center;
  }
  .lotics-button[data-align="stretch"] {
    align-self: stretch;
  }
  .lotics-button[data-align="auto"] {
    align-self: auto;
  }

  /* ─── Grounds ─────────────────────────────────────────────────────────── */

  .lotics-button[data-variant="muted"] {
    color: var(--lotics-ink-muted);
  }

  .lotics-button[data-variant="secondary"] {
    background-color: var(--secondary);
    /* The ground's own ink pair, not the page's. */
    color: var(--secondary-foreground);
  }

  .lotics-button[data-tone="danger"] {
    color: var(--lotics-ink-danger);
  }

  .lotics-button[data-variant="tonal"][data-tone="danger"] {
    background-color: var(--lotics-wash-danger);
  }

  .lotics-button[data-variant="primary"] {
    background-color: var(--primary);
    color: var(--lotics-ink-on-inverse);
    /* Depth on the one filled control: a soft drop shadow lifts it off the surface
       and a whisper of top highlight catches the light. The overlay is the ground's
       own ink at low alpha, so the sheen reproduces over any themed hue. */
    box-shadow:
      inset 0 1px 0 color-mix(in srgb, var(--primary-foreground) 8%, transparent),
      0 1px 2px color-mix(in srgb, var(--lotics-shadow-color) 18%, transparent);
    background-image: linear-gradient(
      180deg,
      color-mix(in srgb, var(--primary-foreground) 14%, transparent) 0%,
      transparent 100%
    );
  }

  /* An outside brand is not on the kit's ladder, so it arrives as data and paints
     solid with the inverted ink. A button that is only WAITING keeps that ground; a
     disabled one falls back to its variant's wash. */
  .lotics-button[data-brand]:not([data-disabled]) {
    background-color: var(--lotics-button-brand);
    color: var(--lotics-ink-on-inverse);
  }
  .lotics-button[data-brand][data-loading] {
    background-color: var(--lotics-button-brand);
  }

  /* ─── Hover and press ─────────────────────────────────────────────────── */

  /* The SELECTION rung carries the hover, per §2.3's table: a button standing on
     the page has no selected state to collide with, and the 2% row rung is a
     hover nobody sees on a page ground. */
  .lotics-button:not([data-disabled]):hover {
    background-image: linear-gradient(
      0deg,
      var(--lotics-wash-selected),
      var(--lotics-wash-selected)
    );
  }
  .lotics-button:not([data-disabled]):active {
    background-image: linear-gradient(0deg, var(--lotics-wash-press), var(--lotics-wash-press));
  }

  .lotics-button[data-variant="tonal"][data-tone="danger"]:not([data-disabled]):hover {
    background-color: var(--lotics-wash-danger-hover);
    background-image: none;
  }
  .lotics-button[data-variant="tonal"][data-tone="danger"]:not([data-disabled]):active {
    background-color: var(--lotics-wash-danger-press);
    background-image: none;
  }
  .lotics-button[data-variant="ghost"][data-tone="danger"]:not([data-disabled]):hover {
    background-color: var(--lotics-wash-danger);
    background-image: none;
  }
  .lotics-button[data-variant="ghost"][data-tone="danger"]:not([data-disabled]):active {
    background-color: var(--lotics-wash-danger-hover);
    background-image: none;
  }

  .lotics-button[data-variant="primary"]:not([data-disabled]):hover {
    background-color: color-mix(
      in srgb,
      var(--primary-foreground) var(--lotics-on-solid-hover),
      var(--primary)
    );
    background-image: none;
  }
  .lotics-button[data-variant="primary"]:not([data-disabled]):active {
    background-color: color-mix(
      in srgb,
      var(--primary-foreground) var(--lotics-on-solid-press),
      var(--primary)
    );
    background-image: none;
  }

  /* The brand DARKENS where the primary lifts — its ink is white, so lifting toward
     the ink would wash the colour out. The rungs are the same ladder. */
  .lotics-button[data-brand]:not([data-disabled]):hover {
    background-color: color-mix(
      in srgb,
      var(--lotics-shadow-color) var(--lotics-on-solid-hover),
      var(--lotics-button-brand)
    );
    background-image: none;
  }
  .lotics-button[data-brand]:not([data-disabled]):active {
    background-color: color-mix(
      in srgb,
      var(--lotics-shadow-color) var(--lotics-on-solid-press),
      var(--lotics-button-brand)
    );
    background-image: none;
  }

  /* ─── Disabled ────────────────────────────────────────────────────────── */

  /* LOADING is not inactive: the button keeps its resting ground and only stops
     answering, so the wash is scoped to a genuinely disabled one. */
  .lotics-button[data-disabled] {
    color: var(--lotics-ink-inactive);
    cursor: default;
  }
  .lotics-button[data-variant="primary"][data-disabled] {
    color: var(--lotics-ink-on-inverse);
  }

  .lotics-button[data-disabled]:not([data-loading]) {
    background-image: none;
    box-shadow: none;
  }
  .lotics-button[data-variant="primary"][data-disabled]:not([data-loading]) {
    background-color: var(--lotics-wash-control-press);
  }
  .lotics-button[data-variant="secondary"][data-disabled]:not([data-loading]) {
    background-color: var(--lotics-wash-hover);
  }
  .lotics-button[data-variant="tonal"][data-tone="danger"][data-disabled]:not([data-loading]) {
    background-color: var(--lotics-wash-danger);
  }
}
