/*
 *  This file is part of adapta-gtk-theme
 *
 * Copyright (C) 2016-2018 Tista <tista.gma500@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

//
// Drawing mixins
//
// Generic drawing of more complex things
//

//
// Scaling function
//

$ref_size: 13.33px; // = 10pt = 1em

@function rem($px, $fs: $ref_size, $sw: $ref_weight) {
  @return round($px / $fs * $sw * 100) / 100 * 1rem;
}


//
// Default shadows
//

$z-depth-1: 0 1px 2px rgba(0, 0, 0, 0.28);
$z-depth-2: 0 2.5px 4.5px rgba(0, 0, 0, 0.34);
$z-depth-3: 0 4.5px 5.5px rgba(0, 0, 0, 0.38);
$z-depth-4: 0 10px 14px rgba(0, 0, 0, 0.44);
$z-depth-5: 0 14px 19px rgba(0, 0, 0, 0.50);

// tile borders + dummy z-depth-2 area
$z-depth-2-tiled: 0 2.5px 4.5px transparent,
                  1px 0 $panel_bg_color, // side-edges
                  -1px 0 $panel_bg_color;
$z-depth-2-tiled-top: 0 2.5px 4.5px transparent,
                      0 1px $panel_bg_color;
$z-depth-2-tiled-bottom: 0 2.5px 4.5px transparent,
                         0 -1px $panel_bg_color;
$z-depth-2-tiled-left: 0 2.5px 4.5px transparent,
                       1px 0 $panel_bg_color;
$z-depth-2-tiled-right: 0 2.5px 4.5px transparent,
                        -1px 0 $panel_bg_color;
// z-depth-2.5 actual shadows + dummy z-depth-4 area
$z-depth-2-backdrop: 0 10px 14px transparent,
                     0 4.5px 5.5px rgba(0, 0, 0, 0.13),
                     $z-depth-2;
$z-depth-2-backdrop-tiled: 0 10px 14px transparent,
                           1px 0 $panel_bg_color,
                           -1px 0 $panel_bg_color;
$z-depth-2-backdrop-tiled-top: 0 10px 14px transparent,
                               0 1px $panel_bg_color;
$z-depth-2-backdrop-tiled-bottom: 0 10px 14px transparent,
                                  0 -1px $panel_bg_color;
$z-depth-2-backdrop-tiled-left: 0 10px 14px transparent,
                                1px 0 $panel_bg_color;
$z-depth-2-backdrop-tiled-right: 0 10px 14px transparent,
                                 -1px 0 $panel_bg_color;


//
// Header-bar shadows
//

$header-shadow-light: 0 1px 1px rgba(0, 0, 0, 0.16),
                      0 1px 2px rgba(0, 0, 0, 0.26),
                      0 2px 3px rgba(0, 0, 0, 0.32);
$header-shadow-dark: 0 1px 1px rgba(0, 0, 0, 0.02),
                     0 1px 2px rgba(0, 0, 0, 0.11),
                     0 2px 3px rgba(0, 0, 0, 0.10);
$sub-header-shadow-light-ltr: 0 1px 1px rgba(0, 0, 0, 0.16),
                              0 1px 2px rgba(0, 0, 0, 0.26),
                              0 2px 3px rgba(0, 0, 0, 0.32),
                              -5px 0 0 -1px $inverted_dark_color,
                              -2px 0 0 -1px $borders_color;
$sub-header-shadow-dark-ltr: 0 1px 1px rgba(0, 0, 0, 0.02),
                             0 1px 2px rgba(0, 0, 0, 0.11),
                             0 2px 3px rgba(0, 0, 0, 0.10),
                             -5px 0 0 -1px $inverted_dark_color,
                             -2px 0 0 -1px $borders_color;
$sub-header-shadow-light-rtl: 0 1px 1px rgba(0, 0, 0, 0.16),
                              0 1px 2px rgba(0, 0, 0, 0.26),
                              0 2px 3px rgba(0, 0, 0, 0.32),
                              5px 0 0 -1px $inverted_dark_color,
                              2px 0 0 -1px $borders_color;
$sub-header-shadow-dark-rtl: 0 1px 1px rgba(0, 0, 0, 0.02),
                             0 1px 2px rgba(0, 0, 0, 0.11),
                             0 2px 3px rgba(0, 0, 0, 0.10),
                             5px 0 0 -1px $inverted_dark_color,
                             2px 0 0 -1px $borders_color;
$selected-header-shadow-light-ltr: 0 1px 1px rgba(0, 0, 0, 0.16),
                                   0 1px 2px rgba(0, 0, 0, 0.26),
                                   0 2px 3px rgba(0, 0, 0, 0.32),
                                   -5px 0 0 -1px
                                   mix($selected_bg_color,
                                   $inverted_dark_color, 87%);
$selected-header-shadow-dark-ltr: 0 1px 1px rgba(0, 0, 0, 0.02),
                                  0 1px 2px rgba(0, 0, 0, 0.11),
                                  0 2px 3px rgba(0, 0, 0, 0.10),
                                  -5px 0 0 -1px
                                  mix($selected_bg_color,
                                  $inverted_dark_color, 87%);
$selected_header-shadow-light-rtl: 0 1px 1px rgba(0, 0, 0, 0.16),
                                   0 1px 2px rgba(0, 0, 0, 0.26),
                                   0 2px 3px rgba(0, 0, 0, 0.32),
                                   5px 0 0 -1px
                                   mix($selected_bg_color,
                                   $inverted_dark_color, 87%);
$selected-header-shadow-dark-rtl: 0 1px 1px rgba(0, 0, 0, 0.02),
                                  0 1px 2px rgba(0, 0, 0, 0.11),
                                  0 2px 3px rgba(0, 0, 0, 0.10),
                                  5px 0 0 -1px
                                  mix($selected_bg_color,
                                  $inverted_dark_color, 87%);
$tiled-header-shadow-light-ltr: 0 1px 1px rgba(0, 0, 0, 0.16),
                                0 1px 2px rgba(0, 0, 0, 0.26),
                                0 2px 3px rgba(0, 0, 0, 0.32),
                                -5px 0 0 -1px $panel_bg_color,
                                -2px 0 0 -1px $borders_color;
$tiled-header-shadow-dark-ltr: 0 1px 1px rgba(0, 0, 0, 0.02),
                               0 1px 2px rgba(0, 0, 0, 0.11),
                               0 2px 3px rgba(0, 0, 0, 0.10),
                               -5px 0 0 -1px $panel_bg_color,
                               -2px 0 0 -1px $borders_color;
$tiled-header-shadow-light-rtl: 0 1px 1px rgba(0, 0, 0, 0.16),
                                0 1px 2px rgba(0, 0, 0, 0.26),
                                0 2px 3px rgba(0, 0, 0, 0.32),
                                5px 0 0 -1px $panel_bg_color,
                                2px 0 0 -1px $borders_color;
$tiled-header-shadow-dark-rtl: 0 1px 1px rgba(0, 0, 0, 0.02),
                               0 1px 2px rgba(0, 0, 0, 0.11),
                               0 2px 3px rgba(0, 0, 0, 0.10),
                               5px 0 0 -1px $panel_bg_color,
                               2px 0 0 -1px $borders_color;
$fake-shadow-light: linear-gradient(to bottom, rgba(0, 0, 0, 0.32),
                                               rgba(0, 0, 0, 0.12) 2px,
                                               rgba(0, 0, 0, 0.04) 4px,
                                               rgba(0, 0, 0, 0.00) 6px,
                                               transparent);
$fake-shadow-dark: linear-gradient(to bottom, rgba(0, 0, 0, 0.14),
                                              rgba(0, 0, 0, 0.05) 2px,
                                              rgba(0, 0, 0, 0.02) 4px,
                                              rgba(0, 0, 0, 0.00) 6px,
                                              transparent);


//
// Side-bar shadows
//

$sidebar-light-ltr: inset -2px 2px 2px -2px rgba(0, 0, 0, 0.05),
                    inset -3px 3px 3px -2px rgba(0, 0, 0, 0.05);
$sidebar-light-rtl: inset 2px 2px 2px -2px rgba(0, 0, 0, 0.05),
                    inset 3px 3px 3px -2px rgba(0, 0, 0, 0.05);
$sidebar-dark-ltr: inset -2px 2px 1px -2px rgba(0, 0, 0, 0.01),
                   inset -3px 1px 3px -2px rgba(0, 0, 0, 0.05);
$sidebar-dark-rtl: inset 2px 2px 1px -2px rgba(0, 0, 0, 0.01),
                   inset 3px 1px 3px -2px rgba(0, 0, 0, 0.05);


//
// Inline-toolbar shadows
//

$inline-shadow-light: inset 0 1px 2px -1px rgba(0, 0, 0, 0.02),
                      inset 0 2px 3px -2px rgba(0, 0, 0, 0.07);
$inline-shadow-dark: inset 0 1px 2px -1px rgba(0, 0, 0, 0.12),
                     inset 0 3px 4px -3px rgba(0, 0, 0, 0.05);


//
// Info-bar shadows
//
// $infobar-shadow-light: inset 0 1px 2px rgba(0, 0, 0, 0.08);
// $infobar-shadow-dark: inset 0 1px 2px rgba(0, 0, 0, 0.04);


//
// Reorderable-tab shadows
//

$tab-shadow-light: -1px 0 2px rgba(0, 0, 0, 0.02),
                  -1px 0 4px rgba(0, 0, 0, 0.02),
                  1px 0 2px rgba(0, 0, 0, 0.02),
                  1px 0 4px rgba(0, 0, 0, 0.02);
$tab-shadow-dark: -1px 0 2px rgba(0, 0, 0, 0.02),
                  -1px 0 4px rgba(0, 0, 0, 0.03),
                  1px 0 2px rgba(0, 0, 0, 0.02),
                  1px 0 4px rgba(0, 0, 0, 0.03);


//
// Toolbar shadows
//

$toolbar-shadow-light: inset 0 1px 1px rgba(0, 0, 0, 0.18),
                       inset 0 4px 2px -4px rgba(0, 0, 0, 0.20),
                       inset 0 8px 3px -5px rgba(0, 0, 0, 0.24);
$toolbar-shadow-dark: inset 0 1px 1px rgba(0, 0, 0, 0.18),
                      inset 0 4px 3px -4px rgba(0, 0, 0, 0.15),
                      inset 0 8px 3px -5px rgba(0, 0, 0, 0.14);


//
// Nautilus Desktop Label shadow
//

$z-depth-1-label: 0 0 1px rgba(0, 0, 0, 0.26),
                  0 1px 2px rgba(0, 0, 0, 0.26),
                  0 2px 3px rgba(0, 0, 0, 0.32);


//
// Transition timing
//

$slope_slow: cubic-bezier(0.0, 0.0, 0.2, 1.0);
$slope_medium: cubic-bezier(0.4, 0.0, 0.2, 1.0);
$slope_quick: cubic-bezier(0.4, 0.0, 0.6, 1.0);


// /******************
//  * Ripple effects *
//  ******************/

