/***************
 * Header bars *
 ***************/
%titlebar,
headerbar {
  padding: 0 6px;
  min-height: 34px;
  background-color: $headerbar_color;
  color: $headerbar_fg_color;
  border-radius: 0;

  &:backdrop {
    border-color: $backdrop_borders_color;
    background-image: none;

    transition: $backdrop_transition;
  }

  .title {
    font-weight: bold;
    padding-left: 12px;
    padding-right: 12px;
  }

  .subtitle {
    font-size: smaller;
    padding-left: 12px;
    padding-right: 12px;

    @extend .dim-label;
  }

  %linked-header {
    border: none;
    border-radius: 3px;
    border-right-style: none;
    box-shadow: none;

    &:first-child {
      border-top-left-radius: 3px;
      border-bottom-left-radius: 3px;
    }

    &:last-child {
      border-top-right-radius: 3px;
      border-bottom-right-radius: 3px;
      border-right-style: solid;
    }

    &:only-child {
      border-radius: 3px;
      border-style: solid;
    }
  }
  entry{ min-height: 25px;}
  button {
    @include button(normal-header);
    min-height: 20px;
    margin-top: 5px;
    margin-bottom: 5px;
    border-radius: 4px;

    &:hover,
    &:active,
    &:active:hover,
    &:checked {
      // box-shadow: none;
      @include button(hover-header);
    }

    &:backdrop,
    &:disabled,
    &:backdrop:disabled {
      @include button(backdrop-header,transparent,transparentize($fg_color,0.8));
    }

    &:backdrop {
      &:hover,
      &:active,
      &:checked {
      background-color: transparent;
      color: $selected_bg_color;
      box-shadow: none;
       // @include button(hover-header,transparent,transparentize(white,0.7));
      }
    }


    //Reset style
    &.titlebutton {
      color: transparent;
      box-shadow: none;

      &:hover,
      &:active,
      &:checked,
      &:backdrop,
      &:backdrop:hover,* {
        color: transparent;
        box-shadow: none;
        background-color: transparent;
      }
    }

    @each $b_type, $b_color in (suggested-action, $cyan),
    (destructive-action, $destructive_color) {
      &.#{$b_type} {
        &:hover { @include button(hover, $b_color, $selected_fg_color); }

        &:active { @include button(active, $b_color, $selected_fg_color); }

        &:disabled {
          @include button(insensitive, $b_color, $selected_fg_color);
          label {color: transparentize($selected_fg_color,0.5);}
        }

        &:backdrop {
          @include button(backdrop, $b_color, $selected_fg_color);
          border-radius: 3px;
        }

        &:backdrop:disabled { @include button(backdrop-insensitive, $b_color, white); }

      }
    }
  }
  .linked > button,
  .linked > button:hover,
  .linked > button:active,
  .linked > button:checked,
  .linked > button:backdrop { @extend %linked-header; }
  .linked > button:active,
  .linked > button:checked{
    &:backdrop{
      color: $backdrop_selected_bg_color;
      label{
        color: $backdrop_selected_bg_color;
      }
    }
  }
  // End reset style

  &.selection-mode {
    $_hc: mix($top_highlight,$selected_bg_color, 50%); // highlight color

    color: $selected_fg_color;
    text-shadow: 0 -1px transparentize(black, 0.5);
    border-color: $selected_borders_color;

    @include headerbar_fill($selected_bg_color, $_hc);

    &:backdrop {
      background-color: $selected_bg_color;
      background-image: none;
      box-shadow: inset 0 1px mix($top_highlight, $selected_bg_color, 60%);
    }

    .subtitle:link { @extend *:link:selected;  }

    button {
      @include button(normal, $selected_bg_color, $selected_fg_color);

      &.flat { @include button(undecorated); }

      &:hover { @include button(hover, $selected_bg_color, $selected_fg_color); }

      &:active,
      &:checked { @include button(active, $selected_bg_color, $selected_fg_color); }

      &:backdrop {
        &.flat, & {
          @include button(backdrop, $selected_bg_color, $selected_fg_color);

          -gtk-icon-filter: none;
          border-color: $selected_borders_color;

          &:active,
          &:checked {
            @include button(backdrop-active, $selected_bg_color, $selected_fg_color);

            border-color: $selected_borders_color;
          }

          &:disabled {
            @include button(backdrop-insensitive, $selected_bg_color, $selected_fg_color);

            border-color: $selected_borders_color;

            &:active, &:checked {
              @include button(backdrop-insensitive-active, $selected_bg_color, $selected_fg_color);

              border-color: $selected_borders_color;
            }
          }
        }
      }

      &.flat { &:backdrop, &:disabled, &:backdrop:disabled { @include button(undecorated); }}

      &:disabled {
        @include button(insensitive, $selected_bg_color, $selected_fg_color);

        &:active,
        &:checked { @include button(insensitive-active, $selected_bg_color, $selected_fg_color); }
      }

      &.suggested-action {
        @include button(normal, $red, white);

        &:hover { @include button(hover, $red, white); }

        &:active { @include button(active, $red, white); }

        &:disabled { @include button(insensitive, $red, white); }

        &:backdrop { @include button(backdrop, $red, white); }

        &:backdrop:disabled { @include button(backdrop-insensitive, $red, white); }
      }
    }

    .selection-menu {
      &:backdrop, & {
        border-color: transparentize($selected_bg_color, 1);
        background-image: linear-gradient(to bottom, transparentize($selected_bg_color, 1), transparentize($selected_bg_color, 1));
        box-shadow: none;
        padding-left: 10px;
        padding-right: 10px;

        .arrow {
          -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
          color: transparentize($selected_fg_color,0.5);
          -gtk-icon-shadow: none;
        }
      }
    }
  }

  .tiled &,
  .maximized & {
    &.titlebar {
      @if $variant == 'light' { box-shadow: none; }
      @else { box-shadow: inset 0 -1px $bottom_highlight; }
    }
    &:backdrop, & { border-radius: 0; }
  } // squared corners when the window is maximized or tiled

  &.default-decoration {
    padding: 4px;
    min-height: 28px;

    button.titlebutton {
      min-height: 26px;
      min-width: 26px;
      margin: 0;
      padding: 0;
    }
  }
}

