// ======
//	fx-grid.css
//	flexbox grid system
// =====

// Internal parameters variables
$fx-grid-gutter: 1.5rem !default;
$fx-grid-cell-min-size: 10em !default; // for .fx-grid--auto
$fx-grid-mobile-limit: $very-small-limit !default;
$fx-grid-tablet-limit: $mobile-limit !default;
$max-cols-mobile : 3 !default;
$max-cols-tablet : 6 !default;
$max-cols-desktop : 9 !default;

// Computed variables, they should not be redefined.
$fx-grid-half-gutter: $fx-grid-gutter / 2;

//	custom media queries
//		ex. @media ($max-grid-mobile-viewport) {}
$max-grid-mobile-viewport: "max-width: #{$fx-grid-mobile-limit}";
$min-grid-tablet-viewport: "min-width: #{min-desktop-viewport($fx-grid-mobile-limit)}";
$min-grid-desktop-viewport: "min-width: #{min-desktop-viewport($fx-grid-tablet-limit)}";


.fx-grid,
[class*="fx-grid--"] {
	display: flex;
	flex-wrap: wrap;
	margin: 0;
	padding: 0;
	margin-left: -1 * $fx-grid-half-gutter;
	margin-right: -1 * $fx-grid-half-gutter;
	/* if flex item are list */
	list-style-type: none;

	> * {
		box-sizing: border-box; // for gadjo
		margin-left: $fx-grid-half-gutter;
		margin-right: $fx-grid-half-gutter;
		flex-basis: calc(100% - #{$fx-grid-gutter});
		hyphens: auto;
	}
}


// mode auto
.fx-grid--auto {
	> * {
		flex-basis: $fx-grid-cell-min-size;
		flex-shrink: 1;
		flex-grow: 1;
	}
}

// mode cols
@for $i from 2 through $max-cols-mobile {
	.fx-grid--#{$i} > *,
	[class*="fx-grid--"][class*="--m#{$i}"] > * {
		flex-basis: calc(#{100%/$i} - #{$fx-grid-gutter});
	}
}
@media ($min-grid-tablet-viewport) {
		@for $i from 2 through $max-cols-tablet {
		[class*="fx-grid--"][class*="--t#{$i}"] > * {
			flex-basis: calc(#{100%/$i} - #{$fx-grid-gutter});
		}
	}
}
@media ($min-grid-desktop-viewport) {
		@for $i from 2 through $max-cols-desktop {
		[class*="fx-grid--"][class*="--d#{$i}"] > * {
			flex-basis: calc(#{100%/$i} - #{$fx-grid-gutter});
		}
	}
}

// custom grid cell size
.fx-grid,
[class*="fx-grid--"] {
	@for $i from 1 through $max-cols-mobile {
		@for $j from 1 through $i {
			> .size--#{$j}-#{$i},
			> [class*="size--"][class*="--m#{$j}-#{$i}"] {
				flex-basis: calc( #{100%*$j/$i} - #{$fx-grid-gutter});
				flex-grow: 0;
			}
		}
	}
	@media ($min-grid-tablet-viewport) {
		@for $i from 1 through $max-cols-tablet {
			@for $j from 1 through $i {
				> [class*="size--"][class*="--t#{$j}-#{$i}"] {
					flex-basis: calc( #{100%*$j/$i} - #{$fx-grid-gutter});
					flex-grow: 0;
				}
			}
		}
	}
	@media ($min-grid-desktop-viewport) {
		@for $i from 1 through $max-cols-desktop {
			@for $j from 1 through $i {
				> [class*="size--"][class*="--d#{$j}-#{$i}"] {
					flex-basis: calc( #{100%*$j/$i} - #{$fx-grid-gutter});
					flex-grow: 0;
				}
			}
		}
	}
}
