/**
 * Checkbox and CheckboxGroup styles
 * @countermeasure/web-components/primitives/checkbox
 */

/* ==========================================================================
   Checkbox
   ========================================================================== */

.cmm-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
}

.cmm-checkbox--disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Visually hidden native input */

.cmm-checkbox__input {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

/* Custom checkbox box */

.cmm-checkbox__box {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  border: 1.5px solid hsl(var(--border));
  border-radius: var(--radius-sm);
  background-color: hsl(var(--background));
  transition: background-color var(--transition-fast),
    border-color var(--transition-fast);
}

.cmm-checkbox__box::after {
  content: '';
  display: none;
}

/* Checked state - checkmark */

.cmm-checkbox__input:checked + .cmm-checkbox__box {
  background-color: hsl(var(--primary));
  border-color: hsl(var(--primary));
}

.cmm-checkbox__input:checked + .cmm-checkbox__box::after {
  display: block;
  width: 0.3rem;
  height: 0.55rem;
  border: solid hsl(var(--primary-foreground));
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translateY(-1px);
}

/* Indeterminate state - dash */

.cmm-checkbox__input:indeterminate + .cmm-checkbox__box {
  background-color: hsl(var(--primary));
  border-color: hsl(var(--primary));
}

.cmm-checkbox__input:indeterminate + .cmm-checkbox__box::after {
  display: block;
  width: 0.5rem;
  height: 0;
  border: solid hsl(var(--primary-foreground));
  border-width: 0 0 2px 0;
  transform: none;
}

/* Hover state */

.cmm-checkbox:hover .cmm-checkbox__box {
  border-color: hsl(var(--ring));
}

/* Focus state */

.cmm-checkbox__input:focus-visible + .cmm-checkbox__box {
  outline: 2px solid hsl(var(--focus-ring));
  outline-offset: 2px;
}

/* Label text */

.cmm-checkbox__label {
  font-size: 0.875rem;
  line-height: 1.5;
  color: hsl(var(--foreground));
}

/* ==========================================================================
   Checkbox Group
   ========================================================================== */

.cmm-checkbox-group {
  display: flex;
}

.cmm-checkbox-group--horizontal {
  flex-direction: row;
  gap: 1rem;
  flex-wrap: wrap;
}

.cmm-checkbox-group--vertical {
  flex-direction: column;
  gap: 0.5rem;
}
