// Shadows
$shadow_0: 0px 1px 2px 0px rgba(16, 16, 16, 0.1), 0px 2px 2px 0px rgba(16, 16, 16, 0.05); // Slider hover shadow
$shadow_1: 0px 1px 1px 0px rgba(16, 16, 16, 0.12), 0px 1px 2px 0px rgba(16, 16, 16, 0.06); // Header-button shadow
$shadow_2: 0px 1px 1px 0px rgba(16, 16, 16, 0.1), 0px 1px 2px 0px rgba(16, 16, 16, 0.05); // Slider normal shadow
$shadow_3: 0px 1px 1px 0px rgba(16, 16, 16, 0.04), 0px 1px 2px 0px rgba(16, 16, 16, 0.01); // Normal button shadow
$shadow_4: 0px 2px 3px 0px rgba(16, 16, 16, 0.2), 0px 3px 5px 0px rgba(16, 16, 16, 0.15); // Switch-slider hover shadow
$shadow_5: 0px 1px 2px 0px rgba(16, 16, 16, 0.15), 0px 2px 3px 0px rgba(16, 16, 16, 0.1); // Switch-slider normal shadow
$text_shadow: 0 -1px rgba(#ffffff, 0.04), -1px  0px rgba(#202020, 0.05), 1px  0px rgba(#202020, 0.05),
              0px  1px rgba(#202020, 0.3), 0px  2px rgba(#202020, 0.05); // text and icon shadow

// Transitions
$ease-out-quad: cubic-bezier(0.25, 0.46, 0.45, 0.94);
$transition_1: all 0.2s cubic-bezier(0, 0, 0.2, 1), box-shadow 0.2s cubic-bezier(0, 0, 0.2, 1);
$transition_2: all 0.1s cubic-bezier(0, 0, 0.2, 1);
$shadow_transition: box-shadow 0.2s cubic-bezier(0, 0, 0.2, 1);
$button_transition: all 100ms $ease-out-quad;
$backdrop_transition: 200ms ease-out;

// Animations
$switch_animation: switch_ripple_effect 0.3s cubic-bezier(0, 0, 0.2, 1);

@keyframes switch_ripple_effect {
  from {
    background-image: radial-gradient(circle farthest-corner at center,
                                      $success_color 0%,
                                      transparent 0%);
  }

  to {
    background-image: radial-gradient(circle farthest-corner at center,
                                      $success_color 100%,
                                      transparent 0%);
  }
}

@keyframes header_ripple_effect {
  from {
    background-image: radial-gradient(circle farthest-corner at center,
                                      $header_bg 0%,
                                      transparent 0%);
  }

  to {
    background-image: radial-gradient(circle farthest-corner at center,
                                      $header_bg 100%,
                                      transparent 0%);
  }
}

// Drawing mixins

// Solid color image
@function _solid($c) {
  @return linear-gradient(to bottom, $c, $c);
}

// Entries

@mixin entry($t) {
//
// Entries drawing function
//
// $t: entry type
//

  @if $t==normal {
  //
  // normal entry
  //
    color: $text_color;
    border-color: $entry_border;
    background-color: $entry_bg;
    @if $variant == 'light' { box-shadow: $shadow_3, inset 0 0 0 1px rgba($borders_color, 0.01); }
  }

  @if $t==focus {
  //
  // focused entry
  //
    color: $text_color;
    border-color: $entry_highlight;
    background-color: $entry_bg;
    @if $variant == 'dark' {box-shadow: inset 0 0 0 2px $entry_highlight; }
    @if $variant == 'light' { box-shadow: 0px 1px 1px 0px transparent,
                                          0px 1px 2px 0px transparent, // set the same size transparent shadow for entry transition
                                          inset 0 0 0 2px $entry_highlight; }
  }

  @if $t==insensitive {
  //
  // insensitive entry
  //
    color: $insensitive_fg_color;
    border-color: $entry_border;
    background-color: transparentize($entry_bg, 0.45);
  }

  @if $t==header-normal {
  //
  // normal header-bar entry
  //
    @if $variant == 'dark' { border: none; }
    color: $header_fg;
    background-color: $header_button_bg;
    background-image: if($variant=='light', linear-gradient( 0deg, #f1f1f1 0%, #fdfdfd 95%, #fefefe 100%), none);

    image, image:hover { color: inherit; }
  }

  @if $t==header-focus {
  //
  // focused header-bar entry
  //
    @if $variant == 'dark' { border: none; box-shadow: 0 0 0 2px $entry_highlight, inset 0 0 0 1px $entry_highlight; }
    @if $variant == 'light' and $compact == 'false' { box-shadow: 0 0 0 2px $entry_highlight; border-color: $entry_highlight; }
    @if $variant == 'light' and $compact == 'true' { box-shadow: 0 0 0 2px $entry_highlight; }
    background-image: none;
  }

  @if $t==header-insensitive {
  //
  // insensitive header-bar entry
  //

    color: transparentize($header_fg, 0.45);
    background-color: transparentize($header_entry_bg, 0.15);
  }

  @else if $t==osd {
  //
  // normal osd entry
  //
    color: $osd_fg_color;
    border-color: $osd_entry_border;
    background-color: $osd_entry_bg;

    image, image:hover { color: inherit; }
  }

  @else if $t==osd-focus {
  //
  // active osd entry
  //
    color: $selected_fg_color;
    border-color: $osd_entry_border;
    background-color: $selected_bg_color;
  }

  @else if $t==osd-insensitive {
  //
  // insensitive osd entry
  //
    color: $osd_fg_color;
    background-color: transparentize($osd_entry_bg, 0.15);
  }
}

// Buttons

@mixin button($t, $actionb_bg:red, $actionb_fg: green) {
//
// Button drawing function
//
// $t:    button type,
// $actionb_bg, $actionb_fg: used for destructive and suggested action buttons

  @if $t==normal {
  //
  // normal button
  //
    color: $fg_color;
    border-color: $button_border;
    background-color: $button_bg;
    @if $variant=='light' { box-shadow: $shadow_3, inset 0 0 0 1px rgba($borders_color, 0.01); }
  }

  @else if $t==hover {
  //
  // hovered button
  //
    color: darken($fg_color, 10%);
    border-color: $borders_color;
    background-color: if($variant=='light', darken($button_bg, 3%), lighten($button_bg, 8%));
    box-shadow: none;
  }

  @else if $t==active {
  //
  // pushed button
  //
    color: $selected_fg_color;
    background-color: $selection_mode_bg;
    border-color: $selection_mode_bg;
    background-image: linear-gradient( 180deg, #4c97fe 0%, #0564e3 100%);
    box-shadow: none;
  }

  @else if $t==insensitive {
  //
  // insensitive button
  //
    label, & { color: $insensitive_fg_color; }

    border-color: $button_border;
    background-color: transparentize($button_bg, 0.45);
    box-shadow: $shadow_3;
  }

  @else if $t==insensitive-active {
  //
  // insensitive pushed button
  //
    label, & { color: transparentize($selected_fg_color, 0.2); }

    border-color: transparentize($selected_bg_color, 0.25);
    background-color: transparentize($selected_bg_color, 0.25);
    box-shadow: none;

    opacity: 0.6;
  }

  @if $t==flat-normal {
  //
  // normal button
  //
    border: none;
    background-color: transparent;
    box-shadow: none;
  }

  @else if $t==flat-hover {
  //
  // hovered button
  //
    color: darken($fg_color, 10%);
    background-color: if($variant=='light', rgba(black, 0.15), rgba(white, 0.15));
    border-color: if($variant=='light', rgba(black, 0.15), rgba(white, 0.15));
  }

  @else if $t==flat-active {
  //
  // pushed button
  //
    background-image: none;
    color: $selected_fg_color;
    background-color: if($variant=='light', rgba(black, 0.5), rgba(white, 0.25));
    text-shadow: if($variant=='light', $text_shadow, none);
    -gtk-icon-shadow: if($variant=='light', $text_shadow, none);
  }

  @else if $t==flat-checked {
  //
  // pushed button
  //
    background-image: none;
    color: $selected_fg_color;
    background-color: if($variant=='light', rgba(black, 0.65), rgba(white, 0.35));
    text-shadow: if($variant=='light', $text_shadow, none);
    -gtk-icon-shadow: if($variant=='light', $text_shadow, none);
  }

  @else if $t==flat-insensitive {
  //
  // insensitive button
  //
    label, & { color: $insensitive_fg_color; }

    background-color: transparent;
//    border: none;
  }

  @else if $t==flat-insensitive-active {
  //
  // insensitive pushed button
  //
    label, & { color: transparentize($selected_fg_color, 0.2); }

    background-color: lighten($fg_color, 20%);
    border-color: lighten($fg_color, 20%);
    opacity: 0.6;
  }

  @if $t==header-normal {
  //
  // normal header-bar button
  //
    border-color: $borders_color;
    color: $header_fg;
    background-color: $header_button_bg;
    background-image: if($variant == 'light', linear-gradient( 0deg, #f1f1f1 0%, #fdfdfd 95%, #fefefe 100%), none);
    box-shadow: $shadow_3;

    @if $variant == 'dark' { border: none; }

  }

  @else if $t==header-hover {
  //
  // hovered header-bar button
  //
    border-color: $borders_color;
    color: darken($header_fg, 2%);
    background-color: $header_button_hover_bg;
    background-image: if($variant == 'light', linear-gradient( 0deg, #f8f8f8 0%, #ffffff 100%), none);
    box-shadow: none;
  }

  @else if $t==header-active {
  //
  // pushed header-bar button
  //
    color: $selected_fg_color;
    background-color: $header_button_active_bg;
    background-image: none;
    border-color: $borders_color;
    text-shadow: if($variant == 'light', $text_shadow, none);
    -gtk-icon-shadow: if($variant == 'light', $text_shadow, none);
    box-shadow: none;
  }

  @else if $t==header-checked {
  //
  // pushed header-bar button
  //
    color: $selected_fg_color;
    background-color: $header_button_checked_bg;
    background-image: if($variant == 'light', linear-gradient( 0deg, #656565 0%, #707070 100%), none);
    border-color: $borders_color;
    border-top-color: if($variant == 'light', lighten($borders_color, 0%), $borders_color);
    border-bottom-color: if($variant == 'light', lighten($borders_color, 0%), $borders_color);
    text-shadow: if($variant == 'light', $text_shadow, none);
    -gtk-icon-shadow: if($variant == 'light', $text_shadow, none);
    box-shadow: none;
  }

  @else if $t==header-insensitive {
  //
  // insensitive header-bar button
  //
    label, & { color: transparentize($header_fg, 0.45); }

    background-color: $header_button_bg;
    box-shadow: $shadow_3;
  }

  @else if $t==header-insensitive-active {
  //
  // header-bar insensitive pushed button
  //
    color: transparentize($selected_fg_color, 0.25);
    background-color: transparentize($header_button_active_bg, 0.35);
    box-shadow: $shadow_3;
  }

  @else if $t==osd {
  //
  // normal osd button
  //
    color: $osd_fg_color;
    border-color: $osd_button_border;
    background-color: $osd_button_bg;
  }

  @else if $t==osd-hover {
  //
  // active osd button
  //
    color: $osd_fg_color;
    border-color: $osd_button_border;
    background-color: opacify(lighten($osd_button_bg, 7%), 0.1);
  }

  @else if $t==osd-active {
  //
  // active osd button
  //
    color: $selected_fg_color;
    border-color: $osd_button_border;
    background-color: $selected_bg_color;
  }

  @else if $t==osd-insensitive {
  //
  // insensitive osd button
  //
    color: $osd_insensitive_fg_color;
    border-color: $osd_button_border;
    background-color: transparentize($osd_button_bg, 0.15);
  }

  @else if $t==suggested_destructive {
  //
  // suggested or destructive action buttons
  //
    background-clip: border-box;

    color: $actionb_fg;
    background-color: $actionb_bg;
    border-color: darken($actionb_bg, 10%);
    background-image: none;
//    box-shadow: none;
  }

  @else if $t==undecorated {
  //
  // reset
  //
    border-color: transparent;
    background-color: transparent;
    background-image: none;
    box-shadow: none;
  }
}

//
// Overshoot
//
@mixin overshoot($p, $c:$selected_bg_color) {
// $p: position
// $c: base color
//
// possible $p values:
// top, bottom, right, left
//

  $_big_gradient_length: 60%;

  $_position: center top;
  $_big_gradient_size: 100% $_big_gradient_length;

  @if $p==bottom {
    $_position: center bottom;
  }

  @else if $p==right {
    $_position: right center;
    $_big_gradient_size: $_big_gradient_length 100%;
  }

  @else if $p==left {
    $_position: left center;
    $_big_gradient_size: $_big_gradient_length 100%;
  }

  background-image: -gtk-gradient(radial,
                                $_position, 0,
                                $_position, 0.6,
                                from(transparentize($c, 0.8)),
                                to(transparentize($c, 1)));

  background-size: $_big_gradient_size;
  background-repeat: no-repeat;
  background-position: $_position;

  background-color: transparent; // reset some properties to be sure to not inherit them somehow
  border: none;                  //
  box-shadow: none;              //
}

//
// Undershoot
//
@mixin undershoot($p) {
// $p: position
//
// possible $p values:
// top, bottom, right, left
//

  $_undershoot_color_dark: transparentize(black, 0.8);
  $_undershoot_color_light: transparentize(white, 0.8);

  $_gradient_dir: left;
  $_dash_bg_size: 10px 1px;
  $_gradient_repeat: repeat-x;
  $_bg_pos: center $p;

  background-color: transparent; // shouldn't be needed, but better to be sure;

  @if ($p == left) or ($p == right) {
    $_gradient_dir: top;
    $_dash_bg_size: 1px 10px;
    $_gradient_repeat: repeat-y;
    $_bg_pos: $p center;
  }

  background-image: linear-gradient(to $_gradient_dir, // this is the dashed line
                                    $_undershoot_color_light 50%,
                                    $_undershoot_color_dark 50%);

  padding-#{$p}: 1px;
  background-size: $_dash_bg_size;
  background-repeat: $_gradient_repeat;
  background-origin: content-box;
  background-position: $_bg_pos;
  border: none;
}
