/* Based on _Adwaita-base.scss from libhandy */

// HdyComboRow

popover.combo {
  padding: 0;

  list {
    background-color: transparent;

    > row {
      padding: 0 10px;
      min-height: 50px;

      &:first-child { @extend %linked_vertical_top; }
      &:last-child { @extend %linked_vertical_bottom; }
    }
  }

  overshoot.top { @extend %linked_vertical_top; }
  overshoot.bottom { @extend %linked_vertical_bottom; }

  scrollbar.vertical {
    background-color: $_popover_bg;

    &:dir(ltr) { @extend %linked_right; }
    &:dir(rtl) { @extend %linked_left; }
  }
}

// HdyExpanderRow

row.expander {
  padding: 0px;

  &:checked image.expander-row-arrow:not(:disabled) {
    color: $selected_bg_color;
  }

  image.expander-row-arrow:disabled {
    color: $insensitive_fg_color;
  }
}

// HdyKeypad

keypad {
  .digit {
    font-size: 200%;
    font-weight: bold;
  }

  .letters {
    font-size: 70%;
  }

  .symbol {
    font-size: 160%;
  }
}

// HdyViewSwitcher

viewswitcher {
  &, & button {
    margin: 0;
    padding: 0;
  }

  button {
    border-radius: 0;
    border-top: 0;
    border-bottom: 0;

    &:not(:checked):not(:hover) {
      background: transparent;
      border-color: transparent;
    }

    &:checked, &:active {
      border-color: $selected_bg_color;
    }

    // View switcher button
    > stack > box {
      &.narrow {
        font-size: 0.75rem;
        padding-top: 7px;
        padding-bottom: 5px;

        image,
        label {
          padding-left: 8px;
          padding-right: 8px;
        }
      }

      &.wide {
        padding: 8px 10px;

        label {
          &:dir(ltr) {
            padding-right: 7px;
          }

          &:dir(rtl) {
            padding-left: 7px;
          }
        }
      }
    }

    &.needs-attention {
      > stack > box label {
        background-image: -gtk-gradient(radial, center center, 0, center center, 0.5, to($selected_bg_color), to(transparent));
        background-size: 6px 6px;
        background-repeat: no-repeat;
        background-position: right 0px;

        &:dir(rtl) {
          background-position: left 0px;
        }
      }

      &:active > stack > box label {
        background-image: -gtk-gradient(radial, center center, 0, center center, 0.5, to($selected_fg_color), to(transparent));
      }
    }
  }
}

// HdyViewSwitcherBar

viewswitcherbar actionbar > revealer > box {
  padding: 0;
}

// Content list

list.content {
  &,
  list {
    background-color: transparent;
  }

  // Nested rows background
  list.nested > row:not(:active) {
    &:not(:hover):not(:selected),
    &:hover:not(.activatable):not(:selected) {
      background-color: mix($bg_color, $base_color);
    }

    &:hover.activatable:not(:selected) {
      background-color: if($variant != 'dark', mix($base_color, black, 95%), mix($base_color, white, 97%));
    }
  }

  > row {
    // Regular rows and expander header rows background
    &:not(.expander):not(:active):not(:hover):not(:selected),
    &:not(.expander):hover:not(.activatable):not(:selected),
    &.expander row.header:not(:active):not(:hover):not(:selected),
    &.expander row.header:hover:not(.activatable):not(:selected) {
      background-color: $base_color;
    }

    &:not(.expander):not(:active):hover.activatable:not(:selected),
    &.expander row.header:not(:active):hover.activatable:not(:selected) {
      background-color: if($variant != 'dark', mix($base_color, black, 95%), mix($base_color, white, 97%));
    }

    &,
    list > row {
      border-color: $borders_color;
      border-style: solid;
      transition: 200ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
    }

    // Top border
    &:not(:last-child) {
      border-width: 1px 1px 0px 1px;
    }

    // Rounded top
    &:first-child,
    &.expander:first-child row.header,
    &.expander:checked,
    &.expander:checked row.header,
    &.expander:checked + row,
    &.expander:checked + row.expander row.header {
      @extend %linked_vertical_top;
    }

    // Bottom border
    &:last-child,
    &.checked-expander-row-previous-sibling,
    &.expander:checked {
      border-width: 1px;
    }

    // Rounded bottom
    &:last-child,
    &.checked-expander-row-previous-sibling,
    &.expander:checked,
    &.expander:not(:checked):last-child row.header,
    &.expander:not(:checked).checked-expander-row-previous-sibling row.header,
    &.expander.empty:checked row.header,
    &.expander list.nested > row:last-child {
      @extend %linked_vertical_bottom;
    }

    // Add space around expanded rows
    &.expander:checked:not(:first-child),
    &.expander:checked + row {
      margin-top: 5px;
    }
  }
}