//
// Ripple effects
//

@keyframes ripple_effect {
//
// Ripple effect drawing function
//

  0% {
    background-image: radial-gradient(circle farthest-corner at center,
                                      $track_color 0%,
                                      transparent 0%),
                      image(gtkalpha(currentColor, 0));
  }
  66% {
    background-image: radial-gradient(circle farthest-corner at center,
                                      $track_color 100%,
                                      transparent 0%),
                      image($track_color);
  }
  100% {
    background-image: radial-gradient(circle farthest-corner at center,
                                      $track_color 100%,
                                      transparent 0%),
                      image(gtkalpha(currentColor, 0));
  }
}

@keyframes flat_ripple_effect {
  0% {
    background-image: radial-gradient(circle farthest-corner at center,
                                      $track_color 0%,
                                      transparent 0%),
                      image($track_color);
  }
  66% {
    background-image: radial-gradient(circle farthest-corner at center,
                                      $track_color 100%,
                                      transparent 0%),
                      image($track_color);
  }
  100% {
    background-image: radial-gradient(circle farthest-corner at center,
                                      gtkalpha(currentColor, 0) 100%,
                                      transparent 0%),
                      image($track_color);
  }
}


//
// Entries
//

// templates for the fallback mode entries
%entry_fallback_normal {
  border: 1px solid if($variant == light,
                    mix($base_color, $fixed_fg_color, 90%),
                    $solid_light_borders_color);
  border-image: none;
  background-color: $light_color;
  color: $secondary_fg_color;
  box-shadow: none;
}

