/* natUIve – Grid */

@import 'natuive-setup';

/* For proper fallback, use .col* for all columns. Automatic column width (no .col*) works for Flexbox only. */

.row {

	width: 100%;
	display: -ms-flexbox;
	display: flex;
// 	-webkit-justify-content: center;
	-webkit-flex-wrap: wrap;
	-ms-flex-wrap: wrap;
	flex-wrap: wrap;
	text-align: center;

}

	.row > * {
	
/*
		vertical-align: top;
		display: inline-block;
*/
		position: relative;
		word-wrap: break-word;
		width: calc(20% - #{$line-height-em});
		--width: 1/5; // Minimum auto column width is 20%
		padding: calc(#{$line-height-em/4});
		margin: calc(#{$line-height-em/4});
		flex-grow: 1;
		text-align: left;
		text-align: start;
		box-sizing: content-box; // IE11 padding. To do: only for IE11-
		min-width: 0; // FF flex-basis bug fix for when a column child is wider than the column

	}
	
	@-moz-document url-prefix() {
	
		.row > * {
			
			margin: calc(#{$line-height-em/4} - .0009em); // FF odd font-size grid fix
		
		}
		
	}

	.row > [class^=col] {
		
		flex-grow: 0;
		
	}
	
	.row:before, .row:after { // Clear margins before/after a row
		
		content: '';
		display: table;
		width: 100%;

	}
	
	.row > *, .row > * > * {
		
		max-width: 100%; /* instead of overflow-x:hidden, which would also activate overflow-y:hidden and clip the tooltip */
		
	}

	.row > * > img {
		
		display: block;
		margin: 0 auto;
		
	}

/* colXY where the column takes up X/Y of space; colY means 1/Y */

	// CSS Variables grid with only 1 line per column variant. To do: fallback.
	
	.row > .col23 {
		
		--width: 2/3; // or with inline style without the need for column classes
		flex-basis: calc(66.667% - #{$line-height-em}); // Fallback for browsers not supporting CSS variables
		
	}

	.row > .col34 {

		--width: 3/4;
		flex-basis: calc(75% - #{$line-height-em});

	}

	.row > .col4 {

		--width: 1/4;
		flex-basis: calc(25% - #{$line-height-em});

	}

	.row > .col5 {

		--width: 1/5;
		flex-basis: calc(20% - #{$line-height-em});

	}

	.row > .col25 {

		--width: 2/5;
		flex-basis: calc(40% - #{$line-height-em});

	}

	.row > .col35 {

		--width: 3/5;
		flex-basis: calc(60% - #{$line-height-em});

	}

	.row > .col45 {

		--width: 4/5;
		flex-basis: calc(80% - #{$line-height-em});

	}

	.row > .col3 {

		--width: 1/3;
		flex-basis: calc(33.333% - #{$line-height-em});

	}

	.row > .col2 {

		--width: 1/2;
		flex-basis: calc(50% - #{$line-height-em});

	}
	
	.row > .col1, .row > *:only-child:not([class^=col]) { // .col1 or a single classless item

		--width: 1;
		flex-basis: calc(100% - #{$line-height-em});

	}

	@supports (--a: 1) {
		
		// Overwrite the fallback flex-basis with CSS variable
		.row > *, .row > *[class^=col] {
			
			--spacing: #{$line-height-em};
			flex-basis: calc(var(--width) * 100% - var(--spacing));
	
		}
		
		@media screen and (max-width: 1024px) {
		
			.row > * {
				
				--width: 1/5;
			
			}
		
		}
		
		@media screen and (max-width: 900px) {
		
			.row > * {
				
				--width: 1/3;
			
			}
		
		}
	
		.row.no-padding, .row.no-padding > * {
			
			--spacing: $line-height-em/2;
			padding: 0;
			
		}
		
		.row.no-margin, .row.no-margin > * {
			
			--spacing: $line-height-em/2;
			margin: 0;
			
		}
		
		.row.no-spacing > * {
			
			--spacing: 0em;
			padding: 0;
			margin: 0;
			
		}
		
		.row.spacing-horizontal > * {
			
			margin: 0 $line-height-em/2;
	
		}
		
		.row.spacing-vertical > * {
			
			margin: $line-height-em/2 0;
	
		}
	
	}
	
.align-left, .align-right .align-left *, .align-left *, .row > .align-left {
	
	text-align: left;
	text-align: start;

}

.align-right, .align-left .align-right *, .align-right *, .row > .align-right {
	
	text-align: right;	
	text-align: end;

}

.align-center, .align-center *, .row > .align-center {
	
	text-align: center;

}

.row > .align-top, .row > .align-middle, .row > .align-bottom {
	
	display: inline-block;
	display: flex;
	
}

.row > .align-top, .align-top .row > * {
	
	vertical-align: top;
	justify-content: flex-start;
	flex-direction: column;
	display: flex;
	
}

.row > .align-middle, .align-middle .row > * {
	
	vertical-align: middle;
	justify-content: center;
	flex-direction: column;
	display: flex;
	
}

.row > .align-bottom, .align-bottom .row > * {
	
	vertical-align: bottom;
	justify-content: flex-end;
	flex-direction: column;
	display: flex;

}

.align-children *, .row.align-children > * {
	
	text-align: inherit;
	
}

section {
	
	position: relative;

}

section:before, section:after { // Prevent inner edge margins from creating blank space between sections
	
	content: '';
	display: table;
	width: 100%;

}

/* Masonry in CSS only */

.masonry {

    -moz-column-count: 3;
    -moz-column-gap: 0;
    -webkit-column-count: 3;
    -webkit-column-gap: 0;
    column-count: 3;
    column-gap: 0;
    margin: $line-height-em 0;

}

    .masonry > * {

//         display: inline-block; // Unwanted wrapping in Chrome – 2 instead of 3 columns
        display: table; // Unwanted wrapping in Chrome – 2 instead of 3 columns
        width: 100%;
// 		margin: 0 $line-height-em $line-height-em;
//         width: calc(100% - #{$line-height-em}*2);
        -webkit-column-break-inside: avoid;
		page-break-inside: avoid;           /* FF 20+ */
		break-inside: avoid-column;
/*
		-webkit-margin-before: 0;
		-webkit-margin-after: 0;
*/
		margin: 0;
		padding: $line-height-em/2;

    }
    
    .masonry.col2 {

	    -moz-column-count: 2;
	    -webkit-column-count: 2;
	    column-count: 2;
	    
    }

    .masonry.col4 {

	    -moz-column-count: 4;
	    -webkit-column-count: 4;
	    column-count: 4;
	    
    }

    .masonry.col4 {

	    -moz-column-count: 5;
	    -webkit-column-count: 5;
	    column-count: 5;
	    
    }

	ul.masonry {
		
		min-height: 0;

	}

	ol.masonry > * {
		
	    padding-left: 2.5em;

	}

.pad {
	
	padding: $line-height-em/2;

}

	.pad-half {
		
		padding: $line-height-em/4;
	
	}

	.unpad, .row > * > .unpad {
		
		margin: #{-$line-height-em/2};
		width: calc(100% + #{$line-height-em});
		max-width: none;
	
	}
	
	.unpad-vertical {
		
		margin: -$line-height-em 0;

	}

.row.border-all {
	
	box-shadow: inset 0 0 0 0.5px #000;
	margin: -$line-height-em/2 0;
	
}

.row.border-all > * {

	margin: -$line-height-em/4 $line-height-em/4;

}

.row.border-all .row {
	
	margin: 0 -#{$line-height-em/2};
	width: calc(100% + #{$line-height-em});
	max-width: none;
	
}

.row.border-all .row > * {

	box-shadow: 0 0 0 0.5px #000;
	margin: 0;

}

.row.border-all .row .row {
	
	margin: 0 -#{$line-height-em/4};
	width: calc(100% + #{$line-height-em/2});
	
}

.row.border-all .row .row:first-child {
	
	margin-top: -#{$line-height-em/4};
	
}

.row.border-all .row .row:last-child {
	
	margin-bottom: -#{$line-height-em/4};
	
}

.row.border {

	border: 1px solid #e6e6e6;
	padding: 0;

}
		
	.row.border > * {
		
		border-left: 1px solid #e6e6e6;
		
	}

	.row.border > *:first-child {
		
		border-left: none;
		
	}
	
	.row * .box { /* Boxes inside grid cells */
		
		background: #fff;
		border: 1px solid #e6e6e6;
		
	}
	
.row.border-off, .row.border-off * {
	
	box-shadow: none !important;

}

.row > .vertical-row { // Split a column vertically
	
	display: flex;
	flex-direction: column;

}

	.row > .vertical-row > * {
		
		flex-grow: 1;

	}
	
/* Image aspect ratio – don't shift the page after loading the image */

.aspect { // aspect ratio is specified as this element's --ratio CSS variable
	
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    overflow: hidden;
    position: relative;
    text-align: center;
    
}

	.aspect > img {
		
		max-width: 100%;
		height: auto;
		margin: 0 auto;
	
	}
	
	.aspect:before {
		
		content: '';
		padding-bottom: calc(100%*1/var(--ratio)); /* ratio:1 */
	
	}

	@-moz-document url-prefix() { // No-flex version for FF. FF devs insist flexbox item's vertical paddign to be 0 without explicit parent height, instead of % of width like Chrome, Safari etc. Disabled because of many problems.

		.aspect { display: block; font-size: 0; letter-spacing: 0; }
		.aspect:before, .aspect > * { display: inline-block; font-size: initial; }
		.aspect:before { display: none; }

	}
	
	.align-bottom.aspect > * {
		
		align-self: flex-end;
		vertical-align: bottom;

	}

	.align-middle.aspect > * {
		
		align-self: center;
		vertical-align: middle;

	}

@media screen and (max-width: $screen-narrow-max) {

	.row:not(.half) { // To do: revert to flex in order to use the order property on mobile
		
		display: block;
		overflow-x: hidden;

	}

	.row > *, .row > [class^=col] {

		padding: 0;
		width: 100%; // Important because of Android Browser
		border: none;
		margin: $line-height-em/2 0;
		box-sizing: border-box;

	}
	
	@supports (--a: 1) {

		.row > *, .row > [class^=col] {
	
			padding: .3em;
			flex: 0 0 100% !important;
	
		}
	
	}
	
	.row > *:empty {
		
		display: none;

	}

	.row > .full-mobile-width, .row > [class^=col].full-mobile-width {
		
		box-sizing: content-box;
		padding: 0;

	}
	
	.row.no-spacing > *, .row.no-spacing > [class^=col] {

		margin: 0;
		padding: 0;

	}

	.no-mobile-gutter.row > * {
		
		padding: 0;

	}
	
	.row > *, .row.border, .row.border > * {

		border: none;

	}

	.row.half > * {
		
		width: 50% !important;
		flex: 0 0 50% !important;

	}
	
	.row.border-all .row {
		
		width: calc(100% + #{$line-height-em});
	
	}
	
	.row.border-all > *:not(:first-child), .row.border-all .row>*:not(:first-child) {
		
		border-left: none;
		border-top: 1px solid;

	}

	.masonry, .masonry[class^=col] {
		
	    -moz-column-count: 2;
	    -webkit-column-count: 2;
	    column-count: 2;
		
	}

}