// Unified window

window.csd.unified:not(.solid-csd):not(.fullscreen):not(.tiled):not(.tiled-top):not(.tiled-bottom):not(.tiled-left):not(.tiled-right):not(.maximized) {
  &,
  > decoration,
  > decoration-overlay {
    border-radius: $_header_radius;
  }
}

// HdyWindowHandle separator

.windowhandle separator.sidebar {
  &:dir(ltr), &.left, &.left:dir(rtl),
  &:dir(rtl), &.right {
    background-color: $header_border;
    margin: 0;
  }
}

// Tabs

@mixin undershoot-gradient($dir) {
  background: linear-gradient(to #{$dir},
                              $bg_color,
                              transparentize($bg_color, 1) 20px);
}

@mixin need-attention-gradient($dir) {
  background: linear-gradient(to #{$dir},
                              transparentize($selected_bg_color, .3),
                              transparentize($selected_bg_color, .5) 1px,
                              transparentize($selected_bg_color, 1) 20px);
}

tabbar {
  .box {
    min-height: 20px;
    background: $bg_color;
    border-bottom: 1px solid $borders_color;
  }

  scrolledwindow.pinned {
    undershoot {
      border: 0 solid $borders_color;
    }

    &:dir(rtl) undershoot.left {
      border-left-width: 1px;
    }

    &:dir(ltr) undershoot.right {
      border-right-width: 1px;
    }

    tabbox {
      &:dir(ltr) {
        padding-right: 1px;
        box-shadow: inset -1px 0 $borders_color;
      }

      &:dir(rtl) {
        padding-left: 1px;
        box-shadow: inset 1px 0 $borders_color;
      }
    }
  }

  undershoot {
    transition: none;

    &.left {
      @include undershoot-gradient("right");
    }

    &.right {
      @include undershoot-gradient("left");
    }
  }

  .needs-attention-left undershoot.left {
    @include need-attention-gradient("right");
  }

  .needs-attention-right undershoot.right {
    @include need-attention-gradient("left");
  }

  tab {
    min-width: 118px;
    border-style: solid;
    border-color: $borders_color;
    border-width: 0 1px 0 1px;
    transition: background 150ms ease-in-out;
    background-color: transparentize($base_color, 1);
    color: $insensitive_fg_color;

    &.pinned {
      min-width: 28px;
    }

    &:checked, &:checked:hover {
      background-color: $base_color;
      color: $fg_color;
    }

    &:hover {
      background-color: transparentize($base_color, 0.5);
      color: mix($fg_color, $insensitive_fg_color, 50%);
    }
  }

  .start-action,
  .end-action {
    background-color: transparentize($base_color, 1);
    border-color: $borders_color;
    border-style: solid;
    transition: background 150ms ease-in-out;

    button {
      border: none;
      border-radius: 0;
    }
  }

  .start-action:dir(ltr),
  .end-action:dir(rtl) {
    border-right-width: 1px;

    > * {
      margin-right: 1px;
    }
  }

  .start-action:dir(rtl),
  .end-action:dir(ltr) {
    border-left-width: 1px;

    > * {
      margin-left: 1px;
    }
  }
}

.tab-drag-icon {
  tab {
    min-height: 20px;
    background-color: $base_color;

    $_wm_border: if($variant!='dark', transparentize(black, 0.9), transparentize(black, 0.45));

    // copy shadow and border color from popovers
    box-shadow: 0 2px 6px 1px if($variant!='dark', transparentize(black, 0.93), transparentize(black, 0.65)),
                0 0 0 1px darken($borders_color, 5%);

    margin: 25px;
  }
}


tabbar,
.tab-drag-icon {
  tab {
    padding: 2px 6px;

    &.needs-attention {
      background-image:
        radial-gradient(ellipse at bottom,
                        transparentize(white, .2),
                        transparentize($selected_bg_color, .8) 15%,
                        transparentize($selected_bg_color, 1) 15%);
    }

    .tab-close-button,
    .tab-indicator {
      padding: 0;
      margin: 0;
      min-width: 22px;
      min-height: 22px;
      color: mix($bg_color, $fg_color, 35%);

      border: none;
      box-shadow: none;
      -gtk-icon-shadow: none;
      text-shadow: none;
      background: none;
    }

    .tab-close-button,
    .tab-indicator.clickable {
      &:hover {
        color: lighten(red, 15%);
      }

      &:active {
        color: $selected_bg_color;
      }
    }
  }
}
