/* =====================================================================
   OSE · Checkbox & radio
   ---------------------------------------------------------------------
   Native <input type="checkbox|radio">, custom-drawn (appearance: none):
   the box/circle is the input, the tick (mask) or dot is its ::before.
   The whole <label class="check"> row is the tap target (≥ 44px tall);
   the box lines up with the first line of a wrapping label.
   Group several in <fieldset class="field field--group"> (field.css).

   Markup
     <label class="check">
       <input class="check__input" type="checkbox" name="consent" required>
       <span class="check__label">Tôi đồng ý để OSE liên hệ tư vấn.</span>
     </label>
     <label class="check">
       <input class="check__input" type="radio" name="contact" value="zalo">
       <span class="check__label">Zalo</span>
     </label>

   States
     unchecked · checked (:checked) · indeterminate (checkbox
     .indeterminate = true; add data-indeterminate + data-js="check" to
     set it from markup) · hover (on the row, pointer devices only) ·
     focus (:focus-visible) · active (row pressed) · disabled (:disabled /
     aria-disabled="true", label dims) · disabled + checked ·
     error (aria-invalid="true" on an unchecked control)
   State rules use :where() so they all weigh the same and the source
   order below is the priority: checked < hover < error < disabled.
   Tokens   --check-*, --radio-* only.
   JS       data-js="check" → js/components/check.js (indeterminate only)
   ===================================================================== */

@layer components {
  .check {
    display: grid;
    grid-template-columns: var(--check-size) minmax(0, 1fr);
    column-gap: var(--check-gap);
    align-items: start;
    min-block-size: var(--check-row-min-height);
    padding-block: calc((var(--check-row-min-height) - var(--check-label-font-size) * var(--check-label-leading)) / 2);
    color: var(--check-label-color);
    font-size: var(--check-label-font-size);
    line-height: var(--check-label-leading);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .check__label {
    min-inline-size: 0;
    overflow-wrap: break-word;
  }

  .check__input {
    --_bg: var(--check-bg);
    --_border: var(--check-border);
    --_mark: var(--check-mark-color);
    --_icon: var(--check-mark-icon);
    appearance: none;
    display: grid;
    place-content: center;
    inline-size: var(--check-size);
    block-size: var(--check-size);
    margin: 0;
    margin-block-start: calc((var(--check-label-font-size) * var(--check-label-leading) - var(--check-size)) / 2);
    border: var(--check-border-width) solid var(--_border);
    border-radius: var(--check-radius);
    background-color: var(--_bg);
    color: inherit;
    font: inherit;
    cursor: inherit;
    transition:
      background-color var(--check-duration) var(--check-ease),
      border-color var(--check-duration) var(--check-ease),
      box-shadow var(--check-duration) var(--check-ease),
      transform var(--check-duration) var(--check-ease);
  }

  .check__input:where([type="radio"]) {
    --_mark: var(--radio-dot-color);
    border-radius: var(--radio-radius);
  }

  /* Tick (checkbox), bar (indeterminate) or dot (radio). */
  .check__input::before {
    content: "";
    inline-size: var(--check-mark-size);
    block-size: var(--check-mark-size);
    background-color: var(--_mark);
    -webkit-mask: var(--_icon) center / contain no-repeat;
    mask: var(--_icon) center / contain no-repeat;
    transition:
      opacity var(--check-duration) var(--check-ease),
      transform var(--check-duration) var(--check-ease);
  }

  .check__input[type="radio"]::before {
    inline-size: var(--radio-dot-size);
    block-size: var(--radio-dot-size);
    border-radius: var(--radio-radius);
    -webkit-mask: none;
    mask: none;
  }

  .check__input[type="checkbox"]:indeterminate {
    --_icon: var(--check-indeterminate-icon);
  }

  /* No mark until checked. (A radio whose group has nothing checked also
     matches :indeterminate, so that pseudo-class is kept to checkboxes.) */
  .check__input:where([type="radio"]:not(:checked), [type="checkbox"]:not(:checked):not(:indeterminate))::before {
    opacity: 0;
    transform: scale(var(--check-mark-enter-scale));
  }

  /* ---- states, lowest priority first --------------------------------- */
  .check__input:where(:checked, [type="checkbox"]:indeterminate) {
    --_bg: var(--check-bg-checked);
    --_border: var(--check-border-checked);
  }

  @media (hover: hover) {
    :where(.check:hover) .check__input {
      --_bg: var(--check-bg-hover);
      --_border: var(--check-border-hover);
    }

    :where(.check:hover) .check__input:where(:checked, [type="checkbox"]:indeterminate) {
      --_bg: var(--check-bg-checked-hover);
      --_border: var(--check-border-checked-hover);
    }
  }

  .check__input:focus-visible {
    box-shadow: var(--check-focus-ring);
  }

  :where(.check:active) .check__input {
    transform: scale(var(--check-press-scale));
  }

  .check__input:where([aria-invalid="true"]):where(:not(:checked, [type="checkbox"]:indeterminate)) {
    --_bg: var(--check-bg-error);
    --_border: var(--check-border-error);
  }

  .check__input:where(:disabled, [aria-disabled="true"]) {
    --_bg: var(--check-bg-disabled);
    --_border: var(--check-border-disabled);
    --_mark: var(--check-mark-color-disabled);
    cursor: not-allowed;
    transform: none;
  }

  .check:has(.check__input:disabled, .check__input[aria-disabled="true"]) {
    color: var(--check-label-color-disabled);
    cursor: not-allowed;
  }

  /* Forced colours: the mark paints with background-color, which the UA
     resets to Canvas; paint it in the text colour instead. */
  @media (forced-colors: active) {
    .check__input::before {
      forced-color-adjust: none;
      background-color: CanvasText;
    }

    .check__input:where(:disabled, [aria-disabled="true"])::before {
      background-color: GrayText;
    }
  }
}