%entry_fallback_focus {
  border: 1px solid $selected_bg_color;
  border-image: none;
  background-color: $light_color;
  color: $fg_color;
  box-shadow: none;
}

%entry_fallback_insensitive {
  border: 1px solid if($variant == light,
                    mix($base_color, $fixed_fg_color, 90%),
                    $solid_light_borders_color);
  border-image: none;
  background-color: mix($bg_color, $fg_color, 96%);
  color: $insensitive_fg_color;
  box-shadow: none;
}

@mixin entry($t, $c: $fg_color, $fc:$selected_bg_color) {
//
// Entries drawing function
//
// $t: entry type
// $c: text color
// $fc: focus color
//
// possible $t values:
// normal, focus, insensitive, flat-normal, flat-focus, flat-insensitive;
//

  @if $t == normal {
    border-radius: 0;
    -gtk-outline-radius: 0;
    border-color: $solid_light_borders_color;
    border-image: radial-gradient(circle farthest-corner at center,
                                  $outline_track_color 100%,
                                  transparent)
                                  0 0 1 / 0 0 1px;
    color: gtkopacity($c, 0.87);
  }
  @if $t == focus {
    border-color: $solid_light_borders_color;
    border-image: radial-gradient(circle farthest-corner at center,
                                  $fc 100%,
                                  transparent)
                                  0 0 2 / 0 0 2px;
    color: $c;
    transition: all 0.2s $slope_medium,
                box-shadow 0.2s $slope_medium,
                color 0s;
  }
  @if $t == insensitive {
    border-color: $solid_light_borders_color;
    border-image: radial-gradient(circle farthest-corner at center,
                                  $outline_track_color 100%,
                                  transparent)
                                  0 0 1 / 0 0 1px;
    color: gtkopacity($c, 0.28);
  }
  @if $t == flat-normal {
    border-radius: 0;
    -gtk-outline-radius: 0;
    border-color: $solid_light_borders_color;
    border-image: radial-gradient(circle farthest-corner at center,
                                  $outline_track_color 100%,
                                  transparent)
                                  0 0 1 / 0 0 1px;
    background-color: transparent;
    color: gtkopacity($c, 0.87);
  }
  @if $t == flat-focus {
    border-color: $solid_light_borders_color;
    border-image: radial-gradient(circle farthest-corner at center,
                                  $fc 100%,
                                  transparent)
                                  0 0 2 / 0 0 2px;
    color: $c;
    transition: all 0.2s $slope_medium,
                box-shadow 0.2s $slope_medium,
                color 0s;
  }
  @if $t == flat-insensitive {
    border-color: $solid_light_borders_color;
    border-image: radial-gradient(circle farthest-corner at center,
                                  $outline_track_color 100%,
                                  transparent)
                                  0 0 1 / 0 0 1px;
    background-color: transparent;
    color: gtkopacity($c, 0.28);
  }
}