headerbar {
  // add vertical margins to common widget on the headerbar to avoid them spanning the whole height
  entry,
  spinbutton,
  separator:not(.sidebar),
  button,
  menubutton {
    margin-top: 5px;
    margin-bottom: 5px;
  }
  // Reset margins for buttons inside menubutton
  menubutton > button,
  spinbutton > button,
  splitbutton > button,
  splitbutton > menubutton,
  entry > menubutton {
    margin-top: 0px;
    margin-bottom: 0px;
  }

  switch {
    margin-top: 0;
    margin-bottom: 0;
  }
  separator { background: transparent; }

  viewswitcher, switcher {
    > box.horizontal {
      > button.radio {
        margin: 0;
        padding: 0;
        border-radius: 0;
      }
    }
  } 
}

.background:not(.tiled):not(.maximized) .titlebar {
  @if $variant == 'light' { box-shadow: inset 0 1px $top_highlight; }
  @else { box-shadow: inset 0 1px $top_highlight,inset 0 -1px $bottom_highlight; }


  &:backdrop, & {
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
  }
}

headerbar {
  window:not(.tiled):not(.maximized) separator:first-child + &, // tackles the paned container case
  window:not(.tiled):not(.maximized) &:first-child { &:backdrop, & { border-top-left-radius: 4px; }}

  window:not(.tiled):not(.maximized) &:last-child { &:backdrop, & { border-top-right-radius: 4px; }}
}

window {
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
}

.titlebar {
  &:not(headerbar){
    window.csd > & {
      // in csd we assume every titlebar is a headerbar so reset anything, this is needed for split toolbars cases
      padding: 0;
      background-color: transparent;
      background-image: none;
      border-style: none;
      border-color: transparent;
      box-shadow: none;
    }
  
    > separator {
      &, &:backdrop { background: $headerbar_color; }
    }
  
    @extend %titlebar;
  }
  button:active {
    color: $selected_bg_color;
  }
}

 // Gnome 
 
.sidebar-pane, .content-pane {
  .top-bar {
    &, headerbar {
      background-color: $headerbar_color;
    }
  }
}

.nautilus-window .sidebar-pane .top-bar headerbar {
  padding-top: 3px;
  padding-bottom: 3px;
}

.raised.top-bar {
  background: transparent;
}