//   Grids + Sass generated by Gridset: https://gridsetapp.com
//
//   Note ---------------------------------------------------------
//
// * The Gridset Sass output is divided into two types: functions and mixins. 
//   
// * prefix = the grid prefix you defined in your set.
//   
// * Containers are optional. Use these when a span is nested within another span. So an element spanning columns 2-3 inside 
//   an element spanning 1-5 would be: gs-span(prefix, 2, 3, (1, 5))
//   
// * When passing arguments, use false for null arguments, so a span with no end would be: gs-span(x, 2), but a span 
//   with no end and a container would be: gs-span(prefix, 2, false, (1, 5))
//   
// * Use IE flags ($ie) when building styles for Internet Explorer 8 and below. You can use either 'ie' or 'true'. 
//   A span in IE would be: gs-span(prefix, 2, 3, false, ie) or gs-span(prefix, 2, 3, false, true)
//
// * Setting *display unit* to true will return the unit with the measurement (ex: 30% or 300px). Default is false.
//   
// * You will need to write your own media queries for different screen sizes. You can generate these based on your 
//   grid widths by using the gs-media function. This will only work in Sass versions 3.2 and up. 
//
// * Use min, max and min-max define the type of query: min-width, max-width, or both, respectively. Here is an example:
//   
//   @include gs-media(prefix, max) {
//   	
//   	-- CSS goes here --
//   	
//   }
//     
//   Functions ----------------------------------------------------
//
//   Functions will return an exact measurement (float) for specific properties.
//   
// * gs-grid(prefix)
//   Returns a list of all column widths (in percentages) in a grid.
//   
// * gs-constraints(prefix)
//   Returns a list of all column widths in a grid that are constrained to a width, min-width, or max-width.
//
// * gs-gutter(prefix, (container start, container end), display unit)
//   Returns the exact gutter of a grid as a numeric value.
//   
// * gs-width(prefix, start, end, (container start, container end), display unit)
//   Returns the exact width measurement of the span of columns as a numeric value.
//   
// * gs-marginleft(prefix, start, (container start, container end), display unit)
//   Returns the exact left offset of a span as a numeric value.
//
// * gs-adjust(prefix, measurement, (container start, container end), display unit)
//   Returns a nested measurement adjusted for the width of the container.
//
//   -------------------------------------------------------------- 

@function gs-grid($prefix){

  @if $prefix == d	{ @return (5.246113991640504,5.246113991640504,5.246113991640504,5.246113991640504,5.246113991640504,5.246113991640504,5.246113991640504,5.246113991640504,5.246113987103131,5.246113985506565,5.246113985251162,5.246113984315122); }
  @if $prefix == t	{ @return (10.22135416837602,10.22135416837602,10.22135416837602,10.22135416837602,10.221354166158505,10.221354164129238,10.221354161814624,10.22135416772665); }
  @if $prefix == m	{ @return (87.8125,9.0625); }

}

@function gs-contraints($prefix){
  
  @if $prefix == d	{ @return (false,false,false,false,false,false,false,false,false,false,false,false); }
  @if $prefix == t	{ @return (false,false,false,false,false,false,false,false); }
  @if $prefix == m	{ @return (false,false); }

}