//
// Buttons
//

// template for standard buttons
%button_normal {
  background-image: radial-gradient(circle farthest-corner at center,
                                    gtkalpha(currentColor, 0) 100%,
                                    transparent 0%),
                    image(gtkalpha(currentColor, 0));
  box-shadow: $z-depth-1,
              inset 0 1px $highlight_color;
  transition-timing-function: $slope_slow;
  transition-duration: 0.2s;
}

%button_hover {
  background-image: radial-gradient(circle farthest-corner at center,
                                    gtkalpha(currentColor, 0) 100%,
                                    transparent 0%),
                    image(gtkalpha(currentColor, 0));
  box-shadow: $z-depth-2,
              inset 0 1px $highlight_color;
}

%button_active {
  box-shadow: $z-depth-2,
              inset 0 1px $highlight_color;
  transition: all 0.2s $slope_slow,
              background-image 0s;
  animation: ripple_effect 0.3s $slope_slow forwards;
}

%button_checked {
  box-shadow: $z-depth-1,
              inset 0 1px $highlight_color;
}

%button_disabled,
%button_checked_disabled {
  box-shadow: none;

  > label { color: inherit; }
}

%button_flat_normal {
  background-image: radial-gradient(circle farthest-corner at center,
                                    gtkalpha(currentColor, 0) 100%,
                                    transparent 0%),
                    image(gtkalpha(currentColor, 0));
  box-shadow: none;
  transition-timing-function: $slope_slow;
  transition-duration: 0.2s;
}

%button_flat_hover {
  background-image: radial-gradient(circle farthest-corner at center,
                                    gtkalpha(currentColor, 0) 100%,
                                    transparent 0%),
                    image($track_color);
  box-shadow: none;
}

%button_flat_active {
  box-shadow: none;
  transition: all 0.2s $slope_slow,
              background-image 0s;
  animation: flat_ripple_effect 0.3s $slope_slow forwards;
}

%button_flat_checked {
  box-shadow: none;
}

