/* Checkbox, tri-state checkbox, radio and toggle.
   Markup: label.pr-opt > input.pr-opt__input + span.pr-check|.pr-toggle (drawn,
   aria-hidden) + text. The native input carries the role and the state
   (checkbox, radio, or checkbox with role="switch"); the drawing follows it.
   On states carry a glyph so they read without colour.
   States: off, on, mixed, disabled, focus, pending (toggle while saving). */

.pr-opt {
  position: relative;
  display: inline-flex; align-items: center; gap: 10px;
  min-height: var(--pr-density-dense-control);
  font-size: 0.85rem; line-height: 1.4;
  color: var(--pr-text-primary);
  cursor: pointer;
}
.pr-opt--block { display: flex; }
.pr-opt__count { color: var(--pr-text-caption); }
.pr-opt__input {
  position: absolute; left: 0; top: 50%;
  width: 20px; height: 20px; margin: -10px 0 0;
  opacity: 0; cursor: inherit;
}
.pr-opt:has(> .pr-opt__input:disabled) { color: var(--pr-text-disabled); cursor: not-allowed; }

/* ---- checkbox and radio drawing ---- */
.pr-check {
  width: 20px; height: 20px; flex: none;
  display: inline-grid; place-items: center;
  border-radius: var(--pr-radius-xs);
  border: 1.5px solid var(--pr-border-control);
  background: var(--pr-surface-nested);
  color: var(--pr-text-on-brand);
}
.pr-check > svg { display: none; }
.pr-opt__input:checked + .pr-check, .pr-check.is-on,
.pr-opt__input:indeterminate + .pr-check, .pr-opt__input[data-pr-indeterminate] + .pr-check, .pr-check.is-mixed { background: var(--pr-brand-fill); border-color: var(--pr-brand-fill); }
.pr-opt__input:checked + .pr-check > .pr-check__on, .pr-check.is-on > .pr-check__on { display: block; }
.pr-opt__input:indeterminate + .pr-check > .pr-check__on,
.pr-opt__input[data-pr-indeterminate] + .pr-check > .pr-check__on { display: none; }
.pr-opt__input:indeterminate + .pr-check > .pr-check__mixed,
.pr-opt__input[data-pr-indeterminate] + .pr-check > .pr-check__mixed, .pr-check.is-mixed > .pr-check__mixed { display: block; }

.pr-check--radio { border-radius: 50%; }
.pr-opt__input:checked + .pr-check--radio, .pr-check--radio.is-on {
  background: var(--pr-surface-nested);
  border: 6px solid var(--pr-brand-fill);
}
.pr-opt__input:checked + .pr-check--radio > svg { display: none; }

.pr-opt__input:disabled + .pr-check, .pr-check.is-disabled { border-style: dashed; background: none; }
.pr-opt__input:disabled:checked + .pr-check:not(.pr-check--radio) { background: var(--pr-text-disabled); border-color: var(--pr-text-disabled); border-style: solid; }
/* Disabled and selected radio: the solid ring in the disabled colour, not a
   dashed brand ring that reads as enabled. */
.pr-opt__input:disabled:checked + .pr-check--radio { border: 6px solid var(--pr-text-disabled); background: var(--pr-surface-nested); }

.pr-opt__input:focus-visible + .pr-check, .pr-check.is-focus,
.pr-opt__input:focus-visible + .pr-toggle, .pr-toggle.is-focus { outline: var(--pr-border-focus) solid var(--pr-focus-ring); outline-offset: var(--pr-border-focus); }

/* ---- toggle (switch) ---- */
.pr-toggle {
  position: relative; flex: none;
  width: 40px; height: 24px;
  border-radius: var(--pr-radius-pill);
  border: 1.5px solid var(--pr-border-control);
  background: var(--pr-surface-nested);
  transition: background-color var(--pr-dur-fast) var(--pr-ease-standard);
}
.pr-toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--pr-text-secondary);
  transition: transform var(--pr-dur-fast) var(--pr-ease-standard);
}
.pr-opt__input:checked + .pr-toggle, .pr-toggle.is-on { background: var(--pr-brand-fill); border-color: var(--pr-brand-fill); }
.pr-opt__input:checked + .pr-toggle::after, .pr-toggle.is-on::after { transform: translateX(16px); background: var(--pr-text-on-brand); }
/* the check glyph inside an on toggle, so on reads without colour */
.pr-opt__input:checked + .pr-toggle::before, .pr-toggle.is-on::before {
  content: ""; position: absolute; left: 8px; top: 5px;
  width: 4px; height: 8px;
  border: solid var(--pr-text-on-brand); border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
}
.pr-opt__input:disabled + .pr-toggle { border-style: dashed; background: none; }
.pr-opt__input:disabled:checked + .pr-toggle { background: var(--pr-text-disabled); border-color: var(--pr-text-disabled); border-style: solid; }
/* Pending: the change is in flight; it holds or rolls back with a toast. */
.pr-opt__input[aria-busy="true"] + .pr-toggle, .pr-toggle.is-pending { opacity: 0.6; }
.pr-opt:has(> .pr-opt__input[aria-busy="true"]) { cursor: progress; }

/* ---- groups ---- */
.pr-choices { display: flex; flex-wrap: wrap; gap: var(--pr-space-xs) var(--pr-space-xl); }
.pr-choices--col { flex-direction: column; gap: 0; }
.pr-choices__legend { font-size: 0.85rem; font-weight: 500; color: var(--pr-text-primary); margin-bottom: var(--pr-space-xs); }

@media (max-width: 768px) {
  .pr-opt { min-height: var(--pr-touch-target); font-size: 1rem; }
}