@function gs-gutter($prefix, $container: false, $unit:false){
  
  $gutter: 0;

  @if $prefix == d	{ $gutter: 3.36787565; }
  @if $prefix == t	{ $gutter: 2.60416667; }
  @if $prefix == m	{ $gutter: 3.125; }

  @if $unit == true { @return #{gs-adjust($prefix, $gutter, $container) + '%'}; }
  @else { @return gs-adjust($prefix, $gutter, $container); }
	
}

@function gs-width($grid, $start, $end: false, $container: false, $unit: false){

  $cols: gs-grid($grid);
  $gutter: gs-gutter($grid);
  $measure: 0;
  $gutters: 0;
  $i: $start;

  @if $end != false {

    @if ($end - $start) > 0 { $gutters: ($gutter * ($end - $start)); }

    @while $i <= $end {
						
      $measure: $measure + nth($cols,$i);
      $i: $i + 1;

    }

  }
  @else {
		
    $conscols: gs-contraints($grid);
    $conscol: nth($conscols,$start);
		
    @if ($conscol != false) and ($unit == true) { @return #{$conscol}; }
		
    $measure: nth($cols,$start);

  }
	
  @if $unit == true { @return #{gs-adjust($grid, $measure + $gutters, $container) + '%'}; }
  @else { @return gs-adjust($grid, $measure + $gutters, $container); }

}

@function gs-marginleft($grid, $spanstart, $container: false, $unit: false){

  @if ($container == false and $spanstart > 1) or ($container != false and $spanstart > nth($container,1)) {

    $start: 1;
    $end: $spanstart - 1;
    
    @if $container != false { $start: nth($container,1); }
    @if $end == $start { $end: false; }
    
    $margin: gs-width($grid, $start, $end);
    $gutter: gs-gutter($grid);
		
    @if $unit == true { @return #{gs-adjust($grid, $margin + $gutter, $container) + '%'}; }
    @else { @return gs-adjust($grid, $margin + $gutter, $container); }

  }
  @else {

    @return 0;

  }

}

@function gs-adjust($grid, $measure, $container: false, $unit: false){
	
  $containerend: false;
  @if length($container) == 2 { $containerend: nth($container,2); }
	
  @if $container != false {

    $adjusted: $measure / gs-width($grid, nth($container,1), $containerend);
    
    @if $unit == true { @return #{($adjusted * 100) + '%'}; }
    @else { @return $adjusted * 100; }

  }
  @else {
	
    @if $unit == true { @return #{$measure + '%'}; }
    @else { @return $measure; }

  }

}

//   Mixins  ------------------------------------------------------
//
//   The Gridset mixins include every property you need to position or add padding to an element, using the functions
//   to calculate these properties.
//   
// * gs-span(prefix, start, end, (container start, container end), IE flag)
//   All of the properties you need to place your element on grid. Enter *all* for 100% width items. 
//   An IE flag of *ie* or *true* (without the astericks) will return special styles for Internet Explorer 8 and below.
//   
// * gs-pad(prefix, padding type, (container start, container end))
//   All of the properties you need to add the different types of padding to an element. 
//   Valid types: pad, padfull, padin, padinfull
//   Explanation of padding types here: https://gridsetapp.com/documentation/classes/
//   
// * gs-float(prefix, direction, (container start, container end))
//   All of the properties you need to float an element in one direction and give it the proper amount of margin 
//   in the opposite direction. Direction = left or right.
//   
// * gs-media(prefix, type)
//   This will generate the appropriate media query for a particular grid based on the range min or max for each grid.
//   If the type is invalid, the styles will be generated without a media query. (Sass versions 3.2+ only)
//   Valid types: min, max, min-max
//   *min* will output a media query for the range min, *max* will output a media query for the 
//   range max, and *min-max* will use both (bookending the query).
//   
//   -------------------------------------------------------------- 

@mixin gs-media($prefix, $type: false){

  @if $prefix == d {
    @if ($type == min) or ($type == min-max) { @media only screen and (min-width: 990px) { @content; } }
    @else { @content; }
  }
  @else if $prefix == t {
    @if $type == min { @media only screen and (min-width: 768px) { @content; } }
    @else if ($type == max) { @media only screen and (max-width: 989px) { @content; } }
    @else if ($type == min-max) { @media only screen and (min-width: 768px) and (max-width: 989px) { @content; } }
  }
  @else if $prefix == m {
    @if ($type == max) or ($type == min-max) { @media only screen and (max-width: 767px) { @content; } }
    @else { @content; }
  }

}

@mixin gs-span($grid, $start, $end: false, $container: false, $ie: false){
	
  @if $start == all {
	
    clear: both;
    display: block;
    float: left;
    margin-left: 0;
    width: 100%;
		
  }
  @else {
  
    $marginright: -100%;
    @if ($ie == ie) or ($ie == true) { $marginright: -99.9%; }
	
    display: block;
    float: left;
    margin-left: gs-marginleft($grid, $start, $container, true);  
    margin-right: $marginright;
    width: gs-width($grid, $start, $end, $container, true);
	  
  }

}

@mixin gs-pad($grid, $type: pad, $container: false){

  $pad: 0;

  @if $type == pad or $type == padin {

    $pad: (gs-gutter($grid) / 2);

  }
  @else if $type == padfull or $type == padinfull {

    $pad: gs-gutter($grid);

  }

  @if $container != false { $pad: gs-adjust($grid, $pad, $container); }

  @if $type == pad or $type == padfull {

    left: #{'-' + $pad + '%'};
    position: relative;

  }
  @else if $type == padin or $type == padinfull {

    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;

  }

  padding-left: #{$pad + '%'};
  padding-right: #{$pad + '%'};

}

@mixin gs-float($grid, $direction, $container: false){
	
  $margin: gs-gutter($grid);
  @if $container != false { $margin: gs-adjust($grid, $margin, $container); }
	
  clear: none;
  float: $direction;
  
  @if $direction == left {
  
    margin-left: 0;
    margin-right: #{$margin + '%'};
  	
  }
  @else if $direction == right {
  
    margin-right: 0;
    margin-left: #{$margin + '%'};
  	
  }
  
}

//   Variables  ---------------------------------------------------
//
//   Information about your grids and measurements to use in your own Sass functions.
//   
//   -------------------------------------------------------------- 

$gs-prefixes: d, t, m;