/* OAIT Design System 2.1.0 · reference/css/segmented.css
   Segmented button (unit c-actions).

   Components
   - Segmented button (.oa-segmented): two to four segments that set a mode of the same content
     (card side, scan direction, print layout). Panels are tabs; form answers are choice cards.

   Implements canonical §10.8, §10.0, §2.7, §6.3 (the inset ring), §8.2 (the check, FILL), and
   D-CAI-16, D-CAI-14, D-CAI-20, D-COL-05, D-ARC-20, D-ARC-32, D-SEM-10.

   Tokens read: --color-outline, --color-surface, --color-on-surface, --color-primary-container,
   --color-on-primary-container; --size-button-md, --size-icon-md, --size-focus-inset;
   --space-2, --space-6; --radius-full, --radius-box; --text-label-lg with its companions;
   --opacity-state-hover, --opacity-state-pressed, --opacity-state-disabled-content;
   --duration-short-3; --ease-standard.
   Context property read: --oa-state (reset to 0 at rest on every segment, so a container's
   layer never leaks into the group).

   Classes: .oa-segmented (+ --wide, --stack), .oa-segmented__btn, .oa-segmented__icon,
   .oa-segmented__check.

   The group is a <fieldset> named by aria-label (or a visually hidden <legend>, or aria-labelledby
   pointing at a visible label above it). Each segment is <button type="button" aria-pressed>.
   Breakpoint is literal: sm 40rem (640px). */


/* ---------------------------------------------------------------------------------------------
   1. Group: a pill with a 1px outline edge on the page color, hugging its segments, clipping
   them. --wide fills the row (a scanner's direction switch). --stack turns the group into a
   column with box corners below 640px, for labels that do not fit side by side at 360px
   (D-CAI-16).
   --------------------------------------------------------------------------------------------- */

.oa-segmented {
  display: flex;
  box-sizing: border-box;
  inline-size: fit-content;
  min-inline-size: 0;
  max-inline-size: 100%;
  margin: 0;
  padding: 0;
  border: 1px solid var(--color-outline);
  border-radius: var(--radius-full);
  background-color: var(--color-surface);
  overflow: hidden;
}

.oa-segmented--wide {
  inline-size: 100%;
}


/* ---------------------------------------------------------------------------------------------
   2. Segment: 48px, label-lg on on-surface, 24px inline padding, dividers in outline, the state
   layer over the segment's border box (its own divider included), the ring inset 4px (the group
   clips). Labels never wrap. The end segments follow the pill, so the inset ring keeps its round
   ends (D-CAI-16, D-SEM-11).
   --------------------------------------------------------------------------------------------- */

.oa-segmented__btn {
  --oa-state: 0;
  position: relative;
  isolation: isolate;
  display: inline-flex;
  flex: 1 1 0;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  box-sizing: border-box;
  min-block-size: var(--size-button-md); /* a minimum: scaled text grows the segment (canonical §4.6) */
  margin: 0;
  padding-block: 0;
  padding-inline: var(--space-6);
  border: 0;
  border-radius: 0;
  background-color: transparent;
  color: var(--color-on-surface);
  font-family: inherit;
  font-size: var(--text-label-lg);
  line-height: var(--text-label-lg--line-height);
  letter-spacing: var(--text-label-lg--letter-spacing);
  font-weight: var(--text-label-lg--font-weight);
  white-space: nowrap;
  cursor: pointer;
  -webkit-user-select: none; /* Safari on iOS reads only the prefixed property */
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    background-color var(--duration-short-3) var(--ease-standard),
    color var(--duration-short-3) var(--ease-standard);
}

.oa-segmented__btn + .oa-segmented__btn {
  border-inline-start: 1px solid var(--color-outline);
}

.oa-segmented__btn:first-of-type {
  border-start-start-radius: var(--radius-full);
  border-end-start-radius: var(--radius-full);
}

.oa-segmented__btn:last-of-type {
  border-start-end-radius: var(--radius-full);
  border-end-end-radius: var(--radius-full);
}

.oa-segmented__btn::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: var(--z-behind);
  border-radius: inherit;
  background-color: currentColor;
  opacity: var(--oa-state, 0);
  pointer-events: none;
  transition: opacity var(--duration-short-3) var(--ease-standard);
}

.oa-segmented__btn + .oa-segmented__btn::before {
  inset-inline-start: -1px; /* the layer covers the segment's own divider */
}

@media (hover: hover) {
  .oa-segmented__btn:hover {
    --oa-state: var(--opacity-state-hover);
  }
}

.oa-segmented__btn:active {
  --oa-state: var(--opacity-state-pressed);
}

.oa-segmented__btn:active::before {
  transition-duration: 0ms; /* lint-ok: a press shows at once; only hover and release fade (canonical §2.7, §7.2) */
}

.oa-segmented__btn:focus-visible,
.oa-segmented__btn[data-demo-focus] {
  outline-offset: var(--size-focus-inset);
}

/* Icons are 20px. The selected segment shows the check (FILL 1) in place of its own icon, its
   non-color cue (D-CAI-14). Write the check in every segment that can be chosen; the attribute
   decides which one shows. */
.oa-segmented__icon,
.oa-segmented__check {
  flex-shrink: 0;
  font-size: var(--size-icon-md);
}

.oa-segmented__check {
  display: none;
  font-variation-settings: "FILL" 1;
}

.oa-segmented__btn[aria-pressed="true"] {
  background-color: var(--color-primary-container);
  color: var(--color-on-primary-container);
}

.oa-segmented__btn[aria-pressed="true"] .oa-segmented__icon {
  display: none;
}

.oa-segmented__btn[aria-pressed="true"] .oa-segmented__check {
  display: inline-block;
}

.oa-segmented__btn:disabled {
  --oa-state: 0;
  color: color-mix(in srgb, var(--color-on-surface) calc(var(--opacity-state-disabled-content) * 100%), transparent);
  cursor: default;
}

/* Forced colors drop the container; the check stays as the selected cue. */
@media (forced-colors: active) {
  .oa-segmented__btn:disabled {
    color: GrayText;
  }
}


/* ---------------------------------------------------------------------------------------------
   3. Stacked below 640px (sm): a column with box corners, dividers on the block start.
   --------------------------------------------------------------------------------------------- */

@media (width < 40rem) {
  .oa-segmented--stack {
    flex-direction: column;
    inline-size: 100%;
    border-radius: var(--radius-box);
  }

  .oa-segmented--stack > .oa-segmented__btn {
    flex: none;
    border-radius: 0;
  }

  .oa-segmented--stack > .oa-segmented__btn + .oa-segmented__btn {
    border-inline-start: 0;
    border-block-start: 1px solid var(--color-outline);
  }

  /* The divider moves to the block start, and the state layer follows it. */
  .oa-segmented--stack > .oa-segmented__btn + .oa-segmented__btn::before {
    inset-inline-start: 0;
    inset-block-start: -1px;
  }

  .oa-segmented--stack > .oa-segmented__btn:first-of-type {
    border-start-start-radius: var(--radius-box);
    border-start-end-radius: var(--radius-box);
  }

  .oa-segmented--stack > .oa-segmented__btn:last-of-type {
    border-end-start-radius: var(--radius-box);
    border-end-end-radius: var(--radius-box);
  }
}
