/* ==========================================================================
   checkboxRadio

   Default generated DOM (SINGLE, NATIVE, VERTICAL, mandatory):

   <fieldset id="payment" class="ui-checkbox-radio ui-checkbox-radio-vertical ui-checkbox-radio-presentation-native"
             role="radiogroup" aria-labelledby="payment-label" aria-required="true">
       <legend id="payment-label" class="ui-checkbox-radio-group-label">Payment method</legend>
       <div class="ui-checkbox-radio-options">
           <label class="ui-checkbox-radio-option" for="payment-option-0" data-index="0" data-selected="false">
               <input id="payment-option-0" class="ui-checkbox-radio-input" type="radio" name="payment" value="card">
               <span class="ui-checkbox-radio-option-label">Card</span>
           </label>
       </div>
       <div id="payment-error" class="ui-checkbox-radio-error" hidden></div>
   </fieldset>

   Conditional structures:
   - MULTIPLE: type="checkbox", no role/aria-required (plain fieldset group); a mandatory MULTIPLE group adds
     <span class="ui-checkbox-radio-visually-hidden">Mandatory</span> (texts.mandatory) inside the legend;
   - mandatory indicator (inside the legend): <span class="ui-checkbox-radio-optional">(Optional)</span> for non-mandatory
     groups (OPTIONAL_TEXT), or <span class="ui-checkbox-radio-mandatory" aria-hidden="true">*</span> for mandatory groups (MANDATORY_ASTERISK);
   - no groupLabel: no <legend>, no aria-labelledby;
   - disabled:true: native [disabled] on the fieldset; option disabled: [disabled] on the input;
   - ICON: <span class="ui-checkbox-radio-icon ui-checkbox-radio-icon-size-{small|medium|large}" aria-hidden="true"><i class="fa-{regular|solid} fa-{circle|square}[-check]"></i></span> before the label span;
   - CHIP: <span class="ui-checkbox-radio-chip">{Chip markup from chipIndex.js}</span> instead of the label span;
   - SEGMENTED: the options form one joined control (always one row; direction ignored); the inputs are visually hidden,
     the segments are separated by the group's background showing through a --border-thin gap, the selected segment
     is filled with the accent colour and its label is bold (not colour alone);
   - help: <div id="{id}-help" class="ui-checkbox-radio-help"> after the options, referenced by aria-describedby on the
     fieldset and every input (the error id is appended while an error is shown);
   - failed validation: .ui-checkbox-radio-invalid on the fieldset, visible error, aria-invalid + aria-describedby on inputs;
     the error element is not a live region (announcing errors belongs to the consumer).

   CHIP presentation: each option is a Chip; its look comes from chip.css and the shared tag tokens (--tag-*).

   STYLE GROUPS. The rules are in three parts; a class can appear in more than one part, each time with
   different properties. Values are design tokens written directly in the rules (no component variables).
     1. APPEARANCE  colours, borders, corners, type, motion. Change freely: only the look changes.
     2. DIMENSIONS  sizes, spacing, widths. Change with care: the component keeps working, its size changes.
     3. STRUCTURE   layout, behaviour, states, accessibility (focus ring, hidden text). Do not change.
   Text uses the typography roles of design-system.css (--font-ui, --fw-ui, --fw-ui-strong, …), never --font-sans
   or --fw-* directly, so a change of a role reaches every component.
   To restyle, change a value in part 1 or 2 (client/local-styling marks app values [APP]), or write the same
   selector with the new value in a stylesheet that loads later, in @layer overrides.
   ui-catalog source and client/local-styling use this file with the app look; client/showcase-styling keeps
   the original values, which the lines marked [APP] name in brackets (library / original).
   Borders use physical sides (top, right, bottom, left): a value set for one side only does not mirror in
   right-to-left languages.
   ========================================================================== */

