/*
 * WHERE YOU ARE, painted in the INK THAT ACTS — `--primary`, which defaults to
 * near-black. A tab rail is the only thing on a screen that answers "which
 * section am I in", and a neutral grey underline would be indistinguishable from
 * a divider, so it has to be a token. Not the accent: on an unthemed screen its
 * blue would be the only blue anywhere, three pixels from a near-black CTA.
 *
 * The tab is THREE boxes. The button carries the underline and the 4px that
 * holds the wash off it; the `surface` inside carries the padding, the radius
 * and the hover/press ground — so a pointer wash reads as a rounded pill above
 * the rule rather than as a block running into it; the `line` inside that is the
 * label's own row, so a `caption` sits UNDER the words rather than beside them.
 */
@layer theme, base, lotics, components, utilities;
@layer lotics.tokens, lotics.reset, lotics.components;

@layer lotics.components {
  /* A STRIP SCROLLS ITSELF, whichever order it is in — but only once WRAPPING
     has run out. A BLOCK scroller, not a flex row: a flex row is an unshrinkable
     item at its max-content width, so the wrap below could never fire. The
     scroll is the last resort for what neither wraps nor scrolls itself. A
     SEQUENCE never wraps, so its BAR takes the scroll. */
  .lotics-tabs {
    display: block;
    min-width: 0;
    overflow-x: auto;
  }

  /* A SEQUENCE'S WALK IS ONE RUN — a wrapped flow reads as two pipelines — so
     the band that opens it and every stage after it are ONE box, and the box
     does not give. */
  .lotics-tabs__walk {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    flex-wrap: nowrap;
    flex-shrink: 0;
    gap: var(--lotics-space-4);
  }

  /*
   * THE EDGE THAT HAS STAGES BEHIND IT FADES, so the strip reads as continuing.
   *
   * A MASK rather than a painted gradient, because the strip sits on whatever
   * ground the surface gives it. A mask reads ALPHA only, so `currentcolor` here
   * is simply "opaque".
   */
  .lotics-tabs__list[data-ahead] {
    mask-image: linear-gradient(
      to right,
      currentcolor calc(100% - var(--lotics-tabs-fade)),
      transparent 100%
    );
  }

  .lotics-tabs__list[data-behind] {
    mask-image: linear-gradient(to right, transparent 0, currentcolor var(--lotics-tabs-fade));
  }

  .lotics-tabs__list[data-behind][data-ahead] {
    mask-image: linear-gradient(
      to right,
      transparent 0,
      currentcolor var(--lotics-tabs-fade),
      currentcolor calc(100% - var(--lotics-tabs-fade)),
      transparent 100%
    );
  }

  .lotics-tabs__stage {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    flex-shrink: 0;
  }

  /* Both joiners sit on the LABEL LINE rather than in the middle of the cell,
     because the cell's middle moves the moment one stage reserves a caption. */
  .lotics-tabs__chevron {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: var(--lotics-space-24);
    height: calc(var(--lotics-space-8) + var(--lotics-leading-sm));
    padding-block-start: var(--lotics-space-8);
    color: var(--lotics-ink-inactive);
  }

  /* The band that is not a stage, and the flow's outcomes: both stand OUTSIDE
     the walk, so both are fenced off it by the same rule — and neither gives,
     for the reason the walk does not. */
  .lotics-tabs__all,
  .lotics-tabs__outcomes {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    flex-shrink: 0;
    gap: var(--lotics-space-4);
  }

  /* The rule is a BOX the height of the label line with the hairline centred in
     it — a line starting at the pill's top edge reads as a column border. */
  .lotics-tabs__rule {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: var(--lotics-space-16);
    height: calc(var(--lotics-space-8) + var(--lotics-leading-sm));
    padding-block-start: var(--lotics-space-8);
  }

  .lotics-tabs__rule::before {
    content: "";
    width: 1px;
    height: 20px;
    background: var(--border);
  }

  /* The bar fills the scroller and wraps inside it, so a FREE strip too wide for
     its column takes a second line before it takes a scrollbar. What cannot wrap
     overflows, and the scroller above absorbs it. */
  .lotics-tabs__list {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    flex-wrap: wrap;
    gap: var(--lotics-space-4);
  }

  /* A SEQUENCE IS ONE LINE AND ONE BEHAVIOUR, so the BAR is what scrolls: a
     broken flow reads as two pipelines, and outcomes dropped behind the walk
     read as a second strip under the first. Nowrap, so nothing folds;
     `overflow-x`, so the run that no longer folds can still be reached. */
  .lotics-tabs__list[data-order="sequence"] {
    flex-wrap: nowrap;
    overflow-x: auto;
    /* How far the edge takes to go: one rung, so a stage is legible right up to
       where it starts to leave. */
    --lotics-tabs-fade: var(--lotics-space-24);
    /* AND THE FADE IS WHAT THE BROWSER KEEPS CLEAR: the browser's own scroll
       stops the moment the box touches the port, leaving the stage under the
       fade. The inset is the fade itself, so the two cannot drift. */
    scroll-padding-inline: var(--lotics-tabs-fade);
  }

  /* Declared on the TAB, not the strip: a sequence wraps it in a stage box, and
     a measure held by the strip's root would have to travel through it. */
  .lotics-tabs__tab {
    --lotics-tabs-dot: 6px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    flex-shrink: 0;
    margin: 0;
    padding: 0 0 var(--lotics-space-4);
    /* 3px of rule: the component's own measure, not a rung — a hairline would
       not read as a position and a 4th pixel starts to read as a bar. */
    border: 0 solid transparent;
    border-bottom-width: 3px;
    background: transparent;
    background-image: none;
    appearance: none;
    color: var(--lotics-ink-default);
    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-regular);
    font-feature-settings: var(--lotics-font-features);
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: border-color var(--lotics-duration-fast) var(--lotics-ease-standard);
  }

  .lotics-tabs__tab[data-active] {
    border-bottom-color: var(--primary);
  }

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

  .lotics-tabs__tab[data-disabled] {
    cursor: default;
    opacity: var(--lotics-disabled-opacity);
  }

  /* 12 of inline padding — the rung every other pill-shaped control in the kit
     sits at (`ChoiceStrip`, `Chip`). */
  .lotics-tabs__surface {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding-block: var(--lotics-space-8);
    padding-inline: var(--lotics-space-12);
    border-radius: var(--lotics-radius-control);
    background: transparent;
    transition: background-color var(--lotics-duration-fast) var(--lotics-ease-standard);
  }

  .lotics-tabs__line {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    /* 6 — the mark's gutter, written as the rung it is made of. */
    gap: var(--lotics-space-6);
  }

  .lotics-tabs__tab:hover .lotics-tabs__surface {
    background: var(--lotics-wash-hover);
  }

  .lotics-tabs__tab:active .lotics-tabs__surface {
    background: var(--lotics-wash-selected);
  }

  .lotics-tabs__status {
    width: var(--lotics-tabs-dot);
    height: var(--lotics-tabs-dot);
    flex-shrink: 0;
    border-radius: var(--lotics-radius-full);
    background: var(--lotics-tabs-status, var(--lotics-tone-zinc-solid));
  }

  .lotics-tabs__label {
    min-width: 0;
    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-regular);
    font-feature-settings: var(--lotics-font-features);
    color: var(--lotics-ink-muted);
    white-space: pre-wrap;
    overflow-wrap: break-word;
  }

  /* The selected tab carries the weight AND the ink: an underline answers "which
     one" only after the eye has travelled to the rule. */
  .lotics-tabs__tab[data-active] .lotics-tabs__label {
    font-weight: var(--lotics-weight-medium);
    color: var(--lotics-ink-default);
  }

  /* Indented past the dot so it starts under the LABEL's first letter.
     Left-aligned whatever the line above does: it is a figure. */
  .lotics-tabs__caption {
    font-family: var(--font-sans);
    font-size: var(--lotics-text-xs);
    line-height: var(--lotics-leading-xs);
    letter-spacing: var(--lotics-tracking-xs);
    font-weight: var(--lotics-weight-regular);
    font-feature-settings: var(--lotics-font-features);
    color: var(--lotics-ink-muted);
    text-align: start;
    white-space: nowrap;
  }

  .lotics-tabs__tab[data-status] .lotics-tabs__caption {
    margin-inline-start: calc(var(--lotics-tabs-dot) + var(--lotics-space-6));
  }

  /* A count never clips — the tab's own label is the half that yields. */
  .lotics-tabs__count {
    flex-shrink: 0;
    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-regular);
    font-feature-settings: var(--lotics-font-features);
    color: var(--lotics-ink-muted);
  }
}
