/*
 * Ordered stages as bars that NARROW. Both orientations share the roles; orientation picks the axis
 * the fraction runs along, so `--lotics-funnel-fill` is a length. `--lotics-funnel-size` is the
 * plot height vertically and bar thickness horizontally.
 */
@layer theme, base, lotics, components, utilities;
@layer lotics.tokens, lotics.reset, lotics.components;

@layer lotics.components {
  .lotics-funnel {
    --lotics-funnel-color: var(--primary);
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  .lotics-funnel[data-orientation="vertical"] {
    gap: var(--lotics-space-8);
  }

  .lotics-funnel[data-orientation="horizontal"] {
    gap: var(--lotics-space-12);
  }

  /* Rates, bars, then each column's figure and name — three rows, each stage a column through them. A
     column's floor is nothing, so a wide rate never widens its column off the bars'. */
  .lotics-funnel__bars {
    display: grid;
    grid-template-columns: repeat(var(--lotics-funnel-count), minmax(0, 1fr));
    grid-template-rows: auto var(--lotics-funnel-size) auto;
    gap: var(--lotics-space-8) var(--lotics-space-10);
  }

  .lotics-funnel[data-orientation="vertical"] .lotics-funnel__stage {
    display: grid;
    grid-row: 1 / span 3;
    grid-template-rows: subgrid;
    min-width: 0;
  }

  .lotics-funnel__rate-slot {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    min-width: 0;
  }

  .lotics-funnel[data-orientation="horizontal"] .lotics-funnel__stage {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--lotics-space-6);
  }

  /* A pressable stage's wash bleeds past its words and over half the gap above and below, as a bar
     chart's row's does. */
  .lotics-funnel[data-orientation="horizontal"] .lotics-funnel__stage[data-pressable] {
    padding: var(--lotics-space-6) var(--lotics-row-wash-bleed);
    margin: calc(var(--lotics-space-6) * -1) calc(var(--lotics-row-wash-bleed) * -1);
  }

  .lotics-funnel__track {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-end;
    border-radius: calc(var(--lotics-radius-control) - var(--lotics-space-8));
    overflow: hidden;
    background-color: var(--muted);
  }

  .lotics-funnel[data-orientation="vertical"] .lotics-funnel__track {
    min-width: 0;
  }

  .lotics-funnel[data-orientation="horizontal"] .lotics-funnel__track {
    height: var(--lotics-funnel-size);
  }

  .lotics-funnel__fill {
    border-radius: calc(var(--lotics-radius-control) - var(--lotics-space-8));
    background-color: var(--lotics-funnel-color);
  }

  .lotics-funnel[data-orientation="vertical"] .lotics-funnel__fill {
    width: 100%;
    height: var(--lotics-funnel-fill);
  }

  .lotics-funnel[data-orientation="horizontal"] .lotics-funnel__fill {
    height: 100%;
    width: var(--lotics-funnel-fill);
  }

  .lotics-funnel[data-orientation="vertical"] .lotics-funnel__caption {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 0;
    gap: var(--lotics-space-2);
  }

  .lotics-funnel[data-orientation="horizontal"] .lotics-funnel__caption {
    display: flex;
    flex-direction: row;
    align-items: baseline;
    gap: var(--lotics-space-8);
  }

  /* Pushed by its own margin, not a spacer. */
  .lotics-funnel[data-orientation="horizontal"] .lotics-funnel__value {
    margin-inline-start: auto;
  }
}