%button_flat_disabled,
%button_flat_checked_disabled {
  box-shadow: none;

  > label { color: inherit; }
}

// templates for the fallback mode buttons
%button_fallback_normal {
  border: 1px solid if($variant == light,
                    mix($base_color, $fixed_fg_color, 90%),
                    $solid_light_borders_color);
  background-color: $light_color;
  color: $secondary_fg_color;
  box-shadow: none;
}

%button_fallback_hover {
  border: 1px solid if($variant == light,
                    mix($base_color, $fixed_fg_color, 80%),
                    $solid_light_borders_color);
  background-color: mix($light_color, $fg_color, 96%);
  color: $fg_color;
  box-shadow: none;
}

%button_fallback_active {
  border: 1px solid if($variant == light,
                    mix($base_color, $fixed_fg_color, 80%),
                    $solid_light_borders_color);
  background-color: mix($light_color, $fg_color, 92%);
  color: $fg_color; // do not use inverted colours
  box-shadow: none;
  animation: none;
}

%button_fallback_insensitive {
  border: none;
  background-color: mix($bg_color, $fg_color, 96%);
  color: $insensitive_fg_color;
  box-shadow: none;
}

%button_fallback_checked_insensitive {
  border: none;
  background-color: mix($selected_bg_color, $light_color, 20%);
  color: mix($selected_bg_color, $light_color, 40%);
  box-shadow: none;
}

@mixin button($t, $c:$light_color, $tc:$fg_color) {
//
// Button drawing function
//
// $t:    button type,
// $c:    base button color for colored* types
// $tc:   optional text color for colored* types
//
// possible $t values:
// normal, hover, active, insensitive, checked, checked-insensitive,
// flat-normal, flat-hover, flat-active, flat-insensitive, flat-checked,
// flat-checked-insensitive, undecorated
//

  @if $t == normal {
  //
  // normal button
  //
    @extend %button_normal;
    background-color: $c;
    color: $secondary_fg_color;
  }

  @else if $t == hover {
  //
  // hovered button
  //
    @extend %button_hover;
    color: $tc;
  }

  @else if $t == active {
  //
  // pushed button
  //
    @extend %button_active;
    color: $tc;
  }
  @else if $t == insensitive {
  //
  // insensitive button
  //
    @extend %button_disabled;
    background-color: $track_color;
    color: if($tc!=$fg_color, $insensitive_fg_color,
                              $insensitive_secondary_fg_color);
  }
  @else if $t == checked {
  //
  // checked button
  //
    @extend %button_checked;
    background-color: $selected_bg_color;
    color: $selected_fg_color;
  }
  @else if $t == checked-insensitive {
  //
  // checked insensitive button
  //
    @extend %button_checked_disabled;
    background-color: $track_color;
    color: gtkopacity($selected_bg_color, 0.4);
  }

  @else if $t == flat-normal {
  //
  // normal flat button
  //
    @extend %button_flat_normal;
    background-color: transparent;
  }
  @else if $t == flat-hover {
  //
  // hovered flat button
  //
    @extend %button_flat_hover;
  }
  @else if $t == flat-active {
  //
  // pushed flat button
  //
    @extend %button_flat_active;
  }
  @else if $t == flat-insensitive {
  //
  // insensitive flat button
  //
    @extend %button_flat_disabled;
    background-color: transparent;
  }
  @else if $t == flat-checked {
  //
  // checked flat button
  //
    @extend %button_flat_checked;
    background-color: $track_color;
    color: $tc;
  }
  @else if $t == flat-checked-insensitive {
  //
  // checked flat insensitive button
  //
    @extend %button_flat_checked_disabled;
  }
}


//
// Overshoot
//

@mixin overshoot($p, $t:normal, $c:$accent_color) {
//
// Overshoot drawing function
//
// $p: position
// $t: type
// $c: base color
//
// possible $p values:
// top, bottom, right, left
//
// possible $t values:
// normal, backdrop
//

  background-size: 150% 50%;

  @if ($p == left) or ($p == right) { background-size: 50% 150%; }

  background-image: radial-gradient(circle farthest-side at $p,
                                    gtkopacity($c, 0.13) 50%,
                                    gtkopacity($c, 0.13) 50%,
                                    transparent);
  background-repeat: no-repeat;
  background-position: $p;
  // reset some properties to be sure to not inherit them somehow
  background-color: transparent;
  border: none;
  box-shadow: none;
  transition: none;
}