@layer components {

    /* ======================================================================
       1. APPEARANCE — change freely
       ====================================================================== */
    /* the group: component font, normal weight and text colour (group label and error are --fw-ui-strong) */
    .ui-checkbox-radio { color: var(--c-text); font-family: var(--font-ui); font-weight: var(--fw-ui); }
    .ui-checkbox-radio-group-label { font-size: var(--fs-label); font-weight: var(--fw-ui-strong); line-height: var(--lh-compact); }
    .ui-checkbox-radio-optional { color: var(--c-muted); font-weight: var(--fw-ui); }
    .ui-checkbox-radio-mandatory { color: var(--c-danger-text); }

    /* DISABLED LABEL — the group label and the "*" of a disabled group use the secondary text colour.
       Disabled = the whole group (disabled:true), or inside a disabled fieldset (e.g. ContentGroup disabled:true); a single
       disabled option does not grey the group label. "(Optional)" and the help text are already --c-muted; the error stays red.
       To change the colour, edit these two lines (a plain .ui-checkbox-radio-group-label rule elsewhere cannot override them). */
    .ui-checkbox-radio:disabled > .ui-checkbox-radio-group-label { color: var(--c-muted); }
    .ui-checkbox-radio:disabled > .ui-checkbox-radio-group-label .ui-checkbox-radio-mandatory { color: var(--c-muted); }

    /* a disabled option (independent of selected) */
    .ui-checkbox-radio-option:has(.ui-checkbox-radio-input:disabled) { opacity: var(--opacity-disabled); }

    /* ICON presentation: icon colour when selected; focus ring corners. CHIP: the focus ring follows the tag corners */
    .ui-checkbox-radio-presentation-icon .ui-checkbox-radio-option:has(.ui-checkbox-radio-input:checked) .ui-checkbox-radio-icon { color: var(--c-accent); }
    .ui-checkbox-radio-presentation-icon .ui-checkbox-radio-option:has(.ui-checkbox-radio-input:focus-visible) { border-top-left-radius: var(--radius-control); border-top-right-radius: var(--radius-control); border-bottom-right-radius: var(--radius-control); border-bottom-left-radius: var(--radius-control); }
    .ui-checkbox-radio-presentation-chip .ui-checkbox-radio-option:has(.ui-checkbox-radio-input:focus-visible) { border-top-left-radius: var(--tag-radius); border-top-right-radius: var(--tag-radius); border-bottom-right-radius: var(--tag-radius); border-bottom-left-radius: var(--tag-radius); }

    /* SEGMENTED: the joined frame (its background shows as the lines between segments), segments, under the pointer,
       selected (accent fill + bold label) and keyboard focus inside the segment */
    .ui-checkbox-radio-presentation-segmented .ui-checkbox-radio-options { border-top: var(--border-thin) solid var(--c-border); border-right: var(--border-thin) solid var(--c-border); border-bottom: var(--border-thin) solid var(--c-border); border-left: var(--border-thin) solid var(--c-border); border-top-left-radius: var(--radius-control); border-top-right-radius: var(--radius-control); border-bottom-right-radius: var(--radius-control); border-bottom-left-radius: var(--radius-control); background-color: var(--c-border); }
    .ui-checkbox-radio-presentation-segmented .ui-checkbox-radio-option { background-color: var(--c-surface); color: var(--c-text); }
    .ui-checkbox-radio-presentation-segmented .ui-checkbox-radio-option:hover:not(:has(.ui-checkbox-radio-input:checked, .ui-checkbox-radio-input:disabled)) { background-color: var(--c-surface-hover); }
    .ui-checkbox-radio-presentation-segmented .ui-checkbox-radio-option:has(.ui-checkbox-radio-input:checked) { background-color: var(--c-accent); color: var(--c-on-accent); }
    .ui-checkbox-radio-presentation-segmented .ui-checkbox-radio-option:has(.ui-checkbox-radio-input:checked) .ui-checkbox-radio-option-label { font-weight: var(--fw-ui-strong); }
    /* validation, help, error */
    .ui-checkbox-radio-invalid .ui-checkbox-radio-group-label { color: var(--c-danger-text); }
    .ui-checkbox-radio-help { color: var(--c-muted); font-size: var(--fs-label); line-height: var(--lh-body); }
    .ui-checkbox-radio-error { color: var(--c-danger-text); font-size: var(--fs-label); font-weight: var(--fw-ui-strong); line-height: var(--lh-body); }

    /* ======================================================================
       2. DIMENSIONS — change with care
       ====================================================================== */
    .ui-checkbox-radio-group-label { margin: 0 0 var(--gap-tight); }                                    /* group label to options */
    .ui-checkbox-radio-vertical .ui-checkbox-radio-options { gap: var(--gap-tight); }
    .ui-checkbox-radio-horizontal .ui-checkbox-radio-options { gap: var(--gap-toolbar); }
    .ui-checkbox-radio-horizontal.ui-checkbox-radio-presentation-chip .ui-checkbox-radio-options { gap: var(--gap-inline-items); }   /* HORIZONTAL chips */
    .ui-checkbox-radio-option { gap: var(--gap-inline-items); }                                         /* control or icon to its label */
    /* SEGMENTED: the line between segments (gap over the frame's background), segment height and side padding */
    .ui-checkbox-radio-horizontal.ui-checkbox-radio-presentation-segmented .ui-checkbox-radio-options { gap: var(--border-thin); }
    .ui-checkbox-radio-presentation-segmented .ui-checkbox-radio-option { min-block-size: var(--control-height); padding: 0 var(--gap-toolbar); }
    /* ICON size (shared icon-size tokens, as Button) */
    .ui-checkbox-radio-icon-size-small { font-size: var(--icon-size-small); }
    .ui-checkbox-radio-icon-size-medium { font-size: var(--icon-size-medium); }
    .ui-checkbox-radio-icon-size-large { font-size: var(--icon-size-large); }
    .ui-checkbox-radio-help, .ui-checkbox-radio-error { margin-block-start: var(--gap-tight); }

    /* ======================================================================
       3. STRUCTURE — do not change
       ====================================================================== */
    /* Fieldset reset */
    .ui-checkbox-radio { min-inline-size:0; margin:0; padding:0; border:0; }
    .ui-checkbox-radio-group-label { padding:0; }

    /* Option → next option */
    .ui-checkbox-radio-options { display:flex; min-inline-size:0; }
    .ui-checkbox-radio-vertical .ui-checkbox-radio-options { flex-direction:column; align-items:flex-start; }
    .ui-checkbox-radio-horizontal .ui-checkbox-radio-options { flex-direction:row; flex-wrap:wrap; align-items:center; }

    /* Control/icon → its own label */
    .ui-checkbox-radio-option { position:relative; display:inline-flex; align-items:center; min-inline-size:0; cursor:pointer; }
    .ui-checkbox-radio-option-label { min-inline-size:0; }
    .ui-checkbox-radio-option:has(.ui-checkbox-radio-input:disabled) { cursor:not-allowed; }

    /* NATIVE: browser control stays visible */
    .ui-checkbox-radio-presentation-native .ui-checkbox-radio-input { flex:0 0 auto; margin:0; }

    /* ICON / CHIP: native input stays focusable and semantic; only its rendering is hidden */
    .ui-checkbox-radio-visually-hidden, .ui-checkbox-radio-presentation-icon .ui-checkbox-radio-input, .ui-checkbox-radio-presentation-chip .ui-checkbox-radio-input, .ui-checkbox-radio-presentation-segmented .ui-checkbox-radio-input { position:absolute; inline-size:1px; block-size:1px; margin:-1px; padding:0; overflow:hidden; clip-path:inset(50%); white-space:nowrap; border:0; }
    .ui-checkbox-radio-presentation-icon .ui-checkbox-radio-option:has(.ui-checkbox-radio-input:focus-visible), .ui-checkbox-radio-presentation-chip .ui-checkbox-radio-option:has(.ui-checkbox-radio-input:focus-visible) { outline:var(--focus-outline); outline-offset:var(--focus-offset); }

    /* SEGMENTED: one row that never wraps (few, short options); the frame clips the segments to its corners; focus is
       drawn inside the focused segment, so the clipping never hides it */
    .ui-checkbox-radio-horizontal.ui-checkbox-radio-presentation-segmented .ui-checkbox-radio-options { display:inline-flex; flex-wrap:nowrap; align-items:stretch; max-inline-size:100%; overflow:hidden; }
    .ui-checkbox-radio-presentation-segmented .ui-checkbox-radio-option { justify-content:center; white-space:nowrap; }
    .ui-checkbox-radio-presentation-segmented .ui-checkbox-radio-option:has(.ui-checkbox-radio-input:focus-visible) { outline:var(--focus-outline); outline-offset:calc(-1 * var(--border-thick)); }
    /* ICON */
    .ui-checkbox-radio-icon { display:inline-flex; flex:0 0 auto; align-items:center; justify-content:center; line-height:1; }

    /* Label on the left: labelPosition START, or INHERIT inside an element with the class ui-labels-start.
       Applies only while the nearest container (e.g. Form, ContentGroup, CollapsiblePanel) is at least 36rem wide;
       narrower, the label returns on top. 36rem is a literal because custom properties cannot be used in container queries.
       Label column width: --form-label-width (design-system.css); gap between label and options: --gap-toolbar. */
    @container (min-width:36rem) {
        :is(.ui-labels-start .ui-checkbox-radio:not(.ui-checkbox-radio-label-top), .ui-checkbox-radio.ui-checkbox-radio-label-start) { display:grid; grid-template-columns:var(--form-label-width) minmax(0,1fr); column-gap:var(--gap-toolbar); }
        :is(.ui-labels-start .ui-checkbox-radio:not(.ui-checkbox-radio-label-top), .ui-checkbox-radio.ui-checkbox-radio-label-start) > * { grid-column:2; }
        :is(.ui-labels-start .ui-checkbox-radio:not(.ui-checkbox-radio-label-top), .ui-checkbox-radio.ui-checkbox-radio-label-start) > .ui-checkbox-radio-group-label { grid-column:1; float:inline-start; margin:0; align-self:start; }
    }
}
